CMS 3D CMS Logo

GEMRecHitMatcher.cc
Go to the documentation of this file.
4 
5 using namespace std;
6 
8  const auto& gemRecHit = pset.getParameterSet("gemRecHit");
9  minBX_ = gemRecHit.getParameter<int>("minBX");
10  maxBX_ = gemRecHit.getParameter<int>("maxBX");
11  verbose_ = gemRecHit.getParameter<int>("verbose");
12 
13  // make a new digi matcher
14  gemDigiMatcher_.reset(new GEMDigiMatcher(pset, std::move(iC)));
15 
16  gemRecHitToken_ = iC.consumes<GEMRecHitCollection>(gemRecHit.getParameter<edm::InputTag>("inputTag"));
17 }
18 
20  gemDigiMatcher_->init(iEvent, iSetup);
21 
22  iEvent.getByToken(gemRecHitToken_, gemRecHitH_);
23 
24  iSetup.get<MuonGeometryRecord>().get(gem_geom_);
25  if (gem_geom_.isValid()) {
26  gemGeometry_ = &*gem_geom_;
27  } else {
28  std::cout << "+++ Info: GEM geometry is unavailable. +++\n";
29  }
30 }
31 
34  // match digis first
35  gemDigiMatcher_->match(t, v);
36 
37  // get the rechit collection
38  const GEMRecHitCollection& gemRecHits = *gemRecHitH_.product();
39 
40  // now match the rechits
41  matchRecHitsToSimTrack(gemRecHits);
42 }
43 
45  // get the matched ids with digis
46  const auto& det_ids = gemDigiMatcher_->detIdsDigi();
47 
48  // loop on those ids
49  for (auto id : det_ids) {
50  // now check the digis in this detid
51  const auto& hit_digis = gemDigiMatcher_->stripNumbersInDetId(id);
52  if (verbose()) {
53  cout << "hit_digis_fat ";
54  copy(hit_digis.begin(), hit_digis.end(), ostream_iterator<int>(cout, " "));
55  cout << endl;
56  }
57 
58  GEMDetId p_id(id);
59  const auto& rechits_in_det = rechits.get(p_id);
60 
61  for (auto d = rechits_in_det.first; d != rechits_in_det.second; ++d) {
62  if (verbose())
63  cout << "recHit " << p_id << " " << *d << endl;
64 
65  // check that the rechit is within BX range
66  if (d->BunchX() < minBX_ || d->BunchX() > maxBX_)
67  continue;
68 
69  int firstStrip = d->firstClusterStrip();
70  int cls = d->clusterSize();
71  bool stripFound = false;
72 
73  // check that it matches a strip that was hit by digis from our track
74  for (int i = firstStrip; i < (firstStrip + cls); i++) {
75  if (hit_digis.find(i) != hit_digis.end())
76  stripFound = true;
77  }
78 
79  // this rechit did not correspond with any previously matched digi
80  if (!stripFound)
81  continue;
82  if (verbose())
83  cout << "oki" << endl;
84 
85  recHits_.push_back(*d);
86  detid_to_recHits_[id].push_back(*d);
87  chamber_to_recHits_[p_id.chamberId().rawId()].push_back(*d);
88  superchamber_to_recHits_[p_id.superChamberId().rawId()].push_back(*d);
89  }
90  }
91 }
92 
93 std::set<unsigned int> GEMRecHitMatcher::detIds() const {
94  std::set<unsigned int> result;
95  for (const auto& p : detid_to_recHits_)
96  result.insert(p.first);
97  return result;
98 }
99 
100 std::set<unsigned int> GEMRecHitMatcher::chamberIds() const {
101  std::set<unsigned int> result;
102  for (const auto& p : chamber_to_recHits_)
103  result.insert(p.first);
104  return result;
105 }
106 
107 std::set<unsigned int> GEMRecHitMatcher::superChamberIds() const {
108  std::set<unsigned int> result;
109  for (const auto& p : superchamber_to_recHits_)
110  result.insert(p.first);
111  return result;
112 }
113 
114 const GEMRecHitContainer& GEMRecHitMatcher::recHitsInDetId(unsigned int detid) const {
115  if (detid_to_recHits_.find(detid) == detid_to_recHits_.end())
116  return no_recHits_;
117  return detid_to_recHits_.at(detid);
118 }
119 
120 const GEMRecHitContainer& GEMRecHitMatcher::recHitsInChamber(unsigned int detid) const {
121  if (chamber_to_recHits_.find(detid) == chamber_to_recHits_.end())
122  return no_recHits_;
123  return chamber_to_recHits_.at(detid);
124 }
125 
127  if (superchamber_to_recHits_.find(detid) == superchamber_to_recHits_.end())
128  return no_recHits_;
129  return superchamber_to_recHits_.at(detid);
130 }
131 
133  set<int> layers;
134  for (const auto& d : recHitsInSuperChamber(detid)) {
135  layers.insert(d.gemId().layer());
136  }
137  return layers.size();
138 }
139 
140 std::set<int> GEMRecHitMatcher::stripNumbersInDetId(unsigned int detid) const {
141  set<int> result;
142  for (const auto& d : recHitsInDetId(detid)) {
143  // loop on all strips hit in this rechit
144  for (int iStrip = d.firstClusterStrip(); iStrip < d.firstClusterStrip() + d.clusterSize(); ++iStrip) {
145  result.insert(iStrip);
146  }
147  }
148  return result;
149 }
150 
151 std::set<int> GEMRecHitMatcher::partitionNumbers() const {
152  std::set<int> result;
153 
154  for (auto id : detIds()) {
155  GEMDetId idd(id);
156  result.insert(idd.roll());
157  }
158  return result;
159 }
160 
162  const GEMDetId& idd = rechit.gemId();
163  const LocalPoint& lp = rechit.localPosition();
164  return gemGeometry_->idToDet(idd)->surface().toGlobal(lp);
165 }
166 
168  GlobalPoint point_zero;
169  if (rechit.empty())
170  return point_zero; // point "zero"
171 
172  float sumx, sumy, sumz;
173  sumx = sumy = sumz = 0.f;
174  size_t n = 0;
175  for (const auto& d : rechit) {
176  GlobalPoint gp = recHitPosition(d);
177  if (gp == point_zero)
178  continue;
179 
180  sumx += gp.x();
181  sumy += gp.y();
182  sumz += gp.z();
183  ++n;
184  }
185  if (n == 0)
186  return GlobalPoint();
187  return GlobalPoint(sumx / n, sumy / n, sumz / n);
188 }
189 
191  bool isSame = false;
192  for (const auto& thisRH : c)
193  if (areGEMRecHitSame(thisRH, rh))
194  isSame = true;
195  return isSame;
196 }
197 
199  return recHitInContainer(thisRh, recHits());
200 }
201 
203  return l.localPosition() == r.localPosition() and l.BunchX() == r.BunchX();
204 }
GEMRecHitCollection
mps_fire.i
i
Definition: mps_fire.py:355
muonGEMRecHitPSet.gemRecHit
gemRecHit
Definition: muonGEMRecHitPSet.py:3
SimVertex
Definition: SimVertex.h:5
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
gather_cfg.cout
cout
Definition: gather_cfg.py:144
GEMDigiMatcher
Definition: GEMDigiMatcher.h:28
GEMDetId::superChamberId
constexpr GEMDetId superChamberId() const
Definition: GEMDetId.h:196
GEMRecHitMatcher::chamberIds
std::set< unsigned int > chamberIds() const
Definition: GEMRecHitMatcher.cc:100
findQualityFiles.v
v
Definition: findQualityFiles.py:179
GEMRecHitMatcher::recHitInContainer
bool recHitInContainer(const GEMRecHit &rh, const GEMRecHitContainer &c) const
Definition: GEMRecHitMatcher.cc:190
GEMRecHitMatcher::recHitPosition
GlobalPoint recHitPosition(const GEMRecHit &rechit) const
Definition: GEMRecHitMatcher.cc:161
edm::EventSetup::get
T get() const
Definition: EventSetup.h:73
GEMRecHitMatcher::areGEMRecHitSame
bool areGEMRecHitSame(const GEMRecHit &l, const GEMRecHit &r) const
Definition: GEMRecHitMatcher.cc:202
GEMRecHitMatcher::recHitsInChamber
const GEMRecHitContainer & recHitsInChamber(unsigned int) const
Definition: GEMRecHitMatcher.cc:120
GEMRecHitMatcher::stripNumbersInDetId
std::set< int > stripNumbersInDetId(unsigned int) const
Definition: GEMRecHitMatcher.cc:140
GEMRecHitContainer
std::vector< GEMRecHit > GEMRecHitContainer
Definition: GEMRecHitMatcher.h:28
verbose
static constexpr int verbose
Definition: HLTExoticaSubAnalysis.cc:25
GlobalPoint
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
Point3DBase< float, GlobalTag >
OrderedSet.t
t
Definition: OrderedSet.py:90
FastTrackerRecHitMaskProducer_cfi.recHits
recHits
Definition: FastTrackerRecHitMaskProducer_cfi.py:8
runTauDisplay.gp
gp
Definition: runTauDisplay.py:431
GEMRecHitMatcher::recHitsInSuperChamber
const GEMRecHitContainer & recHitsInSuperChamber(unsigned int) const
Definition: GEMRecHitMatcher.cc:126
GEMRecHitMatcher::detIds
std::set< unsigned int > detIds() const
Definition: GEMRecHitMatcher.cc:93
edm::ParameterSet
Definition: ParameterSet.h:36
GEMRecHitMatcher::GEMRecHitMatcher
GEMRecHitMatcher(edm::ParameterSet const &iPS, edm::ConsumesCollector &&iC)
Definition: GEMRecHitMatcher.cc:7
GEMRecHitMatcher::isGEMRecHitMatched
bool isGEMRecHitMatched(const GEMRecHit &thisRh) const
Definition: GEMRecHitMatcher.cc:198
GEMRecHitMatcher::nLayersWithRecHitsInSuperChamber
int nLayersWithRecHitsInSuperChamber(unsigned int) const
Definition: GEMRecHitMatcher.cc:132
GEMDetId::roll
constexpr int roll() const
Definition: GEMDetId.h:188
GEMDetId
Definition: GEMDetId.h:17
TrackInfoProducer_cfi.rechits
rechits
Definition: TrackInfoProducer_cfi.py:9
GEMRecHitMatcher::partitionNumbers
std::set< int > partitionNumbers() const
Definition: GEMRecHitMatcher.cc:151
iEvent
int iEvent
Definition: GenABIO.cc:224
GEMRecHitMatcher::matchRecHitsToSimTrack
void matchRecHitsToSimTrack(const GEMRecHitCollection &recHits)
Definition: GEMRecHitMatcher.cc:44
GEMRecHit::gemId
GEMDetId gemId() const
Return the gemId.
Definition: GEMRecHit.h:65
edm::EventSetup
Definition: EventSetup.h:57
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
GEMRecHitMatcher.h
get
#define get
cmsLHEtoEOSManager.l
l
Definition: cmsLHEtoEOSManager.py:193
alignCSCRings.r
r
Definition: alignCSCRings.py:93
GEMRecHitMatcher::recHitsInDetId
const GEMRecHitContainer & recHitsInDetId(unsigned int) const
Definition: GEMRecHitMatcher.cc:114
GEMRecHitMatcher::init
void init(const edm::Event &e, const edm::EventSetup &eventSetup)
Definition: GEMRecHitMatcher.cc:19
GEMRecHitMatcher::recHitMeanPosition
GlobalPoint recHitMeanPosition(const GEMRecHitContainer &rechits) const
Definition: GEMRecHitMatcher.cc:167
GEMGeometry.h
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
SimTrack
Definition: SimTrack.h:6
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:31
GEMDetId::chamberId
constexpr GEMDetId chamberId() const
Definition: GEMDetId.h:193
GEMRecHitMatcher::superChamberIds
std::set< unsigned int > superChamberIds() const
Definition: GEMRecHitMatcher.cc:107
GEMRecHit
Definition: GEMRecHit.h:14
ztail.d
d
Definition: ztail.py:151
mps_fire.result
result
Definition: mps_fire.py:303
gemRecHits_cfi.gemRecHits
gemRecHits
Definition: gemRecHits_cfi.py:7
MuonGeometryRecord.h
edm::Event
Definition: Event.h:73
GEMRecHitMatcher::match
void match(const SimTrack &t, const SimVertex &v)
do the matching
Definition: GEMRecHitMatcher.cc:33
MuonGeometryRecord
Definition: MuonGeometryRecord.h:34
edm::InputTag
Definition: InputTag.h:15
edm::ConsumesCollector
Definition: ConsumesCollector.h:39
hgcalTopologyTester_cfi.layers
layers
Definition: hgcalTopologyTester_cfi.py:8
GEMRecHit::localPosition
LocalPoint localPosition() const override
Return the 3-dimensional local position.
Definition: GEMRecHit.h:37
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27