1 /**************************************************************************
2 * Copyright(c) 2007, 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 **************************************************************************/
18 //This class produces PHOS digits of one event
19 //using AliPHOSRawDecoder.
22 // TClonesArray *digits = new TClonesArray("AliPHOSDigit",100);
23 // AliRawReader* rawReader = new AliRawReaderDate("2006run2211.raw");
24 // AliPHOSRawDecoder dc(rawReader);
25 // while (rawReader->NextEvent()) {
26 // AliPHOSRawDigiProducer producer;
27 // producer.MakeDigits(digits,&dc);
30 // Author: Boris Polichtchouk
32 // --- ROOT system ---
33 #include "TClonesArray.h"
35 // --- AliRoot header files ---
36 #include "AliPHOSRawDigiProducer.h"
37 #include "AliPHOSRawDecoder.h"
38 #include "AliPHOSGeometry.h"
39 #include "AliPHOSDigit.h"
40 #include "AliPHOSRecoParam.h"
41 #include "AliPHOSCalibData.h"
42 #include "AliPHOSPulseGenerator.h"
45 ClassImp(AliPHOSRawDigiProducer)
47 AliPHOSCalibData * AliPHOSRawDigiProducer::fgCalibData = 0 ;
49 //--------------------------------------------------------------------------------------
50 AliPHOSRawDigiProducer::AliPHOSRawDigiProducer():
54 fSampleQualityCut(1.),
55 fGlobalAltroOffset(0),
56 fGlobalAltroThreshold(0),
61 // Default constructor
63 //--------------------------------------------------------------------------------------
64 AliPHOSRawDigiProducer::AliPHOSRawDigiProducer(const AliPHOSRecoParam* recoParam):
68 fSampleQualityCut(1.),
69 fGlobalAltroOffset(0),
70 fGlobalAltroThreshold(0),
75 // Constructor takes paramerters from recoParam
77 if(!recoParam) AliFatal("Reconstruction parameters are not set!");
79 fEmcMinE = recoParam->GetEMCRawDigitThreshold();
80 fCpvMinE = recoParam->GetCPVMinE();
81 fSampleQualityCut = recoParam->GetEMCSampleQualityCut() ;
82 fGlobalAltroOffset = recoParam->GetGlobalAltroOffset() ;
83 fGlobalAltroThreshold = recoParam->GetGlobalAltroThreshold() ;
85 fGeom=AliPHOSGeometry::GetInstance() ;
86 if(!fGeom) fGeom = AliPHOSGeometry::GetInstance("IHEP");
88 fEmcCrystals=fGeom->GetNCristalsInModule()*fGeom->GetNModules() ;
90 fPulseGenerator = new AliPHOSPulseGenerator();
92 GetCalibrationParameters() ;
94 //--------------------------------------------------------------------------------------
95 AliPHOSRawDigiProducer::AliPHOSRawDigiProducer(const AliPHOSRawDigiProducer &dp):
99 fSampleQualityCut(1.),
100 fGlobalAltroOffset(0),
101 fGlobalAltroThreshold(0),
108 fEmcMinE = dp.fEmcMinE ;
109 fCpvMinE = dp.fCpvMinE ;
110 fSampleQualityCut = dp.fSampleQualityCut;
111 fGlobalAltroOffset = dp.fGlobalAltroOffset;
112 fGlobalAltroThreshold = dp.fGlobalAltroThreshold;
113 fEmcCrystals = dp.fEmcCrystals ;
114 fPulseGenerator = new AliPHOSPulseGenerator();
117 //--------------------------------------------------------------------------------------
118 AliPHOSRawDigiProducer& AliPHOSRawDigiProducer::operator= (const AliPHOSRawDigiProducer &dp)
122 if(&dp == this) return *this;
124 fEmcMinE = dp.fEmcMinE ;
125 fCpvMinE = dp.fCpvMinE ;
126 fSampleQualityCut = dp.fSampleQualityCut ;
127 fGlobalAltroOffset = dp.fGlobalAltroOffset ;
128 fGlobalAltroThreshold = dp.fGlobalAltroThreshold ;
129 fEmcCrystals = dp.fEmcCrystals ;
131 if(fPulseGenerator) delete fPulseGenerator ;
132 fPulseGenerator = new AliPHOSPulseGenerator();
135 //--------------------------------------------------------------------------------------
136 AliPHOSRawDigiProducer::~AliPHOSRawDigiProducer()
139 if(fPulseGenerator) delete fPulseGenerator ;
142 //--------------------------------------------------------------------------------------
143 void AliPHOSRawDigiProducer::MakeDigits(TClonesArray *digits, AliPHOSRawDecoder* decoder)
146 //TClonesArray *digits and raw data decoder should be provided by calling function.
151 Int_t relId[4], absId =0;
153 const Double_t baseLine=1. ; //Minimal energy of digit in ADC ch.
154 const Double_t highLowDiff=2.; //Maximal difference between High and Low channels in LG adc channels
156 //Temporary array for LowGain digits
157 TClonesArray tmpLG("AliPHOSDigit",10000) ;
161 //Read current altro offcet from RCU
162 decoder->SetAmpOffset(fGlobalAltroOffset) ;
164 //Read ZS threshold from RCU
165 decoder->SetAmpThreshold(fGlobalAltroThreshold) ;
167 //Let decoder subtract pedestals in case of ZS
168 decoder->SetCalibData(fgCalibData) ;
170 while (decoder->NextDigit()) {
172 Double_t energy=decoder->GetEnergy() ;
173 if(energy<=baseLine) //in ADC channels
176 //remove digits with bad shape. Decoder should calculate quality so that
177 //in default case quality [0,1], while larger values of quality mean somehow
178 //corrupted samples, 999 means obviously corrupted sample.
179 //It is difficult to fit samples with overflow (even setting cut on overflow values)
180 //because too few points are left to fit. So we do not evaluate samples with overflow
181 if(decoder->GetSampleQuality() > fSampleQualityCut && !(decoder->IsOverflow()))
184 Bool_t lowGainFlag = decoder->IsLowGain();
186 relId[0] = decoder->GetModule();
188 relId[2] = decoder->GetRow();
189 relId[3] = decoder->GetColumn();
190 fGeom->RelToAbsNumbering(relId, absId);
192 Double_t time = decoder->GetTime() ;
193 time = CalibrateT(time,relId,lowGainFlag) ;
195 energy = CalibrateE(energy,relId,lowGainFlag) ;
201 new(tmpLG[ilgDigit]) AliPHOSDigit(-1,absId,(Float_t)energy,(Float_t)time);
205 if(decoder->IsOverflow()) //Keep this digit to replace it by Low Gain later.
206 //If there is no LogGain it wil be removed by cut on Min E
207 new((*digits)[iDigit]) AliPHOSDigit(-1,absId,-1.f,(Float_t)time);
209 new((*digits)[iDigit]) AliPHOSDigit(-1,absId,(Float_t)energy,(Float_t)time);
214 //Now scan created LG and HG digits and keep only those which appeared in both lists
215 //replace energy of HighGain digits only if there is overflow
216 //negative energy (overflow)
220 Int_t nLG1 = tmpLG.GetEntriesFast()-1 ;
222 for(Int_t iDig=0 ; iDig < digits->GetEntriesFast() ; iDig++) {
223 AliPHOSDigit * digHG = dynamic_cast<AliPHOSDigit*>(digits->At(iDig)) ;
224 if (!digHG) continue;
225 AliPHOSDigit * digLG = dynamic_cast<AliPHOSDigit*>(tmpLG.At(iLG)) ;
226 while(digLG && iLG<nLG1 && digHG->GetId()> digLG->GetId()){
228 digLG = dynamic_cast<AliPHOSDigit*>(tmpLG.At(iLG)) ;
230 absId=digHG->GetId() ;
231 fGeom->AbsToRelNumbering(absId,relId) ;
233 if(digLG && digHG->GetId() == digLG->GetId()){ //we found pair
234 if(digHG->GetEnergy()<0.){ //This is overflow in HG
235 digHG->SetTime(digLG->GetTime()) ;
236 digHG->SetEnergy(digLG->GetEnergy()) ;
238 else{ //Make approximate comparison of HG and LG energies
239 Double_t de = (digHG->GetEnergy()-digLG->GetEnergy()) ;
240 if(TMath::Abs(de)>CalibrateE(double(highLowDiff),relId,1)){ //too strong difference, remove digit
241 digits->RemoveAt(iDig) ;
245 else{ //no pair - remove
246 // temporary fix for dead LG channels
247 if(relId[2]%2==1 && relId[3]%16==4)
249 if(digHG->GetEnergy()>CalibrateE(double(5.),relId,1)) //One can not always find LG with Amp<5 ADC ch.
250 digits->RemoveAt(iDig) ;
254 CleanDigits(digits) ;
257 //____________________________________________________________________________
258 Double_t AliPHOSRawDigiProducer::CalibrateE(Double_t amp, Int_t* relId, Bool_t isLowGain)
260 // Convert EMC LG amplitude to HG (multipli by ~16)
261 // Calibration parameters are taken from calibration data base
263 Int_t module = relId[0];
264 Int_t column = relId[3];
265 Int_t row = relId[2];
266 if(relId[1]==0) { // this is EMC
268 amp*= fgCalibData->GetHighLowRatioEmc(module,column,row);
275 //____________________________________________________________________________
276 Double_t AliPHOSRawDigiProducer::CalibrateT(Double_t time, Int_t * relId, Bool_t /* isLowGain */)
279 time*=fPulseGenerator->GetRawFormatTimeTrigger() ;
281 Int_t module = relId[0];
282 Int_t column = relId[3];
283 Int_t row = relId[2];
284 if(relId[1]==0) { // this is EMC
285 time += fgCalibData->GetTimeShiftEmc(module,column,row);
292 //____________________________________________________________________________
293 void AliPHOSRawDigiProducer::CleanDigits(TClonesArray * digits)
295 // remove digits with amplitudes below threshold.
296 // remove digits in bad channels
297 // sort digits with icreasing AbsId
299 //remove digits in bad map and below threshold
300 Bool_t isBadMap = 0 ;
301 if(fgCalibData->GetNumOfEmcBadChannels()){
305 for(Int_t i=0; i<digits->GetEntriesFast(); i++){
306 AliPHOSDigit * digit = static_cast<AliPHOSDigit*>(digits->At(i)) ;
309 if ( (IsInEMC(digit) && digit->GetEnergy() < fEmcMinE) ||
310 (IsInCPV(digit) && digit->GetEnergy() < fCpvMinE) ){
311 digits->RemoveAt(i) ;
314 if(isBadMap){ //check bad map now
316 fGeom->AbsToRelNumbering(digit->GetId(), relid) ;
317 if(fgCalibData->IsBadChannelEmc(relid[0],relid[3],relid[2])){
318 digits->RemoveAt(i) ;
323 //Compress, sort and set indexes
325 // digits->Sort(); already sorted earlier
326 for (Int_t i = 0 ; i < digits->GetEntriesFast() ; i++) {
327 AliPHOSDigit *digit = static_cast<AliPHOSDigit*>( digits->At(i) ) ;
328 digit->SetIndexInList(i) ;
331 //____________________________________________________________________________
332 Bool_t AliPHOSRawDigiProducer::IsInEMC(AliPHOSDigit * digit) const
334 // Tells if (true) or not (false) the digit is in a PHOS-EMC module
335 return digit->GetId() <= fEmcCrystals ;
339 //____________________________________________________________________________
340 Bool_t AliPHOSRawDigiProducer::IsInCPV(AliPHOSDigit * digit) const
342 // Tells if (true) or not (false) the digit is in a PHOS-CPV module
343 return digit->GetId() > fEmcCrystals ;
345 //____________________________________________________________________________
346 void AliPHOSRawDigiProducer::GetCalibrationParameters()
348 // Set calibration parameters:
349 // if calibration database exists, they are read from database,
350 // otherwise, reconstruction stops in the constructor of AliPHOSCalibData
352 // It is a user responsilibity to open CDB before reconstruction, for example:
353 // AliCDBStorage* storage = AliCDBManager::Instance()->GetStorage("local://CalibDB");
356 fgCalibData = new AliPHOSCalibData(-1); //use AliCDBManager's run number
358 if (fgCalibData->GetCalibDataEmc() == 0)
359 AliFatal("Calibration parameters for PHOS EMC not found. Stop reconstruction.\n");
360 if (fgCalibData->GetCalibDataCpv() == 0)
361 AliFatal("Calibration parameters for PHOS CPV not found. Stop reconstruction.\n");