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$
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  virtual void beginJob() ;
59  virtual void produce(edm::Event&, const edm::EventSetup&);
60  virtual void endJob() ;
61 
62  virtual void beginRun(edm::Run&, edm::EventSetup const&);
63  virtual void endRun(edm::Run&, edm::EventSetup const&);
66 
67  // ----------member data ---------------------------
71 
72  // boost::shared_ptr<lhef::LHERunInfo> lheRunInfo_;
73 
74 };
75 
76 //
77 // constants, enums and typedefs
78 //
79 
80 
81 //
82 // static data member definitions
83 //
84 
85 //
86 // constructors and destructor
87 //
89 _lheRunSrc(0)
90 {
91  //register your products
92  produces<edm::HepMCProduct>();
93 
94  _lheEventSrcTag = iConfig.getParameter<edm::InputTag>("LHEEventProduct");
95  _lheRunSrcTag = iConfig.getParameter<edm::InputTag>("LHERunInfoProduct");
96 
97 }
98 
99 
101 {
102 
103  // do anything here that needs to be done at desctruction time
104  // (e.g. close files, deallocate resources etc.)
105 
106 }
107 
108 
109 //
110 // member functions
111 //
112 
113 // ------------ method called to produce the data ------------
114 void
116 {
117  using namespace edm;
118  Handle<LHEEventProduct> lheEventSrc;
119  iEvent.getByLabel(_lheEventSrcTag, lheEventSrc);
120 
121  HepMC::GenEvent *evt = new HepMC::GenEvent();
122  HepMC::GenVertex* v = new HepMC::GenVertex();
123  evt->add_vertex(v);
124  if (_lheRunSrc){
125  HepMC::FourVector beam1(0, 0, _lheRunSrc->heprup().EBMUP.first, _lheRunSrc->heprup().EBMUP.first);
126  HepMC::GenParticle* gp1 = new HepMC::GenParticle(beam1, _lheRunSrc->heprup().IDBMUP.first, 4);
127  v->add_particle_in(gp1);
128  HepMC::FourVector beam2(0, 0, _lheRunSrc->heprup().EBMUP.second, _lheRunSrc->heprup().EBMUP.second);
129  HepMC::GenParticle* gp2 = new HepMC::GenParticle(beam2, _lheRunSrc->heprup().IDBMUP.second, 4);
130  v->add_particle_in(gp2);
131  evt->set_beam_particles(gp1, gp2);
132  } else {
133  LogWarning("LHE2HepMCConverter") << "Could not retrieve the LHERunInfoProduct for this event. You'll miss the beam particles in your HepMC product." ;
134  }
135 
136 
137  for (int i = 0; i < lheEventSrc->hepeup().NUP; ++i) {
138  if (lheEventSrc->hepeup().ISTUP[i] != 1) {
139  //cout << reader->hepeup.ISTUP[i] << ", " << reader->hepeup.IDUP[i] << endl;
140  continue;
141  }
142  HepMC::FourVector p(lheEventSrc->hepeup().PUP[i][0], lheEventSrc->hepeup().PUP[i][1],
143  lheEventSrc->hepeup().PUP[i][2], lheEventSrc->hepeup().PUP[i][3]);
144  HepMC::GenParticle* gp = new HepMC::GenParticle(p, lheEventSrc->hepeup().IDUP[i], 1);
145  gp->set_generated_mass(lheEventSrc->hepeup().PUP[i][4]);
146  v->add_particle_out(gp);
147  }
148 
149  std::auto_ptr<HepMCProduct> pOut(new HepMCProduct(evt));
150  iEvent.put(pOut);
151 
152 }
153 
154 // ------------ method called once each job just before starting event loop ------------
155 void
157 {
158 }
159 
160 // ------------ method called once each job just after ending the event loop ------------
161 void
163 }
164 
165 // ------------ method called when starting to processes a run ------------
166 void
168 {
169 
170  edm::Handle<LHERunInfoProduct> lheRunSrcHandle;
171  iRun.getByLabel(_lheRunSrcTag, lheRunSrcHandle);
172  if (lheRunSrcHandle.isValid()) {
173  _lheRunSrc = lheRunSrcHandle.product();
174  }
175  else {
176  if (_lheRunSrcTag.label() != "source" ) {
177  iRun.getByLabel("source", lheRunSrcHandle);
178  if (lheRunSrcHandle.isValid()) {
179  _lheRunSrc = lheRunSrcHandle.product();
180  edm::LogInfo("LHE2HepMCConverter") << "Taking LHERunInfoproduct from source";
181  }
182  else
183  edm::LogWarning("LHE2HepMCConverter") << "No LHERunInfoProduct from source";
184  }
185 
186  }
187 
188 }
189 
190 // ------------ method called when ending the processing of a run ------------
191 void
193 {
194 }
195 
196 // ------------ method called when starting to processes a luminosity block ------------
197 void
199 {
200 }
201 
202 // ------------ method called when ending the processing of a luminosity block ------------
203 void
205 {
206 }
207 
208 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
209 void
211  //The following says we do not know what parameters are allowed so do no validation
212  // Please change this to state exactly what you do use, even if it is no parameters
214  desc.setUnknown();
215  descriptions.addDefault(desc);
216 }
217 
218 //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:174
int i
Definition: DBlmapReader.cc:9
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::pair< double, double > EBMUP
Definition: LesHouches.h:78
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 &)
virtual void produce(edm::Event &, const edm::EventSetup &)
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:84
edm::InputTag _lheEventSrcTag
virtual void beginLuminosityBlock(edm::LuminosityBlock &, edm::EventSetup const &)
const LHERunInfoProduct * _lheRunSrc
virtual void endRun(edm::Run &, edm::EventSetup const &)
bool isValid() const
Definition: HandleBase.h:76
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:359
virtual void endLuminosityBlock(edm::LuminosityBlock &, edm::EventSetup const &)
T const * product() const
Definition: Handle.h:74
std::string const & label() const
Definition: InputTag.h:25
virtual void beginRun(edm::Run &, edm::EventSetup const &)
mathSSE::Vec4< T > v
Definition: Run.h:31