CMS 3D CMS Logo

GEMBaseValidation.h
Go to the documentation of this file.
1 #ifndef Validation_MuonGEMHits_GEMBaseValidation_h
2 #define Validation_MuonGEMHits_GEMBaseValidation_h
3 
13 
15 
16 #include "TMath.h"
17 #include "TDatabasePDG.h"
18 
20 public:
22  ~GEMBaseValidation() override = 0;
23  void analyze(const edm::Event& e, const edm::EventSetup&) override = 0;
24 
25 protected:
26  Int_t getDetOccBinX(Int_t num_layers, Int_t chamber_id, Int_t layer_id);
27  Bool_t isMuonSimHit(const PSimHit&);
28  Float_t toDegree(Float_t radian);
29  Int_t getPidIdx(Int_t pid);
30 
32  Int_t region_id,
33  const char* name_prfix,
34  const char* title_prefix);
35 
36  template <typename T>
38  const T& key,
39  const char* name_prfix,
40  const char* title_prefix);
41 
42  template <typename T>
44  const T& key,
45  const char* name_prefix,
46  const char* title_prefix);
47 
48  template <typename T>
50  const T& key,
51  const char* name_prefix,
52  const char* title_prefix);
53 
54  template <typename T>
56  const T& key,
57  const GEMStation* station,
58  const char* name_prfix,
59  const char* title_prefix);
60 
61  template <typename T>
62  dqm::impl::MonitorElement* bookPIDHist(DQMStore::IBooker& booker, const T& key, const char* name, const char* title);
63 
64  template <typename T>
66  DQMStore::IBooker& booker, const T& key, Int_t ieta, const char* name, const char* title);
67 
68  template <typename T>
70  const T& key,
71  const char* name,
72  const char* title,
73  Int_t nbinsx,
74  Double_t xlow,
75  Double_t xup,
76  const char* x_title = "",
77  const char* y_title = "Entries");
78 
79  template <typename T>
81  const T& key,
82  const char* name,
83  const char* title,
84  Int_t nbinsx,
85  Double_t xlow,
86  Double_t xup,
87  Int_t nbinsy,
88  Double_t ylow,
89  Double_t yup,
90  const char* x_title = "",
91  const char* y_title = "");
92 
93  // NOTE Parameters
95  std::vector<Int_t> pid_list_;
96  std::vector<Int_t> zr_occ_num_bins_;
97  std::vector<Double_t> zr_occ_range_;
98  std::vector<Double_t> eta_range_;
99  Bool_t detail_plot_;
100 
101  // NOTE Constants
102  const Int_t kMuonPDGId_ = 13;
103  const std::string kLogCategory_; // see member initializer list
106 };
107 
108 template <typename T>
110  const T& key,
111  const char* name_prefix,
112  const char* title_prefix) {
113  if (std::tuple_size<T>::value < 2) {
114  edm::LogError(kLogCategory_) << "Wrong T" << std::endl;
115  return nullptr;
116  }
117 
118  Int_t station_id = std::get<1>(key);
119 
120  auto name_suffix = GEMUtils::getSuffixName(key);
121  auto title_suffix = GEMUtils::getSuffixTitle(key);
122 
123  TString name = TString::Format("%s_occ_zr%s", name_prefix, name_suffix.Data());
124  TString title = TString::Format("%s ZR Occupancy :%s;|Z| #[cm];R [cm]", title_prefix, title_suffix.Data());
125 
126  // NOTE currently, only GE11 and GE21 are considered.
127  // Look Validation/MuonGEMHits/python/MuonGEMCommonParameters_cfi.py
128  UInt_t nbins_start = 2 * (station_id - 1);
129  Int_t nbinsx = zr_occ_num_bins_[nbins_start];
130  Int_t nbinsy = zr_occ_num_bins_[nbins_start + 1];
131 
132  // st1 xmin xmax, ymin, ymax | st2 xmin, xmax, ymin ymax
133  UInt_t range_start = 4 * (station_id - 1);
134  // absolute z axis
135  Double_t xlow = zr_occ_range_[range_start];
136  Double_t xup = zr_occ_range_[range_start + 1];
137  // R axis
138  Double_t ylow = zr_occ_range_[range_start + 2];
139  Double_t yup = zr_occ_range_[range_start + 3];
140 
141  return booker.book2D(name, title, nbinsx, xlow, xup, nbinsy, ylow, yup);
142 }
143 
144 template <typename T>
146  const T& key,
147  const char* name_prefix,
148  const char* title_prefix) {
149  auto name_suffix = GEMUtils::getSuffixName(key);
150  auto title_suffix = GEMUtils::getSuffixTitle(key);
151  TString name = TString::Format("%s_occ_xy%s", name_prefix, name_suffix.Data());
152  TString title = TString::Format("%s XY Occupancy :%s;X [cm];Y [cm]", title_prefix, title_suffix.Data());
153  return booker.book2D(name, title, xy_occ_num_bins_, -360.0, 360.0, xy_occ_num_bins_, -360.0f, 360.0);
154 }
155 
156 template <typename T>
158  const T& key,
159  const char* name_prefix,
160  const char* title_prefix) {
161  auto name_suffix = GEMUtils::getSuffixName(key);
162  auto title_suffix = GEMUtils::getSuffixTitle(key);
163  TString name = TString::Format("%s_occ_polar%s", name_prefix, name_suffix.Data());
164  TString title = TString::Format("%s Polar Occupancy :%s", title_prefix, title_suffix.Data());
165  // TODO # of bins
166  // TODO the x-axis lies in the cnter of Ch1
167  dqm::impl::MonitorElement* me = booker.book2D(name, title, 108, -M_PI, M_PI, 108, 0.0, 360.0);
168  return me;
169 }
170 
171 template <typename T>
173  const T& key,
174  const GEMStation* station,
175  const char* name_prefix,
176  const char* title_prefix) {
177  auto name_suffix = GEMUtils::getSuffixName(key);
178  auto title_suffix = GEMUtils::getSuffixTitle(key);
179 
180  TString name = TString::Format("%s_occ_det%s", name_prefix, name_suffix.Data());
181  TString title = TString::Format("%s Occupancy for detector component :%s", title_prefix, title_suffix.Data());
182 
183  std::vector<const GEMSuperChamber*> superchambers = station->superChambers();
184 
185  Int_t num_superchambers = superchambers.size();
186  Int_t num_chambers = 0;
187  Int_t nbinsy = 0;
188  if (num_superchambers > 0) {
189  num_chambers = superchambers.front()->nChambers();
190  if (num_chambers > 0)
191  nbinsy = superchambers.front()->chambers().front()->nEtaPartitions();
192  }
193  Int_t nbinsx = num_superchambers * num_chambers;
194 
195  if (nbinsx <= 0)
196  nbinsx = 20; // Ensure histogram is not zero size
197  if (nbinsy <= 0)
198  nbinsy = 20;
199  auto hist = new TH2F(name, title, nbinsx, 1 - 0.5, nbinsx + 0.5, nbinsy, 1 - 0.5, nbinsy + 0.5);
200  hist->GetXaxis()->SetTitle("Chamber-Layer");
201  hist->GetYaxis()->SetTitle("Eta Partition");
202 
203  TAxis* x_axis = hist->GetXaxis();
204  for (Int_t chamber_id = 1; chamber_id <= num_superchambers; chamber_id++) {
205  for (Int_t layer_id = 1; layer_id <= num_chambers; layer_id++) {
206  Int_t bin = getDetOccBinX(num_chambers, chamber_id, layer_id);
207  TString label = TString::Format("C%dL%d", chamber_id, layer_id);
208  x_axis->SetBinLabel(bin, label);
209  }
210  }
211 
212  TAxis* y_axis = hist->GetYaxis();
213  for (Int_t bin = 1; bin <= nbinsy; bin++) {
214  y_axis->SetBinLabel(bin, TString::Itoa(bin, 10));
215  }
216 
217  return booker.book2D(name, hist);
218 }
219 
220 template <typename T>
222  const T& key,
223  const char* name,
224  const char* title) {
225  auto name_suffix = GEMUtils::getSuffixName(key);
226  auto title_suffix = GEMUtils::getSuffixTitle(key);
227  TString x_title = "Particle Type";
228  TString y_title = "Particles";
229  TString hist_name = TString::Format("%s%s", name, name_suffix.Data());
230  TString hist_title = TString::Format("%s :%s;%s;%s", title, title_suffix.Data(), x_title.Data(), y_title.Data());
231  Int_t nbinsx = pid_list_.size();
232  auto hist = booker.book1D(hist_name, hist_title, nbinsx + 1, 0, nbinsx + 1);
233  TDatabasePDG* pdgDB = TDatabasePDG::Instance();
234  for (Int_t idx = 0; idx < nbinsx; idx++) {
235  Int_t bin = idx + 1;
236  auto particle_name = pdgDB->GetParticle(pid_list_[idx])->GetName();
237  hist->setBinLabel(bin, particle_name);
238  }
239  hist->setBinLabel(nbinsx + 1, "others");
240  return hist;
241 }
242 
243 template <typename T>
245  DQMStore::IBooker& booker, const T& key, Int_t ieta, const char* name, const char* title) {
246  auto name_suffix = GEMUtils::getSuffixName(key);
247  auto title_suffix = GEMUtils::getSuffixTitle(key);
248  TString x_title = "Particle Type";
249  TString y_title = "Particles";
250  TString hist_name = TString::Format("%s%s-E%d", name, name_suffix.Data(), ieta);
251  TString hist_title =
252  TString::Format("%s :%s-E%d;%s;%s", title, title_suffix.Data(), ieta, x_title.Data(), y_title.Data());
253  Int_t nbinsx = pid_list_.size();
254  auto hist = booker.book1D(hist_name, hist_title, nbinsx + 1, 0, nbinsx + 1);
255  TDatabasePDG* pdgDB = TDatabasePDG::Instance();
256  for (Int_t idx = 0; idx < nbinsx; idx++) {
257  Int_t bin = idx + 1;
258  auto particle_name = pdgDB->GetParticle(pid_list_[idx])->GetName();
259  hist->setBinLabel(bin, particle_name);
260  }
261  hist->setBinLabel(nbinsx + 1, "others");
262  return hist;
263 }
264 
265 template <typename T>
267  const T& key,
268  const char* name,
269  const char* title,
270  Int_t nbinsx,
271  Double_t xlow,
272  Double_t xup,
273  const char* x_title,
274  const char* y_title) {
275  auto name_suffix = GEMUtils::getSuffixName(key);
276  auto title_suffix = GEMUtils::getSuffixTitle(key);
277  TString hist_name = TString::Format("%s%s", name, name_suffix.Data());
278  TString hist_title = TString::Format("%s :%s;%s;%s", title, title_suffix.Data(), x_title, y_title);
279  return booker.book1D(hist_name, hist_title, nbinsx, xlow, xup);
280 }
281 
282 template <typename T>
284  const T& key,
285  const char* name,
286  const char* title,
287  Int_t nbinsx,
288  Double_t xlow,
289  Double_t xup,
290  Int_t nbinsy,
291  Double_t ylow,
292  Double_t yup,
293  const char* x_title,
294  const char* y_title) {
295  auto name_suffix = GEMUtils::getSuffixName(key);
296  auto title_suffix = GEMUtils::getSuffixTitle(key);
297  TString hist_name = TString::Format("%s%s", name, name_suffix.Data());
298  TString hist_title = TString::Format("%s :%s;%s;%s", title, title_suffix.Data(), x_title, y_title);
299  return booker.book2D(hist_name, hist_title, nbinsx, xlow, xup, nbinsy, ylow, yup);
300 }
301 
302 #endif // Validation_MuonGEMHits_GEMBaseValidation_h
dqm::impl::MonitorElement * bookHist1D(DQMStore::IBooker &booker, const T &key, const char *name, const char *title, Int_t nbinsx, Double_t xlow, Double_t xup, const char *x_title="", const char *y_title="Entries")
TString getSuffixName(Int_t region_id)
Bool_t isMuonSimHit(const PSimHit &)
std::vector< Int_t > zr_occ_num_bins_
edm::ESGetToken< GEMGeometry, MuonGeometryRecord > geomTokenBeginRun_
Log< level::Error, false > LogError
dqm::impl::MonitorElement * bookZROccupancy(DQMStore::IBooker &booker, Int_t region_id, const char *name_prfix, const char *title_prefix)
TString getSuffixTitle(Int_t region_id)
char const * label
~GEMBaseValidation() override=0
dqm::impl::MonitorElement * bookXYOccupancy(DQMStore::IBooker &booker, const T &key, const char *name_prefix, const char *title_prefix)
std::vector< Int_t > pid_list_
Int_t getPidIdx(Int_t pid)
std::vector< Double_t > eta_range_
double f[11][100]
void analyze(const edm::Event &e, const edm::EventSetup &) override=0
dqm::impl::MonitorElement * bookHist2D(DQMStore::IBooker &booker, const T &key, const char *name, const char *title, Int_t nbinsx, Double_t xlow, Double_t xup, Int_t nbinsy, Double_t ylow, Double_t yup, const char *x_title="", const char *y_title="")
edm::ESGetToken< GEMGeometry, MuonGeometryRecord > geomToken_
#define M_PI
GEMBaseValidation(const edm::ParameterSet &, std::string)
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
Float_t toDegree(Float_t radian)
std::vector< Double_t > zr_occ_range_
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
Int_t getDetOccBinX(Int_t num_layers, Int_t chamber_id, Int_t layer_id)
long double T
dqm::impl::MonitorElement * bookPIDHist(DQMStore::IBooker &booker, const T &key, const char *name, const char *title)
const std::string kLogCategory_
dqm::impl::MonitorElement * bookPolarOccupancy(DQMStore::IBooker &booker, const T &key, const char *name_prefix, const char *title_prefix)
dqm::impl::MonitorElement * bookDetectorOccupancy(DQMStore::IBooker &booker, const T &key, const GEMStation *station, const char *name_prfix, const char *title_prefix)