CbmRoot
Loading...
Searching...
No Matches
CbmEvBuildSource.cxx
Go to the documentation of this file.
1/* Copyright (C) 2016-2021 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Volker Friese [committer] */
4
5#include "CbmEvBuildSource.h"
6
7#include "CbmDigi.h"
8#include "CbmStsAddress.h"
9#include "CbmStsDigi.h"
10#include "CbmTimeSlice.h"
11#include "FairEventHeader.h"
12#include "FairRootManager.h"
13#include "TChain.h"
14#include "TClonesArray.h"
15
16#include <Logger.h>
17
18#include <iostream>
19
20using namespace std;
21
23 : FairSource()
24 , fCh(NULL)
25 , fN(-1111)
26 , fI(-1111)
27 , fSTSDigi(NULL)
28 , fNSTSDigis(-1111)
29 , fSlice(NULL)
30 , fISts(0)
31 , fEv(0)
32 , fNDigis(0)
33 , fSN(-1111)
34 , fST(-1111)
35 , fWindDur(2)
36 , fMinusDeltaT(2)
37 , fPlusDeltaT(5)
38 , fDeadT(10)
39 , fMinHitStations(8)
40 , fMinDigis(2000)
41 , fEvHeader(NULL)
42{
43 fCh = new TChain("cbmsim");
44}
45
47 : FairSource()
48 , fCh(NULL)
49 , fN(-1111)
50 , fI(-1111)
51 , fSTSDigi(NULL)
52 , fNSTSDigis(-1111)
53 , fSlice(NULL)
54 , fISts(0)
55 , fEv(0)
56 , fNDigis(0)
57 , fSN(-1111)
58 , fST(-1111)
59 , fWindDur(2)
60 , fMinusDeltaT(2)
61 , fPlusDeltaT(5)
62 , fDeadT(10)
63 , fMinHitStations(8)
64 , fMinDigis(2000)
65 , fEvHeader(NULL)
66{
67 fCh = new TChain("cbmsim");
68 AddFile(fname);
69}
70
72 : FairSource(source)
73 , fCh(NULL)
74 , fN(-1111)
75 , fI(-1111)
76 , fSTSDigi(NULL)
77 , fNSTSDigis(-1111)
78 , fSlice(NULL)
79 , fISts(0)
80 , fEv(0)
81 , fNDigis(0)
82 , fSN(-1111)
83 , fST(-1111)
84 , fWindDur(2)
85 , fMinusDeltaT(2)
86 , fPlusDeltaT(5)
87 , fDeadT(10)
88 , fMinHitStations(8)
89 , fMinDigis(2000)
90 , fEvHeader(NULL)
91{
92 ;
93}
94
96{
97 Int_t j = 0;
98 // Int_t n=0;
99 Int_t k;
100 Int_t nsts;
101 Double_t t;
102 CbmStsDigi* digi;
103 CbmStsDigi* digi2;
104 Int_t n0;
105 Int_t n1;
106
107 cout << par << " " << fEv << endl;
108 if (par == 0) {
109 fI = -1;
110 fEv = 0;
111 }
112 else if (par != fEv) {
113 LOG(fatal) << "CbmEvBuildSource::ReadEvent(" << par << "): Can't jump to arbitrary event but 0. Current event is "
114 << fEv;
115 return 3;
116 }
117
118 if (fI == -1)
119 if (GetNextTimeSlice() < 0) return 2; //No entries in input chain
120
121 for (;;) {
122 nsts = fSlice->GetDataSize(kSts);
123 for (; fISts < nsts; fISts++) {
124 digi = (CbmStsDigi*) fSlice->GetData(kSts, fISts);
125 if (digi == NULL) continue;
126 t = digi->GetTime();
127 fNDigis++;
129 fNStsDigis[k]++;
130 if (fST == -1111) {
131 fSN = fISts;
132 fST = t;
133 }
134 if (t - fST > fWindDur) {
135 for (j = fSN; j < fISts; j++) {
136 digi2 = (CbmStsDigi*) fSlice->GetData(kSts, j);
137 if (digi2 == NULL) continue;
138 fST = digi2->GetTime();
139 if (t - fST <= fWindDur) {
140 fSN = j;
141 break;
142 }
143 fNDigis--;
145 fNStsDigis[k]--;
146 }
147 if (j == fISts) {
148 fSN = fISts;
149 fST = t;
150 }
151 }
152
153 if (fNDigis >= fMinDigis) {
154 k = 0;
155 for (j = 0; j < 16; j++)
156 if (fNStsDigis[j] > 0) k++;
157 if (k >= fMinHitStations) {
158 // Reached required number of digis and hit stations
159 for (j = fISts; j > -1; j--) {
160 digi2 = (CbmStsDigi*) fSlice->GetData(kSts, j);
161 if (digi2 == NULL) continue;
162 if (fST - digi2->GetTime() > fMinusDeltaT) break;
163 }
164 n0 = j + 1;
165 for (j = fISts + 1; j < nsts; j++) {
166 digi2 = (CbmStsDigi*) fSlice->GetData(kSts, j);
167 if (digi2 == NULL) continue;
168 if (digi2->GetTime() - t > fPlusDeltaT) break;
169 }
170 n1 = j - 1;
171 FillEvent(n0, n1);
172 if (j == nsts) {
173 //Reached the end of the slice
174 fISts = j;
175 return 0;
176 }
177 for (j = n1 + 1; j < nsts; j++) {
178 digi2 = (CbmStsDigi*) fSlice->GetData(kSts, j);
179 if (digi2 == NULL) continue;
180 if (digi2->GetTime() - t > fPlusDeltaT + fDeadT) break;
181 }
182 if (j == nsts) {
183 //Reached the end of the slice
184 fISts = j;
185 return 0;
186 }
187 fISts = j;
188 for (j = 0; j < 16; j++)
189 fNStsDigis[j] = 0;
190 fNDigis = 0;
191 fSN = fISts;
192 digi2 = (CbmStsDigi*) fSlice->GetData(kSts, fISts);
193 fST = digi2->GetTime();
194 return 0;
195 /*
196 cout << "--> ";
197 digi2=(CbmStsDigi*)fSlice->GetData(kSTS, n0);
198 cout << n0 << "(" << digi2->GetTime() << ")" << ", ";
199 digi2=(CbmStsDigi*)fSlice->GetData(kSTS, n1);
200 cout << n1 << "(" << digi2->GetTime() << ")" << ": ";
201 digi2=(CbmStsDigi*)fSlice->GetData(kSTS, i);
202 cout << i << "(" << digi2->GetTime() << ")" << endl;
203*/
204 } // if (k>=fMinHitStations)
205 } // if (fNDigis>=fMinDigis)
206 } // for(;fISts<nsts;fISts++)
207 if (GetNextTimeSlice() < 0) return 1;
208 // cout << t << " " << fST << " " << fNDigis << " :";
209 // for(k=0;k<8;k++) cout << " " << fNStsDigis[k];
210 // cout << endl;
211 }
212
213 // This should be unreachable
214 return 1111;
215}
216
217void CbmEvBuildSource::Close() { return; }
218
220{
221 Int_t i;
222
223 fI++;
224 if (fI == fN) return -1;
225 fCh->GetEntry(fI);
226
227 cout << fEvHeader << endl;
228 LOG(info) << "CbmBuildEventsSimple: Sts digis in slice " << fSlice->GetDataSize(kSts)
229 << ". Slice start: " << fSlice->GetStartTime();
230 fNDigis = 0;
231 for (i = 0; i < 16; i++)
232 fNStsDigis[i] = 0;
233 fSN = 0;
234 fST = -1111;
235 fISts = 0;
236 return fI;
237}
238
240{
241 FairRootManager* mgr = FairRootManager::Instance();
242
243 fCh->SetBranchAddress("TimeSlice.", &(fSlice));
244 fCh->SetBranchAddress("EventHeader.", &(fEvHeader));
245 fN = fCh->GetEntries();
246 fI = -1;
247
248 if (mgr == NULL) {
249 LOG(fatal) << "Can't find root manager in the system.";
250 return kFALSE;
251 }
252
253 fSTSDigi = new TClonesArray("CbmStsDigi", 10000);
254 mgr->Register("StsDigi", "Digital response in STS", fSTSDigi, kTRUE);
255 fSTSDigi->Delete();
256 fNSTSDigis = 0;
257
258 LOG(info) << "CbmEvBuildSource::Init() success";
259 return kTRUE;
260}
261
263{
264 cout << "Reset()" << endl;
265 // fI=0;
266}
267
269void CbmEvBuildSource::FillEvent(Int_t st, Int_t end)
270{
271 Int_t i;
272 CbmStsDigi* digi;
273
274 fNSTSDigis = 0;
275 fSTSDigi->Delete();
276 fEv++;
277 for (i = st; i <= end; i++) {
278 digi = (CbmStsDigi*) fSlice->GetData(kSts, i);
279 new ((*fSTSDigi)[fNSTSDigis]) CbmStsDigi(*digi);
280 fNSTSDigis++;
281 // cout << fSTSDigi->GetEntriesFast() << " " << fNSTSDigis << endl;
282 }
283 LOG(info) << "CbmEvBuildSource: Event constructed. Digis used from " << st << " to " << end << ".";
284}
285
286
287void CbmEvBuildSource::AddFile(const char* fname) { fCh->AddFile(fname); }
288
290{
291 if (fCh) delete fCh;
292 if (fSTSDigi) delete fSTSDigi;
293}
294
295void CbmEvBuildSource::FillEventHeader(FairEventHeader* feh)
296{
297 feh->SetEventTime(fEvHeader->GetEventTime());
298 feh->SetRunId(fEvHeader->GetRunId());
299 feh->SetMCEntryNumber(fEvHeader->GetMCEntryNumber());
300 feh->SetInputFileId(fEvHeader->GetInputFileId());
301}
302
ClassImp(CbmConverterManager)
@ kSts
Silicon Tracking System.
@ kStsUnit
CbmTimeSlice * fSlice
FairEventHeader * fEvHeader
TClonesArray * fSTSDigi
virtual Bool_t Init()
Int_t fN
Chain of input files.
void AddFile(const char *fname)
Int_t fISts
Current time slice.
virtual Int_t ReadEvent(UInt_t par=0)
Int_t fNSTSDigis
Array of output STS digis for each built event.
virtual void FillEventHeader(FairEventHeader *feh)
void FillEvent(Int_t st, Int_t end)
Data class for a single-channel message in the STS.
Definition CbmStsDigi.h:40
XPU_D int32_t GetAddress() const
Definition CbmStsDigi.h:74
double GetStartTime() const
uint32_t GetElementId(int32_t address, int32_t level)
Get the index of an element.
Hash for CbmL1LinkKey.