00001 #include <iostream>
00002 #include <cmath>
00003 #include <vector>
00004 #include <string>
00005
00006 #include <TH1.h>
00007 #include <TProfile.h>
00008
00009 #include "FWCore/Framework/interface/Frameworkfwd.h"
00010 #include "FWCore/Framework/interface/Event.h"
00011 #include "FWCore/Framework/interface/EventSetup.h"
00012 #include "FWCore/Framework/interface/EDAnalyzer.h"
00013 #include "FWCore/Utilities/interface/InputTag.h"
00014 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00015 #include "FWCore/ServiceRegistry/interface/Service.h"
00016
00017 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00018
00019 #include "DataFormats/Common/interface/View.h"
00020 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00021 #include "DataFormats/TrackReco/interface/Track.h"
00022 #include "DataFormats/TrackReco/interface/HitPattern.h"
00023 #include "DataFormats/PatCandidates/interface/Muon.h"
00024
00025 class PatTrackAnalyzer : public edm::EDAnalyzer {
00026 public:
00028 PatTrackAnalyzer(const edm::ParameterSet ¶ms);
00029 ~PatTrackAnalyzer();
00030
00031
00032 virtual void beginJob();
00033 virtual void analyze(const edm::Event &event, const edm::EventSetup &es);
00034
00035 private:
00036
00037 edm::InputTag src_;
00038 edm::InputTag beamSpot_;
00039
00040
00041 std::vector<std::string> qualities_;
00042
00043
00044 struct Plots {
00045 TH1 *eta, *phi;
00046 TH1 *pt, *ptErr;
00047 TH1 *invPt, *invPtErr;
00048 TH1 *d0, *d0Err;
00049 TH1 *nHits;
00050
00051 TProfile *pxbHitsEta, *pxeHitsEta;
00052 TProfile *tibHitsEta, *tobHitsEta;
00053 TProfile *tidHitsEta, *tecHitsEta;
00054 };
00055
00056 std::vector<Plots> plots_;
00057 };
00058
00059
00060 PatTrackAnalyzer::PatTrackAnalyzer(const edm::ParameterSet ¶ms) :
00061 src_(params.getParameter<edm::InputTag>("src")),
00062 beamSpot_(params.getParameter<edm::InputTag>("beamSpot")),
00063 qualities_(params.getParameter< std::vector<std::string> >("qualities"))
00064 {
00065 }
00066
00067 PatTrackAnalyzer::~PatTrackAnalyzer()
00068 {
00069 }
00070
00071 void PatTrackAnalyzer::beginJob()
00072 {
00073
00074
00075 edm::Service<TFileService> fs;
00076
00077
00078 unsigned int nQualities = qualities_.size();
00079
00080 plots_.resize(nQualities);
00081
00082 for(unsigned int i = 0; i < nQualities; ++i) {
00083
00084 const char *quality = qualities_[i].c_str();
00085
00086
00087 Plots &plots = plots_[i];
00088
00089 plots.eta = fs->make<TH1F>(Form("eta_%s", quality),
00090 Form("track \\eta (%s)", quality),
00091 100, -3, 3);
00092 plots.phi = fs->make<TH1F>(Form("phi_%s", quality),
00093 Form("track \\phi (%s)", quality),
00094 100, -M_PI, +M_PI);
00095 plots.pt = fs->make<TH1F>(Form("pt_%s", quality),
00096 Form("track p_{T} (%s)", quality),
00097 100, 0, 10);
00098 plots.ptErr = fs->make<TH1F>(Form("ptErr_%s", quality),
00099 Form("track p_{T} error (%s)", quality),
00100 100, 0, 1);
00101 plots.invPt = fs->make<TH1F>(Form("invPt_%s", quality),
00102 Form("track 1/p_{T} (%s)", quality),
00103 100, -5, 5);
00104 plots.invPtErr = fs->make<TH1F>(Form("invPtErr_%s", quality),
00105 Form("track 1/p_{T} error (%s)", quality),
00106 100, 0, 0.1);
00107 plots.d0 = fs->make<TH1F>(Form("d0_%s", quality),
00108 Form("track d0 (%s)", quality),
00109 100, 0, 0.1);
00110 plots.d0Err = fs->make<TH1F>(Form("d0Err_%s", quality),
00111 Form("track d0 error (%s)", quality),
00112 100, 0, 0.1);
00113 plots.nHits = fs->make<TH1F>(Form("nHits_%s", quality),
00114 Form("track number of total hits (%s)", quality),
00115 60, 0, 60);
00116
00117 plots.pxbHitsEta = fs->make<TProfile>(Form("pxbHitsEta_%s", quality),
00118 Form("#hits in Pixel Barrel (%s)", quality),
00119 100, 0, 3);
00120 plots.pxeHitsEta = fs->make<TProfile>(Form("pxeHitsEta_%s", quality),
00121 Form("#hits in Pixel Endcap (%s)", quality),
00122 100, 0, 3);
00123 plots.tibHitsEta = fs->make<TProfile>(Form("tibHitsEta_%s", quality),
00124 Form("#hits in Tracker Inner Barrel (%s)", quality),
00125 100, 0, 3);
00126 plots.tobHitsEta = fs->make<TProfile>(Form("tobHitsEta_%s", quality),
00127 Form("#hits in Tracker Outer Barrel (%s)", quality),
00128 100, 0, 3);
00129 plots.tidHitsEta = fs->make<TProfile>(Form("tidHitsEta_%s", quality),
00130 Form("#hits in Tracker Inner Disk (%s)", quality),
00131 100, 0, 3);
00132 plots.tecHitsEta = fs->make<TProfile>(Form("tecHitsEta_%s", quality),
00133 Form("#hits in Tracker Endcap (%s)", quality),
00134 100, 0, 3);
00135 }
00136 }
00137
00138 void PatTrackAnalyzer::analyze(const edm::Event &event, const edm::EventSetup &es)
00139 {
00140
00141 edm::Handle<reco::BeamSpot> beamSpot;
00142 edm::Handle< edm::View<reco::Track> > tracksHandle;
00143 edm::Handle< pat::MuonCollection > muonsHandle;
00144
00145
00146 event.getByLabel(beamSpot_, beamSpot);
00147
00148
00149
00150
00151
00152 std::vector<const reco::Track*> tracks;
00153
00154 event.getByLabel(src_, tracksHandle);
00155 if (tracksHandle.isValid()) {
00156
00157
00158 for(edm::View<reco::Track>::const_iterator iter = tracksHandle->begin();
00159 iter != tracksHandle->end(); ++iter)
00160 tracks.push_back(&*iter);
00161 } else {
00162
00163
00164 event.getByLabel(src_, muonsHandle);
00165
00166
00167
00168
00169
00170
00171 for(pat::MuonCollection::const_iterator iter = muonsHandle->begin();
00172 iter != muonsHandle->end(); ++iter) {
00173 reco::TrackRef track = iter->globalTrack();
00174
00175 if (track.isNonnull())
00176 tracks.push_back(&*track);
00177 }
00178 }
00179
00180
00181
00182
00183 unsigned int nQualities = qualities_.size();
00184 for(unsigned int i = 0; i < nQualities; ++i) {
00185
00186
00187
00188 reco::Track::TrackQuality quality = reco::Track::qualityByName(qualities_[i]);
00189
00190
00191 Plots &plots = plots_[i];
00192
00193
00194 for(std::vector<const reco::Track*>::const_iterator iter = tracks.begin();
00195 iter != tracks.end(); ++iter) {
00196
00197 const reco::Track &track = **iter;
00198
00199
00200 if (!track.quality(quality))
00201 continue;
00202
00203
00204 plots.eta->Fill(track.eta());
00205 plots.phi->Fill(track.phi());
00206
00207 plots.pt->Fill(track.pt());
00208 plots.ptErr->Fill(track.ptError());
00209
00210 plots.invPt->Fill(track.qoverp());
00211 plots.invPtErr->Fill(track.qoverpError());
00212
00213
00214
00215
00216 plots.d0->Fill(track.dxy(beamSpot->position()));
00217 plots.d0Err->Fill(track.dxyError());
00218
00219 plots.nHits->Fill(track.numberOfValidHits());
00220
00221
00222
00223 const reco::HitPattern &hits = track.hitPattern();
00224
00225 double absEta = std::abs(track.eta());
00226
00227 plots.pxbHitsEta->Fill(absEta, hits.numberOfValidPixelBarrelHits());
00228 plots.pxeHitsEta->Fill(absEta, hits.numberOfValidPixelEndcapHits());
00229 plots.tibHitsEta->Fill(absEta, hits.numberOfValidStripTIBHits());
00230 plots.tobHitsEta->Fill(absEta, hits.numberOfValidStripTOBHits());
00231 plots.tidHitsEta->Fill(absEta, hits.numberOfValidStripTIDHits());
00232 plots.tecHitsEta->Fill(absEta, hits.numberOfValidStripTECHits());
00233 }
00234 }
00235 }
00236
00237 #include "FWCore/Framework/interface/MakerMacros.h"
00238
00239 DEFINE_FWK_MODULE(PatTrackAnalyzer);