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 AliPHOSRawFitter.
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 "AliPHOSRawFitterv0.h"
38 #include "AliPHOSGeometry.h"
39 #include "AliPHOSDigit.h"
40 #include "AliPHOSCalibData.h"
41 #include "AliPHOSPulseGenerator.h"
42 #include "AliCaloRawStreamV3.h"
45 ClassImp(AliPHOSRawDigiProducer)
47 AliPHOSCalibData * AliPHOSRawDigiProducer::fgCalibData = 0 ;
49 //--------------------------------------------------------------------------------------
50 AliPHOSRawDigiProducer::AliPHOSRawDigiProducer():
54 fSampleQualityCut(1.),
62 // Default constructor
64 fGeom=AliPHOSGeometry::GetInstance() ;
65 if(!fGeom) fGeom = AliPHOSGeometry::GetInstance("IHEP");
67 fEmcCrystals=fGeom->GetNCristalsInModule()*fGeom->GetNModules() ;
68 fPulseGenerator = new AliPHOSPulseGenerator();
69 GetCalibrationParameters() ;
72 //--------------------------------------------------------------------------------------
73 AliPHOSRawDigiProducer::AliPHOSRawDigiProducer(AliRawReader *rawReader,
74 AliAltroMapping **mapping):
78 fSampleQualityCut(1.),
83 fRawReader(rawReader),
86 // Default constructor
88 fGeom=AliPHOSGeometry::GetInstance() ;
89 if(!fGeom) fGeom = AliPHOSGeometry::GetInstance("IHEP");
91 fEmcCrystals=fGeom->GetNCristalsInModule()*fGeom->GetNModules() ;
92 fPulseGenerator = new AliPHOSPulseGenerator();
93 GetCalibrationParameters() ;
95 fRawStream = new AliCaloRawStreamV3(rawReader,"PHOS",mapping);
98 //--------------------------------------------------------------------------------------
99 AliPHOSRawDigiProducer::AliPHOSRawDigiProducer(const AliPHOSRawDigiProducer &dp):
103 fSampleQualityCut(1.),
113 fEmcMinE = dp.fEmcMinE ;
114 fCpvMinE = dp.fCpvMinE ;
115 fSampleQualityCut = dp.fSampleQualityCut;
116 fSampleToSec = dp.fSampleToSec ;
117 fEmcCrystals = dp.fEmcCrystals ;
118 fPulseGenerator = new AliPHOSPulseGenerator();
121 //--------------------------------------------------------------------------------------
122 AliPHOSRawDigiProducer& AliPHOSRawDigiProducer::operator= (const AliPHOSRawDigiProducer &dp)
126 if(&dp == this) return *this;
128 fEmcMinE = dp.fEmcMinE ;
129 fCpvMinE = dp.fCpvMinE ;
130 fSampleQualityCut = dp.fSampleQualityCut ;
131 fSampleToSec = dp.fSampleToSec ;
132 fEmcCrystals = dp.fEmcCrystals ;
134 if(fPulseGenerator) delete fPulseGenerator ;
135 fPulseGenerator = new AliPHOSPulseGenerator();
138 //--------------------------------------------------------------------------------------
139 AliPHOSRawDigiProducer::~AliPHOSRawDigiProducer()
142 if(fPulseGenerator) delete fPulseGenerator ;
146 //--------------------------------------------------------------------------------------
147 void AliPHOSRawDigiProducer::MakeDigits(TClonesArray *digits, AliPHOSRawFitterv0* fitter)
150 //TClonesArray *digits and raw data fitter should be provided by calling function.
155 Int_t relId[4], absId=-1, caloFlag=-1;
157 const Double_t baseLine=1. ; //Minimal energy of digit in ADC ch.
159 //Calculate conversion coeff. from Sample time step to seconds
160 //If OCDB contains negative or zero value - use one from RCU trailer
161 //Negative value in OCDB is used only for simulation of raw digits
162 if(fgCalibData->GetSampleTimeStep()>0.)
163 fSampleToSec=fgCalibData->GetSampleTimeStep() ;
165 fSampleToSec=fRawStream->GetTSample() ;
167 //Temporary array for LowGain digits
168 TClonesArray tmpLG("AliPHOSDigit",10000) ;
171 //Let fitter subtract pedestals in case of ZS
172 fitter->SetCalibData(fgCalibData) ;
174 while (fRawStream->NextDDL()) {
175 while (fRawStream->NextChannel()) {
176 relId[0] = 5 - fRawStream->GetModule() ; // counts from 1 to 5
178 relId[2] = fRawStream->GetCellX() + 1; // counts from 1 to 64
179 relId[3] = fRawStream->GetCellZ() + 1; // counts from 1 to 56
180 caloFlag = fRawStream->GetCaloFlag(); // 0=LG, 1=HG, 2=TRU
182 if(caloFlag!=0 && caloFlag!=1) continue; //TRU data!
184 fitter->SetChannelGeo(relId[0],relId[2],relId[3],caloFlag);
186 if(fitter->GetAmpOffset()==0 && fitter->GetAmpThreshold()==0) {
187 short value = fRawStream->GetAltroCFG1();
188 bool ZeroSuppressionEnabled = (value >> 15) & 0x1;
189 if(ZeroSuppressionEnabled) {
190 short offset = (value >> 10) & 0xf;
191 short threshold = value & 0x3ff;
192 fitter->SubtractPedestals(kFALSE);
193 fitter->SetAmpOffset(offset);
194 fitter->SetAmpThreshold(threshold);
198 fGeom->RelToAbsNumbering(relId, absId);
201 while (fRawStream->NextBunch()) {
203 if (nBunches > 1) continue;
204 const UShort_t *sig = fRawStream->GetSignals();
205 Int_t sigStart = fRawStream->GetStartTimeBin();
206 Int_t sigLength = fRawStream->GetBunchLength();
207 fitter->Eval(sig,sigStart,sigLength);
208 } // End of NextBunch()
210 fitter->SetNBunches(nBunches);
212 Double_t energy = fitter->GetEnergy() ;
213 Double_t time = fitter->GetTime() ;
214 if(energy<=baseLine) //in ADC channels
217 //remove digits with bad shape. Fitter should calculate quality so that
218 //in default case quality [0,1], while larger values of quality mean somehow
219 //corrupted samples, 999 means obviously corrupted sample.
220 //It is difficult to fit samples with overflow (even setting cut on overflow values)
221 //because too few points are left to fit. So we do not evaluate samples with overflow
223 if(fitter->GetSignalQuality() > fSampleQualityCut && !(fitter->IsOverflow()))
226 // energy = CalibrateE(energy,relId,lowGainFlag) ;
227 // time = CalibrateT(time,relId,lowGainFlag) ;
229 //convert time from sample bin units to s
235 if (caloFlag == AliCaloRawStreamV3::kLowGain) {
236 new(tmpLG[ilgDigit]) AliPHOSDigit(-1,absId,(Float_t)energy,(Float_t)time);
239 else if (caloFlag == AliCaloRawStreamV3::kHighGain) {
240 if(fitter->IsOverflow()) //Keep this digit to replace it by Low Gain later.
241 //If there is no LogGain it wil be removed by cut on Min E
242 new((*digits)[iDigit]) AliPHOSDigit(-1,absId,-1.f,(Float_t)time);
244 new((*digits)[iDigit]) AliPHOSDigit(-1,absId,(Float_t)energy,(Float_t)time);
247 } // End of NextChannel()
249 //Now scan created LG and HG digits and keep only those which appeared in both lists
250 //replace energy of HighGain digits only if there is overflow
251 //negative energy (overflow)
255 Int_t nLG1 = tmpLG.GetEntriesFast()-1 ;
257 for(Int_t iDig=0 ; iDig < digits->GetEntriesFast() ; iDig++) {
258 AliPHOSDigit * digHG = dynamic_cast<AliPHOSDigit*>(digits->At(iDig)) ;
259 if (!digHG) continue;
260 AliPHOSDigit * digLG = dynamic_cast<AliPHOSDigit*>(tmpLG.At(iLG)) ;
261 while(digLG && iLG<nLG1 && digHG->GetId()> digLG->GetId()){
263 digLG = dynamic_cast<AliPHOSDigit*>(tmpLG.At(iLG)) ;
265 absId=digHG->GetId() ;
266 fGeom->AbsToRelNumbering(absId,relId) ;
268 if(digLG && digHG->GetId() == digLG->GetId()){ //we found pair
269 if(digHG->GetEnergy()<0.){ //This is overflow in HG
270 digHG->SetTime(digLG->GetTime()) ;
271 digHG->SetEnergy(digLG->GetEnergy()) ;
274 else{ //no pair - remove
275 if(digHG->GetEnergy()<0.) //no pair, in saturation
276 digits->RemoveAt(iDig) ;
279 } // End of NextDDL()
281 CleanDigits(digits) ;
284 //____________________________________________________________________________
285 Double_t AliPHOSRawDigiProducer::CalibrateE(Double_t amp, Int_t* relId, Bool_t isLowGain)
287 // Convert EMC LG amplitude to HG (multipli by ~16)
288 // Calibration parameters are taken from calibration data base
290 Int_t module = relId[0];
291 Int_t column = relId[3];
292 Int_t row = relId[2];
293 if(relId[1]==0) { // this is EMC
295 amp*= fgCalibData->GetHighLowRatioEmc(module,column,row);
302 //____________________________________________________________________________
303 Double_t AliPHOSRawDigiProducer::CalibrateT(Double_t time, Int_t * relId, Bool_t /* isLowGain */)
306 time*=fPulseGenerator->GetRawFormatTimeTrigger() ;
308 Int_t module = relId[0];
309 Int_t column = relId[3];
310 Int_t row = relId[2];
311 if(relId[1]==0) { // this is EMC
312 time += fgCalibData->GetTimeShiftEmc(module,column,row);
319 //____________________________________________________________________________
320 void AliPHOSRawDigiProducer::CleanDigits(TClonesArray * digits)
322 // remove digits with amplitudes below threshold.
323 // remove digits in bad channels
324 // sort digits with icreasing AbsId
326 //remove digits in bad map and below threshold
327 Bool_t isBadMap = 0 ;
328 if(fgCalibData->GetNumOfEmcBadChannels()){
332 for(Int_t i=0; i<digits->GetEntriesFast(); i++){
333 AliPHOSDigit * digit = static_cast<AliPHOSDigit*>(digits->At(i)) ;
336 if ( (IsInEMC(digit) && digit->GetEnergy() < fEmcMinE) ||
337 (IsInCPV(digit) && digit->GetEnergy() < fCpvMinE) ){
338 digits->RemoveAt(i) ;
341 if(isBadMap){ //check bad map now
343 fGeom->AbsToRelNumbering(digit->GetId(), relid) ;
344 if(fgCalibData->IsBadChannelEmc(relid[0],relid[3],relid[2])){
345 digits->RemoveAt(i) ;
350 //Compress, sort and set indexes
352 // digits->Sort(); already sorted earlier
353 for (Int_t i = 0 ; i < digits->GetEntriesFast() ; i++) {
354 AliPHOSDigit *digit = static_cast<AliPHOSDigit*>( digits->At(i) ) ;
355 digit->SetIndexInList(i) ;
358 //____________________________________________________________________________
359 Bool_t AliPHOSRawDigiProducer::IsInEMC(AliPHOSDigit * digit) const
361 // Tells if (true) or not (false) the digit is in a PHOS-EMC module
362 return digit->GetId() <= fEmcCrystals ;
366 //____________________________________________________________________________
367 Bool_t AliPHOSRawDigiProducer::IsInCPV(AliPHOSDigit * digit) const
369 // Tells if (true) or not (false) the digit is in a PHOS-CPV module
370 return digit->GetId() > fEmcCrystals ;
372 //____________________________________________________________________________
373 void AliPHOSRawDigiProducer::GetCalibrationParameters()
375 // Set calibration parameters:
376 // if calibration database exists, they are read from database,
377 // otherwise, reconstruction stops in the constructor of AliPHOSCalibData
379 // It is a user responsilibity to open CDB before reconstruction, for example:
380 // AliCDBStorage* storage = AliCDBManager::Instance()->GetStorage("local://CalibDB");
383 fgCalibData = new AliPHOSCalibData(-1); //use AliCDBManager's run number
385 if (fgCalibData->GetCalibDataEmc() == 0)
386 AliFatal("Calibration parameters for PHOS EMC not found. Stop reconstruction.\n");
387 if (fgCalibData->GetCalibDataCpv() == 0)
388 AliFatal("Calibration parameters for PHOS CPV not found. Stop reconstruction.\n");