MC_GENERIC.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 "Rivet/Projections/FinalState.hh"
00006 #include "Rivet/Projections/ChargedFinalState.hh"
00007 #include "LWH/Histogram1D.h"
00008 
00009 namespace Rivet {
00010 
00011 
00012   /// Generic analysis looking at various distributions of final state particles
00013   class MC_GENERIC : public Analysis {
00014   public:
00015 
00016     /// Constructor
00017     MC_GENERIC()
00018       : Analysis("MC_GENERIC")
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 
00030       // Projections
00031       const FinalState cnfs(-5.0, 5.0, 500*MeV);
00032       const ChargedFinalState cfs(-5.0, 5.0, 500*MeV);
00033       addProjection(cfs, "CFS");
00034       addProjection(cnfs, "FS");
00035 
00036       // Histograms
00037       // @todo Choose E/pT ranged based on input energies... can't do anything about kin. cuts, though
00038       _histMult   = bookHistogram1D("Mult", 100, -0.5, 199.5);
00039       _histMultCh = bookHistogram1D("MultCh", 100, -0.5, 199.5);
00040 
00041       _histPt    = bookHistogram1D("Pt", 300, 0, 30);
00042       _histPtCh  = bookHistogram1D("PtCh", 300, 0, 30);
00043 
00044       _histE    = bookHistogram1D("E", 100, 0, 200);
00045       _histECh  = bookHistogram1D("ECh", 100, 0, 200);
00046 
00047       _histEta    = bookHistogram1D("Eta", 50, -5, 5);
00048       _histEtaCh  = bookHistogram1D("EtaCh", 50, -5, 5);
00049       _tmphistEtaPlus.reset(new LWH::Histogram1D(25, 0, 5));
00050       _tmphistEtaMinus.reset(new LWH::Histogram1D(25, 0, 5));
00051       _tmphistEtaChPlus.reset(new LWH::Histogram1D(25, 0, 5));
00052       _tmphistEtaChMinus.reset(new LWH::Histogram1D(25, 0, 5));
00053 
00054       _histRapidity    = bookHistogram1D("Rapidity", 50, -5, 5);
00055       _histRapidityCh  = bookHistogram1D("RapidityCh", 50, -5, 5);
00056       _tmphistRapPlus.reset(new LWH::Histogram1D(25, 0, 5));
00057       _tmphistRapMinus.reset(new LWH::Histogram1D(25, 0, 5));
00058       _tmphistRapChPlus.reset(new LWH::Histogram1D(25, 0, 5));
00059       _tmphistRapChMinus.reset(new LWH::Histogram1D(25, 0, 5));
00060 
00061       _histPhi    = bookHistogram1D("Phi", 50, 0, TWOPI);
00062       _histPhiCh  = bookHistogram1D("PhiCh", 50, 0, TWOPI);
00063     }
00064 
00065 
00066 
00067     /// Perform the per-event analysis
00068     void analyze(const Event& event) {
00069       const double weight = event.weight();
00070 
00071       // Analyse and print some info
00072       const FinalState& cnfs = applyProjection<FinalState>(event, "FS");
00073       getLog() << Log::DEBUG << "Total multiplicity = " << cnfs.size() << endl;
00074       _histMult->fill(cnfs.size(), weight);
00075       foreach (const Particle& p, cnfs.particles()) {
00076         const double eta = p.momentum().eta();
00077         _histEta->fill(eta, weight);
00078         if (eta > 0) {
00079           _tmphistEtaPlus->fill(fabs(eta), weight);
00080         } else {
00081           _tmphistEtaMinus->fill(fabs(eta), weight);
00082         }
00083         const double rapidity = p.momentum().rapidity();
00084         _histRapidity->fill(rapidity, weight);
00085         if (rapidity > 0) {
00086           _tmphistRapPlus->fill(fabs(rapidity), weight);
00087         } else {
00088           _tmphistRapMinus->fill(fabs(rapidity), weight);
00089         }
00090         _histPt->fill(p.momentum().pT()/GeV, weight);
00091         _histE->fill(p.momentum().E()/GeV, weight);
00092         _histPhi->fill(p.momentum().phi(), weight);
00093       }
00094 
00095       const FinalState& cfs = applyProjection<FinalState>(event, "CFS");
00096       getLog() << Log::DEBUG << "Total charged multiplicity = " << cfs.size() << endl;
00097       _histMultCh->fill(cfs.size(), weight);
00098       foreach (const Particle& p, cfs.particles()) {
00099         const double eta = p.momentum().eta();
00100         _histEtaCh->fill(eta, weight);
00101         if (eta > 0) {
00102           _tmphistEtaChPlus->fill(fabs(eta), weight);
00103         } else {
00104           _tmphistEtaChMinus->fill(fabs(eta), weight);
00105         }
00106         const double rapidity = p.momentum().rapidity();
00107         _histRapidityCh->fill(rapidity, weight);
00108         if (rapidity > 0) {
00109           _tmphistRapChPlus->fill(fabs(rapidity), weight);
00110         } else {
00111           _tmphistRapChMinus->fill(fabs(rapidity), weight);
00112         }
00113         _histPtCh->fill(p.momentum().pT()/GeV, weight);
00114         _histECh->fill(p.momentum().E()/GeV, weight);
00115         _histPhiCh->fill(p.momentum().phi(), weight);
00116       }
00117 
00118     }
00119 
00120 
00121     /// Finalize
00122     void finalize() {
00123       scale(_histMult, 1/sumOfWeights());
00124       scale(_histMultCh, 1/sumOfWeights());
00125       scale(_histEta, 1/sumOfWeights());
00126       scale(_histEtaCh, 1/sumOfWeights());
00127       scale(_histRapidity, 1/sumOfWeights());
00128       scale(_histRapidityCh, 1/sumOfWeights());
00129       scale(_histPt, 1/sumOfWeights());
00130       scale(_histPtCh, 1/sumOfWeights());
00131       scale(_histE, 1/sumOfWeights());
00132       scale(_histECh, 1/sumOfWeights());
00133       scale(_histPhi, 1/sumOfWeights());
00134       scale(_histPhiCh, 1/sumOfWeights());
00135 
00136       histogramFactory().divide(histoPath("EtaPMRatio"), *_tmphistEtaPlus, *_tmphistEtaMinus);
00137       histogramFactory().divide(histoPath("EtaChPMRatio"), *_tmphistEtaChPlus, *_tmphistEtaChMinus);
00138       histogramFactory().divide(histoPath("RapidityPMRatio"), *_tmphistRapPlus, *_tmphistRapMinus);
00139       histogramFactory().divide(histoPath("RapidityChPMRatio"), *_tmphistRapChPlus, *_tmphistRapChMinus);
00140     }
00141 
00142     //@}
00143 
00144 
00145   private:
00146 
00147     /// Temporary histos used to calculate eta+/eta- ratio plot
00148     shared_ptr<LWH::Histogram1D> _tmphistEtaPlus, _tmphistEtaMinus;
00149     shared_ptr<LWH::Histogram1D> _tmphistEtaChPlus, _tmphistEtaChMinus;
00150     shared_ptr<LWH::Histogram1D> _tmphistRapPlus, _tmphistRapMinus;
00151     shared_ptr<LWH::Histogram1D> _tmphistRapChPlus, _tmphistRapChMinus;
00152 
00153     //@{
00154     /// Histograms
00155     AIDA::IHistogram1D *_histMult, *_histMultCh;
00156     AIDA::IHistogram1D *_histEta, *_histEtaCh;
00157     AIDA::IHistogram1D *_histRapidity, *_histRapidityCh;
00158     AIDA::IHistogram1D *_histPt, *_histPtCh;
00159     AIDA::IHistogram1D *_histE, *_histECh;
00160     AIDA::IHistogram1D *_histPhi, *_histPhiCh;
00161     //@}
00162 
00163   };
00164 
00165 
00166 
00167   // This global object acts as a hook for the plugin system
00168   AnalysisBuilder<MC_GENERIC> plugin_MC_GENERIC;
00169 
00170 }