ATLAS Offline Software
PhysValTau.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 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  m_truthTool("TauAnalysisTools::TauTruthMatchingTool/TauTruthMatchingTool", this),
31  m_primTauSel("TauAnalysisTools::TauSelectionTool/PrimitiveTauSelectionTool", this),
32  m_nomiTauSel("TauAnalysisTools::TauSelectionTool/NominalTauSelectionTool", this)
33 {
34  declareProperty("TauContainerName", m_TauJetContainerName = "TauJets");
35  declareProperty("TruthParticleContainerName", m_TruthParticleContainerName = "TruthParticles");
36  declareProperty("isMC", m_isMC = false);
37  declareProperty("TauTruthMatchingTool", m_truthTool);
38  declareProperty("PrimitiveTauSelectionTool", m_primTauSel);
39  declareProperty("NominalTauSelectionTool", m_nomiTauSel);
40 }
41 
42 
44 {
45  ATH_MSG_INFO ("Initializing " << name() << "...");
47 
48  if ( m_isMC ) {
49  ATH_CHECK(m_truthTool.retrieve());
50  }
51  // selections are configured in PhysicsValidation job options
52  ATH_CHECK(m_primTauSel.retrieve());
53  ATH_CHECK(m_nomiTauSel.retrieve());
54 
55  return StatusCode::SUCCESS;
56 }
57 
59 {
60  ATH_MSG_INFO ("Booking hists " << name() << "...");
61 
62  // Physics validation plots are level 10
63  m_oTauValidationPlots.reset(new TauValidationPlots(0,"Tau/" /* + m_TauJetContainerName*/, m_TauJetContainerName));
64  m_oTauValidationPlots->setDetailLevel(100);
65  m_oTauValidationPlots->initialize();
66  std::vector<HistData> hists = m_oTauValidationPlots->retrieveBookedHistograms();
67  ATH_MSG_INFO ("Filling n of hists " << hists.size() << " ");
68  for (const auto& hist : hists) {
69  ATH_CHECK(regHist(hist.first,hist.second,all));
70  }
71 
72  return StatusCode::SUCCESS;
73 }
74 
76 {
77  ATH_MSG_INFO ("Filling hists " << name() << "...");
78 
79  // Retrieve tau container
80  const xAOD::TauJetContainer* taus = nullptr;
82 
83  ATH_MSG_DEBUG("Number of taus: " << taus->size());
84 
85  // Retrieve truth container
86  const xAOD::TruthParticleContainer* truthParticles = nullptr;
87  if ( m_isMC ) {
89  }
90 
91  // Retrieve event info and beamSpotWeight
92  const xAOD::EventInfo* eventInfo = nullptr;
93  ATH_CHECK( evtStore()->retrieve(eventInfo, "EventInfo") );
94 
95  float weight = eventInfo->beamSpotWeight();
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  m_oTauValidationPlots->m_oRecoTauAllProngsPlots.fill(*tau, weight);
105  m_oTauValidationPlots->m_oNewCorePlots.fill(*tau, weight);
106  m_oTauValidationPlots->m_oRecTauEffPlots.fill(*tau, weight);
107  m_oTauValidationPlots->m_oRecoGeneralTauAllProngsPlots.fill(*tau, weight);
108  if ( nominal ) {
109  m_oTauValidationPlots->m_oRecoGeneralNom.fill(*tau, weight);
110  m_oTauValidationPlots->m_oRecTauEffPlotsNom.fill(*tau, weight);
111  m_oTauValidationPlots->m_oRecTauRecoTauPlotsNom.fill(*tau, weight);
112  m_oTauValidationPlots->m_oNewCoreRecTauPlotsNom.fill(*tau, weight);
113  }
114  int recProng = tau->nTracks();
115  if ( recProng == 1 ) {
116  m_oTauValidationPlots->m_oRecoHad1ProngPlots.fill(*tau, weight);
117  m_oTauValidationPlots->m_oRecTauEff1PPlots.fill(*tau, weight);
118  if ( nominal ) {
119  m_oTauValidationPlots->m_oRecoHad1ProngNom.fill(*tau, weight);
120  m_oTauValidationPlots->m_oRecTauEff1PPlotsNom.fill(*tau, weight);
121  }
122  }
123  else if ( recProng == 3 ) {
124  m_oTauValidationPlots->m_oRecoHad3ProngPlots.fill(*tau, weight);
125  m_oTauValidationPlots->m_oRecTauEff3PPlots.fill(*tau, weight);
126  if ( nominal ) {
127  m_oTauValidationPlots->m_oRecoHad3ProngNom.fill(*tau, weight);
128  m_oTauValidationPlots->m_oRecTauEff3PPlotsNom.fill(*tau, weight);
129  }
130  }
131 
132  // Don't fill truth and fake histograms if we are running on data.
133  if ( !m_isMC ) continue;
134 
135  ATH_MSG_DEBUG("Trying to truth-match tau");
136  auto trueTau = m_truthTool->getTruth(*tau);
137 
138  // Fill truth and fake histograms
139  static const SG::ConstAccessor<char> IsTruthMatchedAcc("IsTruthMatched");
140  if ( (bool)IsTruthMatchedAcc(*tau) ) {
141  ATH_MSG_DEBUG("Tau is truth-matched");
142  if ( trueTau->isTau() ) {
143  static const SG::ConstAccessor<char> IsHadronicTauAcc("IsHadronicTau");
144  if ( (bool)IsHadronicTauAcc(*trueTau) ) {
145  ATH_MSG_DEBUG("Tau is hadronic tau");
146  m_oTauValidationPlots->m_oGeneralTauAllProngsPlots.fill(*tau, weight);
147  m_oTauValidationPlots->m_oNewCoreMatchedPlots.fill(*tau, weight);
148  // Substructure/PFO histograms
149  m_oTauValidationPlots->m_oMatchedTauAllProngsPlots.fill(*tau, weight);
150  m_oTauValidationPlots->m_oMatchedTauEffPlots.fill(*tau, weight);
151  if ( nominal ) {
152  m_oTauValidationPlots->m_oMatchedGeneralNom.fill(*tau, weight);
153  m_oTauValidationPlots->m_oMatchedTauEffPlotsNom.fill(*tau, weight);
154  m_oTauValidationPlots->m_oMatchedTauRecoTauPlotsNom.fill(*tau, weight);
155  m_oTauValidationPlots->m_oNewCoreMatchedPlotsNom.fill(*tau, weight);
156  }
157  if ( recProng == 1 ) {
158  m_oTauValidationPlots->m_oHad1ProngPlots.fill(*tau, weight);
159  m_oTauValidationPlots->m_oMatchedTauEff1PPlots.fill(*tau, weight);
160  if ( nominal ) {
161  m_oTauValidationPlots->m_oMatchedHad1ProngNom.fill(*tau, weight);
162  m_oTauValidationPlots->m_oMatchedTauEff1PPlotsNom.fill(*tau, weight);
163  }
164  }
165  else if ( recProng == 3 ) {
166  m_oTauValidationPlots->m_oHad3ProngPlots.fill(*tau, weight);
167  m_oTauValidationPlots->m_oMatchedTauEff3PPlots.fill(*tau, weight);
168  if ( nominal ) {
169  m_oTauValidationPlots->m_oMatchedHad3ProngNom.fill(*tau, weight);
170  m_oTauValidationPlots->m_oMatchedTauEff3PPlotsNom.fill(*tau, weight);
171  }
172  }
173 
174  xAOD::TauJetParameters::DecayMode trueMode = m_truthTool->getDecayMode(*trueTau);
175  m_oTauValidationPlots->m_oMigrationPlots.fill(*tau, trueMode, weight);
176  if ( nominal ) {
177  m_oTauValidationPlots->m_oMigrationPlotsNom.fill(*tau, trueMode, weight);
178  }
179  }
180  } else if(trueTau->isElectron()) {
181  ATH_MSG_DEBUG("Tau is matched to an electron");
182  m_oTauValidationPlots->m_oElMatchedParamPlots.fill(*tau, weight);
183  m_oTauValidationPlots->m_oElMatchedEVetoPlots.fill(*tau, weight);
184  } else if( std::abs(trueTau->pdgId()) < 7 || trueTau->pdgId() == 21){
185  ATH_MSG_DEBUG("Tau is matched to a jet");
186  m_oTauValidationPlots->m_oFakeGeneralTauAllProngsPlots.fill(*tau, weight);
187  // Substructure/PFO histograms
188  m_oTauValidationPlots->m_oFakeTauAllProngsPlots.fill(*tau, weight);
189  m_oTauValidationPlots->m_oNewCoreFakePlots.fill(*tau, weight);
190  m_oTauValidationPlots->m_oFakeTauEffPlots.fill(*tau, weight);
191  if ( nominal ) {
192  m_oTauValidationPlots->m_oFakeGeneralNom.fill(*tau, weight);
193  m_oTauValidationPlots->m_oFakeTauEffPlotsNom.fill(*tau, weight);
194  m_oTauValidationPlots->m_oFakeTauRecoTauPlotsNom.fill(*tau, weight);
195  m_oTauValidationPlots->m_oNewCoreFakePlotsNom.fill(*tau, weight);
196  }
197  if ( recProng == 1 ) {
198  m_oTauValidationPlots->m_oFakeHad1ProngPlots.fill(*tau, weight);
199  m_oTauValidationPlots->m_oFakeTauEff1PPlots.fill(*tau, weight);
200  if ( nominal ) {
201  m_oTauValidationPlots->m_oFakeHad1ProngNom.fill(*tau, weight);
202  m_oTauValidationPlots->m_oFakeTauEff1PPlotsNom.fill(*tau, weight);
203  }
204  }
205  if ( recProng == 3 ) {
206  m_oTauValidationPlots->m_oFakeTauEff3PPlots.fill(*tau, weight);
207  m_oTauValidationPlots->m_oFakeHad3ProngPlots.fill(*tau, weight);
208  if ( nominal ) {
209  m_oTauValidationPlots->m_oFakeHad3ProngNom.fill(*tau, weight);
210  m_oTauValidationPlots->m_oFakeTauEff3PPlotsNom.fill(*tau, weight);
211  }
212  }
213  }
214  }
215  else {
216  ATH_MSG_DEBUG("Tau is unmatched - consider it as fake");
217  m_oTauValidationPlots->m_oFakeGeneralTauAllProngsPlots.fill(*tau, weight);
218  // Substructure/PFO histograms
219  m_oTauValidationPlots->m_oFakeTauAllProngsPlots.fill(*tau, weight);
220  m_oTauValidationPlots->m_oNewCoreFakePlots.fill(*tau, weight);
221  m_oTauValidationPlots->m_oFakeTauEffPlots.fill(*tau, weight);
222  if ( nominal ) {
223  m_oTauValidationPlots->m_oFakeGeneralNom.fill(*tau, weight);
224  m_oTauValidationPlots->m_oFakeTauEffPlotsNom.fill(*tau, weight);
225  m_oTauValidationPlots->m_oFakeTauRecoTauPlotsNom.fill(*tau, weight);
226  m_oTauValidationPlots->m_oNewCoreFakePlotsNom.fill(*tau, weight);
227  }
228  if ( recProng == 1 ) {
229  m_oTauValidationPlots->m_oFakeHad1ProngPlots.fill(*tau, weight);
230  m_oTauValidationPlots->m_oFakeTauEff1PPlots.fill(*tau, weight);
231  if ( nominal ) {
232  m_oTauValidationPlots->m_oFakeHad1ProngNom.fill(*tau, weight);
233  m_oTauValidationPlots->m_oFakeTauEff1PPlotsNom.fill(*tau, weight);
234  }
235  }
236  if ( recProng == 3 ) {
237  m_oTauValidationPlots->m_oFakeTauEff3PPlots.fill(*tau, weight);
238  m_oTauValidationPlots->m_oFakeHad3ProngPlots.fill(*tau, weight);
239  if ( nominal ) {
240  m_oTauValidationPlots->m_oFakeHad3ProngNom.fill(*tau, weight);
241  m_oTauValidationPlots->m_oFakeTauEff3PPlotsNom.fill(*tau, weight);
242  }
243  }
244  }
245  }
246 
247  ATH_CHECK( m_truthTool->lockDecorations (*taus) );
248  return StatusCode::SUCCESS;
249 }
250 
252 {
253  ATH_MSG_INFO ("Finalising hists " << name() << "...");
254  return StatusCode::SUCCESS;
255 }
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:59
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
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
plotmaker.hist
hist
Definition: plotmaker.py:148
TruthParticleContainer.h
PhysValTau::m_primTauSel
ToolHandle< TauAnalysisTools::ITauSelectionTool > m_primTauSel
Definition: PhysValTau.h:58
SG::ConstAccessor< char >
PhysValTau::m_oTauValidationPlots
std::unique_ptr< TauValidationPlots > m_oTauValidationPlots
Definition: PhysValTau.h:63
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:189
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:617
ElectronContainer.h
PhysValTau::m_TruthParticleContainerName
std::string m_TruthParticleContainerName
Definition: PhysValTau.h:46
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
PhysValTau::m_isMC
bool m_isMC
Are we running over MC data?
Definition: PhysValTau.h:48
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
PhysValTau::m_TauJetContainerName
std::string m_TauJetContainerName
Definition: PhysValTau.h:45
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
PhysValTau::initialize
virtual StatusCode initialize()
Definition: PhysValTau.cxx:43
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:56
JetContainer.h
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
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:58
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:251
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:1346
HepMCHelpers.h
PhysValTau::fillHistograms
virtual StatusCode fillHistograms()
An inheriting class should either override this function or fillHists().
Definition: PhysValTau.cxx:75