Belle II Software  release-05-02-19
HepevtReader.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Martin Ritter, Susanne Koblitz *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #ifndef HEPEVTREADER_H
12 #define HEPEVTREADER_H
13 
14 #include <framework/core/FrameworkExceptions.h>
15 #include <mdst/dataobjects/MCParticleGraph.h>
16 #include <boost/tokenizer.hpp>
17 
18 #include <string>
19 #include <fstream>
20 
21 #include <TLorentzRotation.h>
22 
23 namespace Belle2 {
38  class HepevtReader {
39 
40  public:
41 
42  //Define exceptions
44  BELLE2_DEFINE_EXCEPTION(HepEvtCouldNotOpenFileError, "Could not open file %1% !");
46  BELLE2_DEFINE_EXCEPTION(HepEvtInvalidDaughterIndicesError,
47  "Line %1%: Invalid daughter indices d1=%2%, d2=%3%, N=%4% (0<=d1<=d2<=N required)");
49  BELLE2_DEFINE_EXCEPTION(HepEvtHeaderNotValidError, "Line %1%: Event header not understood: %2%");
51  BELLE2_DEFINE_EXCEPTION(HepEvtConvertFieldError, "Line %1%: Could not convert field %2%: %3%");
53  BELLE2_DEFINE_EXCEPTION(HepEvtParticleFormatError, "Line %1%: Particle format not understood, got %2% fields !");
55  BELLE2_DEFINE_EXCEPTION(HepEvtEmptyEventError,
56  "Line %1%: Number of particles in event is %2% ! (This could mean EOF is reached.) ");
60  HepevtReader(): m_nVirtual(0), m_wrongSignPz(false), m_lineNr(0) {}
61 
65  ~HepevtReader() { if (m_input) m_input.close(); }
66 
71  void open(const std::string& filename);
72 
76  void closeCurrentInputFile() {m_input.close();}
77 
84  int getEvent(MCParticleGraph& graph, double& weight);
85 
91  bool skipEvents(int n);
92 
93  int m_nVirtual;
94  bool m_wrongSignPz;
95  TLorentzRotation m_labboost;
98  protected:
100  typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
102  static const boost::char_separator<char> sep;
103 
104  int m_lineNr;
105  std::ifstream m_input;
107  // /* int eventID; /**< The event ID number if provided in HepEvtfile else -1. */ */
109 
110 
115  std::string getLine();
116 
122  int readEventHeader(int& eventID, double& eventWeight);
123 
129  };
130 
132 }
133 
134 #endif //HEPEVTREADER_H
Belle2::HepevtReader::readParticle
void readParticle(MCParticleGraph::GraphParticle &particle)
Reads the information for a single particle from the Hepevt file.
Definition: HepevtReader.cc:158
Belle2::HepevtReader::m_input
std::ifstream m_input
The input stream of the ascii file.
Definition: HepevtReader.h:113
Belle2::HepevtReader::readEventHeader
int readEventHeader(int &eventID, double &eventWeight)
Reads the event header from the hepevt file.
Definition: HepevtReader.cc:115
Belle2::HepevtReader::open
void open(const std::string &filename)
Opens an ascii file and prepares it for reading.
Definition: HepevtReader.cc:29
Belle2::MCParticleGraph
Class to build, validate and sort a particle decay chain.
Definition: MCParticleGraph.h:48
Belle2::HepevtReader::getEvent
int getEvent(MCParticleGraph &graph, double &weight)
Reads the next event and stores the result in the given MCParticle graph.
Definition: HepevtReader.cc:37
Belle2::HepevtReader::m_wrongSignPz
bool m_wrongSignPz
Bool to indicate that HER and LER were swapped.
Definition: HepevtReader.h:102
Belle2::HepevtReader::m_nVirtual
int m_nVirtual
The number of particles in each event with a set Virtual flag.
Definition: HepevtReader.h:101
Belle2::HepevtReader::HepevtReader
HepevtReader()
Constructor.
Definition: HepevtReader.h:68
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::HepevtReader::skipEvents
bool skipEvents(int n)
Skips a given number of events.
Definition: HepevtReader.cc:82
Belle2::HepevtReader::BELLE2_DEFINE_EXCEPTION
BELLE2_DEFINE_EXCEPTION(HepEvtCouldNotOpenFileError, "Could not open file %1% !")
Exception is thrown if the HepEvt file could not be opened.
Belle2::HepevtReader::m_labboost
TLorentzRotation m_labboost
Boost&rotation vector for boost from CM to LAB.
Definition: HepevtReader.h:103
Belle2::HepevtReader::getLine
std::string getLine()
Returns the current line from the Hepevt ascii file.
Definition: HepevtReader.cc:99
Belle2::HepevtReader::~HepevtReader
~HepevtReader()
Destructor.
Definition: HepevtReader.h:73
Belle2::HepevtReader::tokenizer
boost::tokenizer< boost::char_separator< char > > tokenizer
Just a typedef for simple use of the boost::tokenizer to split the lines.
Definition: HepevtReader.h:108
Belle2::HepevtReader::m_lineNr
int m_lineNr
The current line number within the ascii file.
Definition: HepevtReader.h:112
Belle2::HepevtReader::sep
static const boost::char_separator< char > sep
The characters at which to split, defaults to ",; \t".
Definition: HepevtReader.h:110
Belle2::HepevtReader::closeCurrentInputFile
void closeCurrentInputFile()
Closes the current input file to allow opening the next one.
Definition: HepevtReader.h:84
Belle2::MCParticleGraph::GraphParticle
Class to represent Particle data in graph.
Definition: MCParticleGraph.h:86