CMS 3D CMS Logo

CSCRecHitMatcher.cc
Go to the documentation of this file.
1 #include <memory>
2 
6 
7 using namespace std;
8 
10  const auto& cscRecHit2D = pset.getParameter<edm::ParameterSet>("cscRecHit");
11  maxBXCSCRecHit2D_ = cscRecHit2D.getParameter<int>("maxBX");
12  minBXCSCRecHit2D_ = cscRecHit2D.getParameter<int>("minBX");
13  verboseCSCRecHit2D_ = cscRecHit2D.getParameter<int>("verbose");
14 
15  const auto& cscSegment = pset.getParameter<edm::ParameterSet>("cscSegment");
16  maxBXCSCSegment_ = cscSegment.getParameter<int>("maxBX");
17  minBXCSCSegment_ = cscSegment.getParameter<int>("minBX");
18  verboseCSCSegment_ = cscSegment.getParameter<int>("verbose");
19 
20  // make a new digi matcher
21  cscDigiMatcher_ = std::make_unique<CSCDigiMatcher>(pset, std::move(iC));
22 
23  cscRecHit2DToken_ = iC.consumes<CSCRecHit2DCollection>(cscRecHit2D.getParameter<edm::InputTag>("inputTag"));
24  cscSegmentToken_ = iC.consumes<CSCSegmentCollection>(cscSegment.getParameter<edm::InputTag>("inputTag"));
25 }
26 
28  cscDigiMatcher_->init(iEvent, iSetup);
29 
30  iEvent.getByToken(cscRecHit2DToken_, cscRecHit2DH_);
31  iEvent.getByToken(cscSegmentToken_, cscSegmentH_);
32 
33  iSetup.get<MuonGeometryRecord>().get(csc_geom_);
34  if (csc_geom_.isValid()) {
35  cscGeometry_ = &*csc_geom_;
36  } else {
37  edm::LogWarning("CSCSimHitMatcher") << "+++ Info: CSC geometry is unavailable. +++\n";
38  }
39 }
40 
43  // match digis first
44  cscDigiMatcher_->match(t, v);
45 
46  // get the rechit collection
47  const CSCRecHit2DCollection& cscRecHit2Ds = *cscRecHit2DH_.product();
48  const CSCSegmentCollection& cscSegments = *cscSegmentH_.product();
49 
50  // now match the rechits
51  matchCSCRecHit2DsToSimTrack(cscRecHit2Ds);
52  matchCSCSegmentsToSimTrack(cscSegments);
53 }
54 
56  if (verboseCSCRecHit2D_)
57  edm::LogInfo("CSCRecHitMatcher") << "Matching simtrack to CSC rechits";
58 
59  // fetch all layerIds with digis
60  const auto& strip_ids = cscDigiMatcher_->detIdsStrip();
61  const auto& wire_ids = cscDigiMatcher_->detIdsWire();
62 
63  // merge the two collections
64  std::set<unsigned int> layer_ids;
65  layer_ids.insert(strip_ids.begin(), strip_ids.end());
66  layer_ids.insert(wire_ids.begin(), wire_ids.end());
67 
68  if (verboseCSCRecHit2D_)
69  edm::LogInfo("CSCRecHitMatcher") << "Number of matched csc layer_ids " << layer_ids.size();
70 
71  for (const auto& id : layer_ids) {
72  CSCDetId p_id(id);
73 
74  // print all the wires in the CSCChamber
75  const auto& hit_wg(cscDigiMatcher_->wiregroupsInDetId(id));
76  if (verboseCSCRecHit2D_) {
77  edm::LogInfo("CSCRecHitMatcher") << "hit wg csc from simhit" << endl;
78  for (const auto& p : hit_wg) {
79  edm::LogInfo("CSCRecHitMatcher") << p;
80  }
81  }
82 
83  // print all the strips in the CSCChamber
84  const auto& hit_strips(cscDigiMatcher_->stripsInDetId(id));
85  if (verboseCSCRecHit2D_) {
86  edm::LogInfo("CSCRecHitMatcher") << "hit strip csc from simhit" << endl;
87  for (const auto& p : hit_strips) {
88  edm::LogInfo("CSCRecHitMatcher") << p;
89  }
90  }
91 
92  // get the rechits
93  const auto& rechits_in_det = rechits.get(p_id);
94  for (auto d = rechits_in_det.first; d != rechits_in_det.second; ++d) {
95  if (verboseCSCRecHit2D_)
96  edm::LogInfo("CSCRecHitMatcher") << "rechit " << p_id << " " << *d;
97 
98  // does the wire number match?
99  const bool wireMatch(std::find(hit_wg.begin(), hit_wg.end(), d->hitWire()) != hit_wg.end());
100 
101  // does the strip number match?
102  bool stripMatch(false);
103  for (size_t iS = 0; iS < d->nStrips(); ++iS) {
104  if (std::find(hit_strips.begin(), hit_strips.end(), d->channels(iS)) != hit_strips.end())
105  stripMatch = true;
106  }
107 
108  // this rechit was matched to a matching simhit
109  if (wireMatch and stripMatch) {
110  if (verboseCSCRecHit2D_)
111  edm::LogInfo("CSCRecHitMatcher") << "\t...was matched!";
112  layer_to_cscRecHit2D_[id].push_back(*d);
113  chamber_to_cscRecHit2D_[p_id.chamberId().rawId()].push_back(*d);
114  }
115  }
116  }
117 }
118 
120  if (verboseCSCSegment_)
121  edm::LogInfo("CSCRecHitMatcher") << "Matching simtrack to segments";
122  // fetch all chamberIds with 2D rechits
123 
124  const auto& chamber_ids = chamberIdsCSCRecHit2D();
125  if (verboseCSCSegment_)
126  edm::LogInfo("CSCRecHitMatcher") << "Number of matched csc segments " << chamber_ids.size();
127  for (const auto& id : chamber_ids) {
128  CSCDetId p_id(id);
129 
130  // print all CSCRecHit2D in the CSCChamber
131  const auto& csc_rechits(cscRecHit2DsInChamber(id));
132  if (verboseCSCSegment_) {
133  edm::LogInfo("CSCRecHitMatcher") << "hit csc rechits" << endl;
134  for (const auto& p : csc_rechits) {
135  edm::LogInfo("CSCRecHitMatcher") << p;
136  }
137  }
138 
139  // get the segments
140  const auto& segments_in_det = cscSegments.get(p_id);
141  for (auto d = segments_in_det.first; d != segments_in_det.second; ++d) {
142  if (verboseCSCSegment_)
143  edm::LogInfo("CSCRecHitMatcher") << "segment " << p_id << " " << *d << endl;
144 
145  //access the rechits
146  const auto& recHits(d->recHits());
147 
148  int rechitsFound = 0;
149  if (verboseCSCSegment_)
150  edm::LogInfo("CSCRecHitMatcher") << recHits.size() << " csc rechits from segment " << endl;
151  for (const auto& rh : recHits) {
152  const CSCRecHit2D* cscrh(dynamic_cast<const CSCRecHit2D*>(rh));
153  if (isCSCRecHit2DMatched(*cscrh))
154  ++rechitsFound;
155  }
156  if (rechitsFound == 0)
157  continue;
158  if (verboseCSCSegment_) {
159  edm::LogInfo("CSCRecHitMatcher") << "Found " << rechitsFound << " rechits out of "
160  << cscRecHit2DsInChamber(id).size();
161  edm::LogInfo("CSCRecHitMatcher") << "\t...was matched!";
162  }
163  chamber_to_cscSegment_[p_id.rawId()].push_back(*d);
164  }
165  }
166 }
167 
168 std::set<unsigned int> CSCRecHitMatcher::layerIdsCSCRecHit2D() const {
169  std::set<unsigned int> result;
170  for (const auto& p : layer_to_cscRecHit2D_)
171  result.insert(p.first);
172  return result;
173 }
174 
175 std::set<unsigned int> CSCRecHitMatcher::chamberIdsCSCRecHit2D() const {
176  std::set<unsigned int> result;
177  for (const auto& p : chamber_to_cscRecHit2D_)
178  result.insert(p.first);
179  return result;
180 }
181 
182 std::set<unsigned int> CSCRecHitMatcher::chamberIdsCSCSegment() const {
183  std::set<unsigned int> result;
184  for (const auto& p : chamber_to_cscSegment_)
185  result.insert(p.first);
186  return result;
187 }
188 
190  if (layer_to_cscRecHit2D_.find(detid) == layer_to_cscRecHit2D_.end())
191  return no_cscRecHit2Ds_;
192  return layer_to_cscRecHit2D_.at(detid);
193 }
194 
196  if (chamber_to_cscRecHit2D_.find(detid) == chamber_to_cscRecHit2D_.end())
197  return no_cscRecHit2Ds_;
198  return chamber_to_cscRecHit2D_.at(detid);
199 }
200 
202  if (chamber_to_cscSegment_.find(detid) == chamber_to_cscSegment_.end())
203  return no_cscSegments_;
204  return chamber_to_cscSegment_.at(detid);
205 }
206 
207 int CSCRecHitMatcher::nCSCRecHit2DsInLayer(unsigned int detid) const { return cscRecHit2DsInLayer(detid).size(); }
208 
209 int CSCRecHitMatcher::nCSCRecHit2DsInChamber(unsigned int detid) const { return cscRecHit2DsInChamber(detid).size(); }
210 
211 int CSCRecHitMatcher::nCSCSegmentsInChamber(unsigned int detid) const { return cscSegmentsInChamber(detid).size(); }
212 
215  for (const auto& id : chamberIdsCSCRecHit2D()) {
216  const auto& segmentsInChamber(cscRecHit2DsInChamber(id));
217  result.insert(result.end(), segmentsInChamber.begin(), segmentsInChamber.end());
218  }
219  return result;
220 }
221 
224  for (const auto& id : chamberIdsCSCSegment()) {
225  const auto& segmentsInChamber(cscSegmentsInChamber(id));
226  result.insert(result.end(), segmentsInChamber.begin(), segmentsInChamber.end());
227  }
228  return result;
229 }
230 
232  bool isSame = false;
233  for (const auto& segment : c)
234  if (areCSCRecHit2DsSame(sg, segment))
235  isSame = true;
236  return isSame;
237 }
238 
240  bool isSame = false;
241  for (const auto& segment : c)
242  if (areCSCSegmentsSame(sg, segment))
243  isSame = true;
244  return isSame;
245 }
246 
248  return cscRecHit2DInContainer(thisSg, cscRecHit2Ds());
249 }
250 
252  return cscSegmentInContainer(thisSg, cscSegments());
253 }
254 
256  int n = 0;
257  const auto& ids = chamberIdsCSCRecHit2D();
258  for (const auto& id : ids)
259  n += cscRecHit2DsInChamber(id).size();
260  return n;
261 }
262 
264  int n = 0;
265  const auto& ids = chamberIdsCSCSegment();
266  for (const auto& id : ids)
267  n += cscSegmentsInChamber(id).size();
268  return n;
269 }
270 
272  return l.localPosition() == r.localPosition();
273 }
274 
276  return (l.localPosition() == r.localPosition() and l.localDirection() == r.localDirection());
277 }
278 
280  CSCSegment emptySegment;
281  double chi2overNdf = 99;
282  int index = 0;
283  int foundIndex = -99;
284 
285  for (const auto& seg : chamber_to_cscSegment_[id]) {
286  double newChi2overNdf(seg.chi2() / seg.degreesOfFreedom());
287  if (newChi2overNdf < chi2overNdf) {
288  chi2overNdf = newChi2overNdf;
289  foundIndex = index;
290  }
291  ++index;
292  }
293  if (foundIndex != -99)
294  return chamber_to_cscSegment_[id][foundIndex];
295  return emptySegment;
296 }
297 
299  return cscGeometry_->idToDet(c.cscDetId())->surface().toGlobal(c.localPosition());
300 }
CSCRecHitMatcher::cscSegments
const CSCSegmentContainer cscSegments() const
Definition: CSCRecHitMatcher.cc:222
CSCRecHitMatcher.h
CSCRecHit2DCollection
SimVertex
Definition: SimVertex.h:5
CSCRecHitMatcher::nCSCSegments
int nCSCSegments() const
Definition: CSCRecHitMatcher.cc:263
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
CSCRecHitMatcher::matchCSCSegmentsToSimTrack
void matchCSCSegmentsToSimTrack(const CSCSegmentCollection &)
Definition: CSCRecHitMatcher.cc:119
CSCRecHitMatcher::chamberIdsCSCSegment
std::set< unsigned int > chamberIdsCSCSegment() const
Definition: CSCRecHitMatcher.cc:182
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
CSCRecHitMatcher::init
void init(const edm::Event &e, const edm::EventSetup &eventSetup)
Definition: CSCRecHitMatcher.cc:27
CSCRecHitMatcher::layerIdsCSCRecHit2D
std::set< unsigned int > layerIdsCSCRecHit2D() const
Definition: CSCRecHitMatcher.cc:168
CSCRecHit2DContainer
std::vector< CSCRecHit2D > CSCRecHit2DContainer
Definition: CSCRecHitMatcher.h:28
CSCRecHitMatcher::cscRecHit2DInContainer
bool cscRecHit2DInContainer(const CSCRecHit2D &, const CSCRecHit2DContainer &) const
Definition: CSCRecHitMatcher.cc:231
dtChamberEfficiency_cfi.cscSegments
cscSegments
Definition: dtChamberEfficiency_cfi.py:15
CSCSegmentCollection
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
findQualityFiles.v
v
Definition: findQualityFiles.py:179
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
CSCRecHitMatcher::areCSCSegmentsSame
bool areCSCSegmentsSame(const CSCSegment &, const CSCSegment &) const
Definition: CSCRecHitMatcher.cc:275
CSCRecHitMatcher::match
void match(const SimTrack &t, const SimVertex &v)
do the matching
Definition: CSCRecHitMatcher.cc:42
CSCRecHitMatcher::cscSegmentInContainer
bool cscSegmentInContainer(const CSCSegment &, const CSCSegmentContainer &) const
Definition: CSCRecHitMatcher.cc:239
edm::EventSetup::get
T get() const
Definition: EventSetup.h:87
CSCRecHitMatcher::nCSCSegmentsInChamber
int nCSCSegmentsInChamber(unsigned int) const
Definition: CSCRecHitMatcher.cc:211
cscRecHitPSet.cscSegment
cscSegment
Definition: cscRecHitPSet.py:10
HI_PhotonSkim_cff.rechits
rechits
Definition: HI_PhotonSkim_cff.py:76
Point3DBase< float, GlobalTag >
CSCRecHitMatcher::cscSegmentsInChamber
const CSCSegmentContainer & cscSegmentsInChamber(unsigned int) const
Definition: CSCRecHitMatcher.cc:201
CSCRecHitMatcher::isCSCSegmentMatched
bool isCSCSegmentMatched(const CSCSegment &) const
Definition: CSCRecHitMatcher.cc:251
CSCSegment
Definition: CSCSegment.h:21
FastTrackerRecHitMaskProducer_cfi.recHits
recHits
Definition: FastTrackerRecHitMaskProducer_cfi.py:8
CSCRecHitMatcher::nCSCRecHit2DsInChamber
int nCSCRecHit2DsInChamber(unsigned int) const
Definition: CSCRecHitMatcher.cc:209
edm::ParameterSet
Definition: ParameterSet.h:47
CSCRecHit2D
Definition: CSCRecHit2D.h:18
CSCRecHitMatcher::nCSCRecHit2DsInLayer
int nCSCRecHit2DsInLayer(unsigned int) const
Definition: CSCRecHitMatcher.cc:207
CSCDetId
Definition: CSCDetId.h:26
iEvent
int iEvent
Definition: GenABIO.cc:224
CSCRecHitMatcher::chamberIdsCSCRecHit2D
std::set< unsigned int > chamberIdsCSCRecHit2D() const
Definition: CSCRecHitMatcher.cc:175
CSCRecHitMatcher::isCSCRecHit2DMatched
bool isCSCRecHit2DMatched(const CSCRecHit2D &) const
Definition: CSCRecHitMatcher.cc:247
CSCDetId::chamberId
CSCDetId chamberId() const
Definition: CSCDetId.h:47
CSCRecHitMatcher::cscRecHit2DsInLayer
const CSCRecHit2DContainer & cscRecHit2DsInLayer(unsigned int) const
Definition: CSCRecHitMatcher.cc:189
edm::EventSetup
Definition: EventSetup.h:58
get
#define get
CSCRecHitMatcher::matchCSCRecHit2DsToSimTrack
void matchCSCRecHit2DsToSimTrack(const CSCRecHit2DCollection &)
Definition: CSCRecHitMatcher.cc:55
cmsLHEtoEOSManager.l
l
Definition: cmsLHEtoEOSManager.py:204
CSCRecHitMatcher::areCSCRecHit2DsSame
bool areCSCRecHit2DsSame(const CSCRecHit2D &, const CSCRecHit2D &) const
Definition: CSCRecHitMatcher.cc:271
alignCSCRings.r
r
Definition: alignCSCRings.py:93
CSCRecHitMatcher::CSCRecHitMatcher
CSCRecHitMatcher(edm::ParameterSet const &iPS, edm::ConsumesCollector &&iC)
Definition: CSCRecHitMatcher.cc:9
CSCRecHitMatcher::globalPoint
GlobalPoint globalPoint(const CSCSegment &) const
Definition: CSCRecHitMatcher.cc:298
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
CSCRecHitMatcher::cscRecHit2Ds
const CSCRecHit2DContainer cscRecHit2Ds() const
Definition: CSCRecHitMatcher.cc:213
SimTrack
Definition: SimTrack.h:9
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
CSCRecHitMatcher::bestCSCSegment
CSCSegment bestCSCSegment(unsigned int)
Definition: CSCRecHitMatcher.cc:279
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
ztail.d
d
Definition: ztail.py:151
mps_fire.result
result
Definition: mps_fire.py:311
CSCRecHitMatcher::cscRecHit2DsInChamber
const CSCRecHit2DContainer & cscRecHit2DsInChamber(unsigned int) const
Definition: CSCRecHitMatcher.cc:195
CSCRecHitMatcher::nCSCRecHit2Ds
int nCSCRecHit2Ds() const
Definition: CSCRecHitMatcher.cc:255
MuonGeometryRecord.h
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:46
edm::Event
Definition: Event.h:73
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
MuonGeometryRecord
Definition: MuonGeometryRecord.h:34
edm::InputTag
Definition: InputTag.h:15
edm::ConsumesCollector
Definition: ConsumesCollector.h:45
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
CSCGeometry.h
CSCSegmentContainer
std::vector< CSCSegment > CSCSegmentContainer
Definition: CSCRecHitMatcher.h:29