Fixes for the trunk: compilation on Lion (Yves)
[u/mrichter/AliRoot.git] / VZERO / AliVZERODigitizer.cxx
index 00e3a7e..4abae07 100644 (file)
 #include "AliRunLoader.h"
 #include "AliLoader.h"
 #include "AliGRPObject.h"
-#include "AliRunDigitizer.h"
+#include "AliDigitizationInput.h"
 #include "AliCDBManager.h"
 #include "AliCDBStorage.h"
 #include "AliCDBEntry.h"
 #include "AliVZEROCalibData.h"
 #include "AliCTPTimeParams.h"
+#include "AliLHCClockPhase.h"
 #include "AliVZEROdigit.h"
 #include "AliVZERODigitizer.h"
 #include "AliVZEROSDigit.h"
@@ -93,8 +94,8 @@ ClassImp(AliVZERODigitizer)
 }
            
 //____________________________________________________________________________ 
-  AliVZERODigitizer::AliVZERODigitizer(AliRunDigitizer* manager)
-                    :AliDigitizer(manager),
+  AliVZERODigitizer::AliVZERODigitizer(AliDigitizationInput* digInput)
+                    :AliDigitizer(digInput),
                     fCalibData(GetCalibData()),
                      fPhotoCathodeEfficiency(0.18),
                     fNdigits(0),
@@ -165,10 +166,19 @@ Bool_t AliVZERODigitizer::Init()
   AliCTPTimeParams *ctpParams = (AliCTPTimeParams*)entry->GetObject();
   Float_t l1Delay = (Float_t)ctpParams->GetDelayL1L0()*25.0;
 
+  AliCDBEntry *entry1 = AliCDBManager::Instance()->Get("GRP/CTP/TimeAlign");
+  if (!entry1) AliFatal("CTP time-alignment is not found in OCDB !");
+  AliCTPTimeParams *ctpTimeAlign = (AliCTPTimeParams*)entry1->GetObject();
+  l1Delay += ((Float_t)ctpTimeAlign->GetDelayL1L0()*25.0);
+
   AliCDBEntry *entry2 = AliCDBManager::Instance()->Get("VZERO/Calib/TimeDelays");
   if (!entry2) AliFatal("VZERO time delays are not found in OCDB !");
   TH1F *delays = (TH1F*)entry2->GetObject();
 
+  AliCDBEntry *entry3 = AliCDBManager::Instance()->Get("GRP/Calib/LHCClockPhase");
+  if (!entry3) AliFatal("LHC clock-phase shift is not found in OCDB !");
+  AliLHCClockPhase *phase = (AliLHCClockPhase*)entry3->GetObject();
+
   for(Int_t i = 0 ; i < 64; ++i) {
 
     for(Int_t j = 0; j < kNClocks; ++j) fAdc[i][j] = 0;
@@ -188,12 +198,18 @@ Bool_t AliVZERODigitizer::Init()
     fNBinsLT[i] = TMath::Nint(((Float_t)(fCalibData->GetMatchWindow(board)+1)*25.0)/
                              fCalibData->GetTimeResolution(board));
     fBinSize[i] = fCalibData->GetTimeResolution(board);
-    fHptdcOffset[i] = (((Float_t)fCalibData->GetTriggerCountOffset(board)-
-                       (Float_t)fCalibData->GetRollOver(board))*25.0+
-                      fCalibData->GetTimeOffset(i)+
-                      l1Delay+
+    fHptdcOffset[i] = (((Float_t)fCalibData->GetRollOver(board)-
+                       (Float_t)fCalibData->GetTriggerCountOffset(board))*25.0+
+                      fCalibData->GetTimeOffset(i)-
+                      l1Delay-
+                      phase->GetMeanPhase()+
                       delays->GetBinContent(i+1)+
                       kV0Offset);
+    fClockOffset[i] = (((Float_t)fCalibData->GetRollOver(board)-
+                       (Float_t)fCalibData->GetTriggerCountOffset(board))*25.0+
+                      fCalibData->GetTimeOffset(i)-
+                      l1Delay+
+                      kV0Offset);
 
     fTime[i] = new Float_t[fNBins[i]];
     memset(fTime[i],0,fNBins[i]*sizeof(Float_t));
@@ -203,12 +219,12 @@ Bool_t AliVZERODigitizer::Init()
 }
 
 //____________________________________________________________________________
-void AliVZERODigitizer::Exec(Option_t* /*option*/) 
+void AliVZERODigitizer::Digitize(Option_t* /*option*/) 
 {   
   // Creates digits from hits
   fNdigits = 0;  
 
-  if (fVZERO && !fManager) {
+  if (fVZERO && !fDigInput) {
     AliLoader *loader = fVZERO->GetLoader();
     if (!loader) {
       AliError("Can not get VZERO Loader via AliVZERO object!");
@@ -228,10 +244,10 @@ void AliVZERODigitizer::Exec(Option_t* /*option*/)
       }
     }
   }
-  else if (fManager) {
+  else if (fDigInput) {
       ReadSDigits();
       DigitizeSDigits();
-      AliRunLoader *currentLoader = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
+      AliRunLoader *currentLoader = AliRunLoader::GetRunLoader(fDigInput->GetOutputFolderName());
       AliLoader *loader = currentLoader->GetLoader("VZEROLoader");
       if (!loader) { 
        AliError("Cannot get VZERO Loader via RunDigitizer!");
@@ -379,8 +395,6 @@ void AliVZERODigitizer::DigitizeHits()
      }
      TClonesArray* hits = fVZERO->Hits();
 
-     //     Float_t lightYieldCorr[64] = {0.00707,0.00517,0.00520,0.00537,0.00735,0.00537,0.00733,0.00605,0.00778,0.00749,0.00701,0.00755,0.00732,0.00617,0.00669,0.00525,0.00752,0.00820,0.00797,0.01107,0.01080,0.00889,0.00880,0.01712,0.00866,0.00701,0.00811,0.00602,0.00879,0.00821,0.00861,0.01433,0.00061,0.00032,0.00099,0.00061,0.00034,0.00046,0.00031,0.00122,0.00155,0.00091,0.00032,0.00096,0.00120,0.00067,0.00113,0.00060,0.00158,0.00136,0.00340,0.00066,0.00076,0.00119,0.00129,0.00147,0.00137,0.00117,0.00088,0.00164,0.00128,0.00081,0.00121,0.00250};
-     Float_t lightYieldCorr[64] = {0.01173,0.00874,0.00878,0.00886,0.01151,0.00925,0.01167,0.00983,0.01181,0.01243,0.01115,0.01220,0.01228,0.01053,0.01021,0.00930,0.01270,0.01411,0.01316,0.01894,0.01923,0.01860,0.01738,0.00305,0.01584,0.01251,0.01344,0.00310,0.01302,0.01266,0.01407,0.00338,0.00089,0.00100,0.00130,0.00081,0.00052,0.01230,0.00059,0.02452,0.02980,0.00137,0.01421,0.00116,0.00141,0.00092,0.02480,0.00096,0.00182,0.00174,0.00218,0.00106,0.00116,0.00160,0.00162,0.03097,0.00194,0.00171,0.00132,0.00239,0.00173,0.00118,0.00163,0.00262};
 //  Now makes Digits from hits
      Int_t nTracks = (Int_t) treeH->GetEntries();
      for (Int_t iTrack = 0; iTrack < nTracks; iTrack++) {
@@ -392,6 +406,7 @@ void AliVZERODigitizer::DigitizeHits()
           Int_t nPhot = hit->Nphot();
           Int_t cell  = hit->Cell();                          
           Int_t pmt = Cell2Pmt(cell);
+          if (pmt < 0) continue;
           Int_t trackLabel = hit->GetTrack();
           for(Int_t l = 0; l < 3; ++l) {
             if (fLabels[pmt][l] < 0) {
@@ -404,7 +419,7 @@ void AliVZERODigitizer::DigitizeHits()
           if (pmt < 32) t += kV0CDelayCables;
           t += fHptdcOffset[pmt];
           Int_t nPhE;
-          Float_t prob = lightYieldCorr[pmt]*fPhotoCathodeEfficiency; // Optical losses included!
+          Float_t prob = fCalibData->GetLightYields(pmt)*fPhotoCathodeEfficiency; // Optical losses included!
           if (nPhot > 100)
             nPhE = (Int_t)gRandom->Gaus(prob*Float_t(nPhot)+0.5,
                                         sqrt(Float_t(nPhot)*prob*(1.-prob)));
@@ -439,7 +454,7 @@ void AliVZERODigitizer::DigitizeSDigits()
   Float_t maximum = 0.9*fSignalShape->GetMaximum(0,200); // Not exact, one needs to do this on the convoluted
   Float_t integral2 = fSignalShape->Integral(0,200); // function. Anyway the effect is small <10% on the 2.5 ADC thr
   for (Int_t ipmt = 0; ipmt < 64; ++ipmt) {
-    Float_t thr = fCalibData->GetDiscriThr(ipmt)*kChargePerADC*maximum*fBinSize[ipmt]/integral2;
+    Float_t thr = fCalibData->GetCalibDiscriThr(ipmt,kFALSE)*kChargePerADC*maximum*fBinSize[ipmt]/integral2;
     Bool_t ltFound = kFALSE, ttFound = kFALSE;
     for (Int_t iBin = 0; iBin < fNBins[ipmt]; ++iBin) {
       Float_t t = fBinSize[ipmt]*Float_t(iBin);
@@ -457,11 +472,12 @@ void AliVZERODigitizer::DigitizeSDigits()
          }
        }
       }
-      Float_t tadc = t - kClockOffset - fCalibData->GetTimeOffset(ipmt);
+      Float_t tadc = t - fClockOffset[ipmt];
       Int_t clock = kNClocks/2 - Int_t(tadc/25.0);
       if (clock >= 0 && clock < kNClocks)
        fAdc[ipmt][clock] += fTime[ipmt][iBin]/kChargePerADC;
     }
+    AliDebug(1,Form("Channel %d Offset %f Time %f",ipmt,fClockOffset[ipmt],fLeadingTime[ipmt]));
     Int_t board = AliVZEROCalibData::GetBoardNumber(ipmt);
     if (ltFound && ttFound) {
       fTimeWidth[ipmt] = fCalibData->GetWidthResolution(board)*
@@ -477,6 +493,7 @@ void AliVZERODigitizer::DigitizeSDigits()
   for (Int_t j=0; j<64; ++j){
     for (Int_t iClock = 0; iClock < kNClocks; ++iClock) {
       Int_t integrator = (iClock + fEvenOrOdd) % 2;
+      AliDebug(1,Form("ADC %d %d %f",j,iClock,fAdc[j][iClock]));
       fAdc[j][iClock]  += gRandom->Gaus(fAdcPedestal[j][integrator], fAdcSigma[j][integrator]);
     }
   }
@@ -546,11 +563,11 @@ void AliVZERODigitizer::ReadSDigits()
   }
 
   // Loop over input files
-  Int_t nFiles= fManager->GetNinputs();
+  Int_t nFiles= fDigInput->GetNinputs();
   for (Int_t inputFile = 0; inputFile < nFiles; inputFile++) {
     // Get the current loader 
     AliRunLoader* currentLoader = 
-      AliRunLoader::GetRunLoader(fManager->GetInputFolderName(inputFile));
+      AliRunLoader::GetRunLoader(fDigInput->GetInputFolderName(inputFile));
 
     AliLoader *loader = currentLoader->GetLoader("VZEROLoader");
     loader->LoadSDigits("READ");
@@ -558,7 +575,7 @@ void AliVZERODigitizer::ReadSDigits()
     // Get the tree of summable digits
     TTree* sdigitsTree = loader->TreeS();
     if (!sdigitsTree)  {
-      AliError("No sdigit tree from manager");
+      AliError("No sdigit tree from digInput");
       continue;
     }