ATLAS Offline Software
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 // STL includes
13 #include <vector>
14 
15 // FrameWork includes
16 #include "GaudiKernel/IToolSvc.h"
17 #include "xAODJet/JetContainer.h"
19 #include "xAODTau/TauJetContainer.h"
24 
25 
26 PhysValTau::PhysValTau(const std::string& type,
27  const std::string& name,
28  const IInterface* parent) :
30 {
31 }
32 
33 
35 {
36  ATH_MSG_INFO ("Initializing " << name() << "...");
38 
39  if ( m_isMC ) {
40  ATH_CHECK(m_truthTool.retrieve());
41  }
42  // selections are configured in PhysicsValidation job options
43  ATH_CHECK(m_primTauSel.retrieve());
44  ATH_CHECK(m_nomiTauSel.retrieve());
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_TauJetContainerName=="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 
81 {
82  ATH_MSG_DEBUG ("Filling hists " << name() << "...");
83 
84  // Retrieve tau container
85  const xAOD::TauJetContainer* taus = nullptr;
86  if(evtStore()->contains<xAOD::TauJetContainer>(m_TauJetContainerName)){
88  } else {
89  ATH_MSG_INFO("Input collection " << m_TauJetContainerName << " not found. Skip the monitoring ..");
90  return StatusCode::SUCCESS;
91  }
92 
93  ATH_MSG_DEBUG("Number of taus: " << taus->size());
94 
95 
96  // Retrieve event info and beamSpotWeight
97  const xAOD::EventInfo* eventInfo = nullptr;
98  ATH_CHECK( evtStore()->retrieve(eventInfo, "EventInfo") );
99 
100  float weight = eventInfo->beamSpotWeight();
101 
102  // Loop through recoonstructed tau container
103  for (auto tau : *taus) {
104  if ( m_detailLevel < 10 ) continue;
105  if ( !static_cast<bool>(m_primTauSel->accept(*tau)) ) continue;
106  bool nominal = static_cast<bool>(m_nomiTauSel->accept(*tau));
107 
108  // fill histograms for reconstructed taus
109  if(m_TauJetContainerName=="TauJets"){
110  m_oTauValidationPlotsNoCuts->m_oRecoTauAllProngsPlots.fill(*tau, weight);
111  m_oTauValidationPlotsNoCuts->m_oNewCorePlots.fill(*tau, weight);
112  m_oTauValidationPlotsNoCuts->m_oRecTauEffPlots.fill(*tau, weight);
113  m_oTauValidationPlotsNoCuts->m_oRecoGeneralTauAllProngsPlots.fill(*tau, weight);
114  }
115  if ( nominal ) {
116  m_oTauValidationPlotsNominal->m_oRecoGeneralNom.fill(*tau, weight);
117  m_oTauValidationPlotsNominal->m_oRecTauEffPlotsNom.fill(*tau, weight);
118  m_oTauValidationPlotsNominal->m_oRecTauRecoTauPlotsNom.fill(*tau, weight);
119  m_oTauValidationPlotsNominal->m_oNewCoreRecTauPlotsNom.fill(*tau, weight);
120  }
121  int recProng = tau->nTracks();
122  if ( recProng == 1 ) {
123  if(m_TauJetContainerName=="TauJets"){
124  m_oTauValidationPlotsNoCuts->m_oRecoHad1ProngPlots.fill(*tau, weight);
125  m_oTauValidationPlotsNoCuts->m_oRecTauEff1PPlots.fill(*tau, weight);
126  }
127  if ( nominal ) {
128  m_oTauValidationPlotsNominal->m_oRecoHad1ProngNom.fill(*tau, weight);
129  m_oTauValidationPlotsNominal->m_oRecTauEff1PPlotsNom.fill(*tau, weight);
130  }
131  }
132  else if ( recProng == 3 ) {
133  if(m_TauJetContainerName=="TauJets"){
134  m_oTauValidationPlotsNoCuts->m_oRecoHad3ProngPlots.fill(*tau, weight);
135  m_oTauValidationPlotsNoCuts->m_oRecTauEff3PPlots.fill(*tau, weight);
136  }
137  if ( nominal ) {
138  m_oTauValidationPlotsNominal->m_oRecoHad3ProngNom.fill(*tau, weight);
139  m_oTauValidationPlotsNominal->m_oRecTauEff3PPlotsNom.fill(*tau, weight);
140  }
141  }
142 
143  // Don't fill truth and fake histograms if we are running on data.
144  if ( !m_isMC ) continue;
145 
146  ATH_MSG_DEBUG("Trying to truth-match tau");
147  auto trueTau = m_truthTool->getTruth(*tau);
148 
149  // Fill truth and fake histograms
150  static const SG::ConstAccessor<char> IsTruthMatchedAcc("IsTruthMatched");
151  if ( (bool)IsTruthMatchedAcc(*tau) ) {
152  ATH_MSG_DEBUG("Tau is truth-matched");
153  if ( trueTau->isTau() ) {
154  static const SG::ConstAccessor<char> IsHadronicTauAcc("IsHadronicTau");
155  if ( (bool)IsHadronicTauAcc(*trueTau) ) {
156  ATH_MSG_DEBUG("Tau is hadronic tau");
157  if(m_TauJetContainerName=="TauJets"){
158  m_oTauValidationPlotsNoCuts->m_oGeneralTauAllProngsPlots.fill(*tau, weight);
159  m_oTauValidationPlotsNoCuts->m_oNewCoreMatchedPlots.fill(*tau, weight);
160  m_oTauValidationPlotsNoCuts->m_oMatchedResolutionPlots.fill(*tau, *trueTau, weight);
161 
162  // Substructure/PFO histograms
163  m_oTauValidationPlotsNoCuts->m_oMatchedTauAllProngsPlots.fill(*tau, weight);
164  m_oTauValidationPlotsNoCuts->m_oMatchedTauEffPlots.fill(*tau, weight);
165  }
166  if ( nominal ) {
167  m_oTauValidationPlotsNominal->m_oMatchedGeneralNom.fill(*tau, weight);
168  m_oTauValidationPlotsNominal->m_oMatchedResolutionPlotsNom.fill(*tau, *trueTau, weight);
169  m_oTauValidationPlotsNominal->m_oMatchedTauEffPlotsNom.fill(*tau, weight);
170  m_oTauValidationPlotsNominal->m_oMatchedTauRecoTauPlotsNom.fill(*tau, weight);
171  m_oTauValidationPlotsNominal->m_oNewCoreMatchedPlotsNom.fill(*tau, weight);
172  }
173  if ( recProng == 1 ) {
174  if(m_TauJetContainerName=="TauJets"){
175  m_oTauValidationPlotsNoCuts->m_oHad1ProngPlots.fill(*tau, weight);
176  m_oTauValidationPlotsNoCuts->m_oMatchedTauEff1PPlots.fill(*tau, weight);
177  m_oTauValidationPlotsNoCuts->m_oMatchedResolution1PPlots.fill(*tau, *trueTau, weight);
178  }
179  if ( nominal ) {
180  m_oTauValidationPlotsNominal->m_oMatchedHad1ProngNom.fill(*tau, weight);
181  m_oTauValidationPlotsNominal->m_oMatchedTauEff1PPlotsNom.fill(*tau, weight);
182  m_oTauValidationPlotsNominal->m_oMatchedResolution1PPlotsNom.fill(*tau, *trueTau, weight);
183  }
184  }
185  else if ( recProng == 3 ) {
186  if(m_TauJetContainerName=="TauJets"){
187  m_oTauValidationPlotsNoCuts->m_oHad3ProngPlots.fill(*tau, weight);
188  m_oTauValidationPlotsNoCuts->m_oMatchedTauEff3PPlots.fill(*tau, weight);
189  m_oTauValidationPlotsNoCuts->m_oMatchedResolution3PPlots.fill(*tau, *trueTau, weight);
190  }
191  if ( nominal ) {
192  m_oTauValidationPlotsNominal->m_oMatchedHad3ProngNom.fill(*tau, weight);
193  m_oTauValidationPlotsNominal->m_oMatchedTauEff3PPlotsNom.fill(*tau, weight);
194  m_oTauValidationPlotsNominal->m_oMatchedResolution3PPlotsNom.fill(*tau, *trueTau, weight);
195  }
196  }
197 
198  xAOD::TauJetParameters::DecayMode trueMode = m_truthTool->getDecayMode(*trueTau);
199  if(m_TauJetContainerName=="TauJets") m_oTauValidationPlotsNoCuts->m_oMigrationPlots.fill(*tau, trueMode, weight);
200  if ( nominal ) {
201  m_oTauValidationPlotsNominal->m_oMigrationPlotsNom.fill(*tau, trueMode, weight);
202  }
203  }
204  } else if(trueTau->isElectron()) {
205  ATH_MSG_DEBUG("Tau is matched to an electron");
206  if(m_TauJetContainerName=="TauJets"){
207  m_oTauValidationPlotsNoCuts->m_oElMatchedParamPlots.fill(*tau, weight);
208  m_oTauValidationPlotsNoCuts->m_oElMatchedEVetoPlots.fill(*tau, weight);
209  }
210  if ( nominal ) {
211  m_oTauValidationPlotsNominal->m_oElMatchedParamPlotsNom.fill(*tau, weight);
212  m_oTauValidationPlotsNominal->m_oElMatchedEVetoPlotsNom.fill(*tau, weight);
213  if(recProng == 1) m_oTauValidationPlotsNominal->m_oElMatchedEff1PPlotsNom.fill(*tau, weight);
214  }
215 
216  } else if( MC::isSMQuark(trueTau) || MC::isGluon(trueTau) ){
217  ATH_MSG_DEBUG("Tau is matched to a jet");
218  if(m_TauJetContainerName=="TauJets"){
219  m_oTauValidationPlotsNoCuts->m_oFakeGeneralTauAllProngsPlots.fill(*tau, weight);
220  // Substructure/PFO histograms
221  m_oTauValidationPlotsNoCuts->m_oFakeTauAllProngsPlots.fill(*tau, weight);
222  m_oTauValidationPlotsNoCuts->m_oNewCoreFakePlots.fill(*tau, weight);
223  m_oTauValidationPlotsNoCuts->m_oFakeTauEffPlots.fill(*tau, weight);
224  }
225  if ( nominal ) {
226  m_oTauValidationPlotsNominal->m_oFakeGeneralNom.fill(*tau, weight);
227  m_oTauValidationPlotsNominal->m_oFakeTauEffPlotsNom.fill(*tau, weight);
228  m_oTauValidationPlotsNominal->m_oFakeTauRecoTauPlotsNom.fill(*tau, weight);
229  m_oTauValidationPlotsNominal->m_oNewCoreFakePlotsNom.fill(*tau, weight);
230  }
231  if ( recProng == 1 ) {
232  if(m_TauJetContainerName=="TauJets"){
233  m_oTauValidationPlotsNoCuts->m_oFakeHad1ProngPlots.fill(*tau, weight);
234  m_oTauValidationPlotsNoCuts->m_oFakeTauEff1PPlots.fill(*tau, weight);
235  }
236  if ( nominal ) {
237  m_oTauValidationPlotsNominal->m_oFakeHad1ProngNom.fill(*tau, weight);
238  m_oTauValidationPlotsNominal->m_oFakeTauEff1PPlotsNom.fill(*tau, weight);
239  }
240  }
241  if ( recProng == 3 ) {
242  if(m_TauJetContainerName=="TauJets"){
243  m_oTauValidationPlotsNoCuts->m_oFakeTauEff3PPlots.fill(*tau, weight);
244  m_oTauValidationPlotsNoCuts->m_oFakeHad3ProngPlots.fill(*tau, weight);
245  }
246 
247  if ( nominal ) {
248  m_oTauValidationPlotsNominal->m_oFakeHad3ProngNom.fill(*tau, weight);
249  m_oTauValidationPlotsNominal->m_oFakeTauEff3PPlotsNom.fill(*tau, weight);
250  }
251  }
252  }
253  }
254  else {
255  ATH_MSG_DEBUG("Tau is unmatched - consider it as fake");
256  if(m_TauJetContainerName=="TauJets"){
257  m_oTauValidationPlotsNoCuts->m_oFakeGeneralTauAllProngsPlots.fill(*tau, weight);
258  // Substructure/PFO histograms
259  m_oTauValidationPlotsNoCuts->m_oFakeTauAllProngsPlots.fill(*tau, weight);
260  m_oTauValidationPlotsNoCuts->m_oNewCoreFakePlots.fill(*tau, weight);
261  m_oTauValidationPlotsNoCuts->m_oFakeTauEffPlots.fill(*tau, weight);
262  }
263  if ( nominal ) {
264  m_oTauValidationPlotsNominal->m_oFakeGeneralNom.fill(*tau, weight);
265  m_oTauValidationPlotsNominal->m_oFakeTauEffPlotsNom.fill(*tau, weight);
266  m_oTauValidationPlotsNominal->m_oFakeTauRecoTauPlotsNom.fill(*tau, weight);
267  m_oTauValidationPlotsNominal->m_oNewCoreFakePlotsNom.fill(*tau, weight);
268  }
269  if ( recProng == 1 ) {
270  if(m_TauJetContainerName=="TauJets"){
271  m_oTauValidationPlotsNoCuts->m_oFakeHad1ProngPlots.fill(*tau, weight);
272  m_oTauValidationPlotsNoCuts->m_oFakeTauEff1PPlots.fill(*tau, weight);
273  }
274  if ( nominal ) {
275  m_oTauValidationPlotsNominal->m_oFakeHad1ProngNom.fill(*tau, weight);
276  m_oTauValidationPlotsNominal->m_oFakeTauEff1PPlotsNom.fill(*tau, weight);
277  }
278  }
279  if ( recProng == 3 ) {
280  if(m_TauJetContainerName=="TauJets"){
281  m_oTauValidationPlotsNoCuts->m_oFakeTauEff3PPlots.fill(*tau, weight);
282  m_oTauValidationPlotsNoCuts->m_oFakeHad3ProngPlots.fill(*tau, weight);
283  }
284  if ( nominal ) {
285  m_oTauValidationPlotsNominal->m_oFakeHad3ProngNom.fill(*tau, weight);
286  m_oTauValidationPlotsNominal->m_oFakeTauEff3PPlotsNom.fill(*tau, weight);
287  }
288  }
289  }
290  }
291 
292  ATH_CHECK( m_truthTool->lockDecorations (*taus) );
293  return StatusCode::SUCCESS;
294 }
295 
297 {
298  ATH_MSG_INFO ("Finalising hists " << name() << "...");
299  return StatusCode::SUCCESS;
300 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
PhysValTau::PhysValTau
PhysValTau(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
Definition: PhysValTau.cxx:26
PhysValTau::m_nomiTauSel
ToolHandle< TauAnalysisTools::ITauSelectionTool > m_nomiTauSel
Definition: PhysValTau.h:53
PhysValTau::m_isMC
Gaudi::Property< bool > m_isMC
Definition: PhysValTau.h:47
AthCheckMacros.h
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
ManagedMonitorToolBase
Provides functionality for users to implement and save histograms, ntuples, and summary data,...
Definition: ManagedMonitorToolBase.h:73
plotmaker.hist
hist
Definition: plotmaker.py:148
TruthParticleContainer.h
PhysValTau::m_TauJetContainerName
Gaudi::Property< std::string > m_TauJetContainerName
Definition: PhysValTau.h:46
PhysValTau::m_primTauSel
ToolHandle< TauAnalysisTools::ITauSelectionTool > m_primTauSel
Definition: PhysValTau.h:52
PhysValTau::m_oTauValidationPlotsNominal
std::unique_ptr< TauValidationPlotsNominal > m_oTauValidationPlotsNominal
Definition: PhysValTau.h:57
PhysValTau::m_oTauValidationPlotsNoCuts
std::unique_ptr< TauValidationPlotsNoCuts > m_oTauValidationPlotsNoCuts
Definition: PhysValTau.h:58
SG::ConstAccessor< char >
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
isSMQuark
bool isSMQuark(const T &p)
Definition: AtlasPID.h:169
isGluon
bool isGluon(const T &p)
Definition: AtlasPID.h:370
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:190
PhysValTau.h
xAOD::TauJetParameters::DecayMode
DecayMode
Definition: TauDefs.h:385
AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
ManagedMonitorToolBase::initialize
virtual StatusCode initialize()
Definition: ManagedMonitorToolBase.cxx:616
ElectronContainer.h
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
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
TauValidationPlotsNoCuts
Definition: TauValidationPlotsNoCuts.h:23
TauJetContainer.h
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
PhysValTau::initialize
virtual StatusCode initialize()
Definition: PhysValTau.cxx:34
TauValidationPlotsNominal
Definition: TauValidationPlotsNominal.h:23
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
PhysValTau::m_truthTool
ToolHandle< TauAnalysisTools::ITauTruthMatchingTool > m_truthTool
Definition: PhysValTau.h:50
JetContainer.h
ManagedMonitorToolBase::all
@ all
Definition: ManagedMonitorToolBase.h:115
ManagedMonitorToolBase::m_detailLevel
unsigned int m_detailLevel
Definition: ManagedMonitorToolBase.h:836
ConstAccessor.h
Helper class to provide constant type-safe access to aux data.
PhysValTau::bookHistograms
virtual StatusCode bookHistograms()
An inheriting class should either override this function or bookHists().
Definition: PhysValTau.cxx:49
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
xAOD::EventInfo_v1::beamSpotWeight
float beamSpotWeight() const
Weight for beam spot size reweighting.
Definition: EventInfo_v1.cxx:970
PhysValTau::procHistograms
virtual StatusCode procHistograms()
An inheriting class should either override this function or finalHists().
Definition: PhysValTau.cxx:296
ManagedMonitorToolBase::regHist
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 ...
Definition: ManagedMonitorToolBase.cxx:1344
HepMCHelpers.h
PhysValTau::fillHistograms
virtual StatusCode fillHistograms()
An inheriting class should either override this function or fillHists().
Definition: PhysValTau.cxx:80