18 : pHitAssociator_(
nullptr), pEventForWhichAssociatorIsValid_(
nullptr),
19 absoluteNumberOfHits_( config.getParameter<bool>(
"AbsoluteNumberOfHits" ) ),
20 qualitySimToReco_( config.getParameter<double>(
"Quality_SimToReco" ) ),
21 puritySimToReco_( config.getParameter<double>(
"Purity_SimToReco" ) ),
22 cutRecoToSim_( config.getParameter<double>(
"Cut_RecoToSim" ) ),
23 threeHitTracksAreSpecial_( config.getParameter<bool> (
"ThreeHitTracksAreSpecial" ) ),
24 useClusterTPAssociation_(config.getParameter<bool>(
"useClusterTPAssociation")),
25 cluster2TPSrc_(config.getParameter<edm::InputTag>(
"cluster2TPSrc"))
34 else throw cms::Exception(
"QuickTrackAssociatorByHits" ) <<
"SimToRecoDenominator not specified as sim or reco";
50 bool useGrouped, useSplitting;
54 if( config.
exists(
"UseSplitting") ) useSplitting=config.
getParameter<
bool>(
"UseSplitting");
55 else useSplitting=
true;
59 if( !(useGrouped && useSplitting) )
61 edm::LogWarning(
"QuickTrackAssociatorByHits") <<
"UseGrouped and/or UseSplitting has been set to false, but this associator ignores that setting.";
71 : pEventForWhichAssociatorIsValid_(otherAssociator.pEventForWhichAssociatorIsValid_),
72 hitAssociatorParameters_(otherAssociator.hitAssociatorParameters_),
73 absoluteNumberOfHits_(otherAssociator.absoluteNumberOfHits_),
74 qualitySimToReco_(otherAssociator.qualitySimToReco_),
75 puritySimToReco_(otherAssociator.puritySimToReco_),
76 cutRecoToSim_(otherAssociator.cutRecoToSim_),
77 threeHitTracksAreSpecial_(otherAssociator.threeHitTracksAreSpecial_),
78 simToRecoDenominator_(otherAssociator.simToRecoDenominator_),
79 pTrackCollectionHandle_(otherAssociator.pTrackCollectionHandle_),
80 pTrackCollection_(otherAssociator.pTrackCollection_),
81 pTrackingParticleCollectionHandle_(otherAssociator.pTrackingParticleCollectionHandle_),
82 pTrackingParticleCollection_(otherAssociator.pTrackingParticleCollection_),
83 useClusterTPAssociation_(otherAssociator.useClusterTPAssociation_),
84 cluster2TPSrc_(otherAssociator.cluster2TPSrc_)
207 size_t collectionSize;
210 else collectionSize=(*pTrackCollectionHandle_)->size();
213 for(
size_t i=0;
i<collectionSize; ++
i )
221 std::vector< std::pair<edm::Ref<TrackingParticleCollection>,
size_t> > trackingParticleQualityPairs = (
useClusterTPAssociation_)
226 for (std::vector< std::pair<
edm::Ref<TrackingParticleCollection>,
size_t> >::const_iterator iTrackingParticleQualityPair=trackingParticleQualityPairs.begin(); iTrackingParticleQualityPair!=trackingParticleQualityPairs.end(); ++iTrackingParticleQualityPair )
229 size_t numberOfSharedHits=iTrackingParticleQualityPair->second;
230 size_t numberOfValidTrackHits=pTrack->
found();
233 if (numberOfSharedHits==0)
continue;
236 if (
abs(trackingParticleRef->pdgId())==11 && (trackingParticleRef->g4Track_end() - trackingParticleRef->g4Track_begin()) > 1 )
243 quality =
static_cast<double>(numberOfSharedHits);
244 else if (numberOfValidTrackHits != 0)
245 quality = (
static_cast<double>(numberOfSharedHits) / static_cast<double>(numberOfValidTrackHits));
262 size_t collectionSize;
265 else collectionSize=(*pTrackCollectionHandle_)->size();
267 for(
size_t i=0;
i<collectionSize; ++
i )
274 std::vector< std::pair<edm::Ref<TrackingParticleCollection>,
size_t> > trackingParticleQualityPairs = (
useClusterTPAssociation_)
280 iTrackingParticleQualityPair!=trackingParticleQualityPairs.end(); ++iTrackingParticleQualityPair )
283 size_t numberOfSharedHits=iTrackingParticleQualityPair->second;
284 size_t numberOfValidTrackHits=pTrack->
found();
285 size_t numberOfSimulatedHits=0;
288 if( numberOfSharedHits==0 )
continue;
296 numberOfSimulatedHits=trackingParticleRef->numberOfTrackerHits();
301 if (
abs(trackingParticleRef->pdgId())==11 && (trackingParticleRef->g4Track_end() - trackingParticleRef->g4Track_begin()) > 1 )
307 double purity=
static_cast<double>(numberOfSharedHits)/static_cast<double>(numberOfValidTrackHits);
310 else if(
simToRecoDenominator_==
denomsim && numberOfSimulatedHits != 0 ) quality=
static_cast<double>(numberOfSharedHits)/static_cast<double>(numberOfSimulatedHits);
328 std::vector< std::pair<edm::Ref<TrackingParticleCollection>,
size_t> > returnValue;
336 size_t collectionSize;
338 else collectionSize=(*pTrackingParticleCollectionHandle_)->size();
340 for(
size_t i=0;
i<collectionSize; ++
i )
349 size_t numberOfAssociatedHits=0;
352 for( std::vector< std::pair<SimTrackIdentifiers,size_t> >::const_iterator iIdentifierCountPair=hitIdentifiers.begin(); iIdentifierCountPair!=hitIdentifiers.end(); ++iIdentifierCountPair )
357 if( numberOfAssociatedHits>0 )
372 if (pCluster2TPListH.
isValid()) {
377 edm::LogInfo(
"TrackAssociator") <<
"ClusterTPAssociationList with label "<<
cluster2TPSrc_<<
" not found. Using DigiSimLink based associator";
387 std::vector<std::pair<edm::Ref<TrackingParticleCollection>,
size_t> > returnValue;
396 std::map<TrackingParticleRef, size_t> lmap;
397 for (std::vector<OmniClusterRef>::const_iterator it = oClusters.begin(); it != oClusters.end(); ++it) {
399 std::pair<OmniClusterRef, TrackingParticleRef> clusterTPpairWithDummyTP(*it,
TrackingParticleRef());
401 if(range.first != range.second) {
402 for(
auto ip = range.first; ip != range.second; ++ip) {
407 if (trackingParticle->numberOfHits()==0)
continue;
422 auto jpos = lmap.find(trackingParticle);
423 if (jpos != lmap.end())
426 lmap.insert(std::make_pair(trackingParticle, 1));
431 for (
auto ip = lmap.begin(); ip != lmap.end(); ++ip) {
432 returnValue.push_back(std::make_pair(ip->first, ip->second));
439 std::vector<OmniClusterRef> returnValue;
440 for (iter iRecHit = begin; iRecHit !=
end; ++iRecHit) {
446 if (!pRHit->cluster().isNonnull())
447 edm::LogError(
"TrackAssociator") <<
">>> RecHit does not have an associated cluster!" <<
" file: " << __FILE__ <<
" line: " << __LINE__;
448 returnValue.push_back(pRHit->omniClusterRef());
451 const std::type_info &tid =
typeid(*rhit);
452 if (tid ==
typeid(SiStripMatchedRecHit2D)) {
453 const SiStripMatchedRecHit2D* sMatchedRHit =
dynamic_cast<const SiStripMatchedRecHit2D*
>(rhit);
454 if (!sMatchedRHit->monoHit().cluster().isNonnull() || !sMatchedRHit->stereoHit().cluster().isNonnull())
455 edm::LogError(
"TrackAssociator") <<
">>> RecHit does not have an associated cluster!" <<
" file: " << __FILE__ <<
" line: " << __LINE__;
456 returnValue.push_back(sMatchedRHit->monoClusterRef());
457 returnValue.push_back(sMatchedRHit->stereoClusterRef());
459 else if (tid ==
typeid(SiStripRecHit2D)) {
460 const SiStripRecHit2D* sRHit =
dynamic_cast<const SiStripRecHit2D*
>(rhit);
461 if (!sRHit->cluster().isNonnull())
462 edm::LogError(
"TrackAssociator") <<
">>> RecHit does not have an associated cluster!" <<
" file: " << __FILE__ <<
" line: " << __LINE__;
463 returnValue.push_back(sRHit->omniClusterRef());
465 else if (tid ==
typeid(SiStripRecHit1D)) {
466 const SiStripRecHit1D* sRHit =
dynamic_cast<const SiStripRecHit1D*
>(rhit);
467 if (!sRHit->cluster().isNonnull())
468 edm::LogError(
"TrackAssociator") <<
">>> RecHit does not have an associated cluster!" <<
" file: " << __FILE__ <<
" line: " << __LINE__;
469 returnValue.push_back(sRHit->omniClusterRef());
472 edm::LogError(
"TrackAssociator") <<
">>> getMatchedClusters: TrackingRecHit not associated to any SiStripCluster! subdetid = " << subdetid;
476 edm::LogError(
"TrackAssociator") <<
">>> getMatchedClusters: TrackingRecHit not associated to any cluster! subdetid = " << subdetid;
486 std::vector< std::pair<SimTrackIdentifiers,size_t> > returnValue;
488 std::vector<SimTrackIdentifiers> simTrackIdentifiers;
491 for( iter iRecHit=begin; iRecHit!=
end; ++iRecHit )
495 simTrackIdentifiers.clear();
501 for ( std::vector<SimTrackIdentifiers>::const_iterator iIdentifier = simTrackIdentifiers.begin();
502 iIdentifier != simTrackIdentifiers.end();
505 std::vector< std::pair<SimTrackIdentifiers,size_t> >::iterator iIdentifierCountPair;
506 for (iIdentifierCountPair=returnValue.begin(); iIdentifierCountPair!=returnValue.end(); ++iIdentifierCountPair)
508 if (iIdentifierCountPair->first.first==iIdentifier->first && iIdentifierCountPair->first.second==iIdentifier->second )
511 ++iIdentifierCountPair->second;
515 if( iIdentifierCountPair==returnValue.end() ) returnValue.push_back( std::make_pair(*iIdentifier,1) );
526 for( std::vector<SimTrack>::const_iterator iSimTrack=pTrackingParticle->
g4Track_begin(); iSimTrack!=pTrackingParticle->
g4Track_end(); ++iSimTrack )
529 if( iSimTrack->eventId()==identifier.second && iSimTrack->trackId()==identifier.first )
546 std::vector<SimHitIdpr> SimTrackIdsDC;
548 for( iter iHit=startIterator; iHit != endIterator; iHit++ )
554 for (std::vector<OmniClusterRef>::const_iterator it = oClusters.begin(); it != oClusters.end(); ++it) {
555 std::pair<OmniClusterRef, TrackingParticleRef> clusterTPpairWithDummyTP(*it,
TrackingParticleRef());
557 if(range.first != range.second) {
558 for(
auto ip = range.first; ip != range.second; ++ip) {
560 if (associatedTrackingParticle==trackingParticle) {
567 SimTrackIdsDC.clear();
569 if( SimTrackIdsDC.size() > 1 )
573 if(
find( SimTrackIdsDC.begin(), SimTrackIdsDC.end(),
SimHitIdpr( ( *g4T).trackId(), SimTrackIdsDC.begin()->second ) )
574 != SimTrackIdsDC.end() )
581 if( idcount > 1 ) doubleCount+=(idcount - 1);
613 edm::LogVerbatim(
"TrackAssociator") <<
"Starting TrackAssociatorByHits::associateRecoToSim - #seeds="
614 << pSeedCollectionHandle_->size()<<
" #TPs="<<trackingParticleCollectionHandle->size();
624 size_t collectionSize=pSeedCollectionHandle_->
size();
626 for(
size_t i=0;
i<collectionSize; ++
i )
631 std::vector< std::pair<edm::Ref<TrackingParticleCollection>,
size_t> > trackingParticleQualityPairs = (
useClusterTPAssociation_)
635 iTrackingParticleQualityPair!=trackingParticleQualityPairs.end(); ++iTrackingParticleQualityPair )
638 size_t numberOfSharedHits=iTrackingParticleQualityPair->second;
639 size_t numberOfValidTrackHits=pSeed->
recHits().second-pSeed->
recHits().first;
641 if( numberOfSharedHits==0 )
continue;
644 if(
abs(trackingParticleRef->pdgId())==11 && (trackingParticleRef->g4Track_end() - trackingParticleRef->g4Track_begin()) > 1 )
651 else if( numberOfValidTrackHits != 0 ) quality=(
static_cast<double>(numberOfSharedHits) / static_cast<double>(numberOfValidTrackHits) );
661 LogTrace(
"TrackAssociator") <<
"% of Assoc Seeds=" << ((double)returnValue.
size())/((
double)pSeedCollectionHandle_->size());
674 edm::LogVerbatim(
"TrackAssociator") <<
"Starting TrackAssociatorByHits::associateSimToReco - #seeds="
675 <<pSeedCollectionHandle_->size()<<
" #TPs="<<trackingParticleCollectionHandle->size();
685 size_t collectionSize=pSeedCollectionHandle_->
size();
687 for(
size_t i=0;
i<collectionSize; ++
i )
692 std::vector< std::pair<edm::Ref<TrackingParticleCollection>,
size_t> > trackingParticleQualityPairs = (
useClusterTPAssociation_)
696 iTrackingParticleQualityPair!=trackingParticleQualityPairs.end(); ++iTrackingParticleQualityPair )
699 size_t numberOfSharedHits=iTrackingParticleQualityPair->second;
700 size_t numberOfValidTrackHits=pSeed->
recHits().second-pSeed->
recHits().first;
701 size_t numberOfSimulatedHits=0;
703 if( numberOfSharedHits==0 )
continue;
706 if(
abs(trackingParticleRef->pdgId())==11 && (trackingParticleRef->g4Track_end() - trackingParticleRef->g4Track_begin()) > 1 )
717 numberOfSimulatedHits=trackingParticleRef->numberOfTrackerHits();
720 double purity=
static_cast<double>(numberOfSharedHits)/static_cast<double>(numberOfValidTrackHits);
723 else if(
simToRecoDenominator_==
denomsim && numberOfSimulatedHits != 0 ) quality=
static_cast<double>(numberOfSharedHits)/static_cast<double>(numberOfSimulatedHits);
735 LogTrace(
"TrackAssociator") <<
"% of Assoc TPs=" << ((double)returnValue.
size())/((
double)trackingParticleCollectionHandle->size());
T getParameter(std::string const &) const
const TrackingRecHit * getHitFromIter(trackingRecHit_iterator iter) const
std::vector< std::pair< edm::Ref< TrackingParticleCollection >, size_t > > associateTrack(iter begin, iter end) const
Returns the TrackingParticle that has the most associated hits to the given track.
TrackAssociator that associates by hits a bit quicker than the normal TrackAssociatorByHits class...
static bool clusterTPAssociationListGreater(std::pair< OmniClusterRef, TrackingParticleRef > i, std::pair< OmniClusterRef, TrackingParticleRef > j)
const edm::Event * pEventForWhichAssociatorIsValid_
bool trackingParticleContainsIdentifier(const TrackingParticle *pTrackingParticle, const SimTrackIdentifiers &identifier) const
Returns true if the supplied TrackingParticle has the supplied g4 track identifiers.
ClusterTPAssociationList pCluster2TPList_
g4t_iterator g4Track_begin() const
virtual reco::SimToRecoCollection associateSimToReco(edm::Handle< edm::View< reco::Track > > &trackCollectionHandle, edm::Handle< TrackingParticleCollection > &trackingParticleCollectionHandle, const edm::Event *pEvent=0, const edm::EventSetup *pSetup=0) const override
compare reco to sim the handle of reco::Track and TrackingParticle collections
std::vector< std::pair< edm::Ref< TrackingParticleCollection >, size_t > > associateTrackByCluster(iter begin, iter end) const
bool exists(std::string const ¶meterName) const
checks if a parameter exists
QuickTrackAssociatorByHits & operator=(const QuickTrackAssociatorByHits &otherAssociator)
QuickTrackAssociatorByHits(const edm::ParameterSet &config)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
std::vector< SimHitIdpr > associateHitId(const TrackingRecHit &thit)
const edm::RefVector< TrackingParticleCollection > * pTrackingParticleCollection_
Pointer to the TrackingParticle collection handle.
std::pair< uint32_t, EncodedEventId > SimTrackIdentifiers
bool absoluteNumberOfHits_
int getDoubleCount(iter begin, iter end, TrackingParticleRef associatedTrackingParticle) const
This method was copied almost verbatim from the standard TrackAssociatorByHits.
reco::RecoToSimCollection associateRecoToSimImplementation() const
The method that does the work for both overloads of associateRecoToSim.
std::vector< std::pair< SimTrackIdentifiers, size_t > > getAllSimTrackIdentifiers(iter begin, iter end) const
Returns a vector of pairs where first is a SimTrackIdentifiers (see typedef above) and second is the ...
void post_insert()
post insert action
bool threeHitTracksAreSpecial_
void addParameter(std::string const &name, T const &value)
virtual reco::RecoToSimCollection associateRecoToSim(edm::Handle< edm::View< reco::Track > > &trackCollectionHandle, edm::Handle< TrackingParticleCollection > &trackingParticleCollectionHandle, const edm::Event *pEvent=0, const edm::EventSetup *pSetup=0) const override
compare reco to sim the handle of reco::Track and TrackingParticle collections
Abs< T >::type abs(const T &t)
trackingRecHit_iterator recHitsBegin() const
Iterator to first hit on the track.
int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
std::vector< SimTrack >::const_iterator g4t_iterator
std::pair< uint32_t, EncodedEventId > SimHitIdpr
size_type size() const
map size
void insert(const key_type &k, const data_type &v)
insert an association
edm::ParameterSet hitAssociatorParameters_
bool useClusterTPAssociation_
reco::SimToRecoCollection associateSimToRecoImplementation() const
The method that does the work for both overloads of associateSimToReco.
int numberOfHits() const
Gives the total number of hits, including muon hits. Hits on overlaps in the same layer count separat...
T const * product() const
edm::Handle< TrackingParticleCollection > * pTrackingParticleCollectionHandle_
Pointer to the TrackingParticle collection handle.
const edm::RefToBaseVector< reco::Track > * pTrackCollection_
Pointer to the track collection.
std::vector< OmniClusterRef > getMatchedClusters(iter begin, iter end) const
unsigned short found() const
Number of valid hits on track.
size_type size() const
Size of the RefVector.
Monte Carlo truth information used for tracking validation.
SimToRecoDenomType simToRecoDenominator_
void initialiseHitAssociator(const edm::Event *event) const
edm::Handle< edm::View< reco::Track > > * pTrackCollectionHandle_
Pointer to the handle to the track collection.
DetId geographicalId() const
~QuickTrackAssociatorByHits()
g4t_iterator g4Track_end() const
void prepareCluster2TPMap(const edm::Event *pEvent) const
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
edm::Ref< TrackingParticleCollection > TrackingParticleRef
edm::InputTag cluster2TPSrc_
TrackerHitAssociator * pHitAssociator_
trackingRecHit_iterator recHitsEnd() const
Iterator to last hit on the track.