rivet is hosted by Hepforge, IPPP Durham

Rivet analyses reference

MC_PRINTEVENT

Print out a dump of each event to standard output
Experiment: ()
Status: VALIDATED
Authors:
  • Andy Buckley
No references listed
Beams: * *
Beam energies: ANY
Run details:
  • Can be used with any event type.

Print out a dump of the event structure to the terminal standard output, in a conveniently human readable form with e.g. particle names in addition to the usual numerical ID codes.

Source code: MC_PRINTEVENT.cc
  1// -*- C++ -*-
  2#include "Rivet/Analysis.hh"
  3#include "Rivet/Projections/FinalState.hh"
  4
  5namespace Rivet {
  6
  7
  8  /// @author Andy Buckley
  9  class MC_PRINTEVENT : public Analysis {
 10  public:
 11
 12    /// Constructor
 13    MC_PRINTEVENT()
 14      : Analysis("MC_PRINTEVENT")
 15    {    }
 16
 17
 18    /// @name Analysis methods
 19    //@{
 20
 21    void init() {
 22
 23      /// Set up particle name map
 24      // quarks & gluons
 25      _pnames[1] = "d";
 26      _pnames[-1] = "d~";
 27      _pnames[2] = "u";
 28      _pnames[-2] = "u~";
 29      _pnames[3] = "s";
 30      _pnames[-3] = "s~";
 31      _pnames[4] = "c";
 32      _pnames[-4] = "c~";
 33      _pnames[5] = "b";
 34      _pnames[-5] = "b~";
 35      _pnames[6] = "t";
 36      _pnames[-6] = "t~";
 37      // bosons
 38      _pnames[21] = "g";
 39      _pnames[22] = "gamma";
 40      _pnames[23] = "Z0";
 41      _pnames[24] = "W+";
 42      _pnames[-24] = "W-";
 43      _pnames[25] = "h0";
 44      _pnames[26] = "h0";
 45      // leptons
 46      _pnames[11] = "e-";
 47      _pnames[-11] = "e+";
 48      _pnames[13] = "mu-";
 49      _pnames[-13] = "mu+";
 50      _pnames[15] = "tau-";
 51      _pnames[-15] = "tau+";
 52      _pnames[12] = "nu_e";
 53      _pnames[-12] = "nu_e~";
 54      _pnames[14] = "nu_mu";
 55      _pnames[-14] = "nu_mu~";
 56      _pnames[16] = "nu_tau";
 57      _pnames[-16] = "nu_tau~";
 58      // common hadrons
 59      _pnames[111] = "pi0";
 60      _pnames[211] = "pi+";
 61      _pnames[-211] = "pi-";
 62      _pnames[221] = "eta";
 63      _pnames[331] = "eta'";
 64      _pnames[113] = "rho0";
 65      _pnames[213] = "rho+";
 66      _pnames[-213] = "rho-";
 67      _pnames[223] = "omega";
 68      _pnames[333] = "phi";
 69      _pnames[130] = "K0L";
 70      _pnames[310] = "K0S";
 71      _pnames[311] = "K0";
 72      _pnames[-311] = "K0";
 73      _pnames[321] = "K+";
 74      _pnames[-321] = "K-";
 75      _pnames[313] = "K*0";
 76      _pnames[-313] = "K*0~";
 77      _pnames[323] = "K*+";
 78      _pnames[-323] = "K*-";
 79      _pnames[411] = "D+";
 80      _pnames[-411] = "D-";
 81      _pnames[421] = "D0";
 82      _pnames[-421] = "D0~";
 83      _pnames[413] = "D*+";
 84      _pnames[-413] = "D*-";
 85      _pnames[423] = "D*0";
 86      _pnames[-423] = "D*0~";
 87      _pnames[431] = "Ds+";
 88      _pnames[-431] = "Ds-";
 89      _pnames[433] = "Ds*+";
 90      _pnames[-433] = "Ds*-";
 91      _pnames[511] = "B0";
 92      _pnames[-511] = "B0~";
 93      _pnames[521] = "B+";
 94      _pnames[-521] = "B-";
 95      _pnames[513] = "B*0";
 96      _pnames[-513] = "B*0~";
 97      _pnames[523] = "B*+";
 98      _pnames[-523] = "B*-";
 99      _pnames[531] = "B0s";
100      _pnames[541] = "Bc+";
101      _pnames[-541] = "Bc-";
102      _pnames[441] = "eta_c(1S)";
103      _pnames[443] = "J/psi(1S)";
104      _pnames[551] = "eta_b(1S)";
105      _pnames[553] = "Upsilon(1S)";
106      _pnames[2212] = "p+";
107      _pnames[-2212] = "p-";
108      _pnames[2112] = "n";
109      _pnames[-2112] = "n~";
110      _pnames[2224] = "Delta++";
111      _pnames[2214] = "Delta+";
112      _pnames[2114] = "Delta0";
113      _pnames[1114] = "Delta-";
114      _pnames[3122] = "Lambda";
115      _pnames[-3122] = "Lambda~";
116      _pnames[3222] = "Sigma+";
117      _pnames[-3222] = "Sigma+~";
118      _pnames[3212] = "Sigma0";
119      _pnames[-3212] = "Sigma0~";
120      _pnames[3112] = "Sigma-";
121      _pnames[-3112] = "Sigma-~";
122      _pnames[4122] = "Lambda_c+";
123      _pnames[-4122] = "Lambda_c-";
124      _pnames[5122] = "Lambda_b";
125      // exotic
126      _pnames[32] = "Z'";
127      _pnames[34] = "W'+";
128      _pnames[-34] = "W'-";
129      _pnames[35] = "H0";
130      _pnames[36] = "A0";
131      _pnames[37] = "H+";
132      _pnames[-37] = "H-";
133      // shower-specific
134      _pnames[91] = "cluster";
135      _pnames[92] = "string";
136      _pnames[9922212] = "remn";
137      _pnames[1103] = "dd";
138      _pnames[2101] = "ud0";
139      _pnames[2103] = "ud1";
140      _pnames[2203] = "uu";
141
142    }
143
144
145    /// Perform the per-event analysis
146    void analyze(const Event& event) {
147      /// @todo Wouldn't this be nice... if HepMC::IO_AsciiParticles was sane :-/
148      // printEvent(event.genEvent());
149
150      #ifdef RIVET_ENABLE_HEPMC_3
151      
152      /// @todo gonna try this instead of replicating everything below
153      RivetHepMC::Print::content(*(event.genEvent()));
154      
155      #else
156      
157      const GenEvent* evt = event.genEvent();
158
159      cout << string(120, '=') << "\n" << endl;
160
161      // Weights
162      cout << "Weights(" << evt->weights().size() << ")=";
163      /// @todo Re-enable
164      // for (double w,  evt->weights())
165      //   cout << w << " ";
166      cout << "\n"
167           << "EventScale " << evt->event_scale()
168           << " [energy] \t alphaQCD=" << evt->alphaQCD()
169           << "\t alphaQED=" << evt->alphaQED() << endl;
170
171      if (evt->pdf_info()) {
172        cout << "PdfInfo: id1=" << evt->pdf_info()->id1()
173             << " id2=" << evt->pdf_info()->id2()
174             << " x1=" << evt->pdf_info()->x1()
175             << " x2=" << evt->pdf_info()->x2()
176             << " q=" << evt->pdf_info()->scalePDF()
177             << " xpdf1=" << evt->pdf_info()->pdf1()
178             << " xpdf2=" << evt->pdf_info()->pdf2()
179             << endl;
180      } else {
181        cout << "PdfInfo: EMPTY";
182      }
183
184      // Print a legend to describe the particle info
185      char particle_legend[120];
186      sprintf( particle_legend,"     %9s %8s %-15s %4s %8s %8s   (%9s,%9s,%9s,%9s,%9s)",
187               "Barcode","PDG ID","Name","Stat","ProdVtx","DecayVtx","Px","Py","Pz","E ","m");
188      cout << endl;
189      cout << "                                       GenParticle Legend\n" << particle_legend << "\n";
190      // if (m_vertexinfo) {
191      //   sprintf( particle_legend," %60s (%9s,%9s,%9s,%9s)"," ","Vx","Vy","Vz","Vct ");
192      //   cout << particle_legend << endl;
193      // }
194      // cout << string(120, '_') << endl;
195
196      // Print all particles
197      // const HepPDT::ParticleDataTable* pdt = m_ppsvc->PDT();
198      for (HepMC::GenEvent::particle_const_iterator p = evt->particles_begin(); p != evt->particles_end(); ++p) {
199        int p_bcode = (*p)->barcode();
200        int p_pdg_id = (*p)->pdg_id();
201        double p_px = (*p)->momentum().px();
202        double p_py = (*p)->momentum().py();
203        double p_pz = (*p)->momentum().pz();
204        double p_pe = (*p)->momentum().e();
205
206        int p_stat = (*p)->status();
207        int p_prodvtx = 0;
208        if ((*p)->production_vertex() && (*p)->production_vertex()->barcode() != 0) {
209          p_prodvtx = (*p)->production_vertex()->barcode();
210        }
211        int p_endvtx = 0;
212        if ((*p)->end_vertex() && (*p)->end_vertex()->barcode() != 0) {
213          p_endvtx=(*p)->end_vertex()->barcode();
214        }
215        // double v_x = 0;
216        // double v_y = 0;
217        // double v_z = 0;
218        // double v_ct = 0;
219        // if ((*p)->production_vertex()) {
220        //   v_x = (*p)->production_vertex()->position().x();
221        //   v_y = (*p)->production_vertex()->position().y();
222        //   v_z = (*p)->production_vertex()->position().z();
223        //   v_ct = (*p)->production_vertex()->position().t();
224        // }
225
226        // Mass (prefer generated mass if available)
227        double p_mass = (*p)->generated_mass();
228        if (p_mass == 0 && !(p_stat == 1 && p_pdg_id == 22)) p_mass = (*p)->momentum().m();
229
230        // Particle names
231        string sname = (_pnames.find(p_pdg_id) != _pnames.end()) ? _pnames[p_pdg_id] : "";
232        const char* p_name = sname.c_str() ;
233
234        char particle_entries[120];
235        sprintf(particle_entries, " %9i %8i %-15s %4i %8i %8i   (%+9.3g,%+9.3g,%+9.3g,%+9.3g,%9.3g)",
236                p_bcode, p_pdg_id, p_name, p_stat, p_prodvtx, p_endvtx, p_px, p_py, p_pz, p_pe, p_mass);
237        cout << particle_entries << "\n";
238        // if (m_vertexinfo) {
239        //   sprintf(particle_entries," %60s (%+9.3g,%+9.3g,%+9.3g,%+9.3g)"," ",v_x, v_y, v_z, v_ct);
240        //   cout << particle_entries << "\n";
241        // }
242      }
243
244      cout << "\n" << endl;
245      
246      #endif // VERSION_CODE >= 3000000
247    }
248
249
250    /// Normalise histograms etc., after the run
251    void finalize() {    }
252
253    //@}
254
255  private:
256
257    map<long, string> _pnames;
258
259
260  };
261
262
263
264  // The hook for the plugin system
265  RIVET_DECLARE_PLUGIN(MC_PRINTEVENT);
266
267}