Skip to content

Commit 58b398f

Browse files
chiarazampollisawenzel
authored andcommitted
Implementation of CalibTOFapi and first use of it in calibration.
1 parent 44f34d1 commit 58b398f

File tree

11 files changed

+228
-85
lines changed

11 files changed

+228
-85
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ class CalibTimeSlewingParamTOF
5252
void setFractionUnderPeak(int sector, int channel, float value) { mFractionUnderPeak[sector][channel] = value; }
5353
void setSigmaPeak(int sector, int channel, float value) { mSigmaPeak[sector][channel] = value; }
5454

55+
bool isProblematic(int channel) {
56+
int sector = channel/NCHANNELXSECTOR;
57+
int channelInSector = channel%NCHANNELXSECTOR;
58+
return (getFractionUnderPeak(sector, channelInSector) < 0);
59+
}
60+
5561
CalibTimeSlewingParamTOF& operator+=(const CalibTimeSlewingParamTOF& other);
5662

5763
private:

Detectors/GlobalTracking/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ o2_add_library(GlobalTracking
2020
O2::GPUTracking
2121
O2::TPCBase
2222
O2::TPCReconstruction
23-
O2::TOFBase)
23+
O2::TOFBase
24+
O2::TOFCalibration)
2425

2526
o2_target_root_dictionary(GlobalTracking
2627
HEADERS include/GlobalTracking/MatchTPCITS.h

Detectors/GlobalTracking/include/GlobalTracking/CalibTOF.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include "TF1.h"
3131
#include "TFile.h"
3232
#include "TGraphErrors.h"
33-
#include "CCDB/CcdbApi.h"
33+
#include "TOFCalibration/CalibTOFapi.h"
3434

3535
class TTree;
3636

@@ -42,6 +42,7 @@ namespace globaltracking
4242
class CalibTOF
4343
{
4444
using Geo = o2::tof::Geo;
45+
using CalibTOFapi = o2::tof::CalibTOFapi;
4546

4647
public:
4748
static constexpr int NSTRIPSPERSTEP = 13; // we chose this number because we process per sector, and
@@ -165,6 +166,8 @@ class CalibTOF
165166
int mMaxTimestamp = 1; ///< maximum timestamp over the hits that we collect; we need it to
166167
///< book the histogram for the LHCPhase calibration
167168

169+
CalibTOFapi mCalibTOFapi; ///< API to handle TOF calibration objects
170+
168171
// ClassDefNV(CalibTOF, 1);
169172
};
170173
} // namespace globaltracking

Detectors/GlobalTracking/src/CalibTOF.cxx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include <TFile.h>
1717
#include "DataFormatsParameters/GRPObject.h"
1818
#include "ReconstructionDataFormats/PID.h"
19-
#include "CCDB/CcdbApi.h"
2019

2120
#include "GlobalTracking/CalibTOF.h"
2221

@@ -26,7 +25,6 @@
2625
#include "TRandom.h"
2726

2827
using namespace o2::globaltracking;
29-
using CcdbApi = o2::ccdb::CcdbApi;
3028

3129
ClassImp(CalibTOF);
3230

@@ -114,6 +112,9 @@ void CalibTOF::init()
114112
mMaxTimestamp = mMinTimestamp + nbinsLHCphase * 300; // we want that the last bin of the histogram is also large 300s; this we need to do only when we have less than 1000 bins, because in this case we will integrate over intervals that are larger than 300s anyway
115113
mHistoLHCphase = new TH2F("hLHCphase", ";clock offset (ps); timestamp (s)", 1000, -24400, 24400, nbinsLHCphase, mMinTimestamp, mMaxTimestamp);
116114

115+
// setting CCDB for output
116+
mCalibTOFapi.setURL(mCCDBpath.c_str());
117+
117118
mInitDone = true;
118119

119120
print();
@@ -266,16 +267,13 @@ void CalibTOF::fillOutput(int flag)
266267
mOutputTree->Fill();
267268

268269
if (mFillCCDB) {
269-
CcdbApi api;
270-
api.init(mCCDBpath.c_str()); // or http://localhost:8080 for a local installation
271-
272270
if (flag & kLHCphase) {
273271
std::map<std::string, std::string> metadataLHCphase; // can be empty
274-
api.storeAsTFileAny(mLHCphaseObj, "TOF/LHCphase", metadataLHCphase, (ulong)mMinTimestamp*1000, (ulong)mMaxTimestamp*1000); // we use as validity the timestamps that we got from the input for the calibration; but we need to convert to ms for the CCDB (at least for now that we use an integer for the timestamp)
272+
mCalibTOFapi.writeLHCphase(mLHCphaseObj, metadataLHCphase, (ulong)mMinTimestamp*1000, (ulong)mMaxTimestamp*1000); // we use as validity the timestamps that we got from the input for the calibration; but we need to convert to ms for the CCDB (at least for now that we use an integer for the timestamp)
275273
}
276274
if (flag & kChannelOffset || flag & kChannelTimeSlewing) {
277275
std::map<std::string, std::string> metadataChannelCalib; // can be empty
278-
api.storeAsTFileAny(mTimeSlewingObj, "TOF/ChannelCalib", metadataChannelCalib, (ulong)mMinTimestamp*1000); // contains both offset and time slewing; we use as validity the START ONLY timestamp that we got from the input for the calibration; but we need to convert to ms for the CCDB (at least for now that we use an integer for the timestamp), END is default
276+
mCalibTOFapi.writeTimeSlewingParam(mTimeSlewingObj, metadataChannelCalib, (ulong)mMinTimestamp*1000); // contains both offset and time slewing; we use as validity the START ONLY timestamp that we got from the input for the calibration; but we need to convert to ms for the CCDB (at least for now that we use an integer for the timestamp), END is default
279277
}
280278
}
281279
}

Detectors/TOF/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
add_subdirectory(base)
1212
add_subdirectory(simulation)
1313
add_subdirectory(reconstruction)
14+
add_subdirectory(calibration)
1415
if(BUILD_TESTING)
1516
add_subdirectory(prototyping)
1617
endif()
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright CERN and copyright holders of ALICE O2. This software is distributed
2+
# under the terms of the GNU General Public License v3 (GPL Version 3), copied
3+
# 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 or
9+
# submit itself to any jurisdiction.
10+
11+
o2_add_library(TOFCalibration
12+
SOURCES src/CalibTOFapi.cxx
13+
PUBLIC_LINK_LIBRARIES O2::DataFormatsTOF
14+
O2::CCDB)
15+
16+
o2_target_root_dictionary(TOFCalibration
17+
HEADERS include/TOFCalibration/CalibTOFapi.h)
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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_TOF_CALIBTOFAPI_H_
16+
#define ALICEO2_TOF_CALIBTOFAPI_H_
17+
18+
#include <iostream>
19+
#include "CCDB/BasicCCDBManager.h"
20+
#include "DataFormatsTOF/CalibLHCphaseTOF.h"
21+
#include "DataFormatsTOF/CalibTimeSlewingParamTOF.h"
22+
23+
namespace o2
24+
{
25+
namespace tof {
26+
27+
class CalibTOFapi
28+
{
29+
30+
using lhcPhase = o2::dataformats::CalibLHCphaseTOF;
31+
using slewParam = o2::dataformats::CalibTimeSlewingParamTOF;
32+
using ccdbManager = o2::ccdb::BasicCCDBManager;
33+
using CcdbApi = o2::ccdb::CcdbApi;
34+
35+
public:
36+
CalibTOFapi() = default;
37+
CalibTOFapi(const std::string url);
38+
~CalibTOFapi() = default;
39+
void setTimeStamp(long t) {
40+
mTimeStamp = t;
41+
}
42+
void setURL(const std::string url) {
43+
auto& mgr = ccdbManager::instance();
44+
mgr.setURL(url);
45+
}
46+
void readLHCphase();
47+
void readTimeSlewingParam();
48+
void writeLHCphase(lhcPhase* phase, std::map<std::string, std::string> metadataLHCphase, ulong minTimeSTamp, ulong maxTimeStamp);
49+
void writeTimeSlewingParam(slewParam* param, std::map<std::string, std::string> metadataChannelCalib, ulong minTimeSTamp, ulong maxTimeStamp = 0);
50+
float getTimeCalibration(int ich, float tot);
51+
float getTimeDecalibration(int ich, float tot);
52+
bool isProblematic(int ich);
53+
54+
private:
55+
56+
long mTimeStamp; ///< timeStamp for queries
57+
lhcPhase* mLHCphase = nullptr; ///< object for LHC phase
58+
slewParam* mSlewParam = nullptr; ///< object for timeslewing (containing info also for offset and problematic)
59+
60+
ClassDefNV(CalibTOFapi, 1);
61+
};
62+
} // namespace tof
63+
} // namespace o2
64+
#endif

Detectors/TOF/calibration/include/TOFcalibration/CalibTOFapi.h

Lines changed: 0 additions & 44 deletions
This file was deleted.

Detectors/TOF/calibration/src/CalibTOFapi.cxx

Lines changed: 93 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,105 @@
1111
#include "TOFCalibration/CalibTOFapi.h"
1212

1313
using namespace o2::tof;
14-
using ccdbManager = o2::ccdb::BasicCCDBManager;
1514

16-
ClassImp(CalibTOFapi);
15+
ClassImp(o2::tof::CalibTOFapi);
1716

18-
CalibTOFapi(const std::string db) {
17+
CalibTOFapi::CalibTOFapi(const std::string url) {
18+
19+
// setting the URL to the CCDB manager
20+
21+
setURL(url);
22+
23+
}
24+
25+
26+
//______________________________________________________________________
27+
28+
void CalibTOFapi::readLHCphase() {
29+
30+
// getting the LHCphase calibration
31+
32+
auto& mgr = ccdbManager::instance();
33+
mLHCphase = mgr.getForTimeStamp<lhcPhase>("TOF/LHCphase", mTimeStamp);
34+
35+
}
36+
37+
//______________________________________________________________________
38+
39+
void CalibTOFapi::readTimeSlewingParam() {
40+
41+
// getting the TimeSlewing calibration
42+
// it includes also offset and information on problematic
1943

20-
mCCDB = db;
2144
auto& mgr = ccdbManager::instance();
22-
mgr.setURL(db);
45+
mSlewParam = mgr.getForTimeStamp<slewParam>("TOF/ChannelCalib", mTimeStamp);
46+
47+
}
48+
49+
//______________________________________________________________________
2350

51+
void CalibTOFapi::writeLHCphase(lhcPhase* phase, std::map<std::string, std::string> metadataLHCphase, ulong minTimeStamp, ulong maxTimeStamp) {
52+
53+
// write LHCphase object to CCDB
54+
55+
auto& mgr = ccdbManager::instance();
56+
CcdbApi api;
57+
api.init(mgr.getURL());
58+
api.storeAsTFileAny(phase, "TOF/LHCphase", metadataLHCphase, minTimeStamp, maxTimeStamp);
59+
2460
}
2561

2662
//______________________________________________________________________
2763

64+
void CalibTOFapi::writeTimeSlewingParam(slewParam* param, std::map<std::string, std::string> metadataChannelCalib, ulong minTimeStamp, ulong maxTimeStamp) {
65+
66+
// write TiemSlewing object to CCDB (it includes offset + problematic)
67+
68+
auto& mgr = ccdbManager::instance();
69+
CcdbApi api;
70+
api.init(mgr.getURL());
71+
if (maxTimeStamp == 0) {
72+
api.storeAsTFileAny(param, "TOF/ChannelCalib", metadataChannelCalib, minTimeStamp);
73+
}
74+
else api.storeAsTFileAny(param, "TOF/ChannelCalib", metadataChannelCalib, minTimeStamp, maxTimeStamp);
75+
76+
}
77+
78+
//______________________________________________________________________
79+
80+
bool CalibTOFapi::isProblematic(int ich) {
81+
82+
// method to know if the channel was problematic or not
83+
84+
return mSlewParam->isProblematic(ich);
85+
86+
}
87+
88+
//______________________________________________________________________
89+
90+
float CalibTOFapi::getTimeCalibration(int ich, float tot) {
91+
92+
// time calibration to correct measured TOF times
93+
94+
float corr = 0;
95+
96+
// LHCphase
97+
corr += mLHCphase->getLHCphase(int(mTimeStamp/1000)); // timestamp that we use in LHCPhase is in seconds, but for CCDB we need it in ms
98+
99+
// time slewing + channel offset
100+
corr += mSlewParam->evalTimeSlewing(ich, tot);
101+
102+
return corr;
103+
104+
}
105+
106+
//______________________________________________________________________
107+
108+
float CalibTOFapi::getTimeDecalibration(int ich, float tot) {
109+
110+
// time decalibration for simulation (it is just the opposite of the calibration)
111+
112+
return -getTimeCalibration(ich, tot);
113+
114+
}
115+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
#ifdef __CLING__
12+
13+
#pragma link off all globals;
14+
#pragma link off all classes;
15+
#pragma link off all functions;
16+
17+
#pragma link C++ class o2::tof::CalibTOFapi + ;
18+
19+
#endif

0 commit comments

Comments
 (0)