HepMC3 event record library: AnalysisExample.h Source File

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, which implements a toy physics analysis
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"
23 namespace HepMC3
24{
25 class 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 static_cast<bool> (m_file.rdstate());
40 }
41 /// @brief Close file stream
42 void close() override;
43 /// @brief destructor
44 ~AnalysisExample() { close(); }
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
GenEvent.h
Definition of class GenEvent.
GenParticle.h
Definition of class GenParticle.
Version.h
Declaration of the Verrion functions and some macros.
Writer.h
Definition of interface Writer.
HepMC3::AnalysisExample::m_sum_of_weights2
double m_sum_of_weights2
Sum of event weights**2.
Definition AnalysisExample.h:47
HepMC3::AnalysisExample::AnalysisExample
AnalysisExample(const std::string &filename, std::shared_ptr< GenRunInfo > run)
Constructor.
Definition AnalysisExample.cc:17
HepMC3::AnalysisExample::failed
bool failed() override
Return status of the stream.
Definition AnalysisExample.h:38
HepMC3::AnalysisExample::~AnalysisExample
~AnalysisExample()
destructor
Definition AnalysisExample.h:44
HepMC3::AnalysisExample::close
void close() override
Close file stream.
Definition AnalysisExample.cc:57
HepMC3::AnalysisExample::m_file
std::ofstream m_file
Output file.
Definition AnalysisExample.h:52
HepMC3::AnalysisExample::m_errs
std::map< std::string, std::vector< double > > m_errs
Uncertainties.
Definition AnalysisExample.h:50
HepMC3::AnalysisExample::m_vals
std::map< std::string, std::vector< double > > m_vals
Values.
Definition AnalysisExample.h:49
HepMC3::AnalysisExample::m_bins
std::map< std::string, std::vector< double > > m_bins
Binings.
Definition AnalysisExample.h:48
HepMC3::AnalysisExample::write_event
void write_event(const GenEvent &evt) override
Write event to file.
Definition AnalysisExample.cc:41
HepMC3::AnalysisExample::m_stream
std::ostream * m_stream
Output stream.
Definition AnalysisExample.h:53
HepMC3::AnalysisExample::m_sum_of_weights
double m_sum_of_weights
Sum of event weights.
Definition AnalysisExample.h:46
HepMC3::GenEvent
Stores event-related information.
Definition GenEvent.h:47
HepMC3::Writer::Writer
Writer()
Constructor.
Definition Writer.h:29
HepMC3
HepMC3 main namespace.
Definition AnalysisExample.h:24