00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #define TMDCWire_INLINE_DEFINE_HERE
00014 #include "CLHEP/String/Strings.h"
00015
00016
00017
00018 #include "MdcGeomSvc/MdcGeomSvc.h"
00019 #include "TrkReco/TMDC.h"
00020 #include "TrkReco/TMDCWire.h"
00021 #include "TrkReco/TMDCTsf.h"
00022 #include "TrkReco/TMDCUtil.h"
00023
00024 TMDC *
00025 TMDCWire::_cdc = 0;
00026
00027
00028
00029
00030
00031
00032 TMDCWire::TMDCWire(const MdcGeoWire * w, TMDCLayer * l)
00033 : _forwardPosition(w->Backward()*0.1),
00034 _backwardPosition(w->Forward()*0.1),
00035 _tension(w->Tension()),
00036 _direction(w->Backward() -w->Forward()) {
00037
00038
00039
00040 _state = 0;
00041 _geo = w;
00042 _id = w->Id();
00043 _localId = w->Cell();
00044 _layerId = w->Layer();
00045 _layer = l;
00046 _tsf = 0;
00047 _hit = 0;
00048 _xyPosition = 0.5 * (_forwardPosition + _backwardPosition);
00049 _xyPosition.setZ(0.);
00050 _direction = _direction.unit();
00051 }
00052
00053 TMDCWire::~TMDCWire() {
00054 }
00055
00056 void
00057 TMDCWire::dump(const std::string & msg, const std::string & pre) const {
00058 std::cout << pre;
00059 std::cout << "w " << _id;
00060 std::cout << ",local " << _localId;
00061 std::cout << ",layer " << _layerId;
00062 std::cout << ",super layer " << superLayerId();
00063 std::cout << ",local layer " << localLayerId();
00064 std::cout << std::endl;
00065 if (msg.find("neighbor") != std::string::npos || msg.find("detail") != std::string::npos) {
00066 for (unsigned i = 0; i < 6; i++)
00067 if (neighbor(i))
00068 neighbor(i)->dump("", pre + itostring(i) + " ");
00069 }
00070 if (msg.find("tsf") != std::string::npos || msg.find("detail") != std::string::npos) {
00071 if (_tsf) _tsf->dump("", pre + " ");
00072 }
00073 }
00074
00075 const HepPoint3D
00076 TMDCWire::xyPosition(double z) const {
00077 double A=47.35E-6/_tension;
00078 HepPoint3D x0 =(z - _backwardPosition.z()) /_direction.z() * _direction + _backwardPosition;
00079
00080 double zinit = x0.z();
00081 HepVector3D wire;
00082 wire.setX(_forwardPosition.x()-_backwardPosition.x());
00083 wire.setY(_forwardPosition.y()-_backwardPosition.y());
00084 wire.setZ(_forwardPosition.z()-_backwardPosition.z());
00085 double lxz=sqrt(wire.z()*wire.z()+wire.x()*wire.x());
00086 double Zp = (zinit - _backwardPosition.z())*lxz/wire.z();
00087 double x=_direction.x()*(zinit-_backwardPosition.z())/_direction.z() + _backwardPosition.x();
00088 double y=(A*(Zp-lxz)+wire.y()/lxz)*Zp+_backwardPosition.y();
00089 x0.setX(x);
00090 x0.setY(y);
00091 return x0;
00092 }
00093
00094 const TMDCWire * const
00095 TMDCWire::neighbor(unsigned i) const {
00096 if (_cdc == 0) _cdc = TMDC::getTMDC();
00097 static const unsigned nLayers = _cdc->nLayers();
00098
00099
00100 unsigned l = layerId();
00101 int local = (int) localId();
00102 float phi0 = _cdc->layer(l)->offset();
00103 int nWir = (int) _cdc->layer(l)->nWires();
00104 float phi = phi0 + local*2*pi/nWir;
00105 unsigned s = superLayerId();
00106
00107
00108 if (i == WireInnerLeft || i == WireInnerRight) {
00109 if (l == 0) return 0;
00110 --l;
00111 if (_cdc->layer(l)->superLayerId() != s) return 0;
00112 phi0 = _cdc->layer(l)->offset();
00113 nWir = _cdc->layer(l)->nWires();
00114 local = (int)((phi-phi0)/(2*pi/nWir));
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126 if (i == WireInnerLeft) return _cdc->wire(l, local);
00127 else return _cdc->wire(l, local + 1);
00128
00129
00130
00131 }
00132 else if (i == WireLeft || i == WireRight) {
00133
00134
00135
00136
00137
00138
00139 if (i == WireLeft) return _cdc->wire(l, local - 1);
00140 else return _cdc->wire(l, local + 1);
00141 }
00142 else if (i == WireOuterLeft || i == WireOuterRight) {
00143 if (l == nLayers - 1) return 0;
00144 ++l;
00145 if (_cdc->layer(l)->superLayerId() != s) return 0;
00146 phi0 = _cdc->layer(l)->offset();
00147 nWir = _cdc->layer(l)->nWires();
00148 local = (int)((phi-phi0)/(2*pi/nWir));
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159 if (i == WireOuterLeft) return _cdc->wire(l, local);
00160 else return _cdc->wire(l, local + 1);
00161 }
00162 return 0;
00163 }
00164
00165 int
00166 TMDCWire::localIdForPlus(void) const {
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237 if(_layerId == 0){
00238 if(_localId == 39)
00239 return -1;
00240 else return _localId;
00241 }
00242
00243 if(_layerId == 1){
00244 if(_localId == 43)
00245 return -1;
00246 else return _localId;
00247 }
00248
00249 if(_layerId == 2){
00250 if(_localId == 47)
00251 return -1;
00252 else return _localId;
00253 }
00254
00255 if(_layerId == 3){
00256 if(_localId == 55)
00257 return -1;
00258 else return _localId;
00259 }
00260
00261 if(_layerId == 4){
00262 if(_localId == 63)
00263 return -1;
00264 else return _localId;
00265 }
00266
00267 if(_layerId == 5){
00268 if(_localId == 71)
00269 return -1;
00270 else return _localId;
00271 }
00272
00273 if(_layerId == 6 || _layerId == 7){
00274 if(_localId == 79)
00275 return -1;
00276 else return _localId;
00277 }
00278
00279 if(_layerId == 8 || _layerId == 9){
00280 if(_localId == 75)
00281 return -1;
00282 else return _localId;
00283 }
00284
00285 if(_layerId == 10 || _layerId == 11){
00286 if(_localId == 87)
00287 return -1;
00288 else return _localId;
00289 }
00290
00291 if(_layerId == 12 || _layerId == 13){
00292 if(_localId == 99)
00293 return -1;
00294 else return _localId;
00295 }
00296
00297 if(_layerId == 14 || _layerId == 15){
00298 if(_localId == 111)
00299 return -1;
00300 else return _localId;
00301 }
00302
00303 if(_layerId == 16 || _layerId == 17){
00304 if(_localId == 127)
00305 return -1;
00306 else return _localId;
00307 }
00308
00309 if(_layerId == 18 || _layerId == 19){
00310 if(_localId == 139)
00311 return -1;
00312 else return _localId;
00313 }
00314
00315 if(_layerId >= 20 && _layerId <= 23){
00316 if(_localId == 159)
00317 return -1;
00318 else return _localId;
00319 }
00320
00321 if(_layerId >= 24 && _layerId <= 27){
00322 if(_localId == 175)
00323 return -1;
00324 else return _localId;
00325 }
00326
00327 if(_layerId >= 28 && _layerId <= 31){
00328 if(_localId == 207)
00329 return -1;
00330 else return _localId;
00331 }
00332
00333 if(_layerId >= 32 && _layerId <= 35){
00334 if(_localId == 239)
00335 return -1;
00336 else return _localId;
00337 }
00338
00339 if(_layerId >= 36 && _layerId <= 39){
00340 if(_localId == 255)
00341 return -1;
00342 else return _localId;
00343 }
00344
00345 if(_layerId >= 40 && _layerId <= 42){
00346 if(_localId == 287)
00347 return -1;
00348 else return _localId;
00349 }
00350
00351 return -1;
00352 }
00353
00354 int
00355 TMDCWire::localIdForMinus(void) const {
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424 if(_layerId == 0){
00425 if(_localId == 0)
00426 return 40;
00427 else return _localId;
00428 }
00429
00430 if(_layerId == 1){
00431 if(_localId == 0)
00432 return 44;
00433 else return _localId;
00434 }
00435
00436 if(_layerId == 2){
00437 if(_localId == 0)
00438 return 48;
00439 else return _localId;
00440 }
00441
00442 if(_layerId == 3){
00443 if(_localId == 0)
00444 return 56;
00445 else return _localId;
00446 }
00447
00448 if(_layerId == 4){
00449 if(_localId == 0)
00450 return 64;
00451 else return _localId;
00452 }
00453
00454 if(_layerId == 5){
00455 if(_localId == 0)
00456 return 72;
00457 else return _localId;
00458 }
00459
00460 if(_layerId == 6 || _layerId == 7){
00461 if(_localId == 0)
00462 return 80;
00463 else return _localId;
00464 }
00465
00466 if(_layerId == 8 || _layerId == 9){
00467 if(_localId == 0)
00468 return 76;
00469 else return _localId;
00470 }
00471
00472 if(_layerId == 10 || _layerId == 11){
00473 if(_localId == 0)
00474 return 88;
00475 else return _localId;
00476 }
00477
00478 if(_layerId == 12 || _layerId == 13){
00479 if(_localId == 0)
00480 return 100;
00481 else return _localId;
00482 }
00483
00484 if(_layerId == 14 || _layerId == 15){
00485 if(_localId == 0)
00486 return 112;
00487 else return _localId;
00488 }
00489
00490 if(_layerId == 16 || _layerId == 17){
00491 if(_localId == 0)
00492 return 128;
00493 else return _localId;
00494 }
00495
00496 if(_layerId == 18 || _layerId == 19){
00497 if(_localId == 0)
00498 return 140;
00499 else return _localId;
00500 }
00501
00502 if(_layerId >= 20 && _layerId <= 23){
00503 if(_localId == 0)
00504 return 160;
00505 else return _localId;
00506 }
00507
00508 if(_layerId >= 24 && _layerId <= 27){
00509 if(_localId == 0)
00510 return 176;
00511 else return _localId;
00512 }
00513
00514 if(_layerId >= 28 && _layerId <= 31){
00515 if(_localId == 0)
00516 return 208;
00517 else return _localId;
00518 }
00519
00520 if(_layerId >= 32 && _layerId <= 35){
00521 if(_localId == 0)
00522 return 240;
00523 else return _localId;
00524 }
00525
00526 if(_layerId >= 36 && _layerId <= 39){
00527 if(_localId == 0)
00528 return 256;
00529 else return _localId;
00530 }
00531
00532 if(_layerId >= 40 && _layerId <= 42){
00533 if(_localId == 0)
00534 return 288;
00535 else return _localId;
00536 }
00537 return -1;
00538 }
00539
00540 void
00541 TMDCWire::wirePosition(float z,
00542 HepPoint3D & xy,
00543 HepPoint3D & back,
00544 HepVector3D & dir) const {
00545 back = _backwardPosition;
00546
00547
00548 if (! (z > _backwardPosition.z() && z < _forwardPosition.z())) {
00549 xy = _xyPosition;
00550 dir = _direction;
00551 }
00552
00553
00554 int wireID = id();
00555 float wirePosition[3] = {0., 0., 0.};
00556 float dydz = 0;
00557 float ybSag = 0;
00558 float yfSag = 0;
00559
00560
00561
00562
00563
00564 xy.setX((double) wirePosition[0]);
00565 xy.setY((double) wirePosition[1]);
00566 xy.setZ((double) wirePosition[2]);
00567 back.setY((double) ybSag);
00568 HepVector3D v_aux(_forwardPosition.x() - _backwardPosition.x(),
00569 yfSag - ybSag,
00570 _forwardPosition.z() - _backwardPosition.z());
00571 dir = v_aux.unit();
00572
00573 return;
00574 }
00575
00576 int
00577 TMDCWire::localIdDifference(const TMDCWire & a) const {
00578
00579 #ifdef TRKRECO_DEBUG_DETAIL
00580 if (superLayerId() != a.superLayerId()) {
00581 std::cout << "TMDCWire::localIdDifference !!!";
00582 std::cout << "super layer assumption violation" << std::endl;
00583 }
00584 #endif
00585
00586 int diff = int(a.localId()) - int(localId());
00587 unsigned nWires = layer()->nWires();
00588 if (diff > 0) {
00589 int difR = nWires - diff;
00590 if (diff < difR) return diff;
00591 else return - difR;
00592 }
00593 else {
00594 int difR = nWires + diff;
00595 if (- diff < difR) return diff;
00596 else return difR;
00597 }
00598 }