]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TOF/AliTOFDigitizer.cxx
Taking into account that only 1 or 2 values may be present for the
[u/mrichter/AliRoot.git] / TOF / AliTOFDigitizer.cxx
index 6701cb1fa454887ae90e98479c1934eb5aa132ab..fb7bc8a04644679b5b87ec5d1f2f279fe10a707d 100644 (file)
 //                                                                         //
 //_________________________________________________________________________//
 
-#include "Riostream.h"
+//#include "Riostream.h"
 
-#include "TFile.h"
+//#include "TFile.h"
 #include "TH1F.h"
 #include "TTree.h"
 #include "TRandom.h"
+#include "TObjArray.h"
 
 #include "AliLoader.h"
 #include "AliLog.h"
 #include "AliRunLoader.h"
 #include "AliRun.h"
 
-#include "AliTOFCal.h"
 #include "AliTOFcalib.h"
-#include "AliTOFChannel.h"
+//#include "AliTOFChannelOnline.h"
+#include "AliTOFChannelOffline.h"
 #include "AliTOFDigitizer.h"
 #include "AliTOFdigit.h"
 #include "AliTOFHitMap.h"
-#include "AliTOFGeometryV5.h"
+#include "AliTOFGeometry.h"
 #include "AliTOFSDigit.h"
 #include "AliTOF.h"
 
 extern TDirectory *gDirectory;
-extern TFile *gFile;
+//extern TFile *gFile;
 extern TRandom *gRandom;
 
 extern AliRun *gAlice;
@@ -60,49 +61,51 @@ ClassImp(AliTOFDigitizer)
 //___________________________________________
   AliTOFDigitizer::AliTOFDigitizer()  :
     AliDigitizer(),
-    fGeom(0x0),
-    fDigits(0x0),
-    fSDigitsArray(0x0),
-    fhitMap(0x0)
+    fDigits(new TClonesArray("AliTOFdigit",4000)),
+    fSDigitsArray(new TClonesArray("AliTOFSDigit",1000)),
+  fhitMap(0x0),
+  fCalib(new AliTOFcalib())
 {
   // Default ctor - don't use it
+  InitDecalibration();
 }
 
 //___________________________________________
 AliTOFDigitizer::AliTOFDigitizer(AliRunDigitizer* manager): 
   AliDigitizer(manager), 
-  fGeom(0x0),
-  fDigits(0x0),
-  fSDigitsArray(0x0),
-  fhitMap(0x0)
+  fDigits(new TClonesArray("AliTOFdigit",4000)),
+  fSDigitsArray(new TClonesArray("AliTOFSDigit",1000)),
+  fhitMap(0x0),
+  fCalib(new AliTOFcalib())
 {
   //ctor with RunDigitizer
+  InitDecalibration();
 }
 
 //------------------------------------------------------------------------
 AliTOFDigitizer::AliTOFDigitizer(const AliTOFDigitizer &source):
   AliDigitizer(source),
-  fGeom(0x0), 
-  fDigits(0),
-  fSDigitsArray(0),
-  fhitMap(0)
+  fDigits(source.fDigits),
+  fSDigitsArray(source.fSDigitsArray),
+  fhitMap(source.fhitMap),
+  fCalib(source.fCalib)
 {
   // copy constructor
-  this->fDigits=source.fDigits;
-  this->fSDigitsArray=source.fSDigitsArray;
-  this->fhitMap=source.fhitMap;
-  this->fGeom=source.fGeom; 
-
 }
 
 //------------------------------------------------------------------------
   AliTOFDigitizer& AliTOFDigitizer::operator=(const AliTOFDigitizer &source)
 {
   // ass. op.
-  this->fDigits=source.fDigits;
-  this->fSDigitsArray=source.fSDigitsArray;
-  this->fhitMap=source.fhitMap;
-  this->fGeom=source.fGeom; 
+  
+  if (this == &source)
+    return *this;
+
+  AliDigitizer::operator=(source);
+  fDigits=source.fDigits;
+  fSDigitsArray=source.fSDigitsArray;
+  fhitMap=source.fhitMap;
+  fCalib=source.fCalib;
   return *this;
 
 }
@@ -111,6 +114,17 @@ AliTOFDigitizer::AliTOFDigitizer(const AliTOFDigitizer &source):
 AliTOFDigitizer::~AliTOFDigitizer()
 {
   // Destructor
+  delete fCalib;
+  if (fDigits){
+    fDigits->Delete();
+    delete fDigits;
+    fDigits=0x0;
+  }
+  if (fSDigitsArray){
+    fSDigitsArray->Delete();
+    delete fSDigitsArray;
+    fSDigitsArray=0x0;
+  }
 }
 
 //---------------------------------------------------------------------
@@ -136,8 +150,6 @@ void AliTOFDigitizer::Exec(Option_t* /*option*/)
   //Make branches
   char branchname[20];
   sprintf (branchname, "%s", tof->GetName ());
-
-  fDigits=new TClonesArray("AliTOFdigit",4000);
  
   AliRunLoader* outrl = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
   if (outrl == 0x0)
@@ -146,21 +158,6 @@ void AliTOFDigitizer::Exec(Option_t* /*option*/)
      return;
    }
    
-  outrl->CdGAFile();
-  TFile *in=(TFile*)gFile;
-  TDirectory *savedir=gDirectory;
-
-  if (!in->IsOpen()) {
-    AliWarning("Geometry file is not open default  TOF geometry will be used");
-    fGeom = new AliTOFGeometryV5();
-  }
-  else {
-    in->cd();
-    fGeom = (AliTOFGeometry*)in->Get("TOFgeometry");
-  }
-
-  savedir->cd();
-
   AliLoader* outgime = outrl->GetLoader("TOFLoader");
   if (outgime == 0x0)
    {
@@ -178,10 +175,10 @@ void AliTOFDigitizer::Exec(Option_t* /*option*/)
   tof->MakeBranchInTree(treeD,branchname,&fDigits,4000);
 
   // container for all summed sdigits (to be created in Init())
-  fSDigitsArray=new TClonesArray("AliTOFSDigit",1000);
+  //fSDigitsArray=new TClonesArray("AliTOFSDigit",1000);
   
   // create hit map (to be created in Init())
-  fhitMap = new AliTOFHitMap(fSDigitsArray, fGeom);
+  fhitMap = new AliTOFHitMap(fSDigitsArray);
   
   // Loop over files to digitize
 
@@ -195,15 +192,17 @@ void AliTOFDigitizer::Exec(Option_t* /*option*/)
 
   // free used memory for Hit Map in current event
   delete fhitMap;
-  fSDigitsArray->Delete();
-  delete fSDigitsArray;
+  fSDigitsArray->Clear();
 
   treeD->Fill();
+
+  AliDebug(2,"----------------------------------------");
+  AliInfo(Form("%d digits have been created", fDigits->GetEntriesFast()));
+  AliDebug(2,"----------------------------------------");
+
   outgime->WriteDigits("OVERWRITE");
   outgime->UnloadDigits();
-  fDigits->Delete();
-  delete fDigits;
+  fDigits->Clear();
 
 }
 
@@ -247,16 +246,13 @@ void AliTOFDigitizer::CreateDigits()
     // in the while, I perform QA
     Bool_t isSDigitBad = (sector<0 || sector>17 || plate<0 || plate >4 || padz<0 || padz>1 || padx<0 || padx>47);
     
-    if (isSDigitBad) {
-      //AliFatal("strange sdigit found");
-      AliFatal(Form("strange sdigit found   %3i  %2i  %2i  %3i    %3i", sector, plate, padz, padx, strip));
-    }
+    if (isSDigitBad)
+      AliFatal(Form("strange sdigit found   %2d  %1d  %2d  %1d %2d", sector, plate, strip, padz, padx));
     //-------------------------------------------------------
     
     //------------------- Dump section ----------------------
-    if(k<ndump){
-      AliInfo(Form("%2i-th | Sector %2i | Plate %1i | Strip %2i | PadZ %1i | PadX %2i ", k, sector, plate, strip, padz, padx));
-      AliInfo(Form("%2i-th", k));
+    if (k<ndump) {
+      AliInfo(Form("%2d-th digit: Sector %2d | Plate %1d | Strip %2d | PadZ %1d | PadX %2d ", k, sector, plate, strip, padz, padx));
       AliInfo("----------------------------------------------------");
     }
     // ------------------------------------------------------
@@ -268,7 +264,9 @@ void AliTOFDigitizer::CreateDigits()
       
       Int_t tdc=tofsdigit->GetTdc(islot); digit[0]=tdc;
       Int_t adc=tofsdigit->GetAdc(islot); digit[1]=adc;
-      
+
+      //if (tdc>=8192) continue;//AdC
+
       tracknum[0]=tofsdigit->GetTrack(islot,0);
       tracknum[1]=tofsdigit->GetTrack(islot,1);
       tracknum[2]=tofsdigit->GetTrack(islot,2);
@@ -284,11 +282,8 @@ void AliTOFDigitizer::CreateDigits()
   } // end loop on sdigits - end digitizing all collected sdigits
 
   //Insert Decalibration 
-
-  AliTOFcalib * calib = new AliTOFcalib(fGeom);
-  InitDecalibration(calib);
-  DecalibrateTOFSignal(calib);
-  delete calib;
+  AliDebug(2,"in digitizer, create digits");
+  DecalibrateTOFSignal();
 }
 
 //---------------------------------------------------------------------
@@ -301,6 +296,10 @@ void AliTOFDigitizer::ReadSDigit(Int_t inputFile )
   // SDigits from different files are assumed to
   // be created with the same simulation parameters.
   
+  // creating the TClonesArray to store the digits
+  static TClonesArray sdigitsClonesArray("AliTOFSDigit",  1000); 
+  sdigitsClonesArray.Clear();
+
   // get the treeS from manager
   AliRunLoader* rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(inputFile));
   if (rl == 0x0)
@@ -333,8 +332,7 @@ void AliTOFDigitizer::ReadSDigit(Int_t inputFile )
       }
    } 
   // get the branch TOF inside the treeS
-  TClonesArray * sdigitsDummyContainer= new TClonesArray("AliTOFSDigit",  1000); 
-
+  TClonesArray * sdigitsDummyContainer=&sdigitsClonesArray;
   // check if the branch exist
   TBranch* tofBranch=currentTreeS->GetBranch("TOF");
 
@@ -382,12 +380,9 @@ void AliTOFDigitizer::ReadSDigit(Int_t inputFile )
       } // if (hitMap->TestHit(vol) != kEmpty)
       
     } // for (Int_t k=0; k<ndig; k++)
-    sdigitsDummyContainer->Delete();
 
   } // end loop on entries
 
-  delete sdigitsDummyContainer;
-
 }
 
 
@@ -405,21 +400,27 @@ void AliTOFDigitizer::CollectSDigit(AliTOFSDigit * sdigit)
 }
 
 //_____________________________________________________________________________
-void AliTOFDigitizer::InitDecalibration( AliTOFcalib *calib) const {
-  calib->ReadSimParFromCDB("TOF/Calib", -1); // use AliCDBManager's number
+void AliTOFDigitizer::InitDecalibration() const {
+  //
+  //
+  //
+
+  fCalib->CreateCalArrays();
+  fCalib->ReadSimHistoFromCDB("TOF/Calib", -1); // use AliCDBManager's number
+  fCalib->ReadParOfflineFromCDB("TOF/Calib", -1); // use AliCDBManager's number
 }
 //---------------------------------------------------------------------
-void AliTOFDigitizer::DecalibrateTOFSignal( AliTOFcalib *calib){
+void AliTOFDigitizer::DecalibrateTOFSignal(){
 
   // Read Calibration parameters from the CDB
 
-  AliTOFCal * cal= calib->GetTOFCalSimArray();
+  TObjArray * calOffline= fCalib->GetTOFCalArrayOffline();
 
-  AliDebug(2,Form("Size of AliTOFCal = %i",cal->NPads()));
+  AliDebug(2,Form("Size of array for Offline Calibration = %i",calOffline->GetEntries()));
 
   // Initialize Quantities to Simulate ToT Spectra
 
-  TH1F * hToT= calib->GetTOFSimToT();
+  TH1F * hToT= fCalib->GetTOFSimToT();
   Int_t nbins = hToT->GetNbinsX();
   Float_t delta = hToT->GetBinWidth(1);
   Float_t maxch = hToT->GetBinLowEdge(nbins)+delta;
@@ -454,7 +455,7 @@ void AliTOFDigitizer::DecalibrateTOFSignal( AliTOFcalib *calib){
   Bool_t isToTSimulated=kFALSE;
   Bool_t misCalibPars=kFALSE;
   if(hToT->GetEntries()>0)isToTSimulated=kTRUE;  
-  Int_t ndigits = fDigits->GetEntriesFast();    
+  Int_t ndigits = fDigits->GetEntriesFast();
   for (Int_t i=0;i<ndigits;i++){
     AliTOFdigit * dig = (AliTOFdigit*)fDigits->At(i);
     Int_t detId[5];
@@ -469,19 +470,18 @@ void AliTOFDigitizer::DecalibrateTOFSignal( AliTOFcalib *calib){
       //A realistic ToT Spectrum was found in input, 
       //decalibrated TOF Digits likely to be simulated....
  
-      Int_t index = calib->GetIndex(detId); // The channel index    
-      AliTOFChannel *calChannel = cal->GetChannel(index); //retrieve the info
-      Float_t timedelay = calChannel->GetDelay(); //The global channel delay
-      Float_t par[6];  // time slewing parameters
+      Int_t index = AliTOFGeometry::GetIndex(detId); // The channel index    
+      AliTOFChannelOffline *calChannelOffline = (AliTOFChannelOffline *)calOffline->At(index); //retrieve the info for time slewing 
+      Double_t par[6];  // time slewing parameters
   
       //check whether we actually ask for miscalibration
 
-      if(timedelay!=0)misCalibPars=kTRUE;
       for (Int_t j = 0; j<6; j++){
-       par[j]=calChannel->GetSlewPar(j);
+       par[j]=(Double_t)calChannelOffline->GetSlewPar(j);
        if(par[j]!=0)misCalibPars=kTRUE;
       }
-      AliDebug(2,Form(" Calib Pars = %f, %f, %f, %f, %f, %f ",par[0],par[1],par[2],par[3],par[4],par[5]));
+      AliDebug(2,Form(" Calib Pars = %f (0-th parameter for time slewing + time delay), %f, %f, %f, %f, %f ",par[0],par[1],par[2],par[3],par[4],par[5]));
+
       // Now generate Realistic ToT distribution from TestBeam Data. 
       // Tot is in ns, assuming a Matching Window of 10 ns.
 
@@ -502,16 +502,14 @@ void AliTOFDigitizer::DecalibrateTOFSignal( AliTOFcalib *calib){
       tToT= (Double_t) trix; // to apply slewing we start from ns..
       // transform TOF signal in ns
       AliDebug(2,Form(" The Initial Time (counts): %i: ",dig->GetTdc()));
-      AliDebug(2,Form(" Time before miscalibration (ps) %e: ",dig->GetTdc()*AliTOFGeometry::TdcBinWidth()));
+      AliDebug(2,Form(" Time before miscalibration (ps) %e: ",dig->GetTdc()*(Double_t)AliTOFGeometry::TdcBinWidth()));
       // add slewing effect
       timeCorr=par[0] + tToT*(par[1] +tToT*(par[2] +tToT*(par[3] +tToT*(par[4] +tToT*par[5])))); 
-      AliDebug(2,Form(" The Time slewing (ns): %f: ",timeCorr));
+      AliDebug(2,Form(" The Time slewing + delay (ns): %f: ",timeCorr));
       // add global time shift
-      timeCorr = timeCorr + timedelay;
-      AliDebug(2,Form(" The Time Slewing+ delay (ns): %f: ",timeCorr));
       //convert to ps
-      timeCorr*=1E-3;
-      Double_t timeMis = (Double_t)(dig->GetTdc())*AliTOFGeometry::TdcBinWidth();
+      timeCorr*=1E3;
+      Double_t timeMis = (Double_t)(dig->GetTdc())*(Double_t)AliTOFGeometry::TdcBinWidth();
       timeMis = timeMis+timeCorr;
       AliDebug(2,Form(" The Miscalibrated time (ps): %e: ",timeMis));
 
@@ -525,10 +523,10 @@ void AliTOFDigitizer::DecalibrateTOFSignal( AliTOFcalib *calib){
       tToT*=1E3; //back to ps  
       Int_t tot=(Int_t)(tToT/AliTOFGeometry::ToTBinWidth());//(factor 1E3 as input ToT is in ns)
       dig->SetToT(tot); 
-      AliDebug(2,Form(" Final Time and ToT (counts): %i: ",dig->GetTdc(),dig->GetToT()));
+      AliDebug(2,Form(" Final Time and ToT (counts): %d: , %d:",dig->GetTdc(),dig->GetToT()));
       if(tdcCorr<0){
-       AliWarning (Form(" The bad Slewed Time(TDC counts)= %i ", tdcCorr)); 
-       AliWarning(Form(" The bad ToT (TDC counts)= %i ", tot)); 
+       AliWarning (Form(" The bad Slewed Time(TDC counts)= %d ", tdcCorr)); 
+       AliWarning(Form(" The bad ToT (TDC counts)= %d ", tot)); 
       }
     }
     else{
@@ -537,16 +535,14 @@ void AliTOFDigitizer::DecalibrateTOFSignal( AliTOFcalib *calib){
     }
   }
 
-  if(!isToTSimulated){
-    AliDebug(1,"Standard Production, no miscalibrated digits");   
-  }else{
-    if(!misCalibPars){
-    AliDebug(1,"Standard Production, no miscalibrated digits");   
-    }
-    else {
-      AliDebug(1,"Simulating miscalibrated digits");   
-    } 
-  }
+  if(!isToTSimulated)
+    AliDebug(1,"Standard Production, no miscalibrated digits");
+  else
+    if(!misCalibPars)
+      AliDebug(1,"Standard Production, no miscalibrated digits");
+    else
+      AliDebug(1,"Simulating miscalibrated digits");
+
   return;
 }