Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:27:39

0001 #include "RecoTracker/SiTrackerMRHTools/interface/MeasurementByLayerGrouper.h"
0002 #include "TrackingTools/DetLayers/interface/DetLayer.h"
0003 #include "TrackingTools/PatternTools/interface/TrajectoryMeasurement.h"
0004 #include "RecoTracker/TkDetLayers/interface/GeometricSearchTracker.h"
0005 #include "FWCore/Utilities/interface/Exception.h"
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 
0008 using namespace std;
0009 
0010 vector<pair<const DetLayer*, vector<TrajectoryMeasurement> > > MeasurementByLayerGrouper::operator()(
0011     const vector<TM>& vtm) const {
0012   if (vtm.empty())
0013     return vector<pair<const DetLayer*, vector<TM> > >();
0014 
0015   vector<pair<const DetLayer*, vector<TM> > > result;
0016   result.reserve(vtm.size());
0017 
0018   vector<TM>::const_iterator start = vtm.begin();
0019   //here we assume that the TM on the same detLayer are consecutive (as it should)
0020   while (start != vtm.end()) {
0021     vector<TM>::const_iterator ipart = start;
0022     do {
0023       ipart++;
0024     } while (ipart != vtm.end() && getDetLayer(*start) == getDetLayer(*ipart) &&
0025              getDetLayer(*start) != nullptr  //the returned pointer will be 0 in case
0026                                              //the measurement contains an invalid hit with no associated detid.
0027                                              //This kind of hits are at most one per layer.
0028                                              //this last condition avoids that 2 consecutive measurements of this kind
0029                                              //are grouped in the same layer.
0030                                              //it would be useful if invalid hit out of the active area were
0031                                              //given the detid reserved for the whole layer instead of 0
0032     );
0033 
0034     vector<TM> group(start, ipart);
0035     result.push_back(pair<const DetLayer*, vector<TM> >(getDetLayer(*start), group));
0036     start = ipart;
0037   }
0038 #ifdef debug_MeasurementByLayerGrouper_
0039   for (vector<pair<const DetLayer*, vector<TM> > >::const_iterator iter = result.begin(); iter != result.end();
0040        iter++) {
0041     LogTrace("MeasurementByLayerGrouper|SiTrackerMultiRecHitUpdator")
0042         << "DetLayer " << iter->first << " has " << iter->second.size() << " measurements";
0043   }
0044 #endif
0045 
0046   return result;
0047 }
0048 
0049 const DetLayer* MeasurementByLayerGrouper::getDetLayer(const TM& tm) const {
0050   // if the DetLayer is set in the TM...
0051   if (tm.layer())
0052     return tm.layer();
0053 
0054   //if it corresponds to an invalid hit with no geomdet associated
0055   //we can't retrieve the  DetLayer
0056   //because unfortunately the detlayer is not set in these cases
0057   //returns 0 for the moment
0058   //to be revisited
0059 
0060   if (tm.recHit()->det() == nullptr) {
0061     LogDebug("MeasurementByLayerGrouper") << "This hit has no geomdet associated skipping... ";
0062     return nullptr;
0063   }
0064 
0065   //now the cases in which the detid is set
0066 
0067   if (!theGeomSearch) {
0068     throw cms::Exception("MeasurementByLayerGrouper") << "Impossible to retrieve the det layer because it's not set in "
0069                                                          "the TM and the pointer to the GeometricSearchTracker is 0 ";
0070     return nullptr;
0071   }
0072 
0073   return theGeomSearch->detLayer(tm.recHit()->det()->geographicalId());
0074 }