BOSS 7.0.9
BESIII Offline Software System
Loading...
Searching...
No Matches
FTWire.h
Go to the documentation of this file.
1// -*- C++ -*-
2//
3// Package: MdcFastTrkAlg
4// Module: FTWire
5//
6// Description: wire class for MdcFastTrkAlg
7
8#ifndef FTWire_FLAG_
9#define FTWire_FLAG_
10
11//...Defs...
12#define FTWireHit 1
13#define FTWireHitInvalid 2
14#define FTWireHitAppended 4
15#define FTWireHitAppendedOrInvalid 6
16#define FTWireNeighbor0 8
17#define FTWireNeighbor1 16
18#define FTWireNeighbor2 32
19#define FTWireNeighbor3 64
20#define FTWireNeighbor4 128
21#define FTWireNeighbor5 256
22#define FTWireHitSegment 16384
23#define FTWireHitLinked 131072
24#define FTWireHitRight 32768
25#define FTWireHitLeft 65536
26
27#define FTWireFittingInvalid 0x10000000
28#define FTWireInvalid 0x20000000
29#define FTWireStateMask 0xf0000000
30
31#ifndef M_PI
32#define M_PI 3.14159265358979323846
33#endif
34
39#include "TrackUtil/Lpav.h"
40#include "CLHEP/Matrix/Vector.h"
41using namespace CLHEP;
42
43class FTWire{
44public:
45 /// constructors
46 FTWire(const float x, const float y, const float dx, const float dy,
47 const FTLayer &, const int localID, FTWire * const vt);
48
49 FTWire();
50 /// destructor
51 ~FTWire();
52
53public: //Selectors
54
55 /// initNeighbor
56 void initNeighbor(void);
57
58 /// returns position x
59 const float x(void) const;
60
61 /// returns position y
62 const float y(void) const;
63
64 /// returns phi
65 float phi(void) const;
66
67 /// returns local ID
68 const int localId(void) const;
69
70 /// returns layer
71 const FTLayer & layer(void) const;
72
73 /// returns pointer of neighbor array
74 FTWire ** neighborPtr(void);
75
76 /// returns drift distance
77 float distance(void) const;
78
79 /// returns z_distance from the center of wire by drift distance
80 float distance_z(void) const;
81
82 /// returns t0 read at begin run
83 float t0(void) const;
84
85 /// returns pedestal read at begin run
86 float pedestal(void) const;
87
88 /// returns state
89 unsigned state(void) const;
90
91 /// returns state bit
92 unsigned stateAND(const unsigned mask) const;
93
94 /// returns z for track la
95 int z(const Lpav & la, double & z) const;
96
97 /// rerurns TDC time(after t0 subtraction)
98 float time(void) const;
99
100 // wangdy add:return ADC value
101 float getAdc(void) const;
102
103 //max add:return residual
104 float getChi2(void) const;
105
106public: // Modifires
107 /// clear
108 void clear(void);
109
110 /// set drift distance
111 float distance(const float distance);
112
113 /// set t0 at begin-run
114 float t0(const float t0);
115
116 /// set pedestal at begin-run
117 float pedestal(const float ped);
118
119 /// set state
120 unsigned state(const unsigned state);
121
122 /// set state bit
123 void stateOR(const unsigned mask);
124
125 /// invert state bit
126 void stateXOR(const unsigned mask);
127
128 /// reset state bit
129 void stateORXOR(const unsigned mask);
130
131 /// check neighbors of phi-side and raise invalid flag if both hits
132 void chk_left_and_right(void);
133
134 /// reset time
135 float time(float t);
136
137 /// set wireId
138 void wireId(int wireID);
139
140 /// get wireId
141 int getWireId(void);
142
143 /// wangdy add:set Adc value
144 void setAdc(float adc);
145
146 /// set residual fit chi2
147 void setChi2(float chi2);
148
149private: //private member functions
150 /// returns left wire;
151 const FTWire * left(void) const;
152
153 /// returns left wire;
154 const FTWire * right(void) const;
155
156 /// compute inner Neighbor
157 void getInnerNeighbor(FTWire * const vtWire);
158
159 /// compute outer Neighbor
160 void getOuterNeighbor(FTWire * const vtWire);
161
162 /// compute mid Neighbor
163 void getMidNeighbor(void);
164
165private: //private data members
166 const float _x;
167 const float _y;
168 const float _dx;
169 const float _dy;
170 const FTLayer & _layer;
171 FTWire *const & _wire;
172 const int _localId;
173 const float _phi;
174 int _wireId;
175 float _distance;
176 float _t0;
177 float _time;
178 float _pedestal;
179 unsigned int _state;
180 FTWire * _neighbor[6];
181 float m_posx;
182 float m_posy;
183 float m_posz;
184 float m_adc; //wangdy adds
185 float m_chi2; //max adds
186};
187
188//----------------------------------------------
189#ifdef FTWire_NO_INLINE
190#define inline
191#else
192#undef inline
193#define FTWire_INLINE_DEFINE_HERE
194#endif
195
196#ifdef FTWire_INLINE_DEFINE_HERE
197
198inline
199FTWire::FTWire(const float x, const float y,
200 const float dx, const float dy, const FTLayer & layer,
201 const int localID, FTWire * const vt)
202 : _x(x), // x position in z = 0;
203 _y(y), // y position in z = 0;
204 _dx(dx),
205 _dy(dy),
206 _layer(layer),
207 _wire(vt),
208 _localId(localID),
209 _phi((const float)2*M_PI*_localId/(float)_layer.NWire()+_layer.offset()),
210 //_wireId(wireID),
211 //_hep(NULL),
212 _distance(0),
213 _t0(0),
214 _time(0),
215 m_adc(0),
216 _pedestal(0),
217 _state(FTWireHitInvalid)
218{
219 getMidNeighbor();
220}
221
222inline
224 : _x(0),
225 _y(0),
226 _dx(0),
227 _dy(0),
228 _layer(*(FTLayer *)NULL),
229 _wire(NULL),
230 _localId(0),
231 //_wireId(0),
232 _phi(0),
233 _distance(0),
234 _t0(0),
235 _time(0),
236 m_adc(0),
237 _pedestal(0),
238 _state(FTWireHitInvalid)
239{
240 _neighbor[0] = NULL;
241 _neighbor[1] = NULL;
242 _neighbor[2] = NULL;
243 _neighbor[3] = NULL;
244 _neighbor[4] = NULL;
245 _neighbor[5] = NULL;
246}
247
248inline
250{
251}
252
253inline
254void
256{
257 getInnerNeighbor(_wire);
258 getOuterNeighbor(_wire);
259 /*cout << "_layer.layerId()::" << _layer.layerId() << endl;
260 cout << "The WireId ::" << _localId << endl;
261 cout << "Its neighbor 0 ::" << _neighbor[0]->localId() << endl;
262 cout << "Its neighbor 1 ::" << _neighbor[1]->localId() << endl;
263 cout << "Its neighbor 2 ::" << _neighbor[2]->localId() << endl;
264 cout << "Its neighbor 3 ::" << _neighbor[3]->localId() << endl;
265 cout << "Its neighbor 4 ::" << _neighbor[4]->localId() << endl;
266 cout << "Its neighbor 5 ::" << _neighbor[5]->localId() << endl;*/
267}
268inline
269void
270FTWire::getInnerNeighbor(FTWire * const vtWire)
271{
272 if (!_layer.localLayerId()) {
273 _neighbor[0] = _neighbor[1] = vtWire;
274 return;
275 }
276 float thisPhi = phi();
277 const FTLayer * pLayer = &_layer;
278 int n = (*(pLayer-1)).NWire();
279 int low=0, high=n-1, mid = 0;
280 int innerPosition = 1;
281 FTWire * lastInnerPointer = this - localId() - 1;
282 while (low<=high){
283 mid=(low+high)/2;
284 if ((*(lastInnerPointer-mid)).phi() <= thisPhi)
285 high=mid-1;
286 else
287 low=mid+1;
288 }
289
290 innerPosition = mid;
291 if((*(lastInnerPointer-innerPosition)).phi() <= thisPhi) {
292 _neighbor[0] = lastInnerPointer-innerPosition;
293 if(innerPosition == 0) _neighbor[1] = lastInnerPointer-n+1;
294 else _neighbor[1] = lastInnerPointer-innerPosition+1;
295 } else {
296 if((innerPosition+1) == n) _neighbor[0] = lastInnerPointer;
297 else _neighbor[0] = lastInnerPointer-innerPosition-1;
298 _neighbor[1] = lastInnerPointer-innerPosition;
299 }
300
301}
302
303inline
304void
305FTWire::getOuterNeighbor(FTWire * const vtWire)
306{
307 if (_layer.localLayerId()==_layer.superLayer().layerMaxId()) {
308 _neighbor[4] = _neighbor[5] = vtWire;
309 return;
310 }
311 float thisPhi = phi();
312 const FTLayer * pLayer = &_layer;
313 int n = (*(pLayer+1)).NWire();
314 int low=0, high=n-1, mid = 0;
315 int position;
316 FTWire * firstPointer = this + _layer.NWire() - localId();
317 while (low<=high){
318 mid=(low+high)/2;
319 if ((*(firstPointer+mid)).phi() > thisPhi)
320 high=mid-1;
321 else
322 low=mid+1;
323 }
324
325 position = mid;
326 if((*(firstPointer+position)).phi() <= thisPhi) {
327 _neighbor[4] = firstPointer+position;
328 if((position+1) == n) _neighbor[5] = firstPointer;
329 else _neighbor[5] = firstPointer+position+1;
330 } else {
331 if((position-1) == -1) _neighbor[4] = firstPointer + n - 1;
332 else _neighbor[4] = firstPointer+position-1;
333 _neighbor[5] = firstPointer+position;
334 }
335}
336
337inline
338void
339FTWire::getMidNeighbor(void)
340{
341 _neighbor[2] = (FTWire *) left();
342 _neighbor[3] = (FTWire *) right();
343}
344
345inline
346void
348{
349 _distance = 0.;
350 _time = 0.;
351 _t0 = 0.;
352 m_adc = 0.0;
353 _pedestal = 0.;
354 _state = FTWireHitInvalid;
355}
356
357inline
358const FTLayer &
359FTWire::layer(void) const
360{
361 return _layer;
362}
363
364inline
365const float
366FTWire::x(void) const
367{
368 return _x;
369}
370
371inline
372const float
373FTWire::y(void) const
374{
375 return _y;
376}
377
378inline
379const int
381{
382 return _localId;
383}
384
385inline
386FTWire **
388{
389 return _neighbor;
390}
391
392inline
393float
394FTWire::phi(void) const
395{
396 return _phi;
397}
398
399inline
400float
402{
403 return _distance;
404}
405
406inline
407float
409{
410 return _distance * std::fabs(_layer.tanSlant());
411}
412
413inline
414float
415FTWire::distance(const float distance)
416{
417 return _distance = distance;
418}
419
420inline
421float
422FTWire::t0(void) const
423{
424 return _t0;
425}
426
427inline
428float
429FTWire::t0(const float t0)
430{
431 return _t0 = t0;
432}
433
434inline
435float
437{
438 return _pedestal;
439}
440
441inline
442float
443FTWire::pedestal(const float ped)
444{
445 return _pedestal = ped;
446}
447
448inline
449float
451{
452 return _time = t;
453}
454
455inline
456float
457FTWire::time(void) const
458{
459 return _time;
460}
461
462#ifdef FZISAN_DEBUG
463inline
465FTWire::hep(Gen_hepevt * src)
466{
467 return _hep = src;
468}
469
470inline
472FTWire::hep(void) const
473{
474 return _hep;
475}
476#endif
477
478inline
479unsigned
480FTWire::state(void) const
481{
482 return _state;
483}
484
485inline
486unsigned
487FTWire::state(const unsigned state)
488{
489 return _state = (_state&FTWireStateMask)|state;
490}
491
492inline
493unsigned
494FTWire::stateAND(const unsigned mask) const
495{
496 return _state&mask;
497}
498
499inline
500void
501FTWire::stateOR(const unsigned mask)
502{
503 _state|=mask;
504}
505
506inline
507void
508FTWire::stateXOR(const unsigned mask)
509{
510 _state^=mask;
511}
512
513inline
514void
515FTWire::stateORXOR(const unsigned mask)
516{
517 _state=(_state|mask)^mask;
518}
519
520inline
521int
522FTWire::z(const Lpav & la, double & z) const{
523 HepVector center = la.center();
524 double rho = la.radius();
525 double dx2 = center(1) - _x;
526 double dy2 = center(2) - _y;
527 double par1 = _dx*_dx + _dy*_dy;
528 double par2 = (_dx*dx2 + _dy*dy2)/par1;
529 double par3 = _dx*dy2 - _dy*dx2;
530 double par4 = rho*rho*par1 - par3*par3;
531 if (par4<0.) return 0;
532 par4 = std::sqrt(par4)/par1;
533 double delta = par2 + par4;
534 //double delta = 0.5;
535 if (delta>=0. && delta<1.){
536 //z = _layer.zb()+delta*(_layer.zf()-_layer.zb());
537 z = _layer.zf()+delta*(_layer.zb()-_layer.zf());
538 return 1;
539 }else{
540 delta = par2 - par4;
541 if (delta>=0. && delta<1.){
542 //z = _layer.zb()+delta*(_layer.zf()-_layer.zb());
543 z = _layer.zf()+delta*(_layer.zb()-_layer.zf());
544 return 1;
545 }
546 }
547 return 0;
548}
549
550inline
551void
553 if (((**(_neighbor+2))._state&FTWireHit) &&
554 ((**(_neighbor+3))._state&FTWireHit)){
555 _state |= FTWireHitInvalid;
556 (**(_neighbor+2))._state |= FTWireHitInvalid;
557 (**(_neighbor+3))._state |= FTWireHitInvalid;
558 }
559}
560
561inline
562const FTWire *
563FTWire::left(void) const{
564 const FTWire * tmp = this;
565 if (!_localId) tmp += _layer.NWire();
566 return --tmp;
567}
568
569inline
570const FTWire *
571FTWire::right(void) const{
572 const FTWire * tmp = this;
573 if (_localId == (_layer.NWire()-1)) {
574 tmp -= _layer.NWire();
575 }
576 return ++tmp;
577}
578
579// set wireId
580inline void FTWire::wireId(int wireID){
581 _wireId = wireID;
582}
583
584// get wireId
585inline int FTWire::getWireId(void){
586 return _wireId;
587}
588
589// ADC-related extractor and modifier
590// by wangdy
591inline float FTWire::getAdc(void) const{
592 return m_adc;
593}
594
595inline void FTWire::setAdc(float adc) {
596 m_adc = adc;
597}
598
599//chi2 by fit
600inline float FTWire::getChi2(void) const{
601 return m_chi2;
602}
603
604inline void FTWire::setChi2(float chi2) {
605 m_chi2 = chi2;
606}
607
608#endif
609
610#undef inline
611
612#endif /* FTWire_FLAG_ */
const double delta
const Int_t n
Double_t x[10]
#define FTWireHit
Definition: FTWire.h:12
#define FTWireStateMask
Definition: FTWire.h:29
#define FTWireHitInvalid
Definition: FTWire.h:13
#define M_PI
Definition: FTWire.h:32
NTuple::Array< double > m_adc
Definition: MdcHistItem.h:109
#define NULL
TTree * t
Definition: binning.cxx:23
const int localLayerId(void) const
returns local-layer ID
Definition: FTLayer.h:119
const int NWire(void) const
returns the number of wire
Definition: FTLayer.h:126
const float zf(void) const
returns z of forward end-plate
Definition: FTLayer.h:148
const float tanSlant(void) const
returns tangent of slant angle
Definition: FTLayer.h:133
const float zb(void) const
returns z of backward end-plate
Definition: FTLayer.h:155
const FTSuperLayer & superLayer(void) const
returns super-layer
Definition: FTLayer.h:183
const int layerMaxId(void) const
returns layer max ID
Definition: FTSuperLayer.h:209
Definition: FTWire.h:43
float getAdc(void) const
Definition: FTWire.h:591
float phi(void) const
returns phi
Definition: FTWire.h:394
~FTWire()
destructor
Definition: FTWire.h:249
const float y(void) const
returns position y
Definition: FTWire.h:373
int z(const Lpav &la, double &z) const
returns z for track la
Definition: FTWire.h:522
float distance(void) const
returns drift distance
Definition: FTWire.h:401
float getChi2(void) const
Definition: FTWire.h:600
unsigned stateAND(const unsigned mask) const
returns state bit
Definition: FTWire.h:494
FTWire ** neighborPtr(void)
returns pointer of neighbor array
Definition: FTWire.h:387
unsigned state(void) const
returns state
Definition: FTWire.h:480
void initNeighbor(void)
initNeighbor
Definition: FTWire.h:255
const FTLayer & layer(void) const
returns layer
Definition: FTWire.h:359
void stateORXOR(const unsigned mask)
reset state bit
Definition: FTWire.h:515
float distance_z(void) const
returns z_distance from the center of wire by drift distance
Definition: FTWire.h:408
void chk_left_and_right(void)
check neighbors of phi-side and raise invalid flag if both hits
Definition: FTWire.h:552
void setAdc(float adc)
wangdy add:set Adc value
Definition: FTWire.h:595
const int localId(void) const
returns local ID
Definition: FTWire.h:380
int getWireId(void)
get wireId
Definition: FTWire.h:585
const float x(void) const
returns position x
Definition: FTWire.h:366
float pedestal(void) const
returns pedestal read at begin run
Definition: FTWire.h:436
void wireId(int wireID)
set wireId
Definition: FTWire.h:580
void stateXOR(const unsigned mask)
invert state bit
Definition: FTWire.h:508
void stateOR(const unsigned mask)
set state bit
Definition: FTWire.h:501
FTWire()
Definition: FTWire.h:223
float time(void) const
rerurns TDC time(after t0 subtraction)
Definition: FTWire.h:457
void clear(void)
clear
Definition: FTWire.h:347
void setChi2(float chi2)
set residual fit chi2
Definition: FTWire.h:604
float t0(void) const
returns t0 read at begin run
Definition: FTWire.h:422
double y[1000]