Skip to content

Commit

Permalink
Merge pull request #16377 from smoortga/TrackHistoryFixesBackport80X
Browse files Browse the repository at this point in the history
Track history fixes backport80 x
  • Loading branch information
cmsbuild committed Dec 19, 2016
2 parents f850a0f + ec32507 commit 16fb0f2
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 37 deletions.
35 changes: 31 additions & 4 deletions SimTracker/TrackHistory/interface/HistoryBase.h
Expand Up @@ -14,8 +14,14 @@ class HistoryBase

public:

//! GenParticle trail type.
//! HepMC::GenParticle trail type.
typedef std::vector<const HepMC::GenParticle *> GenParticleTrail;

//! reco::GenParticle trail type.
typedef std::vector<const reco::GenParticle *> RecoGenParticleTrail;

//!reco::GenParticle trail helper type.
typedef std::set<const reco::GenParticle *> RecoGenParticleTrailHelper;

//! GenVertex trail type.
typedef std::vector<const HepMC::GenVertex *> GenVertexTrail;
Expand Down Expand Up @@ -67,11 +73,17 @@ class HistoryBase
return genVertexTrail_;
}

//! Return all generated particle in the history.
//! Return all generated particle (HepMC::GenParticle) in the history.
GenParticleTrail const & genParticleTrail() const
{
return genParticleTrail_;
}

//! Return all reco::GenParticle in the history.
RecoGenParticleTrail const & recoGenParticleTrail() const
{
return recoGenParticleTrail_;
}

//! Return the initial tracking particle from the history.
const TrackingParticleRef & simParticle() const
Expand All @@ -85,23 +97,32 @@ class HistoryBase
return simVertexTrail_[0];
}

//! Returns a pointer to most primitive status 1 or 2 particle.
//! Returns a pointer to most primitive status 1 or 2 particle in the genParticleTrail_.
const HepMC::GenParticle * genParticle() const
{
if ( genParticleTrail_.empty() ) return 0;
return genParticleTrail_[genParticleTrail_.size()-1];
}

//! Returns a pointer to most primitive status 1 or 2 particle in the recoGenParticleTrail_.
const reco::GenParticle * recoGenParticle() const
{
if ( recoGenParticleTrail_.empty() ) return 0;
return recoGenParticleTrail_[recoGenParticleTrail_.size()-1];
}

protected:

// History cointainers
GenVertexTrail genVertexTrail_;
GenParticleTrail genParticleTrail_;
RecoGenParticleTrail recoGenParticleTrail_;
SimVertexTrail simVertexTrail_;
SimParticleTrail simParticleTrail_;

// Helper function to speedup search
GenVertexTrailHelper genVertexTrailHelper_;
RecoGenParticleTrailHelper recoGenParticleTrailHelper_;

//! Evaluate track history using a TrackingParticleRef.
/* Return false when the history cannot be determined upto a given depth.
Expand Down Expand Up @@ -141,8 +162,12 @@ class HistoryBase
//! Trace all the simulated information for a given reference to a TrackingVertex.
bool traceSimHistory (TrackingVertexRef const &, int);

//! Trace all the simulated information for a given pointer to a GenParticle.
//! Trace all the simulated information for a given pointer to a HepMC::GenParticle.
void traceGenHistory (HepMC::GenParticle const *);

//! Trace all the simulated information for a given pointer to a reco::GenParticle.
void traceRecoGenHistory (reco::GenParticle const *);


//! Trace all the simulated information for a given pointer to a GenVertex.
void traceGenHistory (HepMC::GenVertex const *);
Expand All @@ -154,6 +179,8 @@ class HistoryBase
simVertexTrail_.clear();
genVertexTrail_.clear();
genParticleTrail_.clear();
recoGenParticleTrail_.clear();
recoGenParticleTrailHelper_.clear();
genVertexTrailHelper_.clear();
}

Expand Down
12 changes: 12 additions & 0 deletions SimTracker/TrackHistory/interface/TrackHistory.h
Expand Up @@ -63,6 +63,16 @@ class TrackHistory : public HistoryBase
{
return recotrack_;
}

// return the TrackingParticle to which the Track was matched
const std::pair<TrackingParticleRef, double> getMatchedTrackingParticle() const
{
std::pair<TrackingParticleRef, double> result;
result.first = trackingParticle_;
result.second = quality_;

return result;
}

double quality() const
{
Expand All @@ -86,6 +96,8 @@ class TrackHistory : public HistoryBase
edm::InputTag trackAssociator_;

reco::TrackBaseRef recotrack_;

TrackingParticleRef trackingParticle_;

reco::RecoToSimCollection recoToSim_;

Expand Down
33 changes: 27 additions & 6 deletions SimTracker/TrackHistory/src/HistoryBase.cc
Expand Up @@ -5,6 +5,29 @@
#include "SimTracker/TrackHistory/interface/HistoryBase.h"


void HistoryBase::traceRecoGenHistory(reco::GenParticle const * genParticle)
{
// fill the trace of reco::GenParticle for correct reading of the History flags etc.
// This is called from the TrackingParticle->genParticle_begin() which is a reco::GenParticle

// Take onlt genParticles with a status() smaller than "depth_". Typically depth is 2 and so you trace back untill you reach the hard partons
// see for status(): https://twiki.cern.ch/twiki/bin/view/CMSPublic/WorkBookGenParticleCandidate#GenPCand
if ( genParticle->status() <= abs(depth_) && (genParticle->pdgId() < 88 || genParticle->pdgId() > 99) )
{
//If the particle is already in the history, it is looping and you should stop
if ( recoGenParticleTrailHelper_.find(genParticle) != recoGenParticleTrailHelper_.end() ){
return;
}
recoGenParticleTrail_.push_back(genParticle);
recoGenParticleTrailHelper_.insert(genParticle);
// Get the genParticle's mother and trace its history
if (genParticle->mother() != 0){
traceRecoGenHistory( (const reco::GenParticle *)genParticle->mother() );
}
}
}


void HistoryBase::traceGenHistory(HepMC::GenParticle const * genParticle)
{
// Third stop criteria: status abs(depth_) particles after the hadronization.
Expand Down Expand Up @@ -46,17 +69,15 @@ bool HistoryBase::traceSimHistory(TrackingParticleRef const & trackingParticle,
{
LogDebug("TrackHistory") << "Particle " << trackingParticle->pdgId() << " has a GenParicle image."
<< std::endl;
//#warning "This file has been modified just to get it to compile without any regard as to whether it still functions as intended"
// this code does not compile likely due to the wrong type of iterator
#ifdef REMOVED_JUST_TO_GET_IT_TO_COMPILE__THIS_CODE_NEEDS_TO_BE_CHECKED
traceGenHistory(&(**(trackingParticle->genParticle_begin())));
#endif

traceRecoGenHistory(&(**(trackingParticle->genParticle_begin())));


}

LogDebug("TrackHistory") << "No GenParticle image for " << trackingParticle->pdgId() << std::endl;

// get a reference to the TP's parent vertex and trace it history
// if no association between TP and genParticles is found: get a reference to the TP's parent vertex and trace its history
return traceSimHistory( trackingParticle->parentVertex(), depth );
}

Expand Down
43 changes: 16 additions & 27 deletions SimTracker/TrackHistory/src/TrackClassifier.cc
Expand Up @@ -262,13 +262,13 @@ void TrackClassifier::qualityInformation(reco::TrackBaseRef const & track)

void TrackClassifier::hadronFlavor()
{
// Get the initial hadron
const HepMC::GenParticle * particle = tracer_.genParticle();
// Get the initial hadron from the recoGenParticleTrail
const reco::GenParticle * particle = tracer_.recoGenParticle();

// Check for the initial hadron
if (particle)
{
HepPDT::ParticleID pid(particle->pdg_id());
HepPDT::ParticleID pid(particle->pdgId());
flags_[Bottom] = pid.hasBottom();
flags_[Charm] = pid.hasCharm();
flags_[Light] = !pid.hasCharm() && !pid.hasBottom();
Expand All @@ -281,26 +281,13 @@ void TrackClassifier::processesAtGenerator()
// pdgid of the "in" particle to the production vertex
int pdgid = 0;

// Get the generated particles from track history
TrackHistory::GenParticleTrail const & genParticleTrail = tracer_.genParticleTrail();
// Get the generated particles from track history (reco::GenParticle in the recoGenParticleTrail)
TrackHistory::RecoGenParticleTrail const & recoGenParticleTrail = tracer_.recoGenParticleTrail();

// Loop over the generated particles
for (TrackHistory::GenParticleTrail::const_iterator iparticle = genParticleTrail.begin(); iparticle != genParticleTrail.end(); ++iparticle)
// Loop over the generated particles (reco::GenParticle in the recoGenParticleTrail)
for (TrackHistory::RecoGenParticleTrail::const_iterator iparticle = recoGenParticleTrail.begin(); iparticle != recoGenParticleTrail.end(); ++iparticle)
{
// Get the source vertex for the particle
HepMC::GenVertex * productionVertex = (*iparticle)->production_vertex();

// Get the pointer to the vertex by removing the const-ness (no const methos in HepMC::GenVertex)
// HepMC::GenVertex * vertex = const_cast<HepMC::GenVertex *>(*ivertex);

// Check for a non-null pointer to the production vertex
if (productionVertex)
{
// Only case track history will navegate (one in or source particle per vertex)
if ( productionVertex->particles_in_size() == 1 )
{
// Look at the pdgid of the first "in" particle to the vertex
pdgid = std::abs((*productionVertex->particles_in_const_begin())->pdg_id());
pdgid = std::abs((*iparticle)->pdgId());
// Get particle type
HepPDT::ParticleID particleID(pdgid);

Expand All @@ -319,9 +306,13 @@ void TrackClassifier::processesAtGenerator()
update(flags_[BWeakDecay], particleID.hasBottom());
update(flags_[CWeakDecay], particleID.hasCharm());
// Check for B and C pure leptonic decay
int daughterId = abs((*iparticle)->pdg_id());
update(flags_[FromBWeakDecayMuon], particleID.hasBottom() && daughterId == 13);
update(flags_[FromCWeakDecayMuon], particleID.hasCharm() && daughterId == 13);
std::set<int> daughterIds;
size_t ndau = (*iparticle)->numberOfDaughters();
for( size_t i = 0; i < ndau; ++ i ){
daughterIds.insert((*iparticle)->daughter(i)->pdgId());
}
update(flags_[FromBWeakDecayMuon], particleID.hasBottom() && (daughterIds.find(13) != daughterIds.end()));
update(flags_[FromCWeakDecayMuon], particleID.hasCharm() && (daughterIds.find(13) != daughterIds.end()));
}
// Check Tau, Ks and Lambda decay
update(flags_[ChargePionDecay], pdgid == 211);
Expand All @@ -333,9 +324,7 @@ void TrackClassifier::processesAtGenerator()
update(flags_[XiDecay], pdgid == 3312);
update(flags_[SigmaPlusDecay], pdgid == 3222);
update(flags_[SigmaMinusDecay], pdgid == 3112);
}
}
}
}
}
// Decays in flight
update(flags_[FromChargePionMuon], flags_[Muon] && flags_[ChargePionDecay]);
Expand Down
1 change: 1 addition & 0 deletions SimTracker/TrackHistory/src/TrackHistory.cc
Expand Up @@ -71,6 +71,7 @@ bool TrackHistory::evaluate ( reco::TrackBaseRef tr )

TrackingParticleRef tpr( result.first );
quality_ = result.second;
trackingParticle_ = tpr;

if ( !tpr.isNull() )
{
Expand Down
Expand Up @@ -51,6 +51,8 @@ class ClusterTPAssociation {
range equal_range(const OmniClusterRef& key) const {
return std::equal_range(map_.begin(), map_.end(), value_type(key, TrackingParticleRef()), compare);
}

const map_type& map() const { return map_; }

void checkMappedProductID(const edm::HandleBase& mappedHandle) const { checkMappedProductID(mappedHandle.id()); }
void checkMappedProductID(const TrackingParticleRef& tp) const { checkMappedProductID(tp.id()); }
Expand Down

0 comments on commit 16fb0f2

Please sign in to comment.