Skip to content

Commit ea450e3

Browse files
committed
add dummy incident protons for safety - needed for the particle gun samples
1 parent e4b8a67 commit ea450e3

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

GeneratorInterface/RivetInterface/plugins/GenParticles2HepMCConverter.cc

+28-10
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class GenParticles2HepMCConverter : public edm::stream::EDProducer<>
3838
edm::ESHandle<ParticleDataTable> pTable_;
3939

4040
std::vector<int> signalParticlePdgIds_;
41+
const double cmEnergy_;
4142

4243
private:
4344
inline HepMC::FourVector FourVector(const reco::Candidate::Point& point)
@@ -54,7 +55,8 @@ class GenParticles2HepMCConverter : public edm::stream::EDProducer<>
5455

5556
};
5657

57-
GenParticles2HepMCConverter::GenParticles2HepMCConverter(const edm::ParameterSet& pset)
58+
GenParticles2HepMCConverter::GenParticles2HepMCConverter(const edm::ParameterSet& pset):
59+
cmEnergy_(pset.getUntrackedParameter<double>("cmEnergy", 13000)) // dummy value to set incident proton pz for particle gun samples
5860
{
5961
genParticlesToken_ = consumes<reco::CandidateView>(pset.getParameter<edm::InputTag>("genParticles"));
6062
genEventInfoToken_ = consumes<GenEventInfoProduct>(pset.getParameter<edm::InputTag>("genEventInfo"));
@@ -84,12 +86,14 @@ void GenParticles2HepMCConverter::produce(edm::Event& event, const edm::EventSet
8486

8587
// Set PDF
8688
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);
89+
if ( pdf != nullptr ) {
90+
const int pdf_id1 = pdf->id.first, pdf_id2 = pdf->id.second;
91+
const double pdf_x1 = pdf->x.first, pdf_x2 = pdf->x.second;
92+
const double pdf_scalePDF = pdf->scalePDF;
93+
const double pdf_xPDF1 = pdf->xPDF.first, pdf_xPDF2 = pdf->xPDF.second;
94+
HepMC::PdfInfo hepmc_pdfInfo(pdf_id1, pdf_id2, pdf_x1, pdf_x2, pdf_scalePDF, pdf_xPDF1, pdf_xPDF2);
95+
hepmc_event->set_pdf_info(hepmc_pdfInfo);
96+
}
9397

9498
// Prepare list of HepMC::GenParticles
9599
std::map<const reco::Candidate*, HepMC::GenParticle*> genCandToHepMCMap;
@@ -125,9 +129,23 @@ void GenParticles2HepMCConverter::produce(edm::Event& event, const edm::EventSet
125129
}
126130
}
127131

128-
// Put incident beam particles : proton -> parton vertex
129-
HepMC::GenVertex* vertex1 = new HepMC::GenVertex(FourVector(parton1->vertex()));
130-
HepMC::GenVertex* vertex2 = new HepMC::GenVertex(FourVector(parton2->vertex()));
132+
HepMC::GenVertex* vertex1 = nullptr;
133+
HepMC::GenVertex* vertex2 = nullptr;
134+
if ( parton1 == nullptr and parton2 == nullptr ) {
135+
// Particle gun samples do not have incident partons. Put dummy incident particle and prod vertex
136+
// Note: leave parton1 and parton2 as nullptr since it is not used anymore after creating hepmc_parton1 and 2
137+
const reco::Candidate::LorentzVector nullP4(0,0,0,0);
138+
const reco::Candidate::LorentzVector beamP4(0,0,cmEnergy_/2, cmEnergy_/2);
139+
vertex1 = new HepMC::GenVertex(FourVector(nullP4));
140+
vertex2 = new HepMC::GenVertex(FourVector(nullP4));
141+
hepmc_parton1 = new HepMC::GenParticle(FourVector(+beamP4), 2212, 4);
142+
hepmc_parton2 = new HepMC::GenParticle(FourVector(-beamP4), 2212, 4);
143+
}
144+
else {
145+
// Put incident beam particles : proton -> parton vertex
146+
vertex1 = new HepMC::GenVertex(FourVector(parton1->vertex()));
147+
vertex2 = new HepMC::GenVertex(FourVector(parton2->vertex()));
148+
}
131149
hepmc_event->add_vertex(vertex1);
132150
hepmc_event->add_vertex(vertex2);
133151
vertex1->add_particle_in(hepmc_parton1);

0 commit comments

Comments
 (0)