CMS 3D CMS Logo

LHE2HepMCConverter.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: LHE2HepMCConverter
4 // Class: LHE2HepMCConverter
5 //
13 //
14 // Original Author: Piergiulio Lenzi,40 1-B01,+41227671638,
15 // Created: Wed Aug 31 19:02:24 CEST 2011
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 
22 // user include files
25 
29 
33 
37 
38 //
39 // class declaration
40 //
41 
42 class LHE2HepMCConverter : public edm::one::EDProducer<edm::one::WatchRuns> {
43 public:
44  explicit LHE2HepMCConverter(const edm::ParameterSet&);
45  ~LHE2HepMCConverter() override = default;
46 
47  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
48 
49 protected:
50  // lhef::LHERunInfo *lheRunInfo() { return lheRunInfo_.get(); }
51 
52 private:
53  void produce(edm::Event&, const edm::EventSetup&) override;
54  void beginRun(edm::Run const&, edm::EventSetup const&) override;
55  void endRun(edm::Run const&, edm::EventSetup const&) override {}
56 
57  // ----------member data ---------------------------
63  // std::shared_ptr<lhef::LHERunInfo> lheRunInfo_;
64 };
65 
66 //
67 // constants, enums and typedefs
68 //
69 
70 //
71 // static data member definitions
72 //
73 
74 //
75 // constructors and destructor
76 //
78  : _lheRunSrc(nullptr),
79  _lheEventSrcTag(iConfig.getParameter<edm::InputTag>("LHEEventProduct")),
80  _lheRunSrcTag(iConfig.getParameter<edm::InputTag>("LHERunInfoProduct")),
81  eventProductToken_(consumes<LHEEventProduct>(_lheEventSrcTag)),
82  runInfoProductToken_(consumes<LHERunInfoProduct, edm::InRun>(_lheRunSrcTag)) {
83  //register your products
84  produces<edm::HepMCProduct>("unsmeared");
85 }
86 
87 //
88 // member functions
89 //
90 
91 // ------------ method called to produce the data ------------
93  using namespace edm;
94  const edm::Handle<LHEEventProduct>& lheEventSrc = iEvent.getHandle(eventProductToken_);
95 
96  HepMC::GenEvent* evt = new HepMC::GenEvent();
97  HepMC::GenVertex* v = new HepMC::GenVertex();
98  evt->add_vertex(v);
99  if (_lheRunSrc) {
100  HepMC::FourVector beam1(0, 0, _lheRunSrc->heprup().EBMUP.first, _lheRunSrc->heprup().EBMUP.first);
101  HepMC::GenParticle* gp1 = new HepMC::GenParticle(beam1, _lheRunSrc->heprup().IDBMUP.first, 4);
102  v->add_particle_in(gp1);
103  HepMC::FourVector beam2(0, 0, _lheRunSrc->heprup().EBMUP.second, _lheRunSrc->heprup().EBMUP.second);
104  HepMC::GenParticle* gp2 = new HepMC::GenParticle(beam2, _lheRunSrc->heprup().IDBMUP.second, 4);
105  v->add_particle_in(gp2);
106  evt->set_beam_particles(gp1, gp2);
107  } else {
108  LogWarning("LHE2HepMCConverter") << "Could not retrieve the LHERunInfoProduct for this event. You'll miss the beam "
109  "particles in your HepMC product.";
110  }
111 
112  for (int i = 0; i < lheEventSrc->hepeup().NUP; ++i) {
113  if (lheEventSrc->hepeup().ISTUP[i] != 1) {
114  //cout << reader->hepeup.ISTUP[i] << ", " << reader->hepeup.IDUP[i] << endl;
115  continue;
116  }
117  HepMC::FourVector p(lheEventSrc->hepeup().PUP[i][0],
118  lheEventSrc->hepeup().PUP[i][1],
119  lheEventSrc->hepeup().PUP[i][2],
120  lheEventSrc->hepeup().PUP[i][3]);
121  HepMC::GenParticle* gp = new HepMC::GenParticle(p, lheEventSrc->hepeup().IDUP[i], 1);
122  gp->set_generated_mass(lheEventSrc->hepeup().PUP[i][4]);
123  v->add_particle_out(gp);
124  }
125 
126  std::unique_ptr<HepMCProduct> pOut(new HepMCProduct(evt));
127  iEvent.put(std::move(pOut), "unsmeared");
128 }
129 
130 // ------------ method called when starting to processes a run ------------
133  if (lheRunSrcHandle.isValid()) {
134  _lheRunSrc = lheRunSrcHandle.product();
135  } else {
136  if (_lheRunSrcTag.label() != "source") {
137  iRun.getByLabel("source", lheRunSrcHandle);
138  if (lheRunSrcHandle.isValid()) {
139  _lheRunSrc = lheRunSrcHandle.product();
140  edm::LogInfo("LHE2HepMCConverter") << "Taking LHERunInfoproduct from source";
141  } else
142  edm::LogWarning("LHE2HepMCConverter") << "No LHERunInfoProduct from source";
143  }
144  }
145 }
146 
147 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
149  //The following says we do not know what parameters are allowed so do no validation
150  // Please change this to state exactly what you do use, even if it is no parameters
152  desc.setUnknown();
153  descriptions.addDefault(desc);
154 }
155 
156 //define this as a plug-in
const edm::EDGetTokenT< LHERunInfoProduct > runInfoProductToken_
std::pair< double, double > EBMUP
Definition: LesHouches.h:82
T const * product() const
Definition: Handle.h:70
~LHE2HepMCConverter() override=default
void produce(edm::Event &, const edm::EventSetup &) override
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::pair< int, int > IDBMUP
Definition: LesHouches.h:77
void endRun(edm::Run const &, edm::EventSetup const &) override
std::string const & label() const
Definition: InputTag.h:36
LHE2HepMCConverter(const edm::ParameterSet &)
int iEvent
Definition: GenABIO.cc:224
void addDefault(ParameterSetDescription const &psetDescription)
const edm::InputTag _lheRunSrcTag
const lhef::HEPRUP & heprup() const
std::vector< FiveVector > PUP
Definition: LesHouches.h:246
bool getByLabel(std::string const &label, Handle< PROD > &result) const
Definition: Run.h:283
const LHERunInfoProduct * _lheRunSrc
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::vector< int > ISTUP
Definition: LesHouches.h:228
std::vector< int > IDUP
Definition: LesHouches.h:223
void beginRun(edm::Run const &, edm::EventSetup const &) override
Log< level::Info, false > LogInfo
bool isValid() const
Definition: HandleBase.h:70
HLT enums.
Log< level::Warning, false > LogWarning
const edm::InputTag _lheEventSrcTag
const edm::EDGetTokenT< LHEEventProduct > eventProductToken_
Handle< PROD > getHandle(EDGetTokenT< PROD > token) const
Definition: Run.h:346
def move(src, dest)
Definition: eostools.py:511
Definition: Run.h:45
const lhef::HEPEUP & hepeup() const