rivet is hosted by Hepforge, IPPP Durham
EXAMPLE.cc
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 #include "Rivet/Analysis.hh"
00003 #include "Rivet/Projections/FinalState.hh"
00004 #include "Rivet/Projections/ChargedFinalState.hh"
00005 #include "Rivet/Projections/FastJets.hh"
00006 #include "Rivet/Projections/Thrust.hh"
00007 #include "Rivet/Projections/Sphericity.hh"
00008 
00009 namespace Rivet {
00010 
00011 
00012   /// @brief Just measures a few random things as an example.
00013   class EXAMPLE : public Analysis {
00014   public:
00015 
00016     /// Constructor
00017     EXAMPLE()
00018       : Analysis("EXAMPLE")
00019     {
00020       // No counters etc. to initialise, hence nothing to do here!
00021     }
00022 
00023 
00024     /// @name Analysis methods
00025     //@{
00026 
00027     /// Set up projections and book histograms
00028     void init() {
00029       // Projections
00030       const FinalState cnfs(-4, 4, 2*GeV);
00031       const ChargedFinalState cfs(-4, 4, 2*GeV);
00032       addProjection(cnfs, "FS");
00033       addProjection(cfs, "CFS");
00034       addProjection(FastJets(cnfs, FastJets::KT, 0.7), "Jets");
00035       addProjection(Thrust(cfs), "Thrust");
00036       addProjection(Sphericity(cfs), "Sphericity");
00037 
00038       // Histograms
00039       _histTot         = bookHisto1D("TotalMult", 100, -0.5, 99.5);
00040       _histChTot       = bookHisto1D("TotalChMult", 50, -1.0, 99.0);
00041       _histHadrTot     = bookHisto1D("HadrTotalMult", 100, -0.5, 99.5);
00042       _histHadrChTot   = bookHisto1D("HadrTotalChMult", 50, -1.0, 99.0);
00043       _histMajor       = bookHisto1D("Major", 10, 0.0, 0.6);
00044       _histSphericity  = bookHisto1D("Sphericity", 10, 0.0, 0.8);
00045       _histAplanarity  = bookHisto1D("Aplanarity", 10, 0.0, 0.3);
00046 
00047       // Non-uniform binning example:
00048       double edges[11] = { 0.5, 0.6, 0.7, 0.80, 0.85, 0.9, 0.92, 0.94, 0.96, 0.98, 1.0 };
00049       vector<double> vedges(edges, edges+11);
00050       _histThrust = bookHisto1D("Thrust", vedges);
00051     }
00052 
00053 
00054     /// Do the analysis
00055     void analyze(const Event& event) {
00056       // Make sure to always include the event weight in histogram fills!
00057       const double weight = event.weight();
00058 
00059       const Particles& cnparticles = applyProjection<FinalState>(event, "FS").particles();
00060       MSG_DEBUG("Total multiplicity = " << cnparticles.size());
00061       _histTot->fill(cnparticles.size(), weight);
00062       int cnhadronmult = 0;
00063       foreach (const Particle& p, cnparticles) if (PID::isHadron(p)) cnhadronmult += 1;
00064       MSG_DEBUG("Hadron multiplicity = " << cnhadronmult);
00065       _histHadrTot->fill(cnhadronmult, weight);
00066 
00067       const Particles& cparticles = applyProjection<FinalState>(event, "CFS").particles();
00068       MSG_DEBUG("Total charged multiplicity = " << cparticles.size());
00069       _histChTot->fill(cparticles.size(), weight);
00070       int chadronmult = 0;
00071       foreach (const Particle& p, cparticles) if (PID::isHadron(p)) chadronmult += 1;
00072       MSG_DEBUG("Hadron charged multiplicity = " << chadronmult);
00073       _histHadrChTot->fill(chadronmult, weight);
00074 
00075       const Thrust& t = applyProjection<Thrust>(event, "Thrust");
00076       MSG_DEBUG("Thrust = " << t.thrust());
00077       _histThrust->fill(t.thrust(), weight);
00078       _histMajor->fill(t.thrustMajor(), weight);
00079 
00080       const Sphericity& s = applyProjection<Sphericity>(event, "Sphericity");
00081       MSG_DEBUG("Sphericity = " << s.sphericity());
00082       _histSphericity->fill(s.sphericity(), weight);
00083       MSG_DEBUG("Aplanarity = " << s.aplanarity());
00084       _histAplanarity->fill(s.aplanarity(), weight);
00085 
00086       unsigned int num_b_jets = 0;
00087       const Jets jets = applyProjection<FastJets>(event, "Jets").jets(5*GeV);
00088       foreach (const Jet& j, jets) {
00089         if (j.containsBottom()) num_b_jets += 1;
00090       }
00091       MSG_DEBUG("Num B-jets with pT > 5 GeV = " << num_b_jets);
00092     }
00093 
00094 
00095     /// Finalize
00096     void finalize() {
00097       normalize(_histTot);
00098       normalize(_histChTot);
00099       normalize(_histHadrTot);
00100       normalize(_histHadrChTot);
00101       normalize(_histThrust);
00102       normalize(_histMajor);
00103       normalize(_histSphericity);
00104       normalize(_histAplanarity);
00105     }
00106 
00107     //@}
00108 
00109 
00110   private:
00111 
00112     //@{
00113     /// Histograms
00114     Histo1DPtr _histTot;
00115     Histo1DPtr _histChTot;
00116     Histo1DPtr _histHadrTot;
00117     Histo1DPtr _histHadrChTot;
00118     Histo1DPtr _histThrust;
00119     Histo1DPtr _histMajor;
00120     Histo1DPtr _histSphericity;
00121     Histo1DPtr _histAplanarity;
00122     //@}
00123 
00124   };
00125 
00126 
00127 
00128   // The hook for the plugin system
00129   DECLARE_RIVET_PLUGIN(EXAMPLE);
00130 
00131 }