ATLAS Offline Software
PMGSherpa22VJetsWeightTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 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):
8 #include "xAODJet/JetContainer.h"
11 
12 // Local include(s):
15 
16 namespace 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:
53  if( ! evtStore()->contains< xAOD::JetContainer >( m_truthJetContainer ) ) {
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  ( ( std::abs( truthParticle->pdgId() ) != 11 ) &&
148  ( std::abs( truthParticle->pdgId() ) != 13 ) ) ) {
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 }
PMGTools::PMGSherpa22VJetsWeightTool::getSherpa22VJets_NJetCorrection
double getSherpa22VJets_NJetCorrection(size_t ntag) const
Return correction for given jet multiplicity.
Definition: PMGSherpa22VJetsWeightTool.cxx:64
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
PMGSherpa22VJetsWeightTool.h
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
xAODP4Helpers.h
TruthParticleContainer.h
asg
Definition: DataHandleTestTool.h:28
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:54
PMGTools::PMGSherpa22VJetsWeightTool::PMGSherpa22VJetsWeightTool
PMGSherpa22VJetsWeightTool(const std::string &name="PMGSherpa22VJetsWeightTool")
Standard tool constructor, with name.
Definition: PMGSherpa22VJetsWeightTool.cxx:19
xAOD::P4Helpers::deltaR2
double deltaR2(double rapidity1, double phi1, double rapidity2, double phi2)
from bare rapidity,phi
Definition: xAODP4Helpers.h:111
PMGTools::PMGSherpa22VJetsWeightTool::initialize
virtual StatusCode initialize() override final
Initialize is required by AsgTool base class.
Definition: PMGSherpa22VJetsWeightTool.cxx:31
PMGTools::PMGSherpa22VJetsWeightTool::getSherpa22VJets_NJet
size_t getSherpa22VJets_NJet(const std::string &jetcontainer) const
Function returns number of jets required for correction.
Definition: PMGSherpa22VJetsWeightTool.cxx:90
AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:41
PMGTools
Tool providing sample cross-sections and k-factors etc.
Definition: AnalysisCommon/PMGTools/PMGTools/IPMGCrossSectionTool.h:15
AthenaPoolTestRead.acc
acc
Definition: AthenaPoolTestRead.py:16
PMGTools::PMGSherpa22VJetsWeightTool::m_corrFactors
std::array< double, NJET_CORRECTION_BINS > m_corrFactors
Correction factors used in the weight calculation.
Definition: PMGSherpa22VJetsWeightTool.h:84
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
JetAnalysisAlgorithmsTest_EMTopo_eljob.jetContainer
string jetContainer
Definition: JetAnalysisAlgorithmsTest_EMTopo_eljob.py:36
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
MC::isStable
bool isStable(const T &p)
Definition: HepMCHelpers.h:30
JetContainer.h
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
PMGTools::PMGSherpa22VJetsWeightTool::m_truthJetContainer
std::string m_truthJetContainer
The truth jet container to use for the calculation.
Definition: PMGSherpa22VJetsWeightTool.h:90
declareProperty
#define declareProperty(n, p, h)
Definition: BaseFakeBkgTool.cxx:15
PMGTools::PMGSherpa22VJetsWeightTool::getWeight
virtual double getWeight() const override
Sherpa 2.2 V+jets jet multiplicity reweight to fix issue from scale settings used in pTV sliced sampl...
Definition: PMGSherpa22VJetsWeightTool.cxx:50
PMGTools::PMGSherpa22VJetsWeightTool::m_truthParticleContainer
std::string m_truthParticleContainer
The truth particle container to use for the calculation.
Definition: PMGSherpa22VJetsWeightTool.h:92
HepMCHelpers.h
vetoJet
bool vetoJet(const xAOD::jFexSRJetRoI *j)
Definition: L1MonitorAdaptors.h:14