|
[Rivet-svn] r2121 - in trunk: . include/Rivet include/Rivet/Math pyext srcblackhole at projects.hepforge.org blackhole at projects.hepforge.orgTue Dec 1 17:04:36 GMT 2009
Author: buckley Date: Tue Dec 1 17:04:36 2009 New Revision: 2121 Log: Various overhauls to (prepare) moving beam info more cleanly into the metadata system. Modified: trunk/ChangeLog trunk/include/Rivet/Analysis.hh trunk/include/Rivet/AnalysisInfo.hh trunk/include/Rivet/Math/MathUtils.hh trunk/include/Rivet/ParticleName.hh trunk/pyext/rivet.i trunk/src/Analysis.cc trunk/src/AnalysisInfo.cc trunk/src/Makefile.am Modified: trunk/ChangeLog ============================================================================== --- trunk/ChangeLog Tue Dec 1 14:30:45 2009 (r2120) +++ trunk/ChangeLog Tue Dec 1 17:04:36 2009 (r2121) @@ -1,3 +1,7 @@ +2009-12-01 Andy Buckley <andy at insectnation.org> + + * Adding parsing of beam types and pairs of energies from YAML. + 2009-12-01 Hendrik Hoeth <hendrik.hoeth at cern.ch> * Fixing trigger efficiency in CDF_2009_S8233977 Modified: trunk/include/Rivet/Analysis.hh ============================================================================== --- trunk/include/Rivet/Analysis.hh Tue Dec 1 14:30:45 2009 (r2120) +++ trunk/include/Rivet/Analysis.hh Tue Dec 1 17:04:36 2009 (r2121) @@ -93,6 +93,9 @@ /// building web pages and the analysis pages in the Rivet manual. //@{ + /// Get the actual AnalysisInfo object in which all this metadata is stored. + virtual const AnalysisInfo& info() const; + /// @brief Get the name of the analysis. /// /// By default this is computed by combining the results of the experiment, @@ -138,7 +141,10 @@ virtual std::string collider() const; /// Incoming beams required by this analysis. - virtual const BeamPair& beams() const; + virtual const std::pair<ParticleName, ParticleName>& beams() 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. /// @@ -151,13 +157,14 @@ /// Whether this analysis is trusted (in any way!) virtual std::string status() const; + //@} public: /// Return the pair of incoming beams required by this analysis. - virtual const BeamPair& requiredBeams() const; + virtual const BeamPair requiredBeams() const; /// Is this analysis able to run on the supplied pair of beams? virtual bool isCompatible(const ParticleName& beam1, const ParticleName& beam2) const; @@ -190,6 +197,7 @@ /// Return true if this analysis needs to know the process cross-section. bool needsCrossSection() const; + protected: /// Get the process cross-section in pb. Throws if this hasn't been set. @@ -357,6 +365,7 @@ /// Make the axis code string (dsDD-xXX-yYY) string _makeAxisCode(const size_t datasetId, const size_t xAxisId, const size_t yAxisId) const; + //@} @@ -387,9 +396,6 @@ bool _needsCrossSection; //@} - /// Allowed beam-type pair. - BeamPair _beams; - /// The controlling AnalysisHandler object. AnalysisHandler* _analysishandler; @@ -406,10 +412,13 @@ /// @todo Reduce memory occupancy, or clear after initialisation? map<string, BinEdges> _histBinEdges; + private: + /// The assignment operator is private and must never be called. /// In fact, it should not even be implemented. Analysis& operator=(const Analysis&); + }; Modified: trunk/include/Rivet/AnalysisInfo.hh ============================================================================== --- trunk/include/Rivet/AnalysisInfo.hh Tue Dec 1 14:30:45 2009 (r2120) +++ trunk/include/Rivet/AnalysisInfo.hh Tue Dec 1 17:04:36 2009 (r2121) @@ -8,23 +8,27 @@ namespace Rivet { - class AnalysisInfo { - + class AnalysisInfo { + /// @todo Remove this when all metadata taken from YAML + friend class Analysis; + public: /// Static factory method: returns null pointer if no metadata found static AnalysisInfo* make(const std::string& name); - /// @name Standard constructors and destructors. //@{ + /// The default constructor. AnalysisInfo() { } /// The destructor. ~AnalysisInfo() { } + //@} + public: /// @name Metadata @@ -69,6 +73,12 @@ /// stable, etc. etc. Should be treated as a restructuredText bullet list /// (http://docutils.sourceforge.net/rst.html) const std::string& runInfo() const { return _runInfo; } + + /// Beam particle types + const std::pair<ParticleName,ParticleName>& beams() const { return _beams; } + + /// Sets of valid beam energy pairs + const std::vector<std::pair<double,double> >& energies() const { return _energies; } /// Experiment which performed and published this analysis. const std::string& experiment() const { return _experiment; } @@ -104,7 +114,8 @@ std::string _runInfo; std::string _experiment; std::string _collider; - //std::pair<BeamParticle,BeamParticle> _beams; + std::pair<ParticleName, ParticleName> _beams; + std::vector<std::pair<double, double> > _energies; std::string _year; std::vector<std::string> _references; std::string _status; Modified: trunk/include/Rivet/Math/MathUtils.hh ============================================================================== --- trunk/include/Rivet/Math/MathUtils.hh Tue Dec 1 14:30:45 2009 (r2120) +++ trunk/include/Rivet/Math/MathUtils.hh Tue Dec 1 17:04:36 2009 (r2121) @@ -71,8 +71,9 @@ /// Determine if @a value is in the range @a low to @a high, with boundary /// types defined by @a lowbound and @a highbound. /// @todo Optimise to one-line at compile time? - inline bool inRange(double value, double low, double high, - RangeBoundary lowbound=OPEN, RangeBoundary highbound=OPEN) { + template<typename NUM> + inline bool inRange(NUM value, NUM low, NUM high, + RangeBoundary lowbound=CLOSED, RangeBoundary highbound=OPEN) { if (lowbound == OPEN && highbound == OPEN) { return (value > low && value < high); } else if (lowbound == OPEN && highbound == CLOSED) { @@ -88,7 +89,7 @@ /// Determine if @a value is in the range @a low to @a high, with boundary /// types defined by @a lowbound and @a highbound. /// @todo Optimise to one-line at compile time? - inline bool inRange(long value, long low, long high, + inline bool inRange(int value, int low, int high, RangeBoundary lowbound=CLOSED, RangeBoundary highbound=CLOSED) { if (lowbound == OPEN && highbound == OPEN) { return (value > low && value < high); Modified: trunk/include/Rivet/ParticleName.hh ============================================================================== --- trunk/include/Rivet/ParticleName.hh Tue Dec 1 14:30:45 2009 (r2120) +++ trunk/include/Rivet/ParticleName.hh Tue Dec 1 17:04:36 2009 (r2121) @@ -64,7 +64,7 @@ }; /// Typedef for a PDG ID code. - typedef long PdgId; + typedef int PdgId; /// Convenience maker of particle ID pairs. inline std::pair<PdgId,PdgId> make_pdgid_pair(PdgId a, PdgId b) { @@ -76,6 +76,11 @@ return make_pdgid_pair(aname, bname); } + /// Convenience maker of particle ID pairs. + inline std::pair<PdgId,PdgId> make_pdgid_pair(std::pair<ParticleName,ParticleName> pnamepair) { + return make_pdgid_pair(pnamepair.first, pnamepair.second); + } + /// Typedef for a map of beam particle name enums to strings. typedef std::map<PdgId, std::string> ParticleNameMap; @@ -120,6 +125,7 @@ return bpmap; } + /// Function which returns a map from beam particle name strings to the corresponding enums. inline ParticleNameMapR getParticleNamesRMap() { ParticleNameMap bpmap = getParticleNamesMap(); @@ -147,8 +153,7 @@ } - /// Function which returns a vector of all the beam particle values in - /// the ParticleName enum. + /// Function which converts a particle name string to a ParticleName enum inline ParticleName getParticleNameEnum(const std::string& pname) { return (ParticleName) Rivet::getParticleNamesRMap()[pname]; } Modified: trunk/pyext/rivet.i ============================================================================== --- trunk/pyext/rivet.i Tue Dec 1 14:30:45 2009 (r2120) +++ trunk/pyext/rivet.i Tue Dec 1 17:04:36 2009 (r2121) @@ -81,6 +81,8 @@ virtual std::string collider() const; virtual std::string year() const; virtual std::string status() const; + // const std::pair<ParticleName,ParticleName>& beams() const { return _beams; } + // const std::vector<std::pair<double,double> >& energies() const { return _energies; } virtual std::vector<std::string> authors() const; virtual std::vector<std::string> references() const; virtual const BeamPair& beams() const; Modified: trunk/src/Analysis.cc ============================================================================== --- trunk/src/Analysis.cc Tue Dec 1 14:30:45 2009 (r2120) +++ trunk/src/Analysis.cc Tue Dec 1 17:04:36 2009 (r2121) @@ -20,8 +20,11 @@ { ProjectionApplier::_allowProjReg = false; _defaultname = name; - _info.reset( AnalysisInfo::make(name) ); - setBeams(ANY, ANY); + AnalysisInfo* ai = AnalysisInfo::make(name); + assert(ai != 0); + _info.reset(ai); + assert(_info.get() != 0); + //setBeams(ANY, ANY); } @@ -86,72 +89,81 @@ //////////////////////////////////////////////////////////// // Metadata - std::string Analysis::name() const { + const AnalysisInfo& Analysis::info() const { + assert(_info.get() != 0); + return *_info; + } + + string Analysis::name() const { if (_info && !_info->name().empty()) return _info->name(); return _defaultname; } - std::string Analysis::spiresId() const { + string Analysis::spiresId() const { if (!_info) return "NONE"; return _info->spiresId(); } - std::vector<std::string> Analysis::authors() const { + vector<string> Analysis::authors() const { if (!_info) return std::vector<std::string>(); return _info->authors(); } - std::string Analysis::summary() const { + string Analysis::summary() const { if (!_info) return "NONE"; return _info->summary(); } - std::string Analysis::description() const { + string Analysis::description() const { if (!_info) return "NONE"; return _info->description(); } - std::string Analysis::runInfo() const { + string Analysis::runInfo() const { if (!_info) return "NONE"; return _info->runInfo(); } - std::string Analysis::experiment() const { + const std::pair<ParticleName,ParticleName>& Analysis::beams() const { + return info().beams(); + } + + const std::vector<std::pair<double,double> >& Analysis::energies() const { + return info().energies(); + } + + string Analysis::experiment() const { if (!_info) return "NONE"; return _info->experiment(); } - std::string Analysis::collider() const { + string Analysis::collider() const { if (!_info) return "NONE"; return _info->collider(); } - const BeamPair& Analysis::beams() const { - return _beams; - } - - std::string Analysis::year() const { + string Analysis::year() const { if (!_info) return "NONE"; return _info->year(); } - std::vector<std::string> Analysis::references() const { - if (!_info) return std::vector<std::string>(); + vector<string> Analysis::references() const { + if (!_info) return vector<string>(); return _info->references(); } - std::string Analysis::status() const { + string Analysis::status() const { if (!_info) return "UNVALIDATED"; return _info->status(); } - const BeamPair& Analysis::requiredBeams() const { - return _beams; + const BeamPair Analysis::requiredBeams() const { + return make_pdgid_pair(info().beams()); } Analysis& Analysis::setBeams(const ParticleName& beam1, const ParticleName& beam2) { - _beams.first = beam1; - _beams.second = beam2; + assert(_info.get() != 0); + _info->_beams = make_pair(beam1, beam2); return *this; } @@ -304,7 +316,7 @@ } - IProfile1D* Analysis::bookProfile1D(const std::string& hname, const std::string& title, + IProfile1D* Analysis::bookProfile1D(const string& hname, const string& title, const string& xtitle, const string& ytitle) { // Get the bin edges (only read the AIDA file once) @@ -466,7 +478,7 @@ const string hpath = tree().findPath(dynamic_cast<const AIDA::IManagedObject&>(*histo)); getLog() << Log::TRACE << "Scaling histo " << hpath << endl; - std::vector<double> x, y, ex, ey; + vector<double> x, y, ex, ey; for (size_t i = 0, N = histo->axis().bins(); i < N; ++i) { x.push_back(0.5 * (histo->axis().binLowerEdge(i) + histo->axis().binUpperEdge(i))); ex.push_back(histo->axis().binWidth(i)*0.5); @@ -480,9 +492,9 @@ ey.push_back(histo->binError(i)*scale/(0.5*histo->axis().binWidth(i))); } - std::string title = histo->title(); - std::string xtitle = histo->xtitle(); - std::string ytitle = histo->ytitle(); + string title = histo->title(); + string xtitle = histo->xtitle(); + string ytitle = histo->ytitle(); tree().mkdir("/tmpnormalize"); tree().mv(hpath, "/tmpnormalize"); Modified: trunk/src/AnalysisInfo.cc ============================================================================== --- trunk/src/AnalysisInfo.cc Tue Dec 1 14:30:45 2009 (r2120) +++ trunk/src/AnalysisInfo.cc Tue Dec 1 17:04:36 2009 (r2121) @@ -44,8 +44,14 @@ break; } } - /// If no ana data file found, return null pointer - if (!found) return 0; + + // Returned AI, in semi-null state + AnalysisInfo* ai = new AnalysisInfo(); + ai->_beams = make_pair(ANY,ANY); + ai->_name = ananame; + + /// If no ana data file found, return null AI + if (!found) return ai; // Read data from YAML document Log::getLog("Rivet.AnalysisInfo") @@ -60,10 +66,9 @@ Log::getLog("Rivet.AnalysisInfo") << Log::ERROR << "Parse error when reading analysis data from " << datapath << endl; - return 0; + return ai; } - AnalysisInfo* ai = new AnalysisInfo(); for (YAML::Iterator it = doc.begin(); it != doc.end(); ++it) { string key; it.first() >> key; @@ -80,9 +85,42 @@ } else if (key == "Experiment") { it.second() >> ai->_experiment; } else if (key == "Beams") { - // it.second() >> ai->_beams; - } else if (key == "NeedCrossSection") { - // it.second() >> ai->_needsCrossSection; + const YAML::Node& beams = it.second(); + vector<ParticleName> beampair; + for (YAML::Iterator b = beams.begin(); b != beams.end(); ++b) { + string bstr; + *b >> bstr; + ParticleName beamname = getParticleNameEnum(bstr); + beampair += beamname; + } + assert(beampair.size() == 2); + ai->_beams = make_pair<ParticleName,ParticleName>(beampair[0], beampair[1]); + // } else if (key == "NeedCrossSection") { + // // it.second() >> ai->_needsCrossSection; + } else if (key == "Energies") { + const YAML::Node& energies = it.second(); + vector<pair<double,double> > beam_energy_pairs; + for (YAML::Iterator be = energies.begin(); be != energies.end(); ++be) { + if (be->GetType() == YAML::CT_SCALAR) { + // If beam energy is a scalar, then assume symmetric beams each with half that energy + double sqrts; + *be >> sqrts; + beam_energy_pairs += make_pair(sqrts/2.0, sqrts/2.0); + } else if (be->GetType() == YAML::CT_SEQUENCE) { + const YAML::Node& beamenergy_strs = be.second(); + vector<double> beamenergies; + for (YAML::Iterator e = beamenergy_strs.begin(); e != beamenergy_strs.end(); ++e) { + double beamenergy; + *e >> beamenergy; + beamenergies += beamenergy; + } + assert(beamenergies.size() == 2); + beam_energy_pairs += make_pair(beamenergies[0], beamenergies[1]); + } else { + assert(0 && "Beam energies have to be a list of either numbers or pairs of numbers"); + } + } + ai->_energies = beam_energy_pairs; } else if (key == "Collider") { it.second() >> ai->_collider; } else if (key == "SpiresID") { @@ -116,7 +154,7 @@ << key << "' from " << datapath << endl; } } - //cout << *ai << endl; + Log::getLog("Rivet.AnalysisInfo") << Log::DEBUG << ai << endl; return ai; } @@ -125,6 +163,8 @@ stringstream ss; ss << ai.name(); ss << " - " << ai.summary(); + // ss << " - " << ai.beams(); + // ss << " - " << ai.energies(); ss << " (" << ai.status() << ")"; return ss.str(); } Modified: trunk/src/Makefile.am ============================================================================== --- trunk/src/Makefile.am Tue Dec 1 14:30:45 2009 (r2120) +++ trunk/src/Makefile.am Tue Dec 1 17:04:36 2009 (r2121) @@ -1,5 +1,4 @@ -SUBDIRS = Projections -SUBDIRS += Tools . Test +SUBDIRS = . Projections Tools Test if ENABLE_ANALYSES SUBDIRS += Analyses endif
More information about the Rivet-svn mailing list |