CMS 3D CMS Logo

PlotCombiner.cc
Go to the documentation of this file.
9 
10 #include "TH1F.h"
11 #include "TH2F.h"
12 
13 using namespace edm;
14 using namespace std;
15 
16 class PlotCombiner : public DQMEDHarvester {
17 public:
19  ~PlotCombiner() override;
20 
21 private:
23 
26 
27 protected:
28  void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override; //performed in the endJob
29 };
30 
32  : myDQMrootFolder(pset.getUntrackedParameter<string>("MyDQMrootFolder")),
33  plots(pset.getUntrackedParameter<VParameterSet>("Plots")) {}
34 
36  for (VParameterSet::const_iterator pset = plots.begin(); pset != plots.end(); pset++) {
37  makePlot(*pset, ibooker_, igetter_);
38  }
39 }
40 
42  //get hold of MEs
43  vector<string> inputMEnames = pset.getUntrackedParameter<vector<string> >("InputMEnames");
44  vector<string> inputLabels = pset.getUntrackedParameter<vector<string> >("InputLabels");
45  if (inputMEnames.size() != inputLabels.size()) {
46  LogDebug("HLTriggerOfflineHeavyFlavor") << "Number of labels must match the histos[0]ber of InputMEnames" << endl;
47  return;
48  }
49  vector<TH1 *> histos;
50  vector<TString> labels;
51  for (size_t i = 0; i < inputMEnames.size(); i++) {
52  string MEname = myDQMrootFolder + "/" + inputMEnames[i];
53  MonitorElement *ME = igetter_.get(MEname);
54  if (ME == nullptr) {
55  LogDebug("HLTriggerOfflineHeavyFlavor") << "Could not find ME: " << MEname << endl;
56  continue;
57  }
58  histos.push_back(ME->getTH1());
59  labels.push_back(inputLabels[i]);
60  }
61  if (histos.empty()) {
62  return;
63  }
64  //figure out the output directory name
65  string outputMEname = pset.getUntrackedParameter<string>("OutputMEname");
66  ;
67  string outputDir = myDQMrootFolder;
68  string::size_type slashPos = outputMEname.rfind('/');
69  if (string::npos != slashPos) {
70  outputDir += "/" + outputMEname.substr(0, slashPos);
71  outputMEname.erase(0, slashPos + 1);
72  }
73  ibooker_.setCurrentFolder(outputDir);
74  //create output ME
75  TH2F *output;
76  if (histos[0]->GetXaxis()->GetXbins()->GetSize() == 0) {
77  output = new TH2F(outputMEname.c_str(),
78  outputMEname.c_str(),
79  histos[0]->GetXaxis()->GetNbins(),
80  histos[0]->GetXaxis()->GetXmin(),
81  histos[0]->GetXaxis()->GetXmax(),
82  histos.size(),
83  0,
84  histos.size());
85  } else {
86  output = new TH2F(outputMEname.c_str(),
87  outputMEname.c_str(),
88  histos[0]->GetXaxis()->GetNbins(),
89  histos[0]->GetXaxis()->GetXbins()->GetArray(),
90  histos.size(),
91  0,
92  histos.size());
93  }
94  output->SetTitle(outputMEname.c_str());
95  output->SetXTitle(histos[0]->GetXaxis()->GetTitle());
96  output->SetStats(kFALSE);
97  output->SetOption("colztexte");
98  for (size_t i = 0; i < histos.size(); i++) {
99  for (int j = 1; j <= histos[0]->GetNbinsX(); j++) {
100  output->SetBinContent(j, i + 1, histos[i]->GetBinContent(j));
101  output->SetBinError(j, i + 1, histos[i]->GetBinError(j));
102  }
103  output->GetYaxis()->SetBinLabel(i + 1, labels[i]);
104  }
105  ibooker_.book2D(outputMEname, output);
106  delete output;
107 }
108 
110 
111 //define this as a plug-in
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
string myDQMrootFolder
Definition: PlotCombiner.cc:24
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::vector< ParameterSet > VParameterSet
Definition: ParameterSet.h:34
~PlotCombiner() override
uint16_t size_type
Definition: ME.h:11
void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override
Definition: PlotCombiner.cc:35
const VParameterSet plots
Definition: PlotCombiner.cc:25
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:212
virtual MonitorElement * get(std::string const &fullpath) const
Definition: DQMStore.cc:680
histos
Definition: combine.py:4
HLT enums.
void makePlot(const ParameterSet &pset, DQMStore::IBooker &, DQMStore::IGetter &)
Definition: PlotCombiner.cc:41
def makePlot(name, x, ys, ytitle, title=None, legends=None, ideal1=None, bounds={}, legendYmax=0.99)
PlotCombiner(const edm::ParameterSet &pset)
Definition: PlotCombiner.cc:31
#define LogDebug(id)