16 #pragma GCC diagnostic push
17 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
18 #include <HepMC/GenEvent.h>
19 #include <HepMC/GenVertex.h>
20 #pragma GCC diagnostic pop
22 #include <HepMC/GenParticle.h>
23 #include <HepMC/PdfInfo.h>
24 #include <HepMC/SimpleVector.h>
25 #include <HepMC/Units.h>
28 #include <eicsmear/erhic/EventMC.h>
29 #include <eicsmear/erhic/EventMilou.h>
30 #include <eicsmear/erhic/ParticleMC.h>
31 #include <eicsmear/erhic/Pid.h>
33 #include <eicsmear/erhic/EventDEMP.h>
55 , m_EvtGenId(
EvtGen::Unknown)
57 , _node_name(
"PHHepMCGenEvent")
75 Tin =
new TChain(
"EICTree",
"EICTree");
76 Tin->Add(name.c_str());
87 string EventClass(
Tin->GetBranch(
"event")->GetClassName());
90 cout <<
"ReadEICFiles: Input Branch Event Class = "
91 << EventClass << endl;
93 if (EventClass.find(
"Milou") != string::npos)
98 if (EventClass.find(
"DEMP") != string::npos)
121 cout <<
"input file " <<
filename <<
" exhausted" << endl;
125 cout <<
"no file opened" << endl;
133 EicEventHeader *evthead = findNode::getClass<EicEventHeader>(topNode,
"EicEventHeader");
138 erhic::EventMilou *
gen =
dynamic_cast<erhic::EventMilou *
>(
GenEvent);
147 erhic::EventDEMP *
gen =
dynamic_cast<erhic::EventDEMP *
>(
GenEvent);
152 case EvtGen::Unknown:
153 cout <<
"unknown event generator" << endl;
156 cout <<
"what is this " <<
m_EvtGenId <<
" ????" << endl;
161 HepMC::GenEvent *evt =
new HepMC::GenEvent();
164 evt->use_units(HepMC::Units::GEV, HepMC::Units::MM);
167 evt->set_event_number(
entry);
170 evt->set_signal_process_id(
GenEvent->GetProcess());
173 HepMC::PdfInfo pdfinfo;
176 pdfinfo.set_scalePDF(
GenEvent->GetQ2());
177 evt->set_pdf_info(pdfinfo);
181 vector<HepMC::GenParticle *> hepmc_particles;
182 vector<unsigned> origin_index;
185 HepMC::GenParticle *hepmc_beam1 =
nullptr;
186 HepMC::GenParticle *hepmc_beam2 =
nullptr;
188 for (
unsigned ii = 0; ii <
GenEvent->GetNTracks(); ii++)
193 erhic::ParticleMC *track_ii =
GenEvent->GetTrack(ii);
197 cout << __PRETTY_FUNCTION__ <<
" : " << __LINE__ << endl;
198 cout <<
"\ttrack " << ii << endl;
199 cout <<
"\t4mom\t" << track_ii->GetPx() <<
"\t" << track_ii->GetPy() <<
"\t" << track_ii->GetPz() <<
"\t" << track_ii->GetE() << endl;
200 cout <<
"\tstatus= " << track_ii->GetStatus() <<
"\tindex= " << track_ii->GetIndex() <<
"\tmass= " << track_ii->GetM() << endl;
204 HepMC::GenParticle *hepmcpart =
new HepMC::GenParticle(HepMC::FourVector(track_ii->GetPx(),
211 switch (track_ii->GetStatus())
214 hepmcpart->set_status(1);
218 hepmcpart->set_status(3);
222 hepmcpart->set_status(0);
228 hepmcpart->set_status(4);
231 hepmcpart->setGeneratedMass(track_ii->GetM());
234 hepmc_particles.push_back(hepmcpart);
235 origin_index.push_back(track_ii->GetIndex());
239 hepmc_beam1 = hepmcpart;
243 hepmc_beam2 = hepmcpart;
247 if (hepmc_particles.size() != origin_index.size())
249 cout <<
"ReadEICFiles::process_event - Lengths of HepMC particles and Origin index vectors do not match!" << endl;
257 vector<HepMC::GenVertex *> hepmc_vertices;
259 for (
unsigned p = 2;
p < hepmc_particles.size();
p++)
261 HepMC::GenParticle *pp = hepmc_particles.at(
p);
264 if (pp->production_vertex() && pp->end_vertex())
268 erhic::ParticleMC *track_pp =
GenEvent->GetTrack(
p);
270 unsigned parent_index = track_pp->GetParentIndex();
272 HepMC::GenParticle *pmother =
nullptr;
273 for (
unsigned m = 0;
m < hepmc_particles.size();
m++)
275 if (origin_index.at(
m) == parent_index)
277 pmother = hepmc_particles.at(
m);
285 HepMC::GenVertex *hepmcvtx =
new HepMC::GenVertex(HepMC::FourVector(track_pp->GetVertex()[0],
286 track_pp->GetVertex()[1],
287 track_pp->GetVertex()[2],
289 hepmc_vertices.push_back(hepmcvtx);
290 hepmcvtx->add_particle_out(pp);
294 else if (pmother->end_vertex())
296 pmother->end_vertex()->add_particle_out(pp);
301 HepMC::GenVertex *hepmcvtx =
new HepMC::GenVertex(HepMC::FourVector(track_pp->GetVertex()[0],
302 track_pp->GetVertex()[1],
303 track_pp->GetVertex()[2],
305 hepmc_vertices.push_back(hepmcvtx);
306 hepmcvtx->add_particle_in(pmother);
307 pmother->end_vertex()->add_particle_out(pp);
312 for (
unsigned p = 0;
p < 2;
p++)
314 HepMC::GenParticle *pp = hepmc_particles.at(
p);
316 if (!pp->end_vertex())
319 HepMC::GenVertex *hepmcvtx =
new HepMC::GenVertex(HepMC::FourVector(0,
323 hepmc_vertices.push_back(hepmcvtx);
324 hepmcvtx->add_particle_in(pp);
329 for (
unsigned p = 2;
p < hepmc_particles.size();
p++)
331 if (!hepmc_particles.at(
p)->production_vertex())
333 cout <<
"ReadEICFiles::process_event - Missing production vertex for one or more non-beam particles!" << endl;
340 for (
unsigned v = 0;
v < hepmc_vertices.size();
v++)
342 evt->add_vertex(hepmc_vertices.at(
v));
346 evt->set_beam_particles(hepmc_beam1, hepmc_beam2);
352 cout << __PRETTY_FUNCTION__ <<
" : " << __LINE__ << endl;
354 cout << endl << endl;
359 cout <<
"ReadEICFiles::process_event - Failed to add event to HepMC record!" << endl;
378 cout <<
PHWHERE <<
"DST Node missing, doing nothing." << endl;
381 EicEventHeader *evthead = findNode::getClass<EicEventHeader>(topNode,
"EicEventHeader");