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():TObject(),
51 fEmcMinE(0.),fCpvMinE(0.),fSampleQualityCut(1.),
52 fEmcCrystals(0),fGeom(0),fPulseGenerator(0){
55 //--------------------------------------------------------------------------------------
56 AliPHOSRawDigiProducer::AliPHOSRawDigiProducer(const AliPHOSRecoParam* parEmc, const AliPHOSRecoParam* parCpv):TObject(),
57 fEmcMinE(0.),fCpvMinE(0.),fSampleQualityCut(1.),fEmcCrystals(0),fGeom(0),fPulseGenerator(0){
59 if(!parEmc) AliFatal("Reconstruction parameters for EMC not set!");
60 if(!parCpv) AliFatal("Reconstruction parameters for CPV not set!");
62 fEmcMinE = parEmc->GetMinE();
63 fCpvMinE = parCpv->GetMinE();
65 fSampleQualityCut = parEmc->GetSampleQualityCut() ;
67 fGeom=AliPHOSGeometry::GetInstance() ;
68 if(!fGeom) fGeom = AliPHOSGeometry::GetInstance("IHEP");
70 fEmcCrystals=fGeom->GetNCristalsInModule()*fGeom->GetNModules() ;
72 fPulseGenerator = new AliPHOSPulseGenerator();
74 GetCalibrationParameters() ;
76 //--------------------------------------------------------------------------------------
77 AliPHOSRawDigiProducer::AliPHOSRawDigiProducer(const AliPHOSRawDigiProducer &dp):TObject(),
78 fEmcMinE(0.),fCpvMinE(0.),fSampleQualityCut(1.),fEmcCrystals(0),fGeom(0),fPulseGenerator(0){
80 fEmcMinE = dp.fEmcMinE ;
81 fCpvMinE = dp.fCpvMinE ;
82 fEmcCrystals = dp.fEmcCrystals ;
83 fPulseGenerator = new AliPHOSPulseGenerator();
86 //--------------------------------------------------------------------------------------
87 AliPHOSRawDigiProducer& AliPHOSRawDigiProducer::operator= (const AliPHOSRawDigiProducer &dp){
88 if(&dp == this) return *this;
90 fEmcMinE = dp.fEmcMinE ;
91 fCpvMinE = dp.fCpvMinE ;
92 fSampleQualityCut = dp.fSampleQualityCut ;
93 fEmcCrystals = dp.fEmcCrystals ;
95 if(fPulseGenerator) delete fPulseGenerator ;
96 fPulseGenerator = new AliPHOSPulseGenerator();
99 //--------------------------------------------------------------------------------------
100 AliPHOSRawDigiProducer::~AliPHOSRawDigiProducer(){
101 if(fPulseGenerator) delete fPulseGenerator ;
104 //--------------------------------------------------------------------------------------
105 void AliPHOSRawDigiProducer::MakeDigits(TClonesArray *digits, AliPHOSRawDecoder* decoder)
108 //TClonesArray *digits and raw data decoder should be provided by calling function.
113 Int_t relId[4], absId =0;
115 const Double_t baseLine=1. ; //Minimal energy of digit in ADC ch.
116 const Double_t highLowDiff=2.; //Maximal difference between High and Low channels in LG adc channels
118 //Temporary array for LowGain digits
119 TClonesArray tmpLG("AliPHOSDigit",10000) ;
122 while (decoder->NextDigit()) {
124 Double_t energy=decoder->GetEnergy() ;
125 if(energy<=baseLine) //in ADC channels
128 //remove digits with bas shape. Decoder should calculate quality so that
129 //in default case quality [0,1], while larger values of quality mean somehow
130 //corrupted samples, 999 means obviously corrupted sample.
131 //It is difficult to fit samples with overflow (even setting cut on overflow values)
132 //because too few points are left to fit. So we do not evaluate samples with overflow
133 if(decoder->GetSampleQuality() > fSampleQualityCut && !(decoder->IsOverflow()))
136 Bool_t lowGainFlag = decoder->IsLowGain();
138 relId[0] = decoder->GetModule();
140 relId[2] = decoder->GetRow();
141 relId[3] = decoder->GetColumn();
142 fGeom->RelToAbsNumbering(relId, absId);
144 Double_t time = decoder->GetTime() ;
145 time = CalibrateT(time,relId,lowGainFlag) ;
147 energy = CalibrateE(energy,relId,lowGainFlag) ;
153 new(tmpLG[ilgDigit]) AliPHOSDigit(-1,absId,(Float_t)energy,(Float_t)time);
157 if(decoder->IsOverflow()) //Keep this digit to replace it by Low Gain later.
158 //If there is no LogGain it wil be removed by cut on Min E
159 new((*digits)[iDigit]) AliPHOSDigit(-1,absId,-1.f,(Float_t)time);
161 new((*digits)[iDigit]) AliPHOSDigit(-1,absId,(Float_t)energy,(Float_t)time);
166 //Now scan created LG and HG digits and keep only those which appeared in both lists
167 //replace energy of HighGain digits only if there is overflow
168 //negative energy (overflow)
172 Int_t nLG1 = tmpLG.GetEntriesFast()-1 ;
174 for(Int_t iDig=0 ; iDig < digits->GetEntriesFast() ; iDig++) {
175 AliPHOSDigit * digHG = dynamic_cast<AliPHOSDigit*>(digits->At(iDig)) ;
176 if (!digHG) continue;
177 AliPHOSDigit * digLG = dynamic_cast<AliPHOSDigit*>(tmpLG.At(iLG)) ;
178 while(digLG && iLG<nLG1 && digHG->GetId()> digLG->GetId()){
180 digLG = dynamic_cast<AliPHOSDigit*>(tmpLG.At(iLG)) ;
182 absId=digHG->GetId() ;
183 fGeom->AbsToRelNumbering(absId,relId) ;
185 if(digLG && digHG->GetId() == digLG->GetId()){ //we found pair
186 if(digHG->GetEnergy()<0.){ //This is overflow in HG
187 digHG->SetTime(digLG->GetTime()) ;
188 digHG->SetEnergy(digLG->GetEnergy()) ;
190 else{ //Make approximate comparison of HG and LG energies
191 Double_t de = (digHG->GetEnergy()-digLG->GetEnergy()) ;
192 if(TMath::Abs(de)>CalibrateE(double(highLowDiff),relId,1)){ //too strong difference, remove digit
193 digits->RemoveAt(iDig) ;
197 else{ //no pair - remove
198 // temporary fix for dead LG channels
199 if(relId[2]%2==1 && relId[3]%16==4)
201 if(digHG->GetEnergy()>CalibrateE(double(5.),relId,1)) //One can not always find LG with Amp<5 ADC ch.
202 digits->RemoveAt(iDig) ;
206 CleanDigits(digits) ;
209 //____________________________________________________________________________
210 Double_t AliPHOSRawDigiProducer::CalibrateE(Double_t amp, Int_t* relId, Bool_t isLowGain)
212 // Convert EMC measured amplitude into real energy.
213 // Calibration parameters are taken from calibration data base for raw data,
214 // or from digitizer parameters for simulated data.
216 Int_t module = relId[0];
217 Int_t column = relId[3];
218 Int_t row = relId[2];
219 if(relId[1]==0) { // this is EMC
221 amp*= fgCalibData->GetHighLowRatioEmc(module,column,row);
223 amp *= fgCalibData->GetADCchannelEmc(module,column,row);
229 //____________________________________________________________________________
230 Double_t AliPHOSRawDigiProducer::CalibrateT(Double_t time, Int_t * relId, Bool_t /* isLowGain */)
233 time*=fPulseGenerator->GetRawFormatTimeTrigger() ;
235 Int_t module = relId[0];
236 Int_t column = relId[3];
237 Int_t row = relId[2];
238 if(relId[1]==0) { // this is EMC
239 time += fgCalibData->GetTimeShiftEmc(module,column,row);
246 //____________________________________________________________________________
247 void AliPHOSRawDigiProducer::CleanDigits(TClonesArray * digits)
249 // remove digits with amplitudes below threshold.
250 // remove digits in bad channels
251 // sort digits with icreasing AbsId
253 //remove digits in bad map and below threshold
254 Bool_t isBadMap = 0 ;
255 if(fgCalibData->GetNumOfEmcBadChannels()){
259 for(Int_t i=0; i<digits->GetEntriesFast(); i++){
260 AliPHOSDigit * digit = static_cast<AliPHOSDigit*>(digits->At(i)) ;
263 if ( (IsInEMC(digit) && digit->GetEnergy() < fEmcMinE) ||
264 (IsInCPV(digit) && digit->GetEnergy() < fCpvMinE) ){
265 digits->RemoveAt(i) ;
268 if(isBadMap){ //check bad map now
270 fGeom->AbsToRelNumbering(digit->GetId(), relid) ;
271 if(fgCalibData->IsBadChannelEmc(relid[0],relid[3],relid[2])){
272 digits->RemoveAt(i) ;
277 //Compress, sort and set indexes
279 // digits->Sort(); already sorted earlier
280 for (Int_t i = 0 ; i < digits->GetEntriesFast() ; i++) {
281 AliPHOSDigit *digit = static_cast<AliPHOSDigit*>( digits->At(i) ) ;
282 digit->SetIndexInList(i) ;
285 //____________________________________________________________________________
286 Bool_t AliPHOSRawDigiProducer::IsInEMC(AliPHOSDigit * digit) const
288 // Tells if (true) or not (false) the digit is in a PHOS-EMC module
289 return digit->GetId() <= fEmcCrystals ;
293 //____________________________________________________________________________
294 Bool_t AliPHOSRawDigiProducer::IsInCPV(AliPHOSDigit * digit) const
296 // Tells if (true) or not (false) the digit is in a PHOS-CPV module
297 return digit->GetId() > fEmcCrystals ;
299 //____________________________________________________________________________
300 void AliPHOSRawDigiProducer::GetCalibrationParameters()
302 // Set calibration parameters:
303 // if calibration database exists, they are read from database,
304 // otherwise, reconstruction stops in the constructor of AliPHOSCalibData
306 // It is a user responsilibity to open CDB before reconstruction, for example:
307 // AliCDBStorage* storage = AliCDBManager::Instance()->GetStorage("local://CalibDB");
310 fgCalibData = new AliPHOSCalibData(-1); //use AliCDBManager's run number
312 if (fgCalibData->GetCalibDataEmc() == 0)
313 AliFatal("Calibration parameters for PHOS EMC not found. Stop reconstruction.\n");
314 if (fgCalibData->GetCalibDataCpv() == 0)
315 AliFatal("Calibration parameters for PHOS CPV not found. Stop reconstruction.\n");