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
8#include "HepPDT/ParticleDataTable.hh"
9#include <iostream>
10#include <cmath>
11
12//---------------------------------------------------------------------
13
20
21//---------------------------------------------------------------------
22
31
32//---------------------------------------------------------------------
33
44
45//---------------------------------------------------------------------
46
47//BeamHaloParticle::operator(const BeamHaloParticle &rhs) {
48//}
49
50//---------------------------------------------------------------------
51
52int 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
113int 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//-------------------------------------------------------------------------------------------------
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.
int fill(const HepPDT::ParticleDataTable *particleDataTable, MarsParticle *marsParticle)
A function to fill the data members from an input MarsParticle object.
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.
double weight() const
A function to return the weight of this particle within the input beam background simulation file.
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.
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.