16#include "Identifier/MucID.h"
17#include "MucGeomSvc/MucConstant.h"
18#include "MucGeomSvc/MucGeoGap.h"
19#include "MucGeomSvc/MucGeoStrip.h"
20#include "MucGeomSvc/MucGeometron.h"
36 const int part,
const int seg,
const int gap,
const int orient,
const int stripNum,
37 const float xSize,
const float ySize,
const float zSize,
const float xTarget1Global,
38 const float yTarget1Global,
const float zTarget1Global,
const float xTarget2Global,
39 const float yTarget2Global,
const float zTarget2Global,
const float xTarget3Global,
40 const float yTarget3Global,
const float zTarget3Global,
const float dzHighEdge,
41 const float dzFarFrontGas,
const float dzNearFrontGas,
const float dzNearBackGas,
42 const float dzFarBackGas,
const float dxTarget1ToFiducial,
const float dyTarget1ToFiducial,
43 const float dxFiducialToCenter,
const float dyFiducialToCenter )
47 , m_StripNum( stripNum )
52 , m_dzHighEdge( dzHighEdge )
53 , m_dzFarFrontGas( dzFarFrontGas )
54 , m_dzNearFrontGas( dzNearFrontGas )
55 , m_dzNearBackGas( dzNearBackGas )
56 , m_dzFarBackGas( dzFarBackGas )
57 , m_pMucGeoStrip(
MucID::getStripNum( part, seg, gap ) ) {
64 Hep3Vector v1Global( xTarget1Global, yTarget1Global, zTarget1Global );
65 Hep3Vector v2Global( xTarget2Global, yTarget2Global, zTarget2Global );
66 Hep3Vector v3Global( xTarget3Global, yTarget3Global, zTarget3Global );
68 Hep3Vector v2To1Global = v1Global - v2Global;
69 Hep3Vector v3To1Global = v1Global - v3Global;
72 Hep3Vector v1Gap( dxTarget1ToFiducial + dxFiducialToCenter,
73 dyTarget1ToFiducial + dyFiducialToCenter, 0.0 );
76 Hep3Vector newX( 1, 0, 0 ), newY( 0, 1, 0 ), newZ( 0, 0, 1 );
77 HepRotation rotateGap( newX, newY, newZ );
85 newZ = newX.cross( newY );
89 newY = -1.0 * v2To1Global;
91 newZ = v3To1Global.cross( newY );
93 newX = newY.cross( newZ );
96 HepRotation rotateGlobal( newX, newY, newZ );
97 HepRotation rotateGapToGlobal( rotateGlobal * rotateGap );
99 Hep3Vector translateGapToGlobal( v1Global - rotateGapToGlobal * v1Gap );
101 m_Rotation = rotateGapToGlobal;
102 m_Translation = translateGapToGlobal;
103 m_Center = m_Translation;
110 HepMatrix rM( 3, 3 ), rMT( 3, 3 );
111 for (
int i = 0; i < 3; i++ )
113 for (
int j = 0; j < 3; j++ ) { rM[i][j] = m_Rotation( i, j ); }
117 Hep3Vector newXT( rMT( 1, 1 ), rMT( 2, 1 ), rMT( 3, 1 ) );
118 Hep3Vector newYT( rMT( 1, 2 ), rMT( 2, 2 ), rMT( 3, 2 ) );
119 Hep3Vector newZT( rMT( 1, 3 ), rMT( 2, 3 ), rMT( 3, 3 ) );
120 HepRotation rotateGlobalToGap( newXT, newYT, newZT );
122 m_RotationT = rotateGlobalToGap;
127 const int stripNum,
const TGeoPhysicalNode* gapPhysicalNode,
128 const float ironThickness )
132 , m_StripNum( stripNum )
134 , m_pMucGeoStrip(
MucID::getStripNum( part, seg, gap ) )
135 , m_IronThickness( ironThickness )
138 TGeoBBox* gapBox = (TGeoBBox*)gapPhysicalNode->GetShape();
140 m_XSize = gapBox->GetDX() * 2.0;
141 m_YSize = gapBox->GetDY() * 2.0;
142 m_ZSize = gapBox->GetDZ() * 2.0;
145 m_dzFarFrontGas = -4.5;
146 m_dzNearFrontGas = -2.5;
147 m_dzNearBackGas = 2.5;
148 m_dzFarBackGas = 4.5;
150 double eRot[9], *pRot;
152 pRot = gapPhysicalNode->GetMatrix()->GetRotationMatrix();
158 Hep3Vector rotX( pRot[0], pRot[3], pRot[6] );
159 Hep3Vector rotY( pRot[1], pRot[4], pRot[7] );
160 Hep3Vector rotZ( pRot[2], pRot[5], pRot[8] );
161 HepRotation rotateGapToGlobal( rotX, rotY, rotZ );
162 m_Rotation = rotateGapToGlobal;
164 Hep3Vector rotTX( pRot[0], pRot[1], pRot[2] );
165 Hep3Vector rotTY( pRot[3], pRot[4], pRot[5] );
166 Hep3Vector rotTZ( pRot[6], pRot[7], pRot[8] );
167 HepRotation rotateGlobalToGap( rotTX, rotTY, rotTZ );
168 m_RotationT = rotateGlobalToGap;
170 double eTrans[3], *pTrans;
172 pTrans = gapPhysicalNode->GetMatrix()->GetTranslation();
174 Hep3Vector translateGapToGlobal( pTrans[0], pTrans[1], pTrans[2] );
175 m_Translation = translateGapToGlobal;
176 m_Center = m_Translation;
178 double eTrans_gap[3], *pTrans_gap;
179 pTrans_gap = eTrans_gap;
180 pTrans_gap = gapPhysicalNode->GetMatrix( 2 )->GetTranslation();
184 Hep3Vector GapSurface1, GapSurface2;
185 Hep3Vector GapCenter( pTrans_gap[0], pTrans_gap[1], pTrans_gap[2] );
186 GapSurface1 = GapCenter - rotZ * 20;
187 GapSurface2 = GapCenter + rotZ * 20;
189 m_SurfaceInner = GapSurface1;
190 m_SurfaceOuter = GapSurface2;
191 if ( GapSurface1.mag() > GapSurface2.mag() )
193 m_SurfaceInner = GapSurface2;
194 m_SurfaceOuter = GapSurface1;
208 m_Part = orig.m_Part;
211 m_StripNum = orig.m_StripNum;
212 m_Orient = orig.m_Orient;
213 m_HitStatus = orig.m_HitStatus;
215 m_XSize = orig.m_XSize;
216 m_YSize = orig.m_YSize;
217 m_ZSize = orig.m_ZSize;
219 m_dzHighEdge = orig.m_dzHighEdge;
220 m_dzFarFrontGas = orig.m_dzFarFrontGas;
221 m_dzNearFrontGas = orig.m_dzNearFrontGas;
222 m_dzNearBackGas = orig.m_dzNearBackGas;
223 m_dzFarBackGas = orig.m_dzFarBackGas;
225 m_Center = orig.m_Center;
226 m_Rotation = orig.m_Rotation;
227 m_RotationT = orig.m_RotationT;
228 m_Translation = orig.m_Translation;
230 m_IronThickness = orig.m_IronThickness;
232 m_pMucGeoStrip = orig.m_pMucGeoStrip;
238 : m_Part( orig.m_Part )
239 , m_Seg( orig.m_Seg )
240 , m_Gap( orig.m_Gap )
241 , m_StripNum( orig.m_StripNum )
242 , m_Orient( orig.m_Orient )
243 , m_HitStatus( orig.m_HitStatus )
244 , m_XSize( orig.m_XSize )
245 , m_YSize( orig.m_YSize )
246 , m_ZSize( orig.m_ZSize )
247 , m_dzHighEdge( orig.m_dzHighEdge )
248 , m_dzFarFrontGas( orig.m_dzFarFrontGas )
249 , m_dzNearFrontGas( orig.m_dzNearFrontGas )
250 , m_dzNearBackGas( orig.m_dzNearBackGas )
251 , m_dzFarBackGas( orig.m_dzFarBackGas )
252 , m_Center( orig.m_Center )
253 , m_Rotation( orig.m_Rotation )
254 , m_RotationT( orig.m_RotationT )
255 , m_Translation( orig.m_Translation )
256 , m_IronThickness( orig.m_IronThickness ) {
258 m_pMucGeoStrip = orig.m_pMucGeoStrip;
264 while ( m_pMucGeoStrip.size() > 0 )
266 pStrip = m_pMucGeoStrip.back();
268 m_pMucGeoStrip.pop_back();
274 if ( strip < 0 || strip >=
int( m_pMucGeoStrip.size() ) )
276 std::cout <<
"Error: MucGeoGap::GetStrip() strip " << strip <<
" exceed strip range"
280 if ( !m_pMucGeoStrip[strip] )
282 std::cout <<
"Error: MucGeoGap::GetStrip() strip " << strip <<
" not found" << endl;
286 return m_pMucGeoStrip[strip];
299 float& thetaZ,
float& phiZ )
const {
301 Hep3Vector
x( m_Rotation.colX() );
302 Hep3Vector y( m_Rotation.colY() );
303 Hep3Vector z( m_Rotation.colZ() );
305 thetaX =
kRad * x.theta();
306 phiX =
kRad * x.phi();
307 thetaY =
kRad * y.theta();
308 phiY =
kRad * y.phi();
309 thetaZ =
kRad * z.theta();
310 phiZ =
kRad * z.phi();
340 dx = ( yn - y0 ) /
n;
341 iGuess = int( ( y - y0 ) / dx + 0.5 );
346 dx = ( xn - x0 ) /
n;
347 iGuess = int( ( x - x0 ) / dx + 0.5 );
353 const Hep3Vector gDirection )
const {
356 Hep3Vector gapVect = m_Rotation.colZ();
359 HepPlane3D plane( gapVect, m_Center );
370 Hep3Vector gapVect = m_Rotation.colZ();
372 HepPlane3D plane( gapVect, m_Center );
375 gDirectionSigma, plane, gCross, gCrossSigma );
384 Hep3Vector gapVect = m_Rotation.colZ();
386 HepPlane3D planeInner( gapVect, m_SurfaceInner );
387 HepPlane3D planeOuter( gapVect, m_SurfaceOuter );
398 const float b,
const float c,
const int whichhalf,
400 Hep3Vector gapVect, center_local;
401 if ( part == 1 && orient == 1 )
403 gapVect = m_Rotation.colZ();
404 center_local = m_Center;
406 else if ( part == 1 && orient == 0 )
411 center_local.setX( 0 );
412 center_local.setY( m_Center.mag() );
413 center_local.setZ( 0 );
420 center_local.setX( m_Center.z() );
421 center_local.setY( 0 );
422 center_local.setZ( 0 );
428 HepPlane3D plane( gapVect, center_local );
437 const float vy,
const float y0,
439 const float b,
const float c,
const int whichhalf,
443 Hep3Vector gapVect = m_Rotation.colZ();
445 HepPlane3D plane( gapVect, m_Center );
458 if (
IsInGap( localCross.x(), localCross.y(), localCross.z() ) )
465 if (
IsInGap( localCross.x(), localCross.y(), localCross.z() ) )
470 if ( found1 && found2 )
472 float center = b / ( -2 * a );
473 if ( whichhalf == 2 )
475 if ( gCross1.x() > center ) good = 1;
476 if ( gCross2.x() > center ) good = 2;
478 if ( whichhalf == 1 )
480 if ( gCross1.x() < center ) good = 1;
481 if ( gCross2.x() < center ) good = 2;
496 const float vy,
const float y0,
498 const float b,
const float c,
const int whichhalf,
505 Hep3Vector gapVect = m_Rotation.colZ();
507 HepPlane3D planeInner( gapVect, m_SurfaceInner );
508 HepPlane3D planeOuter( gapVect, m_SurfaceOuter );
521 const float b,
const float c )
const {
528 if (
IsInGap( localCross.x(), localCross.y(), 0.0 ) )
535 if (
IsInGap( localCross.x(), localCross.y(), 0.0 ) )
540 if ( found1 && found2 )
542 float center = b / ( -2 * a );
543 if ( whichhalf == 2 )
545 if ( gCross1.x() > center ) good = 1;
546 if ( gCross2.x() > center ) good = 2;
548 if ( whichhalf == 1 )
550 if ( gCross1.x() < center ) good = 1;
551 if ( gCross2.x() < center ) good = 2;
555 if ( good == 1 )
return gCross1;
556 else if ( good == 2 )
return gCross2;
560 cout <<
"in MucGeoGap:: both intersection position are bad!!!" << endl;
567 return m_Rotation * pVect;
572 return m_RotationT * gVect;
577 return m_Rotation * pPoint + m_Translation;
582 return m_RotationT * ( gPoint - m_Translation );
587 return ( ( x > -0.5 * m_XSize -
kGapEdge ) && ( x < 0.5 * m_XSize +
kGapEdge ) &&
589 ( z > ( m_dzHighEdge - m_ZSize ) ) && ( z < m_dzHighEdge ) );
597 if ( strip >=
int( m_pMucGeoStrip.size() ) )
599 cout <<
" MucGeoGap::AddStrip strip number " << strip <<
" outside of expected range "
600 << m_pMucGeoStrip.size() << endl;
604 if ( ( strip + 1 ) > m_StripNum ) m_StripNum = strip + 1;
606 if ( m_pMucGeoStrip[strip] )
609 return m_pMucGeoStrip[strip];
614 m_pMucGeoStrip[strip] = pStrip;
621 neighbor = m_pMucGeoStrip[strip - 1];
639 s <<
" Identifier : " << gap.
Part() <<
" " << gap.
Seg() <<
" " << gap.
Gap() << endl;
641 s <<
" Center position (" << center.x() <<
"," << center.y() <<
"," << center.z() <<
")"
643 s <<
" Size (" << dx <<
"," << dy <<
"," << dz <<
")" << endl;
HepGeom::Point3D< double > HepPoint3D
ostream & operator<<(ostream &s, const MucGeoGap &gap)
HepGeom::Point3D< double > HepPoint3D
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)