CMS 3D CMS Logo

BTVHLTOfflineSource.cc
Go to the documentation of this file.
2 
11 
17 
19 
21 
24 
25 #include "TMath.h"
26 #include "TH1F.h"
27 #include "TH2F.h"
28 #include "TProfile.h"
29 #include "TPRegexp.h"
30 
31 #include <cmath>
32 #include <iostream>
33 
34 using namespace edm;
35 using namespace reco;
36 using namespace std;
37 using namespace trigger;
38 
40  LogDebug("BTVHLTOfflineSource") << "constructor....";
41 
42  dirname_ = iConfig.getUntrackedParameter("dirname", std::string("HLT/BTV/"));
43  processname_ = iConfig.getParameter<std::string>("processname");
44  verbose_ = iConfig.getUntrackedParameter<bool>("verbose", false);
45  triggerSummaryLabel_ = iConfig.getParameter<edm::InputTag>("triggerSummaryLabel");
46  triggerResultsLabel_ = iConfig.getParameter<edm::InputTag>("triggerResultsLabel");
47  turnon_threshold_loose_ = iConfig.getParameter<double>("turnon_threshold_loose");
48  turnon_threshold_medium_ = iConfig.getParameter<double>("turnon_threshold_medium");
49  turnon_threshold_tight_ = iConfig.getParameter<double>("turnon_threshold_tight");
50  triggerSummaryToken = consumes<trigger::TriggerEvent>(triggerSummaryLabel_);
51  triggerResultsToken = consumes<edm::TriggerResults>(triggerResultsLabel_);
52  triggerSummaryFUToken = consumes<trigger::TriggerEvent>(
53  edm::InputTag(triggerSummaryLabel_.label(), triggerSummaryLabel_.instance(), std::string("FU")));
54  triggerResultsFUToken = consumes<edm::TriggerResults>(
55  edm::InputTag(triggerResultsLabel_.label(), triggerResultsLabel_.instance(), std::string("FU")));
56  shallowTagInfosTokenCalo_ =
57  consumes<vector<reco::ShallowTagInfo> >(edm::InputTag("hltDeepCombinedSecondaryVertexBJetTagsInfosCalo"));
58  shallowTagInfosTokenPf_ =
59  consumes<vector<reco::ShallowTagInfo> >(edm::InputTag("hltDeepCombinedSecondaryVertexBJetTagsInfos"));
60  // caloTagInfosToken_ = consumes<vector<reco::TemplatedSecondaryVertexTagInfo<reco::IPTagInfo<edm::RefVector<vector<reco::Track>,reco::Track,edm::refhelper::FindUsingAdvance<vector<reco::Track>,reco::Track> >,reco::JTATagInfo>,reco::Vertex> > > (
61  // edm::InputTag("hltCombinedSecondaryVertexBJetTagsCalo"));
62  // pfTagInfosToken_ = consumes<vector<reco::TemplatedSecondaryVertexTagInfo<reco::IPTagInfo<edm::RefVector<vector<reco::Track>,reco::Track,edm::refhelper::FindUsingAdvance<vector<reco::Track>,reco::Track> >,reco::JTATagInfo>,reco::Vertex> > > (
63  // edm::InputTag("hltCombinedSecondaryVertexBJetTagsPF"));
64  pfTagsToken_ = consumes<reco::JetTagCollection>(iConfig.getParameter<edm::InputTag>("onlineDiscrLabelPF"));
65  caloTagsToken_ = consumes<reco::JetTagCollection>(iConfig.getParameter<edm::InputTag>("onlineDiscrLabelCalo"));
66  offlineDiscrTokenb_ = consumes<reco::JetTagCollection>(iConfig.getParameter<edm::InputTag>("offlineDiscrLabelb"));
67  offlineDiscrTokenbb_ = consumes<reco::JetTagCollection>(iConfig.getParameter<edm::InputTag>("offlineDiscrLabelbb"));
68  hltFastPVToken_ = consumes<std::vector<reco::Vertex> >(iConfig.getParameter<edm::InputTag>("hltFastPVLabel"));
69  hltPFPVToken_ = consumes<std::vector<reco::Vertex> >(iConfig.getParameter<edm::InputTag>("hltPFPVLabel"));
70  hltCaloPVToken_ = consumes<std::vector<reco::Vertex> >(iConfig.getParameter<edm::InputTag>("hltCaloPVLabel"));
71  offlinePVToken_ = consumes<std::vector<reco::Vertex> >(iConfig.getParameter<edm::InputTag>("offlinePVLabel"));
72 
73  std::vector<edm::ParameterSet> paths = iConfig.getParameter<std::vector<edm::ParameterSet> >("pathPairs");
74  for (auto& path : paths) {
75  custompathnamepairs_.push_back(
76  make_pair(path.getParameter<std::string>("pathname"), path.getParameter<std::string>("pathtype")));
77  }
78 }
79 
81 
83  bool changed = true;
84  if (!hltConfig_.init(run, c, processname_, changed)) {
85  LogDebug("BTVHLTOfflineSource") << "HLTConfigProvider failed to initialize.";
86  }
87 
88  for (unsigned int i = 0; i != hltConfig_.size(); ++i) {
89  const auto& pathname = hltConfig_.triggerName(i);
90 
91  for (auto& custompathnamepair : custompathnamepairs_) {
92  if (pathname.find(custompathnamepair.first) != std::string::npos) {
93  hltPathsAll_.push_back(PathInfo(1, pathname, "dummy", processname_, 0, custompathnamepair.second));
94  }
95  }
96  }
97 }
98 
101  if (!triggerResults_.isValid()) {
102  iEvent.getByToken(triggerResultsFUToken, triggerResults_);
103  if (!triggerResults_.isValid()) {
104  edm::LogInfo("BTVHLTOfflineSource") << "TriggerResults not found, "
105  "skipping event";
106  return;
107  }
108  }
109 
110  triggerNames_ = iEvent.triggerNames(*triggerResults_);
111 
112  iEvent.getByToken(triggerSummaryToken, triggerObj_);
113  if (!triggerObj_.isValid()) {
114  iEvent.getByToken(triggerSummaryFUToken, triggerObj_);
115  if (!triggerObj_.isValid()) {
116  edm::LogInfo("BTVHLTOfflineSource") << "TriggerEvent not found, "
117  "skipping event";
118  return;
119  }
120  }
121 
122  iEvent.getByToken(caloTagsToken_, caloTags);
123  iEvent.getByToken(pfTagsToken_, pfTags);
124 
125  Handle<reco::VertexCollection> VertexHandler;
126 
127  Handle<reco::JetTagCollection> offlineJetTagHandlerb;
128  iEvent.getByToken(offlineDiscrTokenb_, offlineJetTagHandlerb);
129 
130  Handle<reco::JetTagCollection> offlineJetTagHandlerbb;
131  iEvent.getByToken(offlineDiscrTokenbb_, offlineJetTagHandlerbb);
132 
133  Handle<reco::VertexCollection> offlineVertexHandler;
134  iEvent.getByToken(offlinePVToken_, offlineVertexHandler);
135 
136  if (verbose_ && iEvent.id().event() % 10000 == 0)
137  cout << "Run = " << iEvent.id().run() << ", LS = " << iEvent.luminosityBlock()
138  << ", Event = " << iEvent.id().event() << endl;
139 
140  if (!triggerResults_.isValid())
141  return;
142 
143  for (auto& v : hltPathsAll_) {
144  unsigned index = triggerNames_.triggerIndex(v.getPath());
145  if (!(index < triggerNames_.size())) {
146  continue;
147  }
148 
149  // PF and Calo btagging
150  if ((v.getTriggerType() == "PF" && pfTags.isValid()) ||
151  (v.getTriggerType() == "Calo" && caloTags.isValid() && !caloTags->empty())) {
152  const auto& iter = (v.getTriggerType() == "PF") ? pfTags->begin() : caloTags->begin();
153 
154  float Discr_online = iter->second;
155  if (Discr_online < 0)
156  Discr_online = -0.05;
157 
158  v.Discr->Fill(Discr_online);
159  v.Pt->Fill(iter->first->pt());
160  v.Eta->Fill(iter->first->eta());
161 
162  if (offlineJetTagHandlerb.isValid()) {
163  for (auto const& iterOffb : *offlineJetTagHandlerb) {
164  float DR = reco::deltaR(iterOffb.first->eta(), iterOffb.first->phi(), iter->first->eta(), iter->first->phi());
165  if (DR < 0.3) {
166  float Discr_offline = iterOffb.second;
167 
168  // offline probb and probbb must be added (if probbb isn't specified, it'll just use probb)
169  if (offlineJetTagHandlerbb.isValid()) {
170  for (auto const& iterOffbb : *offlineJetTagHandlerbb) {
171  DR = reco::deltaR(
172  iterOffbb.first->eta(), iterOffbb.first->phi(), iter->first->eta(), iter->first->phi());
173  if (DR < 0.3) {
174  Discr_offline += iterOffbb.second;
175  break;
176  }
177  }
178  }
179 
180  if (Discr_offline < 0)
181  Discr_offline = -0.05;
182  v.Discr_HLTvsRECO->Fill(Discr_online, Discr_offline);
183  v.Discr_HLTMinusRECO->Fill(Discr_online - Discr_offline);
184 
185  v.Discr_turnon_loose.denominator->Fill(Discr_offline);
186  v.Discr_turnon_medium.denominator->Fill(Discr_offline);
187  v.Discr_turnon_tight.denominator->Fill(Discr_offline);
188 
189  if (Discr_online > turnon_threshold_loose_)
190  v.Discr_turnon_loose.numerator->Fill(Discr_offline);
191  if (Discr_online > turnon_threshold_medium_)
192  v.Discr_turnon_medium.numerator->Fill(Discr_offline);
193  if (Discr_online > turnon_threshold_tight_)
194  v.Discr_turnon_tight.numerator->Fill(Discr_offline);
195 
196  break;
197  }
198  }
199  }
200 
201  if (v.getTriggerType() == "PF") {
202  iEvent.getByToken(hltPFPVToken_, VertexHandler);
203  } else {
204  iEvent.getByToken(hltFastPVToken_, VertexHandler);
205  }
206  if (VertexHandler.isValid()) {
207  v.PVz->Fill(VertexHandler->begin()->z());
208  if (offlineVertexHandler.isValid()) {
209  v.PVz_HLTMinusRECO->Fill(VertexHandler->begin()->z() - offlineVertexHandler->begin()->z());
210  }
211  }
212  }
213 
214  // specific to Calo b-tagging
215  if (caloTags.isValid() && v.getTriggerType() == "Calo" && !caloTags->empty()) {
216  iEvent.getByToken(hltCaloPVToken_, VertexHandler);
217  if (VertexHandler.isValid()) {
218  v.fastPVz->Fill(VertexHandler->begin()->z());
219  if (offlineVertexHandler.isValid()) {
220  v.fastPVz_HLTMinusRECO->Fill(VertexHandler->begin()->z() - offlineVertexHandler->begin()->z());
221  }
222  }
223  }
224 
225  // additional plots from tag info collections
227 
228  iEvent.getByToken(shallowTagInfosTokenPf_, shallowTagInfosPf);
229  iEvent.getByToken(shallowTagInfosTokenCalo_, shallowTagInfosCalo);
230  // iEvent.getByToken(pfTagInfosToken_, pfTagInfos);
231  // iEvent.getByToken(caloTagInfosToken_, caloTagInfos);
232 
233  // first try to get info from shallowTagInfos ...
234  if ((v.getTriggerType() == "PF" && shallowTagInfosPf.isValid()) ||
235  (v.getTriggerType() == "Calo" && shallowTagInfosCalo.isValid())) {
236  const auto& shallowTagInfoCollection = (v.getTriggerType() == "PF") ? shallowTagInfosPf : shallowTagInfosCalo;
237  for (const auto& shallowTagInfo : *shallowTagInfoCollection) {
238  const auto& tagVars = shallowTagInfo.taggingVariables();
239 
240  // n secondary vertices and n selected tracks
241  for (const auto& tagVar : tagVars.getList(reco::btau::jetNSecondaryVertices, false)) {
242  v.n_vtx->Fill(tagVar);
243  }
244  for (const auto& tagVar : tagVars.getList(reco::btau::jetNSelectedTracks, false)) {
245  v.n_sel_tracks->Fill(tagVar);
246  }
247 
248  // impact parameter
249  const auto& trackSip3dVal = tagVars.getList(reco::btau::trackSip3dVal, false);
250  const auto& trackSip3dSig = tagVars.getList(reco::btau::trackSip3dSig, false);
251  for (unsigned i_trk = 0; i_trk < trackSip3dVal.size(); i_trk++) {
252  float val = trackSip3dVal[i_trk];
253  float sig = trackSip3dSig[i_trk];
254  v.h_3d_ip_distance->Fill(val);
255  v.h_3d_ip_error->Fill(val / sig);
256  v.h_3d_ip_sig->Fill(sig);
257  }
258 
259  // vertex mass and tracks per vertex
260  for (const auto& tagVar : tagVars.getList(reco::btau::vertexMass, false)) {
261  v.vtx_mass->Fill(tagVar);
262  }
263  for (const auto& tagVar : tagVars.getList(reco::btau::vertexNTracks, false)) {
264  v.n_vtx_trks->Fill(tagVar);
265  }
266 
267  // // track N total/pixel hits
268  // for (const auto & tagVar : tagVars.getList(reco::btau::trackNPixelHits, false)) {
269  // v.n_pixel_hits->Fill(tagVar);}
270  // for (const auto & tagVar : tagVars.getList(reco::btau::trackNTotalHits, false)) {
271  // v.n_total_hits->Fill(tagVar);}
272  }
273  }
274 
275  // ... otherwise from usual tag infos.
276  // else
277  // if ( (v.getTriggerType() == "PF" && pfTagInfos.isValid())
278  // || (v.getTriggerType() == "Calo" && caloTagInfos.isValid()) )
279  // {
280  // const auto & DiscrTagInfoCollection = (v.getTriggerType() == "PF") ? pfTagInfos : caloTagInfos;
281 
282  // // loop over secondary vertex tag infos
283  // for (const auto & DiscrTagInfo : *DiscrTagInfoCollection) {
284  // v.n_vtx->Fill(DiscrTagInfo.nVertexCandidates());
285  // v.n_sel_tracks->Fill(DiscrTagInfo.nSelectedTracks());
286 
287  // // loop over selected tracks in each tag info
288  // for (unsigned i_trk=0; i_trk < DiscrTagInfo.nSelectedTracks(); i_trk++) {
289  // const auto & ip3d = DiscrTagInfo.trackIPData(i_trk).ip3d;
290  // v.h_3d_ip_distance->Fill(ip3d.value());
291  // v.h_3d_ip_error->Fill(ip3d.error());
292  // v.h_3d_ip_sig->Fill(ip3d.significance());
293  // }
294 
295  // // loop over vertex candidates in each tag info
296  // for (unsigned i_sv=0; i_sv < DiscrTagInfo.nVertexCandidates(); i_sv++) {
297  // const auto & sv = DiscrTagInfo.secondaryVertex(i_sv);
298  // v.vtx_mass->Fill(sv.p4().mass());
299  // v.n_vtx_trks->Fill(sv.nTracks());
300 
301  // // loop over tracks for number of pixel and total hits
302  // const auto & trkIPTagInfo = DiscrTagInfo.trackIPTagInfoRef().get();
303  // for (const auto & trk : trkIPTagInfo->selectedTracks()) {
304  // v.n_pixel_hits->Fill(trk.get()->hitPattern().numberOfValidPixelHits());
305  // v.n_total_hits->Fill(trk.get()->hitPattern().numberOfValidHits());
306  // }
307  // }
308  // }
309  // }
310  }
311 }
312 
314  iBooker.setCurrentFolder(dirname_);
315  for (auto& v : hltPathsAll_) {
316  std::string trgPathName = HLTConfigProvider::removeVersion(v.getPath());
317  std::string subdirName = dirname_ + "/" + trgPathName + v.getTriggerType();
318  std::string trigPath = "(" + trgPathName + ")";
319  iBooker.setCurrentFolder(subdirName);
320 
321  std::string labelname("HLT");
322  std::string histoname(labelname + "");
323  std::string title(labelname + "");
324 
325  histoname = labelname + "_Discr";
326  title = labelname + "_Discr " + trigPath;
327  v.Discr = iBooker.book1D(histoname.c_str(), title.c_str(), 110, -0.1, 1);
328 
329  histoname = labelname + "_Pt";
330  title = labelname + "_Pt " + trigPath;
331  v.Pt = iBooker.book1D(histoname.c_str(), title.c_str(), 100, 0, 400);
332 
333  histoname = labelname + "_Eta";
334  title = labelname + "_Eta " + trigPath;
335  v.Eta = iBooker.book1D(histoname.c_str(), title.c_str(), 60, -3.0, 3.0);
336 
337  histoname = "HLTvsRECO_Discr";
338  title = "online discr vs offline discr " + trigPath;
339  v.Discr_HLTvsRECO = iBooker.book2D(histoname.c_str(), title.c_str(), 110, -0.1, 1, 110, -0.1, 1);
340 
341  histoname = "HLTMinusRECO_Discr";
342  title = "online discr minus offline discr " + trigPath;
343  v.Discr_HLTMinusRECO = iBooker.book1D(histoname.c_str(), title.c_str(), 100, -1, 1);
344 
345  histoname = "Turnon_loose_Discr";
346  title = "turn-on with loose threshold " + trigPath;
347  v.bookME(iBooker, v.Discr_turnon_loose, histoname, title, 22, -0.1, 1.);
348 
349  histoname = "Turnon_medium_Discr";
350  title = "turn-on with medium threshold " + trigPath;
351  v.bookME(iBooker, v.Discr_turnon_medium, histoname, title, 22, -0.1, 1.);
352 
353  histoname = "Turnon_tight_Discr";
354  title = "turn-on with tight threshold " + trigPath;
355  v.bookME(iBooker, v.Discr_turnon_tight, histoname, title, 22, -0.1, 1.);
356 
357  histoname = labelname + "_PVz";
358  title = "online z(PV) " + trigPath;
359  v.PVz = iBooker.book1D(histoname.c_str(), title.c_str(), 80, -20, 20);
360 
361  histoname = labelname + "_fastPVz";
362  title = "online z(fastPV) " + trigPath;
363  v.fastPVz = iBooker.book1D(histoname.c_str(), title.c_str(), 80, -20, 20);
364 
365  histoname = "HLTMinusRECO_PVz";
366  title = "online z(PV) - offline z(PV) " + trigPath;
367  v.PVz_HLTMinusRECO = iBooker.book1D(histoname.c_str(), title.c_str(), 200, -0.5, 0.5);
368 
369  histoname = "HLTMinusRECO_fastPVz";
370  title = "online z(fastPV) - offline z(PV) " + trigPath;
371  v.fastPVz_HLTMinusRECO = iBooker.book1D(histoname.c_str(), title.c_str(), 100, -2, 2);
372 
373  histoname = "n_vtx";
374  title = "N vertex candidates " + trigPath;
375  v.n_vtx = iBooker.book1D(histoname.c_str(), title.c_str(), 10, -0.5, 9.5);
376 
377  histoname = "vtx_mass";
378  title = "secondary vertex mass (GeV)" + trigPath;
379  v.vtx_mass = iBooker.book1D(histoname.c_str(), title.c_str(), 20, 0, 10);
380 
381  histoname = "n_vtx_trks";
382  title = "N tracks associated to secondary vertex" + trigPath;
383  v.n_vtx_trks = iBooker.book1D(histoname.c_str(), title.c_str(), 20, -0.5, 19.5);
384 
385  histoname = "n_sel_tracks";
386  title = "N selected tracks" + trigPath;
387  v.n_sel_tracks = iBooker.book1D(histoname.c_str(), title.c_str(), 25, -0.5, 24.5);
388 
389  histoname = "3d_ip_distance";
390  title = "3D IP distance of tracks (cm)" + trigPath;
391  v.h_3d_ip_distance = iBooker.book1D(histoname.c_str(), title.c_str(), 40, -0.1, 0.1);
392 
393  histoname = "3d_ip_error";
394  title = "3D IP error of tracks (cm)" + trigPath;
395  v.h_3d_ip_error = iBooker.book1D(histoname.c_str(), title.c_str(), 40, 0., 0.1);
396 
397  histoname = "3d_ip_sig";
398  title = "3D IP significance of tracks (cm)" + trigPath;
399  v.h_3d_ip_sig = iBooker.book1D(histoname.c_str(), title.c_str(), 40, -40, 40);
400 
401  // histoname = "n_pixel_hits";
402  // title = "N pixel hits"+trigPath;
403  // v.n_pixel_hits = iBooker.book1D(histoname.c_str(), title.c_str(), 16, -0.5, 15.5);
404 
405  // histoname = "n_total_hits";
406  // title = "N hits"+trigPath;
407  // v.n_total_hits = iBooker.book1D(histoname.c_str(), title.c_str(), 40, -0.5, 39.5);
408  }
409 }
410 
411 // Define this as a plug-in
#define LogDebug(id)
void analyze(const edm::Event &, const edm::EventSetup &) override
RunNumber_t run() const
Definition: EventID.h:38
BTVHLTOfflineSource(const edm::ParameterSet &)
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX)
Definition: DQMStore.cc:239
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:40
T getUntrackedParameter(std::string const &, T const &) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:418
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:61
static const std::string removeVersion(const std::string &trigger)
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
~BTVHLTOfflineSource() override
bool isValid() const
Definition: HandleBase.h:70
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:30
void dqmBeginRun(edm::Run const &run, edm::EventSetup const &c) override
std::string const & label() const
Definition: InputTag.h:36
edm::EventID id() const
Definition: EventBase.h:59
fixed size matrix
HLT enums.
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Definition: DQMStore.cc:266
void bookHistograms(DQMStore::IBooker &, edm::Run const &run, edm::EventSetup const &c) override
std::string const & instance() const
Definition: InputTag.h:37
edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const override
Definition: Event.cc:265
Definition: Run.h:45