1 | // class MacroCellData |
---|
2 | // M. Pallavicini - created 20-11-2001 |
---|
3 | // Description of the data gathered by the MacroCell during the whole event |
---|
4 | // |
---|
5 | #include <math.h> |
---|
6 | #include <climits> |
---|
7 | #include "MacroCellData.hh" |
---|
8 | #include "MacroCell.hh" |
---|
9 | #include "FrontEndChip.hh" |
---|
10 | #include "MacroCellHit.hh" |
---|
11 | #include "EEvent.hh" |
---|
12 | #include "Photomultiplier.hh" |
---|
13 | |
---|
14 | ClassImp(MacroCellData) |
---|
15 | |
---|
16 | //______________________________________________________________________________ |
---|
17 | MacroCellData::MacroCellData( MacroCell* p ) : pCell(p) { |
---|
18 | // ctor |
---|
19 | |
---|
20 | fGtuStart = INT_MAX; |
---|
21 | fGtuEnd = 0; |
---|
22 | fGtuTrigger = INT_MAX; |
---|
23 | ftest_triggerPTT=INT_MIN; |
---|
24 | ftest_triggerLTT=INT_MIN; |
---|
25 | ftest_triggerCCB_LTT=INT_MIN; |
---|
26 | fTriggered = false; |
---|
27 | |
---|
28 | fup_countsPTT= INT_MIN; |
---|
29 | fGTU_upPTT= INT_MIN; |
---|
30 | frow_upPTT= INT_MIN; |
---|
31 | fcol_upPTT= INT_MIN; |
---|
32 | fchip_ID_upPTT= INT_MIN; |
---|
33 | fdir_upPTT= INT_MIN; |
---|
34 | fPdmID_PTT=INT_MIN; |
---|
35 | |
---|
36 | fup_countsLTT= INT_MIN; |
---|
37 | fGTU_upLTT= INT_MIN; |
---|
38 | frow_upLTT= INT_MIN; |
---|
39 | fcol_upLTT= INT_MIN; |
---|
40 | fchip_ID_upLTT= INT_MIN; |
---|
41 | fdir_upLTT= INT_MIN; |
---|
42 | fPdmID_LTT=INT_MIN; |
---|
43 | |
---|
44 | fup_countsCCB_LTT= INT_MIN; |
---|
45 | fGTU_upCCB_LTT= INT_MIN; |
---|
46 | frow_upCCB_LTT= INT_MIN; |
---|
47 | fcol_upCCB_LTT= INT_MIN; |
---|
48 | fchip_ID_upCCB_LTT= INT_MIN; |
---|
49 | fdir_upCCB_LTT= INT_MIN; |
---|
50 | fPdmID_CCB_LTT=INT_MIN; |
---|
51 | |
---|
52 | SetEmpty(); |
---|
53 | } |
---|
54 | |
---|
55 | //______________________________________________________________________________ |
---|
56 | MacroCellData::~MacroCellData() { |
---|
57 | // dtor |
---|
58 | |
---|
59 | |
---|
60 | // map<Int_t, map<Int_t,ChipGtuData*>* >::const_iterator itCD2; |
---|
61 | // for(itCD2=fChipData2.begin(); itCD2 != fChipData2.end(); itCD2++) { |
---|
62 | // map<Int_t,ChipGtuData*>* mCGD = itCD2->second; |
---|
63 | // map<Int_t,ChipGtuData*>::const_iterator itCGD; |
---|
64 | // for(itCGD=mCGD->begin(); itCGD!=mCGD->end(); itCGD++) { |
---|
65 | // ChipGtuData* d=itCGD->second; |
---|
66 | // if (d) delete d; |
---|
67 | // } |
---|
68 | // if ( mCGD ) { |
---|
69 | // mCGD->clear(); |
---|
70 | // delete mCGD; |
---|
71 | // } |
---|
72 | // } |
---|
73 | // fChipData2.clear(); |
---|
74 | // |
---|
75 | // map<Int_t, vector<ChipGtuData*>* >::const_iterator it; |
---|
76 | // for(it=fChipData.begin(); it != fChipData.end(); it++) { |
---|
77 | // vector<ChipGtuData*>* hits = it->second; |
---|
78 | // if ( hits ) { |
---|
79 | // /* for(size_t j=0; j < hits->size(); j++) { |
---|
80 | // ChipGtuData* d = (*hits)[j]; |
---|
81 | // if (d) |
---|
82 | // delete d; |
---|
83 | // }*/ |
---|
84 | // hits->clear(); |
---|
85 | // delete hits; |
---|
86 | // } |
---|
87 | // } |
---|
88 | // fChipData.clear(); |
---|
89 | // |
---|
90 | // map<Int_t, vector<MacroCellHit*>* >::const_iterator itMCH; |
---|
91 | // for(itMCH=fData.begin(); itMCH != fData.end(); itMCH++) { |
---|
92 | // vector<MacroCellHit*>* hits = itMCH->second; |
---|
93 | // if ( hits ) { |
---|
94 | // for(size_t j=0;j<hits->size(); j++) { |
---|
95 | // MacroCellHit* h = (*hits)[j]; |
---|
96 | // if (h) |
---|
97 | // delete h; |
---|
98 | // } |
---|
99 | // hits->clear(); |
---|
100 | // delete hits; |
---|
101 | // } |
---|
102 | // } |
---|
103 | // fData.clear(); |
---|
104 | ClearMemory(); |
---|
105 | } |
---|
106 | |
---|
107 | //______________________________________________________________________________ |
---|
108 | void MacroCellData::BuildGtu( Int_t gtu_num ) { |
---|
109 | // perform the single GTU analysis |
---|
110 | // look for X & Y logic for the whole macrocell |
---|
111 | // compute the number of hits and the time recorded for each pixels |
---|
112 | // including ghosts |
---|
113 | // data is saved into a map |
---|
114 | |
---|
115 | Int_t total_counts = 0; |
---|
116 | Double_t trigger_time = HUGE; |
---|
117 | |
---|
118 | fData[gtu_num] = new vector<MacroCellHit*>; |
---|
119 | |
---|
120 | Bool_t active = kFALSE; |
---|
121 | |
---|
122 | // get the list of ChipGtuData associated to this GTU |
---|
123 | vector<ChipGtuData*> *v = fChipData[gtu_num]; |
---|
124 | if ( v == NULL ) { |
---|
125 | return; |
---|
126 | } |
---|
127 | |
---|
128 | // flags for ghost calculation |
---|
129 | vector<Int_t> ColumnFlags; |
---|
130 | vector<Int_t> RowFlags; |
---|
131 | ColumnFlags.clear(); |
---|
132 | RowFlags.clear(); |
---|
133 | |
---|
134 | // loop on all objects |
---|
135 | vector<ChipGtuData*>::const_iterator it = v->begin(); |
---|
136 | for( ; it != v->end(); it++) { |
---|
137 | ChipGtuData *chdat = *it; |
---|
138 | if ( chdat ) { |
---|
139 | Int_t x; |
---|
140 | Int_t y; |
---|
141 | Double_t t; |
---|
142 | Int_t nch = chdat->FrontEnd()->Channels(); |
---|
143 | if ( chdat->GetXYLogic(x,y,t) ) { |
---|
144 | active = kTRUE; |
---|
145 | total_counts += chdat->FastOrHits(); // counts after gate opened |
---|
146 | for(Int_t i=0; i<nch; i++) { |
---|
147 | if ( chdat->CheckCounter(i) ) { |
---|
148 | //FIXME ChkCntr is kTRUE also if counts == threshold |
---|
149 | //FIXME Hits with counts == threshold are also saved |
---|
150 | Int_t mx, my; |
---|
151 | chdat->FrontEnd()->GetPixelCellRowCol( i, mx, my ); |
---|
152 | if ( t < trigger_time ) { |
---|
153 | trigger_time = t; // time at which the logic fired |
---|
154 | } |
---|
155 | // add this hit to the list |
---|
156 | ChannelUniqueId uid = chdat->FrontEnd()->UniqueChanId(i); |
---|
157 | fData[gtu_num]->push_back(new MacroCellHit(mx,my,total_counts,gtu_num,uid)); |
---|
158 | ColumnFlags.push_back(my); |
---|
159 | RowFlags.push_back(mx); |
---|
160 | } |
---|
161 | } |
---|
162 | } |
---|
163 | } |
---|
164 | } |
---|
165 | |
---|
166 | // if there was activity in this gtu, increment the counter |
---|
167 | if ( active ) { |
---|
168 | if ( gtu_num < GtuStart() ) fGtuStart = gtu_num; |
---|
169 | if ( gtu_num > GtuEnd() ) fGtuEnd = gtu_num; |
---|
170 | fNumActiveGtus ++; |
---|
171 | } |
---|
172 | |
---|
173 | // add ghost hits |
---|
174 | for(UInt_t i=0; i<RowFlags.size(); i++) { |
---|
175 | Int_t mx = RowFlags[i]; |
---|
176 | for(UInt_t j=0; j<ColumnFlags.size(); j++) { |
---|
177 | Int_t my = ColumnFlags[j]; |
---|
178 | Int_t uid = Cell()->GetUniqueIdRowCol(mx,my); |
---|
179 | // add hit (avoid duplication with check i != j because the hit was already added before) |
---|
180 | if ( uid && i!=j ) { |
---|
181 | fData[gtu_num]->push_back(new MacroCellHit(mx,my,total_counts,gtu_num,uid)); |
---|
182 | } |
---|
183 | } |
---|
184 | } |
---|
185 | |
---|
186 | // all "hits" (real and ghosts) have the same number of counts |
---|
187 | // the macrocell has just one counter and keep track of every X Y |
---|
188 | // logic fired during the GTU |
---|
189 | // I assume here that when more than one XY pair is active, the |
---|
190 | // macrocell will have no memory of the time in which they occurred |
---|
191 | // and will just associate the total number of hits to all combinations |
---|
192 | // of x and y |
---|
193 | for(UInt_t i=0; i<fData[gtu_num]->size(); i++) { |
---|
194 | // set number of counts to the same value for all Macrocellhits |
---|
195 | (*fData[gtu_num])[i]->SetHits( total_counts ); |
---|
196 | |
---|
197 | // FIXME: debug code |
---|
198 | /*cout << "Hit " << i << ":" |
---|
199 | << (*fData[gtu_num])[i]->Row() << " " |
---|
200 | << (*fData[gtu_num])[i]->Col() << " " |
---|
201 | << (*fData[gtu_num])[i]->Gtu() << " " |
---|
202 | << (*fData[gtu_num])[i]->Hits()<< " " |
---|
203 | << (*fData[gtu_num])[i]->UniqueId()<< " " << endl; |
---|
204 | */ |
---|
205 | } |
---|
206 | } |
---|
207 | |
---|
208 | |
---|
209 | //______________________________________________________________________________ |
---|
210 | void MacroCellData::Add( Int_t gtu_num, ChipGtuData* pData) { |
---|
211 | // add data from a chip; just stored into a map |
---|
212 | // a second map is also filled for triggering purposes |
---|
213 | |
---|
214 | // fill first map only if pData->IsEmpty() is kFALSE, which |
---|
215 | // means at least one channel had at lest 5 hits |
---|
216 | if ( !pData->IsEmpty() ) { |
---|
217 | if ( !fChipData[gtu_num] ) |
---|
218 | fChipData[gtu_num] = new vector<ChipGtuData*>; |
---|
219 | fChipData[gtu_num]->push_back( pData ); |
---|
220 | } |
---|
221 | |
---|
222 | // fill second map every time |
---|
223 | Int_t id = pData->FrontEnd()->Id(); |
---|
224 | if ( !fChipData2[id] ) |
---|
225 | fChipData2[id] = new map<Int_t,ChipGtuData*>; |
---|
226 | (*fChipData2[id])[gtu_num] = pData; |
---|
227 | |
---|
228 | |
---|
229 | SetEmpty( kFALSE ); |
---|
230 | } |
---|
231 | |
---|
232 | //______________________________________________________________________________ |
---|
233 | string& MacroCellData::Dump() { |
---|
234 | // |
---|
235 | // dump macrocell data onto a string |
---|
236 | // |
---|
237 | char line[500]; |
---|
238 | sprintf(line,"MacroCell %d\n",Cell()->Id()); |
---|
239 | text_dump.append(line); |
---|
240 | sprintf(line,"Number of active GTUs = %d\n",GtuEnd()-GtuStart()); |
---|
241 | text_dump.append(line); |
---|
242 | for(UInt_t i=0; i < fData.size(); i++ ) { |
---|
243 | vector<MacroCellHit*>& v = *(fData[i]); |
---|
244 | if ( &v ) { |
---|
245 | sprintf(line,"GTU = %d\n",i); |
---|
246 | text_dump.append(line); |
---|
247 | for( UInt_t j=0; j < v.size(); j++ ) { |
---|
248 | MacroCellHit *hit = v[j]; |
---|
249 | if ( hit ) { |
---|
250 | sprintf(line,"HIT %02d X=%02d Y=%02d Hits=%02d \n", |
---|
251 | j,hit->Row(),hit->Col(), hit->Hits() ); |
---|
252 | text_dump.append(line); |
---|
253 | } |
---|
254 | } |
---|
255 | } |
---|
256 | } |
---|
257 | |
---|
258 | return text_dump; |
---|
259 | } |
---|
260 | |
---|
261 | |
---|
262 | //______________________________________________________________________________ |
---|
263 | Bool_t MacroCellData::CheckContiguity(Int_t gtu1, Int_t gtu2 ) { |
---|
264 | // trigger function |
---|
265 | // returns kTRUE if gtu1 has at least one MacroCellHit |
---|
266 | // that is contiguous (in space) with one MacroCellHit of gtu2 |
---|
267 | |
---|
268 | vector<MacroCellHit*>* hits1 = fData[gtu1]; |
---|
269 | vector<MacroCellHit*>* hits2 = fData[gtu2]; |
---|
270 | if ( !hits1 || !hits2 ) |
---|
271 | return kFALSE; |
---|
272 | for(unsigned i1=0; i1 < hits1->size(); i1++) { |
---|
273 | MacroCellHit* hit1 = (*hits1)[i1]; |
---|
274 | if ( hit1) { |
---|
275 | for(unsigned i2=0; i2 < hits2->size(); i2++) { |
---|
276 | MacroCellHit* hit2 = (*hits2)[i2]; |
---|
277 | if ( hit2) { |
---|
278 | if ( (*hit1)%(*hit2) ) { // % operator for MacroCellHit |
---|
279 | return kTRUE; |
---|
280 | } |
---|
281 | } |
---|
282 | } |
---|
283 | } |
---|
284 | } |
---|
285 | return kFALSE; |
---|
286 | } |
---|
287 | |
---|
288 | //______________________________________________________________________________ |
---|
289 | void MacroCellData::SimulateTrigger() { |
---|
290 | // simulate trigger using all engines associated to the macrocell |
---|
291 | |
---|
292 | // clear trigger word in all engines |
---|
293 | TriggerEngine::ResetTriggerWord(); |
---|
294 | |
---|
295 | // get iterator over existing engines |
---|
296 | map<ETriggerTypeIdentifier,TriggerEngine*>::const_iterator it = Cell()->GetEngines().begin(); |
---|
297 | |
---|
298 | // iterate and simulate trigger |
---|
299 | for( ; it != Cell()->GetEngines().end(); it++ ) { |
---|
300 | TriggerEngine *trg = it->second; |
---|
301 | trg->Simulate( this ); |
---|
302 | if ( trg->HasTriggered() ) { |
---|
303 | SetGtuTrigger( trg->GetGtuTrigger() ); |
---|
304 | } |
---|
305 | } |
---|
306 | } |
---|
307 | |
---|
308 | //______________________________________________________________________________ |
---|
309 | Double_t MacroCellData::GtuTimeStart() { |
---|
310 | // time in ns of the first edge of the first GTU for this event |
---|
311 | // the time is measured from the Photons time |
---|
312 | |
---|
313 | Double_t start = Cell()->GetGtuBegin(); |
---|
314 | start += GtuStart()*Cell()->GetGtuLength(); |
---|
315 | return start; |
---|
316 | } |
---|
317 | |
---|
318 | |
---|
319 | //______________________________________________________________________________ |
---|
320 | Double_t MacroCellData::GtuTimeEnd() { |
---|
321 | // same for second edge of last GTU |
---|
322 | |
---|
323 | Double_t end = Cell()->GetGtuBegin(); |
---|
324 | end += (GtuEnd()+1.)*Cell()->GetGtuLength(); |
---|
325 | return end; |
---|
326 | } |
---|
327 | |
---|
328 | |
---|
329 | //______________________________________________________________________________ |
---|
330 | Int_t MacroCellData::NumMacroCellHits() { |
---|
331 | // compute the total number of hits and returns it |
---|
332 | |
---|
333 | Int_t NumHits = 0; |
---|
334 | for(Int_t iGtu = GtuStart(); iGtu < GtuEnd(); iGtu++) { |
---|
335 | if ( Hits(iGtu) ) { |
---|
336 | NumHits += Hits(iGtu)->size(); |
---|
337 | } |
---|
338 | } |
---|
339 | return NumHits; |
---|
340 | } |
---|
341 | |
---|
342 | //______________________________________________________________________________ |
---|
343 | ChipGtuData* MacroCellData::GetChipGtuData(Int_t chip, Int_t gtu) { |
---|
344 | // Return data of a specific chip in a given gtu |
---|
345 | |
---|
346 | if ( fChipData2.size()==0 ) return NULL; |
---|
347 | |
---|
348 | if ( fChipData2.count(chip)==0 ) return NULL; |
---|
349 | map<Int_t, ChipGtuData*> &m = *(fChipData2[chip]); |
---|
350 | if ( m.count(gtu) ) return m[gtu]; |
---|
351 | else return NULL; |
---|
352 | } |
---|
353 | |
---|
354 | //______________________________________________________________________________ |
---|
355 | Bool_t MacroCellData::ClearMemory() { |
---|
356 | // |
---|
357 | // Physically release the memory allocated by the arrays of this object |
---|
358 | // |
---|
359 | |
---|
360 | map<Int_t, map<Int_t,ChipGtuData*>* >::const_iterator itCD2; |
---|
361 | for(itCD2=fChipData2.begin(); itCD2 != fChipData2.end(); itCD2++) { |
---|
362 | map<Int_t,ChipGtuData*>* mCGD = itCD2->second; |
---|
363 | map<Int_t,ChipGtuData*>::const_iterator itCGD; |
---|
364 | if ( mCGD ) { |
---|
365 | for(itCGD=mCGD->begin(); itCGD!=mCGD->end(); itCGD++) |
---|
366 | delete itCGD->second; |
---|
367 | |
---|
368 | delete mCGD; |
---|
369 | } |
---|
370 | } |
---|
371 | fChipData2.clear(); |
---|
372 | |
---|
373 | map<Int_t, vector<ChipGtuData*>* >::const_iterator it; |
---|
374 | for(it=fChipData.begin(); it != fChipData.end(); it++) |
---|
375 | delete it->second; |
---|
376 | |
---|
377 | fChipData.clear(); |
---|
378 | |
---|
379 | map<Int_t, vector<MacroCellHit*>* >::const_iterator itMC; |
---|
380 | for(itMC=fData.begin(); itMC != fData.end(); itMC++) { |
---|
381 | vector<MacroCellHit*>* hits = itMC->second; |
---|
382 | vector<MacroCellHit*>::const_iterator itMCH; |
---|
383 | if ( hits ) { |
---|
384 | for(itMCH=hits->begin(); itMCH != hits->end(); itMCH++); |
---|
385 | delete *itMCH; |
---|
386 | delete hits; |
---|
387 | } |
---|
388 | } |
---|
389 | fData.clear(); |
---|
390 | |
---|
391 | return kTRUE; |
---|
392 | } |
---|