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.),
64 // Default constructor
66 fGeom=AliPHOSGeometry::GetInstance() ;
67 if(!fGeom) fGeom = AliPHOSGeometry::GetInstance("IHEP");
69 fEmcCrystals=fGeom->GetNCristalsInModule()*fGeom->GetNModules() ;
70 fPulseGenerator = new AliPHOSPulseGenerator();
71 GetCalibrationParameters() ;
74 //--------------------------------------------------------------------------------------
75 AliPHOSRawDigiProducer::AliPHOSRawDigiProducer(AliRawReader *rawReader,
76 AliAltroMapping **mapping):
80 fSampleQualityCut(1.),
85 fRawReader(rawReader),
90 // Default constructor
92 fGeom=AliPHOSGeometry::GetInstance() ;
93 if(!fGeom) fGeom = AliPHOSGeometry::GetInstance("IHEP");
95 fEmcCrystals=fGeom->GetNCristalsInModule()*fGeom->GetNModules() ;
96 fPulseGenerator = new AliPHOSPulseGenerator();
97 GetCalibrationParameters() ;
99 fRawStream = new AliCaloRawStreamV3(rawReader,"PHOS",mapping);
102 //--------------------------------------------------------------------------------------
103 AliPHOSRawDigiProducer::AliPHOSRawDigiProducer(const AliPHOSRawDigiProducer &dp):
107 fSampleQualityCut(1.),
120 fEmcMinE = dp.fEmcMinE ;
121 fCpvMinE = dp.fCpvMinE ;
122 fSampleQualityCut = dp.fSampleQualityCut;
123 fSampleToSec = dp.fSampleToSec ;
124 fEmcCrystals = dp.fEmcCrystals ;
125 fPulseGenerator = new AliPHOSPulseGenerator();
128 //--------------------------------------------------------------------------------------
129 AliPHOSRawDigiProducer& AliPHOSRawDigiProducer::operator= (const AliPHOSRawDigiProducer &dp)
133 if(&dp == this) return *this;
135 fEmcMinE = dp.fEmcMinE ;
136 fCpvMinE = dp.fCpvMinE ;
137 fSampleQualityCut = dp.fSampleQualityCut ;
138 fSampleToSec = dp.fSampleToSec ;
139 fEmcCrystals = dp.fEmcCrystals ;
141 if(fPulseGenerator) delete fPulseGenerator ;
142 fPulseGenerator = new AliPHOSPulseGenerator();
145 //--------------------------------------------------------------------------------------
146 AliPHOSRawDigiProducer::~AliPHOSRawDigiProducer()
149 if(fPulseGenerator) delete fPulseGenerator ;
152 delete [] fADCValuesLG;
153 delete [] fADCValuesHG;
155 //--------------------------------------------------------------------------------------
156 void AliPHOSRawDigiProducer::MakeDigits(TClonesArray *digits, AliPHOSRawFitterv0* fitter)
158 // Create a temporary array of LG digits and then make digits from raw data
160 TClonesArray *tmpLG = new TClonesArray("AliPHOSDigit",10000) ;
161 MakeDigits(digits, tmpLG, fitter);
165 //--------------------------------------------------------------------------------------
166 void AliPHOSRawDigiProducer::MakeDigits(TClonesArray *digits, TClonesArray *tmpDigLG, AliPHOSRawFitterv0* fitter)
169 //TClonesArray *digits, *tmpDigLG and raw data fitter should be provided by calling function.
172 Int_t relId[4], absId=-1, caloFlag=-1;
174 const Double_t baseLine=1. ; //Minimal energy of digit in ADC ch.
176 //Calculate conversion coeff. from Sample time step to seconds
177 //If OCDB contains negative or zero value - use one from RCU trailer
178 //Negative value in OCDB is used only for simulation of raw digits
179 if(fgCalibData->GetSampleTimeStep()>0.)
180 fSampleToSec=fgCalibData->GetSampleTimeStep() ;
182 fSampleToSec=fRawStream->GetTSample() ;
184 // Clear a temporary array for LowGain digits
188 //Let fitter subtract pedestals in case of ZS
189 fitter->SetCalibData(fgCalibData) ;
191 while (fRawStream->NextDDL()) {
192 while (fRawStream->NextChannel()) {
193 relId[0] = 5 - fRawStream->GetModule() ; // counts from 1 to 5
194 relId[1] = 0; // 0=EMC
195 relId[2] = fRawStream->GetCellX() + 1; // counts from 1 to 64
196 relId[3] = fRawStream->GetCellZ() + 1; // counts from 1 to 56
197 caloFlag = fRawStream->GetCaloFlag(); // 0=LG, 1=HG, 2=TRU
199 if(caloFlag!=0 && caloFlag!=1) continue; //TRU data!
201 fitter->SetChannelGeo(relId[0],relId[2],relId[3],caloFlag);
203 if(fitter->GetAmpOffset()==0 && fitter->GetAmpThreshold()==0) {
204 short value = fRawStream->GetAltroCFG1();
205 bool ZeroSuppressionEnabled = (value >> 15) & 0x1;
206 if(ZeroSuppressionEnabled) {
207 short offset = (value >> 10) & 0xf;
208 short threshold = value & 0x3ff;
209 fitter->SubtractPedestals(kFALSE);
210 fitter->SetAmpOffset(offset);
211 fitter->SetAmpThreshold(threshold);
215 fGeom->RelToAbsNumbering(relId, absId);
217 fitter->SetNBunches(0);
220 while (fRawStream->NextBunch()) { //Take the first in time bunch
221 const UShort_t *sig = fRawStream->GetSignals();
222 sigStart = fRawStream->GetStartTimeBin();
223 sigLength = fRawStream->GetBunchLength();
224 fitter->Eval(sig,sigStart,sigLength);
225 if (caloFlag == AliCaloRawStreamV3::kLowGain) {
226 delete [] fADCValuesLG;
227 fADCValuesLG = new Int_t[sigLength];
228 for (Int_t i=0; i<sigLength; i++)
229 fADCValuesLG[sigLength-i-1] = sig[i];
231 else if (caloFlag == AliCaloRawStreamV3::kHighGain) {
232 delete [] fADCValuesHG;
233 fADCValuesHG = new Int_t[sigLength];
234 for (Int_t i=0; i<sigLength; i++)
235 fADCValuesHG[sigLength-i-1] = sig[i];
237 } // End of NextBunch()
240 Double_t energy = fitter->GetEnergy() ;
241 Double_t time = fitter->GetTime() ;
242 if(energy<=baseLine) //in ADC channels
245 //remove digits with bad shape. Fitter should calculate quality so that
246 //in default case quality [0,1], while larger values of quality mean somehow
247 //corrupted samples, 999 means obviously corrupted sample.
248 //It is difficult to fit samples with overflow (even setting cut on overflow values)
249 //because too few points are left to fit. So we do not evaluate samples with overflow
251 if(fitter->GetSignalQuality() > fSampleQualityCut && !(fitter->IsOverflow()))
254 energy = CalibrateE(energy,relId,!caloFlag) ;
256 //convert time from sample bin units to s
258 //CalibrateT moved to Clusterizer
259 // time = CalibrateT(time,relId,!caloFlag) ;
260 // subtract RCU L1 phase (L1Phase is in seconds) w.r.t. L0:
261 //Very strange behaviour of electronics, but cross-checkes several times...
262 if( fRawStream->GetL1Phase()<55.*1.e-9 ) //for phase=0,25,50
263 time -= fRawStream->GetL1Phase();
270 if (caloFlag == AliCaloRawStreamV3::kLowGain) {
271 new((*tmpDigLG)[ilgDigit]) AliPHOSDigit(-1,absId,(Float_t)energy,(Float_t)time);
272 if (sigLength>0 && fADCValuesLG!=0)
273 static_cast<AliPHOSDigit*>(tmpDigLG->At(ilgDigit))->SetALTROSamplesLG(sigLength,fADCValuesLG);
276 else if (caloFlag == AliCaloRawStreamV3::kHighGain) {
277 if(fitter->IsOverflow()) //Keep this digit to replace it by Low Gain later.
278 //If there is no LogGain it wil be removed by cut on Min E
279 new((*digits)[iDigit]) AliPHOSDigit(-1,absId,-1.f,(Float_t)time);
281 new((*digits)[iDigit]) AliPHOSDigit(-1,absId,(Float_t)energy,(Float_t)time);
282 if (sigLength>0 && fADCValuesHG!=0)
283 static_cast<AliPHOSDigit*>(digits->At(iDigit))->SetALTROSamplesHG(sigLength,fADCValuesHG);
286 } // End of NextChannel()
288 //Now scan created LG and HG digits and keep only those which appeared in both lists
289 //replace energy of HighGain digits only if there is overflow
290 //negative energy (overflow)
294 Int_t nLG1 = tmpDigLG->GetEntriesFast()-1 ;
296 for(Int_t iDig=0 ; iDig < digits->GetEntriesFast() ; iDig++) {
297 AliPHOSDigit * digHG = dynamic_cast<AliPHOSDigit*>(digits->At(iDig)) ;
298 if (!digHG) continue;
299 AliPHOSDigit * digLG = dynamic_cast<AliPHOSDigit*>(tmpDigLG->At(iLG)) ;
300 while(digLG && iLG<nLG1 && digHG->GetId()> digLG->GetId()){
302 digLG = dynamic_cast<AliPHOSDigit*>(tmpDigLG->At(iLG)) ;
304 absId=digHG->GetId() ;
305 fGeom->AbsToRelNumbering(absId,relId) ;
307 if(digLG && digHG->GetId() == digLG->GetId()){ //we found pair
308 if(digHG->GetEnergy()<0.){ //This is overflow in HG
309 digHG->SetTime(digLG->GetTime()) ;
310 digHG->SetEnergy(digLG->GetEnergy()) ;
311 digHG->SetLG(kTRUE) ;
314 else{ //no pair - remove
315 if(digHG->GetEnergy()<0.) //no pair, in saturation
316 digits->RemoveAt(iDig) ;
319 } // End of NextDDL()
321 CleanDigits(digits) ;
324 //____________________________________________________________________________
325 Double_t AliPHOSRawDigiProducer::CalibrateE(Double_t amp, Int_t* relId, Bool_t isLowGain)
327 // Convert EMC LG amplitude to HG (multipli by ~16)
328 // Calibration parameters are taken from calibration data base
330 Int_t module = relId[0];
331 Int_t column = relId[3];
332 Int_t row = relId[2];
333 if(relId[1]==0) { // this is EMC
335 amp*= fgCalibData->GetHighLowRatioEmc(module,column,row);
342 //____________________________________________________________________________
343 Double_t AliPHOSRawDigiProducer::CalibrateT(Double_t time, Int_t * relId, Bool_t /* isLowGain */)
347 Int_t module = relId[0];
348 Int_t column = relId[3];
349 Int_t row = relId[2];
350 if(relId[1]==0) { // this is EMC
351 time += fgCalibData->GetTimeShiftEmc(module,column,row);
358 //____________________________________________________________________________
359 void AliPHOSRawDigiProducer::CleanDigits(TClonesArray * digits)
361 // remove digits with amplitudes below threshold.
362 // remove digits in bad channels
363 // sort digits with icreasing AbsId
365 //remove digits in bad map and below threshold
366 Bool_t isBadMap = 0 ;
367 if(fgCalibData->GetNumOfEmcBadChannels()){
371 for(Int_t i=0; i<digits->GetEntriesFast(); i++){
372 AliPHOSDigit * digit = static_cast<AliPHOSDigit*>(digits->At(i)) ;
375 if ( (IsInEMC(digit) && digit->GetEnergy() < fEmcMinE) ||
376 (IsInCPV(digit) && digit->GetEnergy() < fCpvMinE) ){
377 digits->RemoveAt(i) ;
380 if(isBadMap){ //check bad map now
382 fGeom->AbsToRelNumbering(digit->GetId(), relid) ;
383 if(fgCalibData->IsBadChannelEmc(relid[0],relid[3],relid[2])){
384 digits->RemoveAt(i) ;
389 //Compress, sort and set indexes
391 // digits->Sort(); already sorted earlier
392 for (Int_t i = 0 ; i < digits->GetEntriesFast() ; i++) {
393 AliPHOSDigit *digit = static_cast<AliPHOSDigit*>( digits->At(i) ) ;
394 digit->SetIndexInList(i) ;
397 //____________________________________________________________________________
398 Bool_t AliPHOSRawDigiProducer::IsInEMC(AliPHOSDigit * digit) const
400 // Tells if (true) or not (false) the digit is in a PHOS-EMC module
401 return digit->GetId() <= fEmcCrystals ;
405 //____________________________________________________________________________
406 Bool_t AliPHOSRawDigiProducer::IsInCPV(AliPHOSDigit * digit) const
408 // Tells if (true) or not (false) the digit is in a PHOS-CPV module
409 return digit->GetId() > fEmcCrystals ;
411 //____________________________________________________________________________
412 void AliPHOSRawDigiProducer::GetCalibrationParameters()
414 // Set calibration parameters:
415 // if calibration database exists, they are read from database,
416 // otherwise, reconstruction stops in the constructor of AliPHOSCalibData
418 // It is a user responsilibity to open CDB before reconstruction, for example:
419 // AliCDBStorage* storage = AliCDBManager::Instance()->GetStorage("local://CalibDB");
422 fgCalibData = new AliPHOSCalibData(-1); //use AliCDBManager's run number
424 if (fgCalibData->GetCalibDataEmc() == 0)
425 AliFatal("Calibration parameters for PHOS EMC not found. Stop reconstruction.\n");
426 if (fgCalibData->GetCalibDataCpv() == 0)
427 AliFatal("Calibration parameters for PHOS CPV not found. Stop reconstruction.\n");