rivet is hosted by Hepforge, IPPP Durham
Rivet 3.1.6
WriterCompressedAscii.hh
1// -*- C++ -*-
2//
3// This file is part of HepMC
4// Copyright (C) 2014-2019 The HepMC collaboration (see AUTHORS for details)
5//
6#ifndef HEPMC3_WRITERCOMPRESSEDASCII_H
7#define HEPMC3_WRITERCOMPRESSEDASCII_H
17#include "Rivet/Tools/RivetHepMC.hh"
18#include "HepMC3/Writer.h"
19#include "HepMC3/GenEvent.h"
20#include "HepMC3/GenRunInfo.h"
21#include <string>
22#include <fstream>
23
24namespace Rivet {
25
26class WriterCompressedAscii : public HepMC3::Writer {
27
28public:
29
30 typedef HepMC3::GenRunInfo GenRunInfo;
31 typedef HepMC3::FourVector FourVector;
32 typedef HepMC3::ConstGenVertexPtr ConstGenVertexPtr;
33 typedef HepMC3::ConstGenParticlePtr ConstGenParticlePtr;
34
37 WriterCompressedAscii(const std::string& filename,
38 shared_ptr<GenRunInfo> run = shared_ptr<GenRunInfo>());
39
41 WriterCompressedAscii(std::ostream& stream,
42 shared_ptr<GenRunInfo> run = shared_ptr<GenRunInfo>());
43
45 ~WriterCompressedAscii();
46
50 void write_event(const GenEvent& evt);
51
53 void write_run_info();
54
56 bool failed() { return (bool)m_file.rdstate(); }
57
59 void close();
60
65 void use_doubles() {
66 m_use_integers = false;
67 }
68
73 void use_integers() {
74 m_use_integers = true;
75 }
76
81 void add_stripid(long pdgid) {
82 m_stripid.insert(pdgid);
83 }
84
89 void strip(GenEvent & e);
90
94 void set_precision(int prec) {
95 m_precision = prec;
96 }
97
102 void set_precision_phi(double prec) {
103 m_precision_phi = prec;
104 }
105
110 void set_precision_eta(double prec) {
111 m_precision_eta = prec;
112 }
113
118 void set_precision_e(double prec) {
119 m_precision_e = prec;
120 }
121
126 void set_precision_m(double prec) {
127 m_precision_m = prec;
128 }
129
131 int precision() const {
132 return m_precision;
133 }
134
136 double precision_phi() const {
137 return m_precision_phi;
138 }
139
141 double precision_eta() const {
142 return m_precision_eta;
143 }
144
146 double precision_e() const {
147 return m_precision_e;
148 }
149
151 double precision_m() const {
152 return m_precision_m;
153 }
154
156 double psrap(const FourVector & p) const;
157
158private:
159
161 std::string escape(const std::string& s) const;
162
164
165
167
168
170 void write_position(FourVector pos);
171
173 void write_momentum(FourVector p);
174
176 void write_mass(ConstGenParticlePtr p);
177
181 void write_vertex(ConstGenVertexPtr v);
182
186 void write_particle(ConstGenParticlePtr p);
187
189 ConstGenVertexPtr rootvertex() {
190 vector<ConstGenParticlePtr> beams = m_current->beams();
191 if ( beams.empty() ) return ConstGenVertexPtr();
192 return beams[0]->production_vertex();
193 }
195
196private:
197
198 bool m_use_integers;
200
201 std::ofstream m_file;
202 std::ostream* m_stream;
203
204 double m_precision_phi;
205 double m_precision_eta;
206 double m_precision_e;
207 double m_precision_m;
208 int m_precision;
209 set<long> m_stripid;
210 map<long,long> m_masses;
211
212 const GenEvent * m_current;
213 std::ostringstream os;
214
215};
216
217
218} // namespace HepMC3
219
220#endif
double p(const ParticleBase &p)
Unbound function access to p.
Definition: ParticleBaseUtils.hh:653
Definition: MC_Cent_pPb.hh:10
ParticlePair beams(const Event &e)
Get beam particles from an event.