CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GEMDQMBase.cc
Go to the documentation of this file.
3 
4 using namespace std;
5 using namespace edm;
6 
8  log_category_ = cfg.getUntrackedParameter<std::string>("logCategory");
9 
13 }
14 
16  GEMGeometry_ = nullptr;
17  try {
18  //edm::ESHandle<GEMGeometry> hGeom;
19  //iSetup.get<MuonGeometryRecord>().get(hGeom);
20  GEMGeometry_ = &iSetup.getData(geomToken_);
22  edm::LogError(log_category_) << "+++ Error : GEM geometry is unavailable on event loop. +++\n";
23  return -1;
24  }
25 
26  return 0;
27 }
28 
29 // Borrowed from DQMOffline/Muon/src/GEMOfflineDQMBase.cc
31  const auto&& superchambers = station->superChambers();
32  if (not checkRefs(superchambers)) {
33  edm::LogError(log_category_) << "failed to get a valid vector of GEMSuperChamber ptrs" << std::endl;
34  return 0;
35  }
36 
37  const auto& chambers = superchambers.front()->chambers();
38  if (not checkRefs(chambers)) {
39  edm::LogError(log_category_) << "failed to get a valid vector of GEMChamber ptrs" << std::endl;
40  return 0;
41  }
42 
43  return chambers.front()->nEtaPartitions();
44 }
45 
47  if (GEMGeometry_ == nullptr)
48  return -1;
49  gemChambers_.clear();
50  const std::vector<const GEMSuperChamber*>& superChambers_ = GEMGeometry_->superChambers();
51  for (auto sch : superChambers_) { // FIXME: This loop can be merged into the below loop
52  int n_lay = sch->nChambers();
53  for (int l = 0; l < n_lay; l++) {
54  Bool_t bExist = false;
55  if (not sch->chamber(l + 1))
56  continue;
57  for (const auto& ch : gemChambers_) {
58  if (ch.id() == sch->chamber(l + 1)->id()) {
59  bExist = true;
60  break;
61  }
62  }
63  if (bExist)
64  continue;
65  gemChambers_.push_back(*sch->chamber(l + 1));
66  }
67  }
68 
69  // Borrowed from DQMOffline/Muon/src/GEMOfflineMonitor.cc
70  nMaxNumCh_ = 0;
71  for (const GEMRegion* region : GEMGeometry_->regions()) {
72  const int region_number = region->region();
73 
74  for (const GEMStation* station : region->stations()) {
75  const auto&& superchambers = station->superChambers();
76 
77  const int station_number = station->station();
78  const int num_superchambers = superchambers.size();
79  const int num_layers = superchambers.front()->nChambers();
80  const int max_vfat = getMaxVFAT(station->station()); // the number of VFATs per GEMEtaPartition
81  const int num_etas = getNumEtaPartitions(station); // the number of eta partitions per GEMChamber
82  const int num_vfat = num_etas * max_vfat; // the number of VFATs per GEMChamber
83  const int num_digi = GEMeMap::maxChan_; // the number of digis (channels) per VFAT
84 
85  nMaxNumCh_ = std::max(nMaxNumCh_, num_superchambers);
86 
87  for (int layer_number = 1; layer_number <= num_layers; layer_number++) {
88  ME3IdsKey key3(region_number, station_number, layer_number);
89  mapStationInfo_[key3] =
90  MEStationInfo(region_number, station_number, layer_number, num_superchambers, num_etas, num_vfat, num_digi);
91  mapStationInfo_[key3].fMinPhi_ = -0.088344; // FIXME
92  }
93  }
94  }
95 
96  if (mapStationInfo_.find(ME3IdsKey(-1, 0, 1)) != mapStationInfo_.end())
97  nNumEtaPartitionGE0_ = mapStationInfo_[ME3IdsKey(-1, 0, 1)].nNumEtaPartitions_;
98  if (mapStationInfo_.find(ME3IdsKey(-1, 1, 1)) != mapStationInfo_.end())
99  nNumEtaPartitionGE11_ = mapStationInfo_[ME3IdsKey(-1, 1, 1)].nNumEtaPartitions_;
100  if (mapStationInfo_.find(ME3IdsKey(-1, 2, 1)) != mapStationInfo_.end())
101  nNumEtaPartitionGE21_ = mapStationInfo_[ME3IdsKey(-1, 2, 1)].nNumEtaPartitions_;
102 
103  return 0;
104 }
105 
106 int GEMDQMBase::SortingLayers(std::vector<ME3IdsKey>& listLayers) {
107  std::sort(listLayers.begin(), listLayers.end(), [](ME3IdsKey key1, ME3IdsKey key2) {
108  Int_t re1 = std::get<0>(key1), st1 = std::get<1>(key1), la1 = std::get<2>(key1);
109  Int_t re2 = std::get<0>(key2), st2 = std::get<1>(key2), la2 = std::get<2>(key2);
110  if (re1 < 0 && re2 > 0)
111  return false;
112  if (re1 > 0 && re2 < 0)
113  return true;
114  Bool_t bRes = (re1 < 0); // == re2 < 0
115  Int_t sum1 = 256 * std::abs(re1) + 16 * st1 + 1 * la1;
116  Int_t sum2 = 256 * std::abs(re2) + 16 * st2 + 1 * la2;
117  if (sum1 <= sum2)
118  return bRes;
119  return !bRes;
120  });
121 
122  return 0;
123 }
124 
126  std::vector<ME3IdsKey> listLayers;
127  for (auto const& [key, stationInfo] : mapStationInfo_)
128  listLayers.push_back(key);
129  SortingLayers(listLayers);
130  for (Int_t i = 0; i < (Int_t)listLayers.size(); i++)
131  mapStationToIdx_[listLayers[i]] = i + 1;
132 
133  auto h2Res =
134  ibooker.book2D(strName, "", nMaxNumCh_, 0.5, nMaxNumCh_ + 0.5, listLayers.size(), 0.5, listLayers.size() + 0.5);
135  h2Res->setXTitle("Chamber");
136  h2Res->setYTitle("Layer");
137 
138  if (h2Res == nullptr)
139  return nullptr;
140 
141  for (Int_t i = 1; i <= nMaxNumCh_; i++)
142  h2Res->setBinLabel(i, Form("%i", i), 1);
143  for (Int_t i = 1; i <= (Int_t)listLayers.size(); i++) {
144  auto key = listLayers[i - 1];
145  auto strInfo = GEMUtils::getSuffixName(key); // NOTE: It starts with '_'
146  auto region = keyToRegion(key);
147  auto label = Form("GE%i%i-%cL%i;%s",
148  std::abs(region),
149  keyToStation(key),
150  (region > 0 ? 'P' : 'M'),
151  keyToLayer(key),
152  strInfo.Data());
153  h2Res->setBinLabel(i, label, 2);
154  Int_t nNumCh = mapStationInfo_[key].nNumChambers_;
155  h2Res->setBinContent(0, i, nNumCh);
156  }
157 
158  return h2Res;
159 }
160 
162  MEMap2Check_.clear();
163  MEMap2WithEtaCheck_.clear();
164  MEMap2AbsReWithEtaCheck_.clear();
165  MEMap3Check_.clear();
166  MEMap3WithChCheck_.clear();
167  MEMap4Check_.clear();
168  for (const auto& ch : gemChambers_) {
169  GEMDetId gid = ch.id();
170  ME2IdsKey key2{gid.region(), gid.station()};
171  ME3IdsKey key3{gid.region(), gid.station(), gid.layer()};
172  ME4IdsKey key3WithChamber{gid.region(), gid.station(), gid.layer(), gid.chamber()};
173  if (!MEMap2Check_[key2]) {
174  auto strSuffixName = GEMUtils::getSuffixName(key2);
175  auto strSuffixTitle = GEMUtils::getSuffixTitle(key2);
176  BookingHelper bh2(ibooker, strSuffixName, strSuffixTitle);
177  ProcessWithMEMap2(bh2, key2);
178  MEMap2Check_[key2] = true;
179  }
180  if (!MEMap3Check_[key3]) {
181  auto strSuffixName = GEMUtils::getSuffixName(key3);
182  auto strSuffixTitle = GEMUtils::getSuffixTitle(key3);
183  BookingHelper bh3(ibooker, strSuffixName, strSuffixTitle);
184  ProcessWithMEMap3(bh3, key3);
185  MEMap3Check_[key3] = true;
186  }
187  if (!MEMap3WithChCheck_[key3WithChamber]) {
188  Int_t nCh = gid.chamber();
189  Int_t nLa = gid.layer();
190  char cLS = (nCh % 2 == 0 ? 'L' : 'S'); // FIXME: Is it general enough?
191  auto strSuffixName = GEMUtils::getSuffixName(key2) + Form("-%02iL%i-%c", nCh, nLa, cLS);
192  auto strSuffixTitle = GEMUtils::getSuffixTitle(key2) + Form("-%02iL%i-%c", nCh, nLa, cLS);
193  BookingHelper bh3Ch(ibooker, strSuffixName, strSuffixTitle);
194  ProcessWithMEMap3WithChamber(bh3Ch, key3WithChamber);
195  MEMap3WithChCheck_[key3WithChamber] = true;
196  }
197  for (auto iEta : ch.etaPartitions()) {
198  GEMDetId eId = iEta->id();
199  ME4IdsKey key4{gid.region(), gid.station(), gid.layer(), eId.ieta()};
200  ME3IdsKey key2WithEta{gid.region(), gid.station(), eId.ieta()};
201  ME3IdsKey key2AbsReWithEta{std::abs(gid.region()), gid.station(), eId.ieta()};
202  if (!MEMap4Check_[key4]) {
203  auto strSuffixName = GEMUtils::getSuffixName(key3) + Form("-E%02i", eId.ieta());
204  auto strSuffixTitle = GEMUtils::getSuffixTitle(key3) + Form("-E%02i", eId.ieta());
205  BookingHelper bh4(ibooker, strSuffixName, strSuffixTitle);
206  ProcessWithMEMap4(bh4, key4);
207  MEMap4Check_[key4] = true;
208  }
209  if (!MEMap2WithEtaCheck_[key2WithEta]) {
210  auto strSuffixName = GEMUtils::getSuffixName(key2) + Form("-E%02i", eId.ieta());
211  auto strSuffixTitle = GEMUtils::getSuffixTitle(key2) + Form("-E%02i", eId.ieta());
212  BookingHelper bh3(ibooker, strSuffixName, strSuffixTitle);
213  ProcessWithMEMap2WithEta(bh3, key2WithEta);
214  MEMap2WithEtaCheck_[key2WithEta] = true;
215  }
216  if (!MEMap2AbsReWithEtaCheck_[key2AbsReWithEta]) {
217  auto strSuffixName = Form("_GE%d1-E%02i", gid.station(), eId.ieta());
218  auto strSuffixTitle = Form(" GE%d1-E%02i", gid.station(), eId.ieta());
219  BookingHelper bh3(ibooker, strSuffixName, strSuffixTitle);
220  ProcessWithMEMap2AbsReWithEta(bh3, key2AbsReWithEta);
221  MEMap2AbsReWithEtaCheck_[key2AbsReWithEta] = true;
222  }
223  }
224  }
225  return 0;
226 }
T getUntrackedParameter(std::string const &, T const &) const
Int_t nNumEtaPartitionGE11_
Definition: GEMDQMBase.h:567
dqm::impl::MonitorElement * CreateSummaryHist(DQMStore::IBooker &ibooker, TString strName)
Definition: GEMDQMBase.cc:125
bool checkRefs(const std::vector< T * > &)
Definition: GEMDQMBase.h:573
tuple cfg
Definition: looper.py:296
virtual int ProcessWithMEMap4(BookingHelper &bh, ME4IdsKey key)
Definition: GEMDQMBase.h:509
TString getSuffixName(Int_t region_id)
virtual int ProcessWithMEMap2AbsReWithEta(BookingHelper &bh, ME3IdsKey key)
Definition: GEMDQMBase.h:507
int initGeometry(edm::EventSetup const &iSetup)
Definition: GEMDQMBase.cc:15
std::tuple< Int_t, Int_t, Int_t, Int_t > ME4IdsKey
std::map< ME3IdsKey, MEStationInfo > mapStationInfo_
Definition: GEMDQMBase.h:564
int keyToRegion(ME2IdsKey key)
Definition: GEMDQMBase.h:512
int loadChambers()
Definition: GEMDQMBase.cc:46
std::map< ME3IdsKey, int > mapStationToIdx_
Definition: GEMDQMBase.h:563
static const int maxChan_
Definition: GEMeMap.h:72
int keyToLayer(ME3IdsKey key)
Definition: GEMDQMBase.h:518
Log< level::Error, false > LogError
TString getSuffixTitle(Int_t region_id)
std::string log_category_
Definition: GEMDQMBase.h:496
constexpr int ieta() const
Definition: GEMDetId.h:199
std::vector< const GEMSuperChamber * > superChambers() const
Return the super chambers in the region.
Definition: GEMStation.cc:44
bool getData(T &iHolder) const
Definition: EventSetup.h:128
char const * label
std::map< ME3IdsKey, bool > MEMap2AbsReWithEtaCheck_
Definition: GEMDQMBase.h:557
std::map< ME2IdsKey, bool > MEMap2Check_
Definition: GEMDQMBase.h:555
virtual int ProcessWithMEMap3(BookingHelper &bh, ME3IdsKey key)
Definition: GEMDQMBase.h:508
virtual void setXTitle(std::string const &title)
int GenerateMEPerChamber(DQMStore::IBooker &ibooker)
Definition: GEMDQMBase.cc:161
std::map< ME3IdsKey, bool > MEMap3Check_
Definition: GEMDQMBase.h:558
constexpr int region() const
Definition: GEMDetId.h:171
const std::vector< const GEMRegion * > & regions() const
Return a vector of all GEM regions.
Definition: GEMGeometry.cc:30
int getNumEtaPartitions(const GEMStation *)
Definition: GEMDQMBase.cc:30
virtual int ProcessWithMEMap3WithChamber(BookingHelper &bh, ME4IdsKey key)
Definition: GEMDQMBase.h:510
std::vector< GEMChamber > gemChambers_
Definition: GEMDQMBase.h:553
edm::ESGetToken< GEMGeometry, MuonGeometryRecord > geomToken_
Definition: GEMDQMBase.h:551
tuple key
prepare the HTCondor submission files and eventually submit them
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Transition
Definition: Transition.h:12
int getMaxVFAT(const int)
Definition: GEMDQMBase.h:582
int keyToStation(ME2IdsKey key)
Definition: GEMDQMBase.h:515
std::map< ME4IdsKey, bool > MEMap4Check_
Definition: GEMDQMBase.h:560
const std::vector< const GEMSuperChamber * > & superChambers() const
Return a vector of all GEM super chambers.
Definition: GEMGeometry.cc:36
const GEMGeometry * GEMGeometry_
Definition: GEMDQMBase.h:550
constexpr int chamber() const
Definition: GEMDetId.h:183
constexpr int layer() const
Definition: GEMDetId.h:190
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
constexpr int station() const
Definition: GEMDetId.h:179
virtual int ProcessWithMEMap2WithEta(BookingHelper &bh, ME3IdsKey key)
Definition: GEMDQMBase.h:506
int SortingLayers(std::vector< ME3IdsKey > &listLayers)
Definition: GEMDQMBase.cc:106
GEMDQMBase(const edm::ParameterSet &cfg)
Definition: GEMDQMBase.cc:7
std::map< ME3IdsKey, bool > MEMap2WithEtaCheck_
Definition: GEMDQMBase.h:556
int nMaxNumCh_
Definition: GEMDQMBase.h:562
std::tuple< Int_t, Int_t > ME2IdsKey
std::tuple< Int_t, Int_t, Int_t > ME3IdsKey
static char chambers[264][20]
Definition: ReadPGInfo.cc:243
Int_t nNumEtaPartitionGE0_
Definition: GEMDQMBase.h:566
std::map< ME4IdsKey, bool > MEMap3WithChCheck_
Definition: GEMDQMBase.h:559
Int_t nNumEtaPartitionGE21_
Definition: GEMDQMBase.h:568
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
virtual int ProcessWithMEMap2(BookingHelper &bh, ME2IdsKey key)
Definition: GEMDQMBase.h:505