13 #include "HepMC/GenEvent.h" 14 #include "HepMC/GenParticle.h" 15 #include "HepMC/IO_GenEvent.h" 17 #include "CLHEP/Units/GlobalPhysicalConstants.h" 31 if (instance_ ==
nullptr) {
43 edm::LogError(
"HepMCFileReader") <<
"Constructing a new instance";
49 edm::LogInfo(
"HepMCFileReader") <<
"Destructing HepMCFileReader";
58 edm::LogError(
"HepMCFileReader") <<
"Was already initialized... reinitializing";
65 if (
rdstate() == std::ios::failbit) {
66 throw cms::Exception(
"FileNotFound",
"HepMCFileReader::initialize()") <<
"File " <<
filename <<
" was not found.\n";
74 HepMC::IO_GenEvent
const *
p =
dynamic_cast<HepMC::IO_GenEvent
const *
>(
input());
78 return std::ios::failbit;
85 edm::LogInfo(
"HepMCFileReader") <<
"| --- Event Nr. " <<
evt_->event_number() <<
" with " <<
evt_->particles_size()
86 <<
" particles --- !";
91 edm::LogInfo(
"HepMCFileReader") <<
"Got no event" << endl;
94 return evt_ !=
nullptr;
116 int mo1 = 0, mo2 = 0, da1 = 0, da2 = 0,
status = 0, pid = 0;
117 if (
evt_ !=
nullptr) {
118 cout <<
"---#-------pid--st---Mo1---Mo2---Da1---Da2------px------py------pz-------E-";
119 cout <<
"------m---------x---------y---------z---------t-";
121 cout.setf(ios::right, ios::adjustfield);
122 for (
int n = 1;
n <=
evt_->particles_size();
n++) {
125 cout << setw(4) <<
n << setw(8) << pid << setw(5) <<
status << setw(6) << mo1 << setw(6) << mo2 << setw(6) << da1
128 cout.setf(ios::right, ios::adjustfield);
129 cout << setw(10) << setprecision(2) <<
g->momentum().x();
130 cout << setw(8) << setprecision(2) <<
g->momentum().y();
131 cout << setw(10) << setprecision(2) <<
g->momentum().z();
132 cout << setw(8) << setprecision(2) <<
g->momentum().t();
133 cout << setw(8) << setprecision(2) <<
g->generatedMass();
135 if (
g->production_vertex() !=
nullptr &&
g->end_vertex() !=
nullptr &&
status == 2) {
136 cout << setw(10) << setprecision(2) <<
g->production_vertex()->position().x();
137 cout << setw(10) << setprecision(2) <<
g->production_vertex()->position().y();
138 cout << setw(10) << setprecision(2) <<
g->production_vertex()->position().z();
140 double xm =
g->production_vertex()->position().x();
141 double ym =
g->production_vertex()->position().y();
142 double zm =
g->production_vertex()->position().z();
143 double xd =
g->end_vertex()->position().x();
144 double yd =
g->end_vertex()->position().y();
145 double zd =
g->end_vertex()->position().z();
146 double decl =
sqrt((xd - xm) * (xd - xm) + (yd - ym) * (yd - ym) + (zd - zm) * (zd - zm));
147 double labTime = decl / c_light;
149 double properTime = labTime /
g->momentum().rho() * (
g->generatedMass());
151 cout << setw(8) << setprecision(2) << properTime;
153 cout << setw(10) << setprecision(2) << 0.0;
154 cout << setw(10) << setprecision(2) << 0.0;
155 cout << setw(10) << setprecision(2) << 0.0;
156 cout << setw(8) << setprecision(2) << 0.0;
161 cout <<
" HepMCFileReader: No event available !" << endl;
167 unsigned int particle_counter = 0;
170 for (HepMC::GenEvent::vertex_const_iterator
v =
evt_->vertices_begin();
v !=
evt_->vertices_end(); ++
v) {
173 for (HepMC::GenVertex::particles_in_const_iterator
p1 = (*v)->particles_in_const_begin();
174 p1 != (*v)->particles_in_const_end();
187 for (HepMC::GenVertex::particles_out_const_iterator
p2 = (*v)->particles_out_const_begin();
188 p2 != (*v)->particles_out_const_end();
190 if (!(*p2)->end_vertex()) {
207 cout <<
"HepMCFileReader: Got no event :-( Game over already ?" << endl;
218 int last_mother = first_mother + num_mothers - 1;
219 if (first_mother == 0)
232 HepMC::GenVertex::particle_iterator ic;
233 int last_daughter = 0;
240 if (first_daughter == 0)
242 da1 = first_daughter;
253 std::map<HepMC::GenParticle *, int>::const_iterator iter =
m.find(
p);
254 return (iter ==
m.end()) ? 0 : iter->second;
virtual void getStatsFromTuple(int &mo1, int &mo2, int &da1, int &da2, int &status, int &pid, int j) const
static HepMCFileReader * instance_
edm::propagate_const< HepMC::IO_BaseClass * > input_
virtual void initialize(const std::string &filename)
Log< level::Error, false > LogError
virtual bool setEvent(int event)
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
constexpr element_type const * get() const
virtual ~HepMCFileReader()
std::vector< HepMC::GenParticle * > index_to_particle
static HepMCFileReader * instance()
edm::propagate_const< HepMC::GenEvent * > evt_
std::map< HepMC::GenParticle *, int > particle_to_index
int find_in_map(const std::map< HepMC::GenParticle *, int > &m, HepMC::GenParticle *p) const
virtual bool printHepMcEvent() const
Log< level::Info, false > LogInfo
virtual bool readCurrentEvent()
HepMC::GenEvent * fillCurrentEventData()
HepMC::IO_BaseClass const * input() const
bool isInitialized() const