ATLAS Offline Software
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 
9 using namespace CP;
10 using 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 //=============================================================================
25 {
26 }
27 
29 {
31 }
32 
34 {
36 }
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 
CP::ApplyE2YFakeRate::clientForDB
virtual FakeBkgTools::Client clientForDB() override final
This indicates which type of efficiencies/fake factor need to be filled.
Definition: ApplyE2YFakeRate.cxx:28
CP::BaseLinearFakeBkgTool::incrementTotalYield
StatusCode incrementTotalYield()
be sure to only call this once per event! (typically at the end of addEvent())
Definition: BaseLinearFakeBkgTool.cxx:97
ApplyE2YFakeRate.h
FakeBkgTools::Client::E2Y_FAKE
@ E2Y_FAKE
xAOD::Electron
Electron_v1 Electron
Definition of the current "egamma version".
Definition: Event/xAOD/xAODEgamma/xAODEgamma/Electron.h:17
CP::ApplyE2YFakeRate::addEventCustom
virtual StatusCode addEventCustom() override
Definition: ApplyE2YFakeRate.cxx:38
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
FakeBkgTools::Client
Client
Definition: FakeBkgInternals.h:141
CP::BaseLinearFakeBkgTool::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: BaseLinearFakeBkgTool.cxx:34
x
#define x
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:48
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:189
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:85
FakeBkgTools
Definition: BaseFakeBkgTool.h:23
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
CP::ApplyE2YFakeRate::m_e2y_option
int m_e2y_option
Definition: ApplyE2YFakeRate.h:41
CP::BaseLinearFakeBkgTool
Definition: BaseLinearFakeBkgTool.h:39
xAOD::double
double
Definition: CompositeParticle_v1.cxx:159
lumiFormat.array
array
Definition: lumiFormat.py:91
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
FakeBkgTools::maxParticles
constexpr uint8_t maxParticles()
Definition: FakeBkgInternals.h:93
FakeBkgInternals.h
FakeBkgTools::Weight
a structure to hold a weight together with a variable number of systematic uncertainties
Definition: FakeBkgInternals.h:62
CP::BaseFakeBkgTool::m_particles
std::vector< FakeBkgTools::ParticleData > m_particles
Definition: BaseFakeBkgTool.h:85
xAOD::Photon
Photon_v1 Photon
Definition of the current "egamma version".
Definition: Event/xAOD/xAODEgamma/xAODEgamma/Photon.h:17
FakeBkgTools::FinalState
Definition: FakeBkgInternals.h:98
CP::ApplyE2YFakeRate::ApplyE2YFakeRate
ApplyE2YFakeRate(const std::string &name)
Standard constructor.
Definition: ApplyE2YFakeRate.cxx:14
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
Herwig7_QED_EvtGen_ll.fs
dictionary fs
Definition: Herwig7_QED_EvtGen_ll.py:17
FakeBkgTools::FSBitset
std::bitset< maxCombinations()> FSBitset
Definition: FakeBkgInternals.h:95
CP::ApplyE2YFakeRate::~ApplyE2YFakeRate
~ApplyE2YFakeRate()
Standard destructor.
Definition: ApplyE2YFakeRate.cxx:24
CP::BaseLinearFakeBkgTool::m_cachedWeights
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 ...
Definition: BaseLinearFakeBkgTool.h:67
CP::ApplyE2YFakeRate::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: ApplyE2YFakeRate.cxx:33
plotBeamSpotMon.nc
int nc
Definition: plotBeamSpotMon.py:83
fitman.k
k
Definition: fitman.py:528
CP::ApplyE2YFakeRate::getEventWeightCustom
virtual StatusCode getEventWeightCustom(FakeBkgTools::Weight &weight, const FakeBkgTools::FinalState &fs) override
Definition: ApplyE2YFakeRate.cxx:45