CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/TrackingTools/MeasurementDet/interface/GeometricSearchDetMeasurements.h

Go to the documentation of this file.
00001 #ifndef GeometricSearchDetMeasurements_H
00002 #define GeometricSearchDetMeasurements_H
00003 
00004 #include "TrackingTools/DetLayers/interface/GeometricSearchDet.h"
00005 #include "TrackingTools/PatternTools/interface/TrajMeasLessEstim.h"
00006 #include "TrackingTools/GeomPropagators/interface/Propagator.h"
00007 #include "TrackingTools/MeasurementDet/interface/MeasurementDetException.h"
00008 #include "TrackingTools/MeasurementDet/interface/MeasurementDetSystem.h"
00009 #include "TrackingTools/MeasurementDet/interface/MeasurementDet.h"
00010 #include "TrackingTools/MeasurementDet/interface/TrajectoryMeasurementGroup.h"
00011 #include "TrackingTools/TransientTrackingRecHit/interface/InvalidTransientRecHit.h"
00012 
00013 
00014 #include <algorithm>
00015 
00021 class GeometricSearchDetMeasurements {
00022 public:
00023 
00024   typedef GeometricSearchDet::DetWithState DetWithState;
00025   typedef TrajectoryStateOnSurface   TSOS;
00026   typedef TrajectoryMeasurement      TM;
00027   typedef TrajectoryMeasurementGroup TMG;
00028 
00029   GeometricSearchDetMeasurements( const MeasurementDetSystem* detSysytem) :
00030     theDetSystem(detSysytem) {}
00031 
00032 
00033 
00034   /*
00035   template <class TrajectoryState> 
00036   std::vector<DetWithState> getDets( const GeometricSearchDet& det,
00037                                 const TrajectoryState& ts, 
00038                                 const Propagator& prop, 
00039                                 const MeasurementEstimator& est) const {
00040     pair<bool, TSOS> compat = det.compatible( ts, prop, est);
00041     if ( compat.first) return det.fastCompatibleDets( compat.second, ts, prop, est);
00042     else return std::vector<DetWithState>();
00043   }
00044 
00045   template <class TrajectoryState> 
00046   std::vector<DetWithState> getDets( const GeometricSearchDet& det,
00047                                 const TrajectoryStateOnSurface& stateOnDet,
00048                                 const TrajectoryState& ts, 
00049                                 const Propagator& prop, 
00050                                 const MeasurementEstimator& est) const {
00051     return det.fastCompatibleDets( stateOnDet, ts, prop, est);
00052   }
00053 
00054   template <class TrajectoryState>
00055   std::vector<TrajectoryMeasurement> get( const GeometricSearchDet& det,
00056                                      const TrajectoryState& ts, 
00057                                      const Propagator& prop, 
00058                                      const MeasurementEstimator& est) const {
00059     pair<bool, TSOS> compat = det.compatible( ts, prop, est);
00060     if ( compat.first) {
00061       return det.fastMeasurements( compat.second, ts, prop, est);
00062     }
00063     else return std::vector<TrajectoryMeasurement>();
00064   }
00065     
00066   template <class TrajectoryState>
00067   std::vector<TrajectoryMeasurement> get( const GeometricSearchDet& det,
00068                                      const TrajectoryStateOnSurface& stateOnDet,
00069                                      const TrajectoryState& ts, 
00070                                      const Propagator& prop, 
00071                                      const MeasurementEstimator& est) const {
00072     std::vector<DetWithState> compatDets = det.fastCompatibleDets( stateOnDet, ts, prop, est);
00073     if (!compatDets.empty()) {
00074       return get( det, compatDets, ts, prop, est);
00075     }
00076     else {
00077       std::vector<TrajectoryMeasurement> result;
00078       addInvalidMeas( result, stateOnDet, &det);
00079       return result;
00080     }
00081   }
00082   */
00083 
00091   template <class TrajectoryState>
00092   std::vector<TrajectoryMeasurement> get( const GeometricSearchDet& layer,
00093                                           const std::vector<DetWithState>& compatDets,
00094                                           const TrajectoryState& ts, 
00095                                           const Propagator& prop, 
00096                                           const MeasurementEstimator& est) const;
00097   /*
00098   template <class TrajectoryState>
00099   std::vector<TMG>
00100   getGrouped( const GeometricSearchDet& det, const std::vector<DetWithState>& dg,
00101               const TrajectoryState& ts, const Propagator& prop,
00102               const MeasurementEstimator& est) const {
00103     if (!dg.empty()) {
00104       std::vector<TMG> result(1);
00105       result[0] = TMG( get( det, dg, ts, prop, est), dg);
00106       return result;
00107     }
00108     else return std::vector<TMG>();
00109   }
00110   */
00111 
00112   
00113   void addInvalidMeas( std::vector<TrajectoryMeasurement>& result, 
00114                        const TrajectoryStateOnSurface& ts, const GeomDet* det) const {
00115     result.push_back( TM( ts, InvalidTransientRecHit::build(det, TrackingRecHit::missing), 0.F,0));
00116   }
00117   
00118 
00119 private:
00120 
00121   const MeasurementDetSystem* theDetSystem;
00122 
00123 };
00124 
00125 
00126 template <class TrajectoryState>
00127 std::vector<TrajectoryMeasurement> 
00128 GeometricSearchDetMeasurements::get( const GeometricSearchDet& layer,
00129                                      const std::vector<DetWithState>& compatDets,
00130                                      const TrajectoryState& ts, 
00131                                      const Propagator& prop, 
00132                                      const MeasurementEstimator& est) const
00133 {
00134   std::vector<TrajectoryMeasurement> result;
00135   if (!compatDets.empty()) {
00136     for ( std::vector<DetWithState>::const_iterator i=compatDets.begin();
00137           i != compatDets.end(); i++) {
00138       const MeasurementDet* mdet = theDetSystem->idToDet(i->first->geographicalId());
00139       if (mdet == 0) {
00140         throw MeasurementDetException( "MeasurementDet not found");
00141       }
00142 
00143       std::vector<TM> tmp = mdet->fastMeasurements( i->second, ts, prop, est);
00144       if ( !tmp.empty()) {
00145         // only collect valid RecHits
00146         std::vector<TM>::iterator end = (tmp.back().recHit()->getType() != TrackingRecHit::missing ? tmp.end() : tmp.end()-1);
00147         result.insert( result.end(), tmp.begin(), end);
00148       }
00149     }
00150     // WARNING: we might end up with more than one invalid hit of type 'inactive' in result
00151     // to be fixed in order to avoid usless double traj candidates.
00152 
00153     // sort the final result
00154     if ( result.size() > 1) {
00155       sort( result.begin(), result.end(), TrajMeasLessEstim());
00156     }
00157 
00158     
00159     if ( !result.empty()) {
00160       // invalidMeas on Det of most compatible hit
00161       addInvalidMeas( result, result.front().predictedState(), result.front().recHit()->det());
00162     }
00163     else {
00164       // invalid state on first compatible Det
00165       addInvalidMeas( result, compatDets.front().second, compatDets.front().first);
00166     }
00167     
00168 
00169   }
00170   else {
00171     // this case should have been handled by the caller!
00172     throw MeasurementDetException("GeometricSearchDetMeasurements::get called with empty std::vector<DetWithState>");
00173   }
00174   return result;
00175 }
00176 
00177 
00178 #endif