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"
44 const Int_t kNTRU = 30;
47 ClassImp(AliEMCALTriggerElectronics)
50 AliEMCALTriggerElectronics::AliEMCALTriggerElectronics(const AliEMCALTriggerDCSConfig *dcsConf) : TObject(),
51 fTRU(new TClonesArray("AliEMCALTriggerTRU",32)),
61 for (Int_t i=0;i<kNTRU;i++)
63 AliEMCALTriggerTRUDCSConfig* truConf = dcsConf->GetTRUDCSConfig(i);
64 new ((*fTRU)[i]) AliEMCALTriggerTRU(truConf, rSize, i % 2);
67 rSize.Set( 48., 64. );
70 AliEMCALTriggerSTUDCSConfig* stuConf = dcsConf->GetSTUDCSConfig();
71 fSTU = new AliEMCALTriggerSTU(stuConf, rSize);
74 for (Int_t i=0;i<kNTRU;i++) fSTU->Build(str,
76 (static_cast<AliEMCALTriggerTRU*>(fTRU->At(i)))->Map(),
77 (static_cast<AliEMCALTriggerTRU*>(fTRU->At(i)))->RegionSize()
82 AliEMCALTriggerElectronics::~AliEMCALTriggerElectronics()
91 void AliEMCALTriggerElectronics::Digits2Trigger(TClonesArray* digits, const Int_t V0M[], AliEMCALTriggerData* data)
95 AliEMCALGeometry* geom = 0x0;
97 AliRunLoader *rl = AliRunLoader::Instance();
98 if (rl->GetAliRun() && rl->GetAliRun()->GetDetector("EMCAL")){
99 AliEMCAL* emcal = dynamic_cast<AliEMCAL*>(rl->GetAliRun()->GetDetector("EMCAL"));
100 if(emcal)geom = emcal->GetGeometry();
103 if(!geom) geom = AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaultGeometryName());
105 if(!geom) AliError("Cannot access geometry!");
109 Int_t region[48][64], posMap[48][64];
110 for (Int_t i = 0; i < 48; i++) for (Int_t j = 0; j < 64; j++)
116 for (Int_t i = 0; i < digits->GetEntriesFast(); i++)
118 AliEMCALTriggerRawDigit* digit = (AliEMCALTriggerRawDigit*)digits->At(i);
120 Int_t id = digit->GetId();
124 Bool_t isOK1 = geom->GetTRUFromAbsFastORIndex(id, iTRU, iADC);
126 if ((isOK1 && iTRU >= kNTRU) || !isOK1) continue;
128 for (Int_t j = 0; j < digit->GetNSamples(); j++)
131 Bool_t isOK2 = digit->GetTimeSample(j, time, amp);
133 if (isOK1 && isOK2 && amp) (static_cast<AliEMCALTriggerTRU*>(fTRU->At(iTRU)))->SetADC(iADC, time, amp);
137 if (geom->GetPositionInEMCALFromAbsFastORIndex(id, px, py))
141 if (fSTU->GetRawData() && digit->GetL1TimeSum() >= 0)
143 region[px][py] = digit->GetL1TimeSum();
150 for (Int_t i=0; i<kNTRU; i++)
152 AliDebug(999, Form("===========< TRU %2d >============\n", i));
154 AliEMCALTriggerTRU* iTRU = static_cast<AliEMCALTriggerTRU*>(fTRU->At(i));
156 // L0 is always computed from F-ALTRO
161 Int_t sizeX = (Int_t) ((iTRU->PatchSize())->X() * (iTRU->SubRegionSize())->X());
163 Int_t sizeY = (Int_t) ((iTRU->PatchSize())->Y() * (iTRU->SubRegionSize())->Y());
165 // transform local to global
166 TIter Next(&iTRU->Patches());
167 while (AliEMCALTriggerPatch* p = (AliEMCALTriggerPatch*)Next())
169 Int_t px, py, id; p->Position(px, py);
171 if (geom->GetAbsFastORIndexFromPositionInTRU(i, px, py, id)
173 geom->GetPositionInEMCALFromAbsFastORIndex(id, px, py)) p->SetPosition(px, py);
175 if (!data->GetMode()) // Simulation
177 Int_t peaks = p->Peaks();
180 AliEMCALTriggerRawDigit* dig = 0x0;
182 for (Int_t j = 0; j < sizeX * sizeY; j++)
184 if (peaks & (1 << j))
186 pos = posMap[px + j % sizeX][py + j / sizeX];
191 new((*digits)[digits->GetEntriesFast()]) AliEMCALTriggerRawDigit(id, 0x0, 0);
193 dig = (AliEMCALTriggerRawDigit*)digits->At(digits->GetEntriesFast() - 1);
197 dig = (AliEMCALTriggerRawDigit*)digits->At(pos);
200 dig->SetL0Time(p->Time());
204 pos = posMap[px][py];
209 new((*digits)[digits->GetEntriesFast()]) AliEMCALTriggerRawDigit(id, 0x0, 0);
211 dig = (AliEMCALTriggerRawDigit*)digits->At(digits->GetEntriesFast() - 1);
215 dig = (AliEMCALTriggerRawDigit*)digits->At(pos);
218 dig->SetTriggerBit(kL0,0);
222 data->SetL0Trigger(0, i, 1);
225 data->SetL0Trigger(0, i, 0);
228 // A L0 has been issued, run L1
229 // Depending on raw data enabled or not in STU data: L1 computation
230 // should be done from F-ALTRO or directly on TRU time sums in STU raw data
233 // Use L1 threshold from raw data when reconstructing raw data
236 fSTU->SetThreshold(kL1Gamma, data->GetL1GammaThreshold());
237 fSTU->SetThreshold(kL1Jet, data->GetL1JetThreshold() );
241 fSTU->ComputeThFromV0(V0M); // C/A
242 data->SetL1GammaThreshold(fSTU->GetThreshold(kL1Gamma));
243 data->SetL1JetThreshold( fSTU->GetThreshold(kL1Jet) );
246 if (fSTU->GetRawData())
248 // Compute L1 from STU raw data
249 fSTU->SetRegion(region);
253 // Build STU raw data from F-ALTRO
254 TString str = "region";
255 for (Int_t i = 0; i < kNTRU; i++) fSTU->Build(str,
257 (static_cast<AliEMCALTriggerTRU*>(fTRU->At(i)))->Region(),
258 (static_cast<AliEMCALTriggerTRU*>(fTRU->At(i)))->RegionSize());
264 AliEMCALTriggerRawDigit* dig = 0x0;
268 nP = (fSTU->Patches()).MakeIterator();
270 while (AliEMCALTriggerPatch* p = (AliEMCALTriggerPatch*)nP->Next())
274 if (geom->GetAbsFastORIndexFromPositionInEMCAL(px, py, id))
276 if (posMap[px][py] == -1)
279 new((*digits)[digits->GetEntriesFast()]) AliEMCALTriggerRawDigit(id, 0x0, 0);
281 dig = (AliEMCALTriggerRawDigit*)digits->At(digits->GetEntriesFast() - 1);
285 dig = (AliEMCALTriggerRawDigit*)digits->At(posMap[px][py]);
288 dig->SetTriggerBit(kL1Gamma,0);
296 nP = (fSTU->Patches()).MakeIterator();
298 while (AliEMCALTriggerPatch* p = (AliEMCALTriggerPatch*)nP->Next())
302 px *= (Int_t)((fSTU->SubRegionSize())->X());
304 py *= (Int_t)((fSTU->SubRegionSize())->Y());
306 if (geom->GetAbsFastORIndexFromPositionInEMCAL(px, py, id))
308 if (posMap[px][py] == -1)
311 new((*digits)[digits->GetEntriesFast()]) AliEMCALTriggerRawDigit(id, 0x0, 0);
313 dig = (AliEMCALTriggerRawDigit*)digits->At(digits->GetEntriesFast() - 1);
317 dig = (AliEMCALTriggerRawDigit*)digits->At(posMap[px][py]);
320 dig->SetTriggerBit(kL1Jet,0);
324 Int_t** reg = fSTU->Region();
326 if (!fSTU->GetRawData())
328 // Update digits w/ L1 time sum
329 // Done in raw digit maker when raw data enabled
330 for (Int_t i = 0; i < 48; i++)
332 for (Int_t j = 0; j < 64; j++)
336 if (geom->GetAbsFastORIndexFromPositionInEMCAL(i, j, id))
338 if (posMap[i][j] == -1)
340 // Add a new digit with L1 time sum
341 new((*digits)[digits->GetEntriesFast()]) AliEMCALTriggerRawDigit(id, 0x0, 0);
343 dig = (AliEMCALTriggerRawDigit*)digits->At(digits->GetEntriesFast() - 1);
347 dig = (AliEMCALTriggerRawDigit*)digits->At(posMap[i][j]);
350 dig->SetL1TimeSum(reg[i][j]);
358 if (AliDebugLevel() >= 999) data->Scan();
360 // Now reset the electronics for a fresh start with next event
365 void AliEMCALTriggerElectronics::Reset()
370 while ( AliEMCALTriggerTRU *TRU = (AliEMCALTriggerTRU*)NextTRU() ) TRU->Reset();