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