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