CMS 3D CMS Logo

TotemRPDQMHarvester.cc
Go to the documentation of this file.
1 /****************************************************************************
2 *
3 * This is a part of TotemDQM and TOTEM offline software.
4 * Authors:
5 * Jan Kašpar (jan.kaspar@gmail.com)
6 *
7 ****************************************************************************/
8 
12 
15 
17 
18 //----------------------------------------------------------------------------------------------------
19 
21 public:
23  ~TotemRPDQMHarvester() override;
24 
25 protected:
27 
30  const edm::LuminosityBlock &,
31  const edm::EventSetup &) override;
32 
33 private:
34  void MakeHitNumberRatios(unsigned int id, DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter);
35 
36  void MakePlaneEfficiencyHistograms(unsigned int id,
37  DQMStore::IBooker &ibooker,
38  DQMStore::IGetter &igetter,
39  bool &rpPlotInitialized);
40 };
41 
42 //----------------------------------------------------------------------------------------------------
43 //----------------------------------------------------------------------------------------------------
44 
45 using namespace std;
46 using namespace edm;
47 
48 //----------------------------------------------------------------------------------------------------
49 
51 
52 //----------------------------------------------------------------------------------------------------
53 
55 
56 //----------------------------------------------------------------------------------------------------
57 
59  // get source histogram
60  string path;
62 
63  MonitorElement *activity = igetter.get(path + "/activity in planes (2D)");
64 
65  if (!activity)
66  return;
67 
68  // book new histogram, if not yet done
69  const string hit_ratio_name = "hit ratio in hot spot";
70  MonitorElement *hit_ratio = igetter.get(path + "/" + hit_ratio_name);
71 
72  if (hit_ratio == nullptr) {
73  ibooker.setCurrentFolder(path);
74  string title;
76  hit_ratio = ibooker.book1D(hit_ratio_name, title + ";plane;N_hits(320<strip<440) / N_hits(all)", 10, -0.5, 9.5);
77  } else {
78  hit_ratio->getTH1F()->Reset();
79  }
80 
81  // calculate ratios
82  TAxis *y_axis = activity->getTH2F()->GetYaxis();
83  for (int bix = 1; bix <= activity->getNbinsX(); ++bix) {
84  double S_full = 0., S_sel = 0.;
85  for (int biy = 1; biy <= activity->getNbinsY(); ++biy) {
86  double c = activity->getBinContent(bix, biy);
87  double s = y_axis->GetBinCenter(biy);
88 
89  S_full += c;
90 
91  if (s > 320. && s < 440.)
92  S_sel += c;
93  }
94 
95  double r = (S_full > 0.) ? S_sel / S_full : 0.;
96 
97  hit_ratio->setBinContent(bix, r);
98  }
99 }
100 
101 //----------------------------------------------------------------------------------------------------
102 
104  DQMStore::IBooker &ibooker,
105  DQMStore::IGetter &igetter,
106  bool &rpPlotInitialized) {
107  TotemRPDetId detId(id);
108 
109  // get source histograms
110  string path;
112 
113  MonitorElement *efficiency_num = igetter.get(path + "/efficiency num");
114  MonitorElement *efficiency_den = igetter.get(path + "/efficiency den");
115 
116  if (!efficiency_num || !efficiency_den)
117  return;
118 
119  // book new plane histogram, if not yet done
120  const string efficiency_name = "efficiency";
121  MonitorElement *efficiency = igetter.get(path + "/" + efficiency_name);
122 
123  if (efficiency == nullptr) {
124  string title;
126  TAxis *axis = efficiency_den->getTH1()->GetXaxis();
127  ibooker.setCurrentFolder(path);
128  efficiency = ibooker.book1D(
129  efficiency_name, title + ";track position (mm)", axis->GetNbins(), axis->GetXmin(), axis->GetXmax());
130  } else {
131  efficiency->getTH1F()->Reset();
132  }
133 
134  // book new RP histogram, if not yet done
135  CTPPSDetId rpId = detId.rpId();
137  const string rp_efficiency_name = "plane efficiency";
138  MonitorElement *rp_efficiency = igetter.get(path + "/" + rp_efficiency_name);
139 
140  if (rp_efficiency == nullptr) {
141  string title;
143  TAxis *axis = efficiency_den->getTH1()->GetXaxis();
144  ibooker.setCurrentFolder(path);
145  rp_efficiency = ibooker.book2D(rp_efficiency_name,
146  title + ";plane;track position (mm)",
147  10,
148  -0.5,
149  9.5,
150  axis->GetNbins(),
151  axis->GetXmin(),
152  axis->GetXmax());
153  rpPlotInitialized = true;
154  } else {
155  if (!rpPlotInitialized)
156  rp_efficiency->getTH2F()->Reset();
157  rpPlotInitialized = true;
158  }
159 
160  // calculate and fill efficiencies
161  for (signed int bi = 1; bi <= efficiency->getNbinsX(); bi++) {
162  double num = efficiency_num->getBinContent(bi);
163  double den = efficiency_den->getBinContent(bi);
164 
165  if (den > 0) {
166  double p = num / den;
167  double p_unc = sqrt(p * (1. - p) / den);
168  efficiency->setBinContent(bi, p);
169  efficiency->setBinError(bi, p_unc);
170 
171  int pl_bi = detId.plane() + 1;
172  rp_efficiency->setBinContent(pl_bi, bi, p);
173  } else {
174  efficiency->setBinContent(bi, 0.);
175  }
176  }
177 }
178 
179 //----------------------------------------------------------------------------------------------------
180 
182  DQMStore::IGetter &igetter,
183  const edm::LuminosityBlock &,
184  const edm::EventSetup &) {
185  // loop over arms
186  for (unsigned int arm = 0; arm < 2; arm++) {
187  // loop over stations
188  for (unsigned int st = 0; st < 3; st += 2) {
189  // loop over RPs
190  for (unsigned int rp = 0; rp < 6; ++rp) {
191  if (st == 2) {
192  // unit 220-nr is not equipped
193  if (rp <= 2)
194  continue;
195 
196  // RP 220-fr-hr contains pixels
197  if (rp == 3)
198  continue;
199  }
200 
201  TotemRPDetId rpId(arm, st, rp);
202 
203  MakeHitNumberRatios(rpId, ibooker, igetter);
204 
205  bool rpPlotInitialized = false;
206 
207  // loop over planes
208  for (unsigned int pl = 0; pl < 10; ++pl) {
209  TotemRPDetId plId(arm, st, rp, pl);
210 
211  MakePlaneEfficiencyHistograms(plId, ibooker, igetter, rpPlotInitialized);
212  }
213  }
214  }
215  }
216 }
217 
218 //----------------------------------------------------------------------------------------------------
219 
Detector ID class for TOTEM Si strip detectors.
Definition: TotemRPDetId.h:30
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override
uint32_t plane() const
Definition: TotemRPDetId.h:46
virtual TH2F * getTH2F() const
void rpName(std::string &name, NameFlag flag=nFull) const
Definition: CTPPSDetId.h:134
CTPPSDetId rpId() const
Definition: CTPPSDetId.h:84
T sqrt(T t)
Definition: SSEVec.h:19
void MakeHitNumberRatios(unsigned int id, DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void dqmEndLuminosityBlock(DQMStore::IBooker &, DQMStore::IGetter &, const edm::LuminosityBlock &, const edm::EventSetup &) override
virtual int getNbinsY() const
get # of bins in Y-axis
virtual void setBinContent(int binx, double content)
set content of bin (1-D)
void planeName(std::string &name, NameFlag flag=nFull) const
Definition: TotemRPDetId.h:79
virtual TH1F * getTH1F() const
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:690
void MakePlaneEfficiencyHistograms(unsigned int id, DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter, bool &rpPlotInitialized)
Base class for CTPPS detector IDs.
Definition: CTPPSDetId.h:32
virtual TH1 * getTH1() const
HLT enums.
virtual int getNbinsX() const
get # of bins in X-axis
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
TotemRPDQMHarvester(const edm::ParameterSet &ps)
virtual double getBinContent(int binx) const
get content of bin (1-D)