Belle II Software  release-05-02-19
HepevtReader Class Reference

Class to read Hepevt files and store the content in a MCParticle graph. More...

#include <HepevtReader.h>

Collaboration diagram for HepevtReader:

Public Member Functions

 BELLE2_DEFINE_EXCEPTION (HepEvtCouldNotOpenFileError, "Could not open file %1% !")
 Exception is thrown if the HepEvt file could not be opened.
 
 BELLE2_DEFINE_EXCEPTION (HepEvtInvalidDaughterIndicesError, "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.
 
 BELLE2_DEFINE_EXCEPTION (HepEvtHeaderNotValidError, "Line %1%: Event header not understood: %2%")
 Exception is thrown if the header specifying the event header could not be parsed.
 
 BELLE2_DEFINE_EXCEPTION (HepEvtConvertFieldError, "Line %1%: Could not convert field %2%: %3%")
 Exception is thrown if a field in the HepEvt file could not be converted to a number.
 
 BELLE2_DEFINE_EXCEPTION (HepEvtParticleFormatError, "Line %1%: Particle format not understood, got %2% fields !")
 Exception is thrown if the format of a line of the HepEvt file could not be parsed.
 
 BELLE2_DEFINE_EXCEPTION (HepEvtEmptyEventError, "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. More...
 
 HepevtReader ()
 Constructor.
 
 ~HepevtReader ()
 Destructor.
 
void open (const std::string &filename)
 Opens an ascii file and prepares it for reading. More...
 
void closeCurrentInputFile ()
 Closes the current input file to allow opening the next one.
 
int getEvent (MCParticleGraph &graph, double &weight)
 Reads the next event and stores the result in the given MCParticle graph. More...
 
bool skipEvents (int n)
 Skips a given number of events. More...
 

Public Attributes

int m_nVirtual
 The number of particles in each event with a set Virtual flag.
 
bool m_wrongSignPz
 Bool to indicate that HER and LER were swapped.
 
TLorentzRotation m_labboost
 Boost&rotation vector for boost from CM to LAB.
 

Protected Types

typedef boost::tokenizer< boost::char_separator< char > > tokenizer
 Just a typedef for simple use of the boost::tokenizer to split the lines.
 

Protected Member Functions

std::string getLine ()
 Returns the current line from the Hepevt ascii file. More...
 
int readEventHeader (int &eventID, double &eventWeight)
 Reads the event header from the hepevt file. More...
 
void readParticle (MCParticleGraph::GraphParticle &particle)
 Reads the information for a single particle from the Hepevt file. More...
 

Protected Attributes

int m_lineNr
 The current line number within the ascii file.
 
std::ifstream m_input
 The input stream of the ascii file.
 

Static Protected Attributes

static const boost::char_separator< char > sep
 The characters at which to split, defaults to ",; \t".
 

Detailed Description

Class to read Hepevt files and store the content in a MCParticle graph.

The reader supports retrieving the Hepevt information from an ascii text file. Both formats, the short and the long LUND 7 format are supported.

The events are read sequentially with the option of skipping a certain number of events. Random access of events is not possible.

Definition at line 46 of file HepevtReader.h.

Member Function Documentation

◆ BELLE2_DEFINE_EXCEPTION()

BELLE2_DEFINE_EXCEPTION ( HepEvtEmptyEventError  ,
"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.


◆ getEvent()

int getEvent ( MCParticleGraph graph,
double &  weight 
)

Reads the next event and stores the result in the given MCParticle graph.

Parameters
graphReference to the graph which should be filled with the information from the Hepevt file.
weightReference to the event weight which can be filled from the file.
Returns
event numer if the event could be read and the number was provided in the file.

Definition at line 37 of file HepevtReader.cc.

38 {
39  int eventID = -1;
40  int nparticles = readEventHeader(eventID, eventWeight);
41  if (nparticles <= 0) {
42  throw (HepEvtEmptyEventError() << m_lineNr << nparticles);
43  }
44 
45  int first = graph.size();
46  //Make list of particles
47  for (int i = 0; i < nparticles; i++) {
48  graph.addParticle();
49  }
50  //Read particles from file
51  for (int i = 0; i < nparticles; ++i) {
52  MCParticleGraph::GraphParticle& p = graph[first + i];
53  readParticle(p);
54 
55  //boost particles to lab frame:
56  TLorentzVector p4 = p.get4Vector();
57  if (m_wrongSignPz) // this means we have to mirror Pz
58  p4.SetPz(-1.0 * p4.Pz());
59  p4 = m_labboost * p4;
60  p.set4Vector(p4);
61 
62  //Check for sensible daughter indices
63  int d1 = p.getFirstDaughter();
64  int d2 = p.getLastDaughter();
65  if (d1 < 0 || d1 > nparticles || d2 < d1 || d2 > nparticles) {
66  throw (HepEvtInvalidDaughterIndicesError() << m_lineNr << d1 << d2 << nparticles);
67  }
68  if (d1 == 0) p.addStatus(MCParticle::c_StableInGenerator);
69  //Add decays
70  for (int index = d1; index <= d2; ++index) {
71  if (index > 0) p.decaysInto(graph[first + index - 1]);
72  }
73 
74  //check if particle should be made virtual according to steering options:
75  if (i < m_nVirtual)
76  p.setVirtual();
77  }
78  return eventID;
79 }

◆ getLine()

std::string getLine ( )
protected

Returns the current line from the Hepevt ascii file.

  • double eventWeight; /‍**< The event weight if provided in HepEvtfile else 1. *‍/ *‍/
    Returns
    The current line as a string.

Definition at line 99 of file HepevtReader.cc.

◆ open()

void open ( const std::string &  filename)

Opens an ascii file and prepares it for reading.

Parameters
filenameThe filename of the Hepevt ascii file which should be read.

Definition at line 29 of file HepevtReader.cc.

◆ readEventHeader()

int readEventHeader ( int &  eventID,
double &  eventWeight 
)
protected

Reads the event header from the hepevt file.

Returns
The number of particles for the current event. @params: References to the eventID and the eventWeight which can both be read from the file.

Definition at line 115 of file HepevtReader.cc.

◆ readParticle()

void readParticle ( MCParticleGraph::GraphParticle particle)
protected

Reads the information for a single particle from the Hepevt file.

Parameters
particleReference to the particle which will be filled with the information from the Hepevt file.

Definition at line 158 of file HepevtReader.cc.

◆ skipEvents()

bool skipEvents ( int  n)

Skips a given number of events.

Parameters
nThe number of events which should be skipped.
Returns
True if the events could be skipped.

Definition at line 82 of file HepevtReader.cc.


The documentation for this class was generated from the following files:
Belle2::HepevtReader::readParticle
void readParticle(MCParticleGraph::GraphParticle &particle)
Reads the information for a single particle from the Hepevt file.
Definition: HepevtReader.cc:158
Belle2::MCParticleGraph::size
size_t size() const
Return the number of particles in the graph.
Definition: MCParticleGraph.h:253
Belle2::HepevtReader::readEventHeader
int readEventHeader(int &eventID, double &eventWeight)
Reads the event header from the hepevt file.
Definition: HepevtReader.cc:115
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::MCParticleGraph::addParticle
GraphParticle & addParticle()
Add new particle to the graph.
Definition: MCParticleGraph.h:305
Belle2::HepevtReader::m_labboost
TLorentzRotation m_labboost
Boost&rotation vector for boost from CM to LAB.
Definition: HepevtReader.h:103
Belle2::MCParticle::c_StableInGenerator
@ c_StableInGenerator
bit 1: Particle is stable, i.e., not decaying in the generator.
Definition: MCParticle.h:60
Belle2::HepevtReader::m_lineNr
int m_lineNr
The current line number within the ascii file.
Definition: HepevtReader.h:112
Belle2::MCParticleGraph::GraphParticle
Class to represent Particle data in graph.
Definition: MCParticleGraph.h:86