]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TOF/AliTOFAnalysisTaskCalibPass0.cxx
Update Balance Function correction Maps (Alis Rodriguez Manso <alisrm@nikhef.nl>)
[u/mrichter/AliRoot.git] / TOF / AliTOFAnalysisTaskCalibPass0.cxx
index 95c615ba1f10762a1e94f8574c0d6586e19580d9..e88d97c01e541b3fc8098f50340929a5de8aa4df 100644 (file)
@@ -51,14 +51,27 @@ ClassImp(AliTOFAnalysisTaskCalibPass0)
   
 //_______________________________________________________
 
+const Char_t *AliTOFAnalysisTaskCalibPass0::fgkStatusCodeName[AliTOFAnalysisTaskCalibPass0::kNStatusCodes] = {
+  "ok",
+  "input error",
+  "data error",
+  "not active",
+  "low statistics",
+  "no measurement",
+  "store error"
+};
+
 const Int_t AliTOFAnalysisTaskCalibPass0::fgkMaxNumberOfPoints = 10000; // max number of points
-const Double_t AliTOFAnalysisTaskCalibPass0::fgkMinVertexIntegral = 1000.;
-const Double_t AliTOFAnalysisTaskCalibPass0::fgkMinDeltatIntegral = 20000.;
+Double_t AliTOFAnalysisTaskCalibPass0::fgMinVertexIntegral = 100.;
+Double_t AliTOFAnalysisTaskCalibPass0::fgMinDeltatIntegral = 2000.;
+Double_t AliTOFAnalysisTaskCalibPass0::fgMinVertexIntegralSample = 1000.;
+Double_t AliTOFAnalysisTaskCalibPass0::fgMinDeltatIntegralSample = 20000.;
 
 //_______________________________________________________
   
 AliTOFAnalysisTaskCalibPass0::AliTOFAnalysisTaskCalibPass0() :
   AliAnalysisTaskSE("TOFCalib-Pass0"),
+  fStatus(kOk),
   fInitFlag(kFALSE),
   fEventSelectionFlag(kFALSE),
   fVertexSelectionFlag(kFALSE),
@@ -156,13 +169,15 @@ AliTOFAnalysisTaskCalibPass0::InitRun()
   fInitFlag = kTRUE;
   fRunNumber = runNb;
   
+  Int_t useBPTX = fTOFcalib->GetUseLHCClockPhase() ? 1 : 0;
+
   /* set histo title with run-number and start-time */
-  fHistoVertexTimestamp->SetTitle(Form("run: %d, startTimestamp: %u", fRunNumber, fStartTime));
-  fHistoDeltatTimestamp->SetTitle(Form("run: %d, startTimestamp: %u", fRunNumber, fStartTime));
-  fHistoDeltazEta->SetTitle(Form("run: %d, startTimestamp: %u", fRunNumber, fStartTime));
-  fHistoDeltazCosTheta->SetTitle(Form("run: %d, startTimestamp: %u", fRunNumber, fStartTime));
-  fHistoAcceptedTracksEtaPt->SetTitle(Form("run: %d, startTimestamp: %u", fRunNumber, fStartTime));
-  fHistoMatchedTracksEtaPt->SetTitle(Form("run: %d, startTimestamp: %u", fRunNumber, fStartTime));
+  fHistoVertexTimestamp->SetTitle(Form("run: %d, startTimestamp: %u, BPTX: %d", fRunNumber, fStartTime, useBPTX));
+  fHistoDeltatTimestamp->SetTitle(Form("run: %d, startTimestamp: %u, BPTX: %d", fRunNumber, fStartTime, useBPTX));
+  fHistoDeltazEta->SetTitle(Form("run: %d, startTimestamp: %u, BPTX: %d", fRunNumber, fStartTime, useBPTX));
+  fHistoDeltazCosTheta->SetTitle(Form("run: %d, startTimestamp: %u, BPTX: %d", fRunNumber, fStartTime, useBPTX));
+  fHistoAcceptedTracksEtaPt->SetTitle(Form("run: %d, startTimestamp: %u, BPTX: %d", fRunNumber, fStartTime, useBPTX));
+  fHistoMatchedTracksEtaPt->SetTitle(Form("run: %d, startTimestamp: %u, BPTX: %d", fRunNumber, fStartTime, useBPTX));
   
   return kTRUE;
 }
@@ -334,17 +349,97 @@ AliTOFAnalysisTaskCalibPass0::UserExec(Option_t *)
 
 //_______________________________________________________
 
+Int_t
+AliTOFAnalysisTaskCalibPass0::GetStatus()
+{
+  /*
+   * get status
+   */
+
+  switch (fStatus) {
+
+    /* OK, return zero */
+  case kOk:
+    return 0;
+    break;
+    
+    /* non-fatal error, return negative status */
+  case kNotActive:
+  case kLowStatistics:
+  case kNoMeasurement:
+    return -fStatus;
+    break;
+    
+    /* fatal error, return positive status */
+  case kInputError: 
+  case kDataError:
+  case kStoreError:
+    return fStatus;
+    break;
+
+    /* anything else, return negative large number */
+  default:
+    return -999;
+    break;
+  }
+  
+  /* should never arrive here, anyway return negative large number */
+  return -999;
+}
+
+//_______________________________________________________
+
+void
+AliTOFAnalysisTaskCalibPass0::PrintStatus()
+{
+  /*
+   * print status
+   */
+
+  Int_t status = GetStatus();
+  if (status == 0) {
+    AliInfo(Form("TOF calibration successful: %s (status=%d)", fgkStatusCodeName[fStatus], status));
+  }
+  else if (status > 0) {
+    AliInfo(Form("TOF calibration failed: %s (status=%d)", fgkStatusCodeName[fStatus], status));
+  }
+  else if (status < 0) {
+    AliInfo(Form("TOF calibration failed (expected): %s (status=%d)", fgkStatusCodeName[fStatus], status));
+  }
+  
+}
+
+//_______________________________________________________
+
 Bool_t
-AliTOFAnalysisTaskCalibPass0::ProcessOutput(const Char_t *filename, const Char_t *dbString)
+AliTOFAnalysisTaskCalibPass0::ProcessOutput(const Char_t *filename, AliCDBStorage* db)
 {
   /*
    * process output
    */
 
+  Int_t ret = DoProcessOutput(filename, db);
+  PrintStatus();
+  return ret;
+}
+
+//_______________________________________________________
+
+Bool_t
+AliTOFAnalysisTaskCalibPass0::DoProcessOutput(const Char_t *filename, AliCDBStorage *db)
+{
+  /*
+   * do process output
+   */
+
+  /* reset status to OK */
+  fStatus = kOk;
+
   /* open file */
   TFile *file = TFile::Open(filename);
   if (!file || !file->IsOpen()) {
     AliError(Form("cannot open output file %s", filename));
+    fStatus = kInputError;
     return kFALSE;
   }
   /* get histograms */
@@ -376,35 +471,42 @@ AliTOFAnalysisTaskCalibPass0::ProcessOutput(const Char_t *filename, const Char_t
   /* check histos */ 
   if (!histoVertexTimestamp) {
     AliError(Form("cannot get \"hHistoVertexTimestamp\" object from file %s", filename));
+    fStatus = kInputError;
     return kFALSE;
   }
   if (!histoDeltatTimestamp) {
     AliError(Form("cannot get \"hHistoDeltatTimestamp\" object from file %s", filename));
+    fStatus = kInputError;
     return kFALSE;
   }
   if (!histoDeltazEta) {
     AliError(Form("cannot get \"hHistoDeltazEta\" object from file %s", filename));
+    fStatus = kInputError;
     return kFALSE;
   }
   if (!histoDeltazCosTheta) {
     AliError(Form("cannot get \"hHistoDeltazCosTheta\" object from file %s", filename));
+    fStatus = kInputError;
     return kFALSE;
   }
   if (!histoAcceptedTracksEtaPt) {
     AliError(Form("cannot get \"hHistoAccptedTracksEtaPt\" object from file %s", filename));
+    fStatus = kInputError;
     return kFALSE;
   }
   if (!histoMatchedTracksEtaPt) {
     AliError(Form("cannot get \"hHistoMatchedTracksEtaPt\" object from file %s", filename));
+    fStatus = kInputError;
     return kFALSE;
   }
+
   /* check matching performance */
   if (!CheckMatchingPerformance(histoDeltazEta, histoAcceptedTracksEtaPt, histoMatchedTracksEtaPt)) {
     AliError("error while checking matching efficiency");
     return kFALSE;
   }
   /* calibrate and store */
-  if (!CalibrateAndStore(histoVertexTimestamp, histoDeltatTimestamp, dbString)) {
+  if (!CalibrateAndStore(histoVertexTimestamp, histoDeltatTimestamp, db)) {
     AliError("error while calibrating and storing");
     return kFALSE;
   }
@@ -432,7 +534,7 @@ AliTOFAnalysisTaskCalibPass0::CheckMatchingPerformance(const TH2F *histoDeltazCo
 //_______________________________________________________
 
 Bool_t
-AliTOFAnalysisTaskCalibPass0::CalibrateAndStore(TH2F *histoVertexTimestamp, TH2F *histoDeltatTimestamp, const Char_t *dbString)
+AliTOFAnalysisTaskCalibPass0::CalibrateAndStore(TH2F *histoVertexTimestamp, TH2F *histoDeltatTimestamp, AliCDBStorage *db)
 {
   /*
    * calibrate and store
@@ -451,6 +553,7 @@ AliTOFAnalysisTaskCalibPass0::CalibrateAndStore(TH2F *histoVertexTimestamp, TH2F
   strarr = str.Tokenize(",");
   if (!strarr) {
     AliError("problems whith tokenize histogram title");
+    fStatus = kDataError;
     return kFALSE;
   }
   
@@ -458,17 +561,23 @@ AliTOFAnalysisTaskCalibPass0::CalibrateAndStore(TH2F *histoVertexTimestamp, TH2F
   ostr = (TObjString *)strarr->At(0);
   if (!ostr) {
     AliError("problems while getting run number from histogram title");
+    fStatus = kDataError;
+    delete strarr;
     return kFALSE;
   }
   str = ostr->GetString();
   if (!str.BeginsWith("run:")) {
     AliError("problems while getting run number from histogram title");
+    fStatus = kDataError;
+    delete strarr;
     return kFALSE;
   }
   str.Remove(0, 5);
   Int_t runNb = atoi(str.Data());
   if (runNb <= 0) {
     AliError(Form("bad run number: %d", runNb));
+    fStatus = kDataError;
+    delete strarr;
     return kFALSE;
   }
   AliInfo(Form("got run number: %d", runNb));
@@ -477,23 +586,51 @@ AliTOFAnalysisTaskCalibPass0::CalibrateAndStore(TH2F *histoVertexTimestamp, TH2F
   ostr = (TObjString *)strarr->At(1);
   if (!ostr) {
     AliError("problems while getting start timestamp from histogram title");
+    fStatus = kDataError;
+    delete strarr;
     return kFALSE;
   }
   str = ostr->GetString();
   str.Remove(0, 1); /* remove empty space at the beginning */
   if (!str.BeginsWith("startTimestamp:")) {
     AliError("problems while getting start timestamp from histogram title");
+    fStatus = kDataError;
+    delete strarr;
     return kFALSE;
   }
   str.Remove(0, 16);
   UInt_t startTimestamp = atoi(str.Data());
   if (startTimestamp <= 0) {
     AliError(Form("bad start timestamp: %d", startTimestamp));
+    fStatus = kDataError;
+    delete strarr;
     return kFALSE;
   }
   TTimeStamp ts = startTimestamp;
   AliInfo(Form("got start timestamp: %d (%s)", startTimestamp, ts.AsString()));
 
+  /* BPTX */
+  ostr = (TObjString *)strarr->At(2);
+  if (!ostr) {
+    AliError("problems while getting BPTX from histogram title");
+    fStatus = kDataError;
+    delete strarr;
+    return kFALSE;
+  }
+  str = ostr->GetString();
+  str.Remove(0, 1); /* remove empty space at the beginning */
+  if (!str.BeginsWith("BPTX:")) {
+    AliError("problems while getting BPTX from histogram title");
+    fStatus = kDataError;
+    delete strarr;
+    return kFALSE;
+  }
+  str.Remove(0, 6);
+  Bool_t useBPTX = atoi(str.Data());
+  AliInfo(Form("got BPTX: %d", useBPTX));
+
+  delete strarr;
+
   /*** CALIBRATION STAGE ***/
 
   /* get fit function */
@@ -503,6 +640,13 @@ AliTOFAnalysisTaskCalibPass0::CalibrateAndStore(TH2F *histoVertexTimestamp, TH2F
   TH1D *histoVertexTimestamppx = histoVertexTimestamp->ProjectionX("histoVertexTimestamppx");
   TH1D *histoDeltatTimestamppx = histoDeltatTimestamp->ProjectionX("histoDeltatTimestamppx");
 
+  /* check statistics */
+  if (histoVertexTimestamppx->Integral() < fgMinVertexIntegral ||
+      histoDeltatTimestamppx->Integral() < fgMinDeltatIntegral) {
+    fStatus = kLowStatistics;
+    return kFALSE;
+  }
+
   /* define mix and max time bin */
   Int_t minBin = histoVertexTimestamppx->FindFirstBinAbove(0);
   Int_t maxBin = histoVertexTimestamppx->FindLastBinAbove(0);
@@ -525,14 +669,14 @@ AliTOFAnalysisTaskCalibPass0::CalibrateAndStore(TH2F *histoVertexTimestamp, TH2F
     /* define time window */
     Int_t startBin = ibin;
     Int_t endBin = ibin;
-    while(histoVertexTimestamppx->Integral(startBin, endBin) < fgkMinVertexIntegral ||
-         histoDeltatTimestamppx->Integral(startBin, endBin) < fgkMinDeltatIntegral) {
+    while(histoVertexTimestamppx->Integral(startBin, endBin) < fgMinVertexIntegralSample ||
+         histoDeltatTimestamppx->Integral(startBin, endBin) < fgMinDeltatIntegralSample) {
       if (endBin < maxBin) endBin++;
       else if (startBin > minBin) startBin--;
       else break;
     }
-    if (histoVertexTimestamppx->Integral(startBin, endBin) <= 0 ||
-        histoDeltatTimestamppx->Integral(startBin, endBin) <= 0) continue;
+    if (histoVertexTimestamppx->Integral(startBin, endBin) < fgMinVertexIntegral ||
+        histoDeltatTimestamppx->Integral(startBin, endBin) < fgMinDeltatIntegral) continue;
     Float_t startTime = histoVertexTimestamppx->GetBinLowEdge(startBin);
     Float_t endTime = histoVertexTimestamppx->GetBinLowEdge(endBin + 1);
     Float_t vertexIntegral = histoVertexTimestamppx->Integral(startBin, endBin);
@@ -594,6 +738,7 @@ AliTOFAnalysisTaskCalibPass0::CalibrateAndStore(TH2F *histoVertexTimestamp, TH2F
   /* check points */
   if (nPoints <= 0) {
     AliError("no measurement available, quit");
+    fStatus = kNoMeasurement;
     return kFALSE;
   }
   AliInfo(Form("average time-zero  = %f", averageTimeZero / nPoints));
@@ -644,29 +789,27 @@ AliTOFAnalysisTaskCalibPass0::CalibrateAndStore(TH2F *histoVertexTimestamp, TH2F
   obj.SetRunNb(run);
   obj.SetRunFirstPoint(runFirstPoint);
   obj.SetRunLastPoint(runLastPoint);
+  obj.SetUseLHCClockPhase(useBPTX);
   
   /*** CREATE OCDB ENTRY ***/
 
-  if (!dbString) {
-    AliError("cannot store object because of NULL string");
+  if (!db) {
+    AliError("cannot store object because of NULL storage");
+    fStatus = kStoreError;
     return kFALSE;
   }
 
   /* install run params object in OCDB */
-  AliCDBManager *cdb = AliCDBManager::Instance();
-  AliCDBStorage *sto = cdb->GetStorage(dbString);
-  if (!sto) {
-    AliError(Form("cannot get storage %s", dbString));
-    return kFALSE;
-  }
   AliCDBId id("TOF/Calib/RunParams", runNb, runNb);
   AliCDBMetaData md;
   md.SetResponsible("Roberto Preghenella");
   md.SetComment("offline TOF run parameters");
   md.SetAliRootVersion(gSystem->Getenv("ARVERSION"));
   md.SetBeamPeriod(0);
-  if (!sto->Put(&obj, id, &md)) {
-    AliError(Form("error while putting object in storage %s", dbString));
+  if (!db->Put(&obj, id, &md)) {
+    fStatus = kStoreError;
+    AliError(Form("error while putting object in storage %s", db->GetURI().Data()));
+    return kFALSE;
   }
 
   /* success */