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

MuonChamberProjectionHelper * theclass {}
StoreGateSvc * detectorStore {}
bool initattempted {}
bool initsucceeded {}
std::map< GeoPVConstLink, MDTChamberInfo >::iterator itLastMDTChamberLookedUp {}
std::map< GeoPVConstLink, MDTChamberInfo > mdtchambervolinfo

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

504{
505 if ( fabs(x0)<=rectX && fabs(y0)<=rectY ) {
506 if ( fabs(x1)>rectX || fabs(y1)>rectY ) {
507 //P0 inside R, P1 outside R. We must change (x1,y1) so P0-P1 is inside R.
508 if (!constrainPointToRectangleAlongLine( rectX, rectY, x0, y0, x1, y1 ))
509 theclass->message("MuonChamberProjectionHelper Error: Should never happen (1)");
510 }
511 } else {
512 if ( fabs(x1)<=rectX && fabs(y1)<=rectY ) {
513 //Point P1 inside R, P0 outside R. We must change (x0,y0) so P0-P1 is inside R.
514 if (!constrainPointToRectangleAlongLine( rectX, rectY, x1, y1, x0, y0 ))
515 theclass->message("MuonChamberProjectionHelper Error: Should never happen (2)");
516 } else {
517 //Both points outside - but the line might still R!
518
519 //First attempt to put (x1,y1) on edge of R, by sliding towards P0
520 if (!constrainPointToRectangleAlongLine( rectX, rectY, x0, y0, x1, y1 )) {
521 //failed - thus P0-P1 doesn't intersect target rectangle.
522 return false;
523 }
524
525 //Now change (x0,y0) so P0-P1 is inside the target rectangle.
526 if (!constrainPointToRectangleAlongLine( rectX, rectY, x1, y1, x0, y0 ))
527 theclass->message("MuonChamberProjectionHelper Error: Should never happen (3)");
528 }
529 }
530
531 return true;
532
533}
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 410 of file MuonChamberProjectionHelper.cxx.

413{
414 //rectangle R : { (x,z) | abs(x)<=trdX && abs(z)<=trdZ }
415 //
416 //Returns false if segment from (x0,z0) to (x1,z1) doesn't cross R.
417
418 if ( x1 < -trdX ) {
419 if ( x0 < -trdX )
420 return false;
421 //Move (x1,z1) to x == -trdX line:
422 z1 += (-trdX-x1)*(z1-z0)/(x1-x0);
423 x1 = -trdX;
424 if (fabs(z1)>trdZ)
425 return constrainPointToRectangleAlongLine(trdX,trdZ,x0,z0,x1,z1);
426 }
427
428 if ( x1 > trdX ) {
429 if ( x0 > trdX )
430 return false;
431 //Move (x1,z1) to x == trdX line:
432 z1 += (trdX-x1)*(z1-z0)/(x1-x0);
433 x1 = trdX;
434 if (fabs(z1)>trdZ)
435 return constrainPointToRectangleAlongLine(trdX,trdZ,x0,z0,x1,z1);
436 }
437
438 if ( z1 < -trdZ ) {
439 if ( z0 < -trdZ )
440 return false;
441 //Move (x1,z1) to z == -trdZ line:
442 x1 += (-trdZ-z1)*(x1-x0)/(z1-z0);
443 z1 = -trdZ;
444 if (fabs(x1)>trdX)
445 return constrainPointToRectangleAlongLine(trdX,trdZ,x0,z0,x1,z1);
446 }
447
448 if ( z1 > trdZ ) {
449 if ( z0 > trdZ )
450 return false;
451 //Move (x1,z1) to z == trdZ line:
452 x1 += (trdZ-z1)*(x1-x0)/(z1-z0);
453 z1 = trdZ;
454 if (fabs(x1)>trdX)
455 return constrainPointToRectangleAlongLine(trdX,trdZ,x0,z0,x1,z1);
456 }
457
458 //We were actually inside all along:
459 return true;
460}

◆ ensureInited()

bool MuonChamberProjectionHelper::Imp::ensureInited ( )

Definition at line 143 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 318 of file MuonChamberProjectionHelper.cxx.

320 {
321
322 if (!ensureInited())
323 return false;
324
325 if (itLastMDTChamberLookedUp->first == mdtChamber) {
326 itChamberInfo = itLastMDTChamberLookedUp;
327 return true;
328 }
329
330 itChamberInfo = mdtchambervolinfo.find(mdtChamber);
331 if (itChamberInfo == mdtchambervolinfo.end()) {
332 if (!silent)
333 theclass->message("MuonChamberProjectionHelper Error: Can't find MDT chamber among the "
334 +QString::number(mdtchambervolinfo.size())+" registered");
335 return false;
336 }
337
338 itLastMDTChamberLookedUp = itChamberInfo;
339
340 return true;
341}
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 344 of file MuonChamberProjectionHelper.cxx.

345{
346 const GeoTrd * trd = itChamberInfo->second.trd;
347 trdX = trd->getXHalfLength1();
348 trdZ = trd->getZHalfLength();
349 if ( trdX != trd->getXHalfLength2() ) {
350 theclass->message("MuonChamberProjectionHelper Warning: x1!=x2 in GeoTrd shape. Clippings etc. will be to a too large surface.");
351 if ( trdX < trd->getXHalfLength2() )
352 trdX = trd->getXHalfLength2();
353 }
354
355}

◆ init()

bool MuonChamberProjectionHelper::Imp::init ( )

Definition at line 170 of file MuonChamberProjectionHelper.cxx.

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

◆ nameIsMDTChamber()

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

Definition at line 153 of file MuonChamberProjectionHelper.cxx.

154{
155 //MDT chamber volumes starts with:
156 // Endcap: EI, EM, EO or EE
157 // Inner barrel: BI or BEE
158 // Middle barrel: BM
159 // Outer barrel:BO
160 if (n.size()<3)
161 return false;
162 if (n[0]=='E')
163 return n[1]=='I' || n[1]=='M' || n[1]=='O' || n[1]=='E';
164 if (n[0]=='B')
165 return n[1]=='I' || n[1]=='M' || n[1]=='O' || (n[1]=='E'&&n[2]=='E');
166 return false;
167}

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

304{
305
306 double denominator(planeNormal.dot(lineDirection)*lineDirection.mag());
307 if (denominator==0.0) {
308 theclass->message("MuonChamberProjectionHelper Error: pointToPlaneDistAlongLine is undefined!");
309 return -1.0;
310 }
311 double numerator(planeNormal.x() * (planePoint.x() - point.x())
312 + planeNormal.y() * (planePoint.y() - point.y())
313 + planeNormal.z() * (planePoint.z() - point.z()));
314 return fabs(numerator/denominator);
315}

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

401{
402 const double epsilon(0.1);//100micron
403 const double trdY1(trd->getYHalfLength1()), trdY2(trd->getYHalfLength2());
404 const double y( trdY1 + 0.5*(1.0+z/trd->getZHalfLength())*(trdY2-trdY1) );
405 firstEndWall_point= Amg::Vector3D{ x,y+epsilon,z};
406 secondEndWall_point= Amg::Vector3D{x,-y-epsilon,z};
407}
#define y
#define x
#define z
Eigen::Matrix< double, 3, 1 > Vector3D

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: