CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 // $Id: LHE2HepMCConverter.cc,v 1.2 2013/03/01 21:45:29 wdd Exp $
17 //
18 //
19 
20 
21 // system include files
22 #include <memory>
23 
24 #include <boost/shared_ptr.hpp>
25 
26 // user include files
29 
33 
37 
41 
42 //
43 // class declaration
44 //
45 
47  public:
48  explicit LHE2HepMCConverter(const edm::ParameterSet&);
50 
51  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
52 
53  protected:
54 
55  // lhef::LHERunInfo *lheRunInfo() { return lheRunInfo_.get(); }
56 
57  private:
58 
59  virtual void produce(edm::Event&, const edm::EventSetup&) override;
60  virtual void beginRun(edm::Run const&, edm::EventSetup const&) override;
61 
62  // ----------member data ---------------------------
66 
67  // boost::shared_ptr<lhef::LHERunInfo> lheRunInfo_;
68 
69 };
70 
71 //
72 // constants, enums and typedefs
73 //
74 
75 
76 //
77 // static data member definitions
78 //
79 
80 //
81 // constructors and destructor
82 //
84 _lheRunSrc(0)
85 {
86  //register your products
87  produces<edm::HepMCProduct>();
88 
89  _lheEventSrcTag = iConfig.getParameter<edm::InputTag>("LHEEventProduct");
90  _lheRunSrcTag = iConfig.getParameter<edm::InputTag>("LHERunInfoProduct");
91 
92 }
93 
94 
96 {
97 
98  // do anything here that needs to be done at desctruction time
99  // (e.g. close files, deallocate resources etc.)
100 
101 }
102 
103 
104 //
105 // member functions
106 //
107 
108 // ------------ method called to produce the data ------------
109 void
111 {
112  using namespace edm;
113  Handle<LHEEventProduct> lheEventSrc;
114  iEvent.getByLabel(_lheEventSrcTag, lheEventSrc);
115 
116  HepMC::GenEvent *evt = new HepMC::GenEvent();
117  HepMC::GenVertex* v = new HepMC::GenVertex();
118  evt->add_vertex(v);
119  if (_lheRunSrc){
120  HepMC::FourVector beam1(0, 0, _lheRunSrc->heprup().EBMUP.first, _lheRunSrc->heprup().EBMUP.first);
121  HepMC::GenParticle* gp1 = new HepMC::GenParticle(beam1, _lheRunSrc->heprup().IDBMUP.first, 4);
122  v->add_particle_in(gp1);
123  HepMC::FourVector beam2(0, 0, _lheRunSrc->heprup().EBMUP.second, _lheRunSrc->heprup().EBMUP.second);
124  HepMC::GenParticle* gp2 = new HepMC::GenParticle(beam2, _lheRunSrc->heprup().IDBMUP.second, 4);
125  v->add_particle_in(gp2);
126  evt->set_beam_particles(gp1, gp2);
127  } else {
128  LogWarning("LHE2HepMCConverter") << "Could not retrieve the LHERunInfoProduct for this event. You'll miss the beam particles in your HepMC product." ;
129  }
130 
131 
132  for (int i = 0; i < lheEventSrc->hepeup().NUP; ++i) {
133  if (lheEventSrc->hepeup().ISTUP[i] != 1) {
134  //cout << reader->hepeup.ISTUP[i] << ", " << reader->hepeup.IDUP[i] << endl;
135  continue;
136  }
137  HepMC::FourVector p(lheEventSrc->hepeup().PUP[i][0], lheEventSrc->hepeup().PUP[i][1],
138  lheEventSrc->hepeup().PUP[i][2], lheEventSrc->hepeup().PUP[i][3]);
139  HepMC::GenParticle* gp = new HepMC::GenParticle(p, lheEventSrc->hepeup().IDUP[i], 1);
140  gp->set_generated_mass(lheEventSrc->hepeup().PUP[i][4]);
141  v->add_particle_out(gp);
142  }
143 
144  std::auto_ptr<HepMCProduct> pOut(new HepMCProduct(evt));
145  iEvent.put(pOut);
146 
147 }
148 
149 // ------------ method called when starting to processes a run ------------
150 void
152 {
153 
154  edm::Handle<LHERunInfoProduct> lheRunSrcHandle;
155  iRun.getByLabel(_lheRunSrcTag, lheRunSrcHandle);
156  if (lheRunSrcHandle.isValid()) {
157  _lheRunSrc = lheRunSrcHandle.product();
158  }
159  else {
160  if (_lheRunSrcTag.label() != "source" ) {
161  iRun.getByLabel("source", lheRunSrcHandle);
162  if (lheRunSrcHandle.isValid()) {
163  _lheRunSrc = lheRunSrcHandle.product();
164  edm::LogInfo("LHE2HepMCConverter") << "Taking LHERunInfoproduct from source";
165  }
166  else
167  edm::LogWarning("LHE2HepMCConverter") << "No LHERunInfoProduct from source";
168  }
169 
170  }
171 
172 }
173 
174 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
175 void
177  //The following says we do not know what parameters are allowed so do no validation
178  // Please change this to state exactly what you do use, even if it is no parameters
180  desc.setUnknown();
181  descriptions.addDefault(desc);
182 }
183 
184 //define this as a plug-in
T getParameter(std::string const &) const
bool getByLabel(std::string const &label, Handle< PROD > &result) const
Definition: Run.h:176
int i
Definition: DBlmapReader.cc:9
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::pair< double, double > EBMUP
Definition: LesHouches.h:78
virtual void produce(edm::Event &, const edm::EventSetup &) override
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::pair< int, int > IDBMUP
Definition: LesHouches.h:73
edm::InputTag _lheRunSrcTag
const lhef::HEPRUP & heprup() const
LHE2HepMCConverter(const edm::ParameterSet &)
int iEvent
Definition: GenABIO.cc:243
void addDefault(ParameterSetDescription const &psetDescription)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:94
edm::InputTag _lheEventSrcTag
const LHERunInfoProduct * _lheRunSrc
bool isValid() const
Definition: HandleBase.h:76
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
virtual void beginRun(edm::Run const &, edm::EventSetup const &) override
T const * product() const
Definition: Handle.h:74
std::string const & label() const
Definition: InputTag.h:42
Definition: Run.h:36