CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
GenParticles2HepMCConverter Class Reference
Inheritance diagram for GenParticles2HepMCConverter:
edm::EDProducer edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

void beginRun (edm::Run &run, const edm::EventSetup &eventSetup)
 
 GenParticles2HepMCConverter (const edm::ParameterSet &pset)
 
void produce (edm::Event &event, const edm::EventSetup &eventSetup)
 
 ~GenParticles2HepMCConverter ()
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDProducer ()
 
- Public Member Functions inherited from edm::ProducerBase
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription
const &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 
- Public Member Functions inherited from edm::EDConsumerBase
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Private Member Functions

HepMC::FourVector FourVector (const reco::Candidate::Point &point)
 
HepMC::FourVector FourVector (const reco::Candidate::LorentzVector &lvec)
 

Private Attributes

edm::InputTag genEventInfoLabel_
 
edm::InputTag genParticlesLabel_
 
edm::ESHandle< ParticleDataTablepTable_
 

Additional Inherited Members

- Public Types inherited from edm::EDProducer
typedef EDProducer ModuleType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 
- Static Public Member Functions inherited from edm::EDProducer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Definition at line 28 of file GenParticles2HepMCConverter.cc.

Constructor & Destructor Documentation

GenParticles2HepMCConverter::GenParticles2HepMCConverter ( const edm::ParameterSet pset)
explicit

Definition at line 59 of file GenParticles2HepMCConverter.cc.

References edm::ParameterSet::getParameter().

60 {
61 // lheEventLabel_ = pset.getParameter<edm::InputTag>("lheEvent");
62  genParticlesLabel_ = pset.getParameter<edm::InputTag>("genParticles");
63  //genRunInfoLabel_ = pset.getParameter<edm::InputTag>("genRunInfo");
64  genEventInfoLabel_ = pset.getParameter<edm::InputTag>("genEventInfo");
65 
66  produces<edm::HepMCProduct>();
67 }
T getParameter(std::string const &) const
GenParticles2HepMCConverter::~GenParticles2HepMCConverter ( )
inline

Definition at line 32 of file GenParticles2HepMCConverter.cc.

32 {};

Member Function Documentation

void GenParticles2HepMCConverter::beginRun ( edm::Run run,
const edm::EventSetup eventSetup 
)

Definition at line 69 of file GenParticles2HepMCConverter.cc.

70 {
71  //edm::Handle<GenRunInfoProduct> genRunInfoHandle;
72  //event.getByLabel(genRunInfoLabel_, genRunInfoHandle);
73  // const double xsecIn = genRunInfoHandle->internalXSec().value();
74  // const double xsecInErr = genRunInfoHandle->internalXSec().error();
75  // const double xsecLO = genRunInfoHandle->externalXSecLO().value();
76  // const double xsecLOErr = genRunInfoHandle->externalXSecLO().error();
77  // const double xsecNLO = genRunInfoHandle->externalXSecNLO().value();
78  // const double xsecNLOErr = genRunInfoHandle->externalXSecNLO().error();
79 }
HepMC::FourVector GenParticles2HepMCConverter::FourVector ( const reco::Candidate::Point point)
inlineprivate

Definition at line 45 of file GenParticles2HepMCConverter.cc.

46  {
47  return HepMC::FourVector(10*point.x(), 10*point.y(), 10*point.z(), 0);
48  };
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
Definition: invegas.h:5
HepMC::FourVector GenParticles2HepMCConverter::FourVector ( const reco::Candidate::LorentzVector lvec)
inlineprivate

Definition at line 50 of file GenParticles2HepMCConverter.cc.

References max().

51  {
52  // Avoid negative mass, set minimum m^2 = 0
53  return HepMC::FourVector(lvec.px(), lvec.py(), lvec.pz(), std::hypot(lvec.P(), std::max(0., lvec.mass())));
54  };
const T & max(const T &a, const T &b)
void GenParticles2HepMCConverter::produce ( edm::Event event,
const edm::EventSetup eventSetup 
)
virtual

Implements edm::EDProducer.

Definition at line 81 of file GenParticles2HepMCConverter.cc.

References reco::Candidate::daughter(), edm::EventID::event(), configurableAnalysis::GenParticle, edm::EventSetup::getData(), i, gen::PdfInfo::id, edm::EventBase::id(), j, reco::Candidate::mother(), n, reco::Candidate::numberOfMothers(), AlCaHLTBitMon_ParallelJobs::p, reco::Candidate::p4(), reco::Candidate::pdgId(), gen::PdfInfo::scalePDF, reco::Candidate::status(), reco::Candidate::vertex(), gen::PdfInfo::x, and gen::PdfInfo::xPDF.

82 {
83 // edm::Handle<LHEEventProduct> lheEventHandle;
84 // event.getByLabel(lheEventLabel_, lheEventHandle);
85 
86  edm::Handle<reco::CandidateView> genParticlesHandle;
87  event.getByLabel(genParticlesLabel_, genParticlesHandle);
88 
89  edm::Handle<GenEventInfoProduct> genEventInfoHandle;
90  event.getByLabel(genEventInfoLabel_, genEventInfoHandle);
91 
92  eventSetup.getData(pTable_);
93 
94  HepMC::GenEvent* hepmc_event = new HepMC::GenEvent();
95  hepmc_event->set_event_number(event.id().event());
96  hepmc_event->set_signal_process_id(genEventInfoHandle->signalProcessID());
97  hepmc_event->set_event_scale(genEventInfoHandle->qScale());
98  hepmc_event->set_alphaQED(genEventInfoHandle->alphaQED());
99  hepmc_event->set_alphaQCD(genEventInfoHandle->alphaQCD());
100 
101  hepmc_event->weights() = genEventInfoHandle->weights();
102 
103  // Set PDF
104  const gen::PdfInfo* pdf = genEventInfoHandle->pdf();
105  const int pdf_id1 = pdf->id.first, pdf_id2 = pdf->id.second;
106  const double pdf_x1 = pdf->x.first, pdf_x2 = pdf->x.second;
107  const double pdf_scalePDF = pdf->scalePDF;
108  const double pdf_xPDF1 = pdf->xPDF.first, pdf_xPDF2 = pdf->xPDF.second;
109  HepMC::PdfInfo hepmc_pdfInfo(pdf_id1, pdf_id2, pdf_x1, pdf_x2, pdf_scalePDF, pdf_xPDF1, pdf_xPDF2);
110  hepmc_event->set_pdf_info(hepmc_pdfInfo);
111 
112  // Load LHE
113 // const lhef::HEPEUP& lheEvent = lheEventHandle->hepeup();
114 // std::vector<int> lhe_meIndex; // Particle indices with preserved mass, status=2
115 // for ( int i=0, n=lheEvent.ISTUP.size(); i<n; ++i )
116 // {
117 // if ( lheEvent.ISTUP[i] == 2 ) lhe_meIndex.push_back(i);
118 // }
119 
120  // Prepare list of HepMC::GenParticles
121  std::map<const reco::Candidate*, HepMC::GenParticle*> genCandToHepMCMap;
122  std::vector<HepMC::GenParticle*> hepmc_particles;
123  for ( unsigned int i=0, n=genParticlesHandle->size(); i<n; ++i )
124  {
125  const reco::Candidate* p = &genParticlesHandle->at(i);
126  HepMC::GenParticle* hepmc_particle = new HepMC::GenParticle(FourVector(p->p4()), p->pdgId(), p->status());
127  hepmc_particle->suggest_barcode(i+1);
128 
129  // Assign particle's generated mass from the standard particle data table
130  double particleMass = pTable_->particle(p->pdgId())->mass();
131 // // Re-assign generated mass from LHE, find particle among the LHE
132 // for ( unsigned int j=0, m=lhe_meIndex.size(); j<m; ++j )
133 // {
134 // const unsigned int lheIndex = lhe_meIndex[j];
135 // if ( p->pdgId() != lheEvent.IDUP[lheIndex] ) continue;
136 //
137 // const lhef::HEPEUP::FiveVector& vp = lheEvent.PUP[lheIndex];
138 // if ( std::abs(vp[0] - p->px()) > 1e-7 or std::abs(vp[1] - p->py()) > 1e-7 ) continue;
139 // if ( std::abs(vp[2] - p->pz()) > 1e-7 or std::abs(vp[3] - p->energy()) > 1e-7 ) continue;
140 //
141 // particleMass = vp[4];
142 // break;
143 // }
144  hepmc_particle->set_generated_mass(particleMass);
145 
146  hepmc_particles.push_back(hepmc_particle);
147  genCandToHepMCMap[p] = hepmc_particle;
148  }
149 
150  // Put incident beam particles : proton -> parton vertex
151  const reco::Candidate* parton1 = genParticlesHandle->at(0).daughter(0);
152  const reco::Candidate* parton2 = genParticlesHandle->at(1).daughter(0);
153  HepMC::GenVertex* vertex1 = new HepMC::GenVertex(FourVector(parton1->vertex()));
154  HepMC::GenVertex* vertex2 = new HepMC::GenVertex(FourVector(parton2->vertex()));
155  hepmc_event->add_vertex(vertex1);
156  hepmc_event->add_vertex(vertex2);
157  //hepmc_particles[0]->set_status(4);
158  //hepmc_particles[1]->set_status(4);
159  vertex1->add_particle_in(hepmc_particles[0]);
160  vertex2->add_particle_in(hepmc_particles[1]);
161  hepmc_event->set_beam_particles(hepmc_particles[0], hepmc_particles[1]);
162 
163  // Prepare vertex list
164  typedef std::map<const reco::Candidate*, HepMC::GenVertex*> ParticleToVertexMap;
165  ParticleToVertexMap particleToVertexMap;
166  particleToVertexMap[parton1] = vertex1;
167  particleToVertexMap[parton2] = vertex2;
168  for ( unsigned int i=2, n=genParticlesHandle->size(); i<n; ++i )
169  {
170  const reco::Candidate* p = &genParticlesHandle->at(i);
171 
172  // Connect mother-daughters for the other cases
173  for ( unsigned int j=0, nMothers=p->numberOfMothers(); j<nMothers; ++j )
174  {
175  // Mother-daughter hierarchy defines vertex
176  const reco::Candidate* elder = p->mother(j)->daughter(0);
177  HepMC::GenVertex* vertex;
178  if ( particleToVertexMap.find(elder) == particleToVertexMap.end() )
179  {
180  vertex = new HepMC::GenVertex(FourVector(elder->vertex()));
181  hepmc_event->add_vertex(vertex);
182  particleToVertexMap[elder] = vertex;
183  }
184  else
185  {
186  vertex = particleToVertexMap[elder];
187  }
188 
189  // Vertex is found. Now connect each other
190  const reco::Candidate* mother = p->mother(j);
191  vertex->add_particle_in(genCandToHepMCMap[mother]);
192  vertex->add_particle_out(hepmc_particles[i]);
193  }
194  }
195 
196  // Finalize HepMC event record
197  hepmc_event->set_signal_process_vertex(*(vertex1->vertices_begin()));
198 
199  std::auto_ptr<edm::HepMCProduct> hepmc_product(new edm::HepMCProduct());
200  hepmc_product->addHepMCData(hepmc_event);
201  event.put(hepmc_product);
202 
203 }
EventNumber_t event() const
Definition: EventID.h:44
int i
Definition: DBlmapReader.cc:9
virtual const Candidate * daughter(size_type i) const =0
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
virtual const Candidate * mother(size_type i=0) const =0
return pointer to mother
virtual int status() const =0
status word
std::pair< double, double > x
Definition: PdfInfo.h:11
virtual size_type numberOfMothers() const =0
number of mothers (zero or one in most of but not all the cases)
edm::ESHandle< ParticleDataTable > pTable_
HepMC::FourVector FourVector(const reco::Candidate::Point &point)
void getData(T &iHolder) const
Definition: EventSetup.h:67
std::pair< double, double > xPDF
Definition: PdfInfo.h:12
int j
Definition: DBlmapReader.cc:9
virtual const Point & vertex() const =0
vertex position
virtual int pdgId() const =0
PDG identifier.
std::pair< int, int > id
Definition: PdfInfo.h:10
edm::EventID id() const
Definition: EventBase.h:56
double scalePDF
Definition: PdfInfo.h:13
virtual const LorentzVector & p4() const =0
four-momentum Lorentz vector

Member Data Documentation

edm::InputTag GenParticles2HepMCConverter::genEventInfoLabel_
private

Definition at line 41 of file GenParticles2HepMCConverter.cc.

edm::InputTag GenParticles2HepMCConverter::genParticlesLabel_
private

Definition at line 39 of file GenParticles2HepMCConverter.cc.

edm::ESHandle<ParticleDataTable> GenParticles2HepMCConverter::pTable_
private

Definition at line 42 of file GenParticles2HepMCConverter.cc.