AnalysisHandler Class Reference
Collaboration diagram for AnalysisHandler:
![]()
Detailed DescriptionA class which handles a number of analysis objects to be applied to generated events. An Analysis' AnalysisHandler is also responsible for handling the final writing-out of histograms. Definition at line 29 of file AnalysisHandler.hh. Constructor & Destructor Documentation
Preferred constructor, with optional run name. Definition at line 22 of file AnalysisHandler.cc. : _runname(runname), _numEvents(0), _sumOfWeights(0.0), _xs(-1.0), _initialised(false), _ignoreBeams(false) {}
Destructor The destructor is not virtual, as this class should not be inherited from. Definition at line 28 of file AnalysisHandler.cc. {}
The copy constructor is private and must never be called. In fact, it should not even be implemented. Member Function Documentation
Add analyses to the run list using their names. The actual Analysis' to be used will be obtained via AnalysisHandler::addAnalysis(string), which in turn uses AnalysisHandler::getAnalysis(string). If no matching analysis is found for a given name, no analysis is added, but also no error is thrown. Definition at line 232 of file AnalysisHandler.cc. References AnalysisHandler::addAnalysis(). { foreach (const string& aname, analysisnames) { //MSG_DEBUG("Adding analysis '" << aname << "'"); addAnalysis(aname); } return *this; }
Add an analysis to the run list using its name. The actual Analysis to be used will be obtained via AnalysisHandler::getAnalysis(string). If no matching analysis is found, no analysis is added (i.e. the null pointer is checked and discarded.
Definition at line 165 of file AnalysisHandler.cc. References AnalysisHandler::_analyses, AnalysisLoader::getAnalysis(), MSG_DEBUG, and MSG_WARNING. Referenced by AnalysisHandler::addAnalyses(). { // Check for a duplicate analysis /// @todo Might we want to be able to run an analysis twice, with different params? /// Requires avoiding histo tree clashes, i.e. storing the histos on the analysis objects. foreach (const AnaHandle& a, _analyses) { if (a->name() == analysisname) { MSG_WARNING("Analysis '" << analysisname << "' already registered: skipping duplicate"); return *this; } } AnaHandle analysis( AnalysisLoader::getAnalysis(analysisname) ); if (analysis.get() != 0) { // < Check for null analysis. MSG_DEBUG("Adding analysis '" << analysisname << "'"); analysis->_analysishandler = this; _analyses.insert(analysis); } else { MSG_WARNING("Analysis '" << analysisname << "' not found."); } return *this; }
Add an analysis to the run list by object. Definition at line 273 of file AnalysisHandler.cc. References AnalysisHandler::_analyses, and Analysis::_analysishandler.
Get the collection of currently registered analyses. Definition at line 121 of file AnalysisHandler.hh. References AnalysisHandler::_analyses. Referenced by AnalysisHandler::init(). { return _analyses; }
Get a list of the currently registered analyses' names. Definition at line 223 of file AnalysisHandler.cc. References AnalysisHandler::_analyses. Referenced by Run::init(), and AnalysisHandler::init().
Analyze the given event. This function will call the AnalysisBase::analyze() function of all included analysis objects. Definition at line 94 of file AnalysisHandler.cc. References AnalysisHandler::_analyses, AnalysisHandler::_beams, AnalysisHandler::_initialised, AnalysisHandler::_numEvents, AnalysisHandler::_sumOfWeights, AnalysisHandler::beamIds(), AnalysisHandler::beams(), Rivet::compatible(), Rivet::fuzzyEquals(), Rivet::GeV, AnalysisHandler::init(), MSG_DEBUG, AnalysisHandler::setCrossSection(), AnalysisHandler::sqrtS(), and Rivet::toBeamsString(). Referenced by Run::processEvent(). { // Call init with event as template if not already initialised if (!_initialised) { init(ge); } // Proceed with event analysis assert(_initialised); // Ensure that beam details match those from first event const PdgIdPair beams = Rivet::beamIds(ge); const double sqrts = Rivet::sqrtS(ge); if (!compatible(beams, _beams) || !fuzzyEquals(sqrts, sqrtS())) { cerr << "Event beams mismatch: " << toBeamsString(beams) << " @ " << sqrts/GeV << " GeV" << " vs. first beams " << this->beams() << " @ " << this->sqrtS()/GeV << " GeV" << endl; exit(1); } Event event(ge); _numEvents++; // Weights const double weight = event.weight(); _sumOfWeights += weight; MSG_DEBUG("Event #" << _numEvents << " weight = " << weight); #ifdef HEPMC_HAS_CROSS_SECTION if (ge.cross_section()) { const double xs = ge.cross_section()->cross_section(); setCrossSection(xs); } #endif foreach (AnaHandle a, _analyses) { //MSG_DEBUG("About to run analysis " << a->name()); try { a->analyze(event); } catch (const Error& err) { cerr << "Error in " << a->name() << "::analyze method: " << err.what() << endl; exit(1); } //MSG_DEBUG("Finished running analysis " << a->name()); } } Get beam IDs for this run, usually determined from the first event. Definition at line 280 of file AnalysisHandler.cc. References AnalysisHandler::beams(). Referenced by AnalysisHandler::analyze(), and Analysis::beamIds(). { return Rivet::beamIds(beams()); }
Get beam IDs for this run, usually determined from the first event. Definition at line 98 of file AnalysisHandler.hh. References AnalysisHandler::_beams. Referenced by AnalysisHandler::analyze(), AnalysisHandler::beamIds(), Analysis::beams(), AnalysisHandler::init(), AnalysisHandler::setRunBeams(), and AnalysisHandler::sqrtS(). { return _beams; }
Get the cross-section known to the handler. Definition at line 82 of file AnalysisHandler.hh. References AnalysisHandler::_xs. Referenced by Run::crossSection(), and AnalysisHandler::hasCrossSection(). { return _xs; }
Finalize a run. This function calls the AnalysisBase::finalize() functions of all included analysis objects. Definition at line 138 of file AnalysisHandler.cc. References AnalysisHandler::_analyses, AnalysisHandler::_initialised, AnalysisHandler::_numEvents, and MSG_INFO. { assert(_initialised); MSG_INFO("Finalising analyses"); foreach (AnaHandle a, _analyses) { try { a->finalize(); } catch (const Error& err) { cerr << "Error in " << a->name() << "::finalize method: " << err.what() << endl; exit(1); } } // Print out number of events processed MSG_INFO("Processed " << _numEvents << " event" << (_numEvents == 1 ? "" : "s")); // // Delete analyses // MSG_DEBUG("Deleting analyses"); // _analyses.clear(); // Print out MCnet boilerplate cout << endl; cout << "The MCnet usage guidelines apply to Rivet: see http://www.montecarlonet.org/GUIDELINES" << endl; cout << "Please acknowledge plots made with Rivet analyses, and cite arXiv:1003.0694 (http://arxiv.org/abs/1003.0694)" << endl; } Get a logger object. Definition at line 32 of file AnalysisHandler.cc. { return Log::getLog("Rivet.Analysis.Handler"); }
Whether the handler knows about a cross-section. Definition at line 268 of file AnalysisHandler.cc. References AnalysisHandler::crossSection(). Referenced by Run::processEvent(). { return (!std::isnan(crossSection())); }
Initialize a run, with the run beams taken from the example event. Definition at line 37 of file AnalysisHandler.cc. References AnalysisHandler::_analyses, AnalysisHandler::_ignoreBeams, AnalysisHandler::_initialised, AnalysisHandler::_numEvents, AnalysisHandler::_sumOfWeights, AnalysisHandler::analyses(), AnalysisHandler::analysisNames(), Rivet::beams(), AnalysisHandler::beams(), MSG_DEBUG, MSG_WARNING, AnalysisHandler::removeAnalysis(), AnalysisHandler::setRunBeams(), and Rivet::toUpper(). Referenced by AnalysisHandler::analyze(), and Run::init(). { assert(!_initialised); setRunBeams(Rivet::beams(ge)); MSG_DEBUG("Initialising the analysis handler"); _numEvents = 0; _sumOfWeights = 0.0; // Check that analyses are beam-compatible, and remove those that aren't const size_t num_anas_requested = analysisNames().size(); vector<string> anamestodelete; foreach (const AnaHandle a, _analyses) { if ((!a->isCompatible(beams())) && (!_ignoreBeams)) { //MSG_DEBUG(a->name() << " requires beams " << a->requiredBeams() << " @ " << a->requiredEnergies() << " GeV"); anamestodelete.push_back(a->name()); } } foreach (const string& aname, anamestodelete) { MSG_WARNING("Analysis '" << aname << "' is incompatible with the provided beams: removing"); 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 wasn'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()).find("UNVALIDATED") != string::npos) { MSG_WARNING("Analysis '" << a->name() << "' is unvalidated: be careful, it may be broken!"); } } // Initialize the remaining analyses foreach (AnaHandle a, _analyses) { MSG_DEBUG("Initialising analysis: " << a->name()); try { // Allow projection registration in the init phase onwards a->_allowProjReg = true; a->init(); //MSG_DEBUG("Checking consistency of analysis: " << a->name()); //a->checkConsistency(); } catch (const Error& err) { cerr << "Error in " << a->name() << "::init method: " << err.what() << endl; exit(1); } MSG_DEBUG("Done initialising analysis: " << a->name()); } _initialised = true; MSG_DEBUG("Analysis handler initialised"); }
Is cross-section information required by at least one child analysis? Definition at line 249 of file AnalysisHandler.cc. References AnalysisHandler::_analyses. Referenced by Run::processEvent().
Get the number of events seen. Should only really be used by external steering code or analyses in the finalize phase. Definition at line 214 of file AnalysisHandler.cc. References AnalysisHandler::_numEvents. Referenced by Analysis::numEvents(). { return _numEvents; }
The assignment operator is private and must never be called. In fact, it should not even be implemented.
Remove analyses from the run list using their names. Definition at line 241 of file AnalysisHandler.cc. References AnalysisHandler::removeAnalysis(). { foreach (const string& aname, analysisnames) { removeAnalysis(aname); } return *this; }
Remove an analysis from the run list using its name. Definition at line 187 of file AnalysisHandler.cc. References AnalysisHandler::_analyses, and MSG_DEBUG. Referenced by AnalysisHandler::init(), and AnalysisHandler::removeAnalyses().
Get the name of this run. Definition at line 213 of file AnalysisHandler.cc. References AnalysisHandler::_runname. Referenced by Analysis::histoDir(). { return _runname; }
Set the cross-section for the process being generated. Definition at line 259 of file AnalysisHandler.cc. References AnalysisHandler::_analyses, and AnalysisHandler::_xs. Referenced by AnalysisHandler::analyze(), Run::init(), and Run::processEvent().
Setter for _ignoreBeams. Definition at line 289 of file AnalysisHandler.cc. References AnalysisHandler::_ignoreBeams. { _ignoreBeams=ignore; }
Set beams for this run. Definition at line 91 of file AnalysisHandler.hh. References AnalysisHandler::_beams, AnalysisHandler::beams(), Rivet::GeV, MSG_DEBUG, and AnalysisHandler::sqrtS(). Referenced by AnalysisHandler::init().
Set sum of weights. This is useful if Rivet is steered externally and the analyses are run for a sub-contribution of the events (but of course have to be normalised to the total sum of weights) Definition at line 218 of file AnalysisHandler.cc. References AnalysisHandler::_sumOfWeights. { _sumOfWeights=sum; }
Get energy for this run, usually determined from the first event. Definition at line 285 of file AnalysisHandler.cc. References AnalysisHandler::beams(). Referenced by AnalysisHandler::analyze(), AnalysisHandler::setRunBeams(), and Analysis::sqrtS(). { return Rivet::sqrtS(beams()); }
Get the sum of the event weights seen - the weighted equivalent of the number of events. Should only really be used by external steering code or analyses in the finalize phase. Definition at line 215 of file AnalysisHandler.cc. References AnalysisHandler::_sumOfWeights. Referenced by Analysis::sumOfWeights(). { return _sumOfWeights; }
Write all analyses' plots to the named file. Definition at line 202 of file AnalysisHandler.cc. References AnalysisHandler::_analyses. { vector<AnalysisObjectPtr> allPlots; foreach (const AnaHandle a, _analyses) { vector<AnalysisObjectPtr> plots = a->plots(); sort(plots.begin(), plots.end(), AOSortByPath); allPlots.insert(allPlots.end(), plots.begin(), plots.end()); } WriterYODA::write(filename, allPlots.begin(), allPlots.end()); } Member Data Documentation
The collection of Analysis objects to be used. Definition at line 178 of file AnalysisHandler.hh. Referenced by AnalysisHandler::addAnalysis(), AnalysisHandler::analyses(), AnalysisHandler::analysisNames(), AnalysisHandler::analyze(), AnalysisHandler::finalize(), AnalysisHandler::init(), AnalysisHandler::needCrossSection(), AnalysisHandler::removeAnalysis(), AnalysisHandler::setCrossSection(), and AnalysisHandler::writeData().
Beams used by this run. Definition at line 197 of file AnalysisHandler.hh. Referenced by AnalysisHandler::analyze(), AnalysisHandler::beams(), and AnalysisHandler::setRunBeams().
Flag whether input event beams should be ignored in compatibility check. Definition at line 203 of file AnalysisHandler.hh. Referenced by AnalysisHandler::init(), and AnalysisHandler::setIgnoreBeams().
Flag to check if init has been called. Definition at line 200 of file AnalysisHandler.hh. Referenced by AnalysisHandler::analyze(), AnalysisHandler::finalize(), and AnalysisHandler::init().
Number of events seen. Definition at line 188 of file AnalysisHandler.hh. Referenced by AnalysisHandler::analyze(), AnalysisHandler::finalize(), AnalysisHandler::init(), and AnalysisHandler::numEvents().
Run name. Definition at line 185 of file AnalysisHandler.hh. Referenced by AnalysisHandler::runName().
Sum of event weights seen. Definition at line 191 of file AnalysisHandler.hh. Referenced by AnalysisHandler::analyze(), AnalysisHandler::init(), AnalysisHandler::setSumOfWeights(), and AnalysisHandler::sumOfWeights().
Cross-section known to AH. Definition at line 194 of file AnalysisHandler.hh. Referenced by AnalysisHandler::crossSection(), and AnalysisHandler::setCrossSection(). The documentation for this class was generated from the following files: Generated on Fri Dec 21 2012 15:03:50 for The Rivet MC analysis system by ![]() |