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
 
void modulesDependentUpon (const std::string &iProcessName, std::vector< const char * > &oModuleLabels) 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 bookConverter::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  };
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(), GenParticle::GenParticle, edm::EventSetup::getData(), i, gen::PdfInfo::id, edm::EventBase::id(), j, reco::Candidate::mass(), 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;
131  if ( pTable_->particle(p->pdgId()) ) particleMass = pTable_->particle(p->pdgId())->mass();
132  else particleMass = p->mass();
133 // // Re-assign generated mass from LHE, find particle among the LHE
134 // for ( unsigned int j=0, m=lhe_meIndex.size(); j<m; ++j )
135 // {
136 // const unsigned int lheIndex = lhe_meIndex[j];
137 // if ( p->pdgId() != lheEvent.IDUP[lheIndex] ) continue;
138 //
139 // const lhef::HEPEUP::FiveVector& vp = lheEvent.PUP[lheIndex];
140 // if ( std::abs(vp[0] - p->px()) > 1e-7 or std::abs(vp[1] - p->py()) > 1e-7 ) continue;
141 // if ( std::abs(vp[2] - p->pz()) > 1e-7 or std::abs(vp[3] - p->energy()) > 1e-7 ) continue;
142 //
143 // particleMass = vp[4];
144 // break;
145 // }
146  hepmc_particle->set_generated_mass(particleMass);
147 
148  hepmc_particles.push_back(hepmc_particle);
149  genCandToHepMCMap[p] = hepmc_particle;
150  }
151 
152  // Put incident beam particles : proton -> parton vertex
153  const reco::Candidate* parton1 = genParticlesHandle->at(0).daughter(0);
154  const reco::Candidate* parton2 = genParticlesHandle->at(1).daughter(0);
155  HepMC::GenVertex* vertex1 = new HepMC::GenVertex(FourVector(parton1->vertex()));
156  HepMC::GenVertex* vertex2 = new HepMC::GenVertex(FourVector(parton2->vertex()));
157  hepmc_event->add_vertex(vertex1);
158  hepmc_event->add_vertex(vertex2);
159  //hepmc_particles[0]->set_status(4);
160  //hepmc_particles[1]->set_status(4);
161  vertex1->add_particle_in(hepmc_particles[0]);
162  vertex2->add_particle_in(hepmc_particles[1]);
163  hepmc_event->set_beam_particles(hepmc_particles[0], hepmc_particles[1]);
164 
165  // Prepare vertex list
166  typedef std::map<const reco::Candidate*, HepMC::GenVertex*> ParticleToVertexMap;
167  ParticleToVertexMap particleToVertexMap;
168  particleToVertexMap[parton1] = vertex1;
169  particleToVertexMap[parton2] = vertex2;
170  for ( unsigned int i=2, n=genParticlesHandle->size(); i<n; ++i )
171  {
172  const reco::Candidate* p = &genParticlesHandle->at(i);
173 
174  // Connect mother-daughters for the other cases
175  for ( unsigned int j=0, nMothers=p->numberOfMothers(); j<nMothers; ++j )
176  {
177  // Mother-daughter hierarchy defines vertex
178  const reco::Candidate* elder = p->mother(j)->daughter(0);
179  HepMC::GenVertex* vertex;
180  if ( particleToVertexMap.find(elder) == particleToVertexMap.end() )
181  {
182  vertex = new HepMC::GenVertex(FourVector(elder->vertex()));
183  hepmc_event->add_vertex(vertex);
184  particleToVertexMap[elder] = vertex;
185  }
186  else
187  {
188  vertex = particleToVertexMap[elder];
189  }
190 
191  // Vertex is found. Now connect each other
192  const reco::Candidate* mother = p->mother(j);
193  vertex->add_particle_in(genCandToHepMCMap[mother]);
194  vertex->add_particle_out(hepmc_particles[i]);
195  }
196  }
197 
198  // Finalize HepMC event record
199  hepmc_event->set_signal_process_vertex(*(vertex1->vertices_begin()));
200 
201  std::auto_ptr<edm::HepMCProduct> hepmc_product(new edm::HepMCProduct());
202  hepmc_product->addHepMCData(hepmc_event);
203  event.put(hepmc_product);
204 
205 }
EventNumber_t event() const
Definition: EventID.h:41
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 float mass() const =0
mass
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:78
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.