CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/RecoTracker/MeasurementDet/plugins/TkPixelMeasurementDet.cc

Go to the documentation of this file.
00001 #include "TkPixelMeasurementDet.h"
00002 #include "TrackingTools/TransientTrackingRecHit/interface/InvalidTransientRecHit.h"
00003 #include "Geometry/CommonTopologies/interface/PixelTopology.h"
00004 #include "TrackingTools/MeasurementDet/interface/MeasurementDetException.h"
00005 #include "TrackingTools/PatternTools/interface/TrajectoryMeasurement.h"
00006 #include "RecoTracker/TransientTrackingRecHit/interface/TSiPixelRecHit.h"
00007 #include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHit.h"
00008 #include "TrackingTools/PatternTools/interface/MeasurementEstimator.h"
00009 #include "TrackingTools/PatternTools/interface/TrajMeasLessEstim.h"
00010 
00011 
00012 namespace {
00013   const float theRocWidth  = 8.1;
00014   const float theRocHeight = 8.1;
00015 }
00016 
00017 TkPixelMeasurementDet::TkPixelMeasurementDet( const GeomDet* gdet,
00018                                               const PixelClusterParameterEstimator* cpe) : 
00019     MeasurementDet (gdet),
00020     theCPE(cpe),
00021     skipClusters_(0),
00022     empty(true),
00023     activeThisEvent_(true), activeThisPeriod_(true)
00024   {
00025     if ( dynamic_cast<const PixelGeomDetUnit*>(gdet) == 0) {
00026       throw MeasurementDetException( "TkPixelMeasurementDet constructed with a GeomDet which is not a PixelGeomDetUnit");
00027     }
00028   }
00029 
00030 std::vector<TrajectoryMeasurement> 
00031 TkPixelMeasurementDet::fastMeasurements( const TrajectoryStateOnSurface& stateOnThisDet, 
00032                                          const TrajectoryStateOnSurface& startingState, 
00033                                          const Propagator&, 
00034                                          const MeasurementEstimator& est) const
00035 {
00036   std::vector<TrajectoryMeasurement> result;
00037 
00038   if (isActive() == false) {
00039     result.push_back( TrajectoryMeasurement( stateOnThisDet, 
00040                 InvalidTransientRecHit::build(&fastGeomDet(), TrackingRecHit::inactive), 
00041                 0.F));
00042     return result;
00043   }
00044  
00045   MeasurementDet::RecHitContainer allHits = recHits( stateOnThisDet);
00046   for (RecHitContainer::const_iterator ihit=allHits.begin();
00047        ihit != allHits.end(); ihit++) {
00048     std::pair<bool,double> diffEst = est.estimate( stateOnThisDet, **ihit);
00049     if ( diffEst.first) {
00050       result.push_back( TrajectoryMeasurement( stateOnThisDet, *ihit, 
00051                                                diffEst.second));
00052     }
00053     //RC else delete *ihit; // we own allHits and have to delete the ones we don't return
00054   }
00055   if ( result.empty()) {
00056     // create a TrajectoryMeasurement with an invalid RecHit and zero estimate
00057     TrackingRecHit::Type type = (hasBadComponents(stateOnThisDet) ? TrackingRecHit::inactive : TrackingRecHit::missing);
00058     result.push_back( TrajectoryMeasurement( stateOnThisDet, 
00059                                              InvalidTransientRecHit::build(&fastGeomDet(), type), 0.F)); 
00060   }
00061   else {
00062     // sort results according to estimator value
00063     if ( result.size() > 1) {
00064       sort( result.begin(), result.end(), TrajMeasLessEstim());
00065     }
00066   }
00067   return result;
00068 }
00069 
00070 TransientTrackingRecHit::RecHitPointer
00071 TkPixelMeasurementDet::buildRecHit( const SiPixelClusterRef & cluster,
00072                                     const LocalTrajectoryParameters & ltp) const
00073 {
00074   const GeomDetUnit& gdu( specificGeomDet());
00075   LocalValues lv = theCPE->localParameters( * cluster, gdu, ltp );
00076   return TSiPixelRecHit::build( lv.first, lv.second, &fastGeomDet(), cluster, theCPE);
00077 }
00078 
00079 TkPixelMeasurementDet::RecHitContainer 
00080 TkPixelMeasurementDet::recHits( const TrajectoryStateOnSurface& ts ) const
00081 {
00082   RecHitContainer result;
00083   if (empty == true ) return result;
00084   if (isActive() == false) return result;
00085   const SiPixelCluster* begin=0;
00086   if(0!=handle_->data().size()) {
00087      begin = &(handle_->data().front());
00088   }
00089   result.reserve(detSet_.size());
00090   for ( const_iterator ci = detSet_.begin(); ci != detSet_.end(); ++ ci ) {
00091     
00092     if (ci < begin){
00093       edm::LogError("IndexMisMatch")<<"TkPixelMeasurementDet cannot create hit because of index mismatch.";
00094       return result;
00095     }
00096      unsigned int index = ci-begin;
00097      if (skipClusters_!=0 && skipClusters_->size()!=0 &&  index>=skipClusters_->size()){
00098        edm::LogError("IndexMisMatch")<<"TkPixelMeasurementDet cannot create hit because of index mismatch. i.e "<<index<<" >= "<<skipClusters_->size();
00099        return result;
00100      }
00101      if(0==skipClusters_ or skipClusters_->empty() or (not (*skipClusters_)[index]) ) {
00102        SiPixelClusterRef cluster = edmNew::makeRefTo( handle_, ci );
00103        result.push_back( buildRecHit( cluster, ts.localParameters() ) );
00104      }else{   
00105        LogDebug("TkPixelMeasurementDet")<<"skipping this cluster from last iteration on "<<fastGeomDet().geographicalId().rawId()<<" key: "<<index;
00106      }
00107   }
00108   return result;
00109 }
00110 
00111 bool
00112 TkPixelMeasurementDet::hasBadComponents( const TrajectoryStateOnSurface &tsos ) const {
00113     if (badRocPositions_.empty()) return false;
00114     LocalPoint lp = tsos.localPosition();
00115     LocalError le = tsos.localError().positionError();
00116     double dx = 3*std::sqrt(le.xx()) + theRocWidth, dy = 3*std::sqrt(le.yy()) + theRocHeight;
00117     for (std::vector<LocalPoint>::const_iterator it = badRocPositions_.begin(), ed = badRocPositions_.end(); it != ed; ++it) {
00118         if ( (std::abs(it->x() - lp.x()) < dx) &&
00119              (std::abs(it->y() - lp.y()) < dy) ) return true;
00120     } 
00121     return false;
00122 }