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;
41  bool is1D(histType1_ == MonitorElement::Kind::TH1F || histType1_ == MonitorElement::Kind::TH1D);
42  bool is2D(histType1_ == MonitorElement::Kind::TH2F || histType1_ == MonitorElement::Kind::TH2D);
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
79  : !h1_ ? h1Name
80  : h2Name)
81  << " not gettable. Quitting booking" << std::endl;
82 
83  return;
84  }
85 
86  histType1_ = h1_->kind();
87  histType2_ = h2_->kind();
88  }
89 
91  if (histType1_ == MonitorElement::Kind::INVALID) {
92  edm::LogWarning("L1TDiffHarvesting::L1TDiffPlotHandler::isValid")
93  << " Could not find a supported histogram type" << std::endl;
94  return false;
95  }
96  if (histType1_ != histType2_) {
97  edm::LogWarning("L1TDiffHarvesting::L1TDiffPlotHandler::isValid")
98  << " Histogram 1 and 2 have different histogram types" << std::endl;
99  return false;
100  }
101  return true;
102  }
103 
105  ibooker.setCurrentFolder(outputDir_);
106 
107  bool is1D(histType1_ == MonitorElement::Kind::TH1F || histType1_ == MonitorElement::Kind::TH1D);
108  bool is2D(histType1_ == MonitorElement::Kind::TH2F || histType1_ == MonitorElement::Kind::TH2D);
109  bool isProfile(histType1_ == MonitorElement::Kind::TPROFILE);
110 
111  if (is1D) {
112  TH1F *h1 = h1_->getTH1F();
113  double min = h1->GetXaxis()->GetXmin();
114  double max = h1->GetXaxis()->GetXmax();
115  int nBins = h1->GetNbinsX();
116  h_diff_ = ibooker.book1D(plotName_, plotName_, nBins, min, max);
117  } else if (is2D) {
118  TH2F *h1 = h1_->getTH2F();
119  double minX = h1->GetXaxis()->GetXmin();
120  double maxX = h1->GetXaxis()->GetXmax();
121  double minY = h1->GetYaxis()->GetXmin();
122  double maxY = h1->GetYaxis()->GetXmax();
123  int nBinsX = h1->GetNbinsX();
124  int nBinsY = h1->GetNbinsY();
125 
126  h_diff_ = ibooker.book2D(plotName_, plotName_, nBinsX, minX, maxX, nBinsY, minY, maxY);
127  } else if (isProfile) {
128  TProfile *h1 = h1_->getTProfile();
129  double minX = h1->GetXaxis()->GetXmin();
130  double maxX = h1->GetXaxis()->GetXmax();
131  double minY = h1->GetYaxis()->GetXmin();
132  double maxY = h1->GetYaxis()->GetXmax();
133  int nBins = h1->GetNbinsX();
134  h_diff_ = ibooker.bookProfile(plotName_, plotName_, nBins, minX, maxX, minY, maxY);
135  } else {
136  edm::LogWarning("L1TDiffHarvesting::L1TDiffPlotHandler::bookDiff")
137  << "Unknown histogram type. Quitting booking" << std::endl;
138 
139  return;
140  }
141  }
142 
144  using namespace std;
145  for (const auto &plotConfig : ps.getUntrackedParameter<std::vector<edm::ParameterSet>>("plotCfgs")) {
146  vector<string> plots = plotConfig.getUntrackedParameter<vector<string>>("plots");
147  for (const auto &plot : plots) {
148  plotHandlers_.push_back(L1TDiffPlotHandler(plotConfig, plot));
149  }
150  }
151  }
152 
154 
156  edm::LogInfo("L1TEfficiencyHarvesting") << "Called endRun." << std::endl;
157 
158  for (auto plotHandler : plotHandlers_) {
159  plotHandler.computeDiff(ibooker, igetter);
160  }
161  }
162 
164 
165  } // namespace l1t
166 } // namespace dqmoffline
L1TDiffPlotHandler(const edm::ParameterSet &ps, std::string plotName)
virtual TProfile * getTProfile() const
const bool isValid(const Frame &aFrame, const FrameQuality &aQuality, const uint16_t aExpectedPos)
void dqmEndJob(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter) override
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
L1TDiffHarvesting(const edm::ParameterSet &ps)
delete x;
Definition: CaloConfig.h:22
T getUntrackedParameter(std::string const &, T const &) const
virtual TH2F * getTH2F() const
MonitorElement * bookProfile(TString const &name, TString const &title, int nchX, double lowX, double highX, int, double lowY, double highY, char const *option="s", FUNC onbooking=NOOP())
Definition: DQMStore.h:399
bool is2D(HitType hitType)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void computeDiff(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter)
Log< level::Info, false > LogInfo
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:697
Log< level::Warning, false > LogWarning
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98