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; //
38 const Int_t kNup = 2; //
39 const Int_t kNdown = 1; //
42 ClassImp(AliEMCALTriggerTRU)
45 AliEMCALTriggerTRU::AliEMCALTriggerTRU() : AliEMCALTriggerBoard()
49 for (Int_t i=0;i<96;i++) for (Int_t j=0;j<256;j++) fADC[i][j] = 0;
53 AliEMCALTriggerTRU::AliEMCALTriggerTRU(AliEMCALTriggerTRUDCSConfig* dcsConf, const TVector2& rSize, Int_t mapType) :
54 AliEMCALTriggerBoard(rSize)
58 for (Int_t i=0;i<96;i++) for (Int_t j=0;j<256;j++) fADC[i][j] = 0;
60 // FIXME: use of class AliEMCALTriggerParam to get size
64 SetSubRegionSize( size ); // 1 by 1 FOR
67 SetPatchSize( size ); // 2 by 2 subregions
69 for (Int_t ietam=0;ietam<24;ietam++)
71 for (Int_t iphim=0;iphim<4;iphim++)
73 // idx: 0..95 since iphim: 0..11 ietam: 0..23
74 Int_t idx = ( !mapType ) ? ( 3 - iphim ) + ietam * 4 : iphim + (23 - ietam) * 4;
76 // Build a matrix used to get TRU digit id (ADC channel) from (eta,phi)|SM
77 fMap[ietam][iphim] = idx; // [0..11][0..3] namely [eta][phi] in SM
83 AliEMCALTriggerTRU::~AliEMCALTriggerTRU()
85 // delete TRU digits only used as transient containers
86 // to compute FastOR from energy deposit
91 void AliEMCALTriggerTRU::ShowFastOR(Int_t iTimeWindow, Int_t iChannel)
96 if (iChannel != -1) iChanF = iChanL = iChannel;
103 for (Int_t i=iChanF;i<iChanL+1;i++)
105 printf("\tChannel: %2d - ",i);
106 for (Int_t j=0;j<60;j++)
108 if (j == iTimeWindow)
109 printf(" | %4d",fADC[i][j]);
110 else if (j == iTimeWindow+kTimeWindowSize-1)
111 printf(" %4d |",fADC[i][j]);
113 printf(" %4d",fADC[i][j]);
121 Int_t AliEMCALTriggerTRU::L0()
123 // Mimick the TRU L0 'virtual' since not yet released algo
125 // L0 issuing condition is: (2 up & 1 down) AND (time sum > thres)
126 // fill a matrix to support sliding window
127 // compute the time sum for all the FastOR of a given TRU
128 // and then move the space window
130 AliDebug(1,"=== Running TRU L0 algorithm ===");
131 const Int_t xsize = Int_t(fRegionSize->X());
132 Int_t buffer[xsize][xsize][kNup+kNdown];
134 for (Int_t i=0; i<fRegionSize->X(); i++) for (Int_t j=0; j<fRegionSize->Y(); j++)
135 for (Int_t k=0; k<kNup+kNdown; k++) buffer[i][j][k] = 0;
137 // Time sliding window algorithm
138 for (Int_t i=0; i<=(kTimeBins-kTimeWindowSize); i++)
140 AliDebug(1,Form("----------- Time window: %d\n",i));
142 for (Int_t j=0; j<fRegionSize->X(); j++)
144 for (Int_t k=0; k<fRegionSize->Y(); k++)
146 for (Int_t l=i; l<i+kTimeWindowSize; l++)
148 // printf("fRegion[%2d][%2d]: %d += fADC[%2d][%2d]: %d\n",j,k,fRegion[j][k],fMap[j][k],l,fADC[fMap[j][k]][l]);
150 fRegion[j][k] += fADC[fMap[j][k]][l];
153 buffer[j][k][i%(kNup + kNdown)] = fRegion[j][k];
155 if ( i > kNup + kNdown - 1 )
157 for (Int_t v = 0; v < kNup + kNdown - 1; v++) buffer[j][k][v] = buffer[j][k][v+1];
159 buffer[j][k][kNup + kNdown - 1] = fRegion[j][k];
163 buffer[j][k][i] = fRegion[j][k];
167 for (Int_t v = 0; v<kNup + kNdown; v++)
168 printf("buffer[%2d][%2d][%2d]: %d\n",j,k,v,buffer[j][k][v]);
171 // if (kTimeWindowSize > 4) fRegion[j][k] = fRegion[j][k] >> 1; // truncate time sum to fit 14b
175 // Don't start to evaluate space sum if a peak can't be findable
176 if (i < kNup + kNdown - 1)
182 Int_t peaks[xsize][xsize];
184 for (Int_t j=0; j<fRegionSize->X(); j++) for (Int_t k=0; k<fRegionSize->Y(); k++) peaks[j][k] = 0;
188 for (Int_t j=0; j<fRegionSize->X(); j++)
190 for (Int_t k=0; k<fRegionSize->Y(); k++)
196 for (Int_t l= 1;l<kNup ;l++) foundU = ( buffer[j][k][l]> buffer[j][k][l-1] && buffer[j][k][l-1] ) ? 1 : 0;
198 for (Int_t l=kNup;l<kNup+kNdown;l++) foundD = ( buffer[j][k][l]<=buffer[j][k][l-1] && buffer[j][k][l ] ) ? 1 : 0;
200 if ( foundU && foundD )
209 for (Int_t j=0; j<fRegionSize->X(); j++)
211 for (Int_t k=0; k<fRegionSize->Y(); k++)
213 printf("peaks[%2d][%2d]: %d\n",j,k,peaks[j][k]);
224 // FIXME: for now consider just one threshold for all patches, should consider one per patch?
225 // ANSWE: both solutions will be implemented in the TRU
226 // return the list of patches above threshold
227 // Theshold checked out from OCDB
229 SlidingWindow( kGamma, fDCSConfig->GetGTHRL0() );
231 // for(Int_t j=0; j<fRegionSize->X(); j++)
232 // for (Int_t k=0; k<fRegionSize->Y(); k++) fRegion[j][k] = fRegion[j][k]>>2; // go to 12b before shipping to STU
236 for (Int_t j=0; j<fPatches->GetEntriesFast(); j++)
238 AliEMCALTriggerPatch* p = (AliEMCALTriggerPatch*)fPatches->At( j );
240 if ( AliDebugLevel() ) p->Print("");
242 TVector2 v; p->Position(v);
244 Int_t sizeX = (Int_t)(fPatchSize->X() * fSubRegionSize->X());
246 Int_t sizeY = (Int_t)(fPatchSize->Y() * fSubRegionSize->Y());
248 const Int_t psize = sizeX * sizeY; // Number of FastOR in the patch
250 Int_t* idx = new Int_t[psize];
252 for (Int_t xx=0;xx<sizeX;xx++)
254 for (Int_t yy=0;yy<sizeY;yy++)
256 Int_t index = xx*sizeY+yy;
258 idx[index] = fMap[int(v.X()*fSubRegionSize->X())+xx][int(v.Y()*fSubRegionSize->Y())+yy]; // Get current patch FastOR ADC channels
260 if (peaks[int(v.X()*fSubRegionSize->X())+xx][int(v.Y()*fSubRegionSize->Y())+yy]) nP++;
262 if ( AliDebugLevel() ) ShowFastOR(i,idx[index]);
268 // cout << "break patch loop" << endl;
277 // cout << "break time loop" << endl;
278 break; // Stop the algo when at least one patch is found ( thres & max )
281 ZeroRegion(); // Clear fRegion for this time window before computing the next one
284 // cout << "Nof patches: " << fPatches->GetEntriesFast() << endl;
286 return fPatches->GetEntriesFast();
290 void AliEMCALTriggerTRU::SetADC( Int_t channel, Int_t bin, Int_t sig )
293 if (channel>95) AliError("TRU has 96 ADC channels only!");
294 fADC[channel][bin] = sig;
298 void AliEMCALTriggerTRU::SaveRegionADC(Int_t iTRU, Int_t iEvent)
302 gSystem->Exec(Form("mkdir -p Event%d",iEvent));
304 ofstream outfile(Form("Event%d/data_TRU%d.txt",iEvent,iTRU),ios_base::trunc);
306 for (Int_t i=0;i<96;i++)
308 Int_t ietam = 23 - i/4;
310 Int_t iphim = 3 - i%4;
312 outfile << fRegion[ietam][iphim] << endl;
319 void AliEMCALTriggerTRU::Reset()
326 for (Int_t i=0;i<96;i++) for (Int_t j=0;j<256;j++) fADC[i][j] = 0;