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 
8 #include <cmath>
9 
10 using namespace CP;
11 using namespace FakeBkgTools;
12 //=============================================================================
13 // Constructor
14 //=============================================================================
17 {
18  declareProperty("e2y_option", m_e2y_option, "0-apply e2y rate SF, 1-apply e2y rate");
19 
20 }
21 
22 //=============================================================================
23 // Destructor
24 //=============================================================================
26 {
27 }
28 
30 {
32 }
33 
35 {
37 }
38 
40 {
41  m_cachedWeights.clear();
42 
43  return incrementTotalYield();
44 }
45 
48 
49  const size_t n = m_particles.size();
50  const size_t nc = (1 << n);
51 
52  // the E2Y method has no extra selection information in tool
53  // fill all particles bitset to 1
54  FSBitset tights(nc-1);
55  std::array<double,maxParticles()>dev;//first-order partial derivative
56  std::fill_n(dev.begin(), n, 0);
57 
58  // m_e2y_option == 1: Apply the electron to photon fake rate
59  // m_e2y_option == 0: Apply the electron to photon fake rate scale factor
60  // In general, we could only condider one electron fake a photon.
61  // the rate of electron wrongly reconstructed rate and idenified as photon:f = N_y^{reco}/N_e^{true}.
62  // the fake rate is defined:F = N_y^{reco}/N^_e{reco} = f/(1-f)
63 
64  for(size_t i=0;i<nc;i++){
65 
66  // all possible conbination (e.g. for 2 particle final state):
67  // FF, FR, RF, RR
68  // if we want to calculate the weight with process = "1F"
69  // the accepted process : FR, RF
70  // weight = F1 + F2
71  // dev[0] = 1, dev[1] = 1
72  // unc = unc1 + unc2
73 
74  FSBitset reals(i);
75  if(!fs.accept_process(n, reals, tights)) continue;
76  double wei = 1.;
77  for(size_t j=0;j<n;j++){
79  double x = reals[j]? 1 : m_particles[j].fake_factor.nominal;
80  wei *= x;
81  double theta = reals[j]? 0 : 1;
82  for(size_t k=0;k<n;k++){
83  if(k != j) theta *= reals[k]? 1 : m_particles[k].fake_factor.nominal;
84  }
85  dev[j] += theta;
86  }
87  else if(m_e2y_option == 0 && m_particles[j].type == xAOD::Type::Photon){
88  if(reals.count() == 0){ //only consider case all photons are from the electron fake
89  double x = m_particles[j].fake_factor.nominal;
90  wei *= x;
91  double theta = 1.;
92  for(size_t k=0;k<n;k++){
93  if(k != j) theta *= m_particles[k].fake_factor.nominal;
94  }
95  dev[j] += theta;
96  }
97  else{
98  ATH_MSG_ERROR("the process is not supported.Please try to use process = '0R' instead");
99  return StatusCode::FAILURE;
100  }
101 
102  }
103  else{
104  ATH_MSG_ERROR("the option and particle type are not supported by this method");
105  return StatusCode::FAILURE;
106  }
107  }
108  weight.nominal += wei;
109 
110  }
111  for(size_t i=0;i<n;i++){
112  for(auto const &kv :m_particles[i].fake_factor.uncertainties){
113  auto & uncertainties = weight.uncertainties[kv.first];
114  uncertainties.up += dev[i] * kv.second.up;
115  uncertainties.down += dev[i] * kv.second.down;
116  }
117  }
118 
119 
120  return StatusCode::SUCCESS;
121 }
122 
123 
124 
CP::ApplyE2YFakeRate::clientForDB
virtual FakeBkgTools::Client clientForDB() override final
This indicates which type of efficiencies/fake factor need to be filled.
Definition: ApplyE2YFakeRate.cxx:29
CP::BaseLinearFakeBkgTool::incrementTotalYield
StatusCode incrementTotalYield()
be sure to only call this once per event! (typically at the end of addEvent())
Definition: BaseLinearFakeBkgTool.cxx:104
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:39
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
theta
Scalar theta() const
theta method
Definition: AmgMatrixBasePlugin.h:71
FakeBkgTools::Client
Client
Definition: FakeBkgInternals.h:141
CP::BaseLinearFakeBkgTool::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: BaseLinearFakeBkgTool.cxx:41
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:200
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:92
FakeBkgTools
Definition: BaseFakeBkgTool.h:21
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:44
xAOD::double
double
Definition: CompositeParticle_v1.cxx:159
lumiFormat.array
array
Definition: lumiFormat.py:98
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
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:15
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:25
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:72
CP::ApplyE2YFakeRate::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: ApplyE2YFakeRate.cxx:34
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:46