ATLAS Offline Software
Loading...
Searching...
No Matches
PhysValTau.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// 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 return StatusCode::SUCCESS;
38}
39
41{
42 ATH_MSG_INFO ("Booking hists " << name() << "...");
43
44 // Physics validation plots are level 10
46 m_oTauValidationPlotsNominal->setDetailLevel(100);
47 m_oTauValidationPlotsNominal->initialize();
48 std::vector<HistData> hists_nominal = m_oTauValidationPlotsNominal->retrieveBookedHistograms();
49 ATH_MSG_INFO ("Filling n of nominal hists " << hists_nominal.size() << " ");
50 for (const auto& hist : hists_nominal) {
51 ATH_CHECK(regHist(hist.first,hist.second,all));
52 }
53
54
55 if(m_TauJetContainerName=="TauJets"){
56
58 m_oTauValidationPlotsNoCuts->setDetailLevel(100);
59 m_oTauValidationPlotsNoCuts->initialize();
60 std::vector<HistData> hists_nocuts = m_oTauValidationPlotsNoCuts->retrieveBookedHistograms();
61 ATH_MSG_INFO ("Filling n of no cuts hists " << hists_nocuts.size() << " ");
62 for (const auto& hist : hists_nocuts) {
63 ATH_CHECK(regHist(hist.first,hist.second,all));
64 }
65
66 }
67
68 return StatusCode::SUCCESS;
69}
70
72{
73 ATH_MSG_DEBUG ("Filling hists " << name() << "...");
74
75 // Retrieve tau container
76 const xAOD::TauJetContainer* taus = nullptr;
79 } else {
80 ATH_MSG_INFO("Input collection " << m_TauJetContainerName << " not found. Skip the monitoring ..");
81 return StatusCode::SUCCESS;
82 }
83
84 ATH_MSG_DEBUG("Number of taus: " << taus->size());
85
86
87 // Retrieve event info and beamSpotWeight
88 const xAOD::EventInfo* eventInfo = nullptr;
89 ATH_CHECK( evtStore()->retrieve(eventInfo, "EventInfo") );
90
91
92 float weight = eventInfo->beamSpotWeight();
93 float avg_mu = eventInfo->averageInteractionsPerCrossing();
94
95 m_oTauValidationPlotsNominal->m_oEventPlotsNom.fill(avg_mu,weight);
96
97 // Loop through recoonstructed tau container
98 for (auto tau : *taus) {
99 if ( m_detailLevel < 10 ) continue;
100 if ( !static_cast<bool>(m_primTauSel->accept(*tau)) ) continue;
101 bool nominal = static_cast<bool>(m_nomiTauSel->accept(*tau));
102
103 // fill histograms for reconstructed taus
104 if(m_TauJetContainerName=="TauJets"){
105 m_oTauValidationPlotsNoCuts->m_oRecoTauAllProngsPlots.fill(*tau, weight);
106 m_oTauValidationPlotsNoCuts->m_oNewCorePlots.fill(*tau, weight);
107 m_oTauValidationPlotsNoCuts->m_oRecTauEffPlots.fill(*tau, weight, avg_mu);
108 m_oTauValidationPlotsNoCuts->m_oRecoGeneralTauAllProngsPlots.fill(*tau, weight);
109 }
110 if ( nominal ) {
111 m_oTauValidationPlotsNominal->m_oRecoGeneralNom.fill(*tau, weight);
112 m_oTauValidationPlotsNominal->m_oRecTauEffPlotsNom.fill(*tau, weight, avg_mu);
113 m_oTauValidationPlotsNominal->m_oRecTauRecoTauPlotsNom.fill(*tau, weight);
114 m_oTauValidationPlotsNominal->m_oNewCoreRecTauPlotsNom.fill(*tau, weight);
115 }
116 int recProng = tau->nTracks();
117 if ( recProng == 1 ) {
118 if(m_TauJetContainerName=="TauJets"){
119 m_oTauValidationPlotsNoCuts->m_oRecoHad1ProngPlots.fill(*tau, weight);
120 m_oTauValidationPlotsNoCuts->m_oRecTauEff1PPlots.fill(*tau, weight, avg_mu);
121 }
122 if ( nominal ) {
123 m_oTauValidationPlotsNominal->m_oRecoHad1ProngNom.fill(*tau, weight);
124 m_oTauValidationPlotsNominal->m_oRecTauEff1PPlotsNom.fill(*tau, weight, avg_mu);
125 }
126 }
127 else if ( recProng == 3 ) {
128 if(m_TauJetContainerName=="TauJets"){
129 m_oTauValidationPlotsNoCuts->m_oRecoHad3ProngPlots.fill(*tau, weight);
130 m_oTauValidationPlotsNoCuts->m_oRecTauEff3PPlots.fill(*tau, weight, avg_mu);
131 }
132 if ( nominal ) {
133 m_oTauValidationPlotsNominal->m_oRecoHad3ProngNom.fill(*tau, weight);
134 m_oTauValidationPlotsNominal->m_oRecTauEff3PPlotsNom.fill(*tau, weight, avg_mu);
135 }
136 }
137
138 // Don't fill truth and fake histograms if we are running on data.
139 if ( !m_isMC ) continue;
140
141 ATH_MSG_DEBUG("Trying to truth-match tau");
142 auto trueTau = m_truthTool->getTruth(*tau);
143
144 // Fill truth and fake histograms
145 static const SG::ConstAccessor<char> IsTruthMatchedAcc("IsTruthMatched");
146 if ( (bool)IsTruthMatchedAcc(*tau) && (!(MC::isSMQuark(trueTau) || MC::isGluon(trueTau))) ) {
147 ATH_MSG_DEBUG("Tau is truth-matched and not with a quark or a jet");
148 if ( trueTau->isTau() ) {
149 static const SG::ConstAccessor<char> IsHadronicTauAcc("IsHadronicTau");
150 if ( (bool)IsHadronicTauAcc(*trueTau) ) {
151 ATH_MSG_DEBUG("Tau is hadronic tau");
152 if(m_TauJetContainerName=="TauJets"){
153 m_oTauValidationPlotsNoCuts->m_oGeneralTauAllProngsPlots.fill(*tau, weight);
154 m_oTauValidationPlotsNoCuts->m_oNewCoreMatchedPlots.fill(*tau, weight);
155 m_oTauValidationPlotsNoCuts->m_oMatchedResolutionPlots.fill(*tau, *trueTau, weight);
156
157 // Substructure/PFO histograms
158 m_oTauValidationPlotsNoCuts->m_oMatchedTauAllProngsPlots.fill(*tau, weight);
159 m_oTauValidationPlotsNoCuts->m_oMatchedTauEffPlots.fill(*tau, weight, avg_mu);
160 }
161 if ( nominal ) {
162 m_oTauValidationPlotsNominal->m_oMatchedGeneralNom.fill(*tau, weight);
163 m_oTauValidationPlotsNominal->m_oMatchedResolutionPlotsNom.fill(*tau, *trueTau, weight);
164 m_oTauValidationPlotsNominal->m_oMatchedTauEffPlotsNom.fill(*tau, weight, avg_mu);
165 m_oTauValidationPlotsNominal->m_oMatchedTauRecoTauPlotsNom.fill(*tau, weight);
166 m_oTauValidationPlotsNominal->m_oNewCoreMatchedPlotsNom.fill(*tau, weight);
167 }
168 if ( recProng == 1 ) {
169 if(m_TauJetContainerName=="TauJets"){
170 m_oTauValidationPlotsNoCuts->m_oHad1ProngPlots.fill(*tau, weight);
171 m_oTauValidationPlotsNoCuts->m_oMatchedTauEff1PPlots.fill(*tau, weight, avg_mu);
172 m_oTauValidationPlotsNoCuts->m_oMatchedResolution1PPlots.fill(*tau, *trueTau, weight);
173 }
174 if ( nominal ) {
175 m_oTauValidationPlotsNominal->m_oMatchedHad1ProngNom.fill(*tau, weight);
176 m_oTauValidationPlotsNominal->m_oMatchedTauEff1PPlotsNom.fill(*tau, weight, avg_mu);
177 m_oTauValidationPlotsNominal->m_oMatchedResolution1PPlotsNom.fill(*tau, *trueTau, weight);
178 }
179 }
180 else if ( recProng == 3 ) {
181 if(m_TauJetContainerName=="TauJets"){
182 m_oTauValidationPlotsNoCuts->m_oHad3ProngPlots.fill(*tau, weight);
183 m_oTauValidationPlotsNoCuts->m_oMatchedTauEff3PPlots.fill(*tau, weight, avg_mu);
184 m_oTauValidationPlotsNoCuts->m_oMatchedResolution3PPlots.fill(*tau, *trueTau, weight);
185 }
186 if ( nominal ) {
187 m_oTauValidationPlotsNominal->m_oMatchedHad3ProngNom.fill(*tau, weight);
188 m_oTauValidationPlotsNominal->m_oMatchedTauEff3PPlotsNom.fill(*tau, weight, avg_mu);
189 m_oTauValidationPlotsNominal->m_oMatchedResolution3PPlotsNom.fill(*tau, *trueTau, weight);
190 }
191 }
192
193 xAOD::TauJetParameters::DecayMode trueMode = m_truthTool->getDecayMode(*trueTau);
194 if(m_TauJetContainerName=="TauJets") m_oTauValidationPlotsNoCuts->m_oMigrationPlots.fill(*tau, trueMode, weight);
195 if ( nominal ) {
196 m_oTauValidationPlotsNominal->m_oMigrationPlotsNom.fill(*tau, trueMode, weight);
197 }
198 }
199 } else if(trueTau->isElectron()) {
200 ATH_MSG_DEBUG("Tau is matched to an electron");
201 if(m_TauJetContainerName=="TauJets"){
202 m_oTauValidationPlotsNoCuts->m_oElMatchedParamPlots.fill(*tau, weight);
203 m_oTauValidationPlotsNoCuts->m_oElMatchedEVetoPlots.fill(*tau, weight);
204 }
205 if ( nominal ) {
206 m_oTauValidationPlotsNominal->m_oElMatchedParamPlotsNom.fill(*tau, weight);
207 m_oTauValidationPlotsNominal->m_oElMatchedEVetoPlotsNom.fill(*tau, weight);
208 if(recProng == 1) m_oTauValidationPlotsNominal->m_oElMatchedEff1PPlotsNom.fill(*tau, weight, avg_mu);
209 }
210 }
211 }
212 else {
213 ATH_MSG_DEBUG("Tau is matched to a jet or Tau is unmatched - consider it as fake");
214 if(m_TauJetContainerName=="TauJets"){
215 m_oTauValidationPlotsNoCuts->m_oFakeGeneralTauAllProngsPlots.fill(*tau, weight);
216 // Substructure/PFO histograms
217 m_oTauValidationPlotsNoCuts->m_oFakeTauAllProngsPlots.fill(*tau, weight);
218 m_oTauValidationPlotsNoCuts->m_oNewCoreFakePlots.fill(*tau, weight);
219 m_oTauValidationPlotsNoCuts->m_oFakeTauEffPlots.fill(*tau, weight, avg_mu);
220 }
221 if ( nominal ) {
222 m_oTauValidationPlotsNominal->m_oFakeGeneralNom.fill(*tau, weight);
223 m_oTauValidationPlotsNominal->m_oFakeTauEffPlotsNom.fill(*tau, weight, avg_mu);
224 m_oTauValidationPlotsNominal->m_oFakeTauRecoTauPlotsNom.fill(*tau, weight);
225 m_oTauValidationPlotsNominal->m_oNewCoreFakePlotsNom.fill(*tau, weight);
226 }
227 if ( recProng == 1 ) {
228 if(m_TauJetContainerName=="TauJets"){
229 m_oTauValidationPlotsNoCuts->m_oFakeHad1ProngPlots.fill(*tau, weight);
230 m_oTauValidationPlotsNoCuts->m_oFakeTauEff1PPlots.fill(*tau, weight, avg_mu);
231 }
232 if ( nominal ) {
233 m_oTauValidationPlotsNominal->m_oFakeHad1ProngNom.fill(*tau, weight);
234 m_oTauValidationPlotsNominal->m_oFakeTauEff1PPlotsNom.fill(*tau, weight, avg_mu);
235 }
236 }
237 if ( recProng == 3 ) {
238 if(m_TauJetContainerName=="TauJets"){
239 m_oTauValidationPlotsNoCuts->m_oFakeTauEff3PPlots.fill(*tau, weight, avg_mu);
240 m_oTauValidationPlotsNoCuts->m_oFakeHad3ProngPlots.fill(*tau, weight);
241 }
242 if ( nominal ) {
243 m_oTauValidationPlotsNominal->m_oFakeHad3ProngNom.fill(*tau, weight);
244 m_oTauValidationPlotsNominal->m_oFakeTauEff3PPlotsNom.fill(*tau, weight, avg_mu);
245 }
246 }
247 }
248 }
249
250 ATH_CHECK( m_truthTool->lockDecorations (*taus) );
251 return StatusCode::SUCCESS;
252}
253
255{
256 ATH_MSG_INFO ("Finalising hists " << name() << "...");
257 return StatusCode::SUCCESS;
258}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
ATLAS-specific HepMC functions.
static Double_t taus
ServiceHandle< StoreGateSvc > & evtStore()
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:48
ToolHandle< TauAnalysisTools::ITauSelectionTool > m_primTauSel
Definition PhysValTau.h:50
std::unique_ptr< TauValidationPlotsNominal > m_oTauValidationPlotsNominal
Definition PhysValTau.h:55
Gaudi::Property< std::string > m_TauJetContainerName
Definition PhysValTau.h:44
virtual StatusCode bookHistograms()
An inheriting class should either override this function or bookHists().
ToolHandle< TauAnalysisTools::ITauSelectionTool > m_nomiTauSel
Definition PhysValTau.h:51
std::unique_ptr< TauValidationPlotsNoCuts > m_oTauValidationPlotsNoCuts
Definition PhysValTau.h:56
virtual StatusCode fillHistograms()
An inheriting class should either override this function or fillHists().
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:45
Helper class to provide constant type-safe access to aux data.
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 contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:114
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".