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));
142 (static_cast<AliEMCALTriggerTRU*>(fTRU->At(iTRU)))->SetADC(iADC, time, 4 * amp);
144 (static_cast<AliEMCALTriggerTRU*>(fTRU->At(iTRU)))->SetADC(iADC, time, amp);
148 if (fGeometry->GetPositionInEMCALFromAbsFastORIndex(id, px, py)) posMap[px][py] = i;
153 Int_t timeL0[kNTRU] = {0}, timeL0min = 999;
155 for (Int_t i = 0; i < kNTRU; i++)
157 AliEMCALTriggerTRU *iTRU = static_cast<AliEMCALTriggerTRU*>(fTRU->At(i));
160 AliDebug(999, Form("===========< TRU %2d >============", i));
162 if (iTRU->L0()) // L0 recomputation: *ALWAYS* done from FALTRO
166 timeL0[i] = iTRU->GetL0Time();
168 if (!timeL0[i]) AliWarning(Form("TRU# %d has 0 trigger time",i));
170 if (timeL0[i] < timeL0min) timeL0min = timeL0[i];
172 data->SetL0Trigger(0, i, 1); // TRU# i has issued a L0
175 data->SetL0Trigger(0, i, 0);
178 AliDebug(999, Form("=== %2d TRU (out of %2d) has issued a L0 / Min L0 time: %d", iL0, fTRU->GetEntriesFast(), timeL0min));
180 AliEMCALTriggerRawDigit* dig = 0x0;
182 if (iL0 && (!data->GetMode() || !fSTU->GetDCSConfig()->GetRawData()))
184 // Update digits after L0 calculation
185 for (Int_t i = 0; i < kNTRU; i++)
187 AliEMCALTriggerTRU *iTRU = static_cast<AliEMCALTriggerTRU*>(fTRU->At(i));
191 for (int j = 0; j < 24; j++) for (int k = 0; k < 4; k++) reg[j][k] = 0;
193 iTRU->GetL0Region(timeL0min, reg);
195 for (int j = 0; j < iTRU->RegionSize()->X(); j++)
197 for (int k = 0; k < iTRU->RegionSize()->Y(); k++)
201 fGeometry->GetAbsFastORIndexFromPositionInTRU(i, j, k, id)
203 fGeometry->GetPositionInEMCALFromAbsFastORIndex(id, px, py))
205 pos = posMap[px][py];
210 posMap[px][py] = digits->GetEntriesFast();
212 new((*digits)[digits->GetEntriesFast()]) AliEMCALTriggerRawDigit(id, 0x0, 0);
214 dig = (AliEMCALTriggerRawDigit*)digits->At(digits->GetEntriesFast() - 1);
218 dig = (AliEMCALTriggerRawDigit*)digits->At(pos);
221 // 14b to 12b STU time sums
224 dig->SetL1TimeSum(reg[j][k]);
231 if (iL0 && !data->GetMode())
233 for (Int_t i = 0; i < kNTRU; i++)
235 AliEMCALTriggerTRU *iTRU = static_cast<AliEMCALTriggerTRU*>(fTRU->At(i));
238 AliDebug(999, Form("=== TRU# %2d found %d patches", i, (iTRU->Patches()).GetEntriesFast()));
240 TIter next(&iTRU->Patches());
241 while (AliEMCALTriggerPatch* p = (AliEMCALTriggerPatch*)next())
246 if (fGeometry->GetAbsFastORIndexFromPositionInTRU(i, px, py, id)
248 fGeometry->GetPositionInEMCALFromAbsFastORIndex(id, px, py)) p->SetPosition(px, py);
250 if (AliDebugLevel()) p->Print("");
252 Int_t peaks = p->Peaks();
254 Int_t sizeX = (Int_t) ((iTRU->PatchSize())->X() * (iTRU->SubRegionSize())->X());
255 Int_t sizeY = (Int_t) ((iTRU->PatchSize())->Y() * (iTRU->SubRegionSize())->Y());
257 for (Int_t j = 0; j < sizeX * sizeY; j++)
259 if (peaks & (1 << j))
261 pos = posMap[px + j % sizeX][py + j / sizeX];
265 posMap[px + j % sizeX][py + j / sizeX] = digits->GetEntriesFast();
267 new((*digits)[digits->GetEntriesFast()]) AliEMCALTriggerRawDigit(id, 0x0, 0);
269 dig = (AliEMCALTriggerRawDigit*)digits->At(digits->GetEntriesFast() - 1);
271 dig = (AliEMCALTriggerRawDigit*)digits->At(pos);
274 dig->SetL0Time(p->Time());
278 pos = posMap[px][py];
282 posMap[px][py] = digits->GetEntriesFast();
284 new((*digits)[digits->GetEntriesFast()]) AliEMCALTriggerRawDigit(id, 0x0, 0);
286 dig = (AliEMCALTriggerRawDigit*)digits->At(digits->GetEntriesFast() - 1);
291 dig = (AliEMCALTriggerRawDigit*)digits->At(pos);
294 dig->SetTriggerBit(kL0, 0);
299 // Prepare STU for L1 calculation
300 for (int i = 0; i < (fSTU->RegionSize())->X(); i++) {
301 for (int j = 0; j < (fSTU->RegionSize())->Y(); j++) {
307 AliEMCALTriggerRawDigit *digit = (AliEMCALTriggerRawDigit*)digits->At(pos);
309 if (digit->GetL1TimeSum() > -1) region[i][j] = digit->GetL1TimeSum();
314 AliDebug(999,"==================== STU ====================");
315 if (AliDebugLevel() >= 999) fSTU->Scan();
316 AliDebug(999,"==============================================");
318 fSTU->SetRegion(region);
322 for (int ithr = 0; ithr < 2; ithr++) {
323 AliDebug(999, Form(" THR %d / EGA %d / EJE %d", ithr, data->GetL1GammaThreshold(ithr), data->GetL1JetThreshold(ithr)));
325 fSTU->SetThreshold(kL1GammaHigh + ithr, data->GetL1GammaThreshold(ithr));
326 fSTU->SetThreshold(kL1JetHigh + ithr, data->GetL1JetThreshold( ithr));
331 for (int ithr = 0; ithr < 2; ithr++) {
333 fSTU->ComputeThFromV0(kL1GammaHigh + ithr, V0M);
334 data->SetL1GammaThreshold(ithr, fSTU->GetThreshold(kL1GammaHigh + ithr));
336 fSTU->ComputeThFromV0(kL1JetHigh + ithr, V0M);
337 data->SetL1JetThreshold(ithr, fSTU->GetThreshold(kL1JetHigh + ithr) );
339 AliDebug(999, Form("STU THR %d EGA %d EJE %d", ithr, fSTU->GetThreshold(kL1GammaHigh + ithr), fSTU->GetThreshold(kL1JetHigh + ithr)));
343 for (int ithr = 0; ithr < 2; ithr++) {
347 fSTU->L1(kL1GammaHigh + ithr);
351 nP = (fSTU->Patches()).MakeIterator();
353 AliDebug(999, Form("=== STU found %d gamma patches", (fSTU->Patches()).GetEntriesFast()));
355 while (AliEMCALTriggerPatch* p = (AliEMCALTriggerPatch*)nP->Next())
359 if (AliDebugLevel()) p->Print("");
361 if (fGeometry->GetAbsFastORIndexFromPositionInEMCAL(px, py, id))
363 if (posMap[px][py] == -1)
365 posMap[px][py] = digits->GetEntriesFast();
368 new((*digits)[digits->GetEntriesFast()]) AliEMCALTriggerRawDigit(id, 0x0, 0);
370 dig = (AliEMCALTriggerRawDigit*)digits->At(digits->GetEntriesFast() - 1);
374 dig = (AliEMCALTriggerRawDigit*)digits->At(posMap[px][py]);
377 if (AliDebugLevel()) dig->Print("");
379 dig->SetTriggerBit(kL1GammaHigh + ithr, 0);
385 fSTU->L1(kL1JetHigh + ithr);
387 nP = (fSTU->Patches()).MakeIterator();
389 AliDebug(999, Form("=== STU found %d jet patches", (fSTU->Patches()).GetEntriesFast()));
391 while (AliEMCALTriggerPatch* p = (AliEMCALTriggerPatch*)nP->Next())
395 if (AliDebugLevel()) p->Print("");
397 if (fGeometry->GetAbsFastORIndexFromPositionInEMCAL(px, py, id))
399 if (posMap[px][py] == -1)
401 posMap[px][py] = digits->GetEntriesFast();
404 new((*digits)[digits->GetEntriesFast()]) AliEMCALTriggerRawDigit(id, 0x0, 0);
406 dig = (AliEMCALTriggerRawDigit*)digits->At(digits->GetEntriesFast() - 1);
410 dig = (AliEMCALTriggerRawDigit*)digits->At(posMap[px][py]);
413 if (AliDebugLevel()) dig->Print("");
415 dig->SetTriggerBit(kL1JetHigh + ithr, 0);
420 // Now reset the electronics for a fresh start with next event
425 void AliEMCALTriggerElectronics::Reset()
430 while ( AliEMCALTriggerTRU *TRU = (AliEMCALTriggerTRU*)nextTRU() ) TRU->Reset();