Belle II Software development
LHEReader.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#pragma once
10
11#include <framework/core/FrameworkExceptions.h>
12#include <mdst/dataobjects/MCParticleGraph.h>
13#include <boost/tokenizer.hpp>
14
15#include <string>
16#include <fstream>
17
18namespace Belle2 {
31 class LHEReader {
32
33 public:
34
35 //Define exceptions
37 BELLE2_DEFINE_EXCEPTION(LHECouldNotOpenFileError, "Could not open file %1% !");
39 BELLE2_DEFINE_EXCEPTION(LHEInvalidDaughterIndicesError,
40 "Line %1%: Invalid daughter indices d1=%2%, d2=%3%, N=%4% (0<=d1<=d2<=N required)");
42 BELLE2_DEFINE_EXCEPTION(LHEHeaderNotValidError, "Line %1%: Event header not understood: %2%");
44 BELLE2_DEFINE_EXCEPTION(LHEConvertFieldError, "Line %1%: Could not convert field %2%: %3%");
46 BELLE2_DEFINE_EXCEPTION(LHEParticleFormatError, "Line %1%: Particle format not understood, got %2% fields !");
48 BELLE2_DEFINE_EXCEPTION(LHEEmptyEventError, "Line %1%: Number of particles in event is %2% ! (This could mean EOF is reached.) ");
53 m_wrongSignPz(false),
54 m_lineNr(0),
57 {}
58
62 ~LHEReader() { if (m_input) m_input.close(); }
63
68 void open(const std::string& filename);
69
74
81 int getEvent(MCParticleGraph& graph, double& weight);
82
88 bool skipEvents(int n);
89
94 void setInitialIndex(int index) { m_indexInitial = index; }
95
100 void setVirtualIndex(int index) { m_indexVirtual = index; }
101
103 double m_meanDecayLength = 0.;
104 double m_Rmin = 0.;
105 double m_Rmax = 0.;
108 protected:
110 typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
112 static const boost::char_separator<char> sep;
113
115 std::ifstream m_input;
117 // /* int eventID; /**< The event ID number if provided in LHEfile else -1. */ */
119
120
125 std::string getLine();
126
132 int readEventHeader(double& eventWeight);
133
139
144 };
145
147}
Class to read LHE files and store the content in a MCParticle graph.
Definition: LHEReader.h:31
int readParticle(MCParticleGraph::GraphParticle &particle)
Reads the information for a single particle from the LHE file.
Definition: LHEReader.cc:196
bool skipEvents(int n)
Skips a given number of events.
Definition: LHEReader.cc:112
std::string getLine()
Returns the current line from the LHE ascii file.
Definition: LHEReader.cc:130
void setVirtualIndex(int index)
Set the maximum index of particles in each event that must be set as c_IsVirtual (1-based).
Definition: LHEReader.h:100
double m_Rmin
Minimum of vertex distance to IP.
Definition: LHEReader.h:104
BELLE2_DEFINE_EXCEPTION(LHEInvalidDaughterIndicesError, "Line %1%: Invalid daughter indices d1=%2%, d2=%3%, N=%4% (0<=d1<=d2<=N required)")
Exception is thrown if the given indices of the daughters are not valid.
int m_pdgDisplaced
PDG code of the displaced particle being studied.
Definition: LHEReader.h:106
static const boost::char_separator< char > sep
The characters at which to split, defaults to ",; \t".
Definition: LHEReader.h:112
void setInitialIndex(int index)
Set the maximum index of particles in each event that must be set as c_Initial (1-based).
Definition: LHEReader.h:94
int m_lineNr
The current line number within the ascii file.
Definition: LHEReader.h:114
int m_indexVirtual
Maximum index of particles in each event that must be set as c_IsVirtual (1-based).
Definition: LHEReader.h:142
double m_Rmax
Maximum of vertex distance to IP.
Definition: LHEReader.h:105
void open(const std::string &filename)
Opens an ascii file and prepares it for reading.
Definition: LHEReader.cc:28
void closeCurrentInputFile()
Closes the current input file to allow opening the next one.
Definition: LHEReader.h:73
std::ifstream m_input
The input stream of the ascii file.
Definition: LHEReader.h:115
boost::tokenizer< boost::char_separator< char > > tokenizer
Just a typedef for simple use of the boost::tokenizer to split the lines.
Definition: LHEReader.h:110
BELLE2_DEFINE_EXCEPTION(LHEConvertFieldError, "Line %1%: Could not convert field %2%: %3%")
Exception is thrown if a field in the LHE file could not be converted to a number.
int m_indexInitial
Maximum index of particles in each event that must be set as c_Initial (1-based).
Definition: LHEReader.h:140
int getEvent(MCParticleGraph &graph, double &weight)
Reads the next event and stores the result in the given MCParticle graph.
Definition: LHEReader.cc:36
~LHEReader()
Destructor.
Definition: LHEReader.h:62
bool m_wrongSignPz
Bool to indicate that HER and LER were swapped.
Definition: LHEReader.h:102
int readEventHeader(double &eventWeight)
Reads the event header from the hepevt file.
Definition: LHEReader.cc:149
double m_meanDecayLength
Mean lifetime*c of displaced particle.
Definition: LHEReader.h:103
BELLE2_DEFINE_EXCEPTION(LHEEmptyEventError, "Line %1%: Number of particles in event is %2% ! (This could mean EOF is reached.) ")
Exception is thrown if the number of particles for this event is 0 or less.
BELLE2_DEFINE_EXCEPTION(LHECouldNotOpenFileError, "Could not open file %1% !")
Exception is thrown if the LHE file could not be opened.
LHEReader()
Constructor.
Definition: LHEReader.h:52
BELLE2_DEFINE_EXCEPTION(LHEParticleFormatError, "Line %1%: Particle format not understood, got %2% fields !")
Exception is thrown if the format of a line of the LHE file could not be parsed.
BELLE2_DEFINE_EXCEPTION(LHEHeaderNotValidError, "Line %1%: Event header not understood: %2%")
Exception is thrown if the header specifying the event header could not be parsed.
Class to represent Particle data in graph.
Class to build, validate and sort a particle decay chain.
Abstract base class for different kinds of events.