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  int ndigis = 0;
72  const auto& comp_digis_in_det = comparators.get(layer_id);
73  for (auto c = comp_digis_in_det.first; c != comp_digis_in_det.second; ++c) {
74  if (verboseComparator_)
75  edm::LogInfo("CSCDigiMatcher") << "sdigi " << layer_id << " (comparator, comparator, Tbin ) " << *c;
76 
77  // check that the first BX for this digi wasn't too early or too late
78  if (c->getTimeBin() < minBXComparator_ || c->getTimeBin() > maxBXComparator_)
79  continue;
80 
81  ndigis++;
82 
83  int comparator = c->getStrip(); // comparators are counted from 1
84  // check that it matches a comparator that was hit by SimHits from our track
85  if (hit_comparators.find(comparator) == hit_comparators.end())
86  continue;
87 
88  if (verboseComparator_)
89  edm::LogInfo("CSCDigiMatcher") << "Matched comparator " << *c;
90  detid_to_comparators_[id].push_back(*c);
91  chamber_to_comparators_[layer_id.chamberId().rawId()].push_back(*c);
92  }
93  detid_to_totalcomparators_[id] = ndigis; //id to totalcomparators
94  }
95 }
96 
98  for (auto detUnitIt = strips.begin(); detUnitIt != strips.end(); ++detUnitIt) {
99  const CSCDetId& id = (*detUnitIt).first;
100  const auto& range = (*detUnitIt).second;
101  for (auto digiIt = range.first; digiIt != range.second; ++digiIt) {
102  if (id.station() == 1 and (id.ring() == 1 or id.ring() == 4))
103  if (verboseStrip_)
104  edm::LogInfo("CSCDigiMatcher") << "CSCid " << id << " Strip digi (strip, strip, Tbin ) " << (*digiIt);
105  }
106  }
107 
108  const auto& det_ids = muonSimHitMatcher_->detIds(0);
109  for (const auto& id : det_ids) {
110  CSCDetId layer_id(id);
111 
112  const auto& hit_strips = muonSimHitMatcher_->hitStripsInDetId(id, matchDeltaStrip_);
113  if (verboseStrip_) {
114  cout << "hit_strips_fat, CSCid " << layer_id << " ";
115  copy(hit_strips.begin(), hit_strips.end(), ostream_iterator<int>(cout, " "));
116  cout << endl;
117  }
118 
119  int ndigis = 0;
120 
121  const auto& strip_digis_in_det = strips.get(layer_id);
122  for (auto c = strip_digis_in_det.first; c != strip_digis_in_det.second; ++c) {
123  //next is to remove the strips with pulse at noise level, with ACD info
124  //the detail may be from CSC rechits algorithm
125  if (verboseStrip_)
126  edm::LogInfo("CSCDigiMatcher") << "sdigi " << layer_id << " (strip, ADC ) " << *c;
127 
128  ndigis++;
129 
130  int strip = c->getStrip(); // strips are counted from 1
131  // check that it matches a strip that was hit by SimHits from our track
132  if (hit_strips.find(strip) == hit_strips.end())
133  continue;
134 
135  if (verboseStrip_)
136  edm::LogInfo("CSCDigiMatcher") << "Matched strip " << *c;
137  detid_to_strips_[id].push_back(*c);
138  chamber_to_strips_[layer_id.chamberId().rawId()].push_back(*c);
139  }
140  detid_to_totalstrips_[id] = ndigis;
141  }
142 }
143 
145  const auto& det_ids = muonSimHitMatcher_->detIds(0);
146  for (const auto& id : det_ids) {
147  CSCDetId layer_id(id);
148 
149  const auto& hit_wires = muonSimHitMatcher_->hitWiregroupsInDetId(id, matchDeltaWG_);
150  if (verboseWG_) {
151  cout << "hit_wires ";
152  copy(hit_wires.begin(), hit_wires.end(), ostream_iterator<int>(cout, " "));
153  cout << endl;
154  }
155 
156  int ndigis = 0;
157 
158  const auto& wire_digis_in_det = wires.get(layer_id);
159  for (auto w = wire_digis_in_det.first; w != wire_digis_in_det.second; ++w) {
160  if (verboseStrip_)
161  edm::LogInfo("CSCDigiMatcher") << "wdigi " << layer_id << " (wire, Tbin ) " << *w;
162 
163  // check that the first BX for this digi wasn't too early or too late
164  if (w->getTimeBin() < minBXWire_ || w->getTimeBin() > maxBXWire_)
165  continue;
166 
167  ndigis++;
168 
169  int wg = w->getWireGroup(); // wiregroups are counted from 1
170  // check that it matches a strip that was hit by SimHits from our track
171  if (hit_wires.find(wg) == hit_wires.end())
172  continue;
173 
174  if (verboseStrip_)
175  edm::LogInfo("CSCDigiMatcher") << "Matched wire digi " << *w << endl;
176  detid_to_wires_[id].push_back(*w);
177  chamber_to_wires_[layer_id.chamberId().rawId()].push_back(*w);
178  }
179  detid_to_totalwires_[id] = ndigis;
180  }
181 }
182 
183 std::set<unsigned int> CSCDigiMatcher::detIdsComparator(int csc_type) const {
184  return selectDetIds(detid_to_comparators_, csc_type);
185 }
186 
187 std::set<unsigned int> CSCDigiMatcher::detIdsStrip(int csc_type) const {
188  return selectDetIds(detid_to_strips_, csc_type);
189 }
190 
191 std::set<unsigned int> CSCDigiMatcher::detIdsWire(int csc_type) const {
192  return selectDetIds(detid_to_wires_, csc_type);
193 }
194 
195 std::set<unsigned int> CSCDigiMatcher::chamberIdsComparator(int csc_type) const {
196  return selectDetIds(chamber_to_comparators_, csc_type);
197 }
198 
199 std::set<unsigned int> CSCDigiMatcher::chamberIdsStrip(int csc_type) const {
200  return selectDetIds(chamber_to_strips_, csc_type);
201 }
202 
203 std::set<unsigned int> CSCDigiMatcher::chamberIdsWire(int csc_type) const {
204  return selectDetIds(chamber_to_wires_, csc_type);
205 }
206 
208  if (detid_to_comparators_.find(detid) == detid_to_comparators_.end())
209  return no_comparators_;
210  return detid_to_comparators_.at(detid);
211 }
212 
214  if (chamber_to_comparators_.find(detid) == chamber_to_comparators_.end())
215  return no_comparators_;
216  return chamber_to_comparators_.at(detid);
217 }
218 
220  if (detid_to_strips_.find(detid) == detid_to_strips_.end())
221  return no_strips_;
222  return detid_to_strips_.at(detid);
223 }
224 
226  if (chamber_to_strips_.find(detid) == chamber_to_strips_.end())
227  return no_strips_;
228  return chamber_to_strips_.at(detid);
229 }
230 
231 const CSCWireDigiContainer& CSCDigiMatcher::wireDigisInDetId(unsigned int detid) const {
232  if (detid_to_wires_.find(detid) == detid_to_wires_.end())
233  return no_wires_;
234  return detid_to_wires_.at(detid);
235 }
236 
238  if (chamber_to_wires_.find(detid) == chamber_to_wires_.end())
239  return no_wires_;
240  return chamber_to_wires_.at(detid);
241 }
242 
243 int CSCDigiMatcher::nLayersWithComparatorInChamber(unsigned int detid) const {
244  int nLayers = 0;
245  CSCDetId chamberId(detid);
246  for (int i = 1; i <= 6; ++i) {
247  CSCDetId layerId(chamberId.endcap(), chamberId.station(), chamberId.ring(), chamberId.chamber(), i);
248  if (!comparatorDigisInDetId(layerId.rawId()).empty()) {
249  nLayers++;
250  }
251  }
252  return nLayers;
253 }
254 
255 int CSCDigiMatcher::nLayersWithStripInChamber(unsigned int detid) const {
256  int nLayers = 0;
257  CSCDetId chamberId(detid);
258  for (int i = 1; i <= 6; ++i) {
259  CSCDetId layerId(chamberId.endcap(), chamberId.station(), chamberId.ring(), chamberId.chamber(), i);
260  if (!stripDigisInDetId(layerId.rawId()).empty()) {
261  nLayers++;
262  }
263  }
264  return nLayers;
265 }
266 
267 int CSCDigiMatcher::nLayersWithWireInChamber(unsigned int detid) const {
268  int nLayers = 0;
269  CSCDetId chamberId(detid);
270  for (int i = 1; i <= 6; ++i) {
271  CSCDetId layerId(chamberId.endcap(), chamberId.station(), chamberId.ring(), chamberId.chamber(), i);
272  if (!wireDigisInDetId(layerId.rawId()).empty()) {
273  nLayers++;
274  }
275  }
276  return nLayers;
277 }
278 
280  int result = 0;
281  const auto& chamber_ids = chamberIdsComparator();
282  for (const auto& id : chamber_ids) {
283  if (nLayersWithComparatorInChamber(id) >= min_n_layers)
284  result += 1;
285  }
286  return result;
287 }
288 
289 int CSCDigiMatcher::nCoincidenceStripChambers(int min_n_layers) const {
290  int result = 0;
291  const auto& chamber_ids = chamberIdsStrip();
292  for (const auto& id : chamber_ids) {
293  if (nLayersWithStripInChamber(id) >= min_n_layers)
294  result += 1;
295  }
296  return result;
297 }
298 
299 int CSCDigiMatcher::nCoincidenceWireChambers(int min_n_layers) const {
300  int result = 0;
301  const auto& chamber_ids = chamberIdsWire();
302  for (const auto& id : chamber_ids) {
303  if (nLayersWithWireInChamber(id) >= min_n_layers)
304  result += 1;
305  }
306  return result;
307 }
308 
309 std::set<int> CSCDigiMatcher::comparatorsInDetId(unsigned int detid) const {
310  set<int> result;
311  const auto& digis = comparatorDigisInDetId(detid);
312  for (const auto& d : digis) {
313  result.insert(d.getHalfStrip());
314  }
315  return result;
316 }
317 
318 std::set<int> CSCDigiMatcher::stripsInDetId(unsigned int detid) const {
319  set<int> result;
320  const auto& digis = stripDigisInDetId(detid);
321  for (const auto& d : digis) {
322  result.insert(d.getStrip());
323  }
324  return result;
325 }
326 
327 std::set<int> CSCDigiMatcher::wiregroupsInDetId(unsigned int detid) const {
328  set<int> result;
329  const auto& digis = wireDigisInDetId(detid);
330  for (const auto& d : digis) {
331  result.insert(d.getWireGroup());
332  }
333  return result;
334 }
335 
336 std::set<int> CSCDigiMatcher::comparatorsInChamber(unsigned int detid, int max_gap_to_fill) const {
337  set<int> result;
338  const auto& digis = comparatorDigisInChamber(detid);
339  for (const auto& d : digis) {
340  result.insert(d.getStrip());
341  }
342  if (max_gap_to_fill > 0) {
343  int prev = -111;
344  for (const auto& s : result) {
345  if (s - prev > 1 && s - prev - 1 <= max_gap_to_fill) {
346  for (int fill_s = prev + 1; fill_s < s; ++fill_s)
347  result.insert(fill_s);
348  }
349  prev = s;
350  }
351  }
352 
353  return result;
354 }
355 
356 std::set<int> CSCDigiMatcher::stripsInChamber(unsigned int detid, int max_gap_to_fill) const {
357  set<int> result;
358  const auto& digis = stripDigisInChamber(detid);
359  for (const auto& d : digis) {
360  result.insert(d.getStrip());
361  }
362  if (max_gap_to_fill > 0) {
363  int prev = -111;
364  for (const auto& s : result) {
365  if (s - prev > 1 && s - prev - 1 <= max_gap_to_fill) {
366  for (int fill_s = prev + 1; fill_s < s; ++fill_s)
367  result.insert(fill_s);
368  }
369  prev = s;
370  }
371  }
372 
373  return result;
374 }
375 
376 std::set<int> CSCDigiMatcher::wiregroupsInChamber(unsigned int detid, int max_gap_to_fill) const {
377  set<int> result;
378  const auto& digis = wireDigisInChamber(detid);
379  for (const auto& d : digis) {
380  result.insert(d.getWireGroup());
381  }
382  if (max_gap_to_fill > 0) {
383  int prev = -111;
384  for (const auto& w : result) {
385  if (w - prev > 1 && w - prev - 1 <= max_gap_to_fill) {
386  for (int fill_w = prev + 1; fill_w < w; ++fill_w)
387  result.insert(fill_w);
388  }
389  prev = w;
390  }
391  }
392  return result;
393 }
394 
395 int CSCDigiMatcher::totalComparators(unsigned int detid) const {
396  if (detid_to_totalcomparators_.find(detid) == detid_to_totalcomparators_.end())
397  return 0;
398  return detid_to_totalcomparators_.at(detid);
399 }
400 
401 int CSCDigiMatcher::totalStrips(unsigned int detid) const {
402  if (detid_to_totalstrips_.find(detid) == detid_to_totalstrips_.end())
403  return 0;
404  return detid_to_totalstrips_.at(detid);
405 }
406 
407 int CSCDigiMatcher::totalWires(unsigned int detid) const {
408  if (detid_to_totalwires_.find(detid) == detid_to_totalwires_.end())
409  return 0;
410  return detid_to_totalwires_.at(detid);
411 }
412 
414  detid_to_comparators_.clear();
415  chamber_to_comparators_.clear();
416 
417  detid_to_strips_.clear();
418  chamber_to_strips_.clear();
419 
420  detid_to_wires_.clear();
421  chamber_to_wires_.clear();
422 }
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
int totalWires(unsigned int) const
int totalComparators(unsigned int) 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)
int totalStrips(unsigned int) const
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
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
void clear(EGIsoObj &c)
Definition: egamma.h:82
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