00001
00002
00003
00004
00005
00006
00007
00008 #ifndef FTWire_FLAG_
00009 #define FTWire_FLAG_
00010
00011
00012 #define FTWireHit 1
00013 #define FTWireHitInvalid 2
00014 #define FTWireHitAppended 4
00015 #define FTWireHitAppendedOrInvalid 6
00016 #define FTWireNeighbor0 8
00017 #define FTWireNeighbor1 16
00018 #define FTWireNeighbor2 32
00019 #define FTWireNeighbor3 64
00020 #define FTWireNeighbor4 128
00021 #define FTWireNeighbor5 256
00022 #define FTWireHitSegment 16384
00023 #define FTWireHitLinked 131072
00024 #define FTWireHitRight 32768
00025 #define FTWireHitLeft 65536
00026
00027 #define FTWireFittingInvalid 0x10000000
00028 #define FTWireInvalid 0x20000000
00029 #define FTWireStateMask 0xf0000000
00030
00031 #ifndef M_PI
00032 #define M_PI 3.14159265358979323846
00033 #endif
00034
00035 #include "MdcFastTrkAlg/MdcFastTrkAlg.h"
00036 #include "MdcFastTrkAlg/FTLayer.h"
00037 #include "MdcFastTrkAlg/FTSuperLayer.h"
00038 #include "MdcFastTrkAlg/FTList.h"
00039 #include "TrackUtil/Lpav.h"
00040 #include "CLHEP/Matrix/Vector.h"
00041 using namespace CLHEP;
00042
00043 class FTWire{
00044 public:
00046 FTWire(const float x, const float y, const float dx, const float dy,
00047 const FTLayer &, const int localID, FTWire * const vt);
00048
00049 FTWire();
00051 ~FTWire();
00052
00053 public:
00054
00056 void initNeighbor(void);
00057
00059 const float x(void) const;
00060
00062 const float y(void) const;
00063
00065 float phi(void) const;
00066
00068 const int localId(void) const;
00069
00071 const FTLayer & layer(void) const;
00072
00074 FTWire ** neighborPtr(void);
00075
00077 float distance(void) const;
00078
00080 float distance_z(void) const;
00081
00083 float t0(void) const;
00084
00086 float pedestal(void) const;
00087
00089 unsigned state(void) const;
00090
00092 unsigned stateAND(const unsigned mask) const;
00093
00095 int z(const Lpav & la, double & z) const;
00096
00098 float time(void) const;
00099
00100
00101 float getAdc(void) const;
00102
00103
00104 float getChi2(void) const;
00105
00106 public:
00108 void clear(void);
00109
00111 float distance(const float distance);
00112
00114 float t0(const float t0);
00115
00117 float pedestal(const float ped);
00118
00120 unsigned state(const unsigned state);
00121
00123 void stateOR(const unsigned mask);
00124
00126 void stateXOR(const unsigned mask);
00127
00129 void stateORXOR(const unsigned mask);
00130
00132 void chk_left_and_right(void);
00133
00135 float time(float t);
00136
00138 void wireId(int wireID);
00139
00141 int getWireId(void);
00142
00144 void setAdc(float adc);
00145
00147 void setChi2(float chi2);
00148
00149 private:
00151 const FTWire * left(void) const;
00152
00154 const FTWire * right(void) const;
00155
00157 void getInnerNeighbor(FTWire * const vtWire);
00158
00160 void getOuterNeighbor(FTWire * const vtWire);
00161
00163 void getMidNeighbor(void);
00164
00165 private:
00166 const float _x;
00167 const float _y;
00168 const float _dx;
00169 const float _dy;
00170 const FTLayer & _layer;
00171 FTWire *const & _wire;
00172 const int _localId;
00173 const float _phi;
00174 int _wireId;
00175 float _distance;
00176 float _t0;
00177 float _time;
00178 float _pedestal;
00179 unsigned int _state;
00180 FTWire * _neighbor[6];
00181 float m_posx;
00182 float m_posy;
00183 float m_posz;
00184 float m_adc;
00185 float m_chi2;
00186 };
00187
00188
00189 #ifdef FTWire_NO_INLINE
00190 #define inline
00191 #else
00192 #undef inline
00193 #define FTWire_INLINE_DEFINE_HERE
00194 #endif
00195
00196 #ifdef FTWire_INLINE_DEFINE_HERE
00197
00198 inline
00199 FTWire::FTWire(const float x, const float y,
00200 const float dx, const float dy, const FTLayer & layer,
00201 const int localID, FTWire * const vt)
00202 : _x(x),
00203 _y(y),
00204 _dx(dx),
00205 _dy(dy),
00206 _layer(layer),
00207 _wire(vt),
00208 _localId(localID),
00209 _phi((const float)2*M_PI*_localId/(float)_layer.NWire()+_layer.offset()),
00210
00211
00212 _distance(0),
00213 _t0(0),
00214 _time(0),
00215 m_adc(0),
00216 _pedestal(0),
00217 _state(FTWireHitInvalid)
00218 {
00219 getMidNeighbor();
00220 }
00221
00222 inline
00223 FTWire::FTWire()
00224 : _x(0),
00225 _y(0),
00226 _dx(0),
00227 _dy(0),
00228 _layer(*(FTLayer *)NULL),
00229 _wire(NULL),
00230 _localId(0),
00231
00232 _phi(0),
00233 _distance(0),
00234 _t0(0),
00235 _time(0),
00236 m_adc(0),
00237 _pedestal(0),
00238 _state(FTWireHitInvalid)
00239 {
00240 _neighbor[0] = NULL;
00241 _neighbor[1] = NULL;
00242 _neighbor[2] = NULL;
00243 _neighbor[3] = NULL;
00244 _neighbor[4] = NULL;
00245 _neighbor[5] = NULL;
00246 }
00247
00248 inline
00249 FTWire::~FTWire()
00250 {
00251 }
00252
00253 inline
00254 void
00255 FTWire::initNeighbor()
00256 {
00257 getInnerNeighbor(_wire);
00258 getOuterNeighbor(_wire);
00259
00260
00261
00262
00263
00264
00265
00266
00267 }
00268 inline
00269 void
00270 FTWire::getInnerNeighbor(FTWire * const vtWire)
00271 {
00272 if (!_layer.localLayerId()) {
00273 _neighbor[0] = _neighbor[1] = vtWire;
00274 return;
00275 }
00276 float thisPhi = phi();
00277 const FTLayer * pLayer = &_layer;
00278 int n = (*(pLayer-1)).NWire();
00279 int low=0, high=n-1, mid = 0;
00280 int innerPosition = 1;
00281 FTWire * lastInnerPointer = this - localId() - 1;
00282 while (low<=high){
00283 mid=(low+high)/2;
00284 if ((*(lastInnerPointer-mid)).phi() <= thisPhi)
00285 high=mid-1;
00286 else
00287 low=mid+1;
00288 }
00289
00290 innerPosition = mid;
00291 if((*(lastInnerPointer-innerPosition)).phi() <= thisPhi) {
00292 _neighbor[0] = lastInnerPointer-innerPosition;
00293 if(innerPosition == 0) _neighbor[1] = lastInnerPointer-n+1;
00294 else _neighbor[1] = lastInnerPointer-innerPosition+1;
00295 } else {
00296 if((innerPosition+1) == n) _neighbor[0] = lastInnerPointer;
00297 else _neighbor[0] = lastInnerPointer-innerPosition-1;
00298 _neighbor[1] = lastInnerPointer-innerPosition;
00299 }
00300
00301 }
00302
00303 inline
00304 void
00305 FTWire::getOuterNeighbor(FTWire * const vtWire)
00306 {
00307 if (_layer.localLayerId()==_layer.superLayer().layerMaxId()) {
00308 _neighbor[4] = _neighbor[5] = vtWire;
00309 return;
00310 }
00311 float thisPhi = phi();
00312 const FTLayer * pLayer = &_layer;
00313 int n = (*(pLayer+1)).NWire();
00314 int low=0, high=n-1, mid = 0;
00315 int position;
00316 FTWire * firstPointer = this + _layer.NWire() - localId();
00317 while (low<=high){
00318 mid=(low+high)/2;
00319 if ((*(firstPointer+mid)).phi() > thisPhi)
00320 high=mid-1;
00321 else
00322 low=mid+1;
00323 }
00324
00325 position = mid;
00326 if((*(firstPointer+position)).phi() <= thisPhi) {
00327 _neighbor[4] = firstPointer+position;
00328 if((position+1) == n) _neighbor[5] = firstPointer;
00329 else _neighbor[5] = firstPointer+position+1;
00330 } else {
00331 if((position-1) == -1) _neighbor[4] = firstPointer + n - 1;
00332 else _neighbor[4] = firstPointer+position-1;
00333 _neighbor[5] = firstPointer+position;
00334 }
00335 }
00336
00337 inline
00338 void
00339 FTWire::getMidNeighbor(void)
00340 {
00341 _neighbor[2] = (FTWire *) left();
00342 _neighbor[3] = (FTWire *) right();
00343 }
00344
00345 inline
00346 void
00347 FTWire::clear(void)
00348 {
00349 _distance = 0.;
00350 _time = 0.;
00351 _t0 = 0.;
00352 m_adc = 0.0;
00353 _pedestal = 0.;
00354 _state = FTWireHitInvalid;
00355 }
00356
00357 inline
00358 const FTLayer &
00359 FTWire::layer(void) const
00360 {
00361 return _layer;
00362 }
00363
00364 inline
00365 const float
00366 FTWire::x(void) const
00367 {
00368 return _x;
00369 }
00370
00371 inline
00372 const float
00373 FTWire::y(void) const
00374 {
00375 return _y;
00376 }
00377
00378 inline
00379 const int
00380 FTWire::localId(void) const
00381 {
00382 return _localId;
00383 }
00384
00385 inline
00386 FTWire **
00387 FTWire::neighborPtr(void)
00388 {
00389 return _neighbor;
00390 }
00391
00392 inline
00393 float
00394 FTWire::phi(void) const
00395 {
00396 return _phi;
00397 }
00398
00399 inline
00400 float
00401 FTWire::distance(void) const
00402 {
00403 return _distance;
00404 }
00405
00406 inline
00407 float
00408 FTWire::distance_z(void) const
00409 {
00410 return _distance * std::fabs(_layer.tanSlant());
00411 }
00412
00413 inline
00414 float
00415 FTWire::distance(const float distance)
00416 {
00417 return _distance = distance;
00418 }
00419
00420 inline
00421 float
00422 FTWire::t0(void) const
00423 {
00424 return _t0;
00425 }
00426
00427 inline
00428 float
00429 FTWire::t0(const float t0)
00430 {
00431 return _t0 = t0;
00432 }
00433
00434 inline
00435 float
00436 FTWire::pedestal(void) const
00437 {
00438 return _pedestal;
00439 }
00440
00441 inline
00442 float
00443 FTWire::pedestal(const float ped)
00444 {
00445 return _pedestal = ped;
00446 }
00447
00448 inline
00449 float
00450 FTWire::time(float t)
00451 {
00452 return _time = t;
00453 }
00454
00455 inline
00456 float
00457 FTWire::time(void) const
00458 {
00459 return _time;
00460 }
00461
00462 #ifdef FZISAN_DEBUG
00463 inline
00464 Gen_hepevt *
00465 FTWire::hep(Gen_hepevt * src)
00466 {
00467 return _hep = src;
00468 }
00469
00470 inline
00471 Gen_hepevt *
00472 FTWire::hep(void) const
00473 {
00474 return _hep;
00475 }
00476 #endif
00477
00478 inline
00479 unsigned
00480 FTWire::state(void) const
00481 {
00482 return _state;
00483 }
00484
00485 inline
00486 unsigned
00487 FTWire::state(const unsigned state)
00488 {
00489 return _state = (_state&FTWireStateMask)|state;
00490 }
00491
00492 inline
00493 unsigned
00494 FTWire::stateAND(const unsigned mask) const
00495 {
00496 return _state&mask;
00497 }
00498
00499 inline
00500 void
00501 FTWire::stateOR(const unsigned mask)
00502 {
00503 _state|=mask;
00504 }
00505
00506 inline
00507 void
00508 FTWire::stateXOR(const unsigned mask)
00509 {
00510 _state^=mask;
00511 }
00512
00513 inline
00514 void
00515 FTWire::stateORXOR(const unsigned mask)
00516 {
00517 _state=(_state|mask)^mask;
00518 }
00519
00520 inline
00521 int
00522 FTWire::z(const Lpav & la, double & z) const{
00523 HepVector center = la.center();
00524 double rho = la.radius();
00525 double dx2 = center(1) - _x;
00526 double dy2 = center(2) - _y;
00527 double par1 = _dx*_dx + _dy*_dy;
00528 double par2 = (_dx*dx2 + _dy*dy2)/par1;
00529 double par3 = _dx*dy2 - _dy*dx2;
00530 double par4 = rho*rho*par1 - par3*par3;
00531 if (par4<0.) return 0;
00532 par4 = std::sqrt(par4)/par1;
00533 double delta = par2 + par4;
00534
00535 if (delta>=0. && delta<1.){
00536
00537 z = _layer.zf()+delta*(_layer.zb()-_layer.zf());
00538 return 1;
00539 }else{
00540 delta = par2 - par4;
00541 if (delta>=0. && delta<1.){
00542
00543 z = _layer.zf()+delta*(_layer.zb()-_layer.zf());
00544 return 1;
00545 }
00546 }
00547 return 0;
00548 }
00549
00550 inline
00551 void
00552 FTWire::chk_left_and_right(void){
00553 if (((**(_neighbor+2))._state&FTWireHit) &&
00554 ((**(_neighbor+3))._state&FTWireHit)){
00555 _state |= FTWireHitInvalid;
00556 (**(_neighbor+2))._state |= FTWireHitInvalid;
00557 (**(_neighbor+3))._state |= FTWireHitInvalid;
00558 }
00559 }
00560
00561 inline
00562 const FTWire *
00563 FTWire::left(void) const{
00564 const FTWire * tmp = this;
00565 if (!_localId) tmp += _layer.NWire();
00566 return --tmp;
00567 }
00568
00569 inline
00570 const FTWire *
00571 FTWire::right(void) const{
00572 const FTWire * tmp = this;
00573 if (_localId == (_layer.NWire()-1)) {
00574 tmp -= _layer.NWire();
00575 }
00576 return ++tmp;
00577 }
00578
00579
00580 inline void FTWire::wireId(int wireID){
00581 _wireId = wireID;
00582 }
00583
00584
00585 inline int FTWire::getWireId(void){
00586 return _wireId;
00587 }
00588
00589
00590
00591 inline float FTWire::getAdc(void) const{
00592 return m_adc;
00593 }
00594
00595 inline void FTWire::setAdc(float adc) {
00596 m_adc = adc;
00597 }
00598
00599
00600 inline float FTWire::getChi2(void) const{
00601 return m_chi2;
00602 }
00603
00604 inline void FTWire::setChi2(float chi2) {
00605 m_chi2 = chi2;
00606 }
00607
00608 #endif
00609
00610 #undef inline
00611
00612 #endif