]>
Commit | Line | Data |
---|---|---|
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 | |
379c5c09 | 19 | //using AliPHOSRawFitter. |
7bc140a5 | 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" |
379c5c09 | 37 | #include "AliPHOSRawFitterv0.h" |
88fb5e50 | 38 | #include "AliPHOSGeometry.h" |
39 | #include "AliPHOSDigit.h" | |
c0394bfb | 40 | #include "AliPHOSCalibData.h" |
39569d36 | 41 | #include "AliPHOSPulseGenerator.h" |
379c5c09 | 42 | #include "AliCaloRawStreamV3.h" |
c0394bfb | 43 | #include "AliLog.h" |
88fb5e50 | 44 | |
45 | ClassImp(AliPHOSRawDigiProducer) | |
46 | ||
c0394bfb | 47 | AliPHOSCalibData * AliPHOSRawDigiProducer::fgCalibData = 0 ; |
48 | ||
49 | //-------------------------------------------------------------------------------------- | |
7e88424f | 50 | AliPHOSRawDigiProducer::AliPHOSRawDigiProducer(): |
51 | TObject(), | |
52 | fEmcMinE(0.), | |
53 | fCpvMinE(0.), | |
54 | fSampleQualityCut(1.), | |
6f47f50d | 55 | fSampleToSec(0.), |
7e88424f | 56 | fEmcCrystals(0), |
57 | fGeom(0), | |
379c5c09 | 58 | fPulseGenerator(0), |
59 | fRawReader(0), | |
60 | fRawStream(0) | |
7e88424f | 61 | { |
62 | // Default constructor | |
70d93620 | 63 | |
c0394bfb | 64 | fGeom=AliPHOSGeometry::GetInstance() ; |
65 | if(!fGeom) fGeom = AliPHOSGeometry::GetInstance("IHEP"); | |
66 | ||
67 | fEmcCrystals=fGeom->GetNCristalsInModule()*fGeom->GetNModules() ; | |
39569d36 | 68 | fPulseGenerator = new AliPHOSPulseGenerator(); |
c0394bfb | 69 | GetCalibrationParameters() ; |
8be3a30a | 70 | |
c0394bfb | 71 | } |
379c5c09 | 72 | //-------------------------------------------------------------------------------------- |
73 | AliPHOSRawDigiProducer::AliPHOSRawDigiProducer(AliRawReader *rawReader, | |
74 | AliAltroMapping **mapping): | |
75 | TObject(), | |
76 | fEmcMinE(0.), | |
77 | fCpvMinE(0.), | |
78 | fSampleQualityCut(1.), | |
6f47f50d | 79 | fSampleToSec(0.), |
379c5c09 | 80 | fEmcCrystals(0), |
81 | fGeom(0), | |
82 | fPulseGenerator(0), | |
83 | fRawReader(rawReader), | |
84 | fRawStream(0) | |
85 | { | |
86 | // Default constructor | |
87 | ||
88 | fGeom=AliPHOSGeometry::GetInstance() ; | |
89 | if(!fGeom) fGeom = AliPHOSGeometry::GetInstance("IHEP"); | |
90 | ||
91 | fEmcCrystals=fGeom->GetNCristalsInModule()*fGeom->GetNModules() ; | |
92 | fPulseGenerator = new AliPHOSPulseGenerator(); | |
93 | GetCalibrationParameters() ; | |
94 | ||
95 | fRawStream = new AliCaloRawStreamV3(rawReader,"PHOS",mapping); | |
96 | ||
97 | } | |
98 | //-------------------------------------------------------------------------------------- | |
7e88424f | 99 | AliPHOSRawDigiProducer::AliPHOSRawDigiProducer(const AliPHOSRawDigiProducer &dp): |
100 | TObject(), | |
101 | fEmcMinE(0.), | |
102 | fCpvMinE(0.), | |
103 | fSampleQualityCut(1.), | |
6f47f50d | 104 | fSampleToSec(0.), |
7e88424f | 105 | fEmcCrystals(0), |
106 | fGeom(0), | |
379c5c09 | 107 | fPulseGenerator(0), |
108 | fRawReader(0), | |
109 | fRawStream(0) | |
7e88424f | 110 | { |
111 | // Copy constructor | |
c0394bfb | 112 | |
113 | fEmcMinE = dp.fEmcMinE ; | |
114 | fCpvMinE = dp.fCpvMinE ; | |
f78c9781 | 115 | fSampleQualityCut = dp.fSampleQualityCut; |
6f47f50d | 116 | fSampleToSec = dp.fSampleToSec ; |
c0394bfb | 117 | fEmcCrystals = dp.fEmcCrystals ; |
39569d36 | 118 | fPulseGenerator = new AliPHOSPulseGenerator(); |
c0394bfb | 119 | fGeom = dp.fGeom ; |
120 | } | |
121 | //-------------------------------------------------------------------------------------- | |
7e88424f | 122 | AliPHOSRawDigiProducer& AliPHOSRawDigiProducer::operator= (const AliPHOSRawDigiProducer &dp) |
123 | { | |
124 | // Assign operator | |
125 | ||
c0394bfb | 126 | if(&dp == this) return *this; |
127 | ||
128 | fEmcMinE = dp.fEmcMinE ; | |
129 | fCpvMinE = dp.fCpvMinE ; | |
70d93620 | 130 | fSampleQualityCut = dp.fSampleQualityCut ; |
6f47f50d | 131 | fSampleToSec = dp.fSampleToSec ; |
c0394bfb | 132 | fEmcCrystals = dp.fEmcCrystals ; |
133 | fGeom = dp.fGeom ; | |
39569d36 | 134 | if(fPulseGenerator) delete fPulseGenerator ; |
135 | fPulseGenerator = new AliPHOSPulseGenerator(); | |
c0394bfb | 136 | return *this; |
137 | } | |
379c5c09 | 138 | //-------------------------------------------------------------------------------------- |
7e88424f | 139 | AliPHOSRawDigiProducer::~AliPHOSRawDigiProducer() |
140 | { | |
379c5c09 | 141 | // Destructor |
7e88424f | 142 | if(fPulseGenerator) delete fPulseGenerator ; |
143 | fPulseGenerator=0 ; | |
379c5c09 | 144 | delete fRawStream; |
39569d36 | 145 | } |
7bc140a5 | 146 | //-------------------------------------------------------------------------------------- |
379c5c09 | 147 | void AliPHOSRawDigiProducer::MakeDigits(TClonesArray *digits, AliPHOSRawFitterv0* fitter) |
88fb5e50 | 148 | { |
7bc140a5 | 149 | //Makes the job. |
379c5c09 | 150 | //TClonesArray *digits and raw data fitter should be provided by calling function. |
7bc140a5 | 151 | |
88fb5e50 | 152 | digits->Clear(); |
153 | ||
379c5c09 | 154 | Int_t iDigit=0 ; |
155 | Int_t relId[4], absId=-1, caloFlag=-1; | |
fdd91c5a | 156 | |
c0394bfb | 157 | const Double_t baseLine=1. ; //Minimal energy of digit in ADC ch. |
6f47f50d | 158 | |
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() ; | |
164 | else | |
165 | fSampleToSec=fRawStream->GetTSample() ; | |
fdd91c5a | 166 | |
c0394bfb | 167 | //Temporary array for LowGain digits |
168 | TClonesArray tmpLG("AliPHOSDigit",10000) ; | |
169 | Int_t ilgDigit=0 ; | |
bafc1087 | 170 | |
379c5c09 | 171 | //Let fitter subtract pedestals in case of ZS |
172 | fitter->SetCalibData(fgCalibData) ; | |
c0394bfb | 173 | |
379c5c09 | 174 | while (fRawStream->NextDDL()) { |
175 | while (fRawStream->NextChannel()) { | |
1281504a | 176 | relId[0] = fRawStream->GetModule() + 1; // counts from 1 to 5 |
379c5c09 | 177 | relId[1] = 0; |
1281504a | 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 | |
f4ca5622 | 181 | |
182 | if(caloFlag!=0 && caloFlag!=1) continue; //TRU data! | |
183 | ||
e10f780e | 184 | fitter->SetChannelGeo(relId[0],relId[2],relId[3],caloFlag); |
c4dad9d2 | 185 | if(fitter->GetAmpOffset()==0 && fitter->GetAmpThreshold()==0) { |
186 | short value = fRawStream->GetAltroCFG1(); | |
187 | bool ZeroSuppressionEnabled = (value >> 15) & 0x1; | |
188 | if(ZeroSuppressionEnabled) { | |
189 | short offset = (value >> 10) & 0xf; | |
190 | short threshold = value & 0x3ff; | |
191 | fitter->SubtractPedestals(kFALSE); | |
192 | fitter->SetAmpOffset(offset); | |
193 | fitter->SetAmpThreshold(threshold); | |
194 | } | |
195 | } | |
196 | ||
379c5c09 | 197 | fGeom->RelToAbsNumbering(relId, absId); |
f4ca5622 | 198 | |
379c5c09 | 199 | Int_t nBunches = 0; |
200 | while (fRawStream->NextBunch()) { | |
201 | nBunches++; | |
202 | if (nBunches > 1) continue; | |
203 | const UShort_t *sig = fRawStream->GetSignals(); | |
204 | Int_t sigStart = fRawStream->GetStartTimeBin(); | |
205 | Int_t sigLength = fRawStream->GetBunchLength(); | |
92236b27 | 206 | fitter->Eval(sig,sigStart,sigLength); |
379c5c09 | 207 | } // End of NextBunch() |
70d93620 | 208 | |
379c5c09 | 209 | fitter->SetNBunches(nBunches); |
379c5c09 | 210 | |
211 | Double_t energy = fitter->GetEnergy() ; | |
212 | Double_t time = fitter->GetTime() ; | |
213 | if(energy<=baseLine) //in ADC channels | |
214 | continue ; | |
88fb5e50 | 215 | |
379c5c09 | 216 | //remove digits with bad shape. Fitter should calculate quality so that |
217 | //in default case quality [0,1], while larger values of quality mean somehow | |
218 | //corrupted samples, 999 means obviously corrupted sample. | |
219 | //It is difficult to fit samples with overflow (even setting cut on overflow values) | |
220 | //because too few points are left to fit. So we do not evaluate samples with overflow | |
c0394bfb | 221 | |
379c5c09 | 222 | if(fitter->GetSignalQuality() > fSampleQualityCut && !(fitter->IsOverflow())) |
223 | continue ; | |
224 | ||
225 | // energy = CalibrateE(energy,relId,lowGainFlag) ; | |
226 | // time = CalibrateT(time,relId,lowGainFlag) ; | |
6f47f50d | 227 | |
228 | //convert time from sample bin units to s | |
229 | time*=fSampleToSec ; | |
379c5c09 | 230 | |
231 | if(energy <= 0.) | |
232 | continue; | |
233 | ||
234 | if (caloFlag == AliCaloRawStreamV3::kLowGain) { | |
235 | new(tmpLG[ilgDigit]) AliPHOSDigit(-1,absId,(Float_t)energy,(Float_t)time); | |
236 | ilgDigit++ ; | |
237 | } | |
238 | else if (caloFlag == AliCaloRawStreamV3::kHighGain) { | |
239 | if(fitter->IsOverflow()) //Keep this digit to replace it by Low Gain later. | |
240 | //If there is no LogGain it wil be removed by cut on Min E | |
241 | new((*digits)[iDigit]) AliPHOSDigit(-1,absId,-1.f,(Float_t)time); | |
242 | else | |
243 | new((*digits)[iDigit]) AliPHOSDigit(-1,absId,(Float_t)energy,(Float_t)time); | |
244 | iDigit++; | |
245 | } | |
246 | } // End of NextChannel() | |
c0394bfb | 247 | |
379c5c09 | 248 | //Now scan created LG and HG digits and keep only those which appeared in both lists |
249 | //replace energy of HighGain digits only if there is overflow | |
250 | //negative energy (overflow) | |
251 | digits->Sort() ; | |
252 | tmpLG.Sort() ; | |
253 | Int_t iLG = 0; | |
254 | Int_t nLG1 = tmpLG.GetEntriesFast()-1 ; | |
255 | ||
256 | for(Int_t iDig=0 ; iDig < digits->GetEntriesFast() ; iDig++) { | |
257 | AliPHOSDigit * digHG = dynamic_cast<AliPHOSDigit*>(digits->At(iDig)) ; | |
258 | if (!digHG) continue; | |
259 | AliPHOSDigit * digLG = dynamic_cast<AliPHOSDigit*>(tmpLG.At(iLG)) ; | |
260 | while(digLG && iLG<nLG1 && digHG->GetId()> digLG->GetId()){ | |
261 | iLG++ ; | |
262 | digLG = dynamic_cast<AliPHOSDigit*>(tmpLG.At(iLG)) ; | |
263 | } | |
264 | absId=digHG->GetId() ; | |
265 | fGeom->AbsToRelNumbering(absId,relId) ; | |
a7c985dc | 266 | |
379c5c09 | 267 | if(digLG && digHG->GetId() == digLG->GetId()){ //we found pair |
268 | if(digHG->GetEnergy()<0.){ //This is overflow in HG | |
269 | digHG->SetTime(digLG->GetTime()) ; | |
270 | digHG->SetEnergy(digLG->GetEnergy()) ; | |
271 | } | |
379c5c09 | 272 | } |
273 | else{ //no pair - remove | |
fdd91c5a | 274 | if(digHG->GetEnergy()<0.) //no pair, in saturation |
275 | digits->RemoveAt(iDig) ; | |
88fb5e50 | 276 | } |
88fb5e50 | 277 | } |
379c5c09 | 278 | } // End of NextDDL() |
c0394bfb | 279 | |
280 | CleanDigits(digits) ; | |
379c5c09 | 281 | |
c0394bfb | 282 | } |
283 | //____________________________________________________________________________ | |
284 | Double_t AliPHOSRawDigiProducer::CalibrateE(Double_t amp, Int_t* relId, Bool_t isLowGain) | |
285 | { | |
634d2178 | 286 | // Convert EMC LG amplitude to HG (multipli by ~16) |
287 | // Calibration parameters are taken from calibration data base | |
c0394bfb | 288 | if(fgCalibData){ |
289 | Int_t module = relId[0]; | |
290 | Int_t column = relId[3]; | |
291 | Int_t row = relId[2]; | |
292 | if(relId[1]==0) { // this is EMC | |
293 | if(isLowGain){ | |
294 | amp*= fgCalibData->GetHighLowRatioEmc(module,column,row); | |
88fb5e50 | 295 | } |
c0394bfb | 296 | return amp ; |
297 | } | |
298 | } | |
299 | return 0; | |
300 | } | |
301 | //____________________________________________________________________________ | |
302 | Double_t AliPHOSRawDigiProducer::CalibrateT(Double_t time, Int_t * relId, Bool_t /* isLowGain */) | |
303 | { | |
304 | //Calibrate time | |
39569d36 | 305 | time*=fPulseGenerator->GetRawFormatTimeTrigger() ; |
c0394bfb | 306 | if(fgCalibData){ |
307 | Int_t module = relId[0]; | |
308 | Int_t column = relId[3]; | |
309 | Int_t row = relId[2]; | |
310 | if(relId[1]==0) { // this is EMC | |
311 | time += fgCalibData->GetTimeShiftEmc(module,column,row); | |
312 | return time ; | |
313 | } | |
314 | } | |
315 | ||
316 | return -999.; | |
317 | } | |
318 | //____________________________________________________________________________ | |
319 | void AliPHOSRawDigiProducer::CleanDigits(TClonesArray * digits) | |
320 | { | |
321 | // remove digits with amplitudes below threshold. | |
322 | // remove digits in bad channels | |
323 | // sort digits with icreasing AbsId | |
324 | ||
325 | //remove digits in bad map and below threshold | |
326 | Bool_t isBadMap = 0 ; | |
327 | if(fgCalibData->GetNumOfEmcBadChannels()){ | |
328 | isBadMap=1 ; | |
329 | } | |
330 | ||
331 | for(Int_t i=0; i<digits->GetEntriesFast(); i++){ | |
332 | AliPHOSDigit * digit = static_cast<AliPHOSDigit*>(digits->At(i)) ; | |
333 | if(!digit) | |
334 | continue ; | |
335 | if ( (IsInEMC(digit) && digit->GetEnergy() < fEmcMinE) || | |
336 | (IsInCPV(digit) && digit->GetEnergy() < fCpvMinE) ){ | |
337 | digits->RemoveAt(i) ; | |
338 | continue ; | |
339 | } | |
340 | if(isBadMap){ //check bad map now | |
341 | Int_t relid[4] ; | |
342 | fGeom->AbsToRelNumbering(digit->GetId(), relid) ; | |
a65517aa | 343 | if(fgCalibData->IsBadChannelEmc(relid[0],relid[3],relid[2])){ |
c0394bfb | 344 | digits->RemoveAt(i) ; |
88fb5e50 | 345 | } |
346 | } | |
88fb5e50 | 347 | } |
348 | ||
c0394bfb | 349 | //Compress, sort and set indexes |
350 | digits->Compress() ; | |
351 | // digits->Sort(); already sorted earlier | |
352 | for (Int_t i = 0 ; i < digits->GetEntriesFast() ; i++) { | |
353 | AliPHOSDigit *digit = static_cast<AliPHOSDigit*>( digits->At(i) ) ; | |
354 | digit->SetIndexInList(i) ; | |
355 | } | |
356 | } | |
357 | //____________________________________________________________________________ | |
358 | Bool_t AliPHOSRawDigiProducer::IsInEMC(AliPHOSDigit * digit) const | |
359 | { | |
360 | // Tells if (true) or not (false) the digit is in a PHOS-EMC module | |
361 | return digit->GetId() <= fEmcCrystals ; | |
362 | ||
363 | } | |
364 | ||
365 | //____________________________________________________________________________ | |
366 | Bool_t AliPHOSRawDigiProducer::IsInCPV(AliPHOSDigit * digit) const | |
367 | { | |
368 | // Tells if (true) or not (false) the digit is in a PHOS-CPV module | |
369 | return digit->GetId() > fEmcCrystals ; | |
370 | } | |
371 | //____________________________________________________________________________ | |
372 | void AliPHOSRawDigiProducer::GetCalibrationParameters() | |
373 | { | |
374 | // Set calibration parameters: | |
375 | // if calibration database exists, they are read from database, | |
376 | // otherwise, reconstruction stops in the constructor of AliPHOSCalibData | |
377 | // | |
378 | // It is a user responsilibity to open CDB before reconstruction, for example: | |
379 | // AliCDBStorage* storage = AliCDBManager::Instance()->GetStorage("local://CalibDB"); | |
380 | ||
381 | if (!fgCalibData){ | |
382 | fgCalibData = new AliPHOSCalibData(-1); //use AliCDBManager's run number | |
383 | } | |
384 | if (fgCalibData->GetCalibDataEmc() == 0) | |
385 | AliFatal("Calibration parameters for PHOS EMC not found. Stop reconstruction.\n"); | |
386 | if (fgCalibData->GetCalibDataCpv() == 0) | |
387 | AliFatal("Calibration parameters for PHOS CPV not found. Stop reconstruction.\n"); | |
88fb5e50 | 388 | } |