|
[Rivet-svn] r2044 - in trunk: . include/Rivet srcblackhole at projects.hepforge.org blackhole at projects.hepforge.orgMon Nov 9 01:44:55 GMT 2009
Author: buckley Date: Mon Nov 9 01:44:54 2009 New Revision: 2044 Log: Jet caching (and ParticleBase API) lightly overhauled Modified: trunk/ChangeLog trunk/include/Rivet/Jet.hh trunk/include/Rivet/ParticleBase.hh trunk/src/Jet.cc Modified: trunk/ChangeLog ============================================================================== --- trunk/ChangeLog Sun Nov 8 16:39:33 2009 (r2043) +++ trunk/ChangeLog Mon Nov 9 01:44:54 2009 (r2044) @@ -1,3 +1,10 @@ +2009-11-09 Andy Buckley <andy at insectnation.org> + + * Overhaul of jet caching and ParticleBase interface. + + * Adding lists of analyses' histograms (obtained by scanning the + plot info files) to the LaTeX documentation. + 2009-11-07 Andy Buckley <andy at insectnation.org> * Adding checking system to ensure that Projections aren't Modified: trunk/include/Rivet/Jet.hh ============================================================================== --- trunk/include/Rivet/Jet.hh Sun Nov 8 16:39:33 2009 (r2043) +++ trunk/include/Rivet/Jet.hh Mon Nov 9 01:44:54 2009 (r2044) @@ -67,10 +67,10 @@ } /// Set the particles/tracks collection. - Jet& setParticles(vector<FourMomentum> particles); + Jet& setParticles(const vector<FourMomentum>& particles); /// Add a particle/track to this jet. - Jet& addParticle(FourMomentum particle); + Jet& addParticle(const FourMomentum& particle); /// Add a particle/track to this jet. Jet& addParticle(const Particle& particle); @@ -82,7 +82,7 @@ bool containsParticleId(PdgId pid) const; /// Check whether this jet contains at least one of certain particle types. - bool containsParticleId(vector<PdgId> pids) const; + bool containsParticleId(const vector<PdgId>& pids) const; /// Check whether this jet contains a charm-flavoured hadron. bool containsCharm() const; @@ -110,8 +110,8 @@ /// Get equivalent single momentum four-vector. (caches) const FourMomentum& momentum() const; - /// Get equivalent single momentum four-vector. (caches) - FourMomentum& momentum(); + // /// Get equivalent single momentum four-vector. (caches) + // FourMomentum& momentum(); @@ -135,23 +135,20 @@ private: - /// Clear the internal cached values. + /// @brief Clear the internal cached values. + /// Const because cache variables are mutable. void _resetCaches() const; - // Calculate cached equivalent momentum vector + /// @brief Calculate cached equivalent momentum vector. + /// Const because cache variables are mutable. void _calcMomVector() const; /// Internal caching method to calculate the average \f$ \eta \f$ and \f$ /// \phi \f$ for this jet, weighted by the \f$ p_T \f$ values of the /// constituent tracks. - /// @todo Review if these caches are needed/consistent: just the vector, maybe? + /// Const because cache variables are mutable. void _calcPtAvgs() const; - /// Internal caching method to calculate the unweighted average \f$ \eta - /// \f$ and \f$ \phi \f$ for this jet. - /// @todo Review if these caches are needed/consistent: just the vector, maybe? - void _calcAvgs() const; - private: @@ -160,31 +157,12 @@ /// Full particle information including tracks, ID etc ParticleVector _fullParticles; - - /// Cached values of \f$ \bar{\phi} \f$ and \f$ \bar{\eta} \f$. - /// @todo Review if these caches are needed/consistent: just the vector, maybe? - mutable double _phi, _eta; - /// @todo Review if these caches are needed/consistent: just the vector, maybe? - mutable bool _okPhi, _okEta; /// Cached values of the \f$ p_T \f$-weighted \f$ \bar{\phi} \f$ and \f$ \bar{\eta} \f$. - /// @todo Review if these caches are needed/consistent: just the vector, maybe? mutable double _ptWeightedPhi, _ptWeightedEta; - /// @todo Review if these caches are needed/consistent: just the vector, maybe? mutable bool _okPtWeightedPhi, _okPtWeightedEta; - /// Cached value of the \f$ p_T \f$ sum. - /// @todo Review if these caches are needed/consistent: just the vector, maybe? - mutable double _totalPt; - /// @todo Review if these caches are needed/consistent: just the vector, maybe? - mutable bool _okTotalPt; - - /// Cached value of the \f$ E_T \f$ sum. - /// @todo Review if these caches are needed/consistent: just the vector, maybe? - mutable double _totalEt; - /// @todo Review if these caches are needed/consistent: just the vector, maybe? - mutable bool _okTotalEt; - + /// Cached effective jet 4-vector mutable FourMomentum _momentum; mutable bool _okMomentum; @@ -277,6 +255,7 @@ //@} + } #endif Modified: trunk/include/Rivet/ParticleBase.hh ============================================================================== --- trunk/include/Rivet/ParticleBase.hh Sun Nov 8 16:39:33 2009 (r2043) +++ trunk/include/Rivet/ParticleBase.hh Mon Nov 9 01:44:54 2009 (r2044) @@ -1,113 +1,105 @@ -/* - * ParticleBase.hh - * Rivet - * - * Created by James Monk on 04/08/2008. - * - */ - #ifndef RIVET_ParticleBase_HH #define RIVET_ParticleBase_HH #include "Rivet/Rivet.hh" #include "Rivet/Math/Vectors.hh" -namespace Rivet{ +namespace Rivet { - class ParticleBase{ + class ParticleBase { public: - ParticleBase(){ - }; + ParticleBase() { } - virtual ~ParticleBase(){}; + virtual ~ParticleBase() { } - virtual FourMomentum &momentum()=0;//{return _momentum;}; + // virtual FourMomentum& momentum() = 0; - virtual const FourMomentum &momentum() const =0;//{return _momentum;}; + virtual const FourMomentum& momentum() const = 0; - /// struct for sorting by increasing transverse momentum in stl set, sort etc. - struct byPTAscending{ - bool operator()(const ParticleBase &left, const ParticleBase &right) const{ + /// Struct for sorting by increasing transverse momentum in STL set, sort, etc. + struct byPTAscending { + bool operator()(const ParticleBase& left, const ParticleBase& right) const { double pt2left = left.momentum().pT2(); double pt2right = right.momentum().pT2(); return pt2left < pt2right; } - bool operator()(const ParticleBase *left, const ParticleBase *right) const{ + bool operator()(const ParticleBase* left, const ParticleBase* right) const { return (*this)(*left, *right); } }; - /// struct for sorting by decreasing transverse momentum in stl set, sort etc. - struct byPTDescending{ - bool operator()(const ParticleBase &left, const ParticleBase &right) const{ + /// Struct for sorting by decreasing transverse momentum in STL set, sort etc. + struct byPTDescending { + bool operator()(const ParticleBase& left, const ParticleBase& right) const { return byPTAscending()(right, left); } - bool operator()(const ParticleBase *left, const ParticleBase *right) const{ + bool operator()(const ParticleBase* left, const ParticleBase* right) const { return (*this)(*left, *right); } }; - /// struct for sorting by increasing transverse energy - struct byETAscending{ - bool operator()(const ParticleBase &left, const ParticleBase &right) const{ + /// Struct for sorting by increasing transverse energy + struct byETAscending { + bool operator()(const ParticleBase& left, const ParticleBase& right) const { double pt2left = left.momentum().Et2(); double pt2right = right.momentum().Et2(); return pt2left < pt2right; } - bool operator()(const ParticleBase *left, const ParticleBase *right) const{ + bool operator()(const ParticleBase* left, const ParticleBase* right) const { return (*this)(*left, *right); } }; - /// struct for sorting by decreasing transverse energy - struct byETDescending{ - bool operator()(const ParticleBase &left, const ParticleBase &right) const{ + /// Struct for sorting by decreasing transverse energy + struct byETDescending { + bool operator()(const ParticleBase& left, const ParticleBase& right) const { return byETAscending()(right, left); } - bool operator()(const ParticleBase *left, const ParticleBase *right) const{ + bool operator()(const ParticleBase* left, const ParticleBase* right) const { return (*this)(*left, *right); } }; - /// struct for sorting by increaing energy - struct byEAscending{ - bool operator()(const ParticleBase &left, const ParticleBase &right) const{ + /// Struct for sorting by increasing energy + struct byEAscending { + bool operator()(const ParticleBase& left, const ParticleBase& right) const { double pt2left = left.momentum().E(); double pt2right = right.momentum().E(); return pt2left < pt2right; } - bool operator()(const ParticleBase *left, const ParticleBase *right) const{ + bool operator()(const ParticleBase* left, const ParticleBase* right) const { return (*this)(*left, *right); } }; - /// struct for sorting by decreasing energy - struct byEDescending{ - bool operator()(const ParticleBase &left, const ParticleBase &right) const{ + /// Struct for sorting by decreasing energy + struct byEDescending { + bool operator()(const ParticleBase& left, const ParticleBase& right) const { return byEAscending()(right, left); } - bool operator()(const ParticleBase *left, const ParticleBase *right) const{ + bool operator()(const ParticleBase* left, const ParticleBase* right) const { return (*this)(*left, *right); } }; - protected: }; + + } #endif Modified: trunk/src/Jet.cc ============================================================================== --- trunk/src/Jet.cc Sun Nov 8 16:39:33 2009 (r2043) +++ trunk/src/Jet.cc Mon Nov 9 01:44:54 2009 (r2044) @@ -13,14 +13,14 @@ } - Jet& Jet::setParticles(vector<FourMomentum> particles) { + Jet& Jet::setParticles(const vector<FourMomentum>& particles) { _particles = particles; _resetCaches(); return *this; } - Jet& Jet::addParticle(FourMomentum particle) { + Jet& Jet::addParticle(const FourMomentum& particle) { _particles.push_back(particle); _resetCaches(); return *this; @@ -52,7 +52,7 @@ } - bool Jet::containsParticleId(vector<PdgId> pids) const { + bool Jet::containsParticleId(const vector<PdgId>& pids) const { foreach (const Particle& p, particles()) { foreach (PdgId pid, pids) { if (p.pdgId() == pid) return true; @@ -96,7 +96,7 @@ bool Jet::containsCharm() const { foreach (const Particle& p, particles()) { - if (abs(p.pdgId())==CQUARK) return true; + if (abs(p.pdgId()) == CQUARK) return true; HepMC::GenVertex* gv = p.genParticle().production_vertex(); if (gv) { foreach (const GenParticle* pi, Rivet::particles(gv, HepMC::ancestors)) { @@ -111,7 +111,7 @@ bool Jet::containsBottom() const { foreach (const Particle& p, particles()) { - if (abs(p.pdgId())==BQUARK) return true; + if (abs(p.pdgId()) == BQUARK) return true; HepMC::GenVertex* gv = p.genParticle().production_vertex(); if (gv) { foreach (const GenParticle* pi, Rivet::particles(gv, HepMC::ancestors)) { @@ -147,16 +147,13 @@ double Jet::eta() const { - _calcAvgs(); - assert(_okEta); - return _eta; + return momentum().eta(); + } double Jet::phi() const { - _calcAvgs(); - assert(_okPhi); - return _phi; + return momentum().phi(); } @@ -166,46 +163,25 @@ } - FourMomentum& Jet::momentum() { - _calcMomVector(); - return _momentum; - } + // FourMomentum& Jet::momentum() { + // _calcMomVector(); + // return _momentum; + // } double Jet::ptSum() const { - if (!_okTotalPt) { - double ptsum(0.0); - for (const_iterator p = this->begin(); p != this->end(); ++p) { - ptsum += p->pT(); - } - _totalPt = ptsum; - _okTotalPt = true; - } - return _totalPt; + return momentum().pT(); } double Jet::EtSum() const { - if (!_okTotalEt) { - double Etsum(0.0); - for (const_iterator p = this->begin(); p != this->end(); ++p) { - Etsum += p->Et(); - } - _totalEt = Etsum; - _okTotalEt = true; - } - return _totalEt; + return momentum().Et(); } - /// @todo Review if these caches are needed/consistent: just the vector, maybe? void Jet::_resetCaches() const { - _okPhi = false; - _okEta = false; _okPtWeightedPhi = false; _okPtWeightedEta = false; - _okTotalPt = false; - _okTotalEt = false; _okMomentum = false; } @@ -218,56 +194,22 @@ } - /// @todo Review if these caches are needed/consistent void Jet::_calcPtAvgs() const { if (!_okPtWeightedEta || !_okPtWeightedPhi) { - double ptwetasum(0.0), ptwphisum(0.0), ptsum(0.0); - double phibegin = 0.0; - for (const_iterator p = this->begin(); p != this->end(); ++p) { - double pt = p->pT(); + double ptwetasum(0.0), ptwdphisum(0.0), ptsum(0.0); + double phi0 = phi(); + foreach (const FourMomentum& p, momenta()) { + double pt = p.pT(); ptsum += pt; - ptwetasum += pt * p->pseudorapidity(); - - if (p == this->begin()) { - phibegin = p->azimuthalAngle(); - } else { - const double dphi = p->azimuthalAngle() - phibegin; - ptwphisum += pt * mapAngleMPiToPi(dphi); - } + ptwetasum += pt * p.pseudorapidity(); + ptwdphisum += pt * mapAngleMPiToPi(phi0 - p.azimuthalAngle()); } - _totalPt = ptsum; - _okTotalPt = true; - _ptWeightedEta = ptwetasum / ptSum(); + _ptWeightedEta = ptwetasum/ptsum; _okPtWeightedEta = true; - _ptWeightedPhi = phibegin + ptwphisum / ptSum(); - _ptWeightedPhi = mapAngleMPiToPi(_ptWeightedPhi); + _ptWeightedPhi = mapAngleMPiToPi(phi0 + ptwdphisum/ptsum); _okPtWeightedPhi = true; } } - - /// @todo Review if these caches are needed/consistent - void Jet::_calcAvgs() const { - if (!_okEta || !_okPhi) { - double etasum(0.0), phisum(0.0); - double phibegin = 0.0; - for (const_iterator p = this->begin(); p != this->end(); ++p) { - etasum += p->pseudorapidity(); - if (p == this->begin()) { - phibegin = p->azimuthalAngle(); - } else { - const double dphi = p->azimuthalAngle() - phibegin; - phisum += mapAngleMPiToPi(dphi); - } - } - const double dnum = _particles.size(); - _eta = etasum / dnum; - _okEta = true; - _phi = phibegin + phisum / dnum; - _phi = mapAngleMPiToPi(_phi); - _okPhi = true; - } - } - }
More information about the Rivet-svn mailing list |