ATLAS Offline Software
Loading...
Searching...
No Matches
MuonChamberProjectionHelper::Imp Class Reference
Collaboration diagram for MuonChamberProjectionHelper::Imp:

Classes

class  MDTChamberInfo

Public Types

typedef std::map< GeoPVConstLink, MDTChamberInfo >::iterator ChamberInfoMapItr

Public Member Functions

 Imp (MuonChamberProjectionHelper *tc, StoreGateSvc *ds)
bool ensureInited ()
bool init ()
bool nameIsMDTChamber (const std::string &n)
bool getMDTChamberVolInfo (const GeoPVConstLink &mdtChamber, ChamberInfoMapItr &itChamberInfo, bool silent=false)
void getMDTChamberXAndZ (ChamberInfoMapItr &itChamberInfo, double &trdX, double &trdZ)
double pointToPlaneDistAlongLine (const Amg::Vector3D &point, const Amg::Vector3D &lineDirection, const Amg::Vector3D &planePoint, const Amg::Vector3D &planeNormal)
void projectXZPointToTrdAlongYAxis (const double &x, const double &z, const GeoTrd *trd, Amg::Vector3D &firstEndWall_point, Amg::Vector3D &secondEndWall_point)
bool clip2DLineSegmentToRectangle (const double &rectX, const double &rectY, double &x0, double &y0, double &x1, double &y1)
const GeoTrd * findTRDInShape (const GeoShape *shape)

Static Public Member Functions

static bool constrainPointToRectangleAlongLine (const double &trdX, const double &trdZ, const double &x0, const double &z0, double &x1, double &z1)

Public Attributes

MuonChamberProjectionHelpertheclass {}
StoreGateSvcdetectorStore {}
bool initattempted {}
bool initsucceeded {}
std::map< GeoPVConstLink, MDTChamberInfo >::iterator itLastMDTChamberLookedUp {}
std::map< GeoPVConstLink, MDTChamberInfomdtchambervolinfo

Detailed Description

Definition at line 32 of file MuonChamberProjectionHelper.cxx.

Member Typedef Documentation

◆ ChamberInfoMapItr

Constructor & Destructor Documentation

◆ Imp()

MuonChamberProjectionHelper::Imp::Imp ( MuonChamberProjectionHelper * tc,
StoreGateSvc * ds )
inline

Member Function Documentation

◆ clip2DLineSegmentToRectangle()

bool MuonChamberProjectionHelper::Imp::clip2DLineSegmentToRectangle ( const double & rectX,
const double & rectY,
double & x0,
double & y0,
double & x1,
double & y1 )

Definition at line 523 of file MuonChamberProjectionHelper.cxx.

525{
526 if ( fabs(x0)<=rectX && fabs(y0)<=rectY ) {
527 if ( fabs(x1)>rectX || fabs(y1)>rectY ) {
528 //P0 inside R, P1 outside R. We must change (x1,y1) so P0-P1 is inside R.
529 if (!constrainPointToRectangleAlongLine( rectX, rectY, x0, y0, x1, y1 ))
530 theclass->message("MuonChamberProjectionHelper Error: Should never happen (1)");
531 }
532 } else {
533 if ( fabs(x1)<=rectX && fabs(y1)<=rectY ) {
534 //Point P1 inside R, P0 outside R. We must change (x0,y0) so P0-P1 is inside R.
535 if (!constrainPointToRectangleAlongLine( rectX, rectY, x1, y1, x0, y0 ))
536 theclass->message("MuonChamberProjectionHelper Error: Should never happen (2)");
537 } else {
538 //Both points outside - but the line might still R!
539
540 //First attempt to put (x1,y1) on edge of R, by sliding towards P0
541 if (!constrainPointToRectangleAlongLine( rectX, rectY, x0, y0, x1, y1 )) {
542 //failed - thus P0-P1 doesn't intersect target rectangle.
543 return false;
544 }
545
546 //Now change (x0,y0) so P0-P1 is inside the target rectangle.
547 if (!constrainPointToRectangleAlongLine( rectX, rectY, x1, y1, x0, y0 ))
548 theclass->message("MuonChamberProjectionHelper Error: Should never happen (3)");
549 }
550 }
551
552 return true;
553
554}
static bool constrainPointToRectangleAlongLine(const double &trdX, const double &trdZ, const double &x0, const double &z0, double &x1, double &z1)

◆ constrainPointToRectangleAlongLine()

bool MuonChamberProjectionHelper::Imp::constrainPointToRectangleAlongLine ( const double & trdX,
const double & trdZ,
const double & x0,
const double & z0,
double & x1,
double & z1 )
static

Definition at line 429 of file MuonChamberProjectionHelper.cxx.

432{
433 //rectangle R : { (x,z) | abs(x)<=trdX && abs(z)<=trdZ }
434 //
435 //Returns false if segment from (x0,z0) to (x1,z1) doesn't cross R.
436
437 if ( x1 < -trdX ) {
438 if ( x0 < -trdX )
439 return false;
440 //Move (x1,z1) to x == -trdX line:
441 z1 += (-trdX-x1)*(z1-z0)/(x1-x0);
442 x1 = -trdX;
443 if (fabs(z1)>trdZ)
444 return constrainPointToRectangleAlongLine(trdX,trdZ,x0,z0,x1,z1);
445 }
446
447 if ( x1 > trdX ) {
448 if ( x0 > trdX )
449 return false;
450 //Move (x1,z1) to x == trdX line:
451 z1 += (trdX-x1)*(z1-z0)/(x1-x0);
452 x1 = trdX;
453 if (fabs(z1)>trdZ)
454 return constrainPointToRectangleAlongLine(trdX,trdZ,x0,z0,x1,z1);
455 }
456
457 if ( z1 < -trdZ ) {
458 if ( z0 < -trdZ )
459 return false;
460 //Move (x1,z1) to z == -trdZ line:
461 x1 += (-trdZ-z1)*(x1-x0)/(z1-z0);
462 z1 = -trdZ;
463 if (fabs(x1)>trdX)
464 return constrainPointToRectangleAlongLine(trdX,trdZ,x0,z0,x1,z1);
465 }
466
467 if ( z1 > trdZ ) {
468 if ( z0 > trdZ )
469 return false;
470 //Move (x1,z1) to z == trdZ line:
471 x1 += (trdZ-z1)*(x1-x0)/(z1-z0);
472 z1 = trdZ;
473 if (fabs(x1)>trdX)
474 return constrainPointToRectangleAlongLine(trdX,trdZ,x0,z0,x1,z1);
475 }
476
477 //We were actually inside all along:
478 return true;
479}

◆ ensureInited()

bool MuonChamberProjectionHelper::Imp::ensureInited ( )

Definition at line 158 of file MuonChamberProjectionHelper.cxx.

◆ findTRDInShape()

const GeoTrd * MuonChamberProjectionHelper::Imp::findTRDInShape ( const GeoShape * shape)
inline

Definition at line 85 of file MuonChamberProjectionHelper.cxx.

86 {
87 if (shape->typeID()==GeoTrd::getClassTypeID())
88 return static_cast<const GeoTrd*>(shape);
89 if (shape->typeID() == GeoShapeShift::getClassTypeID() ) {
90 const GeoShapeShift* theShift = static_cast<const GeoShapeShift*>(shape);
91 return findTRDInShape(theShift->getOp());
92 }
93 if (shape->typeID() == GeoShapeSubtraction::getClassTypeID() ) {
94 const GeoShapeSubtraction* theSubtraction = static_cast<const GeoShapeSubtraction*>(shape);
95 const GeoTrd * trd = findTRDInShape(theSubtraction->getOpA());
96 return trd ? trd : findTRDInShape(theSubtraction->getOpB());
97 }
98 if (shape->typeID() == GeoShapeUnion::getClassTypeID() ) {
99 const GeoShapeUnion* theUnion = static_cast<const GeoShapeUnion*>(shape);
100 const GeoTrd * trd = findTRDInShape(theUnion->getOpA());
101 return trd ? trd : findTRDInShape(theUnion->getOpB());
102 }
103 if (shape->typeID() == GeoShapeIntersection::getClassTypeID() ) {
104 const GeoShapeIntersection* theIntersection = static_cast<const GeoShapeIntersection*>(shape);
105 const GeoTrd * trd = findTRDInShape(theIntersection->getOpA());
106 return trd ? trd : findTRDInShape(theIntersection->getOpB());
107 }
108 return 0;
109 }
const GeoTrd * findTRDInShape(const GeoShape *shape)

◆ getMDTChamberVolInfo()

bool MuonChamberProjectionHelper::Imp::getMDTChamberVolInfo ( const GeoPVConstLink & mdtChamber,
ChamberInfoMapItr & itChamberInfo,
bool silent = false )

Definition at line 333 of file MuonChamberProjectionHelper.cxx.

335 {
336
337 if (!ensureInited())
338 return false;
339
340 if (itLastMDTChamberLookedUp->first == mdtChamber) {
341 itChamberInfo = itLastMDTChamberLookedUp;
342 return true;
343 }
344
345 itChamberInfo = mdtchambervolinfo.find(mdtChamber);
346 if (itChamberInfo == mdtchambervolinfo.end()) {
347 if (!silent)
348 theclass->message("MuonChamberProjectionHelper Error: Can't find MDT chamber among the "
349 +QString::number(mdtchambervolinfo.size())+" registered");
350 return false;
351 }
352
353 itLastMDTChamberLookedUp = itChamberInfo;
354
355 return true;
356}
std::map< GeoPVConstLink, MDTChamberInfo > mdtchambervolinfo
std::map< GeoPVConstLink, MDTChamberInfo >::iterator itLastMDTChamberLookedUp

◆ getMDTChamberXAndZ()

void MuonChamberProjectionHelper::Imp::getMDTChamberXAndZ ( ChamberInfoMapItr & itChamberInfo,
double & trdX,
double & trdZ )

Definition at line 359 of file MuonChamberProjectionHelper.cxx.

360{
361 const GeoTrd * trd = itChamberInfo->second.trd;
362 trdX = trd->getXHalfLength1();
363 trdZ = trd->getZHalfLength();
364 if ( trdX != trd->getXHalfLength2() ) {
365 theclass->message("MuonChamberProjectionHelper Warning: x1!=x2 in GeoTrd shape. Clippings etc. will be to a too large surface.");
366 if ( trdX < trd->getXHalfLength2() )
367 trdX = trd->getXHalfLength2();
368 }
369
370}

◆ init()

bool MuonChamberProjectionHelper::Imp::init ( )

Definition at line 185 of file MuonChamberProjectionHelper.cxx.

186{
188 theclass->messageDebug("Warning: Can't init since muon geometry information is not present." );
189 return false;
190 }
191
192 VP1SGAccessHelper * sgaccess(0);
193 if (theclass->systemBase())
194 sgaccess = new VP1SGAccessHelper(theclass->systemBase());
195 else
196 sgaccess = new VP1SGAccessHelper(detectorStore);
197
198 //Locate the world volume if possible:
199 const GeoModelExperiment * theExpt;
200 if (!sgaccess->retrieve( theExpt, "ATLAS" )) {
201 theclass->message("MuonChamberProjectionHelper Error: Can't retrieve"
202 " the ATLAS GeoModelExperiment from detector store.");
203 delete sgaccess;
204 return false;
205 }
206 delete sgaccess;
207
208 PVConstLink world(theExpt->getPhysVol());
209 GeoVolumeCursor av(world);
210 const GeoLogVol * logvol(0);
211 const GeoShape * shape(0);
212 while (!av.atEnd()) {
213
214 if (av.getName()!="Muon") {
215 av.next();
216 continue;
217 }
218 Amg::Transform3D toptransform = av.getTransform();
219 GeoVolumeCursor av2(av.getVolume());
220 while (!av2.atEnd()) {
221 if (nameIsMDTChamber(av2.getName())) {
222 logvol = av2.getVolume()->getLogVol();
223 if (!logvol) {
224 theclass->message("MuonChamberProjectionHelper Error: Chamber has null logvol");
225 av2.next(); // increment volume cursor.
226 continue;
227 }
228 shape = logvol->getShape();
229 if (!shape) {
230 theclass->message("MuonChamberProjectionHelper Error: Chamber has null shape");
231 av2.next(); // increment volume cursor.
232 continue;
233 }
234 const GeoTrd * trd = findTRDInShape(shape);
235 if (trd) {
236 //Fixme: Test for nan's and clearly crazy numbers (if more than 1km for instance).
237 if ( trd->getZHalfLength()>0.0
238 && trd->getXHalfLength1() > 0.0
239 && trd->getXHalfLength2() > 0.0
240 && trd->getYHalfLength1() > 0.0
241 && trd->getYHalfLength2() > 0.0 ) {
242 trd->ref();
243 Amg::Transform3D geovolume_transf = av2.getTransform();
244 mdtchambervolinfo.insert(std::pair<const GeoPVConstLink,MDTChamberInfo>( av2.getVolume(), Imp::MDTChamberInfo(toptransform * geovolume_transf, trd) ));
245 } else {
246 theclass->message("MuonChamberProjectionHelper Error: Chamber trd has non-positive shape parameters!");
247 }
248 } else {
249 theclass->message("MuonChamberProjectionHelper Error: Chamber shape is not a GeoTrd, and is not a boolean with a Trd somewhere");
250 }
251 }
252 av2.next(); // increment volume cursor.
253 }
254 av.next(); // increment volume cursor.
255 }
256
257 if (mdtchambervolinfo.empty()) {
258 theclass->message("MuonChamberProjectionHelper Error: Found no MDT chambers");
259 return false;
260 }
261
263
264 return true;
265}
GeoPhysVol * getPhysVol()
Destructor.
static bool hasMuonGeometry()
Eigen::Affine3d Transform3D

◆ nameIsMDTChamber()

bool MuonChamberProjectionHelper::Imp::nameIsMDTChamber ( const std::string & n)
inline

Definition at line 168 of file MuonChamberProjectionHelper.cxx.

169{
170 //MDT chamber volumes starts with:
171 // Endcap: EI, EM, EO or EE
172 // Inner barrel: BI or BEE
173 // Middle barrel: BM
174 // Outer barrel:BO
175 if (n.size()<3)
176 return false;
177 if (n[0]=='E')
178 return n[1]=='I' || n[1]=='M' || n[1]=='O' || n[1]=='E';
179 if (n[0]=='B')
180 return n[1]=='I' || n[1]=='M' || n[1]=='O' || (n[1]=='E'&&n[2]=='E');
181 return false;
182}

◆ pointToPlaneDistAlongLine()

double MuonChamberProjectionHelper::Imp::pointToPlaneDistAlongLine ( const Amg::Vector3D & point,
const Amg::Vector3D & lineDirection,
const Amg::Vector3D & planePoint,
const Amg::Vector3D & planeNormal )
inline

Definition at line 317 of file MuonChamberProjectionHelper.cxx.

319{
320
321 double denominator(planeNormal.dot(lineDirection)*lineDirection.mag());
322 if (denominator==0.0) {
323 theclass->message("MuonChamberProjectionHelper Error: pointToPlaneDistAlongLine is undefined!");
324 return -1.0;
325 }
326 double numerator(planeNormal.x() * (planePoint.x() - point.x())
327 + planeNormal.y() * (planePoint.y() - point.y())
328 + planeNormal.z() * (planePoint.z() - point.z()));
329 return fabs(numerator/denominator);
330}

◆ projectXZPointToTrdAlongYAxis()

void MuonChamberProjectionHelper::Imp::projectXZPointToTrdAlongYAxis ( const double & x,
const double & z,
const GeoTrd * trd,
Amg::Vector3D & firstEndWall_point,
Amg::Vector3D & secondEndWall_point )

Definition at line 418 of file MuonChamberProjectionHelper.cxx.

420{
421 const double epsilon(0.1);//100micron
422 const double trdY1(trd->getYHalfLength1()), trdY2(trd->getYHalfLength2());
423 const double y( trdY1 + 0.5*(1.0+z/trd->getZHalfLength())*(trdY2-trdY1) );
424 Amg::setVector3DCartesian(firstEndWall_point, x,y+epsilon,z);
425 Amg::setVector3DCartesian(secondEndWall_point, x,-y-epsilon,z);
426}
#define y
#define x
#define z
void setVector3DCartesian(Amg::Vector3D &v1, double x1, double y1, double z1)
Sets components in cartesian coordinate system.

Member Data Documentation

◆ detectorStore

StoreGateSvc* MuonChamberProjectionHelper::Imp::detectorStore {}

Definition at line 40 of file MuonChamberProjectionHelper.cxx.

40{};

◆ initattempted

bool MuonChamberProjectionHelper::Imp::initattempted {}

Definition at line 41 of file MuonChamberProjectionHelper.cxx.

41{};

◆ initsucceeded

bool MuonChamberProjectionHelper::Imp::initsucceeded {}

Definition at line 42 of file MuonChamberProjectionHelper.cxx.

42{};

◆ itLastMDTChamberLookedUp

std::map<GeoPVConstLink,MDTChamberInfo>::iterator MuonChamberProjectionHelper::Imp::itLastMDTChamberLookedUp {}

Definition at line 57 of file MuonChamberProjectionHelper.cxx.

57{};

◆ mdtchambervolinfo

std::map<GeoPVConstLink,MDTChamberInfo> MuonChamberProjectionHelper::Imp::mdtchambervolinfo

Definition at line 58 of file MuonChamberProjectionHelper.cxx.

◆ theclass

MuonChamberProjectionHelper* MuonChamberProjectionHelper::Imp::theclass {}

Definition at line 39 of file MuonChamberProjectionHelper.cxx.

39{};

The documentation for this class was generated from the following file: