1 #ifndef HEPMC3_ANALYSISEXAMPLE_H 2 #define HEPMC3_ANALYSISEXAMPLE_H 3 /// 4 /// @file AnalysisExample.h 5 /// @brief Definition of class \b AnalysisExample 6 /// 7 /// @class HepMC3::AnalysisExample 8 /// @brief Example analysis. Produces a rapidity distribution of final state particles. 9 /// 10 /// @ingroup Examples 11 /// 12 #include <string> 13 #include <fstream> 14 #include "HepMC3/Writer.h" 15 #include "HepMC3/Version.h" 16 #include "HepMC3/GenEvent.h" 17 #include "HepMC3/GenParticle.h" 18 namespace HepMC3 19 { 20 class AnalysisExample : public Writer 21 { 22 public: 23 /// @brief Constructor 24 /// @warning If file already exists, it will be cleared before writing 25 AnalysisExample(const std::string &filename,std::shared_ptr<GenRunInfo> run); 26 /// @brief Constructor from ostream 27 AnalysisExample(std::ostream& stream,std::shared_ptr<GenRunInfo> run); 28 /// @brief Write event to file 29 /// 30 /// @param[in] evt Event to be serialized 31 void write_event(const GenEvent &evt) override; 32 /// @brief Return status of the stream failed()33 bool failed() override { 34 return (bool)m_file.rdstate(); 35 } 36 /// @brief Close file stream 37 void close() override; 38 /// @brief destructor ~AnalysisExample()39 ~AnalysisExample() { close(); } 40 41 double m_sum_of_weights=0; //!< Sum of event weights 42 double m_sum_of_weights2=0; //!< Sum of event weights**2 43 std::map<std::string, std::vector<double> > m_bins; //!< Binings 44 std::map<std::string, std::vector<double> > m_vals; //!< Values 45 std::map<std::string, std::vector<double> > m_errs; //!< Uncertainties 46 private: 47 std::ofstream m_file; //!< Output file 48 std::ostream* m_stream; //!< Output stream 49 }; 50 } 51 #endif 52