ATLAS Offline Software
Loading...
Searching...
No Matches
PMGSherpa22VJetsWeightTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5// $Id: PMGSherpa22VJetsWeightTool.cxx 764400 2016-07-26 17:47:39Z tripiana $
6
7// EDM include(s):
11
12// Local include(s):
15
16namespace PMGTools {
17
19 PMGSherpa22VJetsWeightTool( const std::string& name )
20 : asg::AsgTool( name ),
21 m_corrFactors( { { 1.0007-1, 0.9904-1, 0.9884-1, 0.9128-1, 0.8114-1,
22 0.7833-1, 0.6872-1, 0.6424-1, 0.6424-1 } } ) {
23
24 // Declare the properties of the tool:
25 declareProperty( "TruthJetContainer",
26 m_truthJetContainer = "AntiKt4TruthWZJets" );
27 declareProperty( "TruthParticleContainer",
28 m_truthParticleContainer = "TruthParticles" );
29 }
30
32
33 // Tell the user what's happening:
34 ATH_MSG_INFO( "Initializing " << name() << "..." );
35 ATH_MSG_DEBUG( "Will be using:" );
36 ATH_MSG_DEBUG( " TruthJetContainer = " << m_truthJetContainer );
37 ATH_MSG_DEBUG( " TruthParticleContainer = " << m_truthParticleContainer );
38
39 // Ensure that the overall normalisation agrees with the Strict
40 // integration setting
41 static const double NORM = 1.007;
42 for( double& corr : m_corrFactors ) {
43 corr *= NORM;
44 }
45
46 // Return gracefully:
47 return StatusCode::SUCCESS;
48 }
49
51
52 // Check if the configured truth jet container is available:
54 ATH_MSG_WARNING( "No TruthJetContainer (\"" << m_truthJetContainer
55 << "\") found! Dummy null weight retrieved." );
56 return 0.;
57 }
58
59 // Calculate the weight:
61 }
62
64 getSherpa22VJets_NJetCorrection( size_t njettruth ) const {
65
66 // See https://twiki.cern.ch/twiki/bin/viewauth/AtlasProtected/CentralMC15ProductionList#NEW_Sherpa_v2_2_V_jets_NJet_rewe
67 // Function of njettruth which is the number of truth jets with
68 // pt>20 and |eta|<4.5
69
70 // Use the last bin if we have more jets than what we have correction
71 // factors for.
72 if( njettruth >= m_corrFactors.size() ) {
73 njettruth = m_corrFactors.size() - 1;
74 }
75
76 // Return the right value:
77 return 1.0 + m_corrFactors[ njettruth ];
78 }
79
81 getSherpa22VJets_NJetCorrection( const std::string &jetContainer ) const {
82
83 // Count truth jets in collection, return correction:
84 const size_t nTruthJets = getSherpa22VJets_NJet( jetContainer );
85 // Use this in the correction calculation:
86 return getSherpa22VJets_NJetCorrection( nTruthJets );
87 }
88
90 getSherpa22VJets_NJet( const std::string& jetContainer ) const {
91
92 //
93 // Count number of truthjets compatible with evaluation of correction
94 //
95
96 // Check whether to do overlap removal with truth leptons:
97 const bool doRemoval = ( jetContainer == "AntiKt4TruthJets" );
98
99 // Retrieve the truth jets
100 const xAOD::JetContainer* truthJets( 0 );
101 if( evtStore()->retrieve( truthJets, jetContainer ).isFailure() ) {
102 ATH_MSG_ERROR( "Couldn't retrieve truth jet container: "
103 << jetContainer );
104 return 0;
105 }
106
107 size_t nTruthJets = 0;
108
109 // Retrieve the truth particles to get the leptons
110 const xAOD::TruthParticleContainer* truthParticles( 0 );
111 if( doRemoval ) {
112 if( evtStore()->retrieve( truthParticles,
113 m_truthParticleContainer ).isFailure() ) {
114 ATH_MSG_ERROR( "Couldn't retrieve truth particle container: "
116 return 0;
117 }
118 }
119
120 // Loop over all truth jets passing basic cuts:
121 for( const xAOD::Jet* truthJet : *truthJets ) {
122
123 // Start with a simple kinematic cut:
124 if( truthJet->pt() <= 20000. || std::abs( truthJet->eta() ) >= 4.5 ) {
125 continue;
126 }
127
128 // Remove hadronic taus e.g. from Ztautau, Wtaunu decays
130 acc( "HadronConeExclTruthLabelID" );
131 if( acc.isAvailable( *truthJet ) && ( acc( *truthJet ) == 15 ) ) {
132 continue;
133 }
134
135 // If no overlap removal is to be made, we're done already:
136 if( ! doRemoval ) {
137 ++nTruthJets;
138 continue;
139 }
140
141 // Loop over the truth particles, to veto some jets:
142 bool vetoJet = false;
143 for( const xAOD::TruthParticle* truthParticle : *truthParticles ) {
144
145 // Only select final state electrons and muons:
146 if( !MC::isStable(truthParticle) ||
147 ( !MC::isElectron(truthParticle) &&
148 !MC::isMuon( truthParticle) ) ) {
149 continue;
150 }
151 // ...which also pass some basic kinematic cuts:
152 if( ( truthParticle->pt() <= 20000.0 ) ||
153 ( std::abs( truthParticle->eta() ) >= 4.5 ) ) {
154 continue;
155 }
156
157 // Veto the jet if it's close to this lepton:
158 static const double MIN_DISTANCE = 0.2 * 0.2;
159 const double dR2 =
160 xAOD::P4Helpers::deltaR2( truthJet, truthParticle, true );
161 if( dR2 < MIN_DISTANCE ) {
162 vetoJet = true;
163 break;
164 }
165 }
166
167 // If the jet was not vetoed:
168 if( ! vetoJet ) {
169 ++nTruthJets;
170 }
171 }
172
173 // Return the calculated value:
174 return nTruthJets;
175 }
176
177}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
ATLAS-specific HepMC functions.
bool vetoJet(const xAOD::jFexSRJetRoI *j)
ServiceHandle< StoreGateSvc > & evtStore()
virtual double getWeight() const override
Sherpa 2.2 V+jets jet multiplicity reweight to fix issue from scale settings used in pTV sliced sampl...
std::string m_truthJetContainer
The truth jet container to use for the calculation.
size_t getSherpa22VJets_NJet(const std::string &jetcontainer) const
Function returns number of jets required for correction.
std::string m_truthParticleContainer
The truth particle container to use for the calculation.
std::array< double, NJET_CORRECTION_BINS > m_corrFactors
Correction factors used in the weight calculation.
double getSherpa22VJets_NJetCorrection(size_t ntag) const
Return correction for given jet multiplicity.
PMGSherpa22VJetsWeightTool(const std::string &name="PMGSherpa22VJetsWeightTool")
Standard tool constructor, with name.
virtual StatusCode initialize() override final
Initialize is required by AsgTool base class.
SG::ConstAccessor< T, ALLOC > ConstAccessor
Definition AuxElement.h:569
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition AsgTool.cxx:58
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:114
bool isElectron(const T &p)
bool isStable(const T &p)
Identify if the particle is stable, i.e. has not decayed.
bool isMuon(const T &p)
Tool providing sample cross-sections and k-factors etc.
double deltaR2(double rapidity1, double phi1, double rapidity2, double phi2)
from bare rapidity,phi
Jet_v1 Jet
Definition of the current "jet version".
TruthParticle_v1 TruthParticle
Typedef to implementation.
JetContainer_v1 JetContainer
Definition of the current "jet container version".
TruthParticleContainer_v1 TruthParticleContainer
Declare the latest version of the truth particle container.