16#include "MucGeomSvc/MucGeoGap.h"
17#include "MucGeomSvc/MucGeoStrip.h"
18#include "MucGeomSvc/MucGeometron.h"
19#include "MucGeomSvc/MucConstant.h"
20#include "Identifier/MucID.h"
44 const float xTarget1Global,
45 const float yTarget1Global,
46 const float zTarget1Global,
47 const float xTarget2Global,
48 const float yTarget2Global,
49 const float zTarget2Global,
50 const float xTarget3Global,
51 const float yTarget3Global,
52 const float zTarget3Global,
53 const float dzHighEdge,
54 const float dzFarFrontGas,
55 const float dzNearFrontGas,
56 const float dzNearBackGas,
57 const float dzFarBackGas,
58 const float dxTarget1ToFiducial,
59 const float dyTarget1ToFiducial,
60 const float dxFiducialToCenter,
61 const float dyFiducialToCenter)
70 m_dzHighEdge(dzHighEdge),
71 m_dzFarFrontGas(dzFarFrontGas),
72 m_dzNearFrontGas(dzNearFrontGas),
73 m_dzNearBackGas(dzNearBackGas),
74 m_dzFarBackGas(dzFarBackGas),
75 m_pMucGeoStrip(
MucID::getStripNum(part, seg, gap))
82 Hep3Vector v1Global(xTarget1Global, yTarget1Global, zTarget1Global);
83 Hep3Vector v2Global(xTarget2Global, yTarget2Global, zTarget2Global);
84 Hep3Vector v3Global(xTarget3Global, yTarget3Global, zTarget3Global);
86 Hep3Vector v2To1Global = v1Global - v2Global;
87 Hep3Vector v3To1Global = v1Global - v3Global;
90 Hep3Vector v1Gap(dxTarget1ToFiducial + dxFiducialToCenter,
91 dyTarget1ToFiducial + dyFiducialToCenter,
95 Hep3Vector newX(1,0,0), newY(0,1,0), newZ(0,0,1);
96 HepRotation rotateGap(newX, newY, newZ);
103 newZ = newX.cross(newY);
106 newY = -1.0*v2To1Global;
108 newZ = v3To1Global.cross(newY);
110 newX = newY.cross(newZ);
113 HepRotation rotateGlobal(newX, newY, newZ);
114 HepRotation rotateGapToGlobal(rotateGlobal * rotateGap);
116 Hep3Vector translateGapToGlobal(v1Global - rotateGapToGlobal * v1Gap);
118 m_Rotation = rotateGapToGlobal;
119 m_Translation = translateGapToGlobal;
120 m_Center = m_Translation;
125 HepMatrix rM(3,3), rMT(3,3);
126 for(
int i=0; i<3; i++){
127 for(
int j=0; j<3; j++){
128 rM[i][j] = m_Rotation(i,j);
133 Hep3Vector newXT(rMT(1,1),rMT(2,1),rMT(3,1));
134 Hep3Vector newYT(rMT(1,2),rMT(2,2),rMT(3,2));
135 Hep3Vector newZT(rMT(1,3),rMT(2,3),rMT(3,3));
136 HepRotation rotateGlobalToGap(newXT,newYT,newZT);
138 m_RotationT = rotateGlobalToGap;
147 const TGeoPhysicalNode *gapPhysicalNode,
148 const float ironThickness)
152 m_StripNum(stripNum),
154 m_pMucGeoStrip(
MucID::getStripNum(part, seg, gap)),
155 m_IronThickness(ironThickness)
158 TGeoBBox *gapBox = (TGeoBBox*)gapPhysicalNode->GetShape();
160 m_XSize = gapBox->GetDX() * 2.0;
161 m_YSize = gapBox->GetDY() * 2.0;
162 m_ZSize = gapBox->GetDZ() * 2.0;
165 m_dzFarFrontGas = -4.5;
166 m_dzNearFrontGas = -2.5;
167 m_dzNearBackGas = 2.5;
168 m_dzFarBackGas = 4.5;
170 double eRot[9], *pRot;
172 pRot = gapPhysicalNode->GetMatrix()->GetRotationMatrix();
178 Hep3Vector rotX(pRot[0], pRot[3], pRot[6]);
179 Hep3Vector rotY(pRot[1], pRot[4], pRot[7]);
180 Hep3Vector rotZ(pRot[2], pRot[5], pRot[8]);
181 HepRotation rotateGapToGlobal(rotX, rotY, rotZ);
182 m_Rotation = rotateGapToGlobal;
184 Hep3Vector rotTX(pRot[0], pRot[1], pRot[2]);
185 Hep3Vector rotTY(pRot[3], pRot[4], pRot[5]);
186 Hep3Vector rotTZ(pRot[6], pRot[7], pRot[8]);
187 HepRotation rotateGlobalToGap(rotTX, rotTY, rotTZ);
188 m_RotationT = rotateGlobalToGap;
190 double eTrans[3], *pTrans;
192 pTrans = gapPhysicalNode->GetMatrix()->GetTranslation();
194 Hep3Vector translateGapToGlobal(pTrans[0], pTrans[1], pTrans[2]);
195 m_Translation = translateGapToGlobal;
196 m_Center = m_Translation;
199 double eTrans_gap[3], *pTrans_gap;
200 pTrans_gap = eTrans_gap;
201 pTrans_gap = gapPhysicalNode->GetMatrix(2)->GetTranslation();
204 Hep3Vector GapSurface1, GapSurface2;
205 Hep3Vector GapCenter(pTrans_gap[0], pTrans_gap[1], pTrans_gap[2]);
206 GapSurface1 = GapCenter - rotZ * 20;
207 GapSurface2 = GapCenter + rotZ * 20;
209 m_SurfaceInner = GapSurface1;
210 m_SurfaceOuter = GapSurface2;
211 if(GapSurface1.mag()>GapSurface2.mag())
213 m_SurfaceInner = GapSurface2;
214 m_SurfaceOuter = GapSurface1;
227 m_Part = orig.m_Part;
230 m_StripNum = orig.m_StripNum;
231 m_Orient = orig.m_Orient;
232 m_HitStatus = orig.m_HitStatus;
234 m_XSize = orig.m_XSize;
235 m_YSize = orig.m_YSize;
236 m_ZSize = orig.m_ZSize;
238 m_dzHighEdge = orig.m_dzHighEdge;
239 m_dzFarFrontGas = orig.m_dzFarFrontGas;
240 m_dzNearFrontGas = orig.m_dzNearFrontGas;
241 m_dzNearBackGas = orig.m_dzNearBackGas;
242 m_dzFarBackGas = orig.m_dzFarBackGas;
245 m_Center = orig.m_Center;
246 m_Rotation = orig.m_Rotation;
247 m_RotationT = orig.m_RotationT;
248 m_Translation = orig.m_Translation;
250 m_IronThickness = orig.m_IronThickness;
252 m_pMucGeoStrip = orig.m_pMucGeoStrip;
258 : m_Part(orig.m_Part),
261 m_StripNum(orig.m_StripNum),
262 m_Orient(orig.m_Orient),
263 m_HitStatus(orig.m_HitStatus),
264 m_XSize(orig.m_XSize),
265 m_YSize(orig.m_YSize),
266 m_ZSize(orig.m_ZSize),
267 m_dzHighEdge(orig.m_dzHighEdge),
268 m_dzFarFrontGas(orig.m_dzFarFrontGas),
269 m_dzNearFrontGas(orig.m_dzNearFrontGas),
270 m_dzNearBackGas(orig.m_dzNearBackGas),
271 m_dzFarBackGas(orig.m_dzFarBackGas),
272 m_Center(orig.m_Center),
273 m_Rotation(orig.m_Rotation),
274 m_RotationT(orig.m_RotationT),
275 m_Translation(orig.m_Translation),
276 m_IronThickness(orig.m_IronThickness)
279 m_pMucGeoStrip = orig.m_pMucGeoStrip;
286 while(m_pMucGeoStrip.size() > 0){
287 pStrip = m_pMucGeoStrip.back();
289 m_pMucGeoStrip.pop_back();
297 if ( strip < 0 || strip >=
int(m_pMucGeoStrip.size()) ) {
298 std::cout <<
"Error: MucGeoGap::GetStrip() strip " << strip <<
" exceed strip range" << endl;
301 if ( !m_pMucGeoStrip[strip] ) {
302 std::cout <<
"Error: MucGeoGap::GetStrip() strip " << strip <<
" not found" << endl;
306 return m_pMucGeoStrip[strip];
322 float &thetaY,
float &phiY,
323 float &thetaZ,
float &phiZ)
const
326 Hep3Vector
x(m_Rotation.colX());
327 Hep3Vector
y(m_Rotation.colY());
328 Hep3Vector z(m_Rotation.colZ());
330 thetaX =
kRad *
x.theta();
331 phiX =
kRad *
x.phi();
332 thetaY =
kRad *
y.theta();
333 phiY =
kRad *
y.phi();
334 thetaZ =
kRad * z.theta();
335 phiZ =
kRad * z.phi();
368 iGuess = int ((
y-y0)/dx+0.5);
373 iGuess = int ((
x-x0)/dx+0.5);
380 const Hep3Vector gDirection)
const
384 Hep3Vector gapVect = m_Rotation.colZ();
397 const Hep3Vector gDirection,
399 const Hep3Vector gDirectionSigma,
403 Hep3Vector gapVect = m_Rotation.colZ();
416 const Hep3Vector gDirection,
422 Hep3Vector gapVect = m_Rotation.colZ();
424 HepPlane3D planeInner(gapVect, m_SurfaceInner);
425 HepPlane3D planeOuter(gapVect, m_SurfaceOuter);
444 Hep3Vector gapVect, center_local;
445 if(part == 1 && orient == 1) {gapVect = m_Rotation.colZ(); center_local = m_Center;}
446 else if(part == 1 && orient == 0) {
447 gapVect.setX(0); gapVect.setY(1); gapVect.setZ(0);
448 center_local.setX(0); center_local.setY(m_Center.mag()); center_local.setZ(0);
451 gapVect.setX(1); gapVect.setY(0); gapVect.setZ(0);
452 center_local.setX(m_Center.z()); center_local.setY(0); center_local.setZ(0);
480 Hep3Vector gapVect = m_Rotation.colZ();
510 float center =
b/(-2*a);
512 if(gCross1.x()>center) good = 1;
513 if(gCross2.x()>center) good = 2;
516 if(gCross1.x()<center) good = 1;
517 if(gCross2.x()<center) good = 2;
520 if(good == 2) {temp = gCross1; gCross1 = gCross2; gCross2 = temp;}
543 Hep3Vector gapVect = m_Rotation.colZ();
545 HepPlane3D planeInner(gapVect, m_SurfaceInner);
546 HepPlane3D planeOuter(gapVect, m_SurfaceOuter);
561 const float b,
const float c )
const
584 float center =
b/(-2*a);
586 if(gCross1.x()>center) good = 1;
587 if(gCross2.x()>center) good = 2;
590 if(gCross1.x()<center) good = 1;
591 if(gCross2.x()<center) good = 2;
595 if(good == 1)
return gCross1;
596 else if(good == 2)
return gCross2;
599 cout<<
"in MucGeoGap:: both intersection position are bad!!!"<<endl;
return Empty;
609 return m_Rotation * pVect;
616 return m_RotationT * gVect;
623 return m_Rotation * pPoint + m_Translation;
630 return m_RotationT * (gPoint - m_Translation);
641 ( z > ( m_dzHighEdge - m_ZSize ) ) && ( z < m_dzHighEdge ) );
651 if( strip >=
int(m_pMucGeoStrip.size()) ) {
652 cout <<
" MucGeoGap::AddStrip strip number "
653 << strip <<
" outside of expected range "
654 << m_pMucGeoStrip.size()
659 if( (strip + 1) > m_StripNum ) m_StripNum = strip + 1;
661 if(m_pMucGeoStrip[strip]) {
663 return m_pMucGeoStrip[strip];
668 m_pMucGeoStrip[strip] = pStrip;
674 neighbor = m_pMucGeoStrip[strip-1];
693 s <<
" Identifier : " << gap.
Part() <<
" " << gap.
Seg() <<
" " << gap.
Gap() << endl;
695 s <<
" Center position (" << center.x() <<
"," << center.y() <<
"," << center.z() <<
")" << endl;
696 s <<
" Size (" << dx <<
"," << dy <<
"," << dz <<
")" << endl;
HepGeom::Plane3D< double > HepPlane3D
ostream & operator<<(ostream &s, const MucGeoGap &gap)
void GetSize(float &xSize, float &ySize, float &zSize) const
Get size of this gap.
HepPoint3D CompareIntersection(const int whichhalf, const HepPoint3D gCross1, const HepPoint3D gCross2, const float a, const float b, const float c) const
Hep3Vector RotateToGlobal(const Hep3Vector pVect) const
Rotate a vector from gap coordinate to global coordinate.
Hep3Vector RotateToGap(const Hep3Vector gVect) const
Rotate a vector from global coordinate to gap coordinate.
HepPoint3D TransformToGlobal(const HepPoint3D pPoint) const
Transform a point from gap coordinate to global coordinate.
int GetStripNum() const
Get SoftID.
MucGeoGap()
Default constructor.
int GuessStrip(const float x, const float y, const float z) const
void ProjectToGapSurface(const HepPoint3D gPoint, const Hep3Vector gVect, HepPoint3D &cross1, HepPoint3D &cross2) const
Given a line, find the intersection with two surface of the gap in the global.
HepPoint3D GetCenter() const
Get gap center position in global coordinate.
int Seg() const
Get seg identifier (0-7).
HepPoint3D ProjectToGap(const HepPoint3D gPoint, const Hep3Vector gVect) const
Given a line, find the intersection with the gap in the global.
MucGeoStrip * AddStrip(const int strip)
Add a strip to the gap.
int Gap() const
Get gap identifier (0-8).
int Part() const
Get part identifier (0,2 for cap, 1 for barrel).
void GetRotationMatrix(float &thetaX, float &phiX, float &thetaY, float &phiY, float &thetaZ, float &phiZ) const
Get the rotation angles (in degrees) of the gap in global coordinate.
HepPoint3D ProjectToGapWithSigma(const HepPoint3D gPoint, const Hep3Vector gVect, const HepPoint3D gPointSigma, const Hep3Vector gVectSigma, HepPoint3D &gCross, HepPoint3D &gCrossSigma) const
MucGeoGap & operator=(const MucGeoGap &orig)
Assignment constructor.
bool IsInGap(const float x, const float y, const float z) const
Check if the point (given in gap coordinate) is within the gap boundary.
HepPoint3D ProjectToGapQuadLocal(const int part, const int orient, const float a, const float b, const float c, const int whichhalf, HepPoint3D &cross1, HepPoint3D &cross2) const
HepPoint3D TransformToGap(const HepPoint3D gPoint) const
Transform a point from global coordinate to gap coordinate.
MucGeoStrip * GetStrip(const int strip) const
Point to a strip within this gap.
void SetLeftNeighbor(MucGeoStrip *p)
Set pointer to the adjacent strip on the -X or -Y side of this one.
void SetRightNeighbor(MucGeoStrip *p)
Set pointer to the adjacent strip on the +X or +Y side of this one.
void GetCenterPos(float &x, float &y, float &z) const
Get center position of this strip (in the gap coordinate system).
bool GetIntersectionQuadPlane(const HepPoint3D pLine, const float vy, const float y0, const float a, const float b, const float c, const HepPlane3D plane, HepPoint3D &cross1, HepPoint3D &cross2)
bool GetIntersectionLinePlane(const HepPoint3D pLine, const Hep3Vector vectLine, const HepPlane3D plane, HepPoint3D &cross)
Get intersection of a line and a plane.
bool GetIntersectionQuadPlaneLocal(const int part, const int orient, const float a, const float b, const float c, const HepPlane3D plane, HepPoint3D &cross1, HepPoint3D &cross2)
bool GetIntersectionLinePlaneWithSigma(const HepPoint3D pLine, const Hep3Vector vectLine, const HepPoint3D pLineSigma, const Hep3Vector vectLineSigma, const HepPlane3D plane, HepPoint3D &cross, HepPoint3D &crossSigma)