CMS 3D CMS Logo

PatBJetVertexAnalyzer.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 #include <Math/GenVector/PxPyPzE4D.h>
12 #include <Math/GenVector/PxPyPzM4D.h>
13 
21 
23 
32 
34 public:
37  ~PatBJetVertexAnalyzer() override;
38 
39  // virtual methods called from base class EDAnalyzer
40  void beginJob() override;
41  void analyze(const edm::Event &event, const edm::EventSetup &es) override;
42 
43 private:
44  // 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  // jet flavour constants
52 
54 
55  TH1 *flavours_;
56 
57  // one group of plots per jet flavour;
58  struct Plots {
59  TH1 *nVertices;
60  TH1 *deltaR, *mass, *dist, *distErr, *distSig;
61  TH1 *nTracks, *chi2;
63 };
64 
66  : jetsToken_(consumes<pat::JetCollection>(params.getParameter<edm::InputTag>("jets"))),
67  jetPtCut_(params.getParameter<double>("jetPtCut")),
68  jetEtaCut_(params.getParameter<double>("jetEtaCut")) {}
69 
71 
73  // retrieve handle to auxiliary service
74  // used for storing histograms into ROOT file
76 
77  flavours_ = fs->make<TH1F>("flavours", "jet flavours", 5, 0, 5);
78 
79  // book histograms for all jet flavours
80  for (unsigned int i = 0; i < N_JET_TYPES; i++) {
81  Plots &plots = plots_[i];
82  const char *flavour, *name;
83 
84  switch ((Flavour)i) {
85  case ALL_JETS:
86  flavour = "all jets";
87  name = "all";
88  break;
89  case UDSG_JETS:
90  flavour = "light flavour jets";
91  name = "udsg";
92  break;
93  case C_JETS:
94  flavour = "charm jets";
95  name = "c";
96  break;
97  case B_JETS:
98  flavour = "bottom jets";
99  name = "b";
100  break;
101  default:
102  flavour = "unidentified jets";
103  name = "ni";
104  break;
105  }
106 
107  plots.nVertices =
108  fs->make<TH1F>(Form("nVertices_%s", name), Form("number of secondary vertices in %s", flavour), 5, 0, 5);
109  plots.deltaR = fs->make<TH1F>(Form("deltaR_%s", name),
110  Form("\\DeltaR between vertex direction and jet direction in %s", flavour),
111  100,
112  0,
113  0.5);
114  plots.mass = fs->make<TH1F>(Form("mass_%s", name), Form("vertex mass in %s", flavour), 100, 0, 10);
115  plots.dist =
116  fs->make<TH1F>(Form("dist_%s", name), Form("Transverse distance between PV and SV in %s", flavour), 100, 0, 2);
117  plots.distErr = fs->make<TH1F>(
118  Form("distErr_%s", name), Form("Transverse distance error between PV and SV in %s", flavour), 100, 0, 0.5);
119  plots.distSig = fs->make<TH1F>(
120  Form("distSig_%s", name), Form("Transverse distance significance between PV and SV in %s", flavour), 100, 0, 50);
121  plots.nTracks = fs->make<TH1F>(
122  Form("nTracks_%s", name), Form("number of tracks at secondary vertex in %s", flavour), 20, 0, 20);
123  plots.chi2 =
124  fs->make<TH1F>(Form("chi2_%s", name), Form("secondary vertex fit \\chi^{2} in %s", flavour), 100, 0, 50);
125  }
126 }
127 
128 // helper function to sort the tracks by impact parameter significance
129 
131  // handle to the jets collection
133  event.getByToken(jetsToken_, jetsHandle);
134 
135  // now go through all jets
136  for (pat::JetCollection::const_iterator jet = jetsHandle->begin(); jet != jetsHandle->end(); ++jet) {
137  // only look at jets that pass the pt and eta cut
138  if (jet->pt() < jetPtCut_ || std::abs(jet->eta()) > jetEtaCut_)
139  continue;
140 
142  // find out the jet flavour (differs between quark and anti-quark)
143  switch (std::abs(jet->partonFlavour())) {
144  case 1:
145  case 2:
146  case 3:
147  case 21:
148  flavour = UDSG_JETS;
149  break;
150  case 4:
151  flavour = C_JETS;
152  break;
153  case 5:
154  flavour = B_JETS;
155  break;
156  default:
158  }
159 
160  // simply count the number of accepted jets
161  flavours_->Fill(ALL_JETS);
162  flavours_->Fill(flavour);
163 
164  // retrieve the "secondary vertex tag infos"
165  // this is the output of the b-tagging reconstruction code
166  // and contains secondary vertices in the jets
167  const reco::SecondaryVertexTagInfo &svTagInfo = *jet->tagInfoSecondaryVertex();
168 
169  // count the number of secondary vertices
170  plots_[ALL_JETS].nVertices->Fill(svTagInfo.nVertices());
171  plots_[flavour].nVertices->Fill(svTagInfo.nVertices());
172 
173  // ignore jets without SV from now on
174  if (svTagInfo.nVertices() < 1)
175  continue;
176 
177  // pick the first secondary vertex (the "best" one)
178  const reco::Vertex &sv = svTagInfo.secondaryVertex(0);
179 
180  // and plot number of tracks and chi^2
181  plots_[ALL_JETS].nTracks->Fill(sv.tracksSize());
182  plots_[flavour].nTracks->Fill(sv.tracksSize());
183 
184  plots_[ALL_JETS].chi2->Fill(sv.chi2());
185  plots_[flavour].chi2->Fill(sv.chi2());
186 
187  // the precomputed transverse distance to the primary vertex
188  Measurement1D distance = svTagInfo.flightDistance(0, true);
189 
190  plots_[ALL_JETS].dist->Fill(distance.value());
191  plots_[flavour].dist->Fill(distance.value());
192 
193  plots_[ALL_JETS].distErr->Fill(distance.error());
194  plots_[flavour].distErr->Fill(distance.error());
195 
196  plots_[ALL_JETS].distSig->Fill(distance.significance());
197  plots_[flavour].distSig->Fill(distance.significance());
198 
199  // the precomputed direction with respect to the primary vertex
200  const GlobalVector &dir = svTagInfo.flightDirection(0);
201 
202  // unfortunately CMSSW hsa all kinds of vectors,
203  // and sometimes we need to convert them *sigh*
204  math::XYZVector dir2(dir.x(), dir.y(), dir.z());
205 
206  // compute a few variables that we are plotting
207  double deltaR = ROOT::Math::VectorUtil::DeltaR(jet->momentum(), dir2);
208 
209  plots_[ALL_JETS].deltaR->Fill(deltaR);
210  plots_[flavour].deltaR->Fill(deltaR);
211 
212  // compute the invariant mass from a four-vector sum
213  math::XYZTLorentzVector trackFourVectorSum;
214 
215  // loop over all tracks in the vertex
216  for (reco::Vertex::trackRef_iterator track = sv.tracks_begin(); track != sv.tracks_end(); ++track) {
217  ROOT::Math::LorentzVector<ROOT::Math::PxPyPzM4D<double> > vec;
218  vec.SetPx((*track)->px());
219  vec.SetPy((*track)->py());
220  vec.SetPz((*track)->pz());
221  vec.SetM(0.13957); // pion mass
222  trackFourVectorSum += vec;
223  }
224 
225  // get the invariant mass: sqrt(E² - px² - py² - pz²)
226  double vertexMass = trackFourVectorSum.M();
227 
228  plots_[ALL_JETS].mass->Fill(vertexMass);
229  plots_[flavour].mass->Fill(vertexMass);
230  }
231 }
232 
234 
Vector3DBase
Definition: Vector3DBase.h:8
PatBJetVertexAnalyzer::B_JETS
Definition: PatBJetVertexAnalyzer.cc:53
PatBJetVertexAnalyzer::PatBJetVertexAnalyzer
PatBJetVertexAnalyzer(const edm::ParameterSet &params)
constructor and destructor
Definition: PatBJetVertexAnalyzer.cc:65
reco::Vertex::trackRef_iterator
std::vector< TrackBaseRef >::const_iterator trackRef_iterator
The iteratator for the vector<TrackRef>
Definition: Vertex.h:38
GenHFHadronMatcher_cff.flavour
flavour
Definition: GenHFHadronMatcher_cff.py:8
L1TDiffHarvesting_cfi.dir2
dir2
Definition: L1TDiffHarvesting_cfi.py:12
Measurement1D
Definition: Measurement1D.h:11
mps_fire.i
i
Definition: mps_fire.py:355
PatBJetVertexAnalyzer::N_JET_TYPES
Definition: PatBJetVertexAnalyzer.cc:53
PatBJetVertexAnalyzer::~PatBJetVertexAnalyzer
~PatBJetVertexAnalyzer() override
Definition: PatBJetVertexAnalyzer.cc:70
PatBJetVertexAnalyzer::Plots::dist
TH1 * dist
Definition: PatBJetVertexAnalyzer.cc:60
CalibrationSummaryClient_cfi.params
params
Definition: CalibrationSummaryClient_cfi.py:14
edm::EDGetTokenT< pat::JetCollection >
edm
HLT enums.
Definition: AlignableModifier.h:19
reco::TemplatedSecondaryVertexTagInfo
Definition: TemplatedSecondaryVertexTagInfo.h:47
PatBJetVertexAnalyzer::plots_
struct PatBJetVertexAnalyzer::Plots plots_[N_JET_TYPES]
reco::TemplatedSecondaryVertexTagInfo::nVertices
unsigned int nVertices() const
Definition: TemplatedSecondaryVertexTagInfo.h:112
Measurement1D.h
HLT_2018_cff.distance
distance
Definition: HLT_2018_cff.py:6417
EDAnalyzer.h
PatBJetVertexAnalyzer::UDSG_JETS
Definition: PatBJetVertexAnalyzer.cc:53
PatBJetVertexAnalyzer::jetPtCut_
double jetPtCut_
Definition: PatBJetVertexAnalyzer.cc:47
edm::Handle
Definition: AssociativeIterator.h:50
PatBJetVertexAnalyzer::beginJob
void beginJob() override
Definition: PatBJetVertexAnalyzer.cc:72
edm::EDAnalyzer
Definition: EDAnalyzer.h:29
PatBJetVertexAnalyzer::Plots::distSig
TH1 * distSig
Definition: PatBJetVertexAnalyzer.cc:60
MakerMacros.h
PatBJetVertexAnalyzer::Plots::mass
TH1 * mass
Definition: PatBJetVertexAnalyzer.cc:60
Track.h
TrackFwd.h
PatBJetVertexAnalyzer::Plots::chi2
TH1 * chi2
Definition: PatBJetVertexAnalyzer.cc:61
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Service.h
SecondaryVertexTagInfo.h
PatBJetVertexAnalyzer::Flavour
Flavour
Definition: PatBJetVertexAnalyzer.cc:53
pfDeepBoostedJetPreprocessParams_cfi.sv
sv
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:226
pat::JetCollection
std::vector< Jet > JetCollection
Definition: Jet.h:53
PatBJetVertexAnalyzer::Plots::nVertices
TH1 * nVertices
Definition: PatBJetVertexAnalyzer.cc:59
PatBJetVertexAnalyzer::Plots::deltaR
TH1 * deltaR
Definition: PatBJetVertexAnalyzer.cc:60
PbPb_ZMuSkimMuonDPG_cff.deltaR
deltaR
Definition: PbPb_ZMuSkimMuonDPG_cff.py:63
Vertex.h
PatBJetVertexAnalyzer
Definition: PatBJetVertexAnalyzer.cc:33
TFileService.h
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::ParameterSet
Definition: ParameterSet.h:36
HLTObjectsMonitor_cfi.plots
plots
Definition: HLTObjectsMonitor_cfi.py:17
Event.h
PatBJetVertexAnalyzer::ALL_JETS
Definition: PatBJetVertexAnalyzer.cc:53
PatBJetVertexAnalyzer::flavours_
TH1 * flavours_
Definition: PatBJetVertexAnalyzer.cc:55
reco::TemplatedSecondaryVertexTagInfo::secondaryVertex
const VTX & secondaryVertex(unsigned int index) const
Definition: TemplatedSecondaryVertexTagInfo.h:107
math::XYZVector
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
LorentzVector.h
edm::Service< TFileService >
PatBJetVertexAnalyzer::jetEtaCut_
double jetEtaCut_
Definition: PatBJetVertexAnalyzer.cc:48
PatBJetVertexAnalyzer::C_JETS
Definition: PatBJetVertexAnalyzer.cc:53
edm::EventSetup
Definition: EventSetup.h:57
pat
Definition: HeavyIon.h:7
electronAnalyzer_cfi.DeltaR
DeltaR
Definition: electronAnalyzer_cfi.py:33
PatBJetVertexAnalyzer::Plots
Definition: PatBJetVertexAnalyzer.cc:58
Jet.h
PatBJetVertexAnalyzer::NONID_JETS
Definition: PatBJetVertexAnalyzer.cc:53
InputTag.h
VertexFwd.h
reco::TemplatedSecondaryVertexTagInfo::flightDistance
Measurement1D flightDistance(unsigned int index, int dim=0) const
Definition: TemplatedSecondaryVertexTagInfo.h:131
PatBJetVertexAnalyzer::Plots::nTracks
TH1 * nTracks
Definition: PatBJetVertexAnalyzer.cc:61
Frameworkfwd.h
math::XYZTLorentzVector
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
metsig::jet
Definition: SignAlgoResolutions.h:47
PatBJetVertexAnalyzer::Plots::distErr
TH1 * distErr
Definition: PatBJetVertexAnalyzer.cc:60
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
EventSetup.h
HLT_2018_cff.track
track
Definition: HLT_2018_cff.py:10352
PatBJetVertexAnalyzer::maxDeltaR_
double maxDeltaR_
Definition: PatBJetVertexAnalyzer.cc:49
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ParameterSet.h
PatBJetVertexAnalyzer::jetsToken_
edm::EDGetTokenT< pat::JetCollection > jetsToken_
Definition: PatBJetVertexAnalyzer.cc:45
event
Definition: event.py:1
edm::Event
Definition: Event.h:73
PatBJetVertexAnalyzer::analyze
void analyze(const edm::Event &event, const edm::EventSetup &es) override
Definition: PatBJetVertexAnalyzer.cc:130
reco::btau::vertexMass
Definition: TaggingVariable.h:75
reco::Vertex
Definition: Vertex.h:35
TFileService::make
T * make(const Args &... args) const
make new ROOT object
Definition: TFileService.h:64
DeadROC_duringRun.dir
dir
Definition: DeadROC_duringRun.py:23
reco::TemplatedSecondaryVertexTagInfo::flightDirection
const GlobalVector & flightDirection(unsigned int index) const
Definition: TemplatedSecondaryVertexTagInfo.h:139