]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOSRawDigiProducer.cxx
TPCNoiseMapComponent included into build (Kelly)
[u/mrichter/AliRoot.git] / PHOS / AliPHOSRawDigiProducer.cxx
CommitLineData
7bc140a5 1/**************************************************************************
2 * Copyright(c) 2007, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16/* $Id$ */
17
18//This class produces PHOS digits of one event
19//using AliPHOSRawDecoder.
20//
21// For example:
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);
28// }
29
30// Author: Boris Polichtchouk
31
32// --- ROOT system ---
88fb5e50 33#include "TClonesArray.h"
34
7bc140a5 35// --- AliRoot header files ---
88fb5e50 36#include "AliPHOSRawDigiProducer.h"
37#include "AliPHOSRawDecoder.h"
38#include "AliPHOSGeometry.h"
39#include "AliPHOSDigit.h"
c0394bfb 40#include "AliPHOSRecoParam.h"
41#include "AliPHOSCalibData.h"
39569d36 42#include "AliPHOSPulseGenerator.h"
c0394bfb 43#include "AliLog.h"
88fb5e50 44
45ClassImp(AliPHOSRawDigiProducer)
46
c0394bfb 47AliPHOSCalibData * AliPHOSRawDigiProducer::fgCalibData = 0 ;
48
49//--------------------------------------------------------------------------------------
50AliPHOSRawDigiProducer::AliPHOSRawDigiProducer():TObject(),
39569d36 51 fEmcMinE(0.),fCpvMinE(0.),fSampleQualityCut(1.),
52 fEmcCrystals(0),fGeom(0),fPulseGenerator(0){
c0394bfb 53
54}
55//--------------------------------------------------------------------------------------
56AliPHOSRawDigiProducer::AliPHOSRawDigiProducer(const AliPHOSRecoParam* parEmc, const AliPHOSRecoParam* parCpv):TObject(),
39569d36 57 fEmcMinE(0.),fCpvMinE(0.),fSampleQualityCut(1.),fEmcCrystals(0),fGeom(0),fPulseGenerator(0){
c0394bfb 58
59 if(!parEmc) AliFatal("Reconstruction parameters for EMC not set!");
60 if(!parCpv) AliFatal("Reconstruction parameters for CPV not set!");
61
62 fEmcMinE = parEmc->GetMinE();
63 fCpvMinE = parCpv->GetMinE();
64
70d93620 65 fSampleQualityCut = parEmc->GetSampleQualityCut() ;
66
c0394bfb 67 fGeom=AliPHOSGeometry::GetInstance() ;
68 if(!fGeom) fGeom = AliPHOSGeometry::GetInstance("IHEP");
69
70 fEmcCrystals=fGeom->GetNCristalsInModule()*fGeom->GetNModules() ;
71
39569d36 72 fPulseGenerator = new AliPHOSPulseGenerator();
73
c0394bfb 74 GetCalibrationParameters() ;
75}
76//--------------------------------------------------------------------------------------
77AliPHOSRawDigiProducer::AliPHOSRawDigiProducer(const AliPHOSRawDigiProducer &dp):TObject(),
39569d36 78 fEmcMinE(0.),fCpvMinE(0.),fSampleQualityCut(1.),fEmcCrystals(0),fGeom(0),fPulseGenerator(0){
c0394bfb 79
80 fEmcMinE = dp.fEmcMinE ;
81 fCpvMinE = dp.fCpvMinE ;
82 fEmcCrystals = dp.fEmcCrystals ;
39569d36 83 fPulseGenerator = new AliPHOSPulseGenerator();
c0394bfb 84 fGeom = dp.fGeom ;
85}
86//--------------------------------------------------------------------------------------
87AliPHOSRawDigiProducer& AliPHOSRawDigiProducer::operator= (const AliPHOSRawDigiProducer &dp){
88 if(&dp == this) return *this;
89
90 fEmcMinE = dp.fEmcMinE ;
91 fCpvMinE = dp.fCpvMinE ;
70d93620 92 fSampleQualityCut = dp.fSampleQualityCut ;
c0394bfb 93 fEmcCrystals = dp.fEmcCrystals ;
94 fGeom = dp.fGeom ;
39569d36 95 if(fPulseGenerator) delete fPulseGenerator ;
96 fPulseGenerator = new AliPHOSPulseGenerator();
c0394bfb 97 return *this;
98}
39569d36 99//--------------------------------------------------------------------------------------
100AliPHOSRawDigiProducer::~AliPHOSRawDigiProducer(){
101 if(fPulseGenerator) delete fPulseGenerator ;
102 fPulseGenerator=0 ;
103}
7bc140a5 104//--------------------------------------------------------------------------------------
88fb5e50 105void AliPHOSRawDigiProducer::MakeDigits(TClonesArray *digits, AliPHOSRawDecoder* decoder)
106{
7bc140a5 107 //Makes the job.
108 //TClonesArray *digits and raw data decoder should be provided by calling function.
109
88fb5e50 110 digits->Clear();
111
88fb5e50 112 Int_t iDigit = 0 ;
88fb5e50 113 Int_t relId[4], absId =0;
114
c0394bfb 115 const Double_t baseLine=1. ; //Minimal energy of digit in ADC ch.
a7c985dc 116 const Double_t highLowDiff=2.; //Maximal difference between High and Low channels in LG adc channels
88fb5e50 117
c0394bfb 118 //Temporary array for LowGain digits
119 TClonesArray tmpLG("AliPHOSDigit",10000) ;
120 Int_t ilgDigit=0 ;
121
122 while (decoder->NextDigit()) {
34827459 123
c0394bfb 124 Double_t energy=decoder->GetEnergy() ;
125 if(energy<=baseLine) //in ADC channels
126 continue ;
1267d56d 127
70d93620 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.
a7c985dc 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()))
70d93620 134 continue ;
135
c0394bfb 136 Bool_t lowGainFlag = decoder->IsLowGain();
88fb5e50 137
138 relId[0] = decoder->GetModule();
139 relId[1] = 0;
140 relId[2] = decoder->GetRow();
141 relId[3] = decoder->GetColumn();
c0394bfb 142 fGeom->RelToAbsNumbering(relId, absId);
143
144 Double_t time = decoder->GetTime() ;
145 time = CalibrateT(time,relId,lowGainFlag) ;
146
147 energy = CalibrateE(energy,relId,lowGainFlag) ;
148
149 if(energy <= 0.)
150 continue;
151
152 if(lowGainFlag){
7899109f 153 new(tmpLG[ilgDigit]) AliPHOSDigit(-1,absId,(Float_t)energy,(Float_t)time);
c0394bfb 154 ilgDigit++ ;
155 }
156 else{
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
7899109f 159 new((*digits)[iDigit]) AliPHOSDigit(-1,absId,-1.f,(Float_t)time);
c0394bfb 160 else
7899109f 161 new((*digits)[iDigit]) AliPHOSDigit(-1,absId,(Float_t)energy,(Float_t)time);
162 iDigit++;
c0394bfb 163 }
164 }
165
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)
169 digits->Sort() ;
170 tmpLG.Sort() ;
171 Int_t iLG = 0;
172 Int_t nLG1 = tmpLG.GetEntriesFast()-1 ;
39569d36 173
c0394bfb 174 for(Int_t iDig=0 ; iDig < digits->GetEntriesFast() ; iDig++) {
175 AliPHOSDigit * digHG = dynamic_cast<AliPHOSDigit*>(digits->At(iDig)) ;
7899109f 176 if (!digHG) continue;
c0394bfb 177 AliPHOSDigit * digLG = dynamic_cast<AliPHOSDigit*>(tmpLG.At(iLG)) ;
a7c985dc 178 while(digLG && iLG<nLG1 && digHG->GetId()> digLG->GetId()){
c0394bfb 179 iLG++ ;
180 digLG = dynamic_cast<AliPHOSDigit*>(tmpLG.At(iLG)) ;
181 }
a7c985dc 182 Int_t absId=digHG->GetId() ;
183 Int_t relId[4] ;
184 fGeom->AbsToRelNumbering(absId,relId) ;
185
7899109f 186 if(digLG && digHG->GetId() == digLG->GetId()){ //we found pair
c0394bfb 187 if(digHG->GetEnergy()<0.){ //This is overflow in HG
7899109f 188 digHG->SetTime(digLG->GetTime()) ;
189 digHG->SetEnergy(digLG->GetEnergy()) ;
c0394bfb 190 }
191 else{ //Make approximate comparison of HG and LG energies
a7c985dc 192 Double_t de = (digHG->GetEnergy()-digLG->GetEnergy()) ;
193 if(TMath::Abs(de)>CalibrateE(double(highLowDiff),relId,1)){ //too strong difference, remove digit
c0394bfb 194 digits->RemoveAt(iDig) ;
88fb5e50 195 }
196 }
88fb5e50 197 }
c0394bfb 198 else{ //no pair - remove
199 // temporary fix for dead LG channels
c0394bfb 200 if(relId[2]%2==1 && relId[3]%16==4)
201 continue ;
a7c985dc 202 if(digHG->GetEnergy()>CalibrateE(double(5.),relId,1)) //One can not always find LG with Amp<5 ADC ch.
39569d36 203 digits->RemoveAt(iDig) ;
c0394bfb 204 }
205 }
206
207 CleanDigits(digits) ;
208
209}
210//____________________________________________________________________________
211Double_t AliPHOSRawDigiProducer::CalibrateE(Double_t amp, Int_t* relId, Bool_t isLowGain)
212{
213 // Convert EMC measured amplitude into real energy.
214 // Calibration parameters are taken from calibration data base for raw data,
215 // or from digitizer parameters for simulated data.
216 if(fgCalibData){
217 Int_t module = relId[0];
218 Int_t column = relId[3];
219 Int_t row = relId[2];
220 if(relId[1]==0) { // this is EMC
221 if(isLowGain){
222 amp*= fgCalibData->GetHighLowRatioEmc(module,column,row);
88fb5e50 223 }
c0394bfb 224 amp *= fgCalibData->GetADCchannelEmc(module,column,row);
225 return amp ;
226 }
227 }
228 return 0;
229}
230//____________________________________________________________________________
231Double_t AliPHOSRawDigiProducer::CalibrateT(Double_t time, Int_t * relId, Bool_t /* isLowGain */)
232{
233 //Calibrate time
39569d36 234 time*=fPulseGenerator->GetRawFormatTimeTrigger() ;
c0394bfb 235 if(fgCalibData){
236 Int_t module = relId[0];
237 Int_t column = relId[3];
238 Int_t row = relId[2];
239 if(relId[1]==0) { // this is EMC
240 time += fgCalibData->GetTimeShiftEmc(module,column,row);
241 return time ;
242 }
243 }
244
245 return -999.;
246}
247//____________________________________________________________________________
248void AliPHOSRawDigiProducer::CleanDigits(TClonesArray * digits)
249{
250 // remove digits with amplitudes below threshold.
251 // remove digits in bad channels
252 // sort digits with icreasing AbsId
253
254 //remove digits in bad map and below threshold
255 Bool_t isBadMap = 0 ;
256 if(fgCalibData->GetNumOfEmcBadChannels()){
257 isBadMap=1 ;
258 }
259
260 for(Int_t i=0; i<digits->GetEntriesFast(); i++){
261 AliPHOSDigit * digit = static_cast<AliPHOSDigit*>(digits->At(i)) ;
262 if(!digit)
263 continue ;
264 if ( (IsInEMC(digit) && digit->GetEnergy() < fEmcMinE) ||
265 (IsInCPV(digit) && digit->GetEnergy() < fCpvMinE) ){
266 digits->RemoveAt(i) ;
267 continue ;
268 }
269 if(isBadMap){ //check bad map now
270 Int_t relid[4] ;
271 fGeom->AbsToRelNumbering(digit->GetId(), relid) ;
a65517aa 272 if(fgCalibData->IsBadChannelEmc(relid[0],relid[3],relid[2])){
c0394bfb 273 digits->RemoveAt(i) ;
88fb5e50 274 }
275 }
88fb5e50 276 }
277
c0394bfb 278 //Compress, sort and set indexes
279 digits->Compress() ;
280// digits->Sort(); already sorted earlier
281 for (Int_t i = 0 ; i < digits->GetEntriesFast() ; i++) {
282 AliPHOSDigit *digit = static_cast<AliPHOSDigit*>( digits->At(i) ) ;
283 digit->SetIndexInList(i) ;
284 }
285}
286//____________________________________________________________________________
287Bool_t AliPHOSRawDigiProducer::IsInEMC(AliPHOSDigit * digit) const
288{
289 // Tells if (true) or not (false) the digit is in a PHOS-EMC module
290 return digit->GetId() <= fEmcCrystals ;
291
292}
293
294//____________________________________________________________________________
295Bool_t AliPHOSRawDigiProducer::IsInCPV(AliPHOSDigit * digit) const
296{
297 // Tells if (true) or not (false) the digit is in a PHOS-CPV module
298 return digit->GetId() > fEmcCrystals ;
299}
300//____________________________________________________________________________
301void AliPHOSRawDigiProducer::GetCalibrationParameters()
302{
303 // Set calibration parameters:
304 // if calibration database exists, they are read from database,
305 // otherwise, reconstruction stops in the constructor of AliPHOSCalibData
306 //
307 // It is a user responsilibity to open CDB before reconstruction, for example:
308 // AliCDBStorage* storage = AliCDBManager::Instance()->GetStorage("local://CalibDB");
309
310 if (!fgCalibData){
311 fgCalibData = new AliPHOSCalibData(-1); //use AliCDBManager's run number
312 }
313 if (fgCalibData->GetCalibDataEmc() == 0)
314 AliFatal("Calibration parameters for PHOS EMC not found. Stop reconstruction.\n");
315 if (fgCalibData->GetCalibDataCpv() == 0)
316 AliFatal("Calibration parameters for PHOS CPV not found. Stop reconstruction.\n");
88fb5e50 317}