[Rivet-svn] r2474 - in trunk: include/Rivet include/Rivet/Projections src/Analyses src/Projections

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Tue Jun 8 23:43:59 BST 2010


Author: buckley
Date: Tue Jun  8 23:44:05 2010
New Revision: 2474

Log:
Generalising LossyFinalState as requested to allow more general lossiness functions. This shouldn't be very complex, although it involves a little bit of templates, inheritance and functors... but I'm now getting a bad_cast exception when running the CDF 2001 analysis (the only *current* user of this kind of final state projection). I can't reproduce the problems with a minimal example, and all tests I've tried indicate that the correct types are being cast. Maybe something is getting lost inside the inheritance chain, or in how the ProjectionHandler is copying things around... it all looks fine to me :( Please unleash your many eyes upon this... and if you need to use the 2001 underlying event analysis, use a production version or a development version of Rivet from before this commit.

Added:
   trunk/include/Rivet/Projections/ConstLossyFinalState.hh
Deleted:
   trunk/src/Projections/LossyFinalState.cc
Modified:
   trunk/include/Rivet/Makefile.am
   trunk/include/Rivet/Projections/LossyFinalState.hh
   trunk/src/Analyses/CDF_2001_S4751469.cc
   trunk/src/Projections/Makefile.am

Modified: trunk/include/Rivet/Makefile.am
==============================================================================
--- trunk/include/Rivet/Makefile.am	Tue Jun  8 23:31:37 2010	(r2473)
+++ trunk/include/Rivet/Makefile.am	Tue Jun  8 23:44:05 2010	(r2474)
@@ -38,6 +38,7 @@
   Projections/ChargedFinalState.hh \
   Projections/ChargedLeptons.hh \
   Projections/ClusteredPhotons.hh \
+  Projections/ConstLossyFinalState.hh \
   Projections/DISKinematics.hh  \
   Projections/DISLepton.hh      \
   Projections/FastJets.hh       \

Added: trunk/include/Rivet/Projections/ConstLossyFinalState.hh
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ trunk/include/Rivet/Projections/ConstLossyFinalState.hh	Tue Jun  8 23:44:05 2010	(r2474)
@@ -0,0 +1,79 @@
+// -*- C++ -*-
+#ifndef RIVET_ConstLossyFinalState_HH
+#define RIVET_ConstLossyFinalState_HH
+
+#include "Rivet/Tools/Logging.hh"
+#include "Rivet/Rivet.hh"
+#include "Rivet/Particle.hh"
+#include "Rivet/Event.hh"
+#include "Rivet/Projection.hh"
+#include "Rivet/Projections/FinalState.hh"
+#include "Rivet/Projections/LossyFinalState.hh"
+
+namespace Rivet {
+
+
+  /// Functor used to implement constant random lossiness.
+  class ConstRandomFilter {
+  public:
+
+    ConstRandomFilter(double lossFraction)
+      : _lossFraction(lossFraction)
+    {
+      assert(_lossFraction >= 0);
+    }
+
+    bool operator()(const Particle& p) {
+      /// @todo Use a better RNG
+      return (rand()/static_cast<double>(RAND_MAX) < _lossFraction);
+    }
+
+    int compare(const ConstRandomFilter& other) const {
+      return cmp(_lossFraction, other._lossFraction);
+    }
+
+  private:
+
+    double _lossFraction;
+
+  };
+
+
+
+  /// @brief Randomly lose a constant fraction of particles.
+  class ConstLossyFinalState : public LossyFinalState<ConstRandomFilter> {
+  public:
+
+    /// @name Constructors
+    //@{
+
+    /// Constructor from a FinalState.
+    ConstLossyFinalState(const FinalState& fsp, double lossfraction)
+      : LossyFinalState<ConstRandomFilter>(fsp, ConstRandomFilter(lossfraction))
+    {
+      setName("ConstLossyFinalState");
+    }
+
+    /// Stand-alone constructor. Initialises the base FinalState projection.
+    ConstLossyFinalState(double lossfraction,
+                         double mineta = -MAXRAPIDITY,
+                         double maxeta = MAXRAPIDITY,
+                         double minpt = 0.0)
+      : LossyFinalState<ConstRandomFilter>(ConstRandomFilter(lossfraction), mineta, maxeta, minpt)
+    {
+      setName("ConstLossyFinalState");
+    }
+
+    /// Clone on the heap.
+    virtual const Projection* clone() {
+      return new ConstLossyFinalState(*this);
+    }
+
+    //@}
+
+  };
+
+
+}
+
+#endif

Modified: trunk/include/Rivet/Projections/LossyFinalState.hh
==============================================================================
--- trunk/include/Rivet/Projections/LossyFinalState.hh	Tue Jun  8 23:31:37 2010	(r2473)
+++ trunk/include/Rivet/Projections/LossyFinalState.hh	Tue Jun  8 23:44:05 2010	(r2474)
@@ -12,7 +12,8 @@
 namespace Rivet {
 
 
-  /// @brief Randomly lose a fraction of the particles from the supplied final state projection.
+  /// @brief Templated FS projection which can lose some of the supplied particles.
+  template <typename FILTER>
   class LossyFinalState : public FinalState {
   public:
 
@@ -20,29 +21,30 @@
     //@{
 
     /// Constructor from FinalState.
-    LossyFinalState(const FinalState& fsp, double lossfraction)
-      : _lossFraction(lossfraction)
+    LossyFinalState(const FinalState& fsp, const FILTER& filter)
+      : _filter(filter)
     {
       setName("LossyFinalState");
       addProjection(fsp, "FS");
-      assert(_lossFraction >= 0);
     }
 
     /// Stand-alone constructor. Initialises the base FinalState projection.
-    LossyFinalState(double lossfraction,
+    LossyFinalState(const FILTER& filter,
                     double mineta = -MAXRAPIDITY,
                     double maxeta = MAXRAPIDITY,
                     double minpt = 0.0)
-      : _lossFraction(lossfraction)
+      : _filter(filter)
     {
       setName("LossyFinalState");
       addProjection(FinalState(mineta, maxeta, minpt), "FS");
-      assert(_lossFraction >= 0);
     }
 
+    /// Virtual destructor, to allow subclassing
+    virtual ~LossyFinalState() { }
+
     /// Clone on the heap.
-    virtual const Projection* clone() const {
-      return new LossyFinalState(*this);
+    virtual const Projection* clone() {
+      return new LossyFinalState<FILTER>(*this);
     }
 
     //@}
@@ -51,26 +53,29 @@
   protected:
 
     /// Apply the projection on the supplied event.
-    void project(const Event& e);
+    void project(const Event& e) {
+      const FinalState& fs = applyProjection<FinalState>(e, "FS");
+      getLog() << Log::DEBUG << "Pre-loss number of FS particles = " << fs.particles().size() << endl;
+      _theParticles.clear();
+      std::remove_copy_if(fs.particles().begin(), fs.particles().end(),
+                          std::back_inserter(_theParticles), _filter);
+      getLog() << Log::DEBUG << "Filtered number of FS particles = " << _theParticles.size() << endl;
+    }
 
-    /// Compare projections.
-    int compare(const Projection& p) const;
 
+    /// Compare projections.
+    int compare(const Projection& p) const {
+      const LossyFinalState<FILTER>& other = pcast< LossyFinalState<FILTER> >(p);
+      const int fscmp = mkNamedPCmp(other, "FS");
+      if (fscmp) return fscmp;
+      return _filter.compare(other._filter);
+    }
 
-  private:
 
-    /// Inner functor used to implement the random lossiness.
-    struct RandomFilter {
-      RandomFilter(double lossFraction) : _lossFraction(lossFraction) {}
-      bool operator()(const Particle& p) {
-        /// @todo Use a better RNG
-        return (rand()/static_cast<double>(RAND_MAX) < _lossFraction);
-      }
-      double _lossFraction;
-    };
+  protected:
 
-    /// Fraction of particles to lose.
-    const double _lossFraction;
+    /// Filtering object: must support operator(const Particle&) and compare(const Filter&)
+    FILTER _filter;
 
   };
 

Modified: trunk/src/Analyses/CDF_2001_S4751469.cc
==============================================================================
--- trunk/src/Analyses/CDF_2001_S4751469.cc	Tue Jun  8 23:31:37 2010	(r2473)
+++ trunk/src/Analyses/CDF_2001_S4751469.cc	Tue Jun  8 23:44:05 2010	(r2474)
@@ -8,7 +8,7 @@
 #include "Rivet/RivetAIDA.hh"
 #include "Rivet/Tools/Logging.hh"
 #include "Rivet/Projections/ChargedFinalState.hh"
-#include "Rivet/Projections/LossyFinalState.hh"
+#include "Rivet/Projections/ConstLossyFinalState.hh"
 #include "Rivet/Projections/FastJets.hh"
 #include "Rivet/Projections/TriggerCDFRun0Run1.hh"
 #include "LWH/Profile1D.h"
@@ -51,7 +51,11 @@
       addProjection(TriggerCDFRun0Run1(), "Trigger");
       // Randomly discard 8% of charged particles as a kind of hacky detector correction.
       const ChargedFinalState cfs(-1.0, 1.0, 0.5*GeV);
-      const LossyFinalState lfs(cfs, 0.08);
+      const ConstLossyFinalState lfs(cfs, 0.08);
+      /// @todo Problem! Getting bad_cast exception... don't know why :(
+      // const LossyFinalState<ConstRandomFilter> lfs(cfs, ConstRandomFilter(0.08));
+      // const Projection* f = new ConstLossyFinalState(0.08);
+      // const ConstLossyFinalState* fp = dynamic_cast<const ConstLossyFinalState*>(f);
       addProjection(lfs, "FS");
       addProjection(FastJets(lfs, FastJets::TRACKJET, 0.7), "TrackJet");
 
@@ -92,7 +96,7 @@
       const JetAlg& tj = applyProjection<JetAlg>(event, "TrackJet");
 
       // Final state (lossy) charged particles
-      const LossyFinalState& fs = applyProjection<LossyFinalState>(event, "FS");
+      const FinalState& fs = applyProjection<FinalState>(event, "FS");
 
       // Get jets, sorted by pT
       const Jets jets = tj.jetsByPt();

Modified: trunk/src/Projections/Makefile.am
==============================================================================
--- trunk/src/Projections/Makefile.am	Tue Jun  8 23:31:37 2010	(r2473)
+++ trunk/src/Projections/Makefile.am	Tue Jun  8 23:44:05 2010	(r2474)
@@ -19,7 +19,6 @@
   JetAlg.cc \
   JetShape.cc \
   LeadingParticlesFinalState.cc \
-  LossyFinalState.cc \
   MergedFinalState.cc \
   MissingMomentum.cc \
   Multiplicity.cc \


More information about the Rivet-svn mailing list