Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:57:19

0001 #include "Alignment/OfflineValidation/interface/SmartSelectionMonitor.h"
0002 
0003 // add new histogram
0004 TH1 *SmartSelectionMonitor::addHistogram(TH1 *h, std::string histo) {
0005   if (!h->GetDefaultSumw2())
0006     h->Sumw2();
0007   if (!hasBaseHisto(histo)) {
0008     allMonitors_[histo] = new std::map<std::string, TH1 *>;
0009   }
0010   (*allMonitors_[histo])["all"] = h;
0011   return (*allMonitors_[histo])["all"];
0012 }
0013 
0014 TH1 *SmartSelectionMonitor::addHistogram(TH1 *h) {
0015   if (h == nullptr)
0016     return nullptr;
0017   return addHistogram(h, h->GetName());
0018 }
0019 
0020 // takes care of filling an histogram
0021 bool SmartSelectionMonitor::fillHisto(std::string name, std::string tag, double val, double weight, bool useBinWidth) {
0022   TH1 *h = getHisto(name, tag);
0023   if (h == nullptr)
0024     return false;
0025   if (useBinWidth) {
0026     int ibin = h->FindBin(val);
0027     double width = h->GetBinWidth(ibin);
0028     weight /= width;
0029   }
0030   h->Fill(val, weight);
0031   return true;
0032 }
0033 
0034 bool SmartSelectionMonitor::fillHisto(
0035     std::string name, std::vector<std::string> tags, double val, double weight, bool useBinWidth) {
0036   for (unsigned int i = 0; i < tags.size(); i++) {
0037     fillHisto(name, tags[i], val, weight, useBinWidth);
0038   }
0039   return true;
0040 }
0041 
0042 bool SmartSelectionMonitor::fillHisto(
0043     std::string name, std::vector<std::string> tags, double val, std::vector<double> weights, bool useBinWidth) {
0044   for (unsigned int i = 0; i < tags.size(); i++) {
0045     fillHisto(name, tags[i], val, weights[i], useBinWidth);
0046   }
0047   return true;
0048 }
0049 
0050 // takes care of filling a 2d histogram
0051 bool SmartSelectionMonitor::fillHisto(
0052     std::string name, std::string tag, double valx, double valy, double weight, bool useBinWidth) {
0053   TH2 *h = (TH2 *)getHisto(name, tag);
0054   if (h == nullptr)
0055     return false;
0056   if (useBinWidth) {
0057     int ibin = h->FindBin(valx, valy);
0058     double width = h->GetBinWidth(ibin);
0059     weight /= width;
0060   }
0061   h->Fill(valx, valy, weight);
0062   return true;
0063 }
0064 
0065 bool SmartSelectionMonitor::fillHisto(
0066     std::string name, std::vector<std::string> tags, double valx, double valy, double weight, bool useBinWidth) {
0067   for (unsigned int i = 0; i < tags.size(); i++) {
0068     fillHisto(name, tags[i], valx, valy, weight, useBinWidth);
0069   }
0070   return true;
0071 }
0072 
0073 bool SmartSelectionMonitor::fillHisto(std::string name,
0074                                       std::vector<std::string> tags,
0075                                       double valx,
0076                                       double valy,
0077                                       std::vector<double> weights,
0078                                       bool useBinWidth) {
0079   for (unsigned int i = 0; i < tags.size(); i++) {
0080     fillHisto(name, tags[i], valx, valy, weights[i], useBinWidth);
0081   }
0082   return true;
0083 }
0084 
0085 // takes care of filling a profile
0086 bool SmartSelectionMonitor::fillProfile(std::string name, std::string tag, double valx, double valy, double weight) {
0087   TProfile *h = (TProfile *)getHisto(name, tag);
0088   if (h == nullptr)
0089     return false;
0090   h->Fill(valx, valy, weight);
0091   return true;
0092 }
0093 
0094 bool SmartSelectionMonitor::fillProfile(
0095     std::string name, std::vector<std::string> tags, double valx, double valy, double weight) {
0096   for (unsigned int i = 0; i < tags.size(); i++) {
0097     fillProfile(name, tags[i], valx, valy, weight);
0098   }
0099   return true;
0100 }
0101 
0102 bool SmartSelectionMonitor::fillProfile(
0103     std::string name, std::vector<std::string> tags, double valx, double valy, std::vector<double> weights) {
0104   for (unsigned int i = 0; i < tags.size(); i++) {
0105     fillProfile(name, tags[i], valx, valy, weights[i]);
0106   }
0107   return true;
0108 }