CbmRoot
CbmBuildEventsSimple.cxx
Go to the documentation of this file.
1 
6 #include "CbmBuildEventsSimple.h"
7 
8 #include "TClonesArray.h"
9 #include "TStopwatch.h"
10 
11 #include "FairLogger.h"
12 #include "FairRootManager.h"
13 
14 #include "CbmEvent.h"
15 #include "CbmLink.h"
16 #include "CbmMatch.h"
17 #include "CbmStsAddress.h"
18 #include "CbmStsDigi.h"
19 
20 #include <cassert>
21 #include <iomanip>
22 #include <iostream>
23 #include <map>
24 
25 using namespace std;
26 
27 
28 // ===== Constructor =====================================================
30  : FairTask("BuildEventsSimple")
31  , fStsDigis(NULL)
32  , fEvents(NULL)
33  , fSliceN(0)
34  , fEv(0)
35  , fNDigis(0)
36  , fSN(-1111)
37  , fST(-1111)
38  , fNStsDigis()
39  , fWindDur(5)
40  , fMinusDeltaT(10)
41  , fPlusDeltaT(15)
42  , fDeadT(10)
43  , fMinHitStations(8)
44  , fMinDigis(2000)
45 
46 {
47  ;
48 }
49 // ===========================================================================
50 
51 
52 // ===== Destructor ======================================================
54 // ===========================================================================
55 
56 
57 // ===== FillEvent method ================================================
58 void CbmBuildEventsSimple::FillEvent(Int_t st, Int_t end) {
59  Int_t i;
60  // CbmStsDigi* digi;
61  Int_t nev = fEvents->GetEntriesFast();
62  CbmEvent* event = new ((*fEvents)[nev]) CbmEvent(fEv++);
63 
64  for (i = st; i <= end; i++) {
65  // digi=(CbmStsDigi*)fStsDigis->At(i);
67  }
68  FairRootManager::Instance()->Fill();
69  LOG(info) << "CbmBuildEventsSimple: Event constructed. Digis used from "
70  << st << " to " << end << ".";
71 }
72 
73 // ===========================================================================
74 
75 // ===== Task execution ==================================================
76 void CbmBuildEventsSimple::Exec(Option_t*) {
77 
78  // Reset output array
79  fEvents->Delete();
80 
81  Int_t i = 0;
82  Int_t j = 0;
83  // Int_t n=0;
84  Int_t k;
85  Int_t nsts = fStsDigis->GetEntriesFast();
86  Double_t t;
87  CbmStsDigi* digi;
88  CbmStsDigi* digi2;
89  Int_t n0;
90  Int_t n1;
91 
92  LOG(info) << "CbmBuildEventsSimple: Sts digis in slice " << nsts;
93  fNDigis = 0;
94  for (i = 0; i < 16; i++)
95  fNStsDigis[i] = 0;
96  fSN = 0;
97  fST = -1111;
98 
99  for (i = 0; i < nsts; i++) {
100  digi = (CbmStsDigi*) fStsDigis->At(i);
101  if (digi == NULL) continue;
102  t = digi->GetTime();
103  fNDigis++;
105  fNStsDigis[k]++;
106  if (fST == -1111) {
107  fSN = i;
108  fST = t;
109  }
110  if (t - fST > fWindDur) {
111  for (j = fSN; j < i; j++) {
112  digi2 = (CbmStsDigi*) fStsDigis->At(j);
113  if (digi2 == NULL) continue;
114  fST = digi2->GetTime();
115  if (t - fST <= fWindDur) {
116  fSN = j;
117  break;
118  }
119  fNDigis--;
121  fNStsDigis[k]--;
122  }
123  if (j == i) {
124  fSN = i;
125  fST = t;
126  }
127  }
128 
129  if (fNDigis >= fMinDigis) {
130  k = 0;
131  for (j = 0; j < 16; j++)
132  if (fNStsDigis[j] > 0) k++;
133  if (k >= fMinHitStations) {
134  // Reached required number of digis and hit stations
135  for (j = i; j > -1; j--) {
136  digi2 = (CbmStsDigi*) fStsDigis->At(j);
137  if (digi2 == NULL) continue;
138  if (fST - digi2->GetTime() > fMinusDeltaT) break;
139  }
140  n0 = j + 1;
141  for (j = i + 1; j < nsts; j++) {
142  digi2 = (CbmStsDigi*) fStsDigis->At(j);
143  if (digi2 == NULL) continue;
144  if (digi2->GetTime() - t > fPlusDeltaT) break;
145  }
146  n1 = j - 1;
147  FillEvent(n0, n1);
148  if (j == nsts) {
149  //Reached the end of the slice
150  i = j;
151  break;
152  }
153  for (j = n1 + 1; j < nsts; j++) {
154  digi2 = (CbmStsDigi*) fStsDigis->At(j);
155  if (digi2 == NULL) continue;
156  if (digi2->GetTime() - t > fPlusDeltaT + fDeadT) break;
157  }
158  if (j == nsts) {
159  //Reached the end of the slice
160  i = j;
161  break;
162  }
163  i = j - 1;
164  for (j = 0; j < 16; j++)
165  fNStsDigis[j] = 0;
166  fNDigis = 0;
167  fSN = i + 1;
168  digi2 = (CbmStsDigi*) fStsDigis->At(i + 1);
169  fST = digi2->GetTime();
170  /*
171  cout << "--> ";
172  digi2=(CbmStsDigi*)fSlice->GetData(kSTS, n0);
173  cout << n0 << "(" << digi2->GetTime() << ")" << ", ";
174  digi2=(CbmStsDigi*)fSlice->GetData(kSTS, n1);
175  cout << n1 << "(" << digi2->GetTime() << ")" << ": ";
176  digi2=(CbmStsDigi*)fSlice->GetData(kSTS, i);
177  cout << i << "(" << digi2->GetTime() << ")" << endl;
178 */
179  }
180  }
181  // cout << t << " " << fST << " " << fNDigis << " :";
182  // for(k=0;k<8;k++) cout << " " << fNStsDigis[k];
183  // cout << endl;
184  }
185  fSliceN++;
186 }
187 // ===========================================================================
188 
189 
190 // ===== Task initialisation =============================================
192  // --- Get FairRootManager instance
193  FairRootManager* ioman = FairRootManager::Instance();
194  assert(ioman);
195 
196  // --- Get input array (CbmStsDigi)
197  fStsDigis = (TClonesArray*) ioman->GetObject("StsDigi");
198  assert(fStsDigis);
199 
200  // Register output array (CbmStsDigi)
201  fEvents = new TClonesArray("CbmEvent", 100);
202  ioman->Register(
203  "Event", "CbmEvent", fEvents, IsOutputBranchPersistent("Event"));
204 
205  return kSUCCESS;
206 }
207 // ===========================================================================
208 
209 
CbmBuildEventsSimple::~CbmBuildEventsSimple
virtual ~CbmBuildEventsSimple()
Definition: CbmBuildEventsSimple.cxx:53
ECbmDataType::kStsDigi
@ kStsDigi
CbmBuildEventsSimple::fEv
Int_t fEv
Definition: CbmBuildEventsSimple.h:50
CbmBuildEventsSimple::fSN
Int_t fSN
Definition: CbmBuildEventsSimple.h:52
i
int i
Definition: L1/vectors/P4_F32vec4.h:25
CbmBuildEventsSimple::fSliceN
Int_t fSliceN
Definition: CbmBuildEventsSimple.h:48
CbmEvent::AddData
void AddData(ECbmDataType type, UInt_t index)
Definition: CbmEvent.cxx:15
CbmBuildEventsSimple::fNDigis
Int_t fNDigis
Definition: CbmBuildEventsSimple.h:51
CbmMatch.h
CbmBuildEventsSimple
Definition: CbmBuildEventsSimple.h:23
CbmBuildEventsSimple::fWindDur
Double_t fWindDur
Definition: CbmBuildEventsSimple.h:55
CbmEvent.h
CbmStsDigi.h
CbmBuildEventsSimple::fMinDigis
Int_t fMinDigis
Definition: CbmBuildEventsSimple.h:63
CbmBuildEventsSimple::fStsDigis
TClonesArray * fStsDigis
Input array (class CbmStsDigi)
Definition: CbmBuildEventsSimple.h:46
CbmBuildEventsSimple::fST
Double_t fST
Definition: CbmBuildEventsSimple.h:53
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
CbmBuildEventsSimple::fPlusDeltaT
Double_t fPlusDeltaT
Definition: CbmBuildEventsSimple.h:58
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
CbmStsDigi
Data class for a single-channel message in the STS.
Definition: CbmStsDigi.h:29
CbmBuildEventsSimple::fEvents
TClonesArray * fEvents
Output array (class CbmEvent)
Definition: CbmBuildEventsSimple.h:47
CbmBuildEventsSimple::fDeadT
Double_t fDeadT
Definition: CbmBuildEventsSimple.h:59
kStsUnit
@ kStsUnit
Definition: CbmStsAddress.h:18
CbmStsDigi::GetAddress
Int_t GetAddress() const
Definition: CbmStsDigi.h:53
CbmBuildEventsSimple::fNStsDigis
Int_t fNStsDigis[16]
Definition: CbmBuildEventsSimple.h:54
CbmBuildEventsSimple::fMinusDeltaT
Double_t fMinusDeltaT
Definition: CbmBuildEventsSimple.h:57
CbmBuildEventsSimple::Exec
virtual void Exec(Option_t *opt)
Definition: CbmBuildEventsSimple.cxx:76
CbmBuildEventsSimple::CbmBuildEventsSimple
CbmBuildEventsSimple()
Definition: CbmBuildEventsSimple.cxx:29
CbmEvent
Class characterising one event by a collection of links (indices) to data objects,...
Definition: CbmEvent.h:30
CbmBuildEventsSimple.h
CbmStsAddress.h
CbmBuildEventsSimple::fMinHitStations
Int_t fMinHitStations
Definition: CbmBuildEventsSimple.h:61
CbmBuildEventsSimple::Init
virtual InitStatus Init()
Definition: CbmBuildEventsSimple.cxx:191
CbmBuildEventsSimple::FillEvent
void FillEvent(Int_t st, Int_t end)
Definition: CbmBuildEventsSimple.cxx:58