Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-09-06 03:13:17

0001 #ifndef VALIDATION_RECOVERTEX_INTERFACE_PRIMARYVERTEXANALYZER4PUSLIMMED_H_
0002 #define VALIDATION_RECOVERTEX_INTERFACE_PRIMARYVERTEXANALYZER4PUSLIMMED_H_
0003 
0004 // -*- C++ -*-
0005 //
0006 // Package:    PrimaryVertexAnalyzer4PUSlimmed
0007 // Class:      PrimaryVertexAnalyzer4PUSlimmed
0008 //
0009 /**\class PrimaryVertexAnalyzer4PUSlimmed PrimaryVertexAnalyzer4PUSlimmed.cc Validation/RecoVertex/src/PrimaryVertexAnalyzer4PUSlimmed.cc
0010 
0011    Description: primary vertex analyzer for events with pile-up
0012 
0013    Implementation:
0014    <Notes on implementation>
0015 */
0016 //
0017 // Original Author: Marco Rovere (code adapted from old code by
0018 // Wolfram Erdmann)
0019 
0020 // system include files
0021 #include <memory>
0022 #include <string>
0023 #include <vector>
0024 #include <map>
0025 #include <algorithm>
0026 
0027 // user include files
0028 #include "FWCore/Framework/interface/Frameworkfwd.h"
0029 #include "FWCore/Framework/interface/ESHandle.h"
0030 
0031 // math
0032 #include "DataFormats/Math/interface/LorentzVector.h"
0033 #include "DataFormats/Math/interface/Point3D.h"
0034 
0035 // reco track
0036 #include "DataFormats/TrackReco/interface/Track.h"
0037 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0038 
0039 // reco vertex
0040 #include "DataFormats/VertexReco/interface/VertexFwd.h"
0041 
0042 // simulated track
0043 #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h"
0044 #include "SimDataFormats/Associations/interface/TrackToTrackingParticleAssociator.h"
0045 
0046 // pile-up
0047 #include "SimDataFormats/PileupSummaryInfo/interface/PileupSummaryInfo.h"
0048 
0049 // vertexing
0050 #include "RecoVertex/PrimaryVertexProducer/interface/TrackFilterForPVFinding.h"
0051 
0052 // simulated vertex
0053 #include "SimDataFormats/Associations/interface/VertexToTrackingVertexAssociator.h"
0054 
0055 // DQM
0056 #include "DQMServices/Core/interface/DQMEDAnalyzer.h"
0057 #include "DQMServices/Core/interface/DQMStore.h"
0058 
0059 // class declaration
0060 class PrimaryVertexAnalyzer4PUSlimmed : public DQMEDAnalyzer {
0061   typedef math::XYZTLorentzVector LorentzVector;
0062 
0063   enum SignalVertexKind { HIGHEST_PT = 0, IS_ASSOC2FIRST_RECO = 1, IS_ASSOC2ANY_RECO = 2 };
0064 
0065   // auxiliary class holding simulated vertices
0066   struct simPrimaryVertex {
0067     simPrimaryVertex(double x1, double y1, double z1)
0068         : x(x1),
0069           y(y1),
0070           z(z1),
0071           ptsq(0),
0072           closest_vertex_distance_z(-1.),
0073           nGenTrk(0),
0074           num_matched_reco_tracks(0),
0075           average_match_quality(0.0) {
0076       ptot.setPx(0);
0077       ptot.setPy(0);
0078       ptot.setPz(0);
0079       ptot.setE(0);
0080       p4 = LorentzVector(0, 0, 0, 0);
0081       r = sqrt(x * x + y * y);
0082     };
0083     double x, y, z, r;
0084     HepMC::FourVector ptot;
0085     LorentzVector p4;
0086     double ptsq;
0087     double closest_vertex_distance_z;
0088     int nGenTrk;
0089     int num_matched_reco_tracks;
0090     float average_match_quality;
0091     EncodedEventId eventId;
0092     TrackingVertexRef sim_vertex;
0093     std::vector<const reco::Vertex *> rec_vertices;
0094   };
0095 
0096   // auxiliary class holding reconstructed vertices
0097   struct recoPrimaryVertex {
0098     enum VertexProperties { NONE = 0, MATCHED = 1, DUPLICATE = 2, MERGED = 4 };
0099     recoPrimaryVertex(double x1, double y1, double z1)
0100         : x(x1),
0101           y(y1),
0102           z(z1),
0103           pt(0),
0104           ptsq(0),
0105           closest_vertex_distance_z(-1.),
0106           purity(-1.),
0107           nRecoTrk(0),
0108           num_matched_sim_tracks(0),
0109           kind_of_vertex(0),
0110           recVtx(nullptr) {
0111       r = sqrt(x * x + y * y);
0112     };
0113     double x, y, z, r;
0114     double pt;
0115     double ptsq;
0116     double closest_vertex_distance_z;
0117     double purity;  // calculated and assigned in calculatePurityAndFillHistograms
0118     int nRecoTrk;
0119     int num_matched_sim_tracks;
0120     int kind_of_vertex;
0121     std::vector<const TrackingVertex *> sim_vertices;
0122     std::vector<const simPrimaryVertex *> sim_vertices_internal;
0123     std::vector<unsigned int> sim_vertices_num_shared_tracks;
0124     const reco::Vertex *recVtx;
0125     reco::VertexBaseRef recVtxRef;
0126   };
0127 
0128 public:
0129   explicit PrimaryVertexAnalyzer4PUSlimmed(const edm::ParameterSet &);
0130   ~PrimaryVertexAnalyzer4PUSlimmed() override;
0131 
0132   void analyze(const edm::Event &, const edm::EventSetup &) override;
0133   void bookHistograms(DQMStore::IBooker &i, edm::Run const &, edm::EventSetup const &) override;
0134 
0135 private:
0136   void resetSimPVAssociation(std::vector<simPrimaryVertex> &);
0137   void matchSim2RecoVertices(std::vector<simPrimaryVertex> &, const reco::VertexSimToRecoCollection &);
0138   void matchReco2SimVertices(std::vector<recoPrimaryVertex> &,
0139                              const reco::VertexRecoToSimCollection &,
0140                              const std::vector<simPrimaryVertex> &);
0141   bool matchRecoTrack2SimSignal(const reco::TrackBaseRef &);
0142   void fillGenericGenVertexHistograms(const simPrimaryVertex &v);
0143   // void fillGenericRecoVertexHistograms(const std::string &,
0144   //                                      const simPrimaryVertex &v);
0145   void fillRecoAssociatedGenVertexHistograms(const std::string &, const simPrimaryVertex &v);
0146   void fillRecoAssociatedGenPVHistograms(const std::string &label,
0147                                          const PrimaryVertexAnalyzer4PUSlimmed::simPrimaryVertex &v,
0148                                          bool genPVMatchedToRecoPV);
0149   void fillGenAssociatedRecoVertexHistograms(const std::string &, int, recoPrimaryVertex &v);
0150   void fillResolutionAndPullHistograms(const std::string &, int, recoPrimaryVertex &v, bool);
0151 
0152   void calculatePurityAndFillHistograms(const std::string &, std::vector<recoPrimaryVertex> &, int, bool);
0153 
0154   std::vector<PrimaryVertexAnalyzer4PUSlimmed::simPrimaryVertex> getSimPVs(
0155       const edm::Handle<TrackingVertexCollection> &);
0156 
0157   std::vector<PrimaryVertexAnalyzer4PUSlimmed::recoPrimaryVertex> getRecoPVs(
0158       const edm::Handle<edm::View<reco::Vertex>> &);
0159 
0160   template <class T>
0161   void computePairDistance(const T &collection, MonitorElement *me);
0162 
0163   // ----------member data ---------------------------
0164   bool verbose_;
0165   bool use_only_charged_tracks_;
0166   const bool do_generic_sim_plots_;
0167   std::string root_folder_;
0168 
0169   std::map<std::string, std::map<std::string, MonitorElement *>> mes_;
0170   const reco::RecoToSimCollection *r2s_;
0171   const reco::SimToRecoCollection *s2r_;
0172 
0173   edm::EDGetTokenT<std::vector<PileupSummaryInfo>> vecPileupSummaryInfoToken_;
0174   std::vector<edm::EDGetTokenT<edm::View<reco::Vertex>>> reco_vertex_collection_tokens_;
0175   std::vector<edm::InputTag> reco_vertex_collections_;
0176   edm::EDGetTokenT<TrackingParticleCollection> trackingParticleCollectionToken_;
0177   edm::EDGetTokenT<TrackingVertexCollection> trackingVertexCollectionToken_;
0178   edm::EDGetTokenT<reco::SimToRecoCollection> simToRecoAssociationToken_;
0179   edm::EDGetTokenT<reco::RecoToSimCollection> recoToSimAssociationToken_;
0180   edm::EDGetTokenT<reco::VertexToTrackingVertexAssociator> vertexAssociatorToken_;
0181 
0182   std::vector<bool> errorPrintedForColl_;
0183 
0184   unsigned int nPUbins_;
0185 };
0186 
0187 #endif  // VALIDATION_RECOVERTEX_INTERFACE_PRIMARYVERTEXANALYZER4PUSLIMMED_H_