ATLAS Offline Software
Loading...
Searching...
No Matches
ApplyE2YFakeRate.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
7#include <cmath>
8
9using namespace CP;
10using namespace FakeBkgTools;
11//=============================================================================
12// Constructor
13//=============================================================================
16{
17 declareProperty("e2y_option", m_e2y_option, "0-apply e2y rate SF, 1-apply e2y rate");
18
19}
20
21//=============================================================================
22// Destructor
23//=============================================================================
27
32
37
39{
40 m_cachedWeights.clear();
41
42 return incrementTotalYield();
43}
44
47
48 const size_t n = m_particles.size();
49 const size_t nc = (1 << n);
50
51 // the E2Y method has no extra selection information in tool
52 // fill all particles bitset to 1
53 FSBitset tights(nc-1);
54 std::array<double,maxParticles()>dev;//first-order partial derivative
55 std::fill_n(dev.begin(), n, 0);
56
57 // m_e2y_option == 1: Apply the electron to photon fake rate
58 // m_e2y_option == 0: Apply the electron to photon fake rate scale factor
59 // In general, we could only condider one electron fake a photon.
60 // the rate of electron wrongly reconstructed rate and idenified as photon:f = N_y^{reco}/N_e^{true}.
61 // the fake rate is defined:F = N_y^{reco}/N^_e{reco} = f/(1-f)
62
63 for(size_t i=0;i<nc;i++){
64
65 // all possible conbination (e.g. for 2 particle final state):
66 // FF, FR, RF, RR
67 // if we want to calculate the weight with process = "1F"
68 // the accepted process : FR, RF
69 // weight = F1 + F2
70 // dev[0] = 1, dev[1] = 1
71 // unc = unc1 + unc2
72
73 FSBitset reals(i);
74 if(!fs.accept_process(n, reals, tights)) continue;
75 double wei = 1.;
76 for(size_t j=0;j<n;j++){
78 double x = reals[j]? 1 : m_particles[j].fake_factor.nominal;
79 wei *= x;
80 double theta = reals[j]? 0 : 1;
81 for(size_t k=0;k<n;k++){
82 if(k != j) theta *= reals[k]? 1 : m_particles[k].fake_factor.nominal;
83 }
84 dev[j] += theta;
85 }
86 else if(m_e2y_option == 0 && m_particles[j].type == xAOD::Type::Photon){
87 if(reals.count() == 0){ //only consider case all photons are from the electron fake
88 double x = m_particles[j].fake_factor.nominal;
89 wei *= x;
90 double theta = 1.;
91 for(size_t k=0;k<n;k++){
92 if(k != j) theta *= m_particles[k].fake_factor.nominal;
93 }
94 dev[j] += theta;
95 }
96 else{
97 ATH_MSG_ERROR("the process is not supported.Please try to use process = '0R' instead");
98 return StatusCode::FAILURE;
99 }
100
101 }
102 else{
103 ATH_MSG_ERROR("the option and particle type are not supported by this method");
104 return StatusCode::FAILURE;
105 }
106 }
107 weight.nominal += wei;
108
109 }
110 for(size_t i=0;i<n;i++){
111 for(auto const &kv :m_particles[i].fake_factor.uncertainties){
112 auto & uncertainties = weight.uncertainties[kv.first];
113 uncertainties.up += dev[i] * kv.second.up;
114 uncertainties.down += dev[i] * kv.second.down;
115 }
116 }
117
118
119 return StatusCode::SUCCESS;
120}
121
122
123
Scalar theta() const
theta method
#define ATH_MSG_ERROR(x)
static Double_t fs
#define x
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
virtual FakeBkgTools::Client clientForDB() override final
This indicates which type of efficiencies/fake factor need to be filled.
ApplyE2YFakeRate(const std::string &name)
Standard constructor.
virtual StatusCode addEventCustom() override
~ApplyE2YFakeRate()
Standard destructor.
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
virtual StatusCode getEventWeightCustom(FakeBkgTools::Weight &weight, const FakeBkgTools::FinalState &fs) override
std::vector< FakeBkgTools::ParticleData > m_particles
BaseLinearFakeBkgTool(const std::string &toolname)
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
StatusCode incrementTotalYield()
be sure to only call this once per event! (typically at the end of addEvent())
std::map< FakeBkgTools::FinalState, FakeBkgTools::Weight > m_cachedWeights
cached weight+uncertainties for a single event Each tool derived from this base class MUST clear the ...
Select isolated Photons, Electrons and Muons.
std::bitset< maxCombinations()> FSBitset
constexpr uint8_t maxParticles()
@ Photon
The object is a photon.
Definition ObjectType.h:47
@ Electron
The object is an electron.
Definition ObjectType.h:46
a structure to hold a weight together with a variable number of systematic uncertainties