CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes
BTagPerformanceAnalyzerMC Class Reference

#include <BTagPerformanceAnalyzerMC.h>

Inheritance diagram for BTagPerformanceAnalyzerMC:
one::DQMEDAnalyzer< T > one::dqmimplementation::DQMBaseClass< T... >

Classes

struct  JetRefCompare
 

Public Member Functions

void analyze (const edm::Event &iEvent, const edm::EventSetup &iSetup) override
 
 BTagPerformanceAnalyzerMC (const edm::ParameterSet &pSet)
 
 ~BTagPerformanceAnalyzerMC () override
 
- Public Member Functions inherited from one::DQMEDAnalyzer< T >
 DQMEDAnalyzer ()=default
 
 DQMEDAnalyzer (DQMEDAnalyzer< T... > const &)=delete
 
 DQMEDAnalyzer (DQMEDAnalyzer< T... > &&)=delete
 
 ~DQMEDAnalyzer () override=default
 

Private Types

typedef std::map< edm::RefToBase< reco::Jet >, unsigned int, JetRefCompareFlavourMap
 
typedef std::pair< reco::Jet, reco::JetFlavourInfoJetWithFlavour
 
typedef std::map< edm::RefToBase< reco::Jet >, reco::JetFlavour::Leptons, JetRefCompareLeptonMap
 

Private Member Functions

void bookHistograms (DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
 
EtaPtBin getEtaPtBin (const int &iEta, const int &iPt)
 
bool getJetWithFlavour (const edm::Event &iEvent, edm::RefToBase< reco::Jet > caloRef, const FlavourMap &_flavours, JetWithFlavour &jetWithFlavour, const reco::JetCorrector *corrector, edm::Handle< edm::Association< reco::GenJetCollection >> genJetsMatched)
 
bool getJetWithGenJet (edm::RefToBase< reco::Jet > jetRef, edm::Handle< edm::Association< reco::GenJetCollection >> genJetsMatched)
 

Private Attributes

std::vector< std::vector< std::unique_ptr< JetTagPlotter > > > binJetTagPlotters
 
std::vector< std::vector< std::unique_ptr< TagCorrelationPlotter > > > binTagCorrelationPlotters
 
std::vector< std::vector< std::unique_ptr< BaseTagInfoPlotter > > > binTagInfoPlotters
 
edm::EDGetTokenT< reco::JetFlavourMatchingCollectioncaloJetToken
 
bool doJEC
 
bool doPUid
 
bool electronPlots
 
std::vector< double > etaRanges
 
bool eventInitialized
 
std::string flavPlots_
 
edm::InputTag genJetsMatchedSrc
 
edm::EDGetTokenT< edm::Association< reco::GenJetCollection > > genJetsMatchedToken
 
edm::EDGetTokenT< GenEventInfoProductgenToken
 
edm::EDGetTokenT< reco::JetCorrectorjecDataToken
 
edm::EDGetTokenT< reco::JetCorrectorjecMCToken
 
CorrectJet jetCorrector
 
MatchJet jetMatcher
 
edm::InputTag jetMCSrc
 
AcceptJet jetSelector
 
std::vector< edm::InputTagjetTagInputTags
 
std::vector< edm::EDGetTokenT< reco::JetTagCollection > > jetTagToken
 
edm::EDGetTokenT< reco::JetFlavourInfoMatchingCollectionjetToken
 
unsigned int mcPlots_
 
std::vector< edm::ParameterSetmoduleConfig
 
bool muonPlots
 
bool ptHatWeight
 
std::vector< double > ptRanges
 
edm::InputTag slInfoTag
 
edm::EDGetTokenT< reco::SoftLeptonTagInfoCollectionslInfoToken
 
std::vector< std::pair< edm::InputTag, edm::InputTag > > tagCorrelationInputTags
 
std::vector< std::pair< edm::EDGetTokenT< reco::JetTagCollection >, edm::EDGetTokenT< reco::JetTagCollection > > > tagCorrelationToken
 
std::vector< std::vector< edm::InputTag > > tagInfoInputTags
 
std::vector< std::vector< edm::EDGetTokenT< edm::View< reco::BaseTagInfo > > > > tagInfoToken
 
bool tauPlots
 
std::vector< std::string > tiDataFormatType
 
bool useOldFlavourTool
 

Detailed Description

Top level steering routine for b tag performance analysis.

Definition at line 27 of file BTagPerformanceAnalyzerMC.h.

Member Typedef Documentation

Definition at line 48 of file BTagPerformanceAnalyzerMC.h.

Definition at line 47 of file BTagPerformanceAnalyzerMC.h.

Definition at line 49 of file BTagPerformanceAnalyzerMC.h.

Constructor & Destructor Documentation

BTagPerformanceAnalyzerMC::BTagPerformanceAnalyzerMC ( const edm::ParameterSet pSet)
explicit

Definition at line 13 of file BTagPerformanceAnalyzerMC.cc.

References binJetTagPlotters, binTagCorrelationPlotters, binTagInfoPlotters, caloJetToken, electronPlots, etaRanges, flavPlots_, genJetsMatchedToken, genToken, edm::ParameterSet::getParameter(), jecDataToken, jecMCToken, jetMatcher, jetTagInputTags, jetTagToken, jetToken, mcPlots_, moduleConfig, muonPlots, ptRanges, MatchJet::setThreshold(), slInfoToken, tagCorrelationInputTags, tagCorrelationToken, tagInfoInputTags, tagInfoToken, tauPlots, and tiDataFormatType.

14  : jetSelector(pSet.getParameter<double>("etaMin"),
15  pSet.getParameter<double>("etaMax"),
16  pSet.getParameter<double>("ptRecJetMin"),
17  pSet.getParameter<double>("ptRecJetMax"),
18  0.0,
19  99999.0,
20  pSet.getParameter<double>("ratioMin"),
21  pSet.getParameter<double>("ratioMax"),
22  pSet.getParameter<bool>("doJetID")),
23  etaRanges(pSet.getParameter<vector<double>>("etaRanges")),
24  ptRanges(pSet.getParameter<vector<double>>("ptRanges")),
25  useOldFlavourTool(pSet.getParameter<bool>("useOldFlavourTool")),
26  doJEC(pSet.getParameter<bool>("doJEC")),
27  ptHatWeight(pSet.getParameter<bool>("applyPtHatWeight")),
28  moduleConfig(pSet.getParameter<vector<edm::ParameterSet>>("tagConfig")),
29  flavPlots_(pSet.getParameter<std::string>("flavPlots")),
30  jetMatcher(pSet.getParameter<edm::ParameterSet>("recJetMatching")),
31  doPUid(pSet.getParameter<bool>("doPUid")) {
32  // mcPlots_ : 1=b+c+l+ni; 2=all+1; 3=1+d+u+s+g; 4=3+all . Default is 2. Don't
33  // use 0.
34  if (flavPlots_.find("dusg") < 15) {
35  if (flavPlots_.find("all") < 15)
36  mcPlots_ = 4;
37  else
38  mcPlots_ = 3;
39  } else {
40  if (flavPlots_.find("all") < 15)
41  mcPlots_ = 2;
42  else
43  mcPlots_ = 1;
44  }
45  double ptRecJetMin = pSet.getParameter<double>("ptRecJetMin");
46  jetMatcher.setThreshold(0.25 * ptRecJetMin);
47  switch (pSet.getParameter<unsigned int>("leptonPlots")) {
48  case 11:
49  electronPlots = true;
50  muonPlots = false;
51  tauPlots = false;
52  break;
53  case 13:
54  muonPlots = true;
55  electronPlots = false;
56  tauPlots = false;
57  break;
58  case 15:
59  tauPlots = true;
60  electronPlots = false;
61  tauPlots = false;
62  break;
63  default:
64  electronPlots = false;
65  muonPlots = false;
66  tauPlots = false;
67  }
68 
69  if (etaRanges.size() <= 1)
70  etaRanges = {pSet.getParameter<double>("etaMin"), pSet.getParameter<double>("etaMax")};
71  if (ptRanges.size() <= 1)
72  ptRanges = {pSet.getParameter<double>("ptRecJetMin"), pSet.getParameter<double>("ptRecJetMax")};
73 
74  genToken = mayConsume<GenEventInfoProduct>(edm::InputTag("generator"));
76  mayConsume<edm::Association<reco::GenJetCollection>>(pSet.getParameter<InputTag>("genJetsMatched"));
77  jetToken = consumes<JetFlavourInfoMatchingCollection>(pSet.getParameter<InputTag>("jetMCSrc"));
78  caloJetToken = mayConsume<JetFlavourMatchingCollection>(pSet.getParameter<InputTag>("caloJetMCSrc"));
79  slInfoToken = consumes<SoftLeptonTagInfoCollection>(pSet.getParameter<InputTag>("softLeptonInfo"));
80  jecMCToken = consumes<JetCorrector>(pSet.getParameter<edm::InputTag>("JECsourceMC"));
81  jecDataToken = mayConsume<JetCorrector>(pSet.getParameter<edm::InputTag>("JECsourceData"));
82 
83  for (vector<edm::ParameterSet>::const_iterator iModule = moduleConfig.begin(); iModule != moduleConfig.end();
84  ++iModule) {
85  const string &dataFormatType = iModule->exists("type") ? iModule->getParameter<string>("type") : "JetTag";
86  if (dataFormatType == "JetTag") {
87  const InputTag &moduleLabel = iModule->getParameter<InputTag>("label");
88  jetTagInputTags.push_back(moduleLabel);
89  binJetTagPlotters.push_back(vector<std::unique_ptr<JetTagPlotter>>());
90  jetTagToken.push_back(consumes<JetTagCollection>(moduleLabel));
91  } else if (dataFormatType == "TagCorrelation") {
92  const InputTag &label1 = iModule->getParameter<InputTag>("label1");
93  const InputTag &label2 = iModule->getParameter<InputTag>("label2");
94  tagCorrelationInputTags.push_back(std::pair<edm::InputTag, edm::InputTag>(label1, label2));
95  binTagCorrelationPlotters.push_back(vector<std::unique_ptr<TagCorrelationPlotter>>());
96  tagCorrelationToken.push_back(
98  consumes<JetTagCollection>(label1), consumes<JetTagCollection>(label2)));
99  } else {
100  vector<edm::InputTag> vIP;
101  tiDataFormatType.push_back(dataFormatType);
102  binTagInfoPlotters.push_back(vector<std::unique_ptr<BaseTagInfoPlotter>>());
103  std::vector<edm::EDGetTokenT<edm::View<reco::BaseTagInfo>>> tokens;
104  if (dataFormatType == "GenericMVA") {
105  const std::vector<InputTag> listInfo = iModule->getParameter<vector<InputTag>>("listTagInfos");
106  for (unsigned int ITi = 0; ITi < listInfo.size(); ITi++) {
107  tokens.push_back(consumes<View<BaseTagInfo>>(listInfo[ITi]));
108  vIP.push_back(listInfo[ITi]);
109  }
110  } else {
111  const InputTag &moduleLabel = iModule->getParameter<InputTag>("label");
112  tokens.push_back(consumes<View<BaseTagInfo>>(moduleLabel));
113  vIP.push_back(moduleLabel);
114  }
115  tagInfoToken.push_back(tokens);
116  tagInfoInputTags.push_back(vIP);
117  }
118  }
119 }
T getParameter(std::string const &) const
edm::EDGetTokenT< edm::Association< reco::GenJetCollection > > genJetsMatchedToken
std::vector< edm::EDGetTokenT< reco::JetTagCollection > > jetTagToken
void setThreshold(const double &energy)
Definition: MatchJet.h:25
edm::EDGetTokenT< reco::JetCorrector > jecMCToken
std::vector< std::pair< edm::InputTag, edm::InputTag > > tagCorrelationInputTags
std::vector< std::pair< edm::EDGetTokenT< reco::JetTagCollection >, edm::EDGetTokenT< reco::JetTagCollection > > > tagCorrelationToken
edm::EDGetTokenT< GenEventInfoProduct > genToken
edm::EDGetTokenT< reco::JetFlavourMatchingCollection > caloJetToken
std::vector< std::vector< std::unique_ptr< TagCorrelationPlotter > > > binTagCorrelationPlotters
std::vector< std::vector< std::unique_ptr< BaseTagInfoPlotter > > > binTagInfoPlotters
edm::EDGetTokenT< reco::JetFlavourInfoMatchingCollection > jetToken
edm::EDGetTokenT< reco::JetCorrector > jecDataToken
std::vector< std::vector< edm::EDGetTokenT< edm::View< reco::BaseTagInfo > > > > tagInfoToken
std::vector< edm::ParameterSet > moduleConfig
std::vector< std::string > tiDataFormatType
edm::EDGetTokenT< reco::SoftLeptonTagInfoCollection > slInfoToken
std::vector< std::vector< edm::InputTag > > tagInfoInputTags
std::vector< edm::InputTag > jetTagInputTags
std::vector< std::vector< std::unique_ptr< JetTagPlotter > > > binJetTagPlotters
BTagPerformanceAnalyzerMC::~BTagPerformanceAnalyzerMC ( )
override

Definition at line 251 of file BTagPerformanceAnalyzerMC.cc.

251 {}

Member Function Documentation

void BTagPerformanceAnalyzerMC::analyze ( const edm::Event iEvent,
const edm::EventSetup iSetup 
)
override

needed for lepton specific plots

needed for lepton specific plots

Definition at line 253 of file BTagPerformanceAnalyzerMC.cc.

References funct::abs(), edm::AssociationVector< KeyRefProd, CVal, KeyRef, SizeType, KeyReferenceHelper >::begin(), binJetTagPlotters, binTagCorrelationPlotters, binTagInfoPlotters, caloJetToken, mitigatedMETSequence_cff::corrector, PFTauDiscriminatorLogicalAndProducer_cfi::discr2, doJEC, doPUid, reco::JetFlavour::Leptons::electron, metsig::electron, electronPlots, edm::AssociationVector< KeyRefProd, CVal, KeyRef, SizeType, KeyReferenceHelper >::end(), eventInitialized, Exception, bTagAnalysis_cfi::genJetsMatched, genJetsMatchedToken, genToken, edm::Event::getByToken(), getJetWithFlavour(), mps_fire::i, edm::ProductID::id(), edm::HandleBase::isValid(), patTestJEC_cfi::jec, jecDataToken, jecMCToken, reco::BaseTagInfo::jet(), jets_cff::jetMC, jetSelector, jetTagInputTags, jetTagToken, jetToken, tablePrinter::labels, AK4GenJetFlavourInfos_cfi::leptons, LogDebug, reco::JetFlavour::Leptons::muon, muonPlots, common_cff::pdgId, edm::Handle< T >::product(), ptHatWeight, edm::AssociationVector< KeyRefProd, CVal, KeyRef, SizeType, KeyReferenceHelper >::size(), edm::RefVector< C, T, F >::size(), findQualityFiles::size, slInfoToken, tagCorrelationInputTags, tagCorrelationToken, tagInfoInputTags, tagInfoToken, reco::JetFlavour::Leptons::tau, metsig::tau, tauPlots, tiDataFormatType, useOldFlavourTool, GenEventInfoProduct::weight(), and mps_merge::weight.

253  {
254  eventInitialized = false;
255 
256  float weight = 1; // event weight
257 
258  if (ptHatWeight) {
259  /* APPLY PTHAT EVENT WEIGHT */
260 
261  edm::Handle<GenEventInfoProduct> genInfoHandle;
262  iEvent.getByToken(genToken, genInfoHandle);
263 
264  if (genInfoHandle.isValid()) {
265  weight = weight * static_cast<float>(genInfoHandle->weight());
266  }
267  }
268 
269  LogDebug("Info") << "Event weight is: " << weight;
270 
271  FlavourMap flavours;
273 
274  if (!useOldFlavourTool) {
276  iEvent.getByToken(jetToken, jetMC);
277  for (JetFlavourInfoMatchingCollection::const_iterator iter = jetMC->begin(); iter != jetMC->end(); ++iter) {
278  unsigned int fl = std::abs(iter->second.getPartonFlavour());
279  flavours.insert(std::make_pair(iter->first, fl));
280  const GenParticleRefVector &lep = iter->second.getLeptons();
281  reco::JetFlavour::Leptons lepCount;
282  for (unsigned int i = 0; i < lep.size(); i++) {
283  if (abs(lep[i]->pdgId()) == 11)
284  lepCount.electron++;
285  else if (abs(lep[i]->pdgId()) == 13)
286  lepCount.muon++;
287  else if (abs(lep[i]->pdgId()) == 15)
288  lepCount.tau++;
289  }
290  leptons.insert(std::make_pair(iter->first, lepCount));
291  }
292  } else {
294  iEvent.getByToken(caloJetToken, jetMC);
295  for (JetFlavourMatchingCollection::const_iterator iter = jetMC->begin(); iter != jetMC->end(); ++iter) {
296  unsigned int fl = std::abs(iter->second.getFlavour());
297  flavours.insert(std::make_pair(iter->first, fl));
298  const reco::JetFlavour::Leptons &lep = iter->second.getLeptons();
299  leptons.insert(std::make_pair(iter->first, lep));
300  }
301  }
302 
304  iEvent.getByToken(slInfoToken, infoHandle);
305 
307  if (doPUid) {
308  iEvent.getByToken(genJetsMatchedToken, genJetsMatched);
309  }
310 
311  // Get JEC
312  const JetCorrector *corrector = nullptr;
313  if (doJEC) {
314  edm::Handle<GenEventInfoProduct> genInfoHandle; // check if data or MC
315  iEvent.getByToken(genToken, genInfoHandle);
316  edm::Handle<JetCorrector> corrHandle;
317  if (!genInfoHandle.isValid())
318  iEvent.getByToken(jecDataToken, corrHandle);
319  else
320  iEvent.getByToken(jecMCToken, corrHandle);
321  corrector = corrHandle.product();
322  }
323  //
324 
325  // Look first at the jetTags
326  for (unsigned int iJetLabel = 0; iJetLabel != jetTagInputTags.size(); ++iJetLabel) {
328  iEvent.getByToken(jetTagToken[iJetLabel], tagHandle);
329  const reco::JetTagCollection &tagColl = *(tagHandle.product());
330  LogDebug("Info") << "Found " << tagColl.size() << " B candidates in collection " << jetTagInputTags[iJetLabel];
331 
332  int plotterSize = binJetTagPlotters[iJetLabel].size();
333  for (JetTagCollection::const_iterator tagI = tagColl.begin(); tagI != tagColl.end(); ++tagI) {
334  // Identify parton associated to jet.
335 
337  if (flavours[tagI->first] == 5 &&
338  ((electronPlots && !leptons[tagI->first].electron) || (muonPlots && !leptons[tagI->first].muon) ||
339  (tauPlots && !leptons[tagI->first].tau)))
340  continue;
341  // JEC
342  double jec = 1.0;
343  /*reco::Jet correctedJet = *(tagI->first);
344  if(doJEC && corrector) {
345  jec = corrector->correction(*(tagI->first));
346  }*/
347 
348  JetWithFlavour jetWithFlavour;
349  // also applies JEC to jet
350  if (!getJetWithFlavour(iEvent, tagI->first, flavours, jetWithFlavour, corrector, genJetsMatched))
351  continue;
352  if (!jetSelector(jetWithFlavour.first, std::abs(jetWithFlavour.second.getPartonFlavour()), infoHandle, jec))
353  continue;
354 
355  for (int iPlotter = 0; iPlotter != plotterSize; ++iPlotter) {
356  bool inBin = false;
357  inBin = binJetTagPlotters[iJetLabel][iPlotter]->etaPtBin().inBin(jetWithFlavour.first, jec);
358  // Fill histograms if in desired pt/rapidity bin.
359  if (inBin)
360  binJetTagPlotters[iJetLabel][iPlotter]->analyzeTag(
361  jetWithFlavour.first, jec, tagI->second, std::abs(jetWithFlavour.second.getPartonFlavour()), weight);
362  }
363  }
364  for (int iPlotter = 0; iPlotter != plotterSize; ++iPlotter) {
365  binJetTagPlotters[iJetLabel][iPlotter]->analyzeTag(weight);
366  }
367  }
368 
369  // Now look at Tag Correlations
370  for (unsigned int iJetLabel = 0; iJetLabel != tagCorrelationInputTags.size(); ++iJetLabel) {
371  const std::pair<edm::EDGetTokenT<reco::JetTagCollection>, edm::EDGetTokenT<reco::JetTagCollection>> &inputTokens =
372  tagCorrelationToken[iJetLabel];
374  iEvent.getByToken(inputTokens.first, tagHandle1);
375  const reco::JetTagCollection &tagColl1 = *(tagHandle1.product());
376 
378  iEvent.getByToken(inputTokens.second, tagHandle2);
379  const reco::JetTagCollection &tagColl2 = *(tagHandle2.product());
380 
381  int plotterSize = binTagCorrelationPlotters[iJetLabel].size();
382  for (JetTagCollection::const_iterator tagI = tagColl1.begin(); tagI != tagColl1.end(); ++tagI) {
383  if (flavours[tagI->first] == 5 &&
384  ((electronPlots && !leptons[tagI->first].electron) || (muonPlots && !leptons[tagI->first].muon) ||
385  (tauPlots && !leptons[tagI->first].tau)))
386  continue;
387 
388  // JEC
389  double jec = 1.0;
390  /*reco::Jet correctedJet = *(tagI->first);
391  if(doJEC && corrector) {
392  jec = corrector->correction(*(tagI->first));
393  }*/
394 
395  JetWithFlavour jetWithFlavour;
396  // also applies JEC to jet
397  if (!getJetWithFlavour(iEvent, tagI->first, flavours, jetWithFlavour, corrector, genJetsMatched))
398  continue;
399  if (!jetSelector(jetWithFlavour.first, std::abs(jetWithFlavour.second.getPartonFlavour()), infoHandle, jec))
400  continue;
401 
402  for (int iPlotter = 0; iPlotter != plotterSize; ++iPlotter) {
403  bool inBin = false;
404  inBin = binTagCorrelationPlotters[iJetLabel][iPlotter]->etaPtBin().inBin(jetWithFlavour.first, jec);
405 
406  if (inBin) {
407  double discr2 = tagColl2[tagI->first];
408  binTagCorrelationPlotters[iJetLabel][iPlotter]->analyzeTags(
409  tagI->second, discr2, std::abs(jetWithFlavour.second.getPartonFlavour()), weight);
410  }
411  }
412  }
413  }
414 
415  // Now look at the TagInfos
416 
417  for (unsigned int iJetLabel = 0; iJetLabel != tiDataFormatType.size(); ++iJetLabel) {
418  int plotterSize = binTagInfoPlotters[iJetLabel].size();
419  for (int iPlotter = 0; iPlotter != plotterSize; ++iPlotter)
420  binTagInfoPlotters[iJetLabel][iPlotter]->setEventSetup(iSetup);
421 
422  vector<edm::EDGetTokenT<edm::View<reco::BaseTagInfo>>> &tokens = tagInfoToken[iJetLabel];
423  // check number of tag infos = expected number of tag infos
424  vector<string> labels = binTagInfoPlotters[iJetLabel][0]->tagInfoRequirements();
425  if (labels.empty())
426  labels.push_back("label");
427  if (labels.size() != tokens.size())
428  throw cms::Exception("Configuration")
429  << "Different number of Tag Infos than expected" << labels.size() << tokens.size() << endl;
430 
431  unsigned int nInputTags = tokens.size();
432  vector<edm::Handle<View<BaseTagInfo>>> tagInfoHandles(nInputTags);
433  edm::ProductID jetProductID;
434  unsigned int nTagInfos = 0;
435  for (unsigned int iInputTags = 0; iInputTags < tokens.size(); ++iInputTags) {
436  edm::Handle<View<BaseTagInfo>> &tagInfoHandle = tagInfoHandles[iInputTags];
437  iEvent.getByToken(tokens[iInputTags], tagInfoHandle);
438  if (tagInfoHandle.isValid() == false) {
439  edm::LogWarning("BTagPerformanceAnalyzerMC")
440  << " Collection " << tagInfoInputTags[iJetLabel][iInputTags] << " not present. Skipping it for this event.";
441  continue;
442  }
443 
444  unsigned int size = tagInfoHandle->size();
445  LogDebug("Info") << "Found " << size << " B candidates in collection " << tagInfoInputTags[iJetLabel][iInputTags];
446  edm::ProductID thisProductID = (size > 0) ? (*tagInfoHandle)[0].jet().id() : edm::ProductID();
447  if (iInputTags == 0) {
448  jetProductID = thisProductID;
449  nTagInfos = size;
450  } else if (jetProductID != thisProductID)
451  throw cms::Exception("Configuration") << "TagInfos are referencing a different jet collection." << endl;
452  else if (nTagInfos != size)
453  throw cms::Exception("Configuration") << "TagInfo collections are having a different size." << endl;
454  }
455 
456  for (unsigned int iTagInfos = 0; iTagInfos < nTagInfos; ++iTagInfos) {
457  vector<const BaseTagInfo *> baseTagInfos(nInputTags);
458  edm::RefToBase<Jet> jetRef;
459  for (unsigned int iTagInfo = 0; iTagInfo < nInputTags; iTagInfo++) {
460  const BaseTagInfo &baseTagInfo = (*tagInfoHandles[iTagInfo])[iTagInfos];
461  if (iTagInfo == 0)
462  jetRef = baseTagInfo.jet();
463  else if (baseTagInfo.jet() != jetRef)
464  throw cms::Exception("Configuration") << "TagInfos pointing to different jets." << endl;
465  baseTagInfos[iTagInfo] = &baseTagInfo;
466  }
467 
468  // Identify parton associated to jet.
469 
471  if (flavours[jetRef] == 5 && ((electronPlots && !leptons[jetRef].electron) ||
472  (muonPlots && !leptons[jetRef].muon) || (tauPlots && !leptons[jetRef].tau)))
473  continue;
474 
475  // JEC
476  double jec = 1.0;
477  /*reco::Jet correctedJet = *(jetRef);
478  if(doJEC && corrector) {
479  jec = corrector->correction(*(jetRef));
480  }*/
481 
482  JetWithFlavour jetWithFlavour;
483  // also applies JEC to jet
484  if (!getJetWithFlavour(iEvent, jetRef, flavours, jetWithFlavour, corrector, genJetsMatched))
485  continue;
486  if (!jetSelector(jetWithFlavour.first, std::abs(jetWithFlavour.second.getPartonFlavour()), infoHandle, jec))
487  continue;
488 
489  for (int iPlotter = 0; iPlotter != plotterSize; ++iPlotter) {
490  bool inBin = false;
491  inBin = binTagInfoPlotters[iJetLabel][iPlotter]->etaPtBin().inBin(*jetRef, jec);
492  // Fill histograms if in desired pt/rapidity bin.
493  if (inBin)
494  binTagInfoPlotters[iJetLabel][iPlotter]->analyzeTag(
495  baseTagInfos, jec, std::abs(jetWithFlavour.second.getPartonFlavour()), weight);
496  }
497  }
498  }
499 }
#define LogDebug(id)
size
Write out results.
transient_vector_type::const_iterator const_iterator
edm::EDGetTokenT< edm::Association< reco::GenJetCollection > > genJetsMatchedToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
std::vector< edm::EDGetTokenT< reco::JetTagCollection > > jetTagToken
edm::EDGetTokenT< reco::JetCorrector > jecMCToken
std::map< edm::RefToBase< reco::Jet >, unsigned int, JetRefCompare > FlavourMap
std::map< edm::RefToBase< reco::Jet >, reco::JetFlavour::Leptons, JetRefCompare > LeptonMap
const_iterator end() const
std::vector< std::pair< edm::InputTag, edm::InputTag > > tagCorrelationInputTags
std::vector< std::pair< edm::EDGetTokenT< reco::JetTagCollection >, edm::EDGetTokenT< reco::JetTagCollection > > > tagCorrelationToken
Definition: weight.py:1
double weight() const
edm::EDGetTokenT< GenEventInfoProduct > genToken
std::pair< Jet, reco::JetFlavourInfo > JetWithFlavour
virtual edm::RefToBase< Jet > jet(void) const
returns a polymorphic reference to the tagged jet
Definition: BaseTagInfo.h:24
edm::EDGetTokenT< reco::JetFlavourMatchingCollection > caloJetToken
std::vector< std::vector< std::unique_ptr< TagCorrelationPlotter > > > binTagCorrelationPlotters
std::vector< std::vector< std::unique_ptr< BaseTagInfoPlotter > > > binTagInfoPlotters
edm::EDGetTokenT< reco::JetFlavourInfoMatchingCollection > jetToken
edm::EDGetTokenT< reco::JetCorrector > jecDataToken
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< std::vector< edm::EDGetTokenT< edm::View< reco::BaseTagInfo > > > > tagInfoToken
bool isValid() const
Definition: HandleBase.h:74
lepton info struct
Definition: JetFlavour.h:23
T const * product() const
Definition: Handle.h:74
std::vector< std::string > tiDataFormatType
edm::EDGetTokenT< reco::SoftLeptonTagInfoCollection > slInfoToken
std::vector< std::vector< edm::InputTag > > tagInfoInputTags
std::vector< edm::InputTag > jetTagInputTags
size_type size() const
Size of the RefVector.
Definition: RefVector.h:107
ProductIndex id() const
Definition: ProductID.h:38
std::vector< std::vector< std::unique_ptr< JetTagPlotter > > > binJetTagPlotters
const_iterator begin() const
bool getJetWithFlavour(const edm::Event &iEvent, edm::RefToBase< reco::Jet > caloRef, const FlavourMap &_flavours, JetWithFlavour &jetWithFlavour, const reco::JetCorrector *corrector, edm::Handle< edm::Association< reco::GenJetCollection >> genJetsMatched)
size_type size() const
void BTagPerformanceAnalyzerMC::bookHistograms ( DQMStore::IBooker ibook,
edm::Run const &  run,
edm::EventSetup const &  es 
)
overrideprivate

Definition at line 121 of file BTagPerformanceAnalyzerMC.cc.

References binJetTagPlotters, binTagCorrelationPlotters, binTagInfoPlotters, TagInfoPlotterFactory::buildPlotter(), etaRanges, getEtaPtBin(), edm::InputTag::label(), mcPlots_, moduleConfig, ptRanges, and plotscripts::setTDRStyle().

Referenced by BTagPerformanceAnalyzerMC::JetRefCompare::operator()().

123  {
124  //
125  // Book all histograms.
126  //
127 
128  // iterate over ranges:
129  const int iEtaStart = -1; // this will be the inactive one
130  const int iEtaEnd = etaRanges.size() > 2 ? etaRanges.size() - 1
131  : 0; // if there is only one bin defined, leave it as the inactive one
132  const int iPtStart = -1; // this will be the inactive one
133  const int iPtEnd =
134  ptRanges.size() > 2 ? ptRanges.size() - 1 : 0; // if there is only one bin defined, leave it as the inactive one
135 
136  setTDRStyle();
137 
138  TagInfoPlotterFactory theFactory;
139  int iTag = -1;
140  int iTagCorr = -1;
141  int iInfoTag = -1;
142  for (vector<edm::ParameterSet>::const_iterator iModule = moduleConfig.begin(); iModule != moduleConfig.end();
143  ++iModule) {
144  const string &dataFormatType = iModule->exists("type") ? iModule->getParameter<string>("type") : "JetTag";
145  if (dataFormatType == "JetTag") {
146  iTag++;
147  const string &folderName = iModule->getParameter<string>("folder");
148 
149  bool doDifferentialPlots = false;
150  double discrCut = -999.;
151  if (iModule->exists("differentialPlots") && iModule->getParameter<bool>("differentialPlots") == true) {
152  doDifferentialPlots = true;
153  discrCut = iModule->getParameter<double>("discrCut");
154  }
155 
156  // eta loop
157  for (int iEta = iEtaStart; iEta < iEtaEnd; iEta++) {
158  // pt loop
159  for (int iPt = iPtStart; iPt < iPtEnd; iPt++) {
160  const EtaPtBin &etaPtBin = getEtaPtBin(iEta, iPt);
161 
162  // Instantiate the genertic b tag plotter
163  binJetTagPlotters.at(iTag).push_back(
164  std::make_unique<JetTagPlotter>(folderName,
165  etaPtBin,
166  iModule->getParameter<edm::ParameterSet>("parameters"),
167  mcPlots_,
168  false,
169  ibook,
170  false,
171  doDifferentialPlots,
172  discrCut));
173  }
174  }
175  } else if (dataFormatType == "TagCorrelation") {
176  iTagCorr++;
177  const InputTag &label1 = iModule->getParameter<InputTag>("label1");
178  const InputTag &label2 = iModule->getParameter<InputTag>("label2");
179 
180  // eta loop
181  for (int iEta = iEtaStart; iEta != iEtaEnd; ++iEta) {
182  // pt loop
183  for (int iPt = iPtStart; iPt != iPtEnd; ++iPt) {
184  const EtaPtBin &etaPtBin = getEtaPtBin(iEta, iPt);
185  // Instantiate the generic b tag correlation plotter
186  binTagCorrelationPlotters.at(iTagCorr).push_back(
187  std::make_unique<TagCorrelationPlotter>(label1.label(),
188  label2.label(),
189  etaPtBin,
190  iModule->getParameter<edm::ParameterSet>("parameters"),
191  mcPlots_,
192  false,
193  false,
194  ibook));
195  }
196  }
197  } else {
198  iInfoTag++;
199  // tag info retrievel is deferred (needs availability of EventSetup)
200  const InputTag &moduleLabel = iModule->getParameter<InputTag>("label");
201  const string &folderName = iModule->getParameter<string>("folder");
202  // eta loop
203  for (int iEta = iEtaStart; iEta < iEtaEnd; iEta++) {
204  // pt loop
205  for (int iPt = iPtStart; iPt < iPtEnd; iPt++) {
206  const EtaPtBin &etaPtBin = getEtaPtBin(iEta, iPt);
207 
208  // Instantiate the tagInfo plotter
209  binTagInfoPlotters.at(iInfoTag).push_back(
210  theFactory.buildPlotter(dataFormatType,
211  moduleLabel.label(),
212  etaPtBin,
213  iModule->getParameter<edm::ParameterSet>("parameters"),
214  folderName,
215  mcPlots_,
216  false,
217  ibook));
218  }
219  }
220  }
221  }
222 }
std::vector< std::vector< std::unique_ptr< TagCorrelationPlotter > > > binTagCorrelationPlotters
std::vector< std::vector< std::unique_ptr< BaseTagInfoPlotter > > > binTagInfoPlotters
def setTDRStyle()
Definition: plotscripts.py:89
std::vector< edm::ParameterSet > moduleConfig
EtaPtBin getEtaPtBin(const int &iEta, const int &iPt)
std::string const & label() const
Definition: InputTag.h:36
std::vector< std::vector< std::unique_ptr< JetTagPlotter > > > binJetTagPlotters
std::unique_ptr< BaseTagInfoPlotter > buildPlotter(const std::string &dataFormatType, const std::string &tagName, const EtaPtBin &etaPtBin, const edm::ParameterSet &pSet, const std::string &folderName, unsigned int mc, bool wf, DQMStore::IBooker &ibook)
EtaPtBin BTagPerformanceAnalyzerMC::getEtaPtBin ( const int &  iEta,
const int &  iPt 
)
private

Definition at line 224 of file BTagPerformanceAnalyzerMC.cc.

References histoStyle::EtaPtBin, etaRanges, and ptRanges.

Referenced by bookHistograms(), and BTagPerformanceAnalyzerMC::JetRefCompare::operator()().

224  {
225  // DEFINE BTagBin:
226  bool etaActive_, ptActive_;
227  double etaMin_, etaMax_, ptMin_, ptMax_;
228 
229  if (iEta != -1) {
230  etaActive_ = true;
231  etaMin_ = etaRanges[iEta];
232  etaMax_ = etaRanges[iEta + 1];
233  } else {
234  etaActive_ = false;
235  etaMin_ = etaRanges[0];
236  etaMax_ = etaRanges[etaRanges.size() - 1];
237  }
238 
239  if (iPt != -1) {
240  ptActive_ = true;
241  ptMin_ = ptRanges[iPt];
242  ptMax_ = ptRanges[iPt + 1];
243  } else {
244  ptActive_ = false;
245  ptMin_ = ptRanges[0];
246  ptMax_ = ptRanges[ptRanges.size() - 1];
247  }
248  return EtaPtBin(etaActive_, etaMin_, etaMax_, ptActive_, ptMin_, ptMax_);
249 }
bool BTagPerformanceAnalyzerMC::getJetWithFlavour ( const edm::Event iEvent,
edm::RefToBase< reco::Jet caloRef,
const FlavourMap _flavours,
JetWithFlavour jetWithFlavour,
const reco::JetCorrector corrector,
edm::Handle< edm::Association< reco::GenJetCollection >>  genJetsMatched 
)
private

Definition at line 511 of file BTagPerformanceAnalyzerMC.cc.

References DEFINE_FWK_MODULE, doPUid, eventInitialized, GenHFHadronMatcher_cff::flavour, bTagAnalysis_cfi::genJetsMatched, getJetWithGenJet(), mps_fire::i, edm::ProductID::id(), edm::RefToBase< T >::id(), edm::RefToBase< T >::isNull(), jetCorrector, jetMatcher, LogTrace, edm::makeRefToBaseProdFrom(), MatchJet::matchCollections(), edm::RefToBaseVector< T >::push_back(), CorrectJet::setCorrector(), and edm::View< T >::size().

Referenced by analyze().

516  {
517  edm::ProductID recProdId = jetRef.id();
518  edm::ProductID refProdId = (flavours.begin() == flavours.end()) ? recProdId : flavours.begin()->first.id();
519 
520  if (!eventInitialized) {
521  jetCorrector.setCorrector(corrector);
522  if (recProdId != refProdId) {
524  for (FlavourMap::const_iterator iter = flavours.begin(); iter != flavours.end(); ++iter)
525  refJets.push_back(iter->first);
526  const edm::RefToBaseProd<Jet> recJetsProd(edm::makeRefToBaseProdFrom(jetRef, iEvent));
528  for (unsigned int i = 0; i < recJetsProd->size(); i++)
529  recJets.push_back(edm::RefToBase<Jet>(recJetsProd, i));
530  jetMatcher.matchCollections(refJets, recJets, corrector);
531  }
532  eventInitialized = true;
533  }
534 
535  if (recProdId != refProdId) {
536  jetRef = jetMatcher(jetRef);
537  if (jetRef.isNull())
538  return false;
539  }
540 
541  // apply JEC
542  jetWithFlavour.first = jetCorrector(*jetRef);
543 
544  auto itFound = flavours.find(jetRef);
545  unsigned int flavour = itFound != flavours.end() ? itFound->second : 0;
546 
547  if (doPUid) {
548  bool isNotPU = getJetWithGenJet(jetRef, genJetsMatched);
549  if (!isNotPU)
550  flavour = 20;
551  }
552 
553  jetWithFlavour.second = reco::JetFlavourInfo(flavour, flavour);
554 
555  LogTrace("Info") << "Found jet with flavour " << jetWithFlavour.second.getPartonFlavour() << endl;
556  LogTrace("Info") << jetWithFlavour.first.p() << " , " << jetWithFlavour.first.pt() << " - " << endl;
557  //<< jetWithFlavour.second.getLorentzVector().P()<<" , "<<
558  // jetWithFlavour.second.getLorentzVector().Pt()<<endl;
559 
560  return true;
561 }
void matchCollections(const edm::RefToBaseVector< reco::Jet > &refJets, const edm::RefToBaseVector< reco::Jet > &recJets, const reco::JetCorrector *corrector)
match the collections
Definition: MatchJet.cc:28
bool getJetWithGenJet(edm::RefToBase< reco::Jet > jetRef, edm::Handle< edm::Association< reco::GenJetCollection >> genJetsMatched)
Class storing the jet flavour information.
#define LogTrace(id)
void setCorrector(const reco::JetCorrector *corrector)
Returns the corrected jet.
Definition: CorrectJet.h:22
RefToBaseProd< T > makeRefToBaseProdFrom(RefToBase< T > const &iRef, Event const &iEvent)
void push_back(const RefToBase< T > &)
ProductIndex id() const
Definition: ProductID.h:38
bool BTagPerformanceAnalyzerMC::getJetWithGenJet ( edm::RefToBase< reco::Jet jetRef,
edm::Handle< edm::Association< reco::GenJetCollection >>  genJetsMatched 
)
private

Definition at line 501 of file BTagPerformanceAnalyzerMC.cc.

References doPUid, edm::Ref< C, T, F >::isAvailable(), and edm::Ref< C, T, F >::isNonnull().

Referenced by getJetWithFlavour().

502  {
503  if (!doPUid)
504  return true;
505  reco::GenJetRef genjet = (*genJetsMatched)[jetRef];
506  if (genjet.isNonnull() && genjet.isAvailable())
507  return true;
508  return false;
509 }
bool isAvailable() const
Definition: Ref.h:575
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:251

Member Data Documentation

std::vector<std::vector<std::unique_ptr<JetTagPlotter> > > BTagPerformanceAnalyzerMC::binJetTagPlotters
private

Definition at line 72 of file BTagPerformanceAnalyzerMC.h.

Referenced by analyze(), bookHistograms(), and BTagPerformanceAnalyzerMC().

std::vector<std::vector<std::unique_ptr<TagCorrelationPlotter> > > BTagPerformanceAnalyzerMC::binTagCorrelationPlotters
private

Definition at line 73 of file BTagPerformanceAnalyzerMC.h.

Referenced by analyze(), bookHistograms(), and BTagPerformanceAnalyzerMC().

std::vector<std::vector<std::unique_ptr<BaseTagInfoPlotter> > > BTagPerformanceAnalyzerMC::binTagInfoPlotters
private

Definition at line 74 of file BTagPerformanceAnalyzerMC.h.

Referenced by analyze(), bookHistograms(), and BTagPerformanceAnalyzerMC().

edm::EDGetTokenT<reco::JetFlavourMatchingCollection> BTagPerformanceAnalyzerMC::caloJetToken
private

Definition at line 97 of file BTagPerformanceAnalyzerMC.h.

Referenced by analyze(), and BTagPerformanceAnalyzerMC().

bool BTagPerformanceAnalyzerMC::doJEC
private

Definition at line 64 of file BTagPerformanceAnalyzerMC.h.

Referenced by analyze().

bool BTagPerformanceAnalyzerMC::doPUid
private

Definition at line 87 of file BTagPerformanceAnalyzerMC.h.

Referenced by analyze(), getJetWithFlavour(), and getJetWithGenJet().

bool BTagPerformanceAnalyzerMC::electronPlots
private

Definition at line 89 of file BTagPerformanceAnalyzerMC.h.

Referenced by analyze(), and BTagPerformanceAnalyzerMC().

std::vector<double> BTagPerformanceAnalyzerMC::etaRanges
private
bool BTagPerformanceAnalyzerMC::eventInitialized
private

Definition at line 88 of file BTagPerformanceAnalyzerMC.h.

Referenced by analyze(), and getJetWithFlavour().

std::string BTagPerformanceAnalyzerMC::flavPlots_
private

Definition at line 81 of file BTagPerformanceAnalyzerMC.h.

Referenced by BTagPerformanceAnalyzerMC().

edm::InputTag BTagPerformanceAnalyzerMC::genJetsMatchedSrc
private

Definition at line 70 of file BTagPerformanceAnalyzerMC.h.

edm::EDGetTokenT<edm::Association<reco::GenJetCollection> > BTagPerformanceAnalyzerMC::genJetsMatchedToken
private

Definition at line 93 of file BTagPerformanceAnalyzerMC.h.

Referenced by analyze(), and BTagPerformanceAnalyzerMC().

edm::EDGetTokenT<GenEventInfoProduct> BTagPerformanceAnalyzerMC::genToken
private

Definition at line 92 of file BTagPerformanceAnalyzerMC.h.

Referenced by analyze(), and BTagPerformanceAnalyzerMC().

edm::EDGetTokenT<reco::JetCorrector> BTagPerformanceAnalyzerMC::jecDataToken
private

Definition at line 95 of file BTagPerformanceAnalyzerMC.h.

Referenced by analyze(), and BTagPerformanceAnalyzerMC().

edm::EDGetTokenT<reco::JetCorrector> BTagPerformanceAnalyzerMC::jecMCToken
private

Definition at line 94 of file BTagPerformanceAnalyzerMC.h.

Referenced by analyze(), and BTagPerformanceAnalyzerMC().

CorrectJet BTagPerformanceAnalyzerMC::jetCorrector
private

Definition at line 84 of file BTagPerformanceAnalyzerMC.h.

Referenced by getJetWithFlavour().

MatchJet BTagPerformanceAnalyzerMC::jetMatcher
private

Definition at line 85 of file BTagPerformanceAnalyzerMC.h.

Referenced by BTagPerformanceAnalyzerMC(), and getJetWithFlavour().

edm::InputTag BTagPerformanceAnalyzerMC::jetMCSrc
private

Definition at line 68 of file BTagPerformanceAnalyzerMC.h.

AcceptJet BTagPerformanceAnalyzerMC::jetSelector
private

Definition at line 61 of file BTagPerformanceAnalyzerMC.h.

Referenced by analyze().

std::vector<edm::InputTag> BTagPerformanceAnalyzerMC::jetTagInputTags
private

Definition at line 75 of file BTagPerformanceAnalyzerMC.h.

Referenced by analyze(), and BTagPerformanceAnalyzerMC().

std::vector<edm::EDGetTokenT<reco::JetTagCollection> > BTagPerformanceAnalyzerMC::jetTagToken
private

Definition at line 99 of file BTagPerformanceAnalyzerMC.h.

Referenced by analyze(), and BTagPerformanceAnalyzerMC().

edm::EDGetTokenT<reco::JetFlavourInfoMatchingCollection> BTagPerformanceAnalyzerMC::jetToken
private

Definition at line 96 of file BTagPerformanceAnalyzerMC.h.

Referenced by analyze(), and BTagPerformanceAnalyzerMC().

unsigned int BTagPerformanceAnalyzerMC::mcPlots_
private

Definition at line 82 of file BTagPerformanceAnalyzerMC.h.

Referenced by bookHistograms(), and BTagPerformanceAnalyzerMC().

std::vector<edm::ParameterSet> BTagPerformanceAnalyzerMC::moduleConfig
private

Definition at line 79 of file BTagPerformanceAnalyzerMC.h.

Referenced by bookHistograms(), and BTagPerformanceAnalyzerMC().

bool BTagPerformanceAnalyzerMC::muonPlots
private

Definition at line 89 of file BTagPerformanceAnalyzerMC.h.

Referenced by analyze(), and BTagPerformanceAnalyzerMC().

bool BTagPerformanceAnalyzerMC::ptHatWeight
private

Definition at line 66 of file BTagPerformanceAnalyzerMC.h.

Referenced by analyze().

std::vector<double> BTagPerformanceAnalyzerMC::ptRanges
private
edm::InputTag BTagPerformanceAnalyzerMC::slInfoTag
private

Definition at line 69 of file BTagPerformanceAnalyzerMC.h.

edm::EDGetTokenT<reco::SoftLeptonTagInfoCollection> BTagPerformanceAnalyzerMC::slInfoToken
private

Definition at line 98 of file BTagPerformanceAnalyzerMC.h.

Referenced by analyze(), and BTagPerformanceAnalyzerMC().

std::vector<std::pair<edm::InputTag, edm::InputTag> > BTagPerformanceAnalyzerMC::tagCorrelationInputTags
private

Definition at line 76 of file BTagPerformanceAnalyzerMC.h.

Referenced by analyze(), and BTagPerformanceAnalyzerMC().

std::vector<std::pair<edm::EDGetTokenT<reco::JetTagCollection>, edm::EDGetTokenT<reco::JetTagCollection> > > BTagPerformanceAnalyzerMC::tagCorrelationToken
private

Definition at line 101 of file BTagPerformanceAnalyzerMC.h.

Referenced by analyze(), and BTagPerformanceAnalyzerMC().

std::vector<std::vector<edm::InputTag> > BTagPerformanceAnalyzerMC::tagInfoInputTags
private

Definition at line 77 of file BTagPerformanceAnalyzerMC.h.

Referenced by analyze(), and BTagPerformanceAnalyzerMC().

std::vector<std::vector<edm::EDGetTokenT<edm::View<reco::BaseTagInfo> > > > BTagPerformanceAnalyzerMC::tagInfoToken
private

Definition at line 102 of file BTagPerformanceAnalyzerMC.h.

Referenced by analyze(), and BTagPerformanceAnalyzerMC().

bool BTagPerformanceAnalyzerMC::tauPlots
private

Definition at line 89 of file BTagPerformanceAnalyzerMC.h.

Referenced by analyze(), and BTagPerformanceAnalyzerMC().

std::vector<std::string> BTagPerformanceAnalyzerMC::tiDataFormatType
private

Definition at line 60 of file BTagPerformanceAnalyzerMC.h.

Referenced by analyze(), and BTagPerformanceAnalyzerMC().

bool BTagPerformanceAnalyzerMC::useOldFlavourTool
private

Definition at line 63 of file BTagPerformanceAnalyzerMC.h.

Referenced by analyze().