34 std::unique_ptr<TrackerHitAssociator> iAssociate,
38 double iQuality_SimToReco,
39 double iPurity_SimToReco,
40 double iCut_RecoToSim,
44 bool iThreeHitTracksAreSpecial,
45 bool iAbsoluteNumberOfHits)
46 : productGetter_(&productGetter),
47 associate(std::
move(iAssociate)),
49 simHitsTPAssoc(iSimHitsTPAssoc),
50 SimToRecoDenominator(iSimToRecoDenominator),
51 quality_SimToReco(iQuality_SimToReco),
52 purity_SimToReco(iPurity_SimToReco),
53 cut_RecoToSim(iCut_RecoToSim),
54 UsePixels(iUsePixels),
55 UseGrouped(iUseGrouped),
56 UseSplitting(iUseSplitting),
57 ThreeHitTracksAreSpecial(iThreeHitTracksAreSpecial),
58 AbsoluteNumberOfHits(iAbsoluteNumberOfHits) {}
98 std::vector<SimHitIdpr> SimTrackIds;
99 std::vector<SimHitIdpr> matchedIds;
103 std::vector<TrackingParticle const*> tPC;
104 tPC.reserve(tPC.size());
105 for (
auto const& ref : TPCollectionH) {
106 tPC.push_back(&(*ref));
115 getMatchedIds<trackingRecHit_iterator>(
116 matchedIds, SimTrackIds, ri, (*track)->recHitsBegin(), (*track)->recHitsEnd(),
associate.get());
126 std::vector<SimHitIdpr> idcachev;
127 if (!matchedIds.empty()) {
129 for (
auto t = tPC.begin();
t != tPC.end(); ++
t, ++tpindex) {
133 nshared =
getShared(matchedIds, idcachev, **
t);
136 if (
abs((*t)->pdgId()) == 11 && ((*t)->g4Track_end() - (*t)->g4Track_begin()) > 1) {
137 nshared -= getDoubleCount<trackingRecHit_iterator>(
138 (*track)->recHitsBegin(), (*track)->recHitsEnd(),
associate.get(), **
t);
142 quality =
static_cast<double>(nshared);
144 quality = (
static_cast<double>(nshared) / static_cast<double>(ri));
151 outputCollection.
insert(tC[tindex], std::make_pair(TPCollectionH[tpindex], quality));
166 return outputCollection;
178 std::vector<SimHitIdpr> SimTrackIds;
179 std::vector<SimHitIdpr> matchedIds;
183 std::vector<TrackingParticle const*> tPC;
184 tPC.reserve(tPC.size());
185 for (
auto const& ref : TPCollectionH) {
186 tPC.push_back(&(*ref));
205 getMatchedIds<trackingRecHit_iterator>(
206 matchedIds, SimTrackIds, ri, (*track)->recHitsBegin(), (*track)->recHitsEnd(),
associate.get());
209 std::vector<SimHitIdpr> idcachev;
210 if (!matchedIds.empty()) {
212 for (
auto t = tPC.begin();
t != tPC.end(); ++
t, ++tpindex) {
217 std::vector<PSimHit> tphits;
220 nshared =
getShared(matchedIds, idcachev, **
t);
234 std::pair<TrackingParticleRef, TrackPSimHitRef> clusterTPpairWithDummyTP(
239 clusterTPpairWithDummyTP,
241 for (
auto ip =
range.first; ip !=
range.second; ++ip) {
245 unsigned int subdetId =
static_cast<unsigned int>(dId.
subdetId());
258 for (std::vector<PSimHit>::const_iterator TPhitOK = tphits.begin(); TPhitOK != tphits.end(); TPhitOK++) {
284 tphits.push_back(*TPhit);
289 totsimhit = tphits.size();
293 quality =
static_cast<double>(nshared);
295 quality = ((double)nshared) / ((double)totsimhit);
297 quality = ((double)nshared) / ((double)ri);
303 float purity = 1.0 * nshared / ri;
307 outputCollection.
insert(TPCollectionH[tpindex], std::make_pair(tC[tindex], quality));
322 return outputCollection;
328 edm::LogVerbatim(
"TrackAssociator") <<
"Starting TrackAssociatorByHitsImpl::associateRecoToSim - #seeds="
329 << seedCollectionH->size() <<
" #TPs=" << TPCollectionH->size();
332 std::vector<SimHitIdpr> SimTrackIds;
333 std::vector<SimHitIdpr> matchedIds;
345 int nsimhit =
seed->nHits();
346 LogTrace(
"TrackAssociator") <<
"\nNEW SEED - seed number " << tindex <<
" # valid=" << nsimhit;
347 getMatchedIds<edm::OwnVector<TrackingRecHit>::const_iterator>(
348 matchedIds, SimTrackIds, ri,
seed->recHits().begin(),
seed->recHits().end(),
associate.get());
351 std::vector<SimHitIdpr> idcachev;
352 if (!matchedIds.empty()) {
354 for (TrackingParticleCollection::const_iterator
t = tPC.begin();
t != tPC.end(); ++
t, ++tpindex) {
355 LogTrace(
"TrackAssociator") <<
"TP number " << tpindex <<
" pdgId=" <<
t->pdgId()
356 <<
" with number of PSimHits: " << nsimhit;
358 nshared =
getShared(matchedIds, idcachev, *
t);
361 if (
abs(
t->pdgId()) == 11 && (
t->g4Track_end() -
t->g4Track_begin()) > 1) {
362 nshared -= getDoubleCount<edm::OwnVector<TrackingRecHit>::const_iterator>(
367 quality =
static_cast<double>(nshared);
369 quality = (
static_cast<double>(nshared) / static_cast<double>(ri));
378 LogTrace(
"TrackAssociator") <<
"Seed number " << tindex <<
" with #hits=" << ri
379 <<
"associated to TP (pdgId, nb segments, p) = " << (*t).pdgId() <<
" "
380 << (*t).g4Tracks().size() <<
" " << (*t).momentum() <<
" number " << tpindex
381 <<
" with quality =" <<
quality;
383 LogTrace(
"TrackAssociator") <<
"Seed number " << tindex <<
" with #hits=" << ri
384 <<
" NOT associated with quality =" <<
quality;
389 LogTrace(
"TrackAssociator") <<
"% of Assoc Seeds="
390 << ((double)outputCollection.
size()) / ((
double)seedCollectionH->size());
393 return outputCollection;
399 edm::LogVerbatim(
"TrackAssociator") <<
"Starting TrackAssociatorByHitsImpl::associateSimToReco - #seeds="
400 << seedCollectionH->size() <<
" #TPs=" << TPCollectionH->size();
403 std::vector<SimHitIdpr> SimTrackIds;
404 std::vector<SimHitIdpr> matchedIds;
415 LogTrace(
"TrackAssociator") <<
"\nNEW SEED - seed number " << tindex <<
" # valid=" <<
seed->nHits();
416 getMatchedIds<edm::OwnVector<TrackingRecHit>::const_iterator>(
417 matchedIds, SimTrackIds, ri,
seed->recHits().begin(),
seed->recHits().end(),
associate.get());
420 std::vector<SimHitIdpr> idcachev;
421 if (!matchedIds.empty()) {
423 for (TrackingParticleCollection::const_iterator
t = tPC.begin();
t != tPC.end(); ++
t, ++tpindex) {
425 int nsimhit =
t->numberOfTrackerHits();
426 LogTrace(
"TrackAssociator") <<
"TP number " << tpindex <<
" pdgId=" <<
t->pdgId()
427 <<
" with number of PSimHits: " << nsimhit;
428 nshared =
getShared(matchedIds, idcachev, *
t);
431 quality =
static_cast<double>(nshared);
433 quality = ((double)nshared) / ((double)ri);
442 LogTrace(
"TrackAssociator") <<
"TrackingParticle number " << tpindex <<
" with #hits=" << nsimhit
443 <<
" associated to seed number " << tindex <<
" with #hits=" << ri
444 <<
" with hit quality =" <<
quality;
446 LogTrace(
"TrackAssociator") <<
"TrackingParticle number " << tpindex <<
" with #hits=" << nsimhit
447 <<
" NOT associated with quality =" <<
quality;
452 LogTrace(
"TrackAssociator") <<
"% of Assoc TPs="
453 << ((double)outputCollection.
size()) / ((
double)TPCollectionH->size());
455 return outputCollection;
458 template <
typename iter>
460 std::vector<SimHitIdpr>& SimTrackIds,
467 for (iter it = begin; it !=
end; it++) {
475 if (!SimTrackIds.empty()) {
476 for (
size_t j = 0;
j < SimTrackIds.size();
j++) {
477 LogTrace(
"TrackAssociator") <<
" hit # " << ri <<
" valid=" << hit->
isValid() <<
" det id = " << t_detID
478 <<
" SimId " << SimTrackIds[
j].first <<
" evt=" << SimTrackIds[
j].second.event()
479 <<
" bc=" << SimTrackIds[
j].second.bunchCrossing();
480 matchedIds.push_back(SimTrackIds[
j]);
506 std::vector<SimHitIdpr>& idcachev,
512 for (
size_t j = 0;
j < matchedIds.size();
j++) {
514 if (
find(idcachev.begin(), idcachev.end(), matchedIds[
j]) == idcachev.end()) {
516 idcachev.push_back(matchedIds[
j]);
526 if ((*g4T).trackId() == matchedIds[
j].first && t.
eventId() == matchedIds[
j].second) {
527 int countedhits =
std::count(matchedIds.begin(), matchedIds.end(), matchedIds[
j]);
528 nshared += countedhits;
539 template <
typename iter>
545 std::vector<SimHitIdpr> SimTrackIdsDC;
547 for (iter it = begin; it !=
end; it++) {
549 SimTrackIdsDC.clear();
552 if (SimTrackIdsDC.size() > 1) {
555 if (
find(SimTrackIdsDC.begin(),
557 SimHitIdpr((*g4T).trackId(), SimTrackIdsDC.begin()->second)) != SimTrackIdsDC.end()) {
563 doublecount += (idcount - 1);
Log< level::Info, true > LogVerbatim
SimToRecoDenomType SimToRecoDenominator
static bool simHitTPAssociationListGreater(SimHitTPPair i, SimHitTPPair j)
const double quality_SimToReco
static constexpr auto TID
g4t_iterator g4Track_begin() const
uint32_t const *__restrict__ Quality * quality
const_iterator end() const
constexpr uint32_t rawId() const
get the raw id
edm::EDProductGetter const * productGetter_
std::unique_ptr< TrackerHitAssociator > associate
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
EDProductGetter const * productGetter(std::atomic< void const * > const &iCache)
const uint16_t range(const Frame &aFrame)
SimHitTPAssociationList const * simHitsTPAssoc
int getShared(std::vector< SimHitIdpr > &, std::vector< SimHitIdpr > &, TrackingParticle const &) const
void getMatchedIds(std::vector< SimHitIdpr > &, std::vector< SimHitIdpr > &, int &, iter, iter, TrackerHitAssociator *) const
const_iterator begin() const
int getDoubleCount(iter, iter, TrackerHitAssociator *, TrackingParticle const &) const
void post_insert()
post insert action
uint32_t partnerDetId() const
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
reco::SimToRecoCollection associateSimToReco(const edm::RefToBaseVector< reco::Track > &, const edm::RefVector< TrackingParticleCollection > &) const override
Association Sim To Reco with Collections.
Abs< T >::type abs(const T &t)
static constexpr auto TOB
std::vector< SimHitTPPair > SimHitTPAssociationList
std::vector< SimTrack >::const_iterator g4t_iterator
Detector identifier class for the strip tracker.
const TrackingRecHit * getHitPtr(edm::OwnVector< TrackingRecHit >::const_iterator iter) const
std::pair< uint32_t, EncodedEventId > SimHitIdpr
size_type size() const
map size
const bool AbsoluteNumberOfHits
T const * product() const
void insert(const key_type &k, const data_type &v)
insert an association
reco::RecoToSimCollection associateRecoToSim(const edm::RefToBaseVector< reco::Track > &, const edm::RefVector< TrackingParticleCollection > &) const override
Association Reco To Sim with Collections.
int numberOfHits() const
Gives the total number of hits, including muon hits. Hits on overlaps in the same layer count separat...
const_iterator begin() const
static constexpr auto TIB
unsigned int layer(const DetId &id) const
EncodedEventId eventId() const
Signal source, crossing number.
std::vector< SimHitIdpr > associateHitId(const TrackingRecHit &thit) const
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
TrackAssociatorByHitsImpl(edm::EDProductGetter const &productGetter, std::unique_ptr< TrackerHitAssociator > iAssociate, TrackerTopology const *iTopo, SimHitTPAssociationList const *iSimHitsTPAssoc, SimToRecoDenomType iSimToRecoDenominator, double iQuality_SimToReco, double iPurity_SimToReco, double iCut_RecoToSim, bool iUsePixels, bool iUseGrouped, bool iUseSplitting, bool ThreeHitTracksAreSpecial, bool AbsoluteNumberOfHits)
edm::Ref< edm::PSimHitContainer > TrackPSimHitRef
const double purity_SimToReco
Monte Carlo truth information used for tracking validation.
const_iterator end() const
std::vector< TrackingParticle > TrackingParticleCollection
DetId geographicalId() const
const bool ThreeHitTracksAreSpecial
g4t_iterator g4Track_end() const
TrackerTopology const * tTopo
static constexpr auto TEC
const double cut_RecoToSim