CMS 3D CMS Logo

PatBJetTrackAnalyzer.cc
Go to the documentation of this file.
1 #include <algorithm>
2 #include <iostream>
3 #include <cmath>
4 #include <vector>
5 #include <string>
6 
7 #include <TH1.h>
8 #include <TProfile.h>
9 
10 #include <Math/VectorUtil.h>
11 
19 
21 
29 
31 public:
34  ~PatBJetTrackAnalyzer() override;
35 
36  // virtual methods called from base class EDAnalyzer
37  void beginJob() override;
38  void analyze(const edm::Event &event, const edm::EventSetup &es) override;
39 
40 private:
41  // configuration parameters
46 
47  double jetPtCut_; // minimum (uncorrected) jet energy
48  double jetEtaCut_; // maximum |eta| for jet
49  double maxDeltaR_; // angle between jet and tracks
50 
51  double minPt_; // track pt quality cut
52  unsigned int minPixelHits_; // minimum number of pixel hits
53  unsigned int minTotalHits_; // minimum number of total hits
54 
55  unsigned int nThTrack_; // n-th hightest track to choose
56 
57  // jet flavour constants
58 
60 
61  TH1 *flavours_;
62 
63  // one group of plots per jet flavour;
64  struct Plots {
70 };
71 
73  : jetsToken_(consumes<pat::JetCollection>(params.getParameter<edm::InputTag>("jets"))),
74  tracksToken_(consumes<reco::TrackCollection>(params.getParameter<edm::InputTag>("tracks"))),
75  beamSpotToken_(consumes<reco::BeamSpot>(params.getParameter<edm::InputTag>("beamSpot"))),
76  primaryVerticesToken_(consumes<reco::VertexCollection>(params.getParameter<edm::InputTag>("primaryVertices"))),
77  jetPtCut_(params.getParameter<double>("jetPtCut")),
78  jetEtaCut_(params.getParameter<double>("jetEtaCut")),
79  maxDeltaR_(params.getParameter<double>("maxDeltaR")),
80  minPt_(params.getParameter<double>("minPt")),
81  minPixelHits_(params.getParameter<unsigned int>("minPixelHits")),
82  minTotalHits_(params.getParameter<unsigned int>("minTotalHits")),
83  nThTrack_(params.getParameter<unsigned int>("nThTrack")) {}
84 
86 
88  // retrieve handle to auxiliary service
89  // used for storing histograms into ROOT file
91 
92  flavours_ = fs->make<TH1F>("flavours", "jet flavours", 5, 0, 5);
93 
94  // book histograms for all jet flavours
95  for (unsigned int i = 0; i < N_JET_TYPES; i++) {
96  Plots &plots = plots_[i];
97  const char *flavour, *name;
98 
99  switch ((Flavour)i) {
100  case ALL_JETS:
101  flavour = "all jets";
102  name = "all";
103  break;
104  case UDSG_JETS:
105  flavour = "light flavour jets";
106  name = "udsg";
107  break;
108  case C_JETS:
109  flavour = "charm jets";
110  name = "c";
111  break;
112  case B_JETS:
113  flavour = "bottom jets";
114  name = "b";
115  break;
116  default:
117  flavour = "unidentified jets";
118  name = "ni";
119  break;
120  }
121 
122  plots.allIP =
123  fs->make<TH1F>(Form("allIP_%s", name), Form("signed IP for all tracks in %s", flavour), 100, -0.1, 0.2);
124  plots.allIPErr = fs->make<TH1F>(
125  Form("allIPErr_%s", name), Form("error of signed IP for all tracks in %s", flavour), 100, 0, 0.05);
126  plots.allIPSig = fs->make<TH1F>(
127  Form("allIPSig_%s", name), Form("signed IP significance for all tracks in %s", flavour), 100, -10, 20);
128 
129  plots.trackIP = fs->make<TH1F>(
130  Form("trackIP_%s", name), Form("signed IP for selected positive track in %s", flavour), 100, -0.1, 0.2);
131  plots.trackIPErr = fs->make<TH1F>(Form("trackIPErr_%s", name),
132  Form("error of signed IP for selected positive track in %s", flavour),
133  100,
134  0,
135  0.05);
136  plots.trackIPSig = fs->make<TH1F>(Form("trackIPSig_%s", name),
137  Form("signed IP significance for selected positive track in %s", flavour),
138  100,
139  -10,
140  20);
141 
142  plots.negativeIP = fs->make<TH1F>(
143  Form("negativeIP_%s", name), Form("signed IP for selected negative track in %s", flavour), 100, -0.2, 0.1);
144  plots.negativeIPErr = fs->make<TH1F>(Form("negativeIPErr_%s", name),
145  Form("error of signed IP for selected negative track in %s", flavour),
146  100,
147  0,
148  0.05);
149  plots.negativeIPSig = fs->make<TH1F>(Form("negativeIPSig_%s", name),
150  Form("signed IP significance for selected negative track in %s", flavour),
151  100,
152  -20,
153  10);
154 
155  plots.nTracks = fs->make<TH1F>(Form("nTracks_%s", name), Form("number of usable tracks in %s", flavour), 30, 0, 30);
156  plots.allDeltaR =
157  fs->make<TH1F>(Form("allDeltaR_%s", name), Form("\\DeltaR between track and %s", flavour), 100, 0, 1);
158  }
159 }
160 
161 // helper function to sort the tracks by impact parameter significance
162 
163 static bool significanceHigher(const Measurement1D &meas1, const Measurement1D &meas2) {
164  return meas1.significance() > meas2.significance();
165 }
166 
168  // handle to the primary vertex collection
170  event.getByToken(primaryVerticesToken_, pvHandle);
171 
172  // handle to the tracks collection
174  event.getByToken(tracksToken_, tracksHandle);
175 
176  // handle to the jets collection
178  event.getByToken(jetsToken_, jetsHandle);
179 
180  // handle to the beam spot
182  event.getByToken(beamSpotToken_, beamSpot);
183 
184  // rare case of no reconstructed primary vertex
185  if (pvHandle->empty())
186  return;
187 
188  // extract the position of the (most probable) reconstructed vertex
189  math::XYZPoint pv = (*pvHandle)[0].position();
190 
191  // now go through all jets
192  for (pat::JetCollection::const_iterator jet = jetsHandle->begin(); jet != jetsHandle->end(); ++jet) {
193  // only look at jets that pass the pt and eta cut
194  if (jet->pt() < jetPtCut_ || std::abs(jet->eta()) > jetEtaCut_)
195  continue;
196 
198  // find out the jet flavour (differs between quark and anti-quark)
199  switch (std::abs(jet->partonFlavour())) {
200  case 1:
201  case 2:
202  case 3:
203  case 21:
204  flavour = UDSG_JETS;
205  break;
206  case 4:
207  flavour = C_JETS;
208  break;
209  case 5:
210  flavour = B_JETS;
211  break;
212  default:
214  }
215 
216  // simply count the number of accepted jets
217  flavours_->Fill(ALL_JETS);
218  flavours_->Fill(flavour);
219 
220  // this vector will contain IP value / error pairs
221  std::vector<Measurement1D> ipValErr;
222 
223  // Note: PAT is also able to store associated tracks
224  // within the jet object, so we don't have to do the
225  // matching ourselves
226  // (see ->associatedTracks() method)
227  // However, using this we can't play with the DeltaR cone
228  // withour rerunning the PAT producer
229 
230  // now loop through all tracks
231  for (reco::TrackCollection::const_iterator track = tracksHandle->begin(); track != tracksHandle->end(); ++track) {
232  // check the quality criteria
233  if (track->pt() < minPt_ || track->hitPattern().numberOfValidHits() < (int)minTotalHits_ ||
234  track->hitPattern().numberOfValidPixelHits() < (int)minPixelHits_)
235  continue;
236 
237  // check the Delta R between jet axis and track
238  // (Delta_R^2 = Delta_Eta^2 + Delta_Phi^2)
239  double deltaR = ROOT::Math::VectorUtil::DeltaR(jet->momentum(), track->momentum());
240 
242  plots_[flavour].allDeltaR->Fill(deltaR);
243 
244  // only look at tracks in jet cone
245  if (deltaR > maxDeltaR_)
246  continue;
247 
248  // What follows here is an approximation!
249  //
250  // The dxy() method of the tracks does a linear
251  // extrapolation from the track reference position
252  // given as the closest point to the beam spot
253  // with respect to the given vertex.
254  // Since we are using primary vertices, this
255  // approximation works well
256  //
257  // In order to get better results, the
258  // "TransientTrack" and specialised methods have
259  // to be used.
260  // Or look at the "impactParameterTagInfos",
261  // which contains the precomputed information
262  // from the official b-tagging algorithms
263  //
264  // see ->tagInfoTrackIP() method
265 
266  double ipError = track->dxyError();
267  double ipValue = std::abs(track->dxy(pv));
268 
269  // in order to compute the sign, we check if
270  // the point of closest approach to the vertex
271  // is in front or behind the vertex.
272  // Again, we a linear approximation
273  //
274  // dot product between reference point and jet axis
275 
276  math::XYZVector closestPoint = track->referencePoint() - beamSpot->position();
277  // only interested in transverse component, z -> 0
278  closestPoint.SetZ(0.);
279  double sign = closestPoint.Dot(jet->momentum());
280 
281  if (sign < 0)
282  ipValue = -ipValue;
283 
284  ipValErr.push_back(Measurement1D(ipValue, ipError));
285  }
286 
287  // now order all tracks by significance (highest first)
288  std::sort(ipValErr.begin(), ipValErr.end(), significanceHigher);
289 
290  plots_[ALL_JETS].nTracks->Fill(ipValErr.size());
291  plots_[flavour].nTracks->Fill(ipValErr.size());
292 
293  // plot all tracks
294 
295  for (std::vector<Measurement1D>::const_iterator iter = ipValErr.begin(); iter != ipValErr.end(); ++iter) {
296  plots_[ALL_JETS].allIP->Fill(iter->value());
297  plots_[flavour].allIP->Fill(iter->value());
298 
299  plots_[ALL_JETS].allIPErr->Fill(iter->error());
300  plots_[flavour].allIPErr->Fill(iter->error());
301 
302  // significance (is really just value / error)
303  plots_[ALL_JETS].allIPSig->Fill(iter->significance());
304  plots_[flavour].allIPSig->Fill(iter->significance());
305  }
306 
307  // check if we have enough tracks to fulfill the
308  // n-th track requirement
309  if (ipValErr.size() < nThTrack_)
310  continue;
311 
312  // pick the n-th highest track
313  const Measurement1D *trk = &ipValErr[nThTrack_ - 1];
314 
315  plots_[ALL_JETS].trackIP->Fill(trk->value());
316  plots_[flavour].trackIP->Fill(trk->value());
317 
318  plots_[ALL_JETS].trackIPErr->Fill(trk->error());
319  plots_[flavour].trackIPErr->Fill(trk->error());
320 
321  plots_[ALL_JETS].trackIPSig->Fill(trk->significance());
322  plots_[flavour].trackIPSig->Fill(trk->significance());
323 
324  // here we define a "negative tagger", i.e. we take
325  // the track with the n-lowest signed IP
326  // (i.e. preferrably select tracks that appear to become
327  // from "behind" the primary vertex, supposedly mismeasured
328  // tracks really coming from the primary vertex, and
329  // the contamination of displaced tracks should be small)
330  trk = &ipValErr[ipValErr.size() - nThTrack_];
331 
332  plots_[ALL_JETS].negativeIP->Fill(trk->value());
333  plots_[flavour].negativeIP->Fill(trk->value());
334 
335  plots_[ALL_JETS].negativeIPErr->Fill(trk->error());
336  plots_[flavour].negativeIPErr->Fill(trk->error());
337 
338  plots_[ALL_JETS].negativeIPSig->Fill(trk->significance());
339  plots_[flavour].negativeIPSig->Fill(trk->significance());
340  }
341 }
342 
344 
PatBJetTrackAnalyzer::analyze
void analyze(const edm::Event &event, const edm::EventSetup &es) override
Definition: PatBJetTrackAnalyzer.cc:167
PatBJetTrackAnalyzer::Plots::allDeltaR
TH1 * allDeltaR
Definition: PatBJetTrackAnalyzer.cc:68
PatBJetTrackAnalyzer::beginJob
void beginJob() override
Definition: PatBJetTrackAnalyzer.cc:87
Measurement1D
Definition: Measurement1D.h:11
mps_fire.i
i
Definition: mps_fire.py:428
PatBJetTrackAnalyzer::jetEtaCut_
double jetEtaCut_
Definition: PatBJetTrackAnalyzer.cc:48
pwdgSkimBPark_cfi.beamSpot
beamSpot
Definition: pwdgSkimBPark_cfi.py:5
HLT_FULL_cff.track
track
Definition: HLT_FULL_cff.py:11724
align::BeamSpot
Definition: StructureType.h:95
CalibrationSummaryClient_cfi.params
params
Definition: CalibrationSummaryClient_cfi.py:14
edm::EDGetTokenT< pat::JetCollection >
edm
HLT enums.
Definition: AlignableModifier.h:19
Measurement1D::value
double value() const
Definition: Measurement1D.h:25
PatBJetTrackAnalyzer::Flavour
Flavour
Definition: PatBJetTrackAnalyzer.cc:59
PatBJetTrackAnalyzer::Plots::trackIPErr
TH1 * trackIPErr
Definition: PatBJetTrackAnalyzer.cc:66
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89301
PatBJetTrackAnalyzer::B_JETS
Definition: PatBJetTrackAnalyzer.cc:59
Measurement1D.h
Validation_hcalonly_cfi.sign
sign
Definition: Validation_hcalonly_cfi.py:32
PatBJetTrackAnalyzer::C_JETS
Definition: PatBJetTrackAnalyzer.cc:59
EDAnalyzer.h
PatBJetTrackAnalyzer::minPixelHits_
unsigned int minPixelHits_
Definition: PatBJetTrackAnalyzer.cc:52
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:46
PatBJetTrackAnalyzer::flavours_
TH1 * flavours_
Definition: PatBJetTrackAnalyzer.cc:61
edm::Handle< reco::VertexCollection >
PatBJetTrackAnalyzer::N_JET_TYPES
Definition: PatBJetTrackAnalyzer.cc:59
edm::EDAnalyzer
Definition: EDAnalyzer.h:28
PatBJetTrackAnalyzer::PatBJetTrackAnalyzer
PatBJetTrackAnalyzer(const edm::ParameterSet &params)
constructor and destructor
Definition: PatBJetTrackAnalyzer.cc:72
PatBJetTrackAnalyzer::tracksToken_
edm::EDGetTokenT< reco::TrackCollection > tracksToken_
Definition: PatBJetTrackAnalyzer.cc:43
MakerMacros.h
PatBJetTrackAnalyzer::Plots::negativeIPErr
TH1 * negativeIPErr
Definition: PatBJetTrackAnalyzer.cc:67
Track.h
TrackFwd.h
PatBJetTrackAnalyzer::NONID_JETS
Definition: PatBJetTrackAnalyzer.cc:59
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
BeamSpot.h
PatBJetTrackAnalyzer::Plots::negativeIP
TH1 * negativeIP
Definition: PatBJetTrackAnalyzer.cc:67
Service.h
pat::JetCollection
std::vector< Jet > JetCollection
Definition: Jet.h:53
PatBJetTrackAnalyzer
Definition: PatBJetTrackAnalyzer.cc:30
PbPb_ZMuSkimMuonDPG_cff.deltaR
deltaR
Definition: PbPb_ZMuSkimMuonDPG_cff.py:63
Measurement1D::error
double error() const
Definition: Measurement1D.h:27
PatBJetTrackAnalyzer::Plots::allIPSig
TH1 * allIPSig
Definition: PatBJetTrackAnalyzer.cc:65
TFileService.h
Measurement1D::significance
double significance() const
Definition: Measurement1D.h:29
edm::ParameterSet
Definition: ParameterSet.h:47
math::XYZPoint
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
HLTObjectsMonitor_cfi.plots
plots
Definition: HLTObjectsMonitor_cfi.py:17
Event.h
PatBJetTrackAnalyzer::beamSpotToken_
edm::EDGetTokenT< reco::BeamSpot > beamSpotToken_
Definition: PatBJetTrackAnalyzer.cc:44
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
significanceHigher
static bool significanceHigher(const Measurement1D &meas1, const Measurement1D &meas2)
Definition: PatBJetTrackAnalyzer.cc:163
math::XYZVector
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
edm::Service< TFileService >
createfilelist.int
int
Definition: createfilelist.py:10
MetAnalyzer.pv
def pv(vc)
Definition: MetAnalyzer.py:7
PatBJetTrackAnalyzer::ALL_JETS
Definition: PatBJetTrackAnalyzer.cc:59
edm::EventSetup
Definition: EventSetup.h:58
pat
Definition: HeavyIon.h:7
PatBJetTrackAnalyzer::Plots::negativeIPSig
TH1 * negativeIPSig
Definition: PatBJetTrackAnalyzer.cc:67
electronAnalyzer_cfi.DeltaR
DeltaR
Definition: electronAnalyzer_cfi.py:33
PatBJetTrackAnalyzer::minTotalHits_
unsigned int minTotalHits_
Definition: PatBJetTrackAnalyzer.cc:53
PatBJetTrackAnalyzer::minPt_
double minPt_
Definition: PatBJetTrackAnalyzer.cc:51
Jet.h
PatBJetTrackAnalyzer::primaryVerticesToken_
edm::EDGetTokenT< reco::VertexCollection > primaryVerticesToken_
Definition: PatBJetTrackAnalyzer.cc:45
TFileService::make
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
PatBJetTrackAnalyzer::Plots::trackIPSig
TH1 * trackIPSig
Definition: PatBJetTrackAnalyzer.cc:66
PatBJetTrackAnalyzer::Plots
Definition: PatBJetTrackAnalyzer.cc:64
PatBJetTrackAnalyzer::maxDeltaR_
double maxDeltaR_
Definition: PatBJetTrackAnalyzer.cc:49
InputTag.h
VertexFwd.h
Vertex.h
PatBJetTrackAnalyzer::~PatBJetTrackAnalyzer
~PatBJetTrackAnalyzer() override
Definition: PatBJetTrackAnalyzer.cc:85
Frameworkfwd.h
PatBJetTrackAnalyzer::Plots::allIP
TH1 * allIP
Definition: PatBJetTrackAnalyzer.cc:65
metsig::jet
Definition: SignAlgoResolutions.h:47
PatBJetTrackAnalyzer::nThTrack_
unsigned int nThTrack_
Definition: PatBJetTrackAnalyzer.cc:55
l1t::VertexCollection
std::vector< Vertex > VertexCollection
Definition: Vertex.h:12
PatBJetTrackAnalyzer::Plots::nTracks
TH1 * nTracks
Definition: PatBJetTrackAnalyzer.cc:68
PatBJetTrackAnalyzer::UDSG_JETS
Definition: PatBJetTrackAnalyzer.cc:59
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
EventSetup.h
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
PatBJetTrackAnalyzer::plots_
struct PatBJetTrackAnalyzer::Plots plots_[N_JET_TYPES]
ParameterSet.h
PatBJetTrackAnalyzer::Plots::allIPErr
TH1 * allIPErr
Definition: PatBJetTrackAnalyzer.cc:65
event
Definition: event.py:1
edm::Event
Definition: Event.h:73
PatBJetTrackAnalyzer::jetPtCut_
double jetPtCut_
Definition: PatBJetTrackAnalyzer.cc:47
reco::TrackCollection
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
DiLeptonHelp::flavour
flavour
Definition: DiLeptonVertexHelpers.h:46
PatBJetTrackAnalyzer::jetsToken_
edm::EDGetTokenT< pat::JetCollection > jetsToken_
Definition: PatBJetTrackAnalyzer.cc:42
PatBJetTrackAnalyzer::Plots::trackIP
TH1 * trackIP
Definition: PatBJetTrackAnalyzer.cc:66