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  std::string strRunType = cfg.getUntrackedParameter<std::string>("runType");
9 
11 
12  if (strRunType == "online") {
13  nRunType_ = GEMDQM_RUNTYPE_ONLINE;
14  } else if (strRunType == "offline") {
15  nRunType_ = GEMDQM_RUNTYPE_OFFLINE;
16  } else if (strRunType == "relval") {
17  nRunType_ = GEMDQM_RUNTYPE_RELVAL;
18  } else if (strRunType == "allplots") {
19  nRunType_ = GEMDQM_RUNTYPE_ALLPLOTS;
20  } else {
21  edm::LogError(log_category_) << "+++ Error : GEM geometry is unavailable on event loop. +++\n";
22  }
23 
24  log_category_ = cfg.getUntrackedParameter<std::string>("logCategory");
25 
29 }
30 
32  GEMGeometry_ = nullptr;
33  try {
34  //edm::ESHandle<GEMGeometry> hGeom;
35  //iSetup.get<MuonGeometryRecord>().get(hGeom);
36  GEMGeometry_ = &iSetup.getData(geomToken_);
38  edm::LogError(log_category_) << "+++ Error : GEM geometry is unavailable on event loop. +++\n";
39  return -1;
40  }
41 
42  return 0;
43 }
44 
45 // Borrowed from DQM/GEM/src/GEMOfflineDQMBase.cc
47  const auto&& superchambers = station->superChambers();
48  if (not checkRefs(superchambers)) {
49  edm::LogError(log_category_) << "failed to get a valid vector of GEMSuperChamber ptrs" << std::endl;
50  return 0;
51  }
52 
53  const auto& chambers = superchambers.front()->chambers();
54  if (not checkRefs(chambers)) {
55  edm::LogError(log_category_) << "failed to get a valid vector of GEMChamber ptrs" << std::endl;
56  return 0;
57  }
58 
59  return chambers.front()->nEtaPartitions();
60 }
61 
63  if (GEMGeometry_ == nullptr)
64  return -1;
65  gemChambers_.clear();
66  const std::vector<const GEMSuperChamber*>& superChambers_ = GEMGeometry_->superChambers();
67  for (auto sch : superChambers_) { // FIXME: This loop can be merged into the below loop
68  int n_lay = sch->nChambers();
69  for (int l = 0; l < n_lay; l++) {
70  Bool_t bExist = false;
71  if (not sch->chamber(l + 1))
72  continue;
73  for (const auto& ch : gemChambers_) {
74  if (ch.id() == sch->chamber(l + 1)->id()) {
75  bExist = true;
76  break;
77  }
78  }
79  if (bExist)
80  continue;
81  gemChambers_.push_back(*sch->chamber(l + 1));
82  }
83  }
84 
85  // Borrwed from DQM/GEM/src/GEMOfflineMonitor.cc
86  nMaxNumCh_ = 0;
87  for (const GEMRegion* region : GEMGeometry_->regions()) {
88  const int region_number = region->region();
89 
90  for (const GEMStation* station : region->stations()) {
91  const auto&& superchambers = station->superChambers();
92 
93  const int station_number = station->station();
94  const int num_superchambers = superchambers.size();
95  const int num_layers = superchambers.front()->nChambers();
96  const int max_vfat = getMaxVFAT(station->station()); // the number of VFATs per GEMEtaPartition
97  const int num_etas = getNumEtaPartitions(station); // the number of eta partitions per GEMChamber
98  const int num_vfat = num_etas * max_vfat; // the number of VFATs per GEMChamber
99  const int num_digi = GEMeMap::maxChan_; // the number of digis (channels) per VFAT
100 
101  nMaxNumCh_ = std::max(nMaxNumCh_, num_superchambers);
102 
103  for (int layer_number = 1; layer_number <= num_layers; layer_number++) {
104  ME3IdsKey key3(region_number, station_number, layer_number);
105  mapStationInfo_[key3] =
106  MEStationInfo(region_number, station_number, layer_number, num_superchambers, num_etas, num_vfat, num_digi);
109  }
110  }
111  }
112 
113  if (mapStationInfo_.find(ME3IdsKey(-1, 0, 1)) != mapStationInfo_.end())
114  nNumEtaPartitionGE0_ = mapStationInfo_[ME3IdsKey(-1, 0, 1)].nNumEtaPartitions_;
115  if (mapStationInfo_.find(ME3IdsKey(-1, 1, 1)) != mapStationInfo_.end())
116  nNumEtaPartitionGE11_ = mapStationInfo_[ME3IdsKey(-1, 1, 1)].nNumEtaPartitions_;
117  if (mapStationInfo_.find(ME3IdsKey(-1, 2, 1)) != mapStationInfo_.end())
118  nNumEtaPartitionGE21_ = mapStationInfo_[ME3IdsKey(-1, 2, 1)].nNumEtaPartitions_;
119 
120  return 0;
121 }
122 
123 int GEMDQMBase::SortingLayers(std::vector<ME3IdsKey>& listLayers) {
124  std::sort(listLayers.begin(), listLayers.end(), [](ME3IdsKey key1, ME3IdsKey key2) {
125  Int_t re1 = std::get<0>(key1), st1 = std::get<1>(key1), la1 = std::get<2>(key1);
126  Int_t re2 = std::get<0>(key2), st2 = std::get<1>(key2), la2 = std::get<2>(key2);
127  if (re1 < 0 && re2 > 0)
128  return false;
129  if (re1 > 0 && re2 < 0)
130  return true;
131  Bool_t bRes = (re1 < 0); // == re2 < 0
132  Int_t sum1 = 256 * std::abs(re1) + 16 * st1 + 1 * la1;
133  Int_t sum2 = 256 * std::abs(re2) + 16 * st2 + 1 * la2;
134  if (sum1 <= sum2)
135  return bRes;
136  return !bRes;
137  });
138 
139  return 0;
140 }
141 
143  std::vector<ME3IdsKey> listLayers;
144  for (auto const& [key, stationInfo] : mapStationInfo_)
145  listLayers.push_back(key);
146  SortingLayers(listLayers);
147  for (Int_t i = 0; i < (Int_t)listLayers.size(); i++)
148  mapStationToIdx_[listLayers[i]] = i + 1;
149 
150  auto h2Res =
151  ibooker.book2D(strName, "", nMaxNumCh_, 0.5, nMaxNumCh_ + 0.5, listLayers.size(), 0.5, listLayers.size() + 0.5);
152  h2Res->setXTitle("Chamber");
153  h2Res->setYTitle("Layer");
154 
155  if (h2Res == nullptr)
156  return nullptr;
157 
158  for (Int_t i = 1; i <= nMaxNumCh_; i++)
159  h2Res->setBinLabel(i, Form("%i", i), 1);
160  for (Int_t i = 1; i <= (Int_t)listLayers.size(); i++) {
161  auto key = listLayers[i - 1];
162  auto strInfo = GEMUtils::getSuffixName(key); // NOTE: It starts with '_'
163  auto region = keyToRegion(key);
164  auto label =
165  Form("GE%+i1-%cL%i;%s", region * keyToStation(key), (region > 0 ? 'P' : 'M'), keyToLayer(key), strInfo.Data());
166  h2Res->setBinLabel(i, label, 2);
167  Int_t nNumCh = mapStationInfo_[key].nNumChambers_;
168  h2Res->setBinContent(0, i, nNumCh);
169  }
170 
171  return h2Res;
172 }
173 
175  MEMap2Check_.clear();
176  MEMap2WithEtaCheck_.clear();
177  MEMap2AbsReWithEtaCheck_.clear();
178  MEMap3Check_.clear();
179  MEMap3WithChCheck_.clear();
180  MEMap4Check_.clear();
181  for (const auto& ch : gemChambers_) {
182  GEMDetId gid = ch.id();
183  ME2IdsKey key2{gid.region(), gid.station()};
184  ME3IdsKey key3{gid.region(), gid.station(), gid.layer()};
185  ME4IdsKey key3WithChamber{gid.region(), gid.station(), gid.layer(), gid.chamber()};
186  if (!MEMap2Check_[key2]) {
187  auto strSuffixName = GEMUtils::getSuffixName(key2);
188  auto strSuffixTitle = GEMUtils::getSuffixTitle(key2);
189  BookingHelper bh2(ibooker, strSuffixName, strSuffixTitle);
190  ProcessWithMEMap2(bh2, key2);
191  MEMap2Check_[key2] = true;
192  }
193  if (!MEMap3Check_[key3]) {
194  auto strSuffixName = GEMUtils::getSuffixName(key3);
195  auto strSuffixTitle = GEMUtils::getSuffixTitle(key3);
196  BookingHelper bh3(ibooker, strSuffixName, strSuffixTitle);
197  ProcessWithMEMap3(bh3, key3);
198  MEMap3Check_[key3] = true;
199  }
200  if (!MEMap3WithChCheck_[key3WithChamber]) {
201  Int_t nCh = gid.chamber();
202  Int_t nLa = gid.layer();
203  char cLS = (nCh % 2 == 0 ? 'L' : 'S'); // FIXME: Is it general enough?
204  auto strSuffixName = GEMUtils::getSuffixName(key2) + Form("-%02iL%i-%c", nCh, nLa, cLS);
205  auto strSuffixTitle = GEMUtils::getSuffixTitle(key2) + Form("-%02iL%i-%c", nCh, nLa, cLS);
206  BookingHelper bh3Ch(ibooker, strSuffixName, strSuffixTitle);
207  ProcessWithMEMap3WithChamber(bh3Ch, key3WithChamber);
208  MEMap3WithChCheck_[key3WithChamber] = true;
209  }
210  for (auto iEta : ch.etaPartitions()) {
211  GEMDetId eId = iEta->id();
212  ME4IdsKey key4{gid.region(), gid.station(), gid.layer(), eId.ieta()};
213  ME3IdsKey key2WithEta{gid.region(), gid.station(), eId.ieta()};
214  ME3IdsKey key2AbsReWithEta{std::abs(gid.region()), gid.station(), eId.ieta()};
215  if (!MEMap4Check_[key4]) {
216  auto strSuffixName = GEMUtils::getSuffixName(key3) + Form("-E%02i", eId.ieta());
217  auto strSuffixTitle = GEMUtils::getSuffixTitle(key3) + Form("-E%02i", eId.ieta());
218  BookingHelper bh4(ibooker, strSuffixName, strSuffixTitle);
219  ProcessWithMEMap4(bh4, key4);
220  MEMap4Check_[key4] = true;
221  }
222  if (!MEMap2WithEtaCheck_[key2WithEta]) {
223  auto strSuffixName = GEMUtils::getSuffixName(key2) + Form("-E%02i", eId.ieta());
224  auto strSuffixTitle = GEMUtils::getSuffixTitle(key2) + Form("-E%02i", eId.ieta());
225  BookingHelper bh3(ibooker, strSuffixName, strSuffixTitle);
226  ProcessWithMEMap2WithEta(bh3, key2WithEta);
227  MEMap2WithEtaCheck_[key2WithEta] = true;
228  }
229  if (!MEMap2AbsReWithEtaCheck_[key2AbsReWithEta]) {
230  auto strSuffixName = Form("_GE%d1-E%02i", gid.station(), eId.ieta());
231  auto strSuffixTitle = Form(" GE%d1-E%02i", gid.station(), eId.ieta());
232  BookingHelper bh3(ibooker, strSuffixName, strSuffixTitle);
233  ProcessWithMEMap2AbsReWithEta(bh3, key2AbsReWithEta);
234  MEMap2AbsReWithEtaCheck_[key2AbsReWithEta] = true;
235  }
236  }
237  }
238  return 0;
239 }
240 
242  auto listSuperChambers = station->superChambers();
243 
244  Bool_t bDoneEven = false, bDoneOdd = false;
245 
246  // Obtaining radius intervals of even/odd chambers
247  for (auto superchamber : listSuperChambers) {
248  Int_t chamberNo = superchamber->id().chamber();
249  if (chamberNo % 2 == 0 && bDoneEven)
250  continue;
251  if (chamberNo % 2 != 0 && bDoneOdd)
252  continue;
253 
254  auto& etaPartitions = superchamber->chambers().front()->etaPartitions();
255 
256  // A little of additional procedures to list up the radius intervals
257  // It would be independent to local direction of chambers and the order of eta partitions
258  // 1. Obtain the radius of the middle top/bottom points of the trapezoid
259  // 2. Sort these two values and determine which one is the lower/upper one
260  // 3. Keep them all and then sort them
261  // 4. The intermediate radii are set as the mean of the corresponding values of upper/lowers.
262  std::vector<Float_t> listRadiusLower, listRadiusUpper;
263  for (auto iEta : etaPartitions) {
264  const GEMStripTopology& stripTopology = dynamic_cast<const GEMStripTopology&>(iEta->specificTopology());
265  Float_t fHeight = stripTopology.stripLength();
266  LocalPoint lp1(0.0, -0.5 * fHeight), lp2(0.0, 0.5 * fHeight);
267  auto& surface = iEta->surface();
268  GlobalPoint gp1 = surface.toGlobal(lp1), gp2 = surface.toGlobal(lp2);
269  Float_t fR1 = gp1.perp(), fR2 = gp2.perp();
270  Float_t fRL = std::min(fR1, fR2), fRH = std::max(fR1, fR2);
271  listRadiusLower.push_back(fRL);
272  listRadiusUpper.push_back(fRH);
273  // For a future usage
274  //std::cout << "GEO_RADIUS: " << iEta->id().chamber() << " " << iEta->id().ieta() << " "
275  // << fRL << " " << fRH << std::endl;
276  }
277 
278  std::sort(listRadiusLower.begin(), listRadiusLower.end());
279  std::sort(listRadiusUpper.begin(), listRadiusUpper.end());
280 
281  std::vector<Float_t>& listR =
282  (chamberNo % 2 == 0 ? stationInfo.listRadiusEvenChamber_ : stationInfo.listRadiusOddChamber_);
283  listR.clear();
284  listR.push_back(listRadiusLower.front());
285  for (int i = 1; i < (int)listRadiusLower.size(); i++) {
286  listR.push_back(0.5 * (listRadiusLower[i] + listRadiusUpper[i - 1]));
287  }
288  listR.push_back(listRadiusUpper.back());
289 
290  if (chamberNo % 2 == 0)
291  bDoneEven = true;
292  if (chamberNo % 2 != 0)
293  bDoneOdd = true;
294 
295  if (bDoneEven && bDoneOdd)
296  break;
297  }
298 
299  return 0;
300 }
301 
303  auto listSuperChambers = station->superChambers();
304  //Int_t nNumStripVFAT = stationInfo.nNumDigi_ / ( stationInfo.nMaxVFAT_ / stationInfo.nNumEtaPartitions_ );
305  Int_t nNumStripEta = stationInfo.nNumDigi_ * (stationInfo.nMaxVFAT_ / stationInfo.nNumEtaPartitions_);
306 
307  std::vector<std::pair<Int_t, std::pair<std::pair<Float_t, Float_t>, Bool_t>>> listDivPhi;
308 
309  // Obtaining phi intervals of chambers
310  for (auto superchamber : listSuperChambers) {
311  auto iEta = superchamber->chambers().front()->etaPartitions().front();
312 
313  // What is the index of the first strip? Rather than to ask to someone, let's calculate it!
314  Float_t fWidthStrip = std::abs(iEta->centreOfStrip((Int_t)1).x() - iEta->centreOfStrip((Int_t)0).x());
315  LocalPoint lpRef(-fWidthStrip / 3.0, 0.0);
316  Int_t nStripMid = (Int_t)iEta->strip(lpRef);
317  Int_t nFirstStrip = 1 - ((nNumStripEta / 2) - nStripMid);
318  Int_t nLastStrip = nFirstStrip + nNumStripEta - 1;
319 
320  auto& surface = iEta->surface();
321  LocalPoint lpF = iEta->centreOfStrip((Float_t)(nFirstStrip - 0.5)); // To avoid the round error(?)
322  LocalPoint lpL = iEta->centreOfStrip((Float_t)(nLastStrip + 0.5)); // To avoid the round error(?)
323  GlobalPoint gpF = surface.toGlobal(lpF);
324  GlobalPoint gpL = surface.toGlobal(lpL);
325 
326  Float_t fPhiF = gpF.phi();
327  Float_t fPhiL = gpL.phi();
328  if (fPhiF * fPhiL < 0 && std::abs(fPhiF) > 0.5 * 3.14159265359) {
329  if (fPhiF < 0)
330  fPhiF += 2 * 3.14159265359;
331  if (fPhiL < 0)
332  fPhiL += 2 * 3.14159265359;
333  }
334  Bool_t bFlipped = fPhiF > fPhiL;
335  Float_t fPhiMin = std::min(fPhiF, fPhiL);
336  Float_t fPhiMax = std::max(fPhiF, fPhiL);
337 
338  listDivPhi.emplace_back();
339  listDivPhi.back().first = iEta->id().chamber();
340  listDivPhi.back().second.first.first = fPhiMin;
341  listDivPhi.back().second.first.second = fPhiMax;
342  listDivPhi.back().second.second = bFlipped;
343  }
344 
345  stationInfo.fMinPhi_ = 1048576.0;
346  for (auto p : listDivPhi) {
347  if (p.first == 1) {
348  stationInfo.fMinPhi_ = p.second.first.first;
349  break;
350  }
351  }
352 
353  // For a future usage
354  //for ( auto p : listDivPhi ) {
355  // std::cout << "GEO_PHI: " << p.first << " "
356  // << p.second.first.first << " " << p.second.first.second << " " << p.second.second << std::endl;
357  //}
358 
359  return 0;
360 }
float stripLength() const override
T getUntrackedParameter(std::string const &, T const &) const
Int_t nNumEtaPartitionGE11_
Definition: GEMDQMBase.h:588
dqm::impl::MonitorElement * CreateSummaryHist(DQMStore::IBooker &ibooker, TString strName)
Definition: GEMDQMBase.cc:142
bool checkRefs(const std::vector< T * > &)
Definition: GEMDQMBase.h:594
tuple cfg
Definition: looper.py:296
Int_t nRunType_
Definition: GEMDQMBase.h:516
T perp() const
Definition: PV3DBase.h:69
virtual int ProcessWithMEMap4(BookingHelper &bh, ME4IdsKey key)
Definition: GEMDQMBase.h:529
TString getSuffixName(Int_t region_id)
virtual int ProcessWithMEMap2AbsReWithEta(BookingHelper &bh, ME3IdsKey key)
Definition: GEMDQMBase.h:527
int initGeometry(edm::EventSetup const &iSetup)
Definition: GEMDQMBase.cc:31
std::tuple< Int_t, Int_t, Int_t, Int_t > ME4IdsKey
int readGeometryRadiusInfoChamber(const GEMStation *station, MEStationInfo &stationInfo)
Definition: GEMDQMBase.cc:241
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
std::map< ME3IdsKey, MEStationInfo > mapStationInfo_
Definition: GEMDQMBase.h:585
int keyToRegion(ME2IdsKey key)
Definition: GEMDQMBase.h:532
int readGeometryPhiInfoChamber(const GEMStation *station, MEStationInfo &stationInfo)
Definition: GEMDQMBase.cc:302
int loadChambers()
Definition: GEMDQMBase.cc:62
std::map< ME3IdsKey, int > mapStationToIdx_
Definition: GEMDQMBase.h:584
static const int maxChan_
Definition: GEMeMap.h:72
int keyToLayer(ME3IdsKey key)
Definition: GEMDQMBase.h:538
Log< level::Error, false > LogError
TString getSuffixTitle(Int_t region_id)
std::vector< Float_t > listRadiusOddChamber_
Definition: GEMDQMBase.h:498
std::string log_category_
Definition: GEMDQMBase.h:518
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:122
char const * label
std::map< ME3IdsKey, bool > MEMap2AbsReWithEtaCheck_
Definition: GEMDQMBase.h:578
std::map< ME2IdsKey, bool > MEMap2Check_
Definition: GEMDQMBase.h:576
virtual int ProcessWithMEMap3(BookingHelper &bh, ME3IdsKey key)
Definition: GEMDQMBase.h:528
virtual void setXTitle(std::string const &title)
int GenerateMEPerChamber(DQMStore::IBooker &ibooker)
Definition: GEMDQMBase.cc:174
std::vector< Float_t > listRadiusEvenChamber_
Definition: GEMDQMBase.h:497
std::map< ME3IdsKey, bool > MEMap3Check_
Definition: GEMDQMBase.h:579
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:46
virtual int ProcessWithMEMap3WithChamber(BookingHelper &bh, ME4IdsKey key)
Definition: GEMDQMBase.h:530
std::vector< GEMChamber > gemChambers_
Definition: GEMDQMBase.h:574
edm::ESGetToken< GEMGeometry, MuonGeometryRecord > geomToken_
Definition: GEMDQMBase.h:572
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:603
int keyToStation(ME2IdsKey key)
Definition: GEMDQMBase.h:535
std::map< ME4IdsKey, bool > MEMap4Check_
Definition: GEMDQMBase.h:581
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:571
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:212
constexpr int station() const
Definition: GEMDetId.h:179
virtual int ProcessWithMEMap2WithEta(BookingHelper &bh, ME3IdsKey key)
Definition: GEMDQMBase.h:526
int SortingLayers(std::vector< ME3IdsKey > &listLayers)
Definition: GEMDQMBase.cc:123
GEMDQMBase(const edm::ParameterSet &cfg)
Definition: GEMDQMBase.cc:7
std::map< ME3IdsKey, bool > MEMap2WithEtaCheck_
Definition: GEMDQMBase.h:577
int nMaxNumCh_
Definition: GEMDQMBase.h:583
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:587
std::map< ME4IdsKey, bool > MEMap3WithChCheck_
Definition: GEMDQMBase.h:580
Int_t nNumEtaPartitionGE21_
Definition: GEMDQMBase.h:589
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
virtual int ProcessWithMEMap2(BookingHelper &bh, ME2IdsKey key)
Definition: GEMDQMBase.h:525