]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TOF/AliTOFDigitizer.cxx
Updates in calibration objects handling
[u/mrichter/AliRoot.git] / TOF / AliTOFDigitizer.cxx
index 77ac3b0f22de2ed9451640db4925f0ff27c60a0e..d838c6e3417aa209a3ff329e971ec95515e26a0c 100644 (file)
@@ -31,6 +31,7 @@
 #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"
 
@@ -60,7 +61,6 @@ ClassImp(AliTOFDigitizer)
 //___________________________________________
   AliTOFDigitizer::AliTOFDigitizer()  :
     AliDigitizer(),
-    fGeom(0x0),
     fDigits(0x0),
     fSDigitsArray(0x0),
     fhitMap(0x0)
@@ -71,7 +71,6 @@ ClassImp(AliTOFDigitizer)
 //___________________________________________
 AliTOFDigitizer::AliTOFDigitizer(AliRunDigitizer* manager): 
   AliDigitizer(manager), 
-  fGeom(0x0),
   fDigits(0x0),
   fSDigitsArray(0x0),
   fhitMap(0x0)
@@ -82,7 +81,6 @@ AliTOFDigitizer::AliTOFDigitizer(AliRunDigitizer* manager):
 //------------------------------------------------------------------------
 AliTOFDigitizer::AliTOFDigitizer(const AliTOFDigitizer &source):
   AliDigitizer(source),
-  fGeom(0x0), 
   fDigits(0),
   fSDigitsArray(0),
   fhitMap(0)
@@ -91,7 +89,6 @@ AliTOFDigitizer::AliTOFDigitizer(const AliTOFDigitizer &source):
   this->fDigits=source.fDigits;
   this->fSDigitsArray=source.fSDigitsArray;
   this->fhitMap=source.fhitMap;
-  this->fGeom=source.fGeom; 
 
 }
 
@@ -102,7 +99,6 @@ AliTOFDigitizer::AliTOFDigitizer(const AliTOFDigitizer &source):
   this->fDigits=source.fDigits;
   this->fSDigitsArray=source.fSDigitsArray;
   this->fhitMap=source.fhitMap;
-  this->fGeom=source.fGeom; 
   return *this;
 
 }
@@ -146,21 +142,25 @@ void AliTOFDigitizer::Exec(Option_t* /*option*/)
      return;
    }
    
+  /*
   outrl->CdGAFile();
   TFile *in=(TFile*)gFile;
   TDirectory *savedir=gDirectory;
 
+   
+  //when fGeom was needed
+
   if (!in->IsOpen()) {
     AliWarning("Geometry file is not open default  TOF geometry will be used");
-    fGeom = new AliTOFGeometryV5();
+    fGeom = new AliTOFGeometry();
   }
   else {
     in->cd();
     fGeom = (AliTOFGeometry*)in->Get("TOFgeometry");
   }
-
+  
   savedir->cd();
-
+  */
   AliLoader* outgime = outrl->GetLoader("TOFLoader");
   if (outgime == 0x0)
    {
@@ -181,7 +181,7 @@ void AliTOFDigitizer::Exec(Option_t* /*option*/)
   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
 
@@ -263,11 +263,11 @@ void AliTOFDigitizer::CreateDigits()
     
     // start loop on number of slots for current sdigit
     for (Int_t islot = 0; islot < nslot; islot++) {
-      Float_t  digit[4] = {-1.,-1.,-1.,-1.};     // TOF digit variables
+      Int_t  digit[4] = {-1,-1,-1,-1};     // TOF digit variables
       Int_t tracknum[AliTOFSDigit::kMAXDIGITS];     // contributing tracks for the current slot
       
-      Float_t tdc=tofsdigit->GetTdc(islot); digit[0]=tdc;
-      Float_t adc=tofsdigit->GetAdc(islot); digit[1]=adc;
+      Int_t tdc=tofsdigit->GetTdc(islot); digit[0]=tdc;
+      Int_t adc=tofsdigit->GetAdc(islot); digit[1]=adc;
       
       tracknum[0]=tofsdigit->GetTrack(islot,0);
       tracknum[1]=tofsdigit->GetTrack(islot,1);
@@ -284,8 +284,8 @@ void AliTOFDigitizer::CreateDigits()
   } // end loop on sdigits - end digitizing all collected sdigits
 
   //Insert Decalibration 
-
-  AliTOFcalib * calib = new AliTOFcalib(fGeom);
+  AliInfo("in digitizer, create digits");
+  AliTOFcalib * calib = new AliTOFcalib();
   InitDecalibration(calib);
   DecalibrateTOFSignal(calib);
   delete calib;
@@ -406,16 +406,22 @@ void AliTOFDigitizer::CollectSDigit(AliTOFSDigit * sdigit)
 
 //_____________________________________________________________________________
 void AliTOFDigitizer::InitDecalibration( AliTOFcalib *calib) const {
-  calib->ReadSimParFromCDB("TOF/Calib", -1); // use AliCDBManager's number
+  //
+  //
+  //
+
+  calib->CreateCalArrays();
+  calib->ReadSimHistoFromCDB("TOF/Calib", -1); // use AliCDBManager's number
+  calib->ReadParOfflineFromCDB("TOF/Calib", -1); // use AliCDBManager's number
 }
 //---------------------------------------------------------------------
 void AliTOFDigitizer::DecalibrateTOFSignal( AliTOFcalib *calib){
 
   // Read Calibration parameters from the CDB
 
-  AliTOFCal * cal= calib->GetTOFCalSimArray();
+  TObjArray * calOffline= calib->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
 
@@ -442,14 +448,19 @@ void AliTOFDigitizer::DecalibrateTOFSignal( AliTOFcalib *calib){
 
   Float_t maxToT=max;
   Float_t minToT=min;
   Float_t maxToTDistr=hToT->GetMaximum();
+
+  AliDebug (1, Form(" The minimum ToT = %f", minToT)); 
+  AliDebug (1, Form(" The maximum ToT = %f", maxToT)); 
+  AliDebug (1, Form(" The maximum peak in ToT = %f", maxToTDistr)); 
   
   // Loop on TOF Digits
 
   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];
@@ -464,25 +475,26 @@ 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 (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.
 
       Float_t simToT = 0;
       Float_t trix = 0;
       Float_t triy = 0;
+      Double_t timeCorr;
+      Double_t tToT;
       while (simToT <= triy){
        trix = gRandom->Rndm(i);
        triy = gRandom->Rndm(i);
@@ -492,25 +504,39 @@ void AliTOFDigitizer::DecalibrateTOFSignal( AliTOFcalib *calib){
        simToT=hToT->GetBinContent(binx);
       }
       // the generated ToT (ns)
-      Float_t tToT= trix; // to apply slewing need to go back to ns..
-      // transform TOF signal in ns, factor 1E-3 as bin width is in ps.
-      Float_t tdc = ((dig->GetTdc())*AliTOFGeometry::TdcBinWidth()+32)*1.E-3; 
-      AliDebug(2,Form(" Time before miscalibration (ns) %f: ",tdc));
+      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()*(Double_t)AliTOFGeometry::TdcBinWidth()));
       // add slewing effect
-      Float_t timeoffset=par[0] + tToT*(par[1] +tToT*(par[2] +tToT*(par[3] +tToT*(par[4] +tToT*par[5])))); 
-      Float_t timeSlewed = tdc+timeoffset;
-      AliDebug(2,Form(" Time after applying slewing (ns): %f: ",timeSlewed));
+      timeCorr=par[0] + tToT*(par[1] +tToT*(par[2] +tToT*(par[3] +tToT*(par[4] +tToT*par[5])))); 
+      AliDebug(2,Form(" The Time slewing + delay (ns): %f: ",timeCorr));
       // add global time shift
-      timeSlewed = timeSlewed + timedelay;
-      AliDebug(2,Form(" Time after applying global delay (ns): %f: ",timeSlewed));
+      //convert to ps
+      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));
+
+      // now update the digit info
+      Int_t tdcCorr= (Int_t)(timeMis/AliTOFGeometry::TdcBinWidth());
+      AliDebug(2,Form(" Final Time (counts): %i: ",tdcCorr));
       // Setting Decalibrated Time signal (TDC counts)    
-      dig->SetTdc((timeSlewed*1E3-32)/AliTOFGeometry::TdcBinWidth());   
-      // Setting realistic ToT signal (TDC counts)   
-      dig->SetToT(trix/AliTOFGeometry::ToTBinWidth()*1.E3); //(factor 1E3 as input ToT is in ns)
+      dig->SetTdc(tdcCorr);   
+      // Setting realistic ToT signal (TDC counts) 
+      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: , %i:",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)); 
+      }
     }
     else{
     // For Data with no Miscalibration, set ToT signal == Adc
-    dig->SetToT(dig->GetAdc()/AliTOFGeometry::ToTBinWidth()*1.E3); 
+      dig->SetToT((Int_t)(dig->GetAdc()/AliTOFGeometry::ToTBinWidth())); //remove the factor 10^3 just to have a reasonable ToT range for raw data simulation even in the case of non-realistic ToT distribution (n.b. fAdc is practically an arbitrary quantity, and ToT has no impact on the TOF reco for non-miscalibrated digits)
     }
   }