1 #include "HepMC3/GenEvent.h"
2 #include "HepMC3/GenVertex.h"
3 #include "HepMC3/GenParticle.h"
4 #include "HepMC3/Print.h"
5 #include "PhotosHepMC3Particle.h"
9 using namespace HepMC3;
14 PhotosHepMC3Particle::PhotosHepMC3Particle(){
15 m_particle = make_shared<GenParticle>();
18 PhotosHepMC3Particle::PhotosHepMC3Particle(
int pdg_id,
int status,
double mass){
19 m_particle = make_shared<GenParticle>();
20 m_particle->set_pid(pdg_id);
21 m_particle->set_status(status);
22 m_particle->set_generated_mass(mass);
25 PhotosHepMC3Particle::PhotosHepMC3Particle(GenParticlePtr particle){
26 m_particle = particle;
29 PhotosHepMC3Particle::~PhotosHepMC3Particle(){
37 void PhotosHepMC3Particle::clear(std::vector<PhotosParticle*> v){
45 GenParticlePtr PhotosHepMC3Particle::getHepMC3(){
49 void PhotosHepMC3Particle::setMothers(vector<PhotosParticle*> mothers){
62 GenVertexPtr production_vertex = part->end_vertex();
63 GenVertexPtr orig_production_vertex = production_vertex;
65 if(!production_vertex){
66 production_vertex = make_shared<GenVertex>();
67 part->parent_event()->add_vertex(production_vertex);
71 vector<PhotosParticle*>::iterator mother_itr;
72 for(mother_itr = mothers.begin(); mother_itr != mothers.end();
78 if(moth->end_vertex()!=orig_production_vertex)
79 Log::Fatal(
"PhotosHepMC3Particle::setMothers(): Mother production_vertices point to difference places. Can not override. Please delete vertices first.",1);
81 production_vertex->add_particle_in(moth);
84 if(moth->status()==PhotosParticle::STABLE)
90 production_vertex->add_particle_out(m_particle);
99 m_daughters.push_back(daughter);
103 if(!m_particle->end_vertex())
104 Log::Fatal(
"PhotosHepMC3Particle::addDaughter(): This method assumes an end_vertex exists. Maybe you really want to use setDaughters.",2);
107 m_particle->end_vertex()->add_particle_out(daugh);
111 void PhotosHepMC3Particle::setDaughters(vector<PhotosParticle*> daughters){
113 if(!m_particle->parent_event())
114 Log::Fatal(
"PhotosHepMC3Particle::setDaughters(): New particle needs the event set before it's daughters can be added",3);
119 if(daughters.size()>0){
122 GenParticlePtr first_daughter;
125 GenVertexPtr end_vertex;
126 end_vertex=first_daughter->production_vertex();
127 GenVertexPtr orig_end_vertex = end_vertex;
130 end_vertex = make_shared<GenVertex>();
131 m_particle->parent_event()->add_vertex(end_vertex);
135 vector<PhotosParticle*>::iterator daughter_itr;
136 for(daughter_itr = daughters.begin(); daughter_itr != daughters.end();
143 if(daug->production_vertex()!=orig_end_vertex)
144 Log::Fatal(
"PhotosHepMC3Particle::setDaughters(): Daughter production_vertices point to difference places. Can not override. Please delete vertices first.",4);
146 end_vertex->add_particle_out(daug);
148 end_vertex->add_particle_in(m_particle);
153 std::vector<PhotosParticle*> PhotosHepMC3Particle::getMothers(){
155 if(m_mothers.size()==0&&m_particle->production_vertex()){
157 for(
auto p: m_particle->production_vertex()->particles_in() ) {
164 std::vector<PhotosParticle*> PhotosHepMC3Particle::getDaughters(){
166 if(m_daughters.size()==0&&m_particle->end_vertex()){
168 for(
auto p: m_particle->end_vertex()->particles_out() ) {
171 if( Photos::isStatusCodeIgnored( p->status() ) )
continue;
180 std::vector<PhotosParticle*> PhotosHepMC3Particle::getAllDecayProducts(){
182 m_decay_products.clear();
185 return m_decay_products;
187 std::vector<PhotosParticle*> daughters = getDaughters();
190 m_decay_products.insert(m_decay_products.end(),daughters.begin(),daughters.end());
198 for(
unsigned int i=0;i<m_decay_products.size();i++)
200 std::vector<PhotosParticle*> daughters2 = m_decay_products[i]->getDaughters();
202 if(!m_decay_products[i]->hasDaughters())
continue;
203 for(
unsigned int j=0;j<daughters2.size();j++)
206 for(
unsigned int k=0;k<m_decay_products.size();k++)
207 if( daughters2[j]->getBarcode() == m_decay_products[k]->getBarcode() )
213 if(add) m_decay_products.push_back(daughters2[j]);
216 return m_decay_products;
219 bool PhotosHepMC3Particle::checkMomentumConservation(){
221 if(!m_particle->end_vertex())
return true;
227 for(ConstGenParticlePtr p: m_particle->end_vertex()->particles_in() ) {
228 if( Photos::isStatusCodeIgnored(p->status()) )
continue;
230 sum += p->momentum();
233 for(ConstGenParticlePtr p: m_particle->end_vertex()->particles_out() ) {
234 if( Photos::isStatusCodeIgnored(p->status()) )
continue;
236 sum -= p->momentum();
239 if( sum.length() > Photos::momentum_conservation_threshold ) {
240 Log::Warning()<<
"Momentum not conserved in the vertex:"<<endl;
241 Log::RedirectOutput(Log::Warning(
false));
242 Print::line(m_particle->end_vertex());
250 void PhotosHepMC3Particle::setPdgID(
int pdg_id){
251 m_particle->set_pid(pdg_id);
254 void PhotosHepMC3Particle::setMass(
double mass){
255 m_particle->set_generated_mass(mass);
258 void PhotosHepMC3Particle::setStatus(
int status){
259 m_particle->set_status(status);
262 int PhotosHepMC3Particle::getPdgID(){
263 return m_particle->pid();
266 int PhotosHepMC3Particle::getStatus(){
267 return m_particle->status();
270 int PhotosHepMC3Particle::getBarcode(){
271 return m_particle->id();
276 int pdg_id,
int status,
double mass,
277 double px,
double py,
double pz,
double e){
280 new_particle->
getHepMC3()->set_pid(pdg_id);
281 new_particle->
getHepMC3()->set_status(status);
282 new_particle->
getHepMC3()->set_generated_mass(mass);
284 FourVector momentum(px,py,pz,e);
285 new_particle->
getHepMC3()->set_momentum(momentum);
287 m_created_particles.push_back(new_particle);
291 void PhotosHepMC3Particle::createHistoryEntry(){
293 if(!m_particle->production_vertex())
295 Log::Warning()<<
"PhotosHepMC3Particle::createHistoryEntry(): particle without production vertex."<<endl;
299 GenParticlePtr part = make_shared<GenParticle>(*m_particle);
300 part->set_status(Photos::historyEntriesStatus);
301 m_particle->production_vertex()->add_particle_out(part);
306 if(m_particle->end_vertex())
308 Log::Error()<<
"PhotosHepMC3Particle::createSelfDecayVertex: particle already has end vertex!"<<endl;
312 if(getHepMC3()->parent_event()==NULL)
314 Log::Error()<<
"PhotosHepMC3Particle::createSelfDecayVertex: particle not in the HepMC event!"<<endl;
319 GenParticlePtr outgoing = make_shared<GenParticle>( *(
dynamic_cast<PhotosHepMC3Particle*
>(out)->m_particle) );
320 GenVertexPtr v = make_shared<GenVertex>();
323 v->set_position( m_particle->production_vertex()->position() );
325 v->add_particle_in (m_particle);
326 v->add_particle_out(outgoing);
328 getHepMC3()->parent_event()->add_vertex(v);
331 if(getStatus()==1) setStatus(2);
334 void PhotosHepMC3Particle::print(){
335 Print::line(m_particle);
341 inline double PhotosHepMC3Particle::getPx(){
342 return m_particle->momentum().px();
345 inline double PhotosHepMC3Particle::getPy(){
346 return m_particle->momentum().py();
349 double PhotosHepMC3Particle::getPz(){
350 return m_particle->momentum().pz();
353 double PhotosHepMC3Particle::getE(){
354 return m_particle->momentum().e();
357 void PhotosHepMC3Particle::setPx(
double px){
361 FourVector momentum(m_particle->momentum());
363 m_particle->set_momentum(momentum);
366 void PhotosHepMC3Particle::setPy(
double py){
367 FourVector momentum(m_particle->momentum());
369 m_particle->set_momentum(momentum);
373 void PhotosHepMC3Particle::setPz(
double pz){
374 FourVector momentum(m_particle->momentum());
376 m_particle->set_momentum(momentum);
379 void PhotosHepMC3Particle::setE(
double e){
380 FourVector momentum(m_particle->momentum());
382 m_particle->set_momentum(momentum);
385 double PhotosHepMC3Particle::getMass()
387 return m_particle->generated_mass();
GenParticlePtr getHepMC3()