CMS 3D CMS Logo

Classes | Public Member Functions | Private Member Functions | Private Attributes

TkGluedMeasurementDet Class Reference

#include <TkGluedMeasurementDet.h>

Inheritance diagram for TkGluedMeasurementDet:
MeasurementDet

List of all members.

Classes

class  HitCollectorForFastMeasurements
class  HitCollectorForRecHits

Public Member Functions

virtual std::vector
< TrajectoryMeasurement
fastMeasurements (const TrajectoryStateOnSurface &stateOnThisDet, const TrajectoryStateOnSurface &startingState, const Propagator &, const MeasurementEstimator &) const
bool hasBadComponents (const TrajectoryStateOnSurface &tsos) const
 return TRUE if at least one of the mono and stereo components has badChannels
bool isActive () const
 return TRUE if both mono and stereo components are active
const TkStripMeasurementDetmonoDet () const
template<typename Collector >
void projectOnGluedDet (Collector &collector, const RecHitContainer &hits, const GlobalVector &gdir) const
virtual RecHitContainer recHits (const TrajectoryStateOnSurface &) const
const GluedGeomDetspecificGeomDet () const
const TkStripMeasurementDetstereoDet () const
 TkGluedMeasurementDet (const GluedGeomDet *gdet, const SiStripRecHitMatcher *matcher, const MeasurementDet *monoDet, const MeasurementDet *stereoDet)

Private Member Functions

void checkHitProjection (const TransientTrackingRecHit &hit, const TrajectoryStateOnSurface &ts, const GeomDet &det) const dso_internal
void checkProjection (const TrajectoryStateOnSurface &ts, const RecHitContainer &monoHits, const RecHitContainer &stereoHits) const
template<typename Collector >
void collectRecHits (const TrajectoryStateOnSurface &, Collector &coll) const dso_internal
template<typename Collector >
void doubleMatch (const TrajectoryStateOnSurface &ts, Collector &collector) const dso_internal
template<typename HitCollector >
void projectOnGluedDet (HitCollector &collector, const RecHitContainer &hits, const GlobalVector &gdir) const dso_internal
RecHitContainer projectOnGluedDet (const RecHitContainer &hits, const TrajectoryStateOnSurface &ts) const dso_internal
bool testStrips (const TrajectoryStateOnSurface &tsos, const BoundPlane &gluedPlane, const TkStripMeasurementDet &mdet) const dso_internal
 Test the strips on one of the two dets with projection.

Private Attributes

const GluedGeomDettheGeomDet
const SiStripRecHitMatchertheMatcher
const TkStripMeasurementDettheMonoDet
const TkStripMeasurementDettheStereoDet

Detailed Description

Definition at line 18 of file TkGluedMeasurementDet.h.


Constructor & Destructor Documentation

TkGluedMeasurementDet::TkGluedMeasurementDet ( const GluedGeomDet gdet,
const SiStripRecHitMatcher matcher,
const MeasurementDet monoDet,
const MeasurementDet stereoDet 
)

Definition at line 23 of file TkGluedMeasurementDet.cc.

References theMonoDet, and theStereoDet.

                                                                               :
  MeasurementDet(gdet), theGeomDet(gdet), 
  theMatcher(matcher), 
  theMonoDet( dynamic_cast<const TkStripMeasurementDet *>(monoDet)), 
  theStereoDet( dynamic_cast<const TkStripMeasurementDet *>(stereoDet))
{
  if ((theMonoDet == 0) || (theStereoDet == 0)) {
        throw MeasurementDetException("TkGluedMeasurementDet ERROR: Trying to glue a det which is not a TkStripMeasurementDet");
  }
  
}

Member Function Documentation

void TkGluedMeasurementDet::checkHitProjection ( const TransientTrackingRecHit hit,
const TrajectoryStateOnSurface ts,
const GeomDet det 
) const [private]

Definition at line 198 of file TkGluedMeasurementDet.cc.

References gather_cfg::cout, prof2calltree::cutoff, TrajectoryStateOnSurface::localError(), TrajectoryStateOnSurface::localPosition(), mag(), max(), LocalTrajectoryError::positionError(), TrackingRecHitProjector< ResultingHit >::project(), RecHitPropagator::propagate(), GeomDet::surface(), LocalError::xx(), LocalError::xy(), and LocalError::yy().

Referenced by checkProjection().

{
  TrackingRecHitProjector<ProjectedRecHit2D> proj;
  TransientTrackingRecHit::RecHitPointer projectedHit = proj.project( hit, det, ts);

  RecHitPropagator prop;
  TrajectoryStateOnSurface propState = prop.propagate( hit, det.surface(), ts);

  if ((projectedHit->localPosition()-propState.localPosition()).mag() > 0.0001) {
    cout << "PROBLEM: projected and propagated hit positions differ by " 
         << (projectedHit->localPosition()-propState.localPosition()).mag() << endl;
  }

  LocalError le1 = projectedHit->localPositionError();
  LocalError le2 = propState.localError().positionError();
  double eps = 1.e-5;
  double cutoff = 1.e-4; // if element below cutoff, use absolute instead of relative accuracy
  double maxdiff = std::max( std::max( fabs(le1.xx() - le2.xx())/(cutoff+le1.xx()),
                                       fabs(le1.xy() - le2.xy())/(cutoff+fabs(le1.xy()))),
                             fabs(le1.yy() - le2.yy())/(cutoff+le1.xx()));  
  if (maxdiff > eps) { 
    cout << "PROBLEM: projected and propagated hit errors differ by " 
         << maxdiff << endl;
  }
  
}
void TkGluedMeasurementDet::checkProjection ( const TrajectoryStateOnSurface ts,
const RecHitContainer monoHits,
const RecHitContainer stereoHits 
) const [private]

Definition at line 186 of file TkGluedMeasurementDet.cc.

References checkHitProjection(), MeasurementDet::geomDet(), and i.

{
  for (RecHitContainer::const_iterator i=monoHits.begin(); i != monoHits.end(); ++i) {
    checkHitProjection( **i, ts, geomDet());
  }
  for (RecHitContainer::const_iterator i=stereoHits.begin(); i != stereoHits.end(); ++i) {
    checkHitProjection( **i, ts, geomDet());
  }
}
template<typename Collector >
void TkGluedMeasurementDet::collectRecHits ( const TrajectoryStateOnSurface ts,
Collector &  coll 
) const [private]

Definition at line 60 of file TkGluedMeasurementDet.cc.

References TrajectoryStateOnSurface::globalParameters(), TrajectoryStateOnSurface::isValid(), TrajectoryStateOnSurface::localDirection(), SiStripRecHitMatcher::match(), GlobalTrajectoryParameters::momentum(), MeasurementDet::position(), projectOnGluedDet(), TkStripMeasurementDet::recHits(), TkStripMeasurementDet::simpleRecHits(), specificGeomDet(), MeasurementDet::surface(), theMatcher, theMonoDet, theStereoDet, and GloballyPositioned< T >::toLocal().

Referenced by fastMeasurements(), and recHits().

{
  //------ WARNING: here ts is used as it is on the mono/stereo surface.
  //-----           A further propagation is necessary.
  //-----           To limit the problem, the SimpleCPE should be used
  RecHitContainer monoHits = theMonoDet->recHits( ts);
  GlobalVector glbDir = (ts.isValid() ? ts.globalParameters().momentum() : position()-GlobalPoint(0,0,0));

  //edm::LogWarning("TkGluedMeasurementDet::recHits") << "Query-for-detid-" << theGeomDet->geographicalId().rawId();

  //checkProjection(ts, monoHits, stereoHits);

  if (monoHits.empty()) {
      // make stereo TTRHs and project them
      projectOnGluedDet( collector, theStereoDet->recHits(ts), glbDir);
  } else {
      // collect simple stereo hits
      static std::vector<SiStripRecHit2D> simpleSteroHitsByValue;
      simpleSteroHitsByValue.clear();
      theStereoDet->simpleRecHits(ts, simpleSteroHitsByValue);

      if (simpleSteroHitsByValue.empty()) {
          projectOnGluedDet( collector, monoHits, glbDir);
      } else {

          LocalVector tkDir = (ts.isValid() ? ts.localDirection() : surface().toLocal( position()-GlobalPoint(0,0,0)));
          static SiStripRecHitMatcher::SimpleHitCollection vsStereoHits;
          vsStereoHits.resize(simpleSteroHitsByValue.size());
          std::transform(simpleSteroHitsByValue.begin(), simpleSteroHitsByValue.end(), vsStereoHits.begin(), take_address()); 

          // convert mono hits to type expected by matcher
          for (RecHitContainer::const_iterator monoHit = monoHits.begin();
                  monoHit != monoHits.end(); ++monoHit) {
              const TrackingRecHit* tkhit = (**monoHit).hit();
              const SiStripRecHit2D* verySpecificMonoHit = reinterpret_cast<const SiStripRecHit2D*>(tkhit);
              theMatcher->match( verySpecificMonoHit, vsStereoHits.begin(), vsStereoHits.end(), 
                      collector.collector(), &specificGeomDet(), tkDir);

              if (collector.hasNewMatchedHits()) {
                  collector.clearNewMatchedHitsFlag();
              } else {
                  collector.addProjected( **monoHit, glbDir );
              }
          } // loop on mono hit
      }
      //GIO// std::cerr << "TkGluedMeasurementDet hits " << monoHits.size() << "/" << stereoHits.size() << " => " << result.size() << std::endl;
  }
}
template<typename Collector >
void TkGluedMeasurementDet::doubleMatch ( const TrajectoryStateOnSurface ts,
Collector &  collector 
) const [private]
std::vector< TrajectoryMeasurement > TkGluedMeasurementDet::fastMeasurements ( const TrajectoryStateOnSurface stateOnThisDet,
const TrajectoryStateOnSurface startingState,
const Propagator ,
const MeasurementEstimator  
) const [virtual]

faster version in case the TrajectoryState on the surface of the Det is already available. The first TrajectoryStateOnSurface is on the surface of this Det, and the second TrajectoryStateOnSurface is the statrting state, usually not on the surface of this Det. The stateOnThisDet should the result of
prop.propagate( startingState, this->surface())

Implements MeasurementDet.

Definition at line 111 of file TkGluedMeasurementDet.cc.

References InvalidTransientRecHit::build(), collectRecHits(), MeasurementDet::geomDet(), TkStripMeasurementDet::hasAllGoodChannels(), TrajectoryStateOnSurface::hasError(), TrackingRecHit::inactive, TkStripMeasurementDet::isActive(), query::result, python::multivaluedict::sort(), GeomDet::surface(), testStrips(), theMatcher, theMonoDet, and theStereoDet.

{
   std::vector<TrajectoryMeasurement> result;
   if (theMonoDet->isActive() || theStereoDet->isActive()) {

      HitCollectorForFastMeasurements collector( &geomDet(), theMatcher, stateOnThisDet, est, result);
      collectRecHits(stateOnThisDet, collector);
       
      if ( result.empty()) {
          //LogDebug("TkStripMeasurementDet") << "No hit found on TkGlued. Testing strips...  ";
          const BoundPlane &gluedPlane = geomDet().surface();
          if (  // sorry for the big IF, but I want to exploit short-circuiting of logic
               stateOnThisDet.hasError() && ( /* do this only if the state has uncertainties, otherwise it will throw 
                                                 (states without uncertainties are passed to this code from seeding */
                (theMonoDet->isActive() && 
                    (theMonoDet->hasAllGoodChannels() || 
                       testStrips(stateOnThisDet,gluedPlane,*theMonoDet)
                    )
                ) /*Mono OK*/ || 
                (theStereoDet->isActive() && 
                    (theStereoDet->hasAllGoodChannels() || 
                       testStrips(stateOnThisDet,gluedPlane,*theStereoDet)
                    )
                ) /*Stereo OK*/ 
               ) /* State has errors */
              ) {
              result.push_back( TrajectoryMeasurement( stateOnThisDet, 
                          InvalidTransientRecHit::build(&geomDet()), 0.F)); 
          } else {
              result.push_back( TrajectoryMeasurement(stateOnThisDet, 
                         InvalidTransientRecHit::build(&geomDet(), TrackingRecHit::inactive), 0.F));
          }
      } else {
          // sort results according to estimator value
          if ( result.size() > 1) {
              sort( result.begin(), result.end(), TrajMeasLessEstim());
          }
      }
   } else {
     //     LogDebug("TkStripMeasurementDet") << " DetID " << geomDet().geographicalId().rawId() << " (glued) fully inactive";
      result.push_back( TrajectoryMeasurement( stateOnThisDet, 
               InvalidTransientRecHit::build(&geomDet(), TrackingRecHit::inactive), 
               0.F));
   }
   return result;       

}
bool TkGluedMeasurementDet::hasBadComponents ( const TrajectoryStateOnSurface tsos) const [inline, virtual]

return TRUE if at least one of the mono and stereo components has badChannels

Implements MeasurementDet.

Definition at line 42 of file TkGluedMeasurementDet.h.

References monoDet(), and stereoDet().

                                                                      {
    return (monoDet()->hasBadComponents(tsos) || stereoDet()->hasBadComponents(tsos));}
bool TkGluedMeasurementDet::isActive ( ) const [inline, virtual]

return TRUE if both mono and stereo components are active

Implements MeasurementDet.

Definition at line 39 of file TkGluedMeasurementDet.h.

References TkStripMeasurementDet::isActive(), monoDet(), and stereoDet().

{return monoDet()->isActive() && stereoDet()->isActive(); }
const TkStripMeasurementDet* TkGluedMeasurementDet::monoDet ( ) const [inline]

Definition at line 35 of file TkGluedMeasurementDet.h.

References theMonoDet.

Referenced by hasBadComponents(), OnDemandMeasurementTracker::idToDet(), and isActive().

{ return theMonoDet;} 
TkGluedMeasurementDet::RecHitContainer TkGluedMeasurementDet::projectOnGluedDet ( const RecHitContainer hits,
const TrajectoryStateOnSurface ts 
) const [private]

Definition at line 163 of file TkGluedMeasurementDet.cc.

References MeasurementDet::geomDet(), TrackingRecHitProjector< ResultingHit >::project(), and query::result.

Referenced by collectRecHits().

{
  if (hits.empty()) return hits;
  TrackingRecHitProjector<ProjectedRecHit2D> proj;
  RecHitContainer result;
  for ( RecHitContainer::const_iterator ihit = hits.begin(); ihit!=hits.end(); ihit++) {
    result.push_back( proj.project( **ihit, geomDet(), ts));
  }
  return result;
}
template<typename HitCollector >
void TkGluedMeasurementDet::projectOnGluedDet ( HitCollector &  collector,
const RecHitContainer hits,
const GlobalVector gdir 
) const [private]
template<typename Collector >
void TkGluedMeasurementDet::projectOnGluedDet ( Collector &  collector,
const RecHitContainer hits,
const GlobalVector gdir 
) const

Definition at line 177 of file TkGluedMeasurementDet.cc.

{
  for ( RecHitContainer::const_iterator ihit = hits.begin(); ihit!=hits.end(); ihit++) {
    collector.addProjected( **ihit, gdir );
  }
}
TkGluedMeasurementDet::RecHitContainer TkGluedMeasurementDet::recHits ( const TrajectoryStateOnSurface ts) const [virtual]

Implements MeasurementDet.

Definition at line 39 of file TkGluedMeasurementDet.cc.

References collectRecHits(), MeasurementDet::geomDet(), query::result, and theMatcher.

{

  RecHitContainer result;
  HitCollectorForRecHits collector( &geomDet(), theMatcher, result );
  collectRecHits(ts, collector);
  return result;
}
const GluedGeomDet& TkGluedMeasurementDet::specificGeomDet ( ) const [inline]

Definition at line 27 of file TkGluedMeasurementDet.h.

References theGeomDet.

Referenced by collectRecHits().

{return *theGeomDet;}
const TkStripMeasurementDet* TkGluedMeasurementDet::stereoDet ( ) const [inline]

Definition at line 36 of file TkGluedMeasurementDet.h.

References theStereoDet.

Referenced by hasBadComponents(), OnDemandMeasurementTracker::idToDet(), and isActive().

{ return theStereoDet;} 
bool TkGluedMeasurementDet::testStrips ( const TrajectoryStateOnSurface tsos,
const BoundPlane gluedPlane,
const TkStripMeasurementDet mdet 
) const [private]

Test the strips on one of the two dets with projection.

Definition at line 228 of file TkGluedMeasurementDet.cc.

References delta, Vector3DBase< T, FrameTag >::dot(), MeasurementDet::geomDet(), TrajectoryStateOnSurface::globalParameters(), TrajectoryStateOnSurface::globalPosition(), TrajectoryStateOnSurface::localError(), Plane::localZ(), Topology::measurementError(), Topology::measurementPosition(), GlobalTrajectoryParameters::momentum(), Plane::normalVector(), pos, LocalTrajectoryError::positionError(), LocalError::rotate(), TkStripMeasurementDet::specificGeomDet(), StripGeomDetUnit::specificTopology(), mathSSE::sqrt(), GeomDet::surface(), TkStripMeasurementDet::testStrips(), Surface::toGlobal(), GloballyPositioned< T >::toLocal(), MeasurementError::uu(), PV3DBase< T, PVType, FrameType >::x(), PV2DBase< T, PVType, FrameType >::x(), LocalError::xx(), LocalError::xy(), PV3DBase< T, PVType, FrameType >::y(), LocalError::yy(), and PV3DBase< T, PVType, FrameType >::z().

Referenced by fastMeasurements().

                                                                           {
   // from TrackingRecHitProjector
   const GeomDet &det = mdet.geomDet();
   const BoundPlane &stripPlane = det.surface();

   //LocalPoint glp = tsos.localPosition();
   LocalError  err = tsos.localError().positionError();
   /*LogDebug("TkStripMeasurementDet") << 
      "Testing local pos glued: " << glp << 
      " local err glued: " << tsos.localError().positionError() << 
      " in? " << gluedPlane.bounds().inside(glp) <<
      " in(3s)? " << gluedPlane.bounds().inside(glp, err, 3.0f);*/

   GlobalVector gdir = tsos.globalParameters().momentum();

   LocalPoint  slp = stripPlane.toLocal(tsos.globalPosition()); 
   LocalVector sld = stripPlane.toLocal(gdir);

   double delta = stripPlane.localZ( tsos.globalPosition());
   LocalPoint pos = slp - sld * delta/sld.z();


   // now the error
   LocalVector hitXAxis = stripPlane.toLocal( gluedPlane.toGlobal( LocalVector(1,0,0)));
   if (stripPlane.normalVector().dot( gluedPlane.normalVector()) < 0) {
       // the two planes are inverted, and the correlation element must change sign
       err = LocalError( err.xx(), -err.xy(), err.yy());
   }
   LocalError rotatedError = err.rotate( hitXAxis.x(), hitXAxis.y());

   /* // This is probably meaningless 
   LogDebug("TkStripMeasurementDet") << 
      "Testing local pos on strip (SLP): " << slp << 
      " in? :" << stripPlane.bounds().inside(slp) <<
      " in(3s)? :" << stripPlane.bounds().inside(slp, rotatedError, 3.0f);
   // but it helps to test bugs in the formula for POS */
   /*LogDebug("TkStripMeasurementDet") << 
      "Testing local pos strip: " << pos << 
      " in? " << stripPlane.bounds().inside(pos) <<
      " in(3s)? " << stripPlane.bounds().inside(pos, rotatedError, 3.0f);*/

   // now we need to convert to MeasurementFrame
   const StripTopology &topo = mdet.specificGeomDet().specificTopology();
   float utraj = topo.measurementPosition(pos).x();
   float uerr  = std::sqrt(topo.measurementError(pos,rotatedError).uu());
   return mdet.testStrips(utraj, uerr);
} 

Member Data Documentation

Reimplemented from MeasurementDet.

Definition at line 46 of file TkGluedMeasurementDet.h.

Referenced by specificGeomDet().

Definition at line 47 of file TkGluedMeasurementDet.h.

Referenced by collectRecHits(), fastMeasurements(), and recHits().