]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PHOS/AliPHOSDigitizer.cxx
pyquen added.
[u/mrichter/AliRoot.git] / PHOS / AliPHOSDigitizer.cxx
index 1ae4977be96c2f1758001d97adbb8543543bda3c..1f96779d1c663ae4394a121122e7f20b9027bf94 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"
+#include "TRandom.h"
 
 // --- Standard library ---
 
 // --- AliRoot header files ---
-#include "AliRun.h"
-#include "AliHeader.h"
-#include "AliStream.h"
+
 #include "AliRunDigitizer.h"
 #include "AliPHOSDigit.h"
-#include "AliPHOS.h"
 #include "AliPHOSGetter.h"
 #include "AliPHOSDigitizer.h"
 #include "AliPHOSSDigitizer.h"
@@ -97,12 +90,13 @@ ClassImp(AliPHOSDigitizer)
 }
 
 //____________________________________________________________________________ 
-AliPHOSDigitizer::AliPHOSDigitizer(const TString alirunFileName, const TString eventFolderName):
-  AliDigitizer("PHOS"+AliConfig::fgkDigitizerTaskName, alirunFileName),
+AliPHOSDigitizer::AliPHOSDigitizer(TString alirunFileName, 
+                                  TString eventFolderName):
+  AliDigitizer("PHOS"+AliConfig::Instance()->GetDigitizerTaskName(), 
+              alirunFileName), 
   fInputFileNames(0), fEventNames(0), fEventFolderName(eventFolderName)
 {
   // ctor
-
   InitParameters() ; 
   Init() ;
   fDefaultInit = kFALSE ; 
@@ -111,6 +105,7 @@ AliPHOSDigitizer::AliPHOSDigitizer(const TString alirunFileName, const TString e
 
 //____________________________________________________________________________ 
 AliPHOSDigitizer::AliPHOSDigitizer(const AliPHOSDigitizer & d)
+  : AliDigitizer(d)
 {
   // copyy ctor 
 
@@ -134,16 +129,14 @@ AliPHOSDigitizer::AliPHOSDigitizer(const AliPHOSDigitizer & d)
 
 //____________________________________________________________________________ 
 AliPHOSDigitizer::AliPHOSDigitizer(AliRunDigitizer * rd):
- AliDigitizer(rd,"PHOS"+AliConfig::fgkDigitizerTaskName),
+ AliDigitizer(rd,"PHOS"+AliConfig::Instance()->GetDigitizerTaskName()),
  fEventFolderName(0)
 {
-  // ctor
+  // ctor Init() is called by RunDigitizer
   fManager = rd ; 
-  SetName(fManager->GetInputFolderName(0)) ;
-  // take title as name of stream 0
+  fEventFolderName = fManager->GetInputFolderName(0) ;
   SetTitle(dynamic_cast<AliStream*>(fManager->GetInputStream(0))->GetFileName(0));
   InitParameters() ; 
-  Init() ; 
   fDefaultInit = kFALSE ; 
 }
 
@@ -151,23 +144,30 @@ AliPHOSDigitizer::AliPHOSDigitizer(AliRunDigitizer * rd):
   AliPHOSDigitizer::~AliPHOSDigitizer()
 {
   // dtor
+  AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle(),fEventFolderName);
+  gime->PhosLoader()->CleanDigitizer();
   delete [] fInputFileNames ; 
   delete [] fEventNames ; 
  
 }
 
 //____________________________________________________________________________
-void AliPHOSDigitizer::Digitize(const Int_t event) 
+void AliPHOSDigitizer::Digitize(Int_t event) 
 { 
   
   // Makes the digitization of the collected summable digits.
   //  It first creates the array of all PHOS modules
-  //  filled with noise (different for EMC, CPV and PPSD) and
+  //  filled with noise (different for EMC, and CPV) and
   //  then adds contributions from SDigits. 
   // This design avoids scanning over the list of digits to add 
   // contribution to new SDigits only.
 
   AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName) ; 
+  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() ;
 
@@ -188,7 +188,7 @@ void AliPHOSDigitizer::Digitize(const Int_t event)
   AliPHOSSDigitizer * sDigitizer = gime->SDigitizer(); 
 
   if ( !sDigitizer )
-    Fatal("Digitize", "SDigitizer with name %s %s not found", fEventFolderName.Data(), GetTitle() ) ; 
+    Fatal("Digitize", "SDigitizer with name %s %s not found", GetTitle(), fEventFolderName.Data() ) ; 
 
   //take all the inputs to add together and load the SDigits
   TObjArray * sdigArray = new TObjArray(fInput) ;
@@ -197,8 +197,11 @@ void AliPHOSDigitizer::Digitize(const Int_t event)
   for(i = 1 ; i < fInput ; i++){
     TString tempo(fEventNames[i]) ; 
     tempo += i ;
-    AliPHOSGetter * gime = AliPHOSGetter::Instance(fInputFileNames[i], tempo) ; 
-    gime->Event(event,"S");
+    AliPHOSGetter * gime = AliPHOSGetter::Instance(fInputFileNames[i], tempo) ;
+    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) ;
   }
 
@@ -291,7 +294,6 @@ void AliPHOSDigitizer::Digitize(const Int_t event)
   ticks->Delete() ;
   delete ticks ;
   
-  
   //Now CPV digits (different noise and no timing)
   for(absID = nEMC+1; absID <= nCPV; absID++){
     Float_t noise = gRandom->Gaus(0., fCPVNoise) ; 
@@ -389,7 +391,11 @@ Int_t AliPHOSDigitizer::DigitizeEnergy(Float_t energy, Int_t absId)
 //____________________________________________________________________________
 void AliPHOSDigitizer::Exec(Option_t *option) 
 { 
-  // Does the job
+  // 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() ) ;
@@ -404,22 +410,24 @@ void AliPHOSDigitizer::Exec(Option_t *option)
   if(strstr(option,"tim"))
     gBenchmark->Start("PHOSDigitizer");
   
-  if (fManager) 
-    fInput = fManager->GetNinputs() ;
-  
-  AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
+  AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle()) ;
 
-  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
 
-    WriteDigits(ievent) ;
+    WriteDigits() ;
 
     if(strstr(option,"deb"))
       PrintDigits(option);
@@ -434,7 +442,7 @@ void AliPHOSDigitizer::Exec(Option_t *option)
     message = "  took %f seconds for Digitizing %f seconds per event\n" ; 
     Info("Exec", message.Data(), 
         gBenchmark->GetCpuTime("PHOSDigitizer"), 
-        gBenchmark->GetCpuTime("PHOSDigitizer")/nevents ); 
+        gBenchmark->GetCpuTime("PHOSDigitizer")/nEvents ); 
   } 
 }
 
@@ -484,6 +492,8 @@ Bool_t AliPHOSDigitizer::Init()
   // Post Digitizer to the white board
   gime->PostDigitizer(this) ;
   
+  fFirstEvent = 0 ; 
+  fLastEvent = fFirstEvent ; 
   if (fManager) 
     fInput = fManager->GetNinputs() ; 
   else 
@@ -497,7 +507,7 @@ Bool_t AliPHOSDigitizer::Init()
   for (index = 1 ; index < fInput ; index++) {
     fInputFileNames[index] = dynamic_cast<AliStream*>(fManager->GetInputStream(index))->GetFileName(0); 
     TString tempo = fManager->GetInputFolderName(index) ;
-    fEventNames[index] = tempo.Remove(tempo.Length()-1) ; // strip of the stream number added bt fManager 
+    fEventNames[index] = tempo.Remove(tempo.Length()-1) ; // strip of the stream number added by fManager
   }
 
   //to prevent cleaning of this object while GetEvent is called
@@ -509,7 +519,7 @@ Bool_t AliPHOSDigitizer::Init()
 //____________________________________________________________________________ 
 void AliPHOSDigitizer::InitParameters()
 {
-  // Set initial parameters for Digitizer
+  // Set initial parameters Digitizer
 
   fPinNoise           = 0.004 ;
   fEMCDigitThreshold  = 0.012 ;
@@ -527,11 +537,12 @@ void AliPHOSDigitizer::InitParameters()
   fNADCcpv = (Int_t) TMath::Power(2,12);      // number of channels in CPV ADC
 
   fTimeThreshold = 0.001*10000000 ; //Means 1 MeV in terms of SDigits amplitude
+  SetEventRange(0,-1) ;
     
 }
 
 //__________________________________________________________________
-void AliPHOSDigitizer::MixWith(const TString alirunFileName, const TString eventFolderName)
+void AliPHOSDigitizer::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 
@@ -560,7 +571,7 @@ void AliPHOSDigitizer::MixWith(const TString alirunFileName, const TString event
   // looking for the file which contains SDigits
   AliPHOSGetter * gime = AliPHOSGetter::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()) ;
@@ -602,7 +613,7 @@ void AliPHOSDigitizer::Print()const
       tempo += index ;
       AliPHOSGetter * gime = AliPHOSGetter::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()) ; 
     }
@@ -646,12 +657,13 @@ void AliPHOSDigitizer::Print()const
       digit = (AliPHOSDigit * )  digits->At(index) ;
       if(digit->GetNprimary() == 0) 
        continue;
-      printf("\n%6d  %8d    %6.5e %4d      %2d :",
+      printf("%6d  %8d    %6.5e %4d      %2d :",
              digit->GetId(), digit->GetAmp(), digit->GetTime(), digit->GetIndexInList(), digit->GetNprimary()) ;  
       Int_t iprimary;
       for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
        printf("%d ",digit->GetPrimary(iprimary+1) ) ; 
       }    
+      printf("\n") ;
     }
   }
   
@@ -666,12 +678,13 @@ void AliPHOSDigitizer::Print()const
     for (index = 0 ; index < digits->GetEntriesFast(); index++) {
       digit = (AliPHOSDigit * )  digits->At(index) ;
       if(digit->GetId() > maxEmc){
-       printf("\n%6d  %8d    %4d      %2d :",
+       printf("%6d  %8d    %4d      %2d :",
                digit->GetId(), digit->GetAmp(), digit->GetIndexInList(), digit->GetNprimary()) ;  
        Int_t iprimary;
        for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) {
          printf("%d ",digit->GetPrimary(iprimary+1) ) ; 
        }    
+       printf("\n") ;
       }
     }
   }
@@ -703,7 +716,7 @@ void AliPHOSDigitizer::Unload()
 }
 
 //____________________________________________________________________________
-void AliPHOSDigitizer::WriteDigits(Int_t event)
+void AliPHOSDigitizer::WriteDigits()
 {
 
   // Makes TreeD in the output file.