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 
std::map< Key, std::pair< double, double > > TimingMap
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:166
ESProducts< std::remove_reference_t< TArgs >... > products(TArgs &&... args)
Definition: ESProducts.h:128
PPSTimingCalibrationESSource(const edm::ParameterSet &)
static const IOVSyncValue & endOfTime()
Definition: IOVSyncValue.cc:82
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &) override
std::pair< Time_t, Time_t > ValidityInterval
Definition: Time.h:17
std::unique_ptr< PPSTimingCalibration > parsePPSDiamondJsonFile() const
Extract calibration data from JSON file (PPS horizontal diamond)
EventSetup record for TOTEM/PPS timing calibration information.
static const IOVSyncValue & beginOfTime()
Definition: IOVSyncValue.cc:88
Helper structure for indexing calibration data.
edm::ESProducts< std::unique_ptr< PPSTimingCalibration > > produce(const PPSTimingCalibrationRcd &)
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
Definition: SourceFactory.h:92
std::unique_ptr< PPSTimingCalibration > parseTotemUFSDJsonFile() const
Extract calibration data from JSON file (TOTEM vertical)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
HLT enums.
std::map< Key, std::vector< double > > ParametersMap
static void fillDescriptions(edm::ConfigurationDescriptions &)