1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 ***************************************************************************/
16 ///////////////////////////////////////////////////////////////
18 // This class provides TOF pass0/passX calibration tools //
20 ///////////////////////////////////////////////////////////////
22 #include "AliTOFAnalysisTaskCalibPass0.h"
23 #include "AliESDtrack.h"
24 #include "AliESDEvent.h"
25 #include "AliPhysicsSelection.h"
26 #include "AliESDtrackCuts.h"
27 #include "AliCDBManager.h"
28 #include "AliGRPManager.h"
29 #include "AliGRPObject.h"
30 #include "AliTOFcalib.h"
35 #include "TObjArray.h"
37 #include "TObjString.h"
42 #include "TTimeStamp.h"
43 #include "AliTOFRunParams.h"
44 #include "AliCDBStorage.h"
46 #include "AliCDBMetaData.h"
50 ClassImp(AliTOFAnalysisTaskCalibPass0)
52 //_______________________________________________________
54 const Char_t *AliTOFAnalysisTaskCalibPass0::fgkStatusCodeName[AliTOFAnalysisTaskCalibPass0::kNStatusCodes] = {
64 const Int_t AliTOFAnalysisTaskCalibPass0::fgkMaxNumberOfPoints = 10000; // max number of points
65 Double_t AliTOFAnalysisTaskCalibPass0::fgMinVertexIntegral = 100.;
66 Double_t AliTOFAnalysisTaskCalibPass0::fgMinDeltatIntegral = 2000.;
67 Double_t AliTOFAnalysisTaskCalibPass0::fgMinVertexIntegralSample = 1000.;
68 Double_t AliTOFAnalysisTaskCalibPass0::fgMinDeltatIntegralSample = 20000.;
70 //_______________________________________________________
72 AliTOFAnalysisTaskCalibPass0::AliTOFAnalysisTaskCalibPass0() :
73 AliAnalysisTaskSE("TOFCalib-Pass0"),
76 fEventSelectionFlag(kFALSE),
77 fVertexSelectionFlag(kFALSE),
81 fEventCuts(new AliPhysicsSelection()),
82 fTrackCuts(new AliESDtrackCuts()),
88 fGRPManager(new AliGRPManager()),
90 fTOFcalib(new AliTOFcalib()),
91 fHistoList(new TList()),
92 fHistoVertexTimestamp(NULL),
93 fHistoDeltatTimestamp(NULL),
94 fHistoDeltazEta(NULL),
95 fHistoDeltatEta(NULL),
96 fHistoDeltazCosTheta(NULL),
97 fHistoAcceptedTracksEtaPt(NULL),
98 fHistoMatchedTracksEtaPt(NULL)
101 * default constructor
105 fHistoList->SetOwner(kTRUE);
106 DefineOutput(1, TList::Class());
109 //_______________________________________________________
111 AliTOFAnalysisTaskCalibPass0::~AliTOFAnalysisTaskCalibPass0()
117 if (fHistoList) delete fHistoList;
120 //_______________________________________________________
123 AliTOFAnalysisTaskCalibPass0::InitRun()
130 fESDEvent = dynamic_cast<AliESDEvent *>(InputEvent());
132 AliError("cannot get ESD event");
136 Int_t runNb = fESDEvent->GetRunNumber();
137 /* check run already initialized */
138 if (fInitFlag && fRunNumber == runNb) return kTRUE;
139 if (fInitFlag && fRunNumber != runNb) {
140 AliFatal(Form("run number has changed within same job and this is not allowed: %d -> %d", fRunNumber, runNb));
144 /* init cdb if not yet done */
145 AliCDBManager *cdb = AliCDBManager::Instance();
146 if (!cdb->IsDefaultStorageSet())
147 cdb->SetDefaultStorage("raw://");
148 if (cdb->GetRun() < 0)
151 if (!fTOFcalib->Init()) {
152 AliError("cannot init TOF calib");
156 if (!fGRPManager->ReadGRPEntry()) {
157 AliError("error while reading \"GRPEntry\" from OCDB");
160 fkGRPObject = fGRPManager->GetGRPData();
162 AliError("cannot get \"GRPData\" from GRP manager");
165 fStartTime = fkGRPObject->GetTimeStart();
166 fEndTime = fkGRPObject->GetTimeEnd();
167 AliInfo(Form("got \"GRPData\": startTime=%d, endTime=%d", fStartTime, fEndTime));
169 AliInfo(Form("initialized for run %d", runNb));
173 Int_t useBPTX = fTOFcalib->GetUseLHCClockPhase() ? 1 : 0;
175 /* set histo title with run-number and start-time */
176 fHistoVertexTimestamp->SetTitle(Form("run: %d, startTimestamp: %u, BPTX: %d", fRunNumber, fStartTime, useBPTX));
177 fHistoDeltatTimestamp->SetTitle(Form("run: %d, startTimestamp: %u, BPTX: %d", fRunNumber, fStartTime, useBPTX));
178 fHistoDeltazEta->SetTitle(Form("run: %d, startTimestamp: %u, BPTX: %d", fRunNumber, fStartTime, useBPTX));
179 fHistoDeltatEta->SetTitle(Form("run: %d, startTimestamp: %u, BPTX: %d", fRunNumber, fStartTime, useBPTX));
180 fHistoDeltazCosTheta->SetTitle(Form("run: %d, startTimestamp: %u, BPTX: %d", fRunNumber, fStartTime, useBPTX));
181 fHistoAcceptedTracksEtaPt->SetTitle(Form("run: %d, startTimestamp: %u, BPTX: %d", fRunNumber, fStartTime, useBPTX));
182 fHistoMatchedTracksEtaPt->SetTitle(Form("run: %d, startTimestamp: %u, BPTX: %d", fRunNumber, fStartTime, useBPTX));
187 //_______________________________________________________
190 AliTOFAnalysisTaskCalibPass0::InitEvent()
197 fESDEvent = dynamic_cast<AliESDEvent *>(InputEvent());
198 if (!fESDEvent) return kFALSE;
199 /* set event time and elapsed time */
200 fEventTime = fESDEvent->GetTimeStamp();
201 fElapsedTime = fESDEvent->GetTimeStamp() - fStartTime;
202 /* event selection */
203 if (fEventSelectionFlag && !fEventCuts->IsCollisionCandidate(fESDEvent)) return kFALSE;
204 /* vertex selection */
205 fkVertex = fESDEvent->GetPrimaryVertexTracks();
206 if (fVertexSelectionFlag && fkVertex->GetNContributors() < 1) {
207 fkVertex = fESDEvent->GetPrimaryVertexSPD();
208 if (fkVertex->GetNContributors() < 1) return kFALSE;
210 if (fVertexSelectionFlag && TMath::Abs(fkVertex->GetZ()) > fVertexCut) return kFALSE;
211 /* calibrate ESD if requested */
212 fTOFcalib->CalibrateESD(fESDEvent);
217 //_______________________________________________________
220 AliTOFAnalysisTaskCalibPass0::HasTOFMeasurement(const AliESDtrack *track) const
223 * has TOF measurement
226 /* check TOF status flags */
227 if (!(track->GetStatus() & AliESDtrack::kTOFout) ||
228 !(track->GetStatus() & AliESDtrack::kTIME)) return kFALSE;
229 /* check integrated length */
230 if (track->GetIntegratedLength() < 350.) return kFALSE;
232 /* TOF measurement ok */
236 //_______________________________________________________
239 AliTOFAnalysisTaskCalibPass0::UserCreateOutputObjects()
242 * user create output objects
246 Int_t timeBins = 288;
247 Float_t timeMin = 0.;
248 Float_t timeMax = 24. * 3600.;
250 Int_t vertexBins = 200;
251 Float_t vertexMin = -50.;
252 Float_t vertexMax = 50.;
254 Int_t deltatBins = 2000;
255 Float_t deltatMin = -24400.;
256 Float_t deltatMax = 24400.;
258 Int_t deltazBins = 200;
259 Float_t deltazMin = -10.;
260 Float_t deltazMax = 10.;
263 Float_t etaMin = -1.;
270 fHistoVertexTimestamp = new TH2F("hHistoVertexTimestamp", "Vertex position;elapsed time (s);z (cm);", timeBins, timeMin, timeMax, vertexBins, vertexMin, vertexMax);
271 fHistoList->Add(fHistoVertexTimestamp);
273 fHistoDeltatTimestamp = new TH2F("hHistoDeltatTimestamp", "Global time shift (T0-fill);elapsed time (s);t - t_{exp}^{(#pi)} (ps);", timeBins, timeMin, timeMax, deltatBins, deltatMin, deltatMax);
274 fHistoList->Add(fHistoDeltatTimestamp);
276 fHistoDeltazEta = new TH2F("hHistoDeltazEta", "Matching residuals (longitudinal);#eta;#Deltaz (cm);", etaBins, etaMin, etaMax, deltazBins, deltazMin, deltazMax);
277 fHistoList->Add(fHistoDeltazEta);
279 fHistoDeltatEta = new TH2F("hHistoDeltatEta", "Global time shift (T0-fill) vs #eta; #eta; t - t_{exp}^{(#pi)} (ps);", etaBins, etaMin, etaMax, deltatBins, deltatMin, deltatMax);
280 fHistoList->Add(fHistoDeltatEta);
282 fHistoDeltazCosTheta = new TH2F("hHistoDeltazCosTheta", "Matching residuals (longitudinal);cos #theta;#Deltaz (cm);", etaBins, etaMin, etaMax, deltazBins, deltazMin, deltazMax);
283 fHistoList->Add(fHistoDeltazCosTheta);
285 fHistoAcceptedTracksEtaPt = new TH2F("hHistoAcceptedTracksEtaPt", "Accepted tracks;#eta;#p_{T} (GeV/c);", etaBins, etaMin, etaMax, pBins, pMin, pMax);
286 fHistoList->Add(fHistoAcceptedTracksEtaPt);
288 fHistoMatchedTracksEtaPt = new TH2F("hHistoMatchedTracksEtaPt", "Matched tracks;#eta;p_{T} (GeV/c);", etaBins, etaMin, etaMax, pBins, pMin, pMax);
289 fHistoList->Add(fHistoMatchedTracksEtaPt);
292 PostData(1, fHistoList);
295 //_______________________________________________________
298 AliTOFAnalysisTaskCalibPass0::UserExec(Option_t *)
305 if (!InitRun()) return;
307 if (!InitEvent()) return;
309 /*** ACCEPTED EVENT ***/
311 /* fill vertex histo */
312 fHistoVertexTimestamp->Fill(fElapsedTime, fkVertex->GetZ());
314 /* loop over ESD tracks */
315 Int_t nTracks = fESDEvent->GetNumberOfTracks();
317 Double_t eta, costheta, pt, time, timei[AliPID::kSPECIESC], deltat, deltaz;
318 for (Int_t itrk = 0; itrk < nTracks; itrk++) {
320 track = fESDEvent->GetTrack(itrk);
321 if (!track) continue;
322 /* check accept track */
323 if (!fTrackCuts->AcceptTrack(track)) continue;
326 costheta = TMath::Cos(track->Theta());
328 /* fill accepted tracks histo */
329 fHistoAcceptedTracksEtaPt->Fill(eta, pt);
330 /* check TOF measurement */
331 if (!HasTOFMeasurement(track)) continue;
333 /*** ACCEPTED TRACK WITH TOF MEASUREMENT ***/
335 /* fill matched tracks histo */
336 fHistoMatchedTracksEtaPt->Fill(eta, pt);
338 time = track->GetTOFsignal();
339 track->GetIntegratedTimes(timei);
340 deltat = time - timei[AliPID::kPion];
341 deltaz = track->GetTOFsignalDz();
344 fHistoDeltatTimestamp->Fill(fElapsedTime, deltat);
345 fHistoDeltazEta->Fill(eta, deltaz);
346 fHistoDeltatEta->Fill(eta, deltat);
347 fHistoDeltazCosTheta->Fill(costheta, deltaz);
349 } /* end of loop over ESD tracks */
352 PostData(1, fHistoList);
356 //_______________________________________________________
359 AliTOFAnalysisTaskCalibPass0::GetStatus()
367 /* OK, return zero */
372 /* non-fatal error, return negative status */
379 /* fatal error, return positive status */
386 /* anything else, return negative large number */
392 /* should never arrive here, anyway return negative large number */
396 //_______________________________________________________
399 AliTOFAnalysisTaskCalibPass0::PrintStatus()
405 Int_t status = GetStatus();
407 AliInfo(Form("TOF calibration successful: %s (status=%d)", fgkStatusCodeName[fStatus], status));
409 else if (status > 0) {
410 AliInfo(Form("TOF calibration failed: %s (status=%d)", fgkStatusCodeName[fStatus], status));
412 else if (status < 0) {
413 AliInfo(Form("TOF calibration failed (expected): %s (status=%d)", fgkStatusCodeName[fStatus], status));
418 //_______________________________________________________
421 AliTOFAnalysisTaskCalibPass0::ProcessOutput(const Char_t *filename, AliCDBStorage* db)
427 Int_t ret = DoProcessOutput(filename, db);
432 //_______________________________________________________
435 AliTOFAnalysisTaskCalibPass0::DoProcessOutput(const Char_t *filename, AliCDBStorage *db)
441 /* reset status to OK */
445 TFile *file = TFile::Open(filename);
446 if (!file || !file->IsOpen()) {
447 AliError(Form("cannot open output file %s", filename));
448 fStatus = kInputError;
452 TList *list = (TList *)file->Get("TOFHistos");
453 TH2F *histoVertexTimestamp = NULL;
454 TH2F *histoDeltatTimestamp = NULL;
455 TH2F *histoDeltazEta = NULL;
456 TH2F *histoDeltatEta = NULL;
457 TH2F *histoDeltazCosTheta = NULL;
458 TH2F *histoAcceptedTracksEtaPt = NULL;
459 TH2F *histoMatchedTracksEtaPt = NULL;
461 AliInfo(Form("getting histograms from \"Histos\" list from file %s", filename));
462 histoVertexTimestamp = (TH2F *)list->FindObject("hHistoVertexTimestamp");
463 histoDeltatTimestamp = (TH2F *)list->FindObject("hHistoDeltatTimestamp");
464 histoDeltazEta = (TH2F *)list->FindObject("hHistoDeltazEta");
465 histoDeltatEta = (TH2F *)list->FindObject("hHistoDeltatEta");
466 histoDeltazCosTheta = (TH2F *)list->FindObject("hHistoDeltazCosTheta");
467 histoAcceptedTracksEtaPt = (TH2F *)list->FindObject("hHistoAcceptedTracksEtaPt");
468 histoMatchedTracksEtaPt = (TH2F *)list->FindObject("hHistoMatchedTracksEtaPt");
471 AliInfo(Form("getting histograms directly from file %s", filename));
472 histoVertexTimestamp = (TH2F *)file->Get("hHistoVertexTimestamp");
473 histoDeltatTimestamp = (TH2F *)file->Get("hHistoDeltatTimestamp");
474 histoDeltazEta = (TH2F *)file->Get("hHistoDeltazEta");
475 histoDeltatEta = (TH2F *)file->Get("hHistoDeltatEta");
476 histoDeltazCosTheta = (TH2F *)file->Get("hHistoDeltazCosTheta");
477 histoAcceptedTracksEtaPt = (TH2F *)file->Get("hHistoAcceptedTracksEtaPt");
478 histoMatchedTracksEtaPt = (TH2F *)file->Get("hHistoMatchedTracksEtaPt");
481 if (!histoVertexTimestamp) {
482 AliError(Form("cannot get \"hHistoVertexTimestamp\" object from file %s", filename));
483 fStatus = kInputError;
487 if (histoVertexTimestamp) delete histoVertexTimestamp;
488 if (histoDeltatTimestamp )delete histoDeltatTimestamp;
489 if (histoDeltazEta) delete histoDeltazEta;
490 if (histoDeltatEta) delete histoDeltatEta;
491 if (histoDeltazCosTheta) delete histoDeltazCosTheta;
492 if (histoAcceptedTracksEtaPt) delete histoAcceptedTracksEtaPt;
493 if (histoMatchedTracksEtaPt) delete histoMatchedTracksEtaPt;
497 if (!histoDeltatTimestamp) {
498 AliError(Form("cannot get \"hHistoDeltatTimestamp\" object from file %s", filename));
499 fStatus = kInputError;
503 if (histoVertexTimestamp) delete histoVertexTimestamp;
504 if (histoDeltatTimestamp )delete histoDeltatTimestamp;
505 if (histoDeltazEta) delete histoDeltazEta;
506 if (histoDeltatEta) delete histoDeltatEta;
507 if (histoDeltazCosTheta) delete histoDeltazCosTheta;
508 if (histoAcceptedTracksEtaPt) delete histoAcceptedTracksEtaPt;
509 if (histoMatchedTracksEtaPt) delete histoMatchedTracksEtaPt;
513 if (!histoDeltazEta) {
514 AliError(Form("cannot get \"hHistoDeltazEta\" object from file %s", filename));
515 fStatus = kInputError;
519 if (histoVertexTimestamp) delete histoVertexTimestamp;
520 if (histoDeltatTimestamp )delete histoDeltatTimestamp;
521 if (histoDeltazEta) delete histoDeltazEta;
522 if (histoDeltatEta) delete histoDeltatEta;
523 if (histoDeltazCosTheta) delete histoDeltazCosTheta;
524 if (histoAcceptedTracksEtaPt) delete histoAcceptedTracksEtaPt;
525 if (histoMatchedTracksEtaPt) delete histoMatchedTracksEtaPt;
529 if (!histoDeltatEta) {
530 AliError(Form("cannot get \"hHistoDeltatEta\" object from file %s", filename));
531 fStatus = kInputError;
535 if (histoVertexTimestamp) delete histoVertexTimestamp;
536 if (histoDeltatTimestamp )delete histoDeltatTimestamp;
537 if (histoDeltazEta) delete histoDeltazEta;
538 if (histoDeltatEta) delete histoDeltatEta;
539 if (histoDeltazCosTheta) delete histoDeltazCosTheta;
540 if (histoAcceptedTracksEtaPt) delete histoAcceptedTracksEtaPt;
541 if (histoMatchedTracksEtaPt) delete histoMatchedTracksEtaPt;
545 if (!histoDeltazCosTheta) {
546 AliError(Form("cannot get \"hHistoDeltazCosTheta\" object from file %s", filename));
547 fStatus = kInputError;
551 if (histoVertexTimestamp) delete histoVertexTimestamp;
552 if (histoDeltatTimestamp )delete histoDeltatTimestamp;
553 if (histoDeltazEta) delete histoDeltazEta;
554 if (histoDeltatEta) delete histoDeltatEta;
555 if (histoDeltazCosTheta) delete histoDeltazCosTheta;
556 if (histoAcceptedTracksEtaPt) delete histoAcceptedTracksEtaPt;
557 if (histoMatchedTracksEtaPt) delete histoMatchedTracksEtaPt;
561 if (!histoAcceptedTracksEtaPt) {
562 AliError(Form("cannot get \"hHistoAccptedTracksEtaPt\" object from file %s", filename));
563 fStatus = kInputError;
567 if (histoVertexTimestamp) delete histoVertexTimestamp;
568 if (histoDeltatTimestamp )delete histoDeltatTimestamp;
569 if (histoDeltazEta) delete histoDeltazEta;
570 if (histoDeltatEta) delete histoDeltatEta;
571 if (histoDeltazCosTheta) delete histoDeltazCosTheta;
572 if (histoAcceptedTracksEtaPt) delete histoAcceptedTracksEtaPt;
573 if (histoMatchedTracksEtaPt) delete histoMatchedTracksEtaPt;
577 if (!histoMatchedTracksEtaPt) {
578 AliError(Form("cannot get \"hHistoMatchedTracksEtaPt\" object from file %s", filename));
579 fStatus = kInputError;
583 if (histoVertexTimestamp) delete histoVertexTimestamp;
584 if (histoDeltatTimestamp )delete histoDeltatTimestamp;
585 if (histoDeltazEta) delete histoDeltazEta;
586 if (histoDeltatEta) delete histoDeltatEta;
587 if (histoDeltazCosTheta) delete histoDeltazCosTheta;
588 if (histoAcceptedTracksEtaPt) delete histoAcceptedTracksEtaPt;
589 if (histoMatchedTracksEtaPt) delete histoMatchedTracksEtaPt;
594 /* check matching performance */
595 if (!CheckMatchingPerformance(histoDeltazEta, histoAcceptedTracksEtaPt, histoMatchedTracksEtaPt)) {
596 AliError("error while checking matching efficiency");
600 if (histoVertexTimestamp) delete histoVertexTimestamp;
601 if (histoDeltatTimestamp )delete histoDeltatTimestamp;
602 if (histoDeltazEta) delete histoDeltazEta;
603 if (histoDeltatEta) delete histoDeltatEta;
604 if (histoDeltazCosTheta) delete histoDeltazCosTheta;
605 if (histoAcceptedTracksEtaPt) delete histoAcceptedTracksEtaPt;
606 if (histoMatchedTracksEtaPt) delete histoMatchedTracksEtaPt;
610 /* calibrate and store */
611 if (!CalibrateAndStore(histoVertexTimestamp, histoDeltatTimestamp, db)) {
612 AliError("error while calibrating and storing");
616 if (histoVertexTimestamp) delete histoVertexTimestamp;
617 if (histoDeltatTimestamp )delete histoDeltatTimestamp;
618 if (histoDeltazEta) delete histoDeltazEta;
619 if (histoDeltatEta) delete histoDeltatEta;
620 if (histoDeltazCosTheta) delete histoDeltazCosTheta;
621 if (histoAcceptedTracksEtaPt) delete histoAcceptedTracksEtaPt;
622 if (histoMatchedTracksEtaPt) delete histoMatchedTracksEtaPt;
630 if (histoVertexTimestamp) delete histoVertexTimestamp;
631 if (histoDeltatTimestamp )delete histoDeltatTimestamp;
632 if (histoDeltazEta) delete histoDeltazEta;
633 if (histoDeltatEta) delete histoDeltatEta;
634 if (histoDeltazCosTheta) delete histoDeltazCosTheta;
635 if (histoAcceptedTracksEtaPt) delete histoAcceptedTracksEtaPt;
636 if (histoMatchedTracksEtaPt) delete histoMatchedTracksEtaPt;
643 //_______________________________________________________
646 AliTOFAnalysisTaskCalibPass0::CheckMatchingPerformance(const TH2F *histoDeltazCosTheta, const TH2F *histoAcceptedTracksEtaPt, const TH2F *histoMatchedTracksEtaPt) const
649 * check matching performance
653 if (!histoDeltazCosTheta || !histoAcceptedTracksEtaPt || !histoMatchedTracksEtaPt)
655 /* dummy for the time being */
659 //_______________________________________________________
662 AliTOFAnalysisTaskCalibPass0::CalibrateAndStore(TH2F *histoVertexTimestamp, TH2F *histoDeltatTimestamp, AliCDBStorage *db)
665 * calibrate and store
669 if (!histoVertexTimestamp || !histoDeltatTimestamp)
672 /*** GET RUN-NUMBER AND START-TIMESTAMP ***/
675 TObjArray *strarr = NULL;
676 TObjString *ostr = NULL;
677 str = histoVertexTimestamp->GetTitle();
678 strarr = str.Tokenize(",");
680 AliError("problems whith tokenize histogram title");
681 fStatus = kDataError;
686 ostr = (TObjString *)strarr->At(0);
688 AliError("problems while getting run number from histogram title");
689 fStatus = kDataError;
693 str = ostr->GetString();
694 if (!str.BeginsWith("run:")) {
695 AliError("problems while getting run number from histogram title");
696 fStatus = kDataError;
701 Int_t runNb = atoi(str.Data());
703 AliError(Form("bad run number: %d", runNb));
704 fStatus = kDataError;
708 AliInfo(Form("got run number: %d", runNb));
710 /* start timestamp */
711 ostr = (TObjString *)strarr->At(1);
713 AliError("problems while getting start timestamp from histogram title");
714 fStatus = kDataError;
718 str = ostr->GetString();
719 str.Remove(0, 1); /* remove empty space at the beginning */
720 if (!str.BeginsWith("startTimestamp:")) {
721 AliError("problems while getting start timestamp from histogram title");
722 fStatus = kDataError;
727 UInt_t startTimestamp = atoi(str.Data());
728 if (startTimestamp <= 0) {
729 AliError(Form("bad start timestamp: %d", startTimestamp));
730 fStatus = kDataError;
734 TTimeStamp ts = startTimestamp;
735 AliInfo(Form("got start timestamp: %d (%s)", startTimestamp, ts.AsString()));
738 ostr = (TObjString *)strarr->At(2);
740 AliError("problems while getting BPTX from histogram title");
741 fStatus = kDataError;
745 str = ostr->GetString();
746 str.Remove(0, 1); /* remove empty space at the beginning */
747 if (!str.BeginsWith("BPTX:")) {
748 AliError("problems while getting BPTX from histogram title");
749 fStatus = kDataError;
754 Bool_t useBPTX = atoi(str.Data());
755 AliInfo(Form("got BPTX: %d", useBPTX));
759 /*** CALIBRATION STAGE ***/
761 /* get fit function */
762 // TF1 *fitFunc = (TF1 *)gROOT->GetFunction("gaus");
763 TF1 ftgs("ftgs","gaus",-1,1);
764 TF1 *fitFunc = &ftgs; //new (TF1 *)gROOT->GetFunction("gaus");
767 TH1D *histoVertexTimestamppx = histoVertexTimestamp->ProjectionX("histoVertexTimestamppx");
768 TH1D *histoDeltatTimestamppx = histoDeltatTimestamp->ProjectionX("histoDeltatTimestamppx");
770 /* check statistics */
771 if (histoVertexTimestamppx->Integral() < fgMinVertexIntegral ||
772 histoDeltatTimestamppx->Integral() < fgMinDeltatIntegral) {
773 fStatus = kLowStatistics;
777 /* define mix and max time bin */
778 Int_t minBin = histoVertexTimestamppx->FindFirstBinAbove(0);
779 Int_t maxBin = histoVertexTimestamppx->FindLastBinAbove(0);
780 Float_t minTime = histoVertexTimestamppx->GetBinLowEdge(minBin);
781 Float_t maxTime = histoVertexTimestamppx->GetBinLowEdge(maxBin + 1);
782 AliInfo(Form("min/max time defined: %d < t < %d s [%d, %d]", (Int_t)minTime, (Int_t)maxTime, minBin, maxBin));
784 /* loop over time bins */
786 Float_t time[fgkMaxNumberOfPoints], timeerr[fgkMaxNumberOfPoints];
787 Float_t vertexMean[fgkMaxNumberOfPoints], vertexMeanerr[fgkMaxNumberOfPoints];
788 Float_t vertexSigma[fgkMaxNumberOfPoints], vertexSigmaerr[fgkMaxNumberOfPoints];
789 Float_t timeZeroMean[fgkMaxNumberOfPoints], timeZeroMeanerr[fgkMaxNumberOfPoints];
790 Float_t timeZeroSigma[fgkMaxNumberOfPoints], timeZeroSigmaerr[fgkMaxNumberOfPoints];
791 Float_t averageTimeZero = 0.;
792 Float_t averageTimeSigma = 0.;
793 Float_t averageVertexSpread = 0.;
794 for (Int_t ibin = minBin; ibin <= maxBin; ibin++) {
796 /* define time window */
797 Int_t startBin = ibin;
799 while(histoVertexTimestamppx->Integral(startBin, endBin) < fgMinVertexIntegralSample ||
800 histoDeltatTimestamppx->Integral(startBin, endBin) < fgMinDeltatIntegralSample) {
801 if (endBin < maxBin) endBin++;
802 else if (startBin > minBin) startBin--;
805 if (histoVertexTimestamppx->Integral(startBin, endBin) < fgMinVertexIntegral ||
806 histoDeltatTimestamppx->Integral(startBin, endBin) < fgMinDeltatIntegral) continue;
807 Float_t startTime = histoVertexTimestamppx->GetBinLowEdge(startBin);
808 Float_t endTime = histoVertexTimestamppx->GetBinLowEdge(endBin + 1);
809 Float_t vertexIntegral = histoVertexTimestamppx->Integral(startBin, endBin);
810 Float_t deltatIntegral = histoDeltatTimestamppx->Integral(startBin, endBin);
811 AliInfo(Form("time window defined: %d < t < %d s [%d, %d]: %d vertices, %d tracks", (Int_t)startTime, (Int_t)endTime, startBin, endBin, (Int_t)vertexIntegral, (Int_t)deltatIntegral));
814 TH1D *histoVertexTimestamppy = histoVertexTimestamp->ProjectionY("histoVertexTimestamppy", startBin, endBin);
815 TH1D *histoDeltatTimestamppy = histoDeltatTimestamp->ProjectionY("histoDeltatTimestamppy", startBin, endBin);
818 histoVertexTimestamppx->GetXaxis()->SetRange(startBin, endBin);
819 time[nPoints] = histoVertexTimestamppx->GetMean();
820 timeerr[nPoints] = histoVertexTimestamppx->GetMeanError();
823 if (FitPeak(fitFunc, histoVertexTimestamppy, 10., 3., 3.) != 0) {
824 AliError("troubles fitting vertex, skip");
825 delete histoVertexTimestamppy;
826 delete histoDeltatTimestamppy;
829 vertexMean[nPoints] = fitFunc->GetParameter(1);
830 vertexMeanerr[nPoints] = fitFunc->GetParError(1);
831 vertexSigma[nPoints] = fitFunc->GetParameter(2);
832 vertexSigmaerr[nPoints] = fitFunc->GetParError(2);
833 averageVertexSpread += fitFunc->GetParameter(2);
836 if (FitPeak(fitFunc, histoDeltatTimestamppy, 500., 2., 1.) != 0) {
837 AliError("troubles fitting time-zero TRACKS, skip");
838 delete histoVertexTimestamppy;
839 delete histoDeltatTimestamppy;
842 timeZeroMean[nPoints] = fitFunc->GetParameter(1);
843 timeZeroMeanerr[nPoints] = fitFunc->GetParError(1);
844 timeZeroSigma[nPoints] = fitFunc->GetParameter(2);
845 timeZeroSigmaerr[nPoints] = fitFunc->GetParError(2);
846 averageTimeZero += fitFunc->GetParameter(1);
847 averageTimeSigma += fitFunc->GetParameter(2);
849 /* delete projection-y */
850 delete histoVertexTimestamppy;
851 delete histoDeltatTimestamppy;
853 /* increment n points */
856 /* set current bin */
859 } /* end of loop over time bins */
861 /* delete projection-x */
862 delete histoVertexTimestamppx;
863 delete histoDeltatTimestamppx;
867 AliError("no measurement available, quit");
868 fStatus = kNoMeasurement;
871 AliInfo(Form("average time-zero = %f", averageTimeZero / nPoints));
872 AliInfo(Form("average time-sigma = %f", averageTimeSigma / nPoints));
873 AliInfo(Form("average v-spread = %f", averageVertexSpread / nPoints));
875 /*** CREATE RUN PARAMS OBJECT ***/
878 /* get start time from GRP */
879 TGrid::Connect("alien://", 0, 0, "t");
880 AliCDBManager *cdb = AliCDBManager::Instance();
881 cdb->SetDefaultStorage("raw://");
884 if (!grp.ReadGRPEntry()) {
885 AliError("error while reading GRP entry");
888 UInt_t startTimestamp = grp.GetGRPData()->GetTimeStart();
891 AliInfo(Form("got start time from GRP: %s", ts.AsString()));
895 UInt_t timestamp[fgkMaxNumberOfPoints];
896 Float_t t0[fgkMaxNumberOfPoints];
897 Float_t tofReso[fgkMaxNumberOfPoints];
898 Float_t t0Spread[fgkMaxNumberOfPoints];
899 for (Int_t ipoint = 0; ipoint < nPoints; ipoint++) {
900 timestamp[ipoint] = (UInt_t)time[ipoint] + startTimestamp;
901 t0[ipoint] = timeZeroMean[ipoint];
902 tofReso[ipoint] = timeZeroSigma[ipoint];
903 t0Spread[ipoint] = vertexSigma[ipoint] / 2.99792457999999984e-02;
905 UInt_t run[1] = {static_cast<UInt_t>(runNb)};
906 UInt_t runFirstPoint[1] = {0};
907 UInt_t runLastPoint[1] = {static_cast<UInt_t>(nPoints - 1)};
909 /* create run params object */
910 AliTOFRunParams obj(nPoints, 1);
911 AliInfo(Form("create run params object for run %d with %d points", runNb, nPoints));
912 obj.SetTimestamp(timestamp);
914 obj.SetTOFResolution(tofReso);
915 obj.SetT0Spread(t0Spread);
917 obj.SetRunFirstPoint(runFirstPoint);
918 obj.SetRunLastPoint(runLastPoint);
919 obj.SetUseLHCClockPhase(useBPTX);
921 /*** CREATE OCDB ENTRY ***/
924 AliError("cannot store object because of NULL storage");
925 fStatus = kStoreError;
929 /* install run params object in OCDB */
930 AliCDBId id("TOF/Calib/RunParams", runNb, runNb);
932 md.SetResponsible("Roberto Preghenella");
933 md.SetComment("offline TOF run parameters");
934 md.SetAliRootVersion(gSystem->Getenv("ARVERSION"));
936 if (!db->Put(&obj, id, &md)) {
937 fStatus = kStoreError;
938 AliError(Form("error while putting object in storage %s", db->GetURI().Data()));
946 //_____________________________________________________________
949 AliTOFAnalysisTaskCalibPass0::FitPeak(TF1 *fitFunc, TH1D *h, Float_t startSigma, Float_t nSigmaMin, Float_t nSigmaMax)
954 for (int i=3;i--;) fitFunc->SetParError(i,0);
955 fitFunc->SetRange(h->GetXaxis()->GetXmin(),h->GetXaxis()->GetXmax());
956 Double_t fitCent = h->GetBinCenter(h->GetMaximumBin());
957 Double_t fitMin = fitCent - nSigmaMin * startSigma;
958 Double_t fitMax = fitCent + nSigmaMax * startSigma;
959 if (fitMin < h->GetXaxis()->GetXmin()) fitMin = h->GetXaxis()->GetXmin();
960 if (fitMax > h->GetXaxis()->GetXmax()) fitMax = h->GetXaxis()->GetXmax();
961 fitFunc->SetParameter(1, fitCent);
962 fitFunc->SetParameter(2, startSigma);
963 Int_t fitres = h->Fit(fitFunc, "WWq0", "", fitMin, fitMax);
964 if (fitres != 0) return fitres;
965 /* refit with better range */
966 for (Int_t i = 0; i < 3; i++) {
967 fitCent = fitFunc->GetParameter(1);
968 fitMin = fitCent - nSigmaMin * fitFunc->GetParameter(2);
969 fitMax = fitCent + nSigmaMax * fitFunc->GetParameter(2);
970 if (fitMin < h->GetXaxis()->GetXmin()) fitMin = h->GetXaxis()->GetXmin();
971 if (fitMax > h->GetXaxis()->GetXmax()) fitMax = h->GetXaxis()->GetXmax();
972 fitres = h->Fit(fitFunc, "q0", "", fitMin, fitMax);
973 if (fitres != 0) return fitres;