CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PatTrackAnalyzer.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <cmath>
3 #include <vector>
4 #include <string>
5 
6 #include <TH1.h>
7 #include <TProfile.h>
8 
16 
18 
24 
26  public:
28  PatTrackAnalyzer(const edm::ParameterSet &params);
30 
31  // virtual methods called from base class EDAnalyzer
32  virtual void beginJob();
33  virtual void analyze(const edm::Event &event, const edm::EventSetup &es);
34 
35  private:
36  // configuration parameters
39 
40  // the list of track quality cuts to demand from the tracking
41  std::vector<std::string> qualities_;
42 
43  // holder for the histograms, one set per quality flag
44  struct Plots {
45  TH1 *eta, *phi;
46  TH1 *pt, *ptErr;
47  TH1 *invPt, *invPtErr;
48  TH1 *d0, *d0Err;
49  TH1 *nHits;
50 
51  TProfile *pxbHitsEta, *pxeHitsEta;
52  TProfile *tibHitsEta, *tobHitsEta;
53  TProfile *tidHitsEta, *tecHitsEta;
54  };
55 
56  std::vector<Plots> plots_;
57 };
58 
59 
61  src_(params.getParameter<edm::InputTag>("src")),
62  beamSpot_(params.getParameter<edm::InputTag>("beamSpot")),
63  qualities_(params.getParameter< std::vector<std::string> >("qualities"))
64 {
65 }
66 
68 {
69 }
70 
72 {
73  // retrieve handle to auxiliary service
74  // used for storing histograms into ROOT file
76 
77  // now book the histograms, for each category
78  unsigned int nQualities = qualities_.size();
79 
80  plots_.resize(nQualities);
81 
82  for(unsigned int i = 0; i < nQualities; ++i) {
83  // the name of the quality flag
84  const char *quality = qualities_[i].c_str();
85 
86  // the set of plots
87  Plots &plots = plots_[i];
88 
89  plots.eta = fs->make<TH1F>(Form("eta_%s", quality),
90  Form("track \\eta (%s)", quality),
91  100, -3, 3);
92  plots.phi = fs->make<TH1F>(Form("phi_%s", quality),
93  Form("track \\phi (%s)", quality),
94  100, -M_PI, +M_PI);
95  plots.pt = fs->make<TH1F>(Form("pt_%s", quality),
96  Form("track p_{T} (%s)", quality),
97  100, 0, 10);
98  plots.ptErr = fs->make<TH1F>(Form("ptErr_%s", quality),
99  Form("track p_{T} error (%s)", quality),
100  100, 0, 1);
101  plots.invPt = fs->make<TH1F>(Form("invPt_%s", quality),
102  Form("track 1/p_{T} (%s)", quality),
103  100, -5, 5);
104  plots.invPtErr = fs->make<TH1F>(Form("invPtErr_%s", quality),
105  Form("track 1/p_{T} error (%s)", quality),
106  100, 0, 0.1);
107  plots.d0 = fs->make<TH1F>(Form("d0_%s", quality),
108  Form("track d0 (%s)", quality),
109  100, 0, 0.1);
110  plots.d0Err = fs->make<TH1F>(Form("d0Err_%s", quality),
111  Form("track d0 error (%s)", quality),
112  100, 0, 0.1);
113  plots.nHits = fs->make<TH1F>(Form("nHits_%s", quality),
114  Form("track number of total hits (%s)", quality),
115  60, 0, 60);
116 
117  plots.pxbHitsEta = fs->make<TProfile>(Form("pxbHitsEta_%s", quality),
118  Form("#hits in Pixel Barrel (%s)", quality),
119  100, 0, 3);
120  plots.pxeHitsEta = fs->make<TProfile>(Form("pxeHitsEta_%s", quality),
121  Form("#hits in Pixel Endcap (%s)", quality),
122  100, 0, 3);
123  plots.tibHitsEta = fs->make<TProfile>(Form("tibHitsEta_%s", quality),
124  Form("#hits in Tracker Inner Barrel (%s)", quality),
125  100, 0, 3);
126  plots.tobHitsEta = fs->make<TProfile>(Form("tobHitsEta_%s", quality),
127  Form("#hits in Tracker Outer Barrel (%s)", quality),
128  100, 0, 3);
129  plots.tidHitsEta = fs->make<TProfile>(Form("tidHitsEta_%s", quality),
130  Form("#hits in Tracker Inner Disk (%s)", quality),
131  100, 0, 3);
132  plots.tecHitsEta = fs->make<TProfile>(Form("tecHitsEta_%s", quality),
133  Form("#hits in Tracker Endcap (%s)", quality),
134  100, 0, 3);
135  }
136 }
137 
139 {
140  // handles to kinds of data we might want to read
144 
145  // read the beam spot
146  event.getByLabel(beamSpot_, beamSpot);
147 
148  // our internal copy of track points
149  // (we need this in order to able to simultaneously access tracks
150  // directly or embedded in PAT objects, like muons, normally you
151  // would iterate over the handle directly)
152  std::vector<const reco::Track*> tracks;
153 
154  event.getByLabel(src_, tracksHandle);
155  if (tracksHandle.isValid()) {
156  // framework was able to read the collection as a view of
157  // tracks, no copy them to our "tracks" variable
158  for(edm::View<reco::Track>::const_iterator iter = tracksHandle->begin();
159  iter != tracksHandle->end(); ++iter)
160  tracks.push_back(&*iter);
161  } else {
162  // does not exist or is not a track collection
163  // let's assume it is a collection of PAT muons
164  event.getByLabel(src_, muonsHandle);
165 
166  // and copy them over
167  // NOTE: We are using ->globalTrack() here
168  // This means we are using the global fit over both
169  // the inner tracker and the muon stations!
170  // other alternatives are: innerTrack(), outerTrack()
171  for(pat::MuonCollection::const_iterator iter = muonsHandle->begin();
172  iter != muonsHandle->end(); ++iter) {
173  reco::TrackRef track = iter->globalTrack();
174  // the muon might not be a "global" muon
175  if (track.isNonnull())
176  tracks.push_back(&*track);
177  }
178  }
179 
180  // we are done filling the tracks into our "tracks" vector.
181  // now analyze them, once for each track quality category
182 
183  unsigned int nQualities = qualities_.size();
184  for(unsigned int i = 0; i < nQualities; ++i) {
185  // we convert the quality flag from its name as a string
186  // to the enumeration value used by the tracking code
187  // (which is essentially an integer number)
189 
190  // our set of plots
191  Plots &plots = plots_[i];
192 
193  // now loop over the tracks
194  for(std::vector<const reco::Track*>::const_iterator iter = tracks.begin();
195  iter != tracks.end(); ++iter) {
196  // this is our track
197  const reco::Track &track = **iter;
198 
199  // ignore tracks that fail the quality cut
200  if (!track.quality(quality))
201  continue;
202 
203  // and fill all the plots
204  plots.eta->Fill(track.eta());
205  plots.phi->Fill(track.phi());
206 
207  plots.pt->Fill(track.pt());
208  plots.ptErr->Fill(track.ptError());
209 
210  plots.invPt->Fill(track.qoverp());
211  plots.invPtErr->Fill(track.qoverpError());
212 
213  // the transverse IP is taken with respect to
214  // the beam spot instead of (0, 0)
215  // because the beam spot in CMS is not at (0, 0)
216  plots.d0->Fill(track.dxy(beamSpot->position()));
217  plots.d0Err->Fill(track.dxyError());
218 
219  plots.nHits->Fill(track.numberOfValidHits());
220 
221  // the hit pattern contains information about
222  // which modules of the detector have been hit
223  const reco::HitPattern &hits = track.hitPattern();
224 
225  double absEta = std::abs(track.eta());
226  // now fill the number of hits in a layer depending on eta
227  plots.pxbHitsEta->Fill(absEta, hits.numberOfValidPixelBarrelHits());
228  plots.pxeHitsEta->Fill(absEta, hits.numberOfValidPixelEndcapHits());
229  plots.tibHitsEta->Fill(absEta, hits.numberOfValidStripTIBHits());
230  plots.tobHitsEta->Fill(absEta, hits.numberOfValidStripTOBHits());
231  plots.tidHitsEta->Fill(absEta, hits.numberOfValidStripTIDHits());
232  plots.tecHitsEta->Fill(absEta, hits.numberOfValidStripTECHits());
233  }
234  }
235 }
236 
238 
double qoverp() const
q/p
Definition: TrackBase.h:115
int i
Definition: DBlmapReader.cc:9
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
TrackQuality
track quality
Definition: TrackBase.h:95
double dxyError() const
error on dxy
Definition: TrackBase.h:209
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< Plots > plots_
std::vector< std::string > qualities_
#define abs(x)
Definition: mlp_lapack.h:159
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:139
int numberOfValidStripTIDHits() const
Definition: HitPattern.cc:424
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:249
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:141
int numberOfValidPixelEndcapHits() const
Definition: HitPattern.cc:385
double pt() const
track transverse momentum
Definition: TrackBase.h:131
double ptError() const
error on Pt (set to 1000 TeV if charge==0 for safety)
Definition: TrackBase.h:194
int numberOfValidStripTECHits() const
Definition: HitPattern.cc:450
unsigned short numberOfValidHits() const
number of valid hits found
Definition: TrackBase.h:232
edm::InputTag beamSpot_
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
Definition: TrackBase.h:223
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
bool isValid() const
Definition: HandleBase.h:76
PatTrackAnalyzer(const edm::ParameterSet &params)
constructor and destructor
int numberOfValidStripTIBHits() const
Definition: HitPattern.cc:411
double qoverpError() const
error on signed transverse curvature
Definition: TrackBase.h:192
virtual void analyze(const edm::Event &event, const edm::EventSetup &es)
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:46
#define M_PI
Definition: BFit3D.cc:3
tuple tracks
Definition: testEve_cfg.py:39
bool quality(const TrackQuality) const
Track quality.
Definition: TrackBase.h:364
int numberOfValidStripTOBHits() const
Definition: HitPattern.cc:437
edm::InputTag src_
T * make() const
make new ROOT object
virtual void beginJob()
int numberOfValidPixelBarrelHits() const
Definition: HitPattern.cc:372
double dxy() const
dxy parameter. (This is the transverse impact parameter w.r.t. to (0,0,0) ONLY if refPoint is close t...
Definition: TrackBase.h:121