CMS 3D CMS Logo

UETableProducer.cc
Go to the documentation of this file.
1 // system include files
2 #include <iostream>
3 #include <fstream>
4 #include <vector>
5 #include <string>
6 #include <algorithm>
7 
8 // user include files
11 
17 
19 
23 
24 // For DB entry using JetCorrector to store the vector of float
26 
28 
29 using namespace std;
30 //
31 // class decleration
32 //
33 
34 namespace {
35  class UETableProducer : public edm::one::EDAnalyzer<> {
36  public:
37  explicit UETableProducer(const edm::ParameterSet&);
38  ~UETableProducer() override;
39 
40  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
41 
42  private:
43  void beginJob() override {}
44  void analyze(const edm::Event&, const edm::EventSetup&) override;
45  void endJob() override;
46 
47  // ----------member data ---------------------------
48 
49  bool debug_;
50  bool jetCorrectorFormat_;
51 
52  string calibrationFile_;
53  unsigned int runnum_;
54 
55  unsigned int index = 0, np[5], ni0[2], ni1[2], ni2[2];
56 
57  // ue_interpolation_pf0[15][344],
58  // ue_interpolation_pf1[15][344],
59  // ue_interpolation_pf2[15][82];
60  };
61 } // namespace
62 //
63 // constants, enums and typedefs
64 //
65 
66 //
67 // static data member definitions
68 //
69 
70 //
71 // constructors and destructor
72 //
73 UETableProducer::UETableProducer(const edm::ParameterSet& iConfig) : runnum_(0) {
74  //now do what ever initialization is needed
75  calibrationFile_ = iConfig.getParameter<std::string>("txtFile");
76  //calibrationFile_ = "RecoHI/HiJetAlgos/data/ue_calibrations_pf_data.txt";
77 
78  debug_ = iConfig.getUntrackedParameter<bool>("debug", false);
79  jetCorrectorFormat_ = iConfig.getUntrackedParameter<bool>("jetCorrectorFormat", false);
80 
81  np[0] = 3; // Number of reduced PF ID (track, ECAL, HCAL)
82  np[1] = 15; // Number of pseudorapidity block
83  np[2] = 5; // Fourier series order
84  np[3] = 2; // Re or Im
85  np[4] = 82; // Number of feature parameter
86 
87  ni0[0] = np[1];
88  ni0[1] = 344; // Number of track binning (kept = ECAL)
89 
90  ni1[0] = np[1];
91  ni1[1] = 344; // Number of ECAL binning
92 
93  ni2[0] = np[1];
94  ni2[1] = 82; // Number of HCAL binning
95 }
96 
97 UETableProducer::~UETableProducer() {
98  // do anything here that needs to be done at desctruction time
99  // (e.g. close files, deallocate resources etc.)
100 }
101 
102 //
103 // member functions
104 //
105 
106 // ------------ method called to for each event ------------
107 void UETableProducer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
108  // nothing
109 }
110 
111 // ------------ method called once each job just after ending the event loop ------------
112 void UETableProducer::endJob() {
113  std::string qpDataName = calibrationFile_;
114  std::ifstream textTable_(qpDataName.c_str());
115 
116  std::vector<float> ue_vec;
117  std::unique_ptr<UETable> ue_predictor_pf;
118 
119  if (!jetCorrectorFormat_) {
120  ue_predictor_pf = std::make_unique<UETable>();
121  }
122  // unsigned int Nnp_full = np[0] * np[1] * np[2] * np[3] * np[4];
123  unsigned int Nnp = np[0] * np[1] * (1 + (np[2] - 1) * np[3]) * np[4];
124  unsigned int Nni0 = ni0[0] * ni0[1];
125  unsigned int Nni1 = ni1[0] * ni1[1];
126  unsigned int Nni2 = ni2[0] * ni2[1];
127 
128  if (!jetCorrectorFormat_) {
129  ue_predictor_pf->np.resize(5);
130  ue_predictor_pf->ni0.resize(2);
131  ue_predictor_pf->ni1.resize(2);
132  ue_predictor_pf->ni2.resize(2);
133 
134  std::copy(np, np + 5, ue_predictor_pf->np.begin());
135  std::copy(ni0, ni0 + 2, ue_predictor_pf->ni0.begin());
136  std::copy(ni1, ni1 + 2, ue_predictor_pf->ni1.begin());
137  std::copy(ni2, ni2 + 2, ue_predictor_pf->ni2.begin());
138 
139  static const float edge_pseudorapidity[16] = {-5.191,
140  -2.650,
141  -2.043,
142  -1.740,
143  -1.479,
144  -1.131,
145  -0.783,
146  -0.522,
147  0.522,
148  0.783,
149  1.131,
150  1.479,
151  1.740,
152  2.043,
153  2.650,
154  5.191};
155 
156  ue_predictor_pf->edgeEta.resize(16);
157 
158  std::copy(edge_pseudorapidity, edge_pseudorapidity + 16, ue_predictor_pf->edgeEta.begin());
159  }
160 
162 
163  while (std::getline(textTable_, line)) {
164  if (line.empty() || line[0] == '#') {
165  std::cout << " continue " << std::endl;
166  continue;
167  }
168  std::istringstream linestream(line);
169  float val;
170  int bin0, bin1, bin2, bin3, bin4;
171  if (index < Nnp) {
172  linestream >> bin0 >> bin1 >> bin2 >> bin3 >> bin4 >> val;
173  ue_vec.push_back(val);
174  } else if (index < Nnp + Nni0) {
175  linestream >> bin0 >> bin1 >> val;
176  ue_vec.push_back(val);
177  } else if (index < Nnp + Nni0 + Nni1) {
178  linestream >> bin0 >> bin1 >> val;
179  ue_vec.push_back(val);
180  } else if (index < Nnp + Nni0 + Nni1 + Nni2) {
181  linestream >> bin0 >> bin1 >> val;
182  ue_vec.push_back(val);
183  }
184  ++index;
185  }
186 
188 
189  if (pool.isAvailable()) {
190  if (jetCorrectorFormat_) {
191  // A minimal dummy line that satisfies the JME # token >= 6 requirement, and has the correct key type
192  JetCorrectorParameters::Definitions definition("1 0 0 0 Correction L1Offset");
193  std::vector<JetCorrectorParameters::Record> record(
194  1,
196  ue_vec.size(), std::vector<float>(ue_vec.size(), 0), std::vector<float>(ue_vec.size(), 0), ue_vec));
198 
199  std::unique_ptr<JetCorrectorParametersCollection> jme_payload =
200  std::make_unique<JetCorrectorParametersCollection>();
201 
202  jme_payload->push_back(JetCorrectorParametersCollection::L1Offset, parameter);
203 
204  if (pool->isNewTagRequest("JetCorrectionsRecord")) {
205  pool->createNewIOV<JetCorrectorParametersCollection>(
206  jme_payload.get(), pool->beginOfTime(), pool->endOfTime(), "JetCorrectionsRecord");
207  } else {
208  pool->appendSinceTime<JetCorrectorParametersCollection>(
209  jme_payload.get(), pool->currentTime(), "JetCorrectionsRecord");
210  }
211  } else {
212  ue_predictor_pf->values = ue_vec;
213 
214  if (pool->isNewTagRequest("HeavyIonUERcd")) {
215  pool->createNewIOV<UETable>(ue_predictor_pf.get(), pool->beginOfTime(), pool->endOfTime(), "HeavyIonUERcd");
216  } else {
217  pool->appendSinceTime<UETable>(ue_predictor_pf.get(), pool->currentTime(), "HeavyIonUERcd");
218  }
219  }
220  }
221 }
222 
225  desc.add<std::string>("txtFile", "example");
226  desc.addUntracked<bool>("debug", false);
227  desc.addUntracked<bool>("jetCorrectorFormat", false);
228  descriptions.add("produceUETable", desc);
229 }
230 
231 //define this as a plug-in
232 DEFINE_FWK_MODULE(UETableProducer);
bk::beginJob
void beginJob()
Definition: Breakpoints.cc:14
EDAnalyzer.h
JetCorrectorParametersCollection
Definition: JetCorrectorParameters.h:139
pfMETsysShiftCorrections_cfi.parameter
parameter
Definition: pfMETsysShiftCorrections_cfi.py:118
filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
ESHandle.h
JetCorrectorParametersCollection::L1Offset
Definition: JetCorrectorParameters.h:147
gather_cfg.cout
cout
Definition: gather_cfg.py:144
np
int np
Definition: AMPTWrapper.h:43
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
JetCorrectorParameters::Record
Definition: JetCorrectorParameters.h:63
GlobalPosition_Frontier_DevDB_cff.record
record
Definition: GlobalPosition_Frontier_DevDB_cff.py:10
UETable.h
JetCorrectorParameters::Definitions
Definition: JetCorrectorParameters.h:31
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
edm::one::EDAnalyzer
Definition: EDAnalyzer.h:30
UETable
Definition: UETable.h:7
FileInPath.h
MakerMacros.h
PoolDBOutputService.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
Service.h
JetCorrectorParameters.h
fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
edm::Service< cond::service::PoolDBOutputService >
iEvent
int iEvent
Definition: GenABIO.cc:224
analyze
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
edm::EventSetup
Definition: EventSetup.h:57
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
heppy_batch.val
val
Definition: heppy_batch.py:351
std
Definition: JetResolutionObject.h:76
Frameworkfwd.h
HeavyIonUERcd.h
JetCorrectorParameters
Definition: JetCorrectorParameters.h:25
EventSetup.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
ParameterSet.h
edm::Event
Definition: Event.h:73
mps_splice.line
line
Definition: mps_splice.py:76
submitPVResolutionJobs.pool
pool
Definition: submitPVResolutionJobs.py:351