ATLAS Offline Software
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 
11 const 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 
26 BeamHaloGeneratorSettings::BeamHaloGeneratorSettings(const std::vector<std::string>& settings):
27  m_generatorSettings(settings),
28  m_allowedPdgIds(),
29  m_limits(),
30  m_limitsEnabled(),
31  m_shapeRequirement(0),
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;
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 
89  printSettings();
90 
91  m_settingsParsed = true;
92 
93  return 0;
94 }
95 
96 //---------------------------------------------------------------------
97 
98 int 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) {
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 
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
python.SystemOfUnits.second
int second
Definition: SystemOfUnits.py:120
AsciiInput.h
BeamHaloGeneratorSettings::ENUM_LIMITS_SIZE
@ ENUM_LIMITS_SIZE
Definition: BeamHaloGeneratorSettings.h:64
BeamHaloGeneratorSettings::PY_LIMIT
@ PY_LIMIT
Definition: BeamHaloGeneratorSettings.h:53
BeamHaloParticle
A class to describe a generic beam halo particle.
Definition: BeamHaloParticle.h:22
BeamHaloGeneratorSettings::CYLINDER
@ CYLINDER
Definition: BeamHaloGeneratorSettings.h:49
BeamHaloGeneratorSettings::m_settingsParsed
bool m_settingsParsed
A flag to check if the settings have been parsed or not.
Definition: BeamHaloGeneratorSettings.h:96
BeamHaloGeneratorSettings::E_LIMIT
@ E_LIMIT
Definition: BeamHaloGeneratorSettings.h:55
BeamHaloGeneratorSettings::parseSettings
int parseSettings(void)
A function to parse the settings using the vector of strings given to the constructor of this class.
Definition: BeamHaloGeneratorSettings.cxx:43
PixelAthClusterMonAlgCfg.zmin
zmin
Definition: PixelAthClusterMonAlgCfg.py:169
index
Definition: index.py:1
athena.value
value
Definition: athena.py:124
BeamHaloGeneratorSettings::m_limitNames
static const std::string m_limitNames[ENUM_LIMITS_SIZE]
The name of the limits.
Definition: BeamHaloGeneratorSettings.h:77
BeamHaloGeneratorSettings::m_limitsEnabled
std::vector< std::pair< bool, bool > > m_limitsEnabled
A vector of flags to signal if a limit should be used or not.
Definition: BeamHaloGeneratorSettings.h:90
BeamHaloGeneratorSettings::checkSetting
bool checkSetting(int index, double value)
A function to check if a particle is within a range.
Definition: BeamHaloGeneratorSettings.cxx:236
BeamHaloParticle.h
BeamHaloGeneratorSettings::printSettings
void printSettings(void)
Print a summary of the current settings.
Definition: BeamHaloGeneratorSettings.cxx:250
BeamHaloGeneratorSettings::m_limits
std::vector< std::pair< float, float > > m_limits
Minimum and maximum limits.
Definition: BeamHaloGeneratorSettings.h:87
BeamHaloGeneratorSettings.h
BeamHaloGeneratorSettings::NONE
@ NONE
Definition: BeamHaloGeneratorSettings.h:48
BeamHaloGeneratorSettings::R_LIMIT
@ R_LIMIT
Definition: BeamHaloGeneratorSettings.h:62
lumiFormat.i
int i
Definition: lumiFormat.py:85
BeamHaloGeneratorSettings::Y_LIMIT
@ Y_LIMIT
Definition: BeamHaloGeneratorSettings.h:57
BeamHaloParticle::pdgId
long pdgId() const
A function to return the PDG id of this particle.
Definition: BeamHaloParticle.h:58
BeamHaloGeneratorSettings::W_LIMIT
@ W_LIMIT
Definition: BeamHaloGeneratorSettings.h:63
AsciiInput::strToLong
static long strToLong(const std::string &inputString)
A helper function to convert a string to a long value.
Definition: AsciiInput.cxx:113
BeamHaloGeneratorSettings::m_generatorSettings
std::vector< std::string > m_generatorSettings
A vector of strings to configure the generator settings.
Definition: BeamHaloGeneratorSettings.h:80
PixelAthClusterMonAlgCfg.zmax
zmax
Definition: PixelAthClusterMonAlgCfg.py:169
BeamHaloGeneratorSettings::parseLimitSetting
int parseLimitSetting(std::vector< std::string > *commandVector)
A function to read the limit settings from the supplied vector of strings.
Definition: BeamHaloGeneratorSettings.cxx:98
BeamHaloGeneratorSettings::m_allowedPdgIds
std::vector< long > m_allowedPdgIds
An allowed set of PDG ids where any empty vector implies all PDG ids are allowed.
Definition: BeamHaloGeneratorSettings.h:84
BeamHaloGeneratorSettings::PHI_LIMIT
@ PHI_LIMIT
Definition: BeamHaloGeneratorSettings.h:60
BeamHaloParticle::fourVector
HepMC::FourVector fourVector() const
A function to return the momentum fourvector of this particle.
Definition: BeamHaloParticle.h:62
BeamHaloGeneratorSettings::checkCylinder
bool checkCylinder(BeamHaloParticle *beamHaloParticle)
A function to check if a particle is within a cylinder.
Definition: BeamHaloGeneratorSettings.cxx:187
BeamHaloGeneratorSettings::checkParticle
bool checkParticle(BeamHaloParticle *beamHaloParticle)
Check if the supplied beam halo particle passes the generator settings.
Definition: BeamHaloGeneratorSettings.cxx:139
BeamHaloGeneratorSettings::m_shapeRequirement
int m_shapeRequirement
A variable to store the volume shape requirement.
Definition: BeamHaloGeneratorSettings.h:93
BeamHaloGeneratorSettings::Z_LIMIT
@ Z_LIMIT
Definition: BeamHaloGeneratorSettings.h:58
BeamHaloGeneratorSettings::BeamHaloGeneratorSettings
BeamHaloGeneratorSettings(const std::vector< std::string > &settings)
Construct a class with a vector of string settings to filter particles.
Definition: BeamHaloGeneratorSettings.cxx:26
BeamHaloParticle::weight
double weight() const
A function to return the weight of this particle within the input beam background simulation file.
Definition: BeamHaloParticle.h:70
DeMoScan.first
bool first
Definition: DeMoScan.py:536
BeamHaloGeneratorSettings::ETA_LIMIT
@ ETA_LIMIT
Definition: BeamHaloGeneratorSettings.h:61
AsciiInput::strToStrVec
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...
Definition: AsciiInput.cxx:67
BeamHaloParticle::positionAtScoringPlane
HepMC::FourVector positionAtScoringPlane() const
A function to return the position fourvector of this particle with respect to the scoring plane.
Definition: BeamHaloParticle.h:66
BeamHaloGeneratorSettings::PZ_LIMIT
@ PZ_LIMIT
Definition: BeamHaloGeneratorSettings.h:54
python.CaloScaleNoiseConfig.default
default
Definition: CaloScaleNoiseConfig.py:79
BeamHaloGeneratorSettings::PT_LIMIT
@ PT_LIMIT
Definition: BeamHaloGeneratorSettings.h:59
AsciiInput::strToDouble
static double strToDouble(const std::string &inputString)
A helper function to convert a string to a double value.
Definition: AsciiInput.cxx:122
BeamHaloGeneratorSettings::X_LIMIT
@ X_LIMIT
Definition: BeamHaloGeneratorSettings.h:56
BeamHaloGeneratorSettings::PX_LIMIT
@ PX_LIMIT
Definition: BeamHaloGeneratorSettings.h:52