File indexing completed on 2023-03-17 11:29:05
0001 #ifndef VALIDATION_RECOVERTEX_INTERFACE_PRIMARYVERTEXANALYZER4PUSLIMMED_H_
0002 #define VALIDATION_RECOVERTEX_INTERFACE_PRIMARYVERTEXANALYZER4PUSLIMMED_H_
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #include <memory>
0022 #include <string>
0023 #include <vector>
0024 #include <map>
0025 #include <algorithm>
0026
0027
0028 #include "FWCore/Framework/interface/Frameworkfwd.h"
0029 #include "FWCore/Framework/interface/ESHandle.h"
0030
0031
0032 #include "DataFormats/Math/interface/LorentzVector.h"
0033 #include "DataFormats/Math/interface/Point3D.h"
0034
0035
0036 #include "DataFormats/TrackReco/interface/Track.h"
0037 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0038
0039
0040 #include "DataFormats/VertexReco/interface/VertexFwd.h"
0041
0042
0043 #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h"
0044 #include "SimDataFormats/Associations/interface/TrackToTrackingParticleAssociator.h"
0045
0046
0047 #include "SimDataFormats/PileupSummaryInfo/interface/PileupSummaryInfo.h"
0048
0049
0050 #include "RecoVertex/PrimaryVertexProducer/interface/TrackFilterForPVFinding.h"
0051
0052
0053 #include "SimDataFormats/Associations/interface/VertexToTrackingVertexAssociator.h"
0054
0055
0056 #include "DQMServices/Core/interface/DQMEDAnalyzer.h"
0057 #include "DQMServices/Core/interface/DQMStore.h"
0058
0059
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
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
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;
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
0144
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
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