Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:13:16

0001 #include "DQMOffline/RecoB/interface/TrackProbabilityTagPlotter.h"
0002 #include "DQMOffline/RecoB/interface/Tools.h"
0003 
0004 using namespace std;
0005 using namespace RecoBTag;
0006 
0007 TrackProbabilityTagPlotter::TrackProbabilityTagPlotter(const std::string& tagName,
0008                                                        const EtaPtBin& etaPtBin,
0009                                                        const edm::ParameterSet& pSet,
0010                                                        const unsigned int& mc,
0011                                                        const bool& wf,
0012                                                        DQMStore::IBooker& ibook)
0013     : BaseTagInfoPlotter(tagName, etaPtBin),
0014       nBinEffPur_(pSet.getParameter<int>("nBinEffPur")),
0015       startEffPur_(pSet.getParameter<double>("startEffPur")),
0016       endEffPur_(pSet.getParameter<double>("endEffPur")),
0017       mcPlots_(mc),
0018       willFinalize_(wf) {
0019   const std::string dir(theExtensionString.substr(1));
0020 
0021   if (willFinalize_)
0022     return;
0023 
0024   for (unsigned int i = 1; i <= 4; i++) {
0025     tkcntHistosSig3D_.push_back(
0026         std::make_unique<FlavourHistograms<double>>("ips" + std::to_string(i) + "_3D" + theExtensionString,
0027                                                     "3D Probability of impact parameter " + std::to_string(i) + ". trk",
0028                                                     50,
0029                                                     -1.0,
0030                                                     1.0,
0031                                                     false,
0032                                                     true,
0033                                                     true,
0034                                                     "b",
0035                                                     dir,
0036                                                     mc,
0037                                                     ibook));
0038   }
0039 
0040   tkcntHistosSig3D_.push_back(std::make_unique<FlavourHistograms<double>>("ips_3D" + theExtensionString,
0041                                                                           "3D Probability of impact parameter",
0042                                                                           50,
0043                                                                           -1.0,
0044                                                                           1.0,
0045                                                                           false,
0046                                                                           true,
0047                                                                           true,
0048                                                                           "b",
0049                                                                           dir,
0050                                                                           mc,
0051                                                                           ibook));
0052 
0053   for (unsigned int i = 1; i <= 4; i++) {
0054     tkcntHistosSig2D_.push_back(
0055         std::make_unique<FlavourHistograms<double>>("ips" + std::to_string(i) + "_2D" + theExtensionString,
0056                                                     "2D Probability of impact parameter " + std::to_string(i) + ". trk",
0057                                                     50,
0058                                                     -1.0,
0059                                                     1.0,
0060                                                     false,
0061                                                     true,
0062                                                     true,
0063                                                     "b",
0064                                                     dir,
0065                                                     mc,
0066                                                     ibook));
0067   }
0068 
0069   tkcntHistosSig2D_.push_back(std::make_unique<FlavourHistograms<double>>("ips_2D" + theExtensionString,
0070                                                                           "2D Probability of impact parameter",
0071                                                                           50,
0072                                                                           -1.0,
0073                                                                           1.0,
0074                                                                           false,
0075                                                                           true,
0076                                                                           true,
0077                                                                           "b",
0078                                                                           dir,
0079                                                                           mc,
0080                                                                           ibook));
0081 }
0082 
0083 TrackProbabilityTagPlotter::~TrackProbabilityTagPlotter() {}
0084 
0085 void TrackProbabilityTagPlotter::analyzeTag(const reco::BaseTagInfo* baseTagInfo,
0086                                             double jec,
0087                                             int jetFlavour,
0088                                             float w /*=1*/) {
0089   const reco::TrackProbabilityTagInfo* tagInfo = dynamic_cast<const reco::TrackProbabilityTagInfo*>(baseTagInfo);
0090 
0091   if (!tagInfo) {
0092     throw cms::Exception("Configuration")
0093         << "BTagPerformanceAnalyzer: Extended TagInfo not of type TrackProbabilityTagInfo. " << endl;
0094   }
0095 
0096   for (int n = 0; n != tagInfo->selectedTracks(1) && n != 4; ++n)
0097     tkcntHistosSig2D_[n]->fill(jetFlavour, tagInfo->probability(n, 1), w);
0098   for (int n = 0; n != tagInfo->selectedTracks(0) && n != 4; ++n)
0099     tkcntHistosSig3D_[n]->fill(jetFlavour, tagInfo->probability(n, 0), w);
0100 
0101   for (int n = 0; n != tagInfo->selectedTracks(1); ++n)
0102     tkcntHistosSig2D_[4]->fill(jetFlavour, tagInfo->probability(n, 1), w);
0103   for (int n = 0; n != tagInfo->selectedTracks(0); ++n)
0104     tkcntHistosSig3D_[4]->fill(jetFlavour, tagInfo->probability(n, 0), w);
0105 }
0106 
0107 void TrackProbabilityTagPlotter::finalize(DQMStore::IBooker& ibook, DQMStore::IGetter& igetter_) {
0108   //
0109   // final processing:
0110   // produce the misid. vs. eff histograms
0111   //
0112   const std::string dir("TrackProbability" + theExtensionString);
0113 
0114   tkcntHistosSig3D_.clear();
0115   tkcntHistosSig2D_.clear();
0116   effPurFromHistos_.clear();
0117 
0118   for (unsigned int i = 2; i <= 3; i++) {
0119     tkcntHistosSig3D_.push_back(
0120         std::make_unique<FlavourHistograms<double>>("ips" + std::to_string(i) + "_3D" + theExtensionString,
0121                                                     "3D Probability of impact parameter " + std::to_string(i) + ". trk",
0122                                                     50,
0123                                                     -1.0,
0124                                                     1.0,
0125                                                     "b",
0126                                                     dir,
0127                                                     mcPlots_,
0128                                                     igetter_));
0129     effPurFromHistos_.push_back(std::make_unique<EffPurFromHistos>(
0130         *tkcntHistosSig3D_.back(), dir, mcPlots_, ibook, nBinEffPur_, startEffPur_, endEffPur_));
0131   }
0132 
0133   for (unsigned int i = 2; i <= 3; i++) {
0134     tkcntHistosSig2D_.push_back(
0135         std::make_unique<FlavourHistograms<double>>("ips" + std::to_string(i) + "_2D" + theExtensionString,
0136                                                     "2D Probability of impact parameter " + std::to_string(i) + ". trk",
0137                                                     50,
0138                                                     -1.0,
0139                                                     1.0,
0140                                                     "b",
0141                                                     dir,
0142                                                     mcPlots_,
0143                                                     igetter_));
0144     effPurFromHistos_.push_back(std::make_unique<EffPurFromHistos>(
0145         *tkcntHistosSig2D_.back(), dir, mcPlots_, ibook, nBinEffPur_, startEffPur_, endEffPur_));
0146   }
0147 
0148   for (int n = 0; n != 4; ++n)
0149     effPurFromHistos_[n]->compute(ibook);
0150 }
0151 
0152 void TrackProbabilityTagPlotter::psPlot(const std::string& name) {
0153   const std::string cName("TrackProbabilityPlots" + theExtensionString);
0154   setTDRStyle()->cd();
0155   TCanvas canvas(cName.c_str(), cName.c_str(), 600, 900);
0156   canvas.UseCurrentStyle();
0157   if (willFinalize_) {
0158     for (int n = 0; n != 2; ++n) {
0159       canvas.Print((name + cName + ".ps").c_str());
0160       canvas.Clear();
0161       canvas.Divide(2, 3);
0162       canvas.cd(1);
0163       effPurFromHistos_[0 + n]->discriminatorNoCutEffic().plot();
0164       canvas.cd(2);
0165       effPurFromHistos_[0 + n]->discriminatorCutEfficScan().plot();
0166       canvas.cd(3);
0167       effPurFromHistos_[0 + n]->plot();
0168       canvas.cd(4);
0169       effPurFromHistos_[1 + n]->discriminatorNoCutEffic().plot();
0170       canvas.cd(5);
0171       effPurFromHistos_[1 + n]->discriminatorCutEfficScan().plot();
0172       canvas.cd(6);
0173       effPurFromHistos_[1 + n]->plot();
0174     }
0175     return;
0176   }
0177 
0178   canvas.Clear();
0179   canvas.Divide(2, 3);
0180   canvas.Print((name + cName + ".ps[").c_str());
0181   canvas.cd(1);
0182 
0183   tkcntHistosSig3D_[4]->plot();
0184   for (int n = 0; n != 4; ++n) {
0185     canvas.cd(2 + n);
0186     tkcntHistosSig3D_[n]->plot();
0187   }
0188 
0189   canvas.Print((name + cName + ".ps").c_str());
0190   canvas.Clear();
0191   canvas.Divide(2, 3);
0192 
0193   canvas.cd(1);
0194   tkcntHistosSig2D_[4]->plot();
0195   for (int n = 0; n != 4; ++n) {
0196     canvas.cd(2 + n);
0197     tkcntHistosSig2D_[n]->plot();
0198   }
0199 
0200   canvas.Print((name + cName + ".ps").c_str());
0201   canvas.Print((name + cName + ".ps]").c_str());
0202 }
0203 
0204 void TrackProbabilityTagPlotter::epsPlot(const std::string& name) {
0205   if (willFinalize_) {
0206     for (int n = 0; n != 4; ++n)
0207       effPurFromHistos_[n]->epsPlot(name);
0208     return;
0209   }
0210   for (int n = 0; n != 5; ++n) {
0211     tkcntHistosSig2D_[n]->epsPlot(name);
0212     tkcntHistosSig3D_[n]->epsPlot(name);
0213   }
0214 }