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 
GenEventInfoProduct
Definition: GenEventInfoProduct.h:17
CompareGeneratorResultsAnalyzer::globalEndRun
void globalEndRun(edm::Run const &, edm::EventSetup const &) const override
Definition: CompareGeneratorResultsAnalyzer.cc:80
edm::StreamID
Definition: StreamID.h:30
GenEventInfoProduct::nMEPartons
int nMEPartons() const
Definition: GenEventInfoProduct.h:54
cgra::DummyCache
Definition: CompareGeneratorResultsAnalyzer.cc:21
CompareGeneratorResultsAnalyzer::analyze
void analyze(edm::StreamID, edm::Event const &, edm::EventSetup const &) const override
Definition: CompareGeneratorResultsAnalyzer.cc:349
mps_fire.i
i
Definition: mps_fire.py:355
GenEventInfoProduct::signalProcessID
unsigned int signalProcessID() const
Definition: GenEventInfoProduct.h:39
GenEventInfoProduct::qScale
double qScale() const
Definition: GenEventInfoProduct.h:41
CompareGeneratorResultsAnalyzer::globalBeginRun
std::shared_ptr< cgra::DummyCache > globalBeginRun(edm::Run const &, edm::EventSetup const &) const override
Definition: CompareGeneratorResultsAnalyzer.cc:75
CompareGeneratorResultsAnalyzer::mod1_
std::string mod1_
Definition: CompareGeneratorResultsAnalyzer.cc:39
edm::LuminosityBlock
Definition: LuminosityBlock.h:50
CompareGeneratorResultsAnalyzer::lumiProductToken1_
edm::EDGetTokenT< GenLumiInfoProduct > lumiProductToken1_
Definition: CompareGeneratorResultsAnalyzer.cc:51
edm::Run
Definition: Run.h:45
edm::EDGetTokenT< GenEventInfoProduct >
LuminosityBlock.h
CompareGeneratorResultsAnalyzer::evToken1_
edm::EDGetTokenT< GenEventInfoProduct > evToken1_
Definition: CompareGeneratorResultsAnalyzer.cc:42
GenEventInfoProduct::binningValues
const std::vector< double > & binningValues() const
Definition: GenEventInfoProduct.h:48
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
GenRunInfoProduct.h
HepMC::GenEvent
Definition: hepmc_rootio.cc:9
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
GenLumiInfoProduct::ProcessInfo
Definition: GenLumiInfoProduct.h:86
CompareGeneratorResultsAnalyzer::runProductToken2_
edm::EDGetTokenT< GenRunInfoProduct > runProductToken2_
Definition: CompareGeneratorResultsAnalyzer.cc:55
Run.h
p2
double p2[4]
Definition: TauolaWrapper.h:90
CompareGeneratorResultsAnalyzer::lumiHeaderToken2_
edm::EDGetTokenT< GenLumiInfoHeader > lumiHeaderToken2_
Definition: CompareGeneratorResultsAnalyzer.cc:49
cgra
Definition: CompareGeneratorResultsAnalyzer.cc:20
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::LogWarning
Definition: MessageLogger.h:141
CompareGeneratorResultsAnalyzer::globalBeginLuminosityBlock
std::shared_ptr< cgra::DummyCache > globalBeginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) const override
Definition: CompareGeneratorResultsAnalyzer.cc:89
CompareGeneratorResultsAnalyzer::CompareGeneratorResultsAnalyzer
CompareGeneratorResultsAnalyzer(edm::ParameterSet const &)
Definition: CompareGeneratorResultsAnalyzer.cc:60
CompareGeneratorResultsAnalyzer::hepMCToken1_
edm::EDGetTokenT< edm::HepMCProduct > hepMCToken1_
Definition: CompareGeneratorResultsAnalyzer.cc:45
edm::ParameterSet
Definition: ParameterSet.h:36
GenEventInfoProduct.h
Event.h
GenEventInfoProduct::alphaQCD
double alphaQCD() const
Definition: GenEventInfoProduct.h:42
prod1Switch_cff.prod1
prod1
Definition: prod1Switch_cff.py:9
iEvent
int iEvent
Definition: GenABIO.cc:224
CompareGeneratorResultsAnalyzer::globalEndLuminosityBlock
void globalEndLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) const override
Definition: CompareGeneratorResultsAnalyzer.cc:256
GenLumiInfoHeader.h
p1
double p1[4]
Definition: TauolaWrapper.h:89
edm::EventSetup
Definition: EventSetup.h:57
GenEventInfoProduct::alphaQED
double alphaQED() const
Definition: GenEventInfoProduct.h:43
edm::LuminosityBlock::get
PROD const & get(EDGetTokenT< PROD > token) const noexcept(false)
Definition: LuminosityBlock.h:356
CompareGeneratorResultsAnalyzer::lumiProductToken2_
edm::EDGetTokenT< GenLumiInfoProduct > lumiProductToken2_
Definition: CompareGeneratorResultsAnalyzer.cc:52
CompareGeneratorResultsAnalyzer::allowXSecDifferences_
bool allowXSecDifferences_
Definition: CompareGeneratorResultsAnalyzer.cc:57
CompareGeneratorResultsAnalyzer
Definition: CompareGeneratorResultsAnalyzer.cc:24
GenEventInfoProduct::DJRValues
const std::vector< float > & DJRValues() const
Definition: GenEventInfoProduct.h:51
Exception
Definition: hltDiff.cc:246
CompareGeneratorResultsAnalyzer::hepMCToken2_
edm::EDGetTokenT< edm::HepMCProduct > hepMCToken2_
Definition: CompareGeneratorResultsAnalyzer.cc:46
Exception.h
CompareGeneratorResultsAnalyzer::runProductToken1_
edm::EDGetTokenT< GenRunInfoProduct > runProductToken1_
Definition: CompareGeneratorResultsAnalyzer.cc:54
GenEventInfoProduct::nMEPartonsFiltered
int nMEPartonsFiltered() const
Definition: GenEventInfoProduct.h:56
CompareGeneratorResultsAnalyzer::lumiHeaderToken1_
edm::EDGetTokenT< GenLumiInfoHeader > lumiHeaderToken1_
Definition: CompareGeneratorResultsAnalyzer.cc:48
ParameterSet.h
edm::Run::get
PROD const & get(EDGetTokenT< PROD > token) const noexcept(false)
Definition: Run.h:352
HepMCProduct.h
GenEventInfoProduct::weights
std::vector< double > & weights()
Definition: GenEventInfoProduct.h:32
compare
bool compare(const P &i, const P &j)
Definition: BDHadronTrackMonitoringAnalyzer.cc:203
edm::Event
Definition: Event.h:73
GenLumiInfoProduct.h
EDAnalyzer.h
CompareGeneratorResultsAnalyzer::evToken2_
edm::EDGetTokenT< GenEventInfoProduct > evToken2_
Definition: CompareGeneratorResultsAnalyzer.cc:43
edm::InputTag
Definition: InputTag.h:15
edm::global::EDAnalyzer
Definition: EDAnalyzer.h:32
CompareGeneratorResultsAnalyzer::mod2_
std::string mod2_
Definition: CompareGeneratorResultsAnalyzer.cc:40