34 std::unique_ptr<TrackerHitAssociator> iAssociate,
38 double iQuality_SimToReco,
39 double iPurity_SimToReco,
40 double iCut_RecoToSim,
44 bool iThreeHitTracksAreSpecial,
45 bool iAbsoluteNumberOfHits)
47 associate(
std::
move(iAssociate)),
49 simHitsTPAssoc(iSimHitsTPAssoc),
51 quality_SimToReco(iQuality_SimToReco),
52 purity_SimToReco(iPurity_SimToReco),
53 cut_RecoToSim(iCut_RecoToSim),
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->recHits().second -
seed->recHits().first;
346 LogTrace(
"TrackAssociator") <<
"\nNEW SEED - seed number " << tindex <<
" # valid=" << nsimhit;
347 getMatchedIds<edm::OwnVector<TrackingRecHit>::const_iterator>(
348 matchedIds, SimTrackIds, ri,
seed->recHits().first,
seed->recHits().second,
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
416 <<
" # valid=" <<
seed->recHits().second -
seed->recHits().first;
417 getMatchedIds<edm::OwnVector<TrackingRecHit>::const_iterator>(
418 matchedIds, SimTrackIds, ri,
seed->recHits().first,
seed->recHits().second,
associate.get());
421 std::vector<SimHitIdpr> idcachev;
422 if (!matchedIds.empty()) {
424 for (TrackingParticleCollection::const_iterator
t = tPC.begin();
t != tPC.end(); ++
t, ++tpindex) {
426 int nsimhit =
t->numberOfTrackerHits();
427 LogTrace(
"TrackAssociator") <<
"TP number " << tpindex <<
" pdgId=" <<
t->pdgId()
428 <<
" with number of PSimHits: " << nsimhit;
429 nshared =
getShared(matchedIds, idcachev, *
t);
432 quality = static_cast<double>(nshared);
434 quality = ((double)nshared) / ((double)ri);
443 LogTrace(
"TrackAssociator") <<
"TrackingParticle number " << tpindex <<
" with #hits=" << nsimhit
444 <<
" associated to seed number " << tindex <<
" with #hits=" << ri
445 <<
" with hit quality =" <<
quality;
447 LogTrace(
"TrackAssociator") <<
"TrackingParticle number " << tpindex <<
" with #hits=" << nsimhit
448 <<
" NOT associated with quality =" <<
quality;
453 LogTrace(
"TrackAssociator") <<
"% of Assoc TPs="
454 << ((double)outputCollection.
size()) / ((
double)TPCollectionH->size());
456 return outputCollection;
459 template <
typename iter>
461 std::vector<SimHitIdpr>& SimTrackIds,
468 for (iter it =
begin; it !=
end; it++) {
470 if (
hit->isValid()) {
472 uint32_t t_detID =
hit->geographicalId().rawId();
476 if (!SimTrackIds.empty()) {
477 for (
size_t j = 0;
j < SimTrackIds.size();
j++) {
478 LogTrace(
"TrackAssociator") <<
" hit # " << ri <<
" valid=" <<
hit->isValid() <<
" det id = " << t_detID
479 <<
" SimId " << SimTrackIds[
j].first <<
" evt=" << SimTrackIds[
j].second.event()
480 <<
" bc=" << SimTrackIds[
j].second.bunchCrossing();
481 matchedIds.push_back(SimTrackIds[
j]);
501 LogTrace(
"TrackAssociator") <<
"\t\t Invalid Hit On " <<
hit->geographicalId().rawId();
507 std::vector<SimHitIdpr>& idcachev,
510 if (
t.numberOfHits() == 0)
513 for (
size_t j = 0;
j < matchedIds.size();
j++) {
515 if (
find(idcachev.begin(), idcachev.end(), matchedIds[
j]) == idcachev.end()) {
517 idcachev.push_back(matchedIds[
j]);
527 if ((*g4T).trackId() == matchedIds[
j].first &&
t.eventId() == matchedIds[
j].second) {
528 int countedhits =
std::count(matchedIds.begin(), matchedIds.end(), matchedIds[
j]);
529 nshared += countedhits;
540 template <
typename iter>
546 std::vector<SimHitIdpr> SimTrackIdsDC;
548 for (iter it =
begin; it !=
end; it++) {
550 SimTrackIdsDC.clear();
553 if (SimTrackIdsDC.size() > 1) {
556 if (
find(SimTrackIdsDC.begin(),
558 SimHitIdpr((*g4T).trackId(), SimTrackIdsDC.begin()->second)) != SimTrackIdsDC.end()) {
564 doublecount += (idcount - 1);