ATLAS Offline Software
Loading...
Searching...
No Matches
GSCCalibStep.cxx
Go to the documentation of this file.
1
2
3/*
4 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
5*/
6
7// GSCCalibStep.cxx
8// Implementation file for class GSCCalibStep
10
12
13GSCCalibStep::GSCCalibStep(const std::string& name)
14 : asg::AsgTool( name ){ }
15
17// Public methods:
19
21 ATH_MSG_DEBUG ("Initializing " << name() );
22
23 ATH_MSG_DEBUG("Reading from " << m_jetInScale << " and writing to " << m_jetOutScale);
24
25 ATH_CHECK( m_histTool_EM3.retrieve());
27 ATH_CHECK( m_histTool_Tile0.retrieve());
29 ATH_CHECK( m_histTool_nTrk.retrieve());
31
32 ATH_CHECK(m_vertexContainer_key.initialize());
33 ATH_CHECK(m_eventInfo_key.initialize());
34
35 return StatusCode::SUCCESS;
36}
37
38
40
41 ATH_MSG_DEBUG("calibrating jet collection.");
42
43 // Retrieve the primary vertex location:
44 int PVindex = 0;
45
46 // Check if an analysis choose their own PV vertex ("PVIndex")
47 static const SG::AuxElement::ConstAccessor<int> pvIndexAccessor("PVIndex");
49 if(eventInfo.isValid()) {
50 if(pvIndexAccessor.isAvailable(*eventInfo)){
51 PVindex = pvIndexAccessor(*eventInfo);
52 }
53 }
54 else{
55 // Get the PV index directly from the vertices
57 const xAOD::VertexContainer& vertices = *vertexHandle;
58 const xAOD::Vertex *HSvertex = findHSVertex(vertices);
59 if(!HSvertex) {
60 ATH_MSG_WARNING("Invalid primary vertex found, will not continue applying the GSC.");
61 return StatusCode::FAILURE;
62 }
63 PVindex = HSvertex->index();
64 }
65
66 ATH_MSG_DEBUG("PV index:" << PVindex);
67
68 // Needed for per-vertex reconstructed jets
69 static const SG::ConstAccessor<xAOD::Vertex> originVertexAcc("OriginVertex");
70
71 // Calibrate the jets
72 for (xAOD::Jet* jet : jets){
73
75
76 // For the per-vertex reconstructed jets, use the vertex the jet was reconstructed with respect to
77 if(originVertexAcc.isAvailable(*jet)){
78 PVindex = jet->getAssociatedObject<xAOD::Vertex>("OriginVertex")->index();
79 }
80
81 xAOD::JetFourMom_t jetconstitP4 = jet->getAttribute<xAOD::JetFourMom_t>("JetConstitScaleMomentum");
82 std::vector<float> samplingFrac = jet->getAttribute<std::vector<float> >("EnergyPerSampling");
83 // get detector Eta
84 float detectorEta = jet->getAttribute<float>("DetectorEta");
85 // get trackWIDTHPVX
86 float trackWIDTHPVX = 0;
87 static const SG::ConstAccessor<std::vector<float> > TrackWidthPt1000Acc ("TrackWidthPt1000");
88 if(TrackWidthPt1000Acc.isAvailable(*jet))
89 {
90 trackWIDTHPVX = TrackWidthPt1000Acc(*jet).at(PVindex);
91 ATH_MSG_DEBUG("trackWIDTHPVX found set to: " << trackWIDTHPVX);
92 }
93 jc.setValue("trackWIDTH", trackWIDTHPVX);
94 // get nTrkPVX
95 int nTrkPVX = 0;
96 static const SG::ConstAccessor<std::vector<int>> NumTrkPt1000Acc ("NumTrkPt1000");
97 if(NumTrkPt1000Acc.isAvailable(*jet))
98 {
99 nTrkPVX = NumTrkPt1000Acc(*jet).at(PVindex);
100 ATH_MSG_DEBUG("nTrkPVX found set to: " << nTrkPVX);
101 }
102 jc.setValue("nTrk", nTrkPVX);
103 // get Charged Fraction
104 float ChargedFraction = 0;
105 static const SG::ConstAccessor<std::vector<float>> SumPtChargedPFOPt500Acc ("SumPtChargedPFOPt500");
106 if(SumPtChargedPFOPt500Acc.isAvailable(*jet))
107 {
108 ChargedFraction = SumPtChargedPFOPt500Acc(*jet).at(PVindex)/jetconstitP4.Pt();
109 ATH_MSG_DEBUG("ChargedFraction found set to: " << ChargedFraction);
110 }
111 jc.setValue("ChargedFraction", ChargedFraction);
112 // get EM3
113 float EM3 = (samplingFrac[3]+samplingFrac[7])/jetconstitP4.e();
114 ATH_MSG_DEBUG("EM3 found set to: " << EM3);
115 jc.setValue("EM3", EM3);
116 // get Tile0
117 float Tile0 = (samplingFrac[12]+samplingFrac[18])/jetconstitP4.e();
118 ATH_MSG_DEBUG("Tile0 found set to: " << Tile0);
119 jc.setValue("Tile0", Tile0);
120 // get N90Constituents
121 double N90Constituents = 0;
122 static const SG::ConstAccessor<float> N90ConstituentsAcc ("N90Constituents");
123 if(N90ConstituentsAcc.isAvailable(*jet))
124 {
125 N90Constituents = N90ConstituentsAcc(*jet);
126 ATH_MSG_DEBUG("N90Constituents found set to: " << N90Constituents);
127 }
128 jc.setValue("N90Constituents", N90Constituents);
129 // get caloWIDTH
130 double caloWIDTH = 0;
131 static const SG::ConstAccessor<float> WidthAcc ("Width");
132 if(WidthAcc.isAvailable(*jet))
133 {
134 caloWIDTH = WidthAcc(*jet);
135 ATH_MSG_DEBUG("caloWIDTH found set to: " << caloWIDTH);
136 }
137 jc.setValue("caloWIDTH", caloWIDTH);
138 // get TG3
139 float TG3 = (samplingFrac[17])/jetconstitP4.e();
140 ATH_MSG_DEBUG("TG3 found set to: " << TG3);
141 jc.setValue("TG3", TG3);
142 // get Muon segments
143 int Nsegments = 0;
144 static const SG::ConstAccessor<int> GhostMuonSegmentCountAcc ("GhostMuonSegmentCount");
145 if(GhostMuonSegmentCountAcc.isAvailable(*jet))
146 {
147 Nsegments = GhostMuonSegmentCountAcc(*jet);
148 ATH_MSG_DEBUG("Nsegments found set to: " << Nsegments);
149 }
150 jc.setValue("Nsegments", Nsegments);
151
152 float getGSCCorrection = 1.0;
153 int etabin = std::abs(detectorEta)/0.1;// m_binSize in old version
154
155 const xAOD::JetFourMom_t startingP4 = jet->getAttribute<xAOD::JetFourMom_t>(m_jetInScale);
156 jet->setJetP4(startingP4);
157
158 ATH_MSG_DEBUG("Jet pt original ("<<m_jetInScale<<"): " << jet->pt()*1e-3);
159
160 ATH_MSG_DEBUG("ChargedFraction Response: " << getChargedFractionResponse(*jet, jc, etabin));
161 ATH_MSG_DEBUG("Tile0 Response: " <<getTile0Response(*jet, jc, etabin));
162 ATH_MSG_DEBUG("EM3 Response: " << getEM3Response(*jet, jc, etabin));
163 ATH_MSG_DEBUG("NTrk Response: " <<getNTrkResponse(*jet, jc, etabin));
164 ATH_MSG_DEBUG("TrkWidth Response: " <<getTrackWIDTHResponse(*jet, jc, etabin));
165
166 getGSCCorrection*=1./getChargedFractionResponse(*jet, jc, etabin);
167 jet->setJetP4( startingP4*getGSCCorrection );
168 getGSCCorrection*=1./getTile0Response(*jet, jc, etabin);
169 jet->setJetP4( startingP4*getGSCCorrection );
170 getGSCCorrection*=1./getEM3Response(*jet, jc, etabin);
171 jet->setJetP4( startingP4*getGSCCorrection );
172 getGSCCorrection*=1./getNTrkResponse(*jet, jc, etabin);
173 jet->setJetP4( startingP4*getGSCCorrection );
174 getGSCCorrection*=1./getTrackWIDTHResponse(*jet, jc, etabin);
175
176 if(m_applyPunchThrough && startingP4.Pt() >= m_punchThroughMinPt){
177 jet->setJetP4( startingP4*getGSCCorrection );
178 getGSCCorrection*=1./getPunchThroughResponse(*jet, jc, std::abs(detectorEta));
179 }
180
181 ATH_MSG_DEBUG("GSC full correction: " << getGSCCorrection);
182
183 jet->setAttribute<xAOD::JetFourMom_t>(m_jetOutScale,startingP4*getGSCCorrection);
184 jet->setJetP4( startingP4*getGSCCorrection );
185
186 ATH_MSG_DEBUG("Jet pt calibrated:" << jet->pt()*1e-3);
187
188
189 }// loop jets
190
191 return StatusCode::SUCCESS;
192}
193
195 if (jc.getValue<float>("ChargedFraction")<=0) return 1; //ChargedFraction < 0 is unphysical, ChargedFraction = 0 is a special case, so we return 1 for ChargedFraction <= 0
196 if ( etabin >= m_histTool_ChargedFraction.size() ) return 1.;
197 double ChargedFractionResponse = m_histTool_ChargedFraction[etabin]->getValue(jet, jc);
198 return ChargedFractionResponse;
199}
200
202 if (jc.getValue<float>("Tile0")<0) return 1; //Tile0 < 0 is unphysical, so we return 1
203 if ( etabin >= m_histTool_Tile0.size() ) return 1.;
204 double Tile0Response = m_histTool_Tile0[etabin]->getValue(jet, jc);
205 return Tile0Response;
206}
207
209 if (jc.getValue<float>("EM3")<=0) return 1; //EM3 < 0 is unphysical, EM3 = 0 is a special case, so we return 1 for EM3 <= 0
210 if ( etabin >= m_histTool_EM3.size() ) return 1.;
211 float EM3Response = m_histTool_EM3[etabin]->getValue(jet, jc);
212 return EM3Response;
213}
214
215float GSCCalibStep::getPunchThroughResponse(const xAOD::Jet& jet, const JetHelper::JetContext& jc, double eta_det) const {
216 int etabin=-99;
218 ATH_MSG_WARNING("Please check that the punch through eta binning is properly set in your config file");
219 if ( eta_det >= m_punchThroughEtaBins[m_punchThroughEtaBins.size()-1] || jc.getValue<int>("Nsegments") < 20 ) return 1;
220 for (uint i=0; i<m_punchThroughEtaBins.size()-1; ++i) {
221 if(eta_det >= m_punchThroughEtaBins[i] && eta_det < m_punchThroughEtaBins[i+1]) etabin = i;
222 }
223 if(etabin<0) {
224 ATH_MSG_WARNING("There was a problem determining the eta bin to use for the punch through correction.");
225 //this could probably be improved, but to avoid a seg fault...
226 return 1;
227 }
228 double PunchThroughResponse = m_histTool_PunchThrough[etabin]->getValue(jet, jc);
229 if(PunchThroughResponse>1) return 1;
230 return PunchThroughResponse;
231}
232
234 if (jc.getValue<int>("nTrk")<=0) return 1; //nTrk < 0 is unphysical, nTrk = 0 is a special case, so return 1 for nTrk <= 0
235 if ( etabin >= m_histTool_nTrk.size() ) return 1.;
236 double nTrkResponse = m_histTool_nTrk[etabin]->getValue(jet, jc);
237 return nTrkResponse;
238}
239
241 if (jc.getValue<float>("trackWIDTH")<=0) return 1;
242 if ( etabin >= m_histTool_trackWIDTH.size() ) return 1.;
243 //jets with no tracks are assigned a trackWIDTH of -1, we use the trackWIDTH=0 correction in those cases
244 double trackWIDTHResponse = m_histTool_trackWIDTH[etabin]->getValue(jet, jc);
245 return trackWIDTHResponse;
246}
247
249 for ( const xAOD::Vertex* vertex : vertices ) {
250 if(vertex->vertexType() == xAOD::VxType::PriVtx) {
251 ATH_MSG_VERBOSE("GSCCalibStep " << name() << " Found HS vertex at index: "<< vertex->index());
252 return vertex;
253 }
254 }
255 if (vertices.size()==1) {
256 ATH_MSG_VERBOSE("GSCCalibStep " << name() << " Found no HS vertex, return dummy");
257 if (vertices.back()->vertexType() == xAOD::VxType::NoVtx)
258 return vertices.back();
259 }
260 ATH_MSG_VERBOSE("No vertex found in container.");
261 return nullptr;
262}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
unsigned int uint
const T * back() const
Access the last element in the collection as an rvalue.
size_type size() const noexcept
Returns the number of elements in the collection.
float getPunchThroughResponse(const xAOD::Jet &jet, const JetHelper::JetContext &jc, double eta_det) const
Gaudi::Property< std::vector< double > > m_punchThroughEtaBins
ToolHandleArray< JetHelper::IVarTool > m_histTool_ChargedFraction
virtual StatusCode calibrate(xAOD::JetContainer &) const override
Apply calibration to a jet container.
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfo_key
EventInfo to retrieve PV index for analyses choosing their own PV (e.g. H to yy)
ToolHandleArray< JetHelper::IVarTool > m_histTool_trackWIDTH
float getNTrkResponse(const xAOD::Jet &jet, const JetHelper::JetContext &jc, uint etabin) const
Gaudi::Property< std::string > m_jetInScale
ToolHandleArray< JetHelper::IVarTool > m_histTool_EM3
float getTile0Response(const xAOD::Jet &jet, const JetHelper::JetContext &jc, uint etabin) const
SG::ReadHandleKey< xAOD::VertexContainer > m_vertexContainer_key
Gaudi::Property< std::string > m_jetOutScale
const xAOD::Vertex * findHSVertex(const xAOD::VertexContainer &vertices) const
Retrieve hard scatter vertex for its index. Return nullptr if one cannot be found.
float getEM3Response(const xAOD::Jet &jet, const JetHelper::JetContext &jc, uint etabin) const
ToolHandleArray< JetHelper::IVarTool > m_histTool_Tile0
float getTrackWIDTHResponse(const xAOD::Jet &jet, const JetHelper::JetContext &jc, uint etabin) const
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
ToolHandleArray< JetHelper::IVarTool > m_histTool_PunchThrough
ToolHandleArray< JetHelper::IVarTool > m_histTool_nTrk
float getChargedFractionResponse(const xAOD::Jet &jet, const JetHelper::JetContext &jc, uint etabin) const
Functions for retrieving the correction factors.
Gaudi::Property< float > m_punchThroughMinPt
Gaudi::Property< bool > m_applyPunchThrough
Properties for the punch-through correction:
GSCCalibStep(const std::string &name="GSCCalibStep")
Constructor with parameters:
Class JetContext Designed to read AOD information related to the event, N vertices,...
Definition JetContext.h:24
bool setValue(const std::string &name, const T value, bool allowOverwrite=false)
Definition JetContext.h:52
void getValue(const std::string &name, T &value) const
Definition JetContext.h:39
SG::ConstAccessor< T, ALLOC > ConstAccessor
Definition AuxElement.h:570
size_t index() const
Return the index of this element within its container.
Helper class to provide constant type-safe access to aux data.
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition AsgTool.cxx:58
VxType::VertexType vertexType() const
The type of the vertex.
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition index.py:1
@ PriVtx
Primary vertex.
@ NoVtx
Dummy vertex. TrackParticle was not used in vertex fit.
Jet_v1 Jet
Definition of the current "jet version".
VertexContainer_v1 VertexContainer
Definition of the current "Vertex container version".
Vertex_v1 Vertex
Define the latest version of the vertex class.
JetContainer_v1 JetContainer
Definition of the current "jet container version".
ROOT::Math::LorentzVector< ROOT::Math::PtEtaPhiM4D< double > > JetFourMom_t
Base 4 Momentum type for Jet.
Definition JetTypes.h:17