JHUGen MELA  JHUGen v7.5.6, MELA v2.4.2
Matrix element calculations as used in JHUGen.
MELAParticle.cc
Go to the documentation of this file.
1 #include "MELAParticle.h"
2 #include "TUtilHelpers.hh"
3 #include "MELAStreamHelpers.hh"
4 
5 
8 using namespace PDGHelpers;
9 
10 
11 namespace debugVars{
12  bool debugFlag = false;
13 }
14 
15 
17 id(-9000),
18 p4(0, 0, 0, 0),
19 passSelection(true),
20 genStatus(-2),
21 lifetime(0)
22 {}
24 id(id_),
25 p4(0, 0, 0, 0),
26 passSelection(true),
27 genStatus(-2),
28 lifetime(0)
29 {}
30 MELAParticle::MELAParticle(int id_, TLorentzVector p4_) :
31 id(id_),
32 p4(p4_),
33 passSelection(true),
34 genStatus(-2),
35 lifetime(0)
36 {}
38 id(particle_.id),
39 p4(particle_.p4),
40 passSelection(particle_.passSelection),
41 genStatus(particle_.genStatus),
42 lifetime(particle_.lifetime),
43 mothers(particle_.mothers),
44 daughters(particle_.daughters)
45 {}
47  MELAParticle tmp(particle_);
48  swap(tmp);
49  return *this;
50 }
51 
53  std::swap(id, particle_.id);
54  std::swap(p4, particle_.p4);
55  std::swap(passSelection, particle_.passSelection);
56  std::swap(genStatus, particle_.genStatus);
57  std::swap(lifetime, particle_.lifetime);
58  std::swap(mothers, particle_.mothers);
59  std::swap(daughters, particle_.daughters);
60 }
61 
62 void MELAParticle::addMother(MELAParticle* myParticle){ if (!checkParticleExists(myParticle, mothers)) mothers.push_back(myParticle); }
63 void MELAParticle::addDaughter(MELAParticle* myParticle){ if (!checkParticleExists(myParticle, daughters)) daughters.push_back(myParticle); }
65  if ((int)mothers.size()>index) return mothers.at(index);
66  else return 0;
67 }
69  if ((int)daughters.size()>index) return daughters.at(index);
70  else return 0;
71 }
72 std::vector<int> MELAParticle::getDaughterIds()const{
73  std::vector<int> result;
74  for (auto& dau:daughters){ if (dau) result.push_back(dau->id); }
75  return result;
76 }
77 void MELAParticle::getRelatedParticles(std::vector<MELAParticle*>& particles) const{
78  for (auto* part:mothers){ if (part) part->getRelatedParticles(particles); }
79  for (auto* part:daughters){ if (part) part->getRelatedParticles(particles); }
80  if (!checkParticleExists(this, particles)) particles.push_back((MELAParticle*) this);
81 }
82 void MELAParticle::getDaughterParticles(std::vector<MELAParticle*>& particles) const{
83  for (auto* part:daughters){ if (part) part->getDaughterParticles(particles); }
84  if (!checkParticleExists(this, particles)) particles.push_back((MELAParticle*) this); // A particle is its own daughter. This is to ensure that particle chains are reported properly.
85 }
86 
89 
90 double MELAParticle::charge()const{
91  double cpos=0;
92  if (isAWBoson(id) || abs(id)==37 || abs(id)==2212 || abs(id)==211 || abs(id)==321 || abs(id)==411 || abs(id)==521) cpos = 1.;
93  else if (isALepton(id)) cpos = -1.;
94  else if (isUpTypeQuark(id)) cpos = 2./3.;
95  else if (isDownTypeQuark(id)) cpos = -1./3.;
96  if (id<0) cpos *= -1.;
97  return cpos;
98 }
99 
100 void MELAParticle::boost(const TVector3& vec, bool boostAll){
101  if (vec.Mag2()<1.){
102  if (boostAll){
103  std::vector<MELAParticle*> particles;
104  this->getRelatedParticles(particles);
105  for (std::vector<MELAParticle*>::iterator it = particles.begin(); it<particles.end(); it++) (*it)->boost(vec, false);
106  }
107  else p4.Boost(vec);
108  }
109  else MELAerr
110  << "MELAParticle::boost: "
111  << "|v|**2 = " << vec.Mag2() << " >=1 cannot be used to boost. "
112  << "v = ( " << vec.X() << " , " << vec.Y() << " , " << vec.Z() << " )"
113  << std::endl;
114 }
115 
116 bool MELAParticle::checkParticleExists(MELAParticle const* myParticle, std::vector<MELAParticle*> const& particleArray){
117  return TUtilHelpers::checkElementExists<MELAParticle const*, MELAParticle*>(myParticle, particleArray);
118 }
120  bool res = false;
121  if (!part1 || !part2) return res;
122  std::vector<MELAParticle*> daughters1; part1->getDaughterParticles(daughters1);
123  std::vector<MELAParticle*> daughters2; part2->getDaughterParticles(daughters2);
124  return TUtilHelpers::hasCommonElements(daughters1, daughters2);
125 }
126 
128  TVector3 res;
129  double const part_mass = this->m();
130  TVector3 const part_vec = this->vect();
131 
132  // Calculate displacement
133  if (part_mass>0.) res = part_vec * (lifetime/part_mass);
134  //MELAout << "Displacement for id=" << this->id << " = " << res.X() << ", " << res.Y() << ", " << res.Z() << " [mom: " << this->p4 << ", lifetime: " << lifetime << "]" << std::endl;
135 
136  // Add mother displacement
137  if (this->getNMothers()==1) res += this->getMother(0)->calculateTotalDisplacement();
138 
139  return res;
140 }
141 
MELAParticle::operator=
MELAParticle & operator=(const MELAParticle &particle_)
Definition: MELAParticle.cc:46
PDGHelpers::isALepton
bool isALepton(const int id)
Definition: PDGHelpers.cc:62
MELAParticle::MELAParticle
MELAParticle()
Definition: MELAParticle.cc:16
MELAParticle::getDaughter
MELAParticle * getDaughter(int index) const
Definition: MELAParticle.cc:68
debugVars::debugFlag
bool debugFlag
Definition: MELAParticle.cc:12
MELAParticle::swap
void swap(MELAParticle &particle_)
Definition: MELAParticle.cc:52
PDGHelpers
Definition: PDGHelpers.h:12
MELAParticle::calculateTotalDisplacement
TVector3 calculateTotalDisplacement() const
Definition: MELAParticle.cc:127
MELAParticle::checkParticleExists
static bool checkParticleExists(MELAParticle const *myParticle, std::vector< MELAParticle * > const &particleArray)
Definition: MELAParticle.cc:116
MELAParticle::hasDaughter
bool hasDaughter(MELAParticle const *part) const
Definition: MELAParticle.cc:88
MELAStreamHelpers::MELAout
MELAOutputStreamer MELAout
MELAParticle::m
double m() const
Definition: MELAParticle.h:66
PDGHelpers::isDownTypeQuark
bool isDownTypeQuark(const int id)
Definition: PDGHelpers.cc:45
MELAParticle::p4
TLorentzVector p4
Definition: MELAParticle.h:18
MELAParticle::hasMother
bool hasMother(MELAParticle const *part) const
Definition: MELAParticle.cc:87
MELAParticle::daughters
std::vector< MELAParticle * > daughters
Definition: MELAParticle.h:25
MELAParticle::vect
TVector3 vect() const
Definition: MELAParticle.h:86
PDGHelpers::isAWBoson
bool isAWBoson(const int id)
Definition: PDGHelpers.cc:80
MELAParticle::genStatus
int genStatus
Definition: MELAParticle.h:20
MELAParticle::charge
double charge() const
Definition: MELAParticle.cc:90
MELAParticle::checkDeepDaughtership
static bool checkDeepDaughtership(MELAParticle const *part1, MELAParticle const *part2)
Definition: MELAParticle.cc:119
MELAParticle
Definition: MELAParticle.h:13
debugVars
Definition: MELAParticle.h:9
MELAParticle::lifetime
double lifetime
Definition: MELAParticle.h:21
MELAParticle::getDaughterParticles
virtual void getDaughterParticles(std::vector< MELAParticle * > &particles) const
Definition: MELAParticle.cc:82
MELAParticle::mothers
std::vector< MELAParticle * > mothers
Definition: MELAParticle.h:24
MELAParticle.h
MELAParticle::addMother
void addMother(MELAParticle *myParticle)
Definition: MELAParticle.cc:62
MELAStreamHelpers::MELAerr
MELAOutputStreamer MELAerr
MELAParticle::passSelection
bool passSelection
Definition: MELAParticle.h:19
TUtilHelpers.hh
MELAParticle::getMother
MELAParticle * getMother(int index) const
Definition: MELAParticle.cc:64
MELAStreamHelpers.hh
TUtilHelpers::hasCommonElements
bool hasCommonElements(std::vector< T > const &v1, std::vector< T > const &v2)
Definition: TUtilHelpers.hh:63
MELAParticle::getRelatedParticles
virtual void getRelatedParticles(std::vector< MELAParticle * > &particles) const
Definition: MELAParticle.cc:77
MELAParticle::id
int id
Definition: MELAParticle.h:17
MELAParticle::getDaughterIds
virtual std::vector< int > getDaughterIds() const
Definition: MELAParticle.cc:72
MELAParticle::boost
void boost(const TVector3 &vec, bool boostAll=false)
Definition: MELAParticle.cc:100
MELAParticle::getNMothers
int getNMothers() const
Definition: MELAParticle.h:49
PDGHelpers::isUpTypeQuark
bool isUpTypeQuark(const int id)
Definition: PDGHelpers.cc:40
MELAParticle::addDaughter
void addDaughter(MELAParticle *myParticle)
Definition: MELAParticle.cc:63