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 = 30;
48 ClassImp(AliEMCALTriggerElectronics)
51 AliEMCALTriggerElectronics::AliEMCALTriggerElectronics(const AliEMCALTriggerDCSConfig *dcsConf) : TObject(),
52 fTRU(new TClonesArray("AliEMCALTriggerTRU",32)),
62 for (Int_t i=0;i<kNTRU;i++)
64 AliEMCALTriggerTRUDCSConfig* truConf = dcsConf->GetTRUDCSConfig(i);
65 new ((*fTRU)[i]) AliEMCALTriggerTRU(truConf, rSize, i % 2);
68 rSize.Set( 48., 64. );
71 AliEMCALTriggerSTUDCSConfig* stuConf = dcsConf->GetSTUDCSConfig();
72 fSTU = new AliEMCALTriggerSTU(stuConf, rSize);
75 for (Int_t i=0;i<kNTRU;i++) fSTU->Build(str,
77 (static_cast<AliEMCALTriggerTRU*>(fTRU->At(i)))->Map(),
78 (static_cast<AliEMCALTriggerTRU*>(fTRU->At(i)))->RegionSize()
83 AliEMCALTriggerElectronics::~AliEMCALTriggerElectronics()
92 void AliEMCALTriggerElectronics::Digits2Trigger(TClonesArray* digits, const Int_t V0M[], AliEMCALTriggerData* data)
96 AliEMCALGeometry* geom = 0x0;
98 AliRunLoader *rl = AliRunLoader::Instance();
99 if (rl->GetAliRun() && rl->GetAliRun()->GetDetector("EMCAL")){
100 AliEMCAL* emcal = dynamic_cast<AliEMCAL*>(rl->GetAliRun()->GetDetector("EMCAL"));
101 if(emcal)geom = emcal->GetGeometry();
104 if(!geom) geom = AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaultGeometryName());
106 if(!geom) AliError("Cannot access geometry!");
108 Int_t pos, px, py, id;
110 Int_t region[48][64], posMap[48][64];
111 for (Int_t i = 0; i < 48; i++) for (Int_t j = 0; j < 64; j++)
117 for (Int_t i = 0; i < digits->GetEntriesFast(); i++)
119 AliEMCALTriggerRawDigit* digit = (AliEMCALTriggerRawDigit*)digits->At(i);
125 Bool_t isOK1 = geom->GetTRUFromAbsFastORIndex(id, iTRU, iADC);
127 if ((isOK1 && iTRU >= kNTRU) || !isOK1) continue;
129 for (Int_t j = 0; j < digit->GetNSamples(); j++)
132 Bool_t isOK2 = digit->GetTimeSample(j, time, amp);
134 if (isOK1 && isOK2 && amp) {
135 AliDebug(999, Form("=== TRU# %2d ADC# %2d time# %2d signal %d ===", iTRU, iADC, time, amp));
138 (static_cast<AliEMCALTriggerTRU*>(fTRU->At(iTRU)))->SetADC(iADC, time, 4 * amp);
140 (static_cast<AliEMCALTriggerTRU*>(fTRU->At(iTRU)))->SetADC(iADC, time, amp);
144 if (geom->GetPositionInEMCALFromAbsFastORIndex(id, px, py)) posMap[px][py] = i;
149 Int_t timeL0[kNTRU] = {0}, timeL0min = 999;
151 for (Int_t i=0; i<kNTRU; i++)
153 AliDebug(999, Form("===========< TRU %2d >============", i));
155 AliEMCALTriggerTRU* iTRU = static_cast<AliEMCALTriggerTRU*>(fTRU->At(i));
157 if (iTRU->L0()) // L0 recomputation: *ALWAYS* done from FALTRO
161 timeL0[i] = iTRU->GetL0Time();
163 if (!timeL0[i]) AliWarning(Form("TRU# %d has 0 trigger time",i));
165 if (timeL0[i] < timeL0min) timeL0min = timeL0[i];
167 data->SetL0Trigger(0, i, 1); // TRU# i has issued a L0
170 data->SetL0Trigger(0, i, 0);
173 AliDebug(999, Form("=== %2d TRU (out of %2d) has issued a L0 / Min L0 time: %d", iL0, kNTRU, timeL0min));
175 AliEMCALTriggerRawDigit* dig = 0x0;
177 if (iL0 && (!data->GetMode() || !fSTU->GetDCSConfig()->GetRawData()))
179 // Update digits after L0 calculation
180 for (Int_t i = 0; i < kNTRU; i++)
182 AliEMCALTriggerTRU *iTRU = static_cast<AliEMCALTriggerTRU*>(fTRU->At(i));
185 for (int j = 0; j < 24; j++) for (int k = 0; k < 4; k++) reg[j][k] = 0;
187 iTRU->GetL0Region(timeL0min, reg);
189 for (int j = 0; j < iTRU->RegionSize()->X(); j++)
191 for (int k = 0; k < iTRU->RegionSize()->Y(); k++)
195 geom->GetAbsFastORIndexFromPositionInTRU(i, j, k, id)
197 geom->GetPositionInEMCALFromAbsFastORIndex(id, px, py))
199 pos = posMap[px][py];
204 posMap[px][py] = digits->GetEntriesFast();
206 new((*digits)[digits->GetEntriesFast()]) AliEMCALTriggerRawDigit(id, 0x0, 0);
208 dig = (AliEMCALTriggerRawDigit*)digits->At(digits->GetEntriesFast() - 1);
212 dig = (AliEMCALTriggerRawDigit*)digits->At(pos);
215 // 14b to 12b STU time sums
218 dig->SetL1TimeSum(reg[j][k]);
225 if (iL0 && !data->GetMode())
227 for (Int_t i = 0; i < kNTRU; i++)
229 AliEMCALTriggerTRU* iTRU = static_cast<AliEMCALTriggerTRU*>(fTRU->At(i));
231 AliDebug(999, Form("=== TRU# %2d found %d patches", i, (iTRU->Patches()).GetEntriesFast()));
233 TIter next(&iTRU->Patches());
234 while (AliEMCALTriggerPatch* p = (AliEMCALTriggerPatch*)next())
239 if (geom->GetAbsFastORIndexFromPositionInTRU(i, px, py, id)
241 geom->GetPositionInEMCALFromAbsFastORIndex(id, px, py)) p->SetPosition(px, py);
243 if (AliDebugLevel()) p->Print("");
245 Int_t peaks = p->Peaks();
247 Int_t sizeX = (Int_t) ((iTRU->PatchSize())->X() * (iTRU->SubRegionSize())->X());
248 Int_t sizeY = (Int_t) ((iTRU->PatchSize())->Y() * (iTRU->SubRegionSize())->Y());
250 for (Int_t j = 0; j < sizeX * sizeY; j++)
252 if (peaks & (1 << j))
254 pos = posMap[px + j % sizeX][py + j / sizeX];
258 posMap[px + j % sizeX][py + j / sizeX] = digits->GetEntriesFast();
260 new((*digits)[digits->GetEntriesFast()]) AliEMCALTriggerRawDigit(id, 0x0, 0);
262 dig = (AliEMCALTriggerRawDigit*)digits->At(digits->GetEntriesFast() - 1);
264 dig = (AliEMCALTriggerRawDigit*)digits->At(pos);
267 dig->SetL0Time(p->Time());
271 pos = posMap[px][py];
275 posMap[px][py] = digits->GetEntriesFast();
277 new((*digits)[digits->GetEntriesFast()]) AliEMCALTriggerRawDigit(id, 0x0, 0);
279 dig = (AliEMCALTriggerRawDigit*)digits->At(digits->GetEntriesFast() - 1);
284 dig = (AliEMCALTriggerRawDigit*)digits->At(pos);
287 dig->SetTriggerBit(kL0, 0);
292 // Prepare STU for L1 calculation
293 for (int i = 0; i < (fSTU->RegionSize())->X(); i++) {
294 for (int j = 0; j < (fSTU->RegionSize())->Y(); j++) {
300 AliEMCALTriggerRawDigit *digit = (AliEMCALTriggerRawDigit*)digits->At(pos);
302 if (digit->GetL1TimeSum() > -1) region[i][j] = digit->GetL1TimeSum();
307 AliDebug(999,"==================== STU ====================");
308 if (AliDebugLevel() >= 999) fSTU->Scan();
309 AliDebug(999,"==============================================");
311 fSTU->SetRegion(region);
315 for (int ithr = 0; ithr < 2; ithr++) {
316 AliDebug(999, Form(" THR %d / EGA %d / EJE %d", ithr, data->GetL1GammaThreshold(ithr), data->GetL1JetThreshold(ithr)));
318 fSTU->SetThreshold(kL1GammaHigh + ithr, data->GetL1GammaThreshold(ithr));
319 fSTU->SetThreshold(kL1JetHigh + ithr, data->GetL1JetThreshold( ithr));
324 for (int ithr = 0; ithr < 2; ithr++) {
326 fSTU->ComputeThFromV0(kL1GammaHigh + ithr, V0M);
327 data->SetL1GammaThreshold(ithr, fSTU->GetThreshold(kL1GammaHigh + ithr));
329 fSTU->ComputeThFromV0(kL1JetHigh + ithr, V0M);
330 data->SetL1JetThreshold(ithr, fSTU->GetThreshold(kL1JetHigh + ithr) );
332 AliDebug(999, Form("STU THR %d EGA %d EJE %d", ithr, fSTU->GetThreshold(kL1GammaHigh + ithr), fSTU->GetThreshold(kL1JetHigh + ithr)));
336 for (int ithr = 0; ithr < 2; ithr++) {
340 fSTU->L1(kL1GammaHigh + ithr);
344 nP = (fSTU->Patches()).MakeIterator();
346 AliDebug(999, Form("=== STU found %d gamma patches", (fSTU->Patches()).GetEntriesFast()));
348 while (AliEMCALTriggerPatch* p = (AliEMCALTriggerPatch*)nP->Next())
352 if (AliDebugLevel()) p->Print("");
354 if (geom->GetAbsFastORIndexFromPositionInEMCAL(px, py, id))
356 if (posMap[px][py] == -1)
358 posMap[px][py] = digits->GetEntriesFast();
361 new((*digits)[digits->GetEntriesFast()]) AliEMCALTriggerRawDigit(id, 0x0, 0);
363 dig = (AliEMCALTriggerRawDigit*)digits->At(digits->GetEntriesFast() - 1);
367 dig = (AliEMCALTriggerRawDigit*)digits->At(posMap[px][py]);
370 if (AliDebugLevel()) dig->Print("");
372 dig->SetTriggerBit(kL1GammaHigh + ithr, 0);
378 fSTU->L1(kL1JetHigh + ithr);
380 nP = (fSTU->Patches()).MakeIterator();
382 AliDebug(999, Form("=== STU found %d jet patches", (fSTU->Patches()).GetEntriesFast()));
384 while (AliEMCALTriggerPatch* p = (AliEMCALTriggerPatch*)nP->Next())
388 if (AliDebugLevel()) p->Print("");
390 if (geom->GetAbsFastORIndexFromPositionInEMCAL(px, py, id))
392 if (posMap[px][py] == -1)
394 posMap[px][py] = digits->GetEntriesFast();
397 new((*digits)[digits->GetEntriesFast()]) AliEMCALTriggerRawDigit(id, 0x0, 0);
399 dig = (AliEMCALTriggerRawDigit*)digits->At(digits->GetEntriesFast() - 1);
403 dig = (AliEMCALTriggerRawDigit*)digits->At(posMap[px][py]);
406 if (AliDebugLevel()) dig->Print("");
408 dig->SetTriggerBit(kL1JetHigh + ithr, 0);
413 // Now reset the electronics for a fresh start with next event
418 void AliEMCALTriggerElectronics::Reset()
423 while ( AliEMCALTriggerTRU *TRU = (AliEMCALTriggerTRU*)nextTRU() ) TRU->Reset();