Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-15 22:40:57

0001 #ifndef Validation_MuonGEMHits_GEMBaseValidation_h
0002 #define Validation_MuonGEMHits_GEMBaseValidation_h
0003 
0004 #include "DQMServices/Core/interface/DQMEDAnalyzer.h"
0005 #include "DQMServices/Core/interface/DQMStore.h"
0006 #include "DQMServices/Core/interface/MonitorElement.h"
0007 #include "Geometry/GEMGeometry/interface/GEMGeometry.h"
0008 #include "Geometry/Records/interface/MuonGeometryRecord.h"
0009 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
0010 #include "FWCore/Utilities/interface/EDGetToken.h"
0011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0012 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0013 
0014 #include "Validation/MuonGEMHits/interface/GEMValidationUtils.h"
0015 
0016 #include "TMath.h"
0017 #include "TDatabasePDG.h"
0018 
0019 class GEMBaseValidation : public DQMEDAnalyzer {
0020 public:
0021   explicit GEMBaseValidation(const edm::ParameterSet&, std::string);
0022   ~GEMBaseValidation() override = 0;
0023   void analyze(const edm::Event& e, const edm::EventSetup&) override = 0;
0024 
0025 protected:
0026   Int_t getDetOccBinX(Int_t num_layers, Int_t chamber_id, Int_t layer_id);
0027   Bool_t isMuonSimHit(const PSimHit&);
0028   Float_t toDegree(Float_t radian);
0029   Int_t getPidIdx(Int_t pid);
0030 
0031   dqm::impl::MonitorElement* bookZROccupancy(DQMStore::IBooker& booker,
0032                                              Int_t region_id,
0033                                              const char* name_prfix,
0034                                              const char* title_prefix);
0035 
0036   template <typename T>
0037   dqm::impl::MonitorElement* bookZROccupancy(DQMStore::IBooker& booker,
0038                                              const T& key,
0039                                              const char* name_prfix,
0040                                              const char* title_prefix);
0041 
0042   template <typename T>
0043   dqm::impl::MonitorElement* bookXYOccupancy(DQMStore::IBooker& booker,
0044                                              const T& key,
0045                                              const char* name_prefix,
0046                                              const char* title_prefix);
0047 
0048   template <typename T>
0049   dqm::impl::MonitorElement* bookPolarOccupancy(DQMStore::IBooker& booker,
0050                                                 const T& key,
0051                                                 const char* name_prefix,
0052                                                 const char* title_prefix);
0053 
0054   template <typename T>
0055   dqm::impl::MonitorElement* bookDetectorOccupancy(DQMStore::IBooker& booker,
0056                                                    const T& key,
0057                                                    const GEMStation* station,
0058                                                    const char* name_prfix,
0059                                                    const char* title_prefix);
0060 
0061   template <typename T>
0062   dqm::impl::MonitorElement* bookPIDHist(DQMStore::IBooker& booker, const T& key, const char* name, const char* title);
0063 
0064   template <typename T>
0065   dqm::impl::MonitorElement* bookPIDHist(
0066       DQMStore::IBooker& booker, const T& key, Int_t ieta, const char* name, const char* title);
0067 
0068   template <typename T>
0069   dqm::impl::MonitorElement* bookHist1D(DQMStore::IBooker& booker,
0070                                         const T& key,
0071                                         const char* name,
0072                                         const char* title,
0073                                         Int_t nbinsx,
0074                                         Double_t xlow,
0075                                         Double_t xup,
0076                                         const char* x_title = "",
0077                                         const char* y_title = "Entries");
0078 
0079   template <typename T>
0080   dqm::impl::MonitorElement* bookHist2D(DQMStore::IBooker& booker,
0081                                         const T& key,
0082                                         const char* name,
0083                                         const char* title,
0084                                         Int_t nbinsx,
0085                                         Double_t xlow,
0086                                         Double_t xup,
0087                                         Int_t nbinsy,
0088                                         Double_t ylow,
0089                                         Double_t yup,
0090                                         const char* x_title = "",
0091                                         const char* y_title = "");
0092 
0093   // NOTE Parameters
0094   Int_t xy_occ_num_bins_;
0095   std::vector<Int_t> pid_list_;
0096   std::vector<Int_t> zr_occ_num_bins_;
0097   std::vector<Double_t> zr_occ_range_;
0098   std::vector<Double_t> eta_range_;
0099   Bool_t detail_plot_;
0100 
0101   // NOTE Constants
0102   const Int_t kMuonPDGId_ = 13;
0103   const std::string kLogCategory_;  // see member initializer list
0104   edm::ESGetToken<GEMGeometry, MuonGeometryRecord> geomToken_;
0105   edm::ESGetToken<GEMGeometry, MuonGeometryRecord> geomTokenBeginRun_;
0106 };
0107 
0108 template <typename T>
0109 dqm::impl::MonitorElement* GEMBaseValidation::bookZROccupancy(DQMStore::IBooker& booker,
0110                                                               const T& key,
0111                                                               const char* name_prefix,
0112                                                               const char* title_prefix) {
0113   if (std::tuple_size<T>::value < 2) {
0114     edm::LogError(kLogCategory_) << "Wrong T" << std::endl;
0115     return nullptr;
0116   }
0117 
0118   Int_t station_id = std::get<1>(key);
0119 
0120   auto name_suffix = GEMUtils::getSuffixName(key);
0121   auto title_suffix = GEMUtils::getSuffixTitle(key);
0122 
0123   TString name = TString::Format("%s_occ_zr%s", name_prefix, name_suffix.Data());
0124   TString title = TString::Format("%s ZR Occupancy :%s;|Z| #[cm];R [cm]", title_prefix, title_suffix.Data());
0125 
0126   // NOTE currently, only GE11 and GE21 are considered.
0127   // Look Validation/MuonGEMHits/python/MuonGEMCommonParameters_cfi.py
0128   UInt_t nbins_start = 2 * (station_id - 1);
0129   Int_t nbinsx = zr_occ_num_bins_[nbins_start];
0130   Int_t nbinsy = zr_occ_num_bins_[nbins_start + 1];
0131 
0132   // st1 xmin xmax, ymin, ymax | st2 xmin, xmax, ymin ymax
0133   UInt_t range_start = 4 * (station_id - 1);
0134   // absolute z axis
0135   Double_t xlow = zr_occ_range_[range_start];
0136   Double_t xup = zr_occ_range_[range_start + 1];
0137   // R axis
0138   Double_t ylow = zr_occ_range_[range_start + 2];
0139   Double_t yup = zr_occ_range_[range_start + 3];
0140 
0141   return booker.book2D(name, title, nbinsx, xlow, xup, nbinsy, ylow, yup);
0142 }
0143 
0144 template <typename T>
0145 dqm::impl::MonitorElement* GEMBaseValidation::bookXYOccupancy(DQMStore::IBooker& booker,
0146                                                               const T& key,
0147                                                               const char* name_prefix,
0148                                                               const char* title_prefix) {
0149   auto name_suffix = GEMUtils::getSuffixName(key);
0150   auto title_suffix = GEMUtils::getSuffixTitle(key);
0151   TString name = TString::Format("%s_occ_xy%s", name_prefix, name_suffix.Data());
0152   TString title = TString::Format("%s XY Occupancy :%s;X [cm];Y [cm]", title_prefix, title_suffix.Data());
0153   return booker.book2D(name, title, xy_occ_num_bins_, -360.0, 360.0, xy_occ_num_bins_, -360.0f, 360.0);
0154 }
0155 
0156 template <typename T>
0157 dqm::impl::MonitorElement* GEMBaseValidation::bookPolarOccupancy(DQMStore::IBooker& booker,
0158                                                                  const T& key,
0159                                                                  const char* name_prefix,
0160                                                                  const char* title_prefix) {
0161   auto name_suffix = GEMUtils::getSuffixName(key);
0162   auto title_suffix = GEMUtils::getSuffixTitle(key);
0163   TString name = TString::Format("%s_occ_polar%s", name_prefix, name_suffix.Data());
0164   TString title = TString::Format("%s Polar Occupancy :%s", title_prefix, title_suffix.Data());
0165   // TODO # of bins
0166   // TODO the x-axis lies in the cnter of Ch1
0167   dqm::impl::MonitorElement* me = booker.book2D(name, title, 108, -M_PI, M_PI, 108, 0.0, 360.0);
0168   return me;
0169 }
0170 
0171 template <typename T>
0172 dqm::impl::MonitorElement* GEMBaseValidation::bookDetectorOccupancy(DQMStore::IBooker& booker,
0173                                                                     const T& key,
0174                                                                     const GEMStation* station,
0175                                                                     const char* name_prefix,
0176                                                                     const char* title_prefix) {
0177   auto name_suffix = GEMUtils::getSuffixName(key);
0178   auto title_suffix = GEMUtils::getSuffixTitle(key);
0179 
0180   TString name = TString::Format("%s_occ_det%s", name_prefix, name_suffix.Data());
0181   TString title = TString::Format("%s Occupancy for detector component :%s", title_prefix, title_suffix.Data());
0182 
0183   std::vector<const GEMSuperChamber*> superchambers = station->superChambers();
0184 
0185   Int_t num_superchambers = superchambers.size();
0186   Int_t num_chambers = 0;
0187   Int_t nbinsy = 0;
0188   if (num_superchambers > 0) {
0189     num_chambers = superchambers.front()->nChambers();
0190     if (num_chambers > 0)
0191       nbinsy = superchambers.front()->chambers().front()->nEtaPartitions();
0192   }
0193   Int_t nbinsx = num_superchambers * num_chambers;
0194 
0195   if (nbinsx <= 0)
0196     nbinsx = 20;  // Ensure histogram is not zero size
0197   if (nbinsy <= 0)
0198     nbinsy = 20;
0199   auto hist = new TH2F(name, title, nbinsx, 1 - 0.5, nbinsx + 0.5, nbinsy, 1 - 0.5, nbinsy + 0.5);
0200   hist->GetXaxis()->SetTitle("Chamber-Layer");
0201   hist->GetYaxis()->SetTitle("Eta Partition");
0202 
0203   TAxis* x_axis = hist->GetXaxis();
0204   for (Int_t chamber_id = 1; chamber_id <= num_superchambers; chamber_id++) {
0205     for (Int_t layer_id = 1; layer_id <= num_chambers; layer_id++) {
0206       Int_t bin = getDetOccBinX(num_chambers, chamber_id, layer_id);
0207       TString label = TString::Format("C%dL%d", chamber_id, layer_id);
0208       x_axis->SetBinLabel(bin, label);
0209     }
0210   }
0211 
0212   TAxis* y_axis = hist->GetYaxis();
0213   for (Int_t bin = 1; bin <= nbinsy; bin++) {
0214     y_axis->SetBinLabel(bin, TString::Itoa(bin, 10));
0215   }
0216 
0217   return booker.book2D(name, hist);
0218 }
0219 
0220 template <typename T>
0221 dqm::impl::MonitorElement* GEMBaseValidation::bookPIDHist(DQMStore::IBooker& booker,
0222                                                           const T& key,
0223                                                           const char* name,
0224                                                           const char* title) {
0225   auto name_suffix = GEMUtils::getSuffixName(key);
0226   auto title_suffix = GEMUtils::getSuffixTitle(key);
0227   TString x_title = "Particle Type";
0228   TString y_title = "Particles";
0229   TString hist_name = TString::Format("%s%s", name, name_suffix.Data());
0230   TString hist_title = TString::Format("%s :%s;%s;%s", title, title_suffix.Data(), x_title.Data(), y_title.Data());
0231   Int_t nbinsx = pid_list_.size();
0232   auto hist = booker.book1D(hist_name, hist_title, nbinsx + 1, 0, nbinsx + 1);
0233   TDatabasePDG* pdgDB = TDatabasePDG::Instance();
0234   for (Int_t idx = 0; idx < nbinsx; idx++) {
0235     Int_t bin = idx + 1;
0236     auto particle_name = pdgDB->GetParticle(pid_list_[idx])->GetName();
0237     hist->setBinLabel(bin, particle_name);
0238   }
0239   hist->setBinLabel(nbinsx + 1, "others");
0240   return hist;
0241 }
0242 
0243 template <typename T>
0244 dqm::impl::MonitorElement* GEMBaseValidation::bookPIDHist(
0245     DQMStore::IBooker& booker, const T& key, Int_t ieta, const char* name, const char* title) {
0246   auto name_suffix = GEMUtils::getSuffixName(key);
0247   auto title_suffix = GEMUtils::getSuffixTitle(key);
0248   TString x_title = "Particle Type";
0249   TString y_title = "Particles";
0250   TString hist_name = TString::Format("%s%s-E%d", name, name_suffix.Data(), ieta);
0251   TString hist_title =
0252       TString::Format("%s :%s-E%d;%s;%s", title, title_suffix.Data(), ieta, x_title.Data(), y_title.Data());
0253   Int_t nbinsx = pid_list_.size();
0254   auto hist = booker.book1D(hist_name, hist_title, nbinsx + 1, 0, nbinsx + 1);
0255   TDatabasePDG* pdgDB = TDatabasePDG::Instance();
0256   for (Int_t idx = 0; idx < nbinsx; idx++) {
0257     Int_t bin = idx + 1;
0258     auto particle_name = pdgDB->GetParticle(pid_list_[idx])->GetName();
0259     hist->setBinLabel(bin, particle_name);
0260   }
0261   hist->setBinLabel(nbinsx + 1, "others");
0262   return hist;
0263 }
0264 
0265 template <typename T>
0266 dqm::impl::MonitorElement* GEMBaseValidation::bookHist1D(DQMStore::IBooker& booker,
0267                                                          const T& key,
0268                                                          const char* name,
0269                                                          const char* title,
0270                                                          Int_t nbinsx,
0271                                                          Double_t xlow,
0272                                                          Double_t xup,
0273                                                          const char* x_title,
0274                                                          const char* y_title) {
0275   auto name_suffix = GEMUtils::getSuffixName(key);
0276   auto title_suffix = GEMUtils::getSuffixTitle(key);
0277   TString hist_name = TString::Format("%s%s", name, name_suffix.Data());
0278   TString hist_title = TString::Format("%s :%s;%s;%s", title, title_suffix.Data(), x_title, y_title);
0279   return booker.book1D(hist_name, hist_title, nbinsx, xlow, xup);
0280 }
0281 
0282 template <typename T>
0283 dqm::impl::MonitorElement* GEMBaseValidation::bookHist2D(DQMStore::IBooker& booker,
0284                                                          const T& key,
0285                                                          const char* name,
0286                                                          const char* title,
0287                                                          Int_t nbinsx,
0288                                                          Double_t xlow,
0289                                                          Double_t xup,
0290                                                          Int_t nbinsy,
0291                                                          Double_t ylow,
0292                                                          Double_t yup,
0293                                                          const char* x_title,
0294                                                          const char* y_title) {
0295   auto name_suffix = GEMUtils::getSuffixName(key);
0296   auto title_suffix = GEMUtils::getSuffixTitle(key);
0297   TString hist_name = TString::Format("%s%s", name, name_suffix.Data());
0298   TString hist_title = TString::Format("%s :%s;%s;%s", title, title_suffix.Data(), x_title, y_title);
0299   return booker.book2D(hist_name, hist_title, nbinsx, xlow, xup, nbinsy, ylow, yup);
0300 }
0301 
0302 #endif  // Validation_MuonGEMHits_GEMBaseValidation_h