]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - EMCAL/AliEMCALDigitizer.cxx
Changes needed to run simulation and reconstrruction in the same AliRoot session
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALDigitizer.cxx
index ef3a2bf8ccad7875df440e06acbd81fd68a55675..ac37421e64a44b9b0e08d84cf9a6235dbaaa5e19 100644 (file)
 ///_________________________________________________________________________________
 
 // --- ROOT system ---
-#include "TFile.h"
 #include "TTree.h"
 #include "TSystem.h"
-#include "TROOT.h"
-#include "TFolder.h"
-#include "TObjString.h"
-#include "TGeometry.h"
 #include "TBenchmark.h"
 
 // --- Standard library ---
 
 // --- AliRoot header files ---
-#include "AliRun.h"
-#include "AliHeader.h"
-#include "AliStream.h"
 #include "AliRunDigitizer.h"
 #include "AliEMCALDigit.h"
 #include "AliEMCAL.h"
@@ -99,8 +91,8 @@ ClassImp(AliEMCALDigitizer)
 }
 
 //____________________________________________________________________________ 
-AliEMCALDigitizer::AliEMCALDigitizer(const TString alirunFileName, const TString eventFolderName):
-  AliDigitizer("EMCAL"+AliConfig::fgkDigitizerTaskName, alirunFileName),
+AliEMCALDigitizer::AliEMCALDigitizer(TString alirunFileName, TString eventFolderName):
+  AliDigitizer("EMCAL"+AliConfig::Instance()->GetDigitizerTaskName(), alirunFileName),
   fInputFileNames(0), fEventNames(0), fEventFolderName(eventFolderName)
 {
   // ctor
@@ -134,31 +126,32 @@ AliEMCALDigitizer::AliEMCALDigitizer(const AliEMCALDigitizer & d) : AliDigitizer
 
 //____________________________________________________________________________ 
 AliEMCALDigitizer::AliEMCALDigitizer(AliRunDigitizer * rd):
- AliDigitizer(rd,"EMCAL"+AliConfig::fgkDigitizerTaskName),
+ AliDigitizer(rd,"EMCAL"+AliConfig::Instance()->GetDigitizerTaskName()),
  fEventFolderName(0)
 {
-  // ctor
+  // ctor Init() is called by RunDigitizer
   fManager = rd ; 
   fEventFolderName = fManager->GetInputFolderName(0) ;
   SetTitle(dynamic_cast<AliStream*>(fManager->GetInputStream(0))->GetFileName(0));
   InitParameters() ; 
-  Init() ; 
   fDefaultInit = kFALSE ; 
 }
 
 //____________________________________________________________________________ 
   AliEMCALDigitizer::~AliEMCALDigitizer()
 {
-  // dtor
-  AliEMCALGetter * gime =AliEMCALGetter::Instance(GetTitle(),fEventFolderName);
-  gime->EmcalLoader()->CleanDigitizer();
+  AliEMCALGetter * gime = AliEMCALGetter::Instance(GetTitle()) ;
+   
+  // Clean Digitizer from the white board
+  gime->EmcalLoader()->CleanDigitizer() ;
+
   delete [] fInputFileNames ; 
   delete [] fEventNames ; 
 
 }
 
 //____________________________________________________________________________
-void AliEMCALDigitizer::Digitize(const Int_t event) 
+void AliEMCALDigitizer::Digitize(Int_t event) 
 { 
 
   // Makes the digitization of the collected summable digits
@@ -168,15 +161,18 @@ void AliEMCALDigitizer::Digitize(const Int_t event)
   // helps to avoid scanning over the list of digits to add 
   // contribution of any new SDigit.
 
-  AliEMCALGetter * gime = AliEMCALGetter::Instance(GetTitle(), fEventFolderName) ; 
+  AliEMCALGetter * gime = AliEMCALGetter::Instance(GetTitle()) ; 
+  Int_t ReadEvent = event ; 
+  if (fManager) 
+    ReadEvent = dynamic_cast<AliStream*>(fManager->GetInputStream(0))->GetCurrentEventNumber() ; 
+  Info("Digitize", "Adding event %d from input stream 0 %s %s", ReadEvent, GetTitle(), fEventFolderName.Data()) ; 
+  gime->Event(ReadEvent, "S") ;
   TClonesArray * digits = gime->Digits() ; 
   digits->Clear() ;
 
   const AliEMCALGeometry *geom = gime->EMCALGeometry() ; 
 
-  //Making digits from noise first
-  Int_t nEMC = 0 ;
-  nEMC = geom->GetNPhi()*geom->GetNZ(); //max number of digits possible
+  Int_t nEMC = geom->GetNPhi()*geom->GetNZ(); //max number of digits possible
   
   Int_t absID ;
 
@@ -198,7 +194,10 @@ void AliEMCALDigitizer::Digitize(const Int_t event)
     TString tempo(fEventNames[i]) ; 
     tempo += i ;
     AliEMCALGetter * gime = AliEMCALGetter::Instance(fInputFileNames[i], tempo) ; 
-    gime->Event(event,"S");
+    if (fManager) 
+      ReadEvent = dynamic_cast<AliStream*>(fManager->GetInputStream(i))->GetCurrentEventNumber() ; 
+    Info("Digitize", "Adding event %d from input stream %d %s %s", ReadEvent, i, fInputFileNames[i].Data(), tempo.Data()) ; 
+    gime->Event(ReadEvent,"S");
     sdigArray->AddAt(gime->SDigits(), i) ;
   }
   
@@ -331,14 +330,18 @@ Int_t AliEMCALDigitizer::DigitizeEnergy(Float_t energy)
   Int_t channel = -999; 
   channel = static_cast<Int_t> (TMath::Ceil( (energy + fADCpedestalEC)/fADCchannelEC ))  ;
   if(channel > fNADCEC ) 
-    channel =  fNADCEC ;   
+    channel =  fNADCEC ; 
   return channel ;
 }
 
 //____________________________________________________________________________
 void AliEMCALDigitizer::Exec(Option_t *option) 
 { 
-  // Managing method
+  // Steering method to process digitization for events
+  // in the range from fFirstEvent to fLastEvent.
+  // This range is optionally set by SetEventRange().
+  // if fLastEvent=-1, then process events until the end.
+  // by default fLastEvent = fFirstEvent (process only one event)
 
   if (!fInit) { // to prevent overwrite existing file
     Error( "Exec", "Give a version name different from %s", fEventFolderName.Data() ) ;
@@ -352,18 +355,23 @@ void AliEMCALDigitizer::Exec(Option_t *option)
   
   if(strstr(option,"tim"))
     gBenchmark->Start("EMCALDigitizer");
-
-  if (fManager) 
-    fInput = fManager->GetNinputs() ;
   
-  AliEMCALGetter * gime = AliEMCALGetter::Instance() ;
+  AliEMCALGetter * gime = AliEMCALGetter::Instance(GetTitle()) ;
+   
+  // Post Digitizer to the white board
+  gime->PostDigitizer(this) ;
   
-  Int_t nevents = gime->MaxEvent() ;;
+  if (fLastEvent == -1) 
+    fLastEvent = gime->MaxEvent() - 1 ;
+  else if (fManager) 
+    fLastEvent = fFirstEvent ; 
+
+  Int_t nEvents   = fLastEvent - fFirstEvent + 1;
   
   Int_t ievent ;
 
-  for(ievent = 0; ievent < nevents; ievent++){
-    
+  for (ievent = fFirstEvent; ievent <= fLastEvent; ievent++) {
+  
     gime->Event(ievent,"S") ; 
 
     Digitize(ievent) ; //Add prepared SDigits to digits and add the noise
@@ -377,10 +385,12 @@ void AliEMCALDigitizer::Exec(Option_t *option)
     fDigitsInRun += gime->Digits()->GetEntriesFast() ;  
   }
   
+  gime->EmcalLoader()->CleanDigitizer() ;
+
   if(strstr(option,"tim")){
     gBenchmark->Stop("EMCALDigitizer");
     printf("Exec: took %f seconds for Digitizing %f seconds per event", 
-        gBenchmark->GetCpuTime("EMCALDigitizer"), gBenchmark->GetCpuTime("EMCALDigitizer")/nevents ) ;
+        gBenchmark->GetCpuTime("EMCALDigitizer"), gBenchmark->GetCpuTime("EMCALDigitizer")/nEvents ) ;
   } 
 }
 
@@ -416,16 +426,15 @@ Bool_t AliEMCALDigitizer::Init()
     Error("Init", "Could not obtain the Getter object for file %s and event %s !", GetTitle(), fEventFolderName.Data()) ;   
     return kFALSE;
   } 
-  
   TString opt("Digits") ; 
   if(gime->VersionExists(opt) ) { 
     Error( "Init", "Give a version name different from %s", fEventFolderName.Data() ) ;
     fInit = kFALSE ; 
   }
 
-  // Post Digitizer to the white board
-  gime->PostDigitizer(this) ;
+  fFirstEvent = 0 ; 
+  fLastEvent = fFirstEvent ; 
+  
   if(fManager)
     fInput = fManager->GetNinputs() ; 
   else 
@@ -451,15 +460,15 @@ Bool_t AliEMCALDigitizer::Init()
 //____________________________________________________________________________ 
 void AliEMCALDigitizer::InitParameters()
 {
-  fMeanPhotonElectron = 1250 ; // electrons per GeV
-  fPinNoise           = 0.001 ; // noise equivalent GeV (random choice)
+  fMeanPhotonElectron = 18200 ; // electrons per GeV
+  fPinNoise           = 0.003 ; // noise equivalent GeV (random choice)
   if (fPinNoise == 0. ) 
     Warning("InitParameters", "No noise added\n") ; 
   fDigitThreshold     = fPinNoise * 3; //2 sigma
-  fTimeResolution     = 0.5e-9 ;
+  fTimeResolution     = 1.0e-9 ;
   fTimeSignalLength   = 1.0e-9 ;
 
-  fADCchannelEC    = 0.000220;                     // width of one ADC channel in GeV
+  fADCchannelEC    = 0.00305;                     // width of one ADC channel in GeV - HG fix so that we see 200 GeV gammas
   fADCpedestalEC   = 0.005 ;                       // GeV
   fNADCEC          = (Int_t) TMath::Power(2,16) ;  // number of channels in Tower ADC
 
@@ -468,7 +477,7 @@ void AliEMCALDigitizer::InitParameters()
 }
 
 //__________________________________________________________________
-void AliEMCALDigitizer::MixWith(const TString alirunFileName, const TString eventFolderName)
+void AliEMCALDigitizer::MixWith(TString alirunFileName, TString eventFolderName)
 {
   // Allows to produce digits by superimposing background and signal event.
   // It is assumed, that headers file with SIGNAL events is opened in 
@@ -497,7 +506,7 @@ void AliEMCALDigitizer::MixWith(const TString alirunFileName, const TString even
   // looking for the file which contains SDigits
   AliEMCALGetter * gime = AliEMCALGetter::Instance() ; 
   TString fileName( gime->GetSDigitsFileName() ) ; 
-    if ( eventFolderName != AliConfig::fgkDefaultEventFolderName) // only if not the default folder name 
+    if ( eventFolderName != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name 
       fileName = fileName.ReplaceAll(".root", "") + "_" + eventFolderName + ".root" ;
     if ( (gSystem->AccessPathName(fileName)) ) { 
       Error("MixWith", "The file %s does not exist!", fileName.Data()) ;
@@ -539,7 +548,7 @@ void AliEMCALDigitizer::Print()const
       tempo += index ;
       AliEMCALGetter * gime = AliEMCALGetter::Instance(fInputFileNames[index], tempo) ; 
       TString fileName( gime->GetSDigitsFileName() ) ; 
-      if ( fEventNames[index] != AliConfig::fgkDefaultEventFolderName) // only if not the default folder name 
+      if ( fEventNames[index] != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name 
        fileName = fileName.ReplaceAll(".root", "") + "_" + fEventNames[index]  + ".root" ;
       printf ("Adding SDigits from %s %s\n", fInputFileNames[index].Data(), fileName.Data()) ; 
     }
@@ -586,10 +595,10 @@ void AliEMCALDigitizer::PrintDigits(Option_t * option){
 
 //__________________________________________________________________
 Float_t AliEMCALDigitizer::TimeOfNoise(void)
-{  // Calculates the time signal generated by noise
-  //to be rewritten, now returns just big number
-  return 1. ;
-
+{  
+  // Calculates the time signal generated by noise
+  //PH  Info("TimeOfNoise", "Change me") ; 
+  return gRandom->Rndm() * 1.28E-5;
 }
 
 //__________________________________________________________________
@@ -620,13 +629,13 @@ void AliEMCALDigitizer::WriteDigits()
   //      and branch "AliEMCALDigitizer", with the same title to keep all the parameters
   //      and names of files, from which digits are made.
 
-  AliEMCALGetter * gime = AliEMCALGetter::Instance(GetTitle(), fEventFolderName) ; 
+  AliEMCALGetter * gime = AliEMCALGetter::Instance(GetTitle()) ; 
   const TClonesArray * digits = gime->Digits() ; 
   TTree * treeD = gime->TreeD(); 
 
   // -- create Digits branch
   Int_t bufferSize = 32000 ;    
-  TBranch * digitsBranch = treeD->Branch("EMCAL",&digits,bufferSize);
+  TBranch * digitsBranch = treeD->Branch("EMCAL","TClonesArray",&digits,bufferSize);
   digitsBranch->SetTitle(fEventFolderName);
   digitsBranch->Fill() ;