ATLAS Offline Software
Loading...
Searching...
No Matches
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
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
18namespace 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 ....
47 IBeamElement::Container_t temp(begin, end);
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:
74 ParticleTracker(IParticle& particle):m_particle(particle) {
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
94 void Beamline::track(IParticle& particle) const {
95 IBeamElement::ConstIter_t nextElement = std::lower_bound(m_elements.begin(),
96 m_elements.end(),
97 particle.z(),
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(),
104 ParticleTracker(particle)
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:
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
IBeamElement::Container_t m_elements
void swap(Beamline &other)
Beamline & operator=(Beamline)
void track(IParticle &) const
std::shared_ptr< const IBeamElement > ConstPtr_t
Container_t::const_iterator ConstIter_t
bool operator()(const IBeamElement::ConstPtr_t &be)
void operator()(const IBeamElement::ConstPtr_t &ib)
std::shared_ptr< std::stringstream > m_ost
bool operator()(const IBeamElement::ConstPtr_t &be, double zpos)
STL class.
std::string label(const std::string &format, int i)
Definition label.h:19
IBeamElement::Iter_t findBeamLineEnd(IBeamElement::Container_t &container)
bool isEndMarker(const IBeamElement::ConstPtr_t &p)
std::ostream & operator<<(std::ostream &os, const Beamline &bl)
std::string fixLabel(const std::string &label)
STL namespace.