[Rivet-svn] r2224 - in trunk: bin include/Rivet src/Core

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Thu Jan 21 17:24:07 GMT 2010


Author: fsiegert
Date: Thu Jan 21 17:24:06 2010
New Revision: 2224

Log:
Streamline run initialisation such that API and command line usage share
more parts of it. This fixes #376 and makes it more elegant as well I
believe.
IMHO the Run class should really only deal with the HepMC IO.

Modified:
   trunk/bin/rivet
   trunk/include/Rivet/AnalysisHandler.hh
   trunk/include/Rivet/Run.hh
   trunk/src/Core/AnalysisHandler.cc
   trunk/src/Core/Run.cc

Modified: trunk/bin/rivet
==============================================================================
--- trunk/bin/rivet	Wed Jan 20 16:54:56 2010	(r2223)
+++ trunk/bin/rivet	Thu Jan 21 17:24:06 2010	(r2224)
@@ -391,9 +391,6 @@
     logging.error("Failed to initialise on event file %s" % evtfile)
     sys.exit(2)
 
-## Now that we have some idea of the run contents, init the analysis handler
-ah.init()
-
 ## Event loop
 starttime = time.time()
 EVTNUM = 0

Modified: trunk/include/Rivet/AnalysisHandler.hh
==============================================================================
--- trunk/include/Rivet/AnalysisHandler.hh	Wed Jan 20 16:54:56 2010	(r2223)
+++ trunk/include/Rivet/AnalysisHandler.hh	Thu Jan 21 17:24:06 2010	(r2224)
@@ -97,15 +97,11 @@
     bool hasCrossSection() const;
 
 
-    /// Set beams for this run (as determined from first event)
-    AnalysisHandler& setRunBeams(const GenEvent& event) { 
-      return setRunBeams(Rivet::beams(event));
-    }
-
-    /// Set beams for this run (as determined from beam particles)
+    /// Set beams for this run
     AnalysisHandler& setRunBeams(const ParticlePair& beams) { 
-      getLog() << Log::DEBUG << "Setting run beams = " << beams << endl;
       _beams = beams;
+      getLog() << Log::DEBUG << "Setting run beams = " << beams
+               << " @ " << sqrtS()/GeV << " GeV" << endl;
       return *this;
     }
 
@@ -176,15 +172,12 @@
     /// @name Main init/execute/finalise
     //@{
 
-    /// Initialize a run (beam configuration should be specified first, via @c{setRunBeams}).
-    void init();
+    /// @deprecated Obsolete method, kept only for backwards compatibility
+    void init() {}
 
 
     /// Initialize a run, with the run beams taken from the example event.
-    void init(const GenEvent& event) {
-      setRunBeams(event);
-      init();
-    }
+    void init(const GenEvent& event);
 
 
     /// Analyze the given \a event. This function will call the

Modified: trunk/include/Rivet/Run.hh
==============================================================================
--- trunk/include/Rivet/Run.hh	Wed Jan 20 16:54:56 2010	(r2223)
+++ trunk/include/Rivet/Run.hh	Thu Jan 21 17:24:06 2010	(r2224)
@@ -39,18 +39,6 @@
     //@}
 
 
-    /// @name Get run conditions
-    //@{
-
-    /// Get beam IDs for this run, determined from first event
-    const BeamPair& beams() const;
-
-    /// Get energy for this run, determined from first event
-    double sqrtS() const;
-
-    //@}
-
-
     /// @name File processing stages
     //@{
 
@@ -81,12 +69,6 @@
     /// Cross-section from command line
     double _xs;
 
-    /// Centre of mass energy, determined from first event
-    double _sqrts;
-
-    /// Beam IDs, determined from first event
-    BeamPair _beams;
-
     //@}
 
 

Modified: trunk/src/Core/AnalysisHandler.cc
==============================================================================
--- trunk/src/Core/AnalysisHandler.cc	Wed Jan 20 16:54:56 2010	(r2223)
+++ trunk/src/Core/AnalysisHandler.cc	Thu Jan 21 17:24:06 2010	(r2224)
@@ -39,11 +39,29 @@
   }
 
 
-  void AnalysisHandler::init() {
+  void AnalysisHandler::init(const GenEvent& ge) {
     assert(!_initialised);
+    setRunBeams(Rivet::beams(ge));
     getLog() << Log::DEBUG << "Initialising the analysis handler" << endl;
     _numEvents = 0;
     _sumOfWeights = 0.0;
+    
+    // Check that analyses are beam-compatible
+    const size_t num_anas_requested = analysisNames().size();
+    removeIncompatibleAnalyses(beamIds());
+    foreach (const Analysis* a, analyses()) {
+      if (toUpper(a->status()) != "VALIDATED") {
+        getLog() << Log::WARN 
+                 << "Analysis '" << a->name() << "' is unvalidated: be careful!" << endl;
+      }
+    }
+    if (num_anas_requested > 0 && analysisNames().size() == 0) {
+      getLog() << Log::ERROR
+               << "All analyses were incompatible with the first event's beams\n"
+               << "Exiting, since this probably isn't intentional!" << endl;
+      exit(1);
+    }
+    
     foreach (Analysis* a, _analyses) {
       getLog() << Log::DEBUG << "Initialising analysis: " << a->name() << endl;
       // Allow projection registration in the init phase onwards
@@ -65,6 +83,17 @@
     }
     // Proceed with event analysis
     assert(_initialised);
+    // Ensure that beam details match those from first event
+    const BeamPair beams = Rivet::beamIds(ge);
+    const double sqrts = Rivet::sqrtS(ge);
+    if (!compatible(beams, _beams) || !fuzzyEquals(sqrts, sqrtS())) {
+      getLog() << Log::ERROR << "Event beams mismatch: "
+               << beams << " @ " << sqrts/GeV << " GeV" << " vs. first beams "
+               << this->beams() << " @ " << this->sqrtS()/GeV << " GeV" << endl;
+      exit(1);
+    }
+
+    
     Event event(ge);
     _numEvents++;
     // Weights

Modified: trunk/src/Core/Run.cc
==============================================================================
--- trunk/src/Core/Run.cc	Wed Jan 20 16:54:56 2010	(r2223)
+++ trunk/src/Core/Run.cc	Thu Jan 21 17:24:06 2010	(r2224)
@@ -9,7 +9,7 @@
 
 
   Run::Run(AnalysisHandler& ah) 
-    : _ah(ah), _xs(-1.0), _sqrts(-1.0)
+    : _ah(ah), _xs(-1.0)
   { }
 
 
@@ -63,15 +63,8 @@
       return false;
     }
 
-    // Set required beams for run based on first beams 
-    const BeamPair beams = beamIds(*_evt);
-    const double sqrts = Rivet::sqrtS(*_evt);
-    _beams = beams;
-    _sqrts = sqrts;
-    Log::getLog("Rivet.Run") << Log::INFO << "First event beams: "
-                             << this->beams() << " @ " << this->sqrtS()/GeV << " GeV" << endl;
-    // Pass to analysis handler
-    _ah.setRunBeams(*_evt);
+    // Initialise AnalysisHandler with beam information from first event
+    _ah.init(*_evt);
 
     // Set cross-section from command line
     if (_xs >= 0.0) {
@@ -80,22 +73,6 @@
       _ah.setCrossSection(_xs);
     }
 
-    // Check that analyses are beam-compatible
-    const size_t num_anas_requested = _ah.analysisNames().size();
-    _ah.removeIncompatibleAnalyses(beams);
-    foreach (const Analysis* a, _ah.analyses()) {
-      if (toUpper(a->status()) != "VALIDATED") {
-        Log::getLog("Rivet.Run") << Log::WARN 
-                                 << "Analysis '" << a->name() << "' is unvalidated: be careful!" << endl;
-      }
-    }
-    if (num_anas_requested > 0 && _ah.analysisNames().size() == 0) {
-      Log::getLog("Rivet.Run") << Log::ERROR
-                               << "All analyses were incompatible with the first event's beams\n"
-                               << "Exiting, since this probably isn't intentional!" << endl;
-      return false;
-    }
-   
     // List the chosen & compatible analyses if requested
     if (_listAnalyses) {
       foreach (const std::string& ana, _ah.analysisNames()) {
@@ -108,17 +85,6 @@
 
 
   bool Run::processEvent() {
-    // Ensure that beam details match those from first event
-    const BeamPair beams = beamIds(*_evt);
-    const double sqrts = Rivet::sqrtS(*_evt);
-    if (beams != _beams || !fuzzyEquals(sqrts, sqrtS())) {
-      Log::getLog("Rivet.Run") 
-        << Log::ERROR << "Event beams mismatch: "
-        << beams << " @ " << sqrts/GeV << " GeV" << " vs. first beams "
-        << this->beams() << " @ " << this->sqrtS()/GeV << " GeV" << endl;
-      return false;
-    }
-
     // Set cross-section if found in event and not from command line
     #ifdef HEPMC_HAS_CROSS_SECTION
     if (_xs < 0.0 && _evt->cross_section()) {
@@ -152,14 +118,6 @@
   }
 
 
-  const BeamPair& Run::beams() const {
-    return _beams;
-  }
-
-
-  double Run::sqrtS() const {
-    return _sqrts;
-  }
 
 
 }


More information about the Rivet-svn mailing list