rivet is hosted by Hepforge, IPPP Durham
EXAMPLE_CUTS.cc
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 #include "Rivet/Analysis.hh"
00003 #include "Rivet/Projections/FinalState.hh"
00004 #include "Rivet/Cuts.hh"
00005 
00006 namespace Rivet {
00007 
00008   using namespace Cuts;
00009 
00010 
00011   /// @brief Just measures a few random things as an example.
00012   class EXAMPLE_CUTS : public Analysis {
00013   public:
00014 
00015     /// Constructor
00016     EXAMPLE_CUTS()
00017       : Analysis("EXAMPLE_CUTS")
00018     {
00019       // No counters etc. to initialise, hence nothing to do here!
00020     }
00021 
00022 
00023     /// @name Analysis methods
00024     //@{
00025 
00026     /// Set up projections and book histograms
00027     void init() {
00028       // Projections
00029       const FinalState cnfs( etaIn(-4, 4) );
00030       addProjection(cnfs, "FS");
00031 
00032       // Histograms
00033       _histPt         = bookHisto1D("pT", 30, 0, 30);
00034       _histMass       = bookHisto1D("Mass", 20, 0, 1);
00035 
00036     }
00037 
00038 
00039     /// Do the analysis
00040     void analyze(const Event& event) {
00041       // Make sure to always include the event weight in histogram fills!
00042       const double weight = event.weight();
00043 
00044       const Particles ps = applyProjection<FinalState>(event, "FS").particlesByPt();
00045 
00046       Cut ptcut = range( pT, 5, 20 );
00047       Cut masscut = range( Cuts::mass, 0, 0.2);
00048       Cut combine = ptcut & masscut; //Possible to combine cuts
00049 
00050       foreach(const Particle& p, ps) {
00051         if ( ptcut->accept(p) ) 
00052       _histPt->fill(p.momentum().pT(), weight);
00053     if ( combine->accept(p) ) 
00054       _histMass->fill(p.momentum().mass(), weight);
00055       }
00056 
00057     }
00058 
00059 
00060     /// Finalize
00061     void finalize() {
00062       normalize(_histPt);
00063       normalize(_histMass);
00064     }
00065 
00066     //@}
00067 
00068 
00069   private:
00070 
00071     //@{
00072     /// Histograms
00073     Histo1DPtr _histPt, _histMass;
00074     //@}
00075 
00076   };
00077 
00078 
00079 
00080   // The hook for the plugin system
00081   DECLARE_RIVET_PLUGIN(EXAMPLE_CUTS);
00082 
00083 }