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"
44 ClassImp(AliPHOSRawDigiProducer)
46 AliPHOSCalibData * AliPHOSRawDigiProducer::fgCalibData = 0 ;
48 //--------------------------------------------------------------------------------------
49 AliPHOSRawDigiProducer::AliPHOSRawDigiProducer():TObject(),
50 fEmcMinE(0.),fCpvMinE(0.),fSampleQualityCut(1.),fEmcCrystals(0),fGeom(0){
53 //--------------------------------------------------------------------------------------
54 AliPHOSRawDigiProducer::AliPHOSRawDigiProducer(const AliPHOSRecoParam* parEmc, const AliPHOSRecoParam* parCpv):TObject(),
55 fEmcMinE(0.),fCpvMinE(0.),fSampleQualityCut(1.),fEmcCrystals(0),fGeom(0){
57 if(!parEmc) AliFatal("Reconstruction parameters for EMC not set!");
58 if(!parCpv) AliFatal("Reconstruction parameters for CPV not set!");
60 fEmcMinE = parEmc->GetMinE();
61 fCpvMinE = parCpv->GetMinE();
63 fSampleQualityCut = parEmc->GetSampleQualityCut() ;
65 fGeom=AliPHOSGeometry::GetInstance() ;
66 if(!fGeom) fGeom = AliPHOSGeometry::GetInstance("IHEP");
68 fEmcCrystals=fGeom->GetNCristalsInModule()*fGeom->GetNModules() ;
70 GetCalibrationParameters() ;
72 //--------------------------------------------------------------------------------------
73 AliPHOSRawDigiProducer::AliPHOSRawDigiProducer(const AliPHOSRawDigiProducer &dp):TObject(),
74 fEmcMinE(0.),fCpvMinE(0.),fSampleQualityCut(1.),fEmcCrystals(0),fGeom(0){
76 fEmcMinE = dp.fEmcMinE ;
77 fCpvMinE = dp.fCpvMinE ;
78 fEmcCrystals = dp.fEmcCrystals ;
81 //--------------------------------------------------------------------------------------
82 AliPHOSRawDigiProducer& AliPHOSRawDigiProducer::operator= (const AliPHOSRawDigiProducer &dp){
83 if(&dp == this) return *this;
85 fEmcMinE = dp.fEmcMinE ;
86 fCpvMinE = dp.fCpvMinE ;
87 fSampleQualityCut = dp.fSampleQualityCut ;
88 fEmcCrystals = dp.fEmcCrystals ;
93 //--------------------------------------------------------------------------------------
94 void AliPHOSRawDigiProducer::MakeDigits(TClonesArray *digits, AliPHOSRawDecoder* decoder)
97 //TClonesArray *digits and raw data decoder should be provided by calling function.
102 Int_t relId[4], absId =0;
104 const Double_t baseLine=1. ; //Minimal energy of digit in ADC ch.
105 const Double_t highLowDiff=2. ; //Maximal difference between High and Low channels in LG adc channels
107 //Temporary array for LowGain digits
108 TClonesArray tmpLG("AliPHOSDigit",10000) ;
111 while (decoder->NextDigit()) {
113 Double_t energy=decoder->GetEnergy() ;
114 if(energy<=baseLine) //in ADC channels
117 //remove digits with bas shape. Decoder should calculate quality so that
118 //in default case quality [0,1], while larger values of quality mean somehow
119 //corrupted samples, 999 means obviously corrupted sample.
120 if(decoder->GetSampleQuality() > fSampleQualityCut )
123 Bool_t lowGainFlag = decoder->IsLowGain();
125 relId[0] = decoder->GetModule();
127 relId[2] = decoder->GetRow();
128 relId[3] = decoder->GetColumn();
129 fGeom->RelToAbsNumbering(relId, absId);
131 Double_t time = decoder->GetTime() ;
132 time = CalibrateT(time,relId,lowGainFlag) ;
134 energy = CalibrateE(energy,relId,lowGainFlag) ;
140 new(tmpLG[ilgDigit]) AliPHOSDigit(-1,absId,(Float_t)energy,(Float_t)time);
144 if(decoder->IsOverflow()) //Keep this digit to replace it by Low Gain later.
145 //If there is no LogGain it wil be removed by cut on Min E
146 new((*digits)[iDigit]) AliPHOSDigit(-1,absId,-1.f,(Float_t)time);
148 new((*digits)[iDigit]) AliPHOSDigit(-1,absId,(Float_t)energy,(Float_t)time);
153 //Now scan created LG and HG digits and keep only those which appeared in both lists
154 //replace energy of HighGain digits only if there is overflow
155 //negative energy (overflow)
159 Int_t nLG1 = tmpLG.GetEntriesFast()-1 ;
160 for(Int_t iDig=0 ; iDig < digits->GetEntriesFast() ; iDig++) {
161 AliPHOSDigit * digHG = dynamic_cast<AliPHOSDigit*>(digits->At(iDig)) ;
162 if (!digHG) continue;
163 AliPHOSDigit * digLG = dynamic_cast<AliPHOSDigit*>(tmpLG.At(iLG)) ;
164 while(iLG<nLG1 && digHG->GetId()> digLG->GetId()){
166 digLG = dynamic_cast<AliPHOSDigit*>(tmpLG.At(iLG)) ;
168 if(digLG && digHG->GetId() == digLG->GetId()){ //we found pair
169 if(digHG->GetEnergy()<0.){ //This is overflow in HG
170 digHG->SetTime(digLG->GetTime()) ;
171 digHG->SetEnergy(digLG->GetEnergy()) ;
173 else{ //Make approximate comparison of HG and LG energies
174 Double_t de = (digHG->GetEnergy()-digLG->GetEnergy())/16./0.005 ; //aproximate difference in LG ADC ch.
175 if(TMath::Abs(de)>highLowDiff){ //too strong difference, remove digit
176 digits->RemoveAt(iDig) ;
180 else{ //no pair - remove
181 // temporary fix for dead LG channels
182 Int_t absId=digHG->GetId() ;
184 fGeom->AbsToRelNumbering(absId,relId) ;
185 if(relId[2]%2==1 && relId[3]%16==4)
187 digits->RemoveAt(iDig) ;
191 CleanDigits(digits) ;
194 //____________________________________________________________________________
195 Double_t AliPHOSRawDigiProducer::CalibrateE(Double_t amp, Int_t* relId, Bool_t isLowGain)
197 // Convert EMC measured amplitude into real energy.
198 // Calibration parameters are taken from calibration data base for raw data,
199 // or from digitizer parameters for simulated data.
201 Int_t module = relId[0];
202 Int_t column = relId[3];
203 Int_t row = relId[2];
204 if(relId[1]==0) { // this is EMC
206 amp*= fgCalibData->GetHighLowRatioEmc(module,column,row);
208 amp *= fgCalibData->GetADCchannelEmc(module,column,row);
214 //____________________________________________________________________________
215 Double_t AliPHOSRawDigiProducer::CalibrateT(Double_t time, Int_t * relId, Bool_t /* isLowGain */)
219 Int_t module = relId[0];
220 Int_t column = relId[3];
221 Int_t row = relId[2];
222 if(relId[1]==0) { // this is EMC
223 time += fgCalibData->GetTimeShiftEmc(module,column,row);
230 //____________________________________________________________________________
231 void AliPHOSRawDigiProducer::CleanDigits(TClonesArray * digits)
233 // remove digits with amplitudes below threshold.
234 // remove digits in bad channels
235 // sort digits with icreasing AbsId
237 //remove digits in bad map and below threshold
238 Bool_t isBadMap = 0 ;
239 if(fgCalibData->GetNumOfEmcBadChannels()){
243 for(Int_t i=0; i<digits->GetEntriesFast(); i++){
244 AliPHOSDigit * digit = static_cast<AliPHOSDigit*>(digits->At(i)) ;
247 if ( (IsInEMC(digit) && digit->GetEnergy() < fEmcMinE) ||
248 (IsInCPV(digit) && digit->GetEnergy() < fCpvMinE) ){
249 digits->RemoveAt(i) ;
252 if(isBadMap){ //check bad map now
254 fGeom->AbsToRelNumbering(digit->GetId(), relid) ;
255 if(fgCalibData->IsBadChannelEmc(relid[0],relid[2],relid[3])){
256 digits->RemoveAt(i) ;
261 //Compress, sort and set indexes
263 // digits->Sort(); already sorted earlier
264 for (Int_t i = 0 ; i < digits->GetEntriesFast() ; i++) {
265 AliPHOSDigit *digit = static_cast<AliPHOSDigit*>( digits->At(i) ) ;
266 digit->SetIndexInList(i) ;
269 //____________________________________________________________________________
270 Bool_t AliPHOSRawDigiProducer::IsInEMC(AliPHOSDigit * digit) const
272 // Tells if (true) or not (false) the digit is in a PHOS-EMC module
273 return digit->GetId() <= fEmcCrystals ;
277 //____________________________________________________________________________
278 Bool_t AliPHOSRawDigiProducer::IsInCPV(AliPHOSDigit * digit) const
280 // Tells if (true) or not (false) the digit is in a PHOS-CPV module
281 return digit->GetId() > fEmcCrystals ;
283 //____________________________________________________________________________
284 void AliPHOSRawDigiProducer::GetCalibrationParameters()
286 // Set calibration parameters:
287 // if calibration database exists, they are read from database,
288 // otherwise, reconstruction stops in the constructor of AliPHOSCalibData
290 // It is a user responsilibity to open CDB before reconstruction, for example:
291 // AliCDBStorage* storage = AliCDBManager::Instance()->GetStorage("local://CalibDB");
294 fgCalibData = new AliPHOSCalibData(-1); //use AliCDBManager's run number
296 if (fgCalibData->GetCalibDataEmc() == 0)
297 AliFatal("Calibration parameters for PHOS EMC not found. Stop reconstruction.\n");
298 if (fgCalibData->GetCalibDataCpv() == 0)
299 AliFatal("Calibration parameters for PHOS CPV not found. Stop reconstruction.\n");