20 #include "GeoModelKernel/GeoVolumeCursor.h" 
   21 #include "GeoModelKernel/GeoLogVol.h" 
   22 #include "GeoModelKernel/GeoTrd.h" 
   23 #include "GeoModelKernel/GeoShapeShift.h" 
   24 #include "GeoModelKernel/GeoShapeUnion.h" 
   25 #include "GeoModelKernel/GeoShapeIntersection.h" 
   26 #include "GeoModelKernel/GeoShapeSubtraction.h" 
   74                           double& 
x1, 
double& z1 );
 
   78                         double& x0, 
double& y0, 
double& 
x1, 
double& 
y1 );
 
   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);
 
   93     if (shape->typeID() == GeoShapeSubtraction::getClassTypeID() ) {
 
   94       const GeoShapeSubtraction* theSubtraction = 
static_cast<const GeoShapeSubtraction*
>(shape);
 
   98     if (shape->typeID() == GeoShapeUnion::getClassTypeID() ) {
 
   99       const GeoShapeUnion* theUnion = 
static_cast<const GeoShapeUnion*
>(shape);
 
  103     if (shape->typeID() == GeoShapeIntersection::getClassTypeID() ) {
 
  104       const GeoShapeIntersection* theIntersection = 
static_cast<const GeoShapeIntersection*
>(shape);
 
  120     message(
"ERROR: Received NULL detectorstore");
 
  128     message(
"ERROR: Received NULL system pointer (and thus can't get detector store pointer");
 
  130     message(
"ERROR: Could not get detectorStore pointer from system pointer");
 
  138     itMDT->second.trd->unref();
 
  146   double vx = 
v.x(), vy = 
v.y(), vz = 
v.z();
 
  151           m(0,0)*vx + 
m(0,1)*vy + 
m(0,2)*vz,
 
  152           m(1,0)*vx + 
m(1,1)*vy + 
m(1,2)*vz,
 
  153           m(2,0)*vx + 
m(2,1)*vy + 
m(2,2)*vz);
 
  178     return n[1]==
'I' || 
n[1]==
'M' || 
n[1]==
'O' || 
n[1]==
'E';
 
  180     return n[1]==
'I' || 
n[1]==
'M' || 
n[1]==
'O' || (
n[1]==
'E'&&
n[2]==
'E');
 
  188     theclass->messageDebug(
"Warning: Can't init since muon geometry information is not present." );
 
  193   if (theclass->systemBase())
 
  200   if (!sgaccess->
retrieve( theExpt, 
"ATLAS" )) {
 
  201     theclass->message(
"MuonChamberProjectionHelper Error: Can't retrieve" 
  202               " the ATLAS GeoModelExperiment from detector store.");
 
  209   GeoVolumeCursor av(world);
 
  210   const GeoLogVol * logvol(0);
 
  211   const GeoShape * shape(0);
 
  212   while (!av.atEnd()) {
 
  214     if (av.getName()!=
"Muon") {
 
  219     GeoVolumeCursor av2(av.getVolume());
 
  220     while (!av2.atEnd()) {
 
  221       if (nameIsMDTChamber(av2.getName())) {
 
  222     logvol = av2.getVolume()->getLogVol();
 
  224       theclass->message(
"MuonChamberProjectionHelper Error: Chamber has null logvol");
 
  228     shape = logvol->getShape();
 
  230       theclass->message(
"MuonChamberProjectionHelper Error: Chamber has null shape");
 
  234     const GeoTrd * trd = findTRDInShape(shape);
 
  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 ) {
 
  244         mdtchambervolinfo.insert(std::pair<const GeoPVConstLink,MDTChamberInfo>( av2.getVolume(), 
Imp::MDTChamberInfo(toptransform * geovolume_transf, trd) ));
 
  246         theclass->message(
"MuonChamberProjectionHelper Error: Chamber trd has non-positive shape parameters!");
 
  249       theclass->message(
"MuonChamberProjectionHelper Error: Chamber shape is not a GeoTrd, and is not a boolean with a Trd somewhere");
 
  257   if (mdtchambervolinfo.empty()) {
 
  258     theclass->message(
"MuonChamberProjectionHelper Error: Found no MDT chambers");
 
  262   itLastMDTChamberLookedUp = mdtchambervolinfo.begin();
 
  277                                       double& distanceToFirstEndPlane, 
double& distanceToSecondEndPlane,
 
  284   const GeoTrd * trd = itChamberInfo->second.trd;
 
  285   double y1(trd->getYHalfLength1()), 
y2(trd->getYHalfLength2()), 
z(trd->getZHalfLength());
 
  297   if (distanceToFirstEndPlane < 0.0 )
 
  301   if (distanceToSecondEndPlane < 0.0 )
 
  307     double costheta1 = unitdir.dot(
n1.unit());
 
  308     double costheta2 = unitdir.dot(n2.unit());
 
  310     distanceToFirstEndPlane += 
r*sqrt(fabs((1-costheta1*costheta1)/costheta1));
 
  311     distanceToSecondEndPlane += 
r*sqrt(fabs((1-costheta2*costheta2)/costheta2));
 
  321   double denominator(planeNormal.dot(lineDirection)*lineDirection.mag());
 
  323     theclass->message(
"MuonChamberProjectionHelper Error: pointToPlaneDistAlongLine is undefined!");
 
  326   double numerator(planeNormal.x() * (planePoint.x() - point.x())
 
  327            + planeNormal.y() * (planePoint.y() - point.y())
 
  328            + planeNormal.z() * (planePoint.z() - point.z()));
 
  340   if (itLastMDTChamberLookedUp->first == mdtChamber) {
 
  341     itChamberInfo = itLastMDTChamberLookedUp;
 
  345   itChamberInfo = mdtchambervolinfo.find(mdtChamber);
 
  346   if (itChamberInfo == mdtchambervolinfo.end()) {
 
  348       theclass->message(
"MuonChamberProjectionHelper Error: Can't find MDT chamber among the " 
  353   itLastMDTChamberLookedUp = itChamberInfo;
 
  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();
 
  377                                               bool& outsidechamber )
 
  387   itChamberInfo->second.ensureInitGlobalToLocal();
 
  388   Amg::Vector3D A((*(itChamberInfo->second.globalToLocal))*pointA), 
B((*(itChamberInfo->second.globalToLocal))*pointB);
 
  389   double ax(
A.x()), az(
A.z()), 
bx(
B.x()), 
bz(
B.z());
 
  408   Amg::transform(firstEndWall_pointA, itChamberInfo->second.localToGlobal);
 
  409   Amg::transform(secondEndWall_pointA, itChamberInfo->second.localToGlobal);
 
  410   Amg::transform(firstEndWall_pointB, itChamberInfo->second.localToGlobal);
 
  411   Amg::transform(secondEndWall_pointB, itChamberInfo->second.localToGlobal);
 
  413   outsidechamber = 
false;
 
  422   const double trdY1(trd->getYHalfLength1()), trdY2(trd->getYHalfLength2());
 
  423   const double y( trdY1 + 0.5*(1.0+
z/trd->getZHalfLength())*(trdY2-trdY1) );
 
  430                                        const double& x0, 
const double& 
z0,
 
  431                                        double& 
x1, 
double& z1 )
 
  441     z1 += (-trdX-
x1)*(z1-
z0)/(
x1-x0);
 
  444       return constrainPointToRectangleAlongLine(trdX,trdZ,x0,
z0,
x1,z1);
 
  451     z1 += (trdX-
x1)*(z1-
z0)/(
x1-x0);
 
  454       return constrainPointToRectangleAlongLine(trdX,trdZ,x0,
z0,
x1,z1);
 
  461     x1 += (-trdZ-z1)*(
x1-x0)/(z1-
z0);
 
  464       return constrainPointToRectangleAlongLine(trdX,trdZ,x0,
z0,
x1,z1);
 
  471     x1 += (trdZ-z1)*(
x1-x0)/(z1-
z0);
 
  474       return constrainPointToRectangleAlongLine(trdX,trdZ,x0,
z0,
x1,z1);
 
  484                                    const double & extradist )
 
  496   if (trdX<=0.0||trdZ<=0.0)
 
  500   itChamberInfo->second.ensureInitGlobalToLocal();
 
  501   Amg::Vector3D A((*(itChamberInfo->second.globalToLocal))*pointA), 
B((*(itChamberInfo->second.globalToLocal))*pointB);
 
  502   double ax(
A.x()), az(
A.z()), 
bx(
B.x()), 
bz(
B.z());
 
  509   double ay(
A.y()), 
by(
B.y());
 
  517   outsidechamber = 
false;
 
  524                                      double& x0, 
double& y0, 
double& 
x1, 
double& 
y1 )
 
  526   if ( fabs(x0)<=rectX && fabs(y0)<=rectY  ) {
 
  527     if ( fabs(
x1)>rectX || fabs(
y1)>rectY  ) {
 
  529       if (!constrainPointToRectangleAlongLine( rectX, rectY, x0, y0, 
x1, 
y1 ))
 
  530     theclass->message(
"MuonChamberProjectionHelper Error: Should never happen (1)");
 
  533     if ( fabs(
x1)<=rectX && fabs(
y1)<=rectY  ) {
 
  535       if (!constrainPointToRectangleAlongLine( rectX, rectY, 
x1, 
y1, x0, y0 ))
 
  536     theclass->message(
"MuonChamberProjectionHelper Error: Should never happen (2)");
 
  541       if (!constrainPointToRectangleAlongLine( rectX, rectY, x0, y0, 
x1, 
y1 )) {
 
  547       if (!constrainPointToRectangleAlongLine( rectX, rectY, 
x1, 
y1, x0, y0 ))
 
  548     theclass->message(
"MuonChamberProjectionHelper Error: Should never happen (3)");