ATLAS Offline Software
TauCommonCalcVars.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 //-----------------------------------------------------------------------------
6 // file: TauCommonCalcVars.cxx
7 // package: Reconstruction/tauRec
8 // authors: Stan Lai
9 // date: 2008-05-18
10 //
11 // This class calculates tau variables after core seed reconstruction
12 //-----------------------------------------------------------------------------
14 #include <vector>
15 
16 //-----------------------------------------------------------------------------
17 // Constructor
18 //-----------------------------------------------------------------------------
19 
22  //if TauTrackClassifier is not run, wide&passTrkSelector==classifiedIsolation==modifiedIsolationTrack
24 }
25 
26 //-----------------------------------------------------------------------------
27 // Destructor
28 //-----------------------------------------------------------------------------
29 
31 }
32 
33 //-----------------------------------------------------------------------------
34 // Execution
35 //-----------------------------------------------------------------------------
37 
39  // Calculate variables that are always valid
41 
42  //init some vars
44 
45  // Leading track pT and et/pt(lead track)
46  if (pTau.nTracks() > 0) {
47  pTau.setDetail( xAOD::TauJetParameters::leadTrkPt, static_cast<float>( pTau.track(0)->pt() ) );
48 
49  float emscale_ptEM = 0.;
50  float emscale_ptHad = 0.;
51 
52  if ( !pTau.detail( xAOD::TauJetParameters::etEMAtEMScale, emscale_ptEM ) )
53  {
54  ATH_MSG_DEBUG("retrieval of tau detail failed. stopping calculation of further variables");
55  return StatusCode::SUCCESS;
56  }
57 
58  if ( !pTau.detail( xAOD::TauJetParameters::etHadAtEMScale, emscale_ptHad ) )
59  {
60  ATH_MSG_DEBUG("retrieval of tau detail failed. stopping calculation of further variables");
61  return StatusCode::SUCCESS;
62  }
63 
64  pTau.setDetail( xAOD::TauJetParameters::etOverPtLeadTrk, static_cast<float>( (emscale_ptEM + emscale_ptHad) / pTau.track(0)->pt() ) );
65  }
66 
67  // invariant mass of track system
68  std::vector<const xAOD::TauTrack*> tauTracks = pTau.tracks(xAOD::TauJetParameters::TauTrackFlag::classifiedCharged);
69  for( const xAOD::TauTrack* trk : pTau.tracks((xAOD::TauJetParameters::TauTrackFlag) m_isolationTrackType) ) tauTracks.push_back(trk);
70  if (!tauTracks.empty()) {
71 
72  TLorentzVector sumOfTrackVector;
73 
74  for (const xAOD::TauTrack* tauTrk : tauTracks)
75  {
76  sumOfTrackVector += tauTrk->p4();
77  }
78  pTau.setDetail( xAOD::TauJetParameters::massTrkSys, static_cast<float>( sumOfTrackVector.M() ) );
79  }
80 
81  if (tauTracks.size()> 1 && pTau.nTracks()>0) {
82 
83  double ptSum = 0.;
84  double sumWeightedDR = 0.;
85  double sumWeightedDR2 = 0.;
86 
87  for (const xAOD::TauTrack* tauTrk : tauTracks) {
88 
89  double deltaR = pTau.track(0)->p4().DeltaR(tauTrk->p4());
90 
91  ptSum += tauTrk->pt();
92  sumWeightedDR += deltaR * tauTrk->pt();
93  sumWeightedDR2 += deltaR * deltaR * tauTrk->pt();
94  }
95 
96  double trkWidth2 = (ptSum!=0.) ? (sumWeightedDR2/ptSum - std::pow(sumWeightedDR/ptSum, 2.)) : 0.;
97 
98  if (trkWidth2 > 0.) pTau.setDetail( xAOD::TauJetParameters::trkWidth2, static_cast<float>( trkWidth2 ) );
99  else pTau.setDetail( xAOD::TauJetParameters::trkWidth2, (float) 0. );
100  }
101 
102  if (!tauTracks.empty()) {
103 
104  double ptSum = 0;
105  double innerPtSum = 0;
106  double sumWeightedDR = 0;
107  double innerSumWeightedDR = 0;
108  double sumWeightedDR2 = 0;
109 
110  for (const xAOD::TauTrack* tauTrk : tauTracks){
111 
112  double deltaR = inTrigger() ? pTau.p4().DeltaR(tauTrk->p4()) : pTau.p4(xAOD::TauJetParameters::IntermediateAxis).DeltaR(tauTrk->p4());
113 
114  ptSum += tauTrk->pt();
115  sumWeightedDR += deltaR * tauTrk->pt();
116  sumWeightedDR2 += deltaR * deltaR * tauTrk->pt();
117 
118  //add calculation of innerTrkAvgDist
120  innerPtSum += tauTrk->pt();
121  innerSumWeightedDR += deltaR * tauTrk->pt();
122  }
123  }
124 
125  if (ptSum > 0.) {
126  // seedCalo_trkAvgDist
127  pTau.setDetail( xAOD::TauJetParameters::trkAvgDist, static_cast<float>( sumWeightedDR / ptSum ) );
128 
129  // seedCalo_trkRmsDist
130  double trkRmsDist2 = sumWeightedDR2 / ptSum - pow(sumWeightedDR/ptSum, 2.);
131  if (trkRmsDist2 > 0.) {
132  pTau.setDetail( xAOD::TauJetParameters::trkRmsDist, static_cast<float>( std::sqrt(trkRmsDist2) ) );
133  }
134  else {
135  pTau.setDetail( xAOD::TauJetParameters::trkRmsDist, (float) 0. );
136  }
137 
138  // SumPtTrkFrac
139  pTau.setDetail( xAOD::TauJetParameters::SumPtTrkFrac, static_cast<float>( 1. - innerPtSum/ptSum ) );
140  }
141  else {
142  pTau.setDetail( xAOD::TauJetParameters::trkAvgDist, (float) 0. );
144  }
145 
146  if (innerPtSum > 0.) {
147  // InnerTrkAvgDist
148  pTau.setDetail( xAOD::TauJetParameters::innerTrkAvgDist, static_cast<float>( innerSumWeightedDR / innerPtSum ) );
149  }
150  else {
152  }
153 
154  }
155 
156  return StatusCode::SUCCESS;
157 }
xAOD::TauJetParameters::TauTrackFlag
TauTrackFlag
Enum for tau track flags.
Definition: TauDefs.h:400
xAOD::TauJetParameters::trkRmsDist
@ trkRmsDist
Get the RMS of track distance to calorimeter seed.
Definition: TauDefs.h:216
xAOD::TauJetParameters::trkWidth2
@ trkWidth2
Definition: TauDefs.h:162
xAOD::TauTrack_v1::p4
virtual FourMom_t p4() const
The full 4-momentum of the particle.
Definition: TauTrack_v1.cxx:31
xAOD::TauJetParameters::IntermediateAxis
@ IntermediateAxis
Definition: TauDefs.h:338
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
conifer::pow
constexpr int pow(int x)
Definition: conifer.h:20
xAOD::TauJet_v3::nTracks
size_t nTracks(TauJetParameters::TauTrackFlag flag=TauJetParameters::TauTrackFlag::classifiedCharged) const
Definition: TauJet_v3.cxx:526
xAOD::TauJetParameters::classifiedCharged
@ classifiedCharged
Definition: TauDefs.h:406
TauRecToolBase
The base class for all tau tools.
Definition: TauRecToolBase.h:21
TauRecToolBase::inTrigger
bool inTrigger() const
Definition: TauRecToolBase.h:87
TauCommonCalcVars::~TauCommonCalcVars
~TauCommonCalcVars()
Definition: TauCommonCalcVars.cxx:30
xAOD::TauJetParameters::etHadAtEMScale
@ etHadAtEMScale
Get Hadronic energy at EM scale.
Definition: TauDefs.h:196
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
xAOD::TauJetParameters::trkAvgDist
@ trkAvgDist
Get calibrated EM transverse energy (DEPRECATED since r19)
Definition: TauDefs.h:214
xAOD::TauJet_v3
Class describing a tau jet.
Definition: TauJet_v3.h:41
xAOD::TauJet_v3::track
const TauTrack * track(size_t i, TauJetParameters::TauTrackFlag flag=TauJetParameters::TauTrackFlag::classifiedCharged, int *container_index=0) const
Get the pointer to a given tauTrack associated with this tau /*container index needed by trackNonCons...
Definition: TauJet_v3.cxx:450
xAOD::TauJetParameters::etOverPtLeadTrk
@ etOverPtLeadTrk
Definition: TauDefs.h:158
xAOD::TauJetParameters::massTrkSys
@ massTrkSys
Definition: TauDefs.h:161
xAOD::TauJet_v3::detail
bool detail(TauJetParameters::Detail detail, int &value) const
Set veto flag.
Definition: TauJet_v3.cxx:292
xAOD::TauTrack_v1::pt
virtual double pt() const
The transverse momentum ( ) of the particle.
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
TauCommonCalcVars::execute
virtual StatusCode execute(xAOD::TauJet &pTau) const override
Execute - called for each tau candidate.
Definition: TauCommonCalcVars.cxx:36
TauCommonCalcVars.h
xAOD::TauJetParameters::innerTrkAvgDist
@ innerTrkAvgDist
Definition: TauDefs.h:287
xAOD::TauTrack_v1
Definition: TauTrack_v1.h:27
xAOD::TauJet_v3::p4
virtual FourMom_t p4() const
The full 4-momentum of the particle.
Definition: TauJet_v3.cxx:97
xAOD::TauJetParameters::modifiedIsolationTrack
@ modifiedIsolationTrack
Definition: TauDefs.h:412
TauCommonCalcVars::TauCommonCalcVars
TauCommonCalcVars(const std::string &name="TauCommonCalcVars")
Definition: TauCommonCalcVars.cxx:20
xAOD::TauJet_v3::setDetail
void setDetail(TauJetParameters::Detail detail, int value)
Definition: TauJet_v3.cxx:337
xAOD::TauJetParameters::SumPtTrkFrac
@ SumPtTrkFrac
Definition: TauDefs.h:289
makeComparison.deltaR
float deltaR
Definition: makeComparison.py:36
xAOD::TauJet_v3::tracks
std::vector< const TauTrack * > tracks(TauJetParameters::TauTrackFlag flag=TauJetParameters::TauTrackFlag::classifiedCharged) const
Get the v<const pointer> to a given tauTrack collection associated with this tau.
Definition: TauJet_v3.cxx:493
xAOD::TauJetParameters::etEMAtEMScale
@ etEMAtEMScale
Get EM energy at EM scale.
Definition: TauDefs.h:194
xAOD::TauJetParameters::leadTrkPt
@ leadTrkPt
Definition: TauDefs.h:159
TauCommonCalcVars::m_isolationTrackType
int m_isolationTrackType
Definition: TauCommonCalcVars.h:32