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

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

#include <LHEReader.h>

Collaboration diagram for LHEReader:

Public Member Functions

 BELLE2_DEFINE_EXCEPTION (LHECouldNotOpenFileError, "Could not open file %1% !")
 Exception is thrown if the LHE file could not be opened.
 
 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.
 
 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.
 
 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.
 
 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 (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. More...
 
 LHEReader ()
 Constructor.
 
 ~LHEReader ()
 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...
 
void setInitialIndex (int index)
 Set the maximum index of particles in each event that must be set as c_Initial (1-based). More...
 
void setVirtualIndex (int index)
 Set the maximum index of particles in each event that must be set as c_IsVirtual (1-based). More...
 

Public Attributes

bool m_wrongSignPz
 Bool to indicate that HER and LER were swapped.
 
TLorentzRotation m_labboost
 Boost&rotation vector for boost from CM to LAB.
 
double m_meanDecayLength = 0.
 Mean lifetime*c of displaced particle.
 
double m_Rmin = 0.
 Minimum of vertex distance to IP.
 
double m_Rmax = 0.
 Maximum of vertex distance to IP.
 
int m_pdgDisplaced = 0
 PDG code of the displaced particle being studied.
 

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 LHE ascii file. More...
 
int readEventHeader (double &eventWeight)
 Reads the event header from the hepevt file. More...
 
int readParticle (MCParticleGraph::GraphParticle &particle)
 Reads the information for a single particle from the LHE 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.
 
int m_indexInitial
 Maximum index of particles in each event that must be set as c_Initial (1-based).
 
int m_indexVirtual
 Maximum index of particles in each event that must be set as c_IsVirtual (1-based).
 

Static Protected Attributes

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

Detailed Description

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

The class is very similar to the HepEvt Reader

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 43 of file LHEReader.h.

Member Function Documentation

◆ BELLE2_DEFINE_EXCEPTION()

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.


◆ 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 LHE 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 39 of file LHEReader.cc.

40 {
41 // int eventID = -1;
42 // int nparticles = readEventHeader(eventID, eventWeight);
43  int nparticles = readEventHeader(eventWeight);
44  if (nparticles <= 0) {
45  throw (LHEEmptyEventError() << m_lineNr << nparticles);
46  }
47 
48  int first = graph.size();
49  //Make list of particles
50  for (int i = 0; i < nparticles; i++) {
51  graph.addParticle();
52  }
53 
54  double r, x = 0, y = 0, z = 0, t = 0;
55  //Read particles from file
56  for (int i = 0; i < nparticles; ++i) {
57  MCParticleGraph::GraphParticle& p = graph[first + i];
58  int mother = readParticle(p);
59 
60  // add the mother
61  if (mother > 0) {
62  MCParticleGraph::GraphParticle* q = &graph[mother - 1];
63  p.comesFrom(*q);
64  }
65 
66  //move vertex position of selected particle and its daughters
67  if (m_meanDecayLength > 0) {
68  if (p.getPDG() == m_pdgDisplaced) {
69  TF1 fr("fr", "exp(-x/[0])", 0, 1000000);
70  TLorentzVector p4 = p.get4Vector();
71  fr.SetRange(m_Rmin, m_Rmax);
72  fr.SetParameter(0, m_meanDecayLength * p4.Gamma());
73  r = fr.GetRandom();
74  x = r * p4.Px() / p4.P();
75  y = r * p4.Py() / p4.P();
76  z = r * p4.Pz() / p4.P();
77  p.setDecayVertex(TVector3(x, y, z));
78  t = (r / Const::speedOfLight) * (p4.E() / p4.P());
79  p.setDecayTime(t);
80  p.setValidVertex(true);
81  }
82 
83  if (mother > 0) {
84  if (graph[mother - 1].getPDG() == m_pdgDisplaced) {
85  p.setProductionVertex(TVector3(x, y, z));
86  p.setProductionTime(t);
87  p.setValidVertex(true);
88  }
89  }
90  }
91 
92  // boost particles to lab frame: both momentum and vertex
93  TLorentzVector p4 = p.get4Vector();
94  TLorentzVector v4;
95  if (m_wrongSignPz) // this means we have to mirror Pz
96  p4.SetPz(-1.0 * p4.Pz());
97  p4 = m_labboost * p4;
98  p.set4Vector(p4);
99  if (p.getPDG() == m_pdgDisplaced) {
100  v4.SetXYZT(p.getDecayVertex().X(), p.getDecayVertex().Y(), p.getDecayVertex().Z(), Const::speedOfLight * p.getDecayTime());
101  v4 = m_labboost * v4;
102  p.setDecayVertex(v4.X(), v4.Y(), v4.Z());
103  p.setDecayTime(v4.T() / Const::speedOfLight);
104  } else if (mother > 0) {
105  if (graph[mother - 1].getPDG() == m_pdgDisplaced) {
106  v4.SetXYZT(p.getProductionVertex().X(), p.getProductionVertex().Y(), p.getProductionVertex().Z(),
107  Const::speedOfLight * p.getProductionTime());
108  v4 = m_labboost * v4;
109  p.setProductionVertex(v4.X(), v4.Y(), v4.Z());
110  p.setProductionTime(v4.T() / Const::speedOfLight);
111  }
112  }
113 
114 
115  // initial 2 (e+/e-), virtual 3 (Z/gamma*)
116  // check if particle should be made virtual according to steering options:
117  if (i < m_indexVirtual && i >= m_indexInitial)
118  p.addStatus(MCParticle::c_IsVirtual);
119 
120  if (i < m_indexInitial)
121  p.addStatus(MCParticle::c_Initial);
122 
123  if (m_indexVirtual < m_indexInitial) B2WARNING("IsVirtual particle requested but is overwritten by Initial");
124 
125  }
126 // return eventID;
127  return -1;
128 }

◆ getLine()

std::string getLine ( )
protected

Returns the current line from the LHE ascii file.

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

Definition at line 149 of file LHEReader.cc.

◆ open()

void open ( const std::string &  filename)

Opens an ascii file and prepares it for reading.

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

Definition at line 31 of file LHEReader.cc.

◆ readEventHeader()

int readEventHeader ( 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 168 of file LHEReader.cc.

◆ readParticle()

int readParticle ( MCParticleGraph::GraphParticle particle)
protected

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

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

Definition at line 215 of file LHEReader.cc.

◆ setInitialIndex()

void setInitialIndex ( int  index)
inline

Set the maximum index of particles in each event that must be set as c_Initial (1-based).

Parameters
[in]indexMaximum index for c_Initial.

Definition at line 106 of file LHEReader.h.

113 :

◆ setVirtualIndex()

void setVirtualIndex ( int  index)
inline

Set the maximum index of particles in each event that must be set as c_IsVirtual (1-based).

Parameters
[in]indexMaximum index for c_IsVirtual.

Definition at line 112 of file LHEReader.h.

◆ 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 131 of file LHEReader.cc.


The documentation for this class was generated from the following files:
Belle2::LHEReader::m_Rmin
double m_Rmin
Minimum of vertex distance to IP.
Definition: LHEReader.h:117
Belle2::MCParticleGraph::size
size_t size() const
Return the number of particles in the graph.
Definition: MCParticleGraph.h:253
Belle2::MCParticle::c_IsVirtual
@ c_IsVirtual
bit 4: Particle is virtual and not going to Geant4.
Definition: MCParticle.h:66
Belle2::LHEReader::m_meanDecayLength
double m_meanDecayLength
Mean lifetime*c of displaced particle.
Definition: LHEReader.h:116
Belle2::LHEReader::m_pdgDisplaced
int m_pdgDisplaced
PDG code of the displaced particle being studied.
Definition: LHEReader.h:119
Belle2::Const::speedOfLight
static const double speedOfLight
[cm/ns]
Definition: Const.h:568
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::LHEReader::m_wrongSignPz
bool m_wrongSignPz
Bool to indicate that HER and LER were swapped.
Definition: LHEReader.h:114
Belle2::MCParticle::c_Initial
@ c_Initial
bit 5: Particle is initial such as e+ or e- and not going to Geant4
Definition: MCParticle.h:68
Belle2::MCParticleGraph::addParticle
GraphParticle & addParticle()
Add new particle to the graph.
Definition: MCParticleGraph.h:305
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::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