Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
#include "DQMOffline/RecoB/interface/TaggingVariablePlotter.h"

using namespace std;
using namespace edm;
using namespace reco;

TaggingVariablePlotter::VariableConfig::VariableConfig(const string &name,
                                                       const ParameterSet &pSet,
                                                       const string &category,
                                                       const string &label,
                                                       unsigned int mc,
                                                       DQMStore::IBooker &ibook)
    : var(getTaggingVariableName(name)),
      nBins(pSet.getParameter<unsigned int>("nBins")),
      min(pSet.getParameter<double>("min")),
      max(pSet.getParameter<double>("max")) {
  if (var == btau::lastTaggingVariable)
    throw cms::Exception("Configuration") << "Tagging variable \"" << name << "\" does not exist." << endl;

  if (pSet.exists("logScale"))
    logScale = pSet.getParameter<bool>("logScale");
  else
    logScale = false;

  std::vector<unsigned int> indices;
  if (pSet.exists("indices"))
    indices = pSet.getParameter<vector<unsigned int>>("indices");
  else
    indices.push_back(0);

  for (const unsigned int iter : indices) {
    Plot plot;
    plot.histo = std::make_shared<FlavourHistograms<double>>(
        name + (iter ? Form("%d", iter) : "") + (category.empty() ? "_" + label : ("_" + category) + "_" + label),
        TaggingVariableDescription[var],
        nBins,
        min,
        max,
        false,
        logScale,
        true,
        "b",
        label,
        mc,
        ibook);
    plot.index = iter;
    plots.push_back(plot);
  }
}

TaggingVariablePlotter::TaggingVariablePlotter(const std::string &tagName,
                                               const EtaPtBin &etaPtBin,
                                               const ParameterSet &pSet,
                                               unsigned int mc,
                                               bool willFinalize,
                                               DQMStore::IBooker &ibook,
                                               const string &category)
    : BaseTagInfoPlotter(tagName, etaPtBin), mcPlots_(mc) {
  const std::string tagVarDir(theExtensionString.substr(1));

  if (willFinalize)
    return;

  const vector<string> &pSets = pSet.getParameterNames();
  for (const std::string &iter : pSets) {
    VariableConfig var(iter, pSet.getParameter<ParameterSet>(iter), category, tagVarDir, mcPlots_, ibook);
    variables.push_back(var);
  }
}

TaggingVariablePlotter::~TaggingVariablePlotter() {}

void TaggingVariablePlotter::analyzeTag(const BaseTagInfo *baseTagInfo, double jec, int jetFlavour, float w /*=1*/) {
  analyzeTag(baseTagInfo->taggingVariables(), jetFlavour, w);
}

void TaggingVariablePlotter::analyzeTag(const TaggingVariableList &vars, int jetFlavour, float w /*=1*/) {
  for (const VariableConfig &cfg : variables) {
    const std::vector<TaggingValue> values(vars.getList(cfg.var, false));
    if (values.empty())
      continue;

    const unsigned int &size = values.size();

    for (const VariableConfig::Plot &plot : cfg.plots) {
      if (plot.index == 0) {
        for (const TaggingValue &val : values)
          plot.histo->fill(jetFlavour, val, w);
      } else if (plot.index - 1 < size)
        plot.histo->fill(jetFlavour, values[plot.index - 1], w);
    }
  }
}