37 double iQuality_SimToReco,
38 double iPurity_SimToReco,
39 double iCut_RecoToSim,
43 bool iThreeHitTracksAreSpecial,
44 bool iAbsoluteNumberOfHits) :
45 associate(std::
move(iAssociate)),
47 simHitsTPAssoc(iSimHitsTPAssoc),
48 SimToRecoDenominator(iSimToRecoDenominator),
49 quality_SimToReco(iQuality_SimToReco),
50 purity_SimToReco(iPurity_SimToReco),
51 cut_RecoToSim(iCut_RecoToSim),
52 UsePixels(iUsePixels),
53 UseGrouped(iUseGrouped),
54 UseSplitting(iUseSplitting),
55 ThreeHitTracksAreSpecial(iThreeHitTracksAreSpecial),
56 AbsoluteNumberOfHits(iAbsoluteNumberOfHits) {}
97 std::vector< SimHitIdpr> SimTrackIds;
98 std::vector< SimHitIdpr> matchedIds;
102 std::vector<TrackingParticle const*> tPC;
103 tPC.reserve(tPC.size());
104 for(
auto const& ref: TPCollectionH) {
105 tPC.push_back(&(*ref));
114 getMatchedIds<trackingRecHit_iterator>(matchedIds, SimTrackIds, ri, (*track)->recHitsBegin(), (*track)->recHitsEnd(),
associate.get());
124 std::vector<SimHitIdpr> idcachev;
125 if(!matchedIds.empty()){
128 for (
auto t = tPC.begin();
t != tPC.end(); ++
t, ++tpindex) {
132 nshared =
getShared(matchedIds, idcachev, **
t);
135 if (
abs((*t)->pdgId())==11&&((*t)->g4Track_end()-(*t)->g4Track_begin())>1){
136 nshared-=getDoubleCount<trackingRecHit_iterator>((*track)->recHitsBegin(), (*track)->recHitsEnd(),
associate.get(), **
t);
140 else if(ri!=0) quality = (
static_cast<double>(nshared)/static_cast<double>(ri));
146 outputCollection.
insert(tC[tindex],
147 std::make_pair(TPCollectionH[tpindex],
163 return outputCollection;
177 std::vector< SimHitIdpr> SimTrackIds;
178 std::vector< SimHitIdpr> matchedIds;
182 std::vector<TrackingParticle const*> tPC;
183 tPC.reserve(tPC.size());
184 for(
auto const& ref: TPCollectionH) {
185 tPC.push_back(&(*ref));
204 getMatchedIds<trackingRecHit_iterator>(matchedIds, SimTrackIds, ri, (*track)->recHitsBegin(), (*track)->recHitsEnd(),
associate.get());
207 std::vector<SimHitIdpr> idcachev;
208 if(!matchedIds.empty()){
211 for (
auto t = tPC.begin();
t != tPC.end(); ++
t, ++tpindex) {
216 std::vector<PSimHit> tphits;
219 nshared =
getShared(matchedIds, idcachev, **
t);
233 std::pair<TrackingParticleRef, TrackPSimHitRef>
238 for(
auto ip = range.first; ip != range.second; ++ip) {
242 unsigned int subdetId =
static_cast<unsigned int>(dId.
subdetId());
255 for(std::vector<PSimHit>::const_iterator TPhitOK = tphits.begin(); TPhitOK != tphits.end(); TPhitOK++){
283 tphits.push_back(*TPhit);
288 totsimhit = tphits.size();
298 float purity = 1.0*nshared/ri;
301 outputCollection.
insert(TPCollectionH[tpindex],
302 std::make_pair(tC[tindex],quality));
317 return outputCollection;
324 edm::LogVerbatim(
"TrackAssociator") <<
"Starting TrackAssociatorByHitsImpl::associateRecoToSim - #seeds="
325 <<seedCollectionH->size()<<
" #TPs="<<TPCollectionH->size();
328 std::vector< SimHitIdpr> SimTrackIds;
329 std::vector< SimHitIdpr> matchedIds;
341 int nsimhit =
seed->recHits().second-
seed->recHits().first;
342 LogTrace(
"TrackAssociator") <<
"\nNEW SEED - seed number " << tindex <<
" # valid=" << nsimhit;
343 getMatchedIds<edm::OwnVector<TrackingRecHit>::const_iterator>(matchedIds, SimTrackIds, ri,
seed->recHits().first,
seed->recHits().second,
associate.get() );
346 std::vector<SimHitIdpr> idcachev;
347 if(!matchedIds.empty()){
350 for (TrackingParticleCollection::const_iterator
t = tPC.begin();
t != tPC.end(); ++
t, ++tpindex) {
351 LogTrace(
"TrackAssociator") <<
"TP number " << tpindex <<
" pdgId=" <<
t->pdgId() <<
" with number of PSimHits: " << nsimhit;
353 nshared =
getShared(matchedIds, idcachev, *
t);
356 if (
abs(
t->pdgId())==11&&(
t->g4Track_end()-
t->g4Track_begin())>1){
357 nshared-=getDoubleCount<edm::OwnVector<TrackingRecHit>::const_iterator>(
seed->recHits().first,
seed->recHits().second,
associate.get(), *
t);
361 else if(ri!=0) quality = (
static_cast<double>(nshared)/static_cast<double>(ri));
368 LogTrace(
"TrackAssociator") <<
"Seed number " << tindex <<
" with #hits=" << ri
369 <<
"associated to TP (pdgId, nb segments, p) = "
370 << (*t).pdgId() <<
" " << (*t).g4Tracks().size()
371 <<
" " << (*t).momentum() <<
" number " << tpindex <<
" with quality =" <<
quality;
373 LogTrace(
"TrackAssociator") <<
"Seed number " << tindex <<
" with #hits=" << ri <<
" NOT associated with quality =" <<
quality;
378 LogTrace(
"TrackAssociator") <<
"% of Assoc Seeds=" << ((double)outputCollection.
size())/((
double)seedCollectionH->size());
381 return outputCollection;
389 edm::LogVerbatim(
"TrackAssociator") <<
"Starting TrackAssociatorByHitsImpl::associateSimToReco - #seeds="
390 <<seedCollectionH->size()<<
" #TPs="<<TPCollectionH->size();
393 std::vector< SimHitIdpr> SimTrackIds;
394 std::vector< SimHitIdpr> matchedIds;
405 LogTrace(
"TrackAssociator") <<
"\nNEW SEED - seed number " << tindex <<
" # valid=" <<
seed->recHits().second-
seed->recHits().first;
406 getMatchedIds<edm::OwnVector<TrackingRecHit>::const_iterator>(matchedIds, SimTrackIds, ri,
seed->recHits().first,
seed->recHits().second,
associate.get() );
409 std::vector<SimHitIdpr> idcachev;
410 if(!matchedIds.empty()){
412 for (TrackingParticleCollection::const_iterator
t = tPC.begin();
t != tPC.end(); ++
t, ++tpindex) {
414 int nsimhit =
t->numberOfTrackerHits();
415 LogTrace(
"TrackAssociator") <<
"TP number " << tpindex <<
" pdgId=" <<
t->pdgId() <<
" with number of PSimHits: " << nsimhit;
416 nshared =
getShared(matchedIds, idcachev, *
t);
419 else if(ri!=0) quality = ((double) nshared)/((double)ri);
427 LogTrace(
"TrackAssociator") <<
"TrackingParticle number " << tpindex <<
" with #hits=" << nsimhit
428 <<
" associated to seed number " << tindex <<
" with #hits=" << ri
429 <<
" with hit quality =" <<
quality ;
432 LogTrace(
"TrackAssociator") <<
"TrackingParticle number " << tpindex <<
" with #hits=" << nsimhit <<
" NOT associated with quality =" <<
quality;
437 LogTrace(
"TrackAssociator") <<
"% of Assoc TPs=" << ((double)outputCollection.
size())/((
double)TPCollectionH->size());
439 return outputCollection;
442 template<
typename iter>
444 std::vector<SimHitIdpr>& SimTrackIds,
451 for (
iter it = begin; it !=
end; it++){
459 if(!SimTrackIds.empty()){
460 for(
size_t j=0;
j<SimTrackIds.size();
j++){
461 LogTrace(
"TrackAssociator") <<
" hit # " << ri <<
" valid=" << hit->
isValid()
462 <<
" det id = " << t_detID <<
" SimId " << SimTrackIds[
j].first
463 <<
" evt=" << SimTrackIds[
j].second.event()
464 <<
" bc=" << SimTrackIds[
j].second.bunchCrossing();
465 matchedIds.push_back(SimTrackIds[
j]);
492 std::vector<SimHitIdpr>& idcachev,
497 for(
size_t j=0;
j<matchedIds.size();
j++){
499 if(
find(idcachev.begin(), idcachev.end(),matchedIds[
j]) == idcachev.end() ){
501 idcachev.push_back(matchedIds[
j]);
511 if((*g4T).trackId() == matchedIds[
j].first && t.
eventId() == matchedIds[
j].second){
512 int countedhits =
std::count(matchedIds.begin(), matchedIds.end(), matchedIds[
j]);
513 nshared += countedhits;
525 template<
typename iter>
530 int doublecount = 0 ;
531 std::vector<SimHitIdpr> SimTrackIdsDC;
533 for (
iter it = begin; it !=
end; it++){
535 SimTrackIdsDC.clear();
538 if(SimTrackIdsDC.size()>1){
541 if(
find(SimTrackIdsDC.begin(), SimTrackIdsDC.end(),
SimHitIdpr((*g4T).trackId(), SimTrackIdsDC.begin()->second)) != SimTrackIdsDC.end() ){
546 if (idcount>1) doublecount+=(idcount-1);
SimToRecoDenomType SimToRecoDenominator
TrackAssociatorByHitsImpl(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)
std::vector< TrackingParticle > TrackingParticleCollection
static bool simHitTPAssociationListGreater(SimHitTPPair i, SimHitTPPair j)
const double quality_SimToReco
const_iterator end() const
std::unique_ptr< TrackerHitAssociator > associate
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
SimHitTPAssociationList const * simHitsTPAssoc
uint32_t rawId() const
get the raw id
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
virtual 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)
int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
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
virtual 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
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
edm::Ref< edm::PSimHitContainer > TrackPSimHitRef
const double purity_SimToReco
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