AnalysisHandler.hh
Go to the documentation of this file.
00001 // -*- C++ -*- 00002 #ifndef RIVET_RivetHandler_HH 00003 #define RIVET_RivetHandler_HH 00004 00005 #include "Rivet/Config/RivetCommon.hh" 00006 #include "Rivet/Particle.hh" 00007 #include "Rivet/AnalysisLoader.hh" 00008 #include "Rivet/Tools/RivetYODA.hh" 00009 00010 namespace Rivet { 00011 00012 00013 // Forward declaration and smart pointer for Analysis 00014 class Analysis; 00015 typedef std::shared_ptr<Analysis> AnaHandle; 00016 00017 00018 // Needed to make smart pointers compare equivalent in the STL set 00019 struct CmpAnaHandle { 00020 bool operator() (const AnaHandle& a, const AnaHandle& b) { 00021 return a.get() < b.get(); 00022 } 00023 }; 00024 00025 00026 /// A class which handles a number of analysis objects to be applied to 00027 /// generated events. An {@link Analysis}' AnalysisHandler is also responsible 00028 /// for handling the final writing-out of histograms. 00029 class AnalysisHandler { 00030 public: 00031 00032 /// @name Constructors and destructors. */ 00033 //@{ 00034 00035 /// Preferred constructor, with optional run name. 00036 AnalysisHandler(const string& runname=""); 00037 00038 /// @brief Destructor 00039 /// The destructor is not virtual, as this class should not be inherited from. 00040 ~AnalysisHandler(); 00041 00042 //@} 00043 00044 00045 private: 00046 00047 /// Get a logger object. 00048 Log& getLog() const; 00049 00050 00051 public: 00052 00053 /// @name Run properties 00054 //@{ 00055 00056 /// Get the name of this run. 00057 string runName() const; 00058 00059 00060 /// Get the number of events seen. Should only really be used by external 00061 /// steering code or analyses in the finalize phase. 00062 size_t numEvents() const; 00063 00064 /// Get the sum of the event weights seen - the weighted equivalent of the 00065 /// number of events. Should only really be used by external steering code 00066 /// or analyses in the finalize phase. 00067 double sumOfWeights() const; 00068 00069 /// Set sum of weights. This is useful if Rivet is steered externally and 00070 /// the analyses are run for a sub-contribution of the events 00071 /// (but of course have to be normalised to the total sum of weights) 00072 void setSumOfWeights(const double& sum); 00073 00074 00075 /// Is cross-section information required by at least one child analysis? 00076 bool needCrossSection() const; 00077 00078 /// Set the cross-section for the process being generated. 00079 AnalysisHandler& setCrossSection(double xs); 00080 00081 /// Get the cross-section known to the handler. 00082 double crossSection() const { 00083 return _xs; 00084 } 00085 00086 /// Whether the handler knows about a cross-section. 00087 bool hasCrossSection() const; 00088 00089 00090 /// Set the beam particles for this run 00091 AnalysisHandler& setRunBeams(const ParticlePair& beams) { 00092 _beams = beams; 00093 MSG_DEBUG("Setting run beams = " << beams << " @ " << sqrtS()/GeV << " GeV"); 00094 return *this; 00095 } 00096 00097 /// Get the beam particles for this run, usually determined from the first event. 00098 const ParticlePair& beams() const { return _beams; } 00099 00100 /// Get beam IDs for this run, usually determined from the first event. 00101 /// @deprecated Use standalone beamIds(ah.beams()), to clean AH interface 00102 PdgIdPair beamIds() const; 00103 00104 /// Get energy for this run, usually determined from the first event. 00105 /// @deprecated Use standalone sqrtS(ah.beams()), to clean AH interface 00106 double sqrtS() const; 00107 00108 /// Setter for _ignoreBeams 00109 void setIgnoreBeams(bool ignore=true); 00110 00111 //@} 00112 00113 00114 /// @name Handle analyses 00115 //@{ 00116 00117 /// Get a list of the currently registered analyses' names. 00118 std::vector<std::string> analysisNames() const; 00119 00120 /// Get the collection of currently registered analyses. 00121 const std::set<AnaHandle, CmpAnaHandle>& analyses() const { 00122 return _analyses; 00123 } 00124 00125 /// Get a registered analysis by name. 00126 const AnaHandle analysis(const std::string& analysisname) const; 00127 00128 00129 /// Add an analysis to the run list by object 00130 AnalysisHandler& addAnalysis(Analysis* analysis); 00131 00132 /// @brief Add an analysis to the run list using its name. 00133 /// 00134 /// The actual Analysis to be used will be obtained via 00135 /// AnalysisLoader::getAnalysis(string). If no matching analysis is found, 00136 /// no analysis is added (i.e. the null pointer is checked and discarded. 00137 AnalysisHandler& addAnalysis(const std::string& analysisname); 00138 00139 /// @brief Add analyses to the run list using their names. 00140 /// 00141 /// The actual {@link Analysis}' to be used will be obtained via 00142 /// AnalysisHandler::addAnalysis(string), which in turn uses 00143 /// AnalysisLoader::getAnalysis(string). If no matching analysis is found 00144 /// for a given name, no analysis is added, but also no error is thrown. 00145 AnalysisHandler& addAnalyses(const std::vector<std::string>& analysisnames); 00146 00147 00148 /// Remove an analysis from the run list using its name. 00149 AnalysisHandler& removeAnalysis(const std::string& analysisname); 00150 00151 /// Remove analyses from the run list using their names. 00152 AnalysisHandler& removeAnalyses(const std::vector<std::string>& analysisnames); 00153 00154 //@} 00155 00156 00157 /// @name Main init/execute/finalise 00158 //@{ 00159 00160 /// Initialize a run, with the run beams taken from the example event. 00161 void init(const GenEvent& event); 00162 00163 /// @brief Analyze the given \a event by reference. 00164 /// 00165 /// This function will call the AnalysisBase::analyze() function of all 00166 /// included analysis objects. 00167 void analyze(const GenEvent& event); 00168 00169 /// @brief Analyze the given \a event by pointer. 00170 /// 00171 /// This function will call the AnalysisBase::analyze() function of all 00172 /// included analysis objects, after checking the event pointer validity. 00173 void analyze(const GenEvent* event); 00174 00175 /// Finalize a run. This function calls the AnalysisBase::finalize() 00176 /// functions of all included analysis objects. 00177 void finalize(); 00178 00179 //@} 00180 00181 00182 /// @name Histogram / data object access 00183 //@{ 00184 00185 /// Get all analyses' plots as a vector of analysis objects. 00186 std::vector<AnalysisObjectPtr> getData() const; 00187 00188 /// Write all analyses' plots to the named file. 00189 void writeData(const std::string& filename) const; 00190 00191 //@} 00192 00193 00194 private: 00195 00196 /// The collection of Analysis objects to be used. 00197 set<AnaHandle, CmpAnaHandle> _analyses; 00198 00199 00200 /// @name Run properties 00201 //@{ 00202 00203 /// Run name 00204 std::string _runname; 00205 00206 /// Number of events seen. 00207 /// @todo Replace by a counter 00208 unsigned int _numEvents; 00209 /// Sum of event weights seen. 00210 /// @todo Replace by a counter 00211 double _sumOfWeights, _sumOfWeightsSq; 00212 00213 /// Cross-section known to AH 00214 double _xs, _xserr; 00215 00216 /// Beams used by this run. 00217 ParticlePair _beams; 00218 00219 /// Flag to check if init has been called 00220 bool _initialised; 00221 00222 /// Flag whether input event beams should be ignored in compatibility check 00223 bool _ignoreBeams; 00224 00225 //@} 00226 00227 private: 00228 00229 /// The assignment operator is private and must never be called. 00230 /// In fact, it should not even be implemented. 00231 AnalysisHandler& operator=(const AnalysisHandler&); 00232 00233 /// The copy constructor is private and must never be called. In 00234 /// fact, it should not even be implemented. 00235 AnalysisHandler(const AnalysisHandler&); 00236 00237 }; 00238 00239 00240 } 00241 00242 #endif Generated on Tue Dec 13 2016 16:32:34 for The Rivet MC analysis system by ![]() |