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;
96 getMatchedIds<trackingRecHit_iterator>(matchedIds, SimTrackIds, ri, (*track)->recHitsBegin(), (*track)->recHitsEnd(), associate);
106 std::vector<SimHitIdpr> idcachev;
107 if(!matchedIds.empty()){
110 for (TrackingParticleCollection::const_iterator
t = tPC.begin();
t != tPC.end(); ++
t, ++tpindex) {
114 nshared = getShared(matchedIds, idcachev,
t);
117 if (
abs(
t->pdgId())==11&&(
t->g4Track_end()-
t->g4Track_begin())>1){
118 nshared-=getDoubleCount<trackingRecHit_iterator>((*track)->recHitsBegin(), (*track)->recHitsEnd(), associate,
t);
121 if (AbsoluteNumberOfHits) quality =
static_cast<double>(nshared);
122 else if(ri!=0) quality = (
static_cast<double>(nshared)/static_cast<double>(ri));
126 if(quality > cut_RecoToSim && !(ThreeHitTracksAreSpecial && ri==3 && nshared<3)){
128 outputCollection.
insert(tC[tindex],
146 return outputCollection;
162 std::vector< SimHitIdpr> SimTrackIds;
163 std::vector< SimHitIdpr> matchedIds;
180 e->
getByLabel(_simHitTpMapTag,simHitsTPAssoc);
187 getMatchedIds<trackingRecHit_iterator>(matchedIds, SimTrackIds, ri, (*track)->recHitsBegin(), (*track)->recHitsEnd(), associate);
190 std::vector<SimHitIdpr> idcachev;
191 if(!matchedIds.empty()){
194 for (TrackingParticleCollection::const_iterator
t = tPC.begin();
t != tPC.end(); ++
t, ++tpindex) {
200 std::vector<PSimHit> tphits;
203 nshared = getShared(matchedIds, idcachev,
t);
217 std::pair<TrackingParticleRef, TrackPSimHitRef>
220 auto range = std::equal_range(simHitsTPAssoc->begin(), simHitsTPAssoc->end(),
222 for(
auto ip = range.first; ip != range.second; ++ip) {
226 unsigned int subdetId =
static_cast<unsigned int>(dId.
subdetId());
239 for(std::vector<PSimHit>::const_iterator TPhitOK = tphits.begin(); TPhitOK != tphits.end(); TPhitOK++){
246 if (!UseGrouped && !UseSplitting)
250 if (!UseGrouped && UseSplitting)
256 if (UseGrouped && !UseSplitting)
262 if (UseGrouped && UseSplitting)
267 tphits.push_back(*TPhit);
272 totsimhit = tphits.size();
275 if (AbsoluteNumberOfHits) quality =
static_cast<double>(nshared);
276 else if(SimToRecoDenominator == denomsim && totsimhit!=0) quality = ((double) nshared)/((double)totsimhit);
277 else if(SimToRecoDenominator == denomreco && ri!=0) quality = ((double) nshared)/((double)ri);
282 float purity = 1.0*nshared/ri;
283 if (quality>quality_SimToReco && !(ThreeHitTracksAreSpecial && totsimhit==3 && nshared<3) && (AbsoluteNumberOfHits||(purity>purity_SimToReco))) {
286 std::make_pair(tC[tindex],quality));
302 return outputCollection;
312 edm::LogVerbatim(
"TrackAssociator") <<
"Starting TrackAssociatorByHits::associateRecoToSim - #seeds="
313 <<seedCollectionH->size()<<
" #TPs="<<TPCollectionH->size();
316 std::vector< SimHitIdpr> SimTrackIds;
317 std::vector< SimHitIdpr> matchedIds;
331 int nsimhit =
seed->recHits().second-
seed->recHits().first;
332 LogTrace(
"TrackAssociator") <<
"\nNEW SEED - seed number " << tindex <<
" # valid=" << nsimhit;
333 getMatchedIds<edm::OwnVector<TrackingRecHit>::const_iterator>(matchedIds, SimTrackIds, ri,
seed->recHits().first,
seed->recHits().second, associate );
336 std::vector<SimHitIdpr> idcachev;
337 if(!matchedIds.empty()){
340 for (TrackingParticleCollection::const_iterator
t = tPC.begin();
t != tPC.end(); ++
t, ++tpindex) {
341 LogTrace(
"TrackAssociator") <<
"TP number " << tpindex <<
" pdgId=" <<
t->pdgId() <<
" with number of PSimHits: " << nsimhit;
343 nshared = getShared(matchedIds, idcachev,
t);
346 if (
abs(
t->pdgId())==11&&(
t->g4Track_end()-
t->g4Track_begin())>1){
347 nshared-=getDoubleCount<edm::OwnVector<TrackingRecHit>::const_iterator>(
seed->recHits().first,
seed->recHits().second, associate,
t);
350 if (AbsoluteNumberOfHits) quality =
static_cast<double>(nshared);
351 else if(ri!=0) quality = (
static_cast<double>(nshared)/static_cast<double>(ri));
354 if(quality > cut_RecoToSim && !(ThreeHitTracksAreSpecial && ri==3 && nshared<3) ){
358 LogTrace(
"TrackAssociator") <<
"Seed number " << tindex <<
" with #hits=" << ri
359 <<
"associated to TP (pdgId, nb segments, p) = "
360 << (*t).pdgId() <<
" " << (*t).g4Tracks().size()
361 <<
" " << (*t).momentum() <<
" number " << tpindex <<
" with quality =" << quality;
363 LogTrace(
"TrackAssociator") <<
"Seed number " << tindex <<
" with #hits=" << ri <<
" NOT associated with quality =" << quality;
368 LogTrace(
"TrackAssociator") <<
"% of Assoc Seeds=" << ((double)outputCollection.
size())/((
double)seedCollectionH->size());
371 return outputCollection;
381 edm::LogVerbatim(
"TrackAssociator") <<
"Starting TrackAssociatorByHits::associateSimToReco - #seeds="
382 <<seedCollectionH->size()<<
" #TPs="<<TPCollectionH->size();
385 std::vector< SimHitIdpr> SimTrackIds;
386 std::vector< SimHitIdpr> matchedIds;
399 LogTrace(
"TrackAssociator") <<
"\nNEW SEED - seed number " << tindex <<
" # valid=" <<
seed->recHits().second-
seed->recHits().first;
400 getMatchedIds<edm::OwnVector<TrackingRecHit>::const_iterator>(matchedIds, SimTrackIds, ri,
seed->recHits().first,
seed->recHits().second, associate );
403 std::vector<SimHitIdpr> idcachev;
404 if(!matchedIds.empty()){
406 for (TrackingParticleCollection::const_iterator
t = tPC.begin();
t != tPC.end(); ++
t, ++tpindex) {
408 int nsimhit =
t->numberOfTrackerHits();
409 LogTrace(
"TrackAssociator") <<
"TP number " << tpindex <<
" pdgId=" <<
t->pdgId() <<
" with number of PSimHits: " << nsimhit;
410 nshared = getShared(matchedIds, idcachev,
t);
412 if (AbsoluteNumberOfHits) quality =
static_cast<double>(nshared);
413 else if(ri!=0) quality = ((double) nshared)/((double)ri);
418 if(quality > quality_SimToReco && !(ThreeHitTracksAreSpecial && ri==3 && nshared<3) ){
421 LogTrace(
"TrackAssociator") <<
"TrackingParticle number " << tpindex <<
" with #hits=" << nsimhit
422 <<
" associated to seed number " << tindex <<
" with #hits=" << ri
423 <<
" with hit quality =" << quality ;
426 LogTrace(
"TrackAssociator") <<
"TrackingParticle number " << tpindex <<
" with #hits=" << nsimhit <<
" NOT associated with quality =" << quality;
431 LogTrace(
"TrackAssociator") <<
"% of Assoc TPs=" << ((double)outputCollection.
size())/((
double)TPCollectionH->size());
434 return outputCollection;
437 template<
typename iter>
439 std::vector<SimHitIdpr>& SimTrackIds,
446 for (
iter it = begin; it !=
end; it++){
454 if(!SimTrackIds.empty()){
455 for(
size_t j=0;
j<SimTrackIds.size();
j++){
456 LogTrace(
"TrackAssociator") <<
" hit # " << ri <<
" valid=" << hit->
isValid()
457 <<
" det id = " << t_detID <<
" SimId " << SimTrackIds[
j].first
458 <<
" evt=" << SimTrackIds[
j].second.event()
459 <<
" bc=" << SimTrackIds[
j].second.bunchCrossing();
460 matchedIds.push_back(SimTrackIds[
j]);
487 std::vector<SimHitIdpr>& idcachev,
488 TrackingParticleCollection::const_iterator
t)
const {
490 if (t->numberOfHits()==0)
return nshared;
492 for(
size_t j=0;
j<matchedIds.size();
j++){
494 if(
find(idcachev.begin(), idcachev.end(),matchedIds[
j]) == idcachev.end() ){
496 idcachev.push_back(matchedIds[
j]);
506 if((*g4T).trackId() == matchedIds[
j].first && t->eventId() == matchedIds[
j].second){
507 int countedhits =
std::count(matchedIds.begin(), matchedIds.end(), matchedIds[
j]);
508 nshared += countedhits;
520 template<
typename iter>
524 TrackingParticleCollection::const_iterator
t)
const {
525 int doublecount = 0 ;
526 std::vector<SimHitIdpr> SimTrackIdsDC;
528 for (
iter it = begin; it !=
end; it++){
530 SimTrackIdsDC.clear();
533 if(SimTrackIdsDC.size()>1){
536 if(
find(SimTrackIdsDC.begin(), SimTrackIdsDC.end(),
SimHitIdpr((*g4T).trackId(), SimTrackIdsDC.begin()->second)) != SimTrackIdsDC.end() ){
541 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
C const * product() const
Accessor for product collection.
static bool simHitTPAssociationListGreater(SimHitTPPair i, SimHitTPPair j)
int getShared(std::vector< SimHitIdpr > &, std::vector< SimHitIdpr > &, TrackingParticleCollection::const_iterator) const
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 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 getDoubleCount(iter, iter, TrackerHitAssociator *, TrackingParticleCollection::const_iterator) const
const_iterator begin() const
unsigned int layer(const DetId &id) const
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.
const_iterator end() const
DetId geographicalId() const
SimToRecoDenomType SimToRecoDenominator
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
edm::Ref< TrackingParticleCollection > TrackingParticleRef