]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EMCAL/AliEMCALTriggerTRU.cxx
Convertor from CATracker output to AliHLTTracksData added. It is needed by QA components.
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALTriggerTRU.cxx
CommitLineData
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
21Author: R. GUERNANE LPSC Grenoble CNRS/IN2P3
22*/
23
24
25#include "AliEMCALTriggerTRU.h"
26#include "AliEMCALTriggerPatch.h"
fff39dd1 27#include "AliEMCALTriggerTRUDCSConfig.h"
916f1e76 28#include "AliLog.h"
29
916f1e76 30#include <TClonesArray.h>
31#include <TSystem.h>
32#include <Riostream.h>
33
34namespace
35{
fff39dd1 36 const Int_t kTimeBins = 16; // number of sampling bins of the FastOR signal
916f1e76 37 const Int_t kTimeWindowSize = 4; //
38 const Int_t kNup = 2; //
39 const Int_t kNdown = 1; //
40}
41
42ClassImp(AliEMCALTriggerTRU)
43
44//________________
fff39dd1 45AliEMCALTriggerTRU::AliEMCALTriggerTRU() : AliEMCALTriggerBoard()
46,fDCSConfig(0x0)
916f1e76 47{
48 //
49 for (Int_t i=0;i<96;i++) for (Int_t j=0;j<256;j++) fADC[i][j] = 0;
50}
51
52//________________
fff39dd1 53AliEMCALTriggerTRU::AliEMCALTriggerTRU(AliEMCALTriggerTRUDCSConfig* dcsConf, const TVector2& rSize, Int_t mapType) :
54AliEMCALTriggerBoard(rSize)
55,fDCSConfig(dcsConf)
916f1e76 56{
57 //
58 for (Int_t i=0;i<96;i++) for (Int_t j=0;j<256;j++) fADC[i][j] = 0;
59
60 // FIXME: use of class AliEMCALTriggerParam to get size
61 TVector2 size;
62
63 size.Set( 1. , 1. );
64 SetSubRegionSize( size ); // 1 by 1 FOR
65
66 size.Set( 2. , 2. );
67 SetPatchSize( size ); // 2 by 2 subregions
68
69 for (Int_t ietam=0;ietam<24;ietam++)
70 {
71 for (Int_t iphim=0;iphim<4;iphim++)
72 {
73 // idx: 0..95 since iphim: 0..11 ietam: 0..23
74 Int_t idx = ( !mapType ) ? ( 3 - iphim ) + ietam * 4 : iphim + (23 - ietam) * 4;
75
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
78 }
79 }
80}
81
82//________________
83AliEMCALTriggerTRU::~AliEMCALTriggerTRU()
84{
85 // delete TRU digits only used as transient containers
86 // to compute FastOR from energy deposit
87
88}
89
916f1e76 90//________________
91void AliEMCALTriggerTRU::ShowFastOR(Int_t iTimeWindow, Int_t iChannel)
92{
93 //
94 Int_t iChanF, iChanL;
95
96 if (iChannel != -1) iChanF = iChanL = iChannel;
97 else
98 {
99 iChanF = 0;
100 iChanL = 96;
101 }
102
103 for (Int_t i=iChanF;i<iChanL+1;i++)
104 {
105 printf("\tChannel: %2d - ",i);
106 for (Int_t j=0;j<60;j++)
107 {
108 if (j == iTimeWindow)
109 printf(" | %4d",fADC[i][j]);
110 else if (j == iTimeWindow+kTimeWindowSize-1)
111 printf(" %4d |",fADC[i][j]);
112 else
113 printf(" %4d",fADC[i][j]);
114 }
115
116 printf("\n");
117 }
118}
119
120//________________
fff39dd1 121Int_t AliEMCALTriggerTRU::L0()
916f1e76 122{
123 // Mimick the TRU L0 'virtual' since not yet released algo
124
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
fff39dd1 129
130 AliDebug(1,"=== Running TRU L0 algorithm ===");
916f1e76 131
fff39dd1 132 Int_t buffer[int(fRegionSize->X())][int(fRegionSize->X())][kNup+kNdown];
916f1e76 133
fff39dd1 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;
136
137 // Time sliding window algorithm
916f1e76 138 for (Int_t i=0; i<=(kTimeBins-kTimeWindowSize); i++)
139 {
fff39dd1 140 AliDebug(1,Form("----------- Time window: %d\n",i));
141
142 for (Int_t j=0; j<fRegionSize->X(); j++)
916f1e76 143 {
144 for (Int_t k=0; k<fRegionSize->Y(); k++)
145 {
146 for (Int_t l=i; l<i+kTimeWindowSize; l++)
147 {
fff39dd1 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]);
916f1e76 149 // [eta][phi][time]
fff39dd1 150 fRegion[j][k] += fADC[fMap[j][k]][l];
916f1e76 151 }
152
fff39dd1 153 buffer[j][k][i%(kNup + kNdown)] = fRegion[j][k];
916f1e76 154
fff39dd1 155 if ( i > kNup + kNdown - 1 )
156 {
157 for (Int_t v = 0; v < kNup + kNdown - 1; v++) buffer[j][k][v] = buffer[j][k][v+1];
158
159 buffer[j][k][kNup + kNdown - 1] = fRegion[j][k];
160 }
161 else
162 {
163 buffer[j][k][i] = fRegion[j][k];
164 }
916f1e76 165
fff39dd1 166/*
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]);
169*/
916f1e76 170
fff39dd1 171// if (kTimeWindowSize > 4) fRegion[j][k] = fRegion[j][k] >> 1; // truncate time sum to fit 14b
916f1e76 172 }
173 }
174
fff39dd1 175 // Don't start to evaluate space sum if a peak can't be findable
176 if (i < kNup + kNdown - 1)
177 {
178 ZeroRegion();
179 continue;
180 }
916f1e76 181
fff39dd1 182 Int_t peaks[int(fRegionSize->X())][int(fRegionSize->X())];
916f1e76 183
fff39dd1 184 for (Int_t j=0; j<fRegionSize->X(); j++) for (Int_t k=0; k<fRegionSize->Y(); k++) peaks[j][k] = 0;
185
186 Int_t nPeaks = 0;
916f1e76 187
188 for (Int_t j=0; j<fRegionSize->X(); j++)
189 {
190 for (Int_t k=0; k<fRegionSize->Y(); k++)
191 {
fff39dd1 192 Int_t foundU = 0;
193
194 Int_t foundD = 0;
195
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;
197
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;
199
200 if ( foundU && foundD )
916f1e76 201 {
fff39dd1 202 peaks[j][k] = 1;
203 nPeaks++;
916f1e76 204 }
916f1e76 205 }
206 }
fff39dd1 207
208/*
209 for (Int_t j=0; j<fRegionSize->X(); j++)
210 {
211 for (Int_t k=0; k<fRegionSize->Y(); k++)
212 {
213 printf("peaks[%2d][%2d]: %d\n",j,k,peaks[j][k]);
214 }
215 }
216*/
217 if ( !nPeaks )
218 {
219 ZeroRegion();
220 continue;
221 }
916f1e76 222
223 // Threshold
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
fff39dd1 227 // Theshold checked out from OCDB
916f1e76 228
fff39dd1 229 SlidingWindow( kGamma, fDCSConfig->GetGTHRL0() );
916f1e76 230
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
233
234 Int_t nP = 0;
235
236 for (Int_t j=0; j<fPatches->GetEntriesFast(); j++)
237 {
238 AliEMCALTriggerPatch* p = (AliEMCALTriggerPatch*)fPatches->At( j );
239
240 if ( AliDebugLevel() ) p->Print("");
241
fff39dd1 242 TVector2 v; p->Position(v);
916f1e76 243
da509d54 244 Int_t sizeX = (Int_t)(fPatchSize->X() * fSubRegionSize->X());
fff39dd1 245
da509d54 246 Int_t sizeY = (Int_t)(fPatchSize->Y() * fSubRegionSize->Y());
916f1e76 247
248 const Int_t psize = sizeX * sizeY; // Number of FastOR in the patch
249
fff39dd1 250 Int_t* idx = new Int_t[psize];
916f1e76 251
252 for (Int_t xx=0;xx<sizeX;xx++)
253 {
254 for (Int_t yy=0;yy<sizeY;yy++)
255 {
fff39dd1 256 Int_t index = xx*sizeY+yy;
916f1e76 257
fff39dd1 258 idx[index] = fMap[int(v.X()*fSubRegionSize->X())+xx][int(v.Y()*fSubRegionSize->Y())+yy]; // Get current patch FastOR ADC channels
916f1e76 259
fff39dd1 260 if (peaks[int(v.X()*fSubRegionSize->X())+xx][int(v.Y()*fSubRegionSize->Y())+yy]) nP++;
261
262 if ( AliDebugLevel() ) ShowFastOR(i,idx[index]);
916f1e76 263 }
264 }
916f1e76 265
fff39dd1 266 if ( nP )
916f1e76 267 {
fff39dd1 268// cout << "break patch loop" << endl;
269 break;
916f1e76 270 }
271 }
272
273 if ( !nP )
274 fPatches->Delete();
275 else
276 {
fff39dd1 277// cout << "break time loop" << endl;
916f1e76 278 break; // Stop the algo when at least one patch is found ( thres & max )
279 }
fff39dd1 280
916f1e76 281 ZeroRegion(); // Clear fRegion for this time window before computing the next one
282 }
283
fff39dd1 284// cout << "Nof patches: " << fPatches->GetEntriesFast() << endl;
916f1e76 285
286 return fPatches->GetEntriesFast();
287}
288
916f1e76 289//________________
290void AliEMCALTriggerTRU::SetADC( Int_t channel, Int_t bin, Int_t sig )
291{
292 //
293 if (channel>95) AliError("TRU has 96 ADC channels only!");
294 fADC[channel][bin] = sig;
295}
296
916f1e76 297//________________
298void AliEMCALTriggerTRU::SaveRegionADC(Int_t iTRU, Int_t iEvent)
299{
300 // O for STU Hw
301 //
302 gSystem->Exec(Form("mkdir -p Event%d",iEvent));
303
304 ofstream outfile(Form("Event%d/data_TRU%d.txt",iEvent,iTRU),ios_base::trunc);
305
306 for (Int_t i=0;i<96;i++)
307 {
308 Int_t ietam = 23 - i/4;
309
310 Int_t iphim = 3 - i%4;
311
312 outfile << fRegion[ietam][iphim] << endl;
313 }
314
315 outfile.close();
316}
317
916f1e76 318//________________
319void AliEMCALTriggerTRU::Reset()
320{
321 //
322 fPatches->Delete();
323
324 ZeroRegion();
325
326 for (Int_t i=0;i<96;i++) for (Int_t j=0;j<256;j++) fADC[i][j] = 0;
327}
328