ATLAS Offline Software
Loading...
Searching...
No Matches
BeamHaloGeneratorSettings.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 <iostream>
9#include <cmath>
10
11const std::string BeamHaloGeneratorSettings::m_limitNames[ENUM_LIMITS_SIZE] = {"pxLimits",
12 "pyLimits",
13 "pzLimits",
14 "energyLimits",
15 "xLimits",
16 "yLimits",
17 "zLimits",
18 "ptLimits",
19 "phiLimits",
20 "etaLimits",
21 "rLimits",
22 "weightLimits"};
23
24//---------------------------------------------------------------------
25
26BeamHaloGeneratorSettings::BeamHaloGeneratorSettings(const std::vector<std::string>& settings):
27 m_generatorSettings(settings),
29 m_limits(),
32 m_settingsParsed(false) {
33
34 // Initialise the lower and upper limits as zero, and disabled.
35 for(int i=0;i<ENUM_LIMITS_SIZE;i++) {
36 m_limits.push_back(std::make_pair(0.,0.));
37 m_limitsEnabled.push_back(std::make_pair(false,false));
38 }
39}
40
41//---------------------------------------------------------------------
42
44 std::vector<std::string> strVector;
45 std::vector<std::string>::iterator row_itr;
46 std::vector<std::string>::iterator row_itr_end;
47 std::vector<std::string>::iterator col_itr;
48 std::vector<std::string>::iterator col_itr_end;
49// double upperLimit, lowerLimit;
50
51 // Loop over all settings.
52 row_itr = m_generatorSettings.begin();
53 row_itr_end = m_generatorSettings.end();
54 for(;row_itr!=row_itr_end;++row_itr) {
55 strVector.clear();
56 strVector = AsciiInput::strToStrVec(*row_itr);
57
58 if(strVector.size() == 0) continue;
59 if(strVector.size() == 1) {
60 std::cerr << "A generator setting must be followed by a value" << std::endl;
61 continue;
62 }
63
64// lowerLimit = -1.; upperLimit = -1.1; // Disable limits by default;
65
66 col_itr = strVector.begin();
67 col_itr_end = strVector.end();
68
69 if((*col_itr) == "allowedPdgId") {
70 ++col_itr;
71 for(;col_itr!=col_itr_end;++col_itr) {
72 m_allowedPdgIds.push_back(AsciiInput::strToLong(*col_itr));
73 }
74 }
75 else if((*col_itr) == "shape") {
76 ++col_itr;
77 if((*col_itr) == "cylinder") {
79 }
80 else {
81 std::cerr << "Warning: unknown shape requirement \"" << (*col_itr) << "\" ignored." << std::endl;
82 }
83 }
84 else {
85 parseLimitSetting(&strVector);
86 }
87 }
88
90
91 m_settingsParsed = true;
92
93 return 0;
94}
95
96//---------------------------------------------------------------------
97
98int BeamHaloGeneratorSettings::parseLimitSetting(std::vector<std::string> *commandVector) {
99 std::vector<std::string>::iterator itr = commandVector->begin();
100 std::vector<std::string>::iterator itr_end = commandVector->end();
101
102 int i = 0;
103 while(i<ENUM_LIMITS_SIZE) {
104 if((*itr) == m_limitNames[i]) break;
105 i++;
106 }
107
108 if(i == ENUM_LIMITS_SIZE) {
109 std::cerr << "Error: " << (*itr) << " is an un-known generator setting." << std::endl;
110 return 1;
111 }
112
113 // Look for the lower limit
114 ++itr;
115 if(itr==itr_end) {
116 std::cerr << "Warning: " << m_limitNames[i] << " was not followed by a lower or upper limit." << std::endl;
117 return 0;
118 }
119
120 // Enable the lower limit.
121 m_limits[i] = std::make_pair(AsciiInput::strToDouble(*itr),0.);
122 m_limitsEnabled[i] = std::make_pair(true,false);
123
124 // Look for the upper limit
125 ++itr;
126 if(itr==itr_end) { // no upper limit.
127 return 0;
128 }
129
130 // Enable the upper limit.
131 m_limits[i].second = AsciiInput::strToDouble(*itr);
132 m_limitsEnabled[i].second = true;
133
134 return 0;
135}
136
137//---------------------------------------------------------------------
138
140 if(!m_settingsParsed) {
141 if(parseSettings() != 0) return false;
142 }
143
144 // Search the allowed PDG id list if it has been defined.
145 if(m_allowedPdgIds.size() != 0) {
146 std::vector<long>::iterator itr = m_allowedPdgIds.begin();
147 std::vector<long>::iterator itr_end = m_allowedPdgIds.end();
148 while(itr!=itr_end) {
149 if(beamHaloParticle->pdgId() == (*itr)) break;
150 ++itr;
151 }
152 if(itr==itr_end) {
153 return false;
154 }
155 }
156
157 // First implement the cuts which are not related to the particle
158 // trajectory.
159 if(!checkSetting(W_LIMIT, std::abs(beamHaloParticle->weight()))) return false;
160 if(!checkSetting(PX_LIMIT, std::abs(beamHaloParticle->fourVector().px()))) return false;
161 if(!checkSetting(PY_LIMIT, std::abs(beamHaloParticle->fourVector().py()))) return false;
162 if(!checkSetting(PZ_LIMIT, std::abs(beamHaloParticle->fourVector().pz()))) return false;
163 if(!checkSetting(E_LIMIT, std::abs(beamHaloParticle->fourVector().e()))) return false;
164 if(!checkSetting(PT_LIMIT, beamHaloParticle->fourVector().perp())) return false;
165 if(!checkSetting(ETA_LIMIT, std::abs(beamHaloParticle->fourVector().pseudoRapidity()))) return false;
166 if(!checkSetting(PHI_LIMIT, std::abs(beamHaloParticle->fourVector().phi()))) return false;
167
168
169 // Require the selection at the scoring plane.
170 if(m_shapeRequirement == NONE) {
171 if(!checkSetting(X_LIMIT, std::abs(beamHaloParticle->positionAtScoringPlane().x()))) return false;
172 if(!checkSetting(Y_LIMIT, std::abs(beamHaloParticle->positionAtScoringPlane().y()))) return false;
173 if(!checkSetting(R_LIMIT, beamHaloParticle->positionAtScoringPlane().perp())) return false;
174 }
175 else if(m_shapeRequirement == CYLINDER) {
176 if(!checkCylinder(beamHaloParticle)) return false;
177 }
178 else {
179 std::cerr << "Warning: m_shapeRequirement = " << m_shapeRequirement << " is an unknown requirement." << std::endl;
180 }
181
182 return true;
183}
184
185//---------------------------------------------------------------------
186
188 double rmin = m_limits[R_LIMIT].first;
189 double rmax = m_limits[R_LIMIT].second;
190 double zmin = m_limits[Z_LIMIT].first;
191 double zmax = m_limits[Z_LIMIT].second;
192
193 // Check if the particle radius at the scoring place is outside the
194 // outer radius of the cylinder and the particle trajectory is away
195 // from the cylinder reject the particle.
196 if(beamHaloParticle->positionAtScoringPlane().perp() > rmax &&
197 beamHaloParticle->fourVector().theta() > 0.) return false;
198
199 // If the particle has no pT then check if it is inside the radius
200 // of the cylinder.
201 if(beamHaloParticle->fourVector().perp() == 0.) {
202 if(beamHaloParticle->positionAtScoringPlane().perp() < rmin ||
203 beamHaloParticle->positionAtScoringPlane().perp() > rmin) {
204 return false;
205 }
206 else {
207 return true;
208 }
209 }
210
211 // r = sqrt(x^2 + y^2)
212 //
213 // tan(theta) = pT/pz
214 // tan(theta) = r/z
215 //
216 // z = (r*pz)/pT
217
218 // The z position where the particle crosses the inner radius.
219 double innerZ = (rmin*beamHaloParticle->fourVector().z())/beamHaloParticle->fourVector().perp();
220
221 // The z position where the particle crosses the outer radius.
222 double outerZ = (rmax*beamHaloParticle->fourVector().z())/beamHaloParticle->fourVector().perp();
223
224 // If the trajectory of the particle crosses either the inner or
225 // outer surface within the length of the cylinder keep it.
226 if((innerZ >= zmin && innerZ <= zmax) ||
227 (outerZ >= zmin && outerZ <= zmax)) {
228 return true;
229 }
230
231 return false;
232}
233
234//---------------------------------------------------------------------
235
237 if(index >= ENUM_LIMITS_SIZE) {
238 std::cerr << "Error: the index " << index << " is out of range." << std::endl;
239 return false;
240 }
241
242 if(m_limitsEnabled[index].first && value < m_limits[index].first) return false;
243 if(m_limitsEnabled[index].second && value >= m_limits[index].second) return false;
244
245 return true;
246}
247
248//---------------------------------------------------------------------
249
251 std::cout << "============== BeamHaloGeneratorSettings ==============" << std::endl;
252 std::cout << " allowedPdfIds: ";
253 if(m_allowedPdgIds.size() != 0) {
254 std::vector<long>::iterator pdgId_itr = m_allowedPdgIds.begin();
255 std::vector<long>::iterator pdgId_itr_end = m_allowedPdgIds.end();
256 for(;pdgId_itr != pdgId_itr_end; ++pdgId_itr) {
257 std::cout << (*pdgId_itr) << " ";
258 }
259 std::cout << std::endl;
260 }
261 else {
262 std::cout << "All PDG IDs are allowed." << std::endl;
263 }
264
265 std::cout << " shapeRequirement: ";
266 switch (m_shapeRequirement) {
267 case(NONE) : std::cout << "NONE"; break;
268 case(CYLINDER) : std::cout << "CYLINDER"; break;
269 default : std::cout << "UNKNOWN"; break;
270 }
271 std::cout << std::endl;
272
273 for(int i=0;i<ENUM_LIMITS_SIZE;i++) {
274 std::cout << " " << m_limitNames[i] << ": {";
275 if(!m_limitsEnabled[i].first) std::cout << "disabled, ";
276 else std::cout << m_limits[i].first << ", ";
277 if(!m_limitsEnabled[i].second) std::cout << "disabled}";
278 else std::cout << m_limits[i].second << "}";
279 std::cout << std::endl;
280 }
281 std::cout << "=======================================================" << std::endl;
282}
283
#define z
static long strToLong(const std::string &inputString)
A helper function to convert a string to a long value.
static std::vector< std::string > strToStrVec(const std::string &inputString)
A helper function to convert a string into a string vector, by using any number of space or tab chara...
static double strToDouble(const std::string &inputString)
A helper function to convert a string to a double value.
bool checkSetting(int index, double value)
A function to check if a particle is within a range.
void printSettings(void)
Print a summary of the current settings.
static const std::string m_limitNames[ENUM_LIMITS_SIZE]
The name of the limits.
int parseSettings(void)
A function to parse the settings using the vector of strings given to the constructor of this class.
bool checkParticle(BeamHaloParticle *beamHaloParticle)
Check if the supplied beam halo particle passes the generator settings.
std::vector< long > m_allowedPdgIds
An allowed set of PDG ids where any empty vector implies all PDG ids are allowed.
int m_shapeRequirement
A variable to store the volume shape requirement.
bool checkCylinder(BeamHaloParticle *beamHaloParticle)
A function to check if a particle is within a cylinder.
std::vector< std::pair< float, float > > m_limits
Minimum and maximum limits.
std::vector< std::pair< bool, bool > > m_limitsEnabled
A vector of flags to signal if a limit should be used or not.
bool m_settingsParsed
A flag to check if the settings have been parsed or not.
std::vector< std::string > m_generatorSettings
A vector of strings to configure the generator settings.
BeamHaloGeneratorSettings(const std::vector< std::string > &settings)
Construct a class with a vector of string settings to filter particles.
int parseLimitSetting(std::vector< std::string > *commandVector)
A function to read the limit settings from the supplied vector of strings.
A class to describe a generic beam halo particle.
long pdgId() const
A function to return the PDG id of this particle.
HepMC::FourVector fourVector() const
A function to return the momentum fourvector of this particle.
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.
Definition index.py:1