7 : pHitAssociator_(
NULL), pEventForWhichAssociatorIsValid_(
NULL),
8 absoluteNumberOfHits_( config.getParameter<bool>(
"AbsoluteNumberOfHits" ) ),
9 qualitySimToReco_( config.getParameter<double>(
"Quality_SimToReco" ) ),
10 puritySimToReco_( config.getParameter<double>(
"Purity_SimToReco" ) ),
11 cutRecoToSim_( config.getParameter<double>(
"Cut_RecoToSim" ) ),
12 threeHitTracksAreSpecial_( config.getParameter<bool> (
"ThreeHitTracksAreSpecial" ) )
18 std::string denominatorString=config.
getParameter<std::string>(
"SimToRecoDenominator");
21 else throw cms::Exception(
"QuickTrackAssociatorByHits" ) <<
"SimToRecoDenominator not specified as sim or reco";
37 bool useGrouped, useSplitting;
41 if( config.
exists(
"UseSplitting") ) useSplitting=config.
getParameter<
bool>(
"UseSplitting");
42 else useSplitting=
true;
46 if( !(useGrouped && useSplitting) )
48 edm::LogWarning(
"QuickTrackAssociatorByHits") <<
"UseGrouped and/or UseSplitting has been set to false, but this associator ignores that setting.";
58 : pEventForWhichAssociatorIsValid_(otherAssociator.pEventForWhichAssociatorIsValid_),
59 hitAssociatorParameters_(otherAssociator.hitAssociatorParameters_),
60 absoluteNumberOfHits_(otherAssociator.absoluteNumberOfHits_),
61 qualitySimToReco_(otherAssociator.qualitySimToReco_),
62 puritySimToReco_(otherAssociator.puritySimToReco_),
63 cutRecoToSim_(otherAssociator.cutRecoToSim_),
64 threeHitTracksAreSpecial_(otherAssociator.threeHitTracksAreSpecial_),
65 simToRecoDenominator_(otherAssociator.simToRecoDenominator_),
66 pTrackCollectionHandle_(otherAssociator.pTrackCollectionHandle_),
67 pTrackCollection_(otherAssociator.pTrackCollection_),
68 pTrackingParticleCollectionHandle_(otherAssociator.pTrackingParticleCollectionHandle_),
69 pTrackingParticleCollection_(otherAssociator.pTrackingParticleCollection_)
175 size_t collectionSize;
178 else collectionSize=(*pTrackCollectionHandle_)->size();
180 for(
size_t i=0;
i<collectionSize; ++
i )
187 std::vector< std::pair<edm::Ref<TrackingParticleCollection>,
size_t> > trackingParticleQualityPairs=
associateTrack( pTrack );
189 iTrackingParticleQualityPair!=trackingParticleQualityPairs.end(); ++iTrackingParticleQualityPair )
192 size_t numberOfSharedHits=iTrackingParticleQualityPair->second;
193 size_t numberOfValidTrackHits=pTrack->
found();
195 if( numberOfSharedHits==0 )
continue;
198 if(
abs(trackingParticleRef->pdgId())==11 && (trackingParticleRef->g4Track_end() - trackingParticleRef->g4Track_begin()) > 1 )
205 else if( numberOfValidTrackHits != 0 ) quality=(
static_cast<double>(numberOfSharedHits) / static_cast<double>(numberOfValidTrackHits) );
222 size_t collectionSize;
225 else collectionSize=(*pTrackCollectionHandle_)->size();
227 for(
size_t i=0;
i<collectionSize; ++
i )
234 std::vector< std::pair<edm::Ref<TrackingParticleCollection>,
size_t> > trackingParticleQualityPairs=
associateTrack( pTrack );
236 iTrackingParticleQualityPair!=trackingParticleQualityPairs.end(); ++iTrackingParticleQualityPair )
239 size_t numberOfSharedHits=iTrackingParticleQualityPair->second;
240 size_t numberOfValidTrackHits=pTrack->
found();
241 size_t numberOfSimulatedHits=0;
243 if( numberOfSharedHits==0 )
continue;
251 numberOfSimulatedHits=trackingParticleRef->trackPSimHit(
DetId::Tracker).size();
254 double purity=
static_cast<double>(numberOfSharedHits)/static_cast<double>(numberOfValidTrackHits);
257 else if(
simToRecoDenominator_==
denomsim && numberOfSimulatedHits != 0 ) quality=
static_cast<double>(numberOfSharedHits)/static_cast<double>(numberOfSimulatedHits);
275 std::vector< std::pair<edm::Ref<TrackingParticleCollection>,
size_t> > returnValue;
283 size_t collectionSize;
285 else collectionSize=(*pTrackingParticleCollectionHandle_)->size();
287 for(
size_t i=0;
i<collectionSize; ++
i )
294 if( pTrackingParticle->
trackPSimHit().empty() )
continue;
296 size_t numberOfAssociatedHits=0;
299 for( std::vector< std::pair<SimTrackIdentifiers,size_t> >::const_iterator iIdentifierCountPair=hitIdentifiers.begin(); iIdentifierCountPair!=hitIdentifiers.end(); ++iIdentifierCountPair )
304 if( numberOfAssociatedHits>0 )
317 std::vector< std::pair<SimTrackIdentifiers,size_t> > returnValue;
319 std::vector<SimTrackIdentifiers> simTrackIdentifiers;
323 if( (*iRecHit)->isValid() )
325 simTrackIdentifiers.clear();
332 for( std::vector<SimTrackIdentifiers>::const_iterator iIdentifier=simTrackIdentifiers.begin(); iIdentifier!=simTrackIdentifiers.end(); ++iIdentifier )
334 std::vector< std::pair<SimTrackIdentifiers,size_t> >::iterator iIdentifierCountPair;
335 for( iIdentifierCountPair=returnValue.begin(); iIdentifierCountPair!=returnValue.end(); ++iIdentifierCountPair )
337 if( iIdentifierCountPair->first.first==iIdentifier->first && iIdentifierCountPair->first.second==iIdentifier->second )
340 ++iIdentifierCountPair->second;
344 if( iIdentifierCountPair==returnValue.end() ) returnValue.push_back( std::make_pair(*iIdentifier,1) );
355 for( std::vector<SimTrack>::const_iterator iSimTrack=pTrackingParticle->
g4Track_begin(); iSimTrack!=pTrackingParticle->
g4Track_end(); ++iSimTrack )
358 if( iSimTrack->eventId()==identifier.second && iSimTrack->trackId()==identifier.first )
375 std::vector<SimHitIdpr> SimTrackIdsDC;
380 SimTrackIdsDC.clear();
383 if( SimTrackIdsDC.size() > 1 )
387 if(
find( SimTrackIdsDC.begin(), SimTrackIdsDC.end(),
SimHitIdpr( ( *g4T).trackId(), SimTrackIdsDC.begin()->second ) )
388 != SimTrackIdsDC.end() )
394 if( idcount > 1 ) doubleCount+=(idcount - 1);
T getParameter(std::string const &) const
TrackAssociator that associates by hits a bit quicker than the normal TrackAssociatorByHits class...
int getDoubleCount(trackingRecHit_iterator begin, trackingRecHit_iterator end, const TrackingParticle &associatedTrackingParticle) const
This method was copied almost verbatim from the standard TrackAssociatorByHits.
const std::vector< PSimHit > & trackPSimHit() const
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.
g4t_iterator g4Track_begin() 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_
reco::RecoToSimCollection associateRecoToSimImplementation() const
The method that does the work for both overloads of associateRecoToSim.
bool threeHitTracksAreSpecial_
void addParameter(std::string const &name, T const &value)
trackingRecHit_iterator recHitsBegin() const
Iterator to first hit on the track.
std::vector< std::pair< edm::Ref< TrackingParticleCollection >, size_t > > associateTrack(const reco::Track *pTrack) const
Returns the TrackingParticle that has the most associated hits to the given track.
std::vector< SimTrack >::const_iterator g4t_iterator
std::pair< uint32_t, EncodedEventId > SimHitIdpr
void insert(const key_type &k, const data_type &v)
insert an association
edm::ParameterSet hitAssociatorParameters_
reco::SimToRecoCollection associateSimToRecoImplementation() const
The method that does the work for both overloads of associateSimToReco.
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.
unsigned short found() const
Number of valid hits on track.
size_type size() const
Size of the RefVector.
SimToRecoDenomType simToRecoDenominator_
void initialiseHitAssociator(const edm::Event *event) const
edm::Handle< edm::View< reco::Track > > * pTrackCollectionHandle_
Pointer to the handle to the track collection.
~QuickTrackAssociatorByHits()
g4t_iterator g4Track_end() const
std::vector< std::pair< SimTrackIdentifiers, size_t > > getAllSimTrackIdentifiers(const reco::Track *pTrack) const
Returns a vector of pairs where first is a SimTrackIdentifiers (see typedef above) and second is the ...
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
compare reco to sim the handle of reco::Track and TrackingParticle collections
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
compare reco to sim the handle of reco::Track and TrackingParticle collections
TrackerHitAssociator * pHitAssociator_
trackingRecHit_iterator recHitsEnd() const
Iterator to last hit on the track.