]>
Commit | Line | Data |
---|---|---|
916f1e76 | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
7 | * Permission to use, copy, modify and distribute this software and its * | |
8 | * documentation strictly for non-commercial purposes is hereby granted * | |
9 | * without fee, provided that the above copyright notice appears in all * | |
10 | * copies and that both the copyright notice and this permission notice * | |
11 | * appear in the supporting documentation. The authors make no claims * | |
12 | * about the suitability of this software for any purpose. It is * | |
13 | * provided "as is" without express or implied warranty. * | |
14 | **************************************************************************/ | |
15 | ||
16 | /* | |
17 | ||
18 | ||
19 | ||
20 | ||
21 | Author: R. GUERNANE LPSC Grenoble CNRS/IN2P3 | |
22 | */ | |
23 | ||
24 | ||
25 | #include "AliEMCALTriggerTRU.h" | |
26 | #include "AliEMCALTriggerPatch.h" | |
27 | #include "AliEMCALDigit.h" | |
28 | #include "AliEMCALTriggerSTU.h" | |
29 | #include "AliEMCALCalibData.h" | |
30 | #include "AliLog.h" | |
31 | ||
32 | #include <TF1.h> | |
33 | #include <TMath.h> | |
34 | #include <TClonesArray.h> | |
35 | #include <TSystem.h> | |
36 | #include <Riostream.h> | |
37 | ||
38 | namespace | |
39 | { | |
40 | const Int_t kTimeBins = 64; // number of sampling bins of the FastOR signal | |
41 | const Int_t kTimeWindowSize = 4; // | |
42 | const Int_t kNup = 2; // | |
43 | const Int_t kNdown = 1; // | |
44 | } | |
45 | ||
46 | ClassImp(AliEMCALTriggerTRU) | |
47 | ||
48 | //________________ | |
49 | AliEMCALTriggerTRU::AliEMCALTriggerTRU() : AliEMCALTriggerBoard()//, | |
50 | //fDigits( 0x0 ) | |
51 | { | |
52 | // | |
53 | for (Int_t i=0;i<96;i++) for (Int_t j=0;j<256;j++) fADC[i][j] = 0; | |
54 | } | |
55 | ||
56 | //________________ | |
57 | AliEMCALTriggerTRU::AliEMCALTriggerTRU(AliEMCALCalibData *calibData, const TVector2& rSize, Int_t mapType) : | |
58 | AliEMCALTriggerBoard(calibData, rSize) | |
59 | { | |
60 | // | |
61 | for (Int_t i=0;i<96;i++) for (Int_t j=0;j<256;j++) fADC[i][j] = 0; | |
62 | ||
63 | // FIXME: use of class AliEMCALTriggerParam to get size | |
64 | TVector2 size; | |
65 | ||
66 | size.Set( 1. , 1. ); | |
67 | SetSubRegionSize( size ); // 1 by 1 FOR | |
68 | ||
69 | size.Set( 2. , 2. ); | |
70 | SetPatchSize( size ); // 2 by 2 subregions | |
71 | ||
72 | for (Int_t ietam=0;ietam<24;ietam++) | |
73 | { | |
74 | for (Int_t iphim=0;iphim<4;iphim++) | |
75 | { | |
76 | // idx: 0..95 since iphim: 0..11 ietam: 0..23 | |
77 | Int_t idx = ( !mapType ) ? ( 3 - iphim ) + ietam * 4 : iphim + (23 - ietam) * 4; | |
78 | ||
79 | // Build a matrix used to get TRU digit id (ADC channel) from (eta,phi)|SM | |
80 | fMap[ietam][iphim] = idx; // [0..11][0..3] namely [eta][phi] in SM | |
81 | } | |
82 | } | |
83 | } | |
84 | ||
85 | //________________ | |
86 | AliEMCALTriggerTRU::~AliEMCALTriggerTRU() | |
87 | { | |
88 | // delete TRU digits only used as transient containers | |
89 | // to compute FastOR from energy deposit | |
90 | ||
91 | } | |
92 | ||
93 | //________________ | |
94 | void AliEMCALTriggerTRU::Peaks(Int_t arr[96][2]) | |
95 | { | |
96 | // Return max time bin & max value for all channels | |
97 | for (Int_t i=0;i<96;i++) | |
98 | { | |
99 | arr[i][0] = arr[i][1] = 0; | |
100 | ||
101 | Int_t max = 0, pos = 0; | |
102 | for (Int_t j=0;j<256;j++) | |
103 | { | |
104 | if (fADC[i][j]>max) | |
105 | { | |
106 | max = fADC[i][j]; | |
107 | pos = j; | |
108 | } | |
109 | } | |
110 | ||
111 | arr[i][0] = max; | |
112 | arr[i][1] = pos; | |
113 | } | |
114 | } | |
115 | ||
116 | //________________ | |
117 | void AliEMCALTriggerTRU::ShowFastOR(Int_t iTimeWindow, Int_t iChannel) | |
118 | { | |
119 | // | |
120 | Int_t iChanF, iChanL; | |
121 | ||
122 | if (iChannel != -1) iChanF = iChanL = iChannel; | |
123 | else | |
124 | { | |
125 | iChanF = 0; | |
126 | iChanL = 96; | |
127 | } | |
128 | ||
129 | for (Int_t i=iChanF;i<iChanL+1;i++) | |
130 | { | |
131 | printf("\tChannel: %2d - ",i); | |
132 | for (Int_t j=0;j<60;j++) | |
133 | { | |
134 | if (j == iTimeWindow) | |
135 | printf(" | %4d",fADC[i][j]); | |
136 | else if (j == iTimeWindow+kTimeWindowSize-1) | |
137 | printf(" %4d |",fADC[i][j]); | |
138 | else | |
139 | printf(" %4d",fADC[i][j]); | |
140 | } | |
141 | ||
142 | printf("\n"); | |
143 | } | |
144 | } | |
145 | ||
146 | //________________ | |
147 | Int_t AliEMCALTriggerTRU::L0v0() | |
148 | { | |
149 | // Mimick the TRU L0 'virtual' since not yet released algo | |
150 | ||
151 | // L0 issuing condition is: (2 up & 1 down) AND (time sum > thres) | |
152 | // fill a matrix to support sliding window | |
153 | // compute the time sum for all the FastOR of a given TRU | |
154 | // and then move the space window | |
155 | ||
156 | Int_t sum[96][3] ;//= { 0 }; | |
157 | for(Int_t i = 0; i < 96 ; i++) | |
158 | for(Int_t j = 0; j < 3 ; j++) sum[i][j] = 0; | |
159 | ||
160 | // Sliding window algorithm | |
161 | for (Int_t i=0; i<=(kTimeBins-kTimeWindowSize); i++) | |
162 | { | |
163 | for(Int_t j=0; j<fRegionSize->X(); j++) | |
164 | { | |
165 | for (Int_t k=0; k<fRegionSize->Y(); k++) | |
166 | { | |
167 | for (Int_t l=i; l<i+kTimeWindowSize; l++) | |
168 | { | |
169 | // [eta][phi][time] | |
170 | fRegion[j][k] += fADC[fMap[j][k]][l]; | |
171 | } | |
172 | ||
173 | // fRegion[j][k] = fRegion[j][k]>>2; // truncate time sum | |
174 | } | |
175 | } | |
176 | ||
177 | // Threshold | |
178 | // FIXME: for now consider just one threshold for all patches, should consider one per patch? | |
179 | // return the list of patches above threshold | |
180 | // Should probably be checked out from OCDB | |
181 | ||
182 | Int_t vL0Threshold = 0; | |
183 | ||
184 | SlidingWindow( kGamma, vL0Threshold ); | |
185 | ||
186 | Int_t nP = 0; | |
187 | ||
188 | for (Int_t j=0; j<fPatches->GetEntriesFast(); j++) | |
189 | { | |
190 | AliEMCALTriggerPatch *p = (AliEMCALTriggerPatch*)fPatches->At( j ); | |
191 | ||
192 | TVector2 v; | |
193 | p->Position(v); | |
194 | ||
195 | Int_t idx = fMap[int(v.X())][int(v.Y())]; | |
196 | ||
197 | if ( i>2 ) | |
198 | { | |
199 | // Now check the '2 up/1 down' on each patch | |
200 | if ( sum[idx][1]>sum[idx][0] && sum[idx][2]<=sum[idx][1] ) nP++; | |
201 | ||
202 | sum[idx][0] = sum[idx][1]; | |
203 | sum[idx][1] = sum[idx][2]; | |
204 | sum[idx][2] = p->Sum(); | |
205 | } | |
206 | else | |
207 | { | |
208 | sum[idx][i] = p->Sum(); | |
209 | } | |
210 | } | |
211 | ||
212 | if ( !nP ) | |
213 | fPatches->Delete(); | |
214 | else | |
215 | break; // Stop the algo when at least one patch is found ( thres & max ) | |
216 | ||
217 | ZeroRegion(); // Clear fRegion for this time window before computing the next one | |
218 | ||
219 | } | |
220 | ||
221 | return fPatches->GetEntriesFast(); | |
222 | } | |
223 | ||
224 | //________________ | |
225 | Int_t AliEMCALTriggerTRU::L0v1() | |
226 | { | |
227 | // Mimick the TRU L0 'virtual' since not yet released algo | |
228 | ||
229 | // L0 issuing condition is: (2 up & 1 down) AND (time sum > thres) | |
230 | // fill a matrix to support sliding window | |
231 | // compute the time sum for all the FastOR of a given TRU | |
232 | // and then move the space window | |
233 | ||
234 | AliDebug(1,"=== Running TRU L0 v1 version ==="); | |
235 | ||
236 | // Time sliding window algorithm | |
237 | for (Int_t i=0; i<=(kTimeBins-kTimeWindowSize); i++) | |
238 | { | |
239 | AliDebug(1,Form("----------- Time window: %d\n",i)); | |
240 | ||
241 | for (Int_t j=0; j<fRegionSize->X(); j++) | |
242 | { | |
243 | for (Int_t k=0; k<fRegionSize->Y(); k++) | |
244 | { | |
245 | for (Int_t l=i; l<i+kTimeWindowSize; l++) | |
246 | { | |
247 | // [eta][phi][time] | |
248 | fRegion[j][k] += fADC[fMap[j][k]][l]; | |
249 | } | |
250 | ||
251 | // if (kTimeWindowSize > 4) fRegion[j][k] = fRegion[j][k] >> 1; // truncate time sum to fit 14b | |
252 | } | |
253 | } | |
254 | ||
255 | // Threshold | |
256 | // FIXME: for now consider just one threshold for all patches, should consider one per patch? | |
257 | // ANSWE: both solutions will be implemented in the TRU | |
258 | // return the list of patches above threshold | |
259 | // Should probably be checked out from OCDB | |
260 | ||
261 | Int_t vL0Threshold = 0; | |
262 | ||
263 | SlidingWindow( kGamma, vL0Threshold ); | |
264 | ||
265 | // for(Int_t j=0; j<fRegionSize->X(); j++) | |
266 | // for (Int_t k=0; k<fRegionSize->Y(); k++) fRegion[j][k] = fRegion[j][k]>>2; // go to 12b before shipping to STU | |
267 | ||
268 | Int_t nP = 0; | |
269 | ||
270 | for (Int_t j=0; j<fPatches->GetEntriesFast(); j++) | |
271 | { | |
272 | AliEMCALTriggerPatch* p = (AliEMCALTriggerPatch*)fPatches->At( j ); | |
273 | ||
274 | if ( AliDebugLevel() ) p->Print(""); | |
275 | ||
276 | TVector2 v; | |
277 | p->Position(v); | |
278 | ||
279 | Int_t sizeX = fPatchSize->X() * fSubRegionSize->X(); | |
280 | Int_t sizeY = fPatchSize->Y() * fSubRegionSize->Y(); | |
281 | ||
282 | const Int_t psize = sizeX * sizeY; // Number of FastOR in the patch | |
283 | ||
284 | Int_t idx[psize]; | |
285 | ||
286 | Int_t aPeaks = 0; | |
287 | ||
288 | for (Int_t xx=0;xx<sizeX;xx++) | |
289 | { | |
290 | for (Int_t yy=0;yy<sizeY;yy++) | |
291 | { | |
292 | idx[xx*sizeY+yy] = fMap[int(v.X()*fSubRegionSize->X())+xx][int(v.Y()*fSubRegionSize->Y())+yy]; // Get current patch FastOR ADC channels | |
293 | ||
294 | if (fRegion[int(v.X()*fSubRegionSize->X())+xx][int(v.Y()*fSubRegionSize->Y())+yy]) aPeaks++; | |
295 | ||
296 | if ( AliDebugLevel() ) ShowFastOR(i,idx[xx*sizeY+yy]); | |
297 | } | |
298 | } | |
299 | ||
300 | Int_t nPeaks = 0; | |
301 | ||
302 | for (Int_t k=i;k<=i+kTimeWindowSize-(kNup+kNdown);k++) | |
303 | { | |
304 | // Now check the 'kNup up / kNdown down' on each FastOR of the patch | |
305 | PeakFinder( idx , psize , k , kNup , kNdown , nPeaks ); | |
306 | } | |
307 | ||
308 | if (nPeaks == aPeaks) | |
309 | { | |
310 | if ( AliDebugLevel() ) | |
311 | { | |
312 | printf("\t----- Valid patch (all FastOR have crossed a maximum)\n"); | |
313 | ||
314 | for (Int_t xx=0;xx<sizeX;xx++) for (Int_t yy=0;yy<sizeY;yy++) ShowFastOR(i,idx[xx*sizeY+yy]); | |
315 | } | |
316 | ||
317 | nP++; // all FOR in the patch must have seen a max | |
318 | } | |
319 | } | |
320 | ||
321 | if ( !nP ) | |
322 | fPatches->Delete(); | |
323 | else | |
324 | { | |
325 | AliDebug(1,Form("==========[ Found %4d valid patches out of %4d ]==========\n",nP,fPatches->GetEntriesFast())); | |
326 | break; // Stop the algo when at least one patch is found ( thres & max ) | |
327 | } | |
328 | ||
329 | ZeroRegion(); // Clear fRegion for this time window before computing the next one | |
330 | } | |
331 | ||
332 | return fPatches->GetEntriesFast(); | |
333 | } | |
334 | ||
335 | ||
336 | //________________ | |
337 | Int_t AliEMCALTriggerTRU::L0v2() | |
338 | { | |
339 | // Activity trigger | |
340 | ||
341 | // Sliding window algorithm | |
342 | ||
343 | for(Int_t j=0; j<fRegionSize->X(); j++) | |
344 | { | |
345 | for (Int_t k=0; k<fRegionSize->Y(); k++) | |
346 | { | |
347 | Int_t max = 0; | |
348 | for (Int_t l=0; l<kTimeBins; l++) | |
349 | { | |
350 | if (fADC[fMap[j][k]][l] > max) max = fADC[fMap[j][k]][l]; | |
351 | } | |
352 | ||
353 | if (max>4) fRegion[j][k] = max; | |
354 | } | |
355 | } | |
356 | ||
357 | Int_t vL0Threshold = 0; | |
358 | ||
359 | SlidingWindow( kGamma, vL0Threshold ); | |
360 | ||
361 | return fPatches->GetEntriesFast(); | |
362 | } | |
363 | ||
364 | ||
365 | //________________ | |
366 | void AliEMCALTriggerTRU::SetADC( Int_t channel, Int_t bin, Int_t sig ) | |
367 | { | |
368 | // | |
369 | if (channel>95) AliError("TRU has 96 ADC channels only!"); | |
370 | fADC[channel][bin] = sig; | |
371 | } | |
372 | ||
373 | //________________ | |
374 | void AliEMCALTriggerTRU::PeakFinder( const Int_t idx[], Int_t nfastor, Int_t start, Int_t nup, Int_t ndown, Int_t& nPeaks ) | |
375 | { | |
376 | // | |
377 | for (Int_t i=0;i<nfastor;i++) | |
378 | { | |
379 | Int_t foundU = 0; | |
380 | Int_t foundD = 0; | |
381 | ||
382 | for (Int_t j=start+ 1;j<start+nup ;j++) foundU = ( fADC[idx[i]][j]> fADC[idx[i]][j-1] && fADC[idx[i]][j-1] ) ? 1 : 0; | |
383 | for (Int_t j=start+nup;j<start+nup+ndown;j++) foundD = ( fADC[idx[i]][j]<=fADC[idx[i]][j-1] && fADC[idx[i]][j ] ) ? 1 : 0; | |
384 | ||
385 | if ( foundU && foundD ) nPeaks++; | |
386 | } | |
387 | } | |
388 | ||
389 | //________________ | |
390 | void AliEMCALTriggerTRU::SaveRegionADC(Int_t iTRU, Int_t iEvent) | |
391 | { | |
392 | // O for STU Hw | |
393 | // | |
394 | gSystem->Exec(Form("mkdir -p Event%d",iEvent)); | |
395 | ||
396 | ofstream outfile(Form("Event%d/data_TRU%d.txt",iEvent,iTRU),ios_base::trunc); | |
397 | ||
398 | for (Int_t i=0;i<96;i++) | |
399 | { | |
400 | Int_t ietam = 23 - i/4; | |
401 | ||
402 | Int_t iphim = 3 - i%4; | |
403 | ||
404 | outfile << fRegion[ietam][iphim] << endl; | |
405 | } | |
406 | ||
407 | outfile.close(); | |
408 | } | |
409 | ||
410 | /* | |
411 | //________________ | |
412 | void AliEMCALTriggerTRU::Scan() | |
413 | { | |
414 | // | |
415 | for (Int_t i=0;i<96;i++) | |
416 | { | |
417 | Int_t ietam = 23 - i/4; | |
418 | ||
419 | Int_t iphim = 3 - i%4; | |
420 | ||
421 | printf("ADC: %2d fRegion[%2d][%2d]: %4d\n",i,ietam,iphim,fRegion[ietam][iphim]); | |
422 | } | |
423 | } | |
424 | */ | |
425 | //________________ | |
426 | void AliEMCALTriggerTRU::Reset() | |
427 | { | |
428 | // | |
429 | fPatches->Delete(); | |
430 | ||
431 | ZeroRegion(); | |
432 | ||
433 | for (Int_t i=0;i<96;i++) for (Int_t j=0;j<256;j++) fADC[i][j] = 0; | |
434 | } | |
435 |