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;
62 if (dcsConf->GetL0SEL() & 0x0001) // 4-by-4
65 SetSubRegionSize( size );
73 SetSubRegionSize( size );
79 for (Int_t ietam=0;ietam<24;ietam++)
81 for (Int_t iphim=0;iphim<4;iphim++)
83 // idx: 0..95 since iphim: 0..11 ietam: 0..23
84 Int_t idx = ( !mapType ) ? ( 3 - iphim ) + ietam * 4 : iphim + (23 - ietam) * 4;
86 // Build a matrix used to get TRU digit id (ADC channel) from (eta,phi)|SM
87 fMap[ietam][iphim] = idx; // [0..11][0..3] namely [eta][phi] in SM
93 AliEMCALTriggerTRU::~AliEMCALTriggerTRU()
99 void AliEMCALTriggerTRU::ShowFastOR(Int_t iTimeWindow, Int_t iChannel)
102 Int_t iChanF, iChanL;
104 if (iChannel != -1) iChanF = iChanL = iChannel;
111 for (Int_t i=iChanF;i<iChanL+1;i++)
113 printf("\tChannel: %2d - ",i);
114 for (Int_t j=0;j<60;j++)
116 if (j == iTimeWindow)
117 printf(" | %4d",fADC[i][j]);
118 else if (j == iTimeWindow+kTimeWindowSize-1)
119 printf(" %4d |",fADC[i][j]);
121 printf(" %4d",fADC[i][j]);
129 Int_t AliEMCALTriggerTRU::L0()
131 // Mimick the TRU L0 'virtual' since not yet released algo
133 // L0 issuing condition is: (2 up & 1 down) AND (time sum > thres)
134 // fill a matrix to support sliding window
135 // compute the time sum for all the FastOR of a given TRU
136 // and then move the space window
138 AliDebug(999,"=== Running TRU L0 algorithm ===");
139 const Int_t xsize = Int_t(fRegionSize->X());
140 const Int_t ysize = Int_t(fRegionSize->Y());
141 const Int_t zsize = kNup+kNdown;
143 Int_t ***buffer = new Int_t**[xsize];
144 for (Int_t x = 0; x < xsize; x++)
146 buffer[x] = new Int_t*[ysize];
148 for (Int_t y = 0; y < ysize; y++)
150 buffer[x][y] = new Int_t[zsize];
154 for (Int_t i = 0; i < fRegionSize->X(); i++)
155 for (Int_t j = 0; j < fRegionSize->Y(); j++)
156 for (Int_t k = 0; k < kNup + kNdown; k++) buffer[i][j][k] = 0;
158 // Time sliding window algorithm
159 for (Int_t i=0; i<=(kTimeBins-kTimeWindowSize); i++)
161 AliDebug(999,Form("----------- Time window: %d\n",i));
163 for (Int_t j=0; j<fRegionSize->X(); j++)
165 for (Int_t k=0; k<fRegionSize->Y(); k++)
167 for (Int_t l=i; l<i+kTimeWindowSize; l++)
170 fRegion[j][k] += fADC[fMap[j][k]][l];
173 buffer[j][k][i%(kNup + kNdown)] = fRegion[j][k];
175 if ( i > kNup + kNdown - 1 )
177 for (Int_t v = 0; v < kNup + kNdown - 1; v++) buffer[j][k][v] = buffer[j][k][v+1];
179 buffer[j][k][kNup + kNdown - 1] = fRegion[j][k];
183 buffer[j][k][i] = fRegion[j][k];
186 // if (kTimeWindowSize > 4) fRegion[j][k] = fRegion[j][k] >> 1; // truncate time sum to fit 14b
190 // Don't start to evaluate space sum if a peak can't be findable
191 if (i < kNup + kNdown - 1)
197 Int_t **peaks = new Int_t*[xsize];
198 for (Int_t x = 0; x < xsize; x++)
200 peaks[x] = new Int_t[ysize];
203 for (Int_t j=0; j<fRegionSize->X(); j++) for (Int_t k=0; k<fRegionSize->Y(); k++) peaks[j][k] = 0;
207 for (Int_t j=0; j<fRegionSize->X(); j++)
209 for (Int_t k=0; k<fRegionSize->Y(); k++)
215 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;
217 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;
219 if ( foundU && foundD )
231 for (Int_t x = 0; x < xsize; x++)
241 // FIXME: for now consider just one threshold for all patches, should consider one per patch?
242 // ANSWE: both solutions will be implemented in the TRU
243 // return the list of patches above threshold
244 // Theshold checked out from OCDB
246 SlidingWindow(kL0, fDCSConfig->GetGTHRL0(), i);
248 // for(Int_t j=0; j<fRegionSize->X(); j++)
249 // for (Int_t k=0; k<fRegionSize->Y(); k++) fRegion[j][k] = fRegion[j][k]>>2; // go to 12b before shipping to STU
251 for (Int_t j=0; j<fPatches->GetEntriesFast(); j++)
253 AliEMCALTriggerPatch* p = (AliEMCALTriggerPatch*)fPatches->At( j );
255 if ( AliDebugLevel() ) p->Print("");
257 TVector2 v; p->Position(v);
259 Int_t sizeX = (Int_t)(fPatchSize->X() * fSubRegionSize->X());
261 Int_t sizeY = (Int_t)(fPatchSize->Y() * fSubRegionSize->Y());
263 const Int_t psize = sizeX * sizeY; // Number of FastOR in the patch
267 Int_t* idx = new Int_t[psize];
269 for (Int_t xx=0;xx<sizeX;xx++)
271 for (Int_t yy=0;yy<sizeY;yy++)
273 Int_t index = xx*sizeY+yy;
275 idx[index] = fMap[int(v.X()*fSubRegionSize->X())+xx][int(v.Y()*fSubRegionSize->Y())+yy]; // Get current patch FastOR ADC channels
277 if (peaks[int(v.X() * fSubRegionSize->X()) + xx][int(v.Y() * fSubRegionSize->Y()) + yy])
281 p->SetPeak(xx, yy, sizeX, sizeY);
284 if (AliDebugLevel() >= 999) ShowFastOR(i, idx[index]);
292 fPatches->RemoveAt( j );
293 fPatches->Compress();
298 for (Int_t x = 0; x < xsize; x++)
304 if ( !fPatches->GetEntriesFast() ) // No patch left
306 else // Stop the algo when at least one patch is found ( thres & max )
308 for (Int_t xx = 0; xx < fRegionSize->X(); xx++)
310 for (Int_t yy = 0; yy < fRegionSize->Y(); yy++)
312 // Prepare data to be sent to STU for further L1 processing
313 // Sent time sum (rollback tuning) is the one before L0 is issued (maximum time sum)
314 fRegion[xx][yy] = buffer[xx][yy][1];
323 for (Int_t x = 0; x < xsize; x++)
325 for (Int_t y = 0; y < ysize; y++)
327 delete [] buffer[x][y];
333 return fPatches->GetEntriesFast();
337 void AliEMCALTriggerTRU::SetADC( Int_t channel, Int_t bin, Int_t sig )
340 if (channel > 95 || bin > 255) {
341 AliError("TRU has 96 ADC channels and 256 bins only!");
344 fADC[channel][bin] = sig;
349 void AliEMCALTriggerTRU::SaveRegionADC(Int_t iTRU, Int_t iEvent)
353 gSystem->Exec(Form("mkdir -p Event%d",iEvent));
355 ofstream outfile(Form("Event%d/data_TRU%d.txt",iEvent,iTRU),ios_base::trunc);
357 for (Int_t i=0;i<96;i++)
359 Int_t ietam = 23 - i/4;
361 Int_t iphim = 3 - i%4;
363 outfile << fRegion[ietam][iphim] << endl;
370 void AliEMCALTriggerTRU::Reset()
377 for (Int_t i=0;i<96;i++) for (Int_t j=0;j<256;j++) fADC[i][j] = 0;