Skip to content

Commit 44f34d1

Browse files
chiarazampollisawenzel
authored andcommitted
Macros to convert the AliRoot/OCDB calibration to the O2/CCDB format
1 parent 80a1cdb commit 44f34d1

File tree

8 files changed

+247
-2
lines changed

8 files changed

+247
-2
lines changed

DataFormats/Detectors/TOF/include/DataFormatsTOF/CalibTimeSlewingParamTOF.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class CalibTimeSlewingParamTOF
4545

4646
int getSize(int sector) const { return (*(mTimeSlewing[sector])).size(); }
4747

48-
int getStartTimeStamp(int sector, int channel) const { return mChannelStart[sector][channel]; }
48+
int getStartIndexForChannel(int sector, int channel) const { return mChannelStart[sector][channel]; }
4949
float getFractionUnderPeak(int sector, int channel) const { return mFractionUnderPeak[sector][channel]; }
5050
float getSigmaPeak(int sector, int channel) const { return mSigmaPeak[sector][channel]; }
5151

DataFormats/Detectors/TOF/src/CalibTimeSlewingParamTOF.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ float CalibTimeSlewingParamTOF::evalTimeSlewing(int channel, float tot) const
7070
if (n >= nstop)
7171
return 0.; // something went wrong!
7272

73-
while (n < nstop && tot < (*(mTimeSlewing[sector]))[n].first)
73+
while (n < nstop && tot > (*(mTimeSlewing[sector]))[n].first)
7474
n++;
7575
n--;
7676

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
/// \file CalibTOFapi.h
12+
/// \brief Class to use TOF calibration (decalibration, calibration)
13+
/// \author Francesco.Noferini@cern.ch, Chiara.Zampolli@cern.ch
14+
15+
#ifndef ALICEO2_GLOBTRACKING_CALIBTOFAPI_
16+
#define ALICEO2_GLOBTRACKING_CALIBTOFAPI_
17+
18+
#include <iostream>
19+
#include "CCDB/BasicCCDBManager.h"
20+
21+
namespace o2
22+
{
23+
24+
namespace tof
25+
26+
class CalibTOFapi
27+
{
28+
public:
29+
CalibTOFapi() = default;
30+
CalibTOFapi(const std::string db);
31+
~CalibTOFapi = default;
32+
void setDB(const std::string db) {
33+
mCCDBserver = db;
34+
}
35+
36+
private:
37+
38+
std::string mCCDB; ///< CCDB server where to look for the TOF CCDB objects
39+
40+
ClassDefNV(CalibTOFapi, 1);
41+
};
42+
} // namespace tof
43+
} // namespace o2
44+
#endif
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
#include "TOFCalibration/CalibTOFapi.h"
12+
13+
using namespace o2::tof;
14+
using ccdbManager = o2::ccdb::BasicCCDBManager;
15+
16+
ClassImp(CalibTOFapi);
17+
18+
CalibTOFapi(const std::string db) {
19+
20+
mCCDB = db;
21+
auto& mgr = ccdbManager::instance();
22+
mgr.setURL(db);
23+
24+
}
25+
26+
//______________________________________________________________________
27+

Detectors/TOF/prototyping/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,7 @@ o2_add_test_root_macro(findTOFclusterFromLabel.C
3939
O2::CommonDataFormat
4040
O2::TOFBase
4141
LABELS tof)
42+
43+
o2_add_test_root_macro(checkTS.C
44+
PUBLIC_LINK_LIBRARIES O2::DataFormatsTOF
45+
LABELS tof)
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#include "CalibTimeSlewingParamTOF.h"
2+
#include "AliTOFCalibFineSlewing.h"
3+
#include "TFile.h"
4+
#include "TROOT.h"
5+
#include "AliCDBEntry.h"
6+
#include "TCanvas.h"
7+
#include "TGraph.h"
8+
#include "TTree.h"
9+
#include "TMath.h"
10+
#include "AliTOFChannelOffline.h"
11+
#include "TH1C.h"
12+
13+
// macro to be run in *** AliRoot *** to convert the TOF OCDB entries in CCDB entries
14+
// How to run (see below for futher instructions):
15+
// gROOT->LoadMacro("CalibTimeSlewingParamTOF.cxx+")
16+
// .x ConvertRun2CalibrationToO2.C+
17+
18+
class MyFineTimeSlewing : public AliTOFCalibFineSlewing
19+
{
20+
21+
public:
22+
23+
// class needed to access some data members of the AliTOFCalibFineSlewing class that are protected
24+
25+
Int_t GetSize() {return fSize;}
26+
void GetChannelArrays(Int_t ich, Float_t* x, Float_t* y, Int_t& n) {
27+
n = fStart[ich+1] - fStart[ich];
28+
if (ich == 157247) n = fSize - fStart[ich];
29+
for (Int_t i = 0; i < n; i++){
30+
x[i] = fX[fStart[ich] + i] * 0.001; // in the OCDB, we saves the tot in ps
31+
y[i] = fY[fStart[ich] + i] * 1.; // make it float
32+
}
33+
}
34+
35+
ClassDef(MyFineTimeSlewing, 1);
36+
37+
};
38+
39+
40+
41+
void ConvertRun2CalibrationToO2() {
42+
43+
gROOT->LoadMacro("CalibTimeSlewingParamTOF.cxx+"); // actually you need to call this outside the macro, or it won't work
44+
// so you should first:
45+
// - copy
46+
// - DataFormats/Detectors/TOF/src/CalibTimeSlewingParamTOF.cxx
47+
// and
48+
// - DataFormats/Detectors/TOF/include/DataFormatsTOF/CalibTimeSlewingParamTOF.h
49+
// in the local working directory, substituting:
50+
// - #include "DataFormatsTOF/CalibTimeSlewingParamTOF.h"
51+
// with
52+
// - #include "CalibTimeSlewingParamTOF.h"
53+
// - then call:
54+
// - gROOT->LoadMacro("CalibTimeSlewingParamTOF.cxx+")
55+
// from the prompt
56+
57+
o2::dataformats::CalibTimeSlewingParamTOF* mTimeSlewingObj = new o2::dataformats::CalibTimeSlewingParamTOF();
58+
59+
TFile* ffineSlewing = new TFile("TOF/Calib/FineSlewing/Run0_999999999_v2_s0.root");
60+
AliCDBEntry* efineSlewing = (AliCDBEntry*)ffineSlewing->Get("AliCDBEntry");
61+
AliTOFCalibFineSlewing* fs = (AliTOFCalibFineSlewing*)efineSlewing->GetObject();
62+
TFile* foffset = new TFile("TOF/Calib/ParOffline/Run297624_999999999_v4_s0.root");
63+
AliCDBEntry* eoffset = (AliCDBEntry*)foffset->Get("AliCDBEntry");
64+
TObjArray* foff = (TObjArray*)eoffset->GetObject();
65+
TFile *fproblematic = new TFile("TOF/Calib/Problematic/Run296631_999999999_v3_s0.root");
66+
AliCDBEntry* eproblematic = (AliCDBEntry*)fproblematic->Get("AliCDBEntry");
67+
TH1C* hProb = (TH1C*)eproblematic->GetObject();
68+
69+
MyFineTimeSlewing* mfs = (MyFineTimeSlewing*)fs;
70+
Printf("size = %d", mfs->GetSize());
71+
72+
73+
Float_t x[10000];
74+
Float_t y[10000];
75+
76+
Int_t n;
77+
78+
for (Int_t i = 0; i < 157248; i++) {
79+
mfs->GetChannelArrays(i, x, y, n);
80+
//Printf("channel %d has %d entries", i, n);
81+
AliTOFChannelOffline* parOffline = (AliTOFChannelOffline*)foff->At(i);
82+
//Printf("channel %d has offset = %f", parOffline->GetSlewPar(0));
83+
for (Int_t j = 0; j < n; j++) {
84+
Float_t corr = 0;
85+
for (Int_t islew = 0; islew < 6; islew++)
86+
corr += parOffline->GetSlewPar(islew) * TMath::Power(x[j], islew) * 1.e3;
87+
if(j==0 && x[j] > 0.03) mTimeSlewingObj->addTimeSlewingInfo(i, 0.025, y[j]+parOffline->GetSlewPar(0)); // force to have an entry for ToT=0
88+
mTimeSlewingObj->addTimeSlewingInfo(i, x[j], y[j]+corr);
89+
}
90+
if(n==0) // force to have at least one entry
91+
mTimeSlewingObj->addTimeSlewingInfo(i, 0.025, parOffline->GetSlewPar(0));
92+
93+
// set problematics
94+
int sector = i/8736;
95+
int localchannel = i%8736;
96+
float fraction = float(hProb->GetBinContent(i)==0) - 0.01; // negative means problematic
97+
mTimeSlewingObj->setFractionUnderPeak(sector, localchannel, fraction);
98+
mTimeSlewingObj->setSigmaPeak(sector, localchannel, 100.);
99+
}
100+
101+
TGraph* g = new TGraph(n, x, y);
102+
103+
new TCanvas();
104+
g->Draw("A*");
105+
106+
Printf("time slewing object has size = %d", mTimeSlewingObj->size());
107+
108+
109+
110+
TFile *fout = new TFile("outputCCDBfromOCDB.root","RECREATE");
111+
TTree *t = new TTree("tree","tree");
112+
t->Branch("CalibTimeSlewingParamTOF",&mTimeSlewingObj);
113+
t->Fill();
114+
t->Write();
115+
fout->Close();
116+
}
117+
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
void checkTS(int ch=0){
2+
3+
// macro to verify the evalTimeSlewing function
4+
5+
TFile *f = new TFile("outputCCDBfromOCDB.root");
6+
f->ls();
7+
8+
TTree *t = (TTree *) f->Get("tree");
9+
10+
o2::dataformats::CalibTimeSlewingParamTOF *obj = new o2::dataformats::CalibTimeSlewingParamTOF();
11+
t->SetBranchAddress("CalibTimeSlewingParamTOF",&obj);
12+
t->GetEvent(0);
13+
14+
int nbin = 1000;
15+
16+
// where the entries for the tot vs timeSlewing correction for the desired channel are stored in the sector-wise vector
17+
int istart = obj->getStartIndexForChannel(ch/8736, ch%8736);
18+
int istop = obj->getStartIndexForChannel(ch/8736, ch%8736 + 1) - 1;
19+
printf("istart = %d -- istop = %d\n", istart, istop);
20+
21+
22+
float a[1000],b[1000];
23+
int np = 0;
24+
float range = 100;
25+
26+
// corrections of the desidered channel
27+
const std::vector<std::pair<float, float>>* vect = obj->getVector(ch/8736);
28+
for(int ii = istart; ii <= istop; ii++){
29+
a[np] = vect->at(ii).first;
30+
b[np] = vect->at(ii).second;
31+
range = a[np]*1.3;
32+
np++;
33+
printf("tot=%f -- time = %f\n", (*vect)[ii].first, (*vect)[ii].second);
34+
}
35+
36+
TGraph *g = new TGraph(np, a, b);
37+
TProfile *h = new TProfile("h", "", nbin, 0, range);
38+
float inv = range/nbin;
39+
40+
for(int i = 1; i <= nbin; i++){
41+
float ts = obj->evalTimeSlewing(ch, (i-0.5)*inv);
42+
printf("bin = %i, tot = %f, timeSlewing correction = %f\n", i, (i-0.5)*inv, ts);
43+
h->Fill((i-0.5)*inv, ts);
44+
}
45+
46+
// comparing if the stored corrections match with what evalTimeSlewing returns
47+
h->Draw("P");
48+
h->SetMarkerStyle(20);
49+
50+
g->SetLineColor(2);
51+
g->Draw("L");
52+
}

cmake/O2RootMacroExclusionList.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ list(APPEND O2_ROOT_MACRO_EXCLUSION_LIST
3838
GPU/TPCFastTransformation/macro/initTPCcalibration.C # Needs AliTPCCalibDB
3939
GPU/TPCFastTransformation/macro/loadlibs.C # Special macro
4040
GPU/TPCFastTransformation/macro/moveTPCFastTransform.C # Relies on initTPCcalibration.C
41+
Detectors/TOF/prototyping/ConvertRun2CalibrationToO2.C
4142
Generators/share/external/hijing.C
4243
Generators/share/external/QEDepem.C
4344
macro/SetIncludePath.C

0 commit comments

Comments
 (0)