ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
ForwardDetectors
FPTracker
src
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
"
8
#include "
FPTracker/IBeamElement.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
22
IBeamElement::Iter_t
findBeamLineEnd
(
IBeamElement::Container_t
& container) {
23
IBeamElement::Iter_t
ei = find_if(container.begin(),
24
container.end(),
25
isEndMarker
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
}
35
class
zPosNextElement
{
36
public
:
37
bool
operator()
(
const
IBeamElement::ConstPtr_t
& be,
double
zpos ){
38
return
std::fabs(zpos) > be->zabspos();
39
}
40
};
41
42
43
Beamline::Beamline
(){}
44
45
Beamline::Beamline
(
IBeamElement::ListIter_t
begin,
IBeamElement::ListIter_t
end)
46
{
// exception aware: attemt to create as a temp, if no exception, do safe swap ....
47
IBeamElement::Container_t
temp(begin, end);
48
IBeamElement::Iter_t
tempIter =
findBeamLineEnd
(temp);
49
IBeamElement::Container_t
temp2(temp.begin(), tempIter);
50
51
m_elements
.swap(temp2);
52
}
53
54
Beamline::Beamline
(
const
Beamline
& rhs)
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
67
void
Beamline::swap
(
Beamline
& other)
68
{
69
m_elements
.swap(other.m_elements);
70
}
71
72
class
ParticleTracker
{
73
public
:
74
ParticleTracker
(
IParticle
& particle):
m_particle
(particle) {
75
}
76
bool
operator()
(
const
IBeamElement::ConstPtr_t
& be){
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
:
89
IParticle
&
m_particle
;
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(),
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(),
104
ParticleTracker
(particle)
105
);
106
107
}
108
109
110
void
Beamline::calibrate
(
IParticle
& particle)
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
119
IBeamElement::ConstIter_t
iter;
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
}
151
void
operator()
(
const
IBeamElement::ConstPtr_t
& ib){
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
Beamline.h
IBeamElement.h
STLHelpers.h
IParticle.h
FPTracker::Beamline
Definition
FPTracker/FPTracker/Beamline.h:15
FPTracker::Beamline::m_elements
IBeamElement::Container_t m_elements
Definition
FPTracker/FPTracker/Beamline.h:27
FPTracker::Beamline::swap
void swap(Beamline &other)
Definition
FPTracker/src/Beamline.cxx:67
FPTracker::Beamline::calibrate
void calibrate(IParticle &)
Definition
FPTracker/src/Beamline.cxx:110
FPTracker::Beamline::Beamline
Beamline()
Definition
FPTracker/src/Beamline.cxx:43
FPTracker::Beamline::operator=
Beamline & operator=(Beamline)
Definition
FPTracker/src/Beamline.cxx:61
FPTracker::Beamline::track
void track(IParticle &) const
Definition
FPTracker/src/Beamline.cxx:94
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::IBeamElement::Iter_t
Container_t::iterator Iter_t
Definition
FPTracker/FPTracker/IBeamElement.h:44
FPTracker::IBeamElement::ListIter_t
List_t::iterator ListIter_t
Definition
FPTracker/FPTracker/IBeamElement.h:48
FPTracker::IBeamElement::Container_t
std::vector< Ptr_t > Container_t
Definition
FPTracker/FPTracker/IBeamElement.h:43
FPTracker::IBeamElement::ConstIter_t
Container_t::const_iterator ConstIter_t
Definition
FPTracker/FPTracker/IBeamElement.h:45
FPTracker::IParticle
Definition
ForwardDetectors/FPTracker/FPTracker/IParticle.h:17
FPTracker::ParticleTracker
Definition
FPTracker/src/Beamline.cxx:72
FPTracker::ParticleTracker::m_particle
IParticle & m_particle
Definition
FPTracker/src/Beamline.cxx:89
FPTracker::ParticleTracker::operator()
bool operator()(const IBeamElement::ConstPtr_t &be)
Definition
FPTracker/src/Beamline.cxx:76
FPTracker::ParticleTracker::ParticleTracker
ParticleTracker(IParticle &particle)
Definition
FPTracker/src/Beamline.cxx:74
FPTracker::Stringer
Definition
FPTracker/src/Beamline.cxx:146
FPTracker::Stringer::operator()
void operator()(const IBeamElement::ConstPtr_t &ib)
Definition
FPTracker/src/Beamline.cxx:151
FPTracker::Stringer::Stringer
Stringer()
Definition
FPTracker/src/Beamline.cxx:148
FPTracker::Stringer::m_ost
std::shared_ptr< std::stringstream > m_ost
Definition
FPTracker/src/Beamline.cxx:156
FPTracker::Stringer::str
std::string str() const
Definition
FPTracker/src/Beamline.cxx:154
FPTracker::zPosNextElement
Definition
FPTracker/src/Beamline.cxx:35
FPTracker::zPosNextElement::operator()
bool operator()(const IBeamElement::ConstPtr_t &be, double zpos)
Definition
FPTracker/src/Beamline.cxx:37
stringstream
STL class.
label
std::string label(const std::string &format, int i)
Definition
label.h:19
FPTracker
Definition
FPTracker/FPTracker/Beamline.h:12
FPTracker::findBeamLineEnd
IBeamElement::Iter_t findBeamLineEnd(IBeamElement::Container_t &container)
Definition
FPTracker/src/Beamline.cxx:22
FPTracker::isEndMarker
bool isEndMarker(const IBeamElement::ConstPtr_t &p)
Definition
FPTracker/src/Beamline.cxx:20
FPTracker::operator<<
std::ostream & operator<<(std::ostream &os, const Beamline &bl)
Definition
FPTracker/src/Beamline.cxx:163
FPTracker::fixLabel
std::string fixLabel(const std::string &label)
Definition
FPTracker/src/Beamline.cxx:139
std
STL namespace.
Generated on
for ATLAS Offline Software by
1.17.0