CMS 3D CMS Logo

GEMDigiMatcher.cc
Go to the documentation of this file.
3 
6 
7 using namespace std;
8 using namespace matching;
9 
10 GEMDigiMatcher::GEMDigiMatcher(const SimHitMatcher& sh, const edm::Event& e, const GEMGeometry& geom, const edm::ParameterSet& cfg,edm::EDGetToken& gem_digiToken, edm::EDGetToken& gem_padToken, edm::EDGetToken& gem_copadToken ):simhit_matcher_(sh),gem_geo_(geom)
11 {
12  minBXGEM_ = cfg.getUntrackedParameter<int>("minBXGEM", -1);
13  maxBXGEM_ = cfg.getUntrackedParameter<int>("maxBXGEM", 1);
14 
15  matchDeltaStrip_ = cfg.getUntrackedParameter<int>("matchDeltaStripGEM", 1);
16 
17  //setVerbose(cfg.getUntrackedParameter<int>("verboseGEMDigi", 0));
18  verbose_=false;
19 
20  e.getByToken(gem_digiToken, gem_digis_);
21  e.getByToken(gem_padToken, gem_pads_);
22  e.getByToken(gem_copadToken, gem_co_pads_);
23  if ( !gem_digis_.isValid() ) return ;
24 
25  init(e);
26 }
27 
29 
30 
31 void
33 {
37 }
38 
39 
40 void
42 {
43  auto det_ids = simhit_matcher_.detIdsGEM();
44  for (auto id: det_ids)
45  {
46  GEMDetId p_id(id);
47  GEMDetId superch_id(p_id.region(), p_id.ring(), p_id.station(), 1, p_id.chamber(), 0);
48 
49  auto hit_strips = simhit_matcher_.hitStripsInDetId(id, matchDeltaStrip_);
50  if (verbose_)
51  {
52  cout<<"hit_strips_fat ";
53  copy(hit_strips.begin(), hit_strips.end(), ostream_iterator<int>(cout, " "));
54  cout<<endl;
55  }
56 
57  auto digis_in_det = digis.get(GEMDetId(id));
58 
59  for (auto d = digis_in_det.first; d != digis_in_det.second; ++d)
60  {
61  if (verbose_) cout<<"gdigi "<<p_id<<" "<<*d<<endl;
62  // check that the digi is within BX range
63  if (d->bx() < minBXGEM_ || d->bx() > maxBXGEM_) continue;
64  // check that it matches a strip that was hit by SimHits from our track
65  if (hit_strips.find(d->strip()) == hit_strips.end()) continue;
66  if (verbose_) cout<<"oki"<<endl;
67 
68  auto mydigi = make_digi(id, d->strip(), d->bx(), GEM_STRIP);
69  detid_to_digis_[id].push_back(mydigi);
70  chamber_to_digis_[ p_id.chamberId().rawId() ].push_back(mydigi);
71  superchamber_to_digis_[ superch_id() ].push_back(mydigi);
72 
73  //int pad_num = 1 + static_cast<int>( roll->padOfStrip(d->strip()) ); // d->strip() is int
74  //digi_map[ make_pair(pad_num, d->bx()) ].push_back( d->strip() );
75  }
76  }
77 }
78 
79 
80 void
82 {
83  auto det_ids = simhit_matcher_.detIdsGEM();
84  for (auto id: det_ids)
85  {
86  GEMDetId p_id(id);
87  GEMDetId superch_id(p_id.region(), p_id.ring(), p_id.station(), 1, p_id.chamber(), 0);
88 
89  auto hit_pads = simhit_matcher_.hitPadsInDetId(id);
90  auto pads_in_det = pads.get(p_id);
91 
92  if (verbose_)
93  {
94  cout<<"checkpads "<<hit_pads.size()<<" "<<std::distance(pads_in_det.first, pads_in_det.second)<<" hit_pads: ";
95  copy(hit_pads.begin(), hit_pads.end(), ostream_iterator<int>(cout," "));
96  cout<<endl;
97  }
98 
99  for (auto pad = pads_in_det.first; pad != pads_in_det.second; ++pad)
100  {
101  if (verbose_) cout<<"chp "<<*pad<<endl;
102  // check that the pad BX is within the range
103  if (pad->bx() < minBXGEM_ || pad->bx() > maxBXGEM_) continue;
104  if (verbose_) cout<<"chp1"<<endl;
105  // check that it matches a pad that was hit by SimHits from our track
106  if (hit_pads.find(pad->pad()) == hit_pads.end()) continue;
107  if (verbose_) cout<<"chp2"<<endl;
108 
109  auto mydigi = make_digi(id, pad->pad(), pad->bx(), GEM_PAD);
110  detid_to_pads_[id].push_back(mydigi);
111  chamber_to_pads_[ p_id.chamberId().rawId() ].push_back(mydigi);
112  superchamber_to_pads_[ superch_id() ].push_back(mydigi);
113  }
114  }
115 }
116 
117 
118 void
120 {
121  auto det_ids = simhit_matcher_.detIdsGEMCoincidences();
122  for (auto id: det_ids)
123  {
124  GEMDetId p_id(id);
125  GEMDetId superch_id(p_id.region(), p_id.ring(), p_id.station(), 1, p_id.chamber(), 0);
126 
127  auto hit_co_pads = simhit_matcher_.hitCoPadsInDetId(id);
128  auto co_pads_in_det = co_pads.get(p_id);
129 
130  for (auto pad = co_pads_in_det.first; pad != co_pads_in_det.second; ++pad)
131  {
132  // check that the pad BX is within the range
133  if (pad->bx(1) < minBXGEM_ || pad->bx(1) > maxBXGEM_) continue;
134  if (pad->bx(2) < minBXGEM_ || pad->bx(2) > maxBXGEM_) continue;
135  // check that it matches a coincidence pad that was hit by SimHits from our track
136  if (hit_co_pads.find(pad->pad(1)) == hit_co_pads.end()) continue;
137  if (hit_co_pads.find(pad->pad(2)) == hit_co_pads.end()) continue;
138 
139  auto mydigi = make_digi(id, pad->pad(1), pad->bx(1), GEM_COPAD);
140  //auto mydigi = make_digi(id, pad->pad(2), pad->bx(2), GEM_COPAD); // FIXIT : Solve duplicate problem.
141  detid_to_copads_[id].push_back(mydigi);
142  superchamber_to_copads_[ superch_id() ].push_back(mydigi);
143  }
144  }
145 }
146 
147 
148 std::set<unsigned int>
150 {
151  std::set<unsigned int> result;
152  for (auto& p: detid_to_digis_) result.insert(p.first);
153  return result;
154 }
155 
156 
157 std::set<unsigned int>
159 {
160  std::set<unsigned int> result;
161  for (auto& p: chamber_to_digis_) result.insert(p.first);
162  return result;
163 }
164 std::set<unsigned int>
166 {
167  std::set<unsigned int> result;
168  for (auto& p: chamber_to_pads_) result.insert(p.first);
169  return result;
170 }
171 std::set<unsigned int>
173 {
174  std::set<unsigned int> result;
175  for (auto& p: superchamber_to_digis_) result.insert(p.first);
176  return result;
177 }
178 std::set<unsigned int>
180 {
181  std::set<unsigned int> result;
182  for (auto& p: superchamber_to_pads_) result.insert(p.first);
183  return result;
184 }
185 std::set<unsigned int>
187 {
188  std::set<unsigned int> result;
189  for (auto& p: superchamber_to_copads_) result.insert(p.first);
190  return result;
191 }
192 std::set<unsigned int>
194 {
195  std::set<unsigned int> result;
196  for (auto& p: detid_to_copads_) result.insert(p.first);
197  return result;
198 }
199 
200 
201 
202 
204 GEMDigiMatcher::digisInDetId(unsigned int detid) const
205 {
206  if (detid_to_digis_.find(detid) == detid_to_digis_.end()) return no_digis_;
207  return detid_to_digis_.at(detid);
208 }
209 
211 GEMDigiMatcher::digisInChamber(unsigned int detid) const
212 {
213  if (chamber_to_digis_.find(detid) == chamber_to_digis_.end()) return no_digis_;
214  return chamber_to_digis_.at(detid);
215 }
216 
218 GEMDigiMatcher::digisInSuperChamber(unsigned int detid) const
219 {
220  if (superchamber_to_digis_.find(detid) == superchamber_to_digis_.end()) return no_digis_;
221  return superchamber_to_digis_.at(detid);
222 }
223 
225 GEMDigiMatcher::padsInDetId(unsigned int detid) const
226 {
227  if (detid_to_pads_.find(detid) == detid_to_pads_.end()) return no_digis_;
228  return detid_to_pads_.at(detid);
229 }
230 
232 GEMDigiMatcher::padsInChamber(unsigned int detid) const
233 {
234  if (chamber_to_pads_.find(detid) == chamber_to_pads_.end()) return no_digis_;
235  return chamber_to_pads_.at(detid);
236 }
237 
239 GEMDigiMatcher::padsInSuperChamber(unsigned int detid) const
240 {
241  if (superchamber_to_pads_.find(detid) == superchamber_to_pads_.end()) return no_digis_;
242  return superchamber_to_pads_.at(detid);
243 }
244 
245 
247 GEMDigiMatcher::coPadsInDetId(unsigned int detid) const
248 {
249  if (detid_to_copads_.find(detid) == detid_to_copads_.end()) return no_digis_;
250  return detid_to_copads_.at(detid);
251 }
252 
254 GEMDigiMatcher::coPadsInSuperChamber(unsigned int detid) const
255 {
256  if (superchamber_to_copads_.find(detid) == superchamber_to_copads_.end()) return no_digis_;
257  return superchamber_to_copads_.at(detid);
258 }
259 
260 
261 int
263 {
264  set<int> layers;
265  auto digis = digisInSuperChamber(detid);
266  for (auto& d: digis)
267  {
268  GEMDetId idd(digi_id(d));
269  layers.insert(idd.layer());
270  }
271  return layers.size();
272 }
273 
274 
275 int
277 {
278  set<int> layers;
279  auto digis = padsInSuperChamber(detid);
280  for (auto& d: digis)
281  {
282  GEMDetId idd(digi_id(d));
283  layers.insert(idd.layer());
284  }
285  return layers.size();
286 }
287 
288 
289 int
291 {
292  int n = 0;
294  for (auto id: ids)
295  {
296  n += coPadsInSuperChamber(id).size();
297  }
298  return n;
299 }
300 
301 
302 int
304 {
305  int n = 0;
306  auto ids = superChamberIdsWithPads();
307  for (auto id: ids)
308  {
309  n += padsInSuperChamber(id).size();
310  }
311  return n;
312 }
313 
314 
315 std::set<int>
316 GEMDigiMatcher::stripNumbersInDetId(unsigned int detid) const
317 {
318  set<int> result;
319  auto digis = digisInDetId(detid);
320  for (auto& d: digis)
321  {
322  result.insert( digi_channel(d) );
323  }
324  return result;
325 }
326 
327 std::set<int>
328 GEMDigiMatcher::padNumbersInDetId(unsigned int detid) const
329 {
330  set<int> result;
331  auto digis = padsInDetId(detid);
332  for (auto& d: digis)
333  {
334  result.insert( digi_channel(d) );
335  }
336  return result;
337 }
338 
339 std::set<int>
340 GEMDigiMatcher::coPadNumbersInDetId(unsigned int detid) const
341 {
342  set<int> result;
343  auto digis = coPadsInDetId(detid);
344  for (auto& d: digis)
345  {
346  result.insert( digi_channel(d) );
347  }
348  return result;
349 }
350 
351 std::set<int>
353 {
354  std::set<int> result;
355 
356  auto detids = detIds();
357  for (auto id: detids)
358  {
359  GEMDetId idd(id);
360  result.insert( idd.roll() );
361  }
362  return result;
363 }
364 
365 std::set<int>
367 {
368  std::set<int> result;
369 
370  auto detids = detIdsWithCoPads();
371  for (auto id: detids)
372  {
373  GEMDetId idd(id);
374  result.insert( idd.roll() );
375  }
376  return result;
377 }
std::set< unsigned int > detIdsGEM() const
GEM partitions&#39; detIds with SimHits.
const DigiContainer & digisInChamber(unsigned int) const
T getUntrackedParameter(std::string const &, T const &) const
std::set< int > padNumbersInDetId(unsigned int) const
std::map< unsigned int, DigiContainer > detid_to_pads_
std::set< unsigned int > superChamberIdsWithPads() const
std::set< unsigned int > detIds() const
std::vector< LayerSetAndLayers > layers(const SeedingLayerSetsHits &sets)
Definition: LayerTriplets.cc:4
const DigiContainer no_digis_
const SimHitMatcher & simhit_matcher_
edm::Handle< GEMPadDigiCollection > gem_pads_
def copy(args, dbName)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
std::set< int > stripNumbersInDetId(unsigned int) const
std::set< int > partitionNumbers() const
std::set< int > hitStripsInDetId(unsigned int, int margin_n_strips=0) const
const DigiContainer & padsInDetId(unsigned int) const
void matchPadsToSimTrack(const GEMPadDigiCollection &pads)
int roll() const
Definition: GEMDetId.h:80
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:47
edm::Handle< GEMDigiCollection > gem_digis_
int ring() const
Definition: GEMDetId.h:59
std::vector< Digi > DigiContainer
Definition: GenericDigi.h:33
int chamber() const
Chamber id: it identifies a chamber in a ring it goes from 1 to 36.
Definition: GEMDetId.h:74
std::map< unsigned int, DigiContainer > superchamber_to_copads_
std::map< unsigned int, DigiContainer > chamber_to_digis_
std::set< unsigned int > superChamberIds() const
void matchDigisToSimTrack(const GEMDigiCollection &digis)
GEMDetId chamberId() const
Return the corresponding ChamberId.
Definition: GEMDetId.h:85
const DigiContainer & digisInSuperChamber(unsigned int) const
std::map< unsigned int, DigiContainer > detid_to_digis_
const DigiContainer & padsInSuperChamber(unsigned int) const
const DigiContainer & digisInDetId(unsigned int) const
std::set< int > partitionNumbersWithCoPads() const
std::set< int > hitPadsInDetId(unsigned int) const
std::map< unsigned int, DigiContainer > superchamber_to_pads_
int layer() const
Layer id: each station have two layers of chambers: layer 1 is the inner chamber and layer 2 is the o...
Definition: GEMDetId.h:69
int station() const
Station id : the station is the pair of chambers at same disk.
Definition: GEMDetId.h:64
const DigiContainer & coPadsInSuperChamber(unsigned int) const
std::set< unsigned int > detIdsGEMCoincidences() const
bool isValid() const
Definition: HandleBase.h:74
int nLayersWithDigisInSuperChamber(unsigned int) const
int region() const
Region id: 0 for Barrel Not in use, +/-1 For +/- Endcap.
Definition: GEMDetId.h:53
const DigiContainer & coPadsInDetId(unsigned int) const
std::map< unsigned int, DigiContainer > superchamber_to_digis_
std::set< unsigned int > superChamberIdsWithCoPads() const
T const * product() const
Definition: Handle.h:81
std::map< unsigned int, DigiContainer > detid_to_copads_
const DigiContainer & padsInChamber(unsigned int) const
GEMDigiMatcher(const SimHitMatcher &sh, const edm::Event &, const GEMGeometry &geom, const edm::ParameterSet &cfg, edm::EDGetToken &, edm::EDGetToken &, edm::EDGetToken &)
std::set< unsigned int > detIdsWithCoPads() const
int digi_channel(const Digi &d)
Definition: GenericDigi.h:47
std::set< unsigned int > chamberIdsWithPads() const
Digi make_digi()
Definition: GenericDigi.h:36
int nLayersWithPadsInSuperChamber(unsigned int) const
std::set< unsigned int > chamberIds() const
edm::Handle< GEMCoPadDigiCollection > gem_co_pads_
std::map< unsigned int, DigiContainer > chamber_to_pads_
int nPads() const
How many pads in GEM did this simtrack get in total?
void matchCoPadsToSimTrack(const GEMCoPadDigiCollection &co_pads)
std::set< int > hitCoPadsInDetId(unsigned int) const
std::set< int > coPadNumbersInDetId(unsigned int) const
void init(const edm::Event &)
unsigned int digi_id(const Digi &d)
Definition: GenericDigi.h:46
int nCoPads() const
How many coincidence pads in GEM did this simtrack get in total?