CMS 3D CMS Logo

PPSTimingCalibrationESSource.cc
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * This is a part of CTPPS offline software.
4  * Authors:
5  * Edoardo Bossini
6  * Filip Dej
7  * Laurent Forthomme
8  *
9  * NOTE:
10  * Given implementation handles calibration files in JSON format,
11  * which can be generated using dedicated python script.
12  *
13  ****************************************************************************/
14 
21 
23 
26 
27 #include <boost/property_tree/json_parser.hpp>
28 #include <boost/property_tree/ptree.hpp>
29 
30 namespace pt = boost::property_tree;
31 
32 //------------------------------------------------------------------------------
33 
35 public:
37 
39 
41 
42 private:
43  enum struct DetectorType { INVALID = 0, TOTEM_UFSD = 1, PPS_DIAMOND = 2 };
44 
46  const edm::IOVSyncValue&,
47  edm::ValidityInterval&) override;
48 
50  std::unique_ptr<PPSTimingCalibration> parseTotemUFSDJsonFile() const;
52  std::unique_ptr<PPSTimingCalibration> parsePPSDiamondJsonFile() const;
53 
56 };
57 
58 //------------------------------------------------------------------------------
59 
61  : filename_(iConfig.getParameter<edm::FileInPath>("calibrationFile").fullPath()),
62  subdetector_((DetectorType)iConfig.getParameter<unsigned int>("subDetector")) {
63  setWhatProduced(this);
64  findingRecord<PPSTimingCalibrationRcd>();
65 }
66 
67 //------------------------------------------------------------------------------
68 
70  const PPSTimingCalibrationRcd&) {
71  switch (subdetector_) {
76  default:
77  throw cms::Exception("PPSTimingCalibrationESSource") << "Subdetector " << (int)subdetector_ << " not recognised!";
78  }
79 }
80 
81 //------------------------------------------------------------------------------
82 
84  const edm::IOVSyncValue&,
85  edm::ValidityInterval& oValidity) {
87 }
88 
89 //------------------------------------------------------------------------------
90 
91 std::unique_ptr<PPSTimingCalibration> PPSTimingCalibrationESSource::parseTotemUFSDJsonFile() const {
92  pt::ptree mother_node;
93  pt::read_json(filename_, mother_node);
94 
95  const std::string formula = mother_node.get<std::string>("formula");
98 
99  for (pt::ptree::value_type& par : mother_node.get_child("parameters")) {
101  key.db = (int)strtol(par.first.data(), nullptr, 10);
102 
103  for (pt::ptree::value_type& board : par.second) {
104  key.sampic = board.second.get<int>("sampic");
105  key.channel = board.second.get<int>("channel");
106  double timeOffset = board.second.get<double>("time_offset");
107  double timePrecision = board.second.get<double>("time_precision");
108  key.cell = -1;
109  time_info[key] = {timeOffset, timePrecision};
110 
111  int cell_ct = 0;
112  for (pt::ptree::value_type& cell : board.second.get_child("cells")) {
113  std::vector<double> values;
114  key.cell = cell_ct;
115 
116  for (pt::ptree::value_type& param : cell.second)
117  values.emplace_back(std::stod(param.second.data(), nullptr));
118  params[key] = values;
119  cell_ct++;
120  }
121  }
122  }
123  return std::make_unique<PPSTimingCalibration>(formula, params, time_info);
124 }
125 
126 std::unique_ptr<PPSTimingCalibration> PPSTimingCalibrationESSource::parsePPSDiamondJsonFile() const {
127  pt::ptree mother_node;
128  pt::read_json(filename_, mother_node);
129 
130  const std::string formula = mother_node.get<std::string>("formula");
133 
134  for (pt::ptree::value_type& par : mother_node.get_child("Parameters.Sectors")) {
136  key.db = par.second.get<int>("sector");
137 
138  for (pt::ptree::value_type& st : par.second.get_child("Stations")) {
139  key.sampic = st.second.get<int>("station");
140 
141  for (pt::ptree::value_type& pl : st.second.get_child("Planes")) {
142  key.channel = pl.second.get<int>("plane");
143 
144  for (pt::ptree::value_type& ch : pl.second.get_child("Channels")) {
145  key.cell = ch.second.get<int>("channel");
146  double timeOffset = ch.second.get<double>("time_offset");
147  double timePrecision = ch.second.get<double>("time_precision");
148  time_info[key] = {timeOffset, timePrecision};
149 
150  std::vector<double> values;
151  for (pt::ptree::value_type& param : ch.second.get_child("param"))
152  values.emplace_back(std::stod(param.second.data(), nullptr));
153  params[key] = values;
154  }
155  }
156  }
157  }
158  return std::make_unique<PPSTimingCalibration>(formula, params, time_info);
159 }
160 
163  desc.add<edm::FileInPath>("calibrationFile", edm::FileInPath())
164  ->setComment("file with SAMPIC calibrations, ADC and INL; if empty or corrupted, no calibration will be applied");
165  desc.add<unsigned int>("subDetector", (unsigned int)PPSTimingCalibrationESSource::DetectorType::INVALID)
166  ->setComment("type of sub-detector for which the calibrations are provided");
167 
168  descriptions.add("ppsTimingCalibrationESSource", desc);
169 }
170 
PPSTimingCalibration::TimingMap
std::map< Key, std::pair< double, double > > TimingMap
Definition: PPSTimingCalibration.h:38
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
PPSTimingCalibrationESSource::DetectorType::PPS_DIAMOND
ESHandle.h
DiDispStaMuonMonitor_cfi.pt
pt
Definition: DiDispStaMuonMonitor_cfi.py:39
CalibrationSummaryClient_cfi.params
params
Definition: CalibrationSummaryClient_cfi.py:14
pfMETCorrectionType0_cfi.formula
formula
Definition: pfMETCorrectionType0_cfi.py:46
contentValuesFiles.fullPath
fullPath
Definition: contentValuesFiles.py:64
edm
HLT enums.
Definition: AlignableModifier.h:19
PPSTimingCalibration::Key
Helper structure for indexing calibration data.
Definition: PPSTimingCalibration.h:26
PPSTimingCalibrationESSource::PPSTimingCalibrationESSource
PPSTimingCalibrationESSource(const edm::ParameterSet &)
Definition: PPSTimingCalibrationESSource.cc:60
edm::ESProducer::setWhatProduced
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:138
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
edm::ValidityInterval
Definition: ValidityInterval.h:28
ESProducer.h
edm::ESProducts
Definition: ESProducts.h:105
hgcalLayerClusters_cfi.timeOffset
timeOffset
Definition: hgcalLayerClusters_cfi.py:56
edm::EventSetupRecordIntervalFinder
Definition: EventSetupRecordIntervalFinder.h:33
PPSTimingCalibrationESSource::DetectorType::TOTEM_UFSD
edm::eventsetup::EventSetupRecordKey
Definition: EventSetupRecordKey.h:30
PPSTimingCalibrationESSource
Definition: PPSTimingCalibrationESSource.cc:34
PPSTimingCalibration::ParametersMap
std::map< Key, std::vector< double > > ParametersMap
Definition: PPSTimingCalibration.h:37
edm::es::products
ESProducts< std::remove_reference_t< TArgs >... > products(TArgs &&... args)
Definition: ESProducts.h:128
PPSTimingCalibrationESSource::setIntervalFor
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &) override
Definition: PPSTimingCalibrationESSource.cc:83
edm::FileInPath
Definition: FileInPath.h:64
MakerMacros.h
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
contentValuesCheck.values
values
Definition: contentValuesCheck.py:38
PPSTimingCalibrationESSource::subdetector_
DetectorType subdetector_
Definition: PPSTimingCalibrationESSource.cc:66
PPSTimingCalibrationESSource::produce
edm::ESProducts< std::unique_ptr< PPSTimingCalibration > > produce(const PPSTimingCalibrationRcd &)
Definition: PPSTimingCalibrationESSource.cc:69
edm::IOVSyncValue
Definition: IOVSyncValue.h:31
DEFINE_FWK_EVENTSETUP_SOURCE
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
Definition: SourceFactory.h:91
EventSetupRecordIntervalFinder.h
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
PPSTimingCalibrationESSource::parsePPSDiamondJsonFile
std::unique_ptr< PPSTimingCalibration > parsePPSDiamondJsonFile() const
Extract calibration data from JSON file (PPS horizontal diamond)
Definition: PPSTimingCalibrationESSource.cc:126
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
ESProducts.h
SourceFactory.h
edm::ParameterSet
Definition: ParameterSet.h:36
PPSTimingCalibrationESSource::filename_
const std::string filename_
Definition: PPSTimingCalibrationESSource.cc:65
edm::IOVSyncValue::endOfTime
static const IOVSyncValue & endOfTime()
Definition: IOVSyncValue.cc:82
createfilelist.int
int
Definition: createfilelist.py:10
PPSTimingCalibrationRcd
EventSetup record for TOTEM/PPS timing calibration information.
Definition: PPSTimingCalibrationRcd.h:14
reco::JetExtendedAssociation::value_type
Container::value_type value_type
Definition: JetExtendedAssociation.h:30
PPSTimingCalibration.h
cond::ValidityInterval
std::pair< Time_t, Time_t > ValidityInterval
Definition: Time.h:17
PPSTimingCalibrationESSource::DetectorType::INVALID
Exception
Definition: hltDiff.cc:246
PPSTimingCalibrationRcd.h
edm::IOVSyncValue::beginOfTime
static const IOVSyncValue & beginOfTime()
Definition: IOVSyncValue.cc:88
edm::ESProducer
Definition: ESProducer.h:101
ParameterSet.h
PPSTimingCalibrationESSource::DetectorType
DetectorType
Definition: PPSTimingCalibrationESSource.cc:54
edm::ParameterDescriptionNode::setComment
void setComment(std::string const &value)
Definition: ParameterDescriptionNode.cc:106
PPSTimingCalibrationESSource::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &)
Definition: PPSTimingCalibrationESSource.cc:161
crabWrapper.key
key
Definition: crabWrapper.py:19
PPSTimingCalibrationESSource::parseTotemUFSDJsonFile
std::unique_ptr< PPSTimingCalibration > parseTotemUFSDJsonFile() const
Extract calibration data from JSON file (TOTEM vertical)
Definition: PPSTimingCalibrationESSource.cc:91