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 522 of file MuonChamberProjectionHelper.cxx.

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

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

◆ ensureInited()

bool MuonChamberProjectionHelper::Imp::ensureInited ( )

Definition at line 157 of file MuonChamberProjectionHelper.cxx.

◆ findTRDInShape()

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

Definition at line 84 of file MuonChamberProjectionHelper.cxx.

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

◆ getMDTChamberVolInfo()

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

Definition at line 332 of file MuonChamberProjectionHelper.cxx.

334 {
335
336 if (!ensureInited())
337 return false;
338
339 if (itLastMDTChamberLookedUp->first == mdtChamber) {
340 itChamberInfo = itLastMDTChamberLookedUp;
341 return true;
342 }
343
344 itChamberInfo = mdtchambervolinfo.find(mdtChamber);
345 if (itChamberInfo == mdtchambervolinfo.end()) {
346 if (!silent)
347 theclass->message("MuonChamberProjectionHelper Error: Can't find MDT chamber among the "
348 +QString::number(mdtchambervolinfo.size())+" registered");
349 return false;
350 }
351
352 itLastMDTChamberLookedUp = itChamberInfo;
353
354 return true;
355}
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 358 of file MuonChamberProjectionHelper.cxx.

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

◆ init()

bool MuonChamberProjectionHelper::Imp::init ( )

Definition at line 184 of file MuonChamberProjectionHelper.cxx.

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

◆ nameIsMDTChamber()

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

Definition at line 167 of file MuonChamberProjectionHelper.cxx.

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

◆ 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 316 of file MuonChamberProjectionHelper.cxx.

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

◆ 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 417 of file MuonChamberProjectionHelper.cxx.

419{
420 const double epsilon(0.1);//100micron
421 const double trdY1(trd->getYHalfLength1()), trdY2(trd->getYHalfLength2());
422 const double y( trdY1 + 0.5*(1.0+z/trd->getZHalfLength())*(trdY2-trdY1) );
423 Amg::setVector3DCartesian(firstEndWall_point, x,y+epsilon,z);
424 Amg::setVector3DCartesian(secondEndWall_point, x,-y-epsilon,z);
425}
#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 56 of file MuonChamberProjectionHelper.cxx.

56{};

◆ mdtchambervolinfo

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

Definition at line 57 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: