CMS 3D CMS Logo

GEMEffByGEMCSCSegmentSource.cc
Go to the documentation of this file.
2 
4 
7  kGEMGeometryTokenBeginRun_(esConsumes<edm::Transition::BeginRun>()),
8  kGEMCSCSegmentCollectionToken_(
9  consumes<GEMCSCSegmentCollection>(ps.getUntrackedParameter<edm::InputTag>("gemcscSegmentTag"))),
10  kMuonCollectionToken_(consumes<reco::MuonCollection>(ps.getUntrackedParameter<edm::InputTag>("muonTag"))),
11  kMinCSCRecHits_(ps.getUntrackedParameter<int>("minCSCRecHits")),
12  kModeDev_(ps.getUntrackedParameter<bool>("modeDev")),
13  kUseMuonSegment_(ps.getUntrackedParameter<bool>("useMuonSegment")),
14  kFolder_(ps.getUntrackedParameter<std::string>("folder")) {}
15 
17 
20 
21  // GEMDQMEfficiencySourceBase
22  desc.addUntracked<edm::InputTag>("ohStatusTag", edm::InputTag("muonGEMDigis", "OHStatus"));
23  desc.addUntracked<edm::InputTag>("vfatStatusTag", edm::InputTag("muonGEMDigis", "VFATStatus"));
24  desc.addUntracked<bool>("monitorGE11", true);
25  desc.addUntracked<bool>("monitorGE21", false);
26  desc.addUntracked<bool>("monitorGE0", false);
27  desc.addUntracked<bool>("maskChamberWithError", false);
28  desc.addUntracked<std::string>("logCategory", "GEMEffByGEMCSCSegmentSource");
29 
30  // GEMEffByGEMCSCSegmentSource
31  desc.addUntracked<edm::InputTag>("gemcscSegmentTag", edm::InputTag("gemcscSegments"));
32  desc.addUntracked<edm::InputTag>("muonTag", edm::InputTag("muons"));
33  desc.addUntracked<int>("minCSCRecHits", 6);
34  desc.addUntracked<bool>("useMuonSegment", false);
35  desc.addUntracked<bool>("modeDev", false);
36  desc.addUntracked<std::string>("folder", "GEM/Efficiency/GEMCSCSegment");
37 
38  descriptions.addWithDefaultLabel(desc);
39 }
40 
42  edm::Run const& run,
43  edm::EventSetup const& setup) {
44  const GEMGeometry* gem = nullptr;
45  if (auto handle = setup.getHandle(kGEMGeometryTokenBeginRun_)) {
46  gem = handle.product();
47  } else {
48  edm::LogError(kLogCategory_ + "|bookHistograms") << "failed to get GEMGeometry";
49  return;
50  }
51 
52  ibooker.setCurrentFolder(kFolder_);
53 
54  for (const GEMStation* station : gem->stations()) {
55  const int region_id = station->region();
56  const int station_id = station->station();
57 
58  if (skipGEMStation(station_id))
59  continue;
60 
61  if (station_id == 1) {
63  // Region - Station - Layer
65  const std::vector<const GEMSuperChamber*> superchamber_vec = station->superChambers();
66  if (not checkRefs(superchamber_vec)) {
67  edm::LogError(kLogCategory_) << "got an invalid ptr from GEMStation::superChambers";
68  return;
69  }
70 
71  const std::vector<const GEMChamber*> chamber_vec = superchamber_vec.front()->chambers();
72  if (not checkRefs(chamber_vec)) {
73  edm::LogError(kLogCategory_) << "got an invalid ptr from GEMSuperChamber::chambers";
74  return;
75  }
76 
77  // we actually loop over layers
78  for (const GEMChamber* chamber : chamber_vec) {
79  const int layer_id = chamber->id().layer();
80  const GEMDetId key = getReStLaKey(chamber->id());
81  const TString suffix = GEMUtils::getSuffixName(region_id, station_id, layer_id);
82  const TString title = GEMUtils::getSuffixTitle(region_id, station_id, layer_id);
83 
84  // book MEs for the efficiency vs the GEM chambver id
85  me_chamber_[key] = bookChamber(ibooker, "chamber" + suffix, title, station);
87 
88  if (kUseMuonSegment_) {
89  me_chamber_muon_segment_[key] = bookChamber(ibooker, "muon_chamber" + suffix, title, station);
91  }
92 
93  if (kModeDev_) {
94  // book MEs for the efficiency vs the number of CSC hits in a CSC segment
95  // CSCSegAlgoRU: min hits = 4, max hits = CSC layers = 6
96  me_num_csc_hits_[key] = ibooker.book1D("num_csc_hits" + suffix, title, 4, 2.5, 6.5);
97  me_num_csc_hits_[key]->setAxisTitle("Number of CSC Hits", 1);
99 
100  me_csc_reduced_chi2_[key] = ibooker.book1D("reduced_chi2" + suffix, title, 100, 0.0, 10.0);
101  me_csc_reduced_chi2_[key]->setAxisTitle("#chi^{2} / N_{dof} of CSC Segment", 1);
103 
104  me_csc_chamber_type_[key] = bookCSCChamberType(ibooker, "csc_chamber_type" + suffix, title);
106  }
107  } // GEMChamber
108  } else {
109  edm::LogWarning(kLogCategory_) << "The monitoring for "; // TODO
110  continue;
111  }
112  } // GEMStataion
113 }
114 
115 // https://github.com/cms-sw/cmssw/blob/CMSSW_12_3_0_pre5/DataFormats/MuonDetId/interface/CSCDetId.h#L187-L193
117  const TString& name,
118  const TString& title) {
119  MonitorElement* monitor_element = ibooker.book1D(name, title, 10, 0.5, 10.5);
120  monitor_element->setAxisTitle("CSC chamber type", 1);
121  for (int chamber_type = 1; chamber_type <= 10; chamber_type++) {
122  const std::string label = CSCDetId::chamberName(chamber_type);
123  monitor_element->setBinLabel(chamber_type, label, 1);
124  }
125  return monitor_element;
126 }
127 
130  // get data from event
132  const GEMCSCSegmentCollection* gemcsc_segment_collection = nullptr;
134  gemcsc_segment_collection = handle.product();
135 
136  } else {
137  edm::LogError(kLogCategory_) << "invalid GEMCSCSegmentCollection";
138  return;
139  }
140 
141  const reco::MuonCollection* muon_collection = nullptr;
142  if (kUseMuonSegment_) {
144  muon_collection = handle.product();
145 
146  } else {
147  edm::LogError(kLogCategory_) << "invalid reco::MuonCollection";
148  return;
149  }
150  }
151 
152  const GEMOHStatusCollection* oh_status_collection = nullptr;
153  const GEMVFATStatusCollection* vfat_status_collection = nullptr;
155  if (auto handle = event.getHandle(kGEMOHStatusCollectionToken_)) {
156  oh_status_collection = handle.product();
157  } else {
158  edm::LogError(kLogCategory_) << "failed to get OHVFATStatusCollection";
159  return;
160  }
161 
162  if (auto handle = event.getHandle(kGEMVFATStatusCollectionToken_)) {
163  vfat_status_collection = handle.product();
164  } else {
165  edm::LogError(kLogCategory_) << "failed to get GEMVFATStatusCollection";
166  return;
167  }
168  }
169 
171  // NOTE
173  if (gemcsc_segment_collection->size() < 1) {
174  LogDebug(kLogCategory_) << "empty GEMCSCSegment";
175  return;
176  }
177 
178  if (kUseMuonSegment_) {
179  findMatchedME11Segments(muon_collection);
180  }
181 
182  for (edm::OwnVector<GEMCSCSegment>::const_iterator iter = gemcsc_segment_collection->begin();
183  iter != gemcsc_segment_collection->end();
184  iter++) {
185  const GEMCSCSegment& gemcsc_segment = *iter;
186 
187  const CSCDetId csc_id = gemcsc_segment.cscDetId();
188  if (csc_id.isME11()) {
189  analyzeGE11ME11Segment(gemcsc_segment, oh_status_collection, vfat_status_collection);
190 
191  } else {
192  LogDebug(kLogCategory_) << "skip " << csc_id;
193  continue;
194  }
195  } // GEMCSCSegment
196 }
197 
198 // TODO doc
200  const GEMOHStatusCollection* oh_status_collection,
201  const GEMVFATStatusCollection* vfat_status_collection) {
202  const GEMRecHit* ge11_hit_layer1 = nullptr;
203  const GEMRecHit* ge11_hit_layer2 = nullptr;
204 
205  const CSCDetId csc_id = gemcsc_segment.cscDetId();
206  for (const GEMRecHit& gem_hit : gemcsc_segment.gemRecHits()) {
207  const GEMDetId gem_id = gem_hit.gemId();
208 
209  if (not gem_id.isGE11()) {
210  edm::LogWarning(kLogCategory_) << "CSCSegment is in " << csc_id << " but GEMRecHit is in " << gem_id
211  << ". skip this GEMCSCSegment."
212  << "check if RecoLocalMuon/GEMCSCSegment/plugins/GEMCSCSegAlgoRR.cc has changed.";
213  return;
214  }
215 
217  const bool has_error = maskChamberWithError(gem_id.chamberId(), oh_status_collection, vfat_status_collection);
218  if (has_error) {
219  return;
220  }
221  }
222 
223  const int layer = gem_id.layer();
224  if (layer == 1) {
225  ge11_hit_layer1 = &gem_hit;
226 
227  } else if (layer == 2) {
228  ge11_hit_layer2 = &gem_hit;
229 
230  } else {
231  edm::LogError(kLogCategory_) << "isGE11 but got unexpected layer " << gem_id << ". skip this GEMCSCSegment.";
232  return;
233  }
234  } // GEMRecHit
235 
236  checkCoincidenceGE11(ge11_hit_layer1, ge11_hit_layer2, gemcsc_segment);
237  checkCoincidenceGE11(ge11_hit_layer2, ge11_hit_layer1, gemcsc_segment);
238 }
239 
240 // TODO doc
242  const GEMRecHit* detection_layer_hit,
243  const GEMCSCSegment& gemcsc_segment) {
244  if (trigger_layer_hit == nullptr) {
245  LogDebug(kLogCategory_) << "trigger_layer_hit is nullptr";
246  return;
247  }
248 
249  const GEMDetId trigger_layer_id = trigger_layer_hit->gemId();
250  const int detection_layer = trigger_layer_id.layer() == 1 ? 2 : 1;
251  // detection layer key
252  // GEMDetId(int region, int ring, int station, int layer, int chamber, int ieta)
253  const GEMDetId key{trigger_layer_id.region(), 1, trigger_layer_id.station(), detection_layer, 0, 0};
254 
255  const int chamber = trigger_layer_id.chamber();
256  const bool is_matched = kUseMuonSegment_ ? isME11SegmentMatched(gemcsc_segment.cscSegment()) : false;
257 
258  const int num_csc_hits = static_cast<int>(gemcsc_segment.cscRecHits().size());
259  const double reduced_chi2 = gemcsc_segment.chi2() / gemcsc_segment.degreesOfFreedom();
260  const int csc_chamber_type = gemcsc_segment.cscDetId().iChamberType();
261 
262  if (kModeDev_) {
263  fillME(me_num_csc_hits_, key, num_csc_hits);
265  fillME(me_csc_chamber_type_, key, csc_chamber_type);
266 
267  if (detection_layer_hit) {
268  fillME(me_num_csc_hits_matched_, key, num_csc_hits);
270  fillME(me_csc_chamber_type_matched_, key, csc_chamber_type);
271  }
272  }
273 
274  // TODO add a method
275  const bool is_good = num_csc_hits >= kMinCSCRecHits_;
276  if (not is_good) {
277  return;
278  }
279 
280  // twofold coincidence rate
282  if (is_matched) {
284  }
285 
286  // threefold coincidence rate
287  if (detection_layer_hit) {
289  if (is_matched) {
291  }
292  }
293 }
294 
295 // TODO docs
298 
299  if (muon_collection == nullptr) {
300  // TODO log
301  return;
302  }
303 
304  for (unsigned int idx = 0; idx < muon_collection->size(); idx++) {
305  const reco::Muon& muon = muon_collection->at(idx);
306 
307  for (const reco::MuonChamberMatch& chamber_match : muon.matches()) {
308  if (chamber_match.detector() != MuonSubdetId::CSC) {
309  continue;
310  }
311 
312  const CSCDetId csc_id{chamber_match.id};
313  if (not csc_id.isME11()) {
314  continue;
315  }
316 
317  for (const reco::MuonSegmentMatch& segment_match : chamber_match.segmentMatches) {
318  if (not segment_match.isMask(reco::MuonSegmentMatch::BestInStationByDR)) {
319  continue;
320  }
321  matched_me11_segment_vector_.push_back(segment_match.cscSegmentRef.get());
322  } // MuonSegmentMatch
323  } // MuonChamberMatch
324  } // MuonCollection
325 }
326 
327 // TODO
329  bool found = false;
330 
331  const CSCDetId csc_id = csc_segment.cscDetId();
332  if (not csc_id.isME11()) {
333  return false;
334  }
335 
336  for (const CSCSegment* matched_segment : matched_me11_segment_vector_) {
337  if (csc_id != matched_segment->cscDetId())
338  continue;
339  if (csc_segment.localPosition().x() != matched_segment->localPosition().x())
340  continue;
341  if (csc_segment.localPosition().y() != matched_segment->localPosition().y())
342  continue;
343  if (csc_segment.localPosition().z() != matched_segment->localPosition().z())
344  continue;
345  if (csc_segment.time() != matched_segment->time())
346  continue;
347 
348  found = true;
349  }
350 
351  return found;
352 }
GEMEffByGEMCSCSegmentSource(const edm::ParameterSet &)
const edm::ESGetToken< GEMGeometry, MuonGeometryRecord > kGEMGeometryTokenBeginRun_
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
constexpr int station() const
Definition: GEMDetId.h:179
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
bool isGE11() const
Definition: GEMDetId.cc:9
constexpr int region() const
Definition: GEMDetId.h:171
float time() const
Definition: CSCSegment.cc:144
LocalPoint localPosition() const override
Definition: CSCSegment.h:39
TString getSuffixName(Int_t region_id)
CSCSegmentRef cscSegmentRef
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
void checkCoincidenceGE11(const GEMRecHit *, const GEMRecHit *, const GEMCSCSegment &)
T z() const
Definition: PV3DBase.h:61
const std::vector< GEMRecHit > & gemRecHits() const
Definition: GEMCSCSegment.h:68
void fillMEWithinLimits(MonitorElement *, const double)
const edm::EDGetTokenT< reco::MuonCollection > kMuonCollectionToken_
bool maskChamberWithError(const GEMDetId &chamber_id, const GEMOHStatusCollection *, const GEMVFATStatusCollection *)
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
static void fillDescriptions(edm::ConfigurationDescriptions &)
int degreesOfFreedom() const override
Degrees of freedom of the segment fit.
Definition: GEMCSCSegment.h:62
Log< level::Error, false > LogError
TString getSuffixTitle(Int_t region_id)
constexpr int layer() const
Definition: GEMDetId.h:190
unsigned short iChamberType() const
Definition: CSCDetId.h:96
const edm::EDGetTokenT< GEMVFATStatusCollection > kGEMVFATStatusCollectionToken_
static const unsigned int BestInStationByDR
constexpr int chamber() const
Definition: GEMDetId.h:183
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
void fillME(MEMap &, const GEMDetId &, const double)
void findMatchedME11Segments(const reco::MuonCollection *)
char const * label
double chi2() const override
Chi2 of the segment fit.
Definition: GEMCSCSegment.h:58
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
MonitorElement * bookCSCChamberType(DQMStore::IBooker &, const TString &, const TString &)
std::string chamberName() const
Definition: CSCDetId.cc:92
MonitorElement * bookNumerator1D(DQMStore::IBooker &, MonitorElement *)
CSCDetId cscDetId() const
Definition: GEMCSCSegment.h:73
bool isMask(unsigned int flag=Arbitrated) const
Transition
Definition: Transition.h:12
MonitorElement * bookChamber(DQMStore::IBooker &, const TString &, const TString &, const GEMStation *)
virtual void setBinLabel(int bin, const std::string &label, int axis=1)
set bin label for x, y or z axis (axis=1, 2, 3 respectively)
void analyzeGE11ME11Segment(const GEMCSCSegment &, const GEMOHStatusCollection *, const GEMVFATStatusCollection *)
const edm::EDGetTokenT< GEMOHStatusCollection > kGEMOHStatusCollectionToken_
const std::vector< CSCRecHit2D > & cscRecHits() const
Definition: GEMCSCSegment.h:69
bool checkRefs(const std::vector< T *> &)
GEMDetId gemId() const
Return the gemId.
Definition: GEMRecHit.h:65
bool isME11() const
Definition: CSCDetId.cc:64
CSCDetId cscDetId() const
Definition: CSCSegment.h:70
fixed size matrix
HLT enums.
bool isME11SegmentMatched(const CSCSegment &)
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:232
void analyze(const edm::Event &event, const edm::EventSetup &eventSetup) override
constexpr GEMDetId chamberId() const
Definition: GEMDetId.h:204
std::vector< const CSCSegment * > matched_me11_segment_vector_
GEMDetId getReStLaKey(const GEMDetId &)
const CSCSegment cscSegment() const
Definition: GEMCSCSegment.h:67
Log< level::Warning, false > LogWarning
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
const edm::EDGetTokenT< GEMCSCSegmentCollection > kGEMCSCSegmentCollectionToken_
static constexpr int CSC
Definition: MuonSubdetId.h:12
Definition: event.py:1
Definition: Run.h:45
#define LogDebug(id)
virtual void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
A container for a generic type of digis indexed by some index, implemented with a map<IndexType...