Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:11:49

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include "ActsExamples/Validation/FakeRatePlotTool.hpp"
0010 
0011 #include "Acts/Utilities/VectorHelpers.hpp"
0012 #include "ActsExamples/EventData/SimParticle.hpp"
0013 
0014 #include <TEfficiency.h>
0015 #include <TH2.h>
0016 
0017 using Acts::VectorHelpers::eta;
0018 using Acts::VectorHelpers::perp;
0019 using Acts::VectorHelpers::phi;
0020 using Acts::VectorHelpers::theta;
0021 
0022 ActsExamples::FakeRatePlotTool::FakeRatePlotTool(
0023     const ActsExamples::FakeRatePlotTool::Config& cfg, Acts::Logging::Level lvl)
0024     : m_cfg(cfg), m_logger(Acts::getDefaultLogger("FakeRatePlotTool", lvl)) {}
0025 
0026 void ActsExamples::FakeRatePlotTool::book(
0027     FakeRatePlotTool::FakeRatePlotCache& fakeRatePlotCache) const {
0028   PlotHelpers::Binning bPt = m_cfg.varBinning.at("Pt");
0029   PlotHelpers::Binning bEta = m_cfg.varBinning.at("Eta");
0030   PlotHelpers::Binning bPhi = m_cfg.varBinning.at("Phi");
0031   PlotHelpers::Binning bNum = m_cfg.varBinning.at("Num");
0032   ACTS_DEBUG("Initialize the histograms for fake rate plots");
0033 
0034   // number of reco tracks vs pT scatter plots
0035   fakeRatePlotCache.nReco_vs_pT = PlotHelpers::bookHisto(
0036       "nRecoTracks_vs_pT", "Number of reconstructed track candidates", bPt,
0037       bNum);
0038   // number of truth-matched tracks vs pT scatter plots
0039   fakeRatePlotCache.nTruthMatched_vs_pT = PlotHelpers::bookHisto(
0040       "nTruthMatchedTracks_vs_pT", "Number of truth-matched track candidates",
0041       bPt, bNum);
0042   // number of fake tracks vs pT scatter plots
0043   fakeRatePlotCache.nFake_vs_pT = PlotHelpers::bookHisto(
0044       "nFakeTracks_vs_pT", "Number of fake track candidates", bPt, bNum);
0045 
0046   // number of reco tracks vs eta scatter plots
0047   fakeRatePlotCache.nReco_vs_eta = PlotHelpers::bookHisto(
0048       "nRecoTracks_vs_eta", "Number of reconstructed track candidates", bEta,
0049       bNum);
0050   // number of truth-matched tracks vs eta scatter plots
0051   fakeRatePlotCache.nTruthMatched_vs_eta = PlotHelpers::bookHisto(
0052       "nTruthMatchedTracks_vs_eta", "Number of truth-matched track candidates",
0053       bEta, bNum);
0054   // number of fake tracks vs eta scatter plots
0055   fakeRatePlotCache.nFake_vs_eta = PlotHelpers::bookHisto(
0056       "nFakeTracks_vs_eta", "Number of fake track candidates", bEta, bNum);
0057 
0058   // fake rate vs pT
0059   fakeRatePlotCache.fakeRate_vs_pT = PlotHelpers::bookEff(
0060       "fakerate_vs_pT", "Tracking fake rate;pT [GeV/c];Fake rate", bPt);
0061   // fake rate vs eta
0062   fakeRatePlotCache.fakeRate_vs_eta = PlotHelpers::bookEff(
0063       "fakerate_vs_eta", "Tracking fake rate;#eta;Fake rate", bEta);
0064   // fake rate vs phi
0065   fakeRatePlotCache.fakeRate_vs_phi = PlotHelpers::bookEff(
0066       "fakerate_vs_phi", "Tracking fake rate;#phi;Fake rate", bPhi);
0067 }
0068 
0069 void ActsExamples::FakeRatePlotTool::clear(
0070     FakeRatePlotCache& fakeRatePlotCache) const {
0071   delete fakeRatePlotCache.nReco_vs_pT;
0072   delete fakeRatePlotCache.nTruthMatched_vs_pT;
0073   delete fakeRatePlotCache.nFake_vs_pT;
0074   delete fakeRatePlotCache.nReco_vs_eta;
0075   delete fakeRatePlotCache.nTruthMatched_vs_eta;
0076   delete fakeRatePlotCache.nFake_vs_eta;
0077   delete fakeRatePlotCache.fakeRate_vs_pT;
0078   delete fakeRatePlotCache.fakeRate_vs_eta;
0079   delete fakeRatePlotCache.fakeRate_vs_phi;
0080 }
0081 
0082 void ActsExamples::FakeRatePlotTool::write(
0083     const FakeRatePlotTool::FakeRatePlotCache& fakeRatePlotCache) const {
0084   ACTS_DEBUG("Write the plots to output file.");
0085   fakeRatePlotCache.nReco_vs_pT->Write();
0086   fakeRatePlotCache.nTruthMatched_vs_pT->Write();
0087   fakeRatePlotCache.nFake_vs_pT->Write();
0088   fakeRatePlotCache.nReco_vs_eta->Write();
0089   fakeRatePlotCache.nTruthMatched_vs_eta->Write();
0090   fakeRatePlotCache.nFake_vs_eta->Write();
0091   fakeRatePlotCache.fakeRate_vs_pT->Write();
0092   fakeRatePlotCache.fakeRate_vs_eta->Write();
0093   fakeRatePlotCache.fakeRate_vs_phi->Write();
0094 }
0095 
0096 void ActsExamples::FakeRatePlotTool::fill(
0097     FakeRatePlotTool::FakeRatePlotCache& fakeRatePlotCache,
0098     const Acts::BoundTrackParameters& fittedParameters, bool status) const {
0099   const auto momentum = fittedParameters.momentum();
0100   const double fit_phi = phi(momentum);
0101   const double fit_eta = eta(momentum);
0102   const double fit_pT = perp(momentum);
0103 
0104   PlotHelpers::fillEff(fakeRatePlotCache.fakeRate_vs_pT, fit_pT, status);
0105   PlotHelpers::fillEff(fakeRatePlotCache.fakeRate_vs_eta, fit_eta, status);
0106   PlotHelpers::fillEff(fakeRatePlotCache.fakeRate_vs_phi, fit_phi, status);
0107 }
0108 
0109 void ActsExamples::FakeRatePlotTool::fill(
0110     FakeRatePlotTool::FakeRatePlotCache& fakeRatePlotCache,
0111     const SimParticleState& truthParticle, std::size_t nTruthMatchedTracks,
0112     std::size_t nFakeTracks) const {
0113   const auto t_eta = eta(truthParticle.direction());
0114   const auto t_pT = truthParticle.transverseMomentum();
0115 
0116   PlotHelpers::fillHisto(fakeRatePlotCache.nReco_vs_pT, t_pT,
0117                          nTruthMatchedTracks + nFakeTracks);
0118   PlotHelpers::fillHisto(fakeRatePlotCache.nTruthMatched_vs_pT, t_pT,
0119                          nTruthMatchedTracks);
0120   PlotHelpers::fillHisto(fakeRatePlotCache.nFake_vs_pT, t_pT, nFakeTracks);
0121 
0122   PlotHelpers::fillHisto(fakeRatePlotCache.nReco_vs_eta, t_eta,
0123                          nTruthMatchedTracks + nFakeTracks);
0124   PlotHelpers::fillHisto(fakeRatePlotCache.nTruthMatched_vs_eta, t_eta,
0125                          nTruthMatchedTracks);
0126   PlotHelpers::fillHisto(fakeRatePlotCache.nFake_vs_eta, t_eta, nFakeTracks);
0127 }