21#include <TGeoManager.h>
30MucGeoGeneral::m_gGeometryInit = 0;
33MucGeoGeneral::m_gpMucGeoGeneral = 0L;
35map<Identifier, MucGeoGap*>
36MucGeoGeneral::m_gpMucGeoGap = map<Identifier, MucGeoGap*>();
38map<Identifier, MucGeoStrip*>
39MucGeoGeneral::m_gpMucGeoStrip = map<Identifier, MucGeoStrip*>();
50 while(m_gpMucGeoGap.size() > 0){
51 map<Identifier, MucGeoGap*>::iterator
iter = m_gpMucGeoGap.end();
52 pGap = (*iter).second;
54 m_gpMucGeoGap.erase(
iter);
58 while(m_gpMucGeoStrip.size() > 0){
59 map<Identifier, MucGeoStrip*>::iterator
iter = m_gpMucGeoStrip.end();
60 pStrip = (*iter).second;
62 m_gpMucGeoStrip.erase(
iter);
70 if (
this != &orig ) {
71 m_gpMucGeoGeneral = orig.m_gpMucGeoGeneral;
72 m_gpMucGeoGap = orig.m_gpMucGeoGap;
73 m_gpMucGeoStrip = orig.m_gpMucGeoStrip;
85 m_StripNumInGap[part][seg][gap] = 0;
97 bool geomanager =
true;
99 gGeoManager =
new TGeoManager(
"BesGeo",
"Bes geometry");
108 if(volMuc) std::cout <<
"Construct Muc from Muc.gdml" << std::endl;
109 else std::cout <<
"volume Muc not found " << std::endl;
113 TGeoIdentity *identity =
new TGeoIdentity();
115 TGeoMaterial *mat =
new TGeoMaterial(
"VOID",0,0,0);
116 TGeoMedium *med =
new TGeoMedium(
"MED",1,mat);
117 TGeoVolume *m_Bes = gGeoManager->MakeBox(
"volBes", med, 0.5*m_BesR, 0.5*m_BesR, 0.5*m_BesZ);
118 gGeoManager->SetTopVolume(m_Bes);
119 m_Bes->AddNode(volMuc, 0, identity);
120 m_MucROOTGeo->
SetChildNo(m_Bes->GetNdaughters()-1);
122 gGeoManager->SetDrawExtraPaths();
123 if(!geomanager)gGeoManager->CloseGeometry();
124 gGeoManager->SetNsegments(20);
128 for (
int part = 0; part < m_MucROOTGeo->
GetPartNum(); part++) {
129 for (
int seg = 0; seg < m_MucROOTGeo->
GetSegNum(part); seg++) {
130 for (
int gap = 0; gap < m_MucROOTGeo->
GetGapNum(part); gap++) {
133 float ironThickness = 0.0;
143 if ( (part == 1 && gap % 2 == 0) || (part != 1 && gap % 2 == 1) ) orient = 1;
145 m_gpMucGeoGap[gapID] = pGap;
147 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;
165 string gapSizeFile =
"muc-gap-size.dat";
166 string gapGeomFile =
"muc-gap-geom.dat";
167 string stripSizeFile =
"muc-strip-size.dat";
168 string stripGeomFile =
"muc-strip-geom.dat";
170 static const int bufSize=512;
171 char lineBuf[bufSize];
177 ifstream ifGapSize(gapSizeFile.c_str());
179 cout <<
"error opening gap size data file : "
185 int part, seg, gap, strip, orient, panel;
186 float xGapTemp, yGapTemp, zGapTemp;
187 float xGapSize[m_kPartNum][m_kSegMax][m_kGapMax];
188 float yGapSize[m_kPartNum][m_kSegMax][m_kGapMax];
189 float zGapSize[m_kPartNum][m_kSegMax][m_kGapMax];;
193 while ( ifGapSize.getline(lineBuf,bufSize,
'\n')) {
194 if (ifGapSize.gcount() > bufSize) {
195 cout <<
"input buffer too small! gcount = " << ifGapSize.gcount()
200 istrstream stringBuf(lineBuf,strlen(lineBuf));
202 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;
225 ifstream ifStripSize(stripSizeFile.c_str());
227 cout <<
"error opening strip size data file : "
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')) {
242 if (ifStripSize.gcount() > bufSize) {
243 cout <<
"input buffer too small! gcount = " << ifStripSize.gcount()
248 istrstream stringBuf(lineBuf,strlen(lineBuf));
250 if (stringBuf >> part >> seg >> gap >> strip >> xStripTemp >> yStripTemp >> zStripTemp) {
251 xStripSize[part][seg][gap][strip] = xStripTemp;
252 yStripSize[part][seg][gap][strip] = yStripTemp;
253 zStripSize[part][seg][gap][strip] = zStripTemp;
255 m_StripNumInGap[part][seg][gap]++;
284 ifstream ifGapGeom(gapGeomFile.c_str());
286 cout <<
"error opening gap geometry data file : "
292 float xGapTarg1, yGapTarg1, zGapTarg1;
293 float xGapTarg2, yGapTarg2, zGapTarg2;
294 float xGapTarg3, yGapTarg3, zGapTarg3;
297 float dzFarFrontGas, dzNearFrontGas;
298 float dzFarBackGas, dzNearBackGas;
300 float dxTarget1ToFiducial, dyTarget1ToFiducial;
301 float dxFiducialToCenter, dyFiducialToCenter;
308 while (ifGapGeom.getline(lineBuf,bufSize,
'\n')) {
310 if ( ifGapGeom.gcount() > bufSize ) {
311 cout <<
"input buffer too small! gcount = " << ifGapGeom.gcount()
316 istrstream stringBuf(lineBuf,strlen(lineBuf));
318 if ( stringBuf >> part >> seg >> gap >> orient
319 >> xGapTarg1 >> yGapTarg1 >> zGapTarg1
320 >> xGapTarg2 >> yGapTarg2 >> zGapTarg2
321 >> xGapTarg3 >> yGapTarg3 >> zGapTarg3
323 >> dzFarFrontGas >> dzNearFrontGas
324 >> dzNearBackGas >> dzFarBackGas
325 >> dxTarget1ToFiducial
326 >> dyTarget1ToFiducial
327 >> dxFiducialToCenter
328 >> dyFiducialToCenter ) {
345 xGapSize[part][seg][gap],
346 yGapSize[part][seg][gap],
347 zGapSize[part][seg][gap],
348 xGapTarg1, yGapTarg1, zGapTarg1,
349 xGapTarg2, yGapTarg2, zGapTarg2,
350 xGapTarg3, yGapTarg3, zGapTarg3,
352 dzFarFrontGas, dzNearFrontGas,
353 dzNearBackGas, dzFarBackGas,
358 m_gpMucGeoGap[gapID] = pGap;
373 ifstream ifStripGeom(stripGeomFile.c_str());
375 cout <<
"error opening strip geometry data file"
383 float xStripTarg1, yStripTarg1, xStripTarg2, yStripTarg2;
385 while (ifStripGeom.getline(lineBuf,bufSize,
'\n')) {
387 if (ifStripGeom.gcount() > bufSize) {
388 cout <<
"input buffer too small! gcount = " << ifStripGeom.gcount()
393 istrstream stringBuf(lineBuf,strlen(lineBuf));
395 if (stringBuf >> part >> seg >> gap >> strip >> panel
396 >> xStripTarg1 >> xStripTarg2
397 >> yStripTarg1 >> yStripTarg2) {
409 if (!m_gpMucGeoStrip[stripID]) {
410 if (m_gpMucGeoGap[gapID]) {
411 pStrip = m_gpMucGeoGap[gapID]->AddStrip(strip);
412 pStrip->
SetStrip(xStripTarg1, xStripTarg2,
413 yStripTarg1, yStripTarg2,
414 xStripSize[part][seg][gap][strip],
415 yStripSize[part][seg][gap][strip],
416 zStripSize[part][seg][gap][strip]);
417 m_gpMucGeoStrip[stripID] = pStrip;
420 cout <<
"missing gap" << gapID << endl;
442 if(!m_gpMucGeoGeneral) {
446 return m_gpMucGeoGeneral;
457 return m_gpMucGeoGap[gapID];
469 return m_gpMucGeoGap[gapID];
476 const int strip)
const
481 return m_gpMucGeoStrip[id];
488 return m_gpMucGeoStrip[id];
510 const Hep3Vector gDirection)
514 vector<Identifier> gapList;
519 Hep3Vector intersectionDir;
529 intersectionDir = ((CLHEP::Hep3Vector)
intersection) - ((CLHEP::Hep3Vector)gPoint);
530 if( intersectionDir.mag() == 0 ) {
534 cos = intersectionDir.dot(gDirection) /
535 ( intersectionDir.mag() * gDirection.mag() );
538 if( (
cos >= 0.0 ) &&
539 ( pGap->
IsInGap(localIntersection.x(),
540 localIntersection.y(),
541 localIntersection.z()) ) ) {
543 gapList.push_back(
id);
550 std::cout <<
"MucGeoGeneral::FindIntersectGaps(), Bad gap Pointer"
565 const Hep3Vector gDirection)
569 vector<Identifier> gapList;
570 vector<Identifier> stripList;
575 int seg, iStripGuess, nStripMax;
578 Hep3Vector localDirection;
582 for(
unsigned int i = 0; i < gapList.size(); i++) {
585 pGap =
GetGap(part, seg, gap);
587 cout <<
"FindIntersectStrips : bad gap pointer!" << endl;
597 iStripGuess = pGap->
GuessStrip(localIntersection.x(),
598 localIntersection.y(),
599 localIntersection.z());
602 int iStripLow = iStripGuess - 2;
603 int iStripHigh = iStripGuess + 2;
604 iStripLow = max(0, iStripLow);
605 iStripHigh = min(nStripMax, iStripHigh);
608 iStripHigh = nStripMax;
614 for(
int j = iStripLow; j < iStripHigh; j++) {
619 stripList.push_back(
id);
634 const Hep3Vector gDirection,
635 vector<int> &padID, vector<float> &intersection_x,
636 vector<float> &intersection_y,vector<float> &intersection_z)
640 vector<Identifier> gapList;
641 vector<Identifier> stripList;
646 int seg, iStripGuess, nStripMax;
649 Hep3Vector localDirection;
653 for(
unsigned int i = 0; i < gapList.size(); i++) {
656 pGap =
GetGap(part, seg, gap);
658 cout <<
"FindIntersectStrips : bad gap pointer!" << endl;
668 iStripGuess = pGap->
GuessStrip(localIntersection.x(),
669 localIntersection.y(),
670 localIntersection.z());
673 int iStripLow = iStripGuess - 2;
674 int iStripHigh = iStripGuess + 2;
675 iStripLow = max(0, iStripLow);
676 iStripHigh = min(nStripMax, iStripHigh);
679 iStripHigh = nStripMax;
685 for(
int j = iStripLow; j < iStripHigh; j++) {
696 float posx,posy,posz;
710 padID.push_back(padid);
711 intersection_x.push_back(localIntersection.x());
712 intersection_y.push_back(localIntersection.y());
713 intersection_z.push_back(localIntersection.z());
716 stripList.push_back(
id);
734 const Hep3Vector gDirection)
738 vector<HepPoint3D> intersectionList;
742 Hep3Vector intersectionDir;
746 pGap =
GetGap(part, seg, gap);
752 intersectionDir = ((CLHEP::Hep3Vector)
intersection) - ((CLHEP::Hep3Vector)gPoint);
753 if( intersectionDir.mag() == 0 ) {
757 cos = intersectionDir.dot(gDirection) /
758 ( intersectionDir.mag() * gDirection.mag() );
761 if( (
cos >= 0.0 ) &&
762 ( pGap->
IsInGap(localIntersection.x(),
763 localIntersection.y(),
764 localIntersection.z()) ) ) {
774 return intersectionList;
805 x = 0.0; sigmaX = 0.0;
806 y = 0.0; sigmaY = 0.0;
807 z = 0.0; sigmaZ = 0.0;
810 cout <<
"MucGeoGeneral::FindIntersection-E101 invalid part = "
829 float distance = 1e30;
834 Hep3Vector
v(vx, vy, vz);
849 distance = r.distance(r0);
877 cout <<
"FindIntersection-E103 bad panel pointer!"
878 <<
" Part" << part <<
" Seg" << seg <<
" Gap" << gap << endl;
904 x1 = 0.0; sigmaX = 0.0; x2 = 0.0;
905 y1 = 0.0; sigmaY = 0.0; y2 = 0.0;
906 z1 = 0.0; sigmaZ = 0.0; z2 = 0.0;
909 cout <<
"MucGeoGeneral::FindIntersection-E101 invalid part = "
921 float distance = 1e30;
927 if(part == 1 && gap%2 == 0) orient = 1;
928 if(part != 1 && gap%2 == 1) orient = 1;
961 cout <<
"FindIntersection-E103 bad panel pointer!"
962 <<
" Part" << part <<
" Seg" << seg <<
" Gap" << gap << endl;
1004 x1 = 0.0; sigmaX = 0.0; x2 = 0.0;
1005 y1 = 0.0; sigmaY = 0.0; y2 = 0.0;
1006 z1 = 0.0; sigmaZ = 0.0; z2 = 0.0;
1009 cout <<
"MucGeoGeneral::FindIntersection-E101 invalid part = "
1028 float distance = 1e30;
1044 distance = r.distance(r0);
1069 cout <<
"FindIntersection-E103 bad panel pointer!"
1070 <<
" Part" << part <<
" Seg" << seg <<
" Gap" << gap << endl;
1113 x1 = 0.0; sigmaX1 = 0.0;
1114 y1 = 0.0; sigmaY1 = 0.0;
1115 z1 = 0.0; sigmaZ1 = 0.0;
1116 x2 = 0.0; sigmaX2 = 0.0;
1117 y2 = 0.0; sigmaY2 = 0.0;
1118 z2 = 0.0; sigmaZ2 = 0.0;
1121 cout <<
"MucGeoGeneral::FindIntersection-E101 invalid part = "
1140 float distance = 1e30;
1145 Hep3Vector
v(vx, vy, vz);
1176 cout <<
"FindIntersection-E103 bad panel pointer!"
1177 <<
" Part" << part <<
" Seg" << seg <<
" Gap" << gap << endl;
1198 const int whichhalf,
1215 x1 = 0.0; sigmaX = 0.0; x2 = 0.0;
1216 y1 = 0.0; sigmaY = 0.0; y2 = 0.0;
1217 z1 = 0.0; sigmaZ = 0.0; z2 = 0.0;
1220 cout <<
"MucGeoGeneral::FindIntersection-E101 invalid part = "
1239 float distance = 1e30;
1275 cout <<
"FindIntersection-E103 bad panel pointer!"
1276 <<
" Part" << part <<
" Seg" << seg <<
" Gap" << gap << endl;
double cos(const BesAngle a)
**********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
int intersection(const HepPoint3D &c1, double r1, const HepPoint3D &c2, double r2, double eps, HepPoint3D &x1, HepPoint3D &x2)
Circle utilities.
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)