]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PHOS/AliPHOSPulseGenerator.cxx
Update to select in centrality (Giacomo)
[u/mrichter/AliRoot.git] / PHOS / AliPHOSPulseGenerator.cxx
index 4d396041a17f3d98b4836857b4926b159ab885d5..8be79d02cf1745c76dc712dab5a0849dc4181f42 100644 (file)
@@ -21,6 +21,7 @@
 //   AliPHOSPulseGenerator *pulse = new AliPHOSPulseGenerator(energy,time);
 //   Int_t *adcHG = new Int_t[pulse->GetRawFormatTimeBins()];
 //   Int_t *adcLG= new Int_t[pulse->GetRawFormatTimeBins()];
+//   pulse->AddNoise(1.);
 //   pulse->MakeSamples();
 //   pulse->GetSamples(adcHG, adcHG) ; 
 //   pulse->Print();
 // Author: Yuri Kharlov, after Yves Schutz and Per Thomas Hille
 
 // --- ROOT system ---
-#include "TMath.h" 
-#include "TF1.h" 
-#include "TGraph.h" 
-#include "TCanvas.h" 
+
+#include <TCanvas.h> 
+#include <TF1.h> 
+#include <TGraph.h> 
+#include <TH1F.h> 
+#include <TMath.h> 
+#include <TRandom.h>
 
 // --- AliRoot header files ---
 #include "AliLog.h"
@@ -47,18 +51,13 @@ using std::endl;
 
 ClassImp(AliPHOSPulseGenerator) 
 
-Double_t AliPHOSPulseGenerator::fgCapa        = 1.;        // 1pF 
 Int_t    AliPHOSPulseGenerator::fgOrder       = 2 ;        // order of the Gamma function
-Double_t AliPHOSPulseGenerator::fgTimeMax     = 2.56E-5 ;  // each sample is over 100 ns fTimeMax/fTimeBins
-Double_t AliPHOSPulseGenerator::fgTimePeak    = 4.1E-6 ;   // 4 micro seconds
-Double_t AliPHOSPulseGenerator::fgTimeTrigger = 100E-9 ;   // 100ns, just for a reference
-Double_t AliPHOSPulseGenerator::fgHighCharge  = 8.2;       // adjusted for a high gain range of 5.12 GeV (10 bits)
-Double_t AliPHOSPulseGenerator::fgHighGain    = 6.64;
-Double_t AliPHOSPulseGenerator::fgHighLowGainFactor = 16.; // adjusted for a low gain range of 82 GeV (10 bits) 
+Double_t AliPHOSPulseGenerator::fgTimePeak    = 2.1E-6 ;   // tau=2.1 micro seconds
+Double_t AliPHOSPulseGenerator::fgTimeTrigger = 100E-9 ;   // one tick 100 ns
 
 //-----------------------------------------------------------------------------
 AliPHOSPulseGenerator::AliPHOSPulseGenerator(Double_t a, Double_t t0)
-  : TObject(), fAmplitude(a), fTZero(t0), fDataHG(0), fDataLG(0), fDigitize(kTRUE)
+  : TObject(), fAmplitude(a), fTZero(t0), fHG2LGratio(16.), fDataHG(0), fDataLG(0), fDigitize(kTRUE)
 {
   // Contruct a pulsegenrator object and initializes all necessary parameters
   // @param a digit amplitude in GeV
@@ -67,11 +66,13 @@ AliPHOSPulseGenerator::AliPHOSPulseGenerator(Double_t a, Double_t t0)
 
   fDataHG = new Double_t[fkTimeBins];
   fDataLG = new Double_t[fkTimeBins];
+  Reset();
 }
 
 //-----------------------------------------------------------------------------
 AliPHOSPulseGenerator::AliPHOSPulseGenerator(const AliPHOSPulseGenerator & pulse)
-  : TObject(), fAmplitude(pulse.fAmplitude), fTZero(pulse.fTZero), fDataHG(0), fDataLG(0), fDigitize(kTRUE)
+  : TObject(), fAmplitude(pulse.fAmplitude), fTZero(pulse.fTZero),fHG2LGratio(pulse.fHG2LGratio),
+  fDataHG(0), fDataLG(0), fDigitize(kTRUE)
 {
   fDataHG = new Double_t[pulse.fkTimeBins];
   fDataLG = new Double_t[pulse.fkTimeBins];
@@ -92,6 +93,17 @@ AliPHOSPulseGenerator::~AliPHOSPulseGenerator()
   fDataLG=0;
 }
 
+//-----------------------------------------------------------------------------
+void AliPHOSPulseGenerator::Reset()
+{
+  // Reset all sample amplitudes to 0
+
+  for (Int_t i=0; i<fkTimeBins; i++) {
+    fDataHG[i] = 0.;
+    fDataLG[i] = 0.;
+  }
+}
+
 //-----------------------------------------------------------------------------
 void AliPHOSPulseGenerator::AddBaseline(Double_t baselineLevel)
 {
@@ -101,18 +113,22 @@ void AliPHOSPulseGenerator::AddBaseline(Double_t baselineLevel)
     fDataHG[i] += baselineLevel;
     fDataLG[i] += baselineLevel;
   }
+  // Digitize floating point amplitudes to integers
+  if (fDigitize) Digitize();
 }
 
 //-----------------------------------------------------------------------------
-void AliPHOSPulseGenerator::AddNoise(Double_t * /* sigma */)
+void AliPHOSPulseGenerator::AddNoise(Double_t sigma)
 {
-  // Adds Gaussian white noise to the sample array given by *dataPtr.
+  // Adds Gaussian uncorrelated to the sample array
   // @param sigma the noise amplitude in entities of ADC levels  
   
-  AliError("not implemented yet");
+  for (Int_t i=0; i<fkTimeBins; i++) {
+    fDataHG[i] = gRandom->Gaus(0., sigma) ; 
+    fDataLG[i] = gRandom->Gaus(0., sigma) ; 
+  }
 }
 
-
 //-----------------------------------------------------------------------------
 void AliPHOSPulseGenerator::AddNoise(Double_t * /* sigma */, Double_t /* cutoff */)
 {
@@ -138,12 +154,12 @@ void AliPHOSPulseGenerator::AddPretriggerSamples(Int_t nPresamples)
   }
   for (i=0; i<fkTimeBins; i++) {
     if (i<nPresamples) {
-      tmpDataHG[i] = 0.;
-      tmpDataLG[i] = 0.;
+      fDataHG[i] = 0.;
+      fDataLG[i] = 0.;
     }
     else {
-      tmpDataHG[i] = fDataHG[i-nPresamples];
-      tmpDataLG[i] = fDataLG[i-nPresamples];
+      fDataHG[i] = tmpDataHG[i-nPresamples];
+      fDataLG[i] = tmpDataLG[i-nPresamples];
     }
   }
   delete [] tmpDataHG;
@@ -153,10 +169,10 @@ void AliPHOSPulseGenerator::AddPretriggerSamples(Int_t nPresamples)
 //-----------------------------------------------------------------------------
 void AliPHOSPulseGenerator::Digitize()
 {
-  // Emulates ADC: rounds down to nearest integer value all amplitudes
+  // Emulates ADC: rounds up to nearest integer value all amplitudes
   for (Int_t i=0; i<fkTimeBins; i++) {
-    fDataHG[i] = (Double_t) ((Int_t)(fDataHG[i] + 0.5));
-    fDataLG[i] = (Double_t) ((Int_t)(fDataLG[i] + 0.5));
+    fDataHG[i] = (Int_t)(fDataHG[i]);
+    fDataLG[i] = (Int_t)(fDataLG[i]);
   }
 }
 
@@ -165,65 +181,52 @@ Double_t AliPHOSPulseGenerator::RawResponseFunction(Double_t *x, Double_t *par)
 {
   // Shape of the electronics raw reponse:
   // It is a semi-gaussian, 2nd order Gamma function of the general form
-  // v(t) = n**n * Q * A**n / C *(t/tp)**n * exp(-n * t/tp) with 
-  // tp : peaking time par[0]
+  // v(t) = A *(t/tp)**n * exp(-n * t/tp-n) with 
+  // tp : peaking time  fgTimePeak
   // n  : order of the function
-  // C  : integrating capacitor in the preamplifier
-  // A  : open loop gain of the preamplifier
-  // Q  : the total APD charge to be measured Q = C * energy
   
   Double_t signal ;
-  Double_t xx = x[0] - ( fgTimeTrigger + par[3] ) ; 
+  Double_t xx = x[0] - ( fgTimeTrigger + par[1] ) ; 
 
-  if (xx < 0 || xx > fgTimeMax
+  if (xx < 0 || xx > GetRawFormatTimeMax()
     signal = 0. ;  
   else {
-    Double_t fac = par[0] * TMath::Power(fgOrder, fgOrder) * TMath::Power(par[1], fgOrder)/fgCapa ; 
-    signal = fac * par[2] * TMath::Power(xx/fgTimePeak, fgOrder) * TMath::Exp(-fgOrder*(xx/fgTimePeak)) ;
+    signal =  par[0] * TMath::Power(xx/fgTimePeak, fgOrder) * TMath::Exp(-fgOrder*(xx/fgTimePeak-1.)) ; //normalized to par[2] at maximum
   }
   return signal ;  
 }
 
-//__________________________________________________________________
-Double_t AliPHOSPulseGenerator::RawResponseFunctionMax(Double_t charge, Double_t gain) 
-{
-  // Maximum value of the shaper response function
-  return ( charge * TMath::Power(fgOrder, fgOrder) * TMath::Power(gain, fgOrder) 
-          / ( fgCapa * TMath::Exp(fgOrder) ) );  
-}
-
 //__________________________________________________________________
 Bool_t AliPHOSPulseGenerator::MakeSamples()
 {
   // for a start time fTZero and an amplitude fAmplitude given by digit, 
   // calculates the raw sampled response AliPHOSPulseGenerator::RawResponseFunction
 
-  const Int_t kRawSignalOverflow = 0x3FF ; 
+  const Int_t kRawSignalOverflow = 0x3FF ; // decimal 1023
   Bool_t lowGain = kFALSE ; 
 
   TF1 signalF("signal", RawResponseFunction, 0, GetRawFormatTimeMax(), 4);
 
   for (Int_t iTime = 0; iTime < GetRawFormatTimeBins(); iTime++) {
-    signalF.SetParameter(0, fgHighCharge) ; 
-    signalF.SetParameter(1, fgHighGain) ; 
-    signalF.SetParameter(2, fAmplitude) ; 
-    signalF.SetParameter(3, fTZero) ; 
+    signalF.SetParameter(0, fAmplitude) ; 
+    signalF.SetParameter(1, fTZero) ; 
     Double_t time = iTime * GetRawFormatTimeMax() / GetRawFormatTimeBins() ;
     Double_t signal = signalF.Eval(time) ;     
-    if ( static_cast<Int_t>(signal+0.5) > kRawSignalOverflow ){  // larger than 10 bits 
-      signal = kRawSignalOverflow ;
+    fDataHG[iTime] += signal;
+    if ( static_cast<Int_t>(fDataHG[iTime]+0.5) > kRawSignalOverflow ){  // larger than 10 bits 
+      fDataHG[iTime] = kRawSignalOverflow ;
       lowGain = kTRUE ; 
     }
-    fDataHG[iTime] = signal;
 
-    signalF.SetParameter(0, GetRawFormatLowCharge() ) ;     
-    signalF.SetParameter(1, GetRawFormatLowGain() ) ; 
+    Double_t aLGamp = fAmplitude/fHG2LGratio ;
+    signalF.SetParameter(0, aLGamp) ;
     signal = signalF.Eval(time) ;  
-    if ( static_cast<Int_t>(signal+0.5) > kRawSignalOverflow)  // larger than 10 bits 
-      signal = kRawSignalOverflow ;
-    fDataLG[iTime] = signal;
-
+    fDataLG[iTime] += signal;
+    if ( static_cast<Int_t>(fDataLG[iTime]+0.5) > kRawSignalOverflow)  // larger than 10 bits 
+      fDataLG[iTime] = kRawSignalOverflow ;
   }
+  // Digitize floating point amplitudes to integers
+  if (fDigitize) Digitize();
   return lowGain ; 
 }
 
@@ -254,9 +257,12 @@ void AliPHOSPulseGenerator::Print(Option_t*) const
 }
 
 //__________________________________________________________________
-void AliPHOSPulseGenerator::Draw(Option_t*)
+void AliPHOSPulseGenerator::Draw(Option_t* opt)
 {
   // Draw graphs with high and low gain samples
+  // Option_t* opt="all": draw both HG and LG in one canvas
+  //               "HG" : draw HG only
+  //               "LG" : draw LG only
 
   Double_t *time = new Double_t[fkTimeBins];
   for (Int_t iTime = 0; iTime < GetRawFormatTimeBins(); iTime++) {
@@ -266,25 +272,36 @@ void AliPHOSPulseGenerator::Draw(Option_t*)
   TGraph *graphHG = new TGraph(nPoints,time,fDataHG);
   TGraph *graphLG = new TGraph(nPoints,time,fDataLG);
   graphHG->SetMarkerStyle(20);
-  graphLG->SetMarkerStyle(24);
-  graphHG->SetMarkerSize(0.3);
-  graphLG->SetMarkerSize(0.3);
+  graphLG->SetMarkerStyle(20);
+  graphHG->SetMarkerSize(0.4);
+  graphLG->SetMarkerSize(0.4);
   graphHG->SetTitle("High gain samples");
   graphLG->SetTitle("Low gain samples");
 
   TCanvas *c1 = new TCanvas("c1","Raw ALTRO samples",10,10,700,500);
-  c1->Divide(2,1);
-  c1->cd(1);
-  gPad->SetLeftMargin(0.15);
-  graphHG->Draw("AP");
-  graphHG->GetHistogram()->SetTitleOffset(1.6,"Y");
-  graphHG->GetHistogram()->SetXTitle("time, #musec");
-  graphHG->GetHistogram()->SetYTitle("Amplitude, ADC counts");
-  c1->cd(2);
-  gPad->SetLeftMargin(0.15);
-  graphLG->Draw("AP");
-  graphLG->GetHistogram()->SetTitleOffset(1.6,"Y");
-  graphLG->GetHistogram()->SetXTitle("time, #musec");
-  graphLG->GetHistogram()->SetYTitle("Amplitude, ADC counts");
+  c1->SetFillColor(0);
+
+  if (strstr(opt,"all")){
+    c1->Divide(2,1);
+    c1->cd(1);
+    gPad->SetLeftMargin(0.15);
+  }
+  if (strstr(opt,"LG") == 0){
+    graphHG->Draw("AP");
+    graphHG->GetHistogram()->SetTitleOffset(1.0,"Y");
+    graphHG->GetHistogram()->SetXTitle("time, sec");
+    graphHG->GetHistogram()->SetYTitle("Amplitude, ADC counts");
+  }
+  if (strstr(opt,"all")){
+    c1->cd(2);
+    gPad->SetLeftMargin(0.15);
+  }
+  if (strstr(opt,"HG") == 0){
+    graphLG->Draw("AP");
+    graphLG->GetHistogram()->SetTitleOffset(1.0,"Y");
+    graphLG->GetHistogram()->SetXTitle("time, sec");
+    graphLG->GetHistogram()->SetYTitle("Amplitude, ADC counts");
+  }
   c1->Update();
 }
+