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 "AliEMCALTriggerDCSConfig.h"
36 #include "AliEMCALTriggerTRUDCSConfig.h"
37 #include "AliEMCALTriggerSTUDCSConfig.h"
38 #include "AliEMCALTriggerData.h"
39 #include "AliEMCALTriggerPatch.h"
42 #include "AliRawDataHeader.h"
43 #include "AliRawVEvent.h"
44 #include "AliRawEventHeaderBase.h"
45 #include "AliRawEvent.h"
46 #include "AliRawVEquipment.h"
47 #include "AliRawEquipmentHeader.h"
49 #include "Riostream.h"
51 #include "AliCaloRawAnalyzerFactory.h"
55 const Int_t kSTUEqId = 4652;
58 ClassImp(AliEMCALTriggerRawDigitMaker)
61 AliEMCALTriggerRawDigitMaker::AliEMCALTriggerRawDigitMaker() : TObject(),
73 AliRunLoader* rl = AliRunLoader::Instance();
74 if (rl && rl->GetAliRun()){
75 AliEMCAL * emcal = dynamic_cast<AliEMCAL*>(rl->GetAliRun()->GetDetector("EMCAL"));
76 if(emcal) fGeometry = emcal->GetGeometry();
81 AliDebug(1, Form("Using default geometry"));
82 fGeometry = AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaultGeometryName());
85 // fRawAnalyzer = new AliCaloRawAnalyzerFakeALTRO ();
87 fRawAnalyzer = (AliCaloRawAnalyzerFakeALTRO*)AliCaloRawAnalyzerFactory::CreateAnalyzer(kFakeAltro);
89 fDCSConfig = AliEMCALTriggerDCSConfigDB::Instance();
91 Int_t nRawDigits = fGeometry->GetNTotalTRU() * 96;
92 for (Int_t i=0; i<nRawDigits; i++) fRawDigitIndex[i] = -1;
96 AliEMCALTriggerRawDigitMaker::~AliEMCALTriggerRawDigitMaker()
102 void AliEMCALTriggerRawDigitMaker::SetIO(AliRawReader* reader, AliCaloRawStreamV3& in, AliEMCALTriggerSTURawStream& inSTU, TClonesArray* digits, AliEMCALTriggerData* data)
107 fCaloRawStream = ∈
109 fSTURawStream = &inSTU;
114 void AliEMCALTriggerRawDigitMaker::Add(const std::vector<AliCaloBunchInfo> &bunchlist)
118 Int_t hwAdd = fCaloRawStream->GetHWAddress();
119 UShort_t iRCU = fCaloRawStream->GetDDLNumber() % 2; // 0/1
120 UShort_t iBranch = ( hwAdd >> 11 ) & 0x1; // 0/1
123 Int_t iTRU = ( (iRCU << 1) | iBranch ) - 1; // 0..2
125 iTRU = (fCaloRawStream->GetModule() % 2) ? 2 * (2 - iTRU) + 1 : 2 * iTRU;
127 iTRU += 6 * int(fCaloRawStream->GetModule()/2);
132 printf("| Hw Adress: 0x%x => SM# %2d / RCU# %d / Branch# %d / TRU# %2d / ADC# %2d\n",
133 hwAdd, fCaloRawStream->GetModule(), iRCU, iBranch, iTRU, fCaloRawStream->GetColumn());
138 AliEMCALTriggerRawDigit* dig = 0x0;
140 Int_t timeSamples[256]; for (Int_t j=0; j<256; j++) timeSamples[j] = 0;
143 UInt_t iBin = bunchlist.at(0).GetStartBin();
146 for (UInt_t i = 0; i < bunchlist.size(); i++)
148 AliCaloBunchInfo bunch = bunchlist.at(i);
150 if (iBin > bunch.GetStartBin())
152 iBin = bunch.GetStartBin();
156 if (fCaloRawStream->GetColumn() < 96)
158 const UShort_t* sig = bunch.GetData();
159 Int_t startBin = bunch.GetStartBin();
161 for (Int_t iS = 0; iS < bunch.GetLength(); iS++)
163 Int_t time = startBin--;
166 if (amp) timeSamples[nSamples++] = ((time << 12) & 0xFF000) | (amp & 0xFFF);
170 printf("ADC# %2d / time: %2d amplitude: %d\n", fCaloRawStream->GetColumn(), time, amp);
176 if (fCaloRawStream->GetColumn() > 95 && fCaloRawStream->GetColumn() < 106)
178 Int_t nBits = (fCaloRawStream->GetColumn() == 105) ? 6 : 10;
180 const UShort_t* sig = bunchlist.at(iBunch).GetData();
182 if (AliDebugLevel()) printf("| L0 id in F-ALTRO => bunch length is: %d\n", bunchlist.at(iBunch).GetLength());
184 for (Int_t i = 0; i < bunchlist.at(iBunch).GetLength(); i++)
186 if (AliDebugLevel()) printf("| sig[%3d]: %x\n",i,sig[i]);
188 for (Int_t j = 0; j < nBits; j++)
190 if (sig[i] & ( 1 << j ))
194 printf("| Add L0 patch index in TRU# %2d position %2d\n",iTRU,(fCaloRawStream->GetColumn() - 96) * 10 + j);
197 if (fGeometry->GetAbsFastORIndexFromTRU(iTRU, (fCaloRawStream->GetColumn() - 96) * 10 + j, idx))
199 if (fRawDigitIndex[idx] >= 0)
201 dig = (AliEMCALTriggerRawDigit*)fRawDigits->At(fRawDigitIndex[idx]);
205 AliDebug(100,"L0: Trying to update trigger info of a non-existent digit!");
207 fRawDigitIndex[idx] = fRawDigits->GetEntriesFast();
208 new((*fRawDigits)[fRawDigits->GetEntriesFast()]) AliEMCALTriggerRawDigit(idx, 0x0, 0);
210 dig = (AliEMCALTriggerRawDigit*)fRawDigits->At(fRawDigitIndex[idx]);
213 dig->SetL0Time(iBin);
218 if (fCaloRawStream->GetColumn() == 105 && (sig[i] & (1 << 6)))
220 fTriggerData->SetL0Trigger(1, iTRU, 1);
222 if (AliDebugLevel()) printf("=======TRU# %2d has issued a L0\n",iTRU);
230 if (nSamples && fGeometry->GetAbsFastORIndexFromTRU(iTRU, fCaloRawStream->GetColumn(), idx))
232 if (fRawDigitIndex[idx] < 0)
234 fRawDigitIndex[idx] = fRawDigits->GetEntriesFast();
235 new((*fRawDigits)[fRawDigits->GetEntriesFast()]) AliEMCALTriggerRawDigit(idx, timeSamples, nSamples);
239 dig = (AliEMCALTriggerRawDigit*)fRawDigits->At(fRawDigitIndex[idx]);
240 dig->SetTimeSamples(timeSamples, nSamples);
245 printf("| Add TRG digit of id# %4d from TRU# %2d ADC# %2d\n", idx, iTRU, fCaloRawStream->GetColumn());
247 dig = (AliEMCALTriggerRawDigit*)fRawDigits->At(fRawDigitIndex[idx]);
250 Int_t iSm, iTru, iEta, iPhi, iD[4], iFor;
251 if (fGeometry->GetPositionInTRUFromAbsFastORIndex(idx, iTru, iEta, iPhi))
253 printf("| Position => TRU: %2d Eta: %2d Phi: %2d\n", iTru, iEta, iPhi);
256 if (fGeometry->GetPositionInSMFromAbsFastORIndex(idx, iSm, iEta, iPhi))
258 printf("| Position => SM: %2d Eta: %2d Phi: %2d\n", iSm, iEta, iPhi);
261 if (fGeometry->GetCellIndexFromFastORIndex(idx, iD))
263 printf("| tower iDs: ");
264 for (Int_t i = 0; i < 4; i++)
266 printf("%5d ",iD[i]);
270 for (Int_t i = 0; i < 4; i++)
272 if (fGeometry->GetFastORIndexFromCellIndex(iD[i], iFor))
274 printf("| tower %d to F-OR %d\n",iD[i],iFor);
284 void AliEMCALTriggerRawDigitMaker::PostProcess()
286 // Post process digits
288 AliDebug(2,"Start post processing the raw digit maker");
291 AliEMCALTriggerRawDigit* dig = 0x0;
293 TVector2 sizeL1gsubr, sizeL1gpatch, sizeL1jsubr, sizeL1jpatch;
295 fDCSConfig->GetTriggerDCSConfig()->GetSTUDCSConfig()->GetSegmentation(sizeL1gsubr, sizeL1gpatch, sizeL1jsubr, sizeL1jpatch);
298 fRawReader->Select("EMCAL",44);
300 Bool_t isSTUin = kFALSE;
302 Int_t nSubEv = fRawReader->GetEvent()->GetNSubEvents();
304 for ( Int_t iSubEv=0; iSubEv<nSubEv; iSubEv++)
306 AliRawVEvent *subEv = ((AliRawEvent*)fRawReader->GetEvent())->GetSubEvent(iSubEv);
307 if ( !subEv ) continue;
309 for (Int_t iEquip = 0; iEquip < subEv->GetNEquipments(); iEquip++)
311 Int_t eqId = subEv->GetEquipment(iEquip)->GetEquipmentHeader()->GetId();
313 if (eqId == kSTUEqId) isSTUin = kTRUE;
319 if (isSTUin && fSTURawStream && fSTURawStream->ReadPayLoad())
321 fTriggerData->SetL1DataDecoded(1);
323 for (int i = 0; i < 2; i++) {
324 fTriggerData->SetL1GammaThreshold(i, fSTURawStream->GetL1GammaThreshold(i));
325 fTriggerData->SetL1JetThreshold( i, fSTURawStream->GetL1JetThreshold(i) );
328 Int_t v0[2] = {fSTURawStream->GetV0A(), fSTURawStream->GetV0C()};
332 fSTURawStream->GetG(0, 0),
333 fSTURawStream->GetG(1, 0),
334 fSTURawStream->GetG(2, 0),
335 fSTURawStream->GetJ(0, 0),
336 fSTURawStream->GetJ(1, 0),
337 fSTURawStream->GetJ(2, 0),
338 fSTURawStream->GetG(0, 1),
339 fSTURawStream->GetG(1, 1),
340 fSTURawStream->GetG(2, 1),
341 fSTURawStream->GetJ(0, 1),
342 fSTURawStream->GetJ(1, 1),
343 fSTURawStream->GetJ(2, 1),
344 fSTURawStream->GetRawData(),
345 fSTURawStream->GetRegionEnable(),
346 fSTURawStream->GetFwVersion()
349 // Modify DCS config from STU payload content
350 fDCSConfig->GetTriggerDCSConfig()->GetSTUDCSConfig()->SetG(0, 0, type[0]);
351 fDCSConfig->GetTriggerDCSConfig()->GetSTUDCSConfig()->SetG(1, 0, type[1]);
352 fDCSConfig->GetTriggerDCSConfig()->GetSTUDCSConfig()->SetG(2, 0, type[2]);
353 fDCSConfig->GetTriggerDCSConfig()->GetSTUDCSConfig()->SetJ(0, 0, type[3]);
354 fDCSConfig->GetTriggerDCSConfig()->GetSTUDCSConfig()->SetJ(1, 0, type[4]);
355 fDCSConfig->GetTriggerDCSConfig()->GetSTUDCSConfig()->SetJ(2, 0, type[5]);
356 fDCSConfig->GetTriggerDCSConfig()->GetSTUDCSConfig()->SetG(0, 1, type[6]);
357 fDCSConfig->GetTriggerDCSConfig()->GetSTUDCSConfig()->SetG(1, 1, type[7]);
358 fDCSConfig->GetTriggerDCSConfig()->GetSTUDCSConfig()->SetG(2, 1, type[8]);
359 fDCSConfig->GetTriggerDCSConfig()->GetSTUDCSConfig()->SetJ(0, 1, type[9]);
360 fDCSConfig->GetTriggerDCSConfig()->GetSTUDCSConfig()->SetJ(1, 1, type[10]);
361 fDCSConfig->GetTriggerDCSConfig()->GetSTUDCSConfig()->SetJ(2, 1, type[11]);
362 fDCSConfig->GetTriggerDCSConfig()->GetSTUDCSConfig()->SetRawData(type[12]);
363 fDCSConfig->GetTriggerDCSConfig()->GetSTUDCSConfig()->SetRegion(type[13]);
364 fDCSConfig->GetTriggerDCSConfig()->GetSTUDCSConfig()->SetFw(type[14]);
366 fTriggerData->SetL1FrameMask(fSTURawStream->GetFrameReceived());
367 fTriggerData->SetL1V0(v0);
368 fTriggerData->SetL1TriggerType(type);
370 fTriggerData->SetL1RawData(fSTURawStream->GetRawData());
374 if (fSTURawStream->GetRawData())
376 if (AliDebugLevel()) printf("| STU => TRU raw data are there!\n");
378 Int_t nTRU = fGeometry->GetNTotalTRU();
379 for (Int_t i = 0; i < nTRU; i++)
381 iTRU = fGeometry->GetTRUIndexFromSTUIndex(i);
383 UInt_t adc[96]; for (Int_t j = 0; j < 96; j++) adc[j] = 0;
385 fSTURawStream->GetADC(i, adc);
387 for (Int_t j = 0; j < 96; j++)
389 if (adc[j] <= 0) continue;
391 AliDebug(10,Form("| STU => TRU# %2d raw data: ADC# %2d: %d\n", iTRU, j, adc[j]));
393 fGeometry->GetAbsFastORIndexFromTRU(iTRU, j, idx);
395 if (fRawDigitIndex[idx] >= 0)
397 dig = (AliEMCALTriggerRawDigit*)fRawDigits->At(fRawDigitIndex[idx]);
399 if (!dig->GetNSamples()) AliDebug(10,Form("TRG digit of id: %4d found in STU but has no time sample in F-ALTRO!",idx));
403 AliDebug(10,Form("TRG digit of id: %4d found in STU but not in F-ALTRO! Create a new digit!",idx));
405 fRawDigitIndex[idx] = fRawDigits->GetEntriesFast();
406 new((*fRawDigits)[fRawDigits->GetEntriesFast()]) AliEMCALTriggerRawDigit(idx, 0x0, 0);
408 dig = (AliEMCALTriggerRawDigit*)fRawDigits->At(fRawDigitIndex[idx]);
411 dig->SetL1TimeSum(adc[j]);
416 // List of patches in EMCal coordinate system
418 for (Int_t i = 0; i < fSTURawStream->GetNL0GammaPatch(); i++)
420 fSTURawStream->GetL0GammaPatch(i, iTRU, x);
422 iTRU = fGeometry->GetTRUIndexFromSTUIndex(iTRU);
424 const Int_t sizePatchL0 =
425 ((AliEMCALTriggerTRUDCSConfig*)fDCSConfig->GetTriggerDCSConfig()->GetTRUArr()->At(fGeometry->GetOnlineIndexFromTRUIndex(iTRU)))->GetSegmentation()
427 ((AliEMCALTriggerTRUDCSConfig*)fDCSConfig->GetTriggerDCSConfig()->GetTRUArr()->At(fGeometry->GetOnlineIndexFromTRUIndex(iTRU)))->GetSegmentation();
429 if (AliDebugLevel()) printf("| STU => Found L0 patch id: %2d in TRU# %2d\n", x, iTRU);
432 for (Int_t j = 0; j < 4; j++) idFastOR[j] = -1;
434 if (fGeometry->GetFastORIndexFromL0Index(iTRU, x, idFastOR, sizePatchL0))
439 if (fGeometry->GetPositionInEMCALFromAbsFastORIndex(idx, px, py))
441 if (AliDebugLevel()) printf("| STU => Add L0 patch at (%2d , %2d)\n", px, py);
443 if (fRawDigitIndex[idx] >= 0)
445 dig = (AliEMCALTriggerRawDigit*)fRawDigits->At(fRawDigitIndex[idx]);
449 fRawDigitIndex[idx] = fRawDigits->GetEntriesFast();
450 new((*fRawDigits)[fRawDigits->GetEntriesFast()]) AliEMCALTriggerRawDigit(idx, 0x0, 0);
452 dig = (AliEMCALTriggerRawDigit*)fRawDigits->At(fRawDigitIndex[idx]);
455 dig->SetTriggerBit(kL0,1);
460 for (int ithr = 0; ithr < 2; ithr++) {
462 for (Int_t i = 0; i < fSTURawStream->GetNL1GammaPatch(ithr); i++)
464 if (fSTURawStream->GetL1GammaPatch(i, ithr, iTRU, x, y)) // col (0..23), row (0..3)
466 iTRU = fGeometry->GetTRUIndexFromSTUIndex(iTRU);
468 if (AliDebugLevel()) printf("| STU => Found L1 gamma patch at (%2d , %2d) in TRU# %2d\n", x, y, iTRU);
470 Int_t vx = 23 - x, vy = y + 4 * int(iTRU / 2); // Position in EMCal frame
472 if (iTRU % 2) vx += 24; // C side
474 vx = vx - int(sizeL1gsubr.X()) * int(sizeL1gpatch.X()) + 1;
476 if (vx >= 0 && vy < 63)
478 if (fGeometry->GetAbsFastORIndexFromPositionInEMCAL(vx, vy, idx))
480 if (AliDebugLevel()) printf("| STU => Add L1 gamma [%d] patch at (%2d , %2d)\n", ithr, vx, vy);
482 if (fRawDigitIndex[idx] >= 0)
484 dig = (AliEMCALTriggerRawDigit*)fRawDigits->At(fRawDigitIndex[idx]);
488 fRawDigitIndex[idx] = fRawDigits->GetEntriesFast();
489 new((*fRawDigits)[fRawDigits->GetEntriesFast()]) AliEMCALTriggerRawDigit(idx, 0x0, 0);
491 dig = (AliEMCALTriggerRawDigit*)fRawDigits->At(fRawDigitIndex[idx]);
494 dig->SetTriggerBit(kL1GammaHigh + ithr,1);
500 for (Int_t i = 0; i < fSTURawStream->GetNL1JetPatch(ithr); i++)
502 if (fSTURawStream->GetL1JetPatch(i, ithr, x, y)) // col (0,15), row (0,11)
504 AliDebug(1, Form("| STU => Found L1 jet [%d] patch at (%2d , %2d)\n", ithr, x, y));
506 Int_t ix = int(sizeL1jsubr.X()) * (11 - y - int(sizeL1jpatch.X()) + 1);
508 Int_t iy = int(sizeL1jsubr.Y()) * (15 - x - int(sizeL1jpatch.Y()) + 1);
510 if (ix >= 0 && iy >= 0)
512 if (fGeometry->GetAbsFastORIndexFromPositionInEMCAL(ix, iy, idx))
514 if (AliDebugLevel()) printf("| STU => Add L1 jet patch at (%2d , %2d)\n", ix, iy);
516 if (fRawDigitIndex[idx] >= 0)
518 dig = (AliEMCALTriggerRawDigit*)fRawDigits->At(fRawDigitIndex[idx]);
522 fRawDigitIndex[idx] = fRawDigits->GetEntriesFast();
523 new((*fRawDigits)[fRawDigits->GetEntriesFast()]) AliEMCALTriggerRawDigit(idx, 0x0, 0);
525 dig = (AliEMCALTriggerRawDigit*)fRawDigits->At(fRawDigitIndex[idx]);
528 dig->SetTriggerBit(kL1JetHigh + ithr,1);
538 void AliEMCALTriggerRawDigitMaker::Reset()
542 Int_t nRawDigits = fGeometry->GetNTotalTRU() * 96;
543 for (Int_t i = 0; i < nRawDigits; i++) fRawDigitIndex[i] = -1;