CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
43 public:
44  explicit LHE2HepMCConverter(const edm::ParameterSet&);
45  ~LHE2HepMCConverter() override;
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 
56  // ----------member data ---------------------------
60 
61  // std::shared_ptr<lhef::LHERunInfo> lheRunInfo_;
62 };
63 
64 //
65 // constants, enums and typedefs
66 //
67 
68 //
69 // static data member definitions
70 //
71 
72 //
73 // constructors and destructor
74 //
76  //register your products
77  produces<edm::HepMCProduct>("unsmeared");
78 
79  _lheEventSrcTag = iConfig.getParameter<edm::InputTag>("LHEEventProduct");
80  _lheRunSrcTag = iConfig.getParameter<edm::InputTag>("LHERunInfoProduct");
81 }
82 
84  // do anything here that needs to be done at desctruction time
85  // (e.g. close files, deallocate resources etc.)
86 }
87 
88 //
89 // member functions
90 //
91 
92 // ------------ method called to produce the data ------------
94  using namespace edm;
95  Handle<LHEEventProduct> lheEventSrc;
96  iEvent.getByLabel(_lheEventSrcTag, lheEventSrc);
97 
98  HepMC::GenEvent* evt = new HepMC::GenEvent();
99  HepMC::GenVertex* v = new HepMC::GenVertex();
100  evt->add_vertex(v);
101  if (_lheRunSrc) {
102  HepMC::FourVector beam1(0, 0, _lheRunSrc->heprup().EBMUP.first, _lheRunSrc->heprup().EBMUP.first);
103  HepMC::GenParticle* gp1 = new HepMC::GenParticle(beam1, _lheRunSrc->heprup().IDBMUP.first, 4);
104  v->add_particle_in(gp1);
105  HepMC::FourVector beam2(0, 0, _lheRunSrc->heprup().EBMUP.second, _lheRunSrc->heprup().EBMUP.second);
106  HepMC::GenParticle* gp2 = new HepMC::GenParticle(beam2, _lheRunSrc->heprup().IDBMUP.second, 4);
107  v->add_particle_in(gp2);
108  evt->set_beam_particles(gp1, gp2);
109  } else {
110  LogWarning("LHE2HepMCConverter") << "Could not retrieve the LHERunInfoProduct for this event. You'll miss the beam "
111  "particles in your HepMC product.";
112  }
113 
114  for (int i = 0; i < lheEventSrc->hepeup().NUP; ++i) {
115  if (lheEventSrc->hepeup().ISTUP[i] != 1) {
116  //cout << reader->hepeup.ISTUP[i] << ", " << reader->hepeup.IDUP[i] << endl;
117  continue;
118  }
119  HepMC::FourVector p(lheEventSrc->hepeup().PUP[i][0],
120  lheEventSrc->hepeup().PUP[i][1],
121  lheEventSrc->hepeup().PUP[i][2],
122  lheEventSrc->hepeup().PUP[i][3]);
123  HepMC::GenParticle* gp = new HepMC::GenParticle(p, lheEventSrc->hepeup().IDUP[i], 1);
124  gp->set_generated_mass(lheEventSrc->hepeup().PUP[i][4]);
125  v->add_particle_out(gp);
126  }
127 
128  std::unique_ptr<HepMCProduct> pOut(new HepMCProduct(evt));
129  iEvent.put(std::move(pOut), "unsmeared");
130 }
131 
132 // ------------ method called when starting to processes a run ------------
134  edm::Handle<LHERunInfoProduct> lheRunSrcHandle;
135  iRun.getByLabel(_lheRunSrcTag, lheRunSrcHandle);
136  if (lheRunSrcHandle.isValid()) {
137  _lheRunSrc = lheRunSrcHandle.product();
138  } else {
139  if (_lheRunSrcTag.label() != "source") {
140  iRun.getByLabel("source", lheRunSrcHandle);
141  if (lheRunSrcHandle.isValid()) {
142  _lheRunSrc = lheRunSrcHandle.product();
143  edm::LogInfo("LHE2HepMCConverter") << "Taking LHERunInfoproduct from source";
144  } else
145  edm::LogWarning("LHE2HepMCConverter") << "No LHERunInfoProduct from source";
146  }
147  }
148 }
149 
150 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
152  //The following says we do not know what parameters are allowed so do no validation
153  // Please change this to state exactly what you do use, even if it is no parameters
155  desc.setUnknown();
156  descriptions.addDefault(desc);
157 }
158 
159 //define this as a plug-in
bool getByLabel(std::string const &label, Handle< PROD > &result) const
Definition: Run.h:283
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::pair< double, double > EBMUP
Definition: LesHouches.h:82
void produce(edm::Event &, const edm::EventSetup &) override
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::pair< int, int > IDBMUP
Definition: LesHouches.h:77
edm::InputTag _lheRunSrcTag
const lhef::HEPRUP & heprup() const
LHE2HepMCConverter(const edm::ParameterSet &)
int iEvent
Definition: GenABIO.cc:224
~LHE2HepMCConverter() override
void addDefault(ParameterSetDescription const &psetDescription)
def move
Definition: eostools.py:511
edm::InputTag _lheEventSrcTag
const LHERunInfoProduct * _lheRunSrc
bool isValid() const
Definition: HandleBase.h:70
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:500
void beginRun(edm::Run const &, edm::EventSetup const &) override
Log< level::Info, false > LogInfo
T const * product() const
Definition: Handle.h:70
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::string const & label() const
Definition: InputTag.h:36
Log< level::Warning, false > LogWarning
Definition: Run.h:45