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