Skip to content

Commit ca88de9

Browse files
committed
HepMC3 output for HadronizerFilter
1 parent 4eeb0e8 commit ca88de9

File tree

6 files changed

+278
-37
lines changed

6 files changed

+278
-37
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifndef BaseHepMC3Filter_H
2+
#define BaseHepMC3Filter_H
3+
4+
// base class for simple filter to run inside of HadronizerFilter for
5+
// multiple hadronization attempts on lhe events
6+
7+
#include "FWCore/ParameterSet/interface/ParameterSet.h"
8+
#include "SimDataFormats/GeneratorProducts/interface/HepMC3Product.h"
9+
10+
//
11+
// class declaration
12+
//
13+
14+
class BaseHepMC3Filter {
15+
public:
16+
BaseHepMC3Filter();
17+
~BaseHepMC3Filter();
18+
19+
bool filter(const HepMC3::GenEvent* evt) { return true; };
20+
};
21+
22+
#endif

GeneratorInterface/Core/interface/HadronizerFilter.h

Lines changed: 117 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
// #include "GeneratorInterface/ExternalDecays/interface/ExternalDecayDriver.h"
3535

3636
#include "GeneratorInterface/Core/interface/HepMCFilterDriver.h"
37+
#include "GeneratorInterface/Core/interface/HepMC3FilterDriver.h"
3738

3839
// LHE Run
3940
#include "SimDataFormats/GeneratorProducts/interface/LHERunInfoProduct.h"
@@ -44,10 +45,12 @@
4445
#include "GeneratorInterface/LHEInterface/interface/LHEEvent.h"
4546

4647
#include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
48+
#include "SimDataFormats/GeneratorProducts/interface/HepMC3Product.h"
4749
#include "SimDataFormats/GeneratorProducts/interface/GenRunInfoProduct.h"
4850
#include "SimDataFormats/GeneratorProducts/interface/GenLumiInfoHeader.h"
4951
#include "SimDataFormats/GeneratorProducts/interface/GenLumiInfoProduct.h"
5052
#include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h"
53+
#include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct3.h"
5154

5255
namespace edm {
5356
template <class HAD, class DEC>
@@ -81,11 +84,13 @@ namespace edm {
8184
// gen::ExternalDecayDriver* decayer_;
8285
Decayer* decayer_;
8386
HepMCFilterDriver* filter_;
87+
HepMC3FilterDriver* filter3_;
8488
InputTag runInfoProductTag_;
8589
EDGetTokenT<LHERunInfoProduct> runInfoProductToken_;
8690
EDGetTokenT<LHEEventProduct> eventProductToken_;
8791
unsigned int counterRunInfoProducts_;
8892
unsigned int nAttempts_;
93+
unsigned int ivhepmc = 2;
8994
};
9095

9196
//------------------------------------------------------------------------
@@ -98,6 +103,7 @@ namespace edm {
98103
hadronizer_(ps),
99104
decayer_(nullptr),
100105
filter_(nullptr),
106+
filter3_(nullptr),
101107
runInfoProductTag_(),
102108
runInfoProductToken_(),
103109
eventProductToken_(),
@@ -143,6 +149,7 @@ namespace edm {
143149
if (ps.exists("HepMCFilter")) {
144150
ParameterSet psfilter = ps.getParameter<ParameterSet>("HepMCFilter");
145151
filter_ = new HepMCFilterDriver(psfilter);
152+
filter3_ = new HepMC3FilterDriver(psfilter);
146153
}
147154

148155
//initialize setting for multiple hadronization attempts
@@ -156,8 +163,14 @@ namespace edm {
156163
usesResource(edm::uniqueSharedResourceName());
157164
}
158165

159-
produces<edm::HepMCProduct>("unsmeared");
160-
produces<GenEventInfoProduct>();
166+
ivhepmc = hadronizer_.getVHepMC();
167+
if (ivhepmc == 2) {
168+
produces<edm::HepMCProduct>("unsmeared");
169+
produces<GenEventInfoProduct>();
170+
} else if (ivhepmc == 3) {
171+
produces<edm::HepMC3Product>("unsmeared");
172+
produces<GenEventInfoProduct3>();
173+
}
161174
produces<GenLumiInfoHeader, edm::Transition::BeginLuminosityBlock>();
162175
produces<GenLumiInfoProduct, edm::Transition::EndLuminosityBlock>();
163176
produces<GenRunInfoProduct, edm::Transition::EndRun>();
@@ -171,6 +184,8 @@ namespace edm {
171184
delete decayer_;
172185
if (filter_)
173186
delete filter_;
187+
if (filter3_)
188+
delete filter3_;
174189
}
175190

176191
template <class HAD, class DEC>
@@ -186,7 +201,9 @@ namespace edm {
186201
ev.getByToken(eventProductToken_, product);
187202

188203
std::unique_ptr<HepMC::GenEvent> finalEvent;
204+
std::unique_ptr<HepMC3::GenEvent> finalEvent3;
189205
std::unique_ptr<GenEventInfoProduct> finalGenEventInfo;
206+
std::unique_ptr<GenEventInfoProduct3> finalGenEventInfo3;
190207

191208
//number of accepted events
192209
unsigned int naccept = 0;
@@ -208,8 +225,11 @@ namespace edm {
208225
continue;
209226

210227
std::unique_ptr<HepMC::GenEvent> event(hadronizer_.getGenEvent());
211-
if (!event.get())
212-
continue;
228+
std::unique_ptr<HepMC3::GenEvent> event3(hadronizer_.getGenEvent3());
229+
if (ivhepmc == 2 && !event.get())
230+
return false;
231+
if (ivhepmc == 3 && !event3.get())
232+
return false;
213233

214234
// The external decay driver is being added to the system,
215235
// it should be called here
@@ -223,60 +243,105 @@ namespace edm {
223243
hadronizer_.setLHEEvent(std::move(lheEvent));
224244
}
225245

226-
if (!event.get())
227-
continue;
246+
if (ivhepmc == 2 && !event.get())
247+
return false;
248+
if (ivhepmc == 3 && !event3.get())
249+
return false;
228250

229251
// check and perform if there're any unstable particles after
230252
// running external decay packges
231253
//
232254
hadronizer_.resetEvent(std::move(event));
255+
hadronizer_.resetEvent3(std::move(event3));
233256
if (!hadronizer_.residualDecay())
234257
continue;
235258

236259
hadronizer_.finalizeEvent();
237260

238261
event = hadronizer_.getGenEvent();
239-
if (!event.get())
240-
continue;
262+
event3 = hadronizer_.getGenEvent3();
263+
if (ivhepmc == 2 && !event.get())
264+
return false;
265+
if (ivhepmc == 3 && !event3.get())
266+
return false;
267+
268+
if (ivhepmc == 2) { // HepMC
269+
event->set_event_number(ev.id().event());
270+
std::unique_ptr<GenEventInfoProduct> genEventInfo(hadronizer_.getGenEventInfo());
271+
if (!genEventInfo.get()) {
272+
// create GenEventInfoProduct from HepMC event in case hadronizer didn't provide one
273+
genEventInfo = std::make_unique<GenEventInfoProduct>(event.get());
274+
}
241275

242-
event->set_event_number(ev.id().event());
276+
//if HepMCFilter was specified, test event
277+
if (filter_ && !filter_->filter(event.get(), genEventInfo->weight()))
278+
continue;
243279

244-
std::unique_ptr<GenEventInfoProduct> genEventInfo(hadronizer_.getGenEventInfo());
245-
if (!genEventInfo.get()) {
246-
// create GenEventInfoProduct from HepMC event in case hadronizer didn't provide one
247-
genEventInfo = std::make_unique<GenEventInfoProduct>(event.get());
248-
}
280+
++naccept;
249281

250-
//if HepMCFilter was specified, test event
251-
if (filter_ && !filter_->filter(event.get(), genEventInfo->weight()))
252-
continue;
282+
//keep the LAST accepted event (which is equivalent to choosing randomly from the accepted events)
283+
finalEvent = std::move(event);
284+
finalGenEventInfo = std::move(genEventInfo);
253285

254-
++naccept;
286+
if (!naccept)
287+
return false;
255288

256-
//keep the LAST accepted event (which is equivalent to choosing randomly from the accepted events)
257-
finalEvent = std::move(event);
258-
finalGenEventInfo = std::move(genEventInfo);
259-
}
289+
//adjust event weights if necessary (in case input event was attempted multiple times)
290+
if (nAttempts_ > 1) {
291+
double multihadweight = double(naccept) / double(nAttempts_);
260292

261-
if (!naccept)
262-
return false;
293+
//adjust weight for GenEventInfoProduct
294+
finalGenEventInfo->weights()[0] *= multihadweight;
263295

264-
//adjust event weights if necessary (in case input event was attempted multiple times)
265-
if (nAttempts_ > 1) {
266-
double multihadweight = double(naccept) / double(nAttempts_);
296+
//adjust weight for HepMC GenEvent (used e.g for RIVET)
297+
finalEvent->weights()[0] *= multihadweight;
298+
}
267299

268-
//adjust weight for GenEventInfoProduct
269-
finalGenEventInfo->weights()[0] *= multihadweight;
300+
ev.put(std::move(finalGenEventInfo));
270301

271-
//adjust weight for HepMC GenEvent (used e.g for RIVET)
272-
finalEvent->weights()[0] *= multihadweight;
273-
}
302+
std::unique_ptr<HepMCProduct> bare_product(new HepMCProduct());
303+
bare_product->addHepMCData(finalEvent.release());
304+
ev.put(std::move(bare_product), "unsmeared");
305+
306+
} else if (ivhepmc == 3) { // HepMC3
307+
event3->set_event_number(ev.id().event());
308+
std::unique_ptr<GenEventInfoProduct3> genEventInfo3(hadronizer_.getGenEventInfo3());
309+
if (!genEventInfo3.get()) {
310+
// create GenEventInfoProduct3 from HepMC3 event in case hadronizer didn't provide one
311+
genEventInfo3 = std::make_unique<GenEventInfoProduct3>(event3.get());
312+
}
313+
314+
//if HepMCFilter was specified, test event
315+
if (filter3_ && !filter3_->filter(event3.get(), genEventInfo3->weight()))
316+
continue;
274317

275-
ev.put(std::move(finalGenEventInfo));
318+
++naccept;
276319

277-
std::unique_ptr<HepMCProduct> bare_product(new HepMCProduct());
278-
bare_product->addHepMCData(finalEvent.release());
279-
ev.put(std::move(bare_product), "unsmeared");
320+
//keep the LAST accepted event (which is equivalent to choosing randomly from the accepted events)
321+
finalEvent3 = std::move(event3);
322+
finalGenEventInfo3 = std::move(genEventInfo3);
323+
324+
if (!naccept)
325+
return false;
326+
327+
//adjust event weights if necessary (in case input event was attempted multiple times)
328+
if (nAttempts_ > 1) {
329+
double multihadweight = double(naccept) / double(nAttempts_);
330+
331+
//adjust weight for GenEventInfoProduct
332+
finalGenEventInfo3->weights()[0] *= multihadweight;
333+
334+
//adjust weight for HepMC GenEvent (used e.g for RIVET)
335+
finalEvent3->weights()[0] *= multihadweight;
336+
}
337+
338+
ev.put(std::move(finalGenEventInfo3));
339+
340+
std::unique_ptr<HepMC3Product> bare_product(new HepMC3Product());
341+
bare_product->addHepMCData(finalEvent3.release());
342+
ev.put(std::move(bare_product), "unsmeared");
343+
}
344+
}
280345

281346
return true;
282347
}
@@ -327,6 +392,8 @@ namespace edm {
327392
decayer_->statistics();
328393
if (filter_)
329394
filter_->statistics();
395+
if (filter3_)
396+
filter3_->statistics();
330397
lheRunInfo->statistics();
331398

332399
std::unique_ptr<GenRunInfoProduct> griproduct(new GenRunInfoProduct(genRunInfo));
@@ -363,6 +430,9 @@ namespace edm {
363430
if (filter_) {
364431
filter_->resetStatistics();
365432
}
433+
if (filter3_) {
434+
filter3_->resetStatistics();
435+
}
366436

367437
if (!hadronizer_.initializeForExternalPartons())
368438
throw edm::Exception(errors::Configuration)
@@ -416,6 +486,17 @@ namespace edm {
416486
filter_->sumtotal_w2()));
417487
lumi.put(std::move(thisProduct));
418488
}
489+
if (filter3_) {
490+
std::unique_ptr<GenFilterInfo> thisProduct(new GenFilterInfo(filter3_->numEventsPassPos(),
491+
filter3_->numEventsPassNeg(),
492+
filter3_->numEventsTotalPos(),
493+
filter3_->numEventsTotalNeg(),
494+
filter3_->sumpass_w(),
495+
filter3_->sumpass_w2(),
496+
filter3_->sumtotal_w(),
497+
filter3_->sumtotal_w2()));
498+
lumi.put(std::move(thisProduct));
499+
}
419500
}
420501

421502
} // namespace edm
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#ifndef gen_HEPMC3FILTERDRIVER_H
2+
#define gen_HEPMC3FILTERDRIVER_H
3+
4+
//class to select a HepMC3Filter to run with multiple hadronization attempts
5+
//inside HadronizerFilter
6+
7+
#include "FWCore/ParameterSet/interface/ParameterSet.h"
8+
#include "SimDataFormats/GeneratorProducts/interface/HepMC3Product.h"
9+
#include "GeneratorInterface/Core/interface/BaseHepMC3Filter.h"
10+
#include "SimDataFormats/GeneratorProducts/interface/GenFilterInfo.h"
11+
12+
//
13+
// class declaration
14+
//
15+
16+
class HepMC3FilterDriver {
17+
public:
18+
HepMC3FilterDriver(const edm::ParameterSet&);
19+
~HepMC3FilterDriver();
20+
21+
bool filter(const HepMC3::GenEvent* evt, double weight = 1.);
22+
void statistics() const;
23+
void resetStatistics();
24+
25+
unsigned int numEventsPassPos() const { return numEventsPassPos_; }
26+
unsigned int numEventsPassNeg() const { return numEventsPassNeg_; }
27+
unsigned int numEventsTotalPos() const { return numEventsTotalPos_; }
28+
unsigned int numEventsTotalNeg() const { return numEventsTotalNeg_; }
29+
double sumpass_w() const { return sumpass_w_; }
30+
double sumpass_w2() const { return sumpass_w2_; }
31+
double sumtotal_w() const { return sumtotal_w_; }
32+
double sumtotal_w2() const { return sumtotal_w2_; }
33+
34+
private:
35+
BaseHepMC3Filter* filter_;
36+
unsigned int numEventsPassPos_;
37+
unsigned int numEventsPassNeg_;
38+
unsigned int numEventsTotalPos_;
39+
unsigned int numEventsTotalNeg_;
40+
double sumpass_w_;
41+
double sumpass_w2_;
42+
double sumtotal_w_;
43+
double sumtotal_w2_;
44+
};
45+
#endif
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include "GeneratorInterface/Core/interface/BaseHepMC3Filter.h"
2+
3+
BaseHepMC3Filter::BaseHepMC3Filter() {}
4+
5+
BaseHepMC3Filter::~BaseHepMC3Filter() {}

0 commit comments

Comments
 (0)