Belle II Software  release-05-02-19
HepMCReader.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2019 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Jo-Frederik Krohn *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #pragma once
11 
12 #include <framework/core/FrameworkExceptions.h>
13 #include <mdst/dataobjects/MCParticleGraph.h>
14 
15 #include <string>
16 #include <fstream>
17 
18 #include <TLorentzRotation.h>
19 
20 #include "HepMC/GenEvent.h"
21 
22 namespace Belle2 {
36  class HepMCReader {
37 
38  public:
39 
40  //Define exceptions
42  BELLE2_DEFINE_EXCEPTION(HepMCCouldNotOpenFileError, "Could not open file %1% !");
44  BELLE2_DEFINE_EXCEPTION(HepMCInvalidDaughterIndicesError,
45  "Event %1%: Invalid daughter indices d1=%2%, d2=%3%, N=%4% (0<=d1<=d2<=N required)");
47  BELLE2_DEFINE_EXCEPTION(HepMCHeaderNotValidError, "Event %1%: Event header not understood: %2%");
49  BELLE2_DEFINE_EXCEPTION(HepMCConvertFieldError, "Event %1%: Could not convert field %2%: %3%");
51  BELLE2_DEFINE_EXCEPTION(HepMCParticleFormatError, "Event %1%: Particle format not understood, got %2% fields !");
53  BELLE2_DEFINE_EXCEPTION(HepMCInvalidEventError, "Event is invalid.");
55  BELLE2_DEFINE_EXCEPTION(HepMCEmptyEventError,
56  "Event %1%: Number of particles in event is %2% ! (This could mean EOF is reached.) ");
60  HepMCReader(const int minEvent = 0, const int maxEvent = INT_MAX): m_nVirtual(0), m_wrongSignPz(false), m_minEvent(minEvent),
61  m_maxEvent(maxEvent) {}
62 
66  ~HepMCReader() { if (m_input) {m_input.close();} }
67 
72  void open(const std::string& filename);
73 
77  void closeCurrentInputFile() {m_input.close();}
78 
83  int nextValidEvent(HepMC::GenEvent& evt);
90  int getEvent(MCParticleGraph& graph, double& weight);
91 
92  int m_nVirtual;
93  bool m_wrongSignPz;
94  const int m_minEvent;
95  const int m_maxEvent;
96  TLorentzRotation m_labboost;
98  int countEvents(const std::string& filename);
99  protected:
100 
101  void readNextEvent(HepMC::GenEvent& evt);
102  std::ifstream m_input;
104  };
105 
107 }
108 
Belle2::HepMCReader::getEvent
int getEvent(MCParticleGraph &graph, double &weight)
Reads the next event and stores the result in the given MCParticle graph.
Definition: HepMCReader.cc:46
Belle2::HepMCReader::m_wrongSignPz
bool m_wrongSignPz
Bool to indicate that HER and LER were swapped.
Definition: HepMCReader.h:101
Belle2::HepMCReader::m_input
std::ifstream m_input
The input stream of the ascii file.
Definition: HepMCReader.h:110
Belle2::HepMCReader::~HepMCReader
~HepMCReader()
Destructor.
Definition: HepMCReader.h:74
Belle2::HepMCReader::m_maxEvent
const int m_maxEvent
max events to process
Definition: HepMCReader.h:103
Belle2::HepMCReader::m_nVirtual
int m_nVirtual
The number of particles in each event with a set Virtual flag.
Definition: HepMCReader.h:100
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::HepMCReader::closeCurrentInputFile
void closeCurrentInputFile()
Closes the current input file to allow opening the next one.
Definition: HepMCReader.h:85
Belle2::HepMCReader::nextValidEvent
int nextValidEvent(HepMC::GenEvent &evt)
Got to next event in bounds.
Definition: HepMCReader.cc:31
Belle2::HepMCReader::m_labboost
TLorentzRotation m_labboost
Boost&rotation vector for boost from CM to LAB.
Definition: HepMCReader.h:104
Belle2::HepMCReader::m_minEvent
const int m_minEvent
min event nr to process
Definition: HepMCReader.h:102
Belle2::HepMCReader::readNextEvent
void readNextEvent(HepMC::GenEvent &evt)
read the next event from the IO stream and write into evt
Definition: HepMCReader.cc:149
Belle2::HepMCReader::open
void open(const std::string &filename)
Opens an ascii file and prepares it for reading.
Definition: HepMCReader.cc:24
Belle2::HepMCReader::countEvents
int countEvents(const std::string &filename)
Count events in file.
Definition: HepMCReader.cc:165
Belle2::HepMCReader::BELLE2_DEFINE_EXCEPTION
BELLE2_DEFINE_EXCEPTION(HepMCCouldNotOpenFileError, "Could not open file %1% !")
Exception is thrown if the HepMC file could not be opened.
Belle2::HepMCReader::HepMCReader
HepMCReader(const int minEvent=0, const int maxEvent=INT_MAX)
Constructor.
Definition: HepMCReader.h:68