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 {
36  public:
38 
40 
42 
43  private:
44  enum struct DetectorType
45  {
46  INVALID = 0,
47  TOTEM_UFSD = 1,
48  PPS_DIAMOND = 2
49  };
50 
52 
54  std::unique_ptr<PPSTimingCalibration> parseTotemUFSDJsonFile() const;
56  std::unique_ptr<PPSTimingCalibration> parsePPSDiamondJsonFile() const;
57 
60 };
61 
62 //------------------------------------------------------------------------------
63 
65  filename_ ( iConfig.getParameter<edm::FileInPath>( "calibrationFile" ).fullPath() ),
66  subdetector_( (DetectorType)iConfig.getParameter<unsigned int>( "subDetector" ) )
67 {
68  setWhatProduced( this );
69  findingRecord<PPSTimingCalibrationRcd>();
70 }
71 
72 //------------------------------------------------------------------------------
73 
76 {
77  switch ( subdetector_ ) {
82  default:
83  throw cms::Exception( "PPSTimingCalibrationESSource" )
84  << "Subdetector " << (int)subdetector_ << " not recognised!";
85  }
86 }
87 
88 //------------------------------------------------------------------------------
89 
90 void
92  const edm::IOVSyncValue&,
93  edm::ValidityInterval& oValidity )
94 {
96 }
97 
98 //------------------------------------------------------------------------------
99 
100 std::unique_ptr<PPSTimingCalibration>
102 {
103  pt::ptree mother_node;
104  pt::read_json( filename_, mother_node );
105 
106  const std::string formula = mother_node.get<std::string>( "formula" );
109 
110  for ( pt::ptree::value_type& par : mother_node.get_child( "parameters" ) ) {
112  key.db = (int)strtol( par.first.data(), nullptr, 10 );
113 
114  for ( pt::ptree::value_type& board : par.second ) {
115  key.sampic = board.second.get<int>( "sampic" );
116  key.channel = board.second.get<int>( "channel" );
117  double timeOffset = board.second.get<double>( "time_offset" );
118  double timePrecision = board.second.get<double>( "time_precision" );
119  key.cell = -1;
120  time_info[key] = { timeOffset, timePrecision };
121 
122  int cell_ct = 0;
123  for ( pt::ptree::value_type& cell : board.second.get_child( "cells" ) ) {
124  std::vector<double> values;
125  key.cell = cell_ct;
126 
127  for ( pt::ptree::value_type& param : cell.second )
128  values.emplace_back( std::stod( param.second.data(), nullptr ) );
129  params[key] = values;
130  cell_ct++;
131  }
132  }
133  }
134  return std::make_unique<PPSTimingCalibration>( formula, params, time_info );
135 }
136 
137 std::unique_ptr<PPSTimingCalibration>
139 {
140  pt::ptree mother_node;
141  pt::read_json( filename_, mother_node );
142 
143  const std::string formula = mother_node.get<std::string>( "formula" );
146 
147  for ( pt::ptree::value_type& par : mother_node.get_child( "Parameters.Sectors" ) ) {
149  key.db = par.second.get<int>( "sector" );
150 
151  for ( pt::ptree::value_type& st : par.second.get_child( "Stations" ) ) {
152  key.sampic = st.second.get<int>( "station" );
153 
154  for ( pt::ptree::value_type& pl : st.second.get_child( "Planes" ) ) {
155  key.channel = pl.second.get<int>( "plane" );
156 
157  for ( pt::ptree::value_type& ch : pl.second.get_child( "Channels" ) ) {
158  key.cell = ch.second.get<int>( "channel" );
159  double timeOffset = ch.second.get<double>( "time_offset" );
160  double timePrecision = ch.second.get<double>( "time_precision" );
161  time_info[key] = { timeOffset, timePrecision };
162 
163  std::vector<double> values;
164  for ( pt::ptree::value_type& param : ch.second.get_child( "param" ) )
165  values.emplace_back( std::stod( param.second.data(), nullptr ) );
166  params[key] = values;
167  }
168  }
169  }
170  }
171  return std::make_unique<PPSTimingCalibration>( formula, params, time_info );
172 }
173 
174 void
176 {
178  desc.add<edm::FileInPath>( "calibrationFile", edm::FileInPath() )
179  ->setComment( "file with SAMPIC calibrations, ADC and INL; if empty or corrupted, no calibration will be applied" );
180  desc.add<unsigned int>( "subDetector", (unsigned int)PPSTimingCalibrationESSource::DetectorType::INVALID )
181  ->setComment( "type of sub-detector for which the calibrations are provided" );
182 
183  descriptions.add( "ppsTimingCalibrationESSource", desc );
184 }
185 
187 
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:124
void setComment(std::string const &value)
std::map< Key, std::pair< double, double > > TimingMap
#define nullptr
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:19
EventSetup record for TOTEM/PPS timing calibration information.
ESProducts< std::remove_reference_t< TArgs >... > products(TArgs &&...args)
Definition: ESProducts.h:128
std::unique_ptr< PPSTimingCalibration > parsePPSDiamondJsonFile() const
Extract calibration data from JSON file (PPS horizontal diamond)
std::map< Key, std::vector< double > > ParametersMap
static const IOVSyncValue & beginOfTime()
Definition: IOVSyncValue.cc:88
Helper structure for indexing calibration data.
edm::ESProducts< std::unique_ptr< PPSTimingCalibration > > produce(const PPSTimingCalibrationRcd &)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
HLT enums.
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
Definition: SourceFactory.h:91
std::unique_ptr< PPSTimingCalibration > parseTotemUFSDJsonFile() const
Extract calibration data from JSON file (TOTEM vertical)
static void fillDescriptions(edm::ConfigurationDescriptions &)