CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
GenParticles2HepMCConverter Class Reference
Inheritance diagram for GenParticles2HepMCConverter:
edm::stream::EDProducer<> edm::stream::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 GenParticles2HepMCConverter (const edm::ParameterSet &pset)
 
void produce (edm::Event &event, const edm::EventSetup &eventSetup) override
 
 ~GenParticles2HepMCConverter ()
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
- Public Member Functions inherited from edm::stream::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDProducerBase ()
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription const &)> registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, std::unordered_multimap< std::string, edm::ProductResolverIndex > const &iIndicies, std::string const &moduleLabel)
 
virtual ~ProducerBase () noexcept(false)
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Member Functions

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

Private Attributes

edm::EDGetTokenT< GenEventInfoProductgenEventInfoToken_
 
edm::EDGetTokenT< reco::CandidateViewgenParticlesToken_
 
edm::ESHandle< ParticleDataTablepTable_
 
std::vector< int > signalParticlePdgIds_
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
typedef CacheContexts< T... > CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T... > HasAbility
 
typedef CacheTypes::LuminosityBlockCache LuminosityBlockCache
 
typedef LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCacheLuminosityBlockContext
 
typedef CacheTypes::LuminosityBlockSummaryCache LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache, GlobalCacheRunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 
- Public Types inherited from edm::stream::EDProducerBase
typedef EDProducerAdaptorBase ModuleType
 
- Public Types inherited from edm::ProducerBase
typedef ProductRegistryHelper::TypeLabelList TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::stream::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- 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 27 of file GenParticles2HepMCConverter.cc.

Constructor & Destructor Documentation

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

Definition at line 57 of file GenParticles2HepMCConverter.cc.

References edm::ParameterSet::getParameter().

58 {
59  genParticlesToken_ = consumes<reco::CandidateView>(pset.getParameter<edm::InputTag>("genParticles"));
60  genEventInfoToken_ = consumes<GenEventInfoProduct>(pset.getParameter<edm::InputTag>("genEventInfo"));
61  signalParticlePdgIds_ = pset.getParameter<std::vector<int>>("signalParticlePdgIds");
62 
63  produces<edm::HepMCProduct>("unsmeared");
64 }
T getParameter(std::string const &) const
edm::EDGetTokenT< GenEventInfoProduct > genEventInfoToken_
edm::EDGetTokenT< reco::CandidateView > genParticlesToken_
GenParticles2HepMCConverter::~GenParticles2HepMCConverter ( )
inline

Definition at line 31 of file GenParticles2HepMCConverter.cc.

31 {};

Member Function Documentation

HepMC::FourVector GenParticles2HepMCConverter::FourVector ( const reco::Candidate::Point point)
inlineprivate

Definition at line 43 of file GenParticles2HepMCConverter.cc.

44  {
45  return HepMC::FourVector(10*point.x(), 10*point.y(), 10*point.z(), 0);
46  };
*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 48 of file GenParticles2HepMCConverter.cc.

References hpstanc_transforms::max.

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

Definition at line 66 of file GenParticles2HepMCConverter.cc.

References GenEventInfoProduct::alphaQCD(), GenEventInfoProduct::alphaQED(), edm::View< T >::at(), class-composition::children, reco::Candidate::daughter(), DEFINE_FWK_MODULE, edm::EventID::event(), spr::find(), GenParticle::GenParticle, edm::EventSetup::getData(), mps_fire::i, gen::PdfInfo::id, edm::EventBase::id(), ResonanceBuilder::mass, reco::Candidate::mass(), reco::Candidate::mother(), eostools::move(), gen::n, reco::Candidate::numberOfMothers(), AlCaHLTBitMon_ParallelJobs::p, reco::Candidate::p4(), GenEventInfoProduct::pdf(), cosmictrackingParticleSelector_cfi::pdgId, reco::Candidate::pdgId(), GenEventInfoProduct::qScale(), gen::PdfInfo::scalePDF, GenEventInfoProduct::signalProcessID(), edm::View< T >::size(), reco::Candidate::status(), findQualityFiles::v, reco::Candidate::vertex(), GenEventInfoProduct::weights(), gen::PdfInfo::x, and gen::PdfInfo::xPDF.

67 {
68  edm::Handle<reco::CandidateView> genParticlesHandle;
69  event.getByToken(genParticlesToken_, genParticlesHandle);
70 
71  edm::Handle<GenEventInfoProduct> genEventInfoHandle;
72  event.getByToken(genEventInfoToken_, genEventInfoHandle);
73 
74  eventSetup.getData(pTable_);
75 
76  HepMC::GenEvent* hepmc_event = new HepMC::GenEvent();
77  hepmc_event->set_event_number(event.id().event());
78  hepmc_event->set_signal_process_id(genEventInfoHandle->signalProcessID());
79  hepmc_event->set_event_scale(genEventInfoHandle->qScale());
80  hepmc_event->set_alphaQED(genEventInfoHandle->alphaQED());
81  hepmc_event->set_alphaQCD(genEventInfoHandle->alphaQCD());
82 
83  hepmc_event->weights() = genEventInfoHandle->weights();
84 
85  // Set PDF
86  const gen::PdfInfo* pdf = genEventInfoHandle->pdf();
87  const int pdf_id1 = pdf->id.first, pdf_id2 = pdf->id.second;
88  const double pdf_x1 = pdf->x.first, pdf_x2 = pdf->x.second;
89  const double pdf_scalePDF = pdf->scalePDF;
90  const double pdf_xPDF1 = pdf->xPDF.first, pdf_xPDF2 = pdf->xPDF.second;
91  HepMC::PdfInfo hepmc_pdfInfo(pdf_id1, pdf_id2, pdf_x1, pdf_x2, pdf_scalePDF, pdf_xPDF1, pdf_xPDF2);
92  hepmc_event->set_pdf_info(hepmc_pdfInfo);
93 
94  // Prepare list of HepMC::GenParticles
95  std::map<const reco::Candidate*, HepMC::GenParticle*> genCandToHepMCMap;
96  std::vector<HepMC::GenParticle*> hepmc_particles;
97  for ( unsigned int i=0, n=genParticlesHandle->size(); i<n; ++i )
98  {
99  const reco::Candidate* p = &genParticlesHandle->at(i);
100  HepMC::GenParticle* hepmc_particle = new HepMC::GenParticle(FourVector(p->p4()), p->pdgId(), p->status());
101  hepmc_particle->suggest_barcode(i+1);
102 
103  // Assign particle's generated mass from the standard particle data table
104  double particleMass;
105  if ( pTable_->particle(p->pdgId()) ) particleMass = pTable_->particle(p->pdgId())->mass();
106  else particleMass = p->mass();
107 
108  hepmc_particle->set_generated_mass(particleMass);
109 
110  hepmc_particles.push_back(hepmc_particle);
111  genCandToHepMCMap[p] = hepmc_particle;
112  }
113 
114  // Put incident beam particles : proton -> parton vertex
115  const reco::Candidate* parton1 = genParticlesHandle->at(0).daughter(0);
116  const reco::Candidate* parton2 = genParticlesHandle->at(1).daughter(0);
117  HepMC::GenVertex* vertex1 = new HepMC::GenVertex(FourVector(parton1->vertex()));
118  HepMC::GenVertex* vertex2 = new HepMC::GenVertex(FourVector(parton2->vertex()));
119  hepmc_event->add_vertex(vertex1);
120  hepmc_event->add_vertex(vertex2);
121  vertex1->add_particle_in(hepmc_particles[0]);
122  vertex2->add_particle_in(hepmc_particles[1]);
123  hepmc_event->set_beam_particles(hepmc_particles[0], hepmc_particles[1]);
124 
125  // Prepare vertex list
126  typedef std::map<const reco::Candidate*, HepMC::GenVertex*> ParticleToVertexMap;
127  ParticleToVertexMap particleToVertexMap;
128  particleToVertexMap[parton1] = vertex1;
129  particleToVertexMap[parton2] = vertex2;
130  for ( unsigned int i=2, n=genParticlesHandle->size(); i<n; ++i )
131  {
132  const reco::Candidate* p = &genParticlesHandle->at(i);
133 
134  // Connect mother-daughters for the other cases
135  for ( unsigned int j=0, nMothers=p->numberOfMothers(); j<nMothers; ++j )
136  {
137  // Mother-daughter hierarchy defines vertex
138  const reco::Candidate* elder = p->mother(j)->daughter(0);
139  HepMC::GenVertex* vertex;
140  if ( particleToVertexMap.find(elder) == particleToVertexMap.end() )
141  {
142  vertex = new HepMC::GenVertex(FourVector(elder->vertex()));
143  hepmc_event->add_vertex(vertex);
144  particleToVertexMap[elder] = vertex;
145  }
146  else
147  {
148  vertex = particleToVertexMap[elder];
149  }
150 
151  // Vertex is found. Now connect each other
152  const reco::Candidate* mother = p->mother(j);
153  vertex->add_particle_in(genCandToHepMCMap[mother]);
154  vertex->add_particle_out(hepmc_particles[i]);
155  }
156  }
157 
158  // Finalize HepMC event record
159  bool hasSignalVertex = false;
160  if ( !signalParticlePdgIds_.empty() ) {
161  // Loop over all vertices to assign the signal vertex, decaying to a signal particle
162  for ( auto v = hepmc_event->vertices_begin(); v != hepmc_event->vertices_end(); ++v ) {
163  for ( auto p = (*v)->particles_begin(HepMC::children);
164  p != (*v)->particles_end(HepMC::children); ++p ) {
165  const int pdgId = (*p)->pdg_id();
167  hepmc_event->set_signal_process_vertex(*v);
168  hasSignalVertex = true;
169  break;
170  }
171  }
172  if ( hasSignalVertex ) break;
173  }
174  }
175  // Set the default signal vertex if still not set
176  if ( !hasSignalVertex ) hepmc_event->set_signal_process_vertex(*(vertex1->vertices_begin()));
177 
178  std::unique_ptr<edm::HepMCProduct> hepmc_product(new edm::HepMCProduct());
179  hepmc_product->addHepMCData(hepmc_event);
180  event.put(std::move(hepmc_product), "unsmeared");
181 
182 }
EventNumber_t event() const
Definition: EventID.h:41
edm::EDGetTokenT< GenEventInfoProduct > genEventInfoToken_
const PDF * pdf() const
double alphaQCD() const
virtual const Candidate * daughter(size_type i) const =0
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
std::pair< double, double > x
Definition: PdfInfo.h:13
edm::ESHandle< ParticleDataTable > pTable_
size_type size() const
virtual const Candidate * mother(size_type i=0) const =0
return pointer to mother
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
HepMC::FourVector FourVector(const reco::Candidate::Point &point)
edm::EDGetTokenT< reco::CandidateView > genParticlesToken_
void getData(T &iHolder) const
Definition: EventSetup.h:79
std::pair< double, double > xPDF
Definition: PdfInfo.h:14
virtual int status() const =0
status word
double qScale() const
virtual const LorentzVector & p4() const =0
four-momentum Lorentz vector
virtual int pdgId() const =0
PDG identifier.
virtual size_type numberOfMothers() const =0
number of mothers (zero or one in most of but not all the cases)
double alphaQED() const
std::pair< int, int > id
Definition: PdfInfo.h:12
virtual double mass() const =0
mass
edm::EventID id() const
Definition: EventBase.h:60
std::vector< double > & weights()
const_reference at(size_type pos) const
virtual const Point & vertex() const =0
vertex position
unsigned int signalProcessID() const
double scalePDF
Definition: PdfInfo.h:15
def move(src, dest)
Definition: eostools.py:510

Member Data Documentation

edm::EDGetTokenT<GenEventInfoProduct> GenParticles2HepMCConverter::genEventInfoToken_
private

Definition at line 37 of file GenParticles2HepMCConverter.cc.

edm::EDGetTokenT<reco::CandidateView> GenParticles2HepMCConverter::genParticlesToken_
private

Definition at line 36 of file GenParticles2HepMCConverter.cc.

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

Definition at line 38 of file GenParticles2HepMCConverter.cc.

std::vector<int> GenParticles2HepMCConverter::signalParticlePdgIds_
private

Definition at line 40 of file GenParticles2HepMCConverter.cc.