BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
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 "BmnZdcBScanner.h"
9
10#include <BmnEventHeader.h>
11#include <FairMCEventHeader.h>
12
13void BmnZdcBScanner::SetEventData(TClonesArray* pArrayOfBmnZDCDigit, Double_t scale)
14{
15 Int_t N = pArrayOfBmnZDCDigit->GetEntries();
16 printf("SetEventData from %d entries\n", N);
17 fEventData.Reset();
18 for (Int_t i = 0; i < N; i++) {
19 BmnZDCDigit* p = (BmnZDCDigit*)pArrayOfBmnZDCDigit->At(i);
20 if (p == 0)
21 continue;
22 fEventData.Add(p, scale);
23 }
24}
25
27{
28 printf("Starting scan\n");
29 TString name = TString::Format("BSpectrum_%c", mode);
30 TString title = TString::Format("b-spectrum from %c", mode);
31 TH1D* pH = new TH1D(name.Data(), title.Data(), 100, 0, 20);
32
33 TClonesArray* pArrayOfBmnZDCDigit = new TClonesArray("BmnZDCDigit");
34 fInpChain.SetBranchAddress("ZDC", &pArrayOfBmnZDCDigit);
35
36 FairMCEventHeader* pHeader = new FairMCEventHeader();
37 fInpChain.SetBranchAddress("MCEventHeader.", &pHeader);
38
39 UInt_t entries = fInpChain.GetEntries();
40 if (fMaxEntries && entries > fMaxEntries)
41 entries = fMaxEntries;
42
43 printf("Started for %u entries\n", entries);
44
45 if (fIndex)
46 delete fIndex;
47
48 fIndexSize = 0;
49 fIndex = new Item[entries];
50 if (!fIndex)
51 throw;
52
53 UInt_t percent = entries / 100;
54 for (UInt_t i = 0; i < entries; i++) {
55 fInpChain.GetEntry(i);
56
57 OnEvent(pArrayOfBmnZDCDigit, mode, pHeader->GetB());
58
59 if (fShowProgress && percent > 0 && i % percent == 0)
60 DrawBar(i, entries);
61 }
62
64
65 Double_t scanValue;
66 switch (mode) {
67 case 'A':
68 scanValue = fEventData.GetA();
69 break;
70 case 'E':
71 scanValue = fEventData.GetE();
72 break;
73 case 'H':
74 scanValue = fEventData.GetHits();
75 break;
76 case 'M':
77 scanValue = fEventData.GetM();
78 break;
79 default:
80 printf("Unexpected mode '%c'\n", mode);
81 throw;
82 }
83
84 OnScan(fScanWidth, scanValue, pH);
85
86 return pH;
87}
88
89void BmnZdcBScanner::OnEvent(TClonesArray* pArrayOfBmnZDCDigit, char mode, Double_t b)
90{
91 Int_t N = pArrayOfBmnZDCDigit->GetEntries();
92
93 ZdcMoment MoI;
94
95 for (Int_t i = 0; i < N; i++) {
96 BmnZDCDigit* p = (BmnZDCDigit*)pArrayOfBmnZDCDigit->At(i);
97 if (p == 0)
98 continue;
99 MoI.Add(p, fSimScale);
100 }
101
102 if (MoI.GetE() == 0.)
103 return;
104
105 Item* p = fIndex + fIndexSize++;
106 switch (mode) {
107 case 'A':
108 p->index = MoI.GetA();
109 break;
110 case 'E':
111 p->index = MoI.GetE();
112 break;
113 case 'H':
114 p->index = MoI.GetHits();
115 break;
116 case 'M':
117 p->index = MoI.GetM();
118 break;
119 default:
120 printf("Unexpected mode '%c'\n", mode);
121 throw;
122 }
123
124 p->b = b;
125}
126
128{
129 if (n > (Int_t)fIndexSize)
130 n = fIndexSize;
131 Int_t cnt = 0;
132
133 UInt_t iFwd = 0;
134 UInt_t iRew = 0;
135 Double_t dPos = fIndex[iFwd].index - scanValue;
136 Double_t dNeg = 0;
137
138 // Double_t bS = 0;
139 // Double_t bSS = 0;
140
141 while (dPos <= 0) {
142 iFwd++;
143 if (iFwd >= fIndexSize)
144 return;
145 dPos = fIndex[iFwd].index - scanValue;
146 }
147
148 if (iFwd > 0) {
149 iRew = iFwd - 1;
150 dNeg = scanValue - fIndex[iRew].index;
151 }
152
153 while (cnt < n) {
154 Int_t i = -1;
155 if (dNeg > 0 && (dNeg < dPos || iFwd >= fIndexSize - 1)) {
156 if (iRew > 0) {
157 iRew--;
158 i = iRew;
159 dNeg = scanValue - fIndex[iRew].index;
160 }
161 } else {
162 if (iFwd < fIndexSize - 1) {
163 iFwd++;
164 i = iFwd;
165 dPos = fIndex[iFwd].index - scanValue;
166 }
167 }
168 if (i < 0) {
169 return;
170 } else {
171 cnt++;
172 Double_t b = fIndex[i].b;
173 if (pBH)
174 pBH->Fill(b);
175 }
176 }
177}
void DrawBar(UInt_t iEv, UInt_t nEv)
Definition BmnMath.cxx:940
int i
Definition P4_F32vec4.h:22
int Int_t
unsigned int UInt_t
double Double_t
class ZdcMoment fEventData
void OnEvent(TClonesArray *pArrayOfBmnZDCDigit, char mode, Double_t b)
static bool compareItem(Item i1, Item i2)
virtual TH1D * Scan(char mode)
void SetEventData(TClonesArray *pArrayOfBmnZDCDigit, Double_t scale=1.)
struct BmnZdcBScanner::Item * fIndex
void OnScan(Int_t n, Double_t scanValue, TH1D *pBH)
virtual Int_t Fill(const char *name, Double_t w)
Int_t GetEntries() const override
TObject * At(Int_t idx) const override
const char * Data() const
static TString Format(const char *fmt,...)
Double_t GetE()
Int_t GetHits()
Double_t GetA()
Double_t GetM()
void Add(BmnZDCDigit *p, Double_t scale=1.)
*brief user defined string literal for JSON values *sa std::size_t n
Definition json.hpp:20362