CMS 3D CMS Logo

L1TDiffHarvesting.cc
Go to the documentation of this file.
2 
5 
6 namespace dqmoffline {
7 namespace l1t {
8 
10  dir1_(ps.getUntrackedParameter < std::string > ("dir1")),
11  dir2_(ps.getUntrackedParameter < std::string > ("dir2")),
12  outputDir_(ps.getUntrackedParameter < std::string > ("outputDir", dir1_)),
13  plotName_(plotName),
14  h1_(),
15  h2_(),
16  h_diff_(),
17  histType1_(),
18  histType2_()
19 {
20 
21 }
22 
24  dir1_(handler.dir1_),
25  dir2_(handler.dir2_),
26  outputDir_(handler.outputDir_),
27  plotName_(handler.plotName_),
28  h1_(),
29  h2_(),
30  h_diff_(),
31  histType1_(),
32  histType2_()
33 {
34 
35 }
36 
38 {
39  loadHistograms(igetter);
40  if (!isValid()) {
41  return;
42  }
43  bookDiff(ibooker);
44 
45  TH1* h_diff;
46  TH1* h1;
47  TH1* h2;
49 
50  if (is1D) {
51  h_diff = h_diff_->getTH1F();
52  h1 = h1_->getTH1F();
53  h2 = h2_->getTH1F();
54  } else { // TH2
55  h_diff = h_diff_->getTH2F();
56  h1 = h1_->getTH2F();
57  h2 = h2_->getTH2F();
58  }
59  h_diff->Add(h1);
60  h_diff->Add(h2, -1);
61  // if histograms are identical h_diff will have 0 entries -> not good to check if anything happened
62  // let's fix it
63  h_diff->SetEntries(h1->GetEntries() + h2->GetEntries());
64 }
65 
67 {
68  std::string h1Name = dir1_ + "/" + plotName_;
69  std::string h2Name = dir2_ + "/" + plotName_;
70  h1_ = igetter.get(h1Name);
71  h2_ = igetter.get(h2Name);
72 
73  if (!h1_ || !h2_) {
74  edm::LogError("L1TDiffHarvesting::L1TDiffPlotHandler::loadHistograms")
75  << (!h1_ && !h2_ ? h1Name + " && " + h2Name : !h1_ ? h1Name : h2Name) << " not gettable. Quitting booking"
76  << std::endl;
77 
78  return;
79  }
80 
81  histType1_ = h1_->kind();
82  histType2_ = h2_->kind();
83 
84 }
85 
87 {
89  edm::LogError("L1TDiffHarvesting::L1TDiffPlotHandler::isValid") << " Could not find a supported histogram type"
90  << std::endl;
91  return false;
92  }
93  if (histType1_ != histType2_) {
94  edm::LogError("L1TDiffHarvesting::L1TDiffPlotHandler::isValid")
95  << " Histogram 1 and 2 have different histogram types" << std::endl;
96  return false;
97  }
98  return true;
99 }
100 
102 {
103  ibooker.setCurrentFolder(outputDir_);
104 
106  if (is1D) {
107  TH1F* h1 = h1_->getTH1F();
108  double min = h1->GetXaxis()->GetXmin();
109  double max = h1->GetXaxis()->GetXmax();
110  int nBins = h1->GetNbinsX();
111  h_diff_ = ibooker.book1D(plotName_, plotName_, nBins, min, max);
112  } else { // TH2
113  TH2F* h1 = h1_->getTH2F();
114  double minX = h1->GetXaxis()->GetXmin();
115  double maxX = h1->GetXaxis()->GetXmax();
116  double minY = h1->GetYaxis()->GetXmin();
117  double maxY = h1->GetYaxis()->GetXmax();
118  int nBinsX = h1->GetNbinsX();
119  int nBinsY = h1->GetNbinsY();
120 
121  h_diff_ = ibooker.book2D(plotName_, plotName_, nBinsX, minX, maxX, nBinsY, minY, maxY);
122  }
123 
124 }
125 
127  plotHandlers_()
128 {
129  using namespace std;
130  for (auto plotConfig : ps.getUntrackedParameter < std::vector<edm::ParameterSet> > ("plotCfgs")) {
131  vector < string > plots = plotConfig.getUntrackedParameter < vector < string >> ("plots");
132  for (auto plot : plots) {
133  plotHandlers_.push_back(L1TDiffPlotHandler(plotConfig, plot));
134  }
135  }
136 }
137 
139 {
140 
141 }
142 
144 {
145  edm::LogInfo("L1TEfficiencyHarvesting") << "Called endRun." << std::endl;
146 
147  for (auto plotHandler : plotHandlers_) {
148  plotHandler.computeDiff(ibooker, igetter);
149  }
150 }
151 
153  edm::EventSetup const& c)
154 {
155 }
156 
158 
159 } // l1t
160 } // dqmoffline
virtual void dqmEndLuminosityBlock(DQMStore::IGetter &igetter, edm::LuminosityBlock const &lumiBlock, edm::EventSetup const &c)
T getUntrackedParameter(std::string const &, T const &) const
L1TDiffPlotHandler(const edm::ParameterSet &ps, std::string plotName)
void dqmEndJob(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter) override
L1TDiffHarvesting(const edm::ParameterSet &ps)
MonitorElement * get(const std::string &path)
Definition: DQMStore.cc:305
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
delete x;
Definition: CaloConfig.h:22
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
T min(T a, T b)
Definition: MathUtil.h:58
Kind kind(void) const
Get the type of the monitor element.
void computeDiff(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter)
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:277
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:133
TH1F * getTH1F(void) const
TH2F * getTH2F(void) const