]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TOF/AliTOFcalibHisto.cxx
Muon correction calculation added, kAnyINT changed to kAny.
[u/mrichter/AliRoot.git] / TOF / AliTOFcalibHisto.cxx
index 2c4cd36af9a00ad77cffed57a3f2c8499613c332..26452c4e8935e7dec682b4f8cb3a94db6f4025dd 100644 (file)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-/*************************************************************************
- *
- * AliTOFcalibHisto - class to handle TOF calibration histograms,
- *                    map histograms and more
- *
- * autors:   Roberto Preghenella (R+)
- * concacts: preghenella@bo.infn.it
- *
- *************************************************************************/
+// *
+// *
+// * AliTOFcalibHisto - class to handle TOF calibration histograms,
+// *                    map histograms and more
+// *
+// *
+// * autors:   Roberto Preghenella (R+)
+// * concacts: preghenella@bo.infn.it
+// *
+// *
 
 #include "AliTOFcalibHisto.h"
 #include "AliLog.h"
-#include "TH1F.h"
+#include "TH1D.h"
 #include "TFile.h"
 #include "AliTOFRawStream.h"
 #include "AliTOFCableLengthMap.h"
 #include "AliESDtrack.h"
 
+#define SLEW_TOTMIN 10.
+#define SLEW_TOTMAX 16.
+
 ClassImp(AliTOFcalibHisto)
 
 //__________________________________________________________________________
 
 TFile *AliTOFcalibHisto::fgCalibHistoFile = NULL;
 TFile *AliTOFcalibHisto::fgCalibParFile = NULL;
+TFile *AliTOFcalibHisto::fgCalibStatFile = NULL;
 
 //__________________________________________________________________________
 
 TString AliTOFcalibHisto::fgCalibHistoFileName = "$ALICE_ROOT/TOF/data/AliTOFcalibHisto.root";
 TString AliTOFcalibHisto::fgCalibParFileName = "$ALICE_ROOT/TOF/data/AliTOFcalibPar.root";
+TString AliTOFcalibHisto::fgCalibStatFileName = "$ALICE_ROOT/TOF/data/AliTOFcalibStat.root";
 
 //__________________________________________________________________________
 
@@ -87,31 +93,41 @@ const TString AliTOFcalibHisto::fgkCalibParName[kNcalibPars] = {
   "hLeftFEAchDelay",
   "hRightFEAchDelay",
   "hFEADelay",
+  "hICDelay",
   "hTRMDelay",
-  "hSlew"
+  "hStripDelay",
+  "hIndexDelay",
+  "hSlewing"
+};
+
+//__________________________________________________________________________
+
+const TString AliTOFcalibHisto::fgkCalibStatName[kNcalibStats] = {
+  "hStripStat"
 };
 
 //__________________________________________________________________________
 
 /* LHC clock period [ns] */
-const Float_t AliTOFcalibHisto::fgkLHCperiod = 25.; /* SET THE CORRECT VALUE !!! */
+const Double_t AliTOFcalibHisto::fgkLHCperiod = (24.4e-3 * 1024); /* ns */
 
 //__________________________________________________________________________
 
 /* Amphenol cable delay [ns/cm] */
-const Float_t AliTOFcalibHisto::fgkAmphenolCableDelay = 5.13e-2; /* from measurement */
+const Double_t AliTOFcalibHisto::fgkAmphenolCableDelay = 5.13e-2; /* from measurement */
 
 //__________________________________________________________________________
 
 /* flat cable delay [ns/cm] */
-//const Float_t AliTOFcalibHisto::fgkFlatCableDelay = 5.3e-2; /* from Amphenol 132-2829 series data-sheet */
-const Float_t AliTOFcalibHisto::fgkFlatCableDelay = 5.124e-2; /* from LHC08d calibration */
+//const Double_t AliTOFcalibHisto::fgkFlatCableDelay = 5.3e-2; /* from Amphenol 132-2829 series data-sheet */
+const Double_t AliTOFcalibHisto::fgkFlatCableDelay = 5.124e-2; /* from LHC08d calibration */
 
 //__________________________________________________________________________
 
 /* interface card delay [ns/cm] */
-//const Float_t AliTOFcalibHisto::fgkInterfaceCardDelay = 6.9e-2; /* from HyperLinx simulation */
-const Float_t AliTOFcalibHisto::fgkInterfaceCardDelay = 5.7898e-2; /* from LHC08d calibration */
+//const Double_t AliTOFcalibHisto::fgkInterfaceCardDelay = 6.9e-2; /* from HyperLinx simulation */
+//const Double_t AliTOFcalibHisto::fgkInterfaceCardDelay = 5.7898e-2; /* from LHC08d calibration */
+const Double_t AliTOFcalibHisto::fgkInterfaceCardDelay = 6.31360207815420404e-02; /* from LHC09c calibration */
 
 //__________________________________________________________________________
 
@@ -140,13 +156,13 @@ const Int_t AliTOFcalibHisto::fgkDDLBCshift[72] = {
   2, 2, -2, -2,
   2, 2, -1, -1,
   2, 2, -1, -1,
-  2, 2, -1, -1,
+  2, 2, -1, -1
 };
 
 //__________________________________________________________________________
 
 /* strip flat-cable length (preliminary) [cm] */
-const Float_t AliTOFcalibHisto::fgkFlatCableLength[91] = {
+const Double_t AliTOFcalibHisto::fgkFlatCableLength[91] = {
   18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 18., 17.,
   21., 21., 21., 21., 21., 17., 17., 21., 21., 17., 21., 21., 21., 17., 21., 21., 17., 21., 23.,
   17., 19., 17., 19., 17., 19., 17., 19., 17., 19., 17., 19., 17., 19., 17.,
@@ -157,7 +173,7 @@ const Float_t AliTOFcalibHisto::fgkFlatCableLength[91] = {
 //__________________________________________________________________________
 
 /* interface card lenght (preliminary) [cm] */
-const Float_t AliTOFcalibHisto::fgkInterfaceCardLength[48] = {
+const Double_t AliTOFcalibHisto::fgkInterfaceCardLength[48] = {
   13.97, 12.57, 14.52, 13.10, 15.44, 13.60, 10.58, 9.14, 
   11.21, 9.76, 12.11, 10.76, 8.67, 7.58, 9.32, 8.09,
   10.24, 8.4, 5.51, 4.31, 6.54, 5.23, 7.48, 6.28,
@@ -178,6 +194,9 @@ Bool_t AliTOFcalibHisto::fgCableCorrectionFlag[kNcorrections] = {
   kFALSE, // kFEAchDelayCorr
   kFALSE, // kFEAdelayCorr
   kFALSE, // kTRMdelayCorr
+  kFALSE, // kICdelayCorr
+  kFALSE, // kStripDelayCorr
+  kFALSE, // kIndexDelayCorr
   kFALSE, // kTimeSlewingCorr
 };
 
@@ -193,7 +212,124 @@ Bool_t AliTOFcalibHisto::fgFullCorrectionFlag[kNcorrections] = {
   kTRUE, // kFEAchDelayCorr
   kTRUE, // kFEAdelayCorr
   kTRUE, // kTRMdelayCorr
-  kFALSE, // kTimeSlewingCorr
+  kFALSE, // kICdelayCorr
+  kTRUE, // kStripDelayCorr
+  kTRUE, // kIndexDelayCorr
+  kTRUE, // kTimeSlewingCorr
+};
+
+//__________________________________________________________________________
+
+const Int_t AliTOFcalibHisto::fgkStripStat[18][91] = {
+
+  {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
+   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
+   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
+   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, /* S00 */
+  
+  {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
+   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
+   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
+   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, /* S01 */
+
+  {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
+   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
+   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
+   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, /* S02 */
+  
+  {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
+   1, 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1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
+   1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1,
+   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
+   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
+   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}  /* S17 */
+
 };
 
 //__________________________________________________________________________
@@ -202,7 +338,8 @@ AliTOFcalibHisto::AliTOFcalibHisto() :
   TObject(),
   fCalibConst(),
   fCalibMap(),
-  fCalibPar()
+  fCalibPar(),
+  fCalibStat()
 {
   /* default constructor */
 }
@@ -217,10 +354,10 @@ AliTOFcalibHisto::~AliTOFcalibHisto()
 //__________________________________________________________________________
 
 void 
-AliTOFcalibHisto::LoadHisto(TFile* file, TH1F **histo, const Char_t *name) 
+AliTOFcalibHisto::LoadHisto(TFile * const file, TH1D **histo, const Char_t *name) 
 {
   /* load histo */
-  *histo = (TH1F *)file->Get(name);
+  *histo = (TH1D *)file->Get(name);
   if (!*histo)
     AliWarning(Form("error while getting %s histo", name));
 }
@@ -228,10 +365,10 @@ AliTOFcalibHisto::LoadHisto(TFile* file, TH1F **histo, const Char_t *name)
 //__________________________________________________________________________
 
 void 
-AliTOFcalibHisto::CreateHisto(TH1F **histo, const Char_t *name, Int_t size) 
+AliTOFcalibHisto::CreateHisto(TH1D **histo, const Char_t *name, Int_t size) 
 {
   /* create histo */
-  *histo = new TH1F(name, Form(";index;%s", name), size, 0, size);
+  *histo = new TH1D(name, Form(";index;%s", name), size, 0, size);
   if (!*histo)
     AliWarning(Form("error while creating %s histo", name));
 }
@@ -239,7 +376,7 @@ AliTOFcalibHisto::CreateHisto(TH1F **histo, const Char_t *name, Int_t size)
 //__________________________________________________________________________
 
 void 
-AliTOFcalibHisto::WriteHisto(TFile *file, TH1F *histo) 
+AliTOFcalibHisto::WriteHisto(TFile *file, TH1D *histo) 
 {
   /* write histo */
   if (!file || !file->IsOpen() || !histo)
@@ -251,7 +388,7 @@ AliTOFcalibHisto::WriteHisto(TFile *file, TH1F *histo)
 //__________________________________________________________________________
 
 void
-AliTOFcalibHisto::SetHisto(TH1F *histo, Int_t index, Float_t value)
+AliTOFcalibHisto::SetHisto(TH1D *histo, Int_t index, Double_t value)
 {
   /* set histo */
   if (!histo)
@@ -261,8 +398,8 @@ AliTOFcalibHisto::SetHisto(TH1F *histo, Int_t index, Float_t value)
 
 //__________________________________________________________________________
 
-Float_t
-AliTOFcalibHisto::GetHisto(TH1F *histo, Int_t index)
+Double_t
+AliTOFcalibHisto::GetHisto(TH1D *histo, Int_t index)
 {
   /* get histo */
   if (!histo) {
@@ -284,8 +421,10 @@ AliTOFcalibHisto::LoadCalibHisto()
 
   /* open input file */
   TFile *fileIn = TFile::Open(GetCalibHistoFileName());
-  if (!fileIn || !fileIn->IsOpen())
+  if (!fileIn || !fileIn->IsOpen()) {
     AliFatal(Form("cannot open input file %s", GetCalibHistoFileName()));
+    return;
+  }
 
   /* set calib histo file */
   fgCalibHistoFile = fileIn;
@@ -313,8 +452,10 @@ AliTOFcalibHisto::LoadCalibPar()
 
   /* open input file */
   TFile *fileIn = TFile::Open(GetCalibParFileName());
-  if (!fileIn || !fileIn->IsOpen())
+  if (!fileIn || !fileIn->IsOpen()) {
     AliError(Form("cannot open input file %s", GetCalibParFileName()));
+    return;
+  }
 
   /* set calib par file */
   fgCalibParFile = fileIn;
@@ -327,6 +468,35 @@ AliTOFcalibHisto::LoadCalibPar()
 
 //__________________________________________________________________________
 
+void
+AliTOFcalibHisto::LoadCalibStat()
+{
+  /* load calib stat */
+
+  if (fgCalibStatFile && fgCalibStatFile->IsOpen())
+    AliWarning("calib par file already open: reloading"); 
+
+  /* load calib histo */
+  LoadCalibHisto();
+
+  /* open input file */
+  TFile *fileIn = TFile::Open(GetCalibStatFileName());
+  if (!fileIn || !fileIn->IsOpen()) {
+    AliError(Form("cannot open input file %s", GetCalibStatFileName()));
+    return;
+  }
+
+  /* set calib par file */
+  fgCalibStatFile = fileIn;
+
+  /* load pars */
+  for (Int_t i = 0; i < kNcalibStats; i++)
+    LoadHisto(fileIn, &fCalibStat[i], fgkCalibStatName[i].Data());
+
+}
+
+//__________________________________________________________________________
+
 void
 AliTOFcalibHisto::WriteCalibHisto()
 {
@@ -334,8 +504,10 @@ AliTOFcalibHisto::WriteCalibHisto()
 
   /* open output file */
   TFile *fileOut = TFile::Open(GetCalibHistoFileName(), "RECREATE");
-  if (!fileOut || !fileOut->IsOpen())
+  if (!fileOut || !fileOut->IsOpen()) {
     AliFatal(Form("cannot open output file %s", GetCalibHistoFileName()));
+    return;
+  }
 
   /* create consts */
   for (Int_t iConst = 0; iConst < kNcalibConsts; iConst++)
@@ -382,7 +554,7 @@ AliTOFcalibHisto::WriteCalibHisto()
            dummy = det[3]; det[3] = det[4]; det[4] = dummy;
            
            /* check detector indices */
-           if (det[0] < 0 || det[0] > 71 ||
+           if (det[0] < 0 || det[0] > 17 ||
                det[1] < 0 || det[1] > 4 ||
                det[2] < 0 || det[2] > 18 ||
                det[3] < 0 || det[3] > 1 ||
@@ -445,13 +617,54 @@ AliTOFcalibHisto::WriteCalibHisto()
 
 //__________________________________________________________________________
 
-Float_t
-AliTOFcalibHisto::GetCorrection(Int_t corr, Int_t index, Float_t tot)
+void
+AliTOFcalibHisto::WriteCalibStat()
+{
+  /* write calib stat */
+
+  /* open output file */
+  TFile *fileOut = TFile::Open(GetCalibStatFileName(), "RECREATE");
+  if (!fileOut || !fileOut->IsOpen()) {
+    AliFatal(Form("cannot open output file %s", GetCalibStatFileName()));
+    return;
+  }
+
+  /* create stats */
+  for (Int_t iStat = 0; iStat < kNcalibStats; iStat++)
+    CreateHisto(&fCalibStat[iStat], fgkCalibStatName[iStat].Data(), fgkNchannels);
+
+  /***  SETUP STATS  ***/
+
+  Int_t sector, sectorStrip;
+
+  /* load calib histo */
+  LoadCalibHisto();
+
+  /* loop over channels */
+  for (Int_t index = 0; index < fgkNchannels; index++) {
+    sector = (Int_t)GetCalibMap(kSector, index);
+    sectorStrip = (Int_t)GetCalibMap(kSectorStrip, index);
+    /* strip stat */
+    SetHisto(fCalibStat[kStripStat], index, (Double_t)fgkStripStat[sector][sectorStrip]);
+  } /* loop over channels */
+
+  /* write stats */
+  for (Int_t iStat = 0; iStat < kNcalibStats; iStat++)
+    WriteHisto(fileOut, fCalibStat[iStat]);
+
+  /* close output file */
+  fileOut->Close();
+}
+
+//__________________________________________________________________________
+
+Double_t
+AliTOFcalibHisto::GetCorrection(Int_t corr, Int_t index, Double_t tot)
 {
   /* apply correction */
 
-  Int_t ddl, chain, tdc, channel, hptdc, pbCh, feaIndex, sector, plate, strip, padx, trm;
-  Float_t slewing;
+  Int_t ddl, chain, tdc, channel, hptdc, pbCh, feaIndex, sector, plate, padx, trm, icIndex, sectorStrip;
+  Double_t slewing;
   
   switch (corr) {
   case kDDLBCcorr:
@@ -482,14 +695,26 @@ AliTOFcalibHisto::GetCorrection(Int_t corr, Int_t index, Float_t tot)
   case kFEAdelayCorr:
     sector = (Int_t)GetCalibMap(kSector, index);
     plate = (Int_t)GetCalibMap(kPlate, index);
-    strip = (Int_t)GetCalibMap(kStrip, index);
+    sectorStrip = (Int_t)GetCalibMap(kSectorStrip, index);
     padx = (Int_t)GetCalibMap(kPadX, index);
-    feaIndex = padx / 12 + 4 * strip + 4 * 19 * plate + 4 * 19 * 5 * sector;      
+    feaIndex = padx / 12 + 4 * sectorStrip + 364 * sector;      
     return GetCalibPar(kFEAdelayPar, feaIndex);
   case kTRMdelayCorr:
+    ddl = (Int_t)GetCalibMap(kDDL, index);
     trm = (Int_t)GetCalibMap(kTRM, index);
-    return GetCalibPar(kTRMdelayPar, trm);
+    return GetCalibPar(kTRMdelayPar, trm + 10 * ddl);
+  case kICdelayCorr:
+    icIndex = (Int_t)GetCalibMap(kInterfaceCardIndex, index);
+    return GetCalibPar(kICdelayPar, icIndex);
+  case kStripDelayCorr:
+    sector = (Int_t)GetCalibMap(kSector, index);
+    sectorStrip = (Int_t)GetCalibMap(kSectorStrip, index);
+    return GetCalibPar(kStripDelayPar, sectorStrip + 91 * sector);
+  case kIndexDelayCorr:
+    return GetCalibPar(kIndexDelayPar, index);
   case kTimeSlewingCorr:
+    tot = tot < SLEW_TOTMIN ? SLEW_TOTMIN : tot;
+    tot = tot > SLEW_TOTMAX ? SLEW_TOTMAX : tot;
     slewing = 0.;
     for (Int_t i = 0; i < fCalibPar[kTimeSlewingPar]->GetNbinsX(); i++)
       slewing += GetCalibPar(kTimeSlewingPar, i) * TMath::Power(tot, i);
@@ -502,11 +727,11 @@ AliTOFcalibHisto::GetCorrection(Int_t corr, Int_t index, Float_t tot)
 
 //__________________________________________________________________________
 
-Float_t
+Double_t
 AliTOFcalibHisto::GetNominalCorrection(Int_t index)
 {
   /* get nominal correction */
-  Float_t corr = 0;
+  Double_t corr = 0;
   for (Int_t iCorr = 0; iCorr < kNcorrections; iCorr++)
     corr += GetCorrection(iCorr, index);
   return corr;
@@ -527,11 +752,11 @@ AliTOFcalibHisto::ApplyNominalCorrection(AliESDtrack *track)
 
 //__________________________________________________________________________
 
-Float_t
+Double_t
 AliTOFcalibHisto::GetCableCorrection(Int_t index)
 {
   /* get cable correction */
-  Float_t corr = 0;
+  Double_t corr = 0;
   for (Int_t iCorr = 0; iCorr < kNcorrections; iCorr++)
     if (fgCableCorrectionFlag[iCorr])
       corr += GetCorrection(iCorr, index);
@@ -540,14 +765,29 @@ AliTOFcalibHisto::GetCableCorrection(Int_t index)
 
 //__________________________________________________________________________
 
-Float_t
-AliTOFcalibHisto::GetFullCorrection(Int_t index)
+Double_t
+AliTOFcalibHisto::GetFullCorrection(Int_t index, Double_t tot)
 {
   /* get full correction */
-  Float_t corr = 0;
+  Double_t corr = 0;
   for (Int_t iCorr = 0; iCorr < kNcorrections; iCorr++)
-    if (fgFullCorrectionFlag[iCorr])
-      corr += GetCorrection(iCorr, index);
+    if (fgFullCorrectionFlag[iCorr]) {
+      corr += GetCorrection(iCorr, index, tot);
+    }
   return corr;
 }
 
+//__________________________________________________________________________
+
+Bool_t
+AliTOFcalibHisto::GetStatus(Int_t index)
+{
+  /* get status */
+
+  Bool_t status = kTRUE;
+
+  for (Int_t iStat = 0; iStat < kNcalibStats; iStat++)
+    status &= GetCalibStat(iStat, index);
+
+  return status;
+}