]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PHOS/AliPHOSDigitizer.cxx
New PHOS raw stream class based on a new AliAltroRawStream class. As soon as the...
[u/mrichter/AliRoot.git] / PHOS / AliPHOSDigitizer.cxx
index 1ae4977be96c2f1758001d97adbb8543543bda3c..a1899f586a31025ca25980cd4182fd4c416890e5 100644 (file)
 
 /* $Id$ */
 
+/* History of cvs commits:
+ *
+ * $Log$
+ * Revision 1.87  2005/08/24 15:33:49  kharlov
+ * Calibration data for raw digits
+ *
+ * Revision 1.86  2005/07/12 20:07:35  hristov
+ * Changes needed to run simulation and reconstrruction in the same AliRoot session
+ *
+ * Revision 1.85  2005/05/28 14:19:04  schutz
+ * Compilation warnings fixed by T.P.
+ *
+ */
 
 //_________________________________________________________________________
 //*-- Author :  Dmitri Peressounko (SUBATECH & Kurchatov Institute) 
 //
 
 // --- 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 "AliLog.h"
 #include "AliRunDigitizer.h"
 #include "AliPHOSDigit.h"
-#include "AliPHOS.h"
 #include "AliPHOSGetter.h"
 #include "AliPHOSDigitizer.h"
 #include "AliPHOSSDigitizer.h"
@@ -97,12 +103,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 +118,7 @@ AliPHOSDigitizer::AliPHOSDigitizer(const TString alirunFileName, const TString e
 
 //____________________________________________________________________________ 
 AliPHOSDigitizer::AliPHOSDigitizer(const AliPHOSDigitizer & d)
+  : AliDigitizer(d)
 {
   // copyy ctor 
 
@@ -134,22 +142,24 @@ 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 ; 
 }
 
 //____________________________________________________________________________ 
   AliPHOSDigitizer::~AliPHOSDigitizer()
 {
+  AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle()) ;
+
+  // Clean Digitizer from the white board
+  gime->PhosLoader()->CleanDigitizer() ;
   // dtor
   delete [] fInputFileNames ; 
   delete [] fEventNames ; 
@@ -157,17 +167,23 @@ AliPHOSDigitizer::AliPHOSDigitizer(AliRunDigitizer * rd):
 }
 
 //____________________________________________________________________________
-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) ; 
+  AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle()) ; 
+  Int_t ReadEvent = event ; 
+  if (fManager) 
+    ReadEvent = dynamic_cast<AliStream*>(fManager->GetInputStream(0))->GetCurrentEventNumber() ; 
+  AliInfo(Form("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 +204,8 @@ 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() ) ; 
+    AliFatal(Form("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 +214,12 @@ 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() ; 
+    AliInfo(Form("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 +312,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) ; 
@@ -374,12 +394,43 @@ Int_t AliPHOSDigitizer::DigitizeEnergy(Float_t energy, Int_t absId)
 {
   // Returns digitized value of the energy in a cell absId
 
+  AliPHOSGetter* gime = AliPHOSGetter::Instance();
+
+  if(!gime->CalibData()) {
+    AliPHOSCalibData* cdb = new AliPHOSCalibData(gAlice->GetRunNumber());
+    gime->SetCalibData(cdb);
+  }
+
+  //Determine rel.position of the cell absId
+  Int_t relId[4];
+  gime->PHOSGeometry()->AbsToRelNumbering(absId,relId);
+  Int_t module=relId[0];
+  Int_t raw=relId[2];
+  Int_t column=relId[3];
+  
   Int_t chanel ;
+  
   if(absId <= fEmcCrystals){ //digitize as EMC 
+
+    //reading calibration data for cell absId.
+    //If no calibration DB found, accept default values.
+
+    if(gime->CalibData()) {
+      fADCpedestalEmc = gime->CalibData()->GetADCpedestalEmc(module,column,raw);
+      fADCchanelEmc = gime->CalibData()->GetADCchannelEmc(module,column,raw);
+    }
+//         printf("\t\tabsId %d ==>>module=%d column=%d raw=%d ped=%.4f gain=%.4f\n",
+//                absId,module,column,raw,fADCpedestalEmc,fADCchanelEmc);
+
     chanel = (Int_t) TMath::Ceil((energy - fADCpedestalEmc)/fADCchanelEmc) ;       
     if(chanel > fNADCemc ) chanel =  fNADCemc ;
   }
   else{ //Digitize as CPV
+    if(gime->CalibData()) {
+      fADCpedestalCpv = gime->CalibData()->GetADCpedestalCpv(module,column,raw);
+      fADCchanelCpv = gime->CalibData()->GetADCchannelCpv(module,column,raw);
+    }
+
     chanel = (Int_t) TMath::Ceil((energy - fADCpedestalCpv)/fADCchanelCpv) ;       
     if(chanel > fNADCcpv ) chanel =  fNADCcpv ;
   }
@@ -389,10 +440,15 @@ 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() ) ;
+    AliError(Form("Give a version name different from %s", 
+                 fEventFolderName.Data() )) ;
     return ;
   }   
 
@@ -404,22 +460,27 @@ 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() ;
-    
+  // Post Digitizer to the white board
+  gime->PostDigitizer(this) ;
+  
+  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);
@@ -428,13 +489,15 @@ void AliPHOSDigitizer::Exec(Option_t *option)
     fDigitsInRun += gime->Digits()->GetEntriesFast() ;  
  }
   
+  gime->PhosLoader()->CleanDigitizer();
+
   if(strstr(option,"tim")){
     gBenchmark->Stop("PHOSDigitizer");
     TString message ; 
     message = "  took %f seconds for Digitizing %f seconds per event\n" ; 
-    Info("Exec", message.Data(), 
+    AliInfo(Form( message.Data(), 
         gBenchmark->GetCpuTime("PHOSDigitizer"), 
-        gBenchmark->GetCpuTime("PHOSDigitizer")/nevents ); 
+        gBenchmark->GetCpuTime("PHOSDigitizer")/nEvents )); 
   } 
 }
 
@@ -467,7 +530,8 @@ Bool_t AliPHOSDigitizer::Init()
   fInit = kTRUE ; 
   AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName) ; 
   if ( gime == 0 ) {
-    Fatal("Init" ,"Could not obtain the Getter object for file %s and event %s !", GetTitle(), fEventFolderName.Data()) ;  
+    AliFatal(Form("Could not obtain the Getter object for file %s and event %s !", 
+                 GetTitle(), fEventFolderName.Data()));  
     return kFALSE;
   } 
   
@@ -477,13 +541,13 @@ Bool_t AliPHOSDigitizer::Init()
   
   TString opt("Digits") ; 
   if(gime->VersionExists(opt) ) { 
-    Error( "Init", "Give a version name different from %s", fEventFolderName.Data() ) ;
+    AliError(Form("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 
@@ -497,7 +561,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 +573,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 +591,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 
@@ -554,16 +619,16 @@ void AliPHOSDigitizer::MixWith(const TString alirunFileName, const TString event
   }
   // looking for file which contains AliRun
   if (gSystem->AccessPathName(alirunFileName)) {// file does not exist
-    Error("MixWith", "File %s does not exist!", alirunFileName.Data()) ;
+    AliError(Form("File %s does not exist!", alirunFileName.Data())) ;
     return ; 
   }
   // 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()) ;
+      AliError(Form("The file %s does not exist!", fileName.Data())) ;
       return ;
     }
     // need to increase the arrays
@@ -583,10 +648,10 @@ void AliPHOSDigitizer::MixWith(const TString alirunFileName, const TString event
 }
 
 //__________________________________________________________________
-void AliPHOSDigitizer::Print()const 
+void AliPHOSDigitizer::Print(const Option_t *)const 
 {
   // Print Digitizer's parameters
-  Info("Print", "\n------------------- %s -------------", GetName() ) ; 
+  AliInfo(Form("\n------------------- %s -------------", GetName() )) ; 
   if( strcmp(fEventFolderName.Data(), "") != 0 ){
     printf(" Writing Digits to branch with title  %s\n", fEventFolderName.Data()) ;
     
@@ -602,7 +667,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()) ; 
     }
@@ -617,7 +682,7 @@ void AliPHOSDigitizer::Print()const
     printf(" ---------------------------------------------------\n") ;   
   }
   else
-    Info("Print", "AliPHOSDigitizer not initialized" ) ;
+    AliInfo(Form("AliPHOSDigitizer not initialized" )) ;
   
 }
 
@@ -629,7 +694,7 @@ void AliPHOSDigitizer::Print()const
   AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName) ; 
   TClonesArray * digits = gime->Digits() ; 
   
-  Info("PrintDigits", "%d", digits->GetEntriesFast()) ; 
+  AliInfo(Form("%d", digits->GetEntriesFast())) ; 
   printf("\nevent %d", gAlice->GetEvNumber()) ;
   printf("\n       Number of entries in Digits list %d", digits->GetEntriesFast() )  ;  
 
@@ -646,12 +711,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 +732,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") ;
       }
     }
   }
@@ -681,9 +748,8 @@ void AliPHOSDigitizer::Print()const
 //__________________________________________________________________
 Float_t AliPHOSDigitizer::TimeOfNoise(void) const
 {  // Calculates the time signal generated by noise
-  //to be rewritten, now returns just big number
-  return 1. ;
-
+  //PH  Info("TimeOfNoise", "Change me") ; 
+  return gRandom->Rndm() * 1.28E-5;
 }
 
 //__________________________________________________________________
@@ -703,7 +769,7 @@ void AliPHOSDigitizer::Unload()
 }
 
 //____________________________________________________________________________
-void AliPHOSDigitizer::WriteDigits(Int_t event)
+void AliPHOSDigitizer::WriteDigits()
 {
 
   // Makes TreeD in the output file. 
@@ -714,13 +780,13 @@ void AliPHOSDigitizer::WriteDigits(Int_t event)
   //      and branch "AliPHOSDigitizer", with the same title to keep all the parameters
   //      and names of files, from which digits are made.
 
-  AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName) ; 
+  AliPHOSGetter * gime = AliPHOSGetter::Instance(GetTitle()) ; 
   const TClonesArray * digits = gime->Digits() ; 
   TTree * treeD = gime->TreeD();
 
   // -- create Digits branch
   Int_t bufferSize = 32000 ;    
-  TBranch * digitsBranch = treeD->Branch("PHOS",&digits,bufferSize);
+  TBranch * digitsBranch = treeD->Branch("PHOS","TClonesArray",&digits,bufferSize);
   digitsBranch->SetTitle(fEventFolderName);
   digitsBranch->Fill() ;