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),
60 // Default constructor
62 //--------------------------------------------------------------------------------------
63 AliPHOSRawDigiProducer::AliPHOSRawDigiProducer(const AliPHOSRecoParam* recoParam):
67 fSampleQualityCut(1.),
68 fGlobalAltroOffset(0),
73 // Constructor takes paramerters from recoParam
75 if(!recoParam) AliFatal("Reconstruction parameters are not set!");
77 fEmcMinE = recoParam->GetEMCMinE();
78 fCpvMinE = recoParam->GetCPVMinE();
79 fSampleQualityCut = recoParam->GetEMCSampleQualityCut() ;
80 fGlobalAltroOffset = recoParam->GetGlobalAltroOffset() ;
82 fGeom=AliPHOSGeometry::GetInstance() ;
83 if(!fGeom) fGeom = AliPHOSGeometry::GetInstance("IHEP");
85 fEmcCrystals=fGeom->GetNCristalsInModule()*fGeom->GetNModules() ;
87 fPulseGenerator = new AliPHOSPulseGenerator();
89 GetCalibrationParameters() ;
91 //--------------------------------------------------------------------------------------
92 AliPHOSRawDigiProducer::AliPHOSRawDigiProducer(const AliPHOSRawDigiProducer &dp):
96 fSampleQualityCut(1.),
97 fGlobalAltroOffset(0),
104 fEmcMinE = dp.fEmcMinE ;
105 fCpvMinE = dp.fCpvMinE ;
106 fEmcCrystals = dp.fEmcCrystals ;
107 fPulseGenerator = new AliPHOSPulseGenerator();
110 //--------------------------------------------------------------------------------------
111 AliPHOSRawDigiProducer& AliPHOSRawDigiProducer::operator= (const AliPHOSRawDigiProducer &dp)
115 if(&dp == this) return *this;
117 fEmcMinE = dp.fEmcMinE ;
118 fCpvMinE = dp.fCpvMinE ;
119 fSampleQualityCut = dp.fSampleQualityCut ;
120 fGlobalAltroOffset = dp.fGlobalAltroOffset ;
121 fEmcCrystals = dp.fEmcCrystals ;
123 if(fPulseGenerator) delete fPulseGenerator ;
124 fPulseGenerator = new AliPHOSPulseGenerator();
127 //--------------------------------------------------------------------------------------
128 AliPHOSRawDigiProducer::~AliPHOSRawDigiProducer()
131 if(fPulseGenerator) delete fPulseGenerator ;
134 //--------------------------------------------------------------------------------------
135 void AliPHOSRawDigiProducer::MakeDigits(TClonesArray *digits, AliPHOSRawDecoder* decoder)
138 //TClonesArray *digits and raw data decoder should be provided by calling function.
143 Int_t relId[4], absId =0;
145 const Double_t baseLine=1. ; //Minimal energy of digit in ADC ch.
146 const Double_t highLowDiff=2.; //Maximal difference between High and Low channels in LG adc channels
148 //Temporary array for LowGain digits
149 TClonesArray tmpLG("AliPHOSDigit",10000) ;
153 //Read current altro offcet from RCU
154 decoder->SetAmpOffset(fGlobalAltroOffset) ;
156 //Let decoder subtract pedestals in case of ZS
157 decoder->SetCalibData(fgCalibData) ;
159 while (decoder->NextDigit()) {
161 Double_t energy=decoder->GetEnergy() ;
162 if(energy<=baseLine) //in ADC channels
165 //remove digits with bad shape. Decoder should calculate quality so that
166 //in default case quality [0,1], while larger values of quality mean somehow
167 //corrupted samples, 999 means obviously corrupted sample.
168 //It is difficult to fit samples with overflow (even setting cut on overflow values)
169 //because too few points are left to fit. So we do not evaluate samples with overflow
170 if(decoder->GetSampleQuality() > fSampleQualityCut && !(decoder->IsOverflow()))
173 Bool_t lowGainFlag = decoder->IsLowGain();
175 relId[0] = decoder->GetModule();
177 relId[2] = decoder->GetRow();
178 relId[3] = decoder->GetColumn();
179 fGeom->RelToAbsNumbering(relId, absId);
181 Double_t time = decoder->GetTime() ;
182 time = CalibrateT(time,relId,lowGainFlag) ;
184 energy = CalibrateE(energy,relId,lowGainFlag) ;
190 new(tmpLG[ilgDigit]) AliPHOSDigit(-1,absId,(Float_t)energy,(Float_t)time);
194 if(decoder->IsOverflow()) //Keep this digit to replace it by Low Gain later.
195 //If there is no LogGain it wil be removed by cut on Min E
196 new((*digits)[iDigit]) AliPHOSDigit(-1,absId,-1.f,(Float_t)time);
198 new((*digits)[iDigit]) AliPHOSDigit(-1,absId,(Float_t)energy,(Float_t)time);
203 //Now scan created LG and HG digits and keep only those which appeared in both lists
204 //replace energy of HighGain digits only if there is overflow
205 //negative energy (overflow)
209 Int_t nLG1 = tmpLG.GetEntriesFast()-1 ;
211 for(Int_t iDig=0 ; iDig < digits->GetEntriesFast() ; iDig++) {
212 AliPHOSDigit * digHG = dynamic_cast<AliPHOSDigit*>(digits->At(iDig)) ;
213 if (!digHG) continue;
214 AliPHOSDigit * digLG = dynamic_cast<AliPHOSDigit*>(tmpLG.At(iLG)) ;
215 while(digLG && iLG<nLG1 && digHG->GetId()> digLG->GetId()){
217 digLG = dynamic_cast<AliPHOSDigit*>(tmpLG.At(iLG)) ;
219 absId=digHG->GetId() ;
220 fGeom->AbsToRelNumbering(absId,relId) ;
222 if(digLG && digHG->GetId() == digLG->GetId()){ //we found pair
223 if(digHG->GetEnergy()<0.){ //This is overflow in HG
224 digHG->SetTime(digLG->GetTime()) ;
225 digHG->SetEnergy(digLG->GetEnergy()) ;
227 else{ //Make approximate comparison of HG and LG energies
228 Double_t de = (digHG->GetEnergy()-digLG->GetEnergy()) ;
229 if(TMath::Abs(de)>CalibrateE(double(highLowDiff),relId,1)){ //too strong difference, remove digit
230 digits->RemoveAt(iDig) ;
234 else{ //no pair - remove
235 // temporary fix for dead LG channels
236 if(relId[2]%2==1 && relId[3]%16==4)
238 if(digHG->GetEnergy()>CalibrateE(double(5.),relId,1)) //One can not always find LG with Amp<5 ADC ch.
239 digits->RemoveAt(iDig) ;
243 CleanDigits(digits) ;
246 //____________________________________________________________________________
247 Double_t AliPHOSRawDigiProducer::CalibrateE(Double_t amp, Int_t* relId, Bool_t isLowGain)
249 // Convert EMC measured amplitude into real energy.
250 // Calibration parameters are taken from calibration data base for raw data,
251 // or from digitizer parameters for simulated data.
253 Int_t module = relId[0];
254 Int_t column = relId[3];
255 Int_t row = relId[2];
256 if(relId[1]==0) { // this is EMC
258 amp*= fgCalibData->GetHighLowRatioEmc(module,column,row);
260 amp *= fgCalibData->GetADCchannelEmc(module,column,row);
266 //____________________________________________________________________________
267 Double_t AliPHOSRawDigiProducer::CalibrateT(Double_t time, Int_t * relId, Bool_t /* isLowGain */)
270 time*=fPulseGenerator->GetRawFormatTimeTrigger() ;
272 Int_t module = relId[0];
273 Int_t column = relId[3];
274 Int_t row = relId[2];
275 if(relId[1]==0) { // this is EMC
276 time += fgCalibData->GetTimeShiftEmc(module,column,row);
283 //____________________________________________________________________________
284 void AliPHOSRawDigiProducer::CleanDigits(TClonesArray * digits)
286 // remove digits with amplitudes below threshold.
287 // remove digits in bad channels
288 // sort digits with icreasing AbsId
290 //remove digits in bad map and below threshold
291 Bool_t isBadMap = 0 ;
292 if(fgCalibData->GetNumOfEmcBadChannels()){
296 for(Int_t i=0; i<digits->GetEntriesFast(); i++){
297 AliPHOSDigit * digit = static_cast<AliPHOSDigit*>(digits->At(i)) ;
300 if ( (IsInEMC(digit) && digit->GetEnergy() < fEmcMinE) ||
301 (IsInCPV(digit) && digit->GetEnergy() < fCpvMinE) ){
302 digits->RemoveAt(i) ;
305 if(isBadMap){ //check bad map now
307 fGeom->AbsToRelNumbering(digit->GetId(), relid) ;
308 if(fgCalibData->IsBadChannelEmc(relid[0],relid[3],relid[2])){
309 digits->RemoveAt(i) ;
314 //Compress, sort and set indexes
316 // digits->Sort(); already sorted earlier
317 for (Int_t i = 0 ; i < digits->GetEntriesFast() ; i++) {
318 AliPHOSDigit *digit = static_cast<AliPHOSDigit*>( digits->At(i) ) ;
319 digit->SetIndexInList(i) ;
322 //____________________________________________________________________________
323 Bool_t AliPHOSRawDigiProducer::IsInEMC(AliPHOSDigit * digit) const
325 // Tells if (true) or not (false) the digit is in a PHOS-EMC module
326 return digit->GetId() <= fEmcCrystals ;
330 //____________________________________________________________________________
331 Bool_t AliPHOSRawDigiProducer::IsInCPV(AliPHOSDigit * digit) const
333 // Tells if (true) or not (false) the digit is in a PHOS-CPV module
334 return digit->GetId() > fEmcCrystals ;
336 //____________________________________________________________________________
337 void AliPHOSRawDigiProducer::GetCalibrationParameters()
339 // Set calibration parameters:
340 // if calibration database exists, they are read from database,
341 // otherwise, reconstruction stops in the constructor of AliPHOSCalibData
343 // It is a user responsilibity to open CDB before reconstruction, for example:
344 // AliCDBStorage* storage = AliCDBManager::Instance()->GetStorage("local://CalibDB");
347 fgCalibData = new AliPHOSCalibData(-1); //use AliCDBManager's run number
349 if (fgCalibData->GetCalibDataEmc() == 0)
350 AliFatal("Calibration parameters for PHOS EMC not found. Stop reconstruction.\n");
351 if (fgCalibData->GetCalibDataCpv() == 0)
352 AliFatal("Calibration parameters for PHOS CPV not found. Stop reconstruction.\n");