30 #include <boost/property_tree/json_parser.hpp> 31 #include <boost/property_tree/ptree.hpp> 43 namespace pt = boost::property_tree;
71 dqmDir_(iConfig.getParameter<
std::
string>(
"dqmDir")),
72 min_entries_(iConfig.getParameter<unsigned
int>(
"minEntries")),
73 jsonCalibFile_(iConfig.getParameter<
std::
string>(
"jsonCalibFile")),
74 jsonOutputPath_(iConfig.getParameter<
std::
string>(
"jsonOutputPath")) {
86 for (
auto it =
geom.beginSensor(); it !=
geom.endSensor(); ++it) {
98 auto histDb = iGetter.
get(
path +
"db");
99 auto histSampic = iGetter.
get(
path +
"sampic");
100 auto histChannel = iGetter.
get(
path +
"channel");
102 if (histDb ==
nullptr) {
103 edm::LogWarning(
"PPSDiamondSampicTimingCalibrationPCLHarvester:dqmEndJob")
104 <<
"Failed to retrieve db for detid: " << detid;
108 if (histSampic ==
nullptr) {
109 edm::LogWarning(
"PPSDiamondSampicTimingCalibrationPCLHarvester:dqmEndJob")
110 <<
"Failed to retrieve sampic for detid: " << detid;
114 if (histChannel ==
nullptr) {
115 edm::LogWarning(
"PPSDiamondSampicTimingCalibrationPCLHarvester:dqmEndJob")
116 <<
"Failed to retrieve channel hwId for detid: " << detid;
120 db = histDb->getIntValue();
121 sampic = histSampic->getIntValue();
122 channel = histChannel->getIntValue();
129 std::unordered_map<uint32_t, dqm::reco::MonitorElement*> timeHisto;
136 for (
const auto& detid :
detids_) {
138 detid.channelName(ch_name);
140 const auto chid = detid.rawId();
142 int db, sampic, channel;
148 double new_time_offset;
149 if (ct == 16 * (1 - sampic) + channel) {
150 double old_time_offset = par.second.get<
double>(
"time_offset");
152 timeHisto[chid] = iGetter.
get(
path);
154 if (timeHisto[chid] ==
nullptr) {
155 edm::LogWarning(
"PPSDiamondSampicTimingCalibrationPCLHarvester:dqmEndJob")
156 <<
"Failed to retrieve time monitor for detid" << detid;
157 par.second.put<
double>(
"time_offset", old_time_offset);
162 edm::LogWarning(
"PPSDiamondSampicTimingCalibrationPCLHarvester:dqmEndJob")
163 <<
"Not enough entries for channel (" << detid <<
"): " << timeHisto[chid]->getEntries() <<
" < " 165 par.second.put<
double>(
"time_offset", old_time_offset);
168 new_time_offset = old_time_offset - timeHisto[chid]->getMean();
170 timeHisto[chid]->getTH1F()->GetXaxis()->Set(
171 timeHisto[chid]->getTH1F()->GetXaxis()->GetNbins(),
172 timeHisto[chid]->getTH1F()->GetXaxis()->GetXmin() + new_time_offset,
173 timeHisto[chid]->getTH1F()->GetXaxis()->GetXmax() + new_time_offset);
174 timeHisto[chid]->getTH1F()->ResetStats();
176 par.second.put<
double>(
"time_offset", new_time_offset);
194 std::unordered_map<uint32_t, dqm::reco::MonitorElement*> timeHisto;
198 for (
const auto& detid :
detids_) {
200 detid.channelName(ch_name);
202 const auto chid = detid.rawId();
204 int db, sampic, channel;
211 key.channel = channel;
214 double timePrecision =
calib.timePrecision(
db, sampic, channel);
216 edm::LogWarning(
"PPSDiamondSampicTimingCalibrationPCLHarvester:dqmEndJob")
217 <<
"No calibration found for db: " <<
db <<
" sampic: " << sampic <<
" channel: " << channel;
222 while (!
calib.parameters(
db, sampic, channel, cell_ct).empty()) {
232 timeHisto[chid] = iGetter.
get(
path);
233 if (timeHisto[chid] ==
nullptr) {
234 edm::LogWarning(
"PPSDiamondSampicTimingCalibrationPCLHarvester:dqmEndJob")
235 <<
"Failed to retrieve time monitor for detid: " << detid;
240 edm::LogInfo(
"PPSDiamondSampicTimingCalibrationPCLHarvester:dqmEndJob")
241 <<
"Not enough entries (" << detid <<
"): " << timeHisto[chid]->getEntries() <<
" < " <<
min_entries_ 242 <<
". Skipping calibration.";
246 double new_time_offset =
timeOffset - timeHisto[chid]->getMean();
248 timeHisto[chid]->getTH1F()->GetXaxis()->Set(
249 timeHisto[chid]->getTH1F()->GetXaxis()->GetNbins(),
250 timeHisto[chid]->getTH1F()->GetXaxis()->GetXmin() + new_time_offset,
251 timeHisto[chid]->getTH1F()->GetXaxis()->GetXmax() + new_time_offset);
252 timeHisto[chid]->getTH1F()->ResetStats();
254 time_info[
key] = {new_time_offset, timePrecision};
278 desc.add<
std::string>(
"timingCalibrationTag",
"GlobalTag:PPSDiamondSampicCalibration")
279 ->setComment(
"input tag for timing calibration retrieval");
280 desc.add<
std::string>(
"dqmDir",
"AlCaReco/PPSDiamondSampicTimingCalibrationPCL")
281 ->setComment(
"input path for the various DQM plots");
282 desc.add<
unsigned int>(
"minEntries", 1)->setComment(
"minimal number of hits to extract calibration");
285 "input path for json file containing calibration, if none, calibration will be obtained from db instead");
286 desc.add<
std::string>(
"jsonOutputPath",
"offset_cal.json")->setComment(
"output path for the new json calibration");
287 descriptions.
add(
"PPSDiamondSampicTimingCalibrationPCLHarvester",
desc);
edm::ESHandle< PPSTimingCalibration > hTimingCalib_
std::map< Key, std::pair< double, double > > TimingMap
T getParameter(std::string const &) const
PPSDiamondSampicTimingCalibrationPCLHarvester(const edm::ParameterSet &)
virtual void setCurrentFolder(std::string const &fullpath)
#define DEFINE_FWK_MODULE(type)
const std::string jsonCalibFile_
std::string to_string(const V &value)
void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override
edm::ESGetToken< CTPPSGeometry, VeryForwardRealGeometryRecord > geomEsToken_
static void fillDescriptions(edm::ConfigurationDescriptions &)
Container::value_type value_type
cond::Time_t currentTime() const
const std::string dqmDir_
Helper structure for indexing calibration data.
const unsigned int min_entries_
Hash writeOneIOV(const T &payload, Time_t time, const std::string &recordName)
void calibJson(DQMStore::IGetter &iGetter)
bool getData(T &iHolder) const
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
bool getDbSampicChannel(DQMStore::IGetter &iGetter, int &db, int &sampic, int &channel, std::string ch_name, CTPPSDiamondDetId detid)
static bool check(unsigned int raw)
returns true if the raw ID is a PPS-timing one
std::vector< CTPPSDiamondDetId > detids_
Log< level::Info, false > LogInfo
void add(std::string const &label, ParameterSetDescription const &psetDescription)
virtual MonitorElement * get(std::string const &fullpath) const
std::map< Key, std::vector< double > > ParametersMap
Detector ID class for CTPPS Timing Diamond detectors. Bits [19:31] : Assigend in CTPPSDetId Calss Bit...
const std::string jsonOutputPath_
Log< level::Warning, false > LogWarning
void beginRun(const edm::Run &, const edm::EventSetup &) override
void calibDb(DQMStore::IGetter &iGetter)
edm::ESGetToken< PPSTimingCalibration, PPSTimingCalibrationRcd > timingCalibrationToken_