HepMC3 event record library
AnalysisExample.h
Go to the documentation of this file.
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"
18namespace HepMC3
19{
20class AnalysisExample : public Writer
21{
22public:
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
33 bool failed() override {
34 return (bool)m_file.rdstate();
35 }
36 /// @brief Close file stream
37 void close() override;
38 /// @brief destructor
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
46private:
47 std::ofstream m_file; //!< Output file
48 std::ostream* m_stream; //!< Output stream
49};
50}
51#endif
Definition of class GenEvent.
Definition of class GenParticle.
Definition of interface Writer.
Example analysis. Produces a rapidity distribution of final state particles.
double m_sum_of_weights2
Sum of event weights**2.
bool failed() override
Return status of the stream.
void close() override
Close file stream.
std::ofstream m_file
Output file.
std::map< std::string, std::vector< double > > m_errs
Uncertainties.
std::map< std::string, std::vector< double > > m_vals
Values.
std::map< std::string, std::vector< double > > m_bins
Binings.
void write_event(const GenEvent &evt) override
Write event to file.
std::ostream * m_stream
Output stream.
double m_sum_of_weights
Sum of event weights.
Stores event-related information.
Definition: GenEvent.h:41
Base class for all I/O writers.
Definition: Writer.h:25
HepMC3 main namespace.