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_oTauValidationPlots->setDetailLevel(100);
56  m_oTauValidationPlots->initialize();
57  std::vector<HistData> hists = m_oTauValidationPlots->retrieveBookedHistograms();
58  ATH_MSG_INFO ("Filling n of hists " << hists.size() << " ");
59  for (const auto& hist : hists) {
60  ATH_CHECK(regHist(hist.first,hist.second,all));
61  }
62 
63  return StatusCode::SUCCESS;
64 }
65 
67 {
68  ATH_MSG_DEBUG ("Filling hists " << name() << "...");
69 
70  // Retrieve tau container
71  const xAOD::TauJetContainer* taus = nullptr;
72  if(evtStore()->contains<xAOD::TauJetContainer>(m_TauJetContainerName)){
74  } else {
75  ATH_MSG_INFO("Input collection " << m_TauJetContainerName << " not found. Skip the monitoring ..");
76  return StatusCode::SUCCESS;
77  }
78 
79  ATH_MSG_DEBUG("Number of taus: " << taus->size());
80 
81 
82  // Retrieve event info and beamSpotWeight
83  const xAOD::EventInfo* eventInfo = nullptr;
84  ATH_CHECK( evtStore()->retrieve(eventInfo, "EventInfo") );
85 
86  float weight = eventInfo->beamSpotWeight();
87 
88  // Loop through recoonstructed tau container
89  for (auto tau : *taus) {
90  if ( m_detailLevel < 10 ) continue;
91  if ( !static_cast<bool>(m_primTauSel->accept(*tau)) ) continue;
92  bool nominal = static_cast<bool>(m_nomiTauSel->accept(*tau));
93 
94  // fill histograms for reconstructed taus
95  m_oTauValidationPlots->m_oRecoTauAllProngsPlots.fill(*tau, weight);
96  m_oTauValidationPlots->m_oNewCorePlots.fill(*tau, weight);
97  m_oTauValidationPlots->m_oRecTauEffPlots.fill(*tau, weight);
98  m_oTauValidationPlots->m_oRecoGeneralTauAllProngsPlots.fill(*tau, weight);
99  if ( nominal ) {
100  m_oTauValidationPlots->m_oRecoGeneralNom.fill(*tau, weight);
101  m_oTauValidationPlots->m_oRecTauEffPlotsNom.fill(*tau, weight);
102  m_oTauValidationPlots->m_oRecTauRecoTauPlotsNom.fill(*tau, weight);
103  m_oTauValidationPlots->m_oNewCoreRecTauPlotsNom.fill(*tau, weight);
104  }
105  int recProng = tau->nTracks();
106  if ( recProng == 1 ) {
107  m_oTauValidationPlots->m_oRecoHad1ProngPlots.fill(*tau, weight);
108  m_oTauValidationPlots->m_oRecTauEff1PPlots.fill(*tau, weight);
109  if ( nominal ) {
110  m_oTauValidationPlots->m_oRecoHad1ProngNom.fill(*tau, weight);
111  m_oTauValidationPlots->m_oRecTauEff1PPlotsNom.fill(*tau, weight);
112  }
113  }
114  else if ( recProng == 3 ) {
115  m_oTauValidationPlots->m_oRecoHad3ProngPlots.fill(*tau, weight);
116  m_oTauValidationPlots->m_oRecTauEff3PPlots.fill(*tau, weight);
117  if ( nominal ) {
118  m_oTauValidationPlots->m_oRecoHad3ProngNom.fill(*tau, weight);
119  m_oTauValidationPlots->m_oRecTauEff3PPlotsNom.fill(*tau, weight);
120  }
121  }
122 
123  // Don't fill truth and fake histograms if we are running on data.
124  if ( !m_isMC ) continue;
125 
126  ATH_MSG_DEBUG("Trying to truth-match tau");
127  auto trueTau = m_truthTool->getTruth(*tau);
128 
129  // Fill truth and fake histograms
130  static const SG::ConstAccessor<char> IsTruthMatchedAcc("IsTruthMatched");
131  if ( (bool)IsTruthMatchedAcc(*tau) ) {
132  ATH_MSG_DEBUG("Tau is truth-matched");
133  if ( trueTau->isTau() ) {
134  static const SG::ConstAccessor<char> IsHadronicTauAcc("IsHadronicTau");
135  if ( (bool)IsHadronicTauAcc(*trueTau) ) {
136  ATH_MSG_DEBUG("Tau is hadronic tau");
137  m_oTauValidationPlots->m_oGeneralTauAllProngsPlots.fill(*tau, weight);
138  m_oTauValidationPlots->m_oNewCoreMatchedPlots.fill(*tau, weight);
139  m_oTauValidationPlots->m_oMatchedResolutionPlots.fill(*tau, *trueTau, weight);
140  // Substructure/PFO histograms
141  m_oTauValidationPlots->m_oMatchedTauAllProngsPlots.fill(*tau, weight);
142  m_oTauValidationPlots->m_oMatchedTauEffPlots.fill(*tau, weight);
143  if ( nominal ) {
144  m_oTauValidationPlots->m_oMatchedGeneralNom.fill(*tau, weight);
145  m_oTauValidationPlots->m_oMatchedResolutionPlotsNom.fill(*tau, *trueTau, weight);
146  m_oTauValidationPlots->m_oMatchedTauEffPlotsNom.fill(*tau, weight);
147  m_oTauValidationPlots->m_oMatchedTauRecoTauPlotsNom.fill(*tau, weight);
148  m_oTauValidationPlots->m_oNewCoreMatchedPlotsNom.fill(*tau, weight);
149  }
150  if ( recProng == 1 ) {
151  m_oTauValidationPlots->m_oHad1ProngPlots.fill(*tau, weight);
152  m_oTauValidationPlots->m_oMatchedTauEff1PPlots.fill(*tau, weight);
153  m_oTauValidationPlots->m_oMatchedResolution1PPlots.fill(*tau, *trueTau, weight);
154  if ( nominal ) {
155  m_oTauValidationPlots->m_oMatchedHad1ProngNom.fill(*tau, weight);
156  m_oTauValidationPlots->m_oMatchedTauEff1PPlotsNom.fill(*tau, weight);
157  m_oTauValidationPlots->m_oMatchedResolution1PPlotsNom.fill(*tau, *trueTau, weight);
158  }
159  }
160  else if ( recProng == 3 ) {
161  m_oTauValidationPlots->m_oHad3ProngPlots.fill(*tau, weight);
162  m_oTauValidationPlots->m_oMatchedTauEff3PPlots.fill(*tau, weight);
163  m_oTauValidationPlots->m_oMatchedResolution3PPlots.fill(*tau, *trueTau, weight);
164  if ( nominal ) {
165  m_oTauValidationPlots->m_oMatchedHad3ProngNom.fill(*tau, weight);
166  m_oTauValidationPlots->m_oMatchedTauEff3PPlotsNom.fill(*tau, weight);
167  m_oTauValidationPlots->m_oMatchedResolution3PPlotsNom.fill(*tau, *trueTau, weight);
168  }
169  }
170 
171  xAOD::TauJetParameters::DecayMode trueMode = m_truthTool->getDecayMode(*trueTau);
172  m_oTauValidationPlots->m_oMigrationPlots.fill(*tau, trueMode, weight);
173  if ( nominal ) {
174  m_oTauValidationPlots->m_oMigrationPlotsNom.fill(*tau, trueMode, weight);
175  }
176  }
177  } else if(trueTau->isElectron()) {
178  ATH_MSG_DEBUG("Tau is matched to an electron");
179  m_oTauValidationPlots->m_oElMatchedParamPlots.fill(*tau, weight);
180  m_oTauValidationPlots->m_oElMatchedEVetoPlots.fill(*tau, weight);
181  if ( nominal ) {
182  m_oTauValidationPlots->m_oElMatchedParamPlotsNom.fill(*tau, weight);
183  m_oTauValidationPlots->m_oElMatchedEVetoPlotsNom.fill(*tau, weight);
184  if(recProng == 1) m_oTauValidationPlots->m_oElMatchedEff1PPlotsNom.fill(*tau, weight);
185  }
186 
187  } else if( MC::isSMQuark(trueTau) || MC::isGluon(trueTau) ){
188  ATH_MSG_DEBUG("Tau is matched to a jet");
189  m_oTauValidationPlots->m_oFakeGeneralTauAllProngsPlots.fill(*tau, weight);
190  // Substructure/PFO histograms
191  m_oTauValidationPlots->m_oFakeTauAllProngsPlots.fill(*tau, weight);
192  m_oTauValidationPlots->m_oNewCoreFakePlots.fill(*tau, weight);
193  m_oTauValidationPlots->m_oFakeTauEffPlots.fill(*tau, weight);
194  if ( nominal ) {
195  m_oTauValidationPlots->m_oFakeGeneralNom.fill(*tau, weight);
196  m_oTauValidationPlots->m_oFakeTauEffPlotsNom.fill(*tau, weight);
197  m_oTauValidationPlots->m_oFakeTauRecoTauPlotsNom.fill(*tau, weight);
198  m_oTauValidationPlots->m_oNewCoreFakePlotsNom.fill(*tau, weight);
199  }
200  if ( recProng == 1 ) {
201  m_oTauValidationPlots->m_oFakeHad1ProngPlots.fill(*tau, weight);
202  m_oTauValidationPlots->m_oFakeTauEff1PPlots.fill(*tau, weight);
203  if ( nominal ) {
204  m_oTauValidationPlots->m_oFakeHad1ProngNom.fill(*tau, weight);
205  m_oTauValidationPlots->m_oFakeTauEff1PPlotsNom.fill(*tau, weight);
206  }
207  }
208  if ( recProng == 3 ) {
209  m_oTauValidationPlots->m_oFakeTauEff3PPlots.fill(*tau, weight);
210  m_oTauValidationPlots->m_oFakeHad3ProngPlots.fill(*tau, weight);
211  if ( nominal ) {
212  m_oTauValidationPlots->m_oFakeHad3ProngNom.fill(*tau, weight);
213  m_oTauValidationPlots->m_oFakeTauEff3PPlotsNom.fill(*tau, weight);
214  }
215  }
216  }
217  }
218  else {
219  ATH_MSG_DEBUG("Tau is unmatched - consider it as fake");
220  m_oTauValidationPlots->m_oFakeGeneralTauAllProngsPlots.fill(*tau, weight);
221  // Substructure/PFO histograms
222  m_oTauValidationPlots->m_oFakeTauAllProngsPlots.fill(*tau, weight);
223  m_oTauValidationPlots->m_oNewCoreFakePlots.fill(*tau, weight);
224  m_oTauValidationPlots->m_oFakeTauEffPlots.fill(*tau, weight);
225  if ( nominal ) {
226  m_oTauValidationPlots->m_oFakeGeneralNom.fill(*tau, weight);
227  m_oTauValidationPlots->m_oFakeTauEffPlotsNom.fill(*tau, weight);
228  m_oTauValidationPlots->m_oFakeTauRecoTauPlotsNom.fill(*tau, weight);
229  m_oTauValidationPlots->m_oNewCoreFakePlotsNom.fill(*tau, weight);
230  }
231  if ( recProng == 1 ) {
232  m_oTauValidationPlots->m_oFakeHad1ProngPlots.fill(*tau, weight);
233  m_oTauValidationPlots->m_oFakeTauEff1PPlots.fill(*tau, weight);
234  if ( nominal ) {
235  m_oTauValidationPlots->m_oFakeHad1ProngNom.fill(*tau, weight);
236  m_oTauValidationPlots->m_oFakeTauEff1PPlotsNom.fill(*tau, weight);
237  }
238  }
239  if ( recProng == 3 ) {
240  m_oTauValidationPlots->m_oFakeTauEff3PPlots.fill(*tau, weight);
241  m_oTauValidationPlots->m_oFakeHad3ProngPlots.fill(*tau, weight);
242  if ( nominal ) {
243  m_oTauValidationPlots->m_oFakeHad3ProngNom.fill(*tau, weight);
244  m_oTauValidationPlots->m_oFakeTauEff3PPlotsNom.fill(*tau, weight);
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 }
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:52
PhysValTau::m_isMC
Gaudi::Property< bool > m_isMC
Definition: PhysValTau.h:46
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:45
PhysValTau::m_primTauSel
ToolHandle< TauAnalysisTools::ITauSelectionTool > m_primTauSel
Definition: PhysValTau.h:51
SG::ConstAccessor< char >
PhysValTau::m_oTauValidationPlots
std::unique_ptr< TauValidationPlots > m_oTauValidationPlots
Definition: PhysValTau.h:56
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
MakeTH3DFromTH2Ds.hists
hists
Definition: MakeTH3DFromTH2Ds.py:72
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
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
TauValidationPlots
Definition: TauValidationPlots.h:23
PhysValTau::m_truthTool
ToolHandle< TauAnalysisTools::ITauTruthMatchingTool > m_truthTool
Definition: PhysValTau.h:49
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:254
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:66