1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
21 Author: R. GUERNANE LPSC Grenoble CNRS/IN2P3
25 #include "AliEMCALTriggerTRU.h"
26 #include "AliEMCALTriggerPatch.h"
27 #include "AliEMCALTriggerTRUDCSConfig.h"
30 #include <TClonesArray.h>
32 #include <Riostream.h>
36 const Int_t kTimeBins = 16; // number of sampling bins of the FastOR signal
37 const Int_t kTimeWindowSize = 4; //
43 ClassImp(AliEMCALTriggerTRU)
46 AliEMCALTriggerTRU::AliEMCALTriggerTRU() : AliEMCALTriggerBoard(),
52 for (Int_t i=0;i<96;i++) for (Int_t j=0;j<256;j++) fADC[i][j] = 0;
56 AliEMCALTriggerTRU::AliEMCALTriggerTRU(AliEMCALTriggerTRUDCSConfig* dcsConf, const TVector2& rSize, Int_t mapType) :
57 AliEMCALTriggerBoard(rSize),
63 for (Int_t i=0;i<96;i++) for (Int_t j=0;j<256;j++) fADC[i][j] = 0;
67 if (dcsConf->GetL0SEL() & 0x0001) // 4-by-4
70 SetSubRegionSize( size );
78 SetSubRegionSize( size );
84 for (Int_t ietam=0;ietam<24;ietam++)
86 for (Int_t iphim=0;iphim<4;iphim++)
88 // idx: 0..95 since iphim: 0..11 ietam: 0..23
89 Int_t idx = ( !mapType ) ? ( 3 - iphim ) + ietam * 4 : iphim + (23 - ietam) * 4;
91 // Build a matrix used to get TRU digit id (ADC channel) from (eta,phi)|SM
92 fMap[ietam][iphim] = idx; // [0..11][0..3] namely [eta][phi] in SM
98 AliEMCALTriggerTRU::~AliEMCALTriggerTRU()
104 void AliEMCALTriggerTRU::ShowFastOR(Int_t iTimeWindow, Int_t iChannel)
108 Int_t iChanF, iChanL;
110 if (iChannel != -1) iChanF = iChanL = iChannel;
117 for (Int_t i=iChanF;i<iChanL+1;i++)
119 printf("\tChannel: %2d - ",i);
120 for (Int_t j=0;j<60;j++)
122 if (j == iTimeWindow)
123 printf(" | %4d",fADC[i][j]);
124 else if (j == iTimeWindow+kTimeWindowSize-1)
125 printf(" %4d |",fADC[i][j]);
127 printf(" %4d",fADC[i][j]);
135 Int_t AliEMCALTriggerTRU::L0()
137 // L0 algo depending on TRU fw version
139 const Int_t xsize = Int_t(fRegionSize->X());
140 const Int_t ysize = Int_t(fRegionSize->Y());
143 for (Int_t j = 0; j < xsize; j++) {
144 for (Int_t k = 0; k < ysize; k++) {
145 for (Int_t l = 0; l < kTimeBins; l++) {
146 asum += fADC[fMap[j][k]][l];
151 // TRU has no signal, return!
153 AliDebug(999,"=== TRU has no signal ===");
157 AliDebug(999,Form("=== TRU PF: %x",fDCSConfig->GetSELPF()));
159 UInt_t ma = fDCSConfig->GetSELPF() & 0xffff;
162 // for (int i = 0; i < 7; i++) {
163 // UInt_t bit = ma & (1 << i);
169 ma = (ma >> 8) & 0x7f;
171 AliDebug(999,Form("=== TRU fw version %x ===",fDCSConfig->GetFw()));
173 if (fDCSConfig->IsA()->GetClassVersion() >= 3) {
174 if (fDCSConfig->GetFw() < 0x4d) {
184 Int_t AliEMCALTriggerTRU::L0v0(int mask, int pattern)
186 // L0 issuing condition is: (2x2 PF) AND (4x4 > thres)
188 AliDebug(999,"=== Running TRU L0 algorithm version 0 ===");
190 const Int_t xsize = Int_t(fRegionSize->X());
191 const Int_t ysize = Int_t(fRegionSize->Y());
193 Int_t **othr = new Int_t*[xsize];
194 Int_t **patt = new Int_t*[xsize];
195 Int_t **buff = new Int_t*[xsize];
197 for (Int_t x = 0; x < xsize; x++) {
198 othr[x] = new Int_t[ysize];
199 patt[x] = new Int_t[ysize];
200 buff[x] = new Int_t[ysize];
203 for (Int_t i = 0; i < xsize; i++) {
204 for (Int_t j = 0; j < ysize; j++) {
211 // Time sliding window algorithm
212 for (int i = 0; i <= (kTimeBins - kTimeWindowSize); i++)
214 AliDebug(999,Form("----------- Time window: %d\n",i));
216 if (AliDebugLevel()) ShowFastOR(i, -1);
218 for (int j = 0; j < xsize; j++) {
219 for (int k = 0; k < ysize; k++) {
222 // !(j % int(fSubRegionSize->X()))
224 // !(k % int(fSubRegionSize->Y()))
226 // (j + int(fPatchSize->X() * fSubRegionSize->X()) <= xsize)
228 // (k + int(fPatchSize->Y() * fSubRegionSize->Y()) <= ysize)
233 // for (int l = 0; l < int(fPatchSize->X() * fSubRegionSize->X()); l++)
234 // for (int m = 0; m < int(fPatchSize->Y() * fSubRegionSize->Y()); m++) sum += fRegion[j + l][k + m];
236 // if (sum > int(fDCSConfig->GetGTHRL0())) {
237 // AliDebug(999,Form("----------- Patch (%2d,%2d) is over threshold\n", j, k));
242 buff[j][k] = fRegion[j][k];
245 for (Int_t l = i; l < i + kTimeWindowSize; l++) fRegion[j][k] += fADC[fMap[j][k]][l];
247 if (fRegion[j][k] > buff[j][k]) {
251 if (patt[j][k]) AliDebug(999,Form("----------- (%2d,%2d) New: %d Old: %d patt: %x / pattern: %x / mask: %x", j, k, fRegion[j][k], buff[j][k], patt[j][k], pattern, mask));
255 for (int j = 0; j <= int(fRegionSize->X() - fPatchSize->X() * fSubRegionSize->X()); j += int(fSubRegionSize->X())) {
256 for (int k = 0; k <= int(fRegionSize->Y() - fPatchSize->Y() * fSubRegionSize->Y()); k += int(fSubRegionSize->Y())) {
258 // if (!othr[j][k]) continue;
259 int sizeX = int(fPatchSize->X() * fSubRegionSize->X());
260 int sizeY = int(fPatchSize->Y() * fSubRegionSize->Y());
265 for (int l = 0; l < sizeX; l++) {
266 for (int m = 0; m < sizeY; m++) {
267 sum += fRegion[j + l][k + m];
269 if ((patt[j + l][k + m] & mask) == pattern) foundPeak++;
273 if (sum > int(fDCSConfig->GetGTHRL0())) othr[j][k] = sum;
275 if (foundPeak && othr[j][k]) {
277 new((*fPatches)[fPatches->GetEntriesFast()]) AliEMCALTriggerPatch(j, k, othr[j][k], i);
279 AliEMCALTriggerPatch* p = (AliEMCALTriggerPatch*)fPatches->At(fPatches->GetEntriesFast() - 1);
281 if (AliDebugLevel()) p->Print("");
283 const Int_t psize = sizeX * sizeY; // Number of FastOR in the patch
285 Int_t* idx = new Int_t[psize];
287 for (Int_t l = 0; l < sizeX; l++)
289 for (Int_t m = 0; m < sizeY; m++)
291 Int_t index = l * sizeY + m;
293 idx[index] = fMap[int(j * fSubRegionSize->X()) + l][int(k * fSubRegionSize->Y()) + m];
295 if ((patt[j + l][k + m] & mask) == pattern) {
296 // cout << "setting peak at " << l << " " << m << endl;
297 p->SetPeak(l, m, sizeX, sizeY);
300 if (AliDebugLevel() >= 999) ShowFastOR(i, idx[index]);
309 if (fPatches->GetEntriesFast() && !fL0Time) {
310 // Stop the algo when at least one patch is found ( thres & max )
316 for (int j = 0; j < xsize; j++)
317 for (int k = 0; k < ysize; k++) patt[j][k] <<= 1;
320 for (Int_t x = 0; x < xsize; x++) {
330 return fPatches->GetEntriesFast();
334 Int_t AliEMCALTriggerTRU::L0v1(int mask, int pattern)
336 // L0 issuing condition is: (4x4 PF) AND (4x4 > thres)
338 AliDebug(999,"=== Running TRU L0 algorithm version 1 ===");
340 const Int_t xsize = Int_t(fRegionSize->X());
341 const Int_t ysize = Int_t(fRegionSize->Y());
343 Int_t **othr = new Int_t*[xsize];
344 Int_t **buff = new Int_t*[xsize];
345 Int_t **patt = new Int_t*[xsize];
347 for (Int_t i = 0; i < xsize; i++) {
348 buff[i] = new Int_t[ysize];
349 patt[i] = new Int_t[ysize];
350 othr[i] = new Int_t[ysize];
353 for (Int_t i = 0; i < xsize; i++) for (Int_t j = 0; j < ysize; j++) {
359 // Time sliding window algorithm
360 for (Int_t i = 0; i <= (kTimeBins - kTimeWindowSize); i++) {
362 AliDebug(999,Form("----------- Time window: %d\n",i));
364 for (int j = 0; j < xsize; j++) {
365 for (int k = 0; k < ysize; k++) {
368 // !(j % int(fSubRegionSize->X()))
370 // !(k % int(fSubRegionSize->Y()))
372 // (j + int(fPatchSize->X() * fSubRegionSize->X()) <= xsize)
374 // (k + int(fPatchSize->Y() * fSubRegionSize->Y()) <= ysize)
379 // for (int l = 0; l < int(fPatchSize->X() * fSubRegionSize->X()); l++)
380 // for (int m = 0; m < int(fPatchSize->Y() * fSubRegionSize->Y()); m++) sum += fRegion[j + l][k + m];
382 // if (sum > buff[j][k]) patt[j][k] |= 0x1;
384 // AliDebug(999,Form("----------- Patch (%2d,%2d) has sum %d while its whole time pattern is %x\n", j, k, sum, patt[j][k]));
388 // if (sum > int(fDCSConfig->GetGTHRL0())) {
389 // AliDebug(999,Form("----------- Patch (%2d,%2d) is over threshold\n", j, k));
395 for (Int_t l = i; l < i + kTimeWindowSize; l++) fRegion[j][k] += fADC[fMap[j][k]][l];
399 for (int j = 0; j <= int(fRegionSize->X() - fPatchSize->X() * fSubRegionSize->X()); j += int(fSubRegionSize->X())) {
400 for (int k = 0; k <= int(fRegionSize->Y() - fPatchSize->Y() * fSubRegionSize->Y()); k += int(fSubRegionSize->Y())) {
404 for (int l = 0; l < int(fPatchSize->X() * fSubRegionSize->X()); l++)
405 for (int m = 0; m < int(fPatchSize->Y() * fSubRegionSize->Y()); m++) sum += fRegion[j + l][k + m];
407 if (sum > buff[j][k]) patt[j][k] |= 0x1;
409 if (sum > int(fDCSConfig->GetGTHRL0())) {
410 AliDebug(999,Form("----------- Patch (%2d,%2d) is over threshold\n", j, k));
415 AliDebug(999,Form("----------- Patch (%2d,%2d) has sum %d while its whole time pattern is %x\n", j, k, sum, patt[j][k]));
419 if (othr[j][k] && (patt[j][k] & mask) == pattern) {
421 new((*fPatches)[fPatches->GetEntriesFast()]) AliEMCALTriggerPatch(j, k, othr[j][k], i);
423 // AliDebug(999,Form("=== New L0 patch at (%2d,%2d) time: %2d",j, k, i));
425 int sizeX = int(fPatchSize->X() * fSubRegionSize->X());
426 int sizeY = int(fPatchSize->Y() * fSubRegionSize->Y());
428 for (int xx = 0; xx < sizeX; xx++) {
429 for (int yy = 0; yy < sizeY; yy++) {
430 ((AliEMCALTriggerPatch*)fPatches->At(fPatches->GetEntriesFast() - 1))->SetPeak(xx, yy, sizeX, sizeY);
434 AliEMCALTriggerPatch* p = (AliEMCALTriggerPatch*)fPatches->At(fPatches->GetEntriesFast() - 1);
436 if (AliDebugLevel()) p->Print("");
441 if (fPatches->GetEntriesFast() && !fL0Time) {
447 for (int j = 0; j < xsize; j++)
448 for (int k = 0; k < ysize; k++) patt[j][k] <<= 1;
451 for (Int_t x = 0; x < xsize; x++) {
461 return fPatches->GetEntriesFast();
465 void AliEMCALTriggerTRU::SetADC( Int_t channel, Int_t bin, Int_t sig )
468 if (channel > 95 || bin > 255) {
469 AliError("TRU has 96 ADC channels and 256 bins only!");
472 if (((fDCSConfig->GetMaskReg(int(channel / 16)) >> (channel % 16)) & 0x1) == 0) fADC[channel][bin] = sig;
477 void AliEMCALTriggerTRU::GetL0Region(const int time, Int_t arr[][4])
479 Int_t r0 = time - fDCSConfig->GetRLBKSTU();
483 AliError(Form("TRU buffer not accessible! time: %d rollback: %d", time, fDCSConfig->GetRLBKSTU()));
487 for (Int_t i = 0; i < fRegionSize->X(); i++)
489 for (Int_t j = 0; j < fRegionSize->Y(); j++)
491 for (Int_t k = r0; k < r0 + kTimeWindowSize; k++)
493 arr[i][j] += fADC[fMap[i][j]][k];
500 void AliEMCALTriggerTRU::SaveRegionADC(Int_t iTRU, Int_t iEvent)
504 gSystem->Exec(Form("mkdir -p Event%d",iEvent));
506 ofstream outfile(Form("Event%d/data_TRU%d.txt",iEvent,iTRU),ios_base::trunc);
508 for (Int_t i=0;i<96;i++)
510 Int_t ietam = 23 - i/4;
512 Int_t iphim = 3 - i%4;
514 outfile << fRegion[ietam][iphim] << endl;
521 void AliEMCALTriggerTRU::Reset()
529 for (Int_t i=0;i<96;i++) for (Int_t j=0;j<256;j++) fADC[i][j] = 0;