CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/TrackingTools/MeasurementDet/interface/CompositeDetMeasurements.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 
00012 #include <algorithm>
00013 
00019 class GeometricSearchDetMeasurements {
00020 public:
00021 
00022   typedef GeometricSearchDet::DetWithState DetWithState;
00023   typedef TrajectoryStateOnSurface   TSOS;
00024   typedef TrajectoryMeasurement      TM;
00025   typedef TrajectoryMeasurementGroup TMG;
00026 
00027   GeometricSearchDetMeasurements( const MeasurementDetSystem* detSysytem) :
00028     theDetSystem(detSysytem) {}
00029 
00030 
00031 
00032   /*
00033   template <class TrajectoryState> 
00034   std::vector<DetWithState> getDets( const GeometricSearchDet& det,
00035                                 const TrajectoryState& ts, 
00036                                 const Propagator& prop, 
00037                                 const MeasurementEstimator& est) const {
00038     pair<bool, TSOS> compat = det.compatible( ts, prop, est);
00039     if ( compat.first) return det.fastCompatibleDets( compat.second, ts, prop, est);
00040     else return std::vector<DetWithState>();
00041   }
00042 
00043   template <class TrajectoryState> 
00044   std::vector<DetWithState> getDets( const GeometricSearchDet& det,
00045                                 const TrajectoryStateOnSurface& stateOnDet,
00046                                 const TrajectoryState& ts, 
00047                                 const Propagator& prop, 
00048                                 const MeasurementEstimator& est) const {
00049     return det.fastCompatibleDets( stateOnDet, ts, prop, est);
00050   }
00051 
00052   template <class TrajectoryState>
00053   std::vector<TrajectoryMeasurement> get( const GeometricSearchDet& det,
00054                                      const TrajectoryState& ts, 
00055                                      const Propagator& prop, 
00056                                      const MeasurementEstimator& est) const {
00057     pair<bool, TSOS> compat = det.compatible( ts, prop, est);
00058     if ( compat.first) {
00059       return det.fastMeasurements( compat.second, ts, prop, est);
00060     }
00061     else return std::vector<TrajectoryMeasurement>();
00062   }
00063     
00064   template <class TrajectoryState>
00065   std::vector<TrajectoryMeasurement> get( const GeometricSearchDet& det,
00066                                      const TrajectoryStateOnSurface& stateOnDet,
00067                                      const TrajectoryState& ts, 
00068                                      const Propagator& prop, 
00069                                      const MeasurementEstimator& est) const {
00070     std::vector<DetWithState> compatDets = det.fastCompatibleDets( stateOnDet, ts, prop, est);
00071     if (!compatDets.empty()) {
00072       return get( det, compatDets, ts, prop, est);
00073     }
00074     else {
00075       std::vector<TrajectoryMeasurement> result;
00076       addInvalidMeas( result, stateOnDet, &det);
00077       return result;
00078     }
00079   }
00080   */
00081 
00089   template <class TrajectoryState>
00090   std::vector<TrajectoryMeasurement> get( const GeometricSearchDet& det,
00091                                           const std::vector<DetWithState>& compatDets,
00092                                           const TrajectoryState& ts, 
00093                                           const Propagator& prop, 
00094                                           const MeasurementEstimator& est) const;
00095   /*
00096   template <class TrajectoryState>
00097   std::vector<TMG>
00098   getGrouped( const GeometricSearchDet& det, const std::vector<DetWithState>& dg,
00099               const TrajectoryState& ts, const Propagator& prop,
00100               const MeasurementEstimator& est) const {
00101     if (!dg.empty()) {
00102       std::vector<TMG> result(1);
00103       result[0] = TMG( get( det, dg, ts, prop, est), dg);
00104       return result;
00105     }
00106     else return std::vector<TMG>();
00107   }
00108   */
00109 
00110   /*
00111   void addInvalidMeas( std::vector<TrajectoryMeasurement>& result, 
00112                        const TrajectoryStateOnSurface& ts, const Det* det) const {
00113     result.push_back( TM( ts, RecHit(det), 0.));
00114   }
00115   */
00116 
00117 private:
00118 
00119   const MeasurementDetSystem* theDetSystem;
00120 
00121 };
00122 
00123 
00124 template <class TrajectoryState>
00125 std::vector<TrajectoryMeasurement> 
00126 GeometricSearchDetMeasurements::get( const GeometricSearchDet& det,
00127                                      const std::vector<DetWithState>& compatDets,
00128                                      const TrajectoryState& ts, 
00129                                      const Propagator& prop, 
00130                                      const MeasurementEstimator& est) const
00131 {
00132   std::vector<TrajectoryMeasurement> result;
00133   if (!compatDets.empty()) {
00134     for ( std::vector<DetWithState>::const_iterator i=compatDets.begin();
00135           i != compatDets.end(); i++) {
00136       const MeasurementDet* mdet = theDetSystem->idToDet(i->first->geographicalId());
00137       if (mdet == 0) {
00138         throw MeasurementDetException( "MeasurementDet not found");
00139       }
00140 
00141       std::vector<TM> tmp = mdet->fastMeasurements( i->second, ts, prop, est);
00142       if ( !tmp.empty()) {
00143         // only collect valid RecHits
00144         std::vector<TM>::iterator end = (tmp.back().recHit()->isValid() ? tmp.end() : tmp.end()-1);
00145         result.insert( result.end(), tmp.begin(), end);
00146       }
00147     }
00148     // sort the final result
00149     if ( result.size() > 1) {
00150       sort( result.begin(), result.end(), TrajMeasLessEstim());
00151     }
00152 
00153     /*
00154     if ( !result.empty()) {
00155       // invalidMeas on Det of most compatible hit
00156       addInvalidMeas( result, result.front().predictedState(), &result.front().recHit().det());
00157     }
00158     else {
00159       // invalid state on first compatible Det
00160       addInvalidMeas( result, compatDets.front().second, compatDets.front().first);
00161     }
00162     */
00163 
00164   }
00165   else {
00166     // this case should have been handled by the caller!
00167     throw MeasurementDetException("GeometricSearchDetMeasurements::get called with empty std::vector<DetWithState>");
00168   }
00169   return result;
00170 }
00171 
00172 
00173 #endif