rivet is hosted by Hepforge, IPPP Durham
EXAMPLE_SMEAR.cc
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 #include "Rivet/Analysis.hh"
00003 #include "Rivet/Projections/FastJets.hh"
00004 #include "Rivet/Projections/IdentifiedFinalState.hh"
00005 #include "Rivet/Projections/DressedLeptons.hh"
00006 #include "Rivet/Projections/TauFinder.hh"
00007 #include "Rivet/Projections/SmearedJets.hh"
00008 #include "Rivet/Projections/SmearedParticles.hh"
00009 #include "Rivet/Projections/SmearedMET.hh"
00010 
00011 namespace Rivet {
00012 
00013 
00014   class EXAMPLE_SMEAR : public Analysis {
00015   public:
00016 
00017     /// Constructor
00018     DEFAULT_RIVET_ANALYSIS_CTOR(EXAMPLE_SMEAR);
00019 
00020 
00021     /// @name Analysis methods
00022     //@{
00023 
00024     /// Book histograms and initialise projections before the run
00025     void init() {
00026 
00027       MissingMomentum mm(Cuts::abseta < 5);
00028       declare(mm, "MET0");
00029 
00030       SmearedMET smm1(mm, MET_SMEAR_IDENTITY);
00031       declare(smm1, "MET1");
00032 
00033       SmearedMET smm2(mm, [](const Vector3& met, double){ return P3_SMEAR_LEN_GAUSS(met, 0.1*met.mod()); });
00034       declare(smm2, "MET2");
00035 
00036 
00037       FastJets fj(FinalState(Cuts::abseta < 5), FastJets::ANTIKT, 0.4);
00038       declare(fj, "Jets0");
00039 
00040       SmearedJets sj1(fj, JET_SMEAR_IDENTITY);
00041       declare(sj1, "Jets1");
00042 
00043       SmearedJets sj2(fj, JET_SMEAR_ATLAS_RUN1,
00044                       [](const Jet& j){ return j.bTagged() ? 0.7*(1 - exp(-j.pT()/(10*GeV))) : 0.01; } );
00045       declare(sj2, "Jets2");
00046 
00047       SmearedJets sj3(fj,
00048                       [](const Jet& j){ return j; },
00049                       [](const Jet& j){ return j.bTagged() ? 0.7*(1 - exp(-j.pT()/(10*GeV))) : 0.01; },
00050                       JET_CTAG_PERFECT,
00051                       [](const Jet& j){ return 0.8; });
00052       declare(sj3, "Jets3");
00053 
00054 
00055       IdentifiedFinalState photons(Cuts::abseta < 5, PID::PHOTON);
00056 
00057 
00058       IdentifiedFinalState truthelectrons(Cuts::abseta < 5 && Cuts::pT > 10*GeV, {{PID::ELECTRON, PID::POSITRON}});
00059       declare(truthelectrons, "Electrons0");
00060       DressedLeptons dressedelectrons(photons, truthelectrons, 0.2);
00061       declare(dressedelectrons, "Electrons1");
00062       SmearedParticles recoelectrons(truthelectrons, ELECTRON_EFF_ATLAS_RUN1, ELECTRON_SMEAR_ATLAS_RUN1); //< @note Can't use dressedelectrons yet...
00063       declare(recoelectrons, "Electrons2");
00064 
00065       IdentifiedFinalState truthmuons(Cuts::abseta < 5 && Cuts::pT > 10*GeV, {{PID::MUON, PID::ANTIMUON}});
00066       declare(truthmuons, "Muons0");
00067       DressedLeptons dressedmuons(photons, truthmuons, 0.2);
00068       declare(dressedmuons, "Muons1");
00069       SmearedParticles recomuons(truthmuons, MUON_EFF_ATLAS_RUN1, MUON_SMEAR_ATLAS_RUN1); //< @note Can't use dressedmuons yet...
00070       declare(recomuons, "Muons2");
00071 
00072       TauFinder truthtaus(TauFinder::ANY, Cuts::abseta < 5 && Cuts::pT > 10*GeV);
00073       declare(truthtaus, "Taus0");
00074       DressedLeptons dressedtaus(photons, truthtaus, 0.2);
00075       declare(dressedtaus, "Taus1");
00076       SmearedParticles recotaus(truthtaus, TAU_EFF_ATLAS_RUN1, TAU_SMEAR_ATLAS_RUN1); //< @note Can't use dressedtaus yet...
00077       declare(recotaus, "Taus2");
00078 
00079 
00080       _h_met_true = bookHisto1D("met_true", 30, 0.0, 120);
00081       _h_met_reco = bookHisto1D("met_reco", 30, 0.0, 120);
00082 
00083       _h_nj_true = bookHisto1D("jet_N_true", 10, -0.5, 9.5);
00084       _h_nj_reco = bookHisto1D("jet_N_reco", 10, -0.5, 9.5);
00085       _h_j1pt_true = bookHisto1D("jet_pt1_true", 30, 0.0, 120);
00086       _h_j1pt_reco = bookHisto1D("jet_pt1_reco", 30, 0.0, 120);
00087       _h_j1eta_true = bookHisto1D("jet_eta1_true", 20, -5.0, 5.0);
00088       _h_j1eta_reco = bookHisto1D("jet_eta1_reco", 20, -5.0, 5.0);
00089 
00090       _h_ne_true = bookHisto1D("elec_N_true", 5, -0.5, 4.5);
00091       _h_ne_reco = bookHisto1D("elec_N_reco", 5, -0.5, 4.5);
00092       _h_e1pt_true = bookHisto1D("elec_pt1_true", 30, 0, 120);
00093       _h_e1pt_reco = bookHisto1D("elec_pt1_reco", 30, 0, 120);
00094       _h_e1eta_true = bookHisto1D("elec_eta1_true", 20, -5.0, 5.0);
00095       _h_e1eta_reco = bookHisto1D("elec_eta1_reco", 20, -5.0, 5.0);
00096 
00097       _h_nm_true = bookHisto1D("muon_N_true", 5, -0.5, 4.5);
00098       _h_nm_reco = bookHisto1D("muon_N_reco", 5, -0.5, 4.5);
00099       _h_m1pt_true = bookHisto1D("muon_pt1_true", 30, 0, 120);
00100       _h_m1pt_reco = bookHisto1D("muon_pt1_reco", 30, 0, 120);
00101       _h_m1eta_true = bookHisto1D("muon_eta1_true", 20, -5.0, 5.0);
00102       _h_m1eta_reco = bookHisto1D("muon_eta1_reco", 20, -5.0, 5.0);
00103 
00104       _h_nt_true = bookHisto1D("tau_N_true", 5, -0.5, 4.5);
00105       _h_nt_reco = bookHisto1D("tau_N_reco", 5, -0.5, 4.5);
00106       _h_t1pt_true = bookHisto1D("tau_pt1_true", 30, 0, 120);
00107       _h_t1pt_reco = bookHisto1D("tau_pt1_reco", 30, 0, 120);
00108       _h_t1eta_true = bookHisto1D("tau_eta1_true", 20, -5.0, 5.0);
00109       _h_t1eta_reco = bookHisto1D("tau_eta1_reco", 20, -5.0, 5.0);
00110     }
00111 
00112 
00113     /// Perform the per-event analysis
00114     void analyze(const Event& event) {
00115       const double weight = event.weight();
00116 
00117       const Vector3 met0 = apply<MissingMomentum>(event, "MET0").vectorEt();
00118       const Vector3 met1 = apply<SmearedMET>(event, "MET1").vectorEt();
00119       const Vector3 met2 = apply<SmearedMET>(event, "MET2").vectorEt();
00120       MSG_DEBUG("MET = " << met0.mod()/GeV << ", " << met1.mod()/GeV << ", " << met2.mod()/GeV << " GeV");
00121       _h_met_true->fill(met0.mod()/GeV, weight);
00122       _h_met_reco->fill(met2.mod()/GeV, weight);
00123 
00124       const Jets jets0 = apply<JetAlg>(event, "Jets0").jetsByPt(Cuts::pT > 10*GeV);
00125       const Jets jets1 = apply<JetAlg>(event, "Jets1").jetsByPt(Cuts::pT > 10*GeV);
00126       const Jets jets2 = apply<JetAlg>(event, "Jets2").jetsByPt(Cuts::pT > 10*GeV);
00127       const Jets jets3 = apply<JetAlg>(event, "Jets3").jetsByPt(Cuts::pT > 10*GeV);
00128       MSG_DEBUG("Numbers of jets = " << jets0.size() << " true; "
00129                << jets1.size() << ", " << jets2.size() << ", " << jets3.size());
00130       _h_nj_true->fill(jets0.size(), weight);
00131       _h_nj_reco->fill(jets2.size(), weight);
00132       if (!jets0.empty()) {
00133         _h_j1pt_true->fill(jets0.front().pT()/GeV, weight);
00134         _h_j1eta_true->fill(jets0.front().eta(), weight);
00135       }
00136       if (!jets2.empty()) {
00137         _h_j1pt_reco->fill(jets2.front().pT()/GeV, weight);
00138         _h_j1eta_reco->fill(jets2.front().eta(), weight);
00139       }
00140 
00141       const Particles& elecs1 = apply<ParticleFinder>(event, "Electrons1").particlesByPt();
00142       const Particles& elecs2 = apply<ParticleFinder>(event, "Electrons2").particlesByPt();
00143       MSG_DEBUG("Numbers of electrons = " << elecs1.size() << " true; " << elecs2.size() << " reco");
00144       _h_ne_true->fill(elecs1.size(), weight);
00145       _h_ne_reco->fill(elecs2.size(), weight);
00146       if (!elecs1.empty()) {
00147         _h_e1pt_true->fill(elecs1.front().pT()/GeV, weight);
00148         _h_e1eta_true->fill(elecs1.front().eta(), weight);
00149       }
00150       if (!elecs2.empty()) {
00151         _h_e1pt_reco->fill(elecs2.front().pT()/GeV, weight);
00152         _h_e1eta_reco->fill(elecs2.front().eta(), weight);
00153       }
00154 
00155       const Particles& muons1 = apply<ParticleFinder>(event, "Muons1").particlesByPt();
00156       const Particles& muons2 = apply<ParticleFinder>(event, "Muons2").particlesByPt();
00157       MSG_DEBUG("Numbers of muons = " << muons1.size() << " true; " << muons2.size() << " reco");
00158       _h_nm_true->fill(muons1.size(), weight);
00159       _h_nm_reco->fill(muons2.size(), weight);
00160       if (!muons1.empty()) {
00161         _h_m1pt_true->fill(muons1.front().pT()/GeV, weight);
00162         _h_m1eta_true->fill(muons1.front().eta(), weight);
00163       }
00164       if (!muons2.empty()) {
00165         _h_m1pt_reco->fill(muons2.front().pT()/GeV, weight);
00166         _h_m1eta_reco->fill(muons2.front().eta(), weight);
00167       }
00168 
00169       const Particles& taus1 = apply<ParticleFinder>(event, "Taus1").particlesByPt();
00170       const Particles& taus2 = apply<ParticleFinder>(event, "Taus2").particlesByPt();
00171       MSG_DEBUG("Numbers of taus = " << taus1.size() << " true; " << taus2.size() << " reco");
00172       _h_nt_true->fill(taus1.size(), weight);
00173       _h_nt_reco->fill(taus2.size(), weight);
00174       if (!taus1.empty()) {
00175         _h_t1pt_true->fill(taus1.front().pT()/GeV, weight);
00176         _h_t1eta_true->fill(taus1.front().eta(), weight);
00177       }
00178       if (!taus2.empty()) {
00179         _h_t1pt_reco->fill(taus2.front().pT()/GeV, weight);
00180         _h_t1eta_reco->fill(taus2.front().eta(), weight);
00181       }
00182 
00183     }
00184 
00185 
00186     /// Normalise histograms etc., after the run
00187     void finalize() {
00188       normalize(_h_nj_true);
00189       normalize(_h_nj_reco);
00190       normalize(_h_j1pt_true, 1-_h_nj_true->bin(0).area());
00191       normalize(_h_j1pt_reco, 1-_h_nj_reco->bin(0).area());
00192       normalize(_h_j1eta_true, 1-_h_nj_true->bin(0).area());
00193       normalize(_h_j1eta_reco, 1-_h_nj_reco->bin(0).area());
00194 
00195       normalize(_h_ne_true);
00196       normalize(_h_ne_reco);
00197       normalize(_h_e1pt_true, 1-_h_ne_true->bin(0).area());
00198       normalize(_h_e1pt_reco, 1-_h_ne_reco->bin(0).area());
00199       normalize(_h_e1eta_true, 1-_h_ne_true->bin(0).area());
00200       normalize(_h_e1eta_reco, 1-_h_ne_reco->bin(0).area());
00201 
00202       normalize(_h_nm_true);
00203       normalize(_h_nm_reco);
00204       normalize(_h_m1pt_true, 1-_h_nm_true->bin(0).area());
00205       normalize(_h_m1pt_reco, 1-_h_nm_reco->bin(0).area());
00206       normalize(_h_m1eta_true, 1-_h_nm_true->bin(0).area());
00207       normalize(_h_m1eta_reco, 1-_h_nm_reco->bin(0).area());
00208 
00209       normalize(_h_nt_true);
00210       normalize(_h_nt_reco);
00211       normalize(_h_t1pt_true, 1-_h_nt_true->bin(0).area());
00212       normalize(_h_t1pt_reco, 1-_h_nt_reco->bin(0).area());
00213       normalize(_h_t1eta_true, 1-_h_nt_true->bin(0).area());
00214       normalize(_h_t1eta_reco, 1-_h_nt_reco->bin(0).area());
00215     }
00216 
00217     //@}
00218 
00219 
00220   private:
00221 
00222     /// @name Histograms
00223     //@{
00224     Histo1DPtr _h_met_true, _h_met_reco;
00225     Histo1DPtr _h_nj_true, _h_nj_reco, _h_ne_true, _h_ne_reco,  _h_nm_true, _h_nm_reco,  _h_nt_true, _h_nt_reco;
00226     Histo1DPtr _h_j1pt_true, _h_j1pt_reco, _h_e1pt_true, _h_e1pt_reco,  _h_m1pt_true, _h_m1pt_reco,  _h_t1pt_true, _h_t1pt_reco;
00227     Histo1DPtr _h_j1eta_true, _h_j1eta_reco, _h_e1eta_true, _h_e1eta_reco,  _h_m1eta_true, _h_m1eta_reco,  _h_t1eta_true, _h_t1eta_reco;
00228     //@}
00229 
00230   };
00231 
00232 
00233 
00234   // The hook for the plugin system
00235   DECLARE_RIVET_PLUGIN(EXAMPLE_SMEAR);
00236 
00237 
00238 }