Skip to content

Commit

Permalink
Merge pull request #8988 from makortel/mtv_optimize
Browse files Browse the repository at this point in the history
Improve MultiTrackValidator performance
  • Loading branch information
cmsbuild committed May 11, 2015
2 parents bec6b56 + af5504b commit c17e914
Show file tree
Hide file tree
Showing 13 changed files with 438 additions and 486 deletions.
160 changes: 127 additions & 33 deletions SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h
Expand Up @@ -58,12 +58,18 @@ class TrackingParticle
*
* Returns the PDG ID of the first associated gen particle. If there are no gen particles associated
* then it returns type() from the first SimTrack. */
int pdgId() const;
int pdgId() const {
if( genParticles_.empty() ) return g4Tracks_[0].type();
else return (*genParticles_.begin())->pdgId();
}

/** @brief Signal source, crossing number.
*
* Note this is taken from the first SimTrack only, but there shouldn't be any SimTracks from different
* crossings in the TrackingParticle. */
EncodedEventId eventId() const;
EncodedEventId eventId() const {
return g4Tracks_[0].eventId();
}

// Setters for G4 and reco::GenParticle
void addGenParticle( const reco::GenParticleRef& ref);
Expand All @@ -77,54 +83,141 @@ class TrackingParticle
void addDecayVertex(const TrackingVertexRef& ref);
void clearParentVertex();
void clearDecayVertices();

// Getters for Embd and Sim Tracks
const reco::GenParticleRefVector& genParticles() const;
const std::vector<SimTrack>& g4Tracks() const;
const TrackingVertexRef& parentVertex() const;
const reco::GenParticleRefVector& genParticles() const { return genParticles_; }
const std::vector<SimTrack>& g4Tracks() const { return g4Tracks_; }
const TrackingVertexRef& parentVertex() const { return parentVertex_; }

// Accessors for vector of decay vertices
const TrackingVertexRefVector& decayVertices() const;
tv_iterator decayVertices_begin() const;
tv_iterator decayVertices_end() const;
const TrackingVertexRefVector& decayVertices() const { return decayVertices_; }
tv_iterator decayVertices_begin() const { return decayVertices_.begin(); }
tv_iterator decayVertices_end() const { return decayVertices_.end(); }


/// @brief Electric charge. Note this is taken from the first SimTrack only.
float charge() const { return g4Tracks_[0].charge(); }
/// Gives charge in unit of quark charge (should be 3 times "charge()")
int threeCharge() const { return lrintf(3.f*charge()); }

const LorentzVector& p4() const; ///< @brief Four-momentum Lorentz vector. Note this is taken from the first SimTrack only.

Vector momentum() const; ///< spatial momentum vector

Vector boostToCM() const; ///< @brief Vector to boost to the particle centre of mass frame.

double p() const; ///< @brief Magnitude of momentum vector. Note this is taken from the first SimTrack only.
double energy() const; ///< @brief Energy. Note this is taken from the first SimTrack only.
double et() const; ///< @brief Transverse energy. Note this is taken from the first SimTrack only.
double mass() const; ///< @brief Mass. Note this is taken from the first SimTrack only.
double massSqr() const; ///< @brief Mass squared. Note this is taken from the first SimTrack only.
double mt() const; ///< @brief Transverse mass. Note this is taken from the first SimTrack only.
double mtSqr() const; ///< @brief Transverse mass squared. Note this is taken from the first SimTrack only.
double px() const; ///< @brief x coordinate of momentum vector. Note this is taken from the first SimTrack only.
double py() const; ///< @brief y coordinate of momentum vector. Note this is taken from the first SimTrack only.
double pz() const; ///< @brief z coordinate of momentum vector. Note this is taken from the first SimTrack only.
double pt() const; ///< @brief Transverse momentum. Note this is taken from the first SimTrack only.
double phi() const; ///< @brief Momentum azimuthal angle. Note this is taken from the first SimTrack only.
double theta() const; ///< @brief Momentum polar angle. Note this is taken from the first SimTrack only.
double eta() const; ///< @brief Momentum pseudorapidity. Note this is taken from the first SimTrack only.
double rapidity() const; ///< @brief Rapidity. Note this is taken from the first SimTrack only.
double y() const; ///< @brief Same as rapidity().
/// @brief Four-momentum Lorentz vector. Note this is taken from the first SimTrack only.
const LorentzVector& p4() const {
return g4Tracks_[0].momentum();
}

/// @brief spatial momentum vector
Vector momentum() const {
return p4().Vect();
}

/// @brief Vector to boost to the particle centre of mass frame.
Vector boostToCM() const {
return p4().BoostToCM();
}

/// @brief Magnitude of momentum vector. Note this is taken from the first SimTrack only.
double p() const {
return p4().P();
}

/// @brief Energy. Note this is taken from the first SimTrack only.
double energy() const {
return p4().E();
}

/// @brief Transverse energy. Note this is taken from the first SimTrack only.
double et() const {
return p4().Et();
}

/// @brief Mass. Note this is taken from the first SimTrack only.
double mass() const {
return p4().M();
}

/// @brief Mass squared. Note this is taken from the first SimTrack only.
double massSqr() const {
return pow( mass(), 2 );
}

/// @brief Transverse mass. Note this is taken from the first SimTrack only.
double mt() const {
return p4().Mt();
}

/// @brief Transverse mass squared. Note this is taken from the first SimTrack only.
double mtSqr() const {
return p4().Mt2();
}

/// @brief x coordinate of momentum vector. Note this is taken from the first SimTrack only.
double px() const {
return p4().Px();
}

/// @brief y coordinate of momentum vector. Note this is taken from the first SimTrack only.
double py() const {
return p4().Py();
}

/// @brief z coordinate of momentum vector. Note this is taken from the first SimTrack only.
double pz() const {
return p4().Pz();
}

/// @brief Transverse momentum. Note this is taken from the first SimTrack only.
double pt() const {
return p4().Pt();
}

/// @brief Momentum azimuthal angle. Note this is taken from the first SimTrack only.
double phi() const {
return p4().Phi();
}

/// @brief Momentum polar angle. Note this is taken from the first SimTrack only.
double theta() const {
return p4().Theta();
}

/// @brief Momentum pseudorapidity. Note this is taken from the first SimTrack only.
double eta() const {
return p4().Eta();
}

/// @brief Rapidity. Note this is taken from the first SimTrack only.
double rapidity() const {
return p4().Rapidity();
}

/// @brief Same as rapidity().
double y() const {
return rapidity();
}

/// @brief Parent vertex position
Point vertex() const {
const TrackingVertex::LorentzVector & p = (*parentVertex_).position();
return Point(p.x(),p.y(),p.z());
}

double vx() const; ///< @brief x coordinate of parent vertex position
double vy() const; ///< @brief y coordinate of parent vertex position
double vz() const; ///< @brief z coordinate of parent vertex position
/// @brief x coordinate of parent vertex position
double vx() const {
const TrackingVertex& r=( *parentVertex_);
return r.position().X();
}

/// @brief y coordinate of parent vertex position
double vy() const {
const TrackingVertex& r=( *parentVertex_);
return r.position().Y();
}
// @brief z coordinate of parent vertex position
double vz() const {
const TrackingVertex& r=( *parentVertex_);
return r.position().Z();
}

/** @brief Status word.
*
* Returns status() from the first gen particle, or -99 if there are no gen particles attached. */
Expand All @@ -150,6 +243,7 @@ class TrackingParticle
/** @deprecated The number of hits in the tracker but taking account of overlaps.
* Deprecated in favour of the more aptly named numberOfTrackerLayers(). */
int matchedHit() const;

/** @brief The number of tracker layers with a hit.
*
* Different from numberOfTrackerHits because this method counts multiple hits on overlaps in the layer as one hit. */
Expand Down
156 changes: 0 additions & 156 deletions SimDataFormats/TrackingAnalysis/src/TrackingParticle.cc
Expand Up @@ -22,17 +22,6 @@ TrackingParticle::~TrackingParticle()
{
}

int TrackingParticle::pdgId() const
{
if( genParticles_.empty() ) return g4Tracks_[0].type();
else return (*genParticles_.begin())->pdgId();
}

EncodedEventId TrackingParticle::eventId() const
{
return g4Tracks_[0].eventId();
}

void TrackingParticle::addGenParticle( const reco::GenParticleRef& ref )
{
genParticles_.push_back( ref );
Expand Down Expand Up @@ -83,151 +72,6 @@ void TrackingParticle::clearDecayVertices()
decayVertices_.clear();
}

const reco::GenParticleRefVector& TrackingParticle::genParticles() const
{
return genParticles_;
}

const std::vector<SimTrack>& TrackingParticle::g4Tracks() const
{
return g4Tracks_;
}

const TrackingVertexRef& TrackingParticle::parentVertex() const
{
return parentVertex_;
}

const TrackingVertexRefVector& TrackingParticle::decayVertices() const
{
return decayVertices_;
}

tv_iterator TrackingParticle::decayVertices_begin() const
{
return decayVertices_.begin();
}

tv_iterator TrackingParticle::decayVertices_end() const
{
return decayVertices_.end();
}


const TrackingParticle::LorentzVector& TrackingParticle::p4() const
{
return g4Tracks_[0].momentum();
}

TrackingParticle::Vector TrackingParticle::momentum() const
{
return p4().Vect();
}

TrackingParticle::Vector TrackingParticle::boostToCM() const
{
return p4().BoostToCM();
}

double TrackingParticle::p() const
{
return p4().P();
}

double TrackingParticle::energy() const
{
return p4().E();
}

double TrackingParticle::et() const
{
return p4().Et();
}

double TrackingParticle::mass() const
{
return p4().M();
}

double TrackingParticle::massSqr() const
{
return pow( mass(), 2 );
}

double TrackingParticle::mt() const
{
return p4().Mt();
}

double TrackingParticle::mtSqr() const
{
return p4().Mt2();
}

double TrackingParticle::px() const
{
return p4().Px();
}

double TrackingParticle::py() const
{
return p4().Py();
}

double TrackingParticle::pz() const
{
return p4().Pz();
}

double TrackingParticle::pt() const
{
return p4().Pt();
}

double TrackingParticle::phi() const
{
return p4().Phi();
}

double TrackingParticle::theta() const
{
return p4().Theta();
}

double TrackingParticle::eta() const
{
return p4().Eta();
}

double TrackingParticle::rapidity() const
{
return p4().Rapidity();
}

double TrackingParticle::y() const
{
return rapidity();
}

double TrackingParticle::vx() const
{
const TrackingVertex& r=( *parentVertex_);
return r.position().X();
}

double TrackingParticle::vy() const
{
const TrackingVertex& r=( *parentVertex_);
return r.position().Y();
}

double TrackingParticle::vz() const
{
const TrackingVertex& r=( *parentVertex_);
return r.position().Z();
}


int TrackingParticle::matchedHit() const
{
edm::LogWarning("TrackingParticle") << "The method matchedHit() has been deprecated. Use numberOfTrackerLayers() instead.";
Expand Down

0 comments on commit c17e914

Please sign in to comment.