ATLAS Offline Software
FPTracker/src/Beamline.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "FPTracker/Beamline.h"
6 #include "FPTracker/STLHelpers.h"
7 #include "FPTracker/IParticle.h"
9 #include <memory>
10 #include <algorithm>
11 #include <cassert>
12 #include <string>
13 #include <sstream>
14 #include <cstddef>
15 //#include <iostream>
16 #include <stdexcept>
17 
18 namespace FPTracker{
19 
20  bool isEndMarker(const IBeamElement::ConstPtr_t& p){return p->isEndElement();}
21 
23  IBeamElement::Iter_t ei = find_if(container.begin(),
24  container.end(),
26  );
27 
28  if (ei != container.end()) ++ei;
29  else {
30  std::string s("Could not find the end of the beamline.");
31  throw std::runtime_error(s);
32  }
33  return ei;
34  }
36  public:
37  bool operator()( const IBeamElement::ConstPtr_t& be, double zpos ){
38  return std::fabs(zpos) > be->zabspos();
39  }
40  };
41 
42 
44 
46  { // exception aware: attemt to create as a temp, if no exception, do safe swap ....
48  IBeamElement::Iter_t tempIter = findBeamLineEnd(temp);
49  IBeamElement::Container_t temp2(temp.begin(), tempIter);
50 
51  m_elements.swap(temp2);
52  }
53 
55  {
56 
57  IBeamElement::Container_t temp = rhs.m_elements; // exception aware any exceptions occur here
58  m_elements.swap(temp); //nothrow op
59  }
60 
61  Beamline& Beamline::operator=(Beamline rhs) // make a temp copy then swap
62  {
63  this->swap(rhs);
64  return *this;
65  }
66 
68  {
69  m_elements.swap(other.m_elements);
70  }
71 
73  public:
75  }
77 
78  be->track(m_particle); // updates particle position
79  /*
80  std::string label = be->label();
81  if (label[0] == 'v' or label[0] == 'h')
82  {
83  std::cout<<m_particle<<" "<<++m_element<<" "<<be->side()<<" "<<be->frontFace()<<" "<<be->rearFace()<<" "<<label<<'\n';
84  }
85  */
86  return m_particle.isOutOfAperture();
87  }
88  private:
90 
91  };
92 
93 
95  IBeamElement::ConstIter_t nextElement = std::lower_bound(m_elements.begin(),
96  m_elements.end(),
97  particle.z(),
98  zPosNextElement() );
99 
100  // pass the particle to succesive beam elements until either it goes out of aperture, or it reaches the end plane.
101  //cppcheck-suppress ignoredReturnValue
102  (void)std::find_if(nextElement,
103  m_elements.end(),
105  );
106 
107  }
108 
109 
111  {
112  IBeamElement::Iter_t nextElement = std::lower_bound(m_elements.begin(),
113  m_elements.end(),
114  particle.z(),
115  zPosNextElement() );
116 
117  // pass the particle to succesive beam elements until either it goes out of aperture, or it reaches the end plane.
118 
120  for (iter = nextElement; iter!=m_elements.end(); ++iter) {
121  (*iter)->calibrate(particle);
122  if (particle.isOutOfAperture()) break;
123  }
124 
125 
126  if( iter != m_elements.end() )
127  {
128  std::ostringstream s;
129  s<<"Calibration particle did not reach end of beamline\n"<<particle<<'\n';
130  s<<"Particle stopped at beam element "<<**iter<<'\n';
131  throw std::runtime_error(s.str());
132  }
133 
134  }
135 
136 
137 
138 
139  std::string fixLabel(const std::string& label){
140  std::string s = label;
141  std::size_t tsize = 30 - label.size();
142  if (tsize>0){ s += std::string(tsize, ' ');}
143  return s;
144  }
145 
146  class Stringer{
147  public:
148  Stringer():m_ost(new std::stringstream){
149  (*m_ost)<<"\n\n--Beamline--\n";
150  }
152  (*m_ost)<<fixLabel(ib->label())<<" "<<ib->side()<<" "<<ib->frontFace()<<" "<<ib->rearFace()<<'\n';
153  }
154  std::string str() const {return m_ost->str();}
155  private:
156  std::shared_ptr< std::stringstream > m_ost;
157  };
158 
159  std::string Beamline::str() const{
160  return (std::for_each(m_elements.begin(), m_elements.end(), Stringer())).str();
161  }
162 
163  std::ostream& operator<<(std::ostream& os, const Beamline& bl){
164  os<<bl.str()<<std::endl;
165  return os;
166  }
167 }
168 
FPTracker::Stringer::operator()
void operator()(const IBeamElement::ConstPtr_t &ib)
Definition: FPTracker/src/Beamline.cxx:151
FPTracker::IBeamElement::Container_t
std::vector< Ptr_t > Container_t
Definition: FPTracker/FPTracker/IBeamElement.h:43
FPTracker::Beamline::calibrate
void calibrate(IParticle &)
Definition: FPTracker/src/Beamline.cxx:110
Trk::ParticleSwitcher::particle
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:76
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
FPTracker::operator<<
std::ostream & operator<<(std::ostream &os, const Beamline &bl)
Definition: FPTracker/src/Beamline.cxx:163
FPTracker::Beamline::operator=
Beamline & operator=(Beamline)
Definition: FPTracker/src/Beamline.cxx:61
PlotCalibFromCool.label
label
Definition: PlotCalibFromCool.py:78
CSV_InDetExporter.new
new
Definition: CSV_InDetExporter.py:145
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
FPTracker::Beamline::m_elements
IBeamElement::Container_t m_elements
Definition: FPTracker/FPTracker/Beamline.h:27
FPTracker::Stringer::Stringer
Stringer()
Definition: FPTracker/src/Beamline.cxx:148
PlotCalibFromCool.ib
ib
Definition: PlotCalibFromCool.py:419
FPTracker::IParticle::isOutOfAperture
virtual bool isOutOfAperture() const =0
FPTracker::ParticleTracker::ParticleTracker
ParticleTracker(IParticle &particle)
Definition: FPTracker/src/Beamline.cxx:74
FPTracker::Beamline::swap
void swap(Beamline &other)
Definition: FPTracker/src/Beamline.cxx:67
STLHelpers.h
FPTracker::zPosNextElement
Definition: FPTracker/src/Beamline.cxx:35
FPTracker::ParticleTracker::operator()
bool operator()(const IBeamElement::ConstPtr_t &be)
Definition: FPTracker/src/Beamline.cxx:76
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
FPTracker::Beamline
Definition: FPTracker/FPTracker/Beamline.h:15
FPTracker::findBeamLineEnd
IBeamElement::Iter_t findBeamLineEnd(IBeamElement::Container_t &container)
Definition: FPTracker/src/Beamline.cxx:22
IParticle.h
FPTracker::Beamline::Beamline
Beamline()
Definition: FPTracker/src/Beamline.cxx:43
FPTracker::IBeamElement::Iter_t
Container_t::iterator Iter_t
Definition: FPTracker/FPTracker/IBeamElement.h:44
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
FPTracker::Beamline::str
std::string str() const
Definition: FPTracker/src/Beamline.cxx:159
FPTracker::IBeamElement::ConstPtr_t
std::shared_ptr< const IBeamElement > ConstPtr_t
Definition: FPTracker/FPTracker/IBeamElement.h:40
FPTracker::Stringer::m_ost
std::shared_ptr< std::stringstream > m_ost
Definition: FPTracker/src/Beamline.cxx:156
FPTracker::Beamline::track
void track(IParticle &) const
Definition: FPTracker/src/Beamline.cxx:94
FPTracker::fixLabel
std::string fixLabel(const std::string &label)
Definition: FPTracker/src/Beamline.cxx:139
FPTracker::isEndMarker
bool isEndMarker(const IBeamElement::ConstPtr_t &p)
Definition: FPTracker/src/Beamline.cxx:20
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
FPTracker::zPosNextElement::operator()
bool operator()(const IBeamElement::ConstPtr_t &be, double zpos)
Definition: FPTracker/src/Beamline.cxx:37
FPTracker::Stringer::str
std::string str() const
Definition: FPTracker/src/Beamline.cxx:154
FPTracker::IBeamElement::ListIter_t
List_t::iterator ListIter_t
Definition: FPTracker/FPTracker/IBeamElement.h:48
Beamline.h
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
IBeamElement.h
FPTracker::ParticleTracker::m_particle
IParticle & m_particle
Definition: FPTracker/src/Beamline.cxx:89
FPTracker::Stringer
Definition: FPTracker/src/Beamline.cxx:146
FPTracker::ParticleTracker
Definition: FPTracker/src/Beamline.cxx:72
FPTracker
Definition: FPTracker/FPTracker/Beamline.h:12
FPTracker::IBeamElement::ConstIter_t
Container_t::const_iterator ConstIter_t
Definition: FPTracker/FPTracker/IBeamElement.h:45
atlasStyleMacro.tsize
float tsize
Definition: atlasStyleMacro.py:37
FPTracker::IParticle
Definition: ForwardDetectors/FPTracker/FPTracker/IParticle.h:17
PlotCalibFromCool.be
be
Definition: PlotCalibFromCool.py:398