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