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 
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 //
75 LHE2HepMCConverter::LHE2HepMCConverter(const edm::ParameterSet& iConfig) : _lheRunSrc(nullptr) {
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
LHE2HepMCConverter::_lheEventSrcTag
edm::InputTag _lheEventSrcTag
Definition: LHE2HepMCConverter.cc:57
LHE2HepMCConverter
Definition: LHE2HepMCConverter.cc:42
Handle.h
mps_fire.i
i
Definition: mps_fire.py:355
edm::Handle::product
T const * product() const
Definition: Handle.h:70
EDProducer.h
LHE2HepMCConverter::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: LHE2HepMCConverter.cc:93
edm::Run
Definition: Run.h:45
lhef::HEPEUP::ISTUP
std::vector< int > ISTUP
Definition: LesHouches.h:228
edm
HLT enums.
Definition: AlignableModifier.h:19
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
ZgammaFilter_cfi.HepMCProduct
HepMCProduct
Definition: ZgammaFilter_cfi.py:9
edm::LogInfo
Definition: MessageLogger.h:254
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
LHERunInfoProduct::heprup
const lhef::HEPRUP & heprup() const
Definition: LHERunInfoProduct.h:55
LHE2HepMCConverter::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: LHE2HepMCConverter.cc:151
findQualityFiles.v
v
Definition: findQualityFiles.py:179
LHE2HepMCConverter::_lheRunSrc
const LHERunInfoProduct * _lheRunSrc
Definition: LHE2HepMCConverter.cc:59
edm::Handle
Definition: AssociativeIterator.h:50
HepMC::GenEvent
Definition: hepmc_rootio.cc:9
lhef::HEPRUP::EBMUP
std::pair< double, double > EBMUP
Definition: LesHouches.h:82
edm::InputTag::label
std::string const & label() const
Definition: InputTag.h:36
LHERunInfoProduct.h
MakerMacros.h
lhef::HEPEUP::NUP
int NUP
Definition: LesHouches.h:184
LHERunInfoProduct
Definition: LHERunInfoProduct.h:13
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Run.h
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
edm::LogWarning
Definition: MessageLogger.h:141
runTauDisplay.gp
gp
Definition: runTauDisplay.py:431
edm::ParameterSet
Definition: ParameterSet.h:36
Event.h
iEvent
int iEvent
Definition: GenABIO.cc:224
LHE2HepMCConverter::_lheRunSrcTag
edm::InputTag _lheRunSrcTag
Definition: LHE2HepMCConverter.cc:58
edm::ParameterSetDescription::setUnknown
void setUnknown()
Definition: ParameterSetDescription.cc:39
edm::EventSetup
Definition: EventSetup.h:57
InputTag.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
LHEEventProduct::hepeup
const lhef::HEPEUP & hepeup() const
Definition: LHEEventProduct.h:46
LHEEventProduct.h
GenParticle.GenParticle
GenParticle
Definition: GenParticle.py:18
eostools.move
def move(src, dest)
Definition: eostools.py:511
Frameworkfwd.h
lhef::HEPEUP::IDUP
std::vector< int > IDUP
Definition: LesHouches.h:223
edm::EDProducer
Definition: EDProducer.h:36
edm::Run::getByLabel
bool getByLabel(std::string const &label, Handle< PROD > &result) const
Definition: Run.h:280
ParameterSet.h
HepMCProduct.h
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
edm::Event
Definition: Event.h:73
edm::ConfigurationDescriptions::addDefault
void addDefault(ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:99
LHE2HepMCConverter::~LHE2HepMCConverter
~LHE2HepMCConverter() override
Definition: LHE2HepMCConverter.cc:83
lhef::HEPEUP::PUP
std::vector< FiveVector > PUP
Definition: LesHouches.h:246
edm::InputTag
Definition: InputTag.h:15
LHE2HepMCConverter::LHE2HepMCConverter
LHE2HepMCConverter(const edm::ParameterSet &)
Definition: LHE2HepMCConverter.cc:75
lhef::HEPRUP::IDBMUP
std::pair< int, int > IDBMUP
Definition: LesHouches.h:77
LHE2HepMCConverter::beginRun
void beginRun(edm::Run const &, edm::EventSetup const &) override
Definition: LHE2HepMCConverter.cc:133