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 
21  : dir1_(handler.dir1_),
22  dir2_(handler.dir2_),
23  outputDir_(handler.outputDir_),
24  plotName_(handler.plotName_),
25  h1_(),
26  h2_(),
27  h_diff_(),
28  histType1_(),
29  histType2_() {}
30 
32  loadHistograms(igetter);
33  if (!isValid()) {
34  return;
35  }
36  bookDiff(ibooker);
37 
38  TH1 *h_diff;
39  TH1 *h1;
40  TH1 *h2;
43  bool isProfile(histType1_ == MonitorElement::Kind::TPROFILE);
44 
45  if (is1D) {
46  h_diff = h_diff_->getTH1F();
47  h1 = h1_->getTH1F();
48  h2 = h2_->getTH1F();
49  } else if (is2D) {
50  h_diff = h_diff_->getTH2F();
51  h1 = h1_->getTH2F();
52  h2 = h2_->getTH2F();
53  } else if (isProfile) {
54  h_diff = h_diff_->getTProfile();
55  h1 = h1_->getTProfile();
56  h2 = h2_->getTProfile();
57  } else {
58  edm::LogWarning("L1TDiffHarvesting::L1TDiffPlotHandler::computeDiff")
59  << "Unknown histogram type. Quitting booking" << std::endl;
60 
61  return;
62  }
63  h_diff->Add(h1);
64  h_diff->Add(h2, -1);
65  // if histograms are identical h_diff will have 0 entries -> not good to check if anything happened
66  // let's fix it
67  h_diff->SetEntries(h1->GetEntries() + h2->GetEntries());
68  }
69 
71  std::string h1Name = dir1_ + "/" + plotName_;
72  std::string h2Name = dir2_ + "/" + plotName_;
73  h1_ = igetter.get(h1Name);
74  h2_ = igetter.get(h2Name);
75 
76  if (!h1_ || !h2_) {
77  edm::LogWarning("L1TDiffHarvesting::L1TDiffPlotHandler::loadHistograms")
78  << (!h1_ && !h2_ ? h1Name + " && " + h2Name : !h1_ ? h1Name : h2Name) << " not gettable. Quitting booking"
79  << std::endl;
80 
81  return;
82  }
83 
84  histType1_ = h1_->kind();
85  histType2_ = h2_->kind();
86  }
87 
90  edm::LogWarning("L1TDiffHarvesting::L1TDiffPlotHandler::isValid")
91  << " Could not find a supported histogram type" << std::endl;
92  return false;
93  }
94  if (histType1_ != histType2_) {
95  edm::LogWarning("L1TDiffHarvesting::L1TDiffPlotHandler::isValid")
96  << " Histogram 1 and 2 have different histogram types" << std::endl;
97  return false;
98  }
99  return true;
100  }
101 
103  ibooker.setCurrentFolder(outputDir_);
104 
107  bool isProfile(histType1_ == MonitorElement::Kind::TPROFILE);
108 
109  if (is1D) {
110  TH1F *h1 = h1_->getTH1F();
111  double min = h1->GetXaxis()->GetXmin();
112  double max = h1->GetXaxis()->GetXmax();
113  int nBins = h1->GetNbinsX();
114  h_diff_ = ibooker.book1D(plotName_, plotName_, nBins, min, max);
115  } else if (is2D) {
116  TH2F *h1 = h1_->getTH2F();
117  double minX = h1->GetXaxis()->GetXmin();
118  double maxX = h1->GetXaxis()->GetXmax();
119  double minY = h1->GetYaxis()->GetXmin();
120  double maxY = h1->GetYaxis()->GetXmax();
121  int nBinsX = h1->GetNbinsX();
122  int nBinsY = h1->GetNbinsY();
123 
124  h_diff_ = ibooker.book2D(plotName_, plotName_, nBinsX, minX, maxX, nBinsY, minY, maxY);
125  } else if (isProfile) {
126  TProfile *h1 = h1_->getTProfile();
127  double minX = h1->GetXaxis()->GetXmin();
128  double maxX = h1->GetXaxis()->GetXmax();
129  double minY = h1->GetYaxis()->GetXmin();
130  double maxY = h1->GetYaxis()->GetXmax();
131  int nBins = h1->GetNbinsX();
132  h_diff_ = ibooker.bookProfile(plotName_, plotName_, nBins, minX, maxX, minY, maxY);
133  } else {
134  edm::LogWarning("L1TDiffHarvesting::L1TDiffPlotHandler::bookDiff")
135  << "Unknown histogram type. Quitting booking" << std::endl;
136 
137  return;
138  }
139  }
140 
142  using namespace std;
143  for (auto plotConfig : ps.getUntrackedParameter<std::vector<edm::ParameterSet>>("plotCfgs")) {
144  vector<string> plots = plotConfig.getUntrackedParameter<vector<string>>("plots");
145  for (auto plot : plots) {
146  plotHandlers_.push_back(L1TDiffPlotHandler(plotConfig, plot));
147  }
148  }
149  }
150 
152 
154  edm::LogInfo("L1TEfficiencyHarvesting") << "Called endRun." << std::endl;
155 
156  for (auto plotHandler : plotHandlers_) {
157  plotHandler.computeDiff(ibooker, igetter);
158  }
159  }
160 
162 
163  } // namespace l1t
164 } // namespace dqmoffline
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX)
Definition: DQMStore.cc:239
T getUntrackedParameter(std::string const &, T const &) const
L1TDiffPlotHandler(const edm::ParameterSet &ps, std::string plotName)
virtual TH2F * getTH2F() const
void dqmEndJob(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter) override
L1TDiffHarvesting(const edm::ParameterSet &ps)
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:418
virtual TH1F * getTH1F() const
Kind kind() const
Get the type of the monitor element.
delete x;
Definition: CaloConfig.h:22
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
bool is2D(HitType hitType)
MonitorElement * bookProfile(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, char const *option="s")
Definition: DQMStore.cc:333
T min(T a, T b)
Definition: MathUtil.h:58
void computeDiff(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter)
virtual TProfile * getTProfile() const
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Definition: DQMStore.cc:266
MonitorElement * get(std::string const &path)
Definition: DQMStore.cc:437