test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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() || !gem_pads_.isValid() ) return ;
24  // CoPad can be missing when we use only digi data.
25  if ( !gem_co_pads_.isValid() ) {
26  edm::LogError("GEMDigiMatcher")<<"Copad is missing from collections.Pass copad.";
27  }
28  init(e);
29 }
30 
32 
33 
34 void
36 {
40 }
41 
42 
43 void
45 {
46  auto det_ids = simhit_matcher_.detIdsGEM();
47  for (auto id: det_ids)
48  {
49  GEMDetId p_id(id);
50  GEMDetId superch_id(p_id.region(), p_id.ring(), p_id.station(), 1, p_id.chamber(), 0);
51 
52  auto hit_strips = simhit_matcher_.hitStripsInDetId(id, matchDeltaStrip_);
53  if (verbose_)
54  {
55  cout<<"hit_strips_fat ";
56  copy(hit_strips.begin(), hit_strips.end(), ostream_iterator<int>(cout, " "));
57  cout<<endl;
58  }
59 
60  auto digis_in_det = digis.get(GEMDetId(id));
61 
62  for (auto d = digis_in_det.first; d != digis_in_det.second; ++d)
63  {
64  if (verbose_) cout<<"gdigi "<<p_id<<" "<<*d<<endl;
65  // check that the digi is within BX range
66  if (d->bx() < minBXGEM_ || d->bx() > maxBXGEM_) continue;
67  // check that it matches a strip that was hit by SimHits from our track
68  if (hit_strips.find(d->strip()) == hit_strips.end()) continue;
69  if (verbose_) cout<<"oki"<<endl;
70 
71  auto mydigi = make_digi(id, d->strip(), d->bx(), GEM_STRIP);
72  detid_to_digis_[id].push_back(mydigi);
73  chamber_to_digis_[ p_id.chamberId().rawId() ].push_back(mydigi);
74  superchamber_to_digis_[ superch_id() ].push_back(mydigi);
75 
76  //int pad_num = 1 + static_cast<int>( roll->padOfStrip(d->strip()) ); // d->strip() is int
77  //digi_map[ make_pair(pad_num, d->bx()) ].push_back( d->strip() );
78  }
79  }
80 }
81 
82 
83 void
85 {
86  auto det_ids = simhit_matcher_.detIdsGEM();
87  for (auto id: det_ids)
88  {
89  GEMDetId p_id(id);
90  GEMDetId superch_id(p_id.region(), p_id.ring(), p_id.station(), 1, p_id.chamber(), 0);
91 
92  auto hit_pads = simhit_matcher_.hitPadsInDetId(id);
93  auto pads_in_det = pads.get(p_id);
94 
95  if (verbose_)
96  {
97  cout<<"checkpads "<<hit_pads.size()<<" "<<std::distance(pads_in_det.first, pads_in_det.second)<<" hit_pads: ";
98  copy(hit_pads.begin(), hit_pads.end(), ostream_iterator<int>(cout," "));
99  cout<<endl;
100  }
101 
102  for (auto pad = pads_in_det.first; pad != pads_in_det.second; ++pad)
103  {
104  if (verbose_) cout<<"chp "<<*pad<<endl;
105  // check that the pad BX is within the range
106  if (pad->bx() < minBXGEM_ || pad->bx() > maxBXGEM_) continue;
107  if (verbose_) cout<<"chp1"<<endl;
108  // check that it matches a pad that was hit by SimHits from our track
109  if (hit_pads.find(pad->pad()) == hit_pads.end()) continue;
110  if (verbose_) cout<<"chp2"<<endl;
111 
112  auto mydigi = make_digi(id, pad->pad(), pad->bx(), GEM_PAD);
113  detid_to_pads_[id].push_back(mydigi);
114  chamber_to_pads_[ p_id.chamberId().rawId() ].push_back(mydigi);
115  superchamber_to_pads_[ superch_id() ].push_back(mydigi);
116  }
117  }
118 }
119 
120 
121 void
123 {
124  auto det_ids = simhit_matcher_.detIdsGEMCoincidences();
125  for (auto id: det_ids)
126  {
127  GEMDetId p_id(id);
128  GEMDetId superch_id(p_id.region(), p_id.ring(), p_id.station(), 1, p_id.chamber(), 0);
129 
130  auto hit_co_pads = simhit_matcher_.hitCoPadsInDetId(id);
131  auto co_pads_in_det = co_pads.get(p_id);
132 
133  for (auto pad = co_pads_in_det.first; pad != co_pads_in_det.second; ++pad)
134  {
135  // check that the pad BX is within the range
136  if (pad->bx(1) < minBXGEM_ || pad->bx(1) > maxBXGEM_) continue;
137  if (pad->bx(2) < minBXGEM_ || pad->bx(2) > maxBXGEM_) continue;
138  // check that it matches a coincidence pad that was hit by SimHits from our track
139  if (hit_co_pads.find(pad->pad(1)) == hit_co_pads.end()) continue;
140  if (hit_co_pads.find(pad->pad(2)) == hit_co_pads.end()) continue;
141 
142  auto mydigi = make_digi(id, pad->pad(1), pad->bx(1), GEM_COPAD);
143  //auto mydigi = make_digi(id, pad->pad(2), pad->bx(2), GEM_COPAD); // FIXIT : Solve duplicate problem.
144  detid_to_copads_[id].push_back(mydigi);
145  superchamber_to_copads_[ superch_id() ].push_back(mydigi);
146  }
147  }
148 }
149 
150 
151 std::set<unsigned int>
153 {
154  std::set<unsigned int> result;
155  for (auto& p: detid_to_digis_) result.insert(p.first);
156  return result;
157 }
158 
159 
160 std::set<unsigned int>
162 {
163  std::set<unsigned int> result;
164  for (auto& p: chamber_to_digis_) result.insert(p.first);
165  return result;
166 }
167 std::set<unsigned int>
169 {
170  std::set<unsigned int> result;
171  for (auto& p: chamber_to_pads_) result.insert(p.first);
172  return result;
173 }
174 std::set<unsigned int>
176 {
177  std::set<unsigned int> result;
178  for (auto& p: superchamber_to_digis_) result.insert(p.first);
179  return result;
180 }
181 std::set<unsigned int>
183 {
184  std::set<unsigned int> result;
185  for (auto& p: superchamber_to_pads_) result.insert(p.first);
186  return result;
187 }
188 std::set<unsigned int>
190 {
191  std::set<unsigned int> result;
192  for (auto& p: superchamber_to_copads_) result.insert(p.first);
193  return result;
194 }
195 std::set<unsigned int>
197 {
198  std::set<unsigned int> result;
199  for (auto& p: detid_to_copads_) result.insert(p.first);
200  return result;
201 }
202 
203 
204 
205 
207 GEMDigiMatcher::digisInDetId(unsigned int detid) const
208 {
209  if (detid_to_digis_.find(detid) == detid_to_digis_.end()) return no_digis_;
210  return detid_to_digis_.at(detid);
211 }
212 
214 GEMDigiMatcher::digisInChamber(unsigned int detid) const
215 {
216  if (chamber_to_digis_.find(detid) == chamber_to_digis_.end()) return no_digis_;
217  return chamber_to_digis_.at(detid);
218 }
219 
221 GEMDigiMatcher::digisInSuperChamber(unsigned int detid) const
222 {
223  if (superchamber_to_digis_.find(detid) == superchamber_to_digis_.end()) return no_digis_;
224  return superchamber_to_digis_.at(detid);
225 }
226 
228 GEMDigiMatcher::padsInDetId(unsigned int detid) const
229 {
230  if (detid_to_pads_.find(detid) == detid_to_pads_.end()) return no_digis_;
231  return detid_to_pads_.at(detid);
232 }
233 
235 GEMDigiMatcher::padsInChamber(unsigned int detid) const
236 {
237  if (chamber_to_pads_.find(detid) == chamber_to_pads_.end()) return no_digis_;
238  return chamber_to_pads_.at(detid);
239 }
240 
242 GEMDigiMatcher::padsInSuperChamber(unsigned int detid) const
243 {
244  if (superchamber_to_pads_.find(detid) == superchamber_to_pads_.end()) return no_digis_;
245  return superchamber_to_pads_.at(detid);
246 }
247 
248 
250 GEMDigiMatcher::coPadsInDetId(unsigned int detid) const
251 {
252  if (detid_to_copads_.find(detid) == detid_to_copads_.end()) return no_digis_;
253  return detid_to_copads_.at(detid);
254 }
255 
257 GEMDigiMatcher::coPadsInSuperChamber(unsigned int detid) const
258 {
259  if (superchamber_to_copads_.find(detid) == superchamber_to_copads_.end()) return no_digis_;
260  return superchamber_to_copads_.at(detid);
261 }
262 
263 
264 int
266 {
267  set<int> layers;
268  auto digis = digisInSuperChamber(detid);
269  for (auto& d: digis)
270  {
271  GEMDetId idd(digi_id(d));
272  layers.insert(idd.layer());
273  }
274  return layers.size();
275 }
276 
277 
278 int
280 {
281  set<int> layers;
282  auto digis = padsInSuperChamber(detid);
283  for (auto& d: digis)
284  {
285  GEMDetId idd(digi_id(d));
286  layers.insert(idd.layer());
287  }
288  return layers.size();
289 }
290 
291 
292 int
294 {
295  int n = 0;
296  auto ids = superChamberIdsWithCoPads();
297  for (auto id: ids)
298  {
299  n += coPadsInSuperChamber(id).size();
300  }
301  return n;
302 }
303 
304 
305 int
307 {
308  int n = 0;
309  auto ids = superChamberIdsWithPads();
310  for (auto id: ids)
311  {
312  n += padsInSuperChamber(id).size();
313  }
314  return n;
315 }
316 
317 
318 std::set<int>
319 GEMDigiMatcher::stripNumbersInDetId(unsigned int detid) const
320 {
321  set<int> result;
322  auto digis = digisInDetId(detid);
323  for (auto& d: digis)
324  {
325  result.insert( digi_channel(d) );
326  }
327  return result;
328 }
329 
330 std::set<int>
331 GEMDigiMatcher::padNumbersInDetId(unsigned int detid) const
332 {
333  set<int> result;
334  auto digis = padsInDetId(detid);
335  for (auto& d: digis)
336  {
337  result.insert( digi_channel(d) );
338  }
339  return result;
340 }
341 
342 std::set<int>
343 GEMDigiMatcher::coPadNumbersInDetId(unsigned int detid) const
344 {
345  set<int> result;
346  auto digis = coPadsInDetId(detid);
347  for (auto& d: digis)
348  {
349  result.insert( digi_channel(d) );
350  }
351  return result;
352 }
353 
354 std::set<int>
356 {
357  std::set<int> result;
358 
359  auto detids = detIds();
360  for (auto id: detids)
361  {
362  GEMDetId idd(id);
363  result.insert( idd.roll() );
364  }
365  return result;
366 }
367 
368 std::set<int>
370 {
371  std::set<int> result;
372 
373  auto detids = detIdsWithCoPads();
374  for (auto id: detids)
375  {
376  GEMDetId idd(id);
377  result.insert( idd.roll() );
378  }
379  return result;
380 }
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
tuple cfg
Definition: looper.py:293
std::vector< LayerSetAndLayers > layers(const SeedingLayerSetsHits &sets)
Definition: LayerTriplets.cc:4
const DigiContainer no_digis_
const SimHitMatcher & simhit_matcher_
edm::Handle< GEMPadDigiCollection > gem_pads_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
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
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)
tuple result
Definition: mps_fire.py:84
GEMDetId chamberId() const
Return the corresponding ChamberId.
Definition: GEMDetId.h:86
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
tuple d
Definition: ztail.py:151
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:75
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
tuple cout
Definition: gather_cfg.py:145
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?