BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
FTSegment.cxx
Go to the documentation of this file.
1#include "FTSegment.h"
2
3#include "FTLayer.h"
4#include "FTList.h"
5#include "FTSuperLayer.h"
6#include "FTTrack.h"
7#include "FTWire.h"
8#include "MdcParameter.h"
9
10#include <math.h>
11
13 : _wireHits( hits )
14 , _superLayer( super )
15 , _innerBoundHits( 0 )
16 , _outerBoundHits( 0 )
17 , _firstCallUpdate3D( true )
18 , _sList( 0 )
19 , _zList( 0 ) {
20 StatusCode scmgn = Gaudi::svcLocator()->service( "MagneticFieldSvc", m_pmgnIMF );
21 if ( scmgn != StatusCode::SUCCESS )
22 { std::cout << "Unable to open Magnetic field service" << std::endl; }
23}
24
26 const FTList<FTWire*>& outerBound ) {
27 _wireHits.insert( _wireHits.end(), outerHits.begin(), outerHits.end() );
28 _outerBoundHits.clear();
29 _outerBoundHits.insert( _outerBoundHits.end(), outerBound.begin(), outerBound.end() );
30}
31
33 const FTList<FTWire*>& innerBound ) {
34 _wireHits.insert( _wireHits.end(), innerHits.begin(), innerHits.end() );
35 _innerBoundHits.clear();
36 _innerBoundHits.insert( _innerBoundHits.end(), innerBound.begin(), innerBound.end() );
37}
38
40 _wireHits.push_back( h );
41 _outerBoundHits.clear();
42 _outerBoundHits.push_back( h );
43}
44
46 _wireHits.push_back( h );
47 _innerBoundHits.clear();
48 _innerBoundHits.push_back( h );
49}
50
51FTSuperLayer* FTSegment::superLayer() const { return _superLayer; }
52FTList<FTWire*>& FTSegment::wireHits() { return _wireHits; }
53const FTList<FTWire*>& FTSegment::innerBoundHits() { return _innerBoundHits; }
54const FTList<FTWire*>& FTSegment::outerBoundHits() { return _outerBoundHits; }
55float FTSegment::outgoingX() const { return _outgoing_x; }
56float FTSegment::outgoingY() const { return _outgoing_y; }
57float FTSegment::incomingX() const { return _incoming_x; }
58float FTSegment::incomingY() const { return _incoming_y; }
59float FTSegment::r() const { return _r; }
60
61float FTSegment::s() const {
62 if ( _sList.size() ) return _sList[0];
63 else
64 {
65 std::cout << "FTSegment::s() _sList.size() = 0 ! this = " << this << std::endl;
66 return 0;
67 }
68}
69
70float FTSegment::z() const {
71 if ( _zList.size() ) return _zList[0];
72 else
73 {
74 std::cout << "FTSegment::s() _zList.size() = 0 ! this = " << this << std::endl;
75 return 0;
76 }
77}
78
79float FTSegment::kappa() const { return _kappa; }
80
82 if ( _trackList.size() ) return _trackList.front();
83 else return nullptr;
84}
85
87 if ( _trackList.size() ) _trackList.front() = src;
88 else _trackList.push_back( src );
89 return _trackList.front();
90}
91
93 if ( _innerBoundHits.size() > 1 )
94 {
95 auto it = _innerBoundHits.begin();
96 float phi_1st = ( *it )->phi();
97 it++;
98 float phi_2nd = ( *it )->phi();
99 float phi = 0.5 * ( phi_1st + phi_2nd );
100 if ( fabs( phi_1st - phi_2nd ) > M_PI )
101 { return ( phi > M_PI ) ? ( phi - M_PI ) : ( phi + M_PI ); }
102 return phi;
103 }
104 else return _innerBoundHits.front()->phi();
105}
106
108 if ( _outerBoundHits.size() > 1 )
109 {
110 auto it = _outerBoundHits.begin();
111 float phi_1st = ( *it )->phi();
112 it++;
113 float phi_2nd = ( *it )->phi();
114 float phi = 0.5 * ( phi_1st + phi_2nd );
115 if ( fabs( phi_1st - phi_2nd ) > M_PI )
116 { return ( phi > M_PI ) ? ( phi - M_PI ) : ( phi + M_PI ); }
117 return phi;
118 }
119 else return _outerBoundHits.front()->phi();
120}
121
123 float x_len = _outgoing_x - _incoming_x;
124 float y_len = _outgoing_y - _incoming_y;
125 float phi_l = outgoingPhi() - incomingPhi();
126 return sin( phi_l ) / sqrt( x_len * x_len + y_len * y_len );
127}
128
130
132 int stat = -1;
133
134 array<FTList<FTWire*>, 4> wireHitsByLocalLayer;
135
136 for ( auto& hptr : _wireHits )
137 { wireHitsByLocalLayer[hptr->layer()->localLayerId()].push_back( hptr ); }
138
139 float length_phi = 0;
140 int innerBoundId = 0;
141 int outerBoundId = 0;
142 int AlreadyFound = 0;
143
144 const int nLayer = _superLayer->nLayer();
145
146 // to look for the innerBound and outBand of the hits
147 for ( int i = 0; i != nLayer; i++ )
148 {
149 int N_wireHits = wireHitsByLocalLayer[i].size();
150 if ( N_wireHits )
151 {
152 float localPhi_max = 0.;
153 float localPhi_min = 7.;
154
155 for ( int j = 0; j != N_wireHits; j++ )
156 {
157 float localPhi = wireHitsByLocalLayer[i][j]->phi();
158 if ( localPhi > localPhi_max ) localPhi_max = localPhi;
159 if ( localPhi < localPhi_min ) localPhi_min = localPhi;
160 }
161
162 float local_length_phi = localPhi_max - localPhi_min;
163 if ( local_length_phi > M_PI ) local_length_phi = 2 * M_PI - local_length_phi;
164 if ( local_length_phi > length_phi ) length_phi = local_length_phi;
165 outerBoundId = i;
166 AlreadyFound = 1;
167 }
168 else if ( !AlreadyFound ) { innerBoundId++; }
169 else { break; }
170 }
171
172 // length_phi needed to decide more carefully
173 if ( length_phi > FTSuperLayer::_maxDphi[_superLayer->superLayerId()] * 2 * M_PI / 180 )
174 { // by X.-R. Lu
175 stat = 3; // to be divided
176 }
177 else
178 {
179 if ( innerBoundId > 0 )
180 {
181 stat = 2; // outer short
182 }
183 else
184 {
185 if ( outerBoundId < nLayer - 1 )
186 {
187 stat = 1; // inner short
188 }
189 else
190 {
191 stat = 0; // long simple
192 }
193 }
194 }
195 _innerBoundHits.insert( _innerBoundHits.end(), wireHitsByLocalLayer[innerBoundId].begin(),
196 wireHitsByLocalLayer[innerBoundId].end() );
197 _outerBoundHits.insert( _outerBoundHits.end(), wireHitsByLocalLayer[outerBoundId].begin(),
198 wireHitsByLocalLayer[outerBoundId].end() );
199 return stat;
200}
201
203
204 updateInOutXY();
205
206 float in_r = _innerBoundHits.front()->layer()->r();
207 float out_r = _outerBoundHits.front()->layer()->r();
208 float sbX = _incoming_x - _outgoing_x;
209 float sbY = _incoming_y - _outgoing_y;
210
211 _kappa = 2. * ( -1. / 2.99792458 / m_pmgnIMF->getReferField() ) *
212 ( _outgoing_x * _incoming_y - _outgoing_y * _incoming_x ) /
213 ( in_r * out_r * sqrt( sbX * sbX + sbY * sbY ) );
214
215 _r = 0.5 * ( in_r + out_r );
216}
217
219 IMessageSvc* msgSvc;
220 Gaudi::svcLocator()->service( "MessageSvc", msgSvc ).ignore();
221
222 MsgStream log( msgSvc, "FTFinder" );
223
224 if ( _firstCallUpdate3D )
225 {
226 updateInOutXY();
227 _firstCallUpdate3D = false;
228 }
229
230 const Lpav& la = track->lpav();
231 double d;
232 double inS;
233
234 const FTLayer* bound = _innerBoundHits.front()->layer();
235
236 log << MSG::DEBUG << "started inS calculation with layer limit " << bound->limit() << endmsg;
237 if ( !( la.sd( (double)bound->r(), (double)_incoming_x, (double)_incoming_y,
238 (double)bound->limit(), // multiplied with an factor due to bad rphi fit
239 inS, d ) ) )
240 return 0;
241
242 double inZ = bound->z( d );
243 double outS;
244
245 bound = _outerBoundHits.front()->layer();
246 log << MSG::DEBUG << "started outS calculation with layer limit " << bound->limit()
247 << endmsg;
248 if ( !( la.sd( (double)bound->r(), (double)_outgoing_x, (double)_outgoing_y,
249 (double)bound->limit(), // multiplied with an factor due to bad rphi fit
250 outS, d ) ) )
251 return 0;
252
253 double outZ = bound->z( d );
254 _sList.push_back( inS + outS );
255 _zList.push_back( inZ + outZ );
256 _trackList.push_back( track );
257 log << MSG::DEBUG << "-----> coupled! DONE! " << endmsg;
258
259 return 1;
260}
261
263 float min_D_z = 9999.;
264 float S = 0.;
265 float Z = 0.;
266 FTTrack* selected = nullptr;
267
268 int j = 0;
269 for ( auto t : _trackList )
270 {
271 float z_tmp = _zList[j];
272 float s_tmp = _sList[j];
273 float D_z = fabs( t->d_z( s_tmp, z_tmp ) );
274 if ( D_z < min_D_z )
275 {
276 selected = t;
277 min_D_z = D_z;
278 S = s_tmp;
279 Z = z_tmp;
280 }
281 j++;
282 }
283 if ( selected ) { selected->append_stereo( this, S, Z ); }
284}
285
286#ifndef OnlineMode
288
289 IMessageSvc* msgSvc;
290 Gaudi::svcLocator()->service( "MessageSvc", msgSvc );
291
292 MsgStream log( msgSvc, "FTSegment" );
293 log << MSG::DEBUG << "pintout of one segment:" << endmsg;
294
295 for ( auto h : _wireHits )
296 {
297 log << MSG::DEBUG << "hit: layer " << h->layer()->layerId() << " phi " << h->phi()
298 << endmsg;
299 }
300}
301#endif
302
303void FTSegment::updateInOutXY() {
304 int n = _innerBoundHits.size();
305 int m = _outerBoundHits.size();
306
307 if ( n > 1 )
308 {
309 // std::list doesn't support random access, so we have to use an iterator
310 auto it = _innerBoundHits.begin();
311 float x0 = ( *it )->x(), y0 = ( *it )->y();
312 it++;
313 float x1 = ( *it )->x(), y1 = ( *it )->y();
314
315 _incoming_x = 0.5 * ( x0 + x1 );
316 _incoming_y = 0.5 * ( y0 + y1 );
317 }
318 else
319 {
320 _incoming_x = _innerBoundHits.front()->x();
321 _incoming_y = _innerBoundHits.front()->y();
322 }
323
324 if ( m > 1 )
325 {
326 // std::list doesn't support random access, so we have to use an iterator
327 auto it = _outerBoundHits.begin();
328 float x0 = ( *it )->x(), y0 = ( *it )->y();
329 it++;
330 float x1 = ( *it )->x(), y1 = ( *it )->y();
331
332 _outgoing_x = 0.5 * ( x0 + x1 );
333 _outgoing_y = 0.5 * ( y0 + y1 );
334 }
335 else
336 {
337 _outgoing_x = _outerBoundHits.front()->x();
338 _outgoing_y = _outerBoundHits.front()->y();
339 }
340}
int selected
const Int_t n
IMessageSvc * msgSvc()
#define M_PI
Definition TConstant.h:4
const float r() const
returns r form origin
Definition FTLayer.h:35
double z(const double d) const
returns z for "d" in r-phi plane
Definition FTLayer.h:50
const double limit() const
returns limit of "d" for stereo layer
Definition FTLayer.h:47
Definition FTList.h:6
FTSuperLayer * superLayer() const
returns super-layer
Definition FTSegment.cxx:51
float incomingPhi() const
returns phi of incoming position
Definition FTSegment.cxx:92
int examine()
examine segment
FTList< FTWire * > & wireHits()
returns wire-hit FTList
Definition FTSegment.cxx:52
float r() const
returns r from origin
Definition FTSegment.cxx:59
float outgoingY() const
returns y of outgoing position
Definition FTSegment.cxx:56
float kappa() const
returns kappa(axial)
Definition FTSegment.cxx:79
void linkStereoSegments()
link stereo segments by tanLambda
float outgoingX() const
returns x of outgoing position
Definition FTSegment.cxx:55
float incomingX() const
returns x of incoming position
Definition FTSegment.cxx:57
const FTList< FTWire * > & innerBoundHits()
returns innerBoundHits
Definition FTSegment.cxx:53
void update()
update information for axial segment
const FTList< FTWire * > & outerBoundHits()
returns outerBoundHits
Definition FTSegment.cxx:54
void printout()
void connect_inner(const FTList< FTWire * > &, const FTList< FTWire * > &)
Definition FTSegment.cxx:32
float outgoingPhi() const
returns phi of outgoing position
FTSegment(FTSuperLayer *super, FTList< FTWire * > &hits)
Definition FTSegment.cxx:12
FTTrack * track() const
returns track
Definition FTSegment.cxx:81
float z() const
returns z for matched 2D track
Definition FTSegment.cxx:70
float attr_const() const
returns the sin(dphi)/MOD(r_out-r_in)
float incomingY() const
returns y of incoming position
Definition FTSegment.cxx:58
float s() const
returns s for matched 2D track
Definition FTSegment.cxx:61
static MdcParameter * param
Definition FTSegment.h:106
int update3D(FTTrack *track)
update information for stereo segment
void connect_outer(const FTList< FTWire * > &, const FTList< FTWire * > &)
connect short segments
Definition FTSegment.cxx:25
static const std::array< float, 11 > _maxDphi
int sd(double r, double x, double y, double limit, double &s, double &d) const
static MdcParameter * instance()
int t()
Definition t.c:1