]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EMCAL/AliEMCALTriggerElectronics.cxx
Adding Sqitch - Use - Qtot/Qmax
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALTriggerElectronics.cxx
CommitLineData
916f1e76 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16/*
17
18
19EMCal trigger electronics manager L0/L1
20can handle both simulated digits and raw data
21Author: R. GUERNANE LPSC Grenoble CNRS/IN2P3
22*/
23
24#include "AliEMCALTriggerElectronics.h"
25#include "AliEMCALTriggerTRU.h"
26#include "AliEMCALTriggerSTU.h"
27#include "AliEMCALGeometry.h"
28#include "AliRunLoader.h"
29#include "AliEMCAL.h"
30#include "AliRun.h"
fff39dd1 31#include "AliEMCALTriggerDCSConfig.h"
916f1e76 32#include "AliEMCALTriggerData.h"
33#include "AliEMCALDigit.h"
34#include "AliCaloRawStreamV3.h"
916f1e76 35#include "AliEMCALTriggerSTURawStream.h"
36#include "AliEMCALDigit.h"
de39a0ff 37#include "AliEMCALTriggerRawDigit.h"
38#include "AliEMCALTriggerPatch.h"
916f1e76 39
40#include <TVector2.h>
41#include <TClonesArray.h>
916f1e76 42
43namespace
44{
45 const Int_t kNTRU = 32;
46}
47
48ClassImp(AliEMCALTriggerElectronics)
49
50//__________________
fff39dd1 51AliEMCALTriggerElectronics::AliEMCALTriggerElectronics(const AliEMCALTriggerDCSConfig *dcsConf) : TObject(),
916f1e76 52fTRU(new TClonesArray("AliEMCALTriggerTRU",32)),
53fSTU(0x0)
54{
55 TVector2 rSize;
56
57 rSize.Set( 24., 4. );
58
59 // 32 TRUs
fff39dd1 60 for (Int_t i=0;i<kNTRU;i++)
61 {
62 AliEMCALTriggerTRUDCSConfig* truConf = dcsConf->GetTRUDCSConfig(i);
de39a0ff 63 new ((*fTRU)[i]) AliEMCALTriggerTRU(truConf, rSize, i % 2);
fff39dd1 64 }
65
916f1e76 66 rSize.Set( 48., 64. );
67
68 // 1 STU
fff39dd1 69 AliEMCALTriggerSTUDCSConfig* stuConf = dcsConf->GetSTUDCSConfig();
70 fSTU = new AliEMCALTriggerSTU(stuConf, rSize);
916f1e76 71
de39a0ff 72 TString str = "map";
73 for (Int_t i=0;i<kNTRU;i++) fSTU->Build(str,
74 i,
75 (static_cast<AliEMCALTriggerTRU*>(fTRU->At(i)))->Map(),
76 (static_cast<AliEMCALTriggerTRU*>(fTRU->At(i)))->RegionSize()
77 );
916f1e76 78}
79
80//________________
81AliEMCALTriggerElectronics::~AliEMCALTriggerElectronics()
82{
83 //
84 fTRU->Delete();
85 delete fSTU;
86}
87
88//__________________
de39a0ff 89void AliEMCALTriggerElectronics::Digits2Trigger(TClonesArray* digits, const Int_t V0M[], AliEMCALTriggerData* data)
916f1e76 90{
91 //
92 AliEMCALGeometry* geom = 0x0;
93
94 AliRunLoader *rl = AliRunLoader::Instance();
95 if (rl->GetAliRun() && rl->GetAliRun()->GetDetector("EMCAL"))
96 geom = dynamic_cast<AliEMCAL*>(rl->GetAliRun()->GetDetector("EMCAL"))->GetGeometry();
97 else
98 geom = AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaultGeometryName());
99
100 if (!geom) AliError("Cannot access geometry!");
101
de39a0ff 102 // digits->Sort();
103
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++)
106 {
107 region[i][j] = 0;
108 posMap[i][j] = -1;
109 }
110
111 for (Int_t i = 0; i < digits->GetEntriesFast(); i++)
916f1e76 112 {
de39a0ff 113 AliEMCALTriggerRawDigit* digit = (AliEMCALTriggerRawDigit*)digits->At(i);
114
115 Int_t id = digit->GetId();
116
117 Int_t iTRU, iADC;
118
119 Bool_t isOK1 = geom->GetTRUFromAbsFastORIndex(id, iTRU, iADC);
120
121 for (Int_t j = 0; j < digit->GetNSamples(); j++)
916f1e76 122 {
de39a0ff 123 Int_t time, amp;
124 Bool_t isOK2 = digit->GetTimeSample(j, time, amp);
916f1e76 125
de39a0ff 126 if (isOK1 && isOK2 && amp) (static_cast<AliEMCALTriggerTRU*>(fTRU->At(iTRU)))->SetADC(iADC, time, amp);
127 }
128
129 Int_t px, py;
130 if (geom->GetPositionInEMCALFromAbsFastORIndex(id, px, py))
131 {
132 posMap[px][py] = i;
916f1e76 133
de39a0ff 134 if (fSTU->GetRawData() && digit->GetL1TimeSum() >= 0)
916f1e76 135 {
de39a0ff 136 region[px][py] = digit->GetL1TimeSum();
916f1e76 137 }
138 }
139 }
916f1e76 140
de39a0ff 141 Int_t iL0 = 0;
916f1e76 142
143 for (Int_t i=0; i<kNTRU; i++)
144 {
de39a0ff 145 AliDebug(999, Form("===========< TRU %2d >============\n", i));
916f1e76 146
de39a0ff 147 AliEMCALTriggerTRU* iTRU = static_cast<AliEMCALTriggerTRU*>(fTRU->At(i));
916f1e76 148
de39a0ff 149 // L0 is always computed from F-ALTRO
150 if (iTRU->L0())
916f1e76 151 {
de39a0ff 152 iL0 += iTRU->L0();
153
ddd131cc 154 Int_t sizeX = (Int_t) ((iTRU->PatchSize())->X() * (iTRU->SubRegionSize())->X());
de39a0ff 155
ddd131cc 156 Int_t sizeY = (Int_t) ((iTRU->PatchSize())->Y() * (iTRU->SubRegionSize())->Y());
de39a0ff 157
158 // transform local to global
159 TIter Next(&iTRU->Patches());
160 while (AliEMCALTriggerPatch* p = (AliEMCALTriggerPatch*)Next())
161 {
162 Int_t px, py, id; p->Position(px, py);
163
164 if (geom->GetAbsFastORIndexFromPositionInTRU(i, px, py, id)
165 &&
166 geom->GetPositionInEMCALFromAbsFastORIndex(id, px, py)) p->SetPosition(px, py);
167
168 if (!data->GetMode())
169 {
170 Int_t peaks = p->Peaks();
171
172 for (Int_t j = 0; j < sizeX * sizeY; j++)
173 {
174 if (peaks & (1 << j))
175 {
176
177 Int_t pos = posMap[px + j % sizeX][py + j / sizeX];
178
179// cout << "px: " << px << " py: " << py << " j: " << j << " mod: " << j%sizeX << " ratio: " << j / sizeX << " pos: " << pos << endl;
180
181 AliEMCALTriggerRawDigit* dig = 0x0;
182
183 if (pos == -1)
184 {
185 new((*digits)[digits->GetEntriesFast()]) AliEMCALTriggerRawDigit(id, 0x0, 0);
186
187 dig = (AliEMCALTriggerRawDigit*)digits->At(digits->GetEntriesFast() - 1);
188 }
189 else
190 {
191 dig = (AliEMCALTriggerRawDigit*)digits->At(pos);
192 }
193
194 dig->SetL0Time(p->Time());
195 }
196 }
197 }
198 }
199
200 data->SetL0Trigger(0, i, 1);
201
202 data->SetPatches(kL0, 0, iTRU->Patches());
203 }
204 else
205 data->SetL0Trigger(0, i, 0);
916f1e76 206 }
207
208 // A L0 has been issued, run L1
de39a0ff 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
211 if (iL0)
916f1e76 212 {
de39a0ff 213 // Use L1 threshold from raw data when reconstructing raw data
214 if (data->GetMode())
215 {
216 fSTU->SetThreshold(kL1Gamma, data->GetL1GammaThreshold());
217 fSTU->SetThreshold(kL1Jet, data->GetL1JetThreshold() );
218 }
219 else
220 {
221 fSTU->ComputeThFromV0(V0M); // C/A
222 data->SetL1GammaThreshold(fSTU->GetThreshold(kL1Gamma));
223 data->SetL1JetThreshold( fSTU->GetThreshold(kL1Jet) );
224 }
916f1e76 225
de39a0ff 226 if (fSTU->GetRawData())
227 {
228 // Compute L1 from STU raw data
229 fSTU->SetRegion(region);
230 }
231 else
232 {
233 // Build STU raw data from F-ALTRO
234 TString str = "region";
235 for (Int_t i = 0; i < kNTRU; i++) fSTU->Build(str,
236 i,
237 (static_cast<AliEMCALTriggerTRU*>(fTRU->At(i)))->Region(),
238 (static_cast<AliEMCALTriggerTRU*>(fTRU->At(i)))->RegionSize());
239 }
916f1e76 240
de39a0ff 241 fSTU->L1(kL1Gamma);
916f1e76 242
de39a0ff 243 data->SetPatches(kL1Gamma, 0, fSTU->Patches());
916f1e76 244
245 fSTU->Reset();
246
de39a0ff 247 fSTU->L1(kL1Jet);
916f1e76 248
de39a0ff 249 data->SetPatches(kL1Jet, 0, fSTU->Patches());
250
251 Int_t** reg = fSTU->Region();
252
253 if (!fSTU->GetRawData())
254 {
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++)
258 {
259 for (Int_t j = 0; j < 64; j++)
260 {
261 if (reg[i][j])
262 {
263 Int_t id;
264 if (geom->GetAbsFastORIndexFromPositionInEMCAL(i, j, id))
265 {
266 AliEMCALTriggerRawDigit* dig = 0x0;
916f1e76 267
de39a0ff 268 if (posMap[i][j] == -1)
269 {
270 // Add a new digit with L1 time sum
271 new((*digits)[digits->GetEntriesFast()]) AliEMCALTriggerRawDigit(id, 0x0, 0);
272
273 dig = (AliEMCALTriggerRawDigit*)digits->At(digits->GetEntriesFast() - 1);
274 }
275 else
276 {
277 dig = (AliEMCALTriggerRawDigit*)digits->At(posMap[i][j]);
278 }
279
280 dig->SetL1TimeSum(reg[i][j]);
281 }
282 }
283 }
284 }
285 }
916f1e76 286 }
287
de39a0ff 288 if (AliDebugLevel() >= 999) data->Scan();
39c05eac 289
916f1e76 290 // Now reset the electronics for a fresh start with next event
291 Reset();
292}
293
294//__________________
295void AliEMCALTriggerElectronics::Reset()
296{
297 //
298 TIter NextTRU(fTRU);
299 while ( AliEMCALTriggerTRU *TRU = (AliEMCALTriggerTRU*)NextTRU() ) TRU->Reset();
300
301 fSTU->Reset();
302}