ATLAS Offline Software
Loading...
Searching...
No Matches
ForwardTracker/src/Magnet.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
9
10namespace ForwardTracker {
11
13 double y,
14 double z,
15 double length,
16 const std::string& aperType,
17 double aper1,
18 double aper2,
19 double aper3,
20 double aper4,
21 Side side,
22 IBender * bender,
23 const std::string& label):
24 m_label (label),
25 m_side (side),
26 m_frontFace(z>0 ? z - 0.5*length : z + 0.5*length),
27 m_rearFace (z>0 ? z + 0.5*length : z - 0.5*length),
28 m_position (x, y, z),
29 m_aperType (aperType),
30 m_A1 (aper1),
31 m_A2 (aper2),
32 m_A3 (aper3),
33 m_A4 (aper4),
34 m_bender (bender)
35 {}
36
37 void Magnet::track(IParticle& particle) const {
38
39 particle.setBeamCoordinateShift(this);
40
41 if (particle.isOutOfAperture()) return;
42
43 m_bender->bend(particle);
44
45 particle.z() = m_rearFace;
46
47 if (this->isOutOfAperture(particle)) particle.setOutOfAperture(true);
48 }
49
50 bool Magnet::isOutOfAperture(IParticle& particle) const {
51
52 TransversePoint offCenter = particle.displacement();
53
54 if (m_aperType == "\"NONE\"") return false;
55 else if (m_aperType == "\"CIRCLE\"") {
56
57 if (m_A1 == 0) return false;
58
59 if (offCenter.mag2() > m_A1*m_A1) {
60
61 std::ostringstream ost; ost << m_label << " isOutOfAperture ";
62
63 ost << "radius: " << offCenter.mag2() << " > A1*A1: " << m_A1*m_A1;
64 particle.addMsg(ost.str());
65
66 return true;
67 }
68
69 return false;
70 }
71 else if (m_aperType == "\"RECTELLIPSE\"") {
72
73 double xx = (m_A3) ? offCenter.x()/m_A3 : throw std::runtime_error("ERROR: m_A3 == 0");
74 double yy = (m_A4) ? offCenter.y()/m_A4 : throw std::runtime_error("ERROR: m_A4 == 0");
75 double rr = xx*xx + yy*yy;
76
77 if (rr > 1) {
78
79 std::ostringstream ost; ost << m_label << " isOutOfAperture ";
80
81 ost << " x/A3: " << xx << " y/A4: " << yy << " (Squared sum: " << rr << " > 1)";
82 particle.addMsg(ost.str());
83
84 return true;
85 }
86
87 if (m_A1 > 0) {
88
89 if (std::fabs(offCenter.x()) > m_A1) {
90
91 std::ostringstream ost; ost << m_label << " isOutOfAperture ";
92
93 ost << " |x|: " << std::fabs(offCenter.x()) << " > A1: " << m_A1;
94 particle.addMsg(ost.str());
95
96 return true;
97 }
98 }
99
100 if (m_A2 > 0) {
101
102 if (std::fabs(offCenter.y()) > m_A2) {
103
104 std::ostringstream ost; ost << m_label << " isOutOfAperture ";
105
106 ost << " |y|: " << std::fabs(offCenter.y()) << " > A2: " << m_A2;
107 particle.addMsg(ost.str());
108
109 return true;
110 }
111 }
112
113 return false;
114 }
115 else if (m_aperType == "\"OCTAGON\"") {
116
117 if ( m_A1 > 0. ) {
118 if( std::fabs(offCenter.x())>m_A1 ) {
119
120 std::ostringstream ost; ost << m_label << " isOutOfAperture ";
121
122 ost << " |x|: " << std::fabs(offCenter.x()) << " > A1: " << m_A1;
123 particle.addMsg(ost.str());
124 return true;
125 }
126 }
127 if ( m_A2 > 0. ) {
128 if( std::fabs(offCenter.y())>m_A2) {
129
130 std::ostringstream ost; ost << m_label << " isOutOfAperture ";
131
132 ost << " |y|: " << std::fabs(offCenter.y()) << " > A2: " << m_A2;
133 particle.addMsg(ost.str());
134 return true;
135 }
136 }
137 if ( m_A3 > 0. && m_A4 > 0. ) {
138
139 float B3=std::tan(m_A3)*m_A1;
140 float B4=m_A2/std::tan(m_A4);
141 float d=(m_A1-std::fabs(offCenter.x()))/(m_A1-B4)+(m_A2-std::fabs(offCenter.y()))/(m_A2-B3);
142
143 if(d<1.) {
144 std::ostringstream ost; ost << m_label << " isOutOfAperture ";
145
146 ost<<" x: "<<offCenter.x()<<" y: "<<offCenter.y()<<" m_A1 "<<m_A1<<" m_A2 "<<m_A2<<" m_A3 "<<m_A3<<" m_A4 "<<m_A4<<" d: "<<d;
147 particle.addMsg( ost.str() );
148 return true;
149 }
150 }
151
152 return false;
153 }
154 else {
155
156 std::stringstream sstr; sstr << " Unknown magnet aperture type " << m_aperType << "\n";
157 throw std::runtime_error(sstr.str().c_str());
158 }
159
160 return false;
161 }
162
163 std::string Magnet::str() const {
164
165 std::ostringstream ost;
166
167 ost << "m_label " << m_label << "\n"
168 << "m_side " << m_side << "\n"
169 << "m_frontFace " << m_frontFace << "\n"
170 << "m_rearFace " << m_rearFace << "\n"
171 << "m_position " << m_position << "\n"
172 << "m_aperType " << m_aperType << "\n"
173 << "m_A1 " << m_A1 << "\n"
174 << "m_A2 " << m_A2 << "\n"
175 << "m_A3 " << m_A3 << "\n"
176 << "m_A4 " << m_A4 << "\n";
177
178 return ost.str();
179 }
180
181 std::ostream& operator<<(std::ostream& os, const Magnet& mag) { os << mag.str(); return os; }
182}
const boost::regex rr(r_r)
Scalar mag() const
mag method
double length(const pvec &v)
#define y
#define x
#define z
Magnet(double x, double y, double z, double length, const std::string &aperType, double A1, double A2, double A3, double A4, Side side, IBender *bender, const std::string &label)
bool isOutOfAperture(IParticle &) const
std::ostream & operator<<(std::ostream &, const Beamline &)