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"
41 #include <TClonesArray.h>
45 const Int_t kNTRU = 30;
48 ClassImp(AliEMCALTriggerElectronics)
51 AliEMCALTriggerElectronics::AliEMCALTriggerElectronics(const AliEMCALTriggerDCSConfig *dcsConf) : TObject(),
52 fTRU(new TClonesArray("AliEMCALTriggerTRU",32)),
60 for (Int_t i=0;i<kNTRU;i++)
62 AliEMCALTriggerTRUDCSConfig* truConf = dcsConf->GetTRUDCSConfig(i);
63 new ((*fTRU)[i]) AliEMCALTriggerTRU(truConf, rSize, i % 2);
66 rSize.Set( 48., 64. );
69 AliEMCALTriggerSTUDCSConfig* stuConf = dcsConf->GetSTUDCSConfig();
70 fSTU = new AliEMCALTriggerSTU(stuConf, rSize);
73 for (Int_t i=0;i<kNTRU;i++) fSTU->Build(str,
75 (static_cast<AliEMCALTriggerTRU*>(fTRU->At(i)))->Map(),
76 (static_cast<AliEMCALTriggerTRU*>(fTRU->At(i)))->RegionSize()
81 AliEMCALTriggerElectronics::~AliEMCALTriggerElectronics()
89 void AliEMCALTriggerElectronics::Digits2Trigger(TClonesArray* digits, const Int_t V0M[], AliEMCALTriggerData* data)
92 AliEMCALGeometry* geom = 0x0;
94 AliRunLoader *rl = AliRunLoader::Instance();
95 if (rl->GetAliRun() && rl->GetAliRun()->GetDetector("EMCAL")){
96 AliEMCAL* emcal = dynamic_cast<AliEMCAL*>(rl->GetAliRun()->GetDetector("EMCAL"));
97 if(emcal)geom = emcal->GetGeometry();
100 if(!geom) geom = AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaultGeometryName());
102 if(!geom) AliError("Cannot access geometry!");
106 Int_t region[48][64], posMap[48][64];
107 for (Int_t i = 0; i < 48; i++) for (Int_t j = 0; j < 64; j++)
113 for (Int_t i = 0; i < digits->GetEntriesFast(); i++)
115 AliEMCALTriggerRawDigit* digit = (AliEMCALTriggerRawDigit*)digits->At(i);
117 Int_t id = digit->GetId();
121 Bool_t isOK1 = geom->GetTRUFromAbsFastORIndex(id, iTRU, iADC);
123 if ((isOK1 && iTRU >= kNTRU) || !isOK1) continue;
125 for (Int_t j = 0; j < digit->GetNSamples(); j++)
128 Bool_t isOK2 = digit->GetTimeSample(j, time, amp);
130 if (isOK1 && isOK2 && amp) (static_cast<AliEMCALTriggerTRU*>(fTRU->At(iTRU)))->SetADC(iADC, time, amp);
134 if (geom->GetPositionInEMCALFromAbsFastORIndex(id, px, py))
138 if (fSTU->GetRawData() && digit->GetL1TimeSum() >= 0)
140 region[px][py] = digit->GetL1TimeSum();
147 for (Int_t i=0; i<kNTRU; i++)
149 AliDebug(999, Form("===========< TRU %2d >============\n", i));
151 AliEMCALTriggerTRU* iTRU = static_cast<AliEMCALTriggerTRU*>(fTRU->At(i));
153 // L0 is always computed from F-ALTRO
158 Int_t sizeX = (Int_t) ((iTRU->PatchSize())->X() * (iTRU->SubRegionSize())->X());
160 Int_t sizeY = (Int_t) ((iTRU->PatchSize())->Y() * (iTRU->SubRegionSize())->Y());
162 // transform local to global
163 TIter Next(&iTRU->Patches());
164 while (AliEMCALTriggerPatch* p = (AliEMCALTriggerPatch*)Next())
166 Int_t px, py, id; p->Position(px, py);
168 if (geom->GetAbsFastORIndexFromPositionInTRU(i, px, py, id)
170 geom->GetPositionInEMCALFromAbsFastORIndex(id, px, py)) p->SetPosition(px, py);
172 if (!data->GetMode()) // Simulation
174 Int_t peaks = p->Peaks();
177 AliEMCALTriggerRawDigit* dig = 0x0;
179 for (Int_t j = 0; j < sizeX * sizeY; j++)
181 if (peaks & (1 << j))
183 pos = posMap[px + j % sizeX][py + j / sizeX];
188 new((*digits)[digits->GetEntriesFast()]) AliEMCALTriggerRawDigit(id, 0x0, 0);
190 dig = (AliEMCALTriggerRawDigit*)digits->At(digits->GetEntriesFast() - 1);
194 dig = (AliEMCALTriggerRawDigit*)digits->At(pos);
197 dig->SetL0Time(p->Time());
201 pos = posMap[px][py];
206 new((*digits)[digits->GetEntriesFast()]) AliEMCALTriggerRawDigit(id, 0x0, 0);
208 dig = (AliEMCALTriggerRawDigit*)digits->At(digits->GetEntriesFast() - 1);
212 dig = (AliEMCALTriggerRawDigit*)digits->At(pos);
215 dig->SetTriggerBit(kL0,0);
219 data->SetL0Trigger(0, i, 1);
222 data->SetL0Trigger(0, i, 0);
225 // A L0 has been issued, run L1
226 // Depending on raw data enabled or not in STU data: L1 computation
227 // should be done from F-ALTRO or directly on TRU time sums in STU raw data
230 // Use L1 threshold from raw data when reconstructing raw data
233 fSTU->SetThreshold(kL1Gamma, data->GetL1GammaThreshold());
234 fSTU->SetThreshold(kL1Jet, data->GetL1JetThreshold() );
238 fSTU->ComputeThFromV0(V0M); // C/A
239 data->SetL1GammaThreshold(fSTU->GetThreshold(kL1Gamma));
240 data->SetL1JetThreshold( fSTU->GetThreshold(kL1Jet) );
243 if (fSTU->GetRawData())
245 // Compute L1 from STU raw data
246 fSTU->SetRegion(region);
250 // Build STU raw data from F-ALTRO
251 TString str = "region";
252 for (Int_t i = 0; i < kNTRU; i++) fSTU->Build(str,
254 (static_cast<AliEMCALTriggerTRU*>(fTRU->At(i)))->Region(),
255 (static_cast<AliEMCALTriggerTRU*>(fTRU->At(i)))->RegionSize());
261 AliEMCALTriggerRawDigit* dig = 0x0;
265 nP = (fSTU->Patches()).MakeIterator();
267 while (AliEMCALTriggerPatch* p = (AliEMCALTriggerPatch*)nP->Next())
271 if (geom->GetAbsFastORIndexFromPositionInEMCAL(px, py, id))
273 if (posMap[px][py] == -1)
276 new((*digits)[digits->GetEntriesFast()]) AliEMCALTriggerRawDigit(id, 0x0, 0);
278 dig = (AliEMCALTriggerRawDigit*)digits->At(digits->GetEntriesFast() - 1);
282 dig = (AliEMCALTriggerRawDigit*)digits->At(posMap[px][py]);
285 dig->SetTriggerBit(kL1Gamma,0);
293 nP = (fSTU->Patches()).MakeIterator();
295 while (AliEMCALTriggerPatch* p = (AliEMCALTriggerPatch*)nP->Next())
299 px *= (Int_t)((fSTU->SubRegionSize())->X());
301 py *= (Int_t)((fSTU->SubRegionSize())->Y());
303 if (geom->GetAbsFastORIndexFromPositionInEMCAL(px, py, id))
305 if (posMap[px][py] == -1)
308 new((*digits)[digits->GetEntriesFast()]) AliEMCALTriggerRawDigit(id, 0x0, 0);
310 dig = (AliEMCALTriggerRawDigit*)digits->At(digits->GetEntriesFast() - 1);
314 dig = (AliEMCALTriggerRawDigit*)digits->At(posMap[px][py]);
317 dig->SetTriggerBit(kL1Jet,0);
321 Int_t** reg = fSTU->Region();
323 if (!fSTU->GetRawData())
325 // Update digits w/ L1 time sum
326 // Done in raw digit maker when raw data enabled
327 for (Int_t i = 0; i < 48; i++)
329 for (Int_t j = 0; j < 64; j++)
333 if (geom->GetAbsFastORIndexFromPositionInEMCAL(i, j, id))
335 if (posMap[i][j] == -1)
337 // Add a new digit with L1 time sum
338 new((*digits)[digits->GetEntriesFast()]) AliEMCALTriggerRawDigit(id, 0x0, 0);
340 dig = (AliEMCALTriggerRawDigit*)digits->At(digits->GetEntriesFast() - 1);
344 dig = (AliEMCALTriggerRawDigit*)digits->At(posMap[i][j]);
347 dig->SetL1TimeSum(reg[i][j]);
355 if (AliDebugLevel() >= 999) data->Scan();
357 // Now reset the electronics for a fresh start with next event
362 void AliEMCALTriggerElectronics::Reset()
366 while ( AliEMCALTriggerTRU *TRU = (AliEMCALTriggerTRU*)NextTRU() ) TRU->Reset();