BmnRoot
Loading...
Searching...
No Matches
BmnZdcBScanner.cxx
Go to the documentation of this file.
1/*
2 * File: BmnZdcBScanner.cxx
3 * Author: pnaleks <pnaleks@gmail.com>
4 *
5 * Created on 25 октября 2019 г., 12:15
6 */
7
8#include <BmnEventHeader.h>
9#include <FairMCEventHeader.h>
10
11#include "BmnZdcBScanner.h"
12
13void BmnZdcBScanner::SetEventData(TClonesArray* pArrayOfBmnZDCDigit, Double_t scale) {
14 Int_t N = pArrayOfBmnZDCDigit->GetEntries();
15 printf("SetEventData from %d entries\n",N);
16 fEventData.Reset();
17 for (Int_t i = 0; i < N; i++) {
18 BmnZDCDigit * p = (BmnZDCDigit *)pArrayOfBmnZDCDigit->At(i);
19 if (p == 0) continue;
20 fEventData.Add(p,scale);
21 }
22}
23
24TH1D* BmnZdcBScanner::Scan(char mode) {
25 printf("Starting scan\n");
26 TString name = TString::Format("BSpectrum_%c",mode);
27 TString title = TString::Format("b-spectrum from %c",mode);
28 TH1D * pH = new TH1D(name.Data(),title.Data(),100,0,20);
29
30 TClonesArray * pArrayOfBmnZDCDigit = new TClonesArray("BmnZDCDigit");
31 fInpChain.SetBranchAddress("ZDC",&pArrayOfBmnZDCDigit);
32
33 FairMCEventHeader * pHeader = new FairMCEventHeader();
34 fInpChain.SetBranchAddress("MCEventHeader.",&pHeader);
35
36 UInt_t entries = fInpChain.GetEntries();
37 if (fMaxEntries && entries > fMaxEntries) entries = fMaxEntries;
38
39 printf("Started for %u entries\n", entries);
40
41 if (fIndex) delete fIndex;
42
43 fIndexSize = 0;
44 fIndex = new Item[entries];
45 if (!fIndex) throw;
46
47 UInt_t percent = entries / 100;
48 for (UInt_t i = 0; i < entries; i++) {
49 fInpChain.GetEntry(i);
50
51 OnEvent(pArrayOfBmnZDCDigit,mode,pHeader->GetB());
52
53 if (fShowProgress && percent > 0 && i%percent == 0) DrawBar(i, entries);
54 }
55
56 std::sort(fIndex, fIndex + fIndexSize, BmnZdcBScanner::compareItem);
57
58 Double_t scanValue;
59 switch (mode) {
60 case 'A':
61 scanValue = fEventData.GetA();
62 break;
63 case 'E':
64 scanValue = fEventData.GetE();
65 break;
66 case 'H':
67 scanValue = fEventData.GetHits();
68 break;
69 case 'M':
70 scanValue = fEventData.GetM();
71 break;
72 default:
73 printf("Unexpected mode '%c'\n",mode);
74 throw;
75 }
76
77 OnScan(fScanWidth,scanValue,pH);
78
79 return pH;
80}
81
82void BmnZdcBScanner::OnEvent(TClonesArray* pArrayOfBmnZDCDigit, char mode, Double_t b) {
83 Int_t N = pArrayOfBmnZDCDigit->GetEntries();
84
85 ZdcMoment MoI;
86
87 for (Int_t i = 0; i < N; i++) {
88 BmnZDCDigit * p = (BmnZDCDigit*)pArrayOfBmnZDCDigit->At(i);
89 if (p == 0) continue;
90 MoI.Add(p,fSimScale);
91 }
92
93 if (MoI.GetE() == 0.) return;
94
95 Item * p = fIndex + fIndexSize++;
96 switch (mode) {
97 case 'A':
98 p->index = MoI.GetA();
99 break;
100 case 'E':
101 p->index = MoI.GetE();
102 break;
103 case 'H':
104 p->index = MoI.GetHits();
105 break;
106 case 'M':
107 p->index = MoI.GetM();
108 break;
109 default:
110 printf("Unexpected mode '%c'\n",mode);
111 throw;
112 }
113
114 p->b = b;
115}
116
117void BmnZdcBScanner::OnScan(Int_t n, Double_t scanValue, TH1D* pBH) {
118 if (n > (Int_t)fIndexSize) n = fIndexSize;
119 Int_t cnt = 0;
120
121 UInt_t iFwd = 0;
122 UInt_t iRew = 0;
123 Double_t dPos = fIndex[iFwd].index - scanValue;
124 Double_t dNeg = 0;
125
126 //Double_t bS = 0;
127 //Double_t bSS = 0;
128
129 while (dPos <= 0) {
130 iFwd++;
131 if (iFwd >= fIndexSize) return;
132 dPos = fIndex[iFwd].index - scanValue;
133 }
134
135 if (iFwd > 0) {
136 iRew = iFwd-1;
137 dNeg = scanValue - fIndex[iRew].index;
138 }
139
140 while (cnt < n) {
141 Int_t i = -1;
142 if (dNeg > 0 && (dNeg < dPos || iFwd >= fIndexSize-1)) {
143 if (iRew > 0) {
144 iRew--;
145 i = iRew;
146 dNeg = scanValue - fIndex[iRew].index;
147 }
148 } else {
149 if (iFwd < fIndexSize-1) {
150 iFwd++;
151 i = iFwd;
152 dPos = fIndex[iFwd].index - scanValue;
153 }
154 }
155 if (i < 0) {
156 return;
157 } else {
158 cnt++;
159 Double_t b = fIndex[i].b;
160 if (pBH) pBH->Fill(b);
161 }
162 }
163}
void DrawBar(UInt_t iEv, UInt_t nEv)
Definition BmnMath.cxx:940
int i
Definition P4_F32vec4.h:22
virtual TH1D * Scan(char mode)
void SetEventData(TClonesArray *pArrayOfBmnZDCDigit, Double_t scale=1.)
Double_t GetE()
Int_t GetHits()
Double_t GetA()
Double_t GetM()
void Add(BmnZDCDigit *p, Double_t scale=1.)