ATLAS Offline Software
Loading...
Searching...
No Matches
PhysValTau.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5// PhysValTau.cxx
6// Implementation file for class PhysValTau
7// Author: S.Binet<binet@cern.ch>
8
9// PhysVal includes
10#include "PhysValTau.h"
11
12// FrameWork includes
13#include "GaudiKernel/IToolSvc.h"
15
16
17PhysValTau::PhysValTau(const std::string& type,
18 const std::string& name,
19 const IInterface* parent) :
20 ManagedMonitorToolBase(type, name, parent)
21{
22}
23
24
26{
27 ATH_MSG_INFO ("Initializing " << name() << "...");
29
30 if ( m_isMC ) {
31 ATH_CHECK(m_truthTool.retrieve());
32 }
33 // selections are configured in PhysicsValidation job options
34 ATH_CHECK(m_primTauSel.retrieve());
35 ATH_CHECK(m_nomiTauSel.retrieve());
36
37 ATH_CHECK( m_tauContainerKey.initialize() );
38 ATH_CHECK( m_truthTauContainerKey.initialize() );
39
41 ATH_CHECK( m_IsTruthMatchedKey.initialize() );
42
44 ATH_CHECK( m_IsHadronicTauKey.initialize() );
45
46 return StatusCode::SUCCESS;
47}
48
50{
51 ATH_MSG_INFO ("Booking hists " << name() << "...");
52
53 // Physics validation plots are level 10
55 m_oTauValidationPlotsNominal->setDetailLevel(100);
56 m_oTauValidationPlotsNominal->initialize();
57 std::vector<HistData> hists_nominal = m_oTauValidationPlotsNominal->retrieveBookedHistograms();
58 ATH_MSG_INFO ("Filling n of nominal hists " << hists_nominal.size() << " ");
59 for (const auto& hist : hists_nominal) {
60 ATH_CHECK(regHist(hist.first,hist.second,all));
61 }
62
63
64 if(m_tauContainerKey.key()=="TauJets"){
65
67 m_oTauValidationPlotsNoCuts->setDetailLevel(100);
68 m_oTauValidationPlotsNoCuts->initialize();
69 std::vector<HistData> hists_nocuts = m_oTauValidationPlotsNoCuts->retrieveBookedHistograms();
70 ATH_MSG_INFO ("Filling n of no cuts hists " << hists_nocuts.size() << " ");
71 for (const auto& hist : hists_nocuts) {
72 ATH_CHECK(regHist(hist.first,hist.second,all));
73 }
74
75 }
76
77 return StatusCode::SUCCESS;
78}
79
80StatusCode PhysValTau::fillHistograms(const EventContext& ctx)
81{
82 ATH_MSG_DEBUG ("Filling hists " << name() << "...");
83
85 if (!tauJetsReadHandle.isValid()) {
86 ATH_MSG_ERROR ("Could not retrieve TauJetContainer with key " << tauJetsReadHandle.key());
87 return StatusCode::FAILURE;
88 }
89 const xAOD::TauJetContainer* taus = tauJetsReadHandle.cptr();
90
91
92 ATH_MSG_DEBUG("Number of taus: " << taus->size());
93
94 bool found_truth_taus = false;
95 const xAOD::TruthParticleContainer* truth_taus = nullptr;
96 // Retrieve truth tau container for efficiency calculation
97 if ( m_isMC ) {
99 if(!truthTauJetsReadHandle.isValid()) {
100 ATH_MSG_INFO("Input collection " << m_truthTauContainerKey.key() << " not found. Won't do reco efficiency plots ..");
101 found_truth_taus = false;
102 } else {
103 truth_taus = truthTauJetsReadHandle.cptr();
104 found_truth_taus = true;
105 }
106 }
107 // Vectors to calculate the reco efficiency
108 std::vector<const xAOD::TruthParticle*> vec_truth_taus;
109 std::vector<const xAOD::TauJet*> vec_reco_taus;
110
111 // Retrieve event info and beamSpotWeight
112 SG::ReadHandle<xAOD::EventInfo> eventInfoReadHandle("EventInfo", ctx);
113 const xAOD::EventInfo* eventInfo = eventInfoReadHandle.cptr();
114
115 float weight = eventInfo->beamSpotWeight();
116 float avg_mu = eventInfo->averageInteractionsPerCrossing();
117
118 m_oTauValidationPlotsNominal->m_oEventPlotsNom.fill(avg_mu,weight);
119
120 // Loop through recoonstructed tau container
121 for (auto tau : *taus) {
122 if ( m_detailLevel < 10 ) continue;
123 if ( !static_cast<bool>(m_primTauSel->accept(*tau)) ) continue;
124 bool nominal = static_cast<bool>(m_nomiTauSel->accept(*tau));
125
126 // fill histograms for reconstructed taus
127 if(m_tauContainerKey.key()=="TauJets"){
128 m_oTauValidationPlotsNoCuts->m_oRecoTauAllProngsPlots.fill(*tau, weight);
129 m_oTauValidationPlotsNoCuts->m_oNewCorePlots.fill(*tau, weight);
130 m_oTauValidationPlotsNoCuts->m_oRecTauEffPlots.fill(*tau, weight, avg_mu);
131 m_oTauValidationPlotsNoCuts->m_oRecoGeneralTauAllProngsPlots.fill(*tau, weight);
132 }
133 if ( nominal ) {
134 m_oTauValidationPlotsNominal->m_oRecoGeneralNom.fill(*tau, weight);
135 m_oTauValidationPlotsNominal->m_oRecTauEffPlotsNom.fill(*tau, weight, avg_mu);
136 m_oTauValidationPlotsNominal->m_oRecTauRecoTauPlotsNom.fill(*tau, weight);
137 m_oTauValidationPlotsNominal->m_oNewCoreRecTauPlotsNom.fill(*tau, weight);
138 }
139 int recProng = tau->nTracks();
140 if ( recProng == 1 ) {
141 if(m_tauContainerKey.key()=="TauJets"){
142 m_oTauValidationPlotsNoCuts->m_oRecoHad1ProngPlots.fill(*tau, weight);
143 m_oTauValidationPlotsNoCuts->m_oRecTauEff1PPlots.fill(*tau, weight, avg_mu);
144 }
145 if ( nominal ) {
146 m_oTauValidationPlotsNominal->m_oRecoHad1ProngNom.fill(*tau, weight);
147 m_oTauValidationPlotsNominal->m_oRecTauEff1PPlotsNom.fill(*tau, weight, avg_mu);
148 }
149 }
150 else if ( recProng == 3 ) {
151 if(m_tauContainerKey.key()=="TauJets"){
152 m_oTauValidationPlotsNoCuts->m_oRecoHad3ProngPlots.fill(*tau, weight);
153 m_oTauValidationPlotsNoCuts->m_oRecTauEff3PPlots.fill(*tau, weight, avg_mu);
154 }
155 if ( nominal ) {
156 m_oTauValidationPlotsNominal->m_oRecoHad3ProngNom.fill(*tau, weight);
157 m_oTauValidationPlotsNominal->m_oRecTauEff3PPlotsNom.fill(*tau, weight, avg_mu);
158 }
159 }
160
161 // Don't fill truth and fake histograms if we are running on data.
162 if ( !m_isMC ) continue;
163
164 ATH_MSG_DEBUG("Trying to truth-match tau");
165 auto trueTau = m_truthTool->getTruth(*tau);
166
167 // Fill truth and fake histograms
169 if( (bool) isTruthMatched(*tau) && (!(MC::isSMQuark(trueTau) || MC::isGluon(trueTau))) ) {
170 ATH_MSG_DEBUG("Tau is truth-matched and not with a quark or a jet");
171 if ( trueTau->isTau() ) {
173 if( (bool) isHadronicTau(*trueTau) ) {
174 ATH_MSG_DEBUG("Tau is hadronic tau");
175 if(m_tauContainerKey.key()=="TauJets"){
176 m_oTauValidationPlotsNoCuts->m_oGeneralTauAllProngsPlots.fill(*tau, weight);
177 m_oTauValidationPlotsNoCuts->m_oNewCoreMatchedPlots.fill(*tau, weight);
178 m_oTauValidationPlotsNoCuts->m_oMatchedResolutionPlots.fill(*tau, *trueTau, weight);
179
180 // Substructure/PFO histograms
181 m_oTauValidationPlotsNoCuts->m_oMatchedTauAllProngsPlots.fill(*tau, weight);
182 m_oTauValidationPlotsNoCuts->m_oMatchedTauEffPlots.fill(*tau, weight, avg_mu);
183 }
184 if ( nominal ) {
185 m_oTauValidationPlotsNominal->m_oMatchedGeneralNom.fill(*tau, weight);
186 m_oTauValidationPlotsNominal->m_oMatchedResolutionPlotsNom.fill(*tau, *trueTau, weight);
187 m_oTauValidationPlotsNominal->m_oMatchedTauEffPlotsNom.fill(*tau, weight, avg_mu);
188 m_oTauValidationPlotsNominal->m_oMatchedTauRecoTauPlotsNom.fill(*tau, weight);
189 m_oTauValidationPlotsNominal->m_oNewCoreMatchedPlotsNom.fill(*tau, weight);
190
191 if(found_truth_taus){
192 vec_reco_taus.push_back(tau);
193 }
194 }
195 if ( recProng == 1 ) {
196 if(m_tauContainerKey.key()=="TauJets"){
197 m_oTauValidationPlotsNoCuts->m_oHad1ProngPlots.fill(*tau, weight);
198 m_oTauValidationPlotsNoCuts->m_oMatchedTauEff1PPlots.fill(*tau, weight, avg_mu);
199 m_oTauValidationPlotsNoCuts->m_oMatchedResolution1PPlots.fill(*tau, *trueTau, weight);
200 }
201 if ( nominal ) {
202 m_oTauValidationPlotsNominal->m_oMatchedHad1ProngNom.fill(*tau, weight);
203 m_oTauValidationPlotsNominal->m_oMatchedTauEff1PPlotsNom.fill(*tau, weight, avg_mu);
204 m_oTauValidationPlotsNominal->m_oMatchedResolution1PPlotsNom.fill(*tau, *trueTau, weight);
205 }
206 }
207 else if ( recProng == 3 ) {
208 if(m_tauContainerKey.key()=="TauJets"){
209 m_oTauValidationPlotsNoCuts->m_oHad3ProngPlots.fill(*tau, weight);
210 m_oTauValidationPlotsNoCuts->m_oMatchedTauEff3PPlots.fill(*tau, weight, avg_mu);
211 m_oTauValidationPlotsNoCuts->m_oMatchedResolution3PPlots.fill(*tau, *trueTau, weight);
212 }
213 if ( nominal ) {
214 m_oTauValidationPlotsNominal->m_oMatchedHad3ProngNom.fill(*tau, weight);
215 m_oTauValidationPlotsNominal->m_oMatchedTauEff3PPlotsNom.fill(*tau, weight, avg_mu);
216 m_oTauValidationPlotsNominal->m_oMatchedResolution3PPlotsNom.fill(*tau, *trueTau, weight);
217 }
218 }
219
220 xAOD::TauJetParameters::DecayMode trueMode = m_truthTool->getDecayMode(*trueTau);
221 if(m_tauContainerKey.key()=="TauJets") m_oTauValidationPlotsNoCuts->m_oMigrationPlots.fill(*tau, trueMode, weight);
222 if ( nominal ) {
223 m_oTauValidationPlotsNominal->m_oMigrationPlotsNom.fill(*tau, trueMode, weight);
224 }
225 }
226 } else if(trueTau->isElectron()) {
227 ATH_MSG_DEBUG("Tau is matched to an electron");
228 if(m_tauContainerKey.key()=="TauJets"){
229 m_oTauValidationPlotsNoCuts->m_oElMatchedParamPlots.fill(*tau, weight);
230 m_oTauValidationPlotsNoCuts->m_oElMatchedEVetoPlots.fill(*tau, weight);
231 }
232 if ( nominal ) {
233 m_oTauValidationPlotsNominal->m_oElMatchedParamPlotsNom.fill(*tau, weight);
234 m_oTauValidationPlotsNominal->m_oElMatchedEVetoPlotsNom.fill(*tau, weight);
235 if(recProng == 1) m_oTauValidationPlotsNominal->m_oElMatchedEff1PPlotsNom.fill(*tau, weight, avg_mu);
236 }
237 }
238 }
239 else {
240 ATH_MSG_DEBUG("Tau is matched to a jet or Tau is unmatched - consider it as fake");
241 if(m_tauContainerKey.key()=="TauJets"){
242 m_oTauValidationPlotsNoCuts->m_oFakeGeneralTauAllProngsPlots.fill(*tau, weight);
243 // Substructure/PFO histograms
244 m_oTauValidationPlotsNoCuts->m_oFakeTauAllProngsPlots.fill(*tau, weight);
245 m_oTauValidationPlotsNoCuts->m_oNewCoreFakePlots.fill(*tau, weight);
246 m_oTauValidationPlotsNoCuts->m_oFakeTauEffPlots.fill(*tau, weight, avg_mu);
247 }
248 if ( nominal ) {
249 m_oTauValidationPlotsNominal->m_oFakeGeneralNom.fill(*tau, weight);
250 m_oTauValidationPlotsNominal->m_oFakeTauEffPlotsNom.fill(*tau, weight, avg_mu);
251 m_oTauValidationPlotsNominal->m_oFakeTauRecoTauPlotsNom.fill(*tau, weight);
252 m_oTauValidationPlotsNominal->m_oNewCoreFakePlotsNom.fill(*tau, weight);
253 }
254 if ( recProng == 1 ) {
255 if(m_tauContainerKey.key()=="TauJets"){
256 m_oTauValidationPlotsNoCuts->m_oFakeHad1ProngPlots.fill(*tau, weight);
257 m_oTauValidationPlotsNoCuts->m_oFakeTauEff1PPlots.fill(*tau, weight, avg_mu);
258 }
259 if ( nominal ) {
260 m_oTauValidationPlotsNominal->m_oFakeHad1ProngNom.fill(*tau, weight);
261 m_oTauValidationPlotsNominal->m_oFakeTauEff1PPlotsNom.fill(*tau, weight, avg_mu);
262 }
263 }
264 if ( recProng == 3 ) {
265 if(m_tauContainerKey.key()=="TauJets"){
266 m_oTauValidationPlotsNoCuts->m_oFakeTauEff3PPlots.fill(*tau, weight, avg_mu);
267 m_oTauValidationPlotsNoCuts->m_oFakeHad3ProngPlots.fill(*tau, weight);
268 }
269 if ( nominal ) {
270 m_oTauValidationPlotsNominal->m_oFakeHad3ProngNom.fill(*tau, weight);
271 m_oTauValidationPlotsNominal->m_oFakeTauEff3PPlotsNom.fill(*tau, weight, avg_mu);
272 }
273 }
274 }
275 }
276
277 // plots for tau reco efficiency
278 if(found_truth_taus){
279 for (auto truth_tau : *truth_taus) {
280 vec_truth_taus.push_back(truth_tau);
281 }
282
283 // fill histograms
284 m_oTauValidationPlotsNominal->m_oMatchedTauRecoEffPlotsNom.fill(vec_truth_taus, vec_reco_taus, weight, avg_mu);
285 m_oTauValidationPlotsNominal->m_oMatchedTauTrkClassEffPlotsNom.fill(vec_truth_taus, vec_reco_taus, weight, avg_mu);
286 }
287
288 ATH_CHECK( m_truthTool->lockDecorations (*taus) );
289 return StatusCode::SUCCESS;
290}
291
293{
294 ATH_MSG_INFO ("Finalising hists " << name() << "...");
295 return StatusCode::SUCCESS;
296}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
ATLAS-specific HepMC functions.
static Double_t taus
virtual StatusCode regHist(TH1 *h, const std::string &system, Interval_t interval, MgmtAttr_t histo_mgmt=ATTRIB_MANAGED, const std::string &chain="", const std::string &merge="")
Registers a TH1 (including TH2, TH3, and TProfile) to be included in the output stream using logical ...
ManagedMonitorToolBase(const std::string &type, const std::string &name, const IInterface *parent)
virtual StatusCode procHistograms()
An inheriting class should either override this function or finalHists().
ToolHandle< TauAnalysisTools::ITauTruthMatchingTool > m_truthTool
Definition PhysValTau.h:49
SG::ReadDecorHandleKey< xAOD::TruthParticleContainer > m_IsHadronicTauKey
Definition PhysValTau.h:60
ToolHandle< TauAnalysisTools::ITauSelectionTool > m_primTauSel
Definition PhysValTau.h:51
virtual StatusCode fillHistograms(const EventContext &ctx)
An inheriting class should either override this function or fillHists().
std::unique_ptr< TauValidationPlotsNominal > m_oTauValidationPlotsNominal
Definition PhysValTau.h:64
SG::ReadDecorHandleKey< xAOD::TauJetContainer > m_IsTruthMatchedKey
Definition PhysValTau.h:59
virtual StatusCode bookHistograms()
An inheriting class should either override this function or bookHists().
ToolHandle< TauAnalysisTools::ITauSelectionTool > m_nomiTauSel
Definition PhysValTau.h:52
SG::ReadHandleKey< xAOD::TauJetContainer > m_tauContainerKey
Definition PhysValTau.h:55
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_truthTauContainerKey
Definition PhysValTau.h:56
std::unique_ptr< TauValidationPlotsNoCuts > m_oTauValidationPlotsNoCuts
Definition PhysValTau.h:65
PhysValTau(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
virtual StatusCode initialize()
Gaudi::Property< bool > m_isMC
Definition PhysValTau.h:46
Handle class for reading a decoration on an object.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
virtual const std::string & key() const override final
Return the StoreGate ID for the referenced object.
float beamSpotWeight() const
Weight for beam spot size reweighting.
float averageInteractionsPerCrossing() const
Average interactions per crossing for all BCIDs - for out-of-time pile-up.
bool isSMQuark(const T &p)
bool isGluon(const T &p)
EventInfo_v1 EventInfo
Definition of the latest event info version.
TauJetContainer_v3 TauJetContainer
Definition of the current "taujet container version".
TruthParticleContainer_v1 TruthParticleContainer
Declare the latest version of the truth particle container.