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 = 32;
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 geom = dynamic_cast<AliEMCAL*>(rl->GetAliRun()->GetDetector("EMCAL"))->GetGeometry();
98 geom = AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaultGeometryName());
100 if (!geom) AliError("Cannot access geometry!");
104 Int_t region[48][64], posMap[48][64];
105 for (Int_t i = 0; i < 48; i++) for (Int_t j = 0; j < 64; j++)
111 for (Int_t i = 0; i < digits->GetEntriesFast(); i++)
113 AliEMCALTriggerRawDigit* digit = (AliEMCALTriggerRawDigit*)digits->At(i);
115 Int_t id = digit->GetId();
119 Bool_t isOK1 = geom->GetTRUFromAbsFastORIndex(id, iTRU, iADC);
121 for (Int_t j = 0; j < digit->GetNSamples(); j++)
124 Bool_t isOK2 = digit->GetTimeSample(j, time, amp);
126 if (isOK1 && isOK2 && amp) (static_cast<AliEMCALTriggerTRU*>(fTRU->At(iTRU)))->SetADC(iADC, time, amp);
130 if (geom->GetPositionInEMCALFromAbsFastORIndex(id, px, py))
134 if (fSTU->GetRawData() && digit->GetL1TimeSum() >= 0)
136 region[px][py] = digit->GetL1TimeSum();
143 for (Int_t i=0; i<kNTRU; i++)
145 AliDebug(999, Form("===========< TRU %2d >============\n", i));
147 AliEMCALTriggerTRU* iTRU = static_cast<AliEMCALTriggerTRU*>(fTRU->At(i));
149 // L0 is always computed from F-ALTRO
154 Int_t sizeX = (iTRU->PatchSize())->X() * (iTRU->SubRegionSize())->X();
156 Int_t sizeY = (iTRU->PatchSize())->Y() * (iTRU->SubRegionSize())->Y();
158 // transform local to global
159 TIter Next(&iTRU->Patches());
160 while (AliEMCALTriggerPatch* p = (AliEMCALTriggerPatch*)Next())
162 Int_t px, py, id; p->Position(px, py);
164 if (geom->GetAbsFastORIndexFromPositionInTRU(i, px, py, id)
166 geom->GetPositionInEMCALFromAbsFastORIndex(id, px, py)) p->SetPosition(px, py);
168 if (!data->GetMode())
170 Int_t peaks = p->Peaks();
172 for (Int_t j = 0; j < sizeX * sizeY; j++)
174 if (peaks & (1 << j))
177 Int_t pos = posMap[px + j % sizeX][py + j / sizeX];
179 // cout << "px: " << px << " py: " << py << " j: " << j << " mod: " << j%sizeX << " ratio: " << j / sizeX << " pos: " << pos << endl;
181 AliEMCALTriggerRawDigit* dig = 0x0;
185 new((*digits)[digits->GetEntriesFast()]) AliEMCALTriggerRawDigit(id, 0x0, 0);
187 dig = (AliEMCALTriggerRawDigit*)digits->At(digits->GetEntriesFast() - 1);
191 dig = (AliEMCALTriggerRawDigit*)digits->At(pos);
194 dig->SetL0Time(p->Time());
200 data->SetL0Trigger(0, i, 1);
202 data->SetPatches(kL0, 0, iTRU->Patches());
205 data->SetL0Trigger(0, i, 0);
208 // A L0 has been issued, run L1
209 // Depending on raw data enabled or not in STU data: L1 computation
210 // should be done from F-ALTRO or directly on TRU time sums in STU raw data
213 // Use L1 threshold from raw data when reconstructing raw data
216 fSTU->SetThreshold(kL1Gamma, data->GetL1GammaThreshold());
217 fSTU->SetThreshold(kL1Jet, data->GetL1JetThreshold() );
221 fSTU->ComputeThFromV0(V0M); // C/A
222 data->SetL1GammaThreshold(fSTU->GetThreshold(kL1Gamma));
223 data->SetL1JetThreshold( fSTU->GetThreshold(kL1Jet) );
226 if (fSTU->GetRawData())
228 // Compute L1 from STU raw data
229 fSTU->SetRegion(region);
233 // Build STU raw data from F-ALTRO
234 TString str = "region";
235 for (Int_t i = 0; i < kNTRU; i++) fSTU->Build(str,
237 (static_cast<AliEMCALTriggerTRU*>(fTRU->At(i)))->Region(),
238 (static_cast<AliEMCALTriggerTRU*>(fTRU->At(i)))->RegionSize());
243 data->SetPatches(kL1Gamma, 0, fSTU->Patches());
249 data->SetPatches(kL1Jet, 0, fSTU->Patches());
251 Int_t** reg = fSTU->Region();
253 if (!fSTU->GetRawData())
255 // Update digits w/ L1 time sum
256 // Done in raw digit maker when raw data enabled
257 for (Int_t i = 0; i < 48; i++)
259 for (Int_t j = 0; j < 64; j++)
264 if (geom->GetAbsFastORIndexFromPositionInEMCAL(i, j, id))
266 AliEMCALTriggerRawDigit* dig = 0x0;
268 if (posMap[i][j] == -1)
270 // Add a new digit with L1 time sum
271 new((*digits)[digits->GetEntriesFast()]) AliEMCALTriggerRawDigit(id, 0x0, 0);
273 dig = (AliEMCALTriggerRawDigit*)digits->At(digits->GetEntriesFast() - 1);
277 dig = (AliEMCALTriggerRawDigit*)digits->At(posMap[i][j]);
280 dig->SetL1TimeSum(reg[i][j]);
288 if (AliDebugLevel() >= 999) data->Scan();
290 // Now reset the electronics for a fresh start with next event
295 void AliEMCALTriggerElectronics::Reset()
299 while ( AliEMCALTriggerTRU *TRU = (AliEMCALTriggerTRU*)NextTRU() ) TRU->Reset();