]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCAL.cxx
add some missing copy ctors and progress toward code convention compliance
[u/mrichter/AliRoot.git] / EMCAL / AliEMCAL.cxx
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
18 //_________________________________________________________________________
19 // Base Class for EMCAL description:
20 // This class contains material definitions    
21 // for the EMCAL - It does not place the detector in Alice
22 //*-- Author: Yves Schutz (SUBATECH) 
23 //
24 //*-- Additional Contributions: Sahal Yacoob (LBNL/UCT)
25 //
26 //////////////////////////////////////////////////////////////////////////////
27
28 // --- ROOT system ---
29 class TFile;
30 #include <TFolder.h> 
31 #include <TTree.h>
32 #include <TVirtualMC.h> 
33 #include <TH1F.h> 
34 #include <TF1.h> 
35 #include <TRandom.h> 
36 #include <TGraph.h> 
37
38 // --- Standard library ---
39
40 // --- AliRoot header files ---
41 #include "AliMagF.h"
42 #include "AliEMCAL.h"
43 #include "AliRun.h"
44 #include "AliEMCALLoader.h"
45 #include "AliEMCALSDigitizer.h"
46 #include "AliEMCALDigitizer.h"
47 #include "AliEMCALDigit.h"
48 #include "AliAltroBuffer.h"
49 #include "AliRawReader.h"
50 #include "AliEMCALRawStream.h"
51 #include "AliDAQ.h"
52
53 ClassImp(AliEMCAL)
54 Double_t AliEMCAL::fgCapa        = 1.;        // 1pF 
55 Int_t    AliEMCAL::fgOrder       = 2 ;
56 Double_t AliEMCAL::fgTimeMax     = 2.56E-5 ;  // each sample is over 100 ns fTimeMax/fTimeBins
57 Double_t AliEMCAL::fgTimePeak    = 4.1E-6 ;   // 4 micro seconds
58 Double_t AliEMCAL::fgTimeTrigger = 100E-9 ;      // 100ns, just for a reference
59 // some digitization constants
60 Int_t    AliEMCAL::fgThreshold = 1;
61 // 24*48=1152 towers per SM; divided up on 3 DDLs, 
62 // each DDL with 12FEC *32towers or 12*32*2 channels (high&low gain) 
63 Int_t    AliEMCAL::fgChannelsPerDDL = 768; // 2*(1152/3 or 12*32) 
64  
65 //____________________________________________________________________________
66 AliEMCAL::AliEMCAL():AliDetector()
67 {
68   // Default ctor 
69   fName = "EMCAL" ;
70   Init();
71
72 }
73
74 //____________________________________________________________________________
75 AliEMCAL::AliEMCAL(const char* name, const char* title): AliDetector(name,title)
76 {
77   //   ctor : title is used to identify the layout
78   Init();
79
80 }
81
82 //____________________________________________________________________________
83 AliEMCAL::AliEMCAL(const AliEMCAL& emcal) : AliDetector(emcal)
84 {
85   //copy ctor
86   Init();
87
88 }
89
90 //____________________________________________________________________________
91 AliEMCAL::~AliEMCAL()
92 {
93   //dtor
94 }
95
96 //____________________________________________________________________________
97 void AliEMCAL::Init(void)
98 {
99   //initialize EMCAL values
100   fBirkC0 = 1;
101   fBirkC1 = 0.013/1.032;
102   fBirkC2 = 9.6e-6/(1.032 * 1.032);
103   
104   fHighCharge        = 8.2 ;          // adjusted for a high gain range of 5.12 GeV (10 bits)
105   fHighGain          = 6.64 ; 
106   fHighLowGainFactor = 16. ;          // adjusted for a low gain range of 82 GeV (10 bits) 
107   fLowGainOffset     = 1 ;            // offset added to the module id to distinguish high and low gain data
108 }
109
110 //____________________________________________________________________________
111 void AliEMCAL::Copy(AliEMCAL & emcal) const
112 {
113   //copy
114
115   TObject::Copy(emcal) ; 
116   emcal.fHighCharge        = fHighCharge ;
117   emcal.fHighGain          = fHighGain ; 
118   emcal.fHighLowGainFactor = fHighLowGainFactor ;  
119   emcal.fLowGainOffset     = fLowGainOffset;   
120 }
121
122 //____________________________________________________________________________
123 AliDigitizer* AliEMCAL::CreateDigitizer(AliRunDigitizer* manager) const
124 {
125   //create and return the digitizer
126   return new AliEMCALDigitizer(manager);
127 }
128
129 //____________________________________________________________________________
130 void AliEMCAL::CreateMaterials()
131 {
132   // Definitions of materials to build EMCAL and associated tracking media.
133   // media number in idtmed are 1599 to 1698.
134
135   // --- Air ---               
136   Float_t aAir[4]={12.0107,14.0067,15.9994,39.948};
137   Float_t zAir[4]={6.,7.,8.,18.};
138   Float_t wAir[4]={0.000124,0.755267,0.231781,0.012827};
139   Float_t dAir = 1.20479E-3;
140   AliMixture(0, "Air$", aAir, zAir, dAir, 4, wAir) ;
141
142   // --- Lead ---                                                                     
143   AliMaterial(1, "Pb$", 207.2, 82, 11.35, 0.56, 0., 0, 0) ;
144
145
146   // --- The polysterene scintillator (CH) ---
147   Float_t aP[2] = {12.011, 1.00794} ;
148   Float_t zP[2] = {6.0, 1.0} ;
149   Float_t wP[2] = {1.0, 1.0} ;
150   Float_t dP = 1.032 ;
151
152   AliMixture(2, "Polystyrene$", aP, zP, dP, -2, wP) ;
153
154   // --- Aluminium ---
155   AliMaterial(3, "Al$", 26.98, 13., 2.7, 8.9, 999., 0, 0) ;
156   // ---         Absorption length is ignored ^
157
158   // 25-aug-04 by PAI - see  PMD/AliPMDv0.cxx for STEEL definition
159   Float_t asteel[4] = { 55.847,51.9961,58.6934,28.0855 };
160   Float_t zsteel[4] = { 26.,24.,28.,14. };
161   Float_t wsteel[4] = { .715,.18,.1,.005 };
162   AliMixture(4, "STAINLESS STEEL$", asteel, zsteel, 7.88, 4, wsteel);
163
164   // DEFINITION OF THE TRACKING MEDIA
165
166   // for EMCAL: idtmed[1599->1698] equivalent to fIdtmed[0->100]
167   Int_t * idtmed = fIdtmed->GetArray() - 1599 ; 
168   Int_t   isxfld = gAlice->Field()->Integ() ;
169   Float_t sxmgmx = gAlice->Field()->Max() ;
170
171   // Air                                                                         -> idtmed[1599]
172  AliMedium(0, "Air$", 0, 0,
173              isxfld, sxmgmx, 10.0, 1.0, 0.1, 0.1, 10.0, 0, 0) ;
174
175   // The Lead                                                                      -> idtmed[1600]
176  
177   AliMedium(1, "Lead$", 1, 0,
178              isxfld, sxmgmx, 10.0, 0.1, 0.1, 0.1, 0.1, 0, 0) ;
179
180  // The scintillator of the CPV made of Polystyrene scintillator                   -> idtmed[1601]
181   AliMedium(2, "Scintillator$", 2, 1,
182             isxfld, sxmgmx, 10.0, 0.001, 0.1, 0.001, 0.001, 0, 0) ;
183
184   // Various Aluminium parts made of Al                                            -> idtmed[1602]
185   AliMedium(3, "Al$", 3, 0,
186              isxfld, sxmgmx, 10.0, 0.1, 0.1, 0.001, 0.001, 0, 0) ;
187
188   // 25-aug-04 by PAI : see  PMD/AliPMDv0.cxx for STEEL definition                 -> idtmed[1603]
189   AliMedium(4, "S steel$", 4, 0, 
190              isxfld, sxmgmx, 10.0, 0.1, 0.1, 0.001, 0.001, 0, 0) ;
191
192 // --- Set decent energy thresholds for gamma and electron tracking
193
194   // Tracking threshold for photons and electrons in Lead 
195   Float_t cutgam=10.e-5; // 100 kev;
196   Float_t cutele=10.e-5; // 100 kev;
197   TString ntmp(GetTitle()); 
198   ntmp.ToUpper();
199   if(ntmp.Contains("10KEV")) {
200     cutele = cutgam = 1.e-5;
201   } else if(ntmp.Contains("50KEV")) {
202     cutele = cutgam = 5.e-5;
203   } else if(ntmp.Contains("100KEV")) {
204     cutele = cutgam = 1.e-4;
205   } else if(ntmp.Contains("200KEV")) {
206     cutele = cutgam = 2.e-4;
207   } else if(ntmp.Contains("500KEV")) {
208     cutele = cutgam = 5.e-4;
209   }
210
211   gMC->Gstpar(idtmed[1600],"CUTGAM", cutgam);
212   gMC->Gstpar(idtmed[1600],"CUTELE", cutele); // 1MEV -> 0.1MEV; 15-aug-05
213   gMC->Gstpar(idtmed[1600],"BCUTE",  cutgam);  // BCUTE and BCUTM start from GUTGUM
214   gMC->Gstpar(idtmed[1600],"BCUTM",  cutgam);  // BCUTE and BCUTM start from GUTGUM
215   // --- Generate explicitly delta rays in Lead ---
216   gMC->Gstpar(idtmed[1600], "LOSS",3.) ;
217   gMC->Gstpar(idtmed[1600], "DRAY",1.) ;
218   gMC->Gstpar(idtmed[1600], "DCUTE", cutele) ;
219   gMC->Gstpar(idtmed[1600], "DCUTM", cutele) ;
220
221 // --- in aluminium parts ---
222   gMC->Gstpar(idtmed[1602],"CUTGAM", cutgam) ;
223   gMC->Gstpar(idtmed[1602],"CUTELE", cutele) ;
224   gMC->Gstpar(idtmed[1602],"BCUTE",  cutgam);  // BCUTE and BCUTM start from GUTGUM
225   gMC->Gstpar(idtmed[1602],"BCUTM",  cutgam);  // BCUTE and BCUTM start from GUTGUM
226   gMC->Gstpar(idtmed[1602], "LOSS",3.) ;
227   gMC->Gstpar(idtmed[1602], "DRAY",1.) ;
228   gMC->Gstpar(idtmed[1602], "DCUTE", cutele) ;
229   gMC->Gstpar(idtmed[1602], "DCUTM", cutele) ;
230
231 // --- and finally thresholds for photons and electrons in the scintillator ---
232   gMC->Gstpar(idtmed[1601],"CUTGAM", cutgam) ;
233   gMC->Gstpar(idtmed[1601],"CUTELE", cutele) ;// 1MEV -> 0.1MEV; 15-aug-05
234   gMC->Gstpar(idtmed[1601],"BCUTE",  cutgam);  // BCUTE and BCUTM start from GUTGUM
235   gMC->Gstpar(idtmed[1601],"BCUTM",  cutgam);  // BCUTE and BCUTM start from GUTGUM
236   gMC->Gstpar(idtmed[1601], "LOSS",3.) ; // generate delta rays 
237   gMC->Gstpar(idtmed[1601], "DRAY",1.) ;
238   gMC->Gstpar(idtmed[1601], "DCUTE", cutele) ;
239   gMC->Gstpar(idtmed[1601], "DCUTM", cutele) ;
240
241   // S steel - 
242   gMC->Gstpar(idtmed[1603],"CUTGAM", cutgam);
243   gMC->Gstpar(idtmed[1603],"CUTELE", cutele);
244   gMC->Gstpar(idtmed[1603],"BCUTE",  cutgam);  // BCUTE and BCUTM start from GUTGUM
245   gMC->Gstpar(idtmed[1603],"BCUTM",  cutgam);  // BCUTE and BCUTM start from GUTGUM
246   // --- Generate explicitly delta rays 
247   gMC->Gstpar(idtmed[1603], "LOSS",3.);
248   gMC->Gstpar(idtmed[1603], "DRAY",1.);
249   gMC->Gstpar(idtmed[1603], "DCUTE", cutele) ;
250   gMC->Gstpar(idtmed[1603], "DCUTM", cutele) ;
251
252   //set constants for Birk's Law implentation
253   fBirkC0 =  1;
254   fBirkC1 =  0.013/dP;
255   fBirkC2 =  9.6e-6/(dP * dP);
256
257 }
258       
259 //____________________________________________________________________________
260 void AliEMCAL::Digits2Raw()
261 {
262   // convert digits of the current event to raw data
263   AliEMCALLoader * loader = dynamic_cast<AliEMCALLoader*>(fLoader) ; 
264
265   // get the digits
266   loader->LoadDigits("EMCAL");
267   loader->GetEvent();
268   TClonesArray* digits = loader->Digits() ;
269
270   if (!digits) {
271     Error("Digits2Raw", "no digits found !");
272     return;
273   }
274
275   // get the digitizer 
276   loader->LoadDigitizer();
277   AliEMCALDigitizer * digitizer = dynamic_cast<AliEMCALDigitizer *>(loader->Digitizer())  ; 
278   
279
280   AliAltroBuffer* buffer = NULL;
281   Int_t prevDDL = -1;
282   Int_t adcValuesLow[fgkTimeBins];
283   Int_t adcValuesHigh[fgkTimeBins];
284   
285   // loop over digits (assume ordered digits)
286   for (Int_t iDigit = 0; iDigit < digits->GetEntries(); iDigit++) {
287     AliEMCALDigit* digit = dynamic_cast<AliEMCALDigit *>(digits->At(iDigit)) ;
288     if (digit->GetAmp() < fgThreshold) 
289       continue;
290     Int_t iDDL = digit->GetId() / fgChannelsPerDDL ;
291     // for each DDL id is numbered from 1 to  fgChannelsperDDL -1 
292     Int_t idDDL = digit->GetId() - iDDL * ( fgChannelsPerDDL - 1 ) ;  
293     // new DDL
294     if (iDDL != prevDDL) {
295       // write real header and close previous file
296       if (buffer) {
297         buffer->Flush();
298         buffer->WriteDataHeader(kFALSE, kFALSE);
299         delete buffer;
300       }
301
302       // open new file and write dummy header
303       TString fileName(AliDAQ::DdlFileName("EMCAL",iDDL));
304       buffer = new AliAltroBuffer(fileName.Data());
305       buffer->WriteDataHeader(kTRUE, kFALSE);  //Dummy;
306
307       prevDDL = iDDL;
308     }
309
310     // out of time range signal (?)
311     if (digit->GetTimeR() > GetRawFormatTimeMax() ) {
312       buffer->FillBuffer(digit->GetAmp());
313       buffer->FillBuffer(GetRawFormatTimeBins() );  // time bin
314       buffer->FillBuffer(3);          // bunch length
315       buffer->WriteTrailer(3, idDDL, 0, 0);  // trailer
316
317       // calculate the time response function
318     } else {
319       Double_t energy = 0 ;  
320       energy = digit->GetAmp() * digitizer->GetECAchannel() + digitizer->GetECApedestal() ; 
321       
322       Bool_t lowgain = RawSampledResponse(digit->GetTimeR(), energy, adcValuesHigh, adcValuesLow) ; 
323       
324       if (lowgain) 
325         buffer->WriteChannel(iDDL, 0, fLowGainOffset, 
326                              GetRawFormatTimeBins(), adcValuesLow, fgThreshold);
327       else 
328         buffer->WriteChannel(iDDL, 0, 0, 
329                              GetRawFormatTimeBins(), adcValuesHigh, fgThreshold);
330       
331     }
332   }
333   
334   // write real header and close last file
335   if (buffer) {
336     buffer->Flush();
337     buffer->WriteDataHeader(kFALSE, kFALSE);
338     delete buffer;
339   }
340
341   loader->UnloadDigits();
342 }
343
344 //____________________________________________________________________________
345 void AliEMCAL::Raw2Digits(AliRawReader* reader)
346 {
347   // convert raw data of the current event to digits
348   GetGeometry();
349   AliEMCALLoader * loader = dynamic_cast<AliEMCALLoader*>(fLoader) ; 
350
351   // get the digits
352   loader->CleanDigits(); // start from scratch
353   loader->LoadDigits("EMCAL");
354   TClonesArray* digits = loader->Digits() ;
355   digits->Clear(); // yes, this is perhaps somewhat paranoid.. [clearing an extra time]
356
357   if (!digits) {
358     Error("Raw2Digits", "no digits found !");
359     return;
360   }
361   if (!reader) {
362     Error("Raw2Digits", "no raw reader found !");
363     return;
364   }
365
366   // and get the digitizer too 
367   loader->LoadDigitizer();
368   AliEMCALDigitizer * digitizer = dynamic_cast<AliEMCALDigitizer *>(loader->Digitizer())  ; 
369
370   // Use AliAltroRawStream to read the ALTRO format.  No need to
371   // reinvent the wheel :-) 
372   AliEMCALRawStream in(reader);
373   // Select EMCAL DDL's;
374   reader->Select("EMCAL");
375
376   // reading is from previously existing AliEMCALGetter.cxx
377   // ReadRaw method
378   Bool_t first = kTRUE ;
379  
380   TF1 * signalF = new TF1("signal", RawResponseFunction, 0, GetRawFormatTimeMax(), 4);
381   signalF->SetParNames("Charge", "Gain", "Amplitude", "TimeZero"); 
382   
383   Int_t id = -1;
384   Bool_t lowGainFlag = kFALSE ; 
385
386   Int_t idigit = 0 ; 
387   Int_t amp = 0 ; 
388   Double_t time = 0. ; 
389   Double_t energy = 0. ; 
390
391   TGraph * gLowGain = new TGraph(GetRawFormatTimeBins()) ; 
392   TGraph * gHighGain= new TGraph(GetRawFormatTimeBins()) ;  
393
394   while ( in.Next() ) { // EMCAL entries loop 
395     if ( in.IsNewId() ) {
396       if (!first) {
397         FitRaw(lowGainFlag, gLowGain, gHighGain, signalF, energy, time) ; 
398
399         if (time == 0. && energy == 0.) { 
400           amp = 0 ; 
401         }
402         else {
403           amp = static_cast<Int_t>( (energy - digitizer->GetECApedestal()) / digitizer->GetECAchannel() + 0.5 ) ; 
404         }
405
406         if (amp > 0) {
407           new((*digits)[idigit]) AliEMCALDigit( -1, -1, id, amp, time) ;        
408           idigit++ ; 
409         }
410         Int_t index ; 
411         for (index = 0; index < GetRawFormatTimeBins(); index++) {
412           gLowGain->SetPoint(index, index * GetRawFormatTimeMax() / GetRawFormatTimeBins(), 0) ;  
413           gHighGain->SetPoint(index, index * GetRawFormatTimeMax() / GetRawFormatTimeBins(), 0) ; 
414         } 
415       } // not first  
416       first = kFALSE ; 
417       id = in.GetId() ; 
418       if (in.GetModule() == GetRawFormatLowGainOffset() ) {
419         lowGainFlag = kTRUE ; 
420       }
421       else { 
422         lowGainFlag = kFALSE ; 
423       }
424     } // new Id?
425     if (lowGainFlag) {
426       gLowGain->SetPoint(in.GetTime(), 
427                          in.GetTime()* GetRawFormatTimeMax() / GetRawFormatTimeBins(), 
428                          in.GetSignal()) ;
429     }
430     else { 
431       gHighGain->SetPoint(in.GetTime(), 
432                           in.GetTime() * GetRawFormatTimeMax() / GetRawFormatTimeBins(), 
433                           in.GetSignal() ) ;
434     }
435   } // EMCAL entries loop
436   digits->Sort() ; 
437
438   delete signalF ; 
439   delete gLowGain;
440   delete gHighGain ; 
441     
442   return ; 
443 }
444
445 //____________________________________________________________________________ 
446 void AliEMCAL::FitRaw(Bool_t lowGainFlag, TGraph * gLowGain, TGraph * gHighGain, TF1* signalF, Double_t & energy, Double_t & time)
447 {
448   // Fits the raw signal time distribution; from AliEMCALGetter 
449
450   const Int_t kNoiseThreshold = 0 ;
451   Double_t timezero1 = 0., timezero2 = 0., timemax = 0. ;
452   Double_t signal = 0., signalmax = 0. ;       
453   energy = time = 0. ; 
454
455   if (lowGainFlag) {
456     timezero1 = timezero2 = signalmax = timemax = 0. ;
457     signalF->FixParameter(0, GetRawFormatLowCharge()) ; 
458     signalF->FixParameter(1, GetRawFormatLowGain()) ; 
459     Int_t index ; 
460     for (index = 0; index < GetRawFormatTimeBins(); index++) {
461       gLowGain->GetPoint(index, time, signal) ; 
462       if (signal > kNoiseThreshold && timezero1 == 0.) 
463         timezero1 = time ;
464       if (signal <= kNoiseThreshold && timezero1 > 0. && timezero2 == 0.)
465         timezero2 = time ; 
466       if (signal > signalmax) {
467         signalmax = signal ; 
468         timemax   = time ; 
469       }
470     }
471     signalmax /= RawResponseFunctionMax(GetRawFormatLowCharge(), 
472                                                 GetRawFormatLowGain()) ;
473     if ( timezero1 + GetRawFormatTimePeak() < GetRawFormatTimeMax() * 0.4 ) { // else its noise 
474       signalF->SetParameter(2, signalmax) ; 
475       signalF->SetParameter(3, timezero1) ;         
476       gLowGain->Fit(signalF, "QRON", "", 0., timezero2); //, "QRON") ; 
477       energy = signalF->GetParameter(2) ; 
478       time   = signalF->GetMaximumX() - GetRawFormatTimePeak() - GetRawFormatTimeTrigger() ;
479     }
480   } else {
481     timezero1 = timezero2 = signalmax = timemax = 0. ;
482     signalF->FixParameter(0, GetRawFormatHighCharge()) ; 
483     signalF->FixParameter(1, GetRawFormatHighGain()) ; 
484     Int_t index ; 
485     for (index = 0; index < GetRawFormatTimeBins(); index++) {
486       gHighGain->GetPoint(index, time, signal) ;               
487       if (signal > kNoiseThreshold && timezero1 == 0.) 
488         timezero1 = time ;
489       if (signal <= kNoiseThreshold && timezero1 > 0. && timezero2 == 0.)
490         timezero2 = time ; 
491       if (signal > signalmax) {
492         signalmax = signal ;   
493         timemax   = time ; 
494       }
495     }
496     signalmax /= RawResponseFunctionMax(GetRawFormatHighCharge(), 
497                                                 GetRawFormatHighGain()) ;;
498     if ( timezero1 + GetRawFormatTimePeak() < GetRawFormatTimeMax() * 0.4 ) { // else its noise  
499       signalF->SetParameter(2, signalmax) ; 
500       signalF->SetParameter(3, timezero1) ;               
501       gHighGain->Fit(signalF, "QRON", "", 0., timezero2) ; 
502       energy = signalF->GetParameter(2) ; 
503       time   = signalF->GetMaximumX() - GetRawFormatTimePeak() - GetRawFormatTimeTrigger() ;
504     }
505   }
506   
507   return;
508 }
509
510 //____________________________________________________________________________
511 void AliEMCAL::Hits2SDigits()  
512
513 // create summable digits
514
515   GetGeometry();
516   AliEMCALSDigitizer emcalDigitizer(fLoader->GetRunLoader()->GetFileName().Data()) ;
517   emcalDigitizer.SetEventRange(0, -1) ; // do all the events
518   emcalDigitizer.ExecuteTask() ;
519 }
520
521 //____________________________________________________________________________
522
523 AliLoader* AliEMCAL::MakeLoader(const char* topfoldername)
524 {
525 //different behaviour than standard (singleton getter)
526 // --> to be discussed and made eventually coherent
527  fLoader = new AliEMCALLoader(GetName(),topfoldername);
528  return fLoader;
529 }
530
531 //__________________________________________________________________
532 Double_t AliEMCAL::RawResponseFunction(Double_t *x, Double_t *par)
533 {
534   // Shape of the electronics raw reponse:
535   // It is a semi-gaussian, 2nd order Gamma function of the general form
536   // v(t) = n**n * Q * A**n / C *(t/tp)**n * exp(-n * t/tp) with 
537   // tp : peaking time par[0]
538   // n  : order of the function
539   // C  : integrating capacitor in the preamplifier
540   // A  : open loop gain of the preamplifier
541   // Q  : the total APD charge to be measured Q = C * energy
542   
543   Double_t signal ;
544   Double_t xx = x[0] - ( fgTimeTrigger + par[3] ) ; 
545   
546   if (xx < 0 || xx > fgTimeMax) 
547     signal = 0. ;  
548   else { 
549     Double_t fac = par[0] * TMath::Power(fgOrder, fgOrder) * TMath::Power(par[1], fgOrder) / fgCapa ; 
550     signal = fac * par[2] * TMath::Power(xx / fgTimePeak, fgOrder) * TMath::Exp(-fgOrder * (xx / fgTimePeak)) ; 
551   }
552   return signal ;  
553 }
554
555 //__________________________________________________________________
556 Double_t AliEMCAL::RawResponseFunctionMax(Double_t charge, Double_t gain) 
557 {
558   //compute the maximum of the raw response function and return
559   return ( charge * TMath::Power(fgOrder, fgOrder) * TMath::Power(gain, fgOrder) 
560      / ( fgCapa * TMath::Exp(fgOrder) ) );  
561
562 }
563 //__________________________________________________________________
564 Bool_t AliEMCAL::RawSampledResponse(
565 const Double_t dtime, const Double_t damp, Int_t * adcH, Int_t * adcL) const 
566 {
567   // for a start time dtime and an amplitude damp given by digit, 
568   // calculates the raw sampled response AliEMCAL::RawResponseFunction
569
570   const Int_t kRawSignalOverflow = 0x3FF ; 
571   Bool_t lowGain = kFALSE ; 
572
573   TF1 signalF("signal", RawResponseFunction, 0, GetRawFormatTimeMax(), 4);
574
575   for (Int_t iTime = 0; iTime < GetRawFormatTimeBins(); iTime++) {
576     signalF.SetParameter(0, GetRawFormatHighCharge() ) ; 
577     signalF.SetParameter(1, GetRawFormatHighGain() ) ; 
578     signalF.SetParameter(2, damp) ; 
579     signalF.SetParameter(3, dtime) ; 
580     Double_t time = iTime * GetRawFormatTimeMax() / GetRawFormatTimeBins() ;
581     Double_t signal = signalF.Eval(time) ;     
582     if ( static_cast<Int_t>(signal+0.5) > kRawSignalOverflow ){  // larger than 10 bits 
583       signal = kRawSignalOverflow ;
584       lowGain = kTRUE ; 
585     }
586     adcH[iTime] =  static_cast<Int_t>(signal + 0.5) ;
587
588     signalF.SetParameter(0, GetRawFormatLowCharge() ) ;     
589     signalF.SetParameter(1, GetRawFormatLowGain() ) ; 
590     signal = signalF.Eval(time) ;  
591     if ( static_cast<Int_t>(signal+0.5) > kRawSignalOverflow)  // larger than 10 bits 
592       signal = kRawSignalOverflow ;
593     adcL[iTime] = static_cast<Int_t>(0.5 + signal ) ; 
594
595   }
596   return lowGain ; 
597 }