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