ATLAS Offline Software
Loading...
Searching...
No Matches
ResidualOffsetCorrection Class Reference

#include <ResidualOffsetCorrection.h>

Inheritance diagram for ResidualOffsetCorrection:
Collaboration diagram for ResidualOffsetCorrection:

Public Member Functions

 ResidualOffsetCorrection ()
 ResidualOffsetCorrection (const std::string &name, TEnv *config, TString jetAlgo, TString calibAreaTag, bool isData, bool dev)
virtual ~ResidualOffsetCorrection ()
virtual StatusCode initialize ()
double GetResidualOffset (double abseta, double mu, double NPV, int nJet, bool MuOnly, bool NOnly) const
void setLevel (MSG::Level lvl)
 Change the current logging level.
Functions providing the same interface as AthMessaging
bool msgLvl (const MSG::Level lvl) const
 Test the output level of the object.
MsgStream & msg () const
 The standard message stream.
MsgStream & msg (const MSG::Level lvl) const
 The standard message stream.

Private Member Functions

double GetResidualOffsetET (double abseta, double mu, double NPV, int nJet, bool MuOnly, bool NOnly, const std::vector< double > &OffsetMu, const std::vector< double > &OffsetNPV, const std::vector< double > &OffsetNjet, const TAxis *OffsetBins) const
double GetNPVBeamspotCorrection (double NPV) const
void initMessaging () const
 Initialize our message level and MessageSvc.

Private Attributes

TEnv * m_config {}
TString m_jetAlgo
TString m_calibAreaTag
bool m_dev {}
bool m_isData {}
NPVBeamspotCorrectionm_npvBeamspotCorr {}
TString m_resOffsetDesc
TAxis * m_resOffsetBins {}
bool m_applyNPVBeamspotCorrection {}
double m_muSF {}
double m_mu_ref {}
double m_NPV_ref {}
double m_nJet_ref {}
bool m_useNjet {}
std::vector< double > m_resOffsetMu
std::vector< double > m_resOffsetNPV
std::vector< double > m_resOffsetNjet
std::string m_nm
 Message source name.
boost::thread_specific_ptr< MsgStream > m_msg_tls
 MsgStream instance (a std::cout like with print-out levels)
std::atomic< IMessageSvc * > m_imsg { nullptr }
 MessageSvc pointer.
std::atomic< MSG::Level > m_lvl { MSG::NIL }
 Current logging level.
std::atomic_flag m_initialized ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT
 Messaging initialized (initMessaging)

Static Private Attributes

static constexpr float m_GeV = 1000

Detailed Description

Definition at line 26 of file ResidualOffsetCorrection.h.

Constructor & Destructor Documentation

◆ ResidualOffsetCorrection() [1/2]

ResidualOffsetCorrection::ResidualOffsetCorrection ( )

Definition at line 15 of file ResidualOffsetCorrection.cxx.

◆ ResidualOffsetCorrection() [2/2]

ResidualOffsetCorrection::ResidualOffsetCorrection ( const std::string & name,
TEnv * config,
TString jetAlgo,
TString calibAreaTag,
bool isData,
bool dev )

Definition at line 21 of file ResidualOffsetCorrection.cxx.

22 : asg::AsgMessaging(name),
23 m_config(config), m_jetAlgo(std::move(jetAlgo)), m_calibAreaTag(std::move(calibAreaTag)), m_dev(dev), m_isData(isData),
24 m_npvBeamspotCorr(nullptr), m_resOffsetBins(nullptr)
25{ }

◆ ~ResidualOffsetCorrection()

ResidualOffsetCorrection::~ResidualOffsetCorrection ( )
virtual

Definition at line 27 of file ResidualOffsetCorrection.cxx.

27 {
28
31
32}

Member Function Documentation

◆ GetNPVBeamspotCorrection()

double ResidualOffsetCorrection::GetNPVBeamspotCorrection ( double NPV) const
private

Definition at line 179 of file ResidualOffsetCorrection.cxx.

179 {
180 if(!m_isData && m_applyNPVBeamspotCorrection) return std::as_const(m_npvBeamspotCorr)->GetNVertexBsCorrection(NPV);
181 return NPV;
182}

◆ GetResidualOffset()

double ResidualOffsetCorrection::GetResidualOffset ( double abseta,
double mu,
double NPV,
int nJet,
bool MuOnly,
bool NOnly ) const

Definition at line 118 of file ResidualOffsetCorrection.cxx.

119 {
120 return GetResidualOffsetET(abseta, mu, NPV, nJet, MuOnly, NOnly,
122}
double GetResidualOffsetET(double abseta, double mu, double NPV, int nJet, bool MuOnly, bool NOnly, const std::vector< double > &OffsetMu, const std::vector< double > &OffsetNPV, const std::vector< double > &OffsetNjet, const TAxis *OffsetBins) const
std::vector< double > m_resOffsetNPV
std::vector< double > m_resOffsetMu
std::vector< double > m_resOffsetNjet

◆ GetResidualOffsetET()

double ResidualOffsetCorrection::GetResidualOffsetET ( double abseta,
double mu,
double NPV,
int nJet,
bool MuOnly,
bool NOnly,
const std::vector< double > & OffsetMu,
const std::vector< double > & OffsetNPV,
const std::vector< double > & OffsetNjet,
const TAxis * OffsetBins ) const
private

Definition at line 124 of file ResidualOffsetCorrection.cxx.

129 {
130
131 //mu rescaling
132 const double muCorr = m_isData ? mu : mu*m_muSF;
133 if(m_useNjet) {
134 // further correction to nJet if desired
135 int nJetCorr = nJet;
136
137 double alpha, beta, etaEdge;
138 if(!MuOnly){ beta = OffsetNjet[0];
139 } else { beta = 0; }
140 if(!NOnly){ alpha = OffsetMu[0];
141 } else { alpha = 0; }
142 etaEdge=0;
143 int bin=1;
144 for (;bin<=OffsetBins->GetNbins();++bin) {
145 etaEdge = OffsetBins->GetBinLowEdge(bin);
146 const double width=OffsetBins->GetBinWidth(bin);
147 if (abseta<etaEdge+width) break;
148 if(!NOnly) alpha += width*OffsetMu[bin];
149 if(!MuOnly) beta += width*OffsetNjet[bin];
150 }
151 if(!NOnly) alpha += OffsetMu[bin]*(abseta-etaEdge);
152 if(!MuOnly) beta += OffsetNjet[bin]*(abseta-etaEdge);
153 return (alpha*(muCorr-m_mu_ref) + beta*(nJetCorr-m_nJet_ref))*m_GeV;
154 } else {
155 //NPV beamspot correction
156 const double NPVCorr = GetNPVBeamspotCorrection(NPV);
157
158 double alpha, beta, etaEdge;
159 if(!MuOnly){ beta = OffsetNPV[0];
160 } else { beta = 0; }
161 if(!NOnly){ alpha = OffsetMu[0];
162 } else { alpha = 0; }
163 etaEdge = 0;
164 int bin=1;
165 for (;bin<=OffsetBins->GetNbins();++bin) {
166 etaEdge = OffsetBins->GetBinLowEdge(bin);
167 const double width=OffsetBins->GetBinWidth(bin);
168 if (abseta<etaEdge+width) break;
169 if(!NOnly) alpha += width*OffsetMu[bin];
170 if(!MuOnly) beta += width*OffsetNPV[bin];
171 }
172 if(!NOnly) alpha += OffsetMu[bin]*(abseta-etaEdge);
173 if(!MuOnly) beta += OffsetNPV[bin]*(abseta-etaEdge);
174 return (alpha*(muCorr-m_mu_ref) + beta*(NPVCorr-m_NPV_ref))*m_GeV;
175 }
176
177}
const double width
double GetNPVBeamspotCorrection(double NPV) const

◆ initialize()

StatusCode ResidualOffsetCorrection::initialize ( )
virtual

Definition at line 34 of file ResidualOffsetCorrection.cxx.

34 {
35
36 //Read mu scale factor from global config
37 m_muSF = m_config->GetValue("MuScaleFactor",1.0);
38
39 // Read useNjet from global config
40 m_useNjet = m_config->GetValue("OffsetCorrection.UseNjet",false);
41
42 bool doMuOnly = m_config->GetValue("ApplyOnlyMuResidual",false);
43 bool doNPVOnly = m_config->GetValue("ApplyOnlyNPVResidual",false);
44 bool doNJetOnly = m_config->GetValue("ApplyOnlyNJetResidual",false);
45
46 //Read reference mu, NPV and nJet from global config
47 m_mu_ref = m_config->GetValue("OffsetCorrection.DefaultMuRef",-99.0);
48 if (m_mu_ref==-99 && !doNPVOnly && !doNJetOnly) {
49 ATH_MSG_FATAL("OffsetCorrection.DefaultMuRef not specified.");
50 return StatusCode::FAILURE;
51 }
52 m_NPV_ref = m_config->GetValue("OffsetCorrection.DefaultNPVRef",-99.0);
53 if (m_NPV_ref==-99 && !doMuOnly && !m_useNjet) {
54 ATH_MSG_FATAL("OffsetCorrection.DefaultNPVRef not specified.");
55 return StatusCode::FAILURE;
56 }
57
58 if (m_NPV_ref==-99 && !doMuOnly && !m_useNjet) {
59 ATH_MSG_FATAL("OffsetCorrection.DefaultNPVRef not specified.");
60 return StatusCode::FAILURE;
61 }
62 m_nJet_ref = m_config->GetValue("OffsetCorrection.DefaultNjetRef",-99.0);
63 if (m_nJet_ref==-99 && m_useNjet) {
64 ATH_MSG_FATAL("OffsetCorrection.DefaultNjetRef not specified.");
65 return StatusCode::FAILURE;
66 }
67
68 //Add the residual offset correction factors to the config TEnv
69 TString ResidualOffsetCalibFile = m_config->GetValue("ResidualOffset.CalibFile","");
70 if(m_dev){
71 ResidualOffsetCalibFile.Remove(0,33);
72 ResidualOffsetCalibFile.Insert(0,"JetCalibTools/");
73 }
74 else{ResidualOffsetCalibFile.Insert(14,m_calibAreaTag);}
75 TString calibFile = PathResolverFindCalibFile(ResidualOffsetCalibFile.Data());
76 m_config->ReadFile(calibFile, kEnvLocal);
77 //Retrieve information specific to the residual offset correction from the TEnv
78 TString offsetName = m_config->GetValue("ResidualOffsetCorrection.Name","");
79 m_resOffsetDesc = m_config->GetValue(offsetName+".Description","");
80 ATH_MSG_INFO("Reading residual jet-area pile-up correction factors from: " << calibFile);
81 ATH_MSG_INFO("Description: " << m_resOffsetDesc);
82
83 //Check if the config is set to apply the beamspot correction to NPV
84 m_applyNPVBeamspotCorrection = m_config->GetValue("ApplyNPVBeamspotCorrection",false);
85
86 std::vector<double> offsetEtaBins = JetCalibUtils::VectorizeD( m_config->GetValue(offsetName+".AbsEtaBins","") );
87 if (offsetEtaBins.size()<3) { ATH_MSG_FATAL(offsetName << ".AbsEtaBins not specified"); return StatusCode::FAILURE; }
88 m_resOffsetBins = new TAxis(offsetEtaBins.size()-1,&offsetEtaBins[0]);
89
90 if(!doNPVOnly && !doNJetOnly){
91 m_resOffsetMu = JetCalibUtils::VectorizeD(m_config->GetValue(offsetName+".MuTerm."+m_jetAlgo,""));
92 if ( (int)m_resOffsetMu.size()!=m_resOffsetBins->GetNbins()+1 ) {
93 ATH_MSG_FATAL( "Incorrect specification of " << offsetName << ".MuTerm." << m_jetAlgo );
94 return StatusCode::FAILURE;
95 }
96 }
97 if(m_useNjet) {
98 m_resOffsetNjet = JetCalibUtils::VectorizeD(m_config->GetValue(offsetName+".nJetTerm."+m_jetAlgo,""));
99 if ((int)m_resOffsetNjet.size()!=m_resOffsetBins->GetNbins()+1) {
100 ATH_MSG_FATAL( "Incorrect specification of " << offsetName << ".nJetTerm." << m_jetAlgo );
101 return StatusCode::FAILURE;
102 }
103 } else if(!doMuOnly){
104 m_resOffsetNPV = JetCalibUtils::VectorizeD(m_config->GetValue(offsetName+".NPVTerm."+m_jetAlgo,""));
105 if ((int)m_resOffsetNPV.size()!=m_resOffsetBins->GetNbins()+1) {
106 ATH_MSG_FATAL( "Incorrect specification of " << offsetName << ".NPVTerm." << m_jetAlgo );
107 return StatusCode::FAILURE;
108 }
110 m_npvBeamspotCorr = new NPVBeamspotCorrection();
111 ATH_MSG_INFO("\n NPV beamspot correction will be applied.");
112 }
113 }
114
115 return StatusCode::SUCCESS;
116}
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
VecD VectorizeD(const TString &str, const TString &sep=" ")

◆ initMessaging()

void AthMessaging::initMessaging ( ) const
privateinherited

Initialize our message level and MessageSvc.

This method should only be called once.

Definition at line 39 of file AthMessaging.cxx.

40{
42 // If user did not set an explicit level, set a default
43 if (m_lvl == MSG::NIL) {
44 m_lvl = m_imsg ?
45 static_cast<MSG::Level>( m_imsg.load()->outputLevel(m_nm) ) :
46 MSG::INFO;
47 }
48}
std::string m_nm
Message source name.
std::atomic< IMessageSvc * > m_imsg
MessageSvc pointer.
std::atomic< MSG::Level > m_lvl
Current logging level.
IMessageSvc * getMessageSvc(bool quiet=false)

◆ msg() [1/2]

MsgStream & asg::AsgMessaging::msg ( ) const
inherited

The standard message stream.

Returns
A reference to the default message stream of this object.

Definition at line 49 of file AsgMessaging.cxx.

49 {
50#ifndef XAOD_STANDALONE
51 return ::AthMessaging::msg();
52#else // not XAOD_STANDALONE
53 return m_msg;
54#endif // not XAOD_STANDALONE
55 }

◆ msg() [2/2]

MsgStream & asg::AsgMessaging::msg ( const MSG::Level lvl) const
inherited

The standard message stream.

Parameters
lvlThe message level to set the stream to
Returns
A reference to the default message stream, set to level "lvl"

Definition at line 57 of file AsgMessaging.cxx.

57 {
58#ifndef XAOD_STANDALONE
59 return ::AthMessaging::msg( lvl );
60#else // not XAOD_STANDALONE
61 m_msg << lvl;
62 return m_msg;
63#endif // not XAOD_STANDALONE
64 }

◆ msgLvl()

bool asg::AsgMessaging::msgLvl ( const MSG::Level lvl) const
inherited

Test the output level of the object.

Parameters
lvlThe message level to test against
Returns
boolean Indicting if messages at given level will be printed
true If messages at level "lvl" will be printed

Definition at line 41 of file AsgMessaging.cxx.

41 {
42#ifndef XAOD_STANDALONE
43 return ::AthMessaging::msgLvl( lvl );
44#else // not XAOD_STANDALONE
45 return m_msg.msgLevel( lvl );
46#endif // not XAOD_STANDALONE
47 }

◆ setLevel()

void AthMessaging::setLevel ( MSG::Level lvl)
inherited

Change the current logging level.

Use this rather than msg().setLevel() for proper operation with MT.

Definition at line 28 of file AthMessaging.cxx.

29{
30 m_lvl = lvl;
31}

Member Data Documentation

◆ ATLAS_THREAD_SAFE

std::atomic_flag m_initialized AthMessaging::ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT
mutableprivateinherited

Messaging initialized (initMessaging)

Definition at line 141 of file AthMessaging.h.

◆ m_applyNPVBeamspotCorrection

bool ResidualOffsetCorrection::m_applyNPVBeamspotCorrection {}
private

Definition at line 58 of file ResidualOffsetCorrection.h.

58{};

◆ m_calibAreaTag

TString ResidualOffsetCorrection::m_calibAreaTag
private

Definition at line 49 of file ResidualOffsetCorrection.h.

◆ m_config

TEnv* ResidualOffsetCorrection::m_config {}
private

Definition at line 48 of file ResidualOffsetCorrection.h.

48{};

◆ m_dev

bool ResidualOffsetCorrection::m_dev {}
private

Definition at line 50 of file ResidualOffsetCorrection.h.

50{};

◆ m_GeV

float ResidualOffsetCorrection::m_GeV = 1000
staticconstexprprivate

Definition at line 52 of file ResidualOffsetCorrection.h.

◆ m_imsg

std::atomic<IMessageSvc*> AthMessaging::m_imsg { nullptr }
mutableprivateinherited

MessageSvc pointer.

Definition at line 135 of file AthMessaging.h.

135{ nullptr };

◆ m_isData

bool ResidualOffsetCorrection::m_isData {}
private

Definition at line 51 of file ResidualOffsetCorrection.h.

51{};

◆ m_jetAlgo

TString ResidualOffsetCorrection::m_jetAlgo
private

Definition at line 49 of file ResidualOffsetCorrection.h.

◆ m_lvl

std::atomic<MSG::Level> AthMessaging::m_lvl { MSG::NIL }
mutableprivateinherited

Current logging level.

Definition at line 138 of file AthMessaging.h.

138{ MSG::NIL };

◆ m_msg_tls

boost::thread_specific_ptr<MsgStream> AthMessaging::m_msg_tls
mutableprivateinherited

MsgStream instance (a std::cout like with print-out levels)

Definition at line 132 of file AthMessaging.h.

◆ m_mu_ref

double ResidualOffsetCorrection::m_mu_ref {}
private

Definition at line 60 of file ResidualOffsetCorrection.h.

60{}, m_NPV_ref{}, m_nJet_ref{};

◆ m_muSF

double ResidualOffsetCorrection::m_muSF {}
private

Definition at line 59 of file ResidualOffsetCorrection.h.

59{};

◆ m_nJet_ref

double ResidualOffsetCorrection::m_nJet_ref {}
private

Definition at line 60 of file ResidualOffsetCorrection.h.

60{}, m_NPV_ref{}, m_nJet_ref{};

◆ m_nm

std::string AthMessaging::m_nm
privateinherited

Message source name.

Definition at line 129 of file AthMessaging.h.

◆ m_NPV_ref

double ResidualOffsetCorrection::m_NPV_ref {}
private

Definition at line 60 of file ResidualOffsetCorrection.h.

60{}, m_NPV_ref{}, m_nJet_ref{};

◆ m_npvBeamspotCorr

NPVBeamspotCorrection* ResidualOffsetCorrection::m_npvBeamspotCorr {}
private

Definition at line 54 of file ResidualOffsetCorrection.h.

54{};

◆ m_resOffsetBins

TAxis* ResidualOffsetCorrection::m_resOffsetBins {}
private

Definition at line 57 of file ResidualOffsetCorrection.h.

57{};

◆ m_resOffsetDesc

TString ResidualOffsetCorrection::m_resOffsetDesc
private

Definition at line 56 of file ResidualOffsetCorrection.h.

◆ m_resOffsetMu

std::vector<double> ResidualOffsetCorrection::m_resOffsetMu
private

Definition at line 63 of file ResidualOffsetCorrection.h.

◆ m_resOffsetNjet

std::vector<double> ResidualOffsetCorrection::m_resOffsetNjet
private

Definition at line 63 of file ResidualOffsetCorrection.h.

◆ m_resOffsetNPV

std::vector<double> ResidualOffsetCorrection::m_resOffsetNPV
private

Definition at line 63 of file ResidualOffsetCorrection.h.

◆ m_useNjet

bool ResidualOffsetCorrection::m_useNjet {}
private

Definition at line 61 of file ResidualOffsetCorrection.h.

61{};

The documentation for this class was generated from the following files: