20 #include "tables/St_tofGeomAlign_Table.h"
22 #include "StBTofGeometry.h"
25 #include "TDataSetIter.h"
27 #include "TGeoManager.h"
28 #include "TGeoMatrix.h"
29 #include "TGeoPhysicalNode.h"
33 #include "StMessMgr.h"
58 Double_t
const StBTofGeomSensor::mSensorDy = 10.35;
60 const char* StBTofGeometry::trayPref =
"BTRA";
61 const char* StBTofGeometry::senPref =
"BRMD";
65 : fView(element), pView(new
TVolumePosition(*pos)), mMasterNode(top), mTransFlag(kFALSE),
66 mAlign{align.x(), align.y(), align.z()}
68 SetBit(kIsOwner,
false);
76 fView(nullptr), pView(nullptr), mMasterNode(nullptr), mTransFlag(false),
77 mAlign{align.x(), align.y(), align.z()}
79 SetBit(kIsOwner,
true);
81 TGeoBBox* bbox =
static_cast<TGeoBBox*
>( gpNode.GetShape() );
83 mTShape =
new TBRIK( gpNode.GetVolume()->GetName(),
"BTOF shape",
"unknown", bbox->GetDX(), bbox->GetDY(), bbox->GetDZ() );
84 mTVolume =
new TVolume( gpNode.GetVolume()->GetName(),
"BTOF volume", mTShape );
86 TGeoHMatrix* ghMatrix =
static_cast<TGeoHMatrix*
>( gpNode.GetMatrix() );
88 double* rotationM = ghMatrix->GetRotationMatrix();
90 double rotationF[9] = {
91 rotationM[0], rotationM[3], rotationM[6],
92 rotationM[1], rotationM[4], rotationM[7],
93 rotationM[2], rotationM[5], rotationM[8]
97 TRotMatrix* rotMatrix =
new TRotMatrix(
"rotMatrix",
"BTOF rotation matrix", rotationF);
99 double* trans = ghMatrix->GetTranslation();
101 pView =
new TVolumePosition(mTVolume, trans[0], trans[1], trans[2], rotMatrix);
102 pView->SetMatrixOwner(
true);
104 fView =
new TVolumeView( static_cast<TVolume*>(
nullptr), pView);
109 mMasterNode =
new TVolumeView( static_cast<TVolume*>(
nullptr), masterPosition);
117 void StBTofNode::UpdateMatrix()
127 CalcMatrix(
this, mAlign, mTransMRS, mRotMRS);
133 void StBTofNode::CalcMatrix(
StBTofNode* son, Double_t* align,
134 Double_t* trans, Double_t* rot,
StBTofNode* mother)
167 Double_t xl[3], xm[3];
173 xl[0] = 0; xl[1] = 0; xl[2] = 0;
174 ConvertPos(son,xl, mother,xm);
179 xl[0] = 1; xl[1] = 0; xl[2] = 0;
180 ConvertPos(son,xl, mother,xm);
181 rot[0] = xm[0]-trans[0];
182 rot[1] = xm[1]-trans[1];
183 rot[2] = xm[2]-trans[2];
185 xl[0] = 0; xl[1] = 1; xl[2] = 0;
186 ConvertPos(son,xl, mother,xm);
187 rot[3] = xm[0]-trans[0];
188 rot[4] = xm[1]-trans[1];
189 rot[5] = xm[2]-trans[2];
191 xl[0] = 0; xl[1] = 0; xl[2] = 1;
192 ConvertPos(son,xl, mother,xm);
193 rot[6] = xm[0]-trans[0];
194 rot[7] = xm[1]-trans[1];
195 rot[8] = xm[2]-trans[2];
198 trans[0] += align[0];
199 trans[1] += align[1];
200 trans[2] += align[2];
206 void StBTofNode::ConvertPos(
210 if (to==0) from->Local2Master(pos_from,pos_to);
213 from->Local2Master(pos_from,xg);
214 to->Master2Local(xg,pos_to);
221 void StBTofNode::BuildMembers()
229 TBRIK *brik =
dynamic_cast<TBRIK*
>(GetShape());
231 if(!brik) { LOG_INFO <<
" no brik " << endm;
return; }
233 Double_t dy = brik->GetDy();
234 Double_t dz = brik->GetDz();
249 xl[0] = 0; xl[1] = 0; xl[2] = -dz;
250 Local2Master(xl, xg);
254 xl[0] = 0; xl[1] = 0; xl[2] = dz;
255 Local2Master(xl, xg);
259 xl[0] = 0; xl[1] = -dy; xl[2] = 0;
260 Local2Master(xl, xg);
264 xl[0] = 0; xl[1] = dy; xl[2] = 0;
265 Local2Master(xl, xg);
268 if (mEtaMin>mEtaMax) {
269 Double_t tmp = mEtaMin;
274 if (mPhiMin>mPhiMax) {
275 Double_t tmp = mPhiMin;
284 void StBTofNode::Local2Master(
const Double_t* local, Double_t* master)
291 if (!mMasterNode) { LOG_INFO <<
" no Master! " << endm;
return;}
312 master[0] = mTransMRS[0] + mRotMRS[0]*x + mRotMRS[3]*y + mRotMRS[6]*z;
313 master[1] = mTransMRS[1] + mRotMRS[1]*x + mRotMRS[4]*y + mRotMRS[7]*z;
314 master[2] = mTransMRS[2] + mRotMRS[2]*x + mRotMRS[5]*y + mRotMRS[8]*z;
319 void StBTofNode::Master2Local(
const Double_t* master, Double_t* local)
327 LOG_INFO <<
" and No TVolumePosition::Master2Local is wrong, so do nothing" << endm;
333 x = master[0] - mTransMRS[0];
334 y = master[1] - mTransMRS[1];
335 z = master[2] - mTransMRS[2];
337 local[0] = mRotMRS[0]*x + mRotMRS[1]*y + mRotMRS[2]*z;
338 local[1] = mRotMRS[3]*x + mRotMRS[4]*y + mRotMRS[5]*z;
339 local[2] = mRotMRS[6]*x + mRotMRS[7]*y + mRotMRS[8]*z;
350 Double_t ux[3], nx[3];
352 ux[0] = 1; ux[1] = 0; ux[2] = 0;
355 nx[0] -= mTransMRS[0];
356 nx[1] -= mTransMRS[1];
357 nx[2] -= mTransMRS[2];
371 xg[0] = mTransMRS[0];
372 xg[1] = mTransMRS[1];
373 xg[2] = mTransMRS[2];
379 Bool_t StBTofNode::IsLocalPointIn(
const Double_t x,
const Double_t y,
382 TBRIK *brik =
dynamic_cast<TBRIK*
> (GetShape());
383 Double_t dx = brik->GetDx();
384 Double_t dy = brik->GetDy();
385 Double_t dz = brik->GetDz();
386 Bool_t ret = -dx<x && x<dx && -dy<y && y<dy && -dz<z && z<dz;
394 Double_t xl[3], xg[3];
398 Master2Local(xg, xl);
399 Bool_t ret = IsLocalPointIn(xl[0], xl[1], xl[2]);
405 Bool_t StBTofNode::HelixCross(
const StHelixD &helix, Double_t &pathLen,
413 Float_t MaxPathLength = 1000.;
431 pathLen = helix.
pathLength(centerPos,planeNormal);
432 if ( pathLen>0 && pathLen<MaxPathLength ) {
433 cross = helix.at(pathLen);
437 ret = IsGlobalPointIn(cross);
443 Bool_t StBTofNode::HelixCross(
const StHelixD &helix, Double_t &pathLen,
451 Float_t MaxPathLength = 1000.;
469 pathLen = helix.
pathLength(centerPos,planeNormal);
470 if ( pathLen>0 && pathLen<MaxPathLength ) {
471 cross = helix.at(pathLen);
472 theta = planeNormal.angle(helix.cat(pathLen));
476 ret = IsGlobalPointIn(cross);
482 void StBTofNode::Print(Option_t *opt)
const
484 TBRIK *brik =
dynamic_cast<TBRIK*
> (GetShape());
485 LOG_INFO <<
"Name=" << GetName() <<
"\t TBRIK-dimension=" << brik->GetDx()
486 <<
" : " << brik->GetDy() <<
" : " << brik->GetDz()
489 <<
"\n EtaRange=" << mEtaMin <<
" : " << mEtaMax
490 <<
"\t PhiRange=" << mPhiMin <<
" : " << mPhiMax
492 LOG_INFO <<
"trans[0-2]=" << mTransMRS[0] <<
" " <<mTransMRS[1]
494 <<
"\nmRotMRS[0-2]=" <<mRotMRS[0] <<
" " <<mRotMRS[1] <<
" " <<mRotMRS[2]
495 <<
"\nmRotMRS[3-5]=" <<mRotMRS[3] <<
" " <<mRotMRS[4] <<
" " <<mRotMRS[5]
496 <<
"\nmRotMRS[6-8]=" <<mRotMRS[6] <<
" " <<mRotMRS[7] <<
" " <<mRotMRS[8]
508 Bool_t StBTofGeomTray::mDebug = kFALSE;
514 mSectorsInBTOH = top->GetListSize()/2;
515 mBTOHIndex = ibtoh + 1;
516 mTrayIndex = ibtoh * mSectorsInBTOH + sector->GetPosition()->GetId();
520 StBTofGeomTray::StBTofGeomTray(
const int trayId,
const TGeoPhysicalNode& node,
const StThreeVectorD& align)
523 int mBTOHId = ( trayId <= 60 ? 1 : 2 );
524 int sectorId = ( trayId <= 60 ? trayId : trayId - 60 );
526 mSectorsInBTOH = StBTofGeometry::mNTrays/2;
527 mBTOHIndex = mBTOHId;
528 mTrayIndex = (mBTOHId - 1) * mSectorsInBTOH + sectorId;
533 void StBTofGeomTray::Print(
const Option_t *opt)
const
535 LOG_INFO <<
"StBTofGeomTray, tray#=" << mTrayIndex << endm;
536 StBTofNode::Print(opt);
548 Bool_t StBTofGeomSensor::mDebug = kFALSE;
554 mModuleIndex = element->GetPosition()->GetId();
559 StBTofGeomSensor::StBTofGeomSensor(
const int moduleId,
const TGeoPhysicalNode& node,
const StThreeVectorD& align)
562 mModuleIndex = moduleId;
578 Double_t sensor_dy = mSensorDy;
579 Double_t cell_width = 2*sensor_dy/mCells;
581 for (
int i=0; i<=mCells; i++) mCellY[i] = cell_width*i - sensor_dy;
586 Double_t StBTofGeomSensor::GetCellYMin(
const Int_t icell)
590 if (icell<=0 || icell>mCells) {
591 LOG_INFO <<
"cell#=" << icell <<
" is out range=[0," << mCells <<
"]"
593 }
else ret = mCellY[icell-1];
599 Double_t StBTofGeomSensor::GetCellYMax(
const Int_t icell)
603 if (icell<=0 || icell>mCells) {
604 LOG_INFO <<
"cell#=" << icell <<
" is out range=[0," << mCells <<
"]"
606 }
else ret = mCellY[icell];
612 StThreeVectorD StBTofGeomSensor::GetCellPosition(
const Int_t icell)
618 static const char* where =
"StBTofGeomSensor::GetCellPosition";
625 Double_t sensor_dy = mSensorDy;
626 Double_t cell_dy = 2*sensor_dy/mCells;
628 Double_t xl[3], xg[3];
629 if (icell>=1 && icell<=mCells) {
631 xl[1] = (icell*2-1)*cell_dy - sensor_dy;
635 LOG_INFO <<
"Warning in " << where <<
" Invalid cell# =" << icell << endm;
646 Int_t StBTofGeomSensor::FindCellIndex(
const Double_t* local)
653 if ( IsLocalPointIn(local[0],local[1],local[2]) ) {
655 for (Int_t i=0; i<mCells; i++) {
656 if (mCellY[i]<= local[1] && local[1]<=mCellY[i+1]) {
668 void StBTofGeomSensor::Print(
const Option_t *opt)
const
670 LOG_INFO <<
"StBTofGeomSensor, module#=" << mModuleIndex << endm;
671 StBTofNode::Print(opt);
673 LOG_INFO <<
" Cells=" << mCells <<
"\t Y range for cells=\n";
674 for (Int_t i=0; i<=mCells; i++) LOG_INFO <<
" : " << mCellY[i];
687 static const Int_t CELLSINMODULE = 6;
691 bool StBTofGeometry::mGemTofGeom =
true;
695 StBTofGeometry::StBTofGeometry(
const char* name,
const char* title)
698 mCellsInModule = StBTofGeomSensor::GetCells();
707 std::fill( mBTofTray, mBTofTray + mNTrays,
nullptr );
708 std::fill( &mBTofSensor[0][0], &mBTofSensor[mNTrays][0],
nullptr );
714 LOG_INFO <<
"Warning !! There is already StBTofGeometry at pointer="
715 << (
void*)gBTofGeometry <<
", so it is deleted"
717 delete gBTofGeometry;
719 gBTofGeometry =
this;
723 StBTofGeometry::~StBTofGeometry()
725 LOG_INFO <<
"Warning !! StBTofGeometry at pointer =" << (
void*)gBTofGeometry
726 <<
" is deleted" << endm;
729 for(
int i=0;i<mNTrays;i++) {
730 if(mBTofTray[i])
delete mBTofTray[i];
732 for(
int j=0;j<mNModules;j++) {
733 if(mBTofSensor[i][j])
delete mBTofSensor[i][j];
734 mBTofSensor[i][j] = 0;
741 void StBTofGeometry::Init(
StMaker *maker,
TVolume *starHall, TGeoManager* geoManager )
746 if(maker->Debug()) DebugOn();
749 std::fill_n(
mTrayX0, mNTrays, 0);
750 std::fill_n(mTrayY0, mNTrays, 0);
751 std::fill_n(mTrayZ0, mNTrays, 0);
755 std::array<double, mNTrays> phi0{}, x0{}, z0{};
759 LOG_INFO <<
"[StBTofGeometry] detected MC-mode: ignore alignment corrections" << endm;
760 }
else if (strcmp(
mAlignFile.c_str(),
"")!=0) {
761 LOG_INFO <<
"[StBTofGeometry] receiving alignment parameters from input files" << endm;
765 for(
int i=0;i<mNTrays;i++) {
766 inData >> phi0[i] >> z0[i] >> x0[i];
769 LOG_WARN <<
" Bad input file ! Use ideal geometry! " << endm;
773 LOG_INFO <<
"[StBTofGeometry] retrieving geometry alignment parameters from database" << endm;
774 TDataSet *mDbTOFDataSet = maker->GetDataBase(
"Calibrations/tof/tofGeomAlign");
775 if (!mDbTOFDataSet) {
776 LOG_WARN <<
"[StBTofGeometry] unable to find Calibrations/tof/tofGeomAlign! Use ideal geometry!" << endm;
778 St_tofGeomAlign* tofGeomAlign =
static_cast<St_tofGeomAlign*
>(mDbTOFDataSet->
Find(
"tofGeomAlign"));
780 LOG_WARN <<
"Unable to get tof geometry align parameter! Use ideal geometry!" << endm;
782 tofGeomAlign_st* geomAlign =
static_cast<tofGeomAlign_st*
>(tofGeomAlign->GetArray());
784 for (Int_t i=0;i<mNTrays;i++) {
785 phi0[i] = geomAlign[i].phi0;
786 x0[i] = geomAlign[i].x0;
787 z0[i] = geomAlign[i].z0;
793 for(
int i=0;i<mNTrays;i++) {
797 double cs = TMath::Cos(phi*TMath::Pi()/180.);
798 double ss = TMath::Sin(phi*TMath::Pi()/180.);
799 mTrayX0[i] = phi0[i]*ss + x0[i]*cs;
800 mTrayY0[i] = -phi0[i]*cs + x0[i]*ss;
803 phi = 108 + (i-60)*6;
804 double cs = TMath::Cos(phi*TMath::Pi()/180.);
805 double ss = TMath::Sin(phi*TMath::Pi()/180.);
806 mTrayX0[i] = -phi0[i]*ss + x0[i]*cs;
807 mTrayY0[i] = phi0[i]*cs + x0[i]*ss;
812 LOG_DEBUG <<
" Tray # = " << i+1 <<
" Align parameters " <<
mTrayX0[i] <<
" " << mTrayY0[i] <<
" " << mTrayZ0[i] << endm;
820 mGemTofGeom = (maker->GetDateTime().GetYear() >=2013);
823 InitFrom( *geoManager );
825 InitFrom( *starHall );
827 LOG_ERROR <<
"StBTofGeometry::Init - Cannot build BTOF geometry without Geant or TGeo input\n";
836 LOG_INFO <<
"StBTofGeometry::Init -- GEMTOF-tray module indexes will be corrected for year " << maker->GetDateTime().GetYear() << endm;
837 for(Int_t j=0;j<mModulesInTray;j++){
839 if(mBTofSensor[7][j]){
840 imod = mBTofSensor[7][j]->Index();
841 mBTofSensor[7][j]->SetIndex(imod+4);
843 if(mBTofSensor[22][j]){
844 imod = mBTofSensor[22][j]->Index();
845 mBTofSensor[22][j]->SetIndex(imod+4);
847 if(mBTofSensor[92][j]){
848 imod = mBTofSensor[92][j]->Index();
849 mBTofSensor[92][j]->SetIndex(imod+4);
851 if(mBTofSensor[107][j]){
852 imod = mBTofSensor[107][j]->Index();
853 mBTofSensor[107][j]->SetIndex(imod+4);
862 bool StBTofGeometry::TrayHasGmtModules(
int trayId)
866 return trayId == 8 || trayId == 23 || trayId == 93 || trayId == 108;
872 void StBTofGeometry::InitFrom(
TVolume &starHall)
881 TVolume *starDetectorElement = 0;
882 while ( (starDetectorElement = (
TVolume *)volume()) )
886 Bool_t found = ( IsBSEC(starDetectorElement) || IsBTRA(starDetectorElement) || IsBRMD(starDetectorElement) );
890 starDetectorElement->Mark();
891 if (starDetectorElement->GetLineColor()==1 || starDetectorElement->GetLineColor()==7)
892 starDetectorElement->SetLineColor(14);
896 starDetectorElement->UnMark();
911 LOG_WARN <<
" No Top Node for Tof Geometry! " << endm;
914 LOG_INFO <<
"[StBTofGeometry] # of sectors = " << mTopNode->GetListSize() << endm;
930 if(strcmp(detVolume->GetName(),
sectorPref)==0) {
935 if(strcmp(detVolume->GetName(), trayPref)==0) {
936 if ( isec>60 ) ibtoh = 1;
937 int sectorsInBTOH = mTopNode->GetListSize()/2;
938 int trayIndex = ibtoh * sectorsInBTOH + secVolume->GetPosition()->GetId();
939 LOG_DEBUG <<
" Tray # " << trayIndex <<
" has # of modules = " << detVolume->GetListSize() << endm;
941 if(detVolume->GetListSize()) {
943 int itray = trayIndex - 1;
945 align.set(
mTrayX0[itray], mTrayY0[itray], mTrayZ0[itray]);
946 transPos = nextDet[0];
950 mBTofTray[mNValidTrays-1] =
new StBTofGeomTray(ibtoh, secVolume, mTopNode, align, transPos);
951 delete transPos; transPos = 0;
954 LOG_DEBUG <<
" Initialize and save tray # " << mBTofTray[mNValidTrays-1]->Index() <<
" with " << detVolume->GetListSize() <<
" modules" << endm;
955 LOG_DEBUG <<
" alignment parameters \t" <<
mTrayX0[itray] <<
" " << mTrayY0[itray] <<
" " << mTrayZ0[itray] << endm;
956 mBTofTray[mNValidTrays-1]->Print();
961 if(strcmp(detVolume->GetName(), senPref)==0) {
963 transPos = nextDet[0];
965 mBTofSensor[mNValidTrays-1][isensor] =
new StBTofGeomSensor(detVolume, mTopNode, align, transPos);
966 delete transPos; transPos = 0;
968 if(
mDebug) mBTofSensor[mNValidTrays-1][isensor]->Print();
971 if(isensor>mModulesInTray) mModulesInTray = isensor;
976 if (mNValidTrays==120) mBTofConf = 1;
978 LOG_INFO <<
"[StBTofGeometry] Done. NValidTrays = " << mNValidTrays <<
" NModulesInTray = " << mModulesInTray << endm;
990 void StBTofGeometry::InitFrom(TGeoManager &geoManager)
994 for (
int trayId = 1; trayId <= mNTrays; trayId++)
996 bool hasGmt = StBTofGeometry::TrayHasGmtModules(trayId);
998 std::string geoPath( FormTGeoPath(geoManager, trayId, hasGmt) );
1000 if ( geoPath.empty() ) {
1001 LOG_WARN <<
"StBTofGeometry::InitFrom(...) - Cannot find path to BTOF tray "
1002 "(id " << trayId <<
"). Skipping...\n";
1008 const TGeoPhysicalNode* gpNode = geoManager.MakePhysicalNode( geoPath.c_str() );
1012 mBTofTray[mNValidTrays-1] =
new StBTofGeomTray(trayId, *gpNode, align);
1015 int maxModuleId = hasGmt ? 24 : mNModules;
1017 for(
int moduleId = 1; moduleId <= maxModuleId; moduleId++)
1019 std::string geoPath( FormTGeoPath(geoManager, trayId, hasGmt, moduleId) );
1021 if ( geoPath.empty() ) {
1022 LOG_WARN <<
"StBTofGeometry::InitFrom(...) - Cannot find path to BTOF module "
1023 "(id " << moduleId <<
"). Skipping...\n";
1027 const TGeoPhysicalNode* gpNode = geoManager.MakePhysicalNode( geoPath.c_str() );
1029 mBTofSensor[mNValidTrays-1][moduleId-1] =
new StBTofGeomSensor(moduleId, *gpNode, align);
1033 mBTofConf = ( mNValidTrays == 120 ? 1 : 0 );
1035 mModulesInTray = mNModules;
1037 LOG_INFO <<
"[StBTofGeometry] Done. NValidTrays = " << mNValidTrays <<
" NModulesInTray = " << mModulesInTray << endm;
1046 std::string StBTofGeometry::FormTGeoPath(TGeoManager &geoManager,
1047 int trayId,
bool hasGmt,
int moduleId)
1051 int halfId = ( trayId <= 60 ? 1 : 2 );
1052 int sectorId = ( trayId <= 60 ? trayId : trayId - 60 );
1054 std::ostringstream geoPath;
1057 bool trs = geoManager.FindVolumeFast(
"TpcRefSys");
1058 geoPath <<
"/HALL_1/CAVE_1/" << ((trs) ?
"TpcRefSys_1/" :
"") <<
"BTOF_1"
1059 << (halfId == 1 ?
"/BTOH_" :
"/BTO1_") << halfId;
1062 geoPath << ( hasGmt ?
"/BSE1_" :
"/BSEC_" ) << sectorId
1063 << ( hasGmt ?
"/BTR1_1" :
"/BTRA_1");
1066 if ( moduleId >= 1 )
1068 geoPath << ( hasGmt ?
"/BXT1_1/BRT1_1/BGM1_1/BRM1_" :
1069 "/BXTR_1/BRTC_1/BGMT_1/BRMD_" )
1073 bool found = geoManager.CheckPath( geoPath.str().c_str() );
1075 return found ? geoPath.str() :
"";
1080 Bool_t StBTofGeometry::ContainOthers(
TVolume *element)
1083 TList *list = elementView->GetListOfShapes();
1085 LOG_INFO <<
" yes list in " << element->GetName() << endm;
1088 LOG_INFO <<
" no list in " << element->GetName() << endm;
1094 Bool_t StBTofGeometry::LackThis(
const char* fromWhere)
1096 if (gBTofGeometry == 0) {
1097 LOG_INFO <<
" !! Warning from " << fromWhere
1098 <<
"\n no StBTofGeometry existing, create one instance first"
1101 }
else return kFALSE;
1105 Int_t StBTofGeometry::CalcCellId(
const Int_t volumeId,
const Float_t* local)
1109 dlocal[0] = local[0];
1110 dlocal[1] = local[1];
1111 dlocal[2] = local[2];
1112 return CalcCellId(volumeId,dlocal);
1116 Int_t StBTofGeometry::CalcCellId(
const Int_t volumeId,
const Double_t* local)
1123 Int_t icell, imodule, itray;
1124 DecodeVolumeId(volumeId, imodule, itray);
1126 if (!sensor)
return -1;
1127 icell = sensor->FindCellIndex(local);
1128 Int_t ret = CalcCellId(icell, imodule, itray);
1134 Bool_t StBTofGeometry::IsCellValid(
const Int_t icell)
1140 return (icell>=1 && icell<=mCellsInModule);
1144 Bool_t StBTofGeometry::IsSensorValid(
const Int_t imodule)
1150 return (imodule>=1 && imodule<=mModulesInTray);
1154 Bool_t StBTofGeometry::IsTrayValid(
const Int_t itray)
1162 Bool_t ret = kFALSE;
1163 for(
int i=0;i<mNValidTrays;i++) {
1164 if(!mBTofTray[i])
continue;
1165 if(mBTofTray[i]->Index() == itray) {
1175 Int_t StBTofGeometry::CalcSensorId(
const Int_t imodule,
const Int_t itray)
1182 Int_t sensorId = -1;
1183 if (!IsSensorValid(imodule))
return sensorId;
1185 Int_t idx = GetAtOfTray(itray);
1187 if (idx<0)
return sensorId;
1189 sensorId = imodule-1 + mModulesInTray*idx;
1195 Int_t StBTofGeometry::PrevCellId(
const Int_t cellId)
1204 Int_t icell, imodule, itray;
1205 DecodeCellId(cellId,icell,imodule,itray);
1207 Int_t icell_p = sensor->PrevCellIndex(icell);
1209 found = CalcCellId(icell_p,imodule,itray);
1215 Int_t StBTofGeometry::NextCellId(
const Int_t cellId)
1224 Int_t icell, imodule, itray;
1225 DecodeCellId(cellId,icell,imodule,itray);
1227 Int_t icell_p = sensor->NextCellIndex(icell);
1229 found = CalcCellId(icell_p,imodule,itray);
1235 Int_t StBTofGeometry::CalcCellId(
const Int_t icell,
const Int_t imodule,
1244 if (!IsCellValid(icell))
return cellId;
1246 Int_t sensorId = CalcSensorId(imodule,itray);
1247 if (sensorId<0)
return cellId;
1249 cellId = icell-1 + mCellsInModule*sensorId;
1255 Bool_t StBTofGeometry::DecodeSensorId(
const Int_t sensorId,
1256 Int_t &imodule, Int_t &itray)
1263 imodule = sensorId%mModulesInTray + 1;
1264 if (!IsSensorValid(imodule))
return kFALSE;
1266 Int_t idx = sensorId/mModulesInTray;
1268 itray = GetTrayIndexAt(idx);
1271 if (!tray)
return kFALSE;
1272 itray = tray->Index();
1278 Bool_t StBTofGeometry::DecodeCellId(
const Int_t cellId, Int_t &icell,
1279 Int_t &imodule, Int_t &itray)
1286 Int_t sensorId = cellId/mCellsInModule;
1287 if (!DecodeSensorId(sensorId,imodule,itray))
return kFALSE;
1289 icell = cellId%mCellsInModule + 1;
1291 return IsCellValid(icell);
1295 Int_t StBTofGeometry::GetCellIndex(
const Int_t cellId)
1302 Int_t icell = cellId%mCellsInModule + 1;
1308 void StBTofGeometry::DecodeVolumeId(
const Int_t volumeId,
1309 Int_t &imodule, Int_t &itray)
1317 Int_t ires = volumeId;
1319 Int_t rileft = int(ires/10/100/100);
1320 ires = ires-rileft*100*100*10;
1322 itray = int(ires/10/100);
1323 ires = ires-itray*100*10;
1325 imodule = int(ires/10);
1341 Int_t icell, imodule, itray;
1342 DecodeCellId(cellId, icell, imodule, itray);
1357 for(
int i=0;i<mNValidTrays;i++) {
1358 if(!mBTofTray[i])
continue;
1359 if(mBTofTray[i]->Index()==itray) {
1360 for(
int j=0;j<mModulesInTray;j++) {
1361 if(!mBTofSensor[i][j])
continue;
1362 if(mBTofSensor[i][j]->Index()==imodule)
return mBTofSensor[i][j];
1378 for(
int i=0;i<mNValidTrays;i++) {
1379 if(!mBTofTray[i])
continue;
1380 if(mBTofTray[i]->Index()==itray)
return mBTofTray[i];
1386 Int_t StBTofGeometry::GetTrayIndexAt(
const Int_t idx)
1399 Int_t ibtoh = 0, i = 0;
1401 while ( (sectorVolume = (
TVolumeView *)nextSector()) ) {
1404 int trayIndex = ibtoh *
mSectorsInBTOH + sectorVolume->GetPosition()->GetId();
1422 Int_t itray = GetTrayIndexAt(idx);
1423 if(itray<=0||itray>mNTrays)
return 0;
1425 for(
int i=0;i<mNValidTrays; i++) {
1426 if(mBTofTray[i] && mBTofTray[i]->Index()==itray)
return mBTofTray[i];
1433 Int_t StBTofGeometry::GetAtOfTray(
const Int_t itray)
1449 Int_t ibtoh = 0, i = 0;
1450 while ( (sectorVolume = (
TVolumeView *)nextSector()) ) {
1453 int trayIndex = ibtoh *
mSectorsInBTOH + sectorVolume->GetPosition()->GetId();
1454 if (trayIndex == itray) {
1464 void StBTofGeometry::Print(Option_t *opt)
const
1466 LOG_INFO <<
"Trays=" << mNValidTrays <<
"\t ModulesInTray=" << mModulesInTray
1467 <<
"\t CellsInModule=" << mCellsInModule << endm;
1479 Double_t xl[3], xg[3];
1487 Int_t itray = -1, imodule = -1, icell = -1;
1488 for(
int i=0;i<mNValidTrays;i++) {
1489 if(!mBTofTray[i])
continue;
1490 if ( mBTofTray[i]->IsGlobalPointIn(point) ) {
1491 itray = mBTofTray[i]->Index();
1492 if ( !(mBTofTray[i]->GetfView()->GetListSize()) ) {
1493 LOG_INFO <<
" No sensors in tray " << itray << endm;
1497 for(
int j=0;j<mModulesInTray;j++) {
1498 if(!mBTofSensor[i][j])
continue;
1499 if ( mBTofSensor[i][j]->IsGlobalPointIn(point) ) {
1500 imodule = mBTofSensor[i][j]->Index();
1501 mBTofSensor[i][j]->Master2Local(xg,xl);
1502 icell = mBTofSensor[i][j]->FindCellIndex(xl);
1508 if ( itray <= 0 || imodule <= 0 )
return cellId;
1509 cellId = CalcCellId(icell, imodule, itray);
1514 Bool_t StBTofGeometry::HelixCross(
const StHelixD &helix)
1532 IntVec &idVec, DoubleVec &pathVec, PointVec &crossVec)
1542 if( !projTrayVector(helix, projTrayVec) )
return kFALSE;
1551 for(
int i=0;i<mNValidTrays;i++) {
1552 if(!mBTofTray[i])
continue;
1553 int trayId = mBTofTray[i]->Index();
1557 bool itrayFind = kFALSE;
1558 for(
size_t it=0;it<projTrayVec.size();it++) {
1559 int validtrayId = projTrayVec[it];
1560 if(validtrayId==trayId) {
1565 if(!itrayFind)
continue;
1567 for(
int j=0;j<mModulesInTray;j++) {
1568 if(!mBTofSensor[i][j])
continue;
1569 int moduleId = mBTofSensor[i][j]->Index();
1570 if ( mBTofSensor[i][j]->HelixCross(helix,pathLen,cross) ) {
1571 Double_t global[3], local[3];
1572 global[0] = cross.x();
1573 global[1] = cross.y();
1574 global[2] = cross.z();
1575 mBTofSensor[i][j]->Master2Local(global,local);
1576 Int_t icell = mBTofSensor[i][j]->FindCellIndex(local);
1577 cellId = CalcCellId(icell, moduleId, trayId);
1579 pathVec.push_back(pathLen);
1580 idVec.push_back(cellId);
1581 crossVec.push_back(cross);
1587 if (idVec.size()>0) {
1599 IntVec &idVec, DoubleVec &pathVec, PointVec &crossVec, DoubleVec &thetaVec)
1609 if( !projTrayVector(helix, projTrayVec) )
return kFALSE;
1611 Double_t pathLen,theta;
1618 for(
int i=0;i<mNValidTrays;i++) {
1619 if(!mBTofTray[i])
continue;
1620 int trayId = mBTofTray[i]->Index();
1624 bool itrayFind = kFALSE;
1625 for(
size_t it=0;it<projTrayVec.size();it++) {
1626 int validtrayId = projTrayVec[it];
1627 if(validtrayId==trayId) {
1632 if(!itrayFind)
continue;
1634 for(
int j=0;j<mModulesInTray;j++) {
1635 if(!mBTofSensor[i][j])
continue;
1636 int moduleId = mBTofSensor[i][j]->Index();
1637 if ( mBTofSensor[i][j]->HelixCross(helix,pathLen,cross,theta) ) {
1638 Double_t global[3], local[3];
1639 global[0] = cross.x();
1640 global[1] = cross.y();
1641 global[2] = cross.z();
1642 mBTofSensor[i][j]->Master2Local(global,local);
1643 Int_t icell = mBTofSensor[i][j]->FindCellIndex(local);
1644 cellId = CalcCellId(icell, moduleId, trayId);
1646 pathVec.push_back(pathLen);
1647 idVec.push_back(cellId);
1648 crossVec.push_back(cross);
1649 thetaVec.push_back(theta);
1656 if (idVec.size()>0) {
1667 Bool_t StBTofGeometry::HelixCross(
const StHelixD &helix, IntVec validModuleVec, IntVec projTrayVec)
1678 Bool_t crossed =
HelixCrossCellIds(helix,validModuleVec, projTrayVec, idVec,pathVec,crossVec);
1700 if(validModuleVec.size()==0)
return kFALSE;
1701 if(projTrayVec.size()==0)
return kFALSE;
1710 for(
int i=0;i<mNValidTrays;i++) {
1711 if(!mBTofTray[i])
continue;
1712 int trayId = mBTofTray[i]->Index();
1713 bool itrayFind = kFALSE;
1715 for(
size_t it=0;it<projTrayVec.size();it++) {
1716 int validtrayId = projTrayVec[it];
1717 if(validtrayId==trayId) {
1722 if(!itrayFind)
continue;
1726 for(
int j=0;j<mModulesInTray;j++) {
1727 if(!mBTofSensor[i][j])
continue;
1728 int moduleId = mBTofSensor[i][j]->Index();
1729 for(
size_t iv=0;iv<validModuleVec.size();iv++) {
1730 int validtrayId = validModuleVec[iv]/100;
1731 int validmoduleId = validModuleVec[iv]%100;
1732 if(validtrayId==trayId&&validmoduleId==moduleId) {
1733 if ( mBTofSensor[i][j]->HelixCross(helix,pathLen,cross) ) {
1734 Double_t global[3], local[3];
1735 global[0] = cross.x();
1736 global[1] = cross.y();
1737 global[2] = cross.z();
1738 mBTofSensor[i][j]->Master2Local(global,local);
1739 Int_t icell = mBTofSensor[i][j]->FindCellIndex(local);
1740 cellId = CalcCellId(icell, moduleId, trayId);
1742 pathVec.push_back(pathLen);
1743 idVec.push_back(cellId);
1744 crossVec.push_back(cross);
1752 if (idVec.size()>0) {
1764 Bool_t StBTofGeometry::projTrayVector(
const StHelixD &helix, IntVec &trayVec)
const {
1767 double R_tof[2]= {210., 216.};
1771 for(
int i=0;i<2;i++) {
1774 if(s<0.) s = helix.
pathLength(R_tof[i]).second;
1776 double phi = point.phi()*180/3.14159;
1777 double z = point.z();
1779 int itray[3] = {0,0,0};
1782 itray[0] = (255+(int)phi)%360/6+61;
1783 itray[1] = itray[0] - 1;
1784 if(itray[1]<=60) itray[1] += 60;
1785 itray[2] = itray[0] + 1;
1786 if(itray[2]>120) itray[2] -= 60;
1791 itray[0] = (435-(int)phi)%360/6+1;
1792 itray[1] = itray[0] - 1;
1793 if(itray[1]<=0) itray[1] += 60;
1794 itray[2] = itray[0] + 1;
1795 if(itray[2]>60) itray[2] -= 60;
1800 for(
int k=0;k<3;k++) {
1801 if(itray[k]<=0 || itray[k]>120)
continue;
1803 bool found = kFALSE;
1804 for(
size_t j=0;j<trayVec.size();j++) {
1805 if(trayVec[j]==itray[k]) {
1813 trayVec.push_back(itray[k]);
1825 if(trayVec.size()>0)
return kTRUE;
static const char * sectorPref
filename for alignment input
StBTofGeomTray(const Int_t ibtoh, TVolumeView *sector, TVolumeView *top, const StThreeVectorD &align, TVolumePosition *pos=0)
Control message printing of this class.
Bool_t HelixCrossCellIds(const StHelixD &helix, IntVec &idVec, DoubleVec &pathVec, PointVec &crossVec) const
Double_t mTrayX0[mNTrays]
Alignment parameters.
StBTofNode(TVolumeView *element, TVolumeView *top, const StThreeVectorD &align, TVolumePosition *pos=0)
Control message printing of this class.
void CreateGeomCells()
Control message printing of this class.
static Bool_t mDebug
Alignment parameters.
virtual void SetVisibility(ENodeSEEN vis=TVolume::kBothVisible)
virtual TVolumePosition * Local2Master(const TVolumeView *localNode, const TVolumeView *masterNode=0)
to be documented
virtual Double_t * Local2Master(const Double_t *local, Double_t *master, Int_t nPoints=1) const
static TRotMatrix * GetIdentity()
Return a pointer the "identity" matrix.
pair< double, double > pathLength(double r) const
path length at given r (cylindrical r)
string mAlignFile
Control message printing of this class.
static Bool_t mDebug
Control MC input (ignore alignment corrections)
Int_t mSectorsInBTOH
the root file of geometry
virtual TDataSet * Find(const char *path) const