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