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 **************************************************************************/
21 Author: R. GUERNANE LPSC Grenoble CNRS/IN2P3
24 #include "AliEMCALTriggerRawDigitMaker.h"
25 #include "AliEMCALTriggerSTURawStream.h"
26 #include "AliCaloRawAnalyzerFakeALTRO.h"
27 #include "AliEMCALTriggerRawDigit.h"
28 #include "AliCaloRawStreamV3.h"
30 #include "AliRunLoader.h"
32 #include "AliCaloBunchInfo.h"
33 #include "AliRawReader.h"
34 #include "AliEMCALTriggerDCSConfigDB.h"
35 #include "AliEMCALTriggerData.h"
36 #include "AliEMCALTriggerPatch.h"
39 #include "AliRawDataHeader.h"
40 #include "AliRawVEvent.h"
41 #include "AliRawEventHeaderBase.h"
42 #include "AliRawEvent.h"
43 #include "AliRawVEquipment.h"
44 #include "AliRawEquipmentHeader.h"
48 const Int_t kSTUEqId = 4652;
51 ClassImp(AliEMCALTriggerRawDigitMaker)
54 AliEMCALTriggerRawDigitMaker::AliEMCALTriggerRawDigitMaker() : TObject(),
66 AliRunLoader* rl = AliRunLoader::Instance();
67 if (rl && rl->GetAliRun()){
68 AliEMCAL * emcal = dynamic_cast<AliEMCAL*>(rl->GetAliRun()->GetDetector("EMCAL"));
69 if(emcal) fGeometry = emcal->GetGeometry();
74 AliDebug(1, Form("Using default geometry"));
75 fGeometry = AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaultGeometryName());
78 fRawAnalyzer = new AliCaloRawAnalyzerFakeALTRO();
80 fDCSConfig = AliEMCALTriggerDCSConfigDB::Instance();
82 for (Int_t i=0; i<3072; i++) fRawDigitIndex[i] = -1;
86 AliEMCALTriggerRawDigitMaker::~AliEMCALTriggerRawDigitMaker()
92 void AliEMCALTriggerRawDigitMaker::SetIO(AliRawReader* reader, AliCaloRawStreamV3& in, AliEMCALTriggerSTURawStream& inSTU, TClonesArray* digits, AliEMCALTriggerData* data)
98 fSTURawStream = &inSTU;
103 void AliEMCALTriggerRawDigitMaker::Add(const std::vector<AliCaloBunchInfo> &bunchlist)
106 Int_t hwAdd = fCaloRawStream->GetHWAddress();
107 UShort_t iRCU = fCaloRawStream->GetDDLNumber() % 2; // 0/1
108 UShort_t iBranch = ( hwAdd >> 11 ) & 0x1; // 0/1
111 Int_t iTRU = ( (iRCU << 1) | iBranch ) - 1; // 0..2
113 iTRU = (fCaloRawStream->GetModule() % 2) ? 2 * (2 - iTRU) + 1 : 2 * iTRU;
115 iTRU += 6 * int(fCaloRawStream->GetModule()/2);
120 printf("| Hw Adress: 0x%x => SM# %2d / RCU# %d / Branch# %d / TRU# %2d / ADC# %2d\n",
121 hwAdd, fCaloRawStream->GetModule(), iRCU, iBranch, iTRU, fCaloRawStream->GetColumn());
126 AliEMCALTriggerRawDigit* dig = 0x0;
128 Int_t timeSamples[256]; for (Int_t j=0; j<256; j++) timeSamples[j] = 0;
131 UInt_t iBin = bunchlist.at(0).GetStartBin();
134 for (UInt_t i = 0; i < bunchlist.size(); i++)
136 AliCaloBunchInfo bunch = bunchlist.at(i);
138 if (iBin > bunch.GetStartBin())
140 iBin = bunch.GetStartBin();
144 if (fCaloRawStream->GetColumn() < 96)
146 const UShort_t* sig = bunch.GetData();
147 Int_t startBin = bunch.GetStartBin();
149 for (Int_t iS = 0; iS < bunch.GetLength(); iS++)
151 Int_t time = startBin--;
154 if (amp) timeSamples[nSamples++] = ((time << 12) & 0xFF000) | (amp & 0xFFF);
158 printf("ADC# %2d / time: %2d amplitude: %d\n", fCaloRawStream->GetColumn(), time, amp);
164 if (fCaloRawStream->GetColumn() > 95 && fCaloRawStream->GetColumn() < 106)
166 Int_t nBits = (fCaloRawStream->GetColumn() == 105) ? 6 : 10;
168 const UShort_t* sig = bunchlist.at(iBunch).GetData();
170 if (AliDebugLevel()) printf("| L0 id in F-ALTRO => bunch length is: %d\n", bunchlist.at(iBunch).GetLength());
172 for (Int_t i = 0; i < bunchlist.at(iBunch).GetLength(); i++)
174 if (AliDebugLevel()) printf("| sig[%3d]: %x\n",i,sig[i]);
176 for (Int_t j = 0; j < nBits; j++)
178 if (sig[i] & ( 1 << j ))
182 printf("| Add L0 patch index in TRU# %2d position %2d\n",iTRU,(fCaloRawStream->GetColumn() - 96) * 10 + j);
185 if (fGeometry->GetAbsFastORIndexFromTRU(iTRU, (fCaloRawStream->GetColumn() - 96) * 10 + j, idx))
187 if (fRawDigitIndex[idx] >= 0)
189 dig = (AliEMCALTriggerRawDigit*)fRawDigits->At(fRawDigitIndex[idx]);
193 AliDebug(100,"L0: Trying to update trigger info of a non-existent digit!");
195 fRawDigitIndex[idx] = fRawDigits->GetEntriesFast();
196 new((*fRawDigits)[fRawDigits->GetEntriesFast()]) AliEMCALTriggerRawDigit(idx, 0x0, 0);
198 dig = (AliEMCALTriggerRawDigit*)fRawDigits->At(fRawDigitIndex[idx]);
201 dig->SetL0Trigger(1);
202 dig->SetL0Time(iBin);
207 if (fCaloRawStream->GetColumn() == 105 && (sig[i] & (1 << 6)))
209 fTriggerData->SetL0Trigger(1, iTRU, 1);
211 if (AliDebugLevel()) printf("=======TRU# %2d has issued a L0\n",iTRU);
219 if (nSamples && fGeometry->GetAbsFastORIndexFromTRU(iTRU, fCaloRawStream->GetColumn(), idx))
221 if (fRawDigitIndex[idx] < 0)
223 fRawDigitIndex[idx] = fRawDigits->GetEntriesFast();
224 new((*fRawDigits)[fRawDigits->GetEntriesFast()]) AliEMCALTriggerRawDigit(idx, timeSamples, nSamples);
228 dig = (AliEMCALTriggerRawDigit*)fRawDigits->At(fRawDigitIndex[idx]);
229 dig->SetTimeSamples(timeSamples, nSamples);
234 printf("| Add TRG digit of id# %4d from TRU# %2d ADC# %2d\n", idx, iTRU, fCaloRawStream->GetColumn());
236 dig = (AliEMCALTriggerRawDigit*)fRawDigits->At(fRawDigitIndex[idx]);
239 Int_t iSm, iTru, iEta, iPhi, iD[4], iFor;
240 if (fGeometry->GetPositionInTRUFromAbsFastORIndex(idx, iTru, iEta, iPhi))
242 printf("| Position => TRU: %2d Eta: %2d Phi: %2d\n", iTru, iEta, iPhi);
245 if (fGeometry->GetPositionInSMFromAbsFastORIndex(idx, iSm, iEta, iPhi))
247 printf("| Position => SM: %2d Eta: %2d Phi: %2d\n", iSm, iEta, iPhi);
250 if (fGeometry->GetCellIndexFromFastORIndex(idx, iD))
252 printf("| tower iDs: ");
253 for (Int_t i = 0; i < 4; i++)
255 printf("%5d ",iD[i]);
259 for (Int_t i = 0; i < 4; i++)
261 if (fGeometry->GetFastORIndexFromCellIndex(iD[i], iFor))
263 printf("| tower %d to F-OR %d\n",iD[i],iFor);
273 void AliEMCALTriggerRawDigitMaker::PostProcess()
278 AliEMCALTriggerRawDigit* dig = 0x0;
280 Int_t sizeL1gsubr[2], sizeL1gpatch[2], sizeL1jsubr[2], sizeL1jpatch[2];
282 fDCSConfig->GetSTUSegmentation(sizeL1gsubr, sizeL1gpatch, sizeL1jsubr, sizeL1jpatch);
285 fRawReader->Select("EMCAL",44);
287 Bool_t STUin = kFALSE;
289 Int_t nSubEv = fRawReader->GetEvent()->GetNSubEvents();
291 for ( Int_t iSubEv=0; iSubEv<nSubEv; iSubEv++)
293 AliRawVEvent *SubEv = ((AliRawEvent*)fRawReader->GetEvent())->GetSubEvent(iSubEv);
294 if ( !SubEv ) continue;
296 for (Int_t iEquip = 0; iEquip < SubEv->GetNEquipments(); iEquip++)
298 Int_t eqId = SubEv->GetEquipment(iEquip)->GetEquipmentHeader()->GetId();
300 if (eqId == kSTUEqId) STUin = kTRUE;
306 if (STUin && fSTURawStream && fSTURawStream->ReadPayLoad())
308 fTriggerData->SetL1GammaThreshold(fSTURawStream->GetL1GammaThreshold());
309 fTriggerData->SetL1JetThreshold( fSTURawStream->GetL1JetThreshold() );
313 if (fSTURawStream->GetRawData())
315 if (AliDebugLevel()) printf("| STU => TRU raw data are there!\n");
317 for (Int_t i = 0; i < 32; i++)
319 iTRU = fGeometry->GetTRUIndexFromSTUIndex(i);
321 UInt_t adc[96]; for (Int_t j = 0; j < 96; j++) adc[j] = 0;
323 fSTURawStream->GetADC(i, adc);
325 for (Int_t j = 0; j < 96; j++)
327 if (adc[j] < 5) continue;
329 if (AliDebugLevel()) printf("| STU => TRU# %2d raw data: ADC# %2d: %d\n", iTRU, j, adc[j]);
331 fGeometry->GetAbsFastORIndexFromTRU(iTRU, j, idx);
333 if (fRawDigitIndex[idx] >= 0)
335 dig = (AliEMCALTriggerRawDigit*)fRawDigits->At(fRawDigitIndex[idx]);
337 if (!dig->GetNSamples())
338 AliDebug(10,Form("TRG digit of id: %4d found in STU but has 0 sample in F-ALTRO!",idx));
340 dig->SetL1TimeSum(adc[j]);
344 AliDebug(10,Form("TRG digit of id: %4d found in STU but not in F-ALTRO! Create a new digit!",idx));
346 fRawDigitIndex[idx] = fRawDigits->GetEntriesFast();
347 new((*fRawDigits)[fRawDigits->GetEntriesFast()]) AliEMCALTriggerRawDigit(idx, 0x0, 0);
349 dig = (AliEMCALTriggerRawDigit*)fRawDigits->At(fRawDigitIndex[idx]);
350 dig->SetL1TimeSum(adc[j]);
356 // List of patches in EMCal coordinate system
357 TClonesArray* patches = new TClonesArray("AliEMCALTriggerPatch", 96);
359 for (Int_t i = 0; i < fSTURawStream->GetNL0GammaPatch(); i++)
361 fSTURawStream->GetL0GammaPatch(i, iTRU, x);
363 iTRU = fGeometry->GetTRUIndexFromSTUIndex(iTRU);
365 if (AliDebugLevel()) printf("| STU => Found L0 patch id: %2d in TRU# %2d\n", x, iTRU);
367 const Int_t sizePatchL0 = fDCSConfig->GetTRUSegmentation(i) * fDCSConfig->GetTRUSegmentation(i);
369 Int_t* idFastOR = new Int_t[sizePatchL0];
371 for (Int_t j = 0; j < sizePatchL0; j++) idFastOR[j] = -1;
373 if (fGeometry->GetFastORIndexFromL0Index(iTRU, x, idFastOR, sizePatchL0))
376 if (fGeometry->GetPositionInEMCALFromAbsFastORIndex(idFastOR[1], px, py))
378 new((*patches)[patches->GetEntriesFast()]) AliEMCALTriggerPatch(px, py);
380 if (AliDebugLevel()) printf("| STU => Add L0 patch at (%2d , %2d)\n", px, py);
387 fTriggerData->SetPatches(kL0, 1, *patches);
391 for (Int_t i = 0; i < fSTURawStream->GetNL1GammaPatch(); i++)
393 if (fSTURawStream->GetL1GammaPatch(i, iTRU, x, y)) // col (0..23), row (0..3)
395 iTRU = fGeometry->GetTRUIndexFromSTUIndex(iTRU);
397 if (AliDebugLevel()) printf("| STU => Found L1 gamma patch at (%2d , %2d) in TRU# %2d\n", x, y, iTRU);
399 Int_t vx = 23 - x, vy = y + 4 * int(iTRU / 2); // Position in EMCal frame
401 if (iTRU % 2) vx += 24; // C side
403 vx = vx - sizeL1gsubr[0] * sizeL1gpatch[0] + 1;
407 new((*patches)[patches->GetEntriesFast()]) AliEMCALTriggerPatch(vx, vy);
409 if (AliDebugLevel()) printf("| STU => Add L1 gamma patch at (%2d , %2d)\n", vx, vy);
414 fTriggerData->SetPatches(kL1Gamma, 1, *patches);
418 for (Int_t i = 0; i < fSTURawStream->GetNL1JetPatch(); i++)
420 if (fSTURawStream->GetL1JetPatch(i, x, y)) // col (0,15), row (0,11)
422 if (AliDebugLevel()) printf("| STU => Found L1 jet patch at (%2d , %2d)\n", x, y);
424 Int_t ix = sizeL1jsubr[0] * (11 - y - sizeL1jpatch[0] + 1);
426 Int_t iy = sizeL1jsubr[1] * (15 - x - sizeL1jpatch[1] + 1);
428 // FIXME: x = 0 || y = 0 (Olivier's CS) patches a lost?
430 if (ix >= 0 && iy >= 0)
432 new((*patches)[patches->GetEntriesFast()]) AliEMCALTriggerPatch(ix, iy);
434 if (AliDebugLevel()) printf("| STU => Add L1 jet patch at (%2d , %2d)\n", ix, iy);
439 fTriggerData->SetPatches(kL1Jet, 1, *patches);
448 void AliEMCALTriggerRawDigitMaker::Reset()
451 for (Int_t i = 0; i < 3072; i++) fRawDigitIndex[i] = -1;