CMS 3D CMS Logo

CSCDigiMatcher.cc
Go to the documentation of this file.
2 
3 using namespace std;
4 
6  const auto& wireDigi = pset.getParameterSet("cscWireDigi");
7  verboseWG_ = wireDigi.getParameter<int>("verbose");
8  minBXWire_ = wireDigi.getParameter<int>("minBX");
9  maxBXWire_ = wireDigi.getParameter<int>("maxBX");
10  matchDeltaWG_ = wireDigi.getParameter<int>("matchDeltaWG");
11 
12  const auto& comparatorDigi = pset.getParameterSet("cscComparatorDigi");
13  verboseComparator_ = comparatorDigi.getParameter<int>("verbose");
14  minBXComparator_ = comparatorDigi.getParameter<int>("minBX");
15  maxBXComparator_ = comparatorDigi.getParameter<int>("maxBX");
16  matchDeltaComparator_ = comparatorDigi.getParameter<int>("matchDeltaStrip");
17 
18  const auto& stripDigi = pset.getParameterSet("cscStripDigi");
19  verboseStrip_ = stripDigi.getParameter<int>("verbose");
20  minBXStrip_ = stripDigi.getParameter<int>("minBX");
21  maxBXStrip_ = stripDigi.getParameter<int>("maxBX");
22  matchDeltaStrip_ = stripDigi.getParameter<int>("matchDeltaStrip");
23 
24  // make a new simhits matcher
25  muonSimHitMatcher_.reset(new CSCSimHitMatcher(pset, std::move(iC)));
26 
27  comparatorDigiInput_ =
28  iC.consumes<CSCComparatorDigiCollection>(comparatorDigi.getParameter<edm::InputTag>("inputTag"));
29  stripDigiInput_ = iC.consumes<CSCStripDigiCollection>(stripDigi.getParameter<edm::InputTag>("inputTag"));
30  wireDigiInput_ = iC.consumes<CSCWireDigiCollection>(wireDigi.getParameter<edm::InputTag>("inputTag"));
31 }
32 
34  muonSimHitMatcher_->init(iEvent, iSetup);
35 
36  iEvent.getByToken(comparatorDigiInput_, comparatorDigisH_);
37  iEvent.getByToken(stripDigiInput_, stripDigisH_);
38  iEvent.getByToken(wireDigiInput_, wireDigisH_);
39 }
40 
42 void CSCDigiMatcher::match(const SimTrack& t, const SimVertex& v) {
43  // match simhits first
44  muonSimHitMatcher_->match(t, v);
45 
46  // get the digi collections
47  const CSCComparatorDigiCollection& comparators = *comparatorDigisH_.product();
48  const CSCStripDigiCollection& strips = *stripDigisH_.product();
49  const CSCWireDigiCollection& wires = *wireDigisH_.product();
50 
51  clear();
52 
53  // now match the digis
54  matchComparatorsToSimTrack(comparators);
55  matchStripsToSimTrack(strips);
56  matchWiresToSimTrack(wires);
57 }
58 
60  const auto& det_ids = muonSimHitMatcher_->detIds(0);
61  for (const auto& id : det_ids) {
62  CSCDetId layer_id(id);
63 
64  const auto& hit_comparators = muonSimHitMatcher_->hitStripsInDetId(id, matchDeltaStrip_);
65  if (verboseComparator_) {
66  cout << "hit_comparators_fat, CSCid " << layer_id << " ";
67  copy(hit_comparators.begin(), hit_comparators.end(), ostream_iterator<int>(cout, " "));
68  cout << endl;
69  }
70 
71  const auto& comp_digis_in_det = comparators.get(layer_id);
72  for (auto c = comp_digis_in_det.first; c != comp_digis_in_det.second; ++c) {
73  if (verboseComparator_)
74  edm::LogInfo("CSCDigiMatcher") << "sdigi " << layer_id << " (comparator, comparator, Tbin ) " << *c;
75 
76  // check that the first BX for this digi wasn't too early or too late
77  if (c->getTimeBin() < minBXComparator_ || c->getTimeBin() > maxBXComparator_)
78  continue;
79 
80  int comparator = c->getStrip(); // comparators are counted from 1
81  // check that it matches a comparator that was hit by SimHits from our track
82  if (hit_comparators.find(comparator) == hit_comparators.end())
83  continue;
84 
85  if (verboseComparator_)
86  edm::LogInfo("CSCDigiMatcher") << "Matched comparator " << *c;
87  detid_to_comparators_[id].push_back(*c);
88  chamber_to_comparators_[layer_id.chamberId().rawId()].push_back(*c);
89  }
90  }
91 }
92 
94  for (auto detUnitIt = strips.begin(); detUnitIt != strips.end(); ++detUnitIt) {
95  const CSCDetId& id = (*detUnitIt).first;
96  const auto& range = (*detUnitIt).second;
97  for (auto digiIt = range.first; digiIt != range.second; ++digiIt) {
98  if (id.station() == 1 and (id.ring() == 1 or id.ring() == 4))
99  if (verboseStrip_)
100  edm::LogInfo("CSCDigiMatcher") << "CSCid " << id << " Strip digi (strip, strip, Tbin ) " << (*digiIt);
101  }
102  }
103 
104  const auto& det_ids = muonSimHitMatcher_->detIds(0);
105  for (const auto& id : det_ids) {
106  CSCDetId layer_id(id);
107 
108  const auto& hit_strips = muonSimHitMatcher_->hitStripsInDetId(id, matchDeltaStrip_);
109  if (verboseStrip_) {
110  cout << "hit_strips_fat, CSCid " << layer_id << " ";
111  copy(hit_strips.begin(), hit_strips.end(), ostream_iterator<int>(cout, " "));
112  cout << endl;
113  }
114 
115  const auto& strip_digis_in_det = strips.get(layer_id);
116  for (auto c = strip_digis_in_det.first; c != strip_digis_in_det.second; ++c) {
117  if (verboseStrip_)
118  edm::LogInfo("CSCDigiMatcher") << "sdigi " << layer_id << " (strip, Tbin ) " << *c;
119 
120  int strip = c->getStrip(); // strips are counted from 1
121  // check that it matches a strip that was hit by SimHits from our track
122  if (hit_strips.find(strip) == hit_strips.end())
123  continue;
124 
125  if (verboseStrip_)
126  edm::LogInfo("CSCDigiMatcher") << "Matched strip " << *c;
127  detid_to_strips_[id].push_back(*c);
128  chamber_to_strips_[layer_id.chamberId().rawId()].push_back(*c);
129  }
130  }
131 }
132 
134  const auto& det_ids = muonSimHitMatcher_->detIds(0);
135  for (const auto& id : det_ids) {
136  CSCDetId layer_id(id);
137 
138  const auto& hit_wires = muonSimHitMatcher_->hitWiregroupsInDetId(id, matchDeltaWG_);
139  if (verboseWG_) {
140  cout << "hit_wires ";
141  copy(hit_wires.begin(), hit_wires.end(), ostream_iterator<int>(cout, " "));
142  cout << endl;
143  }
144 
145  const auto& wire_digis_in_det = wires.get(layer_id);
146  for (auto w = wire_digis_in_det.first; w != wire_digis_in_det.second; ++w) {
147  if (verboseStrip_)
148  edm::LogInfo("CSCDigiMatcher") << "wdigi " << layer_id << " (wire, Tbin ) " << *w;
149 
150  // check that the first BX for this digi wasn't too early or too late
151  if (w->getTimeBin() < minBXWire_ || w->getTimeBin() > maxBXWire_)
152  continue;
153 
154  int wg = w->getWireGroup(); // wiregroups are counted from 1
155  // check that it matches a strip that was hit by SimHits from our track
156  if (hit_wires.find(wg) == hit_wires.end())
157  continue;
158 
159  if (verboseStrip_)
160  edm::LogInfo("CSCDigiMatcher") << "Matched wire digi " << *w << endl;
161  detid_to_wires_[id].push_back(*w);
162  chamber_to_wires_[layer_id.chamberId().rawId()].push_back(*w);
163  }
164  }
165 }
166 
167 std::set<unsigned int> CSCDigiMatcher::detIdsComparator(int csc_type) const {
168  return selectDetIds(detid_to_comparators_, csc_type);
169 }
170 
171 std::set<unsigned int> CSCDigiMatcher::detIdsStrip(int csc_type) const {
172  return selectDetIds(detid_to_strips_, csc_type);
173 }
174 
175 std::set<unsigned int> CSCDigiMatcher::detIdsWire(int csc_type) const {
176  return selectDetIds(detid_to_wires_, csc_type);
177 }
178 
179 std::set<unsigned int> CSCDigiMatcher::chamberIdsComparator(int csc_type) const {
180  return selectDetIds(chamber_to_comparators_, csc_type);
181 }
182 
183 std::set<unsigned int> CSCDigiMatcher::chamberIdsStrip(int csc_type) const {
184  return selectDetIds(chamber_to_strips_, csc_type);
185 }
186 
187 std::set<unsigned int> CSCDigiMatcher::chamberIdsWire(int csc_type) const {
188  return selectDetIds(chamber_to_wires_, csc_type);
189 }
190 
192  if (detid_to_comparators_.find(detid) == detid_to_comparators_.end())
193  return no_comparators_;
194  return detid_to_comparators_.at(detid);
195 }
196 
198  if (chamber_to_comparators_.find(detid) == chamber_to_comparators_.end())
199  return no_comparators_;
200  return chamber_to_comparators_.at(detid);
201 }
202 
204  if (detid_to_strips_.find(detid) == detid_to_strips_.end())
205  return no_strips_;
206  return detid_to_strips_.at(detid);
207 }
208 
210  if (chamber_to_strips_.find(detid) == chamber_to_strips_.end())
211  return no_strips_;
212  return chamber_to_strips_.at(detid);
213 }
214 
215 const CSCWireDigiContainer& CSCDigiMatcher::wireDigisInDetId(unsigned int detid) const {
216  if (detid_to_wires_.find(detid) == detid_to_wires_.end())
217  return no_wires_;
218  return detid_to_wires_.at(detid);
219 }
220 
222  if (chamber_to_wires_.find(detid) == chamber_to_wires_.end())
223  return no_wires_;
224  return chamber_to_wires_.at(detid);
225 }
226 
227 int CSCDigiMatcher::nLayersWithComparatorInChamber(unsigned int detid) const {
228  int nLayers = 0;
229  CSCDetId chamberId(detid);
230  for (int i = 1; i <= 6; ++i) {
231  CSCDetId layerId(chamberId.endcap(), chamberId.station(), chamberId.ring(), chamberId.chamber(), i);
232  if (!comparatorDigisInDetId(layerId.rawId()).empty()) {
233  nLayers++;
234  }
235  }
236  return nLayers;
237 }
238 
239 int CSCDigiMatcher::nLayersWithStripInChamber(unsigned int detid) const {
240  int nLayers = 0;
241  CSCDetId chamberId(detid);
242  for (int i = 1; i <= 6; ++i) {
243  CSCDetId layerId(chamberId.endcap(), chamberId.station(), chamberId.ring(), chamberId.chamber(), i);
244  if (!stripDigisInDetId(layerId.rawId()).empty()) {
245  nLayers++;
246  }
247  }
248  return nLayers;
249 }
250 
251 int CSCDigiMatcher::nLayersWithWireInChamber(unsigned int detid) const {
252  int nLayers = 0;
253  CSCDetId chamberId(detid);
254  for (int i = 1; i <= 6; ++i) {
255  CSCDetId layerId(chamberId.endcap(), chamberId.station(), chamberId.ring(), chamberId.chamber(), i);
256  if (!wireDigisInDetId(layerId.rawId()).empty()) {
257  nLayers++;
258  }
259  }
260  return nLayers;
261 }
262 
264  int result = 0;
265  const auto& chamber_ids = chamberIdsComparator();
266  for (const auto& id : chamber_ids) {
267  if (nLayersWithComparatorInChamber(id) >= min_n_layers)
268  result += 1;
269  }
270  return result;
271 }
272 
273 int CSCDigiMatcher::nCoincidenceStripChambers(int min_n_layers) const {
274  int result = 0;
275  const auto& chamber_ids = chamberIdsStrip();
276  for (const auto& id : chamber_ids) {
277  if (nLayersWithStripInChamber(id) >= min_n_layers)
278  result += 1;
279  }
280  return result;
281 }
282 
283 int CSCDigiMatcher::nCoincidenceWireChambers(int min_n_layers) const {
284  int result = 0;
285  const auto& chamber_ids = chamberIdsWire();
286  for (const auto& id : chamber_ids) {
287  if (nLayersWithWireInChamber(id) >= min_n_layers)
288  result += 1;
289  }
290  return result;
291 }
292 
293 std::set<int> CSCDigiMatcher::comparatorsInDetId(unsigned int detid) const {
294  set<int> result;
295  const auto& digis = comparatorDigisInDetId(detid);
296  for (const auto& d : digis) {
297  result.insert(d.getHalfStrip());
298  }
299  return result;
300 }
301 
302 std::set<int> CSCDigiMatcher::stripsInDetId(unsigned int detid) const {
303  set<int> result;
304  const auto& digis = stripDigisInDetId(detid);
305  for (const auto& d : digis) {
306  result.insert(d.getStrip());
307  }
308  return result;
309 }
310 
311 std::set<int> CSCDigiMatcher::wiregroupsInDetId(unsigned int detid) const {
312  set<int> result;
313  const auto& digis = wireDigisInDetId(detid);
314  for (const auto& d : digis) {
315  result.insert(d.getWireGroup());
316  }
317  return result;
318 }
319 
320 std::set<int> CSCDigiMatcher::comparatorsInChamber(unsigned int detid, int max_gap_to_fill) const {
321  set<int> result;
322  const auto& digis = comparatorDigisInChamber(detid);
323  for (const auto& d : digis) {
324  result.insert(d.getStrip());
325  }
326  if (max_gap_to_fill > 0) {
327  int prev = -111;
328  for (const auto& s : result) {
329  if (s - prev > 1 && s - prev - 1 <= max_gap_to_fill) {
330  for (int fill_s = prev + 1; fill_s < s; ++fill_s)
331  result.insert(fill_s);
332  }
333  prev = s;
334  }
335  }
336 
337  return result;
338 }
339 
340 std::set<int> CSCDigiMatcher::stripsInChamber(unsigned int detid, int max_gap_to_fill) const {
341  set<int> result;
342  const auto& digis = stripDigisInChamber(detid);
343  for (const auto& d : digis) {
344  result.insert(d.getStrip());
345  }
346  if (max_gap_to_fill > 0) {
347  int prev = -111;
348  for (const auto& s : result) {
349  if (s - prev > 1 && s - prev - 1 <= max_gap_to_fill) {
350  for (int fill_s = prev + 1; fill_s < s; ++fill_s)
351  result.insert(fill_s);
352  }
353  prev = s;
354  }
355  }
356 
357  return result;
358 }
359 
360 std::set<int> CSCDigiMatcher::wiregroupsInChamber(unsigned int detid, int max_gap_to_fill) const {
361  set<int> result;
362  const auto& digis = wireDigisInChamber(detid);
363  for (const auto& d : digis) {
364  result.insert(d.getWireGroup());
365  }
366  if (max_gap_to_fill > 0) {
367  int prev = -111;
368  for (const auto& w : result) {
369  if (w - prev > 1 && w - prev - 1 <= max_gap_to_fill) {
370  for (int fill_w = prev + 1; fill_w < w; ++fill_w)
371  result.insert(fill_w);
372  }
373  prev = w;
374  }
375  }
376  return result;
377 }
378 
380  detid_to_comparators_.clear();
381  chamber_to_comparators_.clear();
382 
383  detid_to_strips_.clear();
384  chamber_to_strips_.clear();
385 
386  detid_to_wires_.clear();
387  chamber_to_wires_.clear();
388 }
std::set< int > comparatorsInDetId(unsigned int) const
int nCoincidenceWireChambers(int min_n_layers=4) const
void match(const SimTrack &t, const SimVertex &v)
do the matching
std::set< unsigned int > detIdsStrip(int csc_type=MuonHitHelper::CSC_ALL) const
T w() const
std::set< int > stripsInDetId(unsigned int) const
std::vector< CSCStripDigi > CSCStripDigiContainer
void matchStripsToSimTrack(const CSCStripDigiCollection &strips)
std::set< int > wiregroupsInDetId(unsigned int) const
void matchWiresToSimTrack(const CSCWireDigiCollection &wires)
std::set< int > stripsInChamber(unsigned int, int max_gap_to_fill=0) const
int iEvent
Definition: GenABIO.cc:224
int nLayersWithStripInChamber(unsigned int) const
int nCoincidenceStripChambers(int min_n_layers=4) const
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
CSCDigiMatcher(edm::ParameterSet const &iPS, edm::ConsumesCollector &&iC)
const CSCComparatorDigiContainer & comparatorDigisInDetId(unsigned int) const
int chamber() const
Definition: CSCDetId.h:62
void init(const edm::Event &e, const edm::EventSetup &eventSetup)
const CSCStripDigiContainer & stripDigisInChamber(unsigned int) const
d
Definition: ztail.py:151
Log< level::Info, false > LogInfo
const CSCWireDigiContainer & wireDigisInChamber(unsigned int) const
std::vector< CSCComparatorDigi > CSCComparatorDigiContainer
int station() const
Definition: CSCDetId.h:79
std::vector< CSCWireDigi > CSCWireDigiContainer
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
CSCDetId chamberId() const
Definition: CSCDetId.h:47
int endcap() const
Definition: CSCDetId.h:85
void matchComparatorsToSimTrack(const CSCComparatorDigiCollection &comparators)
std::set< unsigned int > chamberIdsComparator(int csc_type=MuonHitHelper::CSC_ALL) const
std::set< unsigned int > chamberIdsStrip(int csc_type=MuonHitHelper::CSC_ALL) const
void clear(HadCaloObj &c)
Definition: data.h:124
const CSCWireDigiContainer & wireDigisInDetId(unsigned int) const
std::set< unsigned int > detIdsComparator(int csc_type=MuonHitHelper::CSC_ALL) const
std::set< unsigned int > chamberIdsWire(int csc_type=MuonHitHelper::CSC_ALL) const
std::set< unsigned int > detIdsWire(int csc_type=MuonHitHelper::CSC_ALL) const
const CSCStripDigiContainer & stripDigisInDetId(unsigned int) const
strips
#turn off noise in all subdetectors simHcalUnsuppressedDigis.doNoise = False mix.digitizers.hcal.doNoise = False simEcalUnsuppressedDigis.doNoise = False mix.digitizers.ecal.doNoise = False simEcalUnsuppressedDigis.doESNoise = False simSiPixelDigis.AddNoise = False mix.digitizers.pixel.AddNoise = False simSiStripDigis.Noise = False mix.digitizers.strip.AddNoise = False
Definition: DigiDM_cff.py:32
int nLayersWithWireInChamber(unsigned int) const
int ring() const
Definition: CSCDetId.h:68
const CSCComparatorDigiContainer & comparatorDigisInChamber(unsigned int) const
std::set< int > comparatorsInChamber(unsigned int, int max_gap_to_fill=0) const
std::set< int > wiregroupsInChamber(unsigned int, int max_gap_to_fill=0) const
int nLayersWithComparatorInChamber(unsigned int) const
def move(src, dest)
Definition: eostools.py:511
int nCoincidenceComparatorChambers(int min_n_layers=4) const