]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ZDC/AliZDCReconstructor.cxx
Compare method fixed (Plamen)
[u/mrichter/AliRoot.git] / ZDC / AliZDCReconstructor.cxx
index 2e05ad29d122645719f0d3d18014e4688463ecdf..cf355630cec1e3e00b4d105924a2b2ec81ece0c0 100644 (file)
 
 
 #include <TF1.h>
+#include <TMap.h>
 
 #include "AliRunLoader.h"
 #include "AliRawReader.h"
+#include "AliGRPObject.h"
 #include "AliESDEvent.h"
 #include "AliESDZDC.h"
 #include "AliZDCDigit.h"
@@ -45,9 +47,13 @@ AliZDCRecoParam *AliZDCReconstructor::fRecoParam=0;  //reconstruction parameters
 //_____________________________________________________________________________
 AliZDCReconstructor:: AliZDCReconstructor() :
   fPedData(GetPedData()),
-  fECalibData(GetECalibData())
+  fECalibData(GetECalibData()),
+  fRecoMode(0),
+  fBeamEnergy(0.),
+  fPedSubMode(0)
 {
   // **** Default constructor
+  SetRecoMode();
 
 }
 
@@ -61,6 +67,54 @@ AliZDCReconstructor::~AliZDCReconstructor()
    if(fECalibData) delete fECalibData;
 }
 
+//____________________________________________________________________________
+void AliZDCReconstructor::SetRecoMode()
+{
+  // Setting reconstruction mode
+
+  // Initialization of the GRP entry 
+  AliCDBEntry*  entry = AliCDBManager::Instance()->Get("GRP/GRP/Data");
+  AliGRPObject* grpData = 0x0;
+  if(entry){
+    TMap* m = dynamic_cast<TMap*>(entry->GetObject());  // old GRP entry
+    if(m){
+       m->Print();
+       grpData = new AliGRPObject();
+       grpData->ReadValuesFromMap(m);
+    }
+    else{
+       grpData = dynamic_cast<AliGRPObject*>(entry->GetObject());  // new GRP entry
+       entry->SetOwner(0);
+    }
+    AliCDBManager::Instance()->UnloadFromCache("GRP/GRP/Data");
+  }
+  if(!grpData) AliError("No GRP entry found in OCDB!");
+
+  TString beamType = grpData->GetBeamType();
+  if(beamType==AliGRPObject::GetInvalidString()){
+    AliError("GRP/GRP/Data entry:  missing value for the beam energy !");
+    AliError("\t ZDC does not reconstruct event 4 UNKNOWN beam type\n");
+    return;
+  }
+  //
+  if((beamType.CompareTo("p-p")) == 0){
+    fRecoMode=0;
+    fRecoParam = (AliZDCRecoParampp*) AliZDCRecoParampp::GetppRecoParam();
+  }
+  else if((beamType.CompareTo("A-A")) == 0){
+    fRecoMode=1;
+    fRecoParam = (AliZDCRecoParamPbPb*) AliZDCRecoParamPbPb::GetPbPbRecoParam();
+  }
+  
+  fBeamEnergy = grpData->GetBeamEnergy();
+  if(fBeamEnergy==AliGRPObject::GetInvalidFloat()) {
+    AliError("GRP/GRP/Data entry:  missing value for the beam energy ! Using 0");
+    fBeamEnergy = 0.;
+  }
+  
+  printf("\n ***** ZDC reconstruction initialized for %s @ %1.3f GeV\n\n",beamType.Data(), fBeamEnergy);
+}
+
 //_____________________________________________________________________________
 void AliZDCReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree) const
 {
@@ -68,8 +122,15 @@ void AliZDCReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree) co
   // Works on the current event
     
   // Retrieving calibration data  
-  Float_t meanPed[48];
+  // Parameters for mean value pedestal subtraction
+  Float_t meanPed[48];    
   for(Int_t jj=0; jj<48; jj++) meanPed[jj] = fPedData->GetMeanPed(jj);
+  // Parameters pedestal subtraction through correlation with out-of-time signals
+  Float_t corrCoeff0[48], corrCoeff1[48];
+  for(Int_t jj=0; jj<48; jj++){
+     corrCoeff0[jj] =  fPedData->GetPedCorrCoeff0(jj);
+     corrCoeff1[jj] =  fPedData->GetPedCorrCoeff1(jj);
+  }
 
   // get digits
   AliZDCDigit digit;
@@ -84,92 +145,119 @@ void AliZDCReconstructor::Reconstruct(TTree* digitsTree, TTree* clustersTree) co
      tZN1Corr[i] = tZP1Corr[i] = tZN2Corr[i] = tZP2Corr[i] = 0.;
      if(i<2) dZEM1Corr[i] = dZEM2Corr[i] = PMRef1[i] = PMRef2[i] = 0.;
   }  
-  //
-  for (Int_t iDigit = 0; iDigit < (digitsTree->GetEntries()/2); iDigit++) {
+  
+  Int_t digNentries = digitsTree->GetEntries();
+  int const kNch = 24;
+  Float_t ootDigi[kNch];
+  // -- Reading out-of-time signals (last kNch entries) for current event
+  if(fPedSubMode==1){
+    for(Int_t iDigit=kNch; iDigit<digNentries; iDigit++){
+       ootDigi[iDigit] = digitsTree->GetEntry(iDigit);
+    }
+  }
+  
+  for(Int_t iDigit=0; iDigit<(digNentries/2); iDigit++) {
    digitsTree->GetEntry(iDigit);
    if (!pdigit) continue;
    //  
    Int_t det = digit.GetSector(0);
    Int_t quad = digit.GetSector(1);
-   Int_t pedindex = -1, kNch = 24;
-   //printf("\n\t Digit #%d det %d quad %d", iDigit, det, quad);
+   Int_t pedindex = -1;
+   Float_t ped2SubHg=0., ped2SubLg=0.;
+   if(quad!=5){
+     if(det==1)      pedindex = quad;
+     else if(det==2) pedindex = quad+5;
+     else if(det==3) pedindex = quad+9;
+     else if(det==4) pedindex = quad+12;
+     else if(det==5) pedindex = quad+17;
+   }
+   else pedindex = (det-1)/3+22;
    //
+   if(fPedSubMode==0){
+     ped2SubHg = meanPed[pedindex];
+     ped2SubLg = meanPed[pedindex+kNch];
+   }
+   else if(fPedSubMode==1){
+     ped2SubHg = corrCoeff1[pedindex]*ootDigi[pedindex]+corrCoeff0[pedindex];
+     ped2SubLg = corrCoeff1[pedindex+kNch]*ootDigi[pedindex+kNch]+corrCoeff0[pedindex+kNch];
+   }
+
+   //printf("\n\t Digit #%d det %d quad %d", iDigit, det, quad);
+      
    if(quad != 5){ // ZDC (not reference PTMs!)
     if(det == 1){ // *** ZNC
-       pedindex = quad;
-       tZN1Corr[quad] = (Float_t) (digit.GetADCValue(0)-meanPed[pedindex]);
+       tZN1Corr[quad] = (Float_t) (digit.GetADCValue(0)-ped2SubHg);
+       tZN1Corr[quad+5] = (Float_t) (digit.GetADCValue(1)-ped2SubLg);
        if(tZN1Corr[quad]<0.) tZN1Corr[quad] = 0.;
-       tZN1Corr[quad+5] = (Float_t) (digit.GetADCValue(1)-meanPed[pedindex+kNch]);
-       if(tZN1Corr[quad+5]<0.) tZN1Corr[quad] = 0.;
+       if(tZN1Corr[quad+5]<0.) tZN1Corr[quad+5] = 0.;
        //printf("\t pedindex %d tZN1Corr[%d] = %1.0f tZN1Corr[%d] = %1.0f", 
        //      pedindex, quad, tZN1Corr[quad], quad+5, tZN1Corr[quad+5]);
     }
     else if(det == 2){ // *** ZP1
-       pedindex = quad+5;
-       tZP1Corr[quad] = (Float_t) (digit.GetADCValue(0)-meanPed[pedindex]);
+       tZP1Corr[quad] = (Float_t) (digit.GetADCValue(0)-ped2SubHg);
        if(tZP1Corr[quad]<0.) tZP1Corr[quad] = 0.;
-       tZP1Corr[quad+5] = (Float_t) (digit.GetADCValue(1)-meanPed[pedindex+kNch]);
-       if(tZP1Corr[quad+5]<0.) tZP1Corr[quad] = 0.;
+       tZP1Corr[quad+5] = (Float_t) (digit.GetADCValue(1)-ped2SubLg);
+       if(tZP1Corr[quad+5]<0.) tZP1Corr[quad+5] = 0.;
        //printf("\t pedindex %d tZP1Corr[%d] = %1.0f tZP1Corr[%d] = %1.0f", 
        //      pedindex, quad, tZP1Corr[quad], quad+5, tZP1Corr[quad+5]);
     }
     else if(det == 3){
-       pedindex = quad+9;
        if(quad == 1){      // *** ZEM1  
-         dZEM1Corr[0] += (Float_t) (digit.GetADCValue(0)-meanPed[pedindex]); 
+         dZEM1Corr[0] += (Float_t) (digit.GetADCValue(0)-ped2SubHg); 
          if(dZEM1Corr[0]<0.) dZEM1Corr[0] = 0.;
-         dZEM1Corr[1] += (Float_t) (digit.GetADCValue(1)-meanPed[pedindex+kNch]); 
+         dZEM1Corr[1] += (Float_t) (digit.GetADCValue(1)-ped2SubLg); 
          if(dZEM1Corr[1]<0.) dZEM1Corr[1] = 0.;
          //printf("\t pedindex %d tZEM1Corr[%d] = %1.0f tZEM1Corr[%d] = %1.0f", 
          //    pedindex, quad, tZEM1Corr[quad], quad+1, tZEM1Corr[quad+1]);
        }
        else if(quad == 2){  // *** ZEM2
-         dZEM2Corr[0] += (Float_t) (digit.GetADCValue(0)-meanPed[pedindex]); 
+         dZEM2Corr[0] += (Float_t) (digit.GetADCValue(0)-ped2SubHg); 
          if(dZEM2Corr[0]<0.) dZEM2Corr[0] = 0.;
-         dZEM2Corr[1] += (Float_t) (digit.GetADCValue(1)-meanPed[pedindex+kNch]); 
+         dZEM2Corr[1] += (Float_t) (digit.GetADCValue(1)-ped2SubLg); 
          if(dZEM2Corr[1]<0.) dZEM2Corr[1] = 0.;
          //printf("\t pedindex %d tZEM2Corr[%d] = %1.0f tZEM2Corr[%d] = %1.0f", 
          //    pedindex, quad, tZEM2Corr[quad], quad+1, tZEM2Corr[quad+1]);
        }
     }
     else if(det == 4){  // *** ZN2
-       pedindex = quad+12;
-       tZN2Corr[quad] = (Float_t) (digit.GetADCValue(0)-meanPed[pedindex]);
+       tZN2Corr[quad] = (Float_t) (digit.GetADCValue(0)-ped2SubHg);
        if(tZN2Corr[quad]<0.) tZN2Corr[quad] = 0.;
-       tZN2Corr[quad+5] = (Float_t) (digit.GetADCValue(1)-meanPed[pedindex+kNch]);
+       tZN2Corr[quad+5] = (Float_t) (digit.GetADCValue(1)-ped2SubLg);
        if(tZN2Corr[quad+5]<0.) tZN2Corr[quad+5] = 0.;
        //printf("\t pedindex %d tZN2Corr[%d] = %1.0f tZN2Corr[%d] = %1.0f\n", 
        //      pedindex, quad, tZN2Corr[quad], quad+5, tZN2Corr[quad+5]);
     }
     else if(det == 5){  // *** ZP2 
-       pedindex = quad+17;
-       tZP2Corr[quad] = (Float_t) (digit.GetADCValue(0)-meanPed[pedindex]);
+       tZP2Corr[quad] = (Float_t) (digit.GetADCValue(0)-ped2SubHg);
        if(tZP2Corr[quad]<0.) tZP2Corr[quad] = 0.;
-       tZP2Corr[quad+5] = (Float_t) (digit.GetADCValue(1)-meanPed[pedindex+kNch]);
+       tZP2Corr[quad+5] = (Float_t) (digit.GetADCValue(1)-ped2SubLg);
        if(tZP2Corr[quad+5]<0.) tZP2Corr[quad+5] = 0.;
        //printf("\t pedindex %d tZP2Corr[%d] = %1.0f tZP2Corr[%d] = %1.0f\n", 
        //      pedindex, quad, tZP2Corr[quad], quad+5, tZP2Corr[quad+5]);
     }
    }
    else{ // Reference PMs
-     pedindex = (det-1)/3+22;
      if(det == 1){
-       PMRef1[0] = (Float_t) (digit.GetADCValue(0)-meanPed[pedindex]);
+       PMRef1[0] = (Float_t) (digit.GetADCValue(0)-ped2SubHg);
        if(PMRef1[0]<0.) PMRef1[0] = 0.;
-       PMRef1[1] = (Float_t) (digit.GetADCValue(1)-meanPed[pedindex+kNch]);
+       PMRef1[1] = (Float_t) (digit.GetADCValue(1)-ped2SubLg);
        if(PMRef2[1]<0.) PMRef1[1] = 0.;
      }
      else if(det == 4){
-       PMRef2[0] = (Float_t) (digit.GetADCValue(0)-meanPed[pedindex]);
+       PMRef2[0] = (Float_t) (digit.GetADCValue(0)-ped2SubHg);
        if(PMRef2[0]<0.) PMRef2[0] = 0.;
-       PMRef2[1] = (Float_t) (digit.GetADCValue(1)-meanPed[pedindex+kNch]);
+       PMRef2[1] = (Float_t) (digit.GetADCValue(1)-ped2SubLg);
        if(PMRef2[1]<0.) PMRef2[1] = 0.;
      }
    }
   }
 
   // reconstruct the event
-  ReconstructEventpp(clustersTree, tZN1Corr, tZP1Corr, tZN2Corr, tZP2Corr, 
+  if(fRecoMode==0)
+    ReconstructEventpp(clustersTree, tZN1Corr, tZP1Corr, tZN2Corr, tZP2Corr, 
+       dZEM1Corr, dZEM2Corr, PMRef1, PMRef2);
+  else if(fRecoMode==1)
+    ReconstructEventPbPb(clustersTree, tZN1Corr, tZP1Corr, tZN2Corr, tZP2Corr, 
        dZEM1Corr, dZEM2Corr, PMRef1, PMRef2);
 
 }
@@ -181,8 +269,15 @@ void AliZDCReconstructor::Reconstruct(AliRawReader* rawReader, TTree* clustersTr
   // Works on the current event
   
   // Retrieving calibration data  
-  Float_t meanPed[48];
+  // Parameters for mean value pedestal subtraction
+  Float_t meanPed[48];    
   for(Int_t jj=0; jj<48; jj++) meanPed[jj] = fPedData->GetMeanPed(jj);
+  // Parameters pedestal subtraction through correlation with out-of-time signals
+  Float_t corrCoeff0[48], corrCoeff1[48];
+  for(Int_t jj=0; jj<48; jj++){
+     corrCoeff0[jj] =  fPedData->GetPedCorrCoeff0(jj);
+     corrCoeff1[jj] =  fPedData->GetPedCorrCoeff1(jj);
+  }
 
   rawReader->Reset();
   
@@ -195,8 +290,8 @@ void AliZDCReconstructor::Reconstruct(AliRawReader* rawReader, TTree* clustersTr
   }  
   //
   AliZDCRawStream rawData(rawReader);
-  Int_t kNch = 24;
-  while (rawData.Next()) {
+  Int_t const kNch = 24;
+  while(rawData.Next()) {
     if(rawData.IsADCDataWord()){
      Int_t det = rawData.GetSector(0);
      Int_t quad = rawData.GetSector(1);
@@ -253,7 +348,11 @@ void AliZDCReconstructor::Reconstruct(AliRawReader* rawReader, TTree* clustersTr
   }
     
   // reconstruct the event
-  ReconstructEventpp(clustersTree, tZN1Corr, tZP1Corr, tZN2Corr, tZP2Corr, 
+  if(fRecoMode==0)
+    ReconstructEventpp(clustersTree, tZN1Corr, tZP1Corr, tZN2Corr, tZP2Corr, 
+       dZEM1Corr, dZEM2Corr, PMRef1, PMRef2);
+  else if(fRecoMode==1)
+    ReconstructEventPbPb(clustersTree, tZN1Corr, tZP1Corr, tZN2Corr, tZP2Corr, 
        dZEM1Corr, dZEM2Corr, PMRef1, PMRef2);
 
 }
@@ -278,11 +377,8 @@ void AliZDCReconstructor::ReconstructEventpp(TTree *clustersTree, Float_t* ZN1AD
   }
   // --- Energy calibration factors ------------------------------------
   Float_t calibEne[4];
-  // *********************************************************************
-  // **** Until the beam type info isn't known @ reconstruction level ****
-  // **** the energy calibration coefficient are manually set to 1    ****
-  // **** as it will be in real life for pp data taking               ****
-  // *********************************************************************
+  // **** Energy calibration coefficient set to 1 
+  // **** (no trivial way to calibrate in p-p runs)
   //for(Int_t ij=0; ij<4; ij++) calibEne[ij] = fECalibData->GetEnCalib(ij);
   for(Int_t ij=0; ij<4; ij++) calibEne[ij] = 1.;
   
@@ -322,19 +418,18 @@ void AliZDCReconstructor::ReconstructEventpp(TTree *clustersTree, Float_t* ZN1AD
        calibSumZP2[1] += calibTowZP2[gi];
      }
   }
-
-  //
-  // --- Reconstruction parameters ------------------ 
-  if(!fRecoParam)  fRecoParam = (AliZDCRecoParampp*) AliZDCRecoParampp::GetppRecoParam();
   
   //  ---      Number of detected spectator nucleons
-  //  *** N.B. -> It works only in Pb-Pb
-  Int_t nDetSpecNLeft, nDetSpecPLeft, nDetSpecNRight, nDetSpecPRight;
-  Float_t beamE = fRecoParam->GetBeamEnergy();
-  nDetSpecNLeft = (Int_t) (calibSumZN1[0]/beamE);
-  nDetSpecPLeft = (Int_t) (calibSumZP1[0]/beamE);
-  nDetSpecNRight = (Int_t) (calibSumZN2[0]/beamE);
-  nDetSpecPRight = (Int_t) (calibSumZP2[0]/beamE);
+  //  *** N.B. -> It works only in Pb-Pb!!!!!!!!!!!!
+  //  Variables calculated to comply with ESD structure
+  Int_t nDetSpecNLeft=0, nDetSpecPLeft=0, nDetSpecNRight=0, nDetSpecPRight=0;
+  if(fBeamEnergy!=0){
+   nDetSpecNLeft = (Int_t) (calibSumZN1[0]/fBeamEnergy);
+   nDetSpecPLeft = (Int_t) (calibSumZP1[0]/fBeamEnergy);
+   nDetSpecNRight = (Int_t) (calibSumZN2[0]/fBeamEnergy);
+   nDetSpecPRight = (Int_t) (calibSumZP2[0]/fBeamEnergy);
+  }
+  else AliWarning(" ATTENTION -> fBeamEnergy = 0\n");
   /*printf("\n\t AliZDCReconstructor -> nDetSpecNLeft %d, nDetSpecPLeft %d,"
     " nDetSpecNRight %d, nDetSpecPRight %d\n",nDetSpecNLeft, nDetSpecPLeft, 
     nDetSpecNRight, nDetSpecPRight);*/
@@ -347,7 +442,7 @@ void AliZDCReconstructor::ReconstructEventpp(TTree *clustersTree, Float_t* ZN1AD
   
   // create the output tree
   AliZDCReco reco(calibSumZN1, calibSumZP1, calibSumZN2, calibSumZP2, 
-                 calibTowZN1, calibTowZN2, calibTowZP1, calibTowZP2, 
+                 calibTowZN1, calibTowZP1, calibTowZN2, calibTowZP2, 
                  ZEM1ADCCorr, ZEM2ADCCorr, PMRef1, PMRef2,
                  nDetSpecNLeft, nDetSpecPLeft, nDetSpecNRight, nDetSpecPRight, 
                  nGenSpecNLeft, nGenSpecPLeft, nGenSpecLeft, nGenSpecNRight, 
@@ -445,12 +540,14 @@ void AliZDCReconstructor::ReconstructEventPbPb(TTree *clustersTree, Float_t* ZN1
   
   //  ---      Number of detected spectator nucleons
   //  *** N.B. -> It works only in Pb-Pb
-  Int_t nDetSpecNLeft, nDetSpecPLeft, nDetSpecNRight, nDetSpecPRight;
-  Float_t beamE = fRecoParam->GetBeamEnergy();
-  nDetSpecNLeft = (Int_t) (calibSumZN1[0]/beamE);
-  nDetSpecPLeft = (Int_t) (calibSumZP1[0]/beamE);
-  nDetSpecNRight = (Int_t) (calibSumZN2[0]/beamE);
-  nDetSpecPRight = (Int_t) (calibSumZP2[0]/beamE);
+  Int_t nDetSpecNLeft=0, nDetSpecPLeft=0, nDetSpecNRight=0, nDetSpecPRight=0;
+  if(fBeamEnergy!=0){
+    nDetSpecNLeft = (Int_t) (calibSumZN1[0]/fBeamEnergy);
+    nDetSpecPLeft = (Int_t) (calibSumZP1[0]/fBeamEnergy);
+    nDetSpecNRight = (Int_t) (calibSumZN2[0]/fBeamEnergy);
+    nDetSpecPRight = (Int_t) (calibSumZP2[0]/fBeamEnergy);
+  }
+  else AliWarning(" ATTENTION -> fBeamEnergy = 0\n");
   /*printf("\n\t AliZDCReconstructor -> nDetSpecNLeft %d, nDetSpecPLeft %d,"
     " nDetSpecNRight %d, nDetSpecPRight %d\n",nDetSpecNLeft, nDetSpecPLeft, 
     nDetSpecNRight, nDetSpecPRight);*/
@@ -523,7 +620,7 @@ void AliZDCReconstructor::ReconstructEventPbPb(TTree *clustersTree, Float_t* ZN1
   
   // create the output tree
   AliZDCReco reco(calibSumZN1, calibSumZP1, calibSumZN2, calibSumZP2, 
-                 calibTowZN1, calibTowZN2, calibTowZP1, calibTowZP2, 
+                 calibTowZN1, calibTowZP1, calibTowZN2, calibTowZP2, 
                  ZEM1ADCCorr, ZEM2ADCCorr, PMRef1, PMRef2,
                  nDetSpecNLeft, nDetSpecPLeft, nDetSpecNRight, nDetSpecPRight, 
                  nGenSpecNLeft, nGenSpecPLeft, nGenSpecLeft, nGenSpecNRight, 
@@ -573,7 +670,7 @@ void AliZDCReconstructor::FillZDCintoESD(TTree *clustersTree, AliESDEvent* esd)
   // 
   esd->SetZDC(reco.GetZN1HREnergy(), reco.GetZP1HREnergy(), reco.GetZEM1HRsignal(), 
              reco.GetZEM2HRsignal(), reco.GetZN2HREnergy(), reco.GetZP2HREnergy(), 
-             reco.GetNPartLeft());
+             reco.GetNPartLeft(), reco.GetNPartRight());
   //
   
 }