MARLEY (Model of Argon Reaction Low Energy Yields) v2.0.0
A Monte Carlo event generator for tens-of-MeV neutrino interactions
Loading...
Searching...
No Matches
EventFileReader.hh
1
4//
5// This file is part of MARLEY (Model of Argon Reaction Low Energy Yields)
6//
7// MARLEY is free software: you can redistribute it and/or modify it under the
8// terms of version 3 of the GNU General Public License as published by the
9// Free Software Foundation.
10//
11// For the full text of the license please see COPYING or
12// visit http://opensource.org/licenses/GPL-3.0
13//
14// Please respect the MCnet academic usage guidelines. See GUIDELINES
15// or visit https://www.montecarlonet.org/GUIDELINES for details.
16
17#pragma once
18
19// Standard library includes
20#include <fstream>
21#include <memory>
22#include <string>
23
24// MARLEY includes
25#include "marley/OutputFile.hh"
26
27#ifdef USE_ROOT
28// HepMC3 includes
29#include "HepMC3/Data/GenEventData.h"
30#include "HepMC3/Data/GenRunInfoData.h"
31#include "HepMC3/GenRunInfo.h"
32
33// ROOT includes
34#include "TFile.h"
35#include "TTree.h"
36#endif
37
38// Forward-declare some HepMC3 classes
39namespace HepMC3 {
40 class GenEvent;
41 class GenRunInfo;
42 class ReaderAscii;
43}
44
45namespace marley {
46
48 class EventFileReader {
49
50 public:
51
52 EventFileReader( const std::string& file_name );
53
54 virtual ~EventFileReader() = default;
55
62 virtual bool next_event( HepMC3::GenEvent& ev );
63
72 double flux_averaged_xsec( bool natural_units = false );
73
75 inline EventFileReader& operator>>( HepMC3::GenEvent& ev ) {
76 next_event( ev );
77 return *this;
78 }
79
83 virtual operator bool() const;
84
85 protected:
86
89 std::string file_name_;
90
94 OutputFile::Format format_;
95
97 std::ifstream in_;
98
100 std::shared_ptr< HepMC3::ReaderAscii > reader_;
101
102 #ifdef USE_ROOT
104 std::unique_ptr< TFile > tfile_;
105
106 // @brief Pointer to the TTree containing the MARLEY events to be loaded
107 TTree* ttree_ = nullptr;
108
112 long event_num_ = -1;
113
116 std::unique_ptr< HepMC3::GenEventData > temp_event_data_;
117
120 HepMC3::GenEventData* temp_event_data_ptr_ = nullptr;
121
124 HepMC3::GenRunInfoData* temp_run_info_data_ = nullptr;
125
127 std::shared_ptr< HepMC3::GenRunInfo > run_info_;
128 #endif
129
133 double flux_avg_tot_xs_ = 0.;
134
139 bool initialized_ = false;
140
143 virtual bool deduce_file_format();
144
146 virtual void initialize();
147
153 void ensure_initialized();
154
157 void get_flux_averaged_xsec( const HepMC3::GenRunInfo& run_info );
158 };
159
160}
Stores event-related information.
Definition GenEvent.h:47
Stores run-related information.
Definition GenRunInfo.h:33
GenEvent I/O parsing for structured text files.
Definition ReaderAscii.h:31
virtual void initialize()
Prepares the file for reading the events.
virtual bool deduce_file_format()
Helper function that auto-detects which of the available output formats is appropriate for the reques...
bool initialized_
Flag that indicates whether initialize() has been called or not.
double flux_avg_tot_xs_
Flux-averaged total cross section (MeV -2) used to produce the events in the file,...
virtual bool next_event(HepMC3::GenEvent &ev)
Read the next MARLEY event record from the file.
void ensure_initialized()
This function should be called at the beginning of all public member functions of EventFileReader tha...
std::string file_name_
Name of the file (with any needed path specification) to be read.
void get_flux_averaged_xsec(const HepMC3::GenRunInfo &run_info)
double flux_averaged_xsec(bool natural_units=false)
Returns the flux-averaged total cross section used to produce the events in the file.
std::shared_ptr< HepMC3::ReaderAscii > reader_
Helper object used to interpret ASCII-format HepMC3 files.
OutputFile::Format format_
Format of the output file being read.
std::ifstream in_
Input stream used to read from textual output formats.
EventFileReader & operator>>(HepMC3::GenEvent &ev)
Stream operator for reading in the next event.
Stores serializable event information.
Stores serializable run information.