]>
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$ */ | |
17 | /* History of cvs commits: | |
18 | * | |
c47157cd | 19 | * $Log$ |
48a56166 | 20 | * Revision 1.10 2007/12/06 13:58:11 hristov |
21 | * Additional pritection. Do not delete the mapping, it is owned by another class | |
22 | * | |
e36e3bcf | 23 | * Revision 1.9 2007/12/06 02:19:51 jklay |
24 | * incorporated fitting procedure from testbeam analysis into AliRoot | |
25 | * | |
8cb998bd | 26 | * Revision 1.8 2007/12/05 02:30:51 jklay |
27 | * modification to read Altro mappings into AliEMCALRecParam and pass to AliEMCALRawUtils from AliEMCALReconstructor; add option to AliEMCALRawUtils to set old RCU format (for testbeam) or not | |
28 | * | |
feedcab9 | 29 | * Revision 1.7 2007/11/14 15:51:46 gustavo |
30 | * Take out few unnecessary prints | |
31 | * | |
6d0b6861 | 32 | * Revision 1.6 2007/11/01 01:23:51 mvl |
33 | * Removed call to SetOldRCUFormat, which is only needed for testbeam data | |
34 | * | |
f31c5945 | 35 | * Revision 1.5 2007/11/01 01:20:33 mvl |
36 | * Further improvement of peak finding; more robust fit | |
37 | * | |
e9dbb64a | 38 | * Revision 1.4 2007/10/31 17:15:24 mvl |
39 | * Fixed bug in raw data unpacking; Added pedestal to signal fit; Added logic to deal with high/low gain | |
40 | * | |
82cbdfca | 41 | * Revision 1.3 2007/09/27 08:36:46 mvl |
42 | * More robust setting of fit range in FitRawSignal (P. Hristov) | |
43 | * | |
5a056daa | 44 | * Revision 1.2 2007/09/03 20:55:35 jklay |
45 | * EMCAL e-by-e reconstruction methods from Cvetan | |
46 | * | |
c47157cd | 47 | * Revision 1.1 2007/03/17 19:56:38 mvl |
48 | * Moved signal shape routines from AliEMCAL to separate class AliEMCALRawUtils to streamline raw data reconstruction code. | |
49 | * */ | |
ee299369 | 50 | |
51 | //*-- Author: Marco van Leeuwen (LBL) | |
52 | #include "AliEMCALRawUtils.h" | |
53 | ||
54 | #include "TF1.h" | |
55 | #include "TGraph.h" | |
56 | #include "TSystem.h" | |
57 | ||
58 | #include "AliLog.h" | |
72c58de0 | 59 | #include "AliRun.h" |
ee299369 | 60 | #include "AliRunLoader.h" |
61 | #include "AliCaloAltroMapping.h" | |
62 | #include "AliAltroBuffer.h" | |
63 | #include "AliRawReader.h" | |
64 | #include "AliCaloRawStream.h" | |
65 | #include "AliDAQ.h" | |
66 | ||
feedcab9 | 67 | #include "AliEMCALRecParam.h" |
ee299369 | 68 | #include "AliEMCALLoader.h" |
69 | #include "AliEMCALGeometry.h" | |
70 | #include "AliEMCALDigitizer.h" | |
71 | #include "AliEMCALDigit.h" | |
20b636fc | 72 | #include "AliEMCAL.h" |
ee299369 | 73 | |
74 | ClassImp(AliEMCALRawUtils) | |
75 | ||
76 | // Signal shape parameters | |
82cbdfca | 77 | Double_t AliEMCALRawUtils::fgTimeBinWidth = 100E-9 ; // each sample is 100 ns |
ee299369 | 78 | Double_t AliEMCALRawUtils::fgTimeTrigger = 1.5E-6 ; // 15 time bins ~ 1.5 musec |
79 | ||
80 | // some digitization constants | |
81 | Int_t AliEMCALRawUtils::fgThreshold = 1; | |
82 | Int_t AliEMCALRawUtils::fgDDLPerSuperModule = 2; // 2 ddls per SuperModule | |
fe93d365 | 83 | Int_t AliEMCALRawUtils::fgPedestalValue = 32; // pedestal value for digits2raw |
84 | Double_t AliEMCALRawUtils::fgFEENoise = 3.; // 3 ADC channels of noise (sampled) | |
ee299369 | 85 | |
8cb998bd | 86 | AliEMCALRawUtils::AliEMCALRawUtils() |
b4133f05 | 87 | : fHighLowGainFactor(0.), fOrder(0), fTau(0.), fNoiseThreshold(0), |
88 | fNPedSamples(0), fGeom(0), fOption("") | |
8cb998bd | 89 | { |
b4133f05 | 90 | |
91 | //These are default parameters. | |
92 | //Can be re-set from without with setter functions | |
ee299369 | 93 | fHighLowGainFactor = 16. ; // adjusted for a low gain range of 82 GeV (10 bits) |
b4133f05 | 94 | fOrder = 2; // order of gamma fn |
95 | fTau = 2.35; // in units of timebin, from CERN 2007 testbeam | |
96 | fNoiseThreshold = 3; | |
97 | fNPedSamples = 5; | |
65bdc82f | 98 | |
99 | //Get Mapping RCU files from the AliEMCALRecParam | |
100 | const TObjArray* maps = AliEMCALRecParam::GetMappings(); | |
101 | if(!maps) AliFatal("Cannot retrieve ALTRO mappings!!"); | |
102 | ||
103 | for(Int_t i = 0; i < 2; i++) { | |
104 | fMapping[i] = (AliAltroMapping*)maps->At(i); | |
105 | } | |
106 | ||
72c58de0 | 107 | //To make sure we match with the geometry in a simulation file, |
108 | //let's try to get it first. If not, take the default geometry | |
109 | AliRunLoader *rl = AliRunLoader::GetRunLoader(); | |
110 | if (rl->GetAliRun() && rl->GetAliRun()->GetDetector("EMCAL")) { | |
111 | fGeom = dynamic_cast<AliEMCAL*>(rl->GetAliRun()->GetDetector("EMCAL"))->GetGeometry(); | |
112 | } else { | |
113 | AliInfo(Form("Using default geometry in raw reco")); | |
937d0661 | 114 | fGeom = AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaultGeometryName()); |
65bdc82f | 115 | } |
116 | ||
72c58de0 | 117 | if(!fGeom) AliFatal(Form("Could not get geometry!")); |
118 | ||
65bdc82f | 119 | } |
120 | ||
121 | //____________________________________________________________________________ | |
122 | AliEMCALRawUtils::AliEMCALRawUtils(const AliEMCALRawUtils& rawU) | |
123 | : TObject(), | |
124 | fHighLowGainFactor(rawU.fHighLowGainFactor), | |
b4133f05 | 125 | fOrder(rawU.fOrder), |
126 | fTau(rawU.fTau), | |
127 | fNoiseThreshold(rawU.fNoiseThreshold), | |
128 | fNPedSamples(rawU.fNPedSamples), | |
65bdc82f | 129 | fGeom(rawU.fGeom), |
130 | fOption(rawU.fOption) | |
131 | { | |
132 | //copy ctor | |
133 | fMapping[0] = rawU.fMapping[0]; | |
134 | fMapping[1] = rawU.fMapping[1]; | |
135 | } | |
136 | ||
137 | //____________________________________________________________________________ | |
138 | AliEMCALRawUtils& AliEMCALRawUtils::operator =(const AliEMCALRawUtils &rawU) | |
139 | { | |
140 | //assignment operator | |
141 | ||
142 | if(this != &rawU) { | |
143 | fHighLowGainFactor = rawU.fHighLowGainFactor; | |
b4133f05 | 144 | fOrder = rawU.fOrder; |
145 | fTau = rawU.fTau; | |
146 | fNoiseThreshold = rawU.fNoiseThreshold; | |
147 | fNPedSamples = rawU.fNPedSamples; | |
65bdc82f | 148 | fGeom = rawU.fGeom; |
149 | fOption = rawU.fOption; | |
150 | fMapping[0] = rawU.fMapping[0]; | |
151 | fMapping[1] = rawU.fMapping[1]; | |
152 | } | |
153 | ||
154 | return *this; | |
155 | ||
ee299369 | 156 | } |
65bdc82f | 157 | |
ee299369 | 158 | //____________________________________________________________________________ |
159 | AliEMCALRawUtils::~AliEMCALRawUtils() { | |
65bdc82f | 160 | |
ee299369 | 161 | } |
65bdc82f | 162 | |
ee299369 | 163 | //____________________________________________________________________________ |
65bdc82f | 164 | void AliEMCALRawUtils::Digits2Raw() |
ee299369 | 165 | { |
166 | // convert digits of the current event to raw data | |
167 | ||
168 | AliRunLoader *rl = AliRunLoader::GetRunLoader(); | |
169 | AliEMCALLoader *loader = dynamic_cast<AliEMCALLoader*>(rl->GetDetectorLoader("EMCAL")); | |
170 | ||
171 | // get the digits | |
172 | loader->LoadDigits("EMCAL"); | |
173 | loader->GetEvent(); | |
174 | TClonesArray* digits = loader->Digits() ; | |
175 | ||
176 | if (!digits) { | |
177 | Warning("Digits2Raw", "no digits found !"); | |
178 | return; | |
179 | } | |
65bdc82f | 180 | |
ee299369 | 181 | static const Int_t nDDL = 12*2; // 12 SM hardcoded for now. Buffers allocated dynamically, when needed, so just need an upper limit here |
182 | AliAltroBuffer* buffers[nDDL]; | |
183 | for (Int_t i=0; i < nDDL; i++) | |
184 | buffers[i] = 0; | |
185 | ||
186 | Int_t adcValuesLow[fgkTimeBins]; | |
187 | Int_t adcValuesHigh[fgkTimeBins]; | |
188 | ||
ee299369 | 189 | // loop over digits (assume ordered digits) |
190 | for (Int_t iDigit = 0; iDigit < digits->GetEntries(); iDigit++) { | |
191 | AliEMCALDigit* digit = dynamic_cast<AliEMCALDigit *>(digits->At(iDigit)) ; | |
192 | if (digit->GetAmp() < fgThreshold) | |
193 | continue; | |
194 | ||
195 | //get cell indices | |
196 | Int_t nSM = 0; | |
197 | Int_t nIphi = 0; | |
198 | Int_t nIeta = 0; | |
199 | Int_t iphi = 0; | |
200 | Int_t ieta = 0; | |
201 | Int_t nModule = 0; | |
65bdc82f | 202 | fGeom->GetCellIndex(digit->GetId(), nSM, nModule, nIphi, nIeta); |
203 | fGeom->GetCellPhiEtaIndexInSModule(nSM, nModule, nIphi, nIeta,iphi, ieta) ; | |
ee299369 | 204 | |
205 | //Check which is the RCU of the cell. | |
206 | Int_t iRCU = -111; | |
207 | //RCU0 | |
208 | if (0<=iphi&&iphi<8) iRCU=0; // first cable row | |
209 | else if (8<=iphi&&iphi<16 && 0<=ieta&&ieta<24) iRCU=0; // first half; | |
210 | //second cable row | |
211 | //RCU1 | |
212 | else if(8<=iphi&&iphi<16 && 24<=ieta&&ieta<48) iRCU=1; // second half; | |
213 | //second cable row | |
214 | else if(16<=iphi&&iphi<24) iRCU=1; // third cable row | |
e36e3bcf | 215 | if (iRCU<0) |
216 | Fatal("Digits2Raw()","Non-existent RCU number: %d", iRCU); | |
ee299369 | 217 | |
218 | //Which DDL? | |
219 | Int_t iDDL = fgDDLPerSuperModule* nSM + iRCU; | |
220 | if (iDDL >= nDDL) | |
221 | Fatal("Digits2Raw()","Non-existent DDL board number: %d", iDDL); | |
222 | ||
223 | if (buffers[iDDL] == 0) { | |
224 | // open new file and write dummy header | |
225 | TString fileName = AliDAQ::DdlFileName("EMCAL",iDDL); | |
65bdc82f | 226 | buffers[iDDL] = new AliAltroBuffer(fileName.Data(),fMapping[iRCU]); |
ee299369 | 227 | buffers[iDDL]->WriteDataHeader(kTRUE, kFALSE); //Dummy; |
228 | } | |
229 | ||
230 | // out of time range signal (?) | |
231 | if (digit->GetTimeR() > GetRawFormatTimeMax() ) { | |
232 | AliInfo("Signal is out of time range.\n"); | |
233 | buffers[iDDL]->FillBuffer((Int_t)digit->GetAmp()); | |
234 | buffers[iDDL]->FillBuffer(GetRawFormatTimeBins() ); // time bin | |
235 | buffers[iDDL]->FillBuffer(3); // bunch length | |
236 | buffers[iDDL]->WriteTrailer(3, ieta, iphi, nSM); // trailer | |
237 | // calculate the time response function | |
238 | } else { | |
239 | Bool_t lowgain = RawSampledResponse(digit->GetTimeR(), digit->GetAmp(), adcValuesHigh, adcValuesLow) ; | |
240 | if (lowgain) | |
241 | buffers[iDDL]->WriteChannel(ieta, iphi, 0, GetRawFormatTimeBins(), adcValuesLow, fgThreshold); | |
242 | else | |
243 | buffers[iDDL]->WriteChannel(ieta,iphi, 1, GetRawFormatTimeBins(), adcValuesHigh, fgThreshold); | |
244 | } | |
245 | } | |
246 | ||
247 | // write headers and close files | |
248 | for (Int_t i=0; i < nDDL; i++) { | |
249 | if (buffers[i]) { | |
250 | buffers[i]->Flush(); | |
251 | buffers[i]->WriteDataHeader(kFALSE, kFALSE); | |
252 | delete buffers[i]; | |
253 | } | |
254 | } | |
65bdc82f | 255 | |
ee299369 | 256 | loader->UnloadDigits(); |
257 | } | |
258 | ||
259 | //____________________________________________________________________________ | |
65bdc82f | 260 | void AliEMCALRawUtils::Raw2Digits(AliRawReader* reader,TClonesArray *digitsArr) |
ee299369 | 261 | { |
65bdc82f | 262 | // convert raw data of the current event to digits |
ee299369 | 263 | |
c47157cd | 264 | digitsArr->Clear(); |
ee299369 | 265 | |
c47157cd | 266 | if (!digitsArr) { |
ee299369 | 267 | Error("Raw2Digits", "no digits found !"); |
268 | return; | |
269 | } | |
270 | if (!reader) { | |
271 | Error("Raw2Digits", "no raw reader found !"); | |
272 | return; | |
273 | } | |
274 | ||
65bdc82f | 275 | AliCaloRawStream in(reader,"EMCAL",fMapping); |
ee299369 | 276 | // Select EMCAL DDL's; |
277 | reader->Select("EMCAL"); | |
feedcab9 | 278 | |
279 | TString option = GetOption(); | |
280 | if (option.Contains("OldRCUFormat")) | |
281 | in.SetOldRCUFormat(kTRUE); // Needed for testbeam data | |
282 | else | |
283 | in.SetOldRCUFormat(kFALSE); | |
284 | ||
8cb998bd | 285 | //Updated fitting routine from 2007 beam test takes into account |
286 | //possibility of two peaks in data and selects first one for fitting | |
287 | //Also sets some of the starting parameters based on the shape of the | |
288 | //given raw signal being fit | |
289 | ||
290 | TF1 * signalF = new TF1("signal", RawResponseFunction, 0, GetRawFormatTimeBins(), 5); | |
b4133f05 | 291 | signalF->SetParameters(10.,0.,fTau,fOrder,5.); //set all defaults once, just to be safe |
8cb998bd | 292 | signalF->SetParNames("amp","t0","tau","N","ped"); |
b4133f05 | 293 | signalF->SetParameter(2,fTau); // tau in units of time bin |
8cb998bd | 294 | signalF->SetParLimits(2,2,-1); |
b4133f05 | 295 | signalF->SetParameter(3,fOrder); // order |
8cb998bd | 296 | signalF->SetParLimits(3,2,-1); |
48a56166 | 297 | |
ee299369 | 298 | Int_t id = -1; |
82cbdfca | 299 | Float_t time = 0. ; |
300 | Float_t amp = 0. ; | |
ee299369 | 301 | |
8cb998bd | 302 | //Graph to hold data we will fit (should be converted to an array |
303 | //later to speed up processing | |
304 | TGraph * gSig = new TGraph(GetRawFormatTimeBins()); | |
ee299369 | 305 | |
82cbdfca | 306 | Int_t readOk = 1; |
ee299369 | 307 | Int_t lowGain = 0; |
308 | ||
82cbdfca | 309 | while (readOk && in.GetModule() < 0) |
310 | readOk = in.Next(); // Go to first digit | |
e9dbb64a | 311 | |
8cb998bd | 312 | Int_t col = 0; |
313 | Int_t row = 0; | |
314 | ||
82cbdfca | 315 | while (readOk) { |
65bdc82f | 316 | id = fGeom->GetAbsCellIdFromCellIndexes(in.GetModule(), in.GetRow(), in.GetColumn()) ; |
ee299369 | 317 | lowGain = in.IsLowGain(); |
82cbdfca | 318 | Int_t maxTime = in.GetTime(); // timebins come in reverse order |
e9dbb64a | 319 | if (maxTime < 0 || maxTime >= GetRawFormatTimeBins()) { |
320 | AliWarning(Form("Invalid time bin %d",maxTime)); | |
321 | maxTime = GetRawFormatTimeBins(); | |
322 | } | |
82cbdfca | 323 | gSig->Set(maxTime+1); |
324 | // There is some kind of zero-suppression in the raw data, | |
325 | // so set up the TGraph in advance | |
326 | for (Int_t i=0; i < maxTime; i++) { | |
8cb998bd | 327 | gSig->SetPoint(i, i , 0); |
82cbdfca | 328 | } |
ee299369 | 329 | |
82cbdfca | 330 | Int_t iTime = 0; |
ee299369 | 331 | do { |
82cbdfca | 332 | if (in.GetTime() >= gSig->GetN()) { |
333 | AliWarning("Too many time bins"); | |
334 | gSig->Set(in.GetTime()); | |
ee299369 | 335 | } |
8cb998bd | 336 | col = in.GetColumn(); |
337 | row = in.GetRow(); | |
338 | ||
339 | gSig->SetPoint(in.GetTime(), in.GetTime(), in.GetSignal()) ; | |
fb070798 | 340 | |
82cbdfca | 341 | if (in.GetTime() > maxTime) |
342 | maxTime = in.GetTime(); | |
ee299369 | 343 | iTime++; |
82cbdfca | 344 | } while ((readOk = in.Next()) && !in.IsNewHWAddress()); |
ee299369 | 345 | |
346 | FitRaw(gSig, signalF, amp, time) ; | |
ee299369 | 347 | |
3ced962c | 348 | if (amp > 0 && amp < 10000) { //check both high and low end of |
349 | //result, 10000 is somewhat arbitrary | |
82cbdfca | 350 | AliDebug(2,Form("id %d lowGain %d amp %g", id, lowGain, amp)); |
8cb998bd | 351 | //cout << "col " << col-40 << " row " << row-8 << " lowGain " << lowGain << " amp " << amp << endl; |
fb070798 | 352 | |
82cbdfca | 353 | AddDigit(digitsArr, id, lowGain, (Int_t)amp, time); |
ee299369 | 354 | } |
ee299369 | 355 | |
356 | // Reset graph | |
82cbdfca | 357 | for (Int_t index = 0; index < gSig->GetN(); index++) { |
8cb998bd | 358 | gSig->SetPoint(index, index, 0) ; |
ee299369 | 359 | } |
48a56166 | 360 | // Reset starting parameters for fit function |
b4133f05 | 361 | signalF->SetParameters(10.,0.,fTau,fOrder,5.); //reset all defaults just to be safe |
48a56166 | 362 | |
82cbdfca | 363 | }; // EMCAL entries loop |
ee299369 | 364 | |
365 | delete signalF ; | |
366 | delete gSig; | |
367 | ||
368 | return ; | |
369 | } | |
370 | ||
371 | //____________________________________________________________________________ | |
82cbdfca | 372 | void AliEMCALRawUtils::AddDigit(TClonesArray *digitsArr, Int_t id, Int_t lowGain, Int_t amp, Float_t time) { |
373 | // | |
374 | // Add a new digit. | |
375 | // This routine checks whether a digit exists already for this tower | |
376 | // and then decides whether to use the high or low gain info | |
377 | // | |
378 | // Called by Raw2Digits | |
379 | ||
380 | AliEMCALDigit *digit = 0, *tmpdigit = 0; | |
381 | ||
382 | TIter nextdigit(digitsArr); | |
383 | while (digit == 0 && (tmpdigit = (AliEMCALDigit*) nextdigit())) { | |
384 | if (tmpdigit->GetId() == id) | |
385 | digit = tmpdigit; | |
386 | } | |
387 | ||
388 | if (!digit) { // no digit existed for this tower; create one | |
389 | if (lowGain) | |
390 | amp = Int_t(fHighLowGainFactor * amp); | |
391 | Int_t idigit = digitsArr->GetEntries(); | |
392 | new((*digitsArr)[idigit]) AliEMCALDigit( -1, -1, id, amp, time, idigit) ; | |
393 | } | |
394 | else { // a digit already exists, check range | |
b4133f05 | 395 | // (use high gain if signal < cut value, otherwise low gain) |
82cbdfca | 396 | if (lowGain) { // new digit is low gain |
b4133f05 | 397 | if (digit->GetAmp() > fgkOverflowCut) { // use if stored digit is out of range |
82cbdfca | 398 | digit->SetAmp(Int_t(fHighLowGainFactor * amp)); |
399 | digit->SetTime(time); | |
400 | } | |
401 | } | |
b4133f05 | 402 | else if (amp < fgkOverflowCut) { // new digit is high gain; use if not out of range |
82cbdfca | 403 | digit->SetAmp(amp); |
404 | digit->SetTime(time); | |
405 | } | |
406 | } | |
407 | } | |
408 | ||
409 | //____________________________________________________________________________ | |
410 | void AliEMCALRawUtils::FitRaw(TGraph * gSig, TF1* signalF, Float_t & amp, Float_t & time) | |
ee299369 | 411 | { |
412 | // Fits the raw signal time distribution; from AliEMCALGetter | |
413 | ||
ee299369 | 414 | amp = time = 0. ; |
82cbdfca | 415 | Double_t ped = 0; |
416 | Int_t nPed = 0; | |
ee299369 | 417 | |
b4133f05 | 418 | for (Int_t index = 0; index < fNPedSamples; index++) { |
e9dbb64a | 419 | Double_t ttime, signal; |
82cbdfca | 420 | gSig->GetPoint(index, ttime, signal) ; |
421 | if (signal > 0) { | |
422 | ped += signal; | |
423 | nPed++; | |
ee299369 | 424 | } |
425 | } | |
e9dbb64a | 426 | |
82cbdfca | 427 | if (nPed > 0) |
428 | ped /= nPed; | |
e9dbb64a | 429 | else { |
8cb998bd | 430 | AliWarning("Could not determine pedestal"); |
82cbdfca | 431 | ped = 10; // put some small value as first guess |
e9dbb64a | 432 | } |
82cbdfca | 433 | |
e9dbb64a | 434 | Int_t max_found = 0; |
435 | Int_t i_max = 0; | |
436 | Float_t max = -1; | |
8cb998bd | 437 | Float_t max_fit = gSig->GetN(); |
e9dbb64a | 438 | Float_t min_after_sig = 9999; |
8cb998bd | 439 | Int_t tmin_after_sig = gSig->GetN(); |
e9dbb64a | 440 | Int_t n_ped_after_sig = 0; |
fb070798 | 441 | Int_t plateau_width = 0; |
442 | Int_t plateau_start = 9999; | |
e9dbb64a | 443 | |
b4133f05 | 444 | for (Int_t i=fNPedSamples; i < gSig->GetN(); i++) { |
e9dbb64a | 445 | Double_t ttime, signal; |
446 | gSig->GetPoint(i, ttime, signal) ; | |
447 | if (!max_found && signal > max) { | |
448 | i_max = i; | |
e9dbb64a | 449 | max = signal; |
450 | } | |
b4133f05 | 451 | else if ( max > ped + fNoiseThreshold ) { |
e9dbb64a | 452 | max_found = 1; |
453 | min_after_sig = signal; | |
8cb998bd | 454 | tmin_after_sig = i; |
e9dbb64a | 455 | } |
456 | if (max_found) { | |
457 | if ( signal < min_after_sig) { | |
458 | min_after_sig = signal; | |
8cb998bd | 459 | tmin_after_sig = i; |
e9dbb64a | 460 | } |
461 | if (i > tmin_after_sig + 5) { // Two close peaks; end fit at minimum | |
462 | max_fit = tmin_after_sig; | |
463 | break; | |
464 | } | |
b4133f05 | 465 | if ( signal < ped + fNoiseThreshold) |
e9dbb64a | 466 | n_ped_after_sig++; |
467 | if (n_ped_after_sig >= 5) { // include 5 pedestal bins after peak | |
8cb998bd | 468 | max_fit = i; |
e9dbb64a | 469 | break; |
470 | } | |
5a056daa | 471 | } |
fb070798 | 472 | //Add check on plateau |
473 | if (signal >= fgkRawSignalOverflow - fNoiseThreshold) { | |
474 | if(plateau_width == 0) plateau_start = i; | |
475 | plateau_width++; | |
476 | } | |
477 | } | |
478 | ||
479 | if(plateau_width > 0) { | |
480 | for(int j = 0; j < plateau_width-2; j++) { | |
481 | //Note, have to remove the same point N times because after each | |
482 | //remove, the positions of all subsequent points have shifted down | |
483 | //We leave the first and last as anchor points | |
484 | gSig->RemovePoint(plateau_start+1); | |
485 | } | |
82cbdfca | 486 | } |
5a056daa | 487 | |
b4133f05 | 488 | if ( max - ped > fNoiseThreshold ) { // else its noise |
e9dbb64a | 489 | AliDebug(2,Form("Fitting max %d ped %d", max, ped)); |
8cb998bd | 490 | signalF->SetRange(0,max_fit); |
491 | ||
492 | if(max-ped > 50) | |
493 | signalF->SetParLimits(2,1,3); | |
494 | ||
495 | signalF->SetParameter(4, ped) ; | |
496 | signalF->SetParameter(1, i_max); | |
497 | signalF->SetParameter(0, max); | |
498 | ||
499 | gSig->Fit(signalF, "QROW"); // Note option 'W': equal errors on all points | |
500 | amp = signalF->GetParameter(0); | |
501 | time = signalF->GetParameter(1)*GetRawFormatTimeBinWidth() - fgTimeTrigger; | |
ee299369 | 502 | } |
503 | return; | |
504 | } | |
505 | //__________________________________________________________________ | |
506 | Double_t AliEMCALRawUtils::RawResponseFunction(Double_t *x, Double_t *par) | |
507 | { | |
8cb998bd | 508 | // Matches version used in 2007 beam test |
509 | // | |
ee299369 | 510 | // Shape of the electronics raw reponse: |
511 | // It is a semi-gaussian, 2nd order Gamma function of the general form | |
512 | // | |
513 | // t' = (t - t0 + tau) / tau | |
514 | // F = A * t**N * exp( N * ( 1 - t) ) for t >= 0 | |
515 | // F = 0 for t < 0 | |
516 | // | |
517 | // parameters: | |
8cb998bd | 518 | // A: par[0] // Amplitude = peak value |
519 | // t0: par[1] | |
520 | // tau: par[2] | |
521 | // N: par[3] | |
522 | // ped: par[4] | |
ee299369 | 523 | // |
524 | Double_t signal ; | |
8cb998bd | 525 | Double_t tau =par[2]; |
526 | Double_t N =par[3]; | |
527 | Double_t ped = par[4]; | |
528 | Double_t xx = ( x[0] - par[1] + tau ) / tau ; | |
ee299369 | 529 | |
5a056daa | 530 | if (xx <= 0) |
8cb998bd | 531 | signal = ped ; |
ee299369 | 532 | else { |
8cb998bd | 533 | signal = ped + par[0] * TMath::Power(xx , N) * TMath::Exp(N * (1 - xx )) ; |
ee299369 | 534 | } |
535 | return signal ; | |
536 | } | |
537 | ||
538 | //__________________________________________________________________ | |
539 | Bool_t AliEMCALRawUtils::RawSampledResponse( | |
540 | const Double_t dtime, const Double_t damp, Int_t * adcH, Int_t * adcL) const | |
541 | { | |
542 | // for a start time dtime and an amplitude damp given by digit, | |
543 | // calculates the raw sampled response AliEMCAL::RawResponseFunction | |
544 | ||
ee299369 | 545 | Bool_t lowGain = kFALSE ; |
546 | ||
48a56166 | 547 | // A: par[0] // Amplitude = peak value |
548 | // t0: par[1] | |
549 | // tau: par[2] | |
550 | // N: par[3] | |
551 | // ped: par[4] | |
552 | ||
553 | TF1 signalF("signal", RawResponseFunction, 0, GetRawFormatTimeMax(), 5); | |
554 | signalF.SetParameter(0, damp) ; | |
555 | signalF.SetParameter(1, dtime + fgTimeTrigger) ; | |
b4133f05 | 556 | signalF.SetParameter(2, fTau) ; |
557 | signalF.SetParameter(3, fOrder); | |
fe93d365 | 558 | signalF.SetParameter(4, fgPedestalValue); |
ee299369 | 559 | |
560 | for (Int_t iTime = 0; iTime < GetRawFormatTimeBins(); iTime++) { | |
82cbdfca | 561 | Double_t time = iTime * GetRawFormatTimeBinWidth() ; |
ee299369 | 562 | Double_t signal = signalF.Eval(time) ; |
fe93d365 | 563 | |
564 | //According to Terry Awes, 13-Apr-2008 | |
565 | //add gaussian noise in quadrature to each sample | |
566 | //Double_t noise = gRandom->Gaus(0.,fgFEENoise); | |
567 | //signal = sqrt(signal*signal + noise*noise); | |
568 | ||
ee299369 | 569 | adcH[iTime] = static_cast<Int_t>(signal + 0.5) ; |
b4133f05 | 570 | if ( adcH[iTime] > fgkRawSignalOverflow ){ // larger than 10 bits |
571 | adcH[iTime] = fgkRawSignalOverflow ; | |
ee299369 | 572 | lowGain = kTRUE ; |
573 | } | |
574 | ||
575 | signal /= fHighLowGainFactor; | |
576 | ||
577 | adcL[iTime] = static_cast<Int_t>(signal + 0.5) ; | |
b4133f05 | 578 | if ( adcL[iTime] > fgkRawSignalOverflow) // larger than 10 bits |
579 | adcL[iTime] = fgkRawSignalOverflow ; | |
ee299369 | 580 | } |
581 | return lowGain ; | |
582 | } |