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 // FrameWork includes
13 #include "GaudiKernel/IToolSvc.h"
15 
16 
17 PhysValTau::PhysValTau(const std::string& type,
18  const std::string& name,
19  const IInterface* 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;
77  if(evtStore()->contains<xAOD::TauJetContainer>(m_TauJetContainerName)){
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  float weight = eventInfo->beamSpotWeight();
92 
93  // Loop through recoonstructed tau container
94  for (auto tau : *taus) {
95  if ( m_detailLevel < 10 ) continue;
96  if ( !static_cast<bool>(m_primTauSel->accept(*tau)) ) continue;
97  bool nominal = static_cast<bool>(m_nomiTauSel->accept(*tau));
98 
99  // fill histograms for reconstructed taus
100  if(m_TauJetContainerName=="TauJets"){
101  m_oTauValidationPlotsNoCuts->m_oRecoTauAllProngsPlots.fill(*tau, weight);
102  m_oTauValidationPlotsNoCuts->m_oNewCorePlots.fill(*tau, weight);
103  m_oTauValidationPlotsNoCuts->m_oRecTauEffPlots.fill(*tau, weight);
104  m_oTauValidationPlotsNoCuts->m_oRecoGeneralTauAllProngsPlots.fill(*tau, weight);
105  }
106  if ( nominal ) {
107  m_oTauValidationPlotsNominal->m_oRecoGeneralNom.fill(*tau, weight);
108  m_oTauValidationPlotsNominal->m_oRecTauEffPlotsNom.fill(*tau, weight);
109  m_oTauValidationPlotsNominal->m_oRecTauRecoTauPlotsNom.fill(*tau, weight);
110  m_oTauValidationPlotsNominal->m_oNewCoreRecTauPlotsNom.fill(*tau, weight);
111  }
112  int recProng = tau->nTracks();
113  if ( recProng == 1 ) {
114  if(m_TauJetContainerName=="TauJets"){
115  m_oTauValidationPlotsNoCuts->m_oRecoHad1ProngPlots.fill(*tau, weight);
116  m_oTauValidationPlotsNoCuts->m_oRecTauEff1PPlots.fill(*tau, weight);
117  }
118  if ( nominal ) {
119  m_oTauValidationPlotsNominal->m_oRecoHad1ProngNom.fill(*tau, weight);
120  m_oTauValidationPlotsNominal->m_oRecTauEff1PPlotsNom.fill(*tau, weight);
121  }
122  }
123  else if ( recProng == 3 ) {
124  if(m_TauJetContainerName=="TauJets"){
125  m_oTauValidationPlotsNoCuts->m_oRecoHad3ProngPlots.fill(*tau, weight);
126  m_oTauValidationPlotsNoCuts->m_oRecTauEff3PPlots.fill(*tau, weight);
127  }
128  if ( nominal ) {
129  m_oTauValidationPlotsNominal->m_oRecoHad3ProngNom.fill(*tau, weight);
130  m_oTauValidationPlotsNominal->m_oRecTauEff3PPlotsNom.fill(*tau, weight);
131  }
132  }
133 
134  // Don't fill truth and fake histograms if we are running on data.
135  if ( !m_isMC ) continue;
136 
137  ATH_MSG_DEBUG("Trying to truth-match tau");
138  auto trueTau = m_truthTool->getTruth(*tau);
139 
140  // Fill truth and fake histograms
141  static const SG::ConstAccessor<char> IsTruthMatchedAcc("IsTruthMatched");
142  if ( (bool)IsTruthMatchedAcc(*tau) && (!(MC::isSMQuark(trueTau) || MC::isGluon(trueTau))) ) {
143  ATH_MSG_DEBUG("Tau is truth-matched and not with a quark or a jet");
144  if ( trueTau->isTau() ) {
145  static const SG::ConstAccessor<char> IsHadronicTauAcc("IsHadronicTau");
146  if ( (bool)IsHadronicTauAcc(*trueTau) ) {
147  ATH_MSG_DEBUG("Tau is hadronic tau");
148  if(m_TauJetContainerName=="TauJets"){
149  m_oTauValidationPlotsNoCuts->m_oGeneralTauAllProngsPlots.fill(*tau, weight);
150  m_oTauValidationPlotsNoCuts->m_oNewCoreMatchedPlots.fill(*tau, weight);
151  m_oTauValidationPlotsNoCuts->m_oMatchedResolutionPlots.fill(*tau, *trueTau, weight);
152 
153  // Substructure/PFO histograms
154  m_oTauValidationPlotsNoCuts->m_oMatchedTauAllProngsPlots.fill(*tau, weight);
155  m_oTauValidationPlotsNoCuts->m_oMatchedTauEffPlots.fill(*tau, weight);
156  }
157  if ( nominal ) {
158  m_oTauValidationPlotsNominal->m_oMatchedGeneralNom.fill(*tau, weight);
159  m_oTauValidationPlotsNominal->m_oMatchedResolutionPlotsNom.fill(*tau, *trueTau, weight);
160  m_oTauValidationPlotsNominal->m_oMatchedTauEffPlotsNom.fill(*tau, weight);
161  m_oTauValidationPlotsNominal->m_oMatchedTauRecoTauPlotsNom.fill(*tau, weight);
162  m_oTauValidationPlotsNominal->m_oNewCoreMatchedPlotsNom.fill(*tau, weight);
163  }
164  if ( recProng == 1 ) {
165  if(m_TauJetContainerName=="TauJets"){
166  m_oTauValidationPlotsNoCuts->m_oHad1ProngPlots.fill(*tau, weight);
167  m_oTauValidationPlotsNoCuts->m_oMatchedTauEff1PPlots.fill(*tau, weight);
168  m_oTauValidationPlotsNoCuts->m_oMatchedResolution1PPlots.fill(*tau, *trueTau, weight);
169  }
170  if ( nominal ) {
171  m_oTauValidationPlotsNominal->m_oMatchedHad1ProngNom.fill(*tau, weight);
172  m_oTauValidationPlotsNominal->m_oMatchedTauEff1PPlotsNom.fill(*tau, weight);
173  m_oTauValidationPlotsNominal->m_oMatchedResolution1PPlotsNom.fill(*tau, *trueTau, weight);
174  }
175  }
176  else if ( recProng == 3 ) {
177  if(m_TauJetContainerName=="TauJets"){
178  m_oTauValidationPlotsNoCuts->m_oHad3ProngPlots.fill(*tau, weight);
179  m_oTauValidationPlotsNoCuts->m_oMatchedTauEff3PPlots.fill(*tau, weight);
180  m_oTauValidationPlotsNoCuts->m_oMatchedResolution3PPlots.fill(*tau, *trueTau, weight);
181  }
182  if ( nominal ) {
183  m_oTauValidationPlotsNominal->m_oMatchedHad3ProngNom.fill(*tau, weight);
184  m_oTauValidationPlotsNominal->m_oMatchedTauEff3PPlotsNom.fill(*tau, weight);
185  m_oTauValidationPlotsNominal->m_oMatchedResolution3PPlotsNom.fill(*tau, *trueTau, weight);
186  }
187  }
188 
189  xAOD::TauJetParameters::DecayMode trueMode = m_truthTool->getDecayMode(*trueTau);
190  if(m_TauJetContainerName=="TauJets") m_oTauValidationPlotsNoCuts->m_oMigrationPlots.fill(*tau, trueMode, weight);
191  if ( nominal ) {
192  m_oTauValidationPlotsNominal->m_oMigrationPlotsNom.fill(*tau, trueMode, weight);
193  }
194  }
195  } else if(trueTau->isElectron()) {
196  ATH_MSG_DEBUG("Tau is matched to an electron");
197  if(m_TauJetContainerName=="TauJets"){
198  m_oTauValidationPlotsNoCuts->m_oElMatchedParamPlots.fill(*tau, weight);
199  m_oTauValidationPlotsNoCuts->m_oElMatchedEVetoPlots.fill(*tau, weight);
200  }
201  if ( nominal ) {
202  m_oTauValidationPlotsNominal->m_oElMatchedParamPlotsNom.fill(*tau, weight);
203  m_oTauValidationPlotsNominal->m_oElMatchedEVetoPlotsNom.fill(*tau, weight);
204  if(recProng == 1) m_oTauValidationPlotsNominal->m_oElMatchedEff1PPlotsNom.fill(*tau, weight);
205  }
206  }
207  }
208  else {
209  ATH_MSG_DEBUG("Tau is matched to a jet or Tau is unmatched - consider it as fake");
210  if(m_TauJetContainerName=="TauJets"){
211  m_oTauValidationPlotsNoCuts->m_oFakeGeneralTauAllProngsPlots.fill(*tau, weight);
212  // Substructure/PFO histograms
213  m_oTauValidationPlotsNoCuts->m_oFakeTauAllProngsPlots.fill(*tau, weight);
214  m_oTauValidationPlotsNoCuts->m_oNewCoreFakePlots.fill(*tau, weight);
215  m_oTauValidationPlotsNoCuts->m_oFakeTauEffPlots.fill(*tau, weight);
216  }
217  if ( nominal ) {
218  m_oTauValidationPlotsNominal->m_oFakeGeneralNom.fill(*tau, weight);
219  m_oTauValidationPlotsNominal->m_oFakeTauEffPlotsNom.fill(*tau, weight);
220  m_oTauValidationPlotsNominal->m_oFakeTauRecoTauPlotsNom.fill(*tau, weight);
221  m_oTauValidationPlotsNominal->m_oNewCoreFakePlotsNom.fill(*tau, weight);
222  }
223  if ( recProng == 1 ) {
224  if(m_TauJetContainerName=="TauJets"){
225  m_oTauValidationPlotsNoCuts->m_oFakeHad1ProngPlots.fill(*tau, weight);
226  m_oTauValidationPlotsNoCuts->m_oFakeTauEff1PPlots.fill(*tau, weight);
227  }
228  if ( nominal ) {
229  m_oTauValidationPlotsNominal->m_oFakeHad1ProngNom.fill(*tau, weight);
230  m_oTauValidationPlotsNominal->m_oFakeTauEff1PPlotsNom.fill(*tau, weight);
231  }
232  }
233  if ( recProng == 3 ) {
234  if(m_TauJetContainerName=="TauJets"){
235  m_oTauValidationPlotsNoCuts->m_oFakeTauEff3PPlots.fill(*tau, weight);
236  m_oTauValidationPlotsNoCuts->m_oFakeHad3ProngPlots.fill(*tau, weight);
237  }
238  if ( nominal ) {
239  m_oTauValidationPlotsNominal->m_oFakeHad3ProngNom.fill(*tau, weight);
240  m_oTauValidationPlotsNominal->m_oFakeTauEff3PPlotsNom.fill(*tau, weight);
241  }
242  }
243  }
244  }
245 
246  ATH_CHECK( m_truthTool->lockDecorations (*taus) );
247  return StatusCode::SUCCESS;
248 }
249 
251 {
252  ATH_MSG_INFO ("Finalising hists " << name() << "...");
253  return StatusCode::SUCCESS;
254 }
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:17
PhysValTau::m_nomiTauSel
ToolHandle< TauAnalysisTools::ITauSelectionTool > m_nomiTauSel
Definition: PhysValTau.h:51
PhysValTau::m_isMC
Gaudi::Property< bool > m_isMC
Definition: PhysValTau.h:45
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
PhysValTau::m_TauJetContainerName
Gaudi::Property< std::string > m_TauJetContainerName
Definition: PhysValTau.h:44
PhysValTau::m_primTauSel
ToolHandle< TauAnalysisTools::ITauSelectionTool > m_primTauSel
Definition: PhysValTau.h:50
PhysValTau::m_oTauValidationPlotsNominal
std::unique_ptr< TauValidationPlotsNominal > m_oTauValidationPlotsNominal
Definition: PhysValTau.h:55
PhysValTau::m_oTauValidationPlotsNoCuts
std::unique_ptr< TauValidationPlotsNoCuts > m_oTauValidationPlotsNoCuts
Definition: PhysValTau.h:56
SG::ConstAccessor< char >
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
isSMQuark
bool isSMQuark(const T &p)
Definition: AtlasPID.h:172
isGluon
bool isGluon(const T &p)
Definition: AtlasPID.h:373
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
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:21
DataVector
Derived DataVector<T>.
Definition: DataVector.h:795
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
PhysValTau::initialize
virtual StatusCode initialize()
Definition: PhysValTau.cxx:25
TauValidationPlotsNominal
Definition: TauValidationPlotsNominal.h:20
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:48
ManagedMonitorToolBase::all
@ all
Definition: ManagedMonitorToolBase.h:115
ManagedMonitorToolBase::m_detailLevel
unsigned int m_detailLevel
Definition: ManagedMonitorToolBase.h:836
PhysValTau::bookHistograms
virtual StatusCode bookHistograms()
An inheriting class should either override this function or bookHists().
Definition: PhysValTau.cxx:40
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:250
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:71