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