CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
BTagPerformanceAnalyzerMC.cc
Go to the documentation of this file.
5 
6 using namespace reco;
7 using namespace edm;
8 using namespace std;
9 using namespace RecoBTag;
10 
11 typedef std::pair<Jet, reco::JetFlavourInfo> JetWithFlavour;
12 
14  jetSelector(
15  pSet.getParameter<double>("etaMin"),
16  pSet.getParameter<double>("etaMax"),
17  pSet.getParameter<double>("ptRecJetMin"),
18  pSet.getParameter<double>("ptRecJetMax"),
19  0.0, 99999.0,
20  pSet.getParameter<double>("ratioMin"),
21  pSet.getParameter<double>("ratioMax"),
22  pSet.getParameter<bool>( "doJetID" )
23  ),
24  etaRanges(pSet.getParameter< vector<double> >("etaRanges")),
25  ptRanges(pSet.getParameter< vector<double> >("ptRanges")),
26  useOldFlavourTool(pSet.getParameter<bool>( "useOldFlavourTool" )),
27  doJEC(pSet.getParameter<bool>( "doJEC" )),
28  ptHatWeight(pSet.getParameter< bool >("applyPtHatWeight")),
29  moduleConfig(pSet.getParameter< vector<edm::ParameterSet> >("tagConfig")),
30  flavPlots_(pSet.getParameter< std::string >("flavPlots")),
31  jetMatcher(pSet.getParameter<edm::ParameterSet>("recJetMatching")),
32  doPUid(pSet.getParameter< bool >("doPUid"))
33 {
34  //mcPlots_ : 1=b+c+l+ni; 2=all+1; 3=1+d+u+s+g; 4=3+all . Default is 2. Don't use 0.
35  if(flavPlots_.find("dusg")<15){
36  if(flavPlots_.find("all")<15) mcPlots_ = 4;
37  else mcPlots_ = 3;
38  }
39  else{
40  if(flavPlots_.find("all")<15) mcPlots_ = 2;
41  else mcPlots_ = 1;
42  }
43  double ptRecJetMin = pSet.getParameter<double>("ptRecJetMin");
44  jetMatcher.setThreshold(0.25 * ptRecJetMin);
45  switch(pSet.getParameter<unsigned int>("leptonPlots")) {
46  case 11: electronPlots = true; muonPlots = false; tauPlots = false; break;
47  case 13: muonPlots = true; electronPlots = false; tauPlots = false; break;
48  case 15: tauPlots = true; electronPlots = false; tauPlots = false; break;
49  default: electronPlots = false; muonPlots = false; tauPlots = false;
50  }
51 
52  genToken = mayConsume<GenEventInfoProduct>(edm::InputTag("generator"));
53  genJetsMatchedToken = mayConsume<edm::Association<reco::GenJetCollection>>(pSet.getParameter<InputTag>("genJetsMatched"));
54  jetToken = consumes<JetFlavourInfoMatchingCollection>(pSet.getParameter<InputTag>("jetMCSrc"));
55  caloJetToken = mayConsume<JetFlavourMatchingCollection>(pSet.getParameter<InputTag>("caloJetMCSrc"));
56  slInfoToken = consumes<SoftLeptonTagInfoCollection>(pSet.getParameter<InputTag>("softLeptonInfo"));
57  jecMCToken = consumes<JetCorrector>(pSet.getParameter<edm::InputTag>( "JECsourceMC" ));
58  jecDataToken = mayConsume<JetCorrector>(pSet.getParameter<edm::InputTag>( "JECsourceData" ));
59  for (vector<edm::ParameterSet>::const_iterator iModule = moduleConfig.begin();
60  iModule != moduleConfig.end(); ++iModule) {
61 
62  const string& dataFormatType = iModule->exists("type") ?
63  iModule->getParameter<string>("type") :
64  "JetTag";
65  if (dataFormatType == "JetTag") {
66  const InputTag& moduleLabel = iModule->getParameter<InputTag>("label");
67  jetTagInputTags.push_back(moduleLabel);
68  binJetTagPlotters.push_back(vector<JetTagPlotter*>()) ;
69  jetTagToken.push_back(consumes<JetTagCollection>(moduleLabel));
70  }
71  else if(dataFormatType == "TagCorrelation") {
72  const InputTag& label1 = iModule->getParameter<InputTag>("label1");
73  const InputTag& label2 = iModule->getParameter<InputTag>("label2");
74  tagCorrelationInputTags.push_back(std::pair<edm::InputTag, edm::InputTag>(label1, label2));
75  binTagCorrelationPlotters.push_back(vector<TagCorrelationPlotter*>());
76  tagCorrelationToken.push_back(std::pair< edm::EDGetTokenT<reco::JetTagCollection>, edm::EDGetTokenT<reco::JetTagCollection> >(consumes<JetTagCollection>(label1), consumes<JetTagCollection>(label2)));
77  }
78  else {
79  tagInfoInputTags.push_back(vector<edm::InputTag>());
80  tiDataFormatType.push_back(dataFormatType);
81  binTagInfoPlotters.push_back(vector<BaseTagInfoPlotter*>()) ;
82  std::vector< edm::EDGetTokenT<edm::View<reco::BaseTagInfo>> > tokens;
83  if(dataFormatType == "GenericMVA") {
84  const InputTag& ipinfo = iModule->getParameter<InputTag>("ipTagInfos");
85  const InputTag& svinfo = iModule->getParameter<InputTag>("svTagInfos");
86  tokens.push_back(consumes< View<BaseTagInfo> >(ipinfo));
87  tokens.push_back(consumes< View<BaseTagInfo> >(svinfo));
88  }
89  else {
90  const InputTag& moduleLabel = iModule->getParameter<InputTag>("label");
91  tokens.push_back(consumes< View<BaseTagInfo> >(moduleLabel));
92  }
93  tagInfoToken.push_back(tokens);
94  }
95  }
96 }
97 
99 {
100  //
101  // Book all histograms.
102  //
103 
104  // iterate over ranges:
105  const int iEtaStart = -1 ; // this will be the inactive one
106  const int iEtaEnd = etaRanges.size() - 1 ;
107  const int iPtStart = -1 ; // this will be the inactive one
108  const int iPtEnd = ptRanges.size() - 1 ;
109  setTDRStyle();
110 
111  TagInfoPlotterFactory theFactory;
112  int iTag = -1; int iTagCorr = -1; int iInfoTag = -1;
113  for (vector<edm::ParameterSet>::const_iterator iModule = moduleConfig.begin();
114  iModule != moduleConfig.end(); ++iModule) {
115 
116  const string& dataFormatType = iModule->exists("type") ?
117  iModule->getParameter<string>("type") :
118  "JetTag";
119  if (dataFormatType == "JetTag") {
120  iTag++;
121  const string& folderName = iModule->getParameter<string>("folder");
122 
123  // eta loop
124  for ( int iEta = iEtaStart ; iEta < iEtaEnd ; iEta++ ) {
125  // pt loop
126  for ( int iPt = iPtStart ; iPt < iPtEnd ; iPt++ ) {
127 
128  const EtaPtBin& etaPtBin = getEtaPtBin(iEta, iPt);
129 
130  // Instantiate the genertic b tag plotter
131  JetTagPlotter *jetTagPlotter = new JetTagPlotter(folderName, etaPtBin,
132  iModule->getParameter<edm::ParameterSet>("parameters"),mcPlots_,false, ibook);
133  binJetTagPlotters.at(iTag).push_back ( jetTagPlotter ) ;
134 
135  }
136  }
137  } else if(dataFormatType == "TagCorrelation") {
138  iTagCorr++;
139  const InputTag& label1 = iModule->getParameter<InputTag>("label1");
140  const InputTag& label2 = iModule->getParameter<InputTag>("label2");
141 
142  // eta loop
143  for ( int iEta = iEtaStart ; iEta != iEtaEnd ; ++iEta) {
144  // pt loop
145  for( int iPt = iPtStart ; iPt != iPtEnd ; ++iPt) {
146  const EtaPtBin& etaPtBin = getEtaPtBin(iEta, iPt);
147  // Instantiate the generic b tag correlation plotter
148  TagCorrelationPlotter* tagCorrelationPlotter = new TagCorrelationPlotter(label1.label(), label2.label(), etaPtBin,
149  iModule->getParameter<edm::ParameterSet>("parameters"),
150  mcPlots_, ibook);
151  binTagCorrelationPlotters.at(iTagCorr).push_back(tagCorrelationPlotter);
152  }
153  }
154  } else {
155  iInfoTag++;
156  // tag info retrievel is deferred (needs availability of EventSetup)
157  const InputTag& moduleLabel = iModule->getParameter<InputTag>("label");
158  const string& folderName = iModule->getParameter<string>("folder");
159  // eta loop
160  for ( int iEta = iEtaStart ; iEta < iEtaEnd ; iEta++ ) {
161  // pt loop
162  for ( int iPt = iPtStart ; iPt < iPtEnd ; iPt++ ) {
163  const EtaPtBin& etaPtBin = getEtaPtBin(iEta, iPt);
164 
165  // Instantiate the tagInfo plotter
166 
167  BaseTagInfoPlotter *jetTagPlotter = theFactory.buildPlotter(dataFormatType, moduleLabel.label(),
168  etaPtBin, iModule->getParameter<edm::ParameterSet>("parameters"), folderName,
169  mcPlots_,false, ibook);
170  binTagInfoPlotters.at(iInfoTag).push_back ( jetTagPlotter ) ;
171  binTagInfoPlottersToModuleConfig.insert(make_pair(jetTagPlotter, iModule - moduleConfig.begin()));
172  }
173  }
174  }
175  }
176 }
177 
178 EtaPtBin BTagPerformanceAnalyzerMC::getEtaPtBin(const int& iEta, const int& iPt)
179 {
180  // DEFINE BTagBin:
181  bool etaActive_ , ptActive_;
182  double etaMin_, etaMax_, ptMin_, ptMax_ ;
183 
184  if ( iEta != -1 ) {
185  etaActive_ = true ;
186  etaMin_ = etaRanges[iEta] ;
187  etaMax_ = etaRanges[iEta+1] ;
188  }
189  else {
190  etaActive_ = false ;
191  etaMin_ = etaRanges[0] ;
192  etaMax_ = etaRanges[etaRanges.size() - 1] ;
193  }
194 
195  if ( iPt != -1 ) {
196  ptActive_ = true ;
197  ptMin_ = ptRanges[iPt] ;
198  ptMax_ = ptRanges[iPt+1] ;
199  }
200  else {
201  ptActive_ = false ;
202  ptMin_ = ptRanges[0] ;
203  ptMax_ = ptRanges[ptRanges.size() - 1] ;
204  }
205  return EtaPtBin(etaActive_ , etaMin_ , etaMax_ ,
206  ptActive_ , ptMin_ , ptMax_ );
207 }
208 
210 {
211  for (vector<vector<JetTagPlotter*> >::iterator iJetLabel = binJetTagPlotters.begin();
212  iJetLabel != binJetTagPlotters.end(); ++iJetLabel)
213  for (vector<JetTagPlotter*>::iterator iPlotter = iJetLabel->begin(); iPlotter != iJetLabel->end(); ++iPlotter)
214  delete *iPlotter;
215 
216  for (vector<vector<TagCorrelationPlotter*> >::iterator iJetLabel = binTagCorrelationPlotters.begin();
217  iJetLabel != binTagCorrelationPlotters.end(); ++iJetLabel)
218  for (vector<TagCorrelationPlotter* >::iterator iPlotter = iJetLabel->begin(); iPlotter != iJetLabel->end(); ++iPlotter)
219  delete *iPlotter;
220 
221  for (vector<vector<BaseTagInfoPlotter*> >::iterator iJetLabel = binTagInfoPlotters.begin();
222  iJetLabel != binTagInfoPlotters.end(); ++iJetLabel)
223  for (vector<BaseTagInfoPlotter*>::iterator iPlotter = iJetLabel->begin(); iPlotter != iJetLabel->end(); ++iPlotter)
224  delete *iPlotter;
225 
226 }
227 
229 {
230  eventInitialized = false;
231 
232  float weight = 1; // event weight
233 
234  if (ptHatWeight) {
235 
236  /* APPLY PTHAT EVENT WEIGHT */
237 
238  edm::Handle<GenEventInfoProduct> genInfoHandle;
239  iEvent.getByToken(genToken, genInfoHandle);
240 
241  if( genInfoHandle.isValid() ) {
242  weight = weight*static_cast<float>(genInfoHandle->weight());
243 
244  }
245  }
246 
247  LogDebug("Info") << "Event weight is: " << weight;
248 
249  FlavourMap flavours;
251 
252 
253  if(!useOldFlavourTool) {
255  iEvent.getByToken(jetToken, jetMC);
256  for (JetFlavourInfoMatchingCollection::const_iterator iter = jetMC->begin();
257  iter != jetMC->end(); ++iter) {
258  unsigned int fl = std::abs(iter->second.getPartonFlavour());
259  flavours.insert(std::make_pair(iter->first, fl));
260  const GenParticleRefVector &lep = iter->second.getLeptons();
261  reco::JetFlavour::Leptons lepCount;
262  for (unsigned int i=0; i<lep.size(); i++){
263  if(abs(lep[i]->pdgId())==11) lepCount.electron++;
264  else if(abs(lep[i]->pdgId())==13) lepCount.muon++;
265  else if(abs(lep[i]->pdgId())==15) lepCount.tau++;
266  }
267  leptons.insert(std::make_pair(iter->first, lepCount));
268  }
269  }
270  else {
272  iEvent.getByToken(caloJetToken, jetMC);
273  for (JetFlavourMatchingCollection::const_iterator iter = jetMC->begin();
274  iter != jetMC->end(); ++iter) {
275  unsigned int fl = std::abs(iter->second.getFlavour());
276  flavours.insert(std::make_pair(iter->first, fl));
277  const reco::JetFlavour::Leptons &lep = iter->second.getLeptons();
278  leptons.insert(std::make_pair(iter->first, lep));
279  }
280  }
281 
283  iEvent.getByToken(slInfoToken, infoHandle);
284 
286  if (doPUid) {
287  iEvent.getByToken(genJetsMatchedToken, genJetsMatched);
288  }
289 
290  //Get JEC
291  const JetCorrector* corrector = 0;
292  if(doJEC) {
293  edm::Handle<GenEventInfoProduct> genInfoHandle; //check if data or MC
294  iEvent.getByToken(genToken, genInfoHandle);
295  edm::Handle<JetCorrector> corrHandle;
296  if( !genInfoHandle.isValid() ) iEvent.getByToken( jecDataToken, corrHandle);
297  else iEvent.getByToken( jecMCToken, corrHandle);
298  corrector = corrHandle.product();
299  }
300  //
301 
302 // Look first at the jetTags
303  for (unsigned int iJetLabel = 0; iJetLabel != jetTagInputTags.size(); ++iJetLabel) {
305  iEvent.getByToken(jetTagToken[iJetLabel], tagHandle);
306  const reco::JetTagCollection & tagColl = *(tagHandle.product());
307  LogDebug("Info") << "Found " << tagColl.size() << " B candidates in collection " << jetTagInputTags[iJetLabel];
308 
309  int plotterSize = binJetTagPlotters[iJetLabel].size();
310  for (JetTagCollection::const_iterator tagI = tagColl.begin();
311  tagI != tagColl.end(); ++tagI) {
312  // Identify parton associated to jet.
313 
315  if (flavours[tagI->first] == 5 &&
316  ((electronPlots && !leptons[tagI->first].electron) ||
317  (muonPlots && !leptons[tagI->first].muon) ||
318  (tauPlots && !leptons[tagI->first].tau)))
319  continue;
320  //JEC
321  reco::Jet correctedJet = *(tagI->first);
322  double jec = 1.0;
323  if(doJEC && corrector) {
324  jec = corrector->correction(*(tagI->first));
325  }
326 
327  JetWithFlavour jetWithFlavour;
328  if (!getJetWithFlavour(iEvent, tagI->first, flavours, jetWithFlavour, corrector, genJetsMatched))
329  continue;
330  if (!jetSelector(jetWithFlavour.first, std::abs(jetWithFlavour.second.getPartonFlavour()), infoHandle, jec))
331  continue;
332 
333  for (int iPlotter = 0; iPlotter != plotterSize; ++iPlotter) {
334  bool inBin = false;
335  inBin = binJetTagPlotters[iJetLabel][iPlotter]->etaPtBin().inBin(jetWithFlavour.first, jec);
336  // Fill histograms if in desired pt/rapidity bin.
337  if (inBin)
338  binJetTagPlotters[iJetLabel][iPlotter]->analyzeTag(jetWithFlavour.first, jec, tagI->second, std::abs(jetWithFlavour.second.getPartonFlavour()),weight);
339  }
340  }
341  for (int iPlotter = 0; iPlotter != plotterSize; ++iPlotter) {
342  binJetTagPlotters[iJetLabel][iPlotter]->analyzeTag(weight);
343  }
344  }
345 
346 // Now look at Tag Correlations
347  for (unsigned int iJetLabel = 0; iJetLabel != tagCorrelationInputTags.size(); ++iJetLabel) {
348  const std::pair< edm::EDGetTokenT<reco::JetTagCollection>, edm::EDGetTokenT<reco::JetTagCollection> >& inputTokens = tagCorrelationToken[iJetLabel];
350  iEvent.getByToken(inputTokens.first, tagHandle1);
351  const reco::JetTagCollection& tagColl1 = *(tagHandle1.product());
352 
354  iEvent.getByToken(inputTokens.second, tagHandle2);
355  const reco::JetTagCollection& tagColl2 = *(tagHandle2.product());
356 
357  int plotterSize = binTagCorrelationPlotters[iJetLabel].size();
358  for (JetTagCollection::const_iterator tagI = tagColl1.begin(); tagI != tagColl1.end(); ++tagI) {
359 
360  if (flavours[tagI->first] == 5 &&
361  ((electronPlots && !leptons[tagI->first].electron) ||
362  (muonPlots && !leptons[tagI->first].muon) ||
363  (tauPlots && !leptons[tagI->first].tau)))
364  continue;
365 
366  //JEC
367  reco::Jet correctedJet = *(tagI->first);
368  double jec = 1.0;
369  if(doJEC && corrector) {
370  jec = corrector->correction(*(tagI->first));
371  }
372 
373  JetWithFlavour jetWithFlavour;
374  if (!getJetWithFlavour(iEvent, tagI->first, flavours, jetWithFlavour, corrector, genJetsMatched))
375  continue;
376  if (!jetSelector(jetWithFlavour.first, std::abs(jetWithFlavour.second.getPartonFlavour()), infoHandle, jec))
377  continue;
378 
379  for(int iPlotter = 0; iPlotter != plotterSize; ++iPlotter) {
380  bool inBin = false;
381  inBin = binTagCorrelationPlotters[iJetLabel][iPlotter]->etaPtBin().inBin(jetWithFlavour.first, jec);
382 
383  if(inBin)
384  {
385  double discr2 = tagColl2[tagI->first];
386  binTagCorrelationPlotters[iJetLabel][iPlotter]->analyzeTags(tagI->second, discr2, std::abs(jetWithFlavour.second.getPartonFlavour()),weight);
387  }
388  }
389  }
390  }
391 
392 // Now look at the TagInfos
393 
394  for (unsigned int iJetLabel = 0; iJetLabel != tiDataFormatType.size(); ++iJetLabel) {
395  int plotterSize = binTagInfoPlotters[iJetLabel].size();
396  for (int iPlotter = 0; iPlotter != plotterSize; ++iPlotter)
397  binTagInfoPlotters[iJetLabel][iPlotter]->setEventSetup(iSetup);
398 
399  vector<edm::InputTag> & inputTags = tagInfoInputTags[iJetLabel];
400  if (inputTags.empty()) {
401  // deferred retrieval of input tags
402  BaseTagInfoPlotter *firstPlotter = binTagInfoPlotters[iJetLabel][0];
403  int iModule = binTagInfoPlottersToModuleConfig[firstPlotter];
404  vector<string> labels = firstPlotter->tagInfoRequirements();
405  if (labels.empty())
406  labels.push_back("label");
407  for (vector<string>::const_iterator iLabels = labels.begin();
408  iLabels != labels.end(); ++iLabels) {
410  moduleConfig[iModule].getParameter<InputTag>(*iLabels);
411  inputTags.push_back(inputTag);
412  }
413  }
414 
415  unsigned int nInputTags = inputTags.size();
416  vector< edm::Handle< View<BaseTagInfo> > > tagInfoHandles(nInputTags);
417  edm::ProductID jetProductID;
418  unsigned int nTagInfos = 0;
419  vector<edm::EDGetTokenT<edm::View<reco::BaseTagInfo>> > & tokens = tagInfoToken[iJetLabel];
420  if(nInputTags!=tokens.size()) throw cms::Exception("Configuration") << "Different number of Tag Infos than expected" << endl;
421  for (unsigned int iInputTags = 0; iInputTags < tokens.size(); ++iInputTags) {
422  edm::Handle< View<BaseTagInfo> > & tagInfoHandle = tagInfoHandles[iInputTags];
423  iEvent.getByToken(tokens[iInputTags], tagInfoHandle);
424  unsigned int size = tagInfoHandle->size();
425  LogDebug("Info") << "Found " << size << " B candidates in collection " << inputTags[iInputTags];
426 
427  edm::ProductID thisProductID = (size > 0) ? (*tagInfoHandle)[0].jet().id() : edm::ProductID();
428  if (iInputTags == 0) {
429  jetProductID = thisProductID;
430  nTagInfos = size;
431  } else if (jetProductID != thisProductID)
432  throw cms::Exception("Configuration") << "TagInfos are referencing a different jet collection." << endl;
433  else if (nTagInfos != size)
434  throw cms::Exception("Configuration") << "TagInfo collections are having a different size." << endl;
435  }
436 
437  for (unsigned int iTagInfos = 0; iTagInfos < nTagInfos; ++iTagInfos) {
438  vector<const BaseTagInfo*> baseTagInfos(nInputTags);
439  edm::RefToBase<Jet> jetRef;
440  for (unsigned int iTagInfo = 0; iTagInfo < nInputTags; iTagInfo++) {
441  const BaseTagInfo &baseTagInfo = (*tagInfoHandles[iTagInfo])[iTagInfos];
442  if (iTagInfo == 0)
443  jetRef = baseTagInfo.jet();
444  else if (baseTagInfo.jet() != jetRef)
445  throw cms::Exception("Configuration") << "TagInfos pointing to different jets." << endl;
446  baseTagInfos[iTagInfo] = &baseTagInfo;
447  }
448 
449  // Identify parton associated to jet.
450 
452  if (flavours[jetRef] == 5 &&
453  ((electronPlots && !leptons[jetRef].electron) ||
454  (muonPlots && !leptons[jetRef].muon) ||
455  (tauPlots && !leptons[jetRef].tau)))
456  continue;
457 
458  //JEC
459  reco::Jet correctedJet = *(jetRef);
460  double jec = 1.0;
461  if(doJEC && corrector) {
462  jec = corrector->correction(*(jetRef));
463  }
464 
465  JetWithFlavour jetWithFlavour;
466  if (!getJetWithFlavour(iEvent, jetRef, flavours, jetWithFlavour, corrector, genJetsMatched))
467  continue;
468  if (!jetSelector(jetWithFlavour.first, std::abs(jetWithFlavour.second.getPartonFlavour()), infoHandle, jec))
469  continue;
470 
471  for (int iPlotter = 0; iPlotter != plotterSize; ++iPlotter) {
472  bool inBin = false;
473  inBin = binTagInfoPlotters[iJetLabel][iPlotter]->etaPtBin().inBin(*jetRef, jec);
474  // Fill histograms if in desired pt/rapidity bin.
475  if (inBin)
476  binTagInfoPlotters[iJetLabel][iPlotter]->analyzeTag(baseTagInfos, jec, std::abs(jetWithFlavour.second.getPartonFlavour()),weight);
477  }
478  }
479  }
480 }
481 
483 {
484  if(!doPUid) return true;
485  reco::GenJetRef genjet = (*genJetsMatched)[jetRef];
486  if (genjet.isNonnull() && genjet.isAvailable()) return true;
487  return false;
488 }
489 
491  edm::RefToBase<Jet> jetRef, const FlavourMap& flavours,
492  JetWithFlavour & jetWithFlavour, const JetCorrector * corrector,
494 {
495  edm::ProductID recProdId = jetRef.id();
496  edm::ProductID refProdId = (flavours.begin() == flavours.end())
497  ? recProdId
498  : flavours.begin()->first.id();
499 
500  if (!eventInitialized) {
501  jetCorrector.setCorrector(corrector);
502  if (recProdId != refProdId) {
504  for(FlavourMap::const_iterator iter = flavours.begin();
505  iter != flavours.end(); ++iter)
506  refJets.push_back(iter->first);
507  const edm::RefToBaseProd<Jet> recJetsProd(edm::makeRefToBaseProdFrom(jetRef, iEvent));
509  for(unsigned int i = 0; i < recJetsProd->size(); i++)
510  recJets.push_back(edm::RefToBase<Jet>(recJetsProd, i));
511  jetMatcher.matchCollections(refJets, recJets, corrector);
512  }
513  eventInitialized = true;
514  }
515 
516  if (recProdId != refProdId) {
517  jetRef = jetMatcher(jetRef);
518  if (jetRef.isNull())
519  return false;
520  }
521 
522  jetWithFlavour.first = jetCorrector(*jetRef);
523 
524  auto itFound = flavours.find(jetRef);
525  unsigned int flavour = itFound != flavours.end()? itFound->second : 0;
526 
527  if(doPUid){
528  bool isNotPU = getJetWithGenJet(jetRef, genJetsMatched);
529  if(!isNotPU) flavour=20;
530  }
531 
532  jetWithFlavour.second = reco::JetFlavourInfo(flavour, flavour);
533 
534  LogTrace("Info") << "Found jet with flavour "<<jetWithFlavour.second.getPartonFlavour()<<endl;
535  LogTrace("Info") << jetWithFlavour.first.p()<<" , "<< jetWithFlavour.first.pt()<<" - "<<endl;
536  //<< jetWithFlavour.second.getLorentzVector().P()<<" , "<< jetWithFlavour.second.getLorentzVector().Pt()<<endl;
537 
538  return true;
539 }
540 
541 //define this as a plug-in
#define LogDebug(id)
bool isAvailable() const
Definition: Ref.h:576
std::vector< std::pair< edm::InputTag, edm::InputTag > > tagCorrelationInputTags
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
BaseTagInfoPlotter * buildPlotter(const std::string &dataFormatType, const std::string &tagName, const EtaPtBin &etaPtBin, const edm::ParameterSet &pSet, const std::string &folderName, const unsigned int &mc, const bool &wf, DQMStore::IBooker &ibook)
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:252
std::vector< std::vector< TagCorrelationPlotter * > > binTagCorrelationPlotters
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:464
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
Base class for all types of Jets.
Definition: Jet.h:20
void setThreshold(const double &energy)
Definition: MatchJet.h:25
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
std::vector< edm::EDGetTokenT< reco::JetTagCollection > > jetTagToken
const_iterator end() const
size_type size() const
double correction(const LorentzVector &fJet) const
get correction using Jet information only
Definition: JetCorrector.h:47
std::vector< std::pair< edm::EDGetTokenT< reco::JetTagCollection >, edm::EDGetTokenT< reco::JetTagCollection > > > tagCorrelationToken
bool getJetWithGenJet(edm::RefToBase< reco::Jet > jetRef, edm::Handle< edm::Association< reco::GenJetCollection > > genJetsMatched)
ProductID id() const
Definition: RefToBase.h:233
std::pair< reco::Jet, reco::JetFlavourInfo > JetWithFlavour
edm::EDGetTokenT< GenEventInfoProduct > genToken
void matchCollections(const edm::RefToBaseVector< reco::Jet > &refJets, const edm::RefToBaseVector< reco::Jet > &recJets, const reco::JetCorrector *corrector)
match the collections
Definition: MatchJet.cc:51
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
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
virtual void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup)
BTagPerformanceAnalyzerMC(const edm::ParameterSet &pSet)
int iEvent
Definition: GenABIO.cc:230
edm::EDGetTokenT< reco::JetFlavourMatchingCollection > caloJetToken
tuple corrector
Definition: mvaPFMET_cff.py:86
edm::EDGetTokenT< reco::JetFlavourInfoMatchingCollection > jetToken
Class storing the jet flavour information.
edm::EDGetTokenT< reco::JetCorrector > jecDataToken
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
list EtaPtBin
Definition: histoStyle.py:59
std::vector< std::vector< BaseTagInfoPlotter * > > binTagInfoPlotters
std::vector< edm::ParameterSet > moduleConfig
std::vector< std::vector< edm::InputTag > > tagInfoInputTags
EtaPtBin getEtaPtBin(const int &iEta, const int &iPt)
bool isValid() const
Definition: HandleBase.h:75
#define LogTrace(id)
lepton info struct
Definition: JetFlavour.h:25
std::vector< std::vector< edm::EDGetTokenT< edm::View< reco::BaseTagInfo > > > > tagInfoToken
virtual std::vector< std::string > tagInfoRequirements() const
T const * product() const
Definition: Handle.h:81
std::vector< std::string > tiDataFormatType
edm::EDGetTokenT< reco::SoftLeptonTagInfoCollection > slInfoToken
bool isNull() const
Checks for null.
Definition: RefToBase.h:321
void setCorrector(const reco::JetCorrector *corrector)
Returns the corrected jet.
Definition: CorrectJet.h:22
std::string const & label() const
Definition: InputTag.h:43
void setTDRStyle()
Definition: plotscripts.py:87
RefToBaseProd< T > makeRefToBaseProdFrom(RefToBase< T > const &iRef, Event const &iEvent)
std::vector< edm::InputTag > jetTagInputTags
void push_back(const RefToBase< T > &)
size_type size() const
Size of the RefVector.
Definition: RefVector.h:99
volatile std::atomic< bool > shutdown_flag false
ProductIndex id() const
Definition: ProductID.h:38
std::vector< std::vector< JetTagPlotter * > > binJetTagPlotters
int flavour(const Candidate &part)
Definition: pdgIdUtils.h:31
const_iterator begin() const
std::map< BaseTagInfoPlotter *, size_t > binTagInfoPlottersToModuleConfig
tuple size
Write out results.
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)
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
Definition: Run.h:43
size_type size() const