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.),fEmcCrystals(0),fGeom(0){
53 //--------------------------------------------------------------------------------------
54 AliPHOSRawDigiProducer::AliPHOSRawDigiProducer(const AliPHOSRecoParam* parEmc, const AliPHOSRecoParam* parCpv):TObject(),
55 fEmcMinE(0.),fCpvMinE(0.),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 fGeom=AliPHOSGeometry::GetInstance() ;
64 if(!fGeom) fGeom = AliPHOSGeometry::GetInstance("IHEP");
66 fEmcCrystals=fGeom->GetNCristalsInModule()*fGeom->GetNModules() ;
68 GetCalibrationParameters() ;
70 //--------------------------------------------------------------------------------------
71 AliPHOSRawDigiProducer::AliPHOSRawDigiProducer(const AliPHOSRawDigiProducer &dp):TObject(),
72 fEmcMinE(0.),fCpvMinE(0.),fEmcCrystals(0),fGeom(0){
74 fEmcMinE = dp.fEmcMinE ;
75 fCpvMinE = dp.fCpvMinE ;
76 fEmcCrystals = dp.fEmcCrystals ;
79 //--------------------------------------------------------------------------------------
80 AliPHOSRawDigiProducer& AliPHOSRawDigiProducer::operator= (const AliPHOSRawDigiProducer &dp){
81 if(&dp == this) return *this;
83 fEmcMinE = dp.fEmcMinE ;
84 fCpvMinE = dp.fCpvMinE ;
85 fEmcCrystals = dp.fEmcCrystals ;
90 //--------------------------------------------------------------------------------------
91 void AliPHOSRawDigiProducer::MakeDigits(TClonesArray *digits, AliPHOSRawDecoder* decoder)
94 //TClonesArray *digits and raw data decoder should be provided by calling function.
99 Int_t relId[4], absId =0;
101 const Double_t baseLine=1. ; //Minimal energy of digit in ADC ch.
102 const Double_t highLowDiff=2. ; //Maximal difference between High and Low channels in LG adc channels
104 //Temporary array for LowGain digits
105 TClonesArray tmpLG("AliPHOSDigit",10000) ;
108 while (decoder->NextDigit()) {
110 Double_t energy=decoder->GetEnergy() ;
111 if(energy<=baseLine) //in ADC channels
114 Bool_t lowGainFlag = decoder->IsLowGain();
116 relId[0] = decoder->GetModule();
118 relId[2] = decoder->GetRow();
119 relId[3] = decoder->GetColumn();
120 fGeom->RelToAbsNumbering(relId, absId);
122 Double_t time = decoder->GetTime() ;
123 time = CalibrateT(time,relId,lowGainFlag) ;
125 energy = CalibrateE(energy,relId,lowGainFlag) ;
131 new(tmpLG[ilgDigit]) AliPHOSDigit(-1,absId,(Float_t)energy,(Float_t)time);
135 if(decoder->IsOverflow()) //Keep this digit to replace it by Low Gain later.
136 //If there is no LogGain it wil be removed by cut on Min E
137 new((*digits)[iDigit]) AliPHOSDigit(-1,absId,-1.f,(Float_t)time);
139 new((*digits)[iDigit]) AliPHOSDigit(-1,absId,(Float_t)energy,(Float_t)time);
144 //Now scan created LG and HG digits and keep only those which appeared in both lists
145 //replace energy of HighGain digits only if there is overflow
146 //negative energy (overflow)
150 Int_t nLG1 = tmpLG.GetEntriesFast()-1 ;
151 for(Int_t iDig=0 ; iDig < digits->GetEntriesFast() ; iDig++) {
152 AliPHOSDigit * digHG = dynamic_cast<AliPHOSDigit*>(digits->At(iDig)) ;
153 if (!digHG) continue;
154 AliPHOSDigit * digLG = dynamic_cast<AliPHOSDigit*>(tmpLG.At(iLG)) ;
155 while(iLG<nLG1 && digHG->GetId()> digLG->GetId()){
157 digLG = dynamic_cast<AliPHOSDigit*>(tmpLG.At(iLG)) ;
159 if(digLG && digHG->GetId() == digLG->GetId()){ //we found pair
160 if(digHG->GetEnergy()<0.){ //This is overflow in HG
161 digHG->SetTime(digLG->GetTime()) ;
162 digHG->SetEnergy(digLG->GetEnergy()) ;
164 else{ //Make approximate comparison of HG and LG energies
165 Double_t de = (digHG->GetEnergy()-digLG->GetEnergy())/16./0.005 ; //aproximate difference in LG ADC ch.
166 if(TMath::Abs(de)>highLowDiff){ //too strong difference, remove digit
167 digits->RemoveAt(iDig) ;
171 else{ //no pair - remove
172 // temporary fix for dead LG channels
173 Int_t absId=digHG->GetId() ;
175 fGeom->AbsToRelNumbering(absId,relId) ;
176 if(relId[2]%2==1 && relId[3]%16==4)
178 digits->RemoveAt(iDig) ;
182 CleanDigits(digits) ;
185 //____________________________________________________________________________
186 Double_t AliPHOSRawDigiProducer::CalibrateE(Double_t amp, Int_t* relId, Bool_t isLowGain)
188 // Convert EMC measured amplitude into real energy.
189 // Calibration parameters are taken from calibration data base for raw data,
190 // or from digitizer parameters for simulated data.
192 Int_t module = relId[0];
193 Int_t column = relId[3];
194 Int_t row = relId[2];
195 if(relId[1]==0) { // this is EMC
197 amp*= fgCalibData->GetHighLowRatioEmc(module,column,row);
199 amp *= fgCalibData->GetADCchannelEmc(module,column,row);
205 //____________________________________________________________________________
206 Double_t AliPHOSRawDigiProducer::CalibrateT(Double_t time, Int_t * relId, Bool_t /* isLowGain */)
210 Int_t module = relId[0];
211 Int_t column = relId[3];
212 Int_t row = relId[2];
213 if(relId[1]==0) { // this is EMC
214 time += fgCalibData->GetTimeShiftEmc(module,column,row);
221 //____________________________________________________________________________
222 void AliPHOSRawDigiProducer::CleanDigits(TClonesArray * digits)
224 // remove digits with amplitudes below threshold.
225 // remove digits in bad channels
226 // sort digits with icreasing AbsId
228 //remove digits in bad map and below threshold
229 Bool_t isBadMap = 0 ;
230 if(fgCalibData->GetNumOfEmcBadChannels()){
234 for(Int_t i=0; i<digits->GetEntriesFast(); i++){
235 AliPHOSDigit * digit = static_cast<AliPHOSDigit*>(digits->At(i)) ;
238 if ( (IsInEMC(digit) && digit->GetEnergy() < fEmcMinE) ||
239 (IsInCPV(digit) && digit->GetEnergy() < fCpvMinE) ){
240 digits->RemoveAt(i) ;
243 if(isBadMap){ //check bad map now
245 fGeom->AbsToRelNumbering(digit->GetId(), relid) ;
246 if(fgCalibData->IsBadChannelEmc(relid[0],relid[2],relid[3])){
247 digits->RemoveAt(i) ;
252 //Compress, sort and set indexes
254 // digits->Sort(); already sorted earlier
255 for (Int_t i = 0 ; i < digits->GetEntriesFast() ; i++) {
256 AliPHOSDigit *digit = static_cast<AliPHOSDigit*>( digits->At(i) ) ;
257 digit->SetIndexInList(i) ;
260 //____________________________________________________________________________
261 Bool_t AliPHOSRawDigiProducer::IsInEMC(AliPHOSDigit * digit) const
263 // Tells if (true) or not (false) the digit is in a PHOS-EMC module
264 return digit->GetId() <= fEmcCrystals ;
268 //____________________________________________________________________________
269 Bool_t AliPHOSRawDigiProducer::IsInCPV(AliPHOSDigit * digit) const
271 // Tells if (true) or not (false) the digit is in a PHOS-CPV module
272 return digit->GetId() > fEmcCrystals ;
274 //____________________________________________________________________________
275 void AliPHOSRawDigiProducer::GetCalibrationParameters()
277 // Set calibration parameters:
278 // if calibration database exists, they are read from database,
279 // otherwise, reconstruction stops in the constructor of AliPHOSCalibData
281 // It is a user responsilibity to open CDB before reconstruction, for example:
282 // AliCDBStorage* storage = AliCDBManager::Instance()->GetStorage("local://CalibDB");
285 fgCalibData = new AliPHOSCalibData(-1); //use AliCDBManager's run number
287 if (fgCalibData->GetCalibDataEmc() == 0)
288 AliFatal("Calibration parameters for PHOS EMC not found. Stop reconstruction.\n");
289 if (fgCalibData->GetCalibDataCpv() == 0)
290 AliFatal("Calibration parameters for PHOS CPV not found. Stop reconstruction.\n");