]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - EMCAL/AliEMCALDigitizer.cxx
using non-uniform field option for tracking (Jacek)
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALDigitizer.cxx
index f3bce117a70a7805cd7a9e3341f8e17786c6b1dc..cf49406c42484357db683e106d758c2fbca2e93e 100644 (file)
@@ -18,7 +18,7 @@
 //_________________________________________________________________________
 // 
 //////////////////////////////////////////////////////////////////////////////
-// Class performs digitization of Summable digits 
+// Class performs digitization of Summable digits from simulated data
 //  
 // In addition it performs mixing of summable digits from different events.
 //
 #include <TTree.h>
 #include <TSystem.h>
 #include <TBenchmark.h>
-#include <TList.h>
-#include <TH1.h>
 #include <TBrowser.h>
 #include <TObjectTable.h>
 #include <TRandom.h>
+#include <cassert>
 
 // --- AliRoot header files ---
 #include "AliLog.h"
@@ -83,7 +82,6 @@
 #include "AliEMCALSDigitizer.h"
 #include "AliEMCALGeometry.h"
 #include "AliEMCALTick.h"
-#include "AliEMCALHistoUtilities.h"
 
 ClassImp(AliEMCALDigitizer)
 
@@ -111,12 +109,11 @@ AliEMCALDigitizer::AliEMCALDigitizer()
     fEventFolderName(""),
     fFirstEvent(0),
     fLastEvent(0),
-    fControlHists(0),
-    fHists(0),fCalibData(0x0)
+    fCalibData(0x0)
 {
   // ctor
   InitParameters() ; 
-  fManager = 0 ;                     // We work in the standalong mode
+  fManager = 0 ;                     // We work in the standalone mode
 }
 
 //____________________________________________________________________________ 
@@ -142,13 +139,12 @@ AliEMCALDigitizer::AliEMCALDigitizer(TString alirunFileName, TString eventFolder
     fEventFolderName(eventFolderName),
     fFirstEvent(0),
     fLastEvent(0),
-    fControlHists(0),
-    fHists(0)
+    fCalibData(0x0)
 {
   // ctor
   InitParameters() ; 
   Init() ;
-  fManager = 0 ;                     // We work in the standalong mode
+  fManager = 0 ;                     // We work in the standalone mode
 }
 
 //____________________________________________________________________________ 
@@ -174,8 +170,7 @@ AliEMCALDigitizer::AliEMCALDigitizer(const AliEMCALDigitizer & d)
     fEventFolderName(d.fEventFolderName),
     fFirstEvent(d.fFirstEvent),
     fLastEvent(d.fLastEvent),
-    fControlHists(d.fControlHists),
-    fHists(d.fHists),fCalibData(d.fCalibData)
+    fCalibData(d.fCalibData)
 {
   // copyy ctor 
  }
@@ -203,8 +198,7 @@ AliEMCALDigitizer::AliEMCALDigitizer(AliRunDigitizer * rd)
     fEventFolderName(0),
     fFirstEvent(0),
     fLastEvent(0),
-    fControlHists(0),
-    fHists(0)
+    fCalibData(0x0)
 {
   // ctor Init() is called by RunDigitizer
   fManager = rd ; 
@@ -227,7 +221,6 @@ AliEMCALDigitizer::AliEMCALDigitizer(AliRunDigitizer * rd)
   delete [] fInputFileNames ; 
   delete [] fEventNames ; 
 
-  if(fHists) delete fHists;
 }
 
 //____________________________________________________________________________
@@ -236,11 +229,15 @@ void AliEMCALDigitizer::Digitize(Int_t event)
 
   // Makes the digitization of the collected summable digits
   // for this it first creates the array of all EMCAL modules
-  // filled with noise (different for EMC, CPV and PPSD) and
-  // after that adds contributions from SDigits. This design 
-  // helps to avoid scanning over the list of digits to add 
-  // contribution of any new SDigit.
-  static int isTrd1Geom = -1; // -1 - mean undefined 
+  // filled with noise and after that adds contributions from 
+  // SDigits. This design helps to avoid scanning over the 
+  // list of digits to add  contribution of any new SDigit.
+  //
+  // JLK 26-Jun-2008
+  // Note that SDigit energy info is stored as an amplitude, so we
+  // must call the Calibrate() method of the SDigitizer to convert it
+  // back to an energy in GeV before adding it to the Digit
+  //
   static int nEMC=0; //max number of digits possible
 
   AliRunLoader *rl = AliRunLoader::GetRunLoader();
@@ -254,7 +251,8 @@ void AliEMCALDigitizer::Digitize(Int_t event)
   rl->GetEvent(readEvent);
 
   TClonesArray * digits = emcalLoader->Digits() ; 
-  digits->Delete() ;  
+  digits->Delete() ;  //correct way to clear array when memory is
+                     //allocated by objects stored in array
 
   // Load Geometry
   AliEMCALGeometry *geom = 0;
@@ -265,16 +263,9 @@ void AliEMCALDigitizer::Digitize(Int_t event)
   else 
     AliFatal("Could not get AliRun from runLoader");
 
-  if(isTrd1Geom < 0) { 
-    AliInfo(Form(" get Geometry %s : %s ", geom->GetName(),geom->GetTitle()));
-    TString ng(geom->GetName());
-    isTrd1Geom = 0;
-    if(ng.Contains("SHISH") &&  ng.Contains("TRD1")) isTrd1Geom = 1;
-
-    if(isTrd1Geom == 0) nEMC = geom->GetNPhi()*geom->GetNZ();
-    else                nEMC = geom->GetNCells();
-    AliDebug(1,Form("nEMC %i (number cells in EMCAL) | %s | isTrd1Geom %i\n", nEMC, geom->GetName(), isTrd1Geom));
-  }
+  nEMC = geom->GetNCells();
+  AliDebug(1,Form("nEMC %i (number cells in EMCAL) | %s \n", nEMC, geom->GetName()));
+  
   Int_t absID ;
 
   digits->Expand(nEMC) ;
@@ -331,11 +322,11 @@ void AliEMCALDigitizer::Digitize(Int_t event)
   AliEMCALDigit * digit ;
   AliEMCALDigit * curSDigit ;
 
-  TClonesArray * ticks = new TClonesArray("AliEMCALTick",1000) ;
+  //  TClonesArray * ticks = new TClonesArray("AliEMCALTick",1000) ;
 
   //Put Noise contribution
   for(absID = 0; absID < nEMC; absID++){ // Nov 30, 2006 by PAI; was from 1 to nEMC
-    Float_t amp = 0 ;
+    Float_t energy = 0 ;
     // amplitude set to zero, noise will be added later
     new((*digits)[absID]) AliEMCALDigit( -1, -1, absID, 0, TimeOfNoise() ); // absID-1->absID
     //look if we have to add signal?
@@ -343,14 +334,22 @@ void AliEMCALDigitizer::Digitize(Int_t event)
     
     if(absID==nextSig){
       //Add SDigits from all inputs    
-      ticks->Clear() ;
-      Int_t contrib = 0 ;
-      Float_t a = digit->GetAmp() ;
-      Float_t b = TMath::Abs( a /fTimeSignalLength) ;
+      //      ticks->Clear() ;
+      //Int_t contrib = 0 ;
+
+      //Follow PHOS and comment out this timing model til a better one
+      //can be developed - JLK 28-Apr-2008
+
+      //Float_t a = digit->GetAmp() ;
+      //Float_t b = TMath::Abs( a /fTimeSignalLength) ;
       //Mark the beginning of the signal
-      new((*ticks)[contrib++]) AliEMCALTick(digit->GetTime(),0, b);  
+      //new((*ticks)[contrib++]) AliEMCALTick(digit->GetTime(),0, b);  
       //Mark the end of the signal     
-      new((*ticks)[contrib++]) AliEMCALTick(digit->GetTime()+fTimeSignalLength, -a, -b);
+      //new((*ticks)[contrib++]) AliEMCALTick(digit->GetTime()+fTimeSignalLength, -a, -b);
+
+      // Calculate time as time of the largest digit
+      Float_t time = digit->GetTime() ;
+      Float_t aTime= digit->GetAmp() ;
       
       // loop over input
       for(i = 0; i< fInput ; i++){  //loop over (possible) merge sources
@@ -367,13 +366,18 @@ void AliEMCALDigitizer::Digitize(Int_t event)
          else
            primaryoffset = i ;
          curSDigit->ShiftPrimary(primaryoffset) ;
-         
-         a = curSDigit->GetAmp() ;
-         b = a /fTimeSignalLength ;
-         new((*ticks)[contrib++]) AliEMCALTick(curSDigit->GetTime(),0, b);  
-         new((*ticks)[contrib++]) AliEMCALTick(curSDigit->GetTime()+fTimeSignalLength, -a, -b); 
 
-         *digit = *digit + *curSDigit ;  //add energies
+         //Remove old timing model - JLK 28-April-2008
+         //a = curSDigit->GetAmp() ;
+         //b = a /fTimeSignalLength ;
+         //new((*ticks)[contrib++]) AliEMCALTick(curSDigit->GetTime(),0, b);  
+         //new((*ticks)[contrib++]) AliEMCALTick(curSDigit->GetTime()+fTimeSignalLength, -a, -b); 
+         if(curSDigit->GetAmp()>aTime) {
+           aTime = curSDigit->GetAmp();
+           time = curSDigit->GetTime();
+         }
+
+         *digit = *digit + *curSDigit ;  //adds amplitudes of each digit
 
          index[i]++ ;
          if( dynamic_cast<TClonesArray *>(sdigArray->At(i))->GetEntriesFast() > index[i] )
@@ -382,12 +386,14 @@ void AliEMCALDigitizer::Digitize(Int_t event)
            curSDigit = 0 ;
        }
       }
+      //Here we convert the summed amplitude to an energy in GeV
+      energy = sDigitizer->Calibrate(digit->GetAmp()) ; // GeV
       // add fluctuations for photo-electron creation
-      amp = sDigitizer->Calibrate(digit->GetAmp()) ; // GeV
-      amp *= static_cast<Float_t>(gRandom->Poisson(fMeanPhotonElectron)) / static_cast<Float_t>(fMeanPhotonElectron) ;
+      energy *= static_cast<Float_t>(gRandom->Poisson(fMeanPhotonElectron)) / static_cast<Float_t>(fMeanPhotonElectron) ;
   
       //calculate and set time
-      Float_t time = FrontEdgeTime(ticks) ;
+      //New timing model needed - JLK 28-April-2008
+      //Float_t time = FrontEdgeTime(ticks) ;
       digit->SetTime(time) ;
 
       //Find next signal module
@@ -402,21 +408,27 @@ void AliEMCALDigitizer::Digitize(Int_t event)
       }
     }
     // add the noise now
-    amp += TMath::Abs(gRandom->Gaus(0., fPinNoise)) ;
-    digit->SetAmp(sDigitizer->Digitize(amp)) ;  
-    AliDebug(10,Form(" absID %5i amp %f nextSig %5i\n",
-                    absID, amp, nextSig));
-  } // for(absID = 1; absID <= nEMC; absID++)
+    energy += TMath::Abs(gRandom->Gaus(0., fPinNoise)) ;
+    // JLK 26-June-2008
+    //Now digitize the energy according to the sDigitizer method,
+    //which merely converts the energy to an integer.  Later we will
+    //check that the stored value matches our allowed dynamic ranges
+    digit->SetAmp(sDigitizer->Digitize(energy)) ;  
+    AliDebug(10,Form(" absID %5i energy %f nextSig %5i\n",
+                    absID, energy, nextSig));
+  } // for(absID = 0; absID < nEMC; absID++)
   
-  ticks->Delete() ;
-  delete ticks ;
+  //ticks->Delete() ;
+  //delete ticks ;
 
+  //JLK is it better to call Clear() here?
   delete sdigArray ; //We should not delete its contents
 
   //remove digits below thresholds
   for(i = 0 ; i < nEMC ; i++){
     digit = dynamic_cast<AliEMCALDigit*>( digits->At(i) ) ;
-    Float_t threshold = fDigitThreshold ; 
+    Float_t threshold = fDigitThreshold ; //this is in GeV
+    //need to calibrate digit amplitude to energy in GeV for comparison
     if(sDigitizer->Calibrate( digit->GetAmp() ) < threshold)
       digits->RemoveAt(i) ;
     else 
@@ -426,33 +438,31 @@ void AliEMCALDigitizer::Digitize(Int_t event)
   digits->Compress() ;  
   
   Int_t ndigits = digits->GetEntriesFast() ; 
-  
-  //Set indexes in list of digits and fill hists.
-  AliEMCALHistoUtilities::FillH1(fHists, 0, Double_t(ndigits));
-  Float_t energy=0., esum=0.;
+
+  //JLK 26-June-2008
+  //After we have done the summing and digitizing to create the
+  //digits, now we want to calibrate the resulting amplitude to match
+  //the dynamic range of our real data.  
+  Float_t energy=0;
   for (i = 0 ; i < ndigits ; i++) { 
     digit = dynamic_cast<AliEMCALDigit *>( digits->At(i) ) ; 
     digit->SetIndexInList(i) ; 
     energy = sDigitizer->Calibrate(digit->GetAmp()) ;
-    esum += energy;
-    digit->SetAmp(DigitizeEnergy(energy, digit->GetId()) ) ; // for what ??
-    AliEMCALHistoUtilities::FillH1(fHists, 2, double(digit->GetAmp()));
-    AliEMCALHistoUtilities::FillH1(fHists, 3, double(energy));
-    AliEMCALHistoUtilities::FillH1(fHists, 4, double(digit->GetId()));
-    //    if(digit->GetId() == nEMC) {
-    //  printf(" i %i \n", i );
-    //  digit->Dump();
-    //  assert(0);
-    //}
+    digit->SetAmp(DigitizeEnergy(energy, digit->GetId()) ) ;
   }
-  AliEMCALHistoUtilities::FillH1(fHists, 1, esum);
+
 }
 
 // //_____________________________________________________________________
 Int_t AliEMCALDigitizer::DigitizeEnergy(Float_t energy, Int_t AbsId)
 { 
+  // JLK 26-June-2008
   // Returns digitized value of the energy in a cell absId
-
+  // using the calibration constants stored in the OCDB
+  // or default values if no CalibData object is found.
+  // This effectively converts everything to match the dynamic range
+  // of the real data we will collect
+  //
   // Load Geometry
   const AliEMCALGeometry * geom = AliEMCALGeometry::GetInstance();
 
@@ -605,7 +615,6 @@ Bool_t AliEMCALDigitizer::Init()
   //to prevent cleaning of this object while GetEvent is called
   emcalLoader->GetDigitsDataLoader()->GetBaseTaskLoader()->SetDoNotReload(kTRUE);
 
-  //PH  Print();
   //Calibration instance
   fCalibData = emcalLoader->CalibData();
   return fInit ;    
@@ -614,25 +623,26 @@ Bool_t AliEMCALDigitizer::Init()
 //____________________________________________________________________________ 
 void AliEMCALDigitizer::InitParameters()
 { 
-  //parameter initialization for digitizer
-  // Tune parameters - 24-nov-04
+  // Parameter initialization for digitizer
+  // Tune parameters - 24-nov-04; Apr 29, 2007
+  // New parameters JLK 14-Apr-2008
 
-  fMeanPhotonElectron = 3300 ; // electrons per GeV 
-  fPinNoise           = 0.004; 
+  fMeanPhotonElectron = 4400;  // electrons per GeV 
+  fPinNoise           = 0.037; // pin noise in GEV from analysis test beam data 
   if (fPinNoise == 0. ) 
     Warning("InitParameters", "No noise added\n") ; 
   fDigitThreshold     = fPinNoise * 3; // 3 * sigma
   fTimeResolution     = 0.3e-9 ; // 300 psc
   fTimeSignalLength   = 1.0e-9 ;
 
-  fADCchannelEC    = 0.00305; // 200./65536 - width of one ADC channel in GeV
-  fADCpedestalEC   = 0.009 ;  // GeV
+  // These defaults are normally not used. 
+  // Values are read from calibration database instead
+  fADCchannelEC    = 0.0153; // Update 24 Apr 2007: 250./16/1024 - width of one ADC channel in GeV
+  fADCpedestalEC   = 0.0 ;  // GeV
   fNADCEC          = (Int_t) TMath::Power(2,16) ;  // number of channels in Tower ADC - 65536
 
   fTimeThreshold      = 0.001*10000000 ; // Means 1 MeV in terms of SDigits amplitude ??
-  // hists. for control; no hists on default
-  fControlHists = 0;
-  fHists        = 0;
+
 }
 
 //__________________________________________________________________
@@ -688,6 +698,7 @@ void AliEMCALDigitizer::MixWith(TString alirunFileName, TString eventFolderName)
     fInput++ ;
 }  
 
+//__________________________________________________________________
 void AliEMCALDigitizer::Print1(Option_t * option)
 { // 19-nov-04 - just for convinience
   Print(); 
@@ -834,36 +845,8 @@ void AliEMCALDigitizer::WriteDigits()
 
 }
 
+//__________________________________________________________________
 void AliEMCALDigitizer::Browse(TBrowser* b)
 {
-  if(fHists) b->Add(fHists);
   TTask::Browse(b);
 }
-
-TList *AliEMCALDigitizer::BookControlHists(int var)
-{ 
-  // 22-nov-04
-  // histograms for monitoring digitizer performance
-
-  Info("BookControlHists"," started ");
-  gROOT->cd();
-  const AliEMCALGeometry *geom = AliEMCALGeometry::GetInstance();
-  if(var>=1){
-    new TH1F("hDigiN",  "#EMCAL digits with fAmp > fDigitThreshold", 
-    fNADCEC+1, -0.5, Double_t(fNADCEC));
-    new TH1F("HDigiSumEnergy","Sum.EMCAL energy from digi", 1000, 0.0, 200.);
-    new TH1F("hDigiAmp",  "EMCAL digital amplitude", fNADCEC+1, -0.5, Double_t(fNADCEC));
-    new TH1F("hDigiEnergy","EMCAL cell energy", 2000, 0.0, 200.);
-    new TH1F("hDigiAbsId","EMCAL absId cells with fAmp > fDigitThreshold ",
-    geom->GetNCells(), 0.5, Double_t(geom->GetNCells())+0.5);
-  }
-
-  fHists = AliEMCALHistoUtilities::MoveHistsToList("EmcalDigiControlHists", kFALSE);
-  fHists = 0; //huh? JLK 03-Mar-2006
-  return fHists;
-}
-
-void AliEMCALDigitizer::SaveHists(const char* name, Bool_t kSingleKey, const char* opt)
-{
-  AliEMCALHistoUtilities::SaveListOfHists(fHists, name, kSingleKey, opt); 
-}