CMS 3D CMS Logo

/data/git/CMSSW_5_3_11_patch5/src/TrackingTools/MeasurementDet/src/LayerMeasurements.cc

Go to the documentation of this file.
00001 #include "TrackingTools/MeasurementDet/interface/LayerMeasurements.h"
00002 #include "TrackingTools/PatternTools/interface/TrajectoryMeasurement.h"
00003 #include "TrackingTools/DetLayers/interface/DetLayer.h"
00004 #include "TrackingTools/MeasurementDet/interface/GeometricSearchDetMeasurements.h"
00005 #include "TrackingTools/TransientTrackingRecHit/interface/InvalidTransientRecHit.h"
00006 #include "TrackingTools/MeasurementDet/interface/TrajectoryMeasurementGroup.h"
00007 #include "TrackingTools/MeasurementDet/interface/MeasurementDetException.h"
00008 #include "TrackingTools/MeasurementDet/interface/MeasurementDetSystem.h"
00009 #include "TrackingTools/DetLayers/interface/DetGroup.h"
00010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00011 using namespace std;
00012 
00013 vector<TrajectoryMeasurement>
00014 LayerMeasurements::measurements( const DetLayer& layer, 
00015                                  const TrajectoryStateOnSurface& startingState,
00016                                  const Propagator& prop, 
00017                                  const MeasurementEstimator& est) const
00018 {
00019   typedef DetLayer::DetWithState   DetWithState;
00020   vector<DetWithState> compatDets = layer.compatibleDets( startingState, prop, est);
00021 
00022   vector<TrajectoryMeasurement> result;
00023   if (compatDets.empty()) {
00024     pair<bool, TrajectoryStateOnSurface> compat =
00025       layer.compatible( startingState, prop, est);
00026     
00027 
00028     if ( compat.first) {
00029       result.push_back( TrajectoryMeasurement( compat.second, 
00030                                                InvalidTransientRecHit::build(0, TrackingRecHit::inactive,&layer), 0.F,
00031                                                &layer));
00032       LogDebug("LayerMeasurements")<<"adding a missing hit.";
00033     }else LogDebug("LayerMeasurements")<<"adding not measurement.";
00034     return result;
00035   }
00036 
00037   GeometricSearchDetMeasurements gsdm( theDetSystem);
00038   vector<TrajectoryMeasurement> tmpResult = gsdm.get( layer, compatDets, startingState, prop, est);
00039 
00040   for(vector<TrajectoryMeasurement>::const_iterator tmpIt=tmpResult.begin();tmpIt!=tmpResult.end();tmpIt++){
00041     LogDebug("LayerMeasurements")<<"adding a measurement which rechit is: "<<(tmpIt->recHit()->isValid()?"valid":"invalid");
00042     result.push_back(  TrajectoryMeasurement(tmpIt->predictedState(),tmpIt->recHit(),tmpIt->estimate(),&layer)  );
00043   }
00044   
00045   return result;
00046 }
00047 
00048 
00049 vector<TrajectoryMeasurementGroup>
00050 LayerMeasurements::groupedMeasurements( const DetLayer& layer, 
00051                                         const TrajectoryStateOnSurface& startingState,
00052                                         const Propagator& prop, 
00053                                         const MeasurementEstimator& est) const
00054 {
00055   vector<TrajectoryMeasurementGroup> result;
00056 
00057   {
00058     vector<DetGroup> groups( layer.groupedCompatibleDets( startingState, prop, est));
00059     result.reserve(groups.size());
00060     for (vector<DetGroup>::const_iterator grp=groups.begin(); grp!=groups.end(); grp++) {
00061       if ( grp->empty() )  continue;
00062       
00063       vector<TrajectoryMeasurement> tmpVec;
00064       for (DetGroup::const_iterator idet=grp->begin(); idet!=grp->end(); idet++) {
00065         const MeasurementDet* mdet = theDetSystem->idToDet(idet->det()->geographicalId());
00066         if (mdet == 0) {
00067           throw MeasurementDetException( "MeasurementDet not found");
00068         }      
00069         vector<TrajectoryMeasurement> tmp = 
00070           mdet->fastMeasurements( idet->trajectoryState(), startingState, prop, est);
00071         if (!tmp.empty()) {
00072           // only collect valid RecHits
00073          
00074           if(tmp.back().recHit()->getType() == TrackingRecHit::missing) tmp.pop_back();
00075 #if defined( __GXX_EXPERIMENTAL_CXX0X__)
00076           tmpVec.insert( tmpVec.end(), std::make_move_iterator(tmp.begin()), std::make_move_iterator(tmp.end()));
00077 #else
00078           tmpVec.insert( tmpVec.end(), tmp.begin(), tmp.end());
00079 #endif
00080         }
00081       }
00082       
00083       for(vector<TrajectoryMeasurement>::iterator tmpIt=tmpVec.begin();tmpIt!=tmpVec.end();tmpIt++){
00084         LogDebug("LayerMeasurements")<<"[grouped] temporaryly adding a measurement which rechit is: "<<(tmpIt->recHit()->isValid()?"valid":"invalid");
00085         tmpIt->setLayer(&layer);
00086       }
00087       
00088       
00089       // sort the final result
00090       sort( tmpVec.begin(), tmpVec.end(), TrajMeasLessEstim());
00091       addInvalidMeas( tmpVec, *grp,layer); 
00092 #if defined( __GXX_EXPERIMENTAL_CXX0X__)
00093       result.push_back( TrajectoryMeasurementGroup( std::move(tmpVec), std::move(*grp)));
00094 #else
00095       result.push_back( TrajectoryMeasurementGroup( tmpVec, *grp));
00096 #endif
00097     }
00098   }
00099 
00100   // if the result is empty check if the layer is compatible (for invalid measurement)
00101   if (result.empty()) {
00102     pair<bool, TrajectoryStateOnSurface> compat = layer.compatible( startingState, prop, est);
00103     if ( compat.first) {
00104       TrajectoryMeasurement inval( compat.second, InvalidTransientRecHit::build(0, TrackingRecHit::inactive,&layer), 0.F,&layer);
00105       vector<TrajectoryMeasurement> tmVec(1,inval);
00106       result.push_back( TrajectoryMeasurementGroup( tmVec, DetGroup()));
00107     }
00108   }
00109   return result;
00110 }
00111 
00112 void LayerMeasurements::addInvalidMeas( vector<TrajectoryMeasurement>& measVec,
00113                                         const DetGroup& group,
00114                                         const DetLayer& layer) const
00115 {
00116   if (!measVec.empty()) {
00117     // invalidMeas on Det of most compatible hit
00118     measVec.push_back( TrajectoryMeasurement( measVec.front().predictedState(), 
00119                                               InvalidTransientRecHit::build(measVec.front().recHit()->det(), TrackingRecHit::missing),
00120                                               0.,&layer));
00121   }
00122   else if (!group.empty()) {
00123     // invalid state on first compatible Det
00124     measVec.push_back( TrajectoryMeasurement( group.front().trajectoryState(), 
00125                                               InvalidTransientRecHit::build(group.front().det(), TrackingRecHit::missing), 0.,&layer));
00126   }
00127 }