Belle II Software  release-05-01-25
LHEReader.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Torben Ferber *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #pragma once
12 
13 #include <framework/core/FrameworkExceptions.h>
14 #include <mdst/dataobjects/MCParticleGraph.h>
15 #include <boost/tokenizer.hpp>
16 
17 #include <string>
18 #include <fstream>
19 
20 #include <TLorentzRotation.h>
21 
22 namespace Belle2 {
35  class LHEReader {
36 
37  public:
38 
39  //Define exceptions
41  BELLE2_DEFINE_EXCEPTION(LHECouldNotOpenFileError, "Could not open file %1% !");
43  BELLE2_DEFINE_EXCEPTION(LHEInvalidDaughterIndicesError,
44  "Line %1%: Invalid daughter indices d1=%2%, d2=%3%, N=%4% (0<=d1<=d2<=N required)");
46  BELLE2_DEFINE_EXCEPTION(LHEHeaderNotValidError, "Line %1%: Event header not understood: %2%");
48  BELLE2_DEFINE_EXCEPTION(LHEConvertFieldError, "Line %1%: Could not convert field %2%: %3%");
50  BELLE2_DEFINE_EXCEPTION(LHEParticleFormatError, "Line %1%: Particle format not understood, got %2% fields !");
52  BELLE2_DEFINE_EXCEPTION(LHEEmptyEventError, "Line %1%: Number of particles in event is %2% ! (This could mean EOF is reached.) ");
56  LHEReader():
57  m_wrongSignPz(false),
58  m_lineNr(0),
59  m_indexInitial(0),
61  {}
62 
66  ~LHEReader() { if (m_input) m_input.close(); }
67 
72  void open(const std::string& filename);
73 
77  void closeCurrentInputFile() {m_input.close();}
78 
85  int getEvent(MCParticleGraph& graph, double& weight);
86 
92  bool skipEvents(int n);
93 
98  void setInitialIndex(int index) { m_indexInitial = index; }
99 
104  void setVirtualIndex(int index) { m_indexVirtual = index; }
105 
107  TLorentzRotation m_labboost;
108  double m_meanDecayLength = 0.;
109  double m_Rmin = 0.;
110  double m_Rmax = 0.;
111  int m_pdgDisplaced = 0;
113  protected:
115  typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
117  static const boost::char_separator<char> sep;
118 
119  int m_lineNr;
120  std::ifstream m_input;
122  // /* int eventID; /**< The event ID number if provided in LHEfile else -1. */ */
124 
125 
130  std::string getLine();
131 
137 // int readEventHeader(int& eventID, double& eventWeight);
138  int readEventHeader(double& eventWeight);
139 
145 
146  int m_indexInitial;
148  int m_indexVirtual;
150  };
151 
153 }
Belle2::LHEReader::m_Rmin
double m_Rmin
Minimum of vertex distance to IP.
Definition: LHEReader.h:117
Belle2::LHEReader::closeCurrentInputFile
void closeCurrentInputFile()
Closes the current input file to allow opening the next one.
Definition: LHEReader.h:85
Belle2::LHEReader::setInitialIndex
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:106
Belle2::LHEReader::BELLE2_DEFINE_EXCEPTION
BELLE2_DEFINE_EXCEPTION(LHECouldNotOpenFileError, "Could not open file %1% !")
Exception is thrown if the LHE file could not be opened.
Belle2::MCParticleGraph
Class to build, validate and sort a particle decay chain.
Definition: MCParticleGraph.h:48
Belle2::LHEReader::m_input
std::ifstream m_input
The input stream of the ascii file.
Definition: LHEReader.h:128
Belle2::LHEReader::setVirtualIndex
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:112
Belle2::LHEReader::sep
static const boost::char_separator< char > sep
The characters at which to split, defaults to ",; \t".
Definition: LHEReader.h:125
Belle2::LHEReader::m_meanDecayLength
double m_meanDecayLength
Mean lifetime*c of displaced particle.
Definition: LHEReader.h:116
Belle2::LHEReader::getEvent
int getEvent(MCParticleGraph &graph, double &weight)
Reads the next event and stores the result in the given MCParticle graph.
Definition: LHEReader.cc:39
Belle2::LHEReader::LHEReader
LHEReader()
Constructor.
Definition: LHEReader.h:64
Belle2::LHEReader::m_pdgDisplaced
int m_pdgDisplaced
PDG code of the displaced particle being studied.
Definition: LHEReader.h:119
Belle2::LHEReader::m_Rmax
double m_Rmax
Maximum of vertex distance to IP.
Definition: LHEReader.h:118
Belle2::LHEReader::m_indexVirtual
int m_indexVirtual
Maximum index of particles in each event that must be set as c_IsVirtual (1-based).
Definition: LHEReader.h:156
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::LHEReader::m_wrongSignPz
bool m_wrongSignPz
Bool to indicate that HER and LER were swapped.
Definition: LHEReader.h:114
Belle2::LHEReader::tokenizer
boost::tokenizer< boost::char_separator< char > > tokenizer
Just a typedef for simple use of the boost::tokenizer to split the lines.
Definition: LHEReader.h:123
Belle2::LHEReader::m_indexInitial
int m_indexInitial
Maximum index of particles in each event that must be set as c_Initial (1-based).
Definition: LHEReader.h:154
Belle2::LHEReader::m_labboost
TLorentzRotation m_labboost
Boost&rotation vector for boost from CM to LAB.
Definition: LHEReader.h:115
Belle2::LHEReader::getLine
std::string getLine()
Returns the current line from the LHE ascii file.
Definition: LHEReader.cc:149
Belle2::LHEReader::~LHEReader
~LHEReader()
Destructor.
Definition: LHEReader.h:74
Belle2::LHEReader::readEventHeader
int readEventHeader(double &eventWeight)
Reads the event header from the hepevt file.
Definition: LHEReader.cc:168
Belle2::LHEReader::m_lineNr
int m_lineNr
The current line number within the ascii file.
Definition: LHEReader.h:127
Belle2::MCParticleGraph::GraphParticle
Class to represent Particle data in graph.
Definition: MCParticleGraph.h:86
Belle2::LHEReader::readParticle
int readParticle(MCParticleGraph::GraphParticle &particle)
Reads the information for a single particle from the LHE file.
Definition: LHEReader.cc:215
Belle2::LHEReader::skipEvents
bool skipEvents(int n)
Skips a given number of events.
Definition: LHEReader.cc:131
Belle2::LHEReader::open
void open(const std::string &filename)
Opens an ascii file and prepares it for reading.
Definition: LHEReader.cc:31