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