[Rivet-svn] r2981 - in trunk: . doc include/Rivet pyext/rivet src/Core

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Sat Feb 26 20:44:36 GMT 2011


Author: buckley
Date: Sat Feb 26 20:44:35 2011
New Revision: 2981

Log:
Clean-ups and reworkings in the analysis info treatment: analysis beam energies are now used to ensure that the running analyses are compatible with the specified beams. Correctly configured analyses should no longer have the problem where they segfault due to no histograms being booked for unsupported energies, since they should never be able to run in that mode. Some long-deprecated methods have been removed, and more logging macros are being used. Sorry Frank, but weirdly this was actually quite a fun^Wsatisfying thing to do at the weekend; I need help ;-)

Modified:
   trunk/ChangeLog
   trunk/configure.ac
   trunk/doc/mk-analysis-html
   trunk/doc/mk-analysis-latex
   trunk/include/Rivet/Analysis.hh
   trunk/include/Rivet/AnalysisHandler.hh
   trunk/include/Rivet/Particle.hh
   trunk/pyext/rivet/rivetwrap.i
   trunk/src/Core/Analysis.cc
   trunk/src/Core/AnalysisHandler.cc
   trunk/src/Core/AnalysisInfo.cc

Modified: trunk/ChangeLog
==============================================================================
--- trunk/ChangeLog	Sat Feb 26 20:33:12 2011	(r2980)
+++ trunk/ChangeLog	Sat Feb 26 20:44:35 2011	(r2981)
@@ -1,3 +1,17 @@
+2011-02-26  Andy Buckley  <andy at insectnation.org>
+
+	* Changing internal storage and return type of Particle::pdgId()
+	to PdgId, and adding Particle::energy().
+
+	* Renaming Analysis::energies() as Analysis::requiredEnergies().
+
+	* Adding beam energies into beam consistency checking:
+	Analysis::isCompatible methods now also require the beam energies
+	to be provided.
+
+	* Removing long-deprecated AnalysisHandler::init() constructor and
+	AnalysisHandler::removeIncompatibleAnalyses() methods.
+
 2011-02-25  Andy Buckley  <andy at insectnation.org>
 
 	* Adding --disable-obsolete, which takes its value from the value

Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac	Sat Feb 26 20:33:12 2011	(r2980)
+++ trunk/configure.ac	Sat Feb 26 20:44:35 2011	(r2981)
@@ -1,7 +1,7 @@
 ## Process this file with autoconf to produce a configure script.
 
 AC_PREREQ(2.59)
-AC_INIT([Rivet],[1.5.0a0],[rivet at projects.hepforge.org],[Rivet])
+AC_INIT([Rivet],[1.5.0a1],[rivet at projects.hepforge.org],[Rivet])
 AC_CONFIG_SRCDIR([src/Core/Analysis.cc])
 AC_CONFIG_HEADERS([include/Rivet/Config/DummyConfig.hh include/Rivet/Config/RivetConfig.hh include/Rivet/Config/BuildOptions.hh])
 AM_INIT_AUTOMAKE(dist-bzip2)

Modified: trunk/doc/mk-analysis-html
==============================================================================
--- trunk/doc/mk-analysis-html	Sat Feb 26 20:33:12 2011	(r2980)
+++ trunk/doc/mk-analysis-html	Sat Feb 26 20:44:35 2011	(r2981)
@@ -123,8 +123,8 @@
 
 
     page += "<b>Beam energies:</b> "
-    if ana.energies():
-        page += "; ".join(["(%0.1f, %0.1f)" % (epair[0], epair[1]) for epair in ana.energies()])
+    if ana.requiredEnergies():
+        page += "; ".join(["(%0.1f, %0.1f)" % (epair[0], epair[1]) for epair in ana.requiredEnergies()])
         page += "GeV"
     else:
         page += "ANY"

Modified: trunk/doc/mk-analysis-latex
==============================================================================
--- trunk/doc/mk-analysis-latex	Sat Feb 26 20:33:12 2011	(r2980)
+++ trunk/doc/mk-analysis-latex	Sat Feb 26 20:44:35 2011	(r2981)
@@ -91,9 +91,9 @@
         for bp in ana.requiredBeams():
             beamstrs.append(pid_to_str(bp[0]) + "\\," + pid_to_str(bp[1]))
         page += "\\textbf{Beams:} %s \\newline\n" % ", ".join(beamstrs)
-    if ana.energies():
+    if ana.requiredEnergies():
         page += "\\textbf{Energies:} %s GeV \\newline\n" % \
-            ", ".join(["(%0.1f, %0.1f)" % (epair[0], epair[1]) for epair in ana.energies()])
+            ", ".join(["(%0.1f, %0.1f)" % (epair[0], epair[1]) for epair in ana.requiredEnergies()])
     if ana.experiment():
         page += "\\textbf{Experiment:} %s (%s) \\newline\n" % (ana.experiment(), ana.collider())
     if ana.spiresId():

Modified: trunk/include/Rivet/Analysis.hh
==============================================================================
--- trunk/include/Rivet/Analysis.hh	Sat Feb 26 20:33:12 2011	(r2980)
+++ trunk/include/Rivet/Analysis.hh	Sat Feb 26 20:44:35 2011	(r2981)
@@ -62,7 +62,7 @@
     Analysis(const std::string& name);
 
     /// The destructor.
-    virtual ~Analysis();
+    virtual ~Analysis() {}
 
     //@}
 
@@ -147,16 +147,7 @@
     /// Collider on which the experiment ran.
     virtual std::string collider() const;
 
-    /// Return the pair of incoming beams required by this analysis.
-    virtual const std::vector<PdgIdPair>& requiredBeams() const;
-
-    /// Sets of valid beam energy pairs, in GeV
-    virtual const std::vector<std::pair<double, double> >& energies() const;
-
-    /// @brief When the original experimental analysis was published.
-    ///
-    /// When the refereed paper on which this is based was published,
-    /// according to SPIRES.
+    /// When the original experimental analysis was published.
     virtual std::string year() const;
 
     /// Journal, and preprint references.
@@ -174,10 +165,17 @@
     /// Any work to be done on this analysis.
     virtual std::vector<std::string> todos() const;
 
+    /// Return the pair of incoming beams required by this analysis.
+    virtual const std::vector<PdgIdPair>& requiredBeams() const;
+
+    /// Sets of valid beam energy pairs, in GeV
+    virtual const std::vector<std::pair<double, double> >& requiredEnergies() const;
+
     //@}
 
 
     /// @name Run conditions
+    //@{
 
     /// Incoming beams for this run
     const ParticlePair& beams() const;
@@ -191,13 +189,22 @@
     //@}
 
 
-  public:
+    /// @name Analysis / beam compatibility testing
+    //@{
+
+    /// Check if analysis is compatible with the provided beam particle IDs and energies
+    bool isCompatible(const ParticlePair& beams) const;
+
+    /// Check if analysis is compatible with the provided beam particle IDs and energies
+    bool isCompatible(PdgId beam1, PdgId beam2, double e1, double e2) const;
 
-    /// Is this analysis able to run on the supplied pair of beams?
-    virtual bool isCompatible(PdgId beam1, PdgId beam2) const;
+    /// Check if analysis is compatible with the provided beam particle IDs and energies
+    bool isCompatible(const PdgIdPair& beams, const std::pair<double,double>& energies) const;
+
+    //@}
 
-    /// Is this analysis able to run on the PdgIdPair @a beams ?
-    virtual bool isCompatible(const PdgIdPair& beams) const;
+
+  public:
 
     /// Access the controlling AnalysisHandler object.
     AnalysisHandler& handler() const;
@@ -238,12 +245,13 @@
     Analysis& setCrossSection(double xs);
 
     /// Return true if this analysis needs to know the process cross-section.
-    bool needsCrossSection() const;
+    bool needsCrossSection() const {
+      return _needsCrossSection;
+    }
 
 
   protected:
 
-
     /// Get a Log object based on the name() property of the calling analysis object.
     Log& getLog() const;
 
@@ -456,7 +464,10 @@
     Analysis& setBeams(PdgId beam1, PdgId beam2);
 
     /// Declare whether this analysis needs to know the process cross-section from the generator.
-    Analysis& setNeedsCrossSection(bool needed);
+    Analysis& setNeedsCrossSection(bool needed=true) {
+      _needsCrossSection = needed;
+      return *this;
+    }
 
 
   protected:

Modified: trunk/include/Rivet/AnalysisHandler.hh
==============================================================================
--- trunk/include/Rivet/AnalysisHandler.hh	Sat Feb 26 20:33:12 2011	(r2980)
+++ trunk/include/Rivet/AnalysisHandler.hh	Sat Feb 26 20:44:35 2011	(r2981)
@@ -73,7 +73,7 @@
     void _normalizeTree(AIDA::ITree& tree);
 
     /// Get a logger object.
-    Log& getLog();
+    Log& getLog() const;
 
 
   public:
@@ -118,20 +118,19 @@
     /// Set beams for this run
     AnalysisHandler& setRunBeams(const ParticlePair& beams) {
       _beams = beams;
-      getLog() << Log::DEBUG << "Setting run beams = " << beams
-               << " @ " << sqrtS()/GeV << " GeV" << endl;
+      MSG_DEBUG("Setting run beams = " << beams << " @ " << sqrtS()/GeV << " GeV");
       return *this;
     }
 
-    /// Get beam IDs for this run, determined from first event
+    /// Get beam IDs for this run, usually determined from the first event.
     const ParticlePair& beams() const {
       return _beams;
     }
 
-    /// Get beam IDs for this run, determined from first event
+    /// Get beam IDs for this run, usually determined from the first event.
     PdgIdPair beamIds() const;
 
-    /// Get energy for this run, determined from first event
+    /// Get energy for this run, usually determined from the first event.
     double sqrtS() const;
 
     //@}
@@ -172,20 +171,12 @@
     /// Add an analysis to the run list by object
     AnalysisHandler& addAnalysis(Analysis* analysis);
 
-    /// Remove beam-incompatible analyses from the run list.
-    /// @todo Do this automatically in the init phase (including energies) and deprecate explicit use
-    AnalysisHandler& removeIncompatibleAnalyses(const PdgIdPair& beams);
-
     //@}
 
 
     /// @name Main init/execute/finalise
     //@{
 
-    /// @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);
 

Modified: trunk/include/Rivet/Particle.hh
==============================================================================
--- trunk/include/Rivet/Particle.hh	Sat Feb 26 20:33:12 2011	(r2980)
+++ trunk/include/Rivet/Particle.hh	Sat Feb 26 20:44:35 2011	(r2981)
@@ -53,23 +53,26 @@
 
 
     /// The PDG ID code for this Particle.
-    long pdgId() const {
+    PdgId pdgId() const {
       return _id;
     }
 
 
-    /// The momentum of this Particle.
-    const FourMomentum& momentum() const {
-      return _momentum;
-    }
-
-
     /// Set the momentum of this Particle.
     Particle& setMomentum(const FourMomentum& momentum) {
       _momentum = momentum;
       return *this;
     }
 
+    /// The momentum of this Particle.
+    const FourMomentum& momentum() const {
+      return _momentum;
+    }
+
+    /// The energy of this Particle.
+    double energy() const {
+      return momentum().E();
+    }
 
     /// The mass of this Particle.
     double mass() const {
@@ -97,7 +100,7 @@
     const GenParticle* _original;
 
     /// The PDG ID code for this Particle.
-    long _id;
+    PdgId _id;
 
     /// The momentum of this projection of the Particle.
     FourMomentum _momentum;

Modified: trunk/pyext/rivet/rivetwrap.i
==============================================================================
--- trunk/pyext/rivet/rivetwrap.i	Sat Feb 26 20:33:12 2011	(r2980)
+++ trunk/pyext/rivet/rivetwrap.i	Sat Feb 26 20:44:35 2011	(r2981)
@@ -71,7 +71,9 @@
     Particle();
     bool hasGenParticle() const;
     const HepMC::GenParticle& genParticle() const;
-    const long pdgId() const;
+    const PdgId pdgId() const;
+    const double mass() const;
+    const double energy() const;
   };
 
   ParticlePair beams(const Event& e);
@@ -99,15 +101,16 @@
     virtual std::string collider() const;
     virtual std::string year() const;
     virtual const std::vector<PdgIdPair>& requiredBeams() const;
-    virtual const std::vector<std::pair<double,double> >& energies() const;
+    virtual const std::vector<std::pair<double,double> >& requiredEnergies() const;
     virtual std::vector<std::string> authors() const;
     virtual std::vector<std::string> references() const;
     virtual std::vector<std::string> todos() const;
     virtual std::string status() const;
     virtual std::string bibKey() const;
     virtual std::string bibTeX() const;
-    virtual const bool isCompatible(PdgId beam1, PdgId beam2) const;
-    virtual const bool isCompatible(const PdgIdPair& beams) const;
+    virtual const bool isCompatible(PdgId beam1, PdgId beam2, double e1, double e2) const;
+    virtual const bool isCompatible(const PdgIdPair& beamids, const std::pair<double, double>& beamenergies) const;
+    virtual const bool isCompatible(const ParticlePair& beams) const;
     //AnalysisHandler& handler() const;
     bool needsCrossSection() const;
   private:
@@ -129,8 +132,6 @@
     AnalysisHandler& addAnalyses(const std::vector<std::string>& analysisnames);
     AnalysisHandler& removeAnalysis(const std::string& analysisname);
     AnalysisHandler& removeAnalyses(const std::vector<std::string>& analysisnames);
-    AnalysisHandler& removeIncompatibleAnalyses(const PdgIdPair& beams);
-    void init();
     void init(const HepMC::GenEvent& event);
     void analyze(const HepMC::GenEvent& event);
     void finalize();

Modified: trunk/src/Core/Analysis.cc
==============================================================================
--- trunk/src/Core/Analysis.cc	Sat Feb 26 20:33:12 2011	(r2980)
+++ trunk/src/Core/Analysis.cc	Sat Feb 26 20:44:35 2011	(r2981)
@@ -40,18 +40,14 @@
   {
     ProjectionApplier::_allowProjReg = false;
     _defaultname = name;
+
     AnalysisInfo* ai = AnalysisInfo::make(name);
     assert(ai != 0);
     _info.reset(ai);
     assert(_info.get() != 0);
-    //setBeams(ANY, ANY);
   }
 
 
-  Analysis::~Analysis()
-  {  }
-
-
   IAnalysisFactory& Analysis::analysisFactory() {
     return handler().analysisFactory();
   }
@@ -86,7 +82,7 @@
 
 
   const string Analysis::histoDir() const {
-    /// @todo This doesn't change: calc and cache at Analysis construction!
+    /// @todo This doesn't change: calc and cache at first use!
     string path = "/" + name();
     if (handler().runName().length() > 0) {
       path = "/" + handler().runName() + path;
@@ -158,10 +154,6 @@
     return _info->runInfo();
   }
 
-  const std::vector<std::pair<double,double> >& Analysis::energies() const {
-    return info().energies();
-  }
-
   string Analysis::experiment() const {
     if (!_info) return "NONE";
     return _info->experiment();
@@ -206,9 +198,14 @@
     return info().beams();
   }
 
+  const std::vector<std::pair<double,double> >& Analysis::requiredEnergies() const {
+    return info().energies();
+  }
+
 
   /// @todo Deprecate?
   Analysis& Analysis::setBeams(PdgId beam1, PdgId beam2) {
+    /// @todo Print out a warning when beams def are used from info files and AI fields can be publicly set
     assert(_info.get() != 0);
     _info->_beams.clear();
     _info->_beams += make_pair(beam1, beam2);
@@ -216,19 +213,42 @@
   }
 
 
-  /// @todo Deprecate?
-  bool Analysis::isCompatible(PdgId beam1, PdgId beam2) const {
+  bool Analysis::isCompatible(const ParticlePair& beams) const {
+    return isCompatible(beams.first.pdgId(), beams.second.pdgId(),
+                        beams.first.energy(), beams.first.energy());
+  }
+
+
+  bool Analysis::isCompatible(PdgId beam1, PdgId beam2, double e1, double e2) const {
     PdgIdPair beams(beam1, beam2);
-    return isCompatible(beams);
+    pair<double,double> energies(e1, e2);
+    return isCompatible(beams, energies);
   }
 
 
-  /// @todo Deprecate?
-  bool Analysis::isCompatible(const PdgIdPair& beams) const {
+  bool Analysis::isCompatible(const PdgIdPair& beams, const pair<double,double>& energies) const {
+    // First check the beam IDs
+    bool beamIdsOk = false;
     foreach (const PdgIdPair& bp, requiredBeams()) {
-      if (compatible(beams, bp)) return true;
+      if (compatible(beams, bp)) {
+        beamIdsOk =  true;
+        break;
+      }
+    }
+    if (!beamIdsOk) return false;
+
+    // Next check that the energies are compatible
+    bool beamEnergiesOk = false;
+    typedef pair<double,double> DoublePair;
+    foreach (const DoublePair& ep, requiredEnergies()) {
+      if ((fuzzyEquals(ep.first, energies.first) && fuzzyEquals(ep.second, energies.second)) ||
+          (fuzzyEquals(ep.first, energies.second) && fuzzyEquals(ep.second, energies.first))) {
+        beamEnergiesOk =  true;
+        break;
+      }
     }
-    return false;
+    return beamEnergiesOk;
+
     /// @todo Need to also check internal consistency of the analysis'
     /// beam requirements with those of the projections it uses.
   }
@@ -240,17 +260,6 @@
     return *this;
   }
 
-  /// @todo Deprecate, eventually
-  bool Analysis::needsCrossSection() const {
-    return _needsCrossSection;
-  }
-
-  /// @todo Deprecate, eventually
-  Analysis& Analysis::setNeedsCrossSection(bool needed) {
-    _needsCrossSection = needed;
-    return *this;
-  }
-
   double Analysis::crossSection() const {
     if (!_gotCrossSection || _crossSection < 0) {
       string errMsg = "You did not set the cross section for the analysis " + name();
@@ -279,7 +288,7 @@
   void Analysis::_cacheBinEdges() const {
     _cacheXAxisData();
     if (_histBinEdges.empty()) {
-      getLog() << Log::TRACE << "Getting histo bin edges from AIDA for paper " << name() << endl;
+      MSG_TRACE("Getting histo bin edges from AIDA for paper " << name());
       _histBinEdges = getBinEdges(_dpsData);
     }
   }
@@ -287,7 +296,7 @@
 
   void Analysis::_cacheXAxisData() const {
     if (_dpsData.empty()) {
-      getLog() << Log::TRACE << "Getting DPS x-axis data from AIDA for paper " << name() << endl;
+      MSG_TRACE("Getting DPS x-axis data from AIDA for paper " << name());
       _dpsData = getDPSXValsErrs(name());
     }
   }
@@ -295,14 +304,14 @@
 
   const BinEdges& Analysis::binEdges(const string& hname) const {
     _cacheBinEdges();
-    getLog() << Log::TRACE << "Using histo bin edges for " << name() << ":" << hname << endl;
+    MSG_TRACE("Using histo bin edges for " << name() << ":" << hname);
     const BinEdges& edges = _histBinEdges.find(hname)->second;
     if (getLog().isActive(Log::TRACE)) {
       stringstream edges_ss;
       foreach (const double be, edges) {
         edges_ss << " " << be;
       }
-      getLog() << Log::TRACE << "Edges:" << edges_ss.str() << endl;
+      MSG_TRACE("Edges:" << edges_ss.str());
     }
     return edges;
   }
@@ -344,7 +353,7 @@
     _makeHistoDir();
     const string path = histoPath(hname);
     IHistogram1D* hist = histogramFactory().createHistogram1D(path, title, edges);
-    getLog() << Log::TRACE << "Made histogram " << hname <<  " for " << name() << endl;
+    MSG_TRACE("Made histogram " << hname <<  " for " << name());
     hist->setXTitle(xtitle);
     hist->setYTitle(ytitle);
     return hist;
@@ -358,7 +367,7 @@
     _makeHistoDir();
     const string path = histoPath(hname);
     IHistogram1D* hist = histogramFactory().createHistogram1D(path, title, nbins, lower, upper);
-    getLog() << Log::TRACE << "Made histogram " << hname <<  " for " << name() << endl;
+    MSG_TRACE("Made histogram " << hname <<  " for " << name());
     hist->setXTitle(xtitle);
     hist->setYTitle(ytitle);
     return hist;
@@ -372,7 +381,7 @@
     _makeHistoDir();
     const string path = histoPath(hname);
     IHistogram1D* hist = histogramFactory().createHistogram1D(path, title, binedges);
-    getLog() << Log::TRACE << "Made histogram " << hname <<  " for " << name() << endl;
+    MSG_TRACE("Made histogram " << hname <<  " for " << name());
     hist->setXTitle(xtitle);
     hist->setYTitle(ytitle);
     return hist;
@@ -389,8 +398,7 @@
     IHistogram2D* hist =
       histogramFactory().createHistogram2D(path, title, nxbins, xlower, xupper,
 					   nybins, ylower, yupper);
-    getLog() << Log::TRACE << "Made 2D histogram "
-	     << hname <<  " for " << name() << endl;
+    MSG_TRACE("Made 2D histogram " << hname <<  " for " << name());
     hist->setXTitle(xtitle);
     hist->setYTitle(ytitle);
     hist->setZTitle(ztitle);
@@ -408,8 +416,7 @@
     const string path = histoPath(hname);
     IHistogram2D* hist =
       histogramFactory().createHistogram2D(path, title, xbinedges, ybinedges);
-    getLog() << Log::TRACE << "Made 2D histogram " << hname <<  " for "
-	     << name() << endl;
+    MSG_TRACE("Made 2D histogram " << hname <<  " for " << name());
     hist->setXTitle(xtitle);
     hist->setYTitle(ytitle);
     hist->setZTitle(ztitle);
@@ -436,7 +443,7 @@
     _makeHistoDir();
     const string path = histoPath(hname);
     IProfile1D* prof = histogramFactory().createProfile1D(path, title, edges);
-    getLog() << Log::TRACE << "Made profile histogram " << hname <<  " for " << name() << endl;
+    MSG_TRACE("Made profile histogram " << hname <<  " for " << name());
     prof->setXTitle(xtitle);
     prof->setYTitle(ytitle);
     return prof;
@@ -450,7 +457,7 @@
     _makeHistoDir();
     const string path = histoPath(hname);
     IProfile1D* prof = histogramFactory().createProfile1D(path, title, nbins, lower, upper);
-    getLog() << Log::TRACE << "Made profile histogram " << hname <<  " for " << name() << endl;
+    MSG_TRACE("Made profile histogram " << hname <<  " for " << name());
     prof->setXTitle(xtitle);
     prof->setYTitle(ytitle);
     return prof;
@@ -464,7 +471,7 @@
     _makeHistoDir();
     const string path = histoPath(hname);
     IProfile1D* prof = histogramFactory().createProfile1D(path, title, binedges);
-    getLog() << Log::TRACE << "Made profile histogram " << hname <<  " for " << name() << endl;
+    MSG_TRACE("Made profile histogram " << hname <<  " for " << name());
     prof->setXTitle(xtitle);
     prof->setYTitle(ytitle);
     return prof;
@@ -480,7 +487,7 @@
     _makeHistoDir();
     const string path = histoPath(hname);
     IDataPointSet* dps = datapointsetFactory().create(path, title, 2);
-    getLog() << Log::TRACE << "Made data point set " << hname <<  " for " << name() << endl;
+    MSG_TRACE("Made data point set " << hname <<  " for " << name());
     dps->setXTitle(xtitle);
     dps->setYTitle(ytitle);
     return dps;
@@ -549,12 +556,12 @@
 
   void Analysis::normalize(AIDA::IHistogram1D*& histo, double norm) {
     if (!histo) {
-      getLog() << Log::ERROR << "Failed to normalise histo=NULL in analysis "
-               << name() << " (norm=" << norm << ")" << endl;
+      MSG_ERROR("Failed to normalize histo=NULL in analysis "
+                << name() << " (norm=" << norm << ")");
       return;
     }
     const string hpath = tree().findPath(dynamic_cast<const AIDA::IManagedObject&>(*histo));
-    getLog() << Log::TRACE << "Normalizing histo " << hpath << " to " << norm << endl;
+    MSG_TRACE("Normalizing histo " << hpath << " to " << norm);
 
     double oldintg = 0.0;
     int nBins = histo->axis().bins();
@@ -563,7 +570,7 @@
       oldintg += histo->binHeight(iBin); // * histo->axis().binWidth(iBin);
     }
     if (oldintg == 0.0) {
-      getLog() << Log::WARN << "Histo " << hpath << " has null integral during normalisation" << endl;
+      MSG_WARNING("Histo " << hpath << " has null integral during normalization");
       return;
     }
 
@@ -574,12 +581,12 @@
 
   void Analysis::scale(AIDA::IHistogram1D*& histo, double scale) {
     if (!histo) {
-      getLog() << Log::ERROR << "Failed to scale histo=NULL in analysis "
-          << name() << " (scale=" << scale << ")" << endl;
+      MSG_ERROR("Failed to scale histo=NULL in analysis "
+                << name() << " (scale=" << scale << ")");
       return;
     }
     const string hpath = tree().findPath(dynamic_cast<const AIDA::IManagedObject&>(*histo));
-    getLog() << Log::TRACE << "Scaling histo " << hpath << endl;
+    MSG_TRACE("Scaling histo " << hpath);
 
     vector<double> x, y, ex, ey;
     for (size_t i = 0, N = histo->axis().bins(); i < N; ++i) {
@@ -616,12 +623,12 @@
 
   void Analysis::normalize(AIDA::IHistogram2D*& histo, double norm) {
     if (!histo) {
-      getLog() << Log::ERROR << "Failed to normalise histo=NULL in analysis "
-               << name() << " (norm=" << norm << ")" << endl;
+      MSG_ERROR("Failed to normalize histo=NULL in analysis "
+                << name() << " (norm=" << norm << ")");
       return;
     }
     const string hpath = tree().findPath(dynamic_cast<const AIDA::IManagedObject&>(*histo));
-    getLog() << Log::TRACE << "Normalizing histo " << hpath << " to " << norm << endl;
+    MSG_TRACE("Normalizing histo " << hpath << " to " << norm);
 
     double oldintg = 0.0;
     int nxBins = histo->xAxis().bins();
@@ -633,8 +640,7 @@
 	oldintg += histo->binHeight(ixBin, iyBin); // * histo->axis().binWidth(iBin);
     }
     if (oldintg == 0.0) {
-      getLog() << Log::WARN << "Histo " << hpath
-	       << " has null integral during normalisation" << endl;
+      MSG_WARNING("Histo " << hpath << " has null integral during normalization");
       return;
     }
 
@@ -645,13 +651,13 @@
 
   void Analysis::scale(AIDA::IHistogram2D*& histo, double scale) {
     if (!histo) {
-      getLog() << Log::ERROR << "Failed to scale histo=NULL in analysis "
-	       << name() << " (scale=" << scale << ")" << endl;
+      MSG_ERROR("Failed to scale histo=NULL in analysis "
+                << name() << " (scale=" << scale << ")");
       return;
     }
     const string hpath =
       tree().findPath(dynamic_cast<const AIDA::IManagedObject&>(*histo));
-    getLog() << Log::TRACE << "Scaling histo " << hpath << endl;
+    MSG_TRACE("Scaling histo " << hpath);
 
     vector<double> x, y, z, ex, ey, ez;
     for (size_t ix = 0, Nx = histo->xAxis().bins(); ix < Nx; ++ix)

Modified: trunk/src/Core/AnalysisHandler.cc
==============================================================================
--- trunk/src/Core/AnalysisHandler.cc	Sat Feb 26 20:33:12 2011	(r2980)
+++ trunk/src/Core/AnalysisHandler.cc	Sat Feb 26 20:44:35 2011	(r2981)
@@ -37,22 +37,11 @@
   }
 
 
-  // AnalysisHandler::AnalysisHandler(IAnalysisFactory& afac, string basefilename,
-  //                                  string runname, HistoFormat storetype)
-  //   : _runname(runname), _numEvents(0),
-  //     _sumOfWeights(0.0), _xs(-1.0), _initialised(false),
-  //     _theAnalysisFactory(&afac)
-  // {
-  //   _setupFactories(basefilename, storetype);
-  //   initializeParticleNames();
-  // }
-
-
   AnalysisHandler::~AnalysisHandler()
   {  }
 
 
-  Log& AnalysisHandler::getLog() {
+  Log& AnalysisHandler::getLog() const {
     return Log::getLog("Rivet.Analysis.Handler");
   }
 
@@ -64,24 +53,37 @@
     _numEvents = 0;
     _sumOfWeights = 0.0;
 
-    // Check that analyses are beam-compatible
+    // Check that analyses are beam-compatible, and remove those that aren't
     const size_t num_anas_requested = analysisNames().size();
-    removeIncompatibleAnalyses(beamIds());
+    vector<string> anamestodelete;
+    foreach (const AnaHandle a, _analyses) {
+      if (!a->isCompatible(beams())) {
+        //MSG_DEBUG(a->name() << " requires beams " << a->requiredBeams() << " @ " << a->requiredEnergies() << " GeV");
+        anamestodelete.push_back(a->name());
+      }
+    }
+    foreach (const string& aname, anamestodelete) {
+      MSG_WARNING("Removing incompatible analysis '" << aname << "'");
+      removeAnalysis(aname);
+    }
+    if (num_anas_requested > 0 && analysisNames().size() == 0) {
+      cerr << "All analyses were incompatible with the first event's beams\n"
+           << "Exiting, since this probably isn't intentional!" << endl;
+      exit(1);
+    }
+
+    // Warn if any analysis' status is not unblemished
     foreach (const AnaHandle a, analyses()) {
       if (toUpper(a->status()) == "PRELIMINARY") {
         MSG_WARNING("Analysis '" << a->name() << "' is preliminary: be careful, it may change and/or be renamed!");
       } else if (toUpper(a->status()) == "OBSOLETE") {
         MSG_WARNING("Analysis '" << a->name() << "' is obsolete: please update!");
-      } else if (toUpper(a->status()) != "VALIDATED") {
+      } else if (toUpper(a->status()).find("UNVALIDATED") != string::npos) {
         MSG_WARNING("Analysis '" << a->name() << "' is unvalidated: be careful, it may be broken!");
       }
     }
-    if (num_anas_requested > 0 && analysisNames().size() == 0) {
-      cerr     << "All analyses were incompatible with the first event's beams\n"
-               << "Exiting, since this probably isn't intentional!" << endl;
-      exit(1);
-    }
 
+    // Initialize the remaining analyses
     foreach (AnaHandle a, _analyses) {
       MSG_DEBUG("Initialising analysis: " << a->name());
       try {
@@ -91,8 +93,7 @@
         //MSG_DEBUG("Checking consistency of analysis: " << a->name());
         //a->checkConsistency();
       } catch (const Error& err) {
-        cerr     << "Error in " << a->name() << "::init method: "
-                 << err.what() << endl;
+        cerr << "Error in " << a->name() << "::init method: " << err.what() << endl;
         exit(1);
       }
       MSG_DEBUG("Done initialising analysis: " << a->name());
@@ -216,21 +217,6 @@
   }
 
 
-  AnalysisHandler& AnalysisHandler::removeIncompatibleAnalyses(const PdgIdPair& beams) {
-    vector<string> anamestodelete;
-    foreach (const AnaHandle a, _analyses) {
-      if (! a->isCompatible(beams)) {
-        anamestodelete.push_back(a->name());
-      }
-    }
-    foreach (const string& aname, anamestodelete) {
-      MSG_WARNING("Removing incompatible analysis '" << aname << "'");
-      removeAnalysis(aname);
-    }
-    return *this;
-  }
-
-
   void AnalysisHandler::_setupFactories(const string& basefilename, HistoFormat storetype) {
     string filename(basefilename), storetypestr("");
     if (storetype == AIDAML) {

Modified: trunk/src/Core/AnalysisInfo.cc
==============================================================================
--- trunk/src/Core/AnalysisInfo.cc	Sat Feb 26 20:33:12 2011	(r2980)
+++ trunk/src/Core/AnalysisInfo.cc	Sat Feb 26 20:44:35 2011	(r2981)
@@ -12,45 +12,29 @@
 namespace Rivet {
 
 
-  /// Ideas:
-  ///  * how to determine the name?
-  ///  * only populate pointer on Analysis when requested
-  ///  * use smart pointer: deletes automatically when Analysis
-  ///    goes out of scope
+  namespace {
+    Log& getLog() {
+      return Log::getLog("Rivet.AnalysisInfo");
+    }
+  }
 
 
   /// Static factory method
   AnalysisInfo* AnalysisInfo::make(const std::string& ananame) {
-    // Build the list of directories to search
-    vector<string> dirs = getAnalysisInfoPaths();
-    // And the current dir
-    // dirs += ".";
-
-    bool found = false;
-    string datapath = "";
-    foreach (const string& d, dirs) {
-      if (d.empty()) continue;
-      /// @todo Use system-independent separator (e.g. Boost.File)
-      datapath = d + "/" + ananame + ".info";
-      Log::getLog("Rivet.AnalysisInfo")
-        << Log::TRACE << "Looking for analysis data file '" << datapath << "'" << endl;
-      if (access(datapath.c_str(), R_OK) == 0) {
-        found = true;
-        break;
-      }
-    }
-
     // Returned AI, in semi-null state
     AnalysisInfo* ai = new AnalysisInfo();
-    ai->_beams += make_pair(ANY,ANY);
+    ai->_beams += make_pair(ANY, ANY);
     ai->_name = ananame;
 
     /// If no ana data file found, return null AI
-    if (!found) return ai;
+    const string datapath = findAnalysisInfoFile(ananame + ".info");
+    if (datapath.empty()) {
+      MSG_DEBUG("No datafile " << ananame + ".info found");
+      return ai;
+    }
 
     // Read data from YAML document
-    Log::getLog("Rivet.AnalysisInfo")
-      << Log::DEBUG << "Reading analysis data from " << datapath << endl;
+    MSG_DEBUG("Reading analysis data from " << datapath);
     std::ifstream io(datapath.c_str());
     YAML::Parser parser(io);
     YAML::Node doc;
@@ -58,9 +42,7 @@
       parser.GetNextDocument(doc);
       //cout << doc << endl;
     } catch (const YAML::ParserException& ex) {
-      Log::getLog("Rivet.AnalysisInfo")
-        << Log::ERROR << "Parse error when reading analysis data from "
-        << datapath << endl;
+      MSG_ERROR("Parse error when reading analysis data from " << datapath);
       return ai;
     }
 
@@ -70,8 +52,7 @@
       stringstream sec;
       // sec << it.second();
       // const string secstr = sec.str().substr(0, sec.str().length()-1);
-      // Log::getLog("Rivet.AnalysisInfo")
-      //   << Log::TRACE << key << ": " << secstr << endl;
+      // MSG_TRACE(key << ": " << secstr);
       try {
         if (key == "Name") {
           it.second() >> ai->_name;
@@ -182,7 +163,7 @@
           << key << "' from " << datapath << endl;
       }
     }
-    Log::getLog("Rivet.AnalysisInfo") << Log::TRACE << "AnalysisInfo pointer = " << ai << endl;
+    MSG_TRACE("AnalysisInfo pointer = " << ai);
     return ai;
   }
 


More information about the Rivet-svn mailing list