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 : !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 
89  if (histType1_ == MonitorElement::Kind::INVALID) {
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 
105  bool is1D(histType1_ == MonitorElement::Kind::TH1F || histType1_ == MonitorElement::Kind::TH1D);
106  bool is2D(histType1_ == MonitorElement::Kind::TH2F || histType1_ == MonitorElement::Kind::TH2D);
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 (const auto &plotConfig : ps.getUntrackedParameter<std::vector<edm::ParameterSet>>("plotCfgs")) {
144  vector<string> plots = plotConfig.getUntrackedParameter<vector<string>>("plots");
145  for (const 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
MessageLogger.h
dqmoffline::l1t::L1TDiffHarvesting::L1TDiffPlotHandler::isValid
bool isValid() const
Definition: L1TDiffHarvesting.cc:88
min
T min(T a, T b)
Definition: MathUtil.h:58
MonitorElementData::Kind::TH1F
dqm::implementation::NavigatorBase::setCurrentFolder
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
dqmoffline::l1t::L1TDiffHarvesting::L1TDiffPlotHandler::computeDiff
void computeDiff(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter)
Definition: L1TDiffHarvesting.cc:31
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
plotFactory.plot
plot
Definition: plotFactory.py:109
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
HGVHistoProducerAlgoBlock_cfi.minX
minX
Definition: HGVHistoProducerAlgoBlock_cfi.py:153
MonitorElementData::Kind::TH2D
dqmoffline::l1t::L1TDiffHarvesting::plotHandlers_
L1TDiffPlotHandlers plotHandlers_
Definition: L1TDiffHarvesting.h:50
MonitorElementData::Kind::TH2F
dqmoffline::l1t::L1TDiffHarvesting::dqmEndJob
void dqmEndJob(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter) override
Definition: L1TDiffHarvesting.cc:153
MakerMacros.h
L1TDiffHarvesting.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
L1TEGammaDiff_cfi.plotName
plotName
Definition: L1TEGammaDiff_cfi.py:21
dqm::implementation::IBooker::bookProfile
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:322
dqm::legacy::MonitorElement::getTProfile
virtual TProfile * getTProfile() const
Definition: MonitorElement.h:506
seedmultiplicitymonitor_newtracking_cfi.nBins
nBins
Definition: seedmultiplicitymonitor_newtracking_cfi.py:8
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ParameterSet
Definition: ParameterSet.h:47
HLTObjectsMonitor_cfi.plots
plots
Definition: HLTObjectsMonitor_cfi.py:17
dqmoffline::l1t::L1TDiffHarvesting::L1TDiffPlotHandler
Definition: L1TDiffHarvesting.h:26
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
l1t
delete x;
Definition: CaloConfig.h:22
dqmoffline
Definition: HistDefinition.h:48
HGVHistoProducerAlgoBlock_cfi.minY
minY
Definition: HGVHistoProducerAlgoBlock_cfi.py:158
MonitorElementData::Kind::TH1D
dqmoffline::l1t::L1TDiffHarvesting::L1TDiffPlotHandler::loadHistograms
void loadHistograms(DQMStore::IGetter &igetter)
Definition: L1TDiffHarvesting.cc:70
std
Definition: JetResolutionObject.h:76
MonitorElementData::Kind::INVALID
dqmoffline::l1t::L1TDiffHarvesting
Definition: L1TDiffHarvesting.h:17
dqm::implementation::IGetter
Definition: DQMStore.h:484
HGVHistoProducerAlgoBlock_cfi.maxY
maxY
Definition: HGVHistoProducerAlgoBlock_cfi.py:159
dqm::implementation::IBooker::book2D
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:177
fastTrackerRecHitType::is2D
bool is2D(HitType hitType)
Definition: FastTrackerRecHit.h:36
dqmoffline::l1t::L1TDiffHarvesting::L1TDiffHarvesting
L1TDiffHarvesting(const edm::ParameterSet &ps)
Definition: L1TDiffHarvesting.cc:141
dqmoffline::l1t::L1TDiffHarvesting::~L1TDiffHarvesting
~L1TDiffHarvesting() override
Definition: L1TDiffHarvesting.cc:151
dqm::implementation::IGetter::get
virtual MonitorElement * get(std::string const &fullpath) const
Definition: DQMStore.cc:651
dqm::implementation::IBooker
Definition: DQMStore.h:43
dqmoffline::l1t::L1TDiffHarvesting::L1TDiffPlotHandler::L1TDiffPlotHandler
L1TDiffPlotHandler(const edm::ParameterSet &ps, std::string plotName)
Definition: L1TDiffHarvesting.cc:9
dqmoffline::l1t::L1TDiffHarvesting::L1TDiffPlotHandler::bookDiff
void bookDiff(DQMStore::IBooker &ibooker)
Definition: L1TDiffHarvesting.cc:102
MonitorElementData::Kind::TPROFILE
dqm::implementation::IBooker::book1D
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
HGVHistoProducerAlgoBlock_cfi.maxX
maxX
Definition: HGVHistoProducerAlgoBlock_cfi.py:154
dqm::legacy::MonitorElement::getTH2F
virtual TH2F * getTH2F() const
Definition: MonitorElement.h:490