rivet is hosted by Hepforge, IPPP Durham
MC_PRINTEVENT.cc
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 #include "Rivet/Analysis.hh"
00003 #include "Rivet/Projections/FinalState.hh"
00004 
00005 namespace Rivet {
00006 
00007 
00008   /// @author Andy Buckley
00009   class MC_PRINTEVENT : public Analysis {
00010   public:
00011 
00012     /// @name Constructors etc.
00013     //@{
00014 
00015     /// Constructor
00016     MC_PRINTEVENT()
00017       : Analysis("MC_PRINTEVENT")
00018     {    }
00019 
00020     //@}
00021 
00022 
00023   public:
00024 
00025     /// @name Analysis methods
00026     //@{
00027 
00028     void init() {
00029 
00030       /// Set up particle name map
00031       // quarks & gluons
00032       _pnames[1] = "d";
00033       _pnames[-1] = "d~";
00034       _pnames[2] = "u";
00035       _pnames[-2] = "u~";
00036       _pnames[3] = "s";
00037       _pnames[-3] = "s~";
00038       _pnames[4] = "c";
00039       _pnames[-4] = "c~";
00040       _pnames[5] = "b";
00041       _pnames[-5] = "b~";
00042       _pnames[6] = "t";
00043       _pnames[-6] = "t~";
00044       // bosons
00045       _pnames[21] = "g";
00046       _pnames[22] = "gamma";
00047       _pnames[23] = "W+";
00048       _pnames[-23] = "W-";
00049       _pnames[-24] = "Z0";
00050       _pnames[-25] = "h0";
00051       _pnames[-26] = "h0";
00052       // leptons
00053       _pnames[11] = "e-";
00054       _pnames[-11] = "e+";
00055       _pnames[13] = "mu-";
00056       _pnames[-13] = "mu+";
00057       _pnames[15] = "tau-";
00058       _pnames[-15] = "tau+";
00059       _pnames[12] = "nu_e";
00060       _pnames[-12] = "nu_e~";
00061       _pnames[14] = "nu_mu";
00062       _pnames[-14] = "nu_mu~";
00063       _pnames[16] = "nu_tau";
00064       _pnames[-16] = "nu_tau~";
00065       // common hadrons
00066       _pnames[111] = "pi0";
00067       _pnames[211] = "pi+";
00068       _pnames[-211] = "pi-";
00069       _pnames[221] = "eta";
00070       _pnames[331] = "eta'";
00071       _pnames[113] = "rho0";
00072       _pnames[213] = "rho+";
00073       _pnames[-213] = "rho-";
00074       _pnames[223] = "omega";
00075       _pnames[333] = "phi";
00076       _pnames[130] = "K0L";
00077       _pnames[310] = "K0S";
00078       _pnames[311] = "K0";
00079       _pnames[-311] = "K0";
00080       _pnames[321] = "K+";
00081       _pnames[-321] = "K-";
00082       _pnames[313] = "K*0";
00083       _pnames[-313] = "K*0~";
00084       _pnames[323] = "K*+";
00085       _pnames[-323] = "K*-";
00086       _pnames[411] = "D+";
00087       _pnames[-411] = "D-";
00088       _pnames[421] = "D0";
00089       _pnames[-421] = "D0~";
00090       _pnames[413] = "D*+";
00091       _pnames[-413] = "D*-";
00092       _pnames[423] = "D*0";
00093       _pnames[-423] = "D*0~";
00094       _pnames[431] = "Ds+";
00095       _pnames[-431] = "Ds-";
00096       _pnames[433] = "Ds*+";
00097       _pnames[-433] = "Ds*-";
00098       _pnames[511] = "B0";
00099       _pnames[-511] = "B0~";
00100       _pnames[521] = "B+";
00101       _pnames[-521] = "B-";
00102       _pnames[513] = "B*0";
00103       _pnames[-513] = "B*0~";
00104       _pnames[523] = "B*+";
00105       _pnames[-523] = "B*-";
00106       _pnames[531] = "B0s";
00107       _pnames[541] = "Bc+";
00108       _pnames[-541] = "Bc-";
00109       _pnames[441] = "eta_c(1S)";
00110       _pnames[443] = "J/psi(1S)";
00111       _pnames[551] = "eta_b(1S)";
00112       _pnames[553] = "Upsilon(1S)";
00113       _pnames[2212] = "p+";
00114       _pnames[-2212] = "p-";
00115       _pnames[2112] = "n";
00116       _pnames[-2112] = "n~";
00117       _pnames[2224] = "Delta++";
00118       _pnames[2214] = "Delta+";
00119       _pnames[2114] = "Delta0";
00120       _pnames[1114] = "Delta-";
00121       _pnames[3122] = "Lambda";
00122       _pnames[-3122] = "Lambda~";
00123       _pnames[3222] = "Sigma+";
00124       _pnames[-3222] = "Sigma+~";
00125       _pnames[3212] = "Sigma0";
00126       _pnames[-3212] = "Sigma0~";
00127       _pnames[3112] = "Sigma-";
00128       _pnames[-3112] = "Sigma-~";
00129       _pnames[4122] = "Lambda_c+";
00130       _pnames[-4122] = "Lambda_c-";
00131       _pnames[5122] = "Lambda_b";
00132       // exotic
00133       _pnames[32] = "Z'";
00134       _pnames[34] = "W'+";
00135       _pnames[-34] = "W'-";
00136       _pnames[35] = "H0";
00137       _pnames[36] = "A0";
00138       _pnames[37] = "H+";
00139       _pnames[-37] = "H-";
00140       // shower-specific
00141       _pnames[91] = "cluster";
00142       _pnames[92] = "string";
00143       _pnames[9922212] = "remn";
00144       _pnames[1103] = "dd";
00145       _pnames[2101] = "ud0";
00146       _pnames[2103] = "ud1";
00147       _pnames[2203] = "uu";
00148 
00149     }
00150 
00151 
00152     /// Perform the per-event analysis
00153     void analyze(const Event& event) {
00154       /// @todo Wouldn't this be nice... if HepMC::IO_AsciiParticles was sane :-/
00155       // printEvent(event.genEvent());
00156 
00157       const GenEvent* evt = event.genEvent();
00158 
00159       cout << string(120, '=') << "\n" << endl;
00160 
00161       // Weights
00162       cout << "Weights(" << evt->weights().size() << ")=";
00163       for (HepMC::WeightContainer::const_iterator wgt = evt->weights().begin(); wgt != evt->weights().end(); ++wgt) {
00164         cout << *wgt << " ";
00165       }
00166       cout << "\n"
00167            << "EventScale " << evt->event_scale()
00168            << " [energy] \t alphaQCD=" << evt->alphaQCD()
00169            << "\t alphaQED=" << evt->alphaQED() << endl;
00170 
00171       if (evt->pdf_info()) {
00172         cout << "PdfInfo: id1=" << evt->pdf_info()->id1()
00173              << " id2=" << evt->pdf_info()->id2()
00174              << " x1=" << evt->pdf_info()->x1()
00175              << " x2=" << evt->pdf_info()->x2()
00176              << " q=" << evt->pdf_info()->scalePDF()
00177              << " xpdf1=" << evt->pdf_info()->pdf1()
00178              << " xpdf2=" << evt->pdf_info()->pdf2()
00179              << endl;
00180       } else {
00181         cout << "PdfInfo: EMPTY";
00182       }
00183 
00184       // Print a legend to describe the particle info
00185       char particle_legend[120];
00186       sprintf( particle_legend,"     %9s %8s %-15s %4s %8s %8s   (%9s,%9s,%9s,%9s,%9s)",
00187                "Barcode","PDG ID","Name","Stat","ProdVtx","DecayVtx","Px","Py","Pz","E ","m");
00188       cout << endl;
00189       cout << "                                       GenParticle Legend\n" << particle_legend << "\n";
00190       // if (m_vertexinfo) {
00191       //   sprintf( particle_legend," %60s (%9s,%9s,%9s,%9s)"," ","Vx","Vy","Vz","Vct ");
00192       //   cout << particle_legend << endl;
00193       // }
00194       // cout << string(120, '_') << endl;
00195 
00196       // Print all particles
00197       // const HepPDT::ParticleDataTable* pdt = m_ppsvc->PDT();
00198       for (HepMC::GenEvent::particle_const_iterator p = evt->particles_begin(); p != evt->particles_end(); ++p) {
00199         int p_bcode = (*p)->barcode();
00200         int p_pdg_id = (*p)->pdg_id();
00201         double p_px = (*p)->momentum().px();
00202         double p_py = (*p)->momentum().py();
00203         double p_pz = (*p)->momentum().pz();
00204         double p_pe = (*p)->momentum().e();
00205 
00206         int p_stat = (*p)->status();
00207         int p_prodvtx = 0;
00208         if ((*p)->production_vertex() && (*p)->production_vertex()->barcode() != 0) {
00209           p_prodvtx = (*p)->production_vertex()->barcode();
00210         }
00211         int p_endvtx = 0;
00212         if ((*p)->end_vertex() && (*p)->end_vertex()->barcode() != 0) {
00213           p_endvtx=(*p)->end_vertex()->barcode();
00214         }
00215         // double v_x = 0;
00216         // double v_y = 0;
00217         // double v_z = 0;
00218         // double v_ct = 0;
00219         // if ((*p)->production_vertex()) {
00220         //   v_x = (*p)->production_vertex()->position().x();
00221         //   v_y = (*p)->production_vertex()->position().y();
00222         //   v_z = (*p)->production_vertex()->position().z();
00223         //   v_ct = (*p)->production_vertex()->position().t();
00224         // }
00225 
00226         // Mass (prefer generated mass if available)
00227         double p_mass = (*p)->generated_mass();
00228         if (p_mass == 0 && !(p_stat == 1 && p_pdg_id == 22)) p_mass = (*p)->momentum().m();
00229 
00230         // Particle names
00231         string sname = (_pnames.find(p_pdg_id) != _pnames.end()) ? _pnames[p_pdg_id] : "";
00232         const char* p_name = sname.c_str() ;
00233 
00234         char particle_entries[120];
00235         sprintf(particle_entries, " %9i %8i %-15s %4i %8i %8i   (%+9.3g,%+9.3g,%+9.3g,%+9.3g,%9.3g)",
00236                 p_bcode, p_pdg_id, p_name, p_stat, p_prodvtx, p_endvtx, p_px, p_py, p_pz, p_pe, p_mass);
00237         cout << particle_entries << "\n";
00238         // if (m_vertexinfo) {
00239         //   sprintf(particle_entries," %60s (%+9.3g,%+9.3g,%+9.3g,%+9.3g)"," ",v_x, v_y, v_z, v_ct);
00240         //   cout << particle_entries << "\n";
00241         // }
00242       }
00243 
00244       cout << "\n" << endl;
00245     }
00246 
00247 
00248     /// Normalise histograms etc., after the run
00249     void finalize() {    }
00250 
00251     //@}
00252 
00253   private:
00254 
00255     map<long, string> _pnames;
00256 
00257 
00258   };
00259 
00260 
00261 
00262   // The hook for the plugin system
00263   DECLARE_RIVET_PLUGIN(MC_PRINTEVENT);
00264 
00265 }