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) (static_cast<AliEMCALTriggerTRU*>(fTRU->At(iTRU)))->SetADC(iADC, time, amp);
137 if (geom->GetPositionInEMCALFromAbsFastORIndex(id, px, py)) posMap[px][py] = i;
142 Int_t timeL0[kNTRU] = {0}, timeL0min = 999;
144 for (Int_t i=0; i<kNTRU; i++)
146 AliDebug(999, Form("===========< TRU %2d >============\n", i));
148 AliEMCALTriggerTRU* iTRU = static_cast<AliEMCALTriggerTRU*>(fTRU->At(i));
150 if (iTRU->L0()) // L0 recomputation: *ALWAYS* done from FALTRO
154 timeL0[i] = iTRU->GetL0Time();
156 if (!timeL0[i]) AliWarning(Form("TRU# %d has 0 trigger time",i));
158 if (timeL0[i] < timeL0min) timeL0min = timeL0[i];
160 data->SetL0Trigger(0, i, 1); // TRU# i has issued a L0
163 data->SetL0Trigger(0, i, 0);
166 AliDebug(999, Form("=== %2d TRU (out of %2d) has issued a L0 / Min L0 time: %d\n", iL0, kNTRU, timeL0min));
168 AliEMCALTriggerRawDigit* dig = 0x0;
170 if (iL0 && (!data->GetMode() || !fSTU->GetDCSConfig()->GetRawData()))
172 // Update digits after L0 calculation
173 for (Int_t i = 0; i < kNTRU; i++)
175 AliEMCALTriggerTRU *iTRU = static_cast<AliEMCALTriggerTRU*>(fTRU->At(i));
178 for (int j = 0; j < 24; j++) for (int k = 0; k < 4; k++) reg[j][k] = 0;
180 iTRU->GetL0Region(timeL0min, reg);
182 for (int j = 0; j < iTRU->RegionSize()->X(); j++)
184 for (int k = 0; k < iTRU->RegionSize()->Y(); k++)
188 geom->GetAbsFastORIndexFromPositionInTRU(i, j, k, id)
190 geom->GetPositionInEMCALFromAbsFastORIndex(id, px, py))
192 pos = posMap[px][py];
197 new((*digits)[digits->GetEntriesFast()]) AliEMCALTriggerRawDigit(id, 0x0, 0);
199 dig = (AliEMCALTriggerRawDigit*)digits->At(digits->GetEntriesFast() - 1);
203 dig = (AliEMCALTriggerRawDigit*)digits->At(pos);
206 dig->SetL1TimeSum(reg[j][k]);
213 if (iL0 && !data->GetMode())
215 // transform local to global
217 for (Int_t i = 0; i < kNTRU; i++)
219 AliEMCALTriggerTRU* iTRU = static_cast<AliEMCALTriggerTRU*>(fTRU->At(i));
221 TIter next(&iTRU->Patches());
222 while (AliEMCALTriggerPatch* p = (AliEMCALTriggerPatch*)next())
227 if (geom->GetAbsFastORIndexFromPositionInTRU(i, px, py, id) &&
228 geom->GetPositionInEMCALFromAbsFastORIndex(id, px, py)) p->SetPosition(px, py);
230 Int_t peaks = p->Peaks();
232 Int_t sizeX = (Int_t) ((iTRU->PatchSize())->X() * (iTRU->SubRegionSize())->X());
233 Int_t sizeY = (Int_t) ((iTRU->PatchSize())->Y() * (iTRU->SubRegionSize())->Y());
235 for (Int_t j = 0; j < sizeX * sizeY; j++)
237 if (peaks & (1 << j))
239 pos = posMap[px + j % sizeX][py + j / sizeX];
244 new((*digits)[digits->GetEntriesFast()]) AliEMCALTriggerRawDigit(id, 0x0, 0);
246 dig = (AliEMCALTriggerRawDigit*)digits->At(digits->GetEntriesFast() - 1);
250 dig = (AliEMCALTriggerRawDigit*)digits->At(pos);
253 dig->SetL0Time(timeL0min);
257 pos = posMap[px][py];
262 new((*digits)[digits->GetEntriesFast()]) AliEMCALTriggerRawDigit(id, 0x0, 0);
264 dig = (AliEMCALTriggerRawDigit*)digits->At(digits->GetEntriesFast() - 1);
268 dig = (AliEMCALTriggerRawDigit*)digits->At(pos);
271 dig->SetTriggerBit(kL0, 0);
277 // Prepare STU for L1 calculation
279 for (int i = 0; i < (fSTU->RegionSize())->X(); i++)
281 for (int j = 0; j < (fSTU->RegionSize())->Y(); j++)
287 AliEMCALTriggerRawDigit *digit = (AliEMCALTriggerRawDigit*)digits->At(pos);
289 if (digit->GetL1TimeSum() > -1) region[i][j] = digit->GetL1TimeSum();
294 fSTU->SetRegion(region);
298 fSTU->SetThreshold(kL1Gamma, data->GetL1GammaThreshold());
299 fSTU->SetThreshold(kL1Jet, data->GetL1JetThreshold() );
303 fSTU->ComputeThFromV0(kL1Gamma, V0M);
304 data->SetL1GammaThreshold( fSTU->GetThreshold(kL1Gamma));
305 fSTU->ComputeThFromV0(kL1Jet, V0M);
306 data->SetL1JetThreshold( fSTU->GetThreshold(kL1Jet) );
313 nP = (fSTU->Patches()).MakeIterator();
315 while (AliEMCALTriggerPatch* p = (AliEMCALTriggerPatch*)nP->Next())
319 if (geom->GetAbsFastORIndexFromPositionInEMCAL(px, py, id))
321 if (posMap[px][py] == -1)
324 new((*digits)[digits->GetEntriesFast()]) AliEMCALTriggerRawDigit(id, 0x0, 0);
326 dig = (AliEMCALTriggerRawDigit*)digits->At(digits->GetEntriesFast() - 1);
330 dig = (AliEMCALTriggerRawDigit*)digits->At(posMap[px][py]);
333 dig->SetTriggerBit(kL1Gamma,0);
341 nP = (fSTU->Patches()).MakeIterator();
343 while (AliEMCALTriggerPatch* p = (AliEMCALTriggerPatch*)nP->Next())
347 px *= (Int_t)((fSTU->SubRegionSize())->X());
349 py *= (Int_t)((fSTU->SubRegionSize())->Y());
351 if (geom->GetAbsFastORIndexFromPositionInEMCAL(px, py, id))
353 if (posMap[px][py] == -1)
356 new((*digits)[digits->GetEntriesFast()]) AliEMCALTriggerRawDigit(id, 0x0, 0);
358 dig = (AliEMCALTriggerRawDigit*)digits->At(digits->GetEntriesFast() - 1);
362 dig = (AliEMCALTriggerRawDigit*)digits->At(posMap[px][py]);
365 dig->SetTriggerBit(kL1Jet, 0);
369 if (AliDebugLevel() >= 999) data->Scan();
371 // Now reset the electronics for a fresh start with next event
376 void AliEMCALTriggerElectronics::Reset()
381 while ( AliEMCALTriggerTRU *TRU = (AliEMCALTriggerTRU*)nextTRU() ) TRU->Reset();