CMS 3D CMS Logo

GEMRecHitMatcher.cc
Go to the documentation of this file.
5 
7 
8 using namespace std;
9 using namespace matching;
10 
12  const edm::Event &e,
13  const GEMGeometry &geom,
14  const edm::ParameterSet &cfg,
15  edm::EDGetToken &gem_recHitToken)
16  : simhit_matcher_(sh), gem_geo_(geom) {
17  minBXGEM_ = cfg.getUntrackedParameter<int>("minBXGEM", -1);
18  maxBXGEM_ = cfg.getUntrackedParameter<int>("maxBXGEM", 1);
19 
20  matchDeltaStrip_ = cfg.getUntrackedParameter<int>("matchDeltaStripGEM", 1);
21 
22  // setVerbose(cfg.getUntrackedParameter<int>("verboseGEMDigi", 0));
23  verbose_ = false;
24 
25  e.getByToken(gem_recHitToken, gem_rechits_);
26 
27  init(e);
28 }
29 
31 
33 
35  auto det_ids = simhit_matcher_.detIdsGEM();
36  for (auto id : det_ids) {
37  GEMDetId p_id(id);
38  GEMDetId superch_id(p_id.region(), p_id.ring(), p_id.station(), 1, p_id.chamber(), 0);
39 
40  auto hit_strips = simhit_matcher_.hitStripsInDetId(id, matchDeltaStrip_);
41  if (verbose()) {
42  cout << "hit_strips_fat ";
43  copy(hit_strips.begin(), hit_strips.end(), ostream_iterator<int>(cout, " "));
44  cout << endl;
45  }
46 
47  auto rechits_in_det = rechits.get(GEMDetId(id));
48 
49  for (auto d = rechits_in_det.first; d != rechits_in_det.second; ++d) {
50  if (verbose())
51  cout << "recHit " << p_id << " " << *d << endl;
52  // check that the rechit is within BX range
53  if (d->BunchX() < minBXGEM_ || d->BunchX() > maxBXGEM_)
54  continue;
55  // check that it matches a strip that was hit by SimHits from our track
56 
57  int firstStrip = d->firstClusterStrip();
58  int cls = d->clusterSize();
59  bool stripFound = false;
60 
61  for (int i = firstStrip; i < (firstStrip + cls); i++) {
62  if (hit_strips.find(i) != hit_strips.end())
63  stripFound = true;
64  // std::cout<<i<<" "<<firstStrip<<" "<<cls<<" "<<stripFound<<std::endl;
65  }
66 
67  if (!stripFound)
68  continue;
69  if (verbose())
70  cout << "oki" << endl;
71 
72  auto myrechit = make_digi(id, d->firstClusterStrip(), d->BunchX(), GEM_STRIP, d->clusterSize());
73  detid_to_recHits_[id].push_back(myrechit);
74  chamber_to_recHits_[p_id.chamberId().rawId()].push_back(myrechit);
75  superchamber_to_recHits_[superch_id()].push_back(myrechit);
76  }
77  }
78 }
79 
80 std::set<unsigned int> GEMRecHitMatcher::detIds() const {
81  std::set<unsigned int> result;
82  for (auto &p : detid_to_recHits_)
83  result.insert(p.first);
84  return result;
85 }
86 
87 std::set<unsigned int> GEMRecHitMatcher::chamberIds() const {
88  std::set<unsigned int> result;
89  for (auto &p : chamber_to_recHits_)
90  result.insert(p.first);
91  return result;
92 }
93 
94 std::set<unsigned int> GEMRecHitMatcher::superChamberIds() const {
95  std::set<unsigned int> result;
96  for (auto &p : superchamber_to_recHits_)
97  result.insert(p.first);
98  return result;
99 }
100 
102  if (detid_to_recHits_.find(detid) == detid_to_recHits_.end())
103  return no_recHits_;
104  return detid_to_recHits_.at(detid);
105 }
106 
108  if (chamber_to_recHits_.find(detid) == chamber_to_recHits_.end())
109  return no_recHits_;
110  return chamber_to_recHits_.at(detid);
111 }
112 
114  if (superchamber_to_recHits_.find(detid) == superchamber_to_recHits_.end())
115  return no_recHits_;
116  return superchamber_to_recHits_.at(detid);
117 }
118 
120  set<int> layers;
121  /*
122  auto recHits = recHitsInSuperChamber(detid);
123  for (auto& d: recHits)
124  {
125  GEMDetId idd(digi_id(d));
126  layers.insert(idd.layer());
127  }
128  */
129  return layers.size();
130 }
131 
132 std::set<int> GEMRecHitMatcher::stripNumbersInDetId(unsigned int detid) const {
133  set<int> result;
134  /*
135  auto recHits = recHitsInDetId(detid);
136  for (auto& d: recHits)
137  {
138  result.insert( digi_channel(d) );
139  }
140  */
141  return result;
142 }
143 
144 std::set<int> GEMRecHitMatcher::partitionNumbers() const {
145  std::set<int> result;
146 
147  auto detids = detIds();
148  for (auto id : detids) {
149  GEMDetId idd(id);
150  result.insert(idd.roll());
151  }
152  return result;
153 }
154 
156  unsigned int id = digi_id(rechit);
157  int strip = digi_channel(rechit);
158  DigiType t = digi_type(rechit);
159 
160  GlobalPoint gp;
161  if (t == GEM_STRIP) {
162  GEMDetId idd(id);
163  LocalPoint lp = gem_geo_.etaPartition(idd)->centreOfStrip(strip);
164  gp = gem_geo_.idToDet(id)->surface().toGlobal(lp);
165  }
166 
167  return gp;
168 }
169 
171  GlobalPoint point_zero;
172  if (rechit.empty())
173  return point_zero; // point "zero"
174 
175  float sumx, sumy, sumz;
176  sumx = sumy = sumz = 0.f;
177  size_t n = 0;
178  for (auto &d : rechit) {
180  if (gp == point_zero)
181  continue;
182 
183  sumx += gp.x();
184  sumy += gp.y();
185  sumz += gp.z();
186  ++n;
187  }
188  if (n == 0)
189  return GlobalPoint();
190  return GlobalPoint(sumx / n, sumy / n, sumz / n);
191 }
std::set< unsigned int > detIdsGEM() const
GEM partitions&#39; detIds with SimHits.
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:106
const RecHitContainer & recHitsInDetId(unsigned int) const
const RecHitContainer & recHitsInSuperChamber(unsigned int) const
T getUntrackedParameter(std::string const &, T const &) const
std::set< int > stripNumbersInDetId(unsigned int) const
std::set< unsigned int > chamberIds() const
std::vector< LayerSetAndLayers > layers(const SeedingLayerSetsHits &sets)
Definition: LayerTriplets.cc:4
def copy(args, dbName)
std::map< unsigned int, RecHitContainer > detid_to_recHits_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
std::set< int > hitStripsInDetId(unsigned int, int margin_n_strips=0) const
int roll() const
Definition: GEMDetId.h:80
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
T y() const
Definition: PV3DBase.h:63
int ring() const
Definition: GEMDetId.h:59
const RecHitContainer no_recHits_
int chamber() const
Chamber id: it identifies a chamber in a ring it goes from 1 to 36.
Definition: GEMDetId.h:74
std::set< unsigned int > detIds() const
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:42
const GEMEtaPartition * etaPartition(GEMDetId id) const
Return a GEMEtaPartition given its id.
Definition: GEMGeometry.cc:99
DigiType digi_type(const Digi &d)
Definition: GenericDigi.h:69
LocalPoint centreOfStrip(int strip) const
std::map< unsigned int, RecHitContainer > superchamber_to_recHits_
GEMDetId chamberId() const
Return the corresponding ChamberId.
Definition: GEMDetId.h:85
std::set< unsigned int > superChamberIds() const
const SimHitMatcher & simhit_matcher_
T z() const
Definition: PV3DBase.h:64
int station() const
Station id : the station is the pair of chambers at same disk.
Definition: GEMDetId.h:64
void matchRecHitsToSimTrack(const GEMRecHitCollection &recHits)
GlobalPoint recHitMeanPosition(const RecHitContainer &rechits) const
int region() const
Region id: 0 for Barrel Not in use, +/-1 For +/- Endcap.
Definition: GEMDetId.h:53
int nLayersWithRecHitsInSuperChamber(unsigned int) const
T const * product() const
Definition: Handle.h:74
const GeomDet * idToDet(DetId) const override
Definition: GEMGeometry.cc:38
std::map< unsigned int, RecHitContainer > chamber_to_recHits_
int digi_channel(const Digi &d)
Definition: GenericDigi.h:67
void init(const edm::Event &)
Digi make_digi()
Definition: GenericDigi.h:46
bool verbose() const
matching::Digi RecHit
edm::Handle< GEMRecHitCollection > gem_rechits_
GlobalPoint recHitPosition(const RecHit &rechit) const
T x() const
Definition: PV3DBase.h:62
const GEMGeometry & gem_geo_
matching::DigiContainer RecHitContainer
GEMRecHitMatcher(const SimHitMatcher &sh, const edm::Event &, const GEMGeometry &geom, const edm::ParameterSet &cfg, edm::EDGetToken &)
const RecHitContainer & recHitsInChamber(unsigned int) const
std::set< int > partitionNumbers() const
unsigned int digi_id(const Digi &d)
Definition: GenericDigi.h:66