Skip to content

Commit dcb844d

Browse files
chiarazampollishahor02
authored andcommitted
One calib workflow for both LHCphase and TOF channel offsets
and possibility to use the previously calculated LHCphase during the TOFchannel offset calibration. Most of this is just a comment for now, to set the idea on how to do it. Fix and protection. - fix for retriving offset from TimeSlewing object; - protection for possible division by 0 Adapting to generate LHCphase consisent with few ns and other stuff. Some are debug printouts that will be removed. Some fixes Removed useless lines, comments, change LOG(INFO) --> LOG(DEBUG)... clang-format
1 parent c14a85f commit dcb844d

File tree

12 files changed

+238
-177
lines changed

12 files changed

+238
-177
lines changed

DataFormats/Detectors/TOF/src/CalibTimeSlewingParamTOF.cxx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ CalibTimeSlewingParamTOF::CalibTimeSlewingParamTOF()
5353
CalibTimeSlewingParamTOF::CalibTimeSlewingParamTOF(const CalibTimeSlewingParamTOF& source)
5454
{
5555

56-
for (int iSec = 0 ; iSec < NSECTORS; iSec++) {
56+
for (int iSec = 0; iSec < NSECTORS; iSec++) {
5757
mTimeSlewing[iSec] = source.mTimeSlewing[iSec];
5858
}
5959
/*
@@ -108,7 +108,7 @@ CalibTimeSlewingParamTOF::CalibTimeSlewingParamTOF(const CalibTimeSlewingParamTO
108108
CalibTimeSlewingParamTOF& CalibTimeSlewingParamTOF::operator=(const CalibTimeSlewingParamTOF& source)
109109
{
110110
for (int i = 0; i < NSECTORS; i++) {
111-
mTimeSlewing[i].clear(); // CHECK: mTimeSlewing[i] does not work, probably because it is an array of vectors
111+
mTimeSlewing[i].clear(); // CHECK: mTimeSlewing[i] does not work, probably because it is an array of vectors
112112
mTimeSlewing[i] = source.mTimeSlewing[i];
113113

114114
for (int j = 0; j < NCHANNELXSECTOR; j++) {
@@ -131,7 +131,8 @@ float CalibTimeSlewingParamTOF::evalTimeSlewing(int channel, float totIn) const
131131
{
132132

133133
// totIn is in ns
134-
134+
// the correction is returned in ps
135+
135136
int sector = channel / NCHANNELXSECTOR;
136137
channel = channel % NCHANNELXSECTOR;
137138

@@ -142,17 +143,17 @@ float CalibTimeSlewingParamTOF::evalTimeSlewing(int channel, float totIn) const
142143
if (n < 0)
143144
return 0.;
144145

145-
if (totIn == 0) {
146-
return (float)((mTimeSlewing[sector])[n].second);
147-
}
148-
149146
int nstop = (mTimeSlewing[sector]).size();
150147
if (channel < NCHANNELXSECTOR - 1)
151148
nstop = mChannelStart[sector][channel + 1];
152149

153150
if (n >= nstop)
154151
return 0.; // something went wrong!
155152

153+
if (totIn == 0) {
154+
return (float)((mTimeSlewing[sector])[n].second);
155+
}
156+
156157
// we convert tot from ns to ps and to unsigned short
157158
unsigned short tot = (unsigned short)(totIn * 1000);
158159

@@ -183,7 +184,7 @@ void CalibTimeSlewingParamTOF::addTimeSlewingInfo(int channel, float tot, float
183184
// tot here is provided in ns, time in ps;
184185
// tot will have to be converted into ps;
185186
// type will have to be converted to unsigned short (tot) and short (time)
186-
187+
187188
int sector = channel / NCHANNELXSECTOR;
188189
channel = channel % NCHANNELXSECTOR;
189190

@@ -206,7 +207,7 @@ void CalibTimeSlewingParamTOF::addTimeSlewingInfo(int channel, float tot, float
206207

207208
bool CalibTimeSlewingParamTOF::updateOffsetInfo(int channel, float residualOffset)
208209
{
209-
210+
210211
// to update only the channel offset info in an existing CCDB object
211212
// residual offset is given in ps
212213

@@ -218,12 +219,12 @@ bool CalibTimeSlewingParamTOF::updateOffsetInfo(int channel, float residualOffse
218219

219220
int n = mChannelStart[sector][channel]; // first time slewing entry for the current channel. this corresponds to tot = 0
220221
if ((mTimeSlewing[sector])[n].first != 0) {
221-
printf("DBG: there was no time offset set yet! first tot is %f\n", (mTimeSlewing[sector])[n].first);
222+
printf("DBG: there was no time offset set yet! first tot is %d\n", (mTimeSlewing[sector])[n].first);
222223
std::pair<unsigned short, short> offsetToBeInserted(0, (short)residualOffset);
223224
auto it = (mTimeSlewing[sector]).begin();
224-
(mTimeSlewing[sector]).insert(it+n, offsetToBeInserted);
225+
(mTimeSlewing[sector]).insert(it + n, offsetToBeInserted);
225226
// now we have to increase by 1 all the mChannelStart for the channels that come after this
226-
for (auto ch = channel+1; ch < NCHANNELXSECTOR; ch++){
227+
for (auto ch = channel + 1; ch < NCHANNELXSECTOR; ch++) {
227228
mChannelStart[sector][ch]++;
228229
}
229230
return false;

Detectors/Calibration/include/DetectorsCalibration/TimeSlotCalibration.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ bool TimeSlotCalibration<Input, Container>::process(TFType tf, const gsl::span<c
9292
LOG(INFO) << "Ignoring TF " << tf;
9393
return false;
9494
}
95-
95+
9696
// check if some slots are done
9797
checkSlotsToFinalize(tf, maxDelay);
9898
}
99-
99+
100100
// process current TF
101101
auto& slotTF = getSlotForTF(tf);
102102
slotTF.getContainer()->fill(data);
@@ -141,7 +141,8 @@ inline TFType TimeSlotCalibration<Input, Container>::tf2SlotMin(TFType tf) const
141141
if (tf < mFirstTF) {
142142
throw std::runtime_error("invalide TF");
143143
}
144-
if (mUpdateAtTheEndOfRunOnly) return mFirstTF;
144+
if (mUpdateAtTheEndOfRunOnly)
145+
return mFirstTF;
145146
return TFType((tf - mFirstTF) / mSlotLength) * mSlotLength + mFirstTF;
146147
}
147148

@@ -151,13 +152,14 @@ TimeSlot<Container>& TimeSlotCalibration<Input, Container>::getSlotForTF(TFType
151152
{
152153

153154
if (mUpdateAtTheEndOfRunOnly) {
154-
if (!mSlots.empty() && mSlots.back().getTFEnd() < tf) mSlots.back().setTFEnd(tf);
155+
if (!mSlots.empty() && mSlots.back().getTFEnd() < tf)
156+
mSlots.back().setTFEnd(tf);
155157
else if (mSlots.empty()) {
156158
emplaceNewSlot(true, mFirstTF, tf);
157159
}
158160
return mSlots.back();
159161
}
160-
162+
161163
if (!mSlots.empty() && mSlots.front().getTFStart() > tf) { // we need to add a slot to the beginning
162164
auto tfmn = tf2SlotMin(mSlots.front().getTFStart() - 1);
163165
auto tftgt = tf2SlotMin(tf);

Detectors/TOF/calibration/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,10 @@ o2_add_executable(tof-channel-calib-workflow
5050
O2::TOFCalibration
5151
O2::DetectorsCalibration)
5252

53+
o2_add_executable(tof-calib-workflow
54+
COMPONENT_NAME calibration
55+
SOURCES testWorkflow/tof-calib-workflow.cxx
56+
PUBLIC_LINK_LIBRARIES O2::Framework
57+
O2::TOFCalibration
58+
O2::DetectorsCalibration)
59+

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class CalibTOFapi
5858

5959
SlewParam* getSlewParam() { return mSlewParam; }
6060
SlewParam& getSlewParamObj() { return *mSlewParam; }
61-
61+
6262
private:
6363
long mTimeStamp; ///< timeStamp for queries
6464
LhcPhase* mLHCphase = nullptr; ///< object for LHC phase

Detectors/TOF/calibration/include/TOFCalibration/TOFChannelCalibrator.h

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,30 @@ namespace o2
2727
namespace tof
2828
{
2929

30-
class TOFChannelData {
31-
32-
using Slot = o2::calibration::TimeSlot<o2::tof::TOFChannelData>;
33-
using CalibTOFapi = o2::tof::CalibTOFapi;
34-
using boostHisto = boost::histogram::histogram<std::tuple<boost::histogram::axis::regular<double, boost::use_default, boost::use_default, boost::use_default>, boost::histogram::axis::integer<> >, boost::histogram::unlimited_storage<std::allocator<char> > >;
30+
class TOFChannelData
31+
{
3532

36-
public:
33+
using Slot = o2::calibration::TimeSlot<o2::tof::TOFChannelData>;
34+
using CalibTOFapi = o2::tof::CalibTOFapi;
35+
using boostHisto = boost::histogram::histogram<std::tuple<boost::histogram::axis::regular<double, boost::use_default, boost::use_default, boost::use_default>, boost::histogram::axis::integer<>>, boost::histogram::unlimited_storage<std::allocator<char>>>;
3736

37+
public:
3838
static constexpr int NCHANNELSXSECTOR = o2::tof::Geo::NCHANNELS / o2::tof::Geo::NSECTORS;
39-
40-
TOFChannelData() {
39+
40+
TOFChannelData()
41+
{
4142
LOG(INFO) << "Default c-tor, not to be used";
4243
}
4344

44-
TOFChannelData(int nb, float r, CalibTOFapi* cta) : mNBins(nb), mRange(r), mCalibTOFapi(cta)
45+
TOFChannelData(int nb, float r, CalibTOFapi* cta) : mNBins(nb), mRange(r), mCalibTOFapi(cta)
4546
{
4647
if (r <= 0. || nb < 1) {
4748
throw std::runtime_error("Wrong initialization of the histogram");
4849
}
4950
mV2Bin = mNBins / (2 * mRange);
50-
for (int isect = 0; isect < 18; isect ++){
51+
for (int isect = 0; isect < 18; isect++) {
5152
mHisto[isect] = boost::histogram::make_histogram(boost::histogram::axis::regular<>(mNBins, -mRange, mRange, "t-texp"),
52-
boost::histogram::axis::integer<>(0, o2::tof::Geo::NPADSXSECTOR, "channel index in sector" + std::to_string(isect))); // bin is defined as [low, high[
53+
boost::histogram::axis::integer<>(0, o2::tof::Geo::NPADSXSECTOR, "channel index in sector" + std::to_string(isect))); // bin is defined as [low, high[
5354
}
5455
mEntries.resize(o2::tof::Geo::NCHANNELS, 0);
5556
}
@@ -86,12 +87,11 @@ using boostHisto = boost::histogram::histogram<std::tuple<boost::histogram::axis
8687
float mRange = o2::tof::Geo::BC_TIME_INPS * 0.5;
8788
int mNBins = 1000;
8889
float mV2Bin;
89-
// do I really have to initialize it like below?
90-
std::array<boostHisto,18> mHisto;
90+
std::array<boostHisto, 18> mHisto;
9191
std::vector<int> mEntries; // vector containing number of entries per channel
9292

93-
CalibTOFapi* mCalibTOFapi = nullptr; // calibTOFapi to correct the t-text
94-
93+
CalibTOFapi* mCalibTOFapi = nullptr; // calibTOFapi to correct the t-text
94+
9595
ClassDefNV(TOFChannelData, 1);
9696
};
9797

@@ -106,9 +106,8 @@ class TOFChannelCalibrator : public o2::calibration::TimeSlotCalibration<o2::dat
106106
using TimeSlewingVector = std::vector<TimeSlewing>;
107107

108108
public:
109-
110109
static const int NCHANNELSXSECTOR = o2::tof::Geo::NCHANNELS / o2::tof::Geo::NSECTORS;
111-
TOFChannelCalibrator(int minEnt = 500, int nb = 1000, float r = 24400) : mMinEntries(minEnt), mNBins(nb), mRange(r) {} ;
110+
TOFChannelCalibrator(int minEnt = 500, int nb = 1000, float r = 24400) : mMinEntries(minEnt), mNBins(nb), mRange(r){};
112111

113112
~TOFChannelCalibrator() final = default;
114113

@@ -126,26 +125,26 @@ class TOFChannelCalibrator : public o2::calibration::TimeSlotCalibration<o2::dat
126125

127126
void setCalibTOFapi(CalibTOFapi* api) { mCalibTOFapi = api; }
128127
CalibTOFapi* getCalibTOFapi() const { return mCalibTOFapi; }
129-
128+
130129
void setRange(float r) { mRange = r; }
131130
float getRange() const { return mRange; }
132-
131+
133132
private:
134-
int mMinEntries = 0; // min number of entries to calibrate the TimeSlot
135-
int mNBins = 0; // bins of the histogram with the t-text per channel
136-
float mRange = 0.; // range of the histogram with the t-text per channel
137-
bool mTest = false; // flag to be used when running in test mode: it simplify the processing (e.g. does not go through all channels)
133+
int mMinEntries = 0; // min number of entries to calibrate the TimeSlot
134+
int mNBins = 0; // bins of the histogram with the t-text per channel
135+
float mRange = 0.; // range of the histogram with the t-text per channel
136+
bool mTest = false; // flag to be used when running in test mode: it simplify the processing (e.g. does not go through all channels)
138137

139138
CalibTOFapi* mCalibTOFapi = nullptr; // CalibTOFapi needed to get the previous calibrations read from CCDB (do we need that it is a pointer?)
140139

141-
// output
142-
CcdbObjectInfoVector mInfoVector; // vector of CCDB Infos , each element is filled with the CCDB description of the accompanying TimeSlewing object
143-
TimeSlewingVector mTimeSlewingVector; // vector of TimeSlewing, each element is filled in "process"
144-
// when we finalize one slot (multiple can be finalized
145-
// during the same "process", which is why we have a vector).
146-
// Each element is to be considered the output of the device,
147-
// and will go to the CCDB. Note that for the channel offset
148-
// we still fill the TimeSlewing object
140+
// output
141+
CcdbObjectInfoVector mInfoVector; // vector of CCDB Infos , each element is filled with the CCDB description of the accompanying TimeSlewing object
142+
TimeSlewingVector mTimeSlewingVector; // vector of TimeSlewing, each element is filled in "process"
143+
// when we finalize one slot (multiple can be finalized
144+
// during the same "process", which is why we have a vector).
145+
// Each element is to be considered the output of the device,
146+
// and will go to the CCDB. Note that for the channel offset
147+
// we still fill the TimeSlewing object
149148

150149
ClassDefOverride(TOFChannelCalibrator, 1);
151150
};

Detectors/TOF/calibration/src/TOFCalibrationLinkDef.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@
2626
#pragma link C++ class o2::tof::TOFChannelData + ;
2727
#pragma link C++ class o2::tof::TOFChannelCalibrator + ;
2828
#pragma link C++ class o2::calibration::TimeSlot < o2::tof::TOFChannelData> + ;
29-
#pragma link C++ class o2::calibration::TimeSlotCalibration<o2::dataformats::CalibInfoTOF, o2::tof::TOFChannelData> + ;
29+
#pragma link C++ class o2::calibration::TimeSlotCalibration < o2::dataformats::CalibInfoTOF, o2::tof::TOFChannelData> + ;
3030

3131
#endif

0 commit comments

Comments
 (0)