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),
51 quality_SimToReco(iQuality_SimToReco),
52 purity_SimToReco(iPurity_SimToReco),
53 cut_RecoToSim(iCut_RecoToSim),
99 std::vector< SimHitIdpr> SimTrackIds;
100 std::vector< SimHitIdpr> matchedIds;
104 std::vector<TrackingParticle const*> tPC;
105 tPC.reserve(tPC.size());
106 for(
auto const& ref: TPCollectionH) {
107 tPC.push_back(&(*ref));
116 getMatchedIds<trackingRecHit_iterator>(matchedIds, SimTrackIds, ri, (*track)->recHitsBegin(), (*track)->recHitsEnd(),
associate.get());
126 std::vector<SimHitIdpr> idcachev;
127 if(!matchedIds.empty()){
130 for (
auto t = tPC.begin();
t != tPC.end(); ++
t, ++tpindex) {
134 nshared =
getShared(matchedIds, idcachev, **
t);
137 if (
abs((*t)->pdgId())==11&&((*t)->g4Track_end()-(*t)->g4Track_begin())>1){
138 nshared-=getDoubleCount<trackingRecHit_iterator>((*track)->recHitsBegin(), (*track)->recHitsEnd(),
associate.get(), **
t);
142 else if(ri!=0) quality = (
static_cast<double>(nshared)/static_cast<double>(ri));
148 outputCollection.
insert(tC[tindex],
149 std::make_pair(TPCollectionH[tpindex],
165 return outputCollection;
179 std::vector< SimHitIdpr> SimTrackIds;
180 std::vector< SimHitIdpr> matchedIds;
184 std::vector<TrackingParticle const*> tPC;
185 tPC.reserve(tPC.size());
186 for(
auto const& ref: TPCollectionH) {
187 tPC.push_back(&(*ref));
206 getMatchedIds<trackingRecHit_iterator>(matchedIds, SimTrackIds, ri, (*track)->recHitsBegin(), (*track)->recHitsEnd(),
associate.get());
209 std::vector<SimHitIdpr> idcachev;
210 if(!matchedIds.empty()){
213 for (
auto t = tPC.begin();
t != tPC.end(); ++
t, ++tpindex) {
218 std::vector<PSimHit> tphits;
221 nshared =
getShared(matchedIds, idcachev, **
t);
235 std::pair<TrackingParticleRef, TrackPSimHitRef>
240 for(
auto ip = range.first; ip != range.second; ++ip) {
244 unsigned int subdetId =
static_cast<unsigned int>(dId.
subdetId());
257 for(std::vector<PSimHit>::const_iterator TPhitOK = tphits.begin(); TPhitOK != tphits.end(); TPhitOK++){
285 tphits.push_back(*TPhit);
290 totsimhit = tphits.size();
300 float purity = 1.0*nshared/ri;
303 outputCollection.
insert(TPCollectionH[tpindex],
304 std::make_pair(tC[tindex],quality));
319 return outputCollection;
326 edm::LogVerbatim(
"TrackAssociator") <<
"Starting TrackAssociatorByHitsImpl::associateRecoToSim - #seeds=" 327 <<seedCollectionH->size()<<
" #TPs="<<TPCollectionH->size();
330 std::vector< SimHitIdpr> SimTrackIds;
331 std::vector< SimHitIdpr> matchedIds;
343 int nsimhit =
seed->recHits().second-
seed->recHits().first;
344 LogTrace(
"TrackAssociator") <<
"\nNEW SEED - seed number " << tindex <<
" # valid=" << nsimhit;
345 getMatchedIds<edm::OwnVector<TrackingRecHit>::const_iterator>(matchedIds, SimTrackIds, ri,
seed->recHits().first,
seed->recHits().second,
associate.get() );
348 std::vector<SimHitIdpr> idcachev;
349 if(!matchedIds.empty()){
352 for (TrackingParticleCollection::const_iterator
t = tPC.begin();
t != tPC.end(); ++
t, ++tpindex) {
353 LogTrace(
"TrackAssociator") <<
"TP number " << tpindex <<
" pdgId=" <<
t->pdgId() <<
" with number of PSimHits: " << nsimhit;
355 nshared =
getShared(matchedIds, idcachev, *
t);
358 if (
abs(
t->pdgId())==11&&(
t->g4Track_end()-
t->g4Track_begin())>1){
359 nshared-=getDoubleCount<edm::OwnVector<TrackingRecHit>::const_iterator>(
seed->recHits().first,
seed->recHits().second,
associate.get(), *
t);
363 else if(ri!=0) quality = (
static_cast<double>(nshared)/static_cast<double>(ri));
370 LogTrace(
"TrackAssociator") <<
"Seed number " << tindex <<
" with #hits=" << ri
371 <<
"associated to TP (pdgId, nb segments, p) = " 372 << (*t).pdgId() <<
" " << (*t).g4Tracks().size()
373 <<
" " << (*t).momentum() <<
" number " << tpindex <<
" with quality =" <<
quality;
375 LogTrace(
"TrackAssociator") <<
"Seed number " << tindex <<
" with #hits=" << ri <<
" NOT associated with quality =" <<
quality;
380 LogTrace(
"TrackAssociator") <<
"% of Assoc Seeds=" << ((double)outputCollection.
size())/((
double)seedCollectionH->size());
383 return outputCollection;
391 edm::LogVerbatim(
"TrackAssociator") <<
"Starting TrackAssociatorByHitsImpl::associateSimToReco - #seeds=" 392 <<seedCollectionH->size()<<
" #TPs="<<TPCollectionH->size();
395 std::vector< SimHitIdpr> SimTrackIds;
396 std::vector< SimHitIdpr> matchedIds;
407 LogTrace(
"TrackAssociator") <<
"\nNEW SEED - seed number " << tindex <<
" # valid=" <<
seed->recHits().second-
seed->recHits().first;
408 getMatchedIds<edm::OwnVector<TrackingRecHit>::const_iterator>(matchedIds, SimTrackIds, ri,
seed->recHits().first,
seed->recHits().second,
associate.get() );
411 std::vector<SimHitIdpr> idcachev;
412 if(!matchedIds.empty()){
414 for (TrackingParticleCollection::const_iterator
t = tPC.begin();
t != tPC.end(); ++
t, ++tpindex) {
416 int nsimhit =
t->numberOfTrackerHits();
417 LogTrace(
"TrackAssociator") <<
"TP number " << tpindex <<
" pdgId=" <<
t->pdgId() <<
" with number of PSimHits: " << nsimhit;
418 nshared =
getShared(matchedIds, idcachev, *
t);
421 else if(ri!=0) quality = ((double) nshared)/((double)ri);
429 LogTrace(
"TrackAssociator") <<
"TrackingParticle number " << tpindex <<
" with #hits=" << nsimhit
430 <<
" associated to seed number " << tindex <<
" with #hits=" << ri
431 <<
" with hit quality =" <<
quality ;
434 LogTrace(
"TrackAssociator") <<
"TrackingParticle number " << tpindex <<
" with #hits=" << nsimhit <<
" NOT associated with quality =" <<
quality;
439 LogTrace(
"TrackAssociator") <<
"% of Assoc TPs=" << ((double)outputCollection.
size())/((
double)TPCollectionH->size());
441 return outputCollection;
444 template<
typename iter>
446 std::vector<SimHitIdpr>& SimTrackIds,
453 for (iter it = begin; it !=
end; it++){
461 if(!SimTrackIds.empty()){
462 for(
size_t j=0; j<SimTrackIds.size(); j++){
463 LogTrace(
"TrackAssociator") <<
" hit # " << ri <<
" valid=" << hit->
isValid()
464 <<
" det id = " << t_detID <<
" SimId " << SimTrackIds[j].first
465 <<
" evt=" << SimTrackIds[j].second.event()
466 <<
" bc=" << SimTrackIds[j].second.bunchCrossing();
467 matchedIds.push_back(SimTrackIds[j]);
494 std::vector<SimHitIdpr>& idcachev,
499 for(
size_t j=0; j<matchedIds.size(); j++){
501 if(
find(idcachev.begin(), idcachev.end(),matchedIds[j]) == idcachev.end() ){
503 idcachev.push_back(matchedIds[j]);
513 if((*g4T).trackId() == matchedIds[j].first && t.
eventId() == matchedIds[j].second){
514 int countedhits =
std::count(matchedIds.begin(), matchedIds.end(), matchedIds[j]);
515 nshared += countedhits;
527 template<
typename iter>
532 int doublecount = 0 ;
533 std::vector<SimHitIdpr> SimTrackIdsDC;
535 for (iter it = begin; it !=
end; it++){
537 SimTrackIdsDC.clear();
540 if(SimTrackIdsDC.size()>1){
543 if(
find(SimTrackIdsDC.begin(), SimTrackIdsDC.end(),
SimHitIdpr((*g4T).trackId(), SimTrackIdsDC.begin()->second)) != SimTrackIdsDC.end() ){
548 if (idcount>1) doublecount+=(idcount-1);
SimToRecoDenomType SimToRecoDenominator
std::vector< TrackingParticle > TrackingParticleCollection
static bool simHitTPAssociationListGreater(SimHitTPPair i, SimHitTPPair j)
const double quality_SimToReco
reco::SimToRecoCollection associateSimToReco(const edm::RefToBaseVector< reco::Track > &, const edm::RefVector< TrackingParticleCollection > &) const override
Association Sim To Reco with Collections.
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)
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) ...
Abs< T >::type abs(const T &t)
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
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
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
reco::RecoToSimCollection associateRecoToSim(const edm::RefToBaseVector< reco::Track > &, const edm::RefVector< TrackingParticleCollection > &) const override
Association Reco To Sim with Collections.
Monte Carlo truth information used for tracking validation.
const_iterator end() const
DetId geographicalId() const
const bool ThreeHitTracksAreSpecial
TrackerTopology const * tTopo
const double cut_RecoToSim