File indexing completed on 2024-04-06 12:24:01
0001 #include <iostream>
0002 #include <cmath>
0003 #include <vector>
0004 #include <string>
0005
0006 #include <TH1.h>
0007 #include <TProfile.h>
0008
0009 #include "FWCore/Framework/interface/Frameworkfwd.h"
0010 #include "FWCore/Framework/interface/Event.h"
0011 #include "FWCore/Framework/interface/EventSetup.h"
0012 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0013 #include "FWCore/Utilities/interface/InputTag.h"
0014 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0015 #include "FWCore/ServiceRegistry/interface/Service.h"
0016
0017 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0018
0019 #include "DataFormats/Common/interface/View.h"
0020 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
0021 #include "DataFormats/TrackReco/interface/Track.h"
0022 #include "DataFormats/TrackReco/interface/HitPattern.h"
0023 #include "DataFormats/PatCandidates/interface/Muon.h"
0024
0025 class PatTrackAnalyzer : public edm::one::EDAnalyzer<edm::one::SharedResources> {
0026 public:
0027
0028 PatTrackAnalyzer(const edm::ParameterSet ¶ms);
0029 ~PatTrackAnalyzer() override;
0030
0031
0032 void beginJob() override;
0033 void analyze(const edm::Event &event, const edm::EventSetup &es) override;
0034
0035 private:
0036
0037 edm::EDGetTokenT<edm::View<reco::Track> > srcTracksToken_;
0038 edm::EDGetTokenT<pat::MuonCollection> srcMuonsToken_;
0039 edm::EDGetTokenT<reco::BeamSpot> beamSpotToken_;
0040
0041
0042 std::vector<std::string> qualities_;
0043
0044
0045 struct Plots {
0046 TH1 *eta, *phi;
0047 TH1 *pt, *ptErr;
0048 TH1 *invPt, *invPtErr;
0049 TH1 *d0, *d0Err;
0050 TH1 *nHits;
0051
0052 TProfile *pxbHitsEta, *pxeHitsEta;
0053 TProfile *tibHitsEta, *tobHitsEta;
0054 TProfile *tidHitsEta, *tecHitsEta;
0055 };
0056
0057 std::vector<Plots> plots_;
0058 };
0059
0060 PatTrackAnalyzer::PatTrackAnalyzer(const edm::ParameterSet ¶ms)
0061 : srcTracksToken_(mayConsume<edm::View<reco::Track> >(params.getParameter<edm::InputTag>("src"))),
0062 srcMuonsToken_(mayConsume<pat::MuonCollection>(params.getParameter<edm::InputTag>("src"))),
0063 beamSpotToken_(consumes<reco::BeamSpot>(params.getParameter<edm::InputTag>("beamSpot"))),
0064 qualities_(params.getParameter<std::vector<std::string> >("qualities")) {
0065 usesResource(TFileService::kSharedResource);
0066 }
0067
0068 PatTrackAnalyzer::~PatTrackAnalyzer() {}
0069
0070 void PatTrackAnalyzer::beginJob() {
0071
0072
0073 edm::Service<TFileService> fs;
0074
0075
0076 unsigned int nQualities = qualities_.size();
0077
0078 plots_.resize(nQualities);
0079
0080 for (unsigned int i = 0; i < nQualities; ++i) {
0081
0082 const char *quality = qualities_[i].c_str();
0083
0084
0085 Plots &plots = plots_[i];
0086
0087 plots.eta = fs->make<TH1F>(Form("eta_%s", quality), Form("track \\eta (%s)", quality), 100, -3, 3);
0088 plots.phi = fs->make<TH1F>(Form("phi_%s", quality), Form("track \\phi (%s)", quality), 100, -M_PI, +M_PI);
0089 plots.pt = fs->make<TH1F>(Form("pt_%s", quality), Form("track p_{T} (%s)", quality), 100, 0, 10);
0090 plots.ptErr = fs->make<TH1F>(Form("ptErr_%s", quality), Form("track p_{T} error (%s)", quality), 100, 0, 1);
0091 plots.invPt = fs->make<TH1F>(Form("invPt_%s", quality), Form("track 1/p_{T} (%s)", quality), 100, -5, 5);
0092 plots.invPtErr =
0093 fs->make<TH1F>(Form("invPtErr_%s", quality), Form("track 1/p_{T} error (%s)", quality), 100, 0, 0.1);
0094 plots.d0 = fs->make<TH1F>(Form("d0_%s", quality), Form("track d0 (%s)", quality), 100, 0, 0.1);
0095 plots.d0Err = fs->make<TH1F>(Form("d0Err_%s", quality), Form("track d0 error (%s)", quality), 100, 0, 0.1);
0096 plots.nHits =
0097 fs->make<TH1F>(Form("nHits_%s", quality), Form("track number of total hits (%s)", quality), 60, 0, 60);
0098
0099 plots.pxbHitsEta =
0100 fs->make<TProfile>(Form("pxbHitsEta_%s", quality), Form("#hits in Pixel Barrel (%s)", quality), 100, 0, 3);
0101 plots.pxeHitsEta =
0102 fs->make<TProfile>(Form("pxeHitsEta_%s", quality), Form("#hits in Pixel Endcap (%s)", quality), 100, 0, 3);
0103 plots.tibHitsEta = fs->make<TProfile>(
0104 Form("tibHitsEta_%s", quality), Form("#hits in Tracker Inner Barrel (%s)", quality), 100, 0, 3);
0105 plots.tobHitsEta = fs->make<TProfile>(
0106 Form("tobHitsEta_%s", quality), Form("#hits in Tracker Outer Barrel (%s)", quality), 100, 0, 3);
0107 plots.tidHitsEta = fs->make<TProfile>(
0108 Form("tidHitsEta_%s", quality), Form("#hits in Tracker Inner Disk (%s)", quality), 100, 0, 3);
0109 plots.tecHitsEta =
0110 fs->make<TProfile>(Form("tecHitsEta_%s", quality), Form("#hits in Tracker Endcap (%s)", quality), 100, 0, 3);
0111 }
0112 }
0113
0114 void PatTrackAnalyzer::analyze(const edm::Event &event, const edm::EventSetup &es) {
0115
0116 edm::Handle<reco::BeamSpot> beamSpot;
0117 edm::Handle<edm::View<reco::Track> > tracksHandle;
0118 edm::Handle<pat::MuonCollection> muonsHandle;
0119
0120
0121 event.getByToken(beamSpotToken_, beamSpot);
0122
0123
0124
0125
0126
0127 std::vector<const reco::Track *> tracks;
0128
0129 event.getByToken(srcTracksToken_, tracksHandle);
0130 if (tracksHandle.isValid()) {
0131
0132
0133 for (edm::View<reco::Track>::const_iterator iter = tracksHandle->begin(); iter != tracksHandle->end(); ++iter)
0134 tracks.push_back(&*iter);
0135 } else {
0136
0137
0138 event.getByToken(srcMuonsToken_, muonsHandle);
0139
0140
0141
0142
0143
0144
0145 for (pat::MuonCollection::const_iterator iter = muonsHandle->begin(); iter != muonsHandle->end(); ++iter) {
0146 reco::TrackRef track = iter->globalTrack();
0147
0148 if (track.isNonnull())
0149 tracks.push_back(&*track);
0150 }
0151 }
0152
0153
0154
0155
0156 unsigned int nQualities = qualities_.size();
0157 for (unsigned int i = 0; i < nQualities; ++i) {
0158
0159
0160
0161 reco::Track::TrackQuality quality = reco::Track::qualityByName(qualities_[i]);
0162
0163
0164 Plots &plots = plots_[i];
0165
0166
0167 for (std::vector<const reco::Track *>::const_iterator iter = tracks.begin(); iter != tracks.end(); ++iter) {
0168
0169 const reco::Track &track = **iter;
0170
0171
0172 if (!track.quality(quality))
0173 continue;
0174
0175
0176 plots.eta->Fill(track.eta());
0177 plots.phi->Fill(track.phi());
0178
0179 plots.pt->Fill(track.pt());
0180 plots.ptErr->Fill(track.ptError());
0181
0182 plots.invPt->Fill(track.qoverp());
0183 plots.invPtErr->Fill(track.qoverpError());
0184
0185
0186
0187
0188 plots.d0->Fill(track.dxy(beamSpot->position()));
0189 plots.d0Err->Fill(track.dxyError());
0190
0191 plots.nHits->Fill(track.numberOfValidHits());
0192
0193
0194
0195 const reco::HitPattern &hits = track.hitPattern();
0196
0197 double absEta = std::abs(track.eta());
0198
0199 plots.pxbHitsEta->Fill(absEta, hits.numberOfValidPixelBarrelHits());
0200 plots.pxeHitsEta->Fill(absEta, hits.numberOfValidPixelEndcapHits());
0201 plots.tibHitsEta->Fill(absEta, hits.numberOfValidStripTIBHits());
0202 plots.tobHitsEta->Fill(absEta, hits.numberOfValidStripTOBHits());
0203 plots.tidHitsEta->Fill(absEta, hits.numberOfValidStripTIDHits());
0204 plots.tecHitsEta->Fill(absEta, hits.numberOfValidStripTECHits());
0205 }
0206 }
0207 }
0208
0209 #include "FWCore/Framework/interface/MakerMacros.h"
0210
0211 DEFINE_FWK_MODULE(PatTrackAnalyzer);