]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOSRawDigiProducer.cxx
options to set markers etc.
[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//--------------------------------------------------------------------------------------
7e88424f 50AliPHOSRawDigiProducer::AliPHOSRawDigiProducer():
51 TObject(),
52 fEmcMinE(0.),
53 fCpvMinE(0.),
54 fSampleQualityCut(1.),
bafc1087 55 fGlobalAltroOffset(0),
7e88424f 56 fEmcCrystals(0),
57 fGeom(0),
58 fPulseGenerator(0)
59{
60 // Default constructor
c0394bfb 61}
62//--------------------------------------------------------------------------------------
7e88424f 63AliPHOSRawDigiProducer::AliPHOSRawDigiProducer(const AliPHOSRecoParam* recoParam):
64 TObject(),
65 fEmcMinE(0.),
66 fCpvMinE(0.),
67 fSampleQualityCut(1.),
bafc1087 68 fGlobalAltroOffset(0),
7e88424f 69 fEmcCrystals(0),
70 fGeom(0),
71 fPulseGenerator(0)
72{
73 // Constructor takes paramerters from recoParam
c0394bfb 74
7e88424f 75 if(!recoParam) AliFatal("Reconstruction parameters are not set!");
c0394bfb 76
12dd7f10 77 fEmcMinE = recoParam->GetEMCRawDigitThreshold();
7e88424f 78 fCpvMinE = recoParam->GetCPVMinE();
7e88424f 79 fSampleQualityCut = recoParam->GetEMCSampleQualityCut() ;
bafc1087 80 fGlobalAltroOffset = recoParam->GetGlobalAltroOffset() ;
70d93620 81
c0394bfb 82 fGeom=AliPHOSGeometry::GetInstance() ;
83 if(!fGeom) fGeom = AliPHOSGeometry::GetInstance("IHEP");
84
85 fEmcCrystals=fGeom->GetNCristalsInModule()*fGeom->GetNModules() ;
86
39569d36 87 fPulseGenerator = new AliPHOSPulseGenerator();
88
c0394bfb 89 GetCalibrationParameters() ;
90}
91//--------------------------------------------------------------------------------------
7e88424f 92AliPHOSRawDigiProducer::AliPHOSRawDigiProducer(const AliPHOSRawDigiProducer &dp):
93 TObject(),
94 fEmcMinE(0.),
95 fCpvMinE(0.),
96 fSampleQualityCut(1.),
bafc1087 97 fGlobalAltroOffset(0),
7e88424f 98 fEmcCrystals(0),
99 fGeom(0),
100 fPulseGenerator(0)
101{
102 // Copy constructor
c0394bfb 103
104 fEmcMinE = dp.fEmcMinE ;
105 fCpvMinE = dp.fCpvMinE ;
106 fEmcCrystals = dp.fEmcCrystals ;
39569d36 107 fPulseGenerator = new AliPHOSPulseGenerator();
c0394bfb 108 fGeom = dp.fGeom ;
109}
110//--------------------------------------------------------------------------------------
7e88424f 111AliPHOSRawDigiProducer& AliPHOSRawDigiProducer::operator= (const AliPHOSRawDigiProducer &dp)
112{
113 // Assign operator
114
c0394bfb 115 if(&dp == this) return *this;
116
117 fEmcMinE = dp.fEmcMinE ;
118 fCpvMinE = dp.fCpvMinE ;
70d93620 119 fSampleQualityCut = dp.fSampleQualityCut ;
bafc1087 120 fGlobalAltroOffset = dp.fGlobalAltroOffset ;
c0394bfb 121 fEmcCrystals = dp.fEmcCrystals ;
122 fGeom = dp.fGeom ;
39569d36 123 if(fPulseGenerator) delete fPulseGenerator ;
124 fPulseGenerator = new AliPHOSPulseGenerator();
c0394bfb 125 return *this;
126}
39569d36 127//--------------------------------------------------------------------------------------
7e88424f 128AliPHOSRawDigiProducer::~AliPHOSRawDigiProducer()
129{
130 // Desctructor
131 if(fPulseGenerator) delete fPulseGenerator ;
132 fPulseGenerator=0 ;
39569d36 133}
7bc140a5 134//--------------------------------------------------------------------------------------
88fb5e50 135void AliPHOSRawDigiProducer::MakeDigits(TClonesArray *digits, AliPHOSRawDecoder* decoder)
136{
7bc140a5 137 //Makes the job.
138 //TClonesArray *digits and raw data decoder should be provided by calling function.
139
88fb5e50 140 digits->Clear();
141
88fb5e50 142 Int_t iDigit = 0 ;
88fb5e50 143 Int_t relId[4], absId =0;
144
c0394bfb 145 const Double_t baseLine=1. ; //Minimal energy of digit in ADC ch.
a7c985dc 146 const Double_t highLowDiff=2.; //Maximal difference between High and Low channels in LG adc channels
88fb5e50 147
c0394bfb 148 //Temporary array for LowGain digits
149 TClonesArray tmpLG("AliPHOSDigit",10000) ;
150 Int_t ilgDigit=0 ;
bafc1087 151
152
153 //Read current altro offcet from RCU
154 decoder->SetAmpOffset(fGlobalAltroOffset) ;
155
156 //Let decoder subtract pedestals in case of ZS
157 decoder->SetCalibData(fgCalibData) ;
c0394bfb 158
159 while (decoder->NextDigit()) {
34827459 160
c0394bfb 161 Double_t energy=decoder->GetEnergy() ;
162 if(energy<=baseLine) //in ADC channels
163 continue ;
1267d56d 164
7e88424f 165 //remove digits with bad shape. Decoder should calculate quality so that
70d93620 166 //in default case quality [0,1], while larger values of quality mean somehow
167 //corrupted samples, 999 means obviously corrupted sample.
a7c985dc 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()))
70d93620 171 continue ;
172
c0394bfb 173 Bool_t lowGainFlag = decoder->IsLowGain();
88fb5e50 174
175 relId[0] = decoder->GetModule();
176 relId[1] = 0;
177 relId[2] = decoder->GetRow();
178 relId[3] = decoder->GetColumn();
c0394bfb 179 fGeom->RelToAbsNumbering(relId, absId);
180
181 Double_t time = decoder->GetTime() ;
182 time = CalibrateT(time,relId,lowGainFlag) ;
183
184 energy = CalibrateE(energy,relId,lowGainFlag) ;
185
186 if(energy <= 0.)
187 continue;
188
189 if(lowGainFlag){
7899109f 190 new(tmpLG[ilgDigit]) AliPHOSDigit(-1,absId,(Float_t)energy,(Float_t)time);
c0394bfb 191 ilgDigit++ ;
192 }
193 else{
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
7899109f 196 new((*digits)[iDigit]) AliPHOSDigit(-1,absId,-1.f,(Float_t)time);
c0394bfb 197 else
7899109f 198 new((*digits)[iDigit]) AliPHOSDigit(-1,absId,(Float_t)energy,(Float_t)time);
199 iDigit++;
c0394bfb 200 }
201 }
202
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)
206 digits->Sort() ;
207 tmpLG.Sort() ;
208 Int_t iLG = 0;
209 Int_t nLG1 = tmpLG.GetEntriesFast()-1 ;
39569d36 210
c0394bfb 211 for(Int_t iDig=0 ; iDig < digits->GetEntriesFast() ; iDig++) {
212 AliPHOSDigit * digHG = dynamic_cast<AliPHOSDigit*>(digits->At(iDig)) ;
7899109f 213 if (!digHG) continue;
c0394bfb 214 AliPHOSDigit * digLG = dynamic_cast<AliPHOSDigit*>(tmpLG.At(iLG)) ;
a7c985dc 215 while(digLG && iLG<nLG1 && digHG->GetId()> digLG->GetId()){
c0394bfb 216 iLG++ ;
217 digLG = dynamic_cast<AliPHOSDigit*>(tmpLG.At(iLG)) ;
218 }
605cb8bb 219 absId=digHG->GetId() ;
a7c985dc 220 fGeom->AbsToRelNumbering(absId,relId) ;
221
7899109f 222 if(digLG && digHG->GetId() == digLG->GetId()){ //we found pair
c0394bfb 223 if(digHG->GetEnergy()<0.){ //This is overflow in HG
7899109f 224 digHG->SetTime(digLG->GetTime()) ;
225 digHG->SetEnergy(digLG->GetEnergy()) ;
c0394bfb 226 }
227 else{ //Make approximate comparison of HG and LG energies
a7c985dc 228 Double_t de = (digHG->GetEnergy()-digLG->GetEnergy()) ;
229 if(TMath::Abs(de)>CalibrateE(double(highLowDiff),relId,1)){ //too strong difference, remove digit
c0394bfb 230 digits->RemoveAt(iDig) ;
88fb5e50 231 }
232 }
88fb5e50 233 }
c0394bfb 234 else{ //no pair - remove
235 // temporary fix for dead LG channels
c0394bfb 236 if(relId[2]%2==1 && relId[3]%16==4)
237 continue ;
a7c985dc 238 if(digHG->GetEnergy()>CalibrateE(double(5.),relId,1)) //One can not always find LG with Amp<5 ADC ch.
39569d36 239 digits->RemoveAt(iDig) ;
c0394bfb 240 }
241 }
242
243 CleanDigits(digits) ;
244
245}
246//____________________________________________________________________________
247Double_t AliPHOSRawDigiProducer::CalibrateE(Double_t amp, Int_t* relId, Bool_t isLowGain)
248{
634d2178 249 // Convert EMC LG amplitude to HG (multipli by ~16)
250 // Calibration parameters are taken from calibration data base
c0394bfb 251 if(fgCalibData){
252 Int_t module = relId[0];
253 Int_t column = relId[3];
254 Int_t row = relId[2];
255 if(relId[1]==0) { // this is EMC
256 if(isLowGain){
257 amp*= fgCalibData->GetHighLowRatioEmc(module,column,row);
88fb5e50 258 }
c0394bfb 259 return amp ;
260 }
261 }
262 return 0;
263}
264//____________________________________________________________________________
265Double_t AliPHOSRawDigiProducer::CalibrateT(Double_t time, Int_t * relId, Bool_t /* isLowGain */)
266{
267 //Calibrate time
39569d36 268 time*=fPulseGenerator->GetRawFormatTimeTrigger() ;
c0394bfb 269 if(fgCalibData){
270 Int_t module = relId[0];
271 Int_t column = relId[3];
272 Int_t row = relId[2];
273 if(relId[1]==0) { // this is EMC
274 time += fgCalibData->GetTimeShiftEmc(module,column,row);
275 return time ;
276 }
277 }
278
279 return -999.;
280}
281//____________________________________________________________________________
282void AliPHOSRawDigiProducer::CleanDigits(TClonesArray * digits)
283{
284 // remove digits with amplitudes below threshold.
285 // remove digits in bad channels
286 // sort digits with icreasing AbsId
287
288 //remove digits in bad map and below threshold
289 Bool_t isBadMap = 0 ;
290 if(fgCalibData->GetNumOfEmcBadChannels()){
291 isBadMap=1 ;
292 }
293
294 for(Int_t i=0; i<digits->GetEntriesFast(); i++){
295 AliPHOSDigit * digit = static_cast<AliPHOSDigit*>(digits->At(i)) ;
296 if(!digit)
297 continue ;
298 if ( (IsInEMC(digit) && digit->GetEnergy() < fEmcMinE) ||
299 (IsInCPV(digit) && digit->GetEnergy() < fCpvMinE) ){
300 digits->RemoveAt(i) ;
301 continue ;
302 }
303 if(isBadMap){ //check bad map now
304 Int_t relid[4] ;
305 fGeom->AbsToRelNumbering(digit->GetId(), relid) ;
a65517aa 306 if(fgCalibData->IsBadChannelEmc(relid[0],relid[3],relid[2])){
c0394bfb 307 digits->RemoveAt(i) ;
88fb5e50 308 }
309 }
88fb5e50 310 }
311
c0394bfb 312 //Compress, sort and set indexes
313 digits->Compress() ;
314// digits->Sort(); already sorted earlier
315 for (Int_t i = 0 ; i < digits->GetEntriesFast() ; i++) {
316 AliPHOSDigit *digit = static_cast<AliPHOSDigit*>( digits->At(i) ) ;
317 digit->SetIndexInList(i) ;
318 }
319}
320//____________________________________________________________________________
321Bool_t AliPHOSRawDigiProducer::IsInEMC(AliPHOSDigit * digit) const
322{
323 // Tells if (true) or not (false) the digit is in a PHOS-EMC module
324 return digit->GetId() <= fEmcCrystals ;
325
326}
327
328//____________________________________________________________________________
329Bool_t AliPHOSRawDigiProducer::IsInCPV(AliPHOSDigit * digit) const
330{
331 // Tells if (true) or not (false) the digit is in a PHOS-CPV module
332 return digit->GetId() > fEmcCrystals ;
333}
334//____________________________________________________________________________
335void AliPHOSRawDigiProducer::GetCalibrationParameters()
336{
337 // Set calibration parameters:
338 // if calibration database exists, they are read from database,
339 // otherwise, reconstruction stops in the constructor of AliPHOSCalibData
340 //
341 // It is a user responsilibity to open CDB before reconstruction, for example:
342 // AliCDBStorage* storage = AliCDBManager::Instance()->GetStorage("local://CalibDB");
343
344 if (!fgCalibData){
345 fgCalibData = new AliPHOSCalibData(-1); //use AliCDBManager's run number
346 }
347 if (fgCalibData->GetCalibDataEmc() == 0)
348 AliFatal("Calibration parameters for PHOS EMC not found. Stop reconstruction.\n");
349 if (fgCalibData->GetCalibDataCpv() == 0)
350 AliFatal("Calibration parameters for PHOS CPV not found. Stop reconstruction.\n");
88fb5e50 351}