]>
Commit | Line | Data |
---|---|---|
ee299369 | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, 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$ */ | |
ee299369 | 17 | |
e5bbbc4e | 18 | //_________________________________________________________________________ |
19 | // Utility Class for handling Raw data | |
20 | // Does all transitions from Digits to Raw and vice versa, | |
21 | // for simu and reconstruction | |
22 | // | |
23 | // Note: the current version is still simplified. Only | |
24 | // one raw signal per digit is generated; either high-gain or low-gain | |
25 | // Need to add concurrent high and low-gain info in the future | |
26 | // No pedestal is added to the raw signal. | |
ee299369 | 27 | //*-- Author: Marco van Leeuwen (LBL) |
e5bbbc4e | 28 | |
ee299369 | 29 | #include "AliEMCALRawUtils.h" |
21cad85c | 30 | |
dff7354e | 31 | #include <TF1.h> |
32 | #include <TGraph.h> | |
33 | #include <TRandom.h> | |
e5bbbc4e | 34 | class TSystem; |
21cad85c | 35 | |
e5bbbc4e | 36 | class AliLog; |
72c58de0 | 37 | #include "AliRun.h" |
ee299369 | 38 | #include "AliRunLoader.h" |
e5bbbc4e | 39 | class AliCaloAltroMapping; |
ee299369 | 40 | #include "AliAltroBuffer.h" |
41 | #include "AliRawReader.h" | |
32cd4c24 | 42 | #include "AliCaloRawStreamV3.h" |
ee299369 | 43 | #include "AliDAQ.h" |
21cad85c | 44 | |
feedcab9 | 45 | #include "AliEMCALRecParam.h" |
ee299369 | 46 | #include "AliEMCALLoader.h" |
47 | #include "AliEMCALGeometry.h" | |
e5bbbc4e | 48 | class AliEMCALDigitizer; |
ee299369 | 49 | #include "AliEMCALDigit.h" |
20b636fc | 50 | #include "AliEMCAL.h" |
5e3106bc | 51 | #include "AliCaloCalibPedestal.h" |
9f467289 | 52 | #include "AliCaloFastAltroFitv0.h" |
c8603a2b | 53 | #include "AliCaloNeuralFit.h" |
16605c06 | 54 | #include "AliCaloBunchInfo.h" |
55 | #include "AliCaloFitResults.h" | |
7683df1d | 56 | #include "AliCaloRawAnalyzerFastFit.h" |
57 | #include "AliCaloRawAnalyzerNN.h" | |
16605c06 | 58 | #include "AliCaloRawAnalyzerLMS.h" |
59 | #include "AliCaloRawAnalyzerPeakFinder.h" | |
60 | #include "AliCaloRawAnalyzerCrude.h" | |
9f467289 | 61 | |
ee299369 | 62 | ClassImp(AliEMCALRawUtils) |
21cad85c | 63 | |
ee299369 | 64 | // Signal shape parameters |
89d338a6 | 65 | Int_t AliEMCALRawUtils::fgTimeBins = 256; // number of sampling bins of the raw RO signal (we typically use 15-50; theoretical max is 1k+) |
e5bbbc4e | 66 | Double_t AliEMCALRawUtils::fgTimeBinWidth = 100E-9 ; // each sample is 100 ns |
09974781 | 67 | Double_t AliEMCALRawUtils::fgTimeTrigger = 1.5E-6 ; // 15 time bins ~ 1.5 musec |
ee299369 | 68 | |
69 | // some digitization constants | |
70 | Int_t AliEMCALRawUtils::fgThreshold = 1; | |
71 | Int_t AliEMCALRawUtils::fgDDLPerSuperModule = 2; // 2 ddls per SuperModule | |
e5bbbc4e | 72 | Int_t AliEMCALRawUtils::fgPedestalValue = 32; // pedestal value for digits2raw |
73 | Double_t AliEMCALRawUtils::fgFEENoise = 3.; // 3 ADC channels of noise (sampled) | |
ee299369 | 74 | |
16605c06 | 75 | AliEMCALRawUtils::AliEMCALRawUtils(fitAlgorithm fitAlgo) |
b4133f05 | 76 | : fHighLowGainFactor(0.), fOrder(0), fTau(0.), fNoiseThreshold(0), |
9f467289 | 77 | fNPedSamples(0), fGeom(0), fOption(""), |
16605c06 | 78 | fRemoveBadChannels(kTRUE),fFittingAlgorithm(0),fRawAnalyzer(0) |
8cb998bd | 79 | { |
b4133f05 | 80 | |
81 | //These are default parameters. | |
82 | //Can be re-set from without with setter functions | |
9f467289 | 83 | //Already set in the OCDB and passed via setter in the AliEMCALReconstructor |
ee299369 | 84 | fHighLowGainFactor = 16. ; // adjusted for a low gain range of 82 GeV (10 bits) |
b4133f05 | 85 | fOrder = 2; // order of gamma fn |
86 | fTau = 2.35; // in units of timebin, from CERN 2007 testbeam | |
7643e728 | 87 | fNoiseThreshold = 3; // 3 ADC counts is approx. noise level |
88 | fNPedSamples = 4; // less than this value => likely pedestal samples | |
9f467289 | 89 | fRemoveBadChannels = kTRUE; //Remove bad channels before fitting |
16605c06 | 90 | fFittingAlgorithm = fitAlgo; |
7683df1d | 91 | |
92 | if (fitAlgo == kFastFit) { | |
93 | fRawAnalyzer = new AliCaloRawAnalyzerFastFit(); | |
94 | } | |
95 | else if (fitAlgo == kNeuralNet) { | |
96 | fRawAnalyzer = new AliCaloRawAnalyzerNN(); | |
97 | } | |
98 | else if (fitAlgo == kLMS) { | |
16605c06 | 99 | fRawAnalyzer = new AliCaloRawAnalyzerLMS(); |
100 | } | |
101 | else if (fitAlgo == kPeakFinder) { | |
102 | fRawAnalyzer = new AliCaloRawAnalyzerPeakFinder(); | |
103 | } | |
104 | else if (fitAlgo == kCrude) { | |
105 | fRawAnalyzer = new AliCaloRawAnalyzerCrude(); | |
106 | } | |
107 | else { | |
108 | fRawAnalyzer = new AliCaloRawAnalyzer(); | |
109 | } | |
110 | ||
65bdc82f | 111 | //Get Mapping RCU files from the AliEMCALRecParam |
112 | const TObjArray* maps = AliEMCALRecParam::GetMappings(); | |
113 | if(!maps) AliFatal("Cannot retrieve ALTRO mappings!!"); | |
114 | ||
21cad85c | 115 | for(Int_t i = 0; i < 4; i++) { |
65bdc82f | 116 | fMapping[i] = (AliAltroMapping*)maps->At(i); |
117 | } | |
118 | ||
72c58de0 | 119 | //To make sure we match with the geometry in a simulation file, |
120 | //let's try to get it first. If not, take the default geometry | |
33c3c91a | 121 | AliRunLoader *rl = AliRunLoader::Instance(); |
c61fe3b4 | 122 | if(!rl) AliError("Cannot find RunLoader!"); |
72c58de0 | 123 | if (rl->GetAliRun() && rl->GetAliRun()->GetDetector("EMCAL")) { |
124 | fGeom = dynamic_cast<AliEMCAL*>(rl->GetAliRun()->GetDetector("EMCAL"))->GetGeometry(); | |
125 | } else { | |
126 | AliInfo(Form("Using default geometry in raw reco")); | |
937d0661 | 127 | fGeom = AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaultGeometryName()); |
65bdc82f | 128 | } |
129 | ||
72c58de0 | 130 | if(!fGeom) AliFatal(Form("Could not get geometry!")); |
131 | ||
65bdc82f | 132 | } |
133 | ||
134 | //____________________________________________________________________________ | |
16605c06 | 135 | AliEMCALRawUtils::AliEMCALRawUtils(AliEMCALGeometry *pGeometry, fitAlgorithm fitAlgo) |
5544799a | 136 | : fHighLowGainFactor(0.), fOrder(0), fTau(0.), fNoiseThreshold(0), |
9f467289 | 137 | fNPedSamples(0), fGeom(pGeometry), fOption(""), |
16605c06 | 138 | fRemoveBadChannels(kTRUE),fFittingAlgorithm(0),fRawAnalyzer() |
5544799a | 139 | { |
140 | // | |
141 | // Initialize with the given geometry - constructor required by HLT | |
142 | // HLT does not use/support AliRunLoader(s) instances | |
143 | // This is a minimum intervention solution | |
144 | // Comment by MPloskon@lbl.gov | |
145 | // | |
146 | ||
147 | //These are default parameters. | |
148 | //Can be re-set from without with setter functions | |
9f467289 | 149 | //Already set in the OCDB and passed via setter in the AliEMCALReconstructor |
5544799a | 150 | fHighLowGainFactor = 16. ; // adjusted for a low gain range of 82 GeV (10 bits) |
151 | fOrder = 2; // order of gamma fn | |
152 | fTau = 2.35; // in units of timebin, from CERN 2007 testbeam | |
7643e728 | 153 | fNoiseThreshold = 3; // 3 ADC counts is approx. noise level |
154 | fNPedSamples = 4; // less than this value => likely pedestal samples | |
9f467289 | 155 | fRemoveBadChannels = kTRUE; //Remove bad channels before fitting |
16605c06 | 156 | fFittingAlgorithm = fitAlgo; |
7683df1d | 157 | |
158 | if (fitAlgo == kFastFit) { | |
159 | fRawAnalyzer = new AliCaloRawAnalyzerFastFit(); | |
160 | } | |
161 | else if (fitAlgo == kNeuralNet) { | |
162 | fRawAnalyzer = new AliCaloRawAnalyzerNN(); | |
163 | } | |
164 | else if (fitAlgo == kLMS) { | |
16605c06 | 165 | fRawAnalyzer = new AliCaloRawAnalyzerLMS(); |
166 | } | |
167 | else if (fitAlgo == kPeakFinder) { | |
168 | fRawAnalyzer = new AliCaloRawAnalyzerPeakFinder(); | |
169 | } | |
170 | else if (fitAlgo == kCrude) { | |
171 | fRawAnalyzer = new AliCaloRawAnalyzerCrude(); | |
172 | } | |
173 | else { | |
174 | fRawAnalyzer = new AliCaloRawAnalyzer(); | |
175 | } | |
176 | ||
5544799a | 177 | //Get Mapping RCU files from the AliEMCALRecParam |
178 | const TObjArray* maps = AliEMCALRecParam::GetMappings(); | |
179 | if(!maps) AliFatal("Cannot retrieve ALTRO mappings!!"); | |
180 | ||
21cad85c | 181 | for(Int_t i = 0; i < 4; i++) { |
5544799a | 182 | fMapping[i] = (AliAltroMapping*)maps->At(i); |
183 | } | |
184 | ||
185 | if(!fGeom) AliFatal(Form("Could not get geometry!")); | |
186 | ||
187 | } | |
188 | ||
189 | //____________________________________________________________________________ | |
65bdc82f | 190 | AliEMCALRawUtils::AliEMCALRawUtils(const AliEMCALRawUtils& rawU) |
191 | : TObject(), | |
192 | fHighLowGainFactor(rawU.fHighLowGainFactor), | |
b4133f05 | 193 | fOrder(rawU.fOrder), |
194 | fTau(rawU.fTau), | |
195 | fNoiseThreshold(rawU.fNoiseThreshold), | |
196 | fNPedSamples(rawU.fNPedSamples), | |
65bdc82f | 197 | fGeom(rawU.fGeom), |
9f467289 | 198 | fOption(rawU.fOption), |
199 | fRemoveBadChannels(rawU.fRemoveBadChannels), | |
16605c06 | 200 | fFittingAlgorithm(rawU.fFittingAlgorithm), |
201 | fRawAnalyzer(rawU.fRawAnalyzer) | |
65bdc82f | 202 | { |
203 | //copy ctor | |
204 | fMapping[0] = rawU.fMapping[0]; | |
205 | fMapping[1] = rawU.fMapping[1]; | |
21cad85c | 206 | fMapping[2] = rawU.fMapping[2]; |
207 | fMapping[3] = rawU.fMapping[3]; | |
65bdc82f | 208 | } |
209 | ||
210 | //____________________________________________________________________________ | |
211 | AliEMCALRawUtils& AliEMCALRawUtils::operator =(const AliEMCALRawUtils &rawU) | |
212 | { | |
213 | //assignment operator | |
214 | ||
215 | if(this != &rawU) { | |
216 | fHighLowGainFactor = rawU.fHighLowGainFactor; | |
b4133f05 | 217 | fOrder = rawU.fOrder; |
218 | fTau = rawU.fTau; | |
219 | fNoiseThreshold = rawU.fNoiseThreshold; | |
220 | fNPedSamples = rawU.fNPedSamples; | |
65bdc82f | 221 | fGeom = rawU.fGeom; |
222 | fOption = rawU.fOption; | |
9f467289 | 223 | fRemoveBadChannels = rawU.fRemoveBadChannels; |
224 | fFittingAlgorithm = rawU.fFittingAlgorithm; | |
16605c06 | 225 | fRawAnalyzer = rawU.fRawAnalyzer; |
65bdc82f | 226 | fMapping[0] = rawU.fMapping[0]; |
227 | fMapping[1] = rawU.fMapping[1]; | |
21cad85c | 228 | fMapping[2] = rawU.fMapping[2]; |
229 | fMapping[3] = rawU.fMapping[3]; | |
65bdc82f | 230 | } |
231 | ||
232 | return *this; | |
233 | ||
ee299369 | 234 | } |
65bdc82f | 235 | |
ee299369 | 236 | //____________________________________________________________________________ |
237 | AliEMCALRawUtils::~AliEMCALRawUtils() { | |
e5bbbc4e | 238 | //dtor |
65bdc82f | 239 | |
ee299369 | 240 | } |
65bdc82f | 241 | |
ee299369 | 242 | //____________________________________________________________________________ |
65bdc82f | 243 | void AliEMCALRawUtils::Digits2Raw() |
ee299369 | 244 | { |
245 | // convert digits of the current event to raw data | |
246 | ||
33c3c91a | 247 | AliRunLoader *rl = AliRunLoader::Instance(); |
ee299369 | 248 | AliEMCALLoader *loader = dynamic_cast<AliEMCALLoader*>(rl->GetDetectorLoader("EMCAL")); |
249 | ||
250 | // get the digits | |
251 | loader->LoadDigits("EMCAL"); | |
252 | loader->GetEvent(); | |
253 | TClonesArray* digits = loader->Digits() ; | |
254 | ||
255 | if (!digits) { | |
256 | Warning("Digits2Raw", "no digits found !"); | |
257 | return; | |
258 | } | |
65bdc82f | 259 | |
ee299369 | 260 | static const Int_t nDDL = 12*2; // 12 SM hardcoded for now. Buffers allocated dynamically, when needed, so just need an upper limit here |
261 | AliAltroBuffer* buffers[nDDL]; | |
262 | for (Int_t i=0; i < nDDL; i++) | |
263 | buffers[i] = 0; | |
264 | ||
e2c2134b | 265 | TArrayI adcValuesLow(fgTimeBins); |
266 | TArrayI adcValuesHigh(fgTimeBins); | |
ee299369 | 267 | |
ee299369 | 268 | // loop over digits (assume ordered digits) |
269 | for (Int_t iDigit = 0; iDigit < digits->GetEntries(); iDigit++) { | |
270 | AliEMCALDigit* digit = dynamic_cast<AliEMCALDigit *>(digits->At(iDigit)) ; | |
271 | if (digit->GetAmp() < fgThreshold) | |
272 | continue; | |
273 | ||
274 | //get cell indices | |
275 | Int_t nSM = 0; | |
276 | Int_t nIphi = 0; | |
277 | Int_t nIeta = 0; | |
278 | Int_t iphi = 0; | |
279 | Int_t ieta = 0; | |
280 | Int_t nModule = 0; | |
65bdc82f | 281 | fGeom->GetCellIndex(digit->GetId(), nSM, nModule, nIphi, nIeta); |
282 | fGeom->GetCellPhiEtaIndexInSModule(nSM, nModule, nIphi, nIeta,iphi, ieta) ; | |
ee299369 | 283 | |
21cad85c | 284 | //Check which is the RCU, 0 or 1, of the cell. |
ee299369 | 285 | Int_t iRCU = -111; |
286 | //RCU0 | |
287 | if (0<=iphi&&iphi<8) iRCU=0; // first cable row | |
288 | else if (8<=iphi&&iphi<16 && 0<=ieta&&ieta<24) iRCU=0; // first half; | |
289 | //second cable row | |
290 | //RCU1 | |
291 | else if(8<=iphi&&iphi<16 && 24<=ieta&&ieta<48) iRCU=1; // second half; | |
292 | //second cable row | |
293 | else if(16<=iphi&&iphi<24) iRCU=1; // third cable row | |
21cad85c | 294 | |
295 | if (nSM%2==1) iRCU = 1 - iRCU; // swap for odd=C side, to allow us to cable both sides the same | |
296 | ||
e36e3bcf | 297 | if (iRCU<0) |
298 | Fatal("Digits2Raw()","Non-existent RCU number: %d", iRCU); | |
ee299369 | 299 | |
300 | //Which DDL? | |
301 | Int_t iDDL = fgDDLPerSuperModule* nSM + iRCU; | |
302 | if (iDDL >= nDDL) | |
303 | Fatal("Digits2Raw()","Non-existent DDL board number: %d", iDDL); | |
304 | ||
305 | if (buffers[iDDL] == 0) { | |
306 | // open new file and write dummy header | |
307 | TString fileName = AliDAQ::DdlFileName("EMCAL",iDDL); | |
21cad85c | 308 | //Select mapping file RCU0A, RCU0C, RCU1A, RCU1C |
309 | Int_t iRCUside=iRCU+(nSM%2)*2; | |
310 | //iRCU=0 and even (0) SM -> RCU0A.data 0 | |
311 | //iRCU=1 and even (0) SM -> RCU1A.data 1 | |
312 | //iRCU=0 and odd (1) SM -> RCU0C.data 2 | |
313 | //iRCU=1 and odd (1) SM -> RCU1C.data 3 | |
314 | //cout<<" nSM "<<nSM<<"; iRCU "<<iRCU<<"; iRCUside "<<iRCUside<<endl; | |
315 | buffers[iDDL] = new AliAltroBuffer(fileName.Data(),fMapping[iRCUside]); | |
ee299369 | 316 | buffers[iDDL]->WriteDataHeader(kTRUE, kFALSE); //Dummy; |
317 | } | |
318 | ||
319 | // out of time range signal (?) | |
320 | if (digit->GetTimeR() > GetRawFormatTimeMax() ) { | |
321 | AliInfo("Signal is out of time range.\n"); | |
322 | buffers[iDDL]->FillBuffer((Int_t)digit->GetAmp()); | |
323 | buffers[iDDL]->FillBuffer(GetRawFormatTimeBins() ); // time bin | |
324 | buffers[iDDL]->FillBuffer(3); // bunch length | |
325 | buffers[iDDL]->WriteTrailer(3, ieta, iphi, nSM); // trailer | |
326 | // calculate the time response function | |
327 | } else { | |
e2c2134b | 328 | Bool_t lowgain = RawSampledResponse(digit->GetTimeR(), digit->GetAmp(), adcValuesHigh.GetArray(), adcValuesLow.GetArray()) ; |
ee299369 | 329 | if (lowgain) |
e2c2134b | 330 | buffers[iDDL]->WriteChannel(ieta, iphi, 0, GetRawFormatTimeBins(), adcValuesLow.GetArray(), fgThreshold); |
ee299369 | 331 | else |
e2c2134b | 332 | buffers[iDDL]->WriteChannel(ieta,iphi, 1, GetRawFormatTimeBins(), adcValuesHigh.GetArray(), fgThreshold); |
ee299369 | 333 | } |
334 | } | |
335 | ||
336 | // write headers and close files | |
337 | for (Int_t i=0; i < nDDL; i++) { | |
338 | if (buffers[i]) { | |
339 | buffers[i]->Flush(); | |
340 | buffers[i]->WriteDataHeader(kFALSE, kFALSE); | |
341 | delete buffers[i]; | |
342 | } | |
343 | } | |
65bdc82f | 344 | |
ee299369 | 345 | loader->UnloadDigits(); |
346 | } | |
347 | ||
348 | //____________________________________________________________________________ | |
16605c06 | 349 | void AliEMCALRawUtils::Raw2Digits(AliRawReader* reader,TClonesArray *digitsArr, const AliCaloCalibPedestal* pedbadmap) |
ee299369 | 350 | { |
65bdc82f | 351 | // convert raw data of the current event to digits |
ee299369 | 352 | |
c47157cd | 353 | digitsArr->Clear(); |
ee299369 | 354 | |
c47157cd | 355 | if (!digitsArr) { |
ee299369 | 356 | Error("Raw2Digits", "no digits found !"); |
357 | return; | |
358 | } | |
359 | if (!reader) { | |
360 | Error("Raw2Digits", "no raw reader found !"); | |
361 | return; | |
362 | } | |
363 | ||
32cd4c24 | 364 | AliCaloRawStreamV3 in(reader,"EMCAL",fMapping); |
ee299369 | 365 | // Select EMCAL DDL's; |
7643e728 | 366 | reader->Select("EMCAL",0,43); // 43 = AliEMCALGeoParams::fgkLastAltroDDL |
feedcab9 | 367 | |
16605c06 | 368 | // fRawAnalyzer setup |
369 | fRawAnalyzer->SetAmpCut(fNoiseThreshold); | |
370 | fRawAnalyzer->SetFitArrayCut(fNoiseThreshold); | |
371 | fRawAnalyzer->SetIsZeroSuppressed(true); // TMP - should use stream->IsZeroSuppressed(), or altro cfg registers later | |
ee299369 | 372 | |
16605c06 | 373 | // channel info parameters |
ee299369 | 374 | Int_t lowGain = 0; |
e5bbbc4e | 375 | Int_t caloFlag = 0; // low, high gain, or TRU, or LED ref. |
ee299369 | 376 | |
32cd4c24 | 377 | // start loop over input stream |
378 | while (in.NextDDL()) { | |
379 | while (in.NextChannel()) { | |
7643e728 | 380 | |
381 | //Check if the signal is high or low gain and then do the fit, | |
16605c06 | 382 | //if it is from TRU or LEDMon do not fit |
7643e728 | 383 | caloFlag = in.GetCaloFlag(); |
384 | if (caloFlag != 0 && caloFlag != 1) continue; | |
385 | ||
5e3106bc | 386 | //Do not fit bad channels |
9f467289 | 387 | if(fRemoveBadChannels && pedbadmap->IsBadChannel(in.GetModule(),in.GetColumn(),in.GetRow())) { |
5e3106bc | 388 | //printf("Tower from SM %d, column %d, row %d is BAD!!! Skip \n", in.GetModule(),in.GetColumn(),in.GetRow()); |
389 | continue; | |
390 | } | |
391 | ||
16605c06 | 392 | vector<AliCaloBunchInfo> bunchlist; |
32cd4c24 | 393 | while (in.NextBunch()) { |
16605c06 | 394 | bunchlist.push_back( AliCaloBunchInfo(in.GetStartTimeBin(), in.GetBunchLength(), in.GetSignals() ) ); |
395 | } // loop over bunches | |
7643e728 | 396 | |
16605c06 | 397 | Float_t time = 0; |
398 | Float_t amp = 0; | |
399 | ||
7683df1d | 400 | if ( fFittingAlgorithm == kFastFit || fFittingAlgorithm == kNeuralNet || fFittingAlgorithm == kLMS || fFittingAlgorithm == kPeakFinder || fFittingAlgorithm == kCrude) { |
16605c06 | 401 | // all functionality to determine amp and time etc is encapsulated inside the Evaluate call for these methods |
402 | AliCaloFitResults fitResults = fRawAnalyzer->Evaluate( bunchlist, in.GetAltroCFG1(), in.GetAltroCFG2()); | |
403 | ||
404 | amp = fitResults.GetAmp(); | |
405 | time = fitResults.GetTof(); | |
406 | } | |
407 | else { // for the other methods we for now use the functionality of | |
408 | // AliCaloRawAnalyzer as well, to select samples and prepare for fits, | |
409 | // if it looks like there is something to fit | |
410 | ||
411 | // parameters init. | |
412 | Float_t ampEstimate = 0; | |
413 | short maxADC = 0; | |
414 | short timeEstimate = 0; | |
415 | Float_t pedEstimate = 0; | |
416 | Int_t first = 0; | |
417 | Int_t last = 0; | |
418 | Int_t bunchIndex = 0; | |
419 | // | |
420 | // The PreFitEvaluateSamples + later call to FitRaw will hopefully | |
421 | // be replaced by a single Evaluate call or so soon, like for the other | |
422 | // methods, but this should be good enough for evaluation of | |
423 | // the methods for now (Jan. 2010) | |
424 | // | |
425 | int nsamples = fRawAnalyzer->PreFitEvaluateSamples( bunchlist, in.GetAltroCFG1(), in.GetAltroCFG2(), bunchIndex, ampEstimate, maxADC, timeEstimate, pedEstimate, first, last); | |
7643e728 | 426 | |
16605c06 | 427 | if (ampEstimate > fNoiseThreshold) { // something worth looking at |
7643e728 | 428 | |
16605c06 | 429 | time = timeEstimate; |
430 | amp = ampEstimate; | |
431 | ||
432 | if ( nsamples > 1 ) { // possibly something to fit | |
433 | FitRaw(first, last, amp, time); | |
9f467289 | 434 | } |
16605c06 | 435 | |
436 | if ( amp>0 && time>0 ) { // brief sanity check of fit results | |
437 | ||
438 | // check fit results: should be consistent with initial estimates | |
439 | // more magic numbers, but very loose cuts, for now.. | |
440 | // We have checked that amp and ampEstimate values are positive so division for assymmetry | |
441 | // calculation should be OK/safe | |
442 | Float_t ampAsymm = (amp - ampEstimate)/(amp + ampEstimate); | |
443 | if ( (TMath::Abs(ampAsymm) > 0.1) ) { | |
444 | AliDebug(2,Form("Fit results amp %f time %f not consistent with expectations ped %f max-ped %f time %d", | |
445 | amp, time, pedEstimate, ampEstimate, timeEstimate)); | |
446 | ||
447 | // what should do we do then? skip this channel or assign the simple estimate? | |
448 | // for now just overwrite the fit results with the simple estimate | |
449 | amp = ampEstimate; | |
450 | time = timeEstimate; | |
451 | } // asymm check | |
452 | } // amp & time check | |
453 | } // ampEstimate check | |
454 | } // method selection | |
455 | ||
456 | if (amp > fNoiseThreshold) { // something to be stored | |
457 | Int_t id = fGeom->GetAbsCellIdFromCellIndexes(in.GetModule(), in.GetRow(), in.GetColumn()) ; | |
7643e728 | 458 | lowGain = in.IsLowGain(); |
459 | ||
16605c06 | 460 | // go from time-bin units to physical time fgtimetrigger |
461 | time = time * GetRawFormatTimeBinWidth(); // skip subtraction of fgTimeTrigger? | |
7643e728 | 462 | |
463 | AliDebug(2,Form("id %d lowGain %d amp %g", id, lowGain, amp)); | |
464 | // printf("Added tower: SM %d, row %d, column %d, amp %3.2f\n",in.GetModule(), in.GetRow(), in.GetColumn(),amp); | |
465 | // round off amplitude value to nearest integer | |
466 | AddDigit(digitsArr, id, lowGain, TMath::Nint(amp), time); | |
467 | } | |
468 | ||
32cd4c24 | 469 | } // end while over channel |
470 | } //end while over DDL's, of input stream | |
16605c06 | 471 | |
ee299369 | 472 | return ; |
473 | } | |
474 | ||
475 | //____________________________________________________________________________ | |
82cbdfca | 476 | void AliEMCALRawUtils::AddDigit(TClonesArray *digitsArr, Int_t id, Int_t lowGain, Int_t amp, Float_t time) { |
477 | // | |
478 | // Add a new digit. | |
479 | // This routine checks whether a digit exists already for this tower | |
480 | // and then decides whether to use the high or low gain info | |
481 | // | |
482 | // Called by Raw2Digits | |
483 | ||
484 | AliEMCALDigit *digit = 0, *tmpdigit = 0; | |
82cbdfca | 485 | TIter nextdigit(digitsArr); |
486 | while (digit == 0 && (tmpdigit = (AliEMCALDigit*) nextdigit())) { | |
487 | if (tmpdigit->GetId() == id) | |
488 | digit = tmpdigit; | |
489 | } | |
490 | ||
491 | if (!digit) { // no digit existed for this tower; create one | |
a7ec7165 | 492 | if (lowGain && amp > fgkOverflowCut) |
82cbdfca | 493 | amp = Int_t(fHighLowGainFactor * amp); |
494 | Int_t idigit = digitsArr->GetEntries(); | |
495 | new((*digitsArr)[idigit]) AliEMCALDigit( -1, -1, id, amp, time, idigit) ; | |
496 | } | |
497 | else { // a digit already exists, check range | |
b4133f05 | 498 | // (use high gain if signal < cut value, otherwise low gain) |
82cbdfca | 499 | if (lowGain) { // new digit is low gain |
b4133f05 | 500 | if (digit->GetAmp() > fgkOverflowCut) { // use if stored digit is out of range |
82cbdfca | 501 | digit->SetAmp(Int_t(fHighLowGainFactor * amp)); |
502 | digit->SetTime(time); | |
503 | } | |
504 | } | |
b4133f05 | 505 | else if (amp < fgkOverflowCut) { // new digit is high gain; use if not out of range |
82cbdfca | 506 | digit->SetAmp(amp); |
507 | digit->SetTime(time); | |
508 | } | |
509 | } | |
510 | } | |
511 | ||
512 | //____________________________________________________________________________ | |
16605c06 | 513 | void AliEMCALRawUtils::FitRaw(const Int_t firstTimeBin, const Int_t lastTimeBin, Float_t & amp, Float_t & time) const |
514 | { // Fits the raw signal time distribution | |
515 | ||
516 | //-------------------------------------------------- | |
517 | //Do the fit, different fitting algorithms available | |
518 | //-------------------------------------------------- | |
519 | int nsamples = lastTimeBin - firstTimeBin + 1; | |
ee299369 | 520 | |
16605c06 | 521 | switch(fFittingAlgorithm) { |
522 | case kStandard: | |
523 | { | |
7683df1d | 524 | if (nsamples < 3) { return; } // nothing much to fit |
16605c06 | 525 | //printf("Standard fitter \n"); |
7683df1d | 526 | |
16605c06 | 527 | // Create Graph to hold data we will fit |
7683df1d | 528 | TGraph *gSig = new TGraph( nsamples); |
529 | for (int i=0; i<nsamples; i++) { | |
530 | Int_t timebin = firstTimeBin + i; | |
531 | gSig->SetPoint(timebin, timebin, fRawAnalyzer->GetReversed(timebin)); | |
532 | } | |
533 | ||
16605c06 | 534 | TF1 * signalF = new TF1("signal", RawResponseFunction, 0, GetRawFormatTimeBins(), 5); |
535 | signalF->SetParameters(10.,5.,fTau,fOrder,0.); //set all defaults once, just to be safe | |
536 | signalF->SetParNames("amp","t0","tau","N","ped"); | |
537 | signalF->FixParameter(2,fTau); // tau in units of time bin | |
538 | signalF->FixParameter(3,fOrder); // order | |
539 | signalF->FixParameter(4, 0); // pedestal should be subtracted when we get here | |
540 | signalF->SetParameter(1, time); | |
541 | signalF->SetParameter(0, amp); | |
542 | ||
543 | gSig->Fit(signalF, "QROW"); // Note option 'W': equal errors on all points | |
544 | ||
545 | // assign fit results | |
546 | amp = signalF->GetParameter(0); | |
547 | time = signalF->GetParameter(1); | |
e9dbb64a | 548 | |
16605c06 | 549 | delete signalF; |
550 | ||
551 | // cross-check with ParabolaFit to see if the results make sense | |
552 | FitParabola(gSig, amp); // amp is possibly updated | |
82cbdfca | 553 | |
16605c06 | 554 | //printf("Std : Amp %f, time %g\n",amp, time); |
7683df1d | 555 | delete gSig; // delete TGraph |
16605c06 | 556 | |
557 | break; | |
558 | }//kStandard Fitter | |
559 | //---------------------------- | |
7683df1d | 560 | case kLogFit: |
16605c06 | 561 | { |
7683df1d | 562 | if (nsamples < 3) { return; } // nothing much to fit |
563 | //printf("LogFit \n"); | |
564 | ||
565 | // Create Graph to hold data we will fit | |
566 | TGraph *gSigLog = new TGraph( nsamples); | |
567 | for (int i=0; i<nsamples; i++) { | |
568 | Int_t timebin = firstTimeBin + i; | |
569 | gSigLog->SetPoint(timebin, timebin, TMath::Log(fRawAnalyzer->GetReversed(timebin) ) ); | |
7643e728 | 570 | } |
7683df1d | 571 | |
572 | TF1 * signalFLog = new TF1("signalLog", RawResponseFunctionLog, 0, GetRawFormatTimeBins(), 5); | |
573 | signalFLog->SetParameters(2.3, 5.,fTau,fOrder,0.); //set all defaults once, just to be safe | |
574 | signalFLog->SetParNames("amplog","t0","tau","N","ped"); | |
575 | signalFLog->FixParameter(2,fTau); // tau in units of time bin | |
576 | signalFLog->FixParameter(3,fOrder); // order | |
577 | signalFLog->FixParameter(4, 0); // pedestal should be subtracted when we get here | |
578 | signalFLog->SetParameter(1, time); | |
579 | if (amp>=1) { | |
580 | signalFLog->SetParameter(0, TMath::Log(amp)); | |
16605c06 | 581 | } |
7683df1d | 582 | |
583 | gSigLog->Fit(signalFLog, "QROW"); // Note option 'W': equal errors on all points | |
584 | ||
585 | // assign fit results | |
586 | Double_t amplog = signalFLog->GetParameter(0); //Not Amp, but Log of Amp | |
587 | amp = TMath::Exp(amplog); | |
588 | time = signalFLog->GetParameter(1); | |
589 | ||
590 | delete signalFLog; | |
591 | //printf("LogFit: Amp %f, time %g\n",amp, time); | |
592 | delete gSigLog; | |
16605c06 | 593 | break; |
7683df1d | 594 | } //kLogFit |
595 | //---------------------------- | |
596 | ||
16605c06 | 597 | //---------------------------- |
598 | }//switch fitting algorithms | |
fb070798 | 599 | |
16605c06 | 600 | return; |
601 | } | |
8cb998bd | 602 | |
16605c06 | 603 | //__________________________________________________________________ |
604 | void AliEMCALRawUtils::FitParabola(const TGraph *gSig, Float_t & amp) const | |
605 | { | |
606 | //BEG YS alternative methods to calculate the amplitude | |
607 | Double_t * ymx = gSig->GetX() ; | |
608 | Double_t * ymy = gSig->GetY() ; | |
609 | const Int_t kN = 3 ; | |
610 | Double_t ymMaxX[kN] = {0., 0., 0.} ; | |
611 | Double_t ymMaxY[kN] = {0., 0., 0.} ; | |
612 | Double_t ymax = 0. ; | |
613 | // find the maximum amplitude | |
614 | Int_t ymiMax = 0 ; | |
615 | for (Int_t ymi = 0; ymi < gSig->GetN(); ymi++) { | |
616 | if (ymy[ymi] > ymMaxY[0] ) { | |
617 | ymMaxY[0] = ymy[ymi] ; //<========== This is the maximum amplitude | |
618 | ymMaxX[0] = ymx[ymi] ; | |
619 | ymiMax = ymi ; | |
620 | } | |
621 | } | |
622 | // find the maximum by fitting a parabola through the max and the two adjacent samples | |
623 | if ( ymiMax < gSig->GetN()-1 && ymiMax > 0) { | |
624 | ymMaxY[1] = ymy[ymiMax+1] ; | |
625 | ymMaxY[2] = ymy[ymiMax-1] ; | |
626 | ymMaxX[1] = ymx[ymiMax+1] ; | |
627 | ymMaxX[2] = ymx[ymiMax-1] ; | |
628 | if (ymMaxY[0]*ymMaxY[1]*ymMaxY[2] > 0) { | |
629 | //fit a parabola through the 3 points y= a+bx+x*x*x | |
630 | Double_t sy = 0 ; | |
631 | Double_t sx = 0 ; | |
632 | Double_t sx2 = 0 ; | |
633 | Double_t sx3 = 0 ; | |
634 | Double_t sx4 = 0 ; | |
635 | Double_t sxy = 0 ; | |
636 | Double_t sx2y = 0 ; | |
637 | for (Int_t i = 0; i < kN ; i++) { | |
638 | sy += ymMaxY[i] ; | |
639 | sx += ymMaxX[i] ; | |
640 | sx2 += ymMaxX[i]*ymMaxX[i] ; | |
641 | sx3 += ymMaxX[i]*ymMaxX[i]*ymMaxX[i] ; | |
642 | sx4 += ymMaxX[i]*ymMaxX[i]*ymMaxX[i]*ymMaxX[i] ; | |
643 | sxy += ymMaxX[i]*ymMaxY[i] ; | |
644 | sx2y += ymMaxX[i]*ymMaxX[i]*ymMaxY[i] ; | |
645 | } | |
646 | Double_t cN = (sx2y*kN-sy*sx2)*(sx3*sx-sx2*sx2)-(sx2y*sx-sxy*sx2)*(sx3*kN-sx*sx2); | |
647 | Double_t cD = (sx4*kN-sx2*sx2)*(sx3*sx-sx2*sx2)-(sx4*sx-sx3*sx2)*(sx3*kN-sx*sx2) ; | |
648 | Double_t c = cN / cD ; | |
649 | Double_t b = ((sx2y*kN-sy*sx2)-c*(sx4*kN-sx2*sx2))/(sx3*kN-sx*sx2) ; | |
650 | Double_t a = (sy-b*sx-c*sx2)/kN ; | |
651 | Double_t xmax = -b/(2*c) ; | |
652 | ymax = a + b*xmax + c*xmax*xmax ;//<========== This is the maximum amplitude | |
653 | } | |
654 | } | |
655 | ||
656 | Double_t diff = TMath::Abs(1-ymMaxY[0]/amp) ; | |
657 | if (diff > 0.1) | |
658 | amp = ymMaxY[0] ; | |
659 | //printf("Yves : Amp %f, time %g\n",amp, time); | |
660 | //END YS | |
ee299369 | 661 | return; |
662 | } | |
16605c06 | 663 | |
ee299369 | 664 | //__________________________________________________________________ |
665 | Double_t AliEMCALRawUtils::RawResponseFunction(Double_t *x, Double_t *par) | |
666 | { | |
8cb998bd | 667 | // Matches version used in 2007 beam test |
668 | // | |
ee299369 | 669 | // Shape of the electronics raw reponse: |
670 | // It is a semi-gaussian, 2nd order Gamma function of the general form | |
671 | // | |
7643e728 | 672 | // xx = (t - t0 + tau) / tau [xx is just a convenient help variable] |
673 | // F = A * (xx**N * exp( N * ( 1 - xx) ) for xx >= 0 | |
674 | // F = 0 for xx < 0 | |
ee299369 | 675 | // |
676 | // parameters: | |
8cb998bd | 677 | // A: par[0] // Amplitude = peak value |
678 | // t0: par[1] | |
679 | // tau: par[2] | |
680 | // N: par[3] | |
681 | // ped: par[4] | |
ee299369 | 682 | // |
683 | Double_t signal ; | |
8cb998bd | 684 | Double_t tau =par[2]; |
e5bbbc4e | 685 | Double_t n =par[3]; |
8cb998bd | 686 | Double_t ped = par[4]; |
687 | Double_t xx = ( x[0] - par[1] + tau ) / tau ; | |
ee299369 | 688 | |
5a056daa | 689 | if (xx <= 0) |
8cb998bd | 690 | signal = ped ; |
ee299369 | 691 | else { |
e5bbbc4e | 692 | signal = ped + par[0] * TMath::Power(xx , n) * TMath::Exp(n * (1 - xx )) ; |
ee299369 | 693 | } |
694 | return signal ; | |
695 | } | |
696 | ||
7683df1d | 697 | //__________________________________________________________________ |
698 | Double_t AliEMCALRawUtils::RawResponseFunctionLog(Double_t *x, Double_t *par) | |
699 | { | |
700 | // Matches version used in 2007 beam test | |
701 | // | |
702 | // Shape of the electronics raw reponse: | |
703 | // It is a semi-gaussian, 2nd order Gamma function of the general form | |
704 | // | |
705 | // xx = (t - t0 + tau) / tau [xx is just a convenient help variable] | |
706 | // F = A * (xx**N * exp( N * ( 1 - xx) ) for xx >= 0 | |
707 | // F = 0 for xx < 0 | |
708 | // | |
709 | // parameters: | |
710 | // Log[A]: par[0] // Amplitude = peak value | |
711 | // t0: par[1] | |
712 | // tau: par[2] | |
713 | // N: par[3] | |
714 | // ped: par[4] | |
715 | // | |
716 | Double_t signal ; | |
717 | Double_t tau =par[2]; | |
718 | Double_t n =par[3]; | |
719 | //Double_t ped = par[4]; // not used | |
720 | Double_t xx = ( x[0] - par[1] + tau ) / tau ; | |
721 | ||
722 | if (xx < 0) | |
723 | signal = par[0] - n*TMath::Log(TMath::Abs(xx)) + n * (1 - xx ) ; | |
724 | else { | |
725 | signal = par[0] + n*TMath::Log(xx) + n * (1 - xx ) ; | |
726 | } | |
727 | return signal ; | |
728 | } | |
729 | ||
ee299369 | 730 | //__________________________________________________________________ |
dff7354e | 731 | Bool_t AliEMCALRawUtils::RawSampledResponse(const Double_t dtime, const Double_t damp, |
732 | Int_t * adcH, Int_t * adcL, const Int_t keyErr) const | |
ee299369 | 733 | { |
734 | // for a start time dtime and an amplitude damp given by digit, | |
735 | // calculates the raw sampled response AliEMCAL::RawResponseFunction | |
736 | ||
ee299369 | 737 | Bool_t lowGain = kFALSE ; |
738 | ||
48a56166 | 739 | // A: par[0] // Amplitude = peak value |
740 | // t0: par[1] | |
741 | // tau: par[2] | |
742 | // N: par[3] | |
743 | // ped: par[4] | |
744 | ||
56e13066 | 745 | TF1 signalF("signal", RawResponseFunction, 0, GetRawFormatTimeBins(), 5); |
48a56166 | 746 | signalF.SetParameter(0, damp) ; |
56e13066 | 747 | signalF.SetParameter(1, (dtime + fgTimeTrigger)/fgTimeBinWidth) ; |
b4133f05 | 748 | signalF.SetParameter(2, fTau) ; |
749 | signalF.SetParameter(3, fOrder); | |
fe93d365 | 750 | signalF.SetParameter(4, fgPedestalValue); |
ee299369 | 751 | |
dff7354e | 752 | Double_t signal=0.0, noise=0.0; |
ee299369 | 753 | for (Int_t iTime = 0; iTime < GetRawFormatTimeBins(); iTime++) { |
dff7354e | 754 | signal = signalF.Eval(iTime) ; |
fe93d365 | 755 | |
7643e728 | 756 | // Next lines commeted for the moment but in principle it is not necessary to add |
ff10f540 | 757 | // extra noise since noise already added at the digits level. |
7643e728 | 758 | |
fe93d365 | 759 | //According to Terry Awes, 13-Apr-2008 |
760 | //add gaussian noise in quadrature to each sample | |
09974781 | 761 | //Double_t noise = gRandom->Gaus(0.,fgFEENoise); |
fe93d365 | 762 | //signal = sqrt(signal*signal + noise*noise); |
763 | ||
e2c2134b | 764 | // March 17,09 for fast fit simulations by Alexei Pavlinov. |
dff7354e | 765 | // Get from PHOS analysis. In some sense it is open question. |
766 | if(keyErr>0) { | |
767 | noise = gRandom->Gaus(0.,fgFEENoise); | |
768 | signal += noise; | |
769 | } | |
7643e728 | 770 | |
ee299369 | 771 | adcH[iTime] = static_cast<Int_t>(signal + 0.5) ; |
b4133f05 | 772 | if ( adcH[iTime] > fgkRawSignalOverflow ){ // larger than 10 bits |
773 | adcH[iTime] = fgkRawSignalOverflow ; | |
ee299369 | 774 | lowGain = kTRUE ; |
775 | } | |
776 | ||
777 | signal /= fHighLowGainFactor; | |
778 | ||
779 | adcL[iTime] = static_cast<Int_t>(signal + 0.5) ; | |
b4133f05 | 780 | if ( adcL[iTime] > fgkRawSignalOverflow) // larger than 10 bits |
781 | adcL[iTime] = fgkRawSignalOverflow ; | |
ee299369 | 782 | } |
783 | return lowGain ; | |
784 | } |