Rivet
1.8.0
|
00001 // -*- C++ -*- 00002 #ifndef RIVET_RivetHandler_HH 00003 #define RIVET_RivetHandler_HH 00004 00005 #include "Rivet/Rivet.hh" 00006 #include "Rivet/RivetBoost.hh" 00007 #include "Rivet/Tools/Logging.fhh" 00008 #include "Rivet/AnalysisHandler.fhh" 00009 #include "Rivet/Analysis.fhh" 00010 #include "Rivet/Event.fhh" 00011 #include "Rivet/AnalysisLoader.hh" 00012 00013 namespace Rivet { 00014 00016 typedef shared_ptr<Analysis> AnaHandle; 00017 00018 // Needed to make smart pointers compare equivalent in the STL set 00019 struct AnaHandleLess { 00020 bool operator()(const AnaHandle& a, const AnaHandle& b) { 00021 return a.get() < b.get(); 00022 } 00023 }; 00024 00025 00029 class AnalysisHandler { 00030 public: 00031 00033 00034 00036 AnalysisHandler(const string& runname=""); 00037 00038 00051 AnalysisHandler(const string& basefilename, const string& runname, HistoFormat storetype=AIDAML); 00052 00053 00056 ~AnalysisHandler(); 00057 00059 00060 00061 private: 00062 00065 void _setupFactories(const string& basefilename, HistoFormat storetype); 00066 00069 void _setupFactories(); 00070 00073 void _normalizeTree(AIDA::ITree& tree); 00074 00076 Log& getLog() const; 00077 00078 00079 public: 00080 00082 00083 00085 string runName() const; 00086 00087 00090 size_t numEvents() const; 00091 00095 double sumOfWeights() const; 00096 00100 void setSumOfWeights(const double& sum); 00101 00102 00104 bool needCrossSection() const; 00105 00107 AnalysisHandler& setCrossSection(double xs); 00108 00110 double crossSection() const { 00111 return _xs; 00112 } 00113 00115 bool hasCrossSection() const; 00116 00117 00119 AnalysisHandler& setRunBeams(const ParticlePair& beams) { 00120 _beams = beams; 00121 MSG_DEBUG("Setting run beams = " << beams << " @ " << sqrtS()/GeV << " GeV"); 00122 return *this; 00123 } 00124 00126 const ParticlePair& beams() const { 00127 return _beams; 00128 } 00129 00131 PdgIdPair beamIds() const; 00132 00134 double sqrtS() const; 00135 00137 void setIgnoreBeams(bool ignore=true); 00138 00140 00141 00143 00144 00146 std::vector<std::string> analysisNames() const; 00147 00149 const std::set<AnaHandle, AnaHandleLess>& analyses() const { 00150 return _analyses; 00151 } 00152 00157 AnalysisHandler& addAnalysis(const std::string& analysisname); 00158 00160 AnalysisHandler& removeAnalysis(const std::string& analysisname); 00161 00162 00168 AnalysisHandler& addAnalyses(const std::vector<std::string>& analysisnames); 00169 00171 AnalysisHandler& removeAnalyses(const std::vector<std::string>& analysisnames); 00172 00173 00175 AnalysisHandler& addAnalysis(Analysis* analysis); 00176 00178 00179 00181 00182 00184 void init() {} 00185 00186 00188 void init(const GenEvent& event); 00189 00190 00193 void analyze(const GenEvent& event); 00194 00195 00200 void finalize(); 00201 00203 00204 00207 00208 00211 AIDA::IAnalysisFactory& analysisFactory(); 00212 00213 00216 void commitData(); 00217 00218 00221 void writeData(const std::string& filename); 00222 00223 00226 AIDA::ITree& tree(); 00227 00228 00231 AIDA::IHistogramFactory& histogramFactory(); 00232 00233 00236 AIDA::IDataPointSetFactory& datapointsetFactory(); 00237 00239 00240 00241 private: 00242 00244 set<AnaHandle, AnaHandleLess> _analyses; 00245 00246 00248 00249 00251 std::string _runname; 00252 00254 size_t _numEvents; 00255 00257 double _sumOfWeights; 00258 00260 double _xs; 00261 00263 ParticlePair _beams; 00264 00266 bool _initialised; 00267 00269 bool _ignoreBeams; 00270 00272 00273 00276 00277 00279 shared_ptr<AIDA::IAnalysisFactory> _theAnalysisFactory; 00280 00282 AIDA::ITreeFactory* _theTreeFactory; 00283 00285 AIDA::ITree* _theTree; 00286 00288 AIDA::IHistogramFactory* _theHistogramFactory; 00289 00291 AIDA::IDataPointSetFactory* _theDataPointSetFactory; 00292 00294 00295 00296 private: 00297 00300 AnalysisHandler& operator=(const AnalysisHandler&); 00301 00304 AnalysisHandler(const AnalysisHandler&); 00305 00306 }; 00307 00308 00309 } 00310 00311 #endif