Skip to content

Commit 8e08d0a

Browse files
chiarazampollishahor02
authored andcommitted
Reading existing CCDB implemented.
This is not tested yet. What is not clear, also, is how to retrieve the timestamp of the current TF, which is needed to verify if the latest calib entry available is too old. For now I just used a "placeholder". Also the startTimeValidity of the CCDB object should be passed by the framework. Now I am still using the dummy workflow (tof-dummy-ccdb). fixes, but still I get a crash - this commit is to share with others Next try... Still not working Now working
1 parent c448958 commit 8e08d0a

File tree

10 files changed

+246
-22
lines changed

10 files changed

+246
-22
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,18 @@ class CalibTimeSlewingParamTOF
3030

3131
CalibTimeSlewingParamTOF();
3232

33+
CalibTimeSlewingParamTOF(const CalibTimeSlewingParamTOF& source);
34+
3335
CalibTimeSlewingParamTOF& operator=(const CalibTimeSlewingParamTOF& source);
3436

37+
float getChannelOffset(int channel) const;
38+
3539
float evalTimeSlewing(int channel, float tot) const;
3640

3741
void addTimeSlewingInfo(int channel, float tot, float time);
3842

43+
bool updateOffsetInfo(int channel, float residualOffset);
44+
3945
const std::vector<std::pair<float, float>>* getVector(int sector) const { return mTimeSlewing[sector]; }
4046

4147
int size() const

DataFormats/Detectors/TOF/src/CalibTimeSlewingParamTOF.cxx

Lines changed: 111 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ using namespace o2::dataformats;
2121

2222
CalibTimeSlewingParamTOF::CalibTimeSlewingParamTOF()
2323
{
24-
2524
mTimeSlewing[0] = &mTimeSlewingSec00;
2625
mTimeSlewing[1] = &mTimeSlewingSec01;
2726
mTimeSlewing[2] = &mTimeSlewingSec02;
@@ -50,6 +49,78 @@ CalibTimeSlewingParamTOF::CalibTimeSlewingParamTOF()
5049
}
5150
}
5251
//______________________________________________
52+
CalibTimeSlewingParamTOF::CalibTimeSlewingParamTOF(const CalibTimeSlewingParamTOF& source)
53+
{
54+
mTimeSlewingSec00 = source.mTimeSlewingSec00;
55+
mTimeSlewingSec01 = source.mTimeSlewingSec01;
56+
mTimeSlewingSec02 = source.mTimeSlewingSec02;
57+
mTimeSlewingSec03 = source.mTimeSlewingSec03;
58+
mTimeSlewingSec04 = source.mTimeSlewingSec04;
59+
mTimeSlewingSec05 = source.mTimeSlewingSec05;
60+
mTimeSlewingSec06 = source.mTimeSlewingSec06;
61+
mTimeSlewingSec07 = source.mTimeSlewingSec07;
62+
mTimeSlewingSec08 = source.mTimeSlewingSec08;
63+
mTimeSlewingSec09 = source.mTimeSlewingSec09;
64+
mTimeSlewingSec10 = source.mTimeSlewingSec10;
65+
mTimeSlewingSec11 = source.mTimeSlewingSec11;
66+
mTimeSlewingSec12 = source.mTimeSlewingSec12;
67+
mTimeSlewingSec13 = source.mTimeSlewingSec13;
68+
mTimeSlewingSec14 = source.mTimeSlewingSec14;
69+
mTimeSlewingSec15 = source.mTimeSlewingSec15;
70+
mTimeSlewingSec16 = source.mTimeSlewingSec16;
71+
mTimeSlewingSec17 = source.mTimeSlewingSec17;
72+
/*
73+
for (int i = 0; i < source.mTimeSlewingSec00.size(); i++) {
74+
//printf("i = %d, value first = %f, value second = %f\n", i, source.mTimeSlewingSec00[i].first, source.mTimeSlewingSec00[i].second);
75+
mTimeSlewingSec00.push_back(source.mTimeSlewingSec00[i]);
76+
}
77+
78+
for (int i = 0; i < source.mTimeSlewingSec01.size(); i++) mTimeSlewingSec01.push_back(source.mTimeSlewingSec01[i]);
79+
for (int i = 0; i < source.mTimeSlewingSec02.size(); i++) mTimeSlewingSec02.push_back(source.mTimeSlewingSec02[i]);
80+
for (int i = 0; i < source.mTimeSlewingSec03.size(); i++) mTimeSlewingSec03.push_back(source.mTimeSlewingSec03[i]);
81+
for (int i = 0; i < source.mTimeSlewingSec04.size(); i++) mTimeSlewingSec04.push_back(source.mTimeSlewingSec04[i]);
82+
for (int i = 0; i < source.mTimeSlewingSec05.size(); i++) mTimeSlewingSec05.push_back(source.mTimeSlewingSec05[i]);
83+
for (int i = 0; i < source.mTimeSlewingSec06.size(); i++) mTimeSlewingSec06.push_back(source.mTimeSlewingSec06[i]);
84+
for (int i = 0; i < source.mTimeSlewingSec07.size(); i++) mTimeSlewingSec07.push_back(source.mTimeSlewingSec07[i]);
85+
for (int i = 0; i < source.mTimeSlewingSec08.size(); i++) mTimeSlewingSec08.push_back(source.mTimeSlewingSec08[i]);
86+
for (int i = 0; i < source.mTimeSlewingSec09.size(); i++) mTimeSlewingSec09.push_back(source.mTimeSlewingSec09[i]);
87+
for (int i = 0; i < source.mTimeSlewingSec10.size(); i++) mTimeSlewingSec10.push_back(source.mTimeSlewingSec10[i]);
88+
for (int i = 0; i < source.mTimeSlewingSec11.size(); i++) mTimeSlewingSec11.push_back(source.mTimeSlewingSec11[i]);
89+
for (int i = 0; i < source.mTimeSlewingSec12.size(); i++) mTimeSlewingSec12.push_back(source.mTimeSlewingSec12[i]);
90+
for (int i = 0; i < source.mTimeSlewingSec13.size(); i++) mTimeSlewingSec13.push_back(source.mTimeSlewingSec13[i]);
91+
for (int i = 0; i < source.mTimeSlewingSec14.size(); i++) mTimeSlewingSec14.push_back(source.mTimeSlewingSec14[i]);
92+
for (int i = 0; i < source.mTimeSlewingSec15.size(); i++) mTimeSlewingSec15.push_back(source.mTimeSlewingSec15[i]);
93+
for (int i = 0; i < source.mTimeSlewingSec16.size(); i++) mTimeSlewingSec16.push_back(source.mTimeSlewingSec16[i]);
94+
for (int i = 0; i < source.mTimeSlewingSec17.size(); i++) mTimeSlewingSec17.push_back(source.mTimeSlewingSec17[i]);
95+
*/
96+
mTimeSlewing[0] = &mTimeSlewingSec00;
97+
mTimeSlewing[1] = &mTimeSlewingSec01;
98+
mTimeSlewing[2] = &mTimeSlewingSec02;
99+
mTimeSlewing[3] = &mTimeSlewingSec03;
100+
mTimeSlewing[4] = &mTimeSlewingSec04;
101+
mTimeSlewing[5] = &mTimeSlewingSec05;
102+
mTimeSlewing[6] = &mTimeSlewingSec06;
103+
mTimeSlewing[7] = &mTimeSlewingSec07;
104+
mTimeSlewing[8] = &mTimeSlewingSec08;
105+
mTimeSlewing[9] = &mTimeSlewingSec09;
106+
mTimeSlewing[10] = &mTimeSlewingSec10;
107+
mTimeSlewing[11] = &mTimeSlewingSec11;
108+
mTimeSlewing[12] = &mTimeSlewingSec12;
109+
mTimeSlewing[13] = &mTimeSlewingSec13;
110+
mTimeSlewing[14] = &mTimeSlewingSec14;
111+
mTimeSlewing[15] = &mTimeSlewingSec15;
112+
mTimeSlewing[16] = &mTimeSlewingSec16;
113+
mTimeSlewing[17] = &mTimeSlewingSec17;
114+
115+
for (int i = 0; i < NSECTORS; i++) {
116+
for (int j = 0; j < NCHANNELXSECTOR; j++) {
117+
mChannelStart[i][j] = source.mChannelStart[i][j];
118+
mFractionUnderPeak[i][j] = source.mFractionUnderPeak[i][j];
119+
mSigmaPeak[i][j] = source.mSigmaPeak[i][j];
120+
}
121+
}
122+
}
123+
//______________________________________________
53124
CalibTimeSlewingParamTOF& CalibTimeSlewingParamTOF::operator=(const CalibTimeSlewingParamTOF& source)
54125
{
55126
for (int i = 0; i < NSECTORS; i++) {
@@ -64,6 +135,13 @@ CalibTimeSlewingParamTOF& CalibTimeSlewingParamTOF::operator=(const CalibTimeSle
64135
}
65136
return *this;
66137
}
138+
139+
//______________________________________________
140+
float CalibTimeSlewingParamTOF::getChannelOffset(int channel) const
141+
{
142+
return evalTimeSlewing(channel, 0);
143+
}
144+
67145
//______________________________________________
68146
float CalibTimeSlewingParamTOF::evalTimeSlewing(int channel, float tot) const
69147
{
@@ -77,6 +155,10 @@ float CalibTimeSlewingParamTOF::evalTimeSlewing(int channel, float tot) const
77155
if (n < 0)
78156
return 0.;
79157

158+
if (tot == 0) {
159+
return (*(mTimeSlewing[sector]))[n].second;
160+
}
161+
80162
int nstop = (*(mTimeSlewing[sector])).size();
81163
if (channel < NCHANNELXSECTOR - 1)
82164
nstop = mChannelStart[sector][channel + 1];
@@ -127,6 +209,34 @@ void CalibTimeSlewingParamTOF::addTimeSlewingInfo(int channel, float tot, float
127209
}
128210
//______________________________________________
129211

212+
bool CalibTimeSlewingParamTOF::updateOffsetInfo(int channel, float residualOffset)
213+
{
214+
215+
// to update only the channel offset info in an existing CCDB object
216+
217+
int sector = channel / NCHANNELXSECTOR;
218+
channel = channel % NCHANNELXSECTOR;
219+
// printf("sector = %d, channel = %d\n", sector, channel);
220+
221+
// printf("DBG: addTimeSlewinginfo sec=%i\n",sector);
222+
223+
int n = mChannelStart[sector][channel]; // first time slewing entry for the current channel. this corresponds to tot = 0
224+
if ((*(mTimeSlewing[sector]))[n].first != 0) {
225+
printf("DBG: there was no time offset set yet! first tot is %f\n", (*(mTimeSlewing[sector]))[n].first);
226+
std::pair<float, float> offsetToBeInserted(0, residualOffset);
227+
auto it = (*(mTimeSlewing[sector])).begin();
228+
(*(mTimeSlewing[sector])).insert(it+n, offsetToBeInserted);
229+
// now we have to increase by 1 all the mChannelStart for the channels that come after this
230+
for (auto ch = channel+1; ch < NCHANNELXSECTOR; ch++){
231+
mChannelStart[sector][ch]++;
232+
}
233+
return false;
234+
}
235+
(*(mTimeSlewing[sector]))[n].second += residualOffset;
236+
return true;
237+
}
238+
//______________________________________________
239+
130240
CalibTimeSlewingParamTOF& CalibTimeSlewingParamTOF::operator+=(const CalibTimeSlewingParamTOF& other)
131241
{
132242
for (int i = 0; i < NSECTORS; i++) {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ class CalibTOFapi
5656
bool isProblematic(int ich);
5757
float getFractionUnderPeak(int ich) const { return mSlewParam->getFractionUnderPeak(ich); }
5858

59+
SlewParam* getSlewParam() { return mSlewParam; }
60+
SlewParam& getSlewParamObj() { return *mSlewParam; }
61+
5962
private:
6063
long mTimeStamp; ///< timeStamp for queries
6164
LhcPhase* mLHCphase = nullptr; ///< object for LHC phase

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "DataFormatsTOF/CalibInfoTOF.h"
1717
#include "TOFCalibration/CalibTOFapi.h"
1818
#include "DataFormatsTOF/CalibLHCphaseTOF.h"
19+
#include "TOFBase/Geo.h"
1920
#include "CCDB/CcdbObjectInfo.h"
2021
#include <array>
2122

@@ -25,7 +26,7 @@ namespace tof
2526
{
2627

2728
struct LHCClockDataHisto {
28-
float range = 24400;
29+
float range = o2::tof::Geo::BC_TIME_INPS * 0.5;
2930
int nbins = 1000;
3031
float v2Bin = nbins / (2 * range);
3132
int entries = 0;

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

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
#include "DetectorsCalibration/TimeSlotCalibration.h"
1515
#include "DetectorsCalibration/TimeSlot.h"
1616
#include "DataFormatsTOF/CalibInfoTOF.h"
17-
#include "TOFCalibration/CalibTOFapi.h"
1817
#include "DataFormatsTOF/CalibLHCphaseTOF.h"
1918
#include "TOFBase/Geo.h"
2019
#include "CCDB/CcdbObjectInfo.h"
20+
#include "TOFCalibration/CalibTOFapi.h"
21+
2122
#include <array>
2223
#include <boost/histogram.hpp>
2324

@@ -29,6 +30,7 @@ namespace tof
2930
class TOFChannelData {
3031

3132
using Slot = o2::calibration::TimeSlot<o2::tof::TOFChannelData>;
33+
using CalibTOFapi = o2::tof::CalibTOFapi;
3234
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> > >;
3335

3436
public:
@@ -39,7 +41,7 @@ using boostHisto = boost::histogram::histogram<std::tuple<boost::histogram::axis
3941
LOG(INFO) << "Default c-tor, not to be used";
4042
}
4143

42-
TOFChannelData(int nb, float r) : mNBins(nb), mRange(r)
44+
TOFChannelData(int nb, float r, CalibTOFapi* cta) : mNBins(nb), mRange(r), mCalibTOFapi(cta)
4345
{
4446
if (r <= 0. || nb < 1) {
4547
throw std::runtime_error("Wrong initialization of the histogram");
@@ -81,13 +83,15 @@ using boostHisto = boost::histogram::histogram<std::tuple<boost::histogram::axis
8183
std::vector<int> getEntriesPerChannel() const { return mEntries; }
8284

8385
private:
84-
float mRange = 24400;
86+
float mRange = o2::tof::Geo::BC_TIME_INPS * 0.5;
8587
int mNBins = 1000;
8688
float mV2Bin;
8789
// do I really have to initialize it like below?
8890
std::array<boostHisto,18> mHisto;
8991
std::vector<int> mEntries; // vector containing number of entries per channel
9092

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

@@ -104,7 +108,7 @@ class TOFChannelCalibrator : public o2::calibration::TimeSlotCalibration<o2::dat
104108
public:
105109

106110
static const int NCHANNELSXSECTOR = o2::tof::Geo::NCHANNELS / o2::tof::Geo::NSECTORS;
107-
TOFChannelCalibrator(int minEnt = 500, int nb = 1000, float r = 24400, const std::string path = "http://ccdb-test.cern.ch:8080") : mMinEntries(minEnt), mNBins(nb), mRange(r) { mCalibTOFapi.setURL(path); }
111+
TOFChannelCalibrator(int minEnt = 500, int nb = 1000, float r = 24400) : mMinEntries(minEnt), mNBins(nb), mRange(r) {} ;
108112

109113
~TOFChannelCalibrator() final = default;
110114

@@ -119,13 +123,22 @@ class TOFChannelCalibrator : public o2::calibration::TimeSlotCalibration<o2::dat
119123

120124
void isTest(bool isTest) { mTest = isTest; }
121125
bool isTest() const { return mTest; }
126+
127+
void setCalibTOFapi(CalibTOFapi* api) { mCalibTOFapi = api; }
128+
CalibTOFapi* getCalibTOFapi() const { return mCalibTOFapi; }
129+
130+
void setRange(float r) { mRange = r; }
131+
float getRange() const { return mRange; }
122132

123133
private:
124134
int mMinEntries = 0; // min number of entries to calibrate the TimeSlot
125135
int mNBins = 0; // bins of the histogram with the t-text per channel
126136
float mRange = 0.; // range of the histogram with the t-text per channel
127-
bool mTest; // flag to be used when running in test mode: it simplify the processing (e.g. does not go through all channels)
128-
CalibTOFapi mCalibTOFapi;
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)
138+
139+
CalibTOFapi* mCalibTOFapi = nullptr; // CalibTOFapi needed to get the previous calibrations read from CCDB (do we need that it is a pointer?)
140+
141+
// output
129142
CcdbObjectInfoVector mInfoVector; // vector of CCDB Infos , each element is filled with the CCDB description of the accompanying TimeSlewing object
130143
TimeSlewingVector mTimeSlewingVector; // vector of TimeSlewing, each element is filled in "process"
131144
// when we finalize one slot (multiple can be finalized

Detectors/TOF/calibration/src/TOFChannelCalibrator.cxx

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,18 @@ void TOFChannelData::fill(const gsl::span<const o2::dataformats::CalibInfoTOF> d
3939
{
4040
// fill container
4141
for (int i = data.size(); i--;) {
42-
auto dt = data[i].getDeltaTimePi();
4342
auto ch = data[i].getTOFChIndex();
4443
int sector = ch / o2::tof::Geo::NPADSXSECTOR;
4544
int chInSect = ch % o2::tof::Geo::NPADSXSECTOR;
46-
mHisto[sector](dt, chInSect);
45+
auto dt = data[i].getDeltaTimePi();
46+
auto tot = data[i].getTot();
47+
// TO BE DISCUSSED: could it be that the LHCphase is too old? If we ar ein sync mode, it could be that it is not yet created for the current run, so the one from the previous run (which could be very old) is used. But maybe it does not matter much, since soon enough a calibrated LHC phase should be produced
48+
auto corr = mCalibTOFapi->getTimeCalibration(ch, tot); // we take into account LHCphase, offsets and time slewing
49+
// LOG(INFO) << "inserting dt = " << dt << ", tot = " << tot << ", corr = " << corr << ", corrected dt = " << dt-corr;
50+
mHisto[sector](dt - corr, chInSect); // we pass the calibrated time
4751
mEntries[ch] += 1;
4852
}
53+
4954
}
5055

5156
//_____________________________________________
@@ -423,9 +428,13 @@ void TOFChannelCalibrator::finalizeSlot(Slot& slot)
423428

424429
// for the CCDB entry
425430
std::map<std::string, std::string> md;
426-
TimeSlewing ts;
431+
TimeSlewing& ts = mCalibTOFapi->getSlewParamObj(); // we take the current CCDB object, since we want to simply update the offset
432+
for (int ich = 0; ich < 10; ich++){
433+
LOG(INFO) << "for test, checking channel " << ich << ": offset = " << ts.evalTimeSlewing(ich, 0);
434+
}
427435

428436
for (int ich = 0; ich < o2::tof::Geo::NCHANNELS; ich++) {
437+
// LOG(INFO) << "ich = " << ich;
429438
// make the slice of the 2D histogram so that we have the 1D of the current channel
430439
int sector = ich / o2::tof::Geo::NPADSXSECTOR;
431440
int chinsector = ich % o2::tof::Geo::NPADSXSECTOR;
@@ -489,23 +498,28 @@ void TOFChannelCalibrator::finalizeSlot(Slot& slot)
489498
// now we need to store the results in the TimeSlewingObject
490499
ts.setFractionUnderPeak(ich / o2::tof::Geo::NPADSXSECTOR, ich % o2::tof::Geo::NPADSXSECTOR, fractionUnderPeak);
491500
ts.setSigmaPeak(ich / o2::tof::Geo::NPADSXSECTOR, ich % o2::tof::Geo::NPADSXSECTOR, abs(fitValues[2]));
492-
ts.addTimeSlewingInfo(ich, 0, fitValues[1]);
501+
// ts.addTimeSlewingInfo(ich, 0, fitValues[1]);
502+
ts.updateOffsetInfo(ich, fitValues[1]);
503+
}
504+
for (int ich = 0; ich < 10; ich++){
505+
LOG(INFO) << "for test, checking channel " << ich << ": offset = " << ts.evalTimeSlewing(ich, 0);
493506
}
494507
auto clName = o2::utils::MemFileHelper::getClassName(ts);
495508
auto flName = o2::ccdb::CcdbApi::generateFileName(clName);
496509
mInfoVector.emplace_back("TOF/ChannelCalib", clName, flName, md, slot.getTFStart(), 99999999999999);
497510
mTimeSlewingVector.emplace_back(ts);
498-
499-
slot.print();
511+
512+
// slot.print();
500513

501514
}
502515

503516
//_____________________________________________
504517
Slot& TOFChannelCalibrator::emplaceNewSlot(bool front, TFType tstart, TFType tend)
505518
{
519+
506520
auto& cont = getSlots();
507521
auto& slot = front ? cont.emplace_front(tstart, tend) : cont.emplace_back(tstart, tend);
508-
slot.setContainer(std::make_unique<TOFChannelData>(mNBins, mRange));
522+
slot.setContainer(std::make_unique<TOFChannelData>(mNBins, mRange, mCalibTOFapi));
509523
return slot;
510524
}
511525

Detectors/TOF/calibration/testWorkflow/DataGeneratorSpec.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,9 @@ class TFProcessor : public o2::framework::Task
100100
else {
101101
int channel = mTOFChannelCalibInTestMode? gRandom->Integer(100) : gRandom->Integer(o2::tof::Geo::NCHANNELS);
102102
double value = gRandom->Gaus(mChannelShifts[channel], 100.);
103+
double tot = gRandom->Gaus(12, 2);
103104
//LOG(INFO) << "channel = " << channel << ", value = " << value;
104-
output.emplace_back(channel, 0, value, 0, 0);
105+
output.emplace_back(channel, 0, value, tot, 0);
105106
}
106107
}
107108
}

0 commit comments

Comments
 (0)