BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
FTWire.cxx
Go to the documentation of this file.
1#include "FTWire.h"
2#include "FTGeom.h"
3#include "FTLayer.h"
4#include "FTSuperLayer.h"
5
6#include <iostream>
7
8FTWire::FTWire( const float x, const float y, const float dx, const float dy, const int wireId,
9 FTLayer* layer, const float phi )
10 : _x( x ) // x position in z = 0;
11 , _y( y ) // y position in z = 0;
12 , _dx( dx )
13 , _dy( dy )
14 , _wireId( wireId )
15 , _distance( 0 )
16 , _t0( 0 )
17 , _time( 0 )
18 , m_adc( 0 )
19 , _pedestal( 0 )
20 , _layer( layer )
21 , _phi( phi )
22 , _state( FTWireHitInvalid ) {
23 _neighbor.fill( nullptr );
24}
25
27 : _x( 0 )
28 , _y( 0 )
29 , _dx( 0 )
30 , _dy( 0 )
31 , _layer( nullptr )
32 , _phi( 0 )
33 , _distance( 0 )
34 , _t0( 0 )
35 , _time( 0 )
36 , m_adc( 0 )
37 , _pedestal( 0 )
38 , _state( FTWireHitInvalid ) {
39 _neighbor.fill( nullptr );
40}
41
42const int FTWire::localId() const {
43 return FTGeom::instance()->wire2wireIndexLayer( _wireId );
44}
45
46float FTWire::distance_z() const { return _distance * std::fabs( _layer->tanSlant() ); }
47
49 getInnerNeighbor();
50 getMidNeighbor();
51 getOuterNeighbor();
52}
53
54void FTWire::getInnerNeighbor() {
55 auto geom = FTGeom::instance();
56 if ( _layer->localLayerId() == 0 )
57 {
58 _neighbor[0] = _neighbor[1] = geom->getVirtualWire();
59 return;
60 }
61
62 float thisPhi = phi();
63
64 int innerLayer_id = _layer->layerId() - 1;
65 int n = geom->layer2nWires( innerLayer_id );
66 int low = 0, high = n - 1, mid = 0;
67 int innerPosition = 1;
68
69 const int lastInnerId = geom->layer2wireEnd( innerLayer_id );
70
71 while ( low <= high )
72 {
73 mid = ( low + high ) / 2;
74 if ( geom->getWire( lastInnerId - mid )->phi() <= thisPhi ) high = mid - 1;
75 else low = mid + 1;
76 }
77
78 innerPosition = mid;
79
80 if ( geom->getWire( lastInnerId - innerPosition )->phi() <= thisPhi )
81 {
82 _neighbor[0] = geom->getWire( lastInnerId - innerPosition );
83 if ( innerPosition == 0 ) _neighbor[1] = geom->getWire( lastInnerId - n + 1 );
84 else _neighbor[1] = geom->getWire( lastInnerId - innerPosition + 1 );
85 }
86 else
87 {
88 if ( ( innerPosition + 1 ) == n ) _neighbor[0] = geom->getWire( lastInnerId );
89 else _neighbor[0] = geom->getWire( lastInnerId - innerPosition - 1 );
90 _neighbor[1] = geom->getWire( lastInnerId - innerPosition );
91 }
92}
93
94void FTWire::getOuterNeighbor() {
95 if ( !_layer )
96 {
97 std::cout << "this: " << this << "FTWire::getOuterNeighbor: _layer is nullptr"
98 << std::endl;
99 }
100
101 auto geom = FTGeom::instance();
102
103 int superLayer_id = geom->wire2superLayer( _wireId );
104 int layerMaxId = geom->superLayer2nLayers( superLayer_id ) - 1;
105
106 if ( _layer->localLayerId() == layerMaxId )
107 {
108 _neighbor[4] = _neighbor[5] = geom->getVirtualWire();
109 return;
110 }
111
112 float thisPhi = phi();
113
114 int outerLayer_id = _layer->layerId() + 1;
115 int n = geom->layer2nWires( outerLayer_id );
116 int low = 0, high = n - 1, mid = 0;
117 int position;
118
119 const int firstOuterId = geom->layer2wireStart( outerLayer_id );
120
121 while ( low <= high )
122 {
123 mid = ( low + high ) / 2;
124 if ( geom->getWire( firstOuterId + mid )->phi() > thisPhi ) high = mid - 1;
125 else low = mid + 1;
126 }
127
128 position = mid;
129 if ( geom->getWire( firstOuterId + position )->phi() <= thisPhi )
130 {
131 _neighbor[4] = geom->getWire( firstOuterId + position );
132 if ( ( position + 1 ) == n ) _neighbor[5] = geom->getWire( firstOuterId );
133 else _neighbor[5] = geom->getWire( firstOuterId + position + 1 );
134 }
135 else
136 {
137 if ( ( position - 1 ) == -1 ) _neighbor[4] = geom->getWire( firstOuterId + n - 1 );
138 else _neighbor[4] = geom->getWire( firstOuterId + position - 1 );
139 _neighbor[5] = geom->getWire( firstOuterId + position );
140 }
141}
142
143void FTWire::getMidNeighbor() {
144 _neighbor[2] = (FTWire*)left();
145 _neighbor[3] = (FTWire*)right();
146}
147
149 _distance = 0.;
150 _time = 0.;
151 _t0 = 0.;
152 m_adc = 0.0;
153 _pedestal = 0.;
154 _state = FTWireHitInvalid;
155}
156
157int FTWire::z( const Lpav& la, double& z ) const {
158 HepVector center = la.center();
159 double rho = la.radius();
160 double dx2 = center( 1 ) - _x;
161 double dy2 = center( 2 ) - _y;
162 double par1 = _dx * _dx + _dy * _dy;
163 double par2 = ( _dx * dx2 + _dy * dy2 ) / par1;
164 double par3 = _dx * dy2 - _dy * dx2;
165 double par4 = rho * rho * par1 - par3 * par3;
166
167 if ( par4 < 0. ) return 0;
168
169 par4 = std::sqrt( par4 ) / par1;
170 double delta = par2 + par4;
171
172 if ( delta >= 0. && delta < 1. )
173 {
174 z = _layer->zf() + delta * ( _layer->zb() - _layer->zf() );
175 return 1;
176 }
177 else
178 {
179 delta = par2 - par4;
180 if ( delta >= 0. && delta < 1. )
181 {
182 z = _layer->zf() + delta * ( _layer->zb() - _layer->zf() );
183 return 1;
184 }
185 }
186 return 0;
187}
188
190 if ( ( _neighbor[2]->state() & FTWireHit ) && ( _neighbor[3]->state() & FTWireHit ) )
191 {
192 _state |= FTWireHitInvalid;
193 _neighbor[2]->setState( _neighbor[2]->state() | FTWireHitInvalid );
194 _neighbor[3]->setState( _neighbor[3]->state() | FTWireHitInvalid );
195 }
196}
197
198const FTWire* FTWire::left() const {
199 auto geom = FTGeom::instance();
200 if ( _wireId == geom->wire2wireStartLayer( _wireId ) )
201 return geom->getWire( geom->wire2wireEndLayer( _wireId ) );
202 else return geom->getWire( _wireId - 1 );
203}
204
205const FTWire* FTWire::right() const {
206 auto geom = FTGeom::instance();
207 if ( _wireId == geom->wire2wireEndLayer( _wireId ) )
208 return geom->getWire( geom->wire2wireStartLayer( _wireId ) );
209 else return geom->getWire( _wireId + 1 );
210}
211
212#ifdef FZISAN_DEBUG
213Gen_hepevt* FTWire::hep( Gen_hepevt* src ) { return _hep = src; }
214
215Gen_hepevt* FTWire::hep() const { return _hep; }
216#endif
const Int_t n
#define FTWireHit
Definition FTWire.h:3
#define FTWireHitInvalid
Definition FTWire.h:4
static FTGeom * instance()
Definition FTGeom.cxx:162
const int wire2wireIndexLayer(const int wire_id)
Definition FTGeom.h:78
const int localLayerId() const
returns local-layer ID
Definition FTLayer.h:23
const int localId() const
returns local ID
Definition FTWire.cxx:42
void initNeighbor()
initNeighbor
Definition FTWire.cxx:48
int z(const Lpav &la, double &z) const
returns z for track la
Definition FTWire.cxx:157
void clear()
clear
Definition FTWire.cxx:148
void chk_left_and_right()
check neighbors of phi-side and raise invalid flag if both hits
Definition FTWire.cxx:189
FTLayer * layer() const
returns layer
Definition FTWire.h:60
FTWire(const float x, const float y, const float dx, const float dy, const int wireId, FTLayer *layer, const float phi)
constructors
Definition FTWire.cxx:8
void wireId(int wireID)
set wireId
Definition FTWire.h:132
float distance_z() const
returns z_distance from the center of wire by drift distance
Definition FTWire.cxx:46
const float x() const
returns position x
Definition FTWire.h:48
FTWire()
Definition FTWire.cxx:26
unsigned state() const
returns state
Definition FTWire.h:78
float phi() const
returns phi
Definition FTWire.h:54
const float y() const
returns position y
Definition FTWire.h:51
HepVector center() const