]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EMCAL/AliEMCALTriggerElectronics.cxx
- fixing use of centrality class
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALTriggerElectronics.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
19EMCal trigger electronics manager L0/L1
20can handle both simulated digits and raw data
21Author: R. GUERNANE LPSC Grenoble CNRS/IN2P3
22*/
23
24#include "AliEMCALTriggerElectronics.h"
25#include "AliEMCALTriggerTRU.h"
26#include "AliEMCALTriggerSTU.h"
27#include "AliEMCALGeometry.h"
28#include "AliRunLoader.h"
29#include "AliEMCAL.h"
30#include "AliRun.h"
fff39dd1 31#include "AliEMCALTriggerDCSConfig.h"
916f1e76 32#include "AliEMCALTriggerData.h"
33#include "AliEMCALDigit.h"
34#include "AliCaloRawStreamV3.h"
916f1e76 35#include "AliEMCALTriggerSTURawStream.h"
36#include "AliEMCALDigit.h"
de39a0ff 37#include "AliEMCALTriggerRawDigit.h"
38#include "AliEMCALTriggerPatch.h"
916f1e76 39
40#include <TVector2.h>
41#include <TClonesArray.h>
916f1e76 42
43namespace
44{
45 const Int_t kNTRU = 32;
46}
47
48ClassImp(AliEMCALTriggerElectronics)
49
50//__________________
fff39dd1 51AliEMCALTriggerElectronics::AliEMCALTriggerElectronics(const AliEMCALTriggerDCSConfig *dcsConf) : TObject(),
916f1e76 52fTRU(new TClonesArray("AliEMCALTriggerTRU",32)),
53fSTU(0x0)
54{
55 TVector2 rSize;
56
57 rSize.Set( 24., 4. );
58
59 // 32 TRUs
fff39dd1 60 for (Int_t i=0;i<kNTRU;i++)
61 {
62 AliEMCALTriggerTRUDCSConfig* truConf = dcsConf->GetTRUDCSConfig(i);
de39a0ff 63 new ((*fTRU)[i]) AliEMCALTriggerTRU(truConf, rSize, i % 2);
fff39dd1 64 }
65
916f1e76 66 rSize.Set( 48., 64. );
67
68 // 1 STU
fff39dd1 69 AliEMCALTriggerSTUDCSConfig* stuConf = dcsConf->GetSTUDCSConfig();
70 fSTU = new AliEMCALTriggerSTU(stuConf, rSize);
916f1e76 71
de39a0ff 72 TString str = "map";
73 for (Int_t i=0;i<kNTRU;i++) fSTU->Build(str,
74 i,
75 (static_cast<AliEMCALTriggerTRU*>(fTRU->At(i)))->Map(),
76 (static_cast<AliEMCALTriggerTRU*>(fTRU->At(i)))->RegionSize()
77 );
916f1e76 78}
79
80//________________
81AliEMCALTriggerElectronics::~AliEMCALTriggerElectronics()
82{
83 //
84 fTRU->Delete();
85 delete fSTU;
86}
87
88//__________________
de39a0ff 89void AliEMCALTriggerElectronics::Digits2Trigger(TClonesArray* digits, const Int_t V0M[], AliEMCALTriggerData* data)
916f1e76 90{
91 //
92 AliEMCALGeometry* geom = 0x0;
93
94 AliRunLoader *rl = AliRunLoader::Instance();
a51e676d 95 if (rl->GetAliRun() && rl->GetAliRun()->GetDetector("EMCAL")){
96 AliEMCAL* emcal = dynamic_cast<AliEMCAL*>(rl->GetAliRun()->GetDetector("EMCAL"));
97 if(emcal)geom = emcal->GetGeometry();
98 }
99
100 if(!geom) geom = AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaultGeometryName());
101
102 if(!geom) AliError("Cannot access geometry!");
916f1e76 103
de39a0ff 104 // digits->Sort();
105
106 Int_t region[48][64], posMap[48][64];
107 for (Int_t i = 0; i < 48; i++) for (Int_t j = 0; j < 64; j++)
108 {
109 region[i][j] = 0;
110 posMap[i][j] = -1;
111 }
112
113 for (Int_t i = 0; i < digits->GetEntriesFast(); i++)
916f1e76 114 {
de39a0ff 115 AliEMCALTriggerRawDigit* digit = (AliEMCALTriggerRawDigit*)digits->At(i);
116
117 Int_t id = digit->GetId();
118
119 Int_t iTRU, iADC;
120
121 Bool_t isOK1 = geom->GetTRUFromAbsFastORIndex(id, iTRU, iADC);
122
123 for (Int_t j = 0; j < digit->GetNSamples(); j++)
916f1e76 124 {
de39a0ff 125 Int_t time, amp;
126 Bool_t isOK2 = digit->GetTimeSample(j, time, amp);
916f1e76 127
de39a0ff 128 if (isOK1 && isOK2 && amp) (static_cast<AliEMCALTriggerTRU*>(fTRU->At(iTRU)))->SetADC(iADC, time, amp);
129 }
130
131 Int_t px, py;
132 if (geom->GetPositionInEMCALFromAbsFastORIndex(id, px, py))
133 {
134 posMap[px][py] = i;
916f1e76 135
de39a0ff 136 if (fSTU->GetRawData() && digit->GetL1TimeSum() >= 0)
916f1e76 137 {
de39a0ff 138 region[px][py] = digit->GetL1TimeSum();
916f1e76 139 }
140 }
141 }
916f1e76 142
de39a0ff 143 Int_t iL0 = 0;
916f1e76 144
145 for (Int_t i=0; i<kNTRU; i++)
146 {
de39a0ff 147 AliDebug(999, Form("===========< TRU %2d >============\n", i));
916f1e76 148
de39a0ff 149 AliEMCALTriggerTRU* iTRU = static_cast<AliEMCALTriggerTRU*>(fTRU->At(i));
916f1e76 150
de39a0ff 151 // L0 is always computed from F-ALTRO
152 if (iTRU->L0())
916f1e76 153 {
de39a0ff 154 iL0 += iTRU->L0();
155
ddd131cc 156 Int_t sizeX = (Int_t) ((iTRU->PatchSize())->X() * (iTRU->SubRegionSize())->X());
de39a0ff 157
ddd131cc 158 Int_t sizeY = (Int_t) ((iTRU->PatchSize())->Y() * (iTRU->SubRegionSize())->Y());
de39a0ff 159
160 // transform local to global
161 TIter Next(&iTRU->Patches());
162 while (AliEMCALTriggerPatch* p = (AliEMCALTriggerPatch*)Next())
163 {
164 Int_t px, py, id; p->Position(px, py);
165
166 if (geom->GetAbsFastORIndexFromPositionInTRU(i, px, py, id)
167 &&
168 geom->GetPositionInEMCALFromAbsFastORIndex(id, px, py)) p->SetPosition(px, py);
169
a61738e1 170 if (!data->GetMode()) // Simulation
de39a0ff 171 {
172 Int_t peaks = p->Peaks();
173
a61738e1 174 Int_t pos;
175 AliEMCALTriggerRawDigit* dig = 0x0;
176
de39a0ff 177 for (Int_t j = 0; j < sizeX * sizeY; j++)
178 {
179 if (peaks & (1 << j))
180 {
a61738e1 181 pos = posMap[px + j % sizeX][py + j / sizeX];
de39a0ff 182
183 if (pos == -1)
184 {
a61738e1 185 // Add a new digit
de39a0ff 186 new((*digits)[digits->GetEntriesFast()]) AliEMCALTriggerRawDigit(id, 0x0, 0);
187
188 dig = (AliEMCALTriggerRawDigit*)digits->At(digits->GetEntriesFast() - 1);
189 }
190 else
191 {
192 dig = (AliEMCALTriggerRawDigit*)digits->At(pos);
193 }
194
195 dig->SetL0Time(p->Time());
196 }
a61738e1 197 }
198
199 pos = posMap[px][py];
200
201 if (pos == -1)
202 {
203 // Add a new digit
204 new((*digits)[digits->GetEntriesFast()]) AliEMCALTriggerRawDigit(id, 0x0, 0);
205
206 dig = (AliEMCALTriggerRawDigit*)digits->At(digits->GetEntriesFast() - 1);
207 }
208 else
209 {
210 dig = (AliEMCALTriggerRawDigit*)digits->At(pos);
211 }
212
213 dig->SetTriggerBit(kL0,0);
de39a0ff 214 }
215 }
216
217 data->SetL0Trigger(0, i, 1);
de39a0ff 218 }
219 else
220 data->SetL0Trigger(0, i, 0);
916f1e76 221 }
222
223 // A L0 has been issued, run L1
de39a0ff 224 // Depending on raw data enabled or not in STU data: L1 computation
225 // should be done from F-ALTRO or directly on TRU time sums in STU raw data
226 if (iL0)
916f1e76 227 {
de39a0ff 228 // Use L1 threshold from raw data when reconstructing raw data
229 if (data->GetMode())
230 {
231 fSTU->SetThreshold(kL1Gamma, data->GetL1GammaThreshold());
232 fSTU->SetThreshold(kL1Jet, data->GetL1JetThreshold() );
233 }
234 else
235 {
236 fSTU->ComputeThFromV0(V0M); // C/A
237 data->SetL1GammaThreshold(fSTU->GetThreshold(kL1Gamma));
238 data->SetL1JetThreshold( fSTU->GetThreshold(kL1Jet) );
239 }
916f1e76 240
de39a0ff 241 if (fSTU->GetRawData())
242 {
243 // Compute L1 from STU raw data
244 fSTU->SetRegion(region);
245 }
246 else
247 {
248 // Build STU raw data from F-ALTRO
249 TString str = "region";
250 for (Int_t i = 0; i < kNTRU; i++) fSTU->Build(str,
251 i,
252 (static_cast<AliEMCALTriggerTRU*>(fTRU->At(i)))->Region(),
253 (static_cast<AliEMCALTriggerTRU*>(fTRU->At(i)))->RegionSize());
254 }
916f1e76 255
de39a0ff 256 fSTU->L1(kL1Gamma);
916f1e76 257
a61738e1 258 Int_t id, px, py;
259 AliEMCALTriggerRawDigit* dig = 0x0;
260
261 TIterator* nP = 0x0;
262
263 nP = (fSTU->Patches()).MakeIterator();
264
265 while (AliEMCALTriggerPatch* p = (AliEMCALTriggerPatch*)nP->Next())
266 {
267 p->Position(px, py);
268
269 if (geom->GetAbsFastORIndexFromPositionInEMCAL(px, py, id))
270 {
271 if (posMap[px][py] == -1)
272 {
273 // Add a new digit
274 new((*digits)[digits->GetEntriesFast()]) AliEMCALTriggerRawDigit(id, 0x0, 0);
275
276 dig = (AliEMCALTriggerRawDigit*)digits->At(digits->GetEntriesFast() - 1);
277 }
278 else
279 {
280 dig = (AliEMCALTriggerRawDigit*)digits->At(posMap[px][py]);
281 }
282
283 dig->SetTriggerBit(kL1Gamma,0);
284 }
285 }
916f1e76 286
287 fSTU->Reset();
288
de39a0ff 289 fSTU->L1(kL1Jet);
916f1e76 290
a61738e1 291 nP = (fSTU->Patches()).MakeIterator();
292
293 while (AliEMCALTriggerPatch* p = (AliEMCALTriggerPatch*)nP->Next())
294 {
295 p->Position(px, py);
296
297 px *= (Int_t)((fSTU->SubRegionSize())->X());
298
299 py *= (Int_t)((fSTU->SubRegionSize())->Y());
300
301 if (geom->GetAbsFastORIndexFromPositionInEMCAL(px, py, id))
302 {
303 if (posMap[px][py] == -1)
304 {
305 // Add a new digit
306 new((*digits)[digits->GetEntriesFast()]) AliEMCALTriggerRawDigit(id, 0x0, 0);
307
308 dig = (AliEMCALTriggerRawDigit*)digits->At(digits->GetEntriesFast() - 1);
309 }
310 else
311 {
312 dig = (AliEMCALTriggerRawDigit*)digits->At(posMap[px][py]);
313 }
314
315 dig->SetTriggerBit(kL1Jet,0);
316 }
317 }
de39a0ff 318
319 Int_t** reg = fSTU->Region();
320
321 if (!fSTU->GetRawData())
322 {
323 // Update digits w/ L1 time sum
324 // Done in raw digit maker when raw data enabled
325 for (Int_t i = 0; i < 48; i++)
326 {
327 for (Int_t j = 0; j < 64; j++)
328 {
329 if (reg[i][j])
330 {
de39a0ff 331 if (geom->GetAbsFastORIndexFromPositionInEMCAL(i, j, id))
332 {
de39a0ff 333 if (posMap[i][j] == -1)
334 {
335 // Add a new digit with L1 time sum
336 new((*digits)[digits->GetEntriesFast()]) AliEMCALTriggerRawDigit(id, 0x0, 0);
337
338 dig = (AliEMCALTriggerRawDigit*)digits->At(digits->GetEntriesFast() - 1);
339 }
340 else
341 {
342 dig = (AliEMCALTriggerRawDigit*)digits->At(posMap[i][j]);
343 }
344
345 dig->SetL1TimeSum(reg[i][j]);
346 }
347 }
348 }
349 }
350 }
916f1e76 351 }
352
de39a0ff 353 if (AliDebugLevel() >= 999) data->Scan();
39c05eac 354
916f1e76 355 // Now reset the electronics for a fresh start with next event
356 Reset();
357}
358
359//__________________
360void AliEMCALTriggerElectronics::Reset()
361{
362 //
363 TIter NextTRU(fTRU);
364 while ( AliEMCALTriggerTRU *TRU = (AliEMCALTriggerTRU*)NextTRU() ) TRU->Reset();
365
366 fSTU->Reset();
367}