Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-06-22 02:23:35

0001 // system includes
0002 #include <string>
0003 #include <vector>
0004 #include <map>
0005 #include <tuple>
0006 #include <set>
0007 
0008 // user includes
0009 #include "DQMServices/Core/interface/DQMEDAnalyzer.h"
0010 #include "DQMServices/Core/interface/DQMStore.h"
0011 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
0012 #include "DataFormats/Common/interface/Handle.h"
0013 #include "DataFormats/EgammaCandidates/interface/Electron.h"
0014 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
0015 #include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
0016 #include "DataFormats/EgammaReco/interface/BasicCluster.h"
0017 #include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
0018 #include "DataFormats/Math/interface/deltaPhi.h"
0019 #include "DataFormats/Math/interface/deltaR.h"
0020 #include "DataFormats/MuonReco/interface/Muon.h"
0021 #include "DataFormats/MuonReco/interface/MuonFwd.h"
0022 #include "DataFormats/MuonReco/interface/MuonSelectors.h"
0023 #include "DataFormats/TrackReco/interface/Track.h"
0024 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0025 #include "DataFormats/VertexReco/interface/Vertex.h"
0026 #include "DataFormats/VertexReco/interface/VertexFwd.h"
0027 #include "FWCore/Framework/interface/ESHandle.h"
0028 #include "FWCore/Framework/interface/Event.h"
0029 #include "FWCore/Framework/interface/Frameworkfwd.h"
0030 #include "FWCore/Framework/interface/MakerMacros.h"
0031 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0032 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0033 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0034 #include "FWCore/Utilities/interface/InputTag.h"
0035 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
0036 
0037 // ROOT includes
0038 #include "TFile.h"
0039 #include "TH1.h"
0040 #include "TMath.h"
0041 #include "TPRegexp.h"
0042 
0043 class TrackTypeMonitor : public DQMEDAnalyzer {
0044 public:
0045   TrackTypeMonitor(const edm::ParameterSet&);
0046   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0047 
0048 protected:
0049   void analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup) override;
0050   void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override;
0051 
0052 private:
0053   void fillHistograms(const reco::Track& track, int indx);
0054 
0055   const edm::ParameterSet parameters_;
0056 
0057   const std::string moduleName_;
0058   const std::string folderName_;
0059   const bool verbose_;
0060 
0061   const edm::InputTag muonTag_;
0062   const edm::InputTag electronTag_;
0063   const edm::InputTag trackTag_;
0064   const edm::InputTag bsTag_;
0065   const edm::InputTag vertexTag_;
0066 
0067   const edm::EDGetTokenT<reco::GsfElectronCollection> electronToken_;
0068   const edm::EDGetTokenT<reco::MuonCollection> muonToken_;
0069   const edm::EDGetTokenT<reco::TrackCollection> trackToken_;
0070   const edm::EDGetTokenT<reco::BeamSpot> bsToken_;
0071   const edm::EDGetTokenT<reco::VertexCollection> vertexToken_;
0072 
0073   const std::string trackQuality_;
0074 
0075   std::vector<MonitorElement*> trackEtaHList_;
0076   std::vector<MonitorElement*> trackPhiHList_;
0077   std::vector<MonitorElement*> trackPHList_;
0078   std::vector<MonitorElement*> trackPtHList_;
0079   std::vector<MonitorElement*> trackPterrHList_;
0080   std::vector<MonitorElement*> trackqOverpHList_;
0081   std::vector<MonitorElement*> trackChi2bynDOFHList_;
0082   std::vector<MonitorElement*> nTracksHList_;
0083   std::vector<MonitorElement*> trackdzHList_;
0084 
0085   MonitorElement* hcounterH_;
0086   MonitorElement* dphiH_;
0087   MonitorElement* drH_;
0088 
0089   unsigned long long m_cacheID_;
0090 };
0091 
0092 void TrackTypeMonitor::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0093   edm::ParameterSetDescription desc;
0094 
0095   desc.addUntracked<std::string>("ModuleName", "TrackTypeMonitor");
0096   desc.addUntracked<std::string>("FolderName", "highPurityTracks");
0097   desc.addUntracked<bool>("verbose", false);
0098   desc.addUntracked<edm::InputTag>("muonInputTag", edm::InputTag("muons"));
0099   desc.addUntracked<edm::InputTag>("electronInputTag", edm::InputTag("gedGsfElectrons"));
0100   desc.addUntracked<edm::InputTag>("trackInputTag", edm::InputTag("generalTracks"));
0101   desc.addUntracked<edm::InputTag>("offlineBeamSpot", edm::InputTag("offlineBeamSpot"));
0102   desc.addUntracked<edm::InputTag>("vertexTag", edm::InputTag("offlinePrimaryVertices"));
0103   desc.addUntracked<std::string>("trackQuality", "highPurity");
0104 
0105   std::map<std::string, std::tuple<int, double, double> > listOfPS = {{"TrackEtaPar", {60, -3.0, 3.0}},
0106                                                                       {"TrackPhiPar", {100, -4.0, 4.0}},
0107                                                                       {"TrackPPar", {100, 0., 100.}},
0108                                                                       {"TrackPtPar", {100, 0., 100.}},
0109                                                                       {"TrackPterrPar", {100, 0., 100.}},
0110                                                                       {"TrackqOverpPar", {100, -10., 10.}},
0111                                                                       {"TrackdzPar", {100, -100., 100.}},
0112                                                                       {"TrackChi2bynDOFPar", {100, 0.0, 10.0}},
0113                                                                       {"nTracksPar", {100, -0.5, 99.5}}};
0114 
0115   for (const auto& [key, pSet] : listOfPS) {
0116     edm::ParameterSetDescription PSetToAdd;
0117     PSetToAdd.add<int>("Xbins", std::get<0>(pSet));
0118     PSetToAdd.add<double>("Xmin", std::get<1>(pSet));
0119     PSetToAdd.add<double>("Xmax", std::get<2>(pSet));
0120     desc.add<edm::ParameterSetDescription>(key, PSetToAdd);
0121   }
0122 
0123   descriptions.addWithDefaultLabel(desc);
0124 }
0125 
0126 template <class T>
0127 class PtComparator {
0128 public:
0129   bool operator()(const T* a, const T* b) const { return (a->pt() > b->pt()); }
0130 };
0131 // -----------------------------
0132 // constructors and destructor
0133 // -----------------------------
0134 TrackTypeMonitor::TrackTypeMonitor(const edm::ParameterSet& ps)
0135     : parameters_(ps),
0136       moduleName_(parameters_.getUntrackedParameter<std::string>("ModuleName", "TrackTypeMonitor")),
0137       folderName_(parameters_.getUntrackedParameter<std::string>("FolderName", "highPurityTracks")),
0138       verbose_(parameters_.getUntrackedParameter<bool>("verbose", false)),
0139       muonTag_(ps.getUntrackedParameter<edm::InputTag>("muonInputTag", edm::InputTag("muons"))),
0140       electronTag_(ps.getUntrackedParameter<edm::InputTag>("electronInputTag", edm::InputTag("gedGsfElectrons"))),
0141       trackTag_(parameters_.getUntrackedParameter<edm::InputTag>("trackInputTag", edm::InputTag("generalTracks"))),
0142       bsTag_(parameters_.getUntrackedParameter<edm::InputTag>("offlineBeamSpot", edm::InputTag("offlineBeamSpot"))),
0143       vertexTag_(
0144           parameters_.getUntrackedParameter<edm::InputTag>("vertexTag", edm::InputTag("offlinePrimaryVertices"))),
0145       electronToken_(consumes<reco::GsfElectronCollection>(electronTag_)),
0146       muonToken_(consumes<reco::MuonCollection>(muonTag_)),
0147       trackToken_(consumes<reco::TrackCollection>(trackTag_)),
0148       bsToken_(consumes<reco::BeamSpot>(bsTag_)),
0149       vertexToken_(consumes<reco::VertexCollection>(vertexTag_)),
0150       trackQuality_(parameters_.getUntrackedParameter<std::string>("trackQuality", "highPurity")) {
0151   trackEtaHList_.clear();
0152   trackPhiHList_.clear();
0153   trackPHList_.clear();
0154   trackPtHList_.clear();
0155   trackPterrHList_.clear();
0156   trackqOverpHList_.clear();
0157   trackChi2bynDOFHList_.clear();
0158   nTracksHList_.clear();
0159 }
0160 void TrackTypeMonitor::bookHistograms(DQMStore::IBooker& iBook, edm::Run const& iRun, edm::EventSetup const& iSetup) {
0161   edm::ParameterSet TrackEtaHistoPar = parameters_.getParameter<edm::ParameterSet>("TrackEtaPar");
0162   edm::ParameterSet TrackPhiHistoPar = parameters_.getParameter<edm::ParameterSet>("TrackPhiPar");
0163   edm::ParameterSet TrackPHistoPar = parameters_.getParameter<edm::ParameterSet>("TrackPPar");
0164   edm::ParameterSet TrackPtHistoPar = parameters_.getParameter<edm::ParameterSet>("TrackPtPar");
0165   edm::ParameterSet TrackPterrHistoPar = parameters_.getParameter<edm::ParameterSet>("TrackPterrPar");
0166   edm::ParameterSet TrackqOverpHistoPar = parameters_.getParameter<edm::ParameterSet>("TrackqOverpPar");
0167   edm::ParameterSet TrackdzHistoPar = parameters_.getParameter<edm::ParameterSet>("TrackdzPar");
0168   edm::ParameterSet TrackChi2bynDOFHistoPar = parameters_.getParameter<edm::ParameterSet>("TrackChi2bynDOFPar");
0169   edm::ParameterSet nTracksHistoPar = parameters_.getParameter<edm::ParameterSet>("nTracksPar");
0170 
0171   std::string currentFolder = moduleName_ + "/" + folderName_;
0172   iBook.setCurrentFolder(currentFolder);
0173 
0174   trackEtaHList_.push_back(iBook.book1DD("trackEtaIso",
0175                                          "Isolated Track Eta",
0176                                          TrackEtaHistoPar.getParameter<int32_t>("Xbins"),
0177                                          TrackEtaHistoPar.getParameter<double>("Xmin"),
0178                                          TrackEtaHistoPar.getParameter<double>("Xmax")));
0179   trackEtaHList_.push_back(iBook.book1DD("trackEtaNoIso",
0180                                          "NonIsolated Track Eta",
0181                                          TrackEtaHistoPar.getParameter<int32_t>("Xbins"),
0182                                          TrackEtaHistoPar.getParameter<double>("Xmin"),
0183                                          TrackEtaHistoPar.getParameter<double>("Xmax")));
0184   trackEtaHList_.push_back(iBook.book1DD("trackEtaUL",
0185                                          "Underlying Track Eta",
0186                                          TrackEtaHistoPar.getParameter<int32_t>("Xbins"),
0187                                          TrackEtaHistoPar.getParameter<double>("Xmin"),
0188                                          TrackEtaHistoPar.getParameter<double>("Xmax")));
0189   trackEtaHList_.push_back(iBook.book1DD("trackEtaALL",
0190                                          "All Track Eta",
0191                                          TrackEtaHistoPar.getParameter<int32_t>("Xbins"),
0192                                          TrackEtaHistoPar.getParameter<double>("Xmin"),
0193                                          TrackEtaHistoPar.getParameter<double>("Xmax")));
0194 
0195   trackPhiHList_.push_back(iBook.book1DD("trackPhiIso",
0196                                          "Isolated Track Phi",
0197                                          TrackPhiHistoPar.getParameter<int32_t>("Xbins"),
0198                                          TrackPhiHistoPar.getParameter<double>("Xmin"),
0199                                          TrackPhiHistoPar.getParameter<double>("Xmax")));
0200   trackPhiHList_.push_back(iBook.book1DD("trackPhiNonIso",
0201                                          "NonIsolated Track Phi",
0202                                          TrackPhiHistoPar.getParameter<int32_t>("Xbins"),
0203                                          TrackPhiHistoPar.getParameter<double>("Xmin"),
0204                                          TrackPhiHistoPar.getParameter<double>("Xmax")));
0205   trackPhiHList_.push_back(iBook.book1DD("trackPhiUL",
0206                                          "Underlying Track Phi",
0207                                          TrackPhiHistoPar.getParameter<int32_t>("Xbins"),
0208                                          TrackPhiHistoPar.getParameter<double>("Xmin"),
0209                                          TrackPhiHistoPar.getParameter<double>("Xmax")));
0210   trackPhiHList_.push_back(iBook.book1DD("trackPhiALL",
0211                                          "All Track Phi",
0212                                          TrackPhiHistoPar.getParameter<int32_t>("Xbins"),
0213                                          TrackPhiHistoPar.getParameter<double>("Xmin"),
0214                                          TrackPhiHistoPar.getParameter<double>("Xmax")));
0215 
0216   trackPHList_.push_back(iBook.book1DD("trackPIso",
0217                                        "Isolated Track P",
0218                                        TrackPHistoPar.getParameter<int32_t>("Xbins"),
0219                                        TrackPHistoPar.getParameter<double>("Xmin"),
0220                                        TrackPHistoPar.getParameter<double>("Xmax")));
0221   trackPHList_.push_back(iBook.book1DD("trackPNonIso",
0222                                        "NonIsolated Track P",
0223                                        TrackPHistoPar.getParameter<int32_t>("Xbins"),
0224                                        TrackPHistoPar.getParameter<double>("Xmin"),
0225                                        TrackPHistoPar.getParameter<double>("Xmax")));
0226   trackPHList_.push_back(iBook.book1DD("trackPUL",
0227                                        "Underlying Track P",
0228                                        TrackPHistoPar.getParameter<int32_t>("Xbins"),
0229                                        TrackPHistoPar.getParameter<double>("Xmin"),
0230                                        TrackPHistoPar.getParameter<double>("Xmax")));
0231   trackPHList_.push_back(iBook.book1DD("trackPALL",
0232                                        "All Track P",
0233                                        TrackPHistoPar.getParameter<int32_t>("Xbins"),
0234                                        TrackPHistoPar.getParameter<double>("Xmin"),
0235                                        TrackPHistoPar.getParameter<double>("Xmax")));
0236 
0237   trackPtHList_.push_back(iBook.book1DD("trackPtIsolated",
0238                                         "Isolated Track Pt",
0239                                         TrackPtHistoPar.getParameter<int32_t>("Xbins"),
0240                                         TrackPtHistoPar.getParameter<double>("Xmin"),
0241                                         TrackPtHistoPar.getParameter<double>("Xmax")));
0242   trackPtHList_.push_back(iBook.book1DD("trackPtNonIsolated",
0243                                         "NonIsolated Track Pt",
0244                                         TrackPtHistoPar.getParameter<int32_t>("Xbins"),
0245                                         TrackPtHistoPar.getParameter<double>("Xmin"),
0246                                         TrackPtHistoPar.getParameter<double>("Xmax")));
0247   trackPtHList_.push_back(iBook.book1DD("trackPtUL",
0248                                         "Underlying Track Pt",
0249                                         TrackPtHistoPar.getParameter<int32_t>("Xbins"),
0250                                         TrackPtHistoPar.getParameter<double>("Xmin"),
0251                                         TrackPtHistoPar.getParameter<double>("Xmax")));
0252   trackPtHList_.push_back(iBook.book1DD("trackPtALL",
0253                                         "All Track Pt",
0254                                         TrackPtHistoPar.getParameter<int32_t>("Xbins"),
0255                                         TrackPtHistoPar.getParameter<double>("Xmin"),
0256                                         TrackPtHistoPar.getParameter<double>("Xmax")));
0257 
0258   trackPterrHList_.push_back(iBook.book1DD("trackPterrIsolated",
0259                                            "Isolated Track Pterr",
0260                                            TrackPterrHistoPar.getParameter<int32_t>("Xbins"),
0261                                            TrackPterrHistoPar.getParameter<double>("Xmin"),
0262                                            TrackPterrHistoPar.getParameter<double>("Xmax")));
0263   trackPterrHList_.push_back(iBook.book1DD("trackPterrNonIsolated",
0264                                            "NonIsolated Track Pterr",
0265                                            TrackPterrHistoPar.getParameter<int32_t>("Xbins"),
0266                                            TrackPterrHistoPar.getParameter<double>("Xmin"),
0267                                            TrackPterrHistoPar.getParameter<double>("Xmax")));
0268   trackPterrHList_.push_back(iBook.book1DD("trackPterrUL",
0269                                            "Underlying Track Pterr",
0270                                            TrackPterrHistoPar.getParameter<int32_t>("Xbins"),
0271                                            TrackPterrHistoPar.getParameter<double>("Xmin"),
0272                                            TrackPterrHistoPar.getParameter<double>("Xmax")));
0273   trackPterrHList_.push_back(iBook.book1DD("trackPterrALL",
0274                                            "All Track Pterr",
0275                                            TrackPterrHistoPar.getParameter<int32_t>("Xbins"),
0276                                            TrackPterrHistoPar.getParameter<double>("Xmin"),
0277                                            TrackPterrHistoPar.getParameter<double>("Xmax")));
0278 
0279   trackqOverpHList_.push_back(iBook.book1DD("trackqOverpIsolated",
0280                                             "Isolated Track qOverp",
0281                                             TrackqOverpHistoPar.getParameter<int32_t>("Xbins"),
0282                                             TrackqOverpHistoPar.getParameter<double>("Xmin"),
0283                                             TrackqOverpHistoPar.getParameter<double>("Xmax")));
0284   trackqOverpHList_.push_back(iBook.book1DD("trackqOverpNonIsolated",
0285                                             "NonIsolated Track qOverp",
0286                                             TrackqOverpHistoPar.getParameter<int32_t>("Xbins"),
0287                                             TrackqOverpHistoPar.getParameter<double>("Xmin"),
0288                                             TrackqOverpHistoPar.getParameter<double>("Xmax")));
0289   trackqOverpHList_.push_back(iBook.book1DD("trackqOverpUL",
0290                                             "Underlying Track qOverp",
0291                                             TrackqOverpHistoPar.getParameter<int32_t>("Xbins"),
0292                                             TrackqOverpHistoPar.getParameter<double>("Xmin"),
0293                                             TrackqOverpHistoPar.getParameter<double>("Xmax")));
0294   trackqOverpHList_.push_back(iBook.book1DD("trackqOverpALL",
0295                                             "All Track qOverp",
0296                                             TrackqOverpHistoPar.getParameter<int32_t>("Xbins"),
0297                                             TrackqOverpHistoPar.getParameter<double>("Xmin"),
0298                                             TrackqOverpHistoPar.getParameter<double>("Xmax")));
0299 
0300   trackdzHList_.push_back(iBook.book1DD("trackdzIsolated",
0301                                         "Isolated Track dz",
0302                                         TrackdzHistoPar.getParameter<int32_t>("Xbins"),
0303                                         TrackdzHistoPar.getParameter<double>("Xmin"),
0304                                         TrackdzHistoPar.getParameter<double>("Xmax")));
0305   trackdzHList_.push_back(iBook.book1DD("trackdzNonIsolated",
0306                                         "NonIsolated Track dz",
0307                                         TrackdzHistoPar.getParameter<int32_t>("Xbins"),
0308                                         TrackdzHistoPar.getParameter<double>("Xmin"),
0309                                         TrackdzHistoPar.getParameter<double>("Xmax")));
0310   trackdzHList_.push_back(iBook.book1DD("trackdzUL",
0311                                         "Underlying Track dz",
0312                                         TrackdzHistoPar.getParameter<int32_t>("Xbins"),
0313                                         TrackdzHistoPar.getParameter<double>("Xmin"),
0314                                         TrackdzHistoPar.getParameter<double>("Xmax")));
0315   trackdzHList_.push_back(iBook.book1DD("trackdzALL",
0316                                         "All Track dz",
0317                                         TrackdzHistoPar.getParameter<int32_t>("Xbins"),
0318                                         TrackdzHistoPar.getParameter<double>("Xmin"),
0319                                         TrackdzHistoPar.getParameter<double>("Xmax")));
0320 
0321   trackChi2bynDOFHList_.push_back(iBook.book1DD("trackChi2bynDOFIsolated",
0322                                                 "Isolated Track Chi2bynDOF",
0323                                                 TrackChi2bynDOFHistoPar.getParameter<int32_t>("Xbins"),
0324                                                 TrackChi2bynDOFHistoPar.getParameter<double>("Xmin"),
0325                                                 TrackChi2bynDOFHistoPar.getParameter<double>("Xmax")));
0326   trackChi2bynDOFHList_.push_back(iBook.book1DD("trackChi2bynDOFNonIsolated",
0327                                                 "NonIsolated Track Chi2bynDOF",
0328                                                 TrackChi2bynDOFHistoPar.getParameter<int32_t>("Xbins"),
0329                                                 TrackChi2bynDOFHistoPar.getParameter<double>("Xmin"),
0330                                                 TrackChi2bynDOFHistoPar.getParameter<double>("Xmax")));
0331   trackChi2bynDOFHList_.push_back(iBook.book1DD("trackChi2bynDOFUL",
0332                                                 "Underlying Track Chi2bynDOF",
0333                                                 TrackChi2bynDOFHistoPar.getParameter<int32_t>("Xbins"),
0334                                                 TrackChi2bynDOFHistoPar.getParameter<double>("Xmin"),
0335                                                 TrackChi2bynDOFHistoPar.getParameter<double>("Xmax")));
0336   trackChi2bynDOFHList_.push_back(iBook.book1DD("trackChi2bynDOFAll",
0337                                                 "All Track Chi2bynDOF",
0338                                                 TrackChi2bynDOFHistoPar.getParameter<int32_t>("Xbins"),
0339                                                 TrackChi2bynDOFHistoPar.getParameter<double>("Xmin"),
0340                                                 TrackChi2bynDOFHistoPar.getParameter<double>("Xmax")));
0341 
0342   nTracksHList_.push_back(iBook.book1DD("nTracksIsolated",
0343                                         "Isolated Track nTracks",
0344                                         nTracksHistoPar.getParameter<int32_t>("Xbins"),
0345                                         nTracksHistoPar.getParameter<double>("Xmin"),
0346                                         nTracksHistoPar.getParameter<double>("Xmax")));
0347   nTracksHList_.push_back(iBook.book1DD("nTracksNonIsolated",
0348                                         "NonIsolated Track nTracks",
0349                                         nTracksHistoPar.getParameter<int32_t>("Xbins"),
0350                                         nTracksHistoPar.getParameter<double>("Xmin"),
0351                                         nTracksHistoPar.getParameter<double>("Xmax")));
0352   nTracksHList_.push_back(iBook.book1DD("nTracksUL",
0353                                         "Underlying Track nTracks",
0354                                         nTracksHistoPar.getParameter<int32_t>("Xbins"),
0355                                         nTracksHistoPar.getParameter<double>("Xmin"),
0356                                         nTracksHistoPar.getParameter<double>("Xmax")));
0357   nTracksHList_.push_back(iBook.book1DD("nTracksAll",
0358                                         "All Track nTracks",
0359                                         nTracksHistoPar.getParameter<int32_t>("Xbins"),
0360                                         nTracksHistoPar.getParameter<double>("Xmin"),
0361                                         nTracksHistoPar.getParameter<double>("Xmax")));
0362 
0363   hcounterH_ = iBook.book1DD("hcounter", "hcounter", 7, -0.5, 6.5);
0364   dphiH_ = iBook.book1DD("dphi", "dphi", 100, 0, 7);
0365   drH_ = iBook.book1DD("dr", "dr", 100, 0, 6);
0366 }
0367 void TrackTypeMonitor::analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup) {
0368   // read the beam spot
0369   edm::Handle<reco::BeamSpot> beamSpot;
0370   iEvent.getByToken(bsToken_, beamSpot);
0371 
0372   std::vector<const reco::Track*> isoTrkList;
0373 
0374   // muons
0375   edm::Handle<reco::MuonCollection> muonColl;
0376   iEvent.getByToken(muonToken_, muonColl);
0377 
0378   if (muonColl.isValid()) {
0379     for (auto const& muo : *muonColl) {
0380       if (muo.isGlobalMuon() && muo.isPFMuon() && std::abs(muo.eta()) <= 2.1 && muo.pt() > 1) {
0381         reco::TrackRef gtrkref = muo.globalTrack();
0382         if (!gtrkref.isNonnull())
0383           continue;
0384         const reco::Track* gtk = &(*gtrkref);
0385         double chi2 = gtk->chi2();
0386         double ndof = gtk->ndof();
0387         double chbyndof = (ndof > 0) ? chi2 / ndof : 0;
0388 
0389         const reco::HitPattern& hitp = gtk->hitPattern();
0390         int nPixelHits = hitp.numberOfValidPixelHits();
0391         int nStripHits = hitp.numberOfValidStripHits();
0392 
0393         reco::TrackRef itrkref = muo.innerTrack();  // tracker segment only
0394         if (!itrkref.isNonnull())
0395           continue;
0396         const reco::Track* tk = &(*itrkref);
0397         double trkd0 = tk->d0();
0398         double trkdz = tk->dz();
0399         if (beamSpot.isValid()) {
0400           trkd0 = -(tk->dxy(beamSpot->position()));
0401           trkdz = tk->dz(beamSpot->position());
0402         }
0403 
0404         // Hits/section in the muon chamber
0405         int nChambers = muo.numberOfChambers();
0406         int nMatches = muo.numberOfMatches();
0407         int nMatchedStations = muo.numberOfMatchedStations();
0408 
0409         // PF Isolation
0410         const reco::MuonPFIsolation& pfIso04 = muo.pfIsolationR04();
0411         double absiso = pfIso04.sumChargedParticlePt +
0412                         std::max(0.0, pfIso04.sumNeutralHadronEt + pfIso04.sumPhotonEt - 0.5 * pfIso04.sumPUPt);
0413         if (chbyndof < 10 && std::abs(trkd0) < 0.02 && std::abs(trkdz) < 20 && nPixelHits > 1 && nStripHits > 8 &&
0414             nChambers > 2 && nMatches > 2 && nMatchedStations > 2 && absiso / muo.pt() < 0.3) {
0415           isoTrkList.push_back(gtk);
0416           fillHistograms(*gtk, 0);
0417         }
0418       }
0419     }
0420   }
0421 
0422   // electrons
0423   edm::Handle<reco::GsfElectronCollection> electronColl;
0424   iEvent.getByToken(electronToken_, electronColl);
0425 
0426   if (electronColl.isValid()) {
0427     for (auto const& ele : *electronColl) {
0428       if (!ele.ecalDriven())
0429         continue;
0430       if (ele.pt() < 5)
0431         continue;
0432       hcounterH_->Fill(0);
0433 
0434       double hOverE = ele.hadronicOverEm();
0435       double sigmaee = ele.sigmaIetaIeta();
0436       double deltaPhiIn = ele.deltaPhiSuperClusterTrackAtVtx();
0437       double deltaEtaIn = ele.deltaEtaSuperClusterTrackAtVtx();
0438 
0439       if (ele.isEB()) {
0440         if (std::abs(deltaPhiIn) >= .15 && std::abs(deltaEtaIn) >= .007 && hOverE >= .12 && sigmaee >= .01)
0441           continue;
0442       } else if (ele.isEE()) {
0443         if (std::abs(deltaPhiIn) >= .10 && std::abs(deltaEtaIn) >= .009 && hOverE >= .10 && sigmaee >= .03)
0444           continue;
0445       }
0446       hcounterH_->Fill(1);
0447 
0448       reco::GsfTrackRef gsftrk = ele.gsfTrack();
0449       if (!gsftrk.isNonnull())
0450         continue;
0451       const reco::GsfTrack* trk = &(*gsftrk);
0452       double trkd0 = trk->d0();
0453       double trkdz = trk->dz();
0454       if (beamSpot.isValid()) {
0455         trkd0 = -(trk->dxy(beamSpot->position()));
0456         trkdz = trk->dz(beamSpot->position());
0457       }
0458       double chi2 = trk->chi2();
0459       double ndof = trk->ndof();
0460       double chbyndof = (ndof > 0) ? chi2 / ndof : 0;
0461       if (chbyndof >= 10)
0462         continue;
0463       hcounterH_->Fill(2);
0464 
0465       if (std::abs(trkd0) >= 0.02 || std::abs(trkdz) >= 20)
0466         continue;
0467       hcounterH_->Fill(3);
0468 
0469       const reco::HitPattern& hitp = trk->hitPattern();
0470       int nPixelHits = hitp.numberOfValidPixelHits();
0471       if (nPixelHits < 1)
0472         continue;
0473       hcounterH_->Fill(4);
0474 
0475       int nStripHits = hitp.numberOfValidStripHits();
0476       if (nStripHits < 8)
0477         continue;
0478       hcounterH_->Fill(5);
0479 
0480       reco::GsfElectron::PflowIsolationVariables pfIso = ele.pfIsolationVariables();
0481       float absiso =
0482           pfIso.sumChargedHadronPt + std::max(0.0, pfIso.sumNeutralHadronEt + pfIso.sumPhotonEt - 0.5 * pfIso.sumPUPt);
0483       float eiso = absiso / ele.pt();
0484       if (eiso > 0.2)
0485         continue;
0486       hcounterH_->Fill(6);
0487 
0488       isoTrkList.push_back(trk);
0489       fillHistograms(*trk, 0);
0490     }
0491   }
0492   nTracksHList_.at(0)->Fill(isoTrkList.size());
0493 
0494   // Read track collection
0495   edm::Handle<reco::TrackCollection> tracks;
0496   iEvent.getByToken(trackToken_, tracks);
0497 
0498   // Read vertex collection
0499   edm::Handle<reco::VertexCollection> vertexColl;
0500   iEvent.getByToken(vertexToken_, vertexColl);
0501 
0502   if (tracks.isValid()) {
0503     std::vector<const reco::Track*> nisoTrkList;
0504     const reco::Vertex& vit = vertexColl->front();  // Highest sumPt vertex
0505     reco::Track::TrackQuality quality = reco::Track::qualityByName(trackQuality_);
0506 
0507     int nmatch = 0;
0508     int nTracks = 0, nMBTracks = 0;
0509     for (auto const& track : *tracks) {
0510       if (!track.quality(quality))
0511         continue;
0512       ++nTracks;
0513       fillHistograms(track, 3);
0514 
0515       // now classify primary and underlying tracks using vertex information
0516       double dxy = track.dxy(vit.position());
0517       double dz = track.dz(vit.position());
0518       if (std::abs(dxy) < 0.02 && std::abs(dz) < 20) {  // primary tracks
0519                                                         // remove tracks associated to the identified particles
0520         double drmin = 999;
0521         for (auto const& tk : isoTrkList) {
0522           double dr = deltaR(track.eta(), track.phi(), tk->eta(), tk->phi());
0523           if (dr < drmin)
0524             drmin = dr;
0525         }
0526         if (drmin < 0.01) {
0527           if (verbose_) {
0528             edm::LogInfo("TrackTypeMonitor") << " Match: " << ++nmatch << " drmin = " << drmin;
0529             edm::LogInfo("TrackTypeMonitor")
0530                 << " Track Pt: " << track.pt() << " Eta: " << track.eta() << " Phi: " << track.phi();
0531             for (auto const& isotk : isoTrkList) {
0532               edm::LogInfo("TrackTypeMonitor")
0533                   << " Lepton Pt: " << isotk->pt() << " Eta: " << isotk->eta() << " Phi: " << isotk->phi();
0534             }
0535           }
0536           continue;
0537         }
0538 
0539         fillHistograms(track, 1);
0540         nisoTrkList.push_back(&track);
0541       } else {
0542         ++nMBTracks;
0543         fillHistograms(track, 2);  //non-primary tracks
0544       }
0545     }
0546     nTracksHList_.at(1)->Fill(nisoTrkList.size());
0547     nTracksHList_.at(2)->Fill(nMBTracks);
0548     nTracksHList_.at(3)->Fill(nTracks);
0549 
0550     std::sort(nisoTrkList.begin(), nisoTrkList.end(), PtComparator<reco::Track>());
0551     const reco::Track* isoTrk = isoTrkList.at(0);
0552     for (auto const& obj : nisoTrkList) {
0553       if (obj->pt() > 5) {
0554         double dphi = deltaPhi(isoTrk->phi(), obj->phi());
0555         dphiH_->Fill(std::abs(dphi));
0556 
0557         double dr = deltaR(isoTrk->eta(), isoTrk->phi(), obj->eta(), obj->phi());
0558         drH_->Fill(dr);
0559       }
0560     }
0561   }
0562 }
0563 void TrackTypeMonitor::fillHistograms(const reco::Track& track, int indx) {
0564   if (indx >= 0 && indx < static_cast<int>(trackEtaHList_.size()))
0565     trackEtaHList_.at(indx)->Fill(track.eta());
0566 
0567   if (indx >= 0 && indx < static_cast<int>(trackPhiHList_.size()))
0568     trackPhiHList_.at(indx)->Fill(track.phi());
0569 
0570   if (indx >= 0 && indx < static_cast<int>(trackPHList_.size()))
0571     trackPHList_.at(indx)->Fill(track.p());
0572 
0573   if (indx >= 0 && indx < static_cast<int>(trackPtHList_.size()))
0574     trackPtHList_.at(indx)->Fill(track.pt());
0575 
0576   if (indx >= 0 || indx < static_cast<int>(trackPterrHList_.size()))
0577     trackPterrHList_.at(indx)->Fill(track.ptError());
0578 
0579   if (indx >= 0 || indx < static_cast<int>(trackqOverpHList_.size()))
0580     trackqOverpHList_.at(indx)->Fill(track.qoverp());
0581 
0582   if (indx >= 0 || indx < static_cast<int>(trackqOverpHList_.size()))
0583     trackdzHList_.at(indx)->Fill(track.dz());
0584 
0585   double chi2 = track.chi2();
0586   double ndof = track.ndof();
0587   double chbyndof = (ndof > 0) ? chi2 / ndof : 0;
0588   trackChi2bynDOFHList_.at(indx)->Fill(chbyndof);
0589 }
0590 // Define this as a plug-in
0591 #include "FWCore/Framework/interface/MakerMacros.h"
0592 DEFINE_FWK_MODULE(TrackTypeMonitor);