40 AbsoluteNumberOfHits(conf_.getParameter<bool>(
"AbsoluteNumberOfHits")),
41 SimToRecoDenominator(denomnone),
42 quality_SimToReco(conf_.getParameter<double>(
"Quality_SimToReco")),
43 purity_SimToReco(conf_.getParameter<double>(
"Purity_SimToReco")),
44 cut_RecoToSim(conf_.getParameter<double>(
"Cut_RecoToSim")),
45 UsePixels(conf_.getParameter<bool>(
"UsePixels")),
46 UseGrouped(conf_.getParameter<bool>(
"UseGrouped")),
47 UseSplitting(conf_.getParameter<bool>(
"UseSplitting")),
48 ThreeHitTracksAreSpecial(conf_.getParameter<bool>(
"ThreeHitTracksAreSpecial"))
53 }
else if (tmp ==
"reco") {
58 throw cms::Exception(
"TrackAssociatorByHits") <<
"SimToRecoDenominator not specified as sim or reco";
83 std::vector< SimHitIdpr> SimTrackIds;
84 std::vector< SimHitIdpr> matchedIds;
90 if (TPCollectionH.
size()!=0) tPC = *const_cast<TrackingParticleCollection*>(TPCollectionH.
product());
98 getMatchedIds<trackingRecHit_iterator>(matchedIds, SimTrackIds, ri, (*track)->recHitsBegin(), (*track)->recHitsEnd(), associate);
108 std::vector<SimHitIdpr> idcachev;
109 if(!matchedIds.empty()){
112 for (TrackingParticleCollection::iterator
t = tPC.begin();
t != tPC.end(); ++
t, ++tpindex) {
119 if (
abs(
t->pdgId())==11&&(
t->g4Track_end()-
t->g4Track_begin())>1){
120 nshared-=getDoubleCount<trackingRecHit_iterator>((*track)->recHitsBegin(), (*track)->recHitsEnd(), associate,
t);
124 else if(ri!=0) quality = (
static_cast<double>(nshared)/static_cast<double>(ri));
130 outputCollection.
insert(tC[tindex],
148 return outputCollection;
160 std::vector< SimHitIdpr> SimTrackIds;
161 std::vector< SimHitIdpr> matchedIds;
167 if (TPCollectionH.
size()!=0) tPC = *const_cast<TrackingParticleCollection*>(TPCollectionH.
product());
181 getMatchedIds<trackingRecHit_iterator>(matchedIds, SimTrackIds, ri, (*track)->recHitsBegin(), (*track)->recHitsEnd(), associate);
184 std::vector<SimHitIdpr> idcachev;
185 if(!matchedIds.empty()){
188 for (TrackingParticleCollection::iterator
t = tPC.begin();
t != tPC.end(); ++
t, ++tpindex) {
190 std::vector<PSimHit> trackerPSimHit(
t->trackPSimHit(
DetId::Tracker) );
193 std::vector<PSimHit> tphits;
209 for(std::vector<PSimHit>::const_iterator TPhit = trackerPSimHit.begin(); TPhit != trackerPSimHit.end(); TPhit++){
212 unsigned int subdetId =
static_cast<unsigned int>(dId.
subdetId());
225 for(std::vector<PSimHit>::const_iterator TPhitOK = tphits.begin(); TPhitOK != tphits.end(); TPhitOK++){
253 tphits.push_back(*TPhit);
258 totsimhit = tphits.size();
268 float purity = 1.0*nshared/ri;
272 std::make_pair(tC[tindex],quality));
288 return outputCollection;
294 unsigned int subdetId =
static_cast<unsigned int>(detId.
subdetId());
298 layerNumber = tibid.
layer();
303 layerNumber = tobid.
layer();
308 layerNumber = tidid.
wheel();
313 layerNumber = tecid.
wheel();
318 layerNumber = pxbid.
layer();
323 layerNumber = pxfid.
disk();
326 LogTrace(
"TrackAssociator") <<
"Unknown subdetid: " << subdetId;
337 edm::LogVerbatim(
"TrackAssociator") <<
"Starting TrackAssociatorByHits::associateRecoToSim - #seeds="
338 <<seedCollectionH->size()<<
" #TPs="<<TPCollectionH->size();
341 std::vector< SimHitIdpr> SimTrackIds;
342 std::vector< SimHitIdpr> matchedIds;
356 int nsimhit = seed->recHits().second-seed->recHits().first;
357 LogTrace(
"TrackAssociator") <<
"\nNEW SEED - seed number " << tindex <<
" # valid=" << nsimhit;
358 getMatchedIds<edm::OwnVector<TrackingRecHit>::const_iterator>(matchedIds, SimTrackIds, ri, seed->recHits().first, seed->recHits().second, associate );
361 std::vector<SimHitIdpr> idcachev;
362 if(!matchedIds.empty()){
365 for (TrackingParticleCollection::const_iterator
t = tPC.begin();
t != tPC.end(); ++
t, ++tpindex) {
366 LogTrace(
"TrackAssociator") <<
"TP number " << tpindex <<
" pdgId=" <<
t->pdgId() <<
" with number of PSimHits: " << nsimhit;
371 if (
abs(
t->pdgId())==11&&(
t->g4Track_end()-
t->g4Track_begin())>1){
372 nshared-=getDoubleCount<edm::OwnVector<TrackingRecHit>::const_iterator>(seed->recHits().first, seed->recHits().second, associate,
t);
376 else if(ri!=0) quality = (
static_cast<double>(nshared)/static_cast<double>(ri));
383 LogTrace(
"TrackAssociator") <<
"Seed number " << tindex <<
" with #hits=" << ri
384 <<
"associated to TP (pdgId, nb segments, p) = "
385 << (*t).pdgId() <<
" " << (*t).g4Tracks().size()
386 <<
" " << (*t).momentum() <<
" number " << tpindex <<
" with quality =" << quality;
388 LogTrace(
"TrackAssociator") <<
"Seed number " << tindex <<
" with #hits=" << ri <<
" NOT associated with quality =" << quality;
393 LogTrace(
"TrackAssociator") <<
"% of Assoc Seeds=" << ((double)outputCollection.
size())/((
double)seedCollectionH->size());
396 return outputCollection;
406 edm::LogVerbatim(
"TrackAssociator") <<
"Starting TrackAssociatorByHits::associateSimToReco - #seeds="
407 <<seedCollectionH->size()<<
" #TPs="<<TPCollectionH->size();
410 std::vector< SimHitIdpr> SimTrackIds;
411 std::vector< SimHitIdpr> matchedIds;
424 LogTrace(
"TrackAssociator") <<
"\nNEW SEED - seed number " << tindex <<
" # valid=" << seed->recHits().second-seed->recHits().first;
425 getMatchedIds<edm::OwnVector<TrackingRecHit>::const_iterator>(matchedIds, SimTrackIds, ri, seed->recHits().first, seed->recHits().second, associate );
428 std::vector<SimHitIdpr> idcachev;
429 if(!matchedIds.empty()){
431 for (TrackingParticleCollection::iterator
t = tPC.begin();
t != tPC.end(); ++
t, ++tpindex) {
434 LogTrace(
"TrackAssociator") <<
"TP number " << tpindex <<
" pdgId=" <<
t->pdgId() <<
" with number of PSimHits: " << nsimhit;
438 else if(ri!=0) quality = ((double) nshared)/((double)ri);
446 LogTrace(
"TrackAssociator") <<
"TrackingParticle number " << tpindex <<
" with #hits=" << nsimhit
447 <<
" associated to seed number " << tindex <<
" with #hits=" << ri
448 <<
" with hit quality =" << quality ;
451 LogTrace(
"TrackAssociator") <<
"TrackingParticle number " << tpindex <<
" with #hits=" << nsimhit <<
" NOT associated with quality =" << quality;
456 LogTrace(
"TrackAssociator") <<
"% of Assoc TPs=" << ((double)outputCollection.
size())/((
double)TPCollectionH->size());
459 return outputCollection;
462 template<
typename iter>
464 std::vector<SimHitIdpr>& SimTrackIds,
471 for (iter it = begin; it !=
end; it++){
479 if(!SimTrackIds.empty()){
480 for(
size_t j=0;
j<SimTrackIds.size();
j++){
481 LogTrace(
"TrackAssociator") <<
" hit # " << ri <<
" valid=" << hit->
isValid()
482 <<
" det id = " << t_detID <<
" SimId " << SimTrackIds[
j].first
483 <<
" evt=" << SimTrackIds[
j].second.event()
484 <<
" bc=" << SimTrackIds[
j].second.bunchCrossing();
485 matchedIds.push_back(SimTrackIds[
j]);
512 std::vector<SimHitIdpr>& idcachev,
513 TrackingParticleCollection::const_iterator
t)
const {
515 if (t->trackPSimHit().size()==0)
return nshared;
517 for(
size_t j=0;
j<matchedIds.size();
j++){
519 if(
find(idcachev.begin(), idcachev.end(),matchedIds[
j]) == idcachev.end() ){
521 idcachev.push_back(matchedIds[
j]);
531 if((*g4T).trackId() == matchedIds[
j].first && t->eventId() == matchedIds[
j].second){
532 int countedhits =
std::count(matchedIds.begin(), matchedIds.end(), matchedIds[
j]);
533 nshared += countedhits;
545 template<
typename iter>
549 TrackingParticleCollection::const_iterator
t)
const {
550 int doublecount = 0 ;
551 std::vector<SimHitIdpr> SimTrackIdsDC;
553 for (iter it = begin; it !=
end; it++){
555 SimTrackIdsDC.clear();
558 if(SimTrackIdsDC.size()>1){
561 if(
find(SimTrackIdsDC.begin(), SimTrackIdsDC.end(),
SimHitIdpr((*g4T).trackId(), SimTrackIdsDC.begin()->second)) != SimTrackIdsDC.end() ){
566 if (idcount>1) doublecount+=(idcount-1);
T getParameter(std::string const &) const
const double cut_RecoToSim
TrackAssociatorByHits(const edm::ParameterSet &)
void getMatchedIds(std::vector< SimHitIdpr > &, std::vector< SimHitIdpr > &, int &, iter, iter, TrackerHitAssociator *) const
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
unsigned int layer() const
layer id
const double purity_SimToReco
std::vector< TrackingParticle > TrackingParticleCollection
C const * product() const
Accessor for product collection.
int getShared(std::vector< SimHitIdpr > &, std::vector< SimHitIdpr > &, TrackingParticleCollection::const_iterator) const
unsigned int layerNumber(align::ID)
Layer number increases with rho from 1 to 8.
const_iterator end() const
int LayerFromDetid(const DetId &) const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
std::vector< SimHitIdpr > associateHitId(const TrackingRecHit &thit)
unsigned int layer() const
layer id
uint32_t rawId() const
get the raw id
const TrackingRecHit * getHitPtr(edm::OwnVector< TrackingRecHit >::const_iterator iter) const
const double quality_SimToReco
void post_insert()
post insert action
uint32_t partnerDetId() const
int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
unsigned int disk() const
disk id
std::vector< SimTrack >::const_iterator g4t_iterator
Detector identifier class for the strip tracker.
reco::SimToRecoCollection associateSimToReco(const edm::RefToBaseVector< reco::Track > &, const edm::RefVector< TrackingParticleCollection > &, const edm::Event *event=0, const edm::EventSetup *setup=0) const
Association Sim To Reco with Collections.
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
const bool AbsoluteNumberOfHits
const edm::ParameterSet & conf_
int getDoubleCount(iter, iter, TrackerHitAssociator *, TrackingParticleCollection::const_iterator) const
T const * product() const
unsigned int wheel() const
wheel id
const_iterator begin() const
unsigned int layer() const
layer id
std::vector< std::vector< double > > tmp
const bool ThreeHitTracksAreSpecial
size_type size() const
Size of the RefVector.
reco::RecoToSimCollection associateRecoToSim(const edm::RefToBaseVector< reco::Track > &, const edm::RefVector< TrackingParticleCollection > &, const edm::Event *event=0, const edm::EventSetup *setup=0) const
Association Reco To Sim with Collections.
const_iterator begin() const
const_iterator end() const
DetId geographicalId() const
SimToRecoDenomType SimToRecoDenominator
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
unsigned int wheel() const
wheel id