]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TOF/AliTOFAnalysisTaskCalibPass0.cxx
first version of a bash utilities lib
[u/mrichter/AliRoot.git] / TOF / AliTOFAnalysisTaskCalibPass0.cxx
index 7f857aac2b31a5346a0d1c29c4adfa4f91a40a85..73715b4e529bd1b2507641ef9ee5bd72a2f62209 100644 (file)
@@ -92,6 +92,7 @@ AliTOFAnalysisTaskCalibPass0::AliTOFAnalysisTaskCalibPass0() :
   fHistoVertexTimestamp(NULL),
   fHistoDeltatTimestamp(NULL),
   fHistoDeltazEta(NULL),
+  fHistoDeltatEta(NULL),
   fHistoDeltazCosTheta(NULL),
   fHistoAcceptedTracksEtaPt(NULL),
   fHistoMatchedTracksEtaPt(NULL)
@@ -169,13 +170,16 @@ 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));
+  fHistoDeltatEta->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;
 }
@@ -272,6 +276,9 @@ AliTOFAnalysisTaskCalibPass0::UserCreateOutputObjects()
   fHistoDeltazEta = new TH2F("hHistoDeltazEta", "Matching residuals (longitudinal);#eta;#Deltaz (cm);", etaBins, etaMin, etaMax, deltazBins, deltazMin, deltazMax);
   fHistoList->Add(fHistoDeltazEta);
 
+  fHistoDeltatEta = new TH2F("hHistoDeltatEta", "Global time shift (T0-fill) vs #eta; #eta; t - t_{exp}^{(#pi)} (ps);", etaBins, etaMin, etaMax, deltatBins, deltatMin, deltatMax);
+  fHistoList->Add(fHistoDeltatEta);
+
   fHistoDeltazCosTheta = new TH2F("hHistoDeltazCosTheta", "Matching residuals (longitudinal);cos #theta;#Deltaz (cm);", etaBins, etaMin, etaMax, deltazBins, deltazMin, deltazMax);
   fHistoList->Add(fHistoDeltazCosTheta);
 
@@ -307,7 +314,7 @@ AliTOFAnalysisTaskCalibPass0::UserExec(Option_t *)
   /* loop over ESD tracks */
   Int_t nTracks = fESDEvent->GetNumberOfTracks();
   AliESDtrack *track;
-  Double_t eta, costheta, pt, time, timei[AliPID::kSPECIES], deltat, deltaz;
+  Double_t eta, costheta, pt, time, timei[AliPID::kSPECIESC], deltat, deltaz;
   for (Int_t itrk = 0; itrk < nTracks; itrk++) {
     /* get track */
     track = fESDEvent->GetTrack(itrk);
@@ -336,6 +343,7 @@ AliTOFAnalysisTaskCalibPass0::UserExec(Option_t *)
     /* fill histos */
     fHistoDeltatTimestamp->Fill(fElapsedTime, deltat);
     fHistoDeltazEta->Fill(eta, deltaz);
+    fHistoDeltatEta->Fill(eta, deltat);
     fHistoDeltazCosTheta->Fill(costheta, deltaz);
     
   } /* end of loop over ESD tracks */
@@ -387,14 +395,13 @@ AliTOFAnalysisTaskCalibPass0::GetStatus()
 
 //_______________________________________________________
 
-Bool_t
-AliTOFAnalysisTaskCalibPass0::ProcessOutput(const Char_t *filename, const Char_t *dbString)
+void
+AliTOFAnalysisTaskCalibPass0::PrintStatus()
 {
   /*
-   * process output
+   * print status
    */
 
-  Int_t ret = DoProcessOutput(filename, dbString);
   Int_t status = GetStatus();
   if (status == 0) {
     AliInfo(Form("TOF calibration successful: %s (status=%d)", fgkStatusCodeName[fStatus], status));
@@ -406,13 +413,26 @@ AliTOFAnalysisTaskCalibPass0::ProcessOutput(const Char_t *filename, const Char_t
     AliInfo(Form("TOF calibration failed (expected): %s (status=%d)", fgkStatusCodeName[fStatus], status));
   }
   
+}
+
+//_______________________________________________________
+
+Bool_t
+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, const Char_t *dbString)
+AliTOFAnalysisTaskCalibPass0::DoProcessOutput(const Char_t *filename, AliCDBStorage *db)
 {
   /*
    * do process output
@@ -433,6 +453,7 @@ AliTOFAnalysisTaskCalibPass0::DoProcessOutput(const Char_t *filename, const Char
   TH2F *histoVertexTimestamp = NULL;
   TH2F *histoDeltatTimestamp = NULL;
   TH2F *histoDeltazEta = NULL;
+  TH2F *histoDeltatEta = NULL;
   TH2F *histoDeltazCosTheta = NULL;
   TH2F *histoAcceptedTracksEtaPt = NULL;
   TH2F *histoMatchedTracksEtaPt = NULL;
@@ -441,6 +462,7 @@ AliTOFAnalysisTaskCalibPass0::DoProcessOutput(const Char_t *filename, const Char
     histoVertexTimestamp = (TH2F *)list->FindObject("hHistoVertexTimestamp");
     histoDeltatTimestamp = (TH2F *)list->FindObject("hHistoDeltatTimestamp");
     histoDeltazEta = (TH2F *)list->FindObject("hHistoDeltazEta");
+    histoDeltatEta = (TH2F *)list->FindObject("hHistoDeltatEta");
     histoDeltazCosTheta = (TH2F *)list->FindObject("hHistoDeltazCosTheta");
     histoAcceptedTracksEtaPt = (TH2F *)list->FindObject("hHistoAcceptedTracksEtaPt");
     histoMatchedTracksEtaPt = (TH2F *)list->FindObject("hHistoMatchedTracksEtaPt");
@@ -450,6 +472,7 @@ AliTOFAnalysisTaskCalibPass0::DoProcessOutput(const Char_t *filename, const Char
     histoVertexTimestamp = (TH2F *)file->Get("hHistoVertexTimestamp");
     histoDeltatTimestamp = (TH2F *)file->Get("hHistoDeltatTimestamp");
     histoDeltazEta = (TH2F *)file->Get("hHistoDeltazEta");
+    histoDeltatEta = (TH2F *)file->Get("hHistoDeltatEta");
     histoDeltazCosTheta = (TH2F *)file->Get("hHistoDeltazCosTheta");
     histoAcceptedTracksEtaPt = (TH2F *)file->Get("hHistoAcceptedTracksEtaPt");
     histoMatchedTracksEtaPt = (TH2F *)file->Get("hHistoMatchedTracksEtaPt");
@@ -458,45 +481,161 @@ AliTOFAnalysisTaskCalibPass0::DoProcessOutput(const Char_t *filename, const Char
   if (!histoVertexTimestamp) {
     AliError(Form("cannot get \"hHistoVertexTimestamp\" object from file %s", filename));
     fStatus = kInputError;
+    if (list)
+      delete list;
+    else {
+      if (histoVertexTimestamp) delete histoVertexTimestamp;
+      if (histoDeltatTimestamp )delete histoDeltatTimestamp;
+      if (histoDeltazEta) delete histoDeltazEta;
+      if (histoDeltatEta) delete histoDeltatEta;
+      if (histoDeltazCosTheta) delete histoDeltazCosTheta;
+      if (histoAcceptedTracksEtaPt) delete histoAcceptedTracksEtaPt;
+      if (histoMatchedTracksEtaPt) delete histoMatchedTracksEtaPt;
+    }
     return kFALSE;
   }
   if (!histoDeltatTimestamp) {
     AliError(Form("cannot get \"hHistoDeltatTimestamp\" object from file %s", filename));
     fStatus = kInputError;
+    if (list)
+      delete list;
+    else{
+      if (histoVertexTimestamp) delete histoVertexTimestamp;
+      if (histoDeltatTimestamp )delete histoDeltatTimestamp;
+      if (histoDeltazEta) delete histoDeltazEta;
+      if (histoDeltatEta) delete histoDeltatEta;
+      if (histoDeltazCosTheta) delete histoDeltazCosTheta;
+      if (histoAcceptedTracksEtaPt) delete histoAcceptedTracksEtaPt;
+      if (histoMatchedTracksEtaPt) delete histoMatchedTracksEtaPt;
+    }
     return kFALSE;
   }
   if (!histoDeltazEta) {
     AliError(Form("cannot get \"hHistoDeltazEta\" object from file %s", filename));
     fStatus = kInputError;
+    if (list)
+      delete list;
+    else{
+      if (histoVertexTimestamp) delete histoVertexTimestamp;
+      if (histoDeltatTimestamp )delete histoDeltatTimestamp;
+      if (histoDeltazEta) delete histoDeltazEta;
+      if (histoDeltatEta) delete histoDeltatEta;
+      if (histoDeltazCosTheta) delete histoDeltazCosTheta;
+      if (histoAcceptedTracksEtaPt) delete histoAcceptedTracksEtaPt;
+      if (histoMatchedTracksEtaPt) delete histoMatchedTracksEtaPt;
+    }
+    return kFALSE;
+  }
+  if (!histoDeltatEta) {
+    AliError(Form("cannot get \"hHistoDeltatEta\" object from file %s", filename));
+    fStatus = kInputError;
+    if (list)
+      delete list;
+    else{
+      if (histoVertexTimestamp) delete histoVertexTimestamp;
+      if (histoDeltatTimestamp )delete histoDeltatTimestamp;
+      if (histoDeltazEta) delete histoDeltazEta;
+      if (histoDeltatEta) delete histoDeltatEta;
+      if (histoDeltazCosTheta) delete histoDeltazCosTheta;
+      if (histoAcceptedTracksEtaPt) delete histoAcceptedTracksEtaPt;
+      if (histoMatchedTracksEtaPt) delete histoMatchedTracksEtaPt;
+    }
     return kFALSE;
   }
   if (!histoDeltazCosTheta) {
     AliError(Form("cannot get \"hHistoDeltazCosTheta\" object from file %s", filename));
     fStatus = kInputError;
+    if (list)
+      delete list;
+    else{
+      if (histoVertexTimestamp) delete histoVertexTimestamp;
+      if (histoDeltatTimestamp )delete histoDeltatTimestamp;
+      if (histoDeltazEta) delete histoDeltazEta;
+      if (histoDeltatEta) delete histoDeltatEta;
+      if (histoDeltazCosTheta) delete histoDeltazCosTheta;
+      if (histoAcceptedTracksEtaPt) delete histoAcceptedTracksEtaPt;
+      if (histoMatchedTracksEtaPt) delete histoMatchedTracksEtaPt;
+    }
     return kFALSE;
   }
   if (!histoAcceptedTracksEtaPt) {
     AliError(Form("cannot get \"hHistoAccptedTracksEtaPt\" object from file %s", filename));
     fStatus = kInputError;
+    if (list)
+      delete list;
+    else{
+      if (histoVertexTimestamp) delete histoVertexTimestamp;
+      if (histoDeltatTimestamp )delete histoDeltatTimestamp;
+      if (histoDeltazEta) delete histoDeltazEta;
+      if (histoDeltatEta) delete histoDeltatEta;
+      if (histoDeltazCosTheta) delete histoDeltazCosTheta;
+      if (histoAcceptedTracksEtaPt) delete histoAcceptedTracksEtaPt;
+      if (histoMatchedTracksEtaPt) delete histoMatchedTracksEtaPt;
+    }
     return kFALSE;
   }
   if (!histoMatchedTracksEtaPt) {
     AliError(Form("cannot get \"hHistoMatchedTracksEtaPt\" object from file %s", filename));
     fStatus = kInputError;
+    if (list)
+      delete list;
+    else{
+      if (histoVertexTimestamp) delete histoVertexTimestamp;
+      if (histoDeltatTimestamp )delete histoDeltatTimestamp;
+      if (histoDeltazEta) delete histoDeltazEta;
+      if (histoDeltatEta) delete histoDeltatEta;
+      if (histoDeltazCosTheta) delete histoDeltazCosTheta;
+      if (histoAcceptedTracksEtaPt) delete histoAcceptedTracksEtaPt;
+      if (histoMatchedTracksEtaPt) delete histoMatchedTracksEtaPt;
+    }
     return kFALSE;
   }
 
   /* check matching performance */
   if (!CheckMatchingPerformance(histoDeltazEta, histoAcceptedTracksEtaPt, histoMatchedTracksEtaPt)) {
     AliError("error while checking matching efficiency");
+    if (list)
+      delete list;
+    else{
+      if (histoVertexTimestamp) delete histoVertexTimestamp;
+      if (histoDeltatTimestamp )delete histoDeltatTimestamp;
+      if (histoDeltazEta) delete histoDeltazEta;
+      if (histoDeltatEta) delete histoDeltatEta;
+      if (histoDeltazCosTheta) delete histoDeltazCosTheta;
+      if (histoAcceptedTracksEtaPt) delete histoAcceptedTracksEtaPt;
+      if (histoMatchedTracksEtaPt) delete histoMatchedTracksEtaPt;
+    }
     return kFALSE;
   }
   /* calibrate and store */
-  if (!CalibrateAndStore(histoVertexTimestamp, histoDeltatTimestamp, dbString)) {
+  if (!CalibrateAndStore(histoVertexTimestamp, histoDeltatTimestamp, db)) {
     AliError("error while calibrating and storing");
+    if (list)
+      delete list;
+    else{
+      if (histoVertexTimestamp) delete histoVertexTimestamp;
+      if (histoDeltatTimestamp )delete histoDeltatTimestamp;
+      if (histoDeltazEta) delete histoDeltazEta;
+      if (histoDeltatEta) delete histoDeltatEta;
+      if (histoDeltazCosTheta) delete histoDeltazCosTheta;
+      if (histoAcceptedTracksEtaPt) delete histoAcceptedTracksEtaPt;
+      if (histoMatchedTracksEtaPt) delete histoMatchedTracksEtaPt;
+    }
     return kFALSE;
   }
 
+  if (list)
+    delete list;
+  else{
+    if (histoVertexTimestamp) delete histoVertexTimestamp;
+    if (histoDeltatTimestamp )delete histoDeltatTimestamp;
+    if (histoDeltazEta) delete histoDeltazEta;
+    if (histoDeltatEta) delete histoDeltatEta;
+    if (histoDeltazCosTheta) delete histoDeltazCosTheta;
+    if (histoAcceptedTracksEtaPt) delete histoAcceptedTracksEtaPt;
+    if (histoMatchedTracksEtaPt) delete histoMatchedTracksEtaPt;
+  }
+
   /* success */
   return kTRUE;
 }
@@ -520,7 +659,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
@@ -548,12 +687,14 @@ AliTOFAnalysisTaskCalibPass0::CalibrateAndStore(TH2F *histoVertexTimestamp, TH2F
   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);
@@ -561,6 +702,7 @@ AliTOFAnalysisTaskCalibPass0::CalibrateAndStore(TH2F *histoVertexTimestamp, TH2F
   if (runNb <= 0) {
     AliError(Form("bad run number: %d", runNb));
     fStatus = kDataError;
+    delete strarr;
     return kFALSE;
   }
   AliInfo(Form("got run number: %d", runNb));
@@ -570,6 +712,7 @@ AliTOFAnalysisTaskCalibPass0::CalibrateAndStore(TH2F *histoVertexTimestamp, TH2F
   if (!ostr) {
     AliError("problems while getting start timestamp from histogram title");
     fStatus = kDataError;
+    delete strarr;
     return kFALSE;
   }
   str = ostr->GetString();
@@ -577,6 +720,7 @@ AliTOFAnalysisTaskCalibPass0::CalibrateAndStore(TH2F *histoVertexTimestamp, TH2F
   if (!str.BeginsWith("startTimestamp:")) {
     AliError("problems while getting start timestamp from histogram title");
     fStatus = kDataError;
+    delete strarr;
     return kFALSE;
   }
   str.Remove(0, 16);
@@ -584,16 +728,41 @@ AliTOFAnalysisTaskCalibPass0::CalibrateAndStore(TH2F *histoVertexTimestamp, TH2F
   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 */
-  TF1 *fitFunc = (TF1 *)gROOT->GetFunction("gaus");
-
+  //  TF1 *fitFunc = (TF1 *)gROOT->GetFunction("gaus");
+  TF1 ftgs("ftgs","gaus",-1,1);
+  TF1 *fitFunc = &ftgs; //new (TF1 *)gROOT->GetFunction("gaus");
+  
   /* projection-x */
   TH1D *histoVertexTimestamppx = histoVertexTimestamp->ProjectionX("histoVertexTimestamppx");
   TH1D *histoDeltatTimestamppx = histoDeltatTimestamp->ProjectionX("histoDeltatTimestamppx");
@@ -733,9 +902,9 @@ AliTOFAnalysisTaskCalibPass0::CalibrateAndStore(TH2F *histoVertexTimestamp, TH2F
     tofReso[ipoint] = timeZeroSigma[ipoint];
     t0Spread[ipoint] = vertexSigma[ipoint] / 2.99792457999999984e-02;
   }
-  UInt_t run[1] = {runNb};
+  UInt_t run[1] = {static_cast<UInt_t>(runNb)};
   UInt_t runFirstPoint[1] = {0};
-  UInt_t runLastPoint[1] = {nPoints - 1};
+  UInt_t runLastPoint[1] = {static_cast<UInt_t>(nPoints - 1)};
   
   /* create run params object */
   AliTOFRunParams obj(nPoints, 1);
@@ -747,32 +916,26 @@ 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));
-    fStatus = kStoreError;
-    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)) {
+  if (!db->Put(&obj, id, &md)) {
     fStatus = kStoreError;
-    AliError(Form("error while putting object in storage %s", dbString));
+    AliError(Form("error while putting object in storage %s", db->GetURI().Data()));
     return kFALSE;
   }
 
@@ -788,7 +951,8 @@ AliTOFAnalysisTaskCalibPass0::FitPeak(TF1 *fitFunc, TH1D *h, Float_t startSigma,
   /*
    * fit peak
    */
-
+  for (int i=3;i--;) fitFunc->SetParError(i,0);
+  fitFunc->SetRange(h->GetXaxis()->GetXmin(),h->GetXaxis()->GetXmax());
   Double_t fitCent = h->GetBinCenter(h->GetMaximumBin());
   Double_t fitMin = fitCent - nSigmaMin * startSigma;
   Double_t fitMax = fitCent + nSigmaMax * startSigma;