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::ParameterSet& cfg,edm::EDGetToken& gem_recHitToken)
13  :simhit_matcher_(sh),gem_geo_(geom)
14 {
15  minBXGEM_ = cfg.getUntrackedParameter<int>("minBXGEM", -1);
16  maxBXGEM_ = cfg.getUntrackedParameter<int>("maxBXGEM", 1);
17 
18  matchDeltaStrip_ = cfg.getUntrackedParameter<int>("matchDeltaStripGEM", 1);
19 
20  //setVerbose(cfg.getUntrackedParameter<int>("verboseGEMDigi", 0));
21  verbose_=false;
22 
23  e.getByToken(gem_recHitToken, gem_rechits_);
24 
25  init(e);
26 }
27 
29 
30 
31 void
33 {
35 }
36 
37 
38 void
40 {
41 
42  auto det_ids = simhit_matcher_.detIdsGEM();
43  for (auto id: det_ids)
44  {
45  GEMDetId p_id(id);
46  GEMDetId superch_id(p_id.region(), p_id.ring(), p_id.station(), 1, p_id.chamber(), 0);
47 
48  auto hit_strips = simhit_matcher_.hitStripsInDetId(id, matchDeltaStrip_);
49  if (verbose())
50  {
51  cout<<"hit_strips_fat ";
52  copy(hit_strips.begin(), hit_strips.end(), ostream_iterator<int>(cout, " "));
53  cout<<endl;
54  }
55 
56  auto rechits_in_det = rechits.get(GEMDetId(id));
57 
58  for (auto d = rechits_in_det.first; d != rechits_in_det.second; ++d)
59  {
60  if (verbose()) cout<<"recHit "<<p_id<<" "<<*d<<endl;
61  // check that the rechit is within BX range
62  if (d->BunchX() < minBXGEM_ || d->BunchX() > maxBXGEM_) continue;
63  // check that it matches a strip that was hit by SimHits from our track
64 
65  int firstStrip = d->firstClusterStrip();
66  int cls = d->clusterSize();
67  bool stripFound = false;
68 
69  for(int i = firstStrip; i < (firstStrip + cls); i++){
70 
71  if (hit_strips.find(i) != hit_strips.end()) stripFound = true;
72  //std::cout<<i<<" "<<firstStrip<<" "<<cls<<" "<<stripFound<<std::endl;
73 
74  }
75 
76  if (!stripFound) continue;
77  if (verbose()) cout<<"oki"<<endl;
78 
79  auto myrechit = make_digi(id, d->firstClusterStrip(), d->BunchX(), GEM_STRIP, d->clusterSize());
80  detid_to_recHits_[id].push_back(myrechit);
81  chamber_to_recHits_[ p_id.chamberId().rawId() ].push_back(myrechit);
82  superchamber_to_recHits_[ superch_id() ].push_back(myrechit);
83 
84  }
85  }
86 
87 }
88 
89 
90 std::set<unsigned int>
92 {
93  std::set<unsigned int> result;
94  for (auto& p: detid_to_recHits_) result.insert(p.first);
95  return result;
96 }
97 
98 
99 std::set<unsigned int>
101 {
102  std::set<unsigned int> result;
103  for (auto& p: chamber_to_recHits_) result.insert(p.first);
104  return result;
105 }
106 
107 std::set<unsigned int>
109 {
110  std::set<unsigned int> result;
111  for (auto& p: superchamber_to_recHits_) result.insert(p.first);
112  return result;
113 }
114 
115 
117 GEMRecHitMatcher::recHitsInDetId(unsigned int detid) const
118 {
119  if (detid_to_recHits_.find(detid) == detid_to_recHits_.end()) return no_recHits_;
120  return detid_to_recHits_.at(detid);
121 }
122 
124 GEMRecHitMatcher::recHitsInChamber(unsigned int detid) const
125 {
126  if (chamber_to_recHits_.find(detid) == chamber_to_recHits_.end()) return no_recHits_;
127  return chamber_to_recHits_.at(detid);
128 }
129 
132 {
133  if (superchamber_to_recHits_.find(detid) == superchamber_to_recHits_.end()) return no_recHits_;
134  return superchamber_to_recHits_.at(detid);
135 }
136 
137 int
139 {
140  set<int> layers;
141  /*
142  auto recHits = recHitsInSuperChamber(detid);
143  for (auto& d: recHits)
144  {
145  GEMDetId idd(digi_id(d));
146  layers.insert(idd.layer());
147  }
148  */
149  return layers.size();
150 }
151 
152 
153 std::set<int>
154 GEMRecHitMatcher::stripNumbersInDetId(unsigned int detid) const
155 {
156  set<int> result;
157  /*
158  auto recHits = recHitsInDetId(detid);
159  for (auto& d: recHits)
160  {
161  result.insert( digi_channel(d) );
162  }
163  */
164  return result;
165 }
166 
167 std::set<int>
169 {
170  std::set<int> result;
171 
172  auto detids = detIds();
173  for (auto id: detids)
174  {
175  GEMDetId idd(id);
176  result.insert( idd.roll() );
177  }
178  return result;
179 }
180 
183 {
184  unsigned int id = digi_id(rechit);
185  int strip = digi_channel(rechit);
186  DigiType t = digi_type(rechit);
187 
188  GlobalPoint gp;
189  if ( t == GEM_STRIP )
190  {
191  GEMDetId idd(id);
192  LocalPoint lp = gem_geo_.etaPartition(idd)->centreOfStrip(strip);
193  gp = gem_geo_.idToDet(id)->surface().toGlobal(lp);
194  }
195 
196  return gp;
197 }
198 
199 
202 {
203  GlobalPoint point_zero;
204  if (rechit.empty()) return point_zero; // point "zero"
205 
206  float sumx, sumy, sumz;
207  sumx = sumy = sumz = 0.f;
208  size_t n = 0;
209  for (auto& d: rechit)
210  {
212  if (gp == point_zero) continue;
213 
214  sumx += gp.x();
215  sumy += gp.y();
216  sumz += gp.z();
217  ++n;
218  }
219  if (n == 0) return GlobalPoint();
220  return GlobalPoint(sumx/n, sumy/n, sumz/n);
221 }
222 
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
std::map< unsigned int, RecHitContainer > detid_to_recHits_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
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
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:49
LocalPoint centreOfStrip(int strip) const
std::map< unsigned int, RecHitContainer > superchamber_to_recHits_
GEMDetId chamberId() const
Return the corresponding ChamberId.
Definition: GEMDetId.h:85
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
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:81
virtual 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:47
void init(const edm::Event &)
Digi make_digi()
Definition: GenericDigi.h:36
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:46