CMS 3D CMS Logo

CompareGeneratorResultsAnalyzer.cc
Go to the documentation of this file.
6 
8 
10 
16 
17 #include <sstream>
18 #include <iostream>
19 
20 namespace cgra {
21  struct DummyCache {};
22 }; // namespace cgra
23 
25  : public edm::global::EDAnalyzer<edm::RunCache<cgra::DummyCache>, edm::LuminosityBlockCache<cgra::DummyCache>> {
26 public:
28 
29  std::shared_ptr<cgra::DummyCache> globalBeginRun(edm::Run const&, edm::EventSetup const&) const override;
30  void globalEndRun(edm::Run const&, edm::EventSetup const&) const override;
31 
32  std::shared_ptr<cgra::DummyCache> globalBeginLuminosityBlock(edm::LuminosityBlock const&,
33  edm::EventSetup const&) const override;
34  void globalEndLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) const override;
35 
36  void analyze(edm::StreamID, edm::Event const&, edm::EventSetup const&) const override;
37 
38 private:
41 
44 
47 
50 
53 
56 
58 };
59 
61  : mod1_{iPSet.getUntrackedParameter<std::string>("module1")},
62  mod2_{iPSet.getUntrackedParameter<std::string>("module2")},
63  evToken1_{consumes<GenEventInfoProduct>(mod1_)},
64  evToken2_{consumes<GenEventInfoProduct>(mod2_)},
65  hepMCToken1_{consumes<edm::HepMCProduct>(edm::InputTag(mod1_, "unsmeared"))},
66  hepMCToken2_{consumes<edm::HepMCProduct>(edm::InputTag(mod2_, "unsmeared"))},
67  lumiHeaderToken1_{consumes<GenLumiInfoHeader, edm::InLumi>(mod1_)},
68  lumiHeaderToken2_{consumes<GenLumiInfoHeader, edm::InLumi>(mod2_)},
69  lumiProductToken1_{consumes<GenLumiInfoProduct, edm::InLumi>(mod1_)},
70  lumiProductToken2_{consumes<GenLumiInfoProduct, edm::InLumi>(mod2_)},
71  runProductToken1_{consumes<GenRunInfoProduct, edm::InRun>(mod1_)},
72  runProductToken2_{consumes<GenRunInfoProduct, edm::InRun>(mod2_)},
73  allowXSecDifferences_{iPSet.getUntrackedParameter<bool>("allowXSecDifferences", false)} {}
74 
75 std::shared_ptr<cgra::DummyCache> CompareGeneratorResultsAnalyzer::globalBeginRun(edm::Run const&,
76  edm::EventSetup const&) const {
77  return std::shared_ptr<cgra::DummyCache>();
78 }
79 
81  auto const& prod1 = iRun.get(runProductToken1_);
82  auto const& prod2 = iRun.get(runProductToken2_);
83 
84  if (not prod1.isProductEqual(prod2)) {
85  throw cms::Exception("ComparisonFailure") << "The GenRunInfoProducts are different";
86  }
87 }
88 
90  edm::LuminosityBlock const& iLumi, edm::EventSetup const&) const {
91  auto const& prod1 = iLumi.get(lumiHeaderToken1_);
92  auto const& prod2 = iLumi.get(lumiHeaderToken2_);
93 
94  if (prod1.randomConfigIndex() != prod2.randomConfigIndex()) {
95  throw cms::Exception("ComparisonFailure") << "The GenLumiInfoHeaders have different randomConfigIndex "
96  << prod1.randomConfigIndex() << " " << prod2.randomConfigIndex();
97  }
98 
99  if (prod1.configDescription() != prod2.configDescription()) {
100  throw cms::Exception("ComparisonFailure") << "The GenLumiInfoHeaders have different configDescription "
101  << prod1.configDescription() << " " << prod2.configDescription();
102  }
103 
104  if (prod1.lheHeaders().size() != prod2.lheHeaders().size()) {
105  throw cms::Exception("ComparisonFailure") << "The GenLumiInfoHeaders have different lheHeaders "
106  << prod1.lheHeaders().size() << " " << prod2.lheHeaders().size();
107  }
108 
109  if (prod1.weightNames().size() != prod2.weightNames().size()) {
110  throw cms::Exception("ComparisonFailure") << "The GenLumiInfoHeaders have different weightNames "
111  << prod1.weightNames().size() << " " << prod2.weightNames().size();
112  }
113 
114  return std::shared_ptr<cgra::DummyCache>();
115 }
116 
117 namespace {
118  void compare(size_t iIndex,
121  bool allowXSecDifferences) {
122  if (p1.process() != p2.process()) {
123  throw cms::Exception("ComparisonFailure") << "The GenLumiInfoProducts have different getProcessInfos()[" << iIndex
124  << "] process " << p1.process() << " " << p2.process();
125  }
126 
127  if (p1.nPassPos() != p2.nPassPos()) {
128  throw cms::Exception("ComparisonFailure") << "The GenLumiInfoProducts have different getProcessInfos()[" << iIndex
129  << "] nPassPos " << p1.nPassPos() << " " << p2.nPassPos();
130  }
131 
132  if (p1.nPassNeg() != p2.nPassNeg()) {
133  throw cms::Exception("ComparisonFailure") << "The GenLumiInfoProducts have different getProcessInfos()[" << iIndex
134  << "] nPassNeg " << p1.nPassNeg() << " " << p2.nPassNeg();
135  }
136 
137  if (p1.nTotalPos() != p2.nTotalPos()) {
138  throw cms::Exception("ComparisonFailure") << "The GenLumiInfoProducts have different getProcessInfos()[" << iIndex
139  << "] nTotalPos " << p1.nTotalPos() << " " << p2.nTotalPos();
140  }
141 
142  if (p1.nTotalNeg() != p2.nTotalNeg()) {
143  throw cms::Exception("ComparisonFailure") << "The GenLumiInfoProducts have different getProcessInfos()[" << iIndex
144  << "] nTotalNeg " << p1.nTotalNeg() << " " << p2.nTotalNeg();
145  }
146 
147  if (p1.lheXSec().error() != p2.lheXSec().error()) {
148  if (allowXSecDifferences) {
149  edm::LogWarning("ComparisonFailure")
150  << "The GenLumiInfoProducts have different getProcessInfos()[" << iIndex << "] lheXSec.error "
151  << p1.lheXSec().error() << " " << p2.lheXSec().error();
152  } else {
153  throw cms::Exception("ComparisonFailure")
154  << "The GenLumiInfoProducts have different getProcessInfos()[" << iIndex << "] lheXSec.error "
155  << p1.lheXSec().error() << " " << p2.lheXSec().error();
156  }
157  }
158 
159  if (p1.lheXSec().value() != p2.lheXSec().value()) {
160  if (allowXSecDifferences) {
161  //throw cms::Exception("ComparisonFailure")
162  edm::LogWarning("ComparisonFailure")
163  << "The GenLumiInfoProducts have different getProcessInfos()[" << iIndex << "] lheXSec.value "
164  << p1.lheXSec().value() << " " << p2.lheXSec().value();
165  } else {
166  throw cms::Exception("ComparisonFailure")
167  << "The GenLumiInfoProducts have different getProcessInfos()[" << iIndex << "] lheXSec.value "
168  << p1.lheXSec().value() << " " << p2.lheXSec().value();
169  }
170  }
171 
172  if (p1.tried().n() != p2.tried().n()) {
173  throw cms::Exception("ComparisonFailure") << "The GenLumiInfoProducts have different getProcessInfos()[" << iIndex
174  << "] tried.n " << p1.tried().n() << " " << p2.tried().n();
175  }
176 
177  if (p1.tried().sum() != p2.tried().sum()) {
178  throw cms::Exception("ComparisonFailure") << "The GenLumiInfoProducts have different getProcessInfos()[" << iIndex
179  << "] tried.sum " << p1.tried().sum() << " " << p2.tried().sum();
180  }
181 
182  if (p1.tried().sum2() != p2.tried().sum2()) {
183  throw cms::Exception("ComparisonFailure") << "The GenLumiInfoProducts have different getProcessInfos()[" << iIndex
184  << "] tried.sum2 " << p1.tried().sum2() << " " << p2.tried().sum2();
185  }
186 
187  if (p1.selected().n() != p2.selected().n()) {
188  throw cms::Exception("ComparisonFailure") << "The GenLumiInfoProducts have different getProcessInfos()[" << iIndex
189  << "] selected.n " << p1.selected().n() << " " << p2.selected().n();
190  }
191 
192  if (p1.selected().sum() != p2.selected().sum()) {
193  throw cms::Exception("ComparisonFailure")
194  << "The GenLumiInfoProducts have different getProcessInfos()[" << iIndex << "] selected.sum "
195  << p1.selected().sum() << " " << p2.selected().sum();
196  }
197 
198  if (p1.selected().sum2() != p2.selected().sum2()) {
199  throw cms::Exception("ComparisonFailure")
200  << "The GenLumiInfoProducts have different getProcessInfos()[" << iIndex << "] selected.sum2 "
201  << p1.selected().sum2() << " " << p2.selected().sum2();
202  }
203 
204  if (p1.killed().n() != p2.killed().n()) {
205  throw cms::Exception("ComparisonFailure") << "The GenLumiInfoProducts have different getProcessInfos()[" << iIndex
206  << "] killed.n " << p1.killed().n() << " " << p2.killed().n();
207  }
208 
209  if (p1.killed().sum() != p2.killed().sum()) {
210  throw cms::Exception("ComparisonFailure") << "The GenLumiInfoProducts have different getProcessInfos()[" << iIndex
211  << "] killed sum " << p1.killed().sum() << " " << p2.killed().sum();
212  }
213 
214  if (p1.killed().sum2() != p2.killed().sum2()) {
215  throw cms::Exception("ComparisonFailure") << "The GenLumiInfoProducts have different getProcessInfos()[" << iIndex
216  << "] killed.sum2 " << p1.killed().sum2() << " " << p2.killed().sum2();
217  }
218 
219  if (p1.accepted().n() != p2.accepted().n()) {
220  throw cms::Exception("ComparisonFailure") << "The GenLumiInfoProducts have different getProcessInfos()[" << iIndex
221  << "] accepted.n " << p1.accepted().n() << " " << p2.accepted().n();
222  }
223 
224  if (p1.accepted().sum() != p2.accepted().sum()) {
225  throw cms::Exception("ComparisonFailure")
226  << "The GenLumiInfoProducts have different getProcessInfos()[" << iIndex << "] accepted.sum "
227  << p1.accepted().sum() << " " << p2.accepted().sum();
228  }
229 
230  if (p1.accepted().sum2() != p2.accepted().sum2()) {
231  throw cms::Exception("ComparisonFailure")
232  << "The GenLumiInfoProducts have different getProcessInfos()[" << iIndex << "] accepted.sum2 "
233  << p1.accepted().sum2() << " " << p2.accepted().sum2();
234  }
235 
236  if (p1.acceptedBr().n() != p2.acceptedBr().n()) {
237  throw cms::Exception("ComparisonFailure")
238  << "The GenLumiInfoProducts have different getProcessInfos()[" << iIndex << "] acceptedBr.n "
239  << p1.acceptedBr().n() << " " << p2.acceptedBr().n();
240  }
241 
242  if (p1.acceptedBr().sum() != p2.acceptedBr().sum()) {
243  throw cms::Exception("ComparisonFailure")
244  << "The GenLumiInfoProducts have different getProcessInfos()[" << iIndex << "] acceptedZBr.sum "
245  << p1.acceptedBr().sum() << " " << p2.acceptedBr().sum();
246  }
247 
248  if (p1.acceptedBr().sum2() != p2.acceptedBr().sum2()) {
249  throw cms::Exception("ComparisonFailure")
250  << "The GenLumiInfoProducts have different getProcessInfos()[" << iIndex << "] acceptedBr.sum2 "
251  << p1.acceptedBr().sum2() << " " << p2.acceptedBr().sum2();
252  }
253  }
254 } // namespace
255 
257  edm::EventSetup const&) const {
258  auto const& prod1 = iLumi.get(lumiProductToken1_);
259  auto const& prod2 = iLumi.get(lumiProductToken2_);
260 
261  if (not prod1.isProductEqual(prod2)) {
262  if (prod1.getHEPIDWTUP() != prod1.getHEPIDWTUP()) {
263  throw cms::Exception("ComparisonFailure") << "The GenLumiInfoProducts have different getHEPIDWTUP "
264  << prod1.getHEPIDWTUP() << " " << prod2.getHEPIDWTUP();
265  }
266 
267  if (prod1.getProcessInfos().size() != prod2.getProcessInfos().size()) {
268  throw cms::Exception("ComparisonFailure")
269  << "The GenLumiInfoHeaders have different getProcessInfos " << prod1.getProcessInfos().size() << " "
270  << prod2.getProcessInfos().size();
271  }
272 
273  for (size_t i = 0; i < prod1.getProcessInfos().size(); ++i) {
274  compare(i, prod1.getProcessInfos()[i], prod2.getProcessInfos()[i], allowXSecDifferences_);
275  }
276 
277  if (not allowXSecDifferences_) {
278  throw cms::Exception("ComparisionFailure") << "The GenLumiInfoProducts are different";
279  }
280  }
281 }
282 
283 namespace {
284  void compare(GenEventInfoProduct const& prod1, GenEventInfoProduct const& prod2) {
285  if (prod1.weights().size() != prod2.weights().size()) {
286  throw cms::Exception("ComparisonFailure") << "The GenEventInfoProducts have different weights "
287  << prod1.weights().size() << " " << prod2.weights().size();
288  }
289 
290  if (prod1.binningValues().size() != prod2.binningValues().size()) {
291  throw cms::Exception("ComparisonFailure") << "The GenEventInfoProducts have different binningValues "
292  << prod1.binningValues().size() << " " << prod2.binningValues().size();
293  }
294 
295  if (prod1.DJRValues().size() != prod2.DJRValues().size()) {
296  throw cms::Exception("ComparisonFailure") << "The GenEventInfoProducts have different DJRValues "
297  << prod1.DJRValues().size() << " " << prod2.DJRValues().size();
298  }
299 
300  if (prod1.signalProcessID() != prod2.signalProcessID()) {
301  throw cms::Exception("ComparisonFailure") << "The GenEventInfoProducts have different signalProcessID "
302  << prod1.signalProcessID() << " " << prod2.signalProcessID();
303  }
304 
305  if (prod1.qScale() != prod2.qScale()) {
306  throw cms::Exception("ComparisonFailure")
307  << "The GenEventInfoProducts have different qScale " << prod1.qScale() << " " << prod2.qScale();
308  }
309 
310  if (prod1.alphaQCD() != prod2.alphaQCD()) {
311  throw cms::Exception("ComparisonFailure")
312  << "The GenEventInfoProducts have different alphaQCD " << prod1.alphaQCD() << " " << prod2.alphaQCD();
313  }
314 
315  if (prod1.alphaQED() != prod2.alphaQED()) {
316  throw cms::Exception("ComparisonFailure")
317  << "The GenEventInfoProducts have different alphaQED " << prod1.alphaQED() << " " << prod2.alphaQED();
318  }
319 
320  if (prod1.nMEPartons() != prod2.nMEPartons()) {
321  throw cms::Exception("ComparisonFailure")
322  << "The GenEventInfoProducts have different nMEPartons " << prod1.nMEPartons() << " " << prod2.nMEPartons();
323  }
324 
325  if (prod1.nMEPartonsFiltered() != prod2.nMEPartonsFiltered()) {
326  throw cms::Exception("ComparisonFailure") << "The GenEventInfoProducts have different nMEPartonsFiltered "
327  << prod1.nMEPartonsFiltered() << " " << prod2.nMEPartonsFiltered();
328  }
329  }
330 
331  void compare(HepMC::GenEvent const& prod1, HepMC::GenEvent const& prod2) {
332  if (prod1.signal_process_id() != prod2.signal_process_id()) {
333  throw cms::Exception("ComparisonFailure") << "The HepMCProducts have different signal_process_id "
334  << prod1.signal_process_id() << " " << prod2.signal_process_id();
335  }
336 
337  if (prod1.vertices_size() != prod2.vertices_size()) {
338  throw cms::Exception("ComparisonFailure") << "The HepMCProducts have different vertices_size() "
339  << prod1.vertices_size() << " " << prod2.vertices_size();
340  }
341 
342  if (prod1.particles_size() != prod2.particles_size()) {
343  throw cms::Exception("ComparisonFailure") << "The HepMCProducts have different particles_size() "
344  << prod1.particles_size() << " " << prod2.particles_size();
345  }
346  }
347 } // namespace
348 
350  auto const& prod1 = iEvent.get(evToken1_);
351  auto const& prod2 = iEvent.get(evToken2_);
352 
353  compare(prod1, prod2);
354 
355  auto const& hepmc1 = iEvent.get(hepMCToken1_);
356  auto const& hepmc2 = iEvent.get(hepMCToken2_);
357 
358  compare(hepmc1.getHepMCData(), hepmc2.getHepMCData());
359 }
360 
edm::EDGetTokenT< GenLumiInfoHeader > lumiHeaderToken1_
bool compare(const P &i, const P &j)
const std::vector< double > & binningValues() const
void globalEndRun(edm::Run const &, edm::EventSetup const &) const override
edm::EDGetTokenT< GenLumiInfoHeader > lumiHeaderToken2_
edm::EDGetTokenT< GenLumiInfoProduct > lumiProductToken2_
CompareGeneratorResultsAnalyzer(edm::ParameterSet const &)
std::shared_ptr< cgra::DummyCache > globalBeginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) const override
edm::EDGetTokenT< GenEventInfoProduct > evToken2_
edm::EDGetTokenT< edm::HepMCProduct > hepMCToken2_
int nMEPartonsFiltered() const
T getUntrackedParameter(std::string const &, T const &) const
int iEvent
Definition: GenABIO.cc:224
const std::vector< float > & DJRValues() const
edm::EDGetTokenT< GenEventInfoProduct > evToken1_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
PROD const & get(EDGetTokenT< PROD > token) const noexcept(false)
Definition: Run.h:350
unsigned int signalProcessID() const
edm::EDGetTokenT< GenRunInfoProduct > runProductToken1_
std::shared_ptr< cgra::DummyCache > globalBeginRun(edm::Run const &, edm::EventSetup const &) const override
edm::EDGetTokenT< GenLumiInfoProduct > lumiProductToken1_
std::vector< double > & weights()
edm::EDGetTokenT< edm::HepMCProduct > hepMCToken1_
Log< level::Warning, false > LogWarning
void analyze(edm::StreamID, edm::Event const &, edm::EventSetup const &) const override
edm::EDGetTokenT< GenRunInfoProduct > runProductToken2_
PROD const & get(EDGetTokenT< PROD > token) const noexcept(false)
void globalEndLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) const override
Definition: Run.h:45