Skip to content

Commit 44f6af3

Browse files
jokonigshahor02
authored andcommitted
[EMCAL-565, EMCAL-566] Keep start TS info in case of across-run calib.
- The calibration objects for the bad and time calibration are stored in a root file at the end of run, and loaded at the start of the new run - Here, the timestamp was not propagated and as such, the timestamps in the ccdb were not covering the actual ranges of the corresponding data - This (rarely) leads to some seftover bad channels at the end of the run, or for short runs - Now, the timestamp is saved in the root-file with a granularity of seconds, and read in during the next run. - As the previous histograms did not contain the timestamp in seconds, a protection is implemented that, if the histogram only contains 3 bins, the start TS is neglected (This will only happen once!)
1 parent c084241 commit 44f6af3

2 files changed

Lines changed: 41 additions & 24 deletions

File tree

Detectors/EMCAL/calibration/include/EMCALCalibration/EMCALCalibParams.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ struct EMCALCalibParams : public o2::conf::ConfigurableParamHelper<EMCALCalibPar
8888
bool requireSameRunType = true; ///< if loading calib objects from previous run, require it to be the same run type
8989
int tsDiffMax = 48; ///< if loading calib objects from previous run, limit time between the object being stored and loaded again (in hours)
9090
unsigned int minNEventsSaveSlot = 100000; ///< minimum amount a slot has to have in order to be taken into accoutn in finalize slot. THis is also relevant if the slot should be saved at the EOR
91+
bool useStaticStartTimeSlot = true; ///< if set to true, allows to use the start timestamp set manually. This is important if data from a previous run was loaded as otherwise, the start-timestamp will not include data from the previous run
9192

9293
// Parameters for pedestal calibration
9394
short maxPedestalRMS = 10; ///< Maximum value for RMS for pedestals (has to be tuned)

Detectors/EMCAL/calibration/include/EMCALCalibration/EMCALChannelCalibrator.h

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,13 @@ void EMCALChannelCalibrator<DataInput, DataOutput>::finalizeSlot(o2::calibration
187187
}
188188
}
189189

190+
// get the start timestamp of the slot. Either use the manually set start ts if available, or just the start time of the slot.
191+
long tsStart = slot.getStartTimeMS();
192+
if (EMCALCalibParams::Instance().useStaticStartTimeSlot && slot.getStaticStartTimeMS() > 0) {
193+
tsStart = slot.getStaticStartTimeMS();
194+
LOG(info) << "Adjusting the start TS of the slot from " << slot.getStartTimeMS() << " to " << slot.getStaticStartTimeMS();
195+
}
196+
190197
std::map<std::string, std::string> md;
191198
if constexpr (std::is_same<DataInput, o2::emcal::EMCALChannelData>::value) {
192199
LOG(debug) << "Launching the calibration.";
@@ -195,7 +202,7 @@ void EMCALChannelCalibrator<DataInput, DataOutput>::finalizeSlot(o2::calibration
195202
// for the CCDB entry
196203
auto clName = o2::utils::MemFileHelper::getClassName(bcm);
197204
auto flName = o2::ccdb::CcdbApi::generateFileName(clName);
198-
mInfoVector.emplace_back(CalibDB::getCDBPathBadChannelMap(), clName, flName, md, slot.getStartTimeMS(), slot.getEndTimeMS() + EMCALCalibParams::Instance().endTimeMargin, true);
205+
mInfoVector.emplace_back(CalibDB::getCDBPathBadChannelMap(), clName, flName, md, tsStart, slot.getEndTimeMS() + EMCALCalibParams::Instance().endTimeMargin, true);
199206
mCalibObjectVector.push_back(bcm);
200207

201208
if ((EMCALCalibParams::Instance().localRootFilePath).find(".root") != std::string::npos) {
@@ -205,15 +212,15 @@ void EMCALChannelCalibrator<DataInput, DataOutput>::finalizeSlot(o2::calibration
205212
fLocalStorage.cd();
206213

207214
TH2F* histBCMap = (TH2F*)bcm.getHistogramRepresentation();
208-
std::string nameBCHist = "BadChannels_" + std::to_string(slot.getStartTimeMS());
215+
std::string nameBCHist = "BadChannels_" + std::to_string(tsStart);
209216
histBCMap->Write(nameBCHist.c_str(), TObject::kOverwrite);
210217

211218
TH2F hCalibHist = o2::utils::TH2FFromBoost(c->getHisto());
212-
std::string nameBCInputHist = "EnergyVsCellID_" + std::to_string(slot.getStartTimeMS());
219+
std::string nameBCInputHist = "EnergyVsCellID_" + std::to_string(tsStart);
213220
hCalibHist.Write(nameBCInputHist.c_str(), TObject::kOverwrite);
214221

215222
TH2F hCalibHistTime = o2::utils::TH2FFromBoost(c->getHistoTime());
216-
std::string nameBCInputHistTime = "TimeVsCellID_" + std::to_string(slot.getStartTimeMS());
223+
std::string nameBCInputHistTime = "TimeVsCellID_" + std::to_string(tsStart);
217224
hCalibHistTime.Write(nameBCInputHistTime.c_str(), TObject::kOverwrite);
218225

219226
fLocalStorage.Close();
@@ -226,7 +233,7 @@ void EMCALChannelCalibrator<DataInput, DataOutput>::finalizeSlot(o2::calibration
226233
auto flName = o2::ccdb::CcdbApi::generateFileName(clName);
227234

228235
// prepareCCDBobjectInfo
229-
mInfoVector.emplace_back(CalibDB::getCDBPathTimeCalibrationParams(), clName, flName, md, slot.getStartTimeMS(), slot.getEndTimeMS() + EMCALCalibParams::Instance().endTimeMargin, true);
236+
mInfoVector.emplace_back(CalibDB::getCDBPathTimeCalibrationParams(), clName, flName, md, tsStart, slot.getEndTimeMS() + EMCALCalibParams::Instance().endTimeMargin, true);
230237
mCalibObjectVector.push_back(tcd);
231238

232239
if ((EMCALCalibParams::Instance().localRootFilePath).find(".root") != std::string::npos) {
@@ -235,15 +242,15 @@ void EMCALChannelCalibrator<DataInput, DataOutput>::finalizeSlot(o2::calibration
235242
TFile fLocalStorage((EMCALCalibParams::Instance().localRootFilePath).c_str(), ffile.good() == true ? "update" : "recreate");
236243
fLocalStorage.cd();
237244
TH1F* histTCparams = (TH1F*)tcd.getHistogramRepresentation(false); // high gain calibration
238-
std::string nameTCHist = "TCParams_HG_" + std::to_string(slot.getStartTimeMS());
245+
std::string nameTCHist = "TCParams_HG_" + std::to_string(tsStart);
239246
histTCparams->Write(nameTCHist.c_str(), TObject::kOverwrite);
240247

241248
TH1F* histTCparams_LG = (TH1F*)tcd.getHistogramRepresentation(true); // low gain calibration
242-
std::string nameTCHist_LG = "TCParams_LG_" + std::to_string(slot.getStartTimeMS());
249+
std::string nameTCHist_LG = "TCParams_LG_" + std::to_string(tsStart);
243250
histTCparams_LG->Write(nameTCHist_LG.c_str(), TObject::kOverwrite);
244251

245252
TH2F hCalibHist = o2::utils::TH2FFromBoost(c->getHisto());
246-
std::string nameTCInputHist = "TimeVsCellID_" + std::to_string(slot.getStartTimeMS());
253+
std::string nameTCInputHist = "TimeVsCellID_" + std::to_string(tsStart);
247254
hCalibHist.Write(nameTCInputHist.c_str(), TObject::kOverwrite);
248255
fLocalStorage.Close();
249256
}
@@ -270,8 +277,25 @@ bool EMCALChannelCalibrator<DataInput, DataOutput>::saveLastSlotData(TFile& fl)
270277
auto& slot = cont.at(0);
271278
DataInput* c = slot.getContainer();
272279

273-
// timestamp in hours
274-
int timeNow = static_cast<int>(o2::ccdb::getCurrentTimestamp() / o2::ccdb::CcdbObjectInfo::HOUR);
280+
// get the start timestamp of the slot. Either use the manually set start ts if available, or just the start time of the slot.
281+
long tsStart = slot.getStartTimeMS();
282+
if (EMCALCalibParams::Instance().useStaticStartTimeSlot && slot.getStaticStartTimeMS() > 0) {
283+
tsStart = slot.getStaticStartTimeMS();
284+
}
285+
// timestamp in hours and seconds
286+
int timeNowHour = static_cast<int>(tsStart / o2::ccdb::CcdbObjectInfo::HOUR);
287+
int timeNowSec = static_cast<int>(tsStart / o2::ccdb::CcdbObjectInfo::SECOND);
288+
289+
// create global event properties histogram. Same for both calibration types
290+
TH1I hGlobalProperties("hGlobalProperties", "hGlobalProperties", 4, -0.5, 3.5);
291+
hGlobalProperties.GetXaxis()->SetBinLabel(1, "Fill nr.");
292+
hGlobalProperties.GetXaxis()->SetBinLabel(2, "run type");
293+
hGlobalProperties.GetXaxis()->SetBinLabel(3, "ts in hours");
294+
hGlobalProperties.GetXaxis()->SetBinLabel(4, "ts in seconds");
295+
hGlobalProperties.SetBinContent(1, mFillNr);
296+
hGlobalProperties.SetBinContent(2, mRunType);
297+
hGlobalProperties.SetBinContent(3, timeNowHour);
298+
hGlobalProperties.SetBinContent(4, timeNowSec);
275299

276300
if constexpr (std::is_same<DataInput, o2::emcal::EMCALChannelData>::value) {
277301
auto hist = c->getHisto();
@@ -281,31 +305,18 @@ bool EMCALChannelCalibrator<DataInput, DataOutput>::saveLastSlotData(TFile& fl)
281305
TH2F hTime = o2::utils::TH2FFromBoost(histTime, "histTime");
282306
TH1D hNEvents("hNEvents", "hNEvents", 1, 0, 1);
283307
hNEvents.SetBinContent(1, c->getNEvents());
284-
TH1I hGlobalProperties("hGlobalProperties", "hGlobalProperties", 3, -0.5, 2.5);
285-
hGlobalProperties.GetXaxis()->SetBinLabel(1, "Fill nr.");
286-
hGlobalProperties.GetXaxis()->SetBinLabel(2, "run type");
287-
hGlobalProperties.GetXaxis()->SetBinLabel(3, "ts in hours");
288-
hGlobalProperties.SetBinContent(1, mFillNr);
289-
hGlobalProperties.SetBinContent(2, mRunType);
290-
hGlobalProperties.SetBinContent(3, timeNow);
291308

292309
fl.cd();
293310
hEnergy.Write("EnergyVsCellID");
294311
hTime.Write("TimeVsCellID");
295312
hNEvents.Write("NEvents");
296313
hGlobalProperties.Write("GlobalProperties");
314+
297315
} else if constexpr (std::is_same<DataInput, o2::emcal::EMCALTimeCalibData>::value) {
298316
auto histTime = c->getHisto();
299317
TH2F hTime = o2::utils::TH2FFromBoost(histTime);
300318
TH1D hNEvents("hNEvents", "hNEvents", 1, 0, 1);
301319
hNEvents.SetBinContent(1, c->getNEvents());
302-
TH1I hGlobalProperties("hGlobalProperties", "hGlobalProperties", 3, -0.5, 2.5);
303-
hGlobalProperties.GetXaxis()->SetBinLabel(1, "Fill nr.");
304-
hGlobalProperties.GetXaxis()->SetBinLabel(2, "run type");
305-
hGlobalProperties.GetXaxis()->SetBinLabel(3, "ts in hours");
306-
hGlobalProperties.SetBinContent(1, mFillNr);
307-
hGlobalProperties.SetBinContent(2, mRunType);
308-
hGlobalProperties.SetBinContent(3, timeNow);
309320

310321
fl.cd();
311322
hTime.Write("TimeVsCellID");
@@ -344,6 +355,7 @@ bool EMCALChannelCalibrator<DataInput, DataOutput>::adoptSavedData(const o2::cal
344355
int fillNr = hGlobalProperties->GetBinContent(1);
345356
int runType = hGlobalProperties->GetBinContent(2);
346357
int tsOld = hGlobalProperties->GetBinContent(3);
358+
int tsOldSec = (hGlobalProperties->GetNbinsX() > 3) ? hGlobalProperties->GetBinContent(4) : 0; // Protection as 4th bin was only added later
347359
int tsDiff = (mStartTSCalib > 0 ? mStartTSCalib : static_cast<int>(o2::ccdb::getCurrentTimestamp() / o2::ccdb::CcdbObjectInfo::HOUR)) - tsOld; // get current timestamp if mStartTSCalib is not set
348360
LOG(debug) << "tsOld " << tsOld << " tsNow " << (mStartTSCalib > 0 ? mStartTSCalib : static_cast<int>(o2::ccdb::getCurrentTimestamp() / o2::ccdb::CcdbObjectInfo::HOUR)) << " tsDiff " << tsDiff;
349361

@@ -359,6 +371,10 @@ bool EMCALChannelCalibrator<DataInput, DataOutput>::adoptSavedData(const o2::cal
359371
LOG(info) << "adoptSavedData: Maximum difference in ts is: " << EMCALCalibParams::Instance().tsDiffMax << " but " << tsDiff << " is given";
360372
return false;
361373
}
374+
if (EMCALCalibParams::Instance().useStaticStartTimeSlot && tsOldSec > 0) {
375+
slot.setStaticStartTimeMS(static_cast<long>(tsOldSec * o2::ccdb::CcdbObjectInfo::SECOND));
376+
LOG(info) << "adoptSavedData: Setting the start timestamp to " << static_cast<long>(tsOldSec * o2::ccdb::CcdbObjectInfo::SECOND);
377+
}
362378
}
363379

364380
if constexpr (std::is_same<DataInput, o2::emcal::EMCALChannelData>::value) {

0 commit comments

Comments
 (0)