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