ATLAS Offline Software
L1Topo/L1TopoAlgorithms/Root/cTauMultiplicity.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 // TopoCore
5 //
6 
7 
8 
10 #include "L1TopoCommon/Exception.h"
11 #include "L1TopoInterfaces/Count.h"
13 
14 #include "L1TopoEvent/TOBArray.h"
17 
18 #include <cmath>
19 
20 
21 REGISTER_ALG_TCS(cTauMultiplicity)
22 
24  setNumberOutputBits(12); //To-Do: Make this flexible to adapt to the menu. Each counting requires more than one bit
25 }
26 
27 
29  m_threshold = dynamic_cast<const TrigConf::L1Threshold_cTAU*>(getThreshold());
30  if (not m_threshold){
31  TRG_MSG_ERROR("Dynamic cast failed in TCS::cTauMultiplicity::initialize");
32  return StatusCode::FAILURE;
33  }
34 
36 
37  // Book monitoring histograms
38  bookHistMult(m_histAccept, "cTauMultiplicity_accept_EtaPt_"+m_threshold->name(), "Mult_"+m_threshold->name(), "#eta#times40", "E_{t} [GeV]", 200, -200, 200, 100, 0, 100);
39  bookHistMult(m_histAccept, "cTauMultiplicity_accept_counts_"+m_threshold->name(), "Mult_"+m_threshold->name(), "counts", 15, 0, 15);
40 
41  // cTau TOB monitoring histograms
42  bookHistMult(m_histcTauEt, "cTauTOBEt", "Matched cTau TOB Et", "E_{t} [GeV]", 200, 0, 400);
43  bookHistMult(m_histcTauPhiEta, "cTauTOBPhiEta", "Matched cTau TOB location", "#eta#times40", "#phi#times20", 200, -200, 200, 128, 0, 128);
44  bookHistMult(m_histcTauEtEta, "cTauTOBEtEta", "Matched cTau TOB Et vs eta", "#eta#times40", "E_{t} [GeV]", 200, -200, 200, 200, 0, 400);
45 
46  const std::string wp_name = m_threshold->isolation() != WP::NONE ? TrigConf::Selection::wpToString(m_threshold->isolation()) : "NoIso";
47  bookHistMult(m_histcTauIsoFraction, "cTauTOBIsoFraction", std::string("Matched cTAU ") + wp_name + " isolation fraction", wp_name + " isolation fraction", 200, 0, 10);
48 
49  bookHistMult(m_histcTauIsoMatchedPass, "cTauTOBIsoMatchedPass", "Matched cTau isolation pass", "isolation pass", 2, 0, 2);
50 
51  return StatusCode::SUCCESS;
52 }
53 
54 
55 // To be implemented
57 {
58  return process(input, count);
59 }
60 
61 
63 {
64  const cTauTOBArray& cTaus = dynamic_cast<const cTauTOBArray&>(input);
65 
66  int counting = 0;
67  // Loop over eTau candidates
68  for(cTauTOBArray::const_iterator etauCand = cTaus.begin(); etauCand != cTaus.end(); ++etauCand) {
69  if((*etauCand)->tobType() != TCS::ETAU) continue;
70 
71  bool accept = false; // accept = (isMatched==true && isIsolated==true) || (isMatched==false)
72  bool isMatched = false; // Is the eTau matched to a jTau?
73  bool isIsolated = false; // If matched: does the resulting cTau pass the isolation cut?
74  float isolation_fraction = 0; // cTAU isolation fraction
75 
76  // Loop over jTau candidates
77  for(cTauTOBArray::const_iterator jtauCand = cTaus.begin(); jtauCand != cTaus.end(); ++jtauCand) {
78  if((*jtauCand)->tobType() != TCS::JTAU) continue;
79 
80  isMatched = cTauMatching(*etauCand, *jtauCand);
81 
82  if(isMatched) {
83  float etauCand_et = static_cast<float>((*etauCand)->Et());
84  float etauCand_eta = static_cast<float>((*etauCand)->etaDouble());
85  float jtauCand_et = static_cast<float>((*jtauCand)->Et());
86  float jtauCand_etIso = static_cast<float>((*jtauCand)->EtIso());
87 
88  // Updated isolation condition, WP-dependent (ATR-28641)
89  // I = (E_T^{jTAU Iso} + jTAUCoreScale * (E_T^{jTAU Core} - E_T^{eTAU})) / E_T^{eTAU}
90  if(m_threshold->isolation() != WP::NONE) {
91  isolation_fraction = (jtauCand_etIso + m_extraInfo->isolation(m_threshold->isolation(), etauCand_eta).isolation_jTAUCoreScale_d() * (jtauCand_et - etauCand_et)) / etauCand_et;
92  }
93  // Old isolation condition coded as in firmware: https://indico.cern.ch/event/1079697/contributions/4541419/attachments/2315137/3940824/cTAU_FirmwareAlgoProposal.pdf page 8
94 
95  // Check the isolation WP
96  isIsolated = checkIsolationWP(*etauCand, *jtauCand);
97 
98  break; // Break loop when a match is found
99  }
100 
101  } // End of jTau loop
102 
103  // Fill cTau TOB histograms before threshold cuts (matched cTaus only)
104  if(isMatched) {
105  fillHist1D(m_histcTauEt[0], (*etauCand)->EtDouble());
106  fillHist2D(m_histcTauPhiEta[0], (*etauCand)->eta(), (*etauCand)->phi());
107  fillHist2D(m_histcTauEtEta[0], (*etauCand)->eta(), (*etauCand)->EtDouble());
108  fillHist1D(m_histcTauIsoFraction[0], isolation_fraction);
109  fillHist1D(m_histcTauIsoMatchedPass[0], isMatched && isIsolated);
110  }
111 
112  if(isMatched && isIsolated) accept = true; // This is a good matched cTau
113  if(!isMatched) accept = true; // This is a non-matched eTau
114 
115  if(!checkeTAUWP(*etauCand)) accept = false; // Check eTAU rCore/BDT and rHad WP
116 
117  // Menu threshold uses 0.1 eta granularity but eFex objects have 0.025 eta granularity
118  // eFex eta is calculated as 4*eta_tower (0.1 gran.) + seed (0.025 gran.), eta from -25 to 24
119  int eta_thr;
120  if((*etauCand)->eta()%4 >= 0) eta_thr = (*etauCand)->eta() - (*etauCand)->eta()%4;
121  else eta_thr = (*etauCand)->eta() - (*etauCand)->eta()%4 - 4;
122 
123  accept = accept && (*etauCand)->Et() > m_threshold->thrValue100MeV(eta_thr/4); // Convert eta_thr to units of 0.1 to pass as an argument
124 
125  if(accept) {
126  counting++;
127  fillHist2D(m_histAccept[0], (*etauCand)->eta(), (*etauCand)->EtDouble());
128  }
129 
130  } // End of eTau loop
131 
132  fillHist1D(m_histAccept[1], counting);
133 
134  // Pass counting to TCS::Count object - output bits are composed there
135  count.setSizeCount(counting);
136 
138 }
139 
140 
141 bool TCS::cTauMultiplicity::checkIsolationWP(const TCS::cTauTOB* etauCand, const TCS::cTauTOB* jtauCand) const {
142  if(m_threshold->isolation() == WP::NONE) return true;
143  auto iso_wp = m_extraInfo->isolation(m_threshold->isolation(), etauCand->etaDouble());
144  return jtauCand->EtIso()*1024 + jtauCand->Et()*iso_wp.isolation_jTAUCoreScale_fw() < etauCand->Et()*iso_wp.isolation_fw();
145 }
146 
147 
149  if(m_threshold->isolation() == WP::NONE) return true;
150  auto iso_wp = m_extraInfo->isolation(m_threshold->isolation(), etauCand->etaDouble());
151  return etauCand->RCore() >= iso_wp.eTAU_rCoreMin_WP_fw() && etauCand->RHad() >= iso_wp.eTAU_rHadMin_WP_fw();
152 }
153 
154 
155 bool TCS::cTauMultiplicity::cTauMatching(const TCS::cTauTOB* etauCand, const TCS::cTauTOB* jtauCand) const {
156 
157  bool matching = false;
158 
159  // Matching is done comparing eta_tower and phi_tower (granularity = 0.1)
160  // These coordinates represent the lower edge of the towers (both for eFEX and jFEX)
161 
162  // eTau eta = 4*eta_tower + seed, eta from -25 to 24
163  int eTauEtaTower;
164  if(etauCand->eta()%4 >= 0 ) eTauEtaTower = etauCand->eta() - etauCand->eta()%4;
165  else eTauEtaTower = etauCand->eta() - etauCand->eta()%4 - 4;
166  int jTauEtaTower;
167  if (jtauCand->eta()%4 >= 0 ) jTauEtaTower = jtauCand->eta() - jtauCand->eta()%4;
168  else jTauEtaTower = jtauCand->eta() - jtauCand->eta()%4 - 4;
169 
170  //int jTauEtaTower = jtauCand->eta(); // jTau eta = 4*eta_tower
171  unsigned int eTauPhiTower = etauCand->phi() >> 1; // eTau phi = 2*phi_tower
172  unsigned int jTauPhiTower = jtauCand->phi() >> 1; // jTau phi = 2*phi_tower + 1 (jTau coordinates are at center of tower)
173 
174  matching = (eTauEtaTower == jTauEtaTower) && (eTauPhiTower == jTauPhiTower);
175 
176  return matching;
177 
178 }
179 
180 // Functions used by the HLT seeding
181 
182 #ifndef TRIGCONF_STANDALONE
184 
185  // Return the index of the matched jTau if existent (otherwise return std::numeric_limits<size_t>::max())
186  size_t i_matched{std::numeric_limits<size_t>::max()};
187  size_t i_jTau{0};
188 
189  int eTauEtaTower;
190  if(eTau.iEtaTopo()%4 >= 0 ) eTauEtaTower = eTau.iEtaTopo() - eTau.iEtaTopo()%4;
191  else eTauEtaTower = eTau.iEtaTopo() - eTau.iEtaTopo()%4 - 4;
192 
193  for(const xAOD::jFexTauRoI* jTau : jTauRoIs) {
194 
195  // eFEX: etaTower = iEta, phiTower = iPhi
196  // jFEX: etaTower = globalEta, phiTower = globalPhi
197 
198  int jTauEtaTopo = TSU::toTopoEta(jTau->eta());
199  int jTauEtaTower;
200  if(jTauEtaTopo%4 >= 0 ) jTauEtaTower = jTauEtaTopo - jTauEtaTopo%4;
201  else jTauEtaTower = jTauEtaTopo - jTauEtaTopo%4 - 4;
202 
203  unsigned int jTauPhiTower = TSU::toTopoPhi(jTau->phi()) >> 1; //ignore lowest bit as jTau coordinates are taken at tower center
204  unsigned int eTauPhiTower = static_cast<unsigned int>(eTau.iPhiTopo()) >> 1; //shift eTau location in the same way to stay consistent
205  bool matching = ( eTauEtaTower == jTauEtaTower ) && ( eTauPhiTower == jTauPhiTower );
206 
207  if(matching) {
208  i_matched = i_jTau;
209  break; // Break the loop when a match is found
210  }
211  ++i_jTau;
212  }
213 
214  return i_matched;
215 
216 }
217 
218 
220 
221  // eFEX: etaTower = iEta, phiTower = iPhi
222  // jFEX: etaTower = globalEta, phiTower = globalPhi
223 
224  int eTauEtaTower;
225  if(eTau.iEtaTopo()%4 >= 0 ) eTauEtaTower = eTau.iEtaTopo() - eTau.iEtaTopo()%4;
226  else eTauEtaTower = eTau.iEtaTopo() - eTau.iEtaTopo()%4 - 4;
227 
228  int jTauEtaTopo = TSU::toTopoEta(jTau.eta());
229  int jTauEtaTower;
230  if(jTauEtaTopo%4 >= 0 ) jTauEtaTower = jTauEtaTopo - jTauEtaTopo%4;
231  else jTauEtaTower = jTauEtaTopo - jTauEtaTopo%4 - 4;
232 
233  unsigned int jTauPhiTower = TSU::toTopoPhi(jTau.phi()) >> 1; //ignore lowest bit as jTau coordinates are taken at tower center
234  unsigned int eTauPhiTower = static_cast<unsigned int>(eTau.iPhiTopo()) >> 1; //shift eTau location in the same way to stay consistent
235 
236  bool matching = ( eTauEtaTower == jTauEtaTower ) && ( eTauPhiTower == jTauPhiTower );
237  return matching;
238 
239 }
240 
241 
243  if(thr.isolation() == WP::NONE) return true;
244  auto iso_wp = thr.getExtraInfo()->isolation(thr.isolation(), eTau.eta());
245  return jTau.tobIso()*2*1024 + jTau.tobEt()*2*iso_wp.isolation_jTAUCoreScale_fw() < eTau.etTOB()*iso_wp.isolation_fw();
246 }
247 
248 
250  if(thr.isolation() == WP::NONE) return true;
251  auto iso_wp = thr.getExtraInfo()->isolation(thr.isolation(), eTau.eta());
252  return eTau.tauOneThresholds() >= iso_wp.eTAU_rCoreMin_WP_fw() && eTau.tauTwoThresholds() >= iso_wp.eTAU_rHadMin_WP_fw();
253 }
254 
255 #endif
TCS::cTauMultiplicity::initialize
virtual StatusCode initialize() override
Definition: L1Topo/L1TopoAlgorithms/Root/cTauMultiplicity.cxx:28
NONE
@ NONE
Definition: sTGCenumeration.h:13
TCS::cTauMultiplicity::m_histcTauPhiEta
std::vector< std::string > m_histcTauPhiEta
Definition: L1Topo/L1TopoAlgorithms/L1TopoAlgorithms/cTauMultiplicity.h:63
TRG_MSG_ERROR
#define TRG_MSG_ERROR(x)
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStreamMacros.h:29
xAOD::jFexTauRoI_v1
Class describing properties of a LVL1 jFEX global Trigger Object (TOB) in the xAOD format.
Definition: jFexTauRoI_v1.h:23
TrigConf::L1Threshold_cTAU
Definition: L1Threshold.h:255
xAOD::eFexTauRoI_v1::iEtaTopo
int iEtaTopo() const
Getter for integer phi index (0-63)
Definition: eFexTauRoI_v1.cxx:286
TCS::cTauTOB::EtIso
unsigned int EtIso() const
Definition: cTauTOB.h:44
TCS::StatusCode::SUCCESS
@ SUCCESS
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/L1TopoCommon/StatusCode.h:17
xAOD::jFexTauRoI_v1::eta
float eta() const
TCS::DataArrayImpl< cTauTOB >::const_iterator
data_t::const_iterator const_iterator
Definition: DataArrayImpl.h:18
TCS::StatusCode::FAILURE
@ FAILURE
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/L1TopoCommon/StatusCode.h:17
xAOD::eFexTauRoI_v1::eta
float eta() const
setter for the above
TCS::cTauMultiplicity::m_histcTauIsoMatchedPass
std::vector< std::string > m_histcTauIsoMatchedPass
Definition: L1Topo/L1TopoAlgorithms/L1TopoAlgorithms/cTauMultiplicity.h:66
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
TCS::cTauTOB::RCore
unsigned int RCore() const
Definition: cTauTOB.h:41
CutsMETMaker::accept
StatusCode accept(const xAOD::Muon *mu)
Definition: CutsMETMaker.cxx:18
xAOD::eFexTauRoI_v1::tauTwoThresholds
unsigned int tauTwoThresholds() const
Tau Condition 2 (generic) results.
Definition: eFexTauRoI_v1.cxx:209
TrigConf::Selection::wpToString
static std::string wpToString(WP)
Definition: L1ThresholdBase.cxx:347
TSU::toTopoEta
int toTopoEta(float eta)
Definition: Conversions.cxx:27
xAOD::jFexTauRoI_v1::tobIso
uint16_t tobIso() const
InDetSecVtxTruthMatchUtils::isMatched
bool isMatched(int matchInfo)
Definition: InDetSecVtxTruthMatchTool.h:75
TCS::cTauTOB::etaDouble
double etaDouble() const
Definition: cTauTOB.h:38
const
bool const RAWDATA *ch2 const
Definition: LArRodBlockPhysicsV0.cxx:560
TrigConf::DataStructure::name
virtual const std::string & name() const final
Definition: DataStructure.cxx:109
TCS::cTauTOBArray
Definition: L1Topo/L1TopoEvent/L1TopoEvent/cTauTOBArray.h:14
SUSY_SimplifiedModel_PostInclude.process
string process
Definition: SUSY_SimplifiedModel_PostInclude.py:43
TCS::DataArrayImpl::end
iterator end()
Definition: DataArrayImpl.h:43
Conversions.h
XMLtoHeader.count
count
Definition: XMLtoHeader.py:84
TrigConf::Selection::WP::NONE
@ NONE
xAOD::eFexTauRoI_v1::tauOneThresholds
unsigned int tauOneThresholds() const
Tau Condition 1 (generic) results.
Definition: eFexTauRoI_v1.cxx:205
TCS::cTauMultiplicity::m_histcTauEt
std::vector< std::string > m_histcTauEt
Definition: L1Topo/L1TopoAlgorithms/L1TopoAlgorithms/cTauMultiplicity.h:62
xAOD::eFexTauRoI_v1::iPhiTopo
int iPhiTopo() const
Return phi index in the range used by L1Topo (0->127)
Definition: eFexTauRoI_v1.cxx:278
xAOD::jFexTauRoI_v1::tobEt
uint16_t tobEt() const
xAOD::eFexTauRoI_v1
Class describing a LVL1 eFEX tau region of interest.
Definition: eFexTauRoI_v1.h:29
Count.h
TCS::InputTOBArray
Definition: InputTOBArray.h:15
TrigConf::L1Threshold_cTAU::getExtraInfo
const std::shared_ptr< L1ThrExtraInfo_cTAU > getExtraInfo() const
Definition: L1Threshold.cxx:188
TCS::cTauMultiplicity::checkIsolationWP
static bool checkIsolationWP(const xAOD::eFexTauRoI &eTau, const xAOD::jFexTauRoI &jTau, const TrigConf::L1Threshold_cTAU &thr)
Definition: L1Topo/L1TopoAlgorithms/Root/cTauMultiplicity.cxx:242
cTauMultiplicity.h
TCS::cTauTOB::phi
unsigned int phi() const
Definition: cTauTOB.h:35
xAOD::jFexTauRoI_v1::phi
float phi() const
TOBArray.h
TCS::cTauMultiplicity::checkeTAUWP
static bool checkeTAUWP(const xAOD::eFexTauRoI &eTau, const TrigConf::L1Threshold_cTAU &thr)
Definition: L1Topo/L1TopoAlgorithms/Root/cTauMultiplicity.cxx:249
TCS::cTauMultiplicity::m_extraInfo
std::shared_ptr< TrigConf::L1ThrExtraInfo_cTAU > m_extraInfo
Definition: L1Topo/L1TopoAlgorithms/L1TopoAlgorithms/cTauMultiplicity.h:53
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
TCS::cTauTOB::eta
int eta() const
Definition: cTauTOB.h:34
REGISTER_ALG_TCS
#define REGISTER_ALG_TCS(CLASS)
Definition: AlgFactory.h:62
TCS::cTauMultiplicity::cTauMatching
static size_t cTauMatching(const xAOD::eFexTauRoI &eTau, const xAOD::jFexTauRoIContainer &jTauRoIs)
Definition: L1Topo/L1TopoAlgorithms/Root/cTauMultiplicity.cxx:183
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
TCS::CountingAlg::m_histAccept
std::vector< std::string > m_histAccept
Definition: CountingAlg.h:51
TCS::cTauMultiplicity::m_threshold
const TrigConf::L1Threshold_cTAU * m_threshold
Definition: L1Topo/L1TopoAlgorithms/L1TopoAlgorithms/cTauMultiplicity.h:52
TCS::cTauTOB::Et
unsigned int Et() const
Definition: cTauTOB.h:33
TCS::cTauMultiplicity::m_histcTauIsoFraction
std::vector< std::string > m_histcTauIsoFraction
Definition: L1Topo/L1TopoAlgorithms/L1TopoAlgorithms/cTauMultiplicity.h:65
TCS::DataArrayImpl::begin
iterator begin()
Definition: DataArrayImpl.h:40
TCS::cTauMultiplicity::processBitCorrect
virtual StatusCode processBitCorrect(const TCS::InputTOBArray &input, Count &count) override final
Definition: L1Topo/L1TopoAlgorithms/Root/cTauMultiplicity.cxx:56
TCS::ConfigurableAlg::bookHistMult
void bookHistMult(std::vector< std::string > &regName, const std::string &name, const std::string &title, const std::string &xtitle, const int binx, const int xmin, const int xmax)
Definition: ConfigurableAlg.cxx:338
xAOD::eFexTauRoI_v1::etTOB
unsigned int etTOB() const
Cluster ET (TOB ET scale, 100 MeV/count)
Definition: eFexTauRoI_v1.cxx:159
TCS::Count
Definition: L1Topo/L1TopoInterfaces/L1TopoInterfaces/Count.h:20
TCS::cTauMultiplicity
Definition: L1Topo/L1TopoAlgorithms/L1TopoAlgorithms/cTauMultiplicity.h:28
TCS::cTauMultiplicity::m_histcTauEtEta
std::vector< std::string > m_histcTauEtEta
Definition: L1Topo/L1TopoAlgorithms/L1TopoAlgorithms/cTauMultiplicity.h:64
TCS::CountingAlg::getThreshold
const TrigConf::L1Threshold * getThreshold()
Definition: CountingAlg.h:47
TCS
Definition: Global/GlobalSimulation/src/IO/Decision.h:18
TCS::cTauTOB::RHad
unsigned int RHad() const
Definition: cTauTOB.h:42
TCS::ETAU
@ ETAU
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/L1TopoCommon/Types.h:22
TCS::JTAU
@ JTAU
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/L1TopoCommon/Types.h:13
TCS::cTauTOB
Definition: cTauTOB.h:13
TrigConf::L1Threshold_cTAU::isolation
Selection::WP isolation() const
Definition: L1Threshold.h:262
TCS::cTauMultiplicity::process
virtual StatusCode process(const TCS::InputTOBArray &input, Count &count) override final
Definition: L1Topo/L1TopoAlgorithms/Root/cTauMultiplicity.cxx:62
Exception.h
TCS::CountingAlg
Definition: CountingAlg.h:25
L1ThrExtraInfo.h
TCS::StatusCode
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/L1TopoCommon/StatusCode.h:15
TSU::toTopoPhi
unsigned int toTopoPhi(float phi)
Definition: Conversions.cxx:20
cTauTOBArray.h