Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-07 04:35:20

0001 #ifndef PF_PU_AssoMapAlgos_h
0002 #define PF_PU_AssoMapAlgos_h
0003 
0004 /**\class PF_PU_AssoMap PF_PU_AssoMap.cc CommonTools/RecoUtils/plugins/PF_PU_AssoMap.cc
0005 
0006  Description: Produces a map with association between tracks and their particular most probable vertex with a quality of this association
0007 */
0008 //
0009 // Original Author:  Matthias Geisler,32 4-B20,+41227676487,
0010 // $Id: PF_PU_AssoMapAlgos.h,v 1.7 2012/11/21 09:45:04 mgeisler Exp $
0011 //
0012 //
0013 
0014 #include <string>
0015 
0016 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0017 #include "FWCore/Utilities/interface/InputTag.h"
0018 #include "FWCore/Framework/interface/Event.h"
0019 #include "FWCore/Framework/interface/ConsumesCollector.h"
0020 
0021 #include "DataFormats/Common/interface/Handle.h"
0022 
0023 #include "DataFormats/Common/interface/AssociationMap.h"
0024 #include "DataFormats/Common/interface/OneToManyWithQuality.h"
0025 #include "DataFormats/Common/interface/OneToManyWithQualityGeneric.h"
0026 
0027 #include "DataFormats/Common/interface/View.h"
0028 #include "DataFormats/Math/interface/Point3D.h"
0029 
0030 #include "DataFormats/TrackReco/interface/Track.h"
0031 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0032 #include "DataFormats/TrackReco/interface/TrackBase.h"
0033 #include "TrackingTools/TransientTrack/interface/TransientTrack.h"
0034 
0035 #include "DataFormats/VertexReco/interface/Vertex.h"
0036 #include "DataFormats/VertexReco/interface/VertexFwd.h"
0037 
0038 #include "DataFormats/EgammaCandidates/interface/Conversion.h"
0039 #include "DataFormats/EgammaCandidates/interface/ConversionFwd.h"
0040 
0041 #include "DataFormats/Candidate/interface/VertexCompositeCandidate.h"
0042 #include "DataFormats/ParticleFlowReco/interface/PFDisplacedVertex.h"
0043 #include "DataFormats/ParticleFlowReco/interface/PFDisplacedVertexFwd.h"
0044 
0045 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
0046 
0047 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
0048 #include "Geometry/Records/interface/GlobalTrackingGeometryRecord.h"
0049 
0050 //
0051 // constants, enums and typedefs
0052 //
0053 
0054 const double kMass = 0.49765;
0055 const double lamMass = 1.11568;
0056 
0057 /*limits for the quality criteria*/
0058 
0059 const double tw_90 = 1.e-2;
0060 const double tw_70 = 1.e-1;
0061 const double tw_50 = 2.e-1;
0062 
0063 const double sec_70 = 5.;
0064 const double sec_50 = 19.;
0065 
0066 const double fin_70 = 1.e-1;
0067 const double fin_50 = 3.e-1;
0068 
0069 typedef edm::AssociationMap<edm::OneToManyWithQuality<reco::VertexCollection, reco::TrackCollection, int>>
0070     TrackToVertexAssMap;
0071 typedef edm::AssociationMap<edm::OneToManyWithQuality<reco::TrackCollection, reco::VertexCollection, int>>
0072     VertexToTrackAssMap;
0073 
0074 typedef std::pair<reco::TrackRef, int> TrackQualityPair;
0075 typedef std::vector<TrackQualityPair> TrackQualityPairVector;
0076 
0077 typedef std::pair<reco::VertexRef, int> VertexStepPair;
0078 
0079 typedef std::pair<reco::VertexRef, TrackQualityPair> VertexTrackQuality;
0080 
0081 typedef std::pair<reco::VertexRef, float> VertexPtsumPair;
0082 typedef std::vector<VertexPtsumPair> VertexPtsumVector;
0083 
0084 class PF_PU_AssoMapAlgos {
0085 public:
0086   //dedicated constructor for the algorithms
0087   PF_PU_AssoMapAlgos(const edm::ParameterSet& iConfig, edm::ConsumesCollector&& iC) : PF_PU_AssoMapAlgos(iConfig, iC) {}
0088   PF_PU_AssoMapAlgos(const edm::ParameterSet&, edm::ConsumesCollector&);
0089   // virtual destructor needed when virtual functions declared
0090   virtual ~PF_PU_AssoMapAlgos() noexcept(false) {}
0091 
0092   //get all needed collections at the beginning
0093   virtual void GetInputCollections(edm::Event&, const edm::EventSetup&);
0094 
0095   //create the track-to-vertex and vertex-to-track maps in one go
0096   std::pair<std::unique_ptr<TrackToVertexAssMap>, std::unique_ptr<VertexToTrackAssMap>> createMappings(
0097       edm::Handle<reco::TrackCollection> trkcollH);
0098 
0099   //create the track to vertex association map
0100   std::unique_ptr<TrackToVertexAssMap> CreateTrackToVertexMap(edm::Handle<reco::TrackCollection>);
0101 
0102   //create the vertex to track association map
0103   std::unique_ptr<VertexToTrackAssMap> CreateVertexToTrackMap(edm::Handle<reco::TrackCollection>);
0104 
0105   //function to sort the vertices in the AssociationMap by the sum of (pT - pT_Error)**2
0106   std::unique_ptr<TrackToVertexAssMap> SortAssociationMap(TrackToVertexAssMap*, edm::Handle<reco::TrackCollection>);
0107 
0108 protected:
0109   //protected functions
0110 
0111   //create helping vertex vector to remove associated vertices
0112   std::vector<reco::VertexRef> CreateVertexVector(edm::Handle<reco::VertexCollection>);
0113 
0114   //erase one vertex from the vertex vector
0115   void EraseVertex(std::vector<reco::VertexRef>&, reco::VertexRef);
0116 
0117   //find an association for a certain track
0118   VertexStepPair FindAssociation(const reco::TrackRef&,
0119                                  const std::vector<reco::VertexRef>&,
0120                                  edm::ESHandle<MagneticField>,
0121                                  edm::ESHandle<GlobalTrackingGeometry>,
0122                                  edm::Handle<reco::BeamSpot>,
0123                                  int);
0124 
0125   //get the quality for a certain association
0126   int DefineQuality(int, int, double);
0127 
0128 private:
0129   // private methods for internal usage
0130 
0131   //function to find the closest vertex in z for a certain track
0132   static reco::VertexRef FindClosestZ(const reco::TrackRef, const std::vector<reco::VertexRef>&, double tWeight = 0.);
0133 
0134   //function to find the closest vertex in 3D for a certain track
0135   static reco::VertexRef FindClosest3D(reco::TransientTrack, const std::vector<reco::VertexRef>&, double tWeight = 0.);
0136 
0137   //function to calculate the deltaR between a vector and a vector connecting two points
0138   static double dR(const math::XYZPoint&, const math::XYZVector&, edm::Handle<reco::BeamSpot>);
0139 
0140   //function to filter the conversion collection
0141   static std::unique_ptr<reco::ConversionCollection> GetCleanedConversions(edm::Handle<reco::ConversionCollection>,
0142                                                                            edm::Handle<reco::BeamSpot>,
0143                                                                            bool);
0144 
0145   //function to find out if the track comes from a gamma conversion
0146   static bool ComesFromConversion(const reco::TrackRef, const reco::ConversionCollection&, reco::Conversion*);
0147 
0148   static reco::VertexRef FindConversionVertex(const reco::TrackRef,
0149                                               const reco::Conversion&,
0150                                               edm::ESHandle<MagneticField>,
0151                                               edm::ESHandle<GlobalTrackingGeometry>,
0152                                               edm::Handle<reco::BeamSpot>,
0153                                               const std::vector<reco::VertexRef>&,
0154                                               double);
0155 
0156   //function to filter the Kshort collection
0157   static std::unique_ptr<reco::VertexCompositeCandidateCollection> GetCleanedKshort(
0158       edm::Handle<reco::VertexCompositeCandidateCollection>, edm::Handle<reco::BeamSpot>, bool);
0159 
0160   //function to filter the Lambda collection
0161   static std::unique_ptr<reco::VertexCompositeCandidateCollection> GetCleanedLambda(
0162       edm::Handle<reco::VertexCompositeCandidateCollection>, edm::Handle<reco::BeamSpot>, bool);
0163 
0164   //function to find out if the track comes from a V0 decay
0165   static bool ComesFromV0Decay(const reco::TrackRef,
0166                                const reco::VertexCompositeCandidateCollection&,
0167                                const reco::VertexCompositeCandidateCollection&,
0168                                reco::VertexCompositeCandidate*);
0169 
0170   static reco::VertexRef FindV0Vertex(const reco::TrackRef,
0171                                       const reco::VertexCompositeCandidate&,
0172                                       edm::ESHandle<MagneticField>,
0173                                       edm::ESHandle<GlobalTrackingGeometry>,
0174                                       edm::Handle<reco::BeamSpot>,
0175                                       const std::vector<reco::VertexRef>&,
0176                                       double);
0177 
0178   //function to filter the nuclear interaction collection
0179   static std::unique_ptr<reco::PFDisplacedVertexCollection> GetCleanedNI(edm::Handle<reco::PFDisplacedVertexCollection>,
0180                                                                          edm::Handle<reco::BeamSpot>,
0181                                                                          bool);
0182 
0183   //function to find out if the track comes from a nuclear interaction
0184   static bool ComesFromNI(const reco::TrackRef, const reco::PFDisplacedVertexCollection&, reco::PFDisplacedVertex*);
0185 
0186   static reco::VertexRef FindNIVertex(const reco::TrackRef,
0187                                       const reco::PFDisplacedVertex&,
0188                                       edm::ESHandle<MagneticField>,
0189                                       edm::ESHandle<GlobalTrackingGeometry>,
0190                                       edm::Handle<reco::BeamSpot>,
0191                                       const std::vector<reco::VertexRef>&,
0192                                       double);
0193 
0194   //function to find the vertex with the highest TrackWeight for a certain track
0195   template <typename TREF>
0196   static reco::VertexRef TrackWeightAssociation(const TREF&, const std::vector<reco::VertexRef>&);
0197 
0198   // ----------member data ---------------------------
0199 
0200   int input_MaxNumAssociations_;
0201 
0202   edm::EDGetTokenT<reco::VertexCollection> token_VertexCollection_;
0203   edm::Handle<reco::VertexCollection> vtxcollH;
0204 
0205   edm::EDGetTokenT<reco::BeamSpot> token_BeamSpot_;
0206   edm::Handle<reco::BeamSpot> beamspotH;
0207 
0208   const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> token_bField_;
0209   edm::ESHandle<MagneticField> bFieldH;
0210   const edm::ESGetToken<GlobalTrackingGeometry, GlobalTrackingGeometryRecord> token_TrackingGeometry_;
0211   edm::ESHandle<GlobalTrackingGeometry> trackingGeometryH;
0212 
0213   bool input_doReassociation_;
0214   bool cleanedColls_;
0215 
0216   edm::EDGetTokenT<reco::ConversionCollection> ConversionsCollectionToken_;
0217   edm::Handle<reco::ConversionCollection> convCollH;
0218   std::unique_ptr<reco::ConversionCollection> cleanedConvCollP;
0219 
0220   edm::EDGetTokenT<reco::VertexCompositeCandidateCollection> KshortCollectionToken_;
0221   edm::Handle<reco::VertexCompositeCandidateCollection> vertCompCandCollKshortH;
0222   std::unique_ptr<reco::VertexCompositeCandidateCollection> cleanedKshortCollP;
0223 
0224   edm::EDGetTokenT<reco::VertexCompositeCandidateCollection> LambdaCollectionToken_;
0225   edm::Handle<reco::VertexCompositeCandidateCollection> vertCompCandCollLambdaH;
0226   std::unique_ptr<reco::VertexCompositeCandidateCollection> cleanedLambdaCollP;
0227 
0228   edm::EDGetTokenT<reco::PFDisplacedVertexCollection> NIVertexCollectionToken_;
0229   edm::Handle<reco::PFDisplacedVertexCollection> displVertexCollH;
0230   std::unique_ptr<reco::PFDisplacedVertexCollection> cleanedNICollP;
0231 
0232   int input_FinalAssociation_;
0233 
0234   bool ignoremissingpfcollection_;
0235   bool missingColls;  // is true if there is a diplaced vertex collection in the event
0236 
0237   double input_nTrack_;
0238 
0239   int maxNumWarnings_;  // CV: print Warning if TrackExtra objects don't exist in input file,
0240   int numWarnings_;     //     but only a few times
0241 };
0242 
0243 #endif