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.),
61 // Default constructor
63 fGeom=AliPHOSGeometry::GetInstance() ;
64 if(!fGeom) fGeom = AliPHOSGeometry::GetInstance("IHEP");
66 fEmcCrystals=fGeom->GetNCristalsInModule()*fGeom->GetNModules() ;
67 fPulseGenerator = new AliPHOSPulseGenerator();
68 GetCalibrationParameters() ;
71 //--------------------------------------------------------------------------------------
72 AliPHOSRawDigiProducer::AliPHOSRawDigiProducer(AliRawReader *rawReader,
73 AliAltroMapping **mapping):
77 fSampleQualityCut(1.),
81 fRawReader(rawReader),
84 // Default constructor
86 fGeom=AliPHOSGeometry::GetInstance() ;
87 if(!fGeom) fGeom = AliPHOSGeometry::GetInstance("IHEP");
89 fEmcCrystals=fGeom->GetNCristalsInModule()*fGeom->GetNModules() ;
90 fPulseGenerator = new AliPHOSPulseGenerator();
91 GetCalibrationParameters() ;
93 fRawStream = new AliCaloRawStreamV3(rawReader,"PHOS",mapping);
96 //--------------------------------------------------------------------------------------
97 AliPHOSRawDigiProducer::AliPHOSRawDigiProducer(const AliPHOSRawDigiProducer &dp):
101 fSampleQualityCut(1.),
110 fEmcMinE = dp.fEmcMinE ;
111 fCpvMinE = dp.fCpvMinE ;
112 fSampleQualityCut = dp.fSampleQualityCut;
113 fEmcCrystals = dp.fEmcCrystals ;
114 fPulseGenerator = new AliPHOSPulseGenerator();
117 //--------------------------------------------------------------------------------------
118 AliPHOSRawDigiProducer& AliPHOSRawDigiProducer::operator= (const AliPHOSRawDigiProducer &dp)
122 if(&dp == this) return *this;
124 fEmcMinE = dp.fEmcMinE ;
125 fCpvMinE = dp.fCpvMinE ;
126 fSampleQualityCut = dp.fSampleQualityCut ;
127 fEmcCrystals = dp.fEmcCrystals ;
129 if(fPulseGenerator) delete fPulseGenerator ;
130 fPulseGenerator = new AliPHOSPulseGenerator();
133 //--------------------------------------------------------------------------------------
134 AliPHOSRawDigiProducer::~AliPHOSRawDigiProducer()
137 if(fPulseGenerator) delete fPulseGenerator ;
141 //--------------------------------------------------------------------------------------
142 void AliPHOSRawDigiProducer::MakeDigits(TClonesArray *digits, AliPHOSRawFitterv0* fitter)
145 //TClonesArray *digits and raw data fitter should be provided by calling function.
150 Int_t relId[4], absId=-1, caloFlag=-1;
152 const Double_t baseLine=1. ; //Minimal energy of digit in ADC ch.
154 //Temporary array for LowGain digits
155 TClonesArray tmpLG("AliPHOSDigit",10000) ;
158 //Let fitter subtract pedestals in case of ZS
159 fitter->SetCalibData(fgCalibData) ;
161 while (fRawStream->NextDDL()) {
162 while (fRawStream->NextChannel()) {
163 relId[0] = fRawStream->GetModule() + 1; // counts from 1 to 5
165 relId[2] = fRawStream->GetCellX() + 1; // counts from 1 to 64
166 relId[3] = fRawStream->GetCellZ() + 1; // counts from 1 to 56
167 caloFlag = fRawStream->GetCaloFlag(); // 0=LG, 1=HG, 2=TRU
169 if(caloFlag!=0 && caloFlag!=1) continue; //TRU data!
171 if(fitter->GetAmpOffset()==0 && fitter->GetAmpThreshold()==0) {
172 short value = fRawStream->GetAltroCFG1();
173 bool ZeroSuppressionEnabled = (value >> 15) & 0x1;
174 if(ZeroSuppressionEnabled) {
175 short offset = (value >> 10) & 0xf;
176 short threshold = value & 0x3ff;
177 fitter->SubtractPedestals(kFALSE);
178 fitter->SetAmpOffset(offset);
179 fitter->SetAmpThreshold(threshold);
183 fGeom->RelToAbsNumbering(relId, absId);
186 while (fRawStream->NextBunch()) {
188 if (nBunches > 1) continue;
189 const UShort_t *sig = fRawStream->GetSignals();
190 Int_t sigStart = fRawStream->GetStartTimeBin();
191 Int_t sigLength = fRawStream->GetBunchLength();
192 fitter->SetChannelGeo(relId[0],relId[2],relId[3],caloFlag);
193 fitter->Eval(sig,sigStart,sigLength);
194 } // End of NextBunch()
196 fitter->SetNBunches(nBunches);
198 Double_t energy = fitter->GetEnergy() ;
199 Double_t time = fitter->GetTime() ;
200 if(energy<=baseLine) //in ADC channels
203 //remove digits with bad shape. Fitter should calculate quality so that
204 //in default case quality [0,1], while larger values of quality mean somehow
205 //corrupted samples, 999 means obviously corrupted sample.
206 //It is difficult to fit samples with overflow (even setting cut on overflow values)
207 //because too few points are left to fit. So we do not evaluate samples with overflow
209 if(fitter->GetSignalQuality() > fSampleQualityCut && !(fitter->IsOverflow()))
212 // energy = CalibrateE(energy,relId,lowGainFlag) ;
213 // time = CalibrateT(time,relId,lowGainFlag) ;
218 if (caloFlag == AliCaloRawStreamV3::kLowGain) {
219 new(tmpLG[ilgDigit]) AliPHOSDigit(-1,absId,(Float_t)energy,(Float_t)time);
222 else if (caloFlag == AliCaloRawStreamV3::kHighGain) {
223 if(fitter->IsOverflow()) //Keep this digit to replace it by Low Gain later.
224 //If there is no LogGain it wil be removed by cut on Min E
225 new((*digits)[iDigit]) AliPHOSDigit(-1,absId,-1.f,(Float_t)time);
227 new((*digits)[iDigit]) AliPHOSDigit(-1,absId,(Float_t)energy,(Float_t)time);
230 } // End of NextChannel()
232 //Now scan created LG and HG digits and keep only those which appeared in both lists
233 //replace energy of HighGain digits only if there is overflow
234 //negative energy (overflow)
238 Int_t nLG1 = tmpLG.GetEntriesFast()-1 ;
240 for(Int_t iDig=0 ; iDig < digits->GetEntriesFast() ; iDig++) {
241 AliPHOSDigit * digHG = dynamic_cast<AliPHOSDigit*>(digits->At(iDig)) ;
242 if (!digHG) continue;
243 AliPHOSDigit * digLG = dynamic_cast<AliPHOSDigit*>(tmpLG.At(iLG)) ;
244 while(digLG && iLG<nLG1 && digHG->GetId()> digLG->GetId()){
246 digLG = dynamic_cast<AliPHOSDigit*>(tmpLG.At(iLG)) ;
248 absId=digHG->GetId() ;
249 fGeom->AbsToRelNumbering(absId,relId) ;
251 if(digLG && digHG->GetId() == digLG->GetId()){ //we found pair
252 if(digHG->GetEnergy()<0.){ //This is overflow in HG
253 digHG->SetTime(digLG->GetTime()) ;
254 digHG->SetEnergy(digLG->GetEnergy()) ;
257 else{ //no pair - remove
258 if(digHG->GetEnergy()<0.) //no pair, in saturation
259 digits->RemoveAt(iDig) ;
262 } // End of NextDDL()
264 CleanDigits(digits) ;
267 //____________________________________________________________________________
268 Double_t AliPHOSRawDigiProducer::CalibrateE(Double_t amp, Int_t* relId, Bool_t isLowGain)
270 // Convert EMC LG amplitude to HG (multipli by ~16)
271 // Calibration parameters are taken from calibration data base
273 Int_t module = relId[0];
274 Int_t column = relId[3];
275 Int_t row = relId[2];
276 if(relId[1]==0) { // this is EMC
278 amp*= fgCalibData->GetHighLowRatioEmc(module,column,row);
285 //____________________________________________________________________________
286 Double_t AliPHOSRawDigiProducer::CalibrateT(Double_t time, Int_t * relId, Bool_t /* isLowGain */)
289 time*=fPulseGenerator->GetRawFormatTimeTrigger() ;
291 Int_t module = relId[0];
292 Int_t column = relId[3];
293 Int_t row = relId[2];
294 if(relId[1]==0) { // this is EMC
295 time += fgCalibData->GetTimeShiftEmc(module,column,row);
302 //____________________________________________________________________________
303 void AliPHOSRawDigiProducer::CleanDigits(TClonesArray * digits)
305 // remove digits with amplitudes below threshold.
306 // remove digits in bad channels
307 // sort digits with icreasing AbsId
309 //remove digits in bad map and below threshold
310 Bool_t isBadMap = 0 ;
311 if(fgCalibData->GetNumOfEmcBadChannels()){
315 for(Int_t i=0; i<digits->GetEntriesFast(); i++){
316 AliPHOSDigit * digit = static_cast<AliPHOSDigit*>(digits->At(i)) ;
319 if ( (IsInEMC(digit) && digit->GetEnergy() < fEmcMinE) ||
320 (IsInCPV(digit) && digit->GetEnergy() < fCpvMinE) ){
321 digits->RemoveAt(i) ;
324 if(isBadMap){ //check bad map now
326 fGeom->AbsToRelNumbering(digit->GetId(), relid) ;
327 if(fgCalibData->IsBadChannelEmc(relid[0],relid[3],relid[2])){
328 digits->RemoveAt(i) ;
333 //Compress, sort and set indexes
335 // digits->Sort(); already sorted earlier
336 for (Int_t i = 0 ; i < digits->GetEntriesFast() ; i++) {
337 AliPHOSDigit *digit = static_cast<AliPHOSDigit*>( digits->At(i) ) ;
338 digit->SetIndexInList(i) ;
341 //____________________________________________________________________________
342 Bool_t AliPHOSRawDigiProducer::IsInEMC(AliPHOSDigit * digit) const
344 // Tells if (true) or not (false) the digit is in a PHOS-EMC module
345 return digit->GetId() <= fEmcCrystals ;
349 //____________________________________________________________________________
350 Bool_t AliPHOSRawDigiProducer::IsInCPV(AliPHOSDigit * digit) const
352 // Tells if (true) or not (false) the digit is in a PHOS-CPV module
353 return digit->GetId() > fEmcCrystals ;
355 //____________________________________________________________________________
356 void AliPHOSRawDigiProducer::GetCalibrationParameters()
358 // Set calibration parameters:
359 // if calibration database exists, they are read from database,
360 // otherwise, reconstruction stops in the constructor of AliPHOSCalibData
362 // It is a user responsilibity to open CDB before reconstruction, for example:
363 // AliCDBStorage* storage = AliCDBManager::Instance()->GetStorage("local://CalibDB");
366 fgCalibData = new AliPHOSCalibData(-1); //use AliCDBManager's run number
368 if (fgCalibData->GetCalibDataEmc() == 0)
369 AliFatal("Calibration parameters for PHOS EMC not found. Stop reconstruction.\n");
370 if (fgCalibData->GetCalibDataCpv() == 0)
371 AliFatal("Calibration parameters for PHOS CPV not found. Stop reconstruction.\n");