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 **************************************************************************/
19 EMCal trigger electronics manager L0/L1
20 can handle both simulated digits and raw data
21 Author: R. GUERNANE LPSC Grenoble CNRS/IN2P3
24 #include "AliEMCALTriggerElectronics.h"
25 #include "AliEMCALTriggerTRU.h"
26 #include "AliEMCALTriggerSTU.h"
27 #include "AliEMCALGeometry.h"
28 #include "AliRunLoader.h"
31 #include "AliEMCALTriggerDCSConfig.h"
32 #include "AliEMCALTriggerData.h"
33 #include "AliEMCALDigit.h"
34 #include "AliCaloRawStreamV3.h"
35 #include "AliEMCALTriggerSTURawStream.h"
36 #include "AliEMCALDigit.h"
37 #include "AliEMCALTriggerRawDigit.h"
38 #include "AliEMCALTriggerPatch.h"
39 #include "AliEMCALTriggerSTUDCSConfig.h"
45 const Int_t kNTRU = 32;
48 ClassImp(AliEMCALTriggerElectronics)
51 AliEMCALTriggerElectronics::AliEMCALTriggerElectronics(const AliEMCALTriggerDCSConfig *dcsConf) : TObject(),
52 fTRU(new TClonesArray("AliEMCALTriggerTRU",32)),
62 AliRunLoader *rl = AliRunLoader::Instance();
63 if (rl->GetAliRun() && rl->GetAliRun()->GetDetector("EMCAL")) {
64 AliEMCAL *emcal = dynamic_cast<AliEMCAL*>(rl->GetAliRun()->GetDetector("EMCAL"));
65 if (emcal) fGeometry = emcal->GetGeometry();
69 fGeometry = AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaultGeometryName());
70 AliError("Cannot access geometry, create a new default one!");
74 for (Int_t i = 0; i < kNTRU; i++) {
75 AliEMCALTriggerTRUDCSConfig *truConf = dcsConf->GetTRUDCSConfig(fGeometry->GetOnlineIndexFromTRUIndex(i));
76 if (truConf) new ((*fTRU)[i]) AliEMCALTriggerTRU(truConf, rSize, i % 2);
79 rSize.Set( 48., 64. );
82 AliEMCALTriggerSTUDCSConfig* stuConf = dcsConf->GetSTUDCSConfig();
83 fSTU = new AliEMCALTriggerSTU(stuConf, rSize);
86 for (Int_t i = 0; i < kNTRU; i++) {
87 AliEMCALTriggerTRU *iTRU = static_cast<AliEMCALTriggerTRU*>(fTRU->At(i));
99 AliEMCALTriggerElectronics::~AliEMCALTriggerElectronics()
108 void AliEMCALTriggerElectronics::Digits2Trigger(TClonesArray* digits, const Int_t V0M[], AliEMCALTriggerData* data)
112 Int_t pos, px, py, id;
114 Int_t region[48][64], posMap[48][64];
115 for (Int_t i = 0; i < 48; i++) for (Int_t j = 0; j < 64; j++)
121 for (Int_t i = 0; i < digits->GetEntriesFast(); i++)
123 AliEMCALTriggerRawDigit* digit = (AliEMCALTriggerRawDigit*)digits->At(i);
129 Bool_t isOK1 = fGeometry->GetTRUFromAbsFastORIndex(id, iTRU, iADC);
131 if (!isOK1) continue;
133 for (Int_t j = 0; j < digit->GetNSamples(); j++)
136 Bool_t isOK2 = digit->GetTimeSample(j, time, amp);
138 if (isOK1 && isOK2 && amp) {
139 AliDebug(999, Form("=== TRU# %2d ADC# %2d time# %2d signal %d ===", iTRU, iADC, time, amp));
141 AliEMCALTriggerTRU * etr = (static_cast<AliEMCALTriggerTRU*>(fTRU->At(iTRU)));
144 etr->SetADC(iADC, time, 4 * amp);
146 etr->SetADC(iADC, time, amp);
151 if (fGeometry->GetPositionInEMCALFromAbsFastORIndex(id, px, py)) posMap[px][py] = i;
156 Int_t timeL0[kNTRU] = {0}, timeL0min = 999;
158 for (Int_t i = 0; i < kNTRU; i++)
160 AliEMCALTriggerTRU *iTRU = static_cast<AliEMCALTriggerTRU*>(fTRU->At(i));
163 AliDebug(999, Form("===========< TRU %2d >============", i));
165 if (iTRU->L0()) // L0 recomputation: *ALWAYS* done from FALTRO
169 timeL0[i] = iTRU->GetL0Time();
171 if (!timeL0[i]) AliWarning(Form("TRU# %d has 0 trigger time",i));
173 if (timeL0[i] < timeL0min) timeL0min = timeL0[i];
175 data->SetL0Trigger(0, i, 1); // TRU# i has issued a L0
178 data->SetL0Trigger(0, i, 0);
181 AliDebug(999, Form("=== %2d TRU (out of %2d) has issued a L0 / Min L0 time: %d", iL0, fTRU->GetEntriesFast(), timeL0min));
183 AliEMCALTriggerRawDigit* dig = 0x0;
185 if (iL0 && (!data->GetMode() || !fSTU->GetDCSConfig()->GetRawData()))
187 // Update digits after L0 calculation
188 for (Int_t i = 0; i < kNTRU; i++)
190 AliEMCALTriggerTRU *iTRU = static_cast<AliEMCALTriggerTRU*>(fTRU->At(i));
194 for (int j = 0; j < 24; j++) for (int k = 0; k < 4; k++) reg[j][k] = 0;
196 iTRU->GetL0Region(timeL0min, reg);
198 for (int j = 0; j < iTRU->RegionSize()->X(); j++)
200 for (int k = 0; k < iTRU->RegionSize()->Y(); k++)
204 fGeometry->GetAbsFastORIndexFromPositionInTRU(i, j, k, id)
206 fGeometry->GetPositionInEMCALFromAbsFastORIndex(id, px, py))
208 pos = posMap[px][py];
213 posMap[px][py] = digits->GetEntriesFast();
215 new((*digits)[digits->GetEntriesFast()]) AliEMCALTriggerRawDigit(id, 0x0, 0);
217 dig = (AliEMCALTriggerRawDigit*)digits->At(digits->GetEntriesFast() - 1);
221 dig = (AliEMCALTriggerRawDigit*)digits->At(pos);
224 // 14b to 12b STU time sums
227 dig->SetL1TimeSum(reg[j][k]);
234 if (iL0 && !data->GetMode())
236 for (Int_t i = 0; i < kNTRU; i++)
238 AliEMCALTriggerTRU *iTRU = static_cast<AliEMCALTriggerTRU*>(fTRU->At(i));
241 AliDebug(999, Form("=== TRU# %2d found %d patches", i, (iTRU->Patches()).GetEntriesFast()));
243 TIter next(&iTRU->Patches());
244 while (AliEMCALTriggerPatch* p = (AliEMCALTriggerPatch*)next())
249 if (fGeometry->GetAbsFastORIndexFromPositionInTRU(i, px, py, id)
251 fGeometry->GetPositionInEMCALFromAbsFastORIndex(id, px, py)) p->SetPosition(px, py);
253 if (AliDebugLevel()) p->Print("");
255 Int_t peaks = p->Peaks();
257 Int_t sizeX = (Int_t) ((iTRU->PatchSize())->X() * (iTRU->SubRegionSize())->X());
258 Int_t sizeY = (Int_t) ((iTRU->PatchSize())->Y() * (iTRU->SubRegionSize())->Y());
260 for (Int_t j = 0; j < sizeX * sizeY; j++)
262 if (peaks & (1 << j))
264 pos = posMap[px + j % sizeX][py + j / sizeX];
268 posMap[px + j % sizeX][py + j / sizeX] = digits->GetEntriesFast();
270 new((*digits)[digits->GetEntriesFast()]) AliEMCALTriggerRawDigit(id, 0x0, 0);
272 dig = (AliEMCALTriggerRawDigit*)digits->At(digits->GetEntriesFast() - 1);
274 dig = (AliEMCALTriggerRawDigit*)digits->At(pos);
277 dig->SetL0Time(p->Time());
281 pos = posMap[px][py];
285 posMap[px][py] = digits->GetEntriesFast();
287 new((*digits)[digits->GetEntriesFast()]) AliEMCALTriggerRawDigit(id, 0x0, 0);
289 dig = (AliEMCALTriggerRawDigit*)digits->At(digits->GetEntriesFast() - 1);
294 dig = (AliEMCALTriggerRawDigit*)digits->At(pos);
297 dig->SetTriggerBit(kL0, 0);
302 // Prepare STU for L1 calculation
303 for (int i = 0; i < (fSTU->RegionSize())->X(); i++) {
304 for (int j = 0; j < (fSTU->RegionSize())->Y(); j++) {
310 AliEMCALTriggerRawDigit *digit = (AliEMCALTriggerRawDigit*)digits->At(pos);
312 if (digit->GetL1TimeSum() > -1) region[i][j] = digit->GetL1TimeSum();
317 AliDebug(999,"==================== STU ====================");
318 if (AliDebugLevel() >= 999) fSTU->Scan();
319 AliDebug(999,"==============================================");
321 fSTU->SetRegion(region);
325 for (int ithr = 0; ithr < 2; ithr++) {
326 AliDebug(999, Form(" THR %d / EGA %d / EJE %d", ithr, data->GetL1GammaThreshold(ithr), data->GetL1JetThreshold(ithr)));
328 fSTU->SetThreshold(kL1GammaHigh + ithr, data->GetL1GammaThreshold(ithr));
329 fSTU->SetThreshold(kL1JetHigh + ithr, data->GetL1JetThreshold( ithr));
334 for (int ithr = 0; ithr < 2; ithr++) {
336 fSTU->ComputeThFromV0(kL1GammaHigh + ithr, V0M);
337 data->SetL1GammaThreshold(ithr, fSTU->GetThreshold(kL1GammaHigh + ithr));
339 fSTU->ComputeThFromV0(kL1JetHigh + ithr, V0M);
340 data->SetL1JetThreshold(ithr, fSTU->GetThreshold(kL1JetHigh + ithr) );
342 AliDebug(999, Form("STU THR %d EGA %d EJE %d", ithr, fSTU->GetThreshold(kL1GammaHigh + ithr), fSTU->GetThreshold(kL1JetHigh + ithr)));
346 for (int ithr = 0; ithr < 2; ithr++) {
350 fSTU->L1(kL1GammaHigh + ithr);
354 nP = (fSTU->Patches()).MakeIterator();
356 AliDebug(999, Form("=== STU found %d gamma patches", (fSTU->Patches()).GetEntriesFast()));
358 while (AliEMCALTriggerPatch* p = (AliEMCALTriggerPatch*)nP->Next())
362 if (AliDebugLevel()) p->Print("");
364 if (fGeometry->GetAbsFastORIndexFromPositionInEMCAL(px, py, id))
366 if (posMap[px][py] == -1)
368 posMap[px][py] = digits->GetEntriesFast();
371 new((*digits)[digits->GetEntriesFast()]) AliEMCALTriggerRawDigit(id, 0x0, 0);
373 dig = (AliEMCALTriggerRawDigit*)digits->At(digits->GetEntriesFast() - 1);
377 dig = (AliEMCALTriggerRawDigit*)digits->At(posMap[px][py]);
380 if (AliDebugLevel()) dig->Print("");
382 dig->SetTriggerBit(kL1GammaHigh + ithr, 0);
388 fSTU->L1(kL1JetHigh + ithr);
390 nP = (fSTU->Patches()).MakeIterator();
392 AliDebug(999, Form("=== STU found %d jet patches", (fSTU->Patches()).GetEntriesFast()));
394 while (AliEMCALTriggerPatch* p = (AliEMCALTriggerPatch*)nP->Next())
398 if (AliDebugLevel()) p->Print("");
400 if (fGeometry->GetAbsFastORIndexFromPositionInEMCAL(px, py, id))
402 if (posMap[px][py] == -1)
404 posMap[px][py] = digits->GetEntriesFast();
407 new((*digits)[digits->GetEntriesFast()]) AliEMCALTriggerRawDigit(id, 0x0, 0);
409 dig = (AliEMCALTriggerRawDigit*)digits->At(digits->GetEntriesFast() - 1);
413 dig = (AliEMCALTriggerRawDigit*)digits->At(posMap[px][py]);
416 if (AliDebugLevel()) dig->Print("");
418 dig->SetTriggerBit(kL1JetHigh + ithr, 0);
423 // Now reset the electronics for a fresh start with next event
428 void AliEMCALTriggerElectronics::Reset()
433 while ( AliEMCALTriggerTRU *TRU = (AliEMCALTriggerTRU*)nextTRU() ) TRU->Reset();