MC_XS.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 #include "Rivet/Analysis.hh"
00003 #include "Rivet/RivetAIDA.hh"
00004 #include "Rivet/Tools/Logging.hh"
00005 #include "HepMC/HepMCDefs.h"
00006 
00007 namespace Rivet {
00008 
00009 
00010   /// @brief Analysis for the generated cross section
00011   class MC_XS : public Analysis {
00012   public:
00013 
00014     /// @name Constructors etc.
00015     //@{
00016 
00017     /// Constructor
00018     MC_XS()
00019       : Analysis("MC_XS")
00020     {
00021       setNeedsCrossSection(true);
00022     }
00023 
00024     //@}
00025 
00026 
00027   public:
00028 
00029     /// @name Analysis methods
00030     //@{
00031 
00032     /// Book histograms and initialise projections before the run
00033     void init() {
00034       _h_XS = bookDataPointSet("XS", 1, 0.0, 1.0);
00035       _mc_xs=_mc_error=0.;
00036     }
00037 
00038 
00039     /// Perform the per-event analysis
00040     void analyze(const Event& event) {
00041 #ifdef HEPMC_HAS_CROSS_SECTION
00042       _mc_xs    = event.genEvent().cross_section()->cross_section();
00043       _mc_error = event.genEvent().cross_section()->cross_section_error();
00044 #endif
00045     }
00046 
00047 
00048     /// Normalise histograms etc., after the run
00049     void finalize() {
00050 #ifndef HEPMC_HAS_CROSS_SECTION
00051       _mc_xs=crossSection();
00052       _mc_error=0.0;
00053 #endif
00054       std::vector<double> xs,err;
00055       xs.push_back(_mc_xs);
00056       err.push_back(_mc_error);
00057       _h_XS->setCoordinate(1,xs,err);
00058     }
00059 
00060     //@}
00061 
00062 
00063   private:
00064 
00065     /// @name Histograms
00066     //@{
00067     AIDA::IDataPointSet * _h_XS;
00068     double _mc_xs, _mc_error;
00069     //@}
00070 
00071 
00072   };
00073 
00074 
00075 
00076   // This global object acts as a hook for the plugin system
00077   AnalysisBuilder<MC_XS> plugin_MC_XS;
00078 
00079 
00080 }