21#include <TGeoManager.h>
23#include "MucGeomSvc/MucGeoGeneral.h"
24#include "ROOTGeo/MucROOTGeo.h"
29int MucGeoGeneral::m_gGeometryInit = 0;
33map<Identifier, MucGeoGap*> MucGeoGeneral::m_gpMucGeoGap = map<Identifier, MucGeoGap*>();
35map<Identifier, MucGeoStrip*> MucGeoGeneral::m_gpMucGeoStrip = map<Identifier, MucGeoStrip*>();
44 while ( m_gpMucGeoGap.size() > 0 )
46 map<Identifier, MucGeoGap*>::iterator
iter = m_gpMucGeoGap.end();
47 pGap = ( *iter ).second;
49 m_gpMucGeoGap.erase(
iter );
53 while ( m_gpMucGeoStrip.size() > 0 )
55 map<Identifier, MucGeoStrip*>::iterator
iter = m_gpMucGeoStrip.end();
56 pStrip = ( *iter ).second;
58 m_gpMucGeoStrip.erase(
iter );
66 m_gpMucGeoGeneral = orig.m_gpMucGeoGeneral;
67 m_gpMucGeoGap = orig.m_gpMucGeoGap;
68 m_gpMucGeoStrip = orig.m_gpMucGeoStrip;
79 { m_StripNumInGap[part][seg][gap] = 0; }
88 bool geomanager =
true;
91 gGeoManager =
new TGeoManager(
"BesGeo",
"Bes geometry" );
100 if ( volMuc ) std::cout <<
"Construct Muc from Muc.gdml" << std::endl;
101 else std::cout <<
"volume Muc not found " << std::endl;
105 TGeoIdentity* identity =
new TGeoIdentity();
107 TGeoMaterial* mat =
new TGeoMaterial(
"VOID", 0, 0, 0 );
108 TGeoMedium* med =
new TGeoMedium(
"MED", 1, mat );
110 gGeoManager->MakeBox(
"volBes", med, 0.5 * m_BesR, 0.5 * m_BesR, 0.5 * m_BesZ );
111 gGeoManager->SetTopVolume( m_Bes );
112 m_Bes->AddNode( volMuc, 0, identity );
113 m_MucROOTGeo->
SetChildNo( m_Bes->GetNdaughters() - 1 );
115 gGeoManager->SetDrawExtraPaths();
116 if ( !geomanager ) gGeoManager->CloseGeometry();
117 gGeoManager->SetNsegments( 20 );
121 for (
int part = 0; part < m_MucROOTGeo->
GetPartNum(); part++ )
123 for (
int seg = 0; seg < m_MucROOTGeo->
GetSegNum( part ); seg++ )
125 for (
int gap = 0; gap < m_MucROOTGeo->
GetGapNum( part ); gap++ )
129 float ironThickness = 0.0;
140 if ( ( part == 1 && gap % 2 == 0 ) || ( part != 1 && gap % 2 == 1 ) ) orient = 1;
142 new MucGeoGap( part, seg, gap, orient, 0,
144 m_gpMucGeoGap[gapID] = pGap;
146 for (
int strip = 0; strip < m_MucROOTGeo->
GetStripNum( part, seg, gap ); strip++ )
150 MucGeoStrip* pStrip = m_gpMucGeoGap[gapID]->AddStrip( strip );
152 m_gpMucGeoStrip[stripID] = pStrip;
163 string gapSizeFile =
"muc-gap-size.dat";
164 string gapGeomFile =
"muc-gap-geom.dat";
165 string stripSizeFile =
"muc-strip-size.dat";
166 string stripGeomFile =
"muc-strip-geom.dat";
168 static const int bufSize = 512;
169 char lineBuf[bufSize];
175 ifstream ifGapSize( gapSizeFile.c_str() );
178 cout <<
"error opening gap size data file : " << gapSizeFile << endl;
182 int part, seg, gap, strip, orient, panel;
183 float xGapTemp, yGapTemp, zGapTemp;
184 float xGapSize[m_kPartNum][m_kSegMax][m_kGapMax];
185 float yGapSize[m_kPartNum][m_kSegMax][m_kGapMax];
186 float zGapSize[m_kPartNum][m_kSegMax][m_kGapMax];
191 while ( ifGapSize.getline( lineBuf, bufSize,
'\n' ) )
193 if ( ifGapSize.gcount() > bufSize )
195 cout <<
"input buffer too small! gcount = " << ifGapSize.gcount() << endl;
199 istrstream stringBuf( lineBuf, strlen( lineBuf ) );
201 if ( stringBuf >> part >> seg >> gap >> xGapTemp >> yGapTemp >> zGapTemp )
203 xGapSize[part][seg][gap] = xGapTemp;
204 yGapSize[part][seg][gap] = yGapTemp;
205 zGapSize[part][seg][gap] = zGapTemp;
226 ifstream ifStripSize( stripSizeFile.c_str() );
229 cout <<
"error opening strip size data file : " << stripSizeFile << endl;
233 float xStripTemp, yStripTemp, zStripTemp;
234 float xStripSize[m_kPartNum][m_kSegMax][m_kGapMax][m_kStripMax];
235 float yStripSize[m_kPartNum][m_kSegMax][m_kGapMax][m_kStripMax];
236 float zStripSize[m_kPartNum][m_kSegMax][m_kGapMax][m_kStripMax];
240 while ( ifStripSize.getline( lineBuf, bufSize,
'\n' ) )
243 if ( ifStripSize.gcount() > bufSize )
245 cout <<
"input buffer too small! gcount = " << ifStripSize.gcount() << endl;
249 istrstream stringBuf( lineBuf, strlen( lineBuf ) );
251 if ( stringBuf >> part >> seg >> gap >> strip >> xStripTemp >> yStripTemp >> zStripTemp )
253 xStripSize[part][seg][gap][strip] = xStripTemp;
254 yStripSize[part][seg][gap][strip] = yStripTemp;
255 zStripSize[part][seg][gap][strip] = zStripTemp;
257 m_StripNumInGap[part][seg][gap]++;
287 ifstream ifGapGeom( gapGeomFile.c_str() );
290 cout <<
"error opening gap geometry data file : " << gapGeomFile << endl;
294 float xGapTarg1, yGapTarg1, zGapTarg1;
295 float xGapTarg2, yGapTarg2, zGapTarg2;
296 float xGapTarg3, yGapTarg3, zGapTarg3;
299 float dzFarFrontGas, dzNearFrontGas;
300 float dzFarBackGas, dzNearBackGas;
302 float dxTarget1ToFiducial, dyTarget1ToFiducial;
303 float dxFiducialToCenter, dyFiducialToCenter;
310 while ( ifGapGeom.getline( lineBuf, bufSize,
'\n' ) )
313 if ( ifGapGeom.gcount() > bufSize )
315 cout <<
"input buffer too small! gcount = " << ifGapGeom.gcount() << endl;
319 istrstream stringBuf( lineBuf, strlen( lineBuf ) );
321 if ( stringBuf >> part >> seg >> gap >> orient >> xGapTarg1 >> yGapTarg1 >> zGapTarg1 >>
322 xGapTarg2 >> yGapTarg2 >> zGapTarg2 >> xGapTarg3 >> yGapTarg3 >> zGapTarg3 >>
323 dzHighEdge >> dzFarFrontGas >> dzNearFrontGas >> dzNearBackGas >> dzFarBackGas >>
324 dxTarget1ToFiducial >> dyTarget1ToFiducial >> dxFiducialToCenter >>
342 part, seg, gap, orient, 0, xGapSize[part][seg][gap], yGapSize[part][seg][gap],
343 zGapSize[part][seg][gap], xGapTarg1, yGapTarg1, zGapTarg1, xGapTarg2, yGapTarg2,
344 zGapTarg2, xGapTarg3, yGapTarg3, zGapTarg3, dzHighEdge, dzFarFrontGas,
345 dzNearFrontGas, dzNearBackGas, dzFarBackGas, dxTarget1ToFiducial,
346 dyTarget1ToFiducial, dxFiducialToCenter, dyFiducialToCenter );
347 m_gpMucGeoGap[gapID] = pGap;
362 ifstream ifStripGeom( stripGeomFile.c_str() );
365 cout <<
"error opening strip geometry data file" << stripGeomFile << endl;
371 float xStripTarg1, yStripTarg1, xStripTarg2, yStripTarg2;
373 while ( ifStripGeom.getline( lineBuf, bufSize,
'\n' ) )
376 if ( ifStripGeom.gcount() > bufSize )
378 cout <<
"input buffer too small! gcount = " << ifStripGeom.gcount() << endl;
382 istrstream stringBuf( lineBuf, strlen( lineBuf ) );
384 if ( stringBuf >> part >> seg >> gap >> strip >> panel >> xStripTarg1 >> xStripTarg2 >>
385 yStripTarg1 >> yStripTarg2 )
398 if ( !m_gpMucGeoStrip[stripID] )
400 if ( m_gpMucGeoGap[gapID] )
402 pStrip = m_gpMucGeoGap[gapID]->AddStrip( strip );
403 pStrip->
SetStrip( xStripTarg1, xStripTarg2, yStripTarg1, yStripTarg2,
404 xStripSize[part][seg][gap][strip],
405 yStripSize[part][seg][gap][strip],
406 zStripSize[part][seg][gap][strip] );
407 m_gpMucGeoStrip[stripID] = pStrip;
411 cout <<
"missing gap" << gapID << endl;
430 if ( !m_gpMucGeoGeneral ) { m_gpMucGeoGeneral =
new MucGeoGeneral; }
432 return m_gpMucGeoGeneral;
439 return m_gpMucGeoGap[gapID];
447 return m_gpMucGeoGap[gapID];
451 const int strip )
const {
455 return m_gpMucGeoStrip[id];
460 return m_gpMucGeoStrip[id];
479 const Hep3Vector gDirection ) {
482 vector<Identifier> gapList;
487 Hep3Vector intersectionDir;
499 intersectionDir = ( (CLHEP::Hep3Vector)
intersection ) - ( (CLHEP::Hep3Vector)gPoint );
500 if ( intersectionDir.mag() == 0 ) {
cos = 0.0; }
503 cos = intersectionDir.dot( gDirection ) / ( intersectionDir.mag() * gDirection.mag() );
506 if ( (
cos >= 0.0 ) && ( pGap->
IsInGap( localIntersection.x(), localIntersection.y(),
507 localIntersection.z() ) ) )
510 gapList.push_back(
id );
516 std::cout <<
"MucGeoGeneral::FindIntersectGaps(), Bad gap Pointer"
517 <<
" part " << part <<
" seg " << seg <<
" gap " << gap << std::endl;
526 const Hep3Vector gDirection ) {
529 vector<Identifier> gapList;
530 vector<Identifier> stripList;
535 int seg, iStripGuess, nStripMax;
538 Hep3Vector localDirection;
542 for (
unsigned int i = 0; i < gapList.size(); i++ )
546 pGap =
GetGap( part, seg, gap );
549 cout <<
"FindIntersectStrips : bad gap pointer!" << endl;
559 iStripGuess = pGap->
GuessStrip( localIntersection.x(), localIntersection.y(),
560 localIntersection.z() );
563 int iStripLow = iStripGuess - 2;
564 int iStripHigh = iStripGuess + 2;
565 iStripLow =
max( 0, iStripLow );
566 iStripHigh =
min( nStripMax, iStripHigh );
569 iStripHigh = nStripMax;
575 for (
int j = iStripLow; j < iStripHigh; j++ )
582 stripList.push_back(
id );
591 const int part,
const int gap,
const HepPoint3D gPoint,
const Hep3Vector gDirection,
592 vector<int>& padID, vector<float>& intersection_x, vector<float>& intersection_y,
593 vector<float>& intersection_z ) {
596 vector<Identifier> gapList;
597 vector<Identifier> stripList;
602 int seg, iStripGuess, nStripMax;
605 Hep3Vector localDirection;
609 for (
unsigned int i = 0; i < gapList.size(); i++ )
613 pGap =
GetGap( part, seg, gap );
616 cout <<
"FindIntersectStrips : bad gap pointer!" << endl;
626 iStripGuess = pGap->
GuessStrip( localIntersection.x(), localIntersection.y(),
627 localIntersection.z() );
630 int iStripLow = iStripGuess - 2;
631 int iStripHigh = iStripGuess + 2;
632 iStripLow =
max( 0, iStripLow );
633 iStripHigh =
min( nStripMax, iStripHigh );
636 iStripHigh = nStripMax;
642 for (
int j = iStripLow; j < iStripHigh; j++ )
655 float posx, posy, posz;
663 if ( pGap->
Orient() == 1 )
664 padid = ( localIntersection.y() - pStrip->
GetYmin() ) /
667 padid = ( localIntersection.x() - pStrip->
GetXmin() ) /
671 padID.push_back( padid );
672 intersection_x.push_back( localIntersection.x() );
673 intersection_y.push_back( localIntersection.y() );
674 intersection_z.push_back( localIntersection.z() );
677 stripList.push_back(
id );
687 const Hep3Vector gDirection ) {
690 vector<HepPoint3D> intersectionList;
694 Hep3Vector intersectionDir;
699 pGap =
GetGap( part, seg, gap );
706 intersectionDir = ( (CLHEP::Hep3Vector)
intersection ) - ( (CLHEP::Hep3Vector)gPoint );
707 if ( intersectionDir.mag() == 0 ) {
cos = 0.0; }
710 cos = intersectionDir.dot( gDirection ) / ( intersectionDir.mag() * gDirection.mag() );
713 if ( (
cos >= 0.0 ) && ( pGap->
IsInGap( localIntersection.x(), localIntersection.y(),
714 localIntersection.z() ) ) )
721 return intersectionList;
730 const float vx,
const float vy,
const float vz,
731 const float x0,
const float y0,
const float z0,
732 const float sigmaVx,
const float sigmaVy,
733 const float sigmaVz,
const float sigmaX0,
734 const float sigmaY0,
const float sigmaZ0,
float& x,
735 float& y,
float& z,
float& sigmaX,
float& sigmaY,
746 cout <<
"MucGeoGeneral::FindIntersection-E101 invalid part = " << part << endl;
765 float distance = 1e30;
771 Hep3Vector
v( vx, vy, vz );
785 distance = r.distance( r0 );
811 cout <<
"FindIntersection-E103 bad panel pointer!"
812 <<
" Part" << part <<
" Seg" << seg <<
" Gap" << gap << endl;
822 const float b,
const float c,
823 const int whichhalf,
float& x1,
float& y1,
824 float& z1,
float& x2,
float& y2,
float& z2,
825 float& sigmaX,
float& sigmaY,
float& sigmaZ ) {
838 cout <<
"MucGeoGeneral::FindIntersection-E101 invalid part = " << part << endl;
849 float distance = 1e30;
856 if ( part == 1 && gap % 2 == 0 ) orient = 1;
857 if ( part != 1 && gap % 2 == 1 ) orient = 1;
859 HepPoint3D cross1( 0, 0, 0 ), cross2( 0, 0, 0 );
891 cout <<
"FindIntersection-E103 bad panel pointer!"
892 <<
" Part" << part <<
" Seg" << seg <<
" Gap" << gap << endl;
904 const float vy,
const float x0,
const float y0,
907 const float b,
const float c,
const int whichhalf,
914 float& x1,
float& y1,
float& z1,
float& x2,
float& y2,
915 float& z2,
float& sigmaX,
float& sigmaY,
929 cout <<
"MucGeoGeneral::FindIntersection-E101 invalid part = " << part << endl;
948 float distance = 1e30;
956 HepPoint3D cross1( 0, 0, 0 ), cross2( 0, 0, 0 );
963 distance = r.distance( r0 );
989 cout <<
"FindIntersection-E103 bad panel pointer!"
990 <<
" Part" << part <<
" Seg" << seg <<
" Gap" << gap << endl;
1004 const float vx,
const float vy,
const float vz,
1005 const float x0,
const float y0,
const float z0,
1012 float& x1,
float& y1,
float& z1,
float& x2,
1013 float& y2,
float& z2,
float& sigmaX1,
1014 float& sigmaY1,
float& sigmaZ1,
float& sigmaX2,
1015 float& sigmaY2,
float& sigmaZ2 ) {
1031 cout <<
"MucGeoGeneral::FindIntersection-E101 invalid part = " << part << endl;
1050 float distance = 1e30;
1056 Hep3Vector
v( vx, vy, vz );
1087 cout <<
"FindIntersection-E103 bad panel pointer!"
1088 <<
" Part" << part <<
" Seg" << seg <<
" Gap" << gap << endl;
1097 const float vy,
const float x0,
const float y0,
1100 const float b,
const float c,
const int whichhalf,
1107 float& x1,
float& y1,
float& z1,
float& x2,
1108 float& y2,
float& z2,
float& sigmaX,
1109 float& sigmaY,
float& sigmaZ ) {
1122 cout <<
"MucGeoGeneral::FindIntersection-E101 invalid part = " << part << endl;
1141 float distance = 1e30;
1149 HepPoint3D cross1( 0, 0, 0 ), cross2( 0, 0, 0 );
1176 cout <<
"FindIntersection-E103 bad panel pointer!"
1177 <<
" Part" << part <<
" Seg" << seg <<
" Gap" << gap << endl;
double cos(const BesAngle a)
int intersection(const HepPoint3D &c1, double r1, const HepPoint3D &c2, double r2, double eps, HepPoint3D &x1, HepPoint3D &x2)
Circle utilities.
**********Class see also m_nmax DOUBLE PRECISION m_amel DOUBLE PRECISION m_x2 DOUBLE PRECISION m_alfinv DOUBLE PRECISION m_Xenph INTEGER m_KeyWtm INTEGER m_idyfs DOUBLE PRECISION m_zini DOUBLE PRECISION m_q2 DOUBLE PRECISION m_Wt_KF DOUBLE PRECISION m_WtCut INTEGER m_KFfin *COMMON c_KarLud $ !Input CMS energy[GeV] $ !CMS energy after beam spread beam strahlung[GeV] $ !Beam energy spread[GeV] $ !z boost due to beam spread $ !electron beam mass *ff pair spectrum $ !minimum v
HepGeom::Point3D< double > HepPoint3D
Hep3Vector RotateToGap(const Hep3Vector gVect) const
Rotate a vector from global coordinate to gap coordinate.
int GetStripNum() const
Get SoftID.
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 ProjectToGap(const HepPoint3D gPoint, const Hep3Vector gVect) const
Given a line, find the intersection with the gap in the global.
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.
int GetStripNumTotal()
Get total number of strips.
void FindIntersectionQuadLocal(const int part, const int seg, const int gap, const float a, const float b, const float c, const int whichhalf, float &x1, float &y1, float &z1, float &x2, float &y2, float &z2, float &sigmaX, float &sigmaY, float &sigmaZ)
void Init()
Initialize the instance of MucGeoGeneral.
MucGeoStrip * GetStrip(const int part, const int seg, const int gap, const int strip) const
Get a pointer to the strip identified by (part,seg,gap,strip).
vector< HepPoint3D > FindIntersections(const int part, const int gap, const HepPoint3D gPoint, const Hep3Vector gDirection)
void InitFromXML()
Initialize from xml.
void InitFromASCII()
Initialize form ASCII.
int GetStripNumInGap(const int part, const int seg, const int gap)
MucGeoGap * GetGap(const int part, const int seg, const int gap) const
Get a pointer to the gap identified by (part,seg,gap).
MucGeoGeneral()
Constructor.
~MucGeoGeneral()
Destructor.
vector< Identifier > FindIntersectGaps(const int part, const int gap, const HepPoint3D gPoint, const Hep3Vector gDirection)
vector< Identifier > FindIntersectStrips(const int part, const int gap, const HepPoint3D gPoint, const Hep3Vector gDirection)
void FindIntersectionSurface(const int part, const int seg, const int gap, const float vx, const float vy, const float vz, const float x0, const float y0, const float z0, const float sigmaVx, const float sigmaVy, const float sigmaVz, const float sigmaX0, const float sigmaY0, const float sigmaZ0, float &x1, float &y1, float &z1, float &x2, float &y2, float &z2, float &sigmaX1, float &sigmaY1, float &sigmaZ1, float &sigmaX2, float &sigmaY2, float &sigmaZ2)
MucGeoGeneral & operator=(const MucGeoGeneral &orig)
Assignment constructor.
static MucGeoGeneral * Instance()
Get a pointer to the single instance of MucGeoGeneral.
void FindIntersection(const int part, const int seg, const int gap, const float vx, const float vy, const float vz, const float x0, const float y0, const float z0, const float sigmaVx, const float sigmaVy, const float sigmaVz, const float sigmaX0, const float sigmaY0, const float sigmaZ0, float &x, float &y, float &z, float &sigmaX, float &sigmaY, float &sigmaZ)
float GetYmin() const
Get position of low-Y edge in the gap coordinate system.
float GetXmax() const
Get position of high-X edge in the gap coordinate system.
float GetXmin() const
Get position of low-X edge in the gap coordinate system.
bool CrossGasChamber(const HepPoint3D linePoint, const Hep3Vector lineDir) const
Does the line cross this strip?
float GetYmax() const
Get position of high-Y edge in the gap coordinate system.
void GetCenterPos(float &x, float &y, float &z) const
Get center position of this strip (in the gap coordinate system).
void SetStrip(const float x1, const float x2, const float y1, const float y2, const float xSize, const float ySize, const float zSize)
Set the edge, center and sigma of the strip (in the gap coordinate system).
static int part(const Identifier &id)
static value_type getGapMax()
static value_type getPartNum()
static Identifier channel_id(int barrel_ec, int segment, int layer, int channel)
For a single crystal.
static value_type getSegMax()
static int gap(const Identifier &id)
static int seg(const Identifier &id)
static value_type getSegNum(int part)
static value_type getGapNum(int part)
TGeoVolume * GetVolumeMuc()
Get Muc volume;.
void SetPhysicalNode()
Set the pointers to the physical nodes;.
float GetAbsorberThickness(int part, int seg, int absorber)
Get thickness of an absorber;.
TGeoPhysicalNode * GetPhysicalStrip(int part, int seg, int gap, int strip)
Get strip physical node;.
int GetSegNum(int part)
Get number of segment on part;.
TGeoPhysicalNode * GetPhysicalGap(int part, int seg, int gap)
Get rpc gas chamber node;.
int GetStripNum(int part, int seg, int gap)
Get number of strip on gap;.
int GetPartNum()
Get number of part;.
int GetGapNum(int part)
Get number of gap on part;.
void SetChildNo(int childNo)