HepMC3 event record library: WriterRootTreeOPAL.cc Source File

HepMC3 event record library

WriterRootTreeOPAL.cc
1// -*- C++ -*-
2//
3// This file is part of HepMC
4// Copyright (C) 2014-2023 The HepMC collaboration (see AUTHORS for details)
5//
6#include "WriterRootTreeOPAL.h"
7#include "TTree.h"
8namespace HepMC3
9{
10WriterRootTreeOPAL::WriterRootTreeOPAL(const std::string &filename,std::shared_ptr<GenRunInfo> run):WriterRootTree::WriterRootTree(filename,"h10","h10",run) {}
11 void WriterRootTreeOPAL::init_branches()
12{
13 m_tree->Branch("Irun", &m_Irun);
14 m_tree->Branch("Ievnt", &m_Ievnt);
15 m_tree->Branch("Ebeam",&m_Ebeam);
16}
17 void WriterRootTreeOPAL::write_event(const GenEvent &evt)
18{
19 m_Ievnt=evt.event_number();
20 std::vector<HepMC3::ConstGenParticlePtr> beams;
21 for (const auto& particle : evt.particles()) {
22 if (particle->status() == 4 && std::abs(particle->pid()) == 11)
23 { beams.push_back(particle);}
24 }
25 if (beams.size() == 2) {
26 m_Ebeam = std::abs(beams[0]->momentum().e());
27 } else {
28 m_Ebeam = std::abs(evt.particles().front()->momentum().e());
29 }
30 WriterRootTree::write_event(evt);
31}
32 void WriterRootTreeOPAL::set_run_number(const int nr) {m_Irun=nr;}
33} // namespace HepMC3
WriterRootTreeOPAL.h
Definition of class WriterRootTreeOPAL.
HepMC3::GenEvent
Stores event-related information.
Definition GenEvent.h:47
HepMC3::GenEvent::event_number
int event_number() const
Get event number.
Definition GenEvent.h:155
HepMC3::GenEvent::particles
const std::vector< ConstGenParticlePtr > & particles() const
Get list of particles (const).
Definition GenEvent.cc:39
HepMC3::WriterRootTreeOPAL::m_Irun
int m_Irun
Run number.
Definition WriterRootTreeOPAL.h:36
HepMC3::WriterRootTreeOPAL::m_Ebeam
float m_Ebeam
Beam energy in GEV.
Definition WriterRootTreeOPAL.h:35
HepMC3::WriterRootTreeOPAL::set_run_number
void set_run_number(const int nr)
Set run number.
Definition WriterRootTreeOPAL.cc:32
HepMC3::WriterRootTreeOPAL::init_branches
void init_branches()
Init ROOT branches.
Definition WriterRootTreeOPAL.cc:11
HepMC3::WriterRootTreeOPAL::WriterRootTreeOPAL
WriterRootTreeOPAL(const std::string &filename, std::shared_ptr< GenRunInfo > run=std::shared_ptr< GenRunInfo >())
Constructor.
Definition WriterRootTreeOPAL.cc:10
HepMC3::WriterRootTreeOPAL::write_event
void write_event(const GenEvent &evt)
Write event.
Definition WriterRootTreeOPAL.cc:17
HepMC3::WriterRootTreeOPAL::m_Ievnt
int m_Ievnt
Event number.
Definition WriterRootTreeOPAL.h:37
HepMC3::WriterRootTree::m_tree
TTree * m_tree
Tree handler. Public to allow simple access, e.g. custom branches.
Definition WriterRootTree.h:82
HepMC3::WriterRootTree::WriterRootTree
WriterRootTree(const std::string &filename, std::shared_ptr< GenRunInfo > run=std::shared_ptr< GenRunInfo >())
Default constructor.
Definition WriterRootTree.cc:22
HepMC3::WriterRootTree::write_event
void write_event(const GenEvent &evt) override
Write event to file.
Definition WriterRootTree.cc:55
HepMC3
HepMC3 main namespace.
Definition AnalysisExample.h:24