ATLAS Offline Software
Loading...
Searching...
No Matches
FPTracker/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
5#include "FPTracker/Magnet.h"
8#include "FPTracker/IBender.h"
9#include <sstream>
10#include <cmath>
11#include <cassert>
12
13namespace FPTracker{
14
15 std::string Magnet::label() const{
16 return m_label+":"+m_bender->label();
17 }
18
20 double x,
21 double y,
22 double center,
23 double strength,
24 double length,
25 int apertype,
26 double aper_A1,
27 double aper_A2,
28 double aper_A3,
29 double aper_A4,
30 double xb,
31 Side side,
32 IBender * bender,
33 const std::string& label):
34 m_center(x, y, center),
35 m_frontFace(center>0 ? center-0.5*length:center+0.5*length),
36 m_rearFace(center>0 ? center+0.5*length:center-0.5*length),
37 m_strength(strength),
38 m_apertype(apertype),
39 m_aper_A1(aper_A1),
40 m_aper_A2(aper_A2),
41 m_aper_A3(aper_A3),
42 m_aper_A4(aper_A4),
43 m_xb(xb),
44 m_side(side),
45 m_bender(bender),
47 if (m_apertype == 1){ assert(m_aper_A1 != 0.);}
48 if (m_apertype == 2 || m_apertype == 3){ assert(m_aper_A3 != 0. and m_aper_A4 != 0.);}
49 }
51 IBeamElement::ConstPtr_t pm(new Magnet(*this));
52 return pm;
53 }
54
55 double Magnet::frontFace() const {return m_frontFace;}
56 double Magnet::rearFace() const {return m_rearFace;}
57 double Magnet::zsignedpos() const {return m_center.z();}
58 double Magnet::zabspos() const {return std::fabs(m_center.z());}
60 Side Magnet::side() const {return m_side;}
61
62 bool Magnet::isEndElement() const{return false;}
63
64 void Magnet::track(IParticle& particle) const{
65
66 particle.setBeamCoordinateShift(this);
67 if ( particle.isOutOfAperture() ){return;}
68
69
70 // check if particle x,y coordinates wrt to the magnet are in the aperture.
71 if( this->isOutOfAperture( particle ) ){
72 //std::cout<<"lost at front face "<<std::endl;
73 particle.setOutOfAperture(true);
74 return;
75 }
76
77 // update the particle position and direction affected by the bending of the magnet.
78 m_bender->bend(particle);
79 particle.z() = m_rearFace;
80
81 /*
82 std::cout<<"Magnet::track after bend "<<this->m_frontFace<<" "<<this->label()<<'\n'
83 <<"\n position "<<particle.position()
84 <<"\n p dir "<<particle.direction()
85 <<"\n m pos "<<this->position()<<'\n'<<std::endl;
86
87
88 std::cout<<particle<<'\n';
89 */
90
91 if ( this->isOutOfAperture( particle ) )
92 {
93 particle.setOutOfAperture(true);
94 }
95
96 }
97
99 {
100 return this->track(particle);
101 }
102
103 bool Magnet::isOutOfAperture(IParticle& particle) const{
104
105 TransversePoint offCenter = particle.displacement();
106 if(m_apertype == 1)
107 {
108
109 double radius = m_aper_A1;
110 bool out = offCenter.mag2() > radius*radius;
111
112 if(out)
113 {
114 std::ostringstream ost;
115 ost<<"pos "<<offCenter.mag2()<<" radiusSq "<<radius*radius<<'\n';
116 particle.addMsg( ost.str() );
117 return true;
118 }
119
120 return false;
121 }
122
123 if(m_apertype == 2)
124 {
125 double part_x = offCenter.x();
126 double part_y = offCenter.y();
127
128 double xx = part_x/m_aper_A3;
129 double yy = part_y/m_aper_A4;
130
131 bool out = xx*xx + yy*yy >1.;
132 if(out)
133 {
134 std::ostringstream ost;
135 ost<<"outside for aperture type 2 x xx, xaper "<<part_x<<" "<<xx<<" "<<m_aper_A3<<" y yy yaper "<<part_y<<" "<<yy<<" "<<m_aper_A4<<'\n';
136 particle.addMsg( ost.str() );
137 return true;
138 }
139
140
141 if ( m_aper_A1>0.)
142 {
143 if( std::fabs(part_x)>m_aper_A1 )
144 {
145 std::ostringstream ost;
146 ost<<"outside for aperture type 2 x test: particle x "<<part_x<<" m_aper_A1 "<<m_aper_A1<<"\n";
147 particle.addMsg( ost.str() );
148 return true;
149 }
150 }
151 if ( m_aper_A2>0.)
152 {
153 if( std::fabs(part_y)>m_aper_A2)
154 {
155 std::ostringstream ost;
156 ost<<"outside for aperture type 2 y test: particle y "<<part_y<<" m_aper_A2 "<<m_aper_A2<<"\n";
157 particle.addMsg( ost.str() );
158 return true;
159 }
160 }
161
162 return false;
163 }
164 if(m_apertype == 3)
165 {
166 double part_x = offCenter.x();
167 double part_y = offCenter.y();
168
169 if ( m_aper_A1 > 0. )
170 {
171 if( std::fabs(part_x)>m_aper_A1 )
172 {
173 std::ostringstream ost;
174 ost<<"outside for aperture type 3 x test: particle x "<<part_x<<" m_aper_A1 "<<m_aper_A1<<"\n";
175 particle.addMsg( ost.str() );
176 return true;
177 }
178 }
179 if ( m_aper_A2 > 0. )
180 {
181 if( std::fabs(part_y)>m_aper_A2)
182 {
183 std::ostringstream ost;
184 ost<<"outside for aperture type 3 y test: particle y "<<part_y<<" m_aper_A2 "<<m_aper_A2<<"\n";
185 particle.addMsg( ost.str() );
186 return true;
187 }
188 }
189 if ( m_aper_A3 > 0. && m_aper_A4 > 0. )
190 {
191 float B3=std::tan(m_aper_A3)*m_aper_A1;
192 float B4=m_aper_A2/std::tan(m_aper_A4);
193 float d=(m_aper_A1-std::fabs(part_x))/(m_aper_A1-B4)+(m_aper_A2-std::fabs(part_y))/(m_aper_A2-B3);
194
195 if(d<1.)
196 {
197 std::ostringstream ost;
198 ost<<"outside for aperture type 3 test: particle x "<<part_x<<" particle y "<<part_y<<"; m_aper_A1 "<<m_aper_A1<<" m_aper_A2 "<<m_aper_A2<<" m_aper_A3 "<<m_aper_A3<<" m_aper_A4 "<<m_aper_A4<<"\n";
199 particle.addMsg( ost.str() );
200 return true;
201 }
202 }
203
204 return false;
205 }
206
207 // aperture is checked anly if aperture type i s 1, 2, or 3
208 return false;
209 }
210
211
212 std::string Magnet::str() const {
213 std::ostringstream ost;
214 ost <<" \n\n-- Magnet --\n"
215 << "label " << m_label <<'\n'
216 << "center " << m_center <<'\n'
217 << "frontFace " << m_frontFace <<'\n'
218 << "rearFace " << m_rearFace <<'\n'
219 << "m_strength " << m_strength <<'\n'
220 << "m_apertyp " << m_apertype <<'\n'
221 << "m_aper_A1 " << m_aper_A1 <<'\n'
222 << "m_aper_A2 " << m_aper_A2 <<'\n'
223 << "m_aper_A3 " << m_aper_A3 <<'\n'
224 << "m_aper_A4 " << m_aper_A4 <<'\n'
225 << "m_xb " << m_xb <<'\n'
226 << "m_side " << m_side <<'\n';
227 return ost.str();
228 }
229 std::ostream& operator<<(std::ostream& os, const Magnet& mag){
230 os << mag.str();
231 return os;
232 }
233}
234
Scalar mag() const
mag method
double length(const pvec &v)
#define y
#define x
std::shared_ptr< const IBeamElement > ConstPtr_t
Magnet(double x, double y, double center, double strength, double length, int apertype, double aper_A1, double aper_A2, double aper_A3, double aper_A4, double xb, Side side, IBender *bender, const std::string &label)
void calibrate(IParticle &)
IBeamElement::ConstPtr_t clone() const
void track(IParticle &) const
std::string str() const
std::string label() const
bool isOutOfAperture(IParticle &) const
std::ostream & operator<<(std::ostream &os, const Beamline &bl)