ATLAS Offline Software
BeamHaloParticle.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
8 #include "HepPDT/ParticleDataTable.hh"
9 #include <iostream>
10 #include <cmath>
11 
12 //---------------------------------------------------------------------
13 
15  m_fourVector(),
16  m_positionAtScoringPlane(),
17  m_weight(0.),
18  m_positionAtPrimary() {
19 }
20 
21 //---------------------------------------------------------------------
22 
24  HepMC::FourVector fourVector,
25  HepMC::FourVector positionAtScoringPlane,
26  double weight): m_pdgId(pdgId),
27  m_fourVector(fourVector),
28  m_positionAtScoringPlane(positionAtScoringPlane),
29  m_weight(weight) {
30 }
31 
32 //---------------------------------------------------------------------
33 
35  HepMC::FourVector fourVector,
36  HepMC::FourVector positionAtScoringPlane,
37  double weight,
38  HepMC::FourVector positionAtPrimary): m_pdgId(pdgId),
39  m_fourVector(fourVector),
40  m_positionAtScoringPlane(positionAtScoringPlane),
41  m_weight(weight),
42  m_positionAtPrimary(positionAtPrimary) {
43 }
44 
45 //---------------------------------------------------------------------
46 
47 //BeamHaloParticle::operator(const BeamHaloParticle &rhs) {
48 //}
49 
50 //---------------------------------------------------------------------
51 
52 int BeamHaloParticle::fill(const HepPDT::ParticleDataTable *particleDataTable,
53  MarsParticle *marsParticle) {
54  double p_sq, mod_p, pz, mass, energy;
55 
56  m_pdgId = marsParticle->pdgId();
57  if(!m_pdgId) {
58  std::cerr << "There is no PDG code for MARS id " << marsParticle->particleId() << std::endl;
59  return 1;
60  }
61 
62  // Read mass from pdg table
63  const HepPDT::ParticleData* particleData = particleDataTable->particle(HepPDT::ParticleID(std::abs(m_pdgId)));
64  mass = 0;
65  if(particleData) {
66  mass = particleData->mass().value();
67  }
68  else {
69  std::cerr << "PDG code " << m_pdgId << " is not in the particle data table." << std::endl;
70  return 1;
71  }
72 
73  // Mars uses GeV, convert to MeV then calculate |p|
74  // from relativistic kinetic energy (using c=1):
75  // KE = m - m_0 m^2 = p^2 + m_0^2
76  p_sq = std::pow(marsParticle->kineticEnergy() * 1000.0 + mass, 2) - std::pow(mass,2);
77  mod_p = std::sqrt(p_sq);
78 
79  // ATLAS: the x-axis points towards the centre of the LHC ring, the
80  // y-axis points upwards, and the z-axis points towards the airport
81  // and the Saleve, i.e. towards the A-side.
82  //
83  // MARS simulation: the x-axis points into the ground, the y-axis
84  // points out of the ring, and the z-axis points towards the Jura
85  // i.e. towards the C-side.
86 
87  // Calculate px and py from the directional cosines
88  m_fourVector.setX(-1.0 * marsParticle->directionalCosines().y() * mod_p);
89  m_fourVector.setY(-1.0 * marsParticle->directionalCosines().x() * mod_p);
90 
91  // Calculate pz from sqrt(p^2 - p_T^2)
92  pz = std::sqrt(p_sq - m_fourVector.perp2());
93  m_fourVector.setZ(pz); // This is always +ve. Corrected during conversion to HepParticle
94 
95  // Calculate the energy
96  energy=std::sqrt(std::pow(mass,2)+std::pow(mod_p,2));
97  m_fourVector.setE(energy);
98 
99  // Convert the position from cm to mm.
100  m_positionAtScoringPlane.setX(-1.0 * marsParticle->positionAtScoringPlane().y() * 10.0);
101  m_positionAtScoringPlane.setY(-1.0 * marsParticle->positionAtScoringPlane().x() * 10.0);
102  m_positionAtScoringPlane.setZ(0.0); // The information is not provided in the input file.
103  m_positionAtScoringPlane.setT(0.0); // Assume that this is t = 0
104 
105  // replace this with marsParticle->effectiveWeight();
106  m_weight = marsParticle->weight();
107 
108  return 0;
109 }
110 
111 //-------------------------------------------------------------------------------------------------
112 
113 int BeamHaloParticle::fill(const HepPDT::ParticleDataTable *particleDataTable,
114  FlukaParticle *flukaParticle) {
115  double p_sq, mod_p, pz, mass, energy;
116 
117  // Needed for debugging
118  //flukaParticle->print();
119 
120  m_pdgId = flukaParticle->pdgId();
121  if(!m_pdgId) {
122  std::cerr << "There is no PDG code for FLUKA id " << flukaParticle->flukaId() << std::endl;
123  return 1;
124  }
125 
126  // Read mass from pdg table
127  const HepPDT::ParticleData* particleData = particleDataTable->particle(HepPDT::ParticleID(std::abs(m_pdgId)));
128  mass = 0;
129  if(particleData) {
130  mass = particleData->mass().value();
131  }
132  else {
133  std::cerr << "PDG code " << m_pdgId << " is not in the particle data table." << std::endl;
134  return 1;
135  }
136 
137  // FLUKA uses GeV, convert to MeV then calculate |p|
138  // from relativistic kinetic energy (using c=1):
139  // KE = m - m_0 m^2 = p^2 + m_0^2
140  p_sq = std::pow(flukaParticle->kineticEnergy() * 1000.0 + mass, 2) - std::pow(mass,2);
141  mod_p = std::sqrt(p_sq);
142 
143  // Calculate px, py, pz from the directional cosines
144  m_fourVector.setX(flukaParticle->directionalCosines().x() * mod_p);
145  m_fourVector.setY(flukaParticle->directionalCosines().y() * mod_p);
146 
147  // If the z component of the directional cosine has not been set recalculate it.
148  if(std::abs(flukaParticle->directionalCosines().z()) < 0.0001) {
149  // Calculate pz from sqrt(p^2 - p_T^2)
150  pz = std::sqrt(p_sq - m_fourVector.perp2());
151  m_fourVector.setZ(pz); // This is always +ve. Corrected during conversion to HepParticle
152  }
153  else {
154  m_fourVector.setZ(flukaParticle->directionalCosines().z() * mod_p);
155  }
156 
157  // Calculate the energy
158  energy=std::sqrt(std::pow(mass,2)+std::pow(mod_p,2));
159  m_fourVector.setE(energy);
160 
161  // Convert the position from cm to mm.
162  m_positionAtScoringPlane.setX(flukaParticle->positionAtScoringPlane().x()*10.0); // Convert from cm to mm
163  m_positionAtScoringPlane.setY(flukaParticle->positionAtScoringPlane().y()*10.0); // Convert from cm to mm
164  m_positionAtScoringPlane.setZ(flukaParticle->positionAtScoringPlane().z()*10.0); // Convert from cm to mm
165  m_positionAtScoringPlane.setT(flukaParticle->positionAtScoringPlane().t());
166 
167  // Get the weight
168  m_weight = flukaParticle->weight();
169 
170  // Convert the position from cm to mm.
171  m_positionAtPrimary.setX(flukaParticle->positionAtPrimary().x()*10.0); // Convert from cm to mm
172  m_positionAtPrimary.setY(flukaParticle->positionAtPrimary().y()*10.0); // Convert from cm to mm
173  m_positionAtPrimary.setZ(flukaParticle->positionAtPrimary().z()*10.0); // Convert from cm to mm
174  m_positionAtPrimary.setT(flukaParticle->positionAtPrimary().t());
175 
176  // ATLAS: the x-axis points towards the centre of the LHC ring, the
177  // y-axis points upwards, and the z-axis points towards the airport
178  // and the Saleve, i.e. towards the A-side.
179  //
180  // R. Bruce fluka simulation: the x-axis points away from the
181  // center of the LHC ring, the y-axis points upwards, and the z-axis
182  // points along the beam line, but is positive for beam 1 and beam 2
183  // input files.
184  if(flukaParticle->type() == 0) {
185  m_fourVector.setX(-m_fourVector.x());
188  }
189 
190  return 0;
191 }
192 
193 //-------------------------------------------------------------------------------------------------
194 
196  std::cout.fill(' ');
197  std::cout.precision(6);
198  std::cout.width(11); std::cout << m_pdgId << " ";
199  std::cout.width(13); std::cout.precision(6); std::cout << std::scientific << m_fourVector.px() << " ";
200  std::cout.width(13); std::cout.precision(6); std::cout << std::scientific << m_fourVector.py() << " ";
201  std::cout.width(13); std::cout.precision(6); std::cout << std::scientific << m_fourVector.pz() << " ";
202  std::cout.width(13); std::cout.precision(6); std::cout << std::scientific << m_fourVector.e() << " ";
203  std::cout.width(13); std::cout.precision(6); std::cout << std::scientific << m_positionAtScoringPlane.x() << " ";
204  std::cout.width(13); std::cout.precision(6); std::cout << std::scientific << m_positionAtScoringPlane.y() << " ";
205  std::cout.width(13); std::cout.precision(6); std::cout << std::scientific << m_positionAtScoringPlane.z() << " ";
206  std::cout.width(13); std::cout.precision(6); std::cout << std::scientific << m_positionAtScoringPlane.t() << " ";
207  std::cout.width(13); std::cout.precision(6); std::cout << std::scientific << m_weight << std::endl;
208  std::cout.width(13); std::cout.precision(6); std::cout << std::scientific << m_positionAtPrimary.x() << " ";
209  std::cout.width(13); std::cout.precision(6); std::cout << std::scientific << m_positionAtPrimary.y() << " ";
210  std::cout.width(13); std::cout.precision(6); std::cout << std::scientific << m_positionAtPrimary.z() << " ";
211  std::cout.width(13); std::cout.precision(6); std::cout << std::scientific << m_positionAtPrimary.t() << std::endl;
212 }
213 
214 //-------------------------------------------------------------------------------------------------
BeamHaloParticle::m_fourVector
HepMC::FourVector m_fourVector
A four vector describing this particle at the scoring plane.
Definition: BeamHaloParticle.h:82
MarsParticle
A class to describe a MARS particle read from an input ASCII file.
Definition: MarsParticle.h:55
MarsParticle::positionAtScoringPlane
HepMC::FourVector positionAtScoringPlane() const
A function to the position of this particle with respect to the scoring plane.
Definition: MarsParticle.h:84
BeamHaloParticle::m_positionAtScoringPlane
HepMC::FourVector m_positionAtScoringPlane
Position of the particle at the scoring plane (x,y,z,t).
Definition: BeamHaloParticle.h:85
conifer::pow
constexpr int pow(int x)
Definition: conifer.h:20
FlukaParticle::flukaId
int flukaId(void) const
A function to return the FLUKA particle Id of this particle.
Definition: FlukaParticle.h:42
FlukaParticle::pdgId
int pdgId()
A function to return the PDG id of this particle.
Definition: FlukaParticle.cxx:128
FlukaParticle::positionAtPrimary
HepMC::FourVector positionAtPrimary(void) const
A function to return the position of the primary interaction.
Definition: FlukaParticle.h:67
MarsParticle::weight
double weight() const
A function to return the weight associated with this particle in the input ASCII file.
Definition: MarsParticle.h:80
MarsParticle::pdgId
int pdgId()
A function to return the PDG id for this particle.
Definition: MarsParticle.cxx:115
PowhegPy8EG_H2a.pdgId
dictionary pdgId
Definition: PowhegPy8EG_H2a.py:128
dqt_zlumi_pandas.mass
mass
Definition: dqt_zlumi_pandas.py:170
BeamHaloParticle::m_pdgId
long m_pdgId
The PDG Id of the particle.
Definition: BeamHaloParticle.h:79
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:200
FlukaParticle.h
BeamHaloParticle.h
BeamHaloParticle::print
void print()
A function to print the contents of this particle.
Definition: BeamHaloParticle.cxx:195
BeamHaloParticle::fill
int fill(const HepPDT::ParticleDataTable *particleDataTable, MarsParticle *marsParticle)
A function to fill the data members from an input MarsParticle object.
Definition: BeamHaloParticle.cxx:52
MarsParticle::kineticEnergy
double kineticEnergy() const
A function to return the relativistic kinetic energy of this particle.
Definition: MarsParticle.h:76
ParticleGun_FastCalo_ChargeFlip_Config.energy
energy
Definition: ParticleGun_FastCalo_ChargeFlip_Config.py:78
FlukaParticle::directionalCosines
HepMC::FourVector directionalCosines(void) const
A function to return the directional cosines of this particle.
Definition: FlukaParticle.h:58
Amg::pz
@ pz
Definition: GeoPrimitives.h:40
MarsParticle::particleId
int particleId() const
A function to return the particle identify of this particle.
Definition: MarsParticle.h:72
jobOptions.ParticleID
ParticleID
Definition: jobOptions.decayer.py:85
MarsParticle::directionalCosines
HepMC::FourVector directionalCosines() const
A function to return the directional cosines of this particle.
Definition: MarsParticle.h:88
MarsParticle.h
BeamHaloParticle::m_positionAtPrimary
HepMC::FourVector m_positionAtPrimary
Position of the particle at the primary interaction point (x,y,z,y).
Definition: BeamHaloParticle.h:91
FlukaParticle::weight
double weight(void) const
A function to return the particle or event weight.
Definition: FlukaParticle.h:61
FlukaParticle::positionAtScoringPlane
HepMC::FourVector positionAtScoringPlane(void) const
A function to return the fourvector position with respect to the scoring plane of this particle.
Definition: FlukaParticle.h:54
FlukaParticle
A class to describe a FLUKA particle read from an input ASCII file.
Definition: FlukaParticle.h:19
FlukaParticle::type
int type(void) const
A function to return the type of this FlukaParticle.
Definition: FlukaParticle.h:36
FlukaParticle::kineticEnergy
double kineticEnergy(void) const
A function to return the relativistic kinetic energy of this particle.
Definition: FlukaParticle.h:50
BeamHaloParticle::m_weight
double m_weight
The resultant particle weight after normalisation and rescaling.
Definition: BeamHaloParticle.h:88
BeamHaloParticle::BeamHaloParticle
BeamHaloParticle()
Definition: BeamHaloParticle.cxx:14