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