CMS 3D CMS Logo

GEMDigiMatcher.cc
Go to the documentation of this file.
3 
6 
7 using namespace std;
8 using namespace matching;
9 
11  const edm::Event &e,
12  const GEMGeometry &geom,
13  const edm::ParameterSet &cfg,
14  edm::EDGetToken &gem_digiToken,
15  edm::EDGetToken &gem_padToken,
16  edm::EDGetToken &gem_copadToken)
17  : simhit_matcher_(sh), gem_geo_(geom) {
18  minBXGEM_ = cfg.getUntrackedParameter<int>("minBXGEM", -1);
19  maxBXGEM_ = cfg.getUntrackedParameter<int>("maxBXGEM", 1);
20 
21  matchDeltaStrip_ = cfg.getUntrackedParameter<int>("matchDeltaStripGEM", 1);
22 
23  // setVerbose(cfg.getUntrackedParameter<int>("verboseGEMDigi", 0));
24  verbose_ = false;
25 
26  e.getByToken(gem_digiToken, gem_digis_);
27  e.getByToken(gem_padToken, gem_pads_);
28  e.getByToken(gem_copadToken, gem_co_pads_);
29  if (!gem_digis_.isValid())
30  return;
31 
32  init(e);
33 }
34 
36 
39  if (gem_pads_.isValid())
41  if (gem_co_pads_.isValid())
43 }
44 
46  auto det_ids = simhit_matcher_.detIdsGEM();
47  for (auto id : det_ids) {
48  GEMDetId p_id(id);
49  GEMDetId superch_id(p_id.region(), p_id.ring(), p_id.station(), 1, p_id.chamber(), 0);
50 
51  auto hit_strips = simhit_matcher_.hitStripsInDetId(id, matchDeltaStrip_);
52  if (verbose_) {
53  cout << "hit_strips_fat ";
54  copy(hit_strips.begin(), hit_strips.end(), ostream_iterator<int>(cout, " "));
55  cout << endl;
56  }
57 
58  auto digis_in_det = digis.get(GEMDetId(id));
59 
60  for (auto d = digis_in_det.first; d != digis_in_det.second; ++d) {
61  if (verbose_)
62  cout << "gdigi " << p_id << " " << *d << endl;
63  // check that the digi is within BX range
64  if (d->bx() < minBXGEM_ || d->bx() > maxBXGEM_)
65  continue;
66  // check that it matches a strip that was hit by SimHits from our track
67  if (hit_strips.find(d->strip()) == hit_strips.end())
68  continue;
69  if (verbose_)
70  cout << "oki" << endl;
71 
72  auto mydigi = make_digi(id, d->strip(), d->bx(), GEM_STRIP);
73  detid_to_digis_[id].push_back(mydigi);
74  chamber_to_digis_[p_id.chamberId().rawId()].push_back(mydigi);
75  superchamber_to_digis_[superch_id()].push_back(mydigi);
76 
77  // int pad_num = 1 + static_cast<int>( roll->padOfStrip(d->strip()) ); //
78  // d->strip() is int digi_map[ make_pair(pad_num, d->bx()) ].push_back(
79  // d->strip() );
80  }
81  }
82 }
83 
85  auto det_ids = simhit_matcher_.detIdsGEM();
86  for (auto id : det_ids) {
87  GEMDetId p_id(id);
88  GEMDetId superch_id(p_id.region(), p_id.ring(), p_id.station(), 1, p_id.chamber(), 0);
89 
90  auto hit_pads = simhit_matcher_.hitPadsInDetId(id);
91  auto pads_in_det = pads.get(p_id);
92 
93  if (verbose_) {
94  cout << "checkpads " << hit_pads.size() << " " << std::distance(pads_in_det.first, pads_in_det.second)
95  << " hit_pads: ";
96  copy(hit_pads.begin(), hit_pads.end(), ostream_iterator<int>(cout, " "));
97  cout << endl;
98  }
99 
100  for (auto pad = pads_in_det.first; pad != pads_in_det.second; ++pad) {
101  if (verbose_)
102  cout << "chp " << *pad << endl;
103  // check that the pad BX is within the range
104  if (pad->bx() < minBXGEM_ || pad->bx() > maxBXGEM_)
105  continue;
106  if (verbose_)
107  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())
110  continue;
111  if (verbose_)
112  cout << "chp2" << endl;
113 
114  auto mydigi = make_digi(id, pad->pad(), pad->bx(), GEM_PAD);
115  detid_to_pads_[id].push_back(mydigi);
116  chamber_to_pads_[p_id.chamberId().rawId()].push_back(mydigi);
117  superchamber_to_pads_[superch_id()].push_back(mydigi);
118  }
119  }
120 }
121 
123  auto det_ids = simhit_matcher_.detIdsGEMCoincidences();
124  for (auto id : det_ids) {
125  GEMDetId p_id(id);
126  GEMDetId superch_id(p_id.region(), p_id.ring(), p_id.station(), 1, p_id.chamber(), 0);
127 
128  auto hit_co_pads = simhit_matcher_.hitCoPadsInDetId(id);
129  auto co_pads_in_det = co_pads.get(p_id);
130 
131  for (auto pad = co_pads_in_det.first; pad != co_pads_in_det.second; ++pad) {
132  // check that the pad BX is within the range
133  if (pad->bx(1) < minBXGEM_ || pad->bx(1) > maxBXGEM_)
134  continue;
135  if (pad->bx(2) < minBXGEM_ || pad->bx(2) > maxBXGEM_)
136  continue;
137  // check that it matches a coincidence pad that was hit by SimHits from
138  // our track
139  if (hit_co_pads.find(pad->pad(1)) == hit_co_pads.end())
140  continue;
141  if (hit_co_pads.find(pad->pad(2)) == hit_co_pads.end())
142  continue;
143 
144  auto mydigi = make_digi(id, pad->pad(1), pad->bx(1), GEM_COPAD);
145  // auto mydigi = make_digi(id, pad->pad(2), pad->bx(2), GEM_COPAD); //
146  // FIXIT : Solve duplicate problem.
147  detid_to_copads_[id].push_back(mydigi);
148  superchamber_to_copads_[superch_id()].push_back(mydigi);
149  }
150  }
151 }
152 
153 std::set<unsigned int> GEMDigiMatcher::detIds() const {
154  std::set<unsigned int> result;
155  for (auto &p : detid_to_digis_)
156  result.insert(p.first);
157  return result;
158 }
159 
160 std::set<unsigned int> GEMDigiMatcher::chamberIds() const {
161  std::set<unsigned int> result;
162  for (auto &p : chamber_to_digis_)
163  result.insert(p.first);
164  return result;
165 }
166 std::set<unsigned int> GEMDigiMatcher::chamberIdsWithPads() const {
167  std::set<unsigned int> result;
168  for (auto &p : chamber_to_pads_)
169  result.insert(p.first);
170  return result;
171 }
172 std::set<unsigned int> GEMDigiMatcher::superChamberIds() const {
173  std::set<unsigned int> result;
174  for (auto &p : superchamber_to_digis_)
175  result.insert(p.first);
176  return result;
177 }
178 std::set<unsigned int> GEMDigiMatcher::superChamberIdsWithPads() const {
179  std::set<unsigned int> result;
180  for (auto &p : superchamber_to_pads_)
181  result.insert(p.first);
182  return result;
183 }
184 std::set<unsigned int> GEMDigiMatcher::superChamberIdsWithCoPads() const {
185  std::set<unsigned int> result;
186  for (auto &p : superchamber_to_copads_)
187  result.insert(p.first);
188  return result;
189 }
190 std::set<unsigned int> GEMDigiMatcher::detIdsWithCoPads() const {
191  std::set<unsigned int> result;
192  for (auto &p : detid_to_copads_)
193  result.insert(p.first);
194  return result;
195 }
196 
197 const matching::DigiContainer &GEMDigiMatcher::digisInDetId(unsigned int detid) const {
198  if (detid_to_digis_.find(detid) == detid_to_digis_.end())
199  return no_digis_;
200  return detid_to_digis_.at(detid);
201 }
202 
203 const matching::DigiContainer &GEMDigiMatcher::digisInChamber(unsigned int detid) const {
204  if (chamber_to_digis_.find(detid) == chamber_to_digis_.end())
205  return no_digis_;
206  return chamber_to_digis_.at(detid);
207 }
208 
210  if (superchamber_to_digis_.find(detid) == superchamber_to_digis_.end())
211  return no_digis_;
212  return superchamber_to_digis_.at(detid);
213 }
214 
215 const matching::DigiContainer &GEMDigiMatcher::padsInDetId(unsigned int detid) const {
216  if (detid_to_pads_.find(detid) == detid_to_pads_.end())
217  return no_digis_;
218  return detid_to_pads_.at(detid);
219 }
220 
221 const matching::DigiContainer &GEMDigiMatcher::padsInChamber(unsigned int detid) const {
222  if (chamber_to_pads_.find(detid) == chamber_to_pads_.end())
223  return no_digis_;
224  return chamber_to_pads_.at(detid);
225 }
226 
228  if (superchamber_to_pads_.find(detid) == superchamber_to_pads_.end())
229  return no_digis_;
230  return superchamber_to_pads_.at(detid);
231 }
232 
233 const matching::DigiContainer &GEMDigiMatcher::coPadsInDetId(unsigned int detid) const {
234  if (detid_to_copads_.find(detid) == detid_to_copads_.end())
235  return no_digis_;
236  return detid_to_copads_.at(detid);
237 }
238 
240  if (superchamber_to_copads_.find(detid) == superchamber_to_copads_.end())
241  return no_digis_;
242  return superchamber_to_copads_.at(detid);
243 }
244 
245 int GEMDigiMatcher::nLayersWithDigisInSuperChamber(unsigned int detid) const {
246  set<int> layers;
247  auto digis = digisInSuperChamber(detid);
248  for (auto &d : digis) {
249  GEMDetId idd(digi_id(d));
250  layers.insert(idd.layer());
251  }
252  return layers.size();
253 }
254 
255 int GEMDigiMatcher::nLayersWithPadsInSuperChamber(unsigned int detid) const {
256  set<int> layers;
257  auto digis = padsInSuperChamber(detid);
258  for (auto &d : digis) {
259  GEMDetId idd(digi_id(d));
260  layers.insert(idd.layer());
261  }
262  return layers.size();
263 }
264 
266  int n = 0;
267  auto ids = superChamberIdsWithCoPads();
268  for (auto id : ids) {
269  n += coPadsInSuperChamber(id).size();
270  }
271  return n;
272 }
273 
275  int n = 0;
276  auto ids = superChamberIdsWithPads();
277  for (auto id : ids) {
278  n += padsInSuperChamber(id).size();
279  }
280  return n;
281 }
282 
283 std::set<int> GEMDigiMatcher::stripNumbersInDetId(unsigned int detid) const {
284  set<int> result;
285  auto digis = digisInDetId(detid);
286  for (auto &d : digis) {
287  result.insert(digi_channel(d));
288  }
289  return result;
290 }
291 
292 std::set<int> GEMDigiMatcher::padNumbersInDetId(unsigned int detid) const {
293  set<int> result;
294  auto digis = padsInDetId(detid);
295  for (auto &d : digis) {
296  result.insert(digi_channel(d));
297  }
298  return result;
299 }
300 
301 std::set<int> GEMDigiMatcher::coPadNumbersInDetId(unsigned int detid) const {
302  set<int> result;
303  auto digis = coPadsInDetId(detid);
304  for (auto &d : digis) {
305  result.insert(digi_channel(d));
306  }
307  return result;
308 }
309 
310 std::set<int> GEMDigiMatcher::partitionNumbers() const {
311  std::set<int> result;
312 
313  auto detids = detIds();
314  for (auto id : detids) {
315  GEMDetId idd(id);
316  result.insert(idd.roll());
317  }
318  return result;
319 }
320 
322  std::set<int> result;
323 
324  auto detids = detIdsWithCoPads();
325  for (auto id : detids) {
326  GEMDetId idd(id);
327  result.insert(idd.roll());
328  }
329  return result;
330 }
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:517
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:50
edm::Handle< GEMDigiCollection > gem_digis_
int ring() const
Definition: GEMDetId.h:59
std::vector< Digi > DigiContainer
Definition: GenericDigi.h:43
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:74
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:67
std::set< unsigned int > chamberIdsWithPads() const
Digi make_digi()
Definition: GenericDigi.h:46
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:66
int nCoPads() const
How many coincidence pads in GEM did this simtrack get in total?