Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:24:47

0001 #ifndef RecoEgamma_EgammaElectronAlgos_TrajSeedMatcher_h
0002 #define RecoEgamma_EgammaElectronAlgos_TrajSeedMatcher_h
0003 
0004 //******************************************************************************
0005 //
0006 // Part of the refactorisation of of the E/gamma pixel matching for 2017 pixels
0007 // This refactorisation converts the monolithic  approach to a series of
0008 // independent producer modules, with each modules performing  a specific
0009 // job as recommended by the 2017 tracker framework
0010 //
0011 //
0012 // The module is based of PixelHitMatcher (the seed based functions) but
0013 // extended to match on an arbitary number of hits rather than just doublets.
0014 // It is also aware of how many layers the supercluster trajectory passed through
0015 // and uses that information to determine how many hits to require
0016 // Other than that, its a direct port and follows what PixelHitMatcher did
0017 //
0018 //
0019 // Author : Sam Harper (RAL), 2017
0020 //
0021 //*******************************************************************************
0022 
0023 #include "FWCore/Framework/interface/ESHandle.h"
0024 
0025 #include "MagneticField/Engine/interface/MagneticField.h"
0026 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
0027 
0028 #include "DataFormats/Math/interface/Point3D.h"
0029 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
0030 #include "DataFormats/TrajectorySeed/interface/TrajectorySeedCollection.h"
0031 #include "DataFormats/DetId/interface/DetId.h"
0032 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
0033 #include "TrackingTools/MaterialEffects/interface/PropagatorWithMaterial.h"
0034 #include "TrackingTools/DetLayers/interface/NavigationSchool.h"
0035 #include "TrackingTools/RecoGeometry/interface/GlobalDetLayerGeometry.h"
0036 #include "RecoTracker/MeasurementDet/interface/MeasurementTrackerEvent.h"
0037 #include "RecoEgamma/EgammaElectronAlgos/interface/utils.h"
0038 
0039 #include "RecoTracker/Record/interface/NavigationSchoolRecord.h"
0040 #include "TrackingTools/RecoGeometry/interface/RecoGeometryRecord.h"
0041 #include "TrackingTools/TrajectoryState/interface/ftsFromVertexToPoint.h"
0042 
0043 namespace edm {
0044   class ConsumesCollector;
0045   class EventSetup;
0046   class ConfigurationDescriptions;
0047   class ParameterSet;
0048   class ParameterSetDescription;
0049 }  // namespace edm
0050 
0051 class FreeTrajectoryState;
0052 class TrackingRecHit;
0053 
0054 class TrajSeedMatcher {
0055 public:
0056   struct SCHitMatch {
0057     const DetId detId = 0;
0058     const GlobalPoint hitPos;
0059     const float dRZ = std::numeric_limits<float>::max();
0060     const float dPhi = std::numeric_limits<float>::max();
0061     const TrackingRecHit& hit;
0062     const float et = 0.f;
0063     const float eta = 0.f;
0064     const float phi = 0.f;
0065     const int charge = 0;
0066     const int nrClus = 0;
0067   };
0068 
0069   struct MatchInfo {
0070     const DetId detId;
0071     const float dRZPos;
0072     const float dRZNeg;
0073     const float dPhiPos;
0074     const float dPhiNeg;
0075   };
0076 
0077   struct SeedWithInfo {
0078     const TrajectorySeed& seed;
0079     const std::vector<MatchInfo> matchInfos;
0080     const int nrValidLayers;
0081   };
0082 
0083   class MatchingCuts {
0084   public:
0085     MatchingCuts() {}
0086     virtual ~MatchingCuts() {}
0087     virtual bool operator()(const SCHitMatch& scHitMatch) const = 0;
0088   };
0089 
0090   class MatchingCutsV1 : public MatchingCuts {
0091   public:
0092     explicit MatchingCutsV1(const edm::ParameterSet& pset);
0093     bool operator()(const SCHitMatch& scHitMatch) const override;
0094 
0095   private:
0096     float getDRZCutValue(const float scEt, const float scEta) const;
0097 
0098   private:
0099     const double dPhiMax_;
0100     const double dRZMax_;
0101     const double dRZMaxLowEtThres_;
0102     const std::vector<double> dRZMaxLowEtEtaBins_;
0103     const std::vector<double> dRZMaxLowEt_;
0104   };
0105 
0106   class MatchingCutsV2 : public MatchingCuts {
0107   public:
0108     explicit MatchingCutsV2(const edm::ParameterSet& pset);
0109     bool operator()(const SCHitMatch& scHitMatch) const override;
0110 
0111   private:
0112     size_t getBinNr(float eta) const;
0113     float getCutValue(float et, float highEt, float highEtThres, float lowEtGrad) const {
0114       return highEt + std::min(0.f, et - highEtThres) * lowEtGrad;
0115     }
0116 
0117   private:
0118     std::vector<double> dPhiHighEt_, dPhiHighEtThres_, dPhiLowEtGrad_;
0119     std::vector<double> dRZHighEt_, dRZHighEtThres_, dRZLowEtGrad_;
0120     std::vector<double> etaBins_;
0121   };
0122 
0123 public:
0124   struct Configuration {
0125     Configuration(const edm::ParameterSet& pset, edm::ConsumesCollector&& cc);
0126 
0127     const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> magFieldToken;
0128     const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> paramMagFieldToken;
0129     const edm::ESGetToken<NavigationSchool, NavigationSchoolRecord> navSchoolToken;
0130     const edm::ESGetToken<DetLayerGeometry, RecoGeometryRecord> detLayerGeomToken;
0131 
0132     const bool useRecoVertex;
0133     const bool enableHitSkipping;
0134     const bool requireExactMatchCount;
0135     const bool useParamMagFieldIfDefined;
0136 
0137     //these two variables determine how hits we require
0138     //based on how many valid layers we had
0139     //right now we always need atleast two hits
0140     //also highly dependent on the seeds you pass in
0141     //which also require a given number of hits
0142     const std::vector<unsigned int> minNrHits;
0143     const std::vector<int> minNrHitsValidLayerBins;
0144 
0145     const std::vector<std::unique_ptr<MatchingCuts> > matchingCuts;
0146   };
0147 
0148   explicit TrajSeedMatcher(TrajectorySeedCollection const& seeds,
0149                            math::XYZPoint const& vprim,
0150                            Configuration const& cfg,
0151                            edm::EventSetup const& iSetup,
0152                            MeasurementTrackerEvent const& measTkEvt);
0153   ~TrajSeedMatcher() = default;
0154 
0155   static edm::ParameterSetDescription makePSetDescription();
0156 
0157   std::vector<TrajSeedMatcher::SeedWithInfo> operator()(const GlobalPoint& candPos, const float energy);
0158 
0159 private:
0160   std::vector<SCHitMatch> processSeed(const TrajectorySeed& seed,
0161                                       const GlobalPoint& candPos,
0162                                       const float energy,
0163                                       const TrajectoryStateOnSurface& initialTrajState);
0164 
0165   static float getZVtxFromExtrapolation(const GlobalPoint& primeVtxPos,
0166                                         const GlobalPoint& hitPos,
0167                                         const GlobalPoint& candPos);
0168 
0169   const TrajectoryStateOnSurface& getTrajStateFromVtx(const TrackingRecHit& hit,
0170                                                       const TrajectoryStateOnSurface& initialState,
0171                                                       const PropagatorWithMaterial& propagator);
0172 
0173   const TrajectoryStateOnSurface& getTrajStateFromPoint(const TrackingRecHit& hit,
0174                                                         const FreeTrajectoryState& initialState,
0175                                                         const GlobalPoint& point,
0176                                                         const PropagatorWithMaterial& propagator);
0177 
0178   TrajectoryStateOnSurface makeTrajStateOnSurface(const GlobalPoint& pos, const float energy, const int charge) const;
0179   void clearCache();
0180 
0181   int getNrValidLayersAlongTraj(
0182       const SCHitMatch& hit1, const SCHitMatch& hit2, const GlobalPoint& candPos, const float energy, const int charge);
0183 
0184   int getNrValidLayersAlongTraj(const DetId& hitId, const TrajectoryStateOnSurface& hitTrajState) const;
0185 
0186   bool layerHasValidHits(const DetLayer& layer,
0187                          const TrajectoryStateOnSurface& hitSurState,
0188                          const Propagator& propToLayerFromState) const;
0189 
0190   size_t getNrHitsRequired(const int nrValidLayers) const;
0191 
0192   inline auto ftsFromVertexToPoint(GlobalPoint const& point, GlobalPoint const& vertex, float energy, int charge) const {
0193     //parameterised b-fields may not be valid for entire detector, just tracker volume
0194     //however need we ecal so we auto select based on the position
0195     bool useMagFieldParam = cfg_.useParamMagFieldIfDefined && magFieldParam_.isDefined(point);
0196     auto const& magneticField = useMagFieldParam ? magFieldParam_ : magField_;
0197     return trackingTools::ftsFromVertexToPoint(magneticField, point, vertex, energy, charge);
0198   }
0199 
0200 private:
0201   static constexpr float kElectronMass_ = 0.000511;
0202 
0203   TrajectorySeedCollection const& seeds_;
0204   const GlobalPoint vprim_;
0205 
0206   Configuration const& cfg_;
0207 
0208   MagneticField const& magField_;
0209   MagneticField const& magFieldParam_;
0210   MeasurementTrackerEvent const& measTkEvt_;
0211   NavigationSchool const& navSchool_;
0212   DetLayerGeometry const& detLayerGeom_;
0213 
0214   PropagatorWithMaterial forwardPropagator_;
0215   PropagatorWithMaterial backwardPropagator_;
0216 
0217   std::unordered_map<int, TrajectoryStateOnSurface> trajStateFromVtxPosChargeCache_;
0218   std::unordered_map<int, TrajectoryStateOnSurface> trajStateFromVtxNegChargeCache_;
0219 
0220   IntGlobalPointPairUnorderedMap<TrajectoryStateOnSurface> trajStateFromPointPosChargeCache_;
0221   IntGlobalPointPairUnorderedMap<TrajectoryStateOnSurface> trajStateFromPointNegChargeCache_;
0222 };
0223 
0224 #endif