rivet is hosted by Hepforge, IPPP Durham
MC_XS.cc
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 #include "Rivet/Analysis.hh"
00003 #include "HepMC/HepMCDefs.h"
00004 
00005 namespace Rivet {
00006 
00007   /// @brief Analysis for the generated cross section
00008   class MC_XS : public Analysis {
00009   public:
00010 
00011     /// @name Constructors etc.
00012     //@{
00013 
00014     /// Constructor
00015     MC_XS()
00016       : Analysis("MC_XS")
00017     {    }
00018 
00019     //@}
00020 
00021 
00022   public:
00023 
00024     /// @name Analysis methods
00025     //@{
00026 
00027     /// Book histograms and initialise projections before the run
00028     void init() {
00029       /// @todo Convert to Scatter1D or Counter
00030       _h_XS   = bookScatter2D("XS");
00031       _h_N    = bookHisto1D("N", 1, 0.0, 1.0);
00032       _h_pmXS = bookHisto1D("pmXS", 2, -1.0, 1.0);
00033       _h_pmN  = bookHisto1D("pmN", 2, -1.0, 1.0);
00034       _mc_xs = _mc_error = 0.;
00035     }
00036 
00037 
00038     /// Perform the per-event analysis
00039     void analyze(const Event& event) {
00040       _h_N->fill(0.5,1.);
00041       _h_pmXS->fill(0.5*(event.weight() > 0 ? 1. : -1), abs(event.weight()));
00042       _h_pmN ->fill(0.5*(event.weight() > 0 ? 1. : -1), 1.);
00043       #ifdef HEPMC_HAS_CROSS_SECTION
00044       _mc_xs    = event.genEvent()->cross_section()->cross_section();
00045       _mc_error = event.genEvent()->cross_section()->cross_section_error();
00046       #endif
00047     }
00048 
00049 
00050     /// Normalise histograms etc., after the run
00051     void finalize() {
00052       scale(_h_pmXS, crossSection()/sumOfWeights());
00053       #ifndef HEPMC_HAS_CROSS_SECTION
00054       _mc_xs = crossSection();
00055       _mc_error = 0.0;
00056       #endif
00057       _h_XS->addPoint(0, _mc_xs, 0.5, _mc_error);
00058     }
00059 
00060     //@}
00061 
00062 
00063   private:
00064 
00065     /// @name Histograms
00066     //@{
00067     Scatter2DPtr _h_XS;
00068     Histo1DPtr _h_N;
00069     Histo1DPtr _h_pmXS;
00070     Histo1DPtr _h_pmN;
00071     double _mc_xs, _mc_error;
00072     //@}
00073 
00074   };
00075 
00076 
00077   // The hook for the plugin system
00078   DECLARE_RIVET_PLUGIN(MC_XS);
00079 
00080 }