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