00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 #include "Stiostream.h"
00046 #include <math.h>
00047 #include <vector>
00048 #include <stdlib.h>
00049 #include <stdio.h>
00050
00051 #include "StTofrGeometry.h"
00052 #include "TFile.h"
00053 #include "TDataSet.h"
00054 #include "TDataSetIter.h"
00055 #include "StMaker.h"
00056
00057 #include "StMessMgr.h"
00058
00059
00060
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00080
00081 #ifdef __ROOT__
00082 ClassImp(StTofrNode)
00083 #endif
00084
00085 Bool_t StTofrNode::mDebug = kFALSE;
00086 Double_t const StTofrGeomSensor::mSensorDy = 10.35;
00087 char* const StTofrGeometry::sectorPref = "BSEC";
00088 char* const StTofrGeometry::trayPref = "BTRA";
00089 char* const StTofrGeometry::senPref = "BRMD";
00090
00091
00092 StTofrNode::StTofrNode(TVolumeView *element, TVolumeView *top)
00093 : fView(element), pView(element->GetPosition()), mMasterNode(top), mTransFlag(kFALSE)
00094 {
00095 UpdateMatrix();
00096 BuildMembers();
00097 }
00098
00099
00100 StTofrNode::~StTofrNode()
00101 {
00102 fView = 0;
00103 pView = 0;
00104 mMasterNode = 0;
00105 mTransFlag = kFALSE;
00106 }
00107
00108
00109 void StTofrNode::UpdateMatrix()
00110 {
00111
00112
00113
00114
00115
00116
00117
00118 mTransFlag = kFALSE;
00119 CalcMatrix(this, mTransMRS, mRotMRS);
00120 mTransFlag = kTRUE;
00121
00122 }
00123
00124
00125 void StTofrNode::CalcMatrix(StTofrNode* son,
00126 Double_t* trans, Double_t* rot, StTofrNode* mother)
00127 {
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159 Double_t xl[3], xm[3];
00160
00161
00162
00163
00164
00165 xl[0] = 0; xl[1] = 0; xl[2] = 0;
00166 ConvertPos(son,xl, mother,xm);
00167 trans[0] = xm[0];
00168 trans[1] = xm[1];
00169 trans[2] = xm[2];
00170
00171 xl[0] = 1; xl[1] = 0; xl[2] = 0;
00172 ConvertPos(son,xl, mother,xm);
00173 rot[0] = xm[0]-trans[0];
00174 rot[1] = xm[1]-trans[1];
00175 rot[2] = xm[2]-trans[2];
00176
00177 xl[0] = 0; xl[1] = 1; xl[2] = 0;
00178 ConvertPos(son,xl, mother,xm);
00179 rot[3] = xm[0]-trans[0];
00180 rot[4] = xm[1]-trans[1];
00181 rot[5] = xm[2]-trans[2];
00182
00183 xl[0] = 0; xl[1] = 0; xl[2] = 1;
00184 ConvertPos(son,xl, mother,xm);
00185 rot[6] = xm[0]-trans[0];
00186 rot[7] = xm[1]-trans[1];
00187 rot[8] = xm[2]-trans[2];
00188
00189 return;
00190 }
00191
00192
00193 void StTofrNode::ConvertPos(
00194 StTofrNode* from, const Double_t* pos_from,
00195 StTofrNode* to, Double_t* pos_to)
00196 {
00197 if (to==0) from->Local2Master(pos_from,pos_to);
00198 else {
00199 Double_t xg[3];
00200 from->Local2Master(pos_from,xg);
00201 to->Master2Local(xg,pos_to);
00202 }
00203
00204 return;
00205 }
00206
00207
00208 void StTofrNode::BuildMembers()
00209 {
00210
00211
00212
00213
00214 Double_t xl[3];
00215 Double_t xg[3];
00216 TBRIK *brik = dynamic_cast<TBRIK*>(GetShape());
00217
00218 if(!brik) { LOG_INFO << " no brik " << endm; return; }
00219
00220 Double_t dy = brik->GetDy();
00221 Double_t dz = brik->GetDz();
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236 xl[0] = 0; xl[1] = 0; xl[2] = -dz;
00237 Local2Master(xl, xg);
00238 mEtaMin = StThreeVectorD(xg[0],xg[1],xg[2]).pseudoRapidity();
00239
00240
00241 xl[0] = 0; xl[1] = 0; xl[2] = dz;
00242 Local2Master(xl, xg);
00243 mEtaMax = StThreeVectorD(xg[0],xg[1],xg[2]).pseudoRapidity();
00244
00245
00246 xl[0] = 0; xl[1] = -dy; xl[2] = 0;
00247 Local2Master(xl, xg);
00248 mPhiMin = StThreeVectorD(xg[0],xg[1],xg[2]).phi();
00249
00250
00251 xl[0] = 0; xl[1] = dy; xl[2] = 0;
00252 Local2Master(xl, xg);
00253 mPhiMax = StThreeVectorD(xg[0],xg[1],xg[2]).phi();
00254
00255 if (mEtaMin>mEtaMax) {
00256 Double_t tmp = mEtaMin;
00257 mEtaMin = mEtaMax;
00258 mEtaMax = tmp;
00259 }
00260
00261 if (mPhiMin>mPhiMax) {
00262 Double_t tmp = mPhiMin;
00263 mPhiMin = mPhiMax;
00264 mPhiMax = tmp;
00265 }
00266
00267 return;
00268 }
00269
00270
00271 void StTofrNode::Local2Master(const Double_t* local, Double_t* master)
00272 {
00273
00274
00275
00276
00277 if (!mTransFlag) {
00278 if (!mMasterNode) { LOG_INFO << " no Master! " << endm; return;}
00279 TVolumeView *son = GetfView();
00280 TVolumeView *mrs = GetTopNode();
00281
00282 TVolumePosition *pos = 0;
00283 pos = son->Local2Master(son, mrs);
00284 pos->Local2Master(local, master);
00285 delete pos;
00286 return;
00287 }
00288
00289
00290 Double_t x, y, z;
00291 x = local[0];
00292 y = local[1];
00293 z = local[2];
00294
00295 master[0] = mTransMRS[0] + mRotMRS[0]*x + mRotMRS[3]*y + mRotMRS[6]*z;
00296 master[1] = mTransMRS[1] + mRotMRS[1]*x + mRotMRS[4]*y + mRotMRS[7]*z;
00297 master[2] = mTransMRS[2] + mRotMRS[2]*x + mRotMRS[5]*y + mRotMRS[8]*z;
00298
00299 }
00300
00301
00302 void StTofrNode::Master2Local(const Double_t* master, Double_t* local)
00303 {
00304
00305
00306
00307
00308
00309 if (!mTransFlag) {
00310 LOG_INFO << " and No TVolumePosition::Master2Local is wrong, so do nothing" << endm;
00311 return;
00312 }
00313
00314
00315 Double_t x, y, z;
00316 x = master[0] - mTransMRS[0];
00317 y = master[1] - mTransMRS[1];
00318 z = master[2] - mTransMRS[2];
00319
00320 local[0] = mRotMRS[0]*x + mRotMRS[1]*y + mRotMRS[2]*z;
00321 local[1] = mRotMRS[3]*x + mRotMRS[4]*y + mRotMRS[5]*z;
00322 local[2] = mRotMRS[6]*x + mRotMRS[7]*y + mRotMRS[8]*z;
00323 }
00324
00325
00326 StThreeVectorD StTofrNode::YZPlaneNormal()
00327 {
00328
00329
00330
00331
00332
00333 Double_t ux[3], nx[3];
00334
00335 ux[0] = 1; ux[1] = 0; ux[2] = 0;
00336 Local2Master(ux,nx);
00337
00338 nx[0] -= mTransMRS[0];
00339 nx[1] -= mTransMRS[1];
00340 nx[2] -= mTransMRS[2];
00341
00342 return StThreeVectorD(nx[0],nx[1],nx[2]);
00343 }
00344
00345
00346 StThreeVectorD StTofrNode::GetCenterPosition()
00347 const
00348 {
00349
00350
00351
00352
00353 Double_t xg[3];
00354 xg[0] = mTransMRS[0];
00355 xg[1] = mTransMRS[1];
00356 xg[2] = mTransMRS[2];
00357
00358 return StThreeVectorD(xg[0],xg[1],xg[2]);
00359 }
00360
00361
00362 Bool_t StTofrNode::IsLocalPointIn(const Double_t x, const Double_t y,
00363 const Double_t z)
00364 {
00365 TBRIK *brik = dynamic_cast<TBRIK*> (GetShape());
00366 Double_t dx = brik->GetDx();
00367 Double_t dy = brik->GetDy();
00368 Double_t dz = brik->GetDz();
00369 Bool_t ret = -dx<x && x<dx && -dy<y && y<dy && -dz<z && z<dz;
00370
00371 return ret;
00372 }
00373
00374
00375 Bool_t StTofrNode::IsGlobalPointIn(const StThreeVectorD &global)
00376 {
00377 Double_t xl[3], xg[3];
00378 xg[0] = global.x();
00379 xg[1] = global.y();
00380 xg[2] = global.z();
00381 Master2Local(xg, xl);
00382 Bool_t ret = IsLocalPointIn(xl[0], xl[1], xl[2]);
00383
00384 return ret;
00385 }
00386
00387
00388 Bool_t StTofrNode::HelixCross(const StHelixD &helix, Double_t &pathLen,
00389 StThreeVectorD &cross)
00390 {
00391
00392
00393
00394
00395
00396 Float_t MaxPathLength = 1000.;
00397
00398 Bool_t ret = kFALSE;
00399 pathLen = 0;
00400
00401
00402
00403
00404 StThreeVectorD planeNormal = YZPlaneNormal();
00405
00406
00407
00408
00409 StThreeVectorD centerPos = GetCenterPosition();
00410
00411
00412
00413
00414 pathLen = helix.pathLength(centerPos,planeNormal);
00415 if ( pathLen>0 && pathLen<MaxPathLength ) {
00416 cross = helix.at(pathLen);
00417
00418
00419
00420 ret = IsGlobalPointIn(cross);
00421 }
00422 return ret;
00423 }
00424
00425
00426 void StTofrNode::Print(Option_t *opt) const
00427 {
00428 TBRIK *brik = dynamic_cast<TBRIK*> (GetShape());
00429 LOG_INFO << "Name=" << GetName() << "\t TBRIK-dimension=" << brik->GetDx()
00430 << " : " << brik->GetDy() << " : " << brik->GetDz()
00431
00432
00433 << "\n EtaRange=" << mEtaMin << " : " << mEtaMax
00434 << "\t PhiRange=" << mPhiMin << " : " << mPhiMax
00435 << endm;
00436 LOG_INFO <<"trans[0-2]=" << mTransMRS[0] <<" " <<mTransMRS[1]
00437 <<" " <<mTransMRS[2]
00438 <<"\nmRotMRS[0-2]=" <<mRotMRS[0] <<" " <<mRotMRS[1] <<" " <<mRotMRS[2]
00439 <<"\nmRotMRS[3-5]=" <<mRotMRS[3] <<" " <<mRotMRS[4] <<" " <<mRotMRS[5]
00440 <<"\nmRotMRS[6-8]=" <<mRotMRS[6] <<" " <<mRotMRS[7] <<" " <<mRotMRS[8]
00441 <<endm;
00442 }
00443
00444 #if 0
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462 #ifdef __ROOT__
00463 ClassImp(StTofrGeomNode)
00464 #endif
00465
00466 Bool_t StTofrGeomNode::mDebug = kFALSE;
00467
00468
00469
00470
00471
00472
00473 StTofrGeomNode::StTofrGeomNode(const char* name, const char* title,
00474 TBRIK* brik, const Double_t x, const Double_t y, const Double_t z,
00475 TRotMatrix* matrix)
00476 : TNode(name, title, brik, x, y, z, matrix), mTransFlag(kFALSE)
00477 {
00478 UpdateMatrix();
00479 BuildMembers();
00480 }
00481
00482
00483 StTofrGeomNode::~StTofrGeomNode()
00484 {
00485 }
00486
00487
00488 void StTofrGeomNode::UpdateMatrix()
00489 {
00490
00491
00492
00493
00494
00495
00496
00497 mTransFlag = kFALSE;
00498 CalcMatrix(this, mTransMRS, mRotMRS);
00499 mTransFlag = kTRUE;
00500 }
00501
00502
00503 void StTofrGeomNode::CalcMatrix(TNode* son,
00504 Double_t* trans, Double_t* rot, StTofrGeomNode* mother)
00505 {
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536 Double_t xl[3], xm[3];
00537
00538 son->TNode::UpdateMatrix();
00539
00540 xl[0] = 0; xl[1] = 0; xl[2] = 0;
00541 ConvertPos(son,xl, mother,xm);
00542 trans[0] = xm[0];
00543 trans[1] = xm[1];
00544 trans[2] = xm[2];
00545
00546 xl[0] = 1; xl[1] = 0; xl[2] = 0;
00547 ConvertPos(son,xl, mother,xm);
00548 rot[0] = xm[0]-trans[0];
00549 rot[1] = xm[1]-trans[1];
00550 rot[2] = xm[2]-trans[2];
00551
00552 xl[0] = 0; xl[1] = 1; xl[2] = 0;
00553 ConvertPos(son,xl, mother,xm);
00554 rot[3] = xm[0]-trans[0];
00555 rot[4] = xm[1]-trans[1];
00556 rot[5] = xm[2]-trans[2];
00557
00558 xl[0] = 0; xl[1] = 0; xl[2] = 1;
00559 ConvertPos(son,xl, mother,xm);
00560 rot[6] = xm[0]-trans[0];
00561 rot[7] = xm[1]-trans[1];
00562 rot[8] = xm[2]-trans[2];
00563
00564 return;
00565 }
00566
00567
00568 void StTofrGeomNode::ConvertPos(
00569 TNode* from, const Double_t* pos_from,
00570 StTofrGeomNode* to, Double_t* pos_to)
00571 {
00572
00573
00574
00575
00576
00577 if (to==0) from->Local2Master(pos_from,pos_to);
00578 else {
00579 Double_t xg[3];
00580 from->Local2Master(pos_from,xg);
00581 to->Master2Local(xg,pos_to);
00582 }
00583
00584 return;
00585 }
00586
00587
00588 void StTofrGeomNode::BuildMembers()
00589 {
00590
00591
00592
00593
00594 Double_t xl[3];
00595 Double_t xg[3];
00596 TBRIK *brik = dynamic_cast<TBRIK*> (GetShape());
00597
00598 Double_t dy = brik->GetDy();
00599 Double_t dz = brik->GetDz();
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613 xl[0] = 0; xl[1] = 0; xl[2] = -dz;
00614 Local2Master(xl, xg);
00615 mEtaMin = StThreeVectorD(xg[0],xg[1],xg[2]).pseudoRapidity();
00616
00617
00618 xl[0] = 0; xl[1] = 0; xl[2] = dz;
00619 Local2Master(xl, xg);
00620 mEtaMax = StThreeVectorD(xg[0],xg[1],xg[2]).pseudoRapidity();
00621
00622
00623 xl[0] = 0; xl[1] = -dy; xl[2] = 0;
00624 Local2Master(xl, xg);
00625 mPhiMin = StThreeVectorD(xg[0],xg[1],xg[2]).phi();
00626
00627
00628 xl[0] = 0; xl[1] = dy; xl[2] = 0;
00629 Local2Master(xl, xg);
00630 mPhiMax = StThreeVectorD(xg[0],xg[1],xg[2]).phi();
00631
00632 if (mEtaMin>mEtaMax) {
00633 Double_t tmp = mEtaMin;
00634 mEtaMin = mEtaMax;
00635 mEtaMax = tmp;
00636 }
00637
00638 if (mPhiMin>mPhiMax) {
00639 Double_t tmp = mPhiMin;
00640 mPhiMin = mPhiMax;
00641 mPhiMax = tmp;
00642 }
00643
00644 }
00645
00646
00647 void StTofrGeomNode::Local2Master(const Double_t* local, Double_t* master)
00648 {
00649
00650
00651
00652
00653 if (!mTransFlag) {
00654
00655 TNode::Local2Master(local,master);
00656 return;
00657 }
00658
00659
00660 Double_t x, y, z;
00661 x = local[0];
00662 y = local[1];
00663 z = local[2];
00664
00665 master[0] = mTransMRS[0] + mRotMRS[0]*x + mRotMRS[3]*y + mRotMRS[6]*z;
00666 master[1] = mTransMRS[1] + mRotMRS[1]*x + mRotMRS[4]*y + mRotMRS[7]*z;
00667 master[2] = mTransMRS[2] + mRotMRS[2]*x + mRotMRS[5]*y + mRotMRS[8]*z;
00668
00669 }
00670
00671
00672 void StTofrGeomNode::Master2Local(const Double_t* master, Double_t* local)
00673 {
00674
00675
00676
00677
00678
00679 if (!mTransFlag) {
00680 LOG_INFO << "Warning in StTofrGeomNode::Master2Local\n"
00681 << " StTofrGeomNode::UpdateMatrix not yet invoked\n"
00682 << " and TNode::Master2Local is wrong, so do nothing" << endm;
00683 return;
00684 }
00685
00686
00687 Double_t x, y, z;
00688 x = master[0] - mTransMRS[0];
00689 y = master[1] - mTransMRS[1];
00690 z = master[2] - mTransMRS[2];
00691
00692 local[0] = mRotMRS[0]*x + mRotMRS[1]*y + mRotMRS[2]*z;
00693 local[1] = mRotMRS[3]*x + mRotMRS[4]*y + mRotMRS[5]*z;
00694 local[2] = mRotMRS[6]*x + mRotMRS[7]*y + mRotMRS[8]*z;
00695
00696 }
00697
00698
00699 StThreeVectorD StTofrGeomNode::YZPlaneNormal()
00700 {
00701
00702
00703
00704
00705
00706 Double_t ux[3], nx[3];
00707
00708 ux[0] = 1; ux[1] = 0; ux[2] = 0;
00709 Local2Master(ux,nx);
00710
00711 nx[0] -= mTransMRS[0];
00712 nx[1] -= mTransMRS[1];
00713 nx[2] -= mTransMRS[2];
00714
00715 return StThreeVectorD(nx[0],nx[1],nx[2]);
00716 }
00717
00718
00719 StThreeVectorD StTofrGeomNode::GetCenterPosition()
00720 const
00721 {
00722
00723
00724
00725
00726 Double_t xg[3];
00727 xg[0] = mTransMRS[0];
00728 xg[1] = mTransMRS[1];
00729 xg[2] = mTransMRS[2];
00730
00731 return StThreeVectorD(xg[0],xg[1],xg[2]);
00732 }
00733
00734
00735 Bool_t StTofrGeomNode::IsLocalPointIn(const Double_t x, const Double_t y,
00736 const Double_t z)
00737 const
00738 {
00739 TBRIK *brik = dynamic_cast<TBRIK*> (GetShape());
00740 Double_t dx = brik->GetDx();
00741 Double_t dy = brik->GetDy();
00742 Double_t dz = brik->GetDz();
00743 Bool_t ret = -dx<x && x<dx && -dy<y && y<dy && -dz<z && z<dz;
00744
00745 return ret;
00746 }
00747
00748
00749 Bool_t StTofrGeomNode::IsGlobalPointIn(const StThreeVectorD &global)
00750 {
00751 Double_t xl[3], xg[3];
00752 xg[0] = global.x();
00753 xg[1] = global.y();
00754 xg[2] = global.z();
00755 Master2Local(xg, xl);
00756 Bool_t ret = IsLocalPointIn(xl[0], xl[1], xl[2]);
00757
00758 return ret;
00759 }
00760
00761
00762 Bool_t StTofrGeomNode::HelixCross(const StHelixD &helix, Double_t &pathLen,
00763 StThreeVectorD &cross)
00764 {
00765
00766
00767
00768
00769
00770 static const Float_t MaxPathLength = 1000.;
00771
00772 Bool_t ret = kFALSE;
00773 pathLen = 0;
00774
00775
00776
00777
00778 StThreeVectorD planeNormal = YZPlaneNormal();
00779
00780
00781
00782
00783 StThreeVectorD centerPos = GetCenterPosition();
00784
00785
00786
00787
00788 pathLen = helix.pathLength(centerPos,planeNormal);
00789 if ( pathLen>0 && pathLen<MaxPathLength ) {
00790 cross = helix.at(pathLen);
00791
00792
00793
00794 ret = IsGlobalPointIn(cross);
00795 }
00796
00797 return ret;
00798 }
00799
00800
00801 void StTofrGeomNode::Print(Option_t *opt) const
00802 const
00803 {
00804 TBRIK *brik = dynamic_cast<TBRIK*> (GetShape());
00805 LOG_INFO << "Name=" << GetName() << "\t TBRIK-dimension=" << brik->GetDx()
00806 << " : " << brik->GetDy() << " : " << brik->GetDz()
00807
00808
00809 << "\n EtaRange=" << mEtaMin << " : " << mEtaMax
00810 << "\t PhiRange=" << mPhiMin << " : " << mPhiMax
00811 << endm;
00812 LOG_INFO <<"trans[0-2]=" << mTransMRS[0] <<" " <<mTransMRS[1]
00813 <<" " <<mTransMRS[2]
00814 <<"\nmRotMRS[0-2]=" <<mRotMRS[0] <<" " <<mRotMRS[1] <<" " <<mRotMRS[2]
00815 <<"\nmRotMRS[3-5]=" <<mRotMRS[3] <<" " <<mRotMRS[4] <<" " <<mRotMRS[5]
00816 <<"\nmRotMRS[6-8]=" <<mRotMRS[6] <<" " <<mRotMRS[7] <<" " <<mRotMRS[8]
00817 <<endm;
00818 }
00819 #endif
00820
00821
00823
00824
00825
00826
00828
00829 #ifdef __ROOT__
00830 ClassImp(StTofrGeomTray)
00831 #endif
00832
00833 Bool_t StTofrGeomTray::mDebug = kFALSE;
00834
00835
00836 StTofrGeomTray::StTofrGeomTray(const Int_t ibtoh, TVolumeView *sector, TVolumeView *top)
00837 : StTofrNode((TVolumeView *)sector->First(), top)
00838 {
00839 mSectorsInBTOH = top->GetListSize()/2;
00840 mBTOHIndex = ibtoh + 1;
00841 mTrayIndex = ibtoh * mSectorsInBTOH + sector->GetPosition()->GetId();
00842 }
00843
00844
00845 StTofrGeomTray::~StTofrGeomTray()
00846 {
00847 mBTOHIndex = 0;
00848 mTrayIndex = 0;
00849 }
00850
00851
00852
00853
00854
00855
00856
00857
00858
00859
00860
00861
00862
00863
00864
00865
00866
00867
00868
00869
00870
00871
00872
00873
00874
00875
00876
00877
00878
00879
00880
00881
00882
00883
00884
00885
00886
00887
00888
00889
00890
00891
00892
00893
00894
00895
00896
00897
00898
00899
00900
00901
00902
00903
00904
00905
00906
00907
00908
00909
00910
00911
00912
00913
00914
00915
00916
00917
00918
00919
00920
00921
00922
00923
00924
00925
00926
00927
00928
00929
00930
00931
00932
00933
00934
00935
00936
00937
00938
00939
00940
00941
00942
00943
00944
00945
00946
00947
00948
00949
00950
00951
00952
00953
00954
00955
00956
00957
00958
00959
00960
00961
00962
00963
00964
00965
00966
00967
00968
00969
00970
00971
00972
00973
00974 StTofrGeomSensor* StTofrGeomTray::GetSensor(const Int_t imodule) const
00975 {
00976
00977 StTofrGeomSensor* sensor = 0;
00978
00979 TVolumeView *volume = GetfView();
00980
00981 if ( !(volume->GetListSize()) ) {
00982 LOG_INFO << " No Modules in this tray " << endm;
00983 return sensor;
00984 }
00985
00986
00987 TDataSetIter nextSensor(volume);
00988 TVolumeView *sensorVolume = 0;
00989 TVolumeView *top = GetTopNode();
00990
00991 while ( (sensorVolume = (TVolumeView *)nextSensor()) )
00992 {
00993 if ( sensorVolume && (int)(sensorVolume->GetPosition()->GetId()) == imodule ) {
00994 sensor = new StTofrGeomSensor(sensorVolume, top);
00995 }
00996 }
00997
00998 return sensor;
00999 }
01000
01001
01002 void StTofrGeomTray::Print(const Option_t *opt) const
01003 {
01004 LOG_INFO << "StTofrGeomTray, tray#=" << mTrayIndex << endm;
01005 StTofrNode::Print(opt);
01006 }
01007
01008
01010
01011
01012
01013
01015
01016 #ifdef __ROOT__
01017 ClassImp(StTofrGeomSensor)
01018 #endif
01019
01020 Bool_t StTofrGeomSensor::mDebug = kFALSE;
01021
01022
01023 StTofrGeomSensor::StTofrGeomSensor(TVolumeView *element, TVolumeView *top)
01024 : StTofrNode(element, top)
01025 {
01026 mModuleIndex = element->GetPosition()->GetId();
01027 CreateGeomCells();
01028 }
01029
01030
01031 StTofrGeomSensor::~StTofrGeomSensor()
01032 {
01033 mModuleIndex = 0;
01034 }
01035
01036
01037
01038
01039
01040
01041
01042
01043
01044
01045
01046
01047
01048
01049
01050 void StTofrGeomSensor::CreateGeomCells()
01051 {
01052
01053
01054
01055
01056
01057
01058
01059
01060
01061
01062
01063
01064 Double_t sensor_dy = mSensorDy;
01065 Double_t cell_width = 2*sensor_dy/mCells;
01066
01067 for (int i=0; i<=mCells; i++) mCellY[i] = cell_width*i - sensor_dy;
01068
01069 }
01070
01071
01072 Double_t StTofrGeomSensor::GetCellYMin(const Int_t icell)
01073 const
01074 {
01075 Double_t ret = 0;
01076 if (icell<=0 || icell>mCells) {
01077 LOG_INFO << "cell#=" << icell <<" is out range=[0," << mCells << "]"
01078 << endm;
01079 } else ret = mCellY[icell-1];
01080
01081 return ret;
01082 }
01083
01084
01085 Double_t StTofrGeomSensor::GetCellYMax(const Int_t icell)
01086 const
01087 {
01088 Double_t ret = 0;
01089 if (icell<=0 || icell>mCells) {
01090 LOG_INFO << "cell#=" << icell <<" is out range=[0," << mCells << "]"
01091 << endm;
01092 } else ret = mCellY[icell];
01093
01094 return ret;
01095 }
01096
01097
01098 StThreeVectorD StTofrGeomSensor::GetCellPosition(const Int_t icell)
01099 {
01100
01101
01102
01103
01104 static const char* where = "StTofrGeomSensor::GetCellPosition";
01105
01106
01107
01108
01109
01110
01111 Double_t sensor_dy = mSensorDy;
01112 Double_t cell_dy = 2*sensor_dy/mCells;
01113
01114 Double_t xl[3], xg[3];
01115 if (icell>=1 && icell<=mCells) {
01116 xl[0] = 0;
01117 xl[1] = (icell*2-1)*cell_dy - sensor_dy;
01118 xl[2] = 0;
01119 Local2Master(xl,xg);
01120 } else {
01121 LOG_INFO << "Warning in " << where <<" Invalid cell# =" << icell << endm;
01122 xg[0] = 0.;
01123 xg[1] = 0.;
01124 xg[2] = 0.;
01125 }
01126
01127 return StThreeVectorD(xg[0],xg[1],xg[2]);
01128 }
01129
01130
01131
01132 Int_t StTofrGeomSensor::FindCellIndex(const Double_t* local)
01133 {
01134
01135
01136
01137
01138 Int_t icell=-1;
01139 if ( IsLocalPointIn(local[0],local[1],local[2]) ) {
01140
01141 for (Int_t i=0; i<mCells; i++) {
01142 if (mCellY[i]<= local[1] && local[1]<=mCellY[i+1]) {
01143 icell = i+1;
01144 break;
01145
01146 }
01147 }
01148 }
01149
01150 return icell;
01151 }
01152
01153
01154 void StTofrGeomSensor::Print(const Option_t *opt) const
01155 {
01156 LOG_INFO << "StTofrGeomSensor, module#=" << mModuleIndex << endm;
01157 StTofrNode::Print(opt);
01158
01159 LOG_INFO << " Cells=" << mCells << "\t Y range for cells=\n";
01160 for (Int_t i=0; i<=mCells; i++) LOG_INFO << " : " << mCellY[i];
01161 LOG_INFO << endm;
01162 }
01163
01164
01166
01167
01168
01169
01171
01172 StTofrGeometry *gTofrGeometry = 0;
01173 static const Int_t CELLSINMODULE = 6;
01174
01175 #ifdef __ROOT__
01176 ClassImp(StTofrGeometry)
01177 #endif
01178
01179 Bool_t StTofrGeometry::mDebug = kFALSE;
01180
01181
01182 StTofrGeometry::StTofrGeometry(const char* name, const char* title)
01183 : TNamed(name,title)
01184 {
01185 mCellsInModule = StTofrGeomSensor::GetCells();
01186 mModulesInTray = 0;
01187 mTrays = 0;
01188 mRootFile = 0;
01189 mInitFlag = kFALSE;
01190 mTopNode = 0;
01191 mStarHall = 0;
01192
01193 for(int i=0;i<mNTrays;i++) {
01194 mTofrTray[i] = 0;
01195 for(int j=0;j<mNModules;j++) {
01196 mTofrSensor[i][j] = 0;
01197 }
01198 }
01199
01200
01201
01202
01203 if (gTofrGeometry) {
01204 LOG_INFO << "Warning !! There is already StTofrGeometry at pointer="
01205 << (void*)gTofrGeometry << ", so it is deleted"
01206 << endm;
01207 delete gTofrGeometry;
01208 }
01209 gTofrGeometry = this;
01210 }
01211
01212
01213 StTofrGeometry::~StTofrGeometry()
01214 {
01215 LOG_INFO << "Warning !! StTofrGeometry at pointer =" << (void*)gTofrGeometry
01216 << " is deleted" << endm;
01217 gTofrGeometry = 0;
01218
01219 for(int i=0;i<mNTrays;i++) {
01220 if(mTofrTray[i]) delete mTofrTray[i];
01221 mTofrTray[i] = 0;
01222 for(int j=0;j<mNModules;j++) {
01223 if(mTofrSensor[i][j]) delete mTofrSensor[i][j];
01224 mTofrSensor[i][j] = 0;
01225 }
01226 }
01227
01228 }
01229
01230
01231
01232
01233 void StTofrGeometry::Init(TVolume *starHall)
01234 {
01235
01236
01237
01238
01239
01240
01241 InitFromStar(starHall);
01242 mStarHall = starHall;
01243
01244
01245
01246
01247
01248
01249
01250
01251
01252
01253
01254
01255
01256
01257
01258
01259
01260
01261
01262
01263
01264
01265
01266
01267
01268
01269
01270
01271
01274
01275
01278
01279
01280 }
01281
01282
01283 void StTofrGeometry::InitFromStar(TVolume *starHall)
01284 {
01285
01286
01287
01288
01289
01290
01291
01292
01293
01294
01295
01296
01297
01298
01299
01300
01301 TDataSetIter volume(starHall,0);
01302
01303 TVolume *starDetectorElement = 0;
01304 while ( (starDetectorElement = ( TVolume *)volume()) )
01305 {
01306
01307
01308 Bool_t found = ( IsBSEC(starDetectorElement) || IsBTRA(starDetectorElement) || IsBRMD(starDetectorElement) );
01309 if (found) {
01310
01311 starDetectorElement->SetVisibility(TVolume::kBothVisible);
01312 starDetectorElement->Mark();
01313 if (starDetectorElement->GetLineColor()==1 || starDetectorElement->GetLineColor()==7)
01314 starDetectorElement->SetLineColor(14);
01315
01316 } else {
01317
01318 starDetectorElement->UnMark();
01319 starDetectorElement->SetVisibility(TVolume::kThisUnvisible);
01320
01321 }
01322 }
01323
01324 starHall->SetVisibility(TVolume::kBothVisible);
01325 mTopNode = new TVolumeView(*starHall,10);
01326
01327
01328
01329
01330 mSectorsInBTOH = mTopNode->GetListSize()/2;
01331
01332
01333 TDataSetIter nextSector(mTopNode);
01334 TVolumeView *secVolume = 0;
01335 mTrays = 0;
01336 while ( (secVolume = (TVolumeView *)nextSector()) ) {
01337 TVolumeView *trayVolume = (TVolumeView *)secVolume->First();
01338 if ( trayVolume->GetListSize() ) {
01339 mTrays++;
01340 mModulesInTray = trayVolume->GetListSize();
01341 }
01342 }
01343 mTofrConf = 0;
01344 if (mTrays==120) mTofrConf = 1;
01345
01346
01348
01350 gMessMgr->Info("","OS") << " # of trays = " << mTopNode->GetListSize() << endm;
01351 TList *list = mTopNode->Nodes();
01352 Int_t ibtoh =0;
01353 TVolumeView *sectorVolume = 0;
01354 mNValidTrays = 0;
01355 mNValidModules = 0;
01356 for(Int_t i=0;i<list->GetSize();i++) {
01357 sectorVolume = dynamic_cast<TVolumeView*> (list->At(i));
01358 TVolumeView *trayVolume = (TVolumeView *)sectorVolume->First();
01359 if( !trayVolume->GetListSize() ) continue;
01360 if ( i>=60 ) ibtoh = 1;
01361
01362 mTofrTray[mNValidTrays] = new StTofrGeomTray(ibtoh, sectorVolume, mTopNode);
01363 TList *list1 = trayVolume->Nodes();
01364
01365 if (!list1 ) continue;
01366 TVolumeView *sensorVolume = 0;
01367 if(list1->GetSize()>mNValidModules) mNValidModules=list1->GetSize();
01368 for(Int_t j=0;j<list1->GetSize();j++) {
01369 sensorVolume = dynamic_cast<TVolumeView*> (list1->At(j));
01370 mTofrSensor[mNValidTrays][j] = new StTofrGeomSensor(sensorVolume, mTopNode);
01371 }
01372 mNValidTrays++;
01373 }
01374 gMessMgr->Info("","OS") << "\n-------------------------------------------\n"
01375 << " Summary of initialization: "
01376 << " NValidTrays = " << mNValidTrays << " NValidModules = " << mNValidModules << endm;
01377
01378
01379
01380
01381
01382
01383
01384
01385
01386
01387
01388
01389
01390
01391
01392
01393
01394
01395
01396
01397
01398 return;
01399
01400 }
01401
01402
01403 Bool_t StTofrGeometry::ContainOthers(TVolume *element)
01404 {
01405 TVolumeView *elementView = new TVolumeView(*element,1);
01406 TList *list = elementView->GetListOfShapes();
01407 if ( list ) {
01408 LOG_INFO << " yes list in " << element->GetName() << endm;
01409 return kTRUE;
01410 } else {
01411 LOG_INFO << " no list in " << element->GetName() << endm;
01412 return kFALSE;
01413 }
01414 }
01415
01416
01417
01418
01419
01420
01421
01422
01423
01424
01425
01426
01427
01428
01429
01430
01431
01432
01433
01434
01435
01436
01437
01438
01439
01440
01441
01442
01443
01444
01445
01446
01447
01448
01449
01450
01451
01452
01453
01454
01455
01456
01457
01458
01459
01460
01461
01462
01463
01464
01465
01466
01467
01468
01469
01470
01471
01472
01473
01474
01475
01476
01477
01478
01479
01480
01481
01482
01483
01484
01485
01486
01487
01488
01489
01490
01491
01492
01493
01494
01495
01496
01497
01498
01499
01500
01501
01502
01503
01504
01505
01506
01507
01508
01509
01510
01511
01512
01513
01514
01515
01516
01517
01518
01519
01520
01521
01522
01523
01524
01525
01526
01527
01528
01529
01530
01531
01532
01533
01534
01535
01536
01537
01538
01539
01540
01541
01542
01543
01544
01545
01546
01547
01548
01549
01550
01551
01552
01553
01554
01555
01556
01557
01558
01559
01560
01561
01562
01563
01564
01565
01566
01567
01568
01569
01570
01571
01572
01573
01574
01575
01576
01577
01578
01579
01580
01581
01582
01583
01584
01585
01586
01587
01588
01589
01590
01591
01592
01593
01594
01595
01596 Bool_t StTofrGeometry::LackThis(const char* fromWhere)
01597 {
01598 if (gTofrGeometry == 0) {
01599 LOG_INFO << " !! Warning from " << fromWhere
01600 << "\n no StTofrGeometry existing, create one instance first"
01601 << endm;
01602 return kTRUE;
01603 } else return kFALSE;
01604 }
01605
01606
01607
01608
01609
01610
01611
01612
01613
01614
01615 Int_t StTofrGeometry::CalcCellId(const Int_t volumeId, const Float_t* local)
01616 const
01617 {
01618 Double_t dlocal[3];
01619 dlocal[0] = local[0];
01620 dlocal[1] = local[1];
01621 dlocal[2] = local[2];
01622 return CalcCellId(volumeId,dlocal);
01623 }
01624
01625
01626 Int_t StTofrGeometry::CalcCellId(const Int_t volumeId, const Double_t* local)
01627 const
01628 {
01629
01630
01631
01632
01633 Int_t icell, imodule, itray;
01634 DecodeVolumeId(volumeId, imodule, itray);
01635 StTofrGeomSensor *sensor = GetGeomSensor(imodule, itray);
01636 if (!sensor) return -1;
01637 icell = sensor->FindCellIndex(local);
01638 Int_t ret = CalcCellId(icell, imodule, itray);
01639
01640 return ret;
01641 }
01642
01643
01644 Bool_t StTofrGeometry::IsCellValid(const Int_t icell)
01645 const
01646 {
01647
01648
01649
01650 return (icell>=1 && icell<=mCellsInModule);
01651 }
01652
01653
01654 Bool_t StTofrGeometry::IsSensorValid(const Int_t imodule)
01655 const
01656 {
01657
01658
01659
01660 return (imodule>=1 && imodule<=mModulesInTray);
01661 }
01662
01663
01664 Bool_t StTofrGeometry::IsTrayValid(const Int_t itray)
01665 const
01666 {
01667
01668
01669
01670
01671
01672 Bool_t ret = kFALSE;
01673
01674 TDataSetIter nextSector(mTopNode);
01675 TVolumeView* sectorVolume = 0;
01676 Int_t ibtoh = 0, i = 0;
01677
01678 while ( (sectorVolume = (TVolumeView *)nextSector()) ) {
01679 i++;
01680 if ( i>mSectorsInBTOH ) ibtoh = 1;
01681 int trayIndex = ibtoh * mSectorsInBTOH + sectorVolume->GetPosition()->GetId();
01682
01683
01684 if (trayIndex == itray) {
01685 ret = kTRUE;
01686 break;
01687 }
01688
01689 }
01690
01691
01692
01693
01694
01695
01696
01697
01698
01699
01700
01701
01702
01703
01704 return ret;
01705 }
01706
01707
01708 Int_t StTofrGeometry::CalcSensorId(const Int_t imodule, const Int_t itray)
01709 const
01710 {
01711
01712
01713
01714
01715 Int_t sensorId = -1;
01716 if (!IsSensorValid(imodule)) return sensorId;
01717
01718 Int_t idx = GetAtOfTray(itray);
01719
01720 if (idx<0) return sensorId;
01721
01722 sensorId = imodule-1 + mModulesInTray*idx;
01723
01724 return sensorId;
01725 }
01726
01727
01728 Int_t StTofrGeometry::PrevCellId(const Int_t cellId)
01729 const
01730 {
01731
01732
01733
01734
01735
01736 Int_t found = -1;
01737 Int_t icell, imodule, itray;
01738 DecodeCellId(cellId,icell,imodule,itray);
01739 StTofrGeomSensor* sensor = GetGeomSensor(imodule,itray);
01740 Int_t icell_p = sensor->PrevCellIndex(icell);
01741
01742 found = CalcCellId(icell_p,imodule,itray);
01743
01744 return found;
01745 }
01746
01747
01748 Int_t StTofrGeometry::NextCellId(const Int_t cellId)
01749 const
01750 {
01751
01752
01753
01754
01755
01756 Int_t found = -1;
01757 Int_t icell, imodule, itray;
01758 DecodeCellId(cellId,icell,imodule,itray);
01759 StTofrGeomSensor* sensor = GetGeomSensor(imodule,itray);
01760 Int_t icell_p = sensor->NextCellIndex(icell);
01761
01762 found = CalcCellId(icell_p,imodule,itray);
01763
01764 return found;
01765 }
01766
01767
01768 Int_t StTofrGeometry::CalcCellId(const Int_t icell, const Int_t imodule,
01769 const Int_t itray)
01770 const
01771 {
01772
01773
01774
01775
01776 Int_t cellId = -1;
01777 if (!IsCellValid(icell)) return cellId;
01778
01779 Int_t sensorId = CalcSensorId(imodule,itray);
01780 if (sensorId<0) return cellId;
01781
01782 cellId = icell-1 + mCellsInModule*sensorId;
01783
01784 return cellId;
01785 }
01786
01787
01788 Bool_t StTofrGeometry::DecodeSensorId(const Int_t sensorId,
01789 Int_t &imodule, Int_t &itray)
01790 const
01791 {
01792
01793
01794
01795
01796 imodule = sensorId%mModulesInTray + 1;
01797 if (!IsSensorValid(imodule)) return kFALSE;
01798
01799 Int_t idx = sensorId/mModulesInTray;
01800 StTofrGeomTray *tray = GetGeomTrayAt(idx);
01801 if (!tray) return kFALSE;
01802 itray = tray->Index();
01803 delete tray;
01804 return kTRUE;
01805 }
01806
01807
01808 Bool_t StTofrGeometry::DecodeCellId(const Int_t cellId, Int_t &icell,
01809 Int_t &imodule, Int_t &itray)
01810 const
01811 {
01812
01813
01814
01815
01816 Int_t sensorId = cellId/mCellsInModule;
01817 if (!DecodeSensorId(sensorId,imodule,itray)) return kFALSE;
01818
01819 icell = cellId%mCellsInModule + 1;
01820
01821 return IsCellValid(icell);
01822 }
01823
01824
01825 Int_t StTofrGeometry::GetCellIndex(const Int_t cellId)
01826 const
01827 {
01828
01829
01830
01831
01832 Int_t icell = cellId%mCellsInModule + 1;
01833
01834 return icell;
01835 }
01836
01837
01838 void StTofrGeometry::DecodeVolumeId(const Int_t volumeId,
01839 Int_t &imodule, Int_t &itray)
01840 const
01841 {
01842
01843
01844
01845
01846
01847 Int_t ires = volumeId;
01848
01849 Int_t rileft = int(ires/10/100/100);
01850 ires = ires-rileft*100*100*10;
01851
01852 itray = int(ires/10/100);
01853 ires = ires-itray*100*10;
01854
01855 imodule = int(ires/10);
01856
01857
01858 itray = itray + (rileft-1)*mSectorsInBTOH;
01859
01860 return;
01861 }
01862
01863
01864 StTofrGeomSensor* StTofrGeometry::GetGeomCell(const Int_t cellId)
01865 const
01866 {
01867
01868
01869
01870
01871 Int_t icell, imodule, itray;
01872 DecodeCellId(cellId, icell, imodule, itray);
01873 StTofrGeomSensor* sensor = GetGeomSensor(imodule, itray);
01874
01875 return sensor;
01876 }
01877
01878
01879 StTofrGeomSensor* StTofrGeometry::GetGeomSensor(const Int_t imodule,
01880 const Int_t itray)
01881 const
01882 {
01883
01884
01885
01886
01887 StTofrGeomTray *tray = GetGeomTray(itray);
01888 StTofrGeomSensor* sensor = NULL;
01889 if (tray) sensor = tray->GetSensor(imodule);
01890 delete tray;
01891 return sensor;
01892 }
01893
01894
01895 StTofrGeomTray* StTofrGeometry::GetGeomTray(const Int_t itray)
01896 const
01897 {
01898
01899
01900
01901
01902 StTofrGeomTray* found = 0;
01903
01904 TDataSetIter nextSector(mTopNode);
01905 TVolumeView *sectorVolume = 0;
01906 Int_t ibtoh = 0, i = 0;
01907 while ( (sectorVolume = (TVolumeView *)nextSector()) ) {
01908 i++;
01909 if (i>mSectorsInBTOH ) ibtoh = 1;
01910 int trayIndex = ibtoh * mSectorsInBTOH + sectorVolume->GetPosition()->GetId();
01911
01912
01913 if (trayIndex == itray) {
01914
01915 found = new StTofrGeomTray(ibtoh, sectorVolume, mTopNode);
01916 break;
01917 }
01918
01919 }
01920
01921
01922
01923
01924
01925
01926
01927
01928
01929
01930
01931
01932
01933
01934
01935
01936
01937
01938
01939
01940
01941
01942
01943
01944
01945
01946
01947 return found;
01948 }
01949
01950
01951 StTofrGeomTray* StTofrGeometry::GetGeomTrayAt(const Int_t idx)
01952 const
01953 {
01954
01955
01956
01957
01958 StTofrGeomTray* found = 0;
01959
01960 TDataSetIter nextSector(mTopNode);
01961 TVolumeView *sectorVolume = 0;
01962 Int_t ibtoh = 0, i = 0;
01963 while ( (sectorVolume = (TVolumeView *)nextSector()) ) {
01964 i++;
01965 if ( i>mSectorsInBTOH ) ibtoh = 1;
01966 if (i==idx) {
01967 found = new StTofrGeomTray(ibtoh, sectorVolume, mTopNode);
01968 }
01969 }
01970
01971
01972
01973
01974
01975
01976
01977
01978
01979
01980
01981
01982
01983 return found;
01984 }
01985
01986
01987 Int_t StTofrGeometry::GetAtOfTray(const Int_t itray)
01988 const
01989 {
01990
01991
01992
01993
01994
01995 Int_t at = -1;
01996
01997
01998
01999 TDataSetIter nextSector(mTopNode);
02000 TVolumeView *sectorVolume = 0;
02001
02002 Int_t ibtoh = 0, i = 0;
02003 while ( (sectorVolume = (TVolumeView *)nextSector()) ) {
02004 i++;
02005 if ( i>mSectorsInBTOH ) ibtoh = 1;
02006 int trayIndex = ibtoh * mSectorsInBTOH + sectorVolume->GetPosition()->GetId();
02007
02008
02009 if (trayIndex == itray) {
02010 at = i;
02011 break;
02012 }
02013
02014 }
02015
02016
02017
02018
02019
02020
02021
02022
02023
02024
02025
02026
02027
02028
02029
02030
02031
02032
02033
02034
02035
02036
02037
02038
02039 return at;
02040 }
02041
02042
02043 void StTofrGeometry::Print(Option_t *opt) const
02044 {
02045 LOG_INFO << "Trays=" << mTrays <<"\t ModulesInTray=" << mModulesInTray
02046 << "\t CellsInModule=" << mCellsInModule << endm;
02047 }
02048
02049
02050 Int_t StTofrGeometry::CellIdPointIn(const StThreeVectorD& point)
02051 const
02052 {
02053
02054
02055
02056
02057 Int_t cellId = -1;
02058 Double_t xl[3], xg[3];
02059 xg[0] = point.x();
02060 xg[1] = point.y();
02061 xg[2] = point.z();
02062
02063
02064
02065
02066 Int_t itray = -1, imodule = -1, icell = -1;
02067 for(int i=0;i<mNValidTrays;i++) {
02068 if(!mTofrTray[i]) continue;
02069 if ( mTofrTray[i]->IsGlobalPointIn(point) ) {
02070 itray = mTofrTray[i]->Index();
02071 if ( !(mTofrTray[i]->GetfView()->GetListSize()) ) {
02072 LOG_INFO << " No sensors in tray " << itray << endm;
02073 return cellId;
02074 }
02075
02076 for( int j=0;j<mNValidModules;j++) {
02077 if(!mTofrSensor[i][j]) continue;
02078 if ( mTofrSensor[i][j]->IsGlobalPointIn(point) ) {
02079 imodule = mTofrSensor[i][j]->Index();
02080 mTofrSensor[i][j]->Master2Local(xg,xl);
02081 icell = mTofrSensor[i][j]->FindCellIndex(xl);
02082 }
02083 }
02084 }
02085 }
02086
02087
02088
02089
02090
02091
02092
02093
02094
02095
02096
02097
02098
02099
02100
02101
02102
02103
02104
02105
02106
02107
02108
02109
02110
02111
02112
02113
02114
02115
02116
02117
02118
02119
02120
02121
02122
02123
02124 if ( itray <= 0 || imodule <= 0 ) return cellId;
02125 cellId = CalcCellId(icell, imodule, itray);
02126 return cellId;
02127
02128
02129
02130
02131
02132
02133
02134
02135
02136
02137
02138
02139
02140
02141
02142
02143
02144
02145
02146
02147
02148
02149
02150
02151
02152
02153
02154
02155
02156
02157
02158
02159
02160
02161
02162
02163
02164 }
02165
02166
02167 Bool_t StTofrGeometry::HelixCross(const StHelixD &helix)
02168 const
02169 {
02170
02171
02172
02173
02174 IntVec idVec;
02175 DoubleVec pathVec;
02176 PointVec crossVec;
02177
02178 Bool_t crossed = HelixCrossCellIds(helix,idVec,pathVec,crossVec);
02179
02180 return crossed;
02181 }
02182
02183
02184 Bool_t StTofrGeometry::HelixCrossCellIds(const StHelixD &helix,
02185 IntVec &idVec, DoubleVec &pathVec, PointVec &crossVec)
02186 const
02187 {
02188
02189
02190
02191
02192
02193
02194 Double_t pathLen;
02195 Int_t cellId;
02196 StThreeVectorD cross;
02197 idVec.clear();
02198 pathVec.clear();
02199 crossVec.clear();
02200
02201 for(int i=0;i<mNValidTrays;i++) {
02202 if(!mTofrTray[i]) continue;
02203 int trayId = mTofrTray[i]->Index();
02204
02205 for(int j=0;j<mNValidModules;j++) {
02206 if(!mTofrSensor[i][j]) continue;
02207 int moduleId = mTofrSensor[i][j]->Index();
02208 if ( mTofrSensor[i][j]->HelixCross(helix,pathLen,cross) ) {
02209 Double_t global[3], local[3];
02210 global[0] = cross.x();
02211 global[1] = cross.y();
02212 global[2] = cross.z();
02213 mTofrSensor[i][j]->Master2Local(global,local);
02214 Int_t icell = mTofrSensor[i][j]->FindCellIndex(local);
02215 cellId = CalcCellId(icell, moduleId, trayId);
02216 if (cellId>=0) {
02217 pathVec.push_back(pathLen);
02218 idVec.push_back(cellId);
02219 crossVec.push_back(cross);
02220 }
02221 }
02222 }
02223 }
02224
02225
02226
02227
02228
02229
02230
02231
02232
02233
02234
02235
02236
02237
02238
02239
02240
02241
02242
02243
02244
02245
02246
02247
02248
02249
02250
02251
02252
02253
02254
02255
02256
02257
02258
02259
02260
02261
02262
02263
02264
02265
02266
02267
02268
02269
02270
02271
02272
02273
02274
02275
02276
02277
02278
02279
02280
02281
02282
02283
02284
02285
02286
02287
02288
02289
02290
02291
02292
02293
02294
02295
02296
02297
02298
02299
02300
02301
02302
02303
02304
02305
02306
02307
02308
02309
02310
02311
02312
02313
02314
02315
02316
02317
02318
02319
02320
02321
02322
02323
02324
02325
02326
02327
02328
02329
02330
02331
02332
02333
02334 if (idVec.size()>0) {
02335
02336 return kTRUE;
02337 }
02338 else {
02339
02340 return kFALSE;
02341 }
02342 }
02343
02344
02345
02346 Bool_t StTofrGeometry::HelixCross(const StHelixD &helix, IntVec validModuleVec, IntVec projTrayVec)
02347 const
02348 {
02349
02350
02351
02352
02353 IntVec idVec;
02354 DoubleVec pathVec;
02355 PointVec crossVec;
02356
02357 Bool_t crossed = HelixCrossCellIds(helix,validModuleVec, projTrayVec, idVec,pathVec,crossVec);
02358
02359 return crossed;
02360 }
02361
02362
02363
02364 Bool_t StTofrGeometry::HelixCrossCellIds(const StHelixD &helix, IntVec validModuleVec, IntVec projTrayVec, IntVec &idVec, DoubleVec &pathVec, PointVec &crossVec)
02365 const
02366 {
02368
02369
02370
02371
02373
02374
02375
02376
02377
02378
02379 if(validModuleVec.size()==0) return kFALSE;
02380 if(projTrayVec.size()==0) return kFALSE;
02381
02382 Double_t pathLen;
02383 Int_t cellId;
02384 StThreeVectorD cross;
02385 idVec.clear();
02386 pathVec.clear();
02387 crossVec.clear();
02388
02389 for(int i=0;i<mNValidTrays;i++) {
02390 if(!mTofrTray[i]) continue;
02391 int trayId = mTofrTray[i]->Index();
02392 bool itrayFind = kFALSE;
02393
02394 for(size_t it=0;it<projTrayVec.size();it++) {
02395 int validtrayId = projTrayVec[it];
02396 if(validtrayId==trayId) {
02397 itrayFind = kTRUE;
02398 break;
02399 }
02400 }
02401 if(!itrayFind) continue;
02402
02403
02404
02405 for(int j=0;j<mNValidModules;j++) {
02406 if(!mTofrSensor[i][j]) continue;
02407 int moduleId = mTofrSensor[i][j]->Index();
02408 for(size_t iv=0;iv<validModuleVec.size();iv++) {
02409 int validtrayId = validModuleVec[iv]/100;
02410 int validmoduleId = validModuleVec[iv]%100;
02411 if(validtrayId==trayId&&validmoduleId==moduleId) {
02412 if ( mTofrSensor[i][j]->HelixCross(helix,pathLen,cross) ) {
02413 Double_t global[3], local[3];
02414 global[0] = cross.x();
02415 global[1] = cross.y();
02416 global[2] = cross.z();
02417 mTofrSensor[i][j]->Master2Local(global,local);
02418 Int_t icell = mTofrSensor[i][j]->FindCellIndex(local);
02419 cellId = CalcCellId(icell, moduleId, trayId);
02420 if (cellId>=0) {
02421 pathVec.push_back(pathLen);
02422 idVec.push_back(cellId);
02423 crossVec.push_back(cross);
02424 }
02425 }
02426 }
02427 }
02428 }
02429 }
02430
02431
02432
02433
02434
02435
02436
02437
02438
02439
02440
02441
02442
02443
02444
02445
02446
02447
02448
02449
02450
02451
02452
02453
02454
02455
02456
02457
02458
02459
02460
02461
02462
02463
02464
02465
02466
02467
02468
02469
02470
02471
02472
02473
02474
02475
02476
02477
02478
02479
02480
02481
02482
02483
02484
02485
02486
02487
02488
02489
02490
02491
02492
02493
02494
02495
02496
02497
02498
02499
02500
02501
02502
02503
02504
02505
02506
02507
02508
02509
02510
02511
02512
02513
02514
02515
02516
02517
02518
02519
02520
02521
02522
02523
02524
02525
02526
02527
02528
02529
02530
02531
02532
02533
02534
02535
02536
02537
02538
02539 if (idVec.size()>0) {
02540
02541 return kTRUE;
02542 }
02543 else {
02544
02545 return kFALSE;
02546 }
02547 }
02548
02549
02550
02551 Bool_t StTofrGeometry::projTrayVector(const StHelixD &helix, IntVec &trayVec) const {
02552
02553 trayVec.clear();
02554 double R_tof = 215.;
02555 double res = 5.0;
02556 double s1 = helix.pathLength(R_tof).first;
02557 if(s1<0.) s1 = helix.pathLength(R_tof).second;
02558 StThreeVectorD point = helix.at(s1);
02559 double phi = point.phi()*180/3.14159;
02560
02561
02562 int itray_east = (255+(int)phi)%360/6+61;
02563 trayVec.push_back(itray_east);
02564
02565 int itray_east1 = (255+(int)(phi+res))%360/6+61;
02566 int itray_east2 = (255+(int)(phi-res))%360/6+61;
02567 if(itray_east1!=itray_east) {
02568 trayVec.push_back(itray_east1);
02569 }
02570 if(itray_east2!=itray_east&&itray_east2!=itray_east1) {
02571 trayVec.push_back(itray_east2);
02572 }
02573
02574
02575 int itray_west = (435-(int)phi)%360/6+1;
02576 trayVec.push_back(itray_west);
02577
02578 int itray_west1 = (435-(int)(phi+res))%360/6+1;
02579 int itray_west2 = (435-(int)(phi-res))%360/6+1;
02580 if(itray_west1!=itray_west) {
02581 trayVec.push_back(itray_west1);
02582 }
02583 if(itray_west2!=itray_west&&itray_west2!=itray_west1) {
02584 trayVec.push_back(itray_west2);
02585 }
02586
02587
02588
02589
02590
02591
02592
02593 if(trayVec.size()>0) return kTRUE;
02594 else return kFALSE;
02595 }
02596
02597
02598
02599
02600
02601
02602
02603
02604
02605
02606
02607
02608
02609
02610
02611
02612