37 AbsoluteNumberOfHits(conf_.getParameter<bool>(
"AbsoluteNumberOfHits")),
38 SimToRecoDenominator(denomnone),
39 quality_SimToReco(conf_.getParameter<double>(
"Quality_SimToReco")),
40 purity_SimToReco(conf_.getParameter<double>(
"Purity_SimToReco")),
41 cut_RecoToSim(conf_.getParameter<double>(
"Cut_RecoToSim")),
42 UsePixels(conf_.getParameter<bool>(
"UsePixels")),
43 UseGrouped(conf_.getParameter<bool>(
"UseGrouped")),
44 UseSplitting(conf_.getParameter<bool>(
"UseSplitting")),
45 ThreeHitTracksAreSpecial(conf_.getParameter<bool>(
"ThreeHitTracksAreSpecial")),
46 _simHitTpMapTag(conf_.getParameter<edm::
InputTag>(
"simHitTpMapTag"))
51 }
else if (tmp ==
"reco") {
56 throw cms::Exception(
"TrackAssociatorByHits") <<
"SimToRecoDenominator not specified as sim or reco";
81 std::vector< SimHitIdpr> SimTrackIds;
82 std::vector< SimHitIdpr> matchedIds;
88 std::vector<TrackingParticle const*> tPC;
89 tPC.reserve(TPCollectionH.
size());
90 for(
auto const& ref: TPCollectionH) {
91 tPC.push_back(&(*ref));
100 getMatchedIds<trackingRecHit_iterator>(matchedIds, SimTrackIds, ri, (*track)->recHitsBegin(), (*track)->recHitsEnd(), &associate);
110 std::vector<SimHitIdpr> idcachev;
111 if(!matchedIds.empty()){
114 for (
auto t = tPC.begin();
t != tPC.end(); ++
t, ++tpindex) {
118 nshared = getShared(matchedIds, idcachev, **
t);
121 if (
abs((*t)->pdgId())==11&&((*t)->g4Track_end()-(*t)->g4Track_begin())>1){
122 nshared-=getDoubleCount<trackingRecHit_iterator>((*track)->recHitsBegin(), (*track)->recHitsEnd(), &associate, **
t);
125 if (AbsoluteNumberOfHits) quality =
static_cast<double>(nshared);
126 else if(ri!=0) quality = (
static_cast<double>(nshared)/static_cast<double>(ri));
130 if(quality > cut_RecoToSim && !(ThreeHitTracksAreSpecial && ri==3 && nshared<3)){
132 outputCollection.
insert(tC[tindex],
133 std::make_pair(TPCollectionH[tpindex],
149 return outputCollection;
165 std::vector< SimHitIdpr> SimTrackIds;
166 std::vector< SimHitIdpr> matchedIds;
172 std::vector<TrackingParticle const*> tPC;
173 tPC.reserve(TPCollectionH.
size());
174 for(
auto const& ref: TPCollectionH) {
175 tPC.push_back(&(*ref));
187 e->
getByLabel(_simHitTpMapTag,simHitsTPAssoc);
194 getMatchedIds<trackingRecHit_iterator>(matchedIds, SimTrackIds, ri, (*track)->recHitsBegin(), (*track)->recHitsEnd(), &associate);
197 std::vector<SimHitIdpr> idcachev;
198 if(!matchedIds.empty()){
201 for (
auto t = tPC.begin();
t != tPC.end(); ++
t, ++tpindex) {
207 std::vector<PSimHit> tphits;
210 nshared = getShared(matchedIds, idcachev, **
t);
224 std::pair<TrackingParticleRef, TrackPSimHitRef>
227 auto range = std::equal_range(simHitsTPAssoc->begin(), simHitsTPAssoc->end(),
229 for(
auto ip = range.first; ip != range.second; ++ip) {
233 unsigned int subdetId =
static_cast<unsigned int>(dId.
subdetId());
246 for(std::vector<PSimHit>::const_iterator TPhitOK = tphits.begin(); TPhitOK != tphits.end(); TPhitOK++){
253 if (!UseGrouped && !UseSplitting)
257 if (!UseGrouped && UseSplitting)
263 if (UseGrouped && !UseSplitting)
269 if (UseGrouped && UseSplitting)
274 tphits.push_back(*TPhit);
279 totsimhit = tphits.size();
282 if (AbsoluteNumberOfHits) quality =
static_cast<double>(nshared);
283 else if(SimToRecoDenominator == denomsim && totsimhit!=0) quality = ((double) nshared)/((double)totsimhit);
284 else if(SimToRecoDenominator == denomreco && ri!=0) quality = ((double) nshared)/((double)ri);
289 float purity = 1.0*nshared/ri;
290 if (quality>quality_SimToReco && !(ThreeHitTracksAreSpecial && totsimhit==3 && nshared<3) && (AbsoluteNumberOfHits||(purity>purity_SimToReco))) {
292 outputCollection.
insert(TPCollectionH[tpindex],
293 std::make_pair(tC[tindex],quality));
308 return outputCollection;
318 edm::LogVerbatim(
"TrackAssociator") <<
"Starting TrackAssociatorByHits::associateRecoToSim - #seeds="
319 <<seedCollectionH->size()<<
" #TPs="<<TPCollectionH->size();
322 std::vector< SimHitIdpr> SimTrackIds;
323 std::vector< SimHitIdpr> matchedIds;
337 int nsimhit =
seed->recHits().second-
seed->recHits().first;
338 LogTrace(
"TrackAssociator") <<
"\nNEW SEED - seed number " << tindex <<
" # valid=" << nsimhit;
339 getMatchedIds<edm::OwnVector<TrackingRecHit>::const_iterator>(matchedIds, SimTrackIds, ri,
seed->recHits().first,
seed->recHits().second, &associate );
342 std::vector<SimHitIdpr> idcachev;
343 if(!matchedIds.empty()){
346 for (TrackingParticleCollection::const_iterator
t = tPC.begin();
t != tPC.end(); ++
t, ++tpindex) {
347 LogTrace(
"TrackAssociator") <<
"TP number " << tpindex <<
" pdgId=" <<
t->pdgId() <<
" with number of PSimHits: " << nsimhit;
349 nshared = getShared(matchedIds, idcachev, *
t);
352 if (
abs(
t->pdgId())==11&&(
t->g4Track_end()-
t->g4Track_begin())>1){
353 nshared-=getDoubleCount<edm::OwnVector<TrackingRecHit>::const_iterator>(
seed->recHits().first,
seed->recHits().second, &associate, *
t);
356 if (AbsoluteNumberOfHits) quality =
static_cast<double>(nshared);
357 else if(ri!=0) quality = (
static_cast<double>(nshared)/static_cast<double>(ri));
360 if(quality > cut_RecoToSim && !(ThreeHitTracksAreSpecial && ri==3 && nshared<3) ){
364 LogTrace(
"TrackAssociator") <<
"Seed number " << tindex <<
" with #hits=" << ri
365 <<
"associated to TP (pdgId, nb segments, p) = "
366 << (*t).pdgId() <<
" " << (*t).g4Tracks().size()
367 <<
" " << (*t).momentum() <<
" number " << tpindex <<
" with quality =" <<
quality;
369 LogTrace(
"TrackAssociator") <<
"Seed number " << tindex <<
" with #hits=" << ri <<
" NOT associated with quality =" <<
quality;
374 LogTrace(
"TrackAssociator") <<
"% of Assoc Seeds=" << ((double)outputCollection.
size())/((
double)seedCollectionH->size());
376 return outputCollection;
386 edm::LogVerbatim(
"TrackAssociator") <<
"Starting TrackAssociatorByHits::associateSimToReco - #seeds="
387 <<seedCollectionH->size()<<
" #TPs="<<TPCollectionH->size();
390 std::vector< SimHitIdpr> SimTrackIds;
391 std::vector< SimHitIdpr> matchedIds;
404 LogTrace(
"TrackAssociator") <<
"\nNEW SEED - seed number " << tindex <<
" # valid=" <<
seed->recHits().second-
seed->recHits().first;
405 getMatchedIds<edm::OwnVector<TrackingRecHit>::const_iterator>(matchedIds, SimTrackIds, ri,
seed->recHits().first,
seed->recHits().second, &associate );
408 std::vector<SimHitIdpr> idcachev;
409 if(!matchedIds.empty()){
411 for (TrackingParticleCollection::const_iterator
t = tPC.begin();
t != tPC.end(); ++
t, ++tpindex) {
413 int nsimhit =
t->numberOfTrackerHits();
414 LogTrace(
"TrackAssociator") <<
"TP number " << tpindex <<
" pdgId=" <<
t->pdgId() <<
" with number of PSimHits: " << nsimhit;
415 nshared = getShared(matchedIds, idcachev, *
t);
417 if (AbsoluteNumberOfHits) quality =
static_cast<double>(nshared);
418 else if(ri!=0) quality = ((double) nshared)/((double)ri);
423 if(quality > quality_SimToReco && !(ThreeHitTracksAreSpecial && ri==3 && nshared<3) ){
426 LogTrace(
"TrackAssociator") <<
"TrackingParticle number " << tpindex <<
" with #hits=" << nsimhit
427 <<
" associated to seed number " << tindex <<
" with #hits=" << ri
428 <<
" with hit quality =" <<
quality ;
431 LogTrace(
"TrackAssociator") <<
"TrackingParticle number " << tpindex <<
" with #hits=" << nsimhit <<
" NOT associated with quality =" <<
quality;
436 LogTrace(
"TrackAssociator") <<
"% of Assoc TPs=" << ((double)outputCollection.
size())/((
double)TPCollectionH->size());
438 return outputCollection;
441 template<
typename iter>
443 std::vector<SimHitIdpr>& SimTrackIds,
450 for (
iter it = begin; it !=
end; it++){
458 if(!SimTrackIds.empty()){
459 for(
size_t j=0;
j<SimTrackIds.size();
j++){
460 LogTrace(
"TrackAssociator") <<
" hit # " << ri <<
" valid=" << hit->
isValid()
461 <<
" det id = " << t_detID <<
" SimId " << SimTrackIds[
j].first
462 <<
" evt=" << SimTrackIds[
j].second.event()
463 <<
" bc=" << SimTrackIds[
j].second.bunchCrossing();
464 matchedIds.push_back(SimTrackIds[
j]);
491 std::vector<SimHitIdpr>& idcachev,
496 for(
size_t j=0;
j<matchedIds.size();
j++){
498 if(
find(idcachev.begin(), idcachev.end(),matchedIds[
j]) == idcachev.end() ){
500 idcachev.push_back(matchedIds[
j]);
510 if((*g4T).trackId() == matchedIds[
j].first && t.
eventId() == matchedIds[
j].second){
511 int countedhits =
std::count(matchedIds.begin(), matchedIds.end(), matchedIds[
j]);
512 nshared += countedhits;
524 template<
typename iter>
529 int doublecount = 0 ;
530 std::vector<SimHitIdpr> SimTrackIdsDC;
532 for (
iter it = begin; it !=
end; it++){
534 SimTrackIdsDC.clear();
537 if(SimTrackIdsDC.size()>1){
540 if(
find(SimTrackIdsDC.begin(), SimTrackIdsDC.end(),
SimHitIdpr((*g4T).trackId(), SimTrackIdsDC.begin()->second)) != SimTrackIdsDC.end() ){
545 if (idcount>1) doublecount+=(idcount-1);
T getParameter(std::string const &) const
TrackAssociatorByHits(const edm::ParameterSet &)
virtual reco::SimToRecoCollection associateSimToReco(const edm::RefToBaseVector< reco::Track > &, const edm::RefVector< TrackingParticleCollection > &, const edm::Event *event, const edm::EventSetup *setup) const override
Association Sim To Reco with Collections.
void getMatchedIds(std::vector< SimHitIdpr > &, std::vector< SimHitIdpr > &, int &, iter, iter, TrackerHitAssociator *) const
std::vector< TrackingParticle > TrackingParticleCollection
static bool simHitTPAssociationListGreater(SimHitTPPair i, SimHitTPPair j)
const_iterator end() const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
uint32_t rawId() const
get the raw id
const_iterator begin() const
void post_insert()
post insert action
uint32_t partnerDetId() const
Abs< T >::type abs(const T &t)
int getShared(std::vector< SimHitIdpr > &, std::vector< SimHitIdpr > &, TrackingParticle const &) const
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
Detector identifier class for the strip tracker.
std::pair< uint32_t, EncodedEventId > SimHitIdpr
virtual reco::RecoToSimCollection associateRecoToSim(const edm::RefToBaseVector< reco::Track > &, const edm::RefVector< TrackingParticleCollection > &, const edm::Event *event, const edm::EventSetup *setup) const override
Association Reco To Sim with Collections.
size_type size() const
map size
T const * product() const
void insert(const key_type &k, const data_type &v)
insert an association
T const * product() const
const edm::ParameterSet & conf_
int numberOfHits() const
Gives the total number of hits, including muon hits. Hits on overlaps in the same layer count separat...
int getDoubleCount(iter, iter, TrackerHitAssociator *, TrackingParticle const &) const
const_iterator begin() const
unsigned int layer(const DetId &id) const
EncodedEventId eventId() const
Signal source, crossing number.
std::vector< std::vector< double > > tmp
std::vector< SimHitIdpr > associateHitId(const TrackingRecHit &thit) const
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
edm::Ref< edm::PSimHitContainer > TrackPSimHitRef
size_type size() const
Size of the RefVector.
Monte Carlo truth information used for tracking validation.
const_iterator end() const
DetId geographicalId() const
SimToRecoDenomType SimToRecoDenominator
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")