11 maxBXCSCRecHit2D_ = cscRecHit2D.
getParameter<
int>(
"maxBX");
12 minBXCSCRecHit2D_ = cscRecHit2D.getParameter<
int>(
"minBX");
13 verboseCSCRecHit2D_ = cscRecHit2D.getParameter<
int>(
"verbose");
16 maxBXCSCSegment_ = cscSegment.
getParameter<
int>(
"maxBX");
17 minBXCSCSegment_ = cscSegment.getParameter<
int>(
"minBX");
18 verboseCSCSegment_ = cscSegment.getParameter<
int>(
"verbose");
21 cscDigiMatcher_ = std::make_unique<CSCDigiMatcher>(
pset,
std::move(iC));
28 cscDigiMatcher_->init(iEvent, iSetup);
30 iEvent.
getByToken(cscRecHit2DToken_, cscRecHit2DH_);
31 iEvent.
getByToken(cscSegmentToken_, cscSegmentH_);
34 if (csc_geom_.isValid()) {
35 cscGeometry_ = &*csc_geom_;
37 edm::LogWarning(
"CSCSimHitMatcher") <<
"+++ Info: CSC geometry is unavailable. +++\n";
44 cscDigiMatcher_->match(t, v);
51 matchCSCRecHit2DsToSimTrack(cscRecHit2Ds);
52 matchCSCSegmentsToSimTrack(cscSegments);
56 if (verboseCSCRecHit2D_)
57 edm::LogInfo(
"CSCRecHitMatcher") <<
"Matching simtrack to CSC rechits";
60 const auto& strip_ids = cscDigiMatcher_->detIdsStrip();
61 const auto& wire_ids = cscDigiMatcher_->detIdsWire();
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());
68 if (verboseCSCRecHit2D_)
69 edm::LogInfo(
"CSCRecHitMatcher") <<
"Number of matched csc layer_ids " << layer_ids.size();
71 for (
const auto&
id : layer_ids) {
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) {
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) {
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;
99 const bool wireMatch(
std::find(hit_wg.begin(), hit_wg.end(), d->hitWire()) != hit_wg.end());
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())
109 if (wireMatch and stripMatch) {
110 if (verboseCSCRecHit2D_)
111 edm::LogInfo(
"CSCRecHitMatcher") <<
"\t...was matched!";
112 layer_to_cscRecHit2D_[
id].push_back(*d);
120 if (verboseCSCSegment_)
121 edm::LogInfo(
"CSCRecHitMatcher") <<
"Matching simtrack to segments";
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) {
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) {
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;
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))
156 if (rechitsFound == 0)
158 if (verboseCSCSegment_) {
159 edm::LogInfo(
"CSCRecHitMatcher") <<
"Found " << rechitsFound <<
" rechits out of "
160 << cscRecHit2DsInChamber(
id).size();
161 edm::LogInfo(
"CSCRecHitMatcher") <<
"\t...was matched!";
163 chamber_to_cscSegment_[p_id.
rawId()].push_back(*
d);
169 std::set<unsigned int>
result;
170 for (
const auto&
p : layer_to_cscRecHit2D_)
171 result.insert(
p.first);
176 std::set<unsigned int>
result;
177 for (
const auto&
p : chamber_to_cscRecHit2D_)
178 result.insert(
p.first);
183 std::set<unsigned int>
result;
184 for (
const auto&
p : chamber_to_cscSegment_)
185 result.insert(
p.first);
190 if (layer_to_cscRecHit2D_.find(detid) == layer_to_cscRecHit2D_.end())
191 return no_cscRecHit2Ds_;
192 return layer_to_cscRecHit2D_.at(detid);
196 if (chamber_to_cscRecHit2D_.find(detid) == chamber_to_cscRecHit2D_.end())
197 return no_cscRecHit2Ds_;
198 return chamber_to_cscRecHit2D_.at(detid);
202 if (chamber_to_cscSegment_.find(detid) == chamber_to_cscSegment_.end())
203 return no_cscSegments_;
204 return chamber_to_cscSegment_.at(detid);
215 for (
const auto&
id : chamberIdsCSCRecHit2D()) {
216 const auto& segmentsInChamber(cscRecHit2DsInChamber(
id));
217 result.insert(result.end(), segmentsInChamber.begin(), segmentsInChamber.end());
224 for (
const auto&
id : chamberIdsCSCSegment()) {
225 const auto& segmentsInChamber(cscSegmentsInChamber(
id));
226 result.insert(result.end(), segmentsInChamber.begin(), segmentsInChamber.end());
233 for (
const auto& segment : c)
234 if (areCSCRecHit2DsSame(sg, segment))
241 for (
const auto& segment : c)
242 if (areCSCSegmentsSame(sg, segment))
248 return cscRecHit2DInContainer(thisSg, cscRecHit2Ds());
252 return cscSegmentInContainer(thisSg,
cscSegments());
257 const auto& ids = chamberIdsCSCRecHit2D();
258 for (
const auto&
id : ids)
259 n += cscRecHit2DsInChamber(
id).size();
265 const auto& ids = chamberIdsCSCSegment();
266 for (
const auto&
id : ids)
267 n += cscSegmentsInChamber(
id).size();
281 double chi2overNdf = 99;
283 int foundIndex = -99;
285 for (
const auto& seg : chamber_to_cscSegment_[
id]) {
286 double newChi2overNdf(seg.chi2() / seg.degreesOfFreedom());
287 if (newChi2overNdf < chi2overNdf) {
288 chi2overNdf = newChi2overNdf;
293 if (foundIndex != -99)
294 return chamber_to_cscSegment_[
id][foundIndex];
bool cscRecHit2DInContainer(const CSCRecHit2D &, const CSCRecHit2DContainer &) const
const edm::EventSetup & c
LocalPoint localPosition() const override
CSCDetId cscDetId() const
uint16_t *__restrict__ id
bool areCSCSegmentsSame(const CSCSegment &, const CSCSegment &) const
void matchCSCRecHit2DsToSimTrack(const CSCRecHit2DCollection &)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
const CSCSegmentContainer & cscSegmentsInChamber(unsigned int) const
CSCRecHitMatcher(edm::ParameterSet const &iPS, edm::ConsumesCollector &&iC)
const CSCRecHit2DContainer & cscRecHit2DsInChamber(unsigned int) const
bool cscSegmentInContainer(const CSCSegment &, const CSCSegmentContainer &) const
std::set< unsigned int > chamberIdsCSCSegment() const
constexpr uint32_t rawId() const
get the raw id
bool isCSCRecHit2DMatched(const CSCRecHit2D &) const
std::set< unsigned int > layerIdsCSCRecHit2D() const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
bool isCSCSegmentMatched(const CSCSegment &) const
int nCSCRecHit2DsInChamber(unsigned int) const
CSCSegment bestCSCSegment(unsigned int)
LocalVector localDirection() const override
Local direction.
std::set< unsigned int > chamberIdsCSCRecHit2D() const
int nCSCRecHit2DsInLayer(unsigned int) const
CSCDetId chamberId() const
int nCSCRecHit2Ds() const
LocalPoint localPosition() const override
Log< level::Info, false > LogInfo
void matchCSCSegmentsToSimTrack(const CSCSegmentCollection &)
int nCSCSegmentsInChamber(unsigned int) const
std::vector< CSCSegment > CSCSegmentContainer
void init(const edm::Event &e, const edm::EventSetup &eventSetup)
const CSCRecHit2DContainer & cscRecHit2DsInLayer(unsigned int) const
T getParameter(std::string const &) const
const CSCSegmentContainer cscSegments() const
bool areCSCRecHit2DsSame(const CSCRecHit2D &, const CSCRecHit2D &) const
const CSCRecHit2DContainer cscRecHit2Ds() const
void match(const SimTrack &t, const SimVertex &v)
do the matching
Log< level::Warning, false > LogWarning
GlobalPoint globalPoint(const CSCSegment &) const
std::vector< CSCRecHit2D > CSCRecHit2DContainer