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;
51 
52  if (is1D) {
53  h_diff = h_diff_->getTH1F();
54  h1 = h1_->getTH1F();
55  h2 = h2_->getTH1F();
56  } else if (is2D) {
57  h_diff = h_diff_->getTH2F();
58  h1 = h1_->getTH2F();
59  h2 = h2_->getTH2F();
60  }
61  else if (isProfile){
62  h_diff = h_diff_->getTProfile();
63  h1 = h1_->getTProfile();
64  h2 = h2_->getTProfile();
65  } else {
66  edm::LogWarning("L1TDiffHarvesting::L1TDiffPlotHandler::computeDiff")
67  << "Unknown histogram type. Quitting booking"
68  << std::endl;
69 
70  return;
71  }
72  h_diff->Add(h1);
73  h_diff->Add(h2, -1);
74  // if histograms are identical h_diff will have 0 entries -> not good to check if anything happened
75  // let's fix it
76  h_diff->SetEntries(h1->GetEntries() + h2->GetEntries());
77 }
78 
80 {
81  std::string h1Name = dir1_ + "/" + plotName_;
82  std::string h2Name = dir2_ + "/" + plotName_;
83  h1_ = igetter.get(h1Name);
84  h2_ = igetter.get(h2Name);
85 
86  if (!h1_ || !h2_) {
87  edm::LogWarning("L1TDiffHarvesting::L1TDiffPlotHandler::loadHistograms")
88  << (!h1_ && !h2_ ? h1Name + " && " + h2Name : !h1_ ? h1Name : h2Name) << " not gettable. Quitting booking"
89  << std::endl;
90 
91  return;
92  }
93 
94  histType1_ = h1_->kind();
95  histType2_ = h2_->kind();
96 
97 }
98 
100 {
102  edm::LogWarning("L1TDiffHarvesting::L1TDiffPlotHandler::isValid") << " Could not find a supported histogram type"
103  << std::endl;
104  return false;
105  }
106  if (histType1_ != histType2_) {
107  edm::LogWarning("L1TDiffHarvesting::L1TDiffPlotHandler::isValid")
108  << " Histogram 1 and 2 have different histogram types" << std::endl;
109  return false;
110  }
111  return true;
112 }
113 
115 {
116  ibooker.setCurrentFolder(outputDir_);
117 
121 
122  if (is1D) {
123  TH1F* h1 = h1_->getTH1F();
124  double min = h1->GetXaxis()->GetXmin();
125  double max = h1->GetXaxis()->GetXmax();
126  int nBins = h1->GetNbinsX();
127  h_diff_ = ibooker.book1D(plotName_, plotName_, nBins, min, max);
128  } else if (is2D) {
129  TH2F* h1 = h1_->getTH2F();
130  double minX = h1->GetXaxis()->GetXmin();
131  double maxX = h1->GetXaxis()->GetXmax();
132  double minY = h1->GetYaxis()->GetXmin();
133  double maxY = h1->GetYaxis()->GetXmax();
134  int nBinsX = h1->GetNbinsX();
135  int nBinsY = h1->GetNbinsY();
136 
137  h_diff_ = ibooker.book2D(plotName_, plotName_, nBinsX, minX, maxX, nBinsY, minY, maxY);
138  } else if (isProfile) {
139  TProfile* h1 = h1_->getTProfile();
140  double minX = h1->GetXaxis()->GetXmin();
141  double maxX = h1->GetXaxis()->GetXmax();
142  double minY = h1->GetYaxis()->GetXmin();
143  double maxY = h1->GetYaxis()->GetXmax();
144  int nBins = h1->GetNbinsX();
145  h_diff_ = ibooker.bookProfile(plotName_, plotName_, nBins, minX, maxX, minY, maxY);
146  } else {
147  edm::LogWarning("L1TDiffHarvesting::L1TDiffPlotHandler::bookDiff")
148  << "Unknown histogram type. Quitting booking"
149  << std::endl;
150 
151  return;
152  }
153 
154 }
155 
157  plotHandlers_()
158 {
159  using namespace std;
160  for (auto plotConfig : ps.getUntrackedParameter < std::vector<edm::ParameterSet> > ("plotCfgs")) {
161  vector < string > plots = plotConfig.getUntrackedParameter < vector < string >> ("plots");
162  for (auto plot : plots) {
163  plotHandlers_.push_back(L1TDiffPlotHandler(plotConfig, plot));
164  }
165  }
166 }
167 
169 {
170 
171 }
172 
174 {
175  edm::LogInfo("L1TEfficiencyHarvesting") << "Called endRun." << std::endl;
176 
177  for (auto plotHandler : plotHandlers_) {
178  plotHandler.computeDiff(ibooker, igetter);
179  }
180 }
181 
183 
184 } // l1t
185 } // dqmoffline
TProfile * getTProfile() const
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 * bookProfile(Args &&...args)
Definition: DQMStore.h:113
TH1F * getTH1F() const
delete x;
Definition: CaloConfig.h:22
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:268
bool is2D(HitType hitType)
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:106
T min(T a, T b)
Definition: MathUtil.h:58
void computeDiff(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter)
TH2F * getTH2F() const
MonitorElement * get(std::string const &path)
Definition: DQMStore.cc:303
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:109
Kind kind() const
Get the type of the monitor element.