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.),
59 // Default constructor
61 //--------------------------------------------------------------------------------------
62 AliPHOSRawDigiProducer::AliPHOSRawDigiProducer(const AliPHOSRecoParam* recoParam):
66 fSampleQualityCut(1.),
71 // Constructor takes paramerters from recoParam
73 if(!recoParam) AliFatal("Reconstruction parameters are not set!");
75 fEmcMinE = recoParam->GetEMCMinE();
76 fCpvMinE = recoParam->GetCPVMinE();
78 fSampleQualityCut = recoParam->GetEMCSampleQualityCut() ;
80 fGeom=AliPHOSGeometry::GetInstance() ;
81 if(!fGeom) fGeom = AliPHOSGeometry::GetInstance("IHEP");
83 fEmcCrystals=fGeom->GetNCristalsInModule()*fGeom->GetNModules() ;
85 fPulseGenerator = new AliPHOSPulseGenerator();
87 GetCalibrationParameters() ;
89 //--------------------------------------------------------------------------------------
90 AliPHOSRawDigiProducer::AliPHOSRawDigiProducer(const AliPHOSRawDigiProducer &dp):
94 fSampleQualityCut(1.),
101 fEmcMinE = dp.fEmcMinE ;
102 fCpvMinE = dp.fCpvMinE ;
103 fEmcCrystals = dp.fEmcCrystals ;
104 fPulseGenerator = new AliPHOSPulseGenerator();
107 //--------------------------------------------------------------------------------------
108 AliPHOSRawDigiProducer& AliPHOSRawDigiProducer::operator= (const AliPHOSRawDigiProducer &dp)
112 if(&dp == this) return *this;
114 fEmcMinE = dp.fEmcMinE ;
115 fCpvMinE = dp.fCpvMinE ;
116 fSampleQualityCut = dp.fSampleQualityCut ;
117 fEmcCrystals = dp.fEmcCrystals ;
119 if(fPulseGenerator) delete fPulseGenerator ;
120 fPulseGenerator = new AliPHOSPulseGenerator();
123 //--------------------------------------------------------------------------------------
124 AliPHOSRawDigiProducer::~AliPHOSRawDigiProducer()
127 if(fPulseGenerator) delete fPulseGenerator ;
130 //--------------------------------------------------------------------------------------
131 void AliPHOSRawDigiProducer::MakeDigits(TClonesArray *digits, AliPHOSRawDecoder* decoder)
134 //TClonesArray *digits and raw data decoder should be provided by calling function.
139 Int_t relId[4], absId =0;
141 const Double_t baseLine=1. ; //Minimal energy of digit in ADC ch.
142 const Double_t highLowDiff=2.; //Maximal difference between High and Low channels in LG adc channels
144 //Temporary array for LowGain digits
145 TClonesArray tmpLG("AliPHOSDigit",10000) ;
148 while (decoder->NextDigit()) {
150 Double_t energy=decoder->GetEnergy() ;
151 if(energy<=baseLine) //in ADC channels
154 //remove digits with bad shape. Decoder should calculate quality so that
155 //in default case quality [0,1], while larger values of quality mean somehow
156 //corrupted samples, 999 means obviously corrupted sample.
157 //It is difficult to fit samples with overflow (even setting cut on overflow values)
158 //because too few points are left to fit. So we do not evaluate samples with overflow
159 if(decoder->GetSampleQuality() > fSampleQualityCut && !(decoder->IsOverflow()))
162 Bool_t lowGainFlag = decoder->IsLowGain();
164 relId[0] = decoder->GetModule();
166 relId[2] = decoder->GetRow();
167 relId[3] = decoder->GetColumn();
168 fGeom->RelToAbsNumbering(relId, absId);
170 Double_t time = decoder->GetTime() ;
171 time = CalibrateT(time,relId,lowGainFlag) ;
173 energy = CalibrateE(energy,relId,lowGainFlag) ;
179 new(tmpLG[ilgDigit]) AliPHOSDigit(-1,absId,(Float_t)energy,(Float_t)time);
183 if(decoder->IsOverflow()) //Keep this digit to replace it by Low Gain later.
184 //If there is no LogGain it wil be removed by cut on Min E
185 new((*digits)[iDigit]) AliPHOSDigit(-1,absId,-1.f,(Float_t)time);
187 new((*digits)[iDigit]) AliPHOSDigit(-1,absId,(Float_t)energy,(Float_t)time);
192 //Now scan created LG and HG digits and keep only those which appeared in both lists
193 //replace energy of HighGain digits only if there is overflow
194 //negative energy (overflow)
198 Int_t nLG1 = tmpLG.GetEntriesFast()-1 ;
200 for(Int_t iDig=0 ; iDig < digits->GetEntriesFast() ; iDig++) {
201 AliPHOSDigit * digHG = dynamic_cast<AliPHOSDigit*>(digits->At(iDig)) ;
202 if (!digHG) continue;
203 AliPHOSDigit * digLG = dynamic_cast<AliPHOSDigit*>(tmpLG.At(iLG)) ;
204 while(digLG && iLG<nLG1 && digHG->GetId()> digLG->GetId()){
206 digLG = dynamic_cast<AliPHOSDigit*>(tmpLG.At(iLG)) ;
208 absId=digHG->GetId() ;
209 fGeom->AbsToRelNumbering(absId,relId) ;
211 if(digLG && digHG->GetId() == digLG->GetId()){ //we found pair
212 if(digHG->GetEnergy()<0.){ //This is overflow in HG
213 digHG->SetTime(digLG->GetTime()) ;
214 digHG->SetEnergy(digLG->GetEnergy()) ;
216 else{ //Make approximate comparison of HG and LG energies
217 Double_t de = (digHG->GetEnergy()-digLG->GetEnergy()) ;
218 if(TMath::Abs(de)>CalibrateE(double(highLowDiff),relId,1)){ //too strong difference, remove digit
219 digits->RemoveAt(iDig) ;
223 else{ //no pair - remove
224 // temporary fix for dead LG channels
225 if(relId[2]%2==1 && relId[3]%16==4)
227 if(digHG->GetEnergy()>CalibrateE(double(5.),relId,1)) //One can not always find LG with Amp<5 ADC ch.
228 digits->RemoveAt(iDig) ;
232 CleanDigits(digits) ;
235 //____________________________________________________________________________
236 Double_t AliPHOSRawDigiProducer::CalibrateE(Double_t amp, Int_t* relId, Bool_t isLowGain)
238 // Convert EMC measured amplitude into real energy.
239 // Calibration parameters are taken from calibration data base for raw data,
240 // or from digitizer parameters for simulated data.
242 Int_t module = relId[0];
243 Int_t column = relId[3];
244 Int_t row = relId[2];
245 if(relId[1]==0) { // this is EMC
247 amp*= fgCalibData->GetHighLowRatioEmc(module,column,row);
249 amp *= fgCalibData->GetADCchannelEmc(module,column,row);
255 //____________________________________________________________________________
256 Double_t AliPHOSRawDigiProducer::CalibrateT(Double_t time, Int_t * relId, Bool_t /* isLowGain */)
259 time*=fPulseGenerator->GetRawFormatTimeTrigger() ;
261 Int_t module = relId[0];
262 Int_t column = relId[3];
263 Int_t row = relId[2];
264 if(relId[1]==0) { // this is EMC
265 time += fgCalibData->GetTimeShiftEmc(module,column,row);
272 //____________________________________________________________________________
273 void AliPHOSRawDigiProducer::CleanDigits(TClonesArray * digits)
275 // remove digits with amplitudes below threshold.
276 // remove digits in bad channels
277 // sort digits with icreasing AbsId
279 //remove digits in bad map and below threshold
280 Bool_t isBadMap = 0 ;
281 if(fgCalibData->GetNumOfEmcBadChannels()){
285 for(Int_t i=0; i<digits->GetEntriesFast(); i++){
286 AliPHOSDigit * digit = static_cast<AliPHOSDigit*>(digits->At(i)) ;
289 if ( (IsInEMC(digit) && digit->GetEnergy() < fEmcMinE) ||
290 (IsInCPV(digit) && digit->GetEnergy() < fCpvMinE) ){
291 digits->RemoveAt(i) ;
294 if(isBadMap){ //check bad map now
296 fGeom->AbsToRelNumbering(digit->GetId(), relid) ;
297 if(fgCalibData->IsBadChannelEmc(relid[0],relid[3],relid[2])){
298 digits->RemoveAt(i) ;
303 //Compress, sort and set indexes
305 // digits->Sort(); already sorted earlier
306 for (Int_t i = 0 ; i < digits->GetEntriesFast() ; i++) {
307 AliPHOSDigit *digit = static_cast<AliPHOSDigit*>( digits->At(i) ) ;
308 digit->SetIndexInList(i) ;
311 //____________________________________________________________________________
312 Bool_t AliPHOSRawDigiProducer::IsInEMC(AliPHOSDigit * digit) const
314 // Tells if (true) or not (false) the digit is in a PHOS-EMC module
315 return digit->GetId() <= fEmcCrystals ;
319 //____________________________________________________________________________
320 Bool_t AliPHOSRawDigiProducer::IsInCPV(AliPHOSDigit * digit) const
322 // Tells if (true) or not (false) the digit is in a PHOS-CPV module
323 return digit->GetId() > fEmcCrystals ;
325 //____________________________________________________________________________
326 void AliPHOSRawDigiProducer::GetCalibrationParameters()
328 // Set calibration parameters:
329 // if calibration database exists, they are read from database,
330 // otherwise, reconstruction stops in the constructor of AliPHOSCalibData
332 // It is a user responsilibity to open CDB before reconstruction, for example:
333 // AliCDBStorage* storage = AliCDBManager::Instance()->GetStorage("local://CalibDB");
336 fgCalibData = new AliPHOSCalibData(-1); //use AliCDBManager's run number
338 if (fgCalibData->GetCalibDataEmc() == 0)
339 AliFatal("Calibration parameters for PHOS EMC not found. Stop reconstruction.\n");
340 if (fgCalibData->GetCalibDataCpv() == 0)
341 AliFatal("Calibration parameters for PHOS CPV not found. Stop reconstruction.\n");