]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EMCAL/AliEMCALRawUtils.cxx
New version including PWG2 AddTaskCentral, modified KINK resonances like sign macros...
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALRawUtils.cxx
CommitLineData
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
ee299369 31#include "TF1.h"
32#include "TGraph.h"
e2c2134b 33#include <TRandom.h>
e5bbbc4e 34class TSystem;
21cad85c 35
e5bbbc4e 36class AliLog;
72c58de0 37#include "AliRun.h"
ee299369 38#include "AliRunLoader.h"
e5bbbc4e 39class 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 48class AliEMCALDigitizer;
ee299369 49#include "AliEMCALDigit.h"
20b636fc 50#include "AliEMCAL.h"
21cad85c 51
ee299369 52ClassImp(AliEMCALRawUtils)
21cad85c 53
ee299369 54// Signal shape parameters
e2c2134b 55Int_t AliEMCALRawUtils::fgTimeBins = 256; // number of time bins for EMCAL
e5bbbc4e 56Double_t AliEMCALRawUtils::fgTimeBinWidth = 100E-9 ; // each sample is 100 ns
09974781 57Double_t AliEMCALRawUtils::fgTimeTrigger = 1.5E-6 ; // 15 time bins ~ 1.5 musec
ee299369 58
59// some digitization constants
60Int_t AliEMCALRawUtils::fgThreshold = 1;
61Int_t AliEMCALRawUtils::fgDDLPerSuperModule = 2; // 2 ddls per SuperModule
e5bbbc4e 62Int_t AliEMCALRawUtils::fgPedestalValue = 32; // pedestal value for digits2raw
63Double_t AliEMCALRawUtils::fgFEENoise = 3.; // 3 ADC channels of noise (sampled)
ee299369 64
8cb998bd 65AliEMCALRawUtils::AliEMCALRawUtils()
b4133f05 66 : fHighLowGainFactor(0.), fOrder(0), fTau(0.), fNoiseThreshold(0),
67 fNPedSamples(0), fGeom(0), fOption("")
8cb998bd 68{
b4133f05 69
70 //These are default parameters.
71 //Can be re-set from without with setter functions
ee299369 72 fHighLowGainFactor = 16. ; // adjusted for a low gain range of 82 GeV (10 bits)
b4133f05 73 fOrder = 2; // order of gamma fn
74 fTau = 2.35; // in units of timebin, from CERN 2007 testbeam
98fd4e6f 75 fNoiseThreshold = 3;
b4133f05 76 fNPedSamples = 5;
65bdc82f 77
78 //Get Mapping RCU files from the AliEMCALRecParam
79 const TObjArray* maps = AliEMCALRecParam::GetMappings();
80 if(!maps) AliFatal("Cannot retrieve ALTRO mappings!!");
81
21cad85c 82 for(Int_t i = 0; i < 4; i++) {
65bdc82f 83 fMapping[i] = (AliAltroMapping*)maps->At(i);
84 }
85
72c58de0 86 //To make sure we match with the geometry in a simulation file,
87 //let's try to get it first. If not, take the default geometry
33c3c91a 88 AliRunLoader *rl = AliRunLoader::Instance();
c61fe3b4 89 if(!rl) AliError("Cannot find RunLoader!");
72c58de0 90 if (rl->GetAliRun() && rl->GetAliRun()->GetDetector("EMCAL")) {
91 fGeom = dynamic_cast<AliEMCAL*>(rl->GetAliRun()->GetDetector("EMCAL"))->GetGeometry();
92 } else {
93 AliInfo(Form("Using default geometry in raw reco"));
937d0661 94 fGeom = AliEMCALGeometry::GetInstance(AliEMCALGeometry::GetDefaultGeometryName());
65bdc82f 95 }
96
72c58de0 97 if(!fGeom) AliFatal(Form("Could not get geometry!"));
98
65bdc82f 99}
100
101//____________________________________________________________________________
5544799a 102AliEMCALRawUtils::AliEMCALRawUtils(AliEMCALGeometry *pGeometry)
103 : fHighLowGainFactor(0.), fOrder(0), fTau(0.), fNoiseThreshold(0),
104 fNPedSamples(0), fGeom(pGeometry), fOption("")
105{
106 //
107 // Initialize with the given geometry - constructor required by HLT
108 // HLT does not use/support AliRunLoader(s) instances
109 // This is a minimum intervention solution
110 // Comment by MPloskon@lbl.gov
111 //
112
113 //These are default parameters.
114 //Can be re-set from without with setter functions
115 fHighLowGainFactor = 16. ; // adjusted for a low gain range of 82 GeV (10 bits)
116 fOrder = 2; // order of gamma fn
117 fTau = 2.35; // in units of timebin, from CERN 2007 testbeam
118 fNoiseThreshold = 3;
119 fNPedSamples = 5;
120
121 //Get Mapping RCU files from the AliEMCALRecParam
122 const TObjArray* maps = AliEMCALRecParam::GetMappings();
123 if(!maps) AliFatal("Cannot retrieve ALTRO mappings!!");
124
21cad85c 125 for(Int_t i = 0; i < 4; i++) {
5544799a 126 fMapping[i] = (AliAltroMapping*)maps->At(i);
127 }
128
129 if(!fGeom) AliFatal(Form("Could not get geometry!"));
130
131}
132
133//____________________________________________________________________________
65bdc82f 134AliEMCALRawUtils::AliEMCALRawUtils(const AliEMCALRawUtils& rawU)
135 : TObject(),
136 fHighLowGainFactor(rawU.fHighLowGainFactor),
b4133f05 137 fOrder(rawU.fOrder),
138 fTau(rawU.fTau),
139 fNoiseThreshold(rawU.fNoiseThreshold),
140 fNPedSamples(rawU.fNPedSamples),
65bdc82f 141 fGeom(rawU.fGeom),
142 fOption(rawU.fOption)
143{
144 //copy ctor
145 fMapping[0] = rawU.fMapping[0];
146 fMapping[1] = rawU.fMapping[1];
21cad85c 147 fMapping[2] = rawU.fMapping[2];
148 fMapping[3] = rawU.fMapping[3];
65bdc82f 149}
150
151//____________________________________________________________________________
152AliEMCALRawUtils& AliEMCALRawUtils::operator =(const AliEMCALRawUtils &rawU)
153{
154 //assignment operator
155
156 if(this != &rawU) {
157 fHighLowGainFactor = rawU.fHighLowGainFactor;
b4133f05 158 fOrder = rawU.fOrder;
159 fTau = rawU.fTau;
160 fNoiseThreshold = rawU.fNoiseThreshold;
161 fNPedSamples = rawU.fNPedSamples;
65bdc82f 162 fGeom = rawU.fGeom;
163 fOption = rawU.fOption;
164 fMapping[0] = rawU.fMapping[0];
165 fMapping[1] = rawU.fMapping[1];
21cad85c 166 fMapping[2] = rawU.fMapping[2];
167 fMapping[3] = rawU.fMapping[3];
65bdc82f 168 }
169
170 return *this;
171
ee299369 172}
65bdc82f 173
ee299369 174//____________________________________________________________________________
175AliEMCALRawUtils::~AliEMCALRawUtils() {
e5bbbc4e 176 //dtor
65bdc82f 177
ee299369 178}
65bdc82f 179
ee299369 180//____________________________________________________________________________
65bdc82f 181void AliEMCALRawUtils::Digits2Raw()
ee299369 182{
183 // convert digits of the current event to raw data
184
33c3c91a 185 AliRunLoader *rl = AliRunLoader::Instance();
ee299369 186 AliEMCALLoader *loader = dynamic_cast<AliEMCALLoader*>(rl->GetDetectorLoader("EMCAL"));
187
188 // get the digits
189 loader->LoadDigits("EMCAL");
190 loader->GetEvent();
191 TClonesArray* digits = loader->Digits() ;
192
193 if (!digits) {
194 Warning("Digits2Raw", "no digits found !");
195 return;
196 }
65bdc82f 197
ee299369 198 static const Int_t nDDL = 12*2; // 12 SM hardcoded for now. Buffers allocated dynamically, when needed, so just need an upper limit here
199 AliAltroBuffer* buffers[nDDL];
200 for (Int_t i=0; i < nDDL; i++)
201 buffers[i] = 0;
202
e2c2134b 203 TArrayI adcValuesLow(fgTimeBins);
204 TArrayI adcValuesHigh(fgTimeBins);
ee299369 205
ee299369 206 // loop over digits (assume ordered digits)
207 for (Int_t iDigit = 0; iDigit < digits->GetEntries(); iDigit++) {
208 AliEMCALDigit* digit = dynamic_cast<AliEMCALDigit *>(digits->At(iDigit)) ;
209 if (digit->GetAmp() < fgThreshold)
210 continue;
211
212 //get cell indices
213 Int_t nSM = 0;
214 Int_t nIphi = 0;
215 Int_t nIeta = 0;
216 Int_t iphi = 0;
217 Int_t ieta = 0;
218 Int_t nModule = 0;
65bdc82f 219 fGeom->GetCellIndex(digit->GetId(), nSM, nModule, nIphi, nIeta);
220 fGeom->GetCellPhiEtaIndexInSModule(nSM, nModule, nIphi, nIeta,iphi, ieta) ;
ee299369 221
21cad85c 222 //Check which is the RCU, 0 or 1, of the cell.
ee299369 223 Int_t iRCU = -111;
224 //RCU0
225 if (0<=iphi&&iphi<8) iRCU=0; // first cable row
226 else if (8<=iphi&&iphi<16 && 0<=ieta&&ieta<24) iRCU=0; // first half;
227 //second cable row
228 //RCU1
229 else if(8<=iphi&&iphi<16 && 24<=ieta&&ieta<48) iRCU=1; // second half;
230 //second cable row
231 else if(16<=iphi&&iphi<24) iRCU=1; // third cable row
21cad85c 232
233 if (nSM%2==1) iRCU = 1 - iRCU; // swap for odd=C side, to allow us to cable both sides the same
234
e36e3bcf 235 if (iRCU<0)
236 Fatal("Digits2Raw()","Non-existent RCU number: %d", iRCU);
ee299369 237
238 //Which DDL?
239 Int_t iDDL = fgDDLPerSuperModule* nSM + iRCU;
240 if (iDDL >= nDDL)
241 Fatal("Digits2Raw()","Non-existent DDL board number: %d", iDDL);
242
243 if (buffers[iDDL] == 0) {
244 // open new file and write dummy header
245 TString fileName = AliDAQ::DdlFileName("EMCAL",iDDL);
21cad85c 246 //Select mapping file RCU0A, RCU0C, RCU1A, RCU1C
247 Int_t iRCUside=iRCU+(nSM%2)*2;
248 //iRCU=0 and even (0) SM -> RCU0A.data 0
249 //iRCU=1 and even (0) SM -> RCU1A.data 1
250 //iRCU=0 and odd (1) SM -> RCU0C.data 2
251 //iRCU=1 and odd (1) SM -> RCU1C.data 3
252 //cout<<" nSM "<<nSM<<"; iRCU "<<iRCU<<"; iRCUside "<<iRCUside<<endl;
253 buffers[iDDL] = new AliAltroBuffer(fileName.Data(),fMapping[iRCUside]);
ee299369 254 buffers[iDDL]->WriteDataHeader(kTRUE, kFALSE); //Dummy;
255 }
256
257 // out of time range signal (?)
258 if (digit->GetTimeR() > GetRawFormatTimeMax() ) {
259 AliInfo("Signal is out of time range.\n");
260 buffers[iDDL]->FillBuffer((Int_t)digit->GetAmp());
261 buffers[iDDL]->FillBuffer(GetRawFormatTimeBins() ); // time bin
262 buffers[iDDL]->FillBuffer(3); // bunch length
263 buffers[iDDL]->WriteTrailer(3, ieta, iphi, nSM); // trailer
264 // calculate the time response function
265 } else {
e2c2134b 266 Bool_t lowgain = RawSampledResponse(digit->GetTimeR(), digit->GetAmp(), adcValuesHigh.GetArray(), adcValuesLow.GetArray()) ;
ee299369 267 if (lowgain)
e2c2134b 268 buffers[iDDL]->WriteChannel(ieta, iphi, 0, GetRawFormatTimeBins(), adcValuesLow.GetArray(), fgThreshold);
ee299369 269 else
e2c2134b 270 buffers[iDDL]->WriteChannel(ieta,iphi, 1, GetRawFormatTimeBins(), adcValuesHigh.GetArray(), fgThreshold);
ee299369 271 }
272 }
273
274 // write headers and close files
275 for (Int_t i=0; i < nDDL; i++) {
276 if (buffers[i]) {
277 buffers[i]->Flush();
278 buffers[i]->WriteDataHeader(kFALSE, kFALSE);
279 delete buffers[i];
280 }
281 }
65bdc82f 282
ee299369 283 loader->UnloadDigits();
284}
285
286//____________________________________________________________________________
65bdc82f 287void AliEMCALRawUtils::Raw2Digits(AliRawReader* reader,TClonesArray *digitsArr)
ee299369 288{
65bdc82f 289 // convert raw data of the current event to digits
ee299369 290
c47157cd 291 digitsArr->Clear();
ee299369 292
c47157cd 293 if (!digitsArr) {
ee299369 294 Error("Raw2Digits", "no digits found !");
295 return;
296 }
297 if (!reader) {
298 Error("Raw2Digits", "no raw reader found !");
299 return;
300 }
301
32cd4c24 302 AliCaloRawStreamV3 in(reader,"EMCAL",fMapping);
ee299369 303 // Select EMCAL DDL's;
30aa89b0 304 reader->Select("EMCAL", 0, AliEMCALGeoParams::fgkLastAltroDDL) ; //select EMCAL DDL's
feedcab9 305
8cb998bd 306 //Updated fitting routine from 2007 beam test takes into account
307 //possibility of two peaks in data and selects first one for fitting
308 //Also sets some of the starting parameters based on the shape of the
309 //given raw signal being fit
310
311 TF1 * signalF = new TF1("signal", RawResponseFunction, 0, GetRawFormatTimeBins(), 5);
b4133f05 312 signalF->SetParameters(10.,0.,fTau,fOrder,5.); //set all defaults once, just to be safe
8cb998bd 313 signalF->SetParNames("amp","t0","tau","N","ped");
b4133f05 314 signalF->SetParameter(2,fTau); // tau in units of time bin
8cb998bd 315 signalF->SetParLimits(2,2,-1);
b4133f05 316 signalF->SetParameter(3,fOrder); // order
8cb998bd 317 signalF->SetParLimits(3,2,-1);
48a56166 318
ee299369 319 Int_t id = -1;
82cbdfca 320 Float_t time = 0. ;
321 Float_t amp = 0. ;
32cd4c24 322 Int_t i = 0;
323 Int_t startBin = 0;
ee299369 324
8cb998bd 325 //Graph to hold data we will fit (should be converted to an array
326 //later to speed up processing
327 TGraph * gSig = new TGraph(GetRawFormatTimeBins());
ee299369 328
ee299369 329 Int_t lowGain = 0;
e5bbbc4e 330 Int_t caloFlag = 0; // low, high gain, or TRU, or LED ref.
ee299369 331
32cd4c24 332 // start loop over input stream
333 while (in.NextDDL()) {
334 while (in.NextChannel()) {
8cb998bd 335
03a3ed3f 336 //Check if the signal is high or low gain and then do the fit,
337 //if it is from TRU do not fit
338 caloFlag = in.GetCaloFlag();
339 if (caloFlag != 0 && caloFlag != 1) continue;
340
32cd4c24 341 // There can be zero-suppression in the raw data,
342 // so set up the TGraph in advance
343 for (i=0; i < GetRawFormatTimeBins(); i++) {
344 gSig->SetPoint(i, i , 0);
345 }
d8ada134 346
32cd4c24 347 Int_t maxTime = 0;
03a3ed3f 348 Int_t min = 0x3ff; // init to 10-bit max
349 Int_t max = 0; // init to 10-bit min
56613d93 350 int nsamples = 0;
32cd4c24 351 while (in.NextBunch()) {
352 const UShort_t *sig = in.GetSignals();
353 startBin = in.GetStartTimeBin();
354
d8ada134 355 if (((UInt_t) maxTime) < in.GetStartTimeBin()) {
32cd4c24 356 maxTime = in.GetStartTimeBin(); // timebins come in reverse order
357 }
358
359 if (maxTime < 0 || maxTime >= GetRawFormatTimeBins()) {
360 AliWarning(Form("Invalid time bin %d",maxTime));
361 maxTime = GetRawFormatTimeBins();
362 }
56613d93 363 nsamples += in.GetBunchLength();
32cd4c24 364 for (i = 0; i < in.GetBunchLength(); i++) {
365 time = startBin--;
03a3ed3f 366 gSig->SetPoint(time, time, (Double_t) sig[i]) ;
367 if (max < sig[i]) max= sig[i];
368 if (min > sig[i]) min = sig[i];
32cd4c24 369 }
370 } // loop over bunches
371
56613d93 372 if (nsamples > 0) { // this check is needed for when we have zero-supp. on, but not sparse readout
373
374 id = fGeom->GetAbsCellIdFromCellIndexes(in.GetModule(), in.GetRow(), in.GetColumn()) ;
56613d93 375 lowGain = in.IsLowGain();
376
32cd4c24 377 gSig->Set(maxTime+1);
03a3ed3f 378 if ( (max - min) > fNoiseThreshold) FitRaw(gSig, signalF, amp, time) ;
ee299369 379
03a3ed3f 380 //if (caloFlag == 0 || caloFlag == 1) { // low gain or high gain
32cd4c24 381 if (amp > 0 && amp < 2000) { //check both high and low end of
e5bbbc4e 382 //result, 2000 is somewhat arbitrary - not nice with magic numbers in the code..
32cd4c24 383 AliDebug(2,Form("id %d lowGain %d amp %g", id, lowGain, amp));
ee299369 384
32cd4c24 385 AddDigit(digitsArr, id, lowGain, (Int_t)amp, time);
386 }
e5bbbc4e 387
03a3ed3f 388 //}
e5bbbc4e 389
32cd4c24 390 // Reset graph
391 for (Int_t index = 0; index < gSig->GetN(); index++) {
392 gSig->SetPoint(index, index, 0) ;
393 }
394 // Reset starting parameters for fit function
395 signalF->SetParameters(10.,0.,fTau,fOrder,5.); //reset all defaults just to be safe
48a56166 396
56613d93 397 } // nsamples>0 check, some data found for this channel; not only trailer/header
32cd4c24 398 } // end while over channel
399 } //end while over DDL's, of input stream
ee299369 400
401 delete signalF ;
402 delete gSig;
403
404 return ;
405}
406
407//____________________________________________________________________________
82cbdfca 408void AliEMCALRawUtils::AddDigit(TClonesArray *digitsArr, Int_t id, Int_t lowGain, Int_t amp, Float_t time) {
409 //
410 // Add a new digit.
411 // This routine checks whether a digit exists already for this tower
412 // and then decides whether to use the high or low gain info
413 //
414 // Called by Raw2Digits
415
416 AliEMCALDigit *digit = 0, *tmpdigit = 0;
417
418 TIter nextdigit(digitsArr);
419 while (digit == 0 && (tmpdigit = (AliEMCALDigit*) nextdigit())) {
420 if (tmpdigit->GetId() == id)
421 digit = tmpdigit;
422 }
423
424 if (!digit) { // no digit existed for this tower; create one
425 if (lowGain)
426 amp = Int_t(fHighLowGainFactor * amp);
427 Int_t idigit = digitsArr->GetEntries();
428 new((*digitsArr)[idigit]) AliEMCALDigit( -1, -1, id, amp, time, idigit) ;
429 }
430 else { // a digit already exists, check range
b4133f05 431 // (use high gain if signal < cut value, otherwise low gain)
82cbdfca 432 if (lowGain) { // new digit is low gain
b4133f05 433 if (digit->GetAmp() > fgkOverflowCut) { // use if stored digit is out of range
82cbdfca 434 digit->SetAmp(Int_t(fHighLowGainFactor * amp));
435 digit->SetTime(time);
436 }
437 }
b4133f05 438 else if (amp < fgkOverflowCut) { // new digit is high gain; use if not out of range
82cbdfca 439 digit->SetAmp(amp);
440 digit->SetTime(time);
441 }
442 }
443}
444
445//____________________________________________________________________________
e5bbbc4e 446void AliEMCALRawUtils::FitRaw(TGraph * gSig, TF1* signalF, Float_t & amp, Float_t & time) const
ee299369 447{
448 // Fits the raw signal time distribution; from AliEMCALGetter
ee299369 449 amp = time = 0. ;
82cbdfca 450 Double_t ped = 0;
451 Int_t nPed = 0;
ee299369 452
b4133f05 453 for (Int_t index = 0; index < fNPedSamples; index++) {
e9dbb64a 454 Double_t ttime, signal;
82cbdfca 455 gSig->GetPoint(index, ttime, signal) ;
456 if (signal > 0) {
457 ped += signal;
458 nPed++;
ee299369 459 }
460 }
e9dbb64a 461
82cbdfca 462 if (nPed > 0)
463 ped /= nPed;
e9dbb64a 464 else {
8cb998bd 465 AliWarning("Could not determine pedestal");
82cbdfca 466 ped = 10; // put some small value as first guess
e9dbb64a 467 }
82cbdfca 468
03a3ed3f 469
e5bbbc4e 470 Int_t maxFound = 0;
471 Int_t iMax = 0;
e9dbb64a 472 Float_t max = -1;
e5bbbc4e 473 Float_t maxFit = gSig->GetN();
474 Float_t minAfterSig = 9999;
475 Int_t tminAfterSig = gSig->GetN();
476 Int_t nPedAfterSig = 0;
477 Int_t plateauWidth = 0;
478 Int_t plateauStart = 9999;
479 Float_t cut = 0.3;
e9dbb64a 480
b4133f05 481 for (Int_t i=fNPedSamples; i < gSig->GetN(); i++) {
e9dbb64a 482 Double_t ttime, signal;
03a3ed3f 483 gSig->GetPoint(i, ttime, signal) ;
e5bbbc4e 484 if (!maxFound && signal > max) {
485 iMax = i;
e9dbb64a 486 max = signal;
487 }
b4133f05 488 else if ( max > ped + fNoiseThreshold ) {
e5bbbc4e 489 maxFound = 1;
490 minAfterSig = signal;
491 tminAfterSig = i;
e9dbb64a 492 }
e5bbbc4e 493 if (maxFound) {
494 if ( signal < minAfterSig) {
495 minAfterSig = signal;
496 tminAfterSig = i;
e9dbb64a 497 }
e5bbbc4e 498 if (i > tminAfterSig + 5) { // Two close peaks; end fit at minimum
499 maxFit = tminAfterSig;
e9dbb64a 500 break;
501 }
e5bbbc4e 502 if ( signal < cut*max){ //stop fit at 30% amplitude(avoid the pulse shape falling edge)
503 maxFit = i;
c61fe3b4 504 break;
505 }
b4133f05 506 if ( signal < ped + fNoiseThreshold)
e5bbbc4e 507 nPedAfterSig++;
508 if (nPedAfterSig >= 5) { // include 5 pedestal bins after peak
509 maxFit = i;
e9dbb64a 510 break;
511 }
5a056daa 512 }
fb070798 513 //Add check on plateau
514 if (signal >= fgkRawSignalOverflow - fNoiseThreshold) {
e5bbbc4e 515 if(plateauWidth == 0) plateauStart = i;
516 plateauWidth++;
fb070798 517 }
518 }
519
e5bbbc4e 520 if(plateauWidth > 0) {
521 for(int j = 0; j < plateauWidth; j++) {
fb070798 522 //Note, have to remove the same point N times because after each
523 //remove, the positions of all subsequent points have shifted down
e5bbbc4e 524 gSig->RemovePoint(plateauStart);
fb070798 525 }
82cbdfca 526 }
5a056daa 527
b4133f05 528 if ( max - ped > fNoiseThreshold ) { // else its noise
e9dbb64a 529 AliDebug(2,Form("Fitting max %d ped %d", max, ped));
e5bbbc4e 530 signalF->SetRange(0,maxFit);
8cb998bd 531
532 if(max-ped > 50)
533 signalF->SetParLimits(2,1,3);
534
535 signalF->SetParameter(4, ped) ;
e5bbbc4e 536 signalF->SetParameter(1, iMax);
8cb998bd 537 signalF->SetParameter(0, max);
538
539 gSig->Fit(signalF, "QROW"); // Note option 'W': equal errors on all points
540 amp = signalF->GetParameter(0);
541 time = signalF->GetParameter(1)*GetRawFormatTimeBinWidth() - fgTimeTrigger;
ee299369 542 }
543 return;
544}
545//__________________________________________________________________
546Double_t AliEMCALRawUtils::RawResponseFunction(Double_t *x, Double_t *par)
547{
8cb998bd 548 // Matches version used in 2007 beam test
549 //
ee299369 550 // Shape of the electronics raw reponse:
551 // It is a semi-gaussian, 2nd order Gamma function of the general form
552 //
553 // t' = (t - t0 + tau) / tau
554 // F = A * t**N * exp( N * ( 1 - t) ) for t >= 0
555 // F = 0 for t < 0
556 //
557 // parameters:
8cb998bd 558 // A: par[0] // Amplitude = peak value
559 // t0: par[1]
560 // tau: par[2]
561 // N: par[3]
562 // ped: par[4]
ee299369 563 //
564 Double_t signal ;
8cb998bd 565 Double_t tau =par[2];
e5bbbc4e 566 Double_t n =par[3];
8cb998bd 567 Double_t ped = par[4];
568 Double_t xx = ( x[0] - par[1] + tau ) / tau ;
ee299369 569
5a056daa 570 if (xx <= 0)
8cb998bd 571 signal = ped ;
ee299369 572 else {
e5bbbc4e 573 signal = ped + par[0] * TMath::Power(xx , n) * TMath::Exp(n * (1 - xx )) ;
ee299369 574 }
575 return signal ;
576}
577
578//__________________________________________________________________
579Bool_t AliEMCALRawUtils::RawSampledResponse(
580const Double_t dtime, const Double_t damp, Int_t * adcH, Int_t * adcL) const
581{
582 // for a start time dtime and an amplitude damp given by digit,
583 // calculates the raw sampled response AliEMCAL::RawResponseFunction
584
ee299369 585 Bool_t lowGain = kFALSE ;
586
48a56166 587 // A: par[0] // Amplitude = peak value
588 // t0: par[1]
589 // tau: par[2]
590 // N: par[3]
591 // ped: par[4]
592
56e13066 593 TF1 signalF("signal", RawResponseFunction, 0, GetRawFormatTimeBins(), 5);
48a56166 594 signalF.SetParameter(0, damp) ;
56e13066 595 signalF.SetParameter(1, (dtime + fgTimeTrigger)/fgTimeBinWidth) ;
b4133f05 596 signalF.SetParameter(2, fTau) ;
597 signalF.SetParameter(3, fOrder);
fe93d365 598 signalF.SetParameter(4, fgPedestalValue);
ee299369 599
600 for (Int_t iTime = 0; iTime < GetRawFormatTimeBins(); iTime++) {
56e13066 601 Double_t signal = signalF.Eval(iTime) ;
fe93d365 602
603 //According to Terry Awes, 13-Apr-2008
604 //add gaussian noise in quadrature to each sample
09974781 605 //Double_t noise = gRandom->Gaus(0.,fgFEENoise);
fe93d365 606 //signal = sqrt(signal*signal + noise*noise);
607
e2c2134b 608 // March 17,09 for fast fit simulations by Alexei Pavlinov.
609 // Get from PHOS analysis. In some sense it is open questions.
610 Double_t noise = gRandom->Gaus(0.,fgFEENoise);
611 signal += noise;
612
ee299369 613 adcH[iTime] = static_cast<Int_t>(signal + 0.5) ;
b4133f05 614 if ( adcH[iTime] > fgkRawSignalOverflow ){ // larger than 10 bits
615 adcH[iTime] = fgkRawSignalOverflow ;
ee299369 616 lowGain = kTRUE ;
617 }
618
619 signal /= fHighLowGainFactor;
620
621 adcL[iTime] = static_cast<Int_t>(signal + 0.5) ;
b4133f05 622 if ( adcL[iTime] > fgkRawSignalOverflow) // larger than 10 bits
623 adcL[iTime] = fgkRawSignalOverflow ;
ee299369 624 }
625 return lowGain ;
626}