CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/RecoTracker/SiTrackerMRHTools/src/MeasurementByLayerGrouper.cc

Go to the documentation of this file.
00001 #include "RecoTracker/SiTrackerMRHTools/interface/MeasurementByLayerGrouper.h"
00002 #include "TrackingTools/DetLayers/interface/DetLayer.h"
00003 #include "TrackingTools/PatternTools/interface/TrajectoryMeasurement.h"
00004 #include "RecoTracker/TkDetLayers/interface/GeometricSearchTracker.h"
00005 #include "FWCore/Utilities/interface/Exception.h"
00006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00007 
00008 //#define debug_MeasurementByLayerGrouper_ 
00009 
00010 using namespace std;
00011 
00012 vector<pair<const DetLayer*, vector<TrajectoryMeasurement> > > MeasurementByLayerGrouper::operator()(const vector<TM>& vtm) const{
00013         if(vtm.empty()) 
00014                 return vector<pair<const DetLayer*, vector<TM> > >();
00015 
00016         vector<pair<const DetLayer*, vector<TM> > > result;
00017         result.reserve(vtm.size());
00018 
00019         vector<TM>::const_iterator start = vtm.begin();
00020         //here we assume that the TM on the same detLayer are consecutive (as it should)
00021         while(start != vtm.end()) {
00022                 vector<TM>::const_iterator ipart = start;
00023                 do {ipart++;}
00024                 while(ipart != vtm.end() && 
00025                         getDetLayer(*start)==getDetLayer(*ipart) &&
00026                         getDetLayer(*start) != 0  //the returned pointer will be 0 in case
00027                                                   //the measurement contains an invalid hit with no associated detid.
00028                                                   //This kind of hits are at most one per layer.
00029                                                   //this last condition avoids that 2 consecutive measurements of this kind
00030                                                   //are grouped in the same layer.
00031                                                   //it would be useful if invalid hit out of the active area were 
00032                                                   //given the detid reserved for the whole layer instead of 0    
00033                         ) ;
00034     
00035                 vector<TM> group(start, ipart);
00036                 result.push_back(pair<const DetLayer*, vector<TM> >(getDetLayer(*start),
00037                                                         group));
00038                 start = ipart;
00039         }
00040 #ifdef debug_MeasurementByLayerGrouper_
00041         //debug
00042         
00043         for (vector<pair<const DetLayer*, vector<TM> > >::const_iterator iter = result.begin(); iter != result.end(); iter++){
00044                 LogTrace("MeasurementByLayerGrouper|SiTrackerMultiRecHitUpdator") << "DetLayer " << iter->first << " has " << iter->second.size() << " measurements"; 
00045         }
00046 #endif
00047         
00048         
00049         //      LogDebug("MeasurementByLayerGrouper|SiTrackerMultiRecHitUpdator") <<"Measurement size "<<result.size();
00050         return result;
00051 }
00052 
00053 const DetLayer* MeasurementByLayerGrouper::getDetLayer(const TM& tm) const {
00054         // if the DetLayer is set in the TM...  
00055         if (tm.layer()) return tm.layer();
00056 
00057         //if it corresponds to an invalid hit with no geomdet associated
00058         //we can't retrieve the  DetLayer
00059         //because unfortunately the detlayer is not set in these cases
00060         //returns 0 for the moment
00061         //to be revisited
00062         
00063         if (tm.recHit()->det()==0){
00064           LogDebug("MeasurementByLayerGrouper") <<"This hit has no geomdet associated skipping... ";
00065                 return 0;
00066         }
00067 
00068         //now the cases in which the detid is set
00069 
00070         if (!theGeomSearch) {
00071                 throw cms::Exception("MeasurementByLayerGrouper") << "Impossible to retrieve the det layer because it's not set in the TM and the pointer to the GeometricSearchTracker is 0 ";
00072                 return 0;       
00073         }
00074 
00075         return theGeomSearch->detLayer(tm.recHit()->det()->geographicalId());
00076 }