ATLAS Offline Software
Tool_FeatureExtractor.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 #include "xAODTau/TauJet.h"
6 #include "xAODTracking/Vertex.h"
8 
9 #include "TLorentzVector.h"
10 #include "TVector3.h"
11 
12 #include <cmath>
13 #include <map>
14 #include <vector>
15 
19 #include "PanTauAlgs/PanTauSeed.h"
20 #include "PanTauAlgs/TauFeature.h"
22 
23 
25  return u->getBDTValue() > v->getBDTValue();
26 }
27 
28 
30  return u->p4().Et() > v->p4().Et();
31 }
32 
33 
35  asg::AsgTool(name)
36 {
37 }
38 
39 
41 
42  ATH_MSG_INFO(" initialize()");
43  m_init=true;
44 
45  ATH_CHECK( HelperFunctions::bindToolHandle( m_Tool_InformationStore, m_Tool_InformationStoreName ) );
46  ATH_CHECK( m_Tool_InformationStore.retrieve() );
47 
48  ATH_CHECK( m_Tool_InformationStore->getInfo_String("FeatureExtractor_VarTypeName_varTypeName_Sum", m_varTypeName_Sum) );
49  ATH_CHECK( m_Tool_InformationStore->getInfo_String("FeatureExtractor_VarTypeName_varTypeName_Ratio", m_varTypeName_Ratio) );
50  ATH_CHECK( m_Tool_InformationStore->getInfo_String("FeatureExtractor_VarTypeName_varTypeName_Isolation", m_varTypeName_Isolation) );
51  ATH_CHECK( m_Tool_InformationStore->getInfo_String("FeatureExtractor_VarTypeName_varTypeName_Num", m_varTypeName_Num) );
52  ATH_CHECK( m_Tool_InformationStore->getInfo_String("FeatureExtractor_VarTypeName_varTypeName_Mean", m_varTypeName_Mean) );
53  ATH_CHECK( m_Tool_InformationStore->getInfo_String("FeatureExtractor_VarTypeName_varTypeName_StdDev", m_varTypeName_StdDev) );
54  ATH_CHECK( m_Tool_InformationStore->getInfo_String("FeatureExtractor_VarTypeName_varTypeName_HLV", m_varTypeName_HLV) );
55  ATH_CHECK( m_Tool_InformationStore->getInfo_String("FeatureExtractor_VarTypeName_varTypeName_Angle", m_varTypeName_Angle) );
56  ATH_CHECK( m_Tool_InformationStore->getInfo_String("FeatureExtractor_VarTypeName_varTypeName_DeltaR", m_varTypeName_DeltaR) );
57  ATH_CHECK( m_Tool_InformationStore->getInfo_String("FeatureExtractor_VarTypeName_varTypeName_JetMoment", m_varTypeName_JetMoment) );
58  ATH_CHECK( m_Tool_InformationStore->getInfo_String("FeatureExtractor_VarTypeName_varTypeName_Combined", m_varTypeName_Combined) );
59  ATH_CHECK( m_Tool_InformationStore->getInfo_String("FeatureExtractor_VarTypeName_varTypeName_Basic", m_varTypeName_Basic) );
60  ATH_CHECK( m_Tool_InformationStore->getInfo_String("FeatureExtractor_VarTypeName_varTypeName_PID", m_varTypeName_PID) );
61 
62  ATH_CHECK( m_Tool_InformationStore->getInfo_Int("FeatureExtractor_UseEmptySeeds", m_Config_UseEmptySeeds) );
63 
64  ATH_CHECK( m_Tool_InformationStore->getInfo_VecDouble("CellBased_BinEdges_Eta", m_Config_CellBased_BinEdges_Eta) );
65  ATH_CHECK( m_Tool_InformationStore->getInfo_VecDouble("CellBased_EtaBinned_Pi0MVACut_1prong", m_Config_CellBased_EtaBinned_Pi0MVACut_1prong) );
66  ATH_CHECK( m_Tool_InformationStore->getInfo_VecDouble("CellBased_EtaBinned_Pi0MVACut_3prong", m_Config_CellBased_EtaBinned_Pi0MVACut_3prong) );
67 
68  return StatusCode::SUCCESS;
69 }
70 
71 
72 void PanTau::Tool_FeatureExtractor::fillVariantsSeedEt(const std::vector<PanTau::TauConstituent*>& tauConstituents,
73  std::map<std::string, double>& variants_SeedEt) {
74 
75  //use different approaches to calculate total energy of seed:
76  variants_SeedEt["EtAllConsts"] = 0.0;
77 
78  //loop over all constituents in seed
79  for (unsigned int iConst = 0; iConst < tauConstituents.size(); iConst++) {
80 
81  //get current constituents
82  PanTau::TauConstituent* curConstituent = tauConstituents.at(iConst);
83  double curEt = curConstituent->p4().Et();
84 
85  //update the different Et definitions
86  if (curConstituent->isOfType(PanTau::TauConstituent::t_Charged) ||
87  curConstituent->isOfType(PanTau::TauConstituent::t_Neutral) ) {
88  variants_SeedEt["EtAllConsts"] += curEt;
89  }
90  }//end loop over constituents in seed
91 }
92 
93 
95  const std::string& featName,
96  double numerator,
97  const std::map<std::string, double>& denominatorMap) {
98  std::map<std::string, double>::const_iterator it = denominatorMap.begin();
99  for(; it!=denominatorMap.end(); ++it) {
100  std::string FullName = featName + it->first;
101  float value = static_cast<float>(it->second);
102  if(value <= 0. || std::isnan(value) || std::isinf(value) ) continue;
103  targetMap->addFeature(FullName, numerator / it->second);
104  }
105 }
106 
107 
109 
110  bool noAnyConstituents = inSeed->isOfTechnicalQuality(PanTau::PanTauSeed::t_NoConstituentsAtAll);
111  bool noSelConstituents = inSeed->isOfTechnicalQuality(PanTau::PanTauSeed::t_NoSelectedConstituents);
112  bool noValidInputTau = inSeed->isOfTechnicalQuality(PanTau::PanTauSeed::t_NoValidInputTau);
113  bool isBadSeed = (noAnyConstituents || noSelConstituents || noValidInputTau);
114  if(static_cast<bool>(m_Config_UseEmptySeeds)) isBadSeed = noValidInputTau;
115 
116  if (isBadSeed) {
117  ATH_MSG_DEBUG("Seed is not valid for feature extraction (no constituents or no valid input tau) - just fill isPanTauCandidate feature");
118  inSeed->getFeatures()->addFeature("CellBased_" + m_varTypeName_Basic + "_isPanTauCandidate", 0);
119  return StatusCode::SUCCESS;
120  }
121  inSeed->getFeatures()->addFeature("CellBased_" + m_varTypeName_Basic + "_isPanTauCandidate", 1);
122 
123 
124  ATH_CHECK( calculateBasicFeatures(inSeed) );
125 
126  ATH_CHECK( addConstituentMomenta(inSeed) );
127 
128  // map containing different methods to calc seed et
129  std::map<std::string, double> variants_SeedEt;
130  // calculate the Et variants for the seed
131  fillVariantsSeedEt(inSeed->getConstituentsAsList_All(), variants_SeedEt);
132 
133  //loop through all types of Constituents in tau and calculate type features for them
134  //baseline
135  ATH_CHECK( calculateFeatures(inSeed, PanTau::TauConstituent::t_NoType, variants_SeedEt) ); //=> all constituents
136  ATH_CHECK( calculateFeatures(inSeed, PanTau::TauConstituent::t_Charged, variants_SeedEt) ); //=> charged ones in core
137  ATH_CHECK( calculateFeatures(inSeed, PanTau::TauConstituent::t_Neutral, variants_SeedEt) ); //=> neutral ones in core
138  ATH_CHECK( calculateFeatures(inSeed, PanTau::TauConstituent::t_Pi0Neut, variants_SeedEt) ); //=> pi0 tagged ones in core
139 
140  //fill the combined features
141  ATH_CHECK( addCombinedFeatures(inSeed, variants_SeedEt) );
142 
143  return StatusCode::SUCCESS;
144 }
145 
146 
148 
149  PanTau::TauFeature* featureMap = inSeed->getFeatures();
150 
151  std::string featurePrefix = m_varTypeName_Basic;
152  std::string name = "CellBased_" + featurePrefix;
153 
154  double SumCharge = 0;
155  double AbsCharge = 0;
156 
160  for(int iType=0; iType<PanTau::TauConstituent::t_nTypes; iType++) {
161 
162  bool foundIt = false;
163  std::vector<TauConstituent*> curList = inSeed->getConstituentsOfType(iType, foundIt);
164  if(!foundIt) continue;
165 
166  //store multiplicity of current type
168  unsigned int nConstituents = curList.size();
169  featureMap->addFeature(name + "_N" + typeName + "Consts", nConstituents);
170 
171  //count charge, i.e. skip if not charged
172  if(iType != static_cast<int>(PanTau::TauConstituent::t_Charged)) continue;
173  for(unsigned int iConst=0; iConst<nConstituents; iConst++) {
174  PanTau::TauConstituent* curConstituent = curList[iConst];
175  SumCharge += curConstituent->getCharge();
176  AbsCharge += std::abs(static_cast<double>(curConstituent->getCharge()));
177  }
178  }
179 
180  //store charge
181  featureMap->addFeature(name + "_SumCharge", SumCharge);
182  featureMap->addFeature(name + "_AbsCharge", AbsCharge);
183 
185  //proto 4-vector (just the sum of all constituents)
186  // will have better four momentum after mode ID
187  TLorentzVector tlv_ProtoMomentumCore = inSeed->getProtoMomentumCore();
188  featureMap->addFeature(name + "_ProtoMomentumCore_pt", tlv_ProtoMomentumCore.Perp());
189  featureMap->addFeature(name + "_ProtoMomentumCore_eta", tlv_ProtoMomentumCore.Eta());
190  featureMap->addFeature(name + "_ProtoMomentumCore_phi", tlv_ProtoMomentumCore.Phi());
191  featureMap->addFeature(name + "_ProtoMomentumCore_m", tlv_ProtoMomentumCore.M());
192 
193  return StatusCode::SUCCESS;
194 }
195 
196 
198  TauFeature* tauFeatureMap = inSeed->getFeatures();
199  std::string prefixVARType = m_varTypeName_HLV;
200  for(int iType=0; iType<static_cast<int>(PanTau::TauConstituent::t_nTypes); iType++) {
201  bool isOK;
202  std::vector<PanTau::TauConstituent*> list_TypeConstituents = inSeed->getConstituentsOfType(iType, isOK); // list of constituents of current type
203  unsigned int n_Constituents_Type = list_TypeConstituents.size(); // number of objects of current type
204  TLorentzVector tlv_TypeConstituents = inSeed->getSubsystemHLV(iType, isOK); // summed hlv of objects of current type
205  std::string curTypeName = PanTau::TauConstituent::getTypeName((PanTau::TauConstituent::Type)iType);
206  std::string name = "CellBased_" + curTypeName + "_" + prefixVARType;
207 
208  std::vector<PanTau::TauConstituent*> list_TypeConstituents_SortBDT = inSeed->getConstituentsOfType(iType, isOK);
209  std::sort(list_TypeConstituents_SortBDT.begin(), list_TypeConstituents_SortBDT.end(), sortTauConstituentMVA);
210 
211  if(!list_TypeConstituents.empty()) {
212  tauFeatureMap->addFeature(name + "_SumPt", tlv_TypeConstituents.Perp());
213  tauFeatureMap->addFeature(name + "_SumEta", tlv_TypeConstituents.Eta());
214  tauFeatureMap->addFeature(name + "_SumPhi", tlv_TypeConstituents.Phi());
215  tauFeatureMap->addFeature(name + "_SumM", tlv_TypeConstituents.M());
216  }
217 
218  //store 4-vectors of current type (bdt sort)
219  std::vector<double> curConstsBDT_pt = std::vector<double>(0);
220  std::vector<double> curConstsBDT_eta = std::vector<double>(0);
221  std::vector<double> curConstsBDT_phi = std::vector<double>(0);
222  std::vector<double> curConstsBDT_m = std::vector<double>(0);
223  for(unsigned int iConst=0; iConst<n_Constituents_Type; iConst++) {
224  TLorentzVector tlv_curConstBDT = list_TypeConstituents_SortBDT[iConst]->p4();
225  curConstsBDT_pt.push_back(tlv_curConstBDT.Perp());
226  curConstsBDT_eta.push_back(tlv_curConstBDT.Eta());
227  curConstsBDT_phi.push_back(tlv_curConstBDT.Phi());
228  curConstsBDT_m.push_back(tlv_curConstBDT.M());
229  }
230  tauFeatureMap->addVecFeature(name + "_BDTSort_Constituents_pt", curConstsBDT_pt);
231  tauFeatureMap->addVecFeature(name + "_BDTSort_Constituents_eta", curConstsBDT_eta);
232  tauFeatureMap->addVecFeature(name + "_BDTSort_Constituents_phi", curConstsBDT_phi);
233  tauFeatureMap->addVecFeature(name + "_BDTSort_Constituents_m", curConstsBDT_m);
234 
235  } //end loop over constituent types
236 
237  return StatusCode::SUCCESS;
238 }
239 
240 
242  int tauConstituentType,
243  const std::map<std::string, double>& variants_SeedEt) const {
244 
245  std::string curTypeName = PanTau::TauConstituent::getTypeName( (PanTau::TauConstituent::Type)tauConstituentType );
246  std::string curTypeName_All = PanTau::TauConstituent::AllConstituentsName();
247  PanTau::TauFeature* tauFeatureMap = inSeed->getFeatures();
248  TLorentzVector tlv_Reference = inSeed->getProtoMomentumCore();
249 
250  std::vector<PanTau::TauConstituent*> list_AllConstituents = inSeed->getConstituentsAsList_Core();
251 
252  bool foundIt = false;
253  std::vector<PanTau::TauConstituent*> list_TypeConstituents;
254  if (tauConstituentType != PanTau::TauConstituent::t_NoType) list_TypeConstituents = inSeed->getConstituentsOfType(tauConstituentType, foundIt);
255  if (tauConstituentType == PanTau::TauConstituent::t_NoType) list_TypeConstituents = list_AllConstituents;
256  if (!foundIt) return StatusCode::SUCCESS;
257 
258  unsigned int n_Constituents_Type = list_TypeConstituents.size();
259 
260  //sort the lists by Et
261  std::sort(list_AllConstituents.begin(), list_AllConstituents.end(), sortTauConstituentEt);
262  std::sort(list_TypeConstituents.begin(), list_TypeConstituents.end(), sortTauConstituentEt);
263 
264  //make an additional list of constituents, but now ordered by BDT value
265  std::vector<PanTau::TauConstituent*> list_TypeConstituents_SortBDT = list_TypeConstituents;
266  std::sort(list_TypeConstituents_SortBDT.begin(), list_TypeConstituents_SortBDT.end(), sortTauConstituentMVA);
267 
268  TLorentzVector tlv_1st_BDT;
269 
270  if(!list_TypeConstituents_SortBDT.empty()) tlv_1st_BDT = list_TypeConstituents_SortBDT[0]->p4();
271 
275 
276  // ===> hlv for the leading EFOs and the summed HLV
277  TLorentzVector tlv_TypeConstituents;
278  // ===> Sum of Et, Et^2, E and E^2
279  double sum_Et = 0;
280  double sum_Et2 = 0;
281  // ===> Sum of Et (and E) times DeltaR, DeltaR', Angle
282  double sum_EtxDR = 0;
283  // ===> Multiplicities
284  unsigned int num_EFOs = 0;
285 
289  for(unsigned int iTypeConst=0; iTypeConst<list_TypeConstituents.size(); iTypeConst++) {
290 
291  //get hep lorentz vector
292  TLorentzVector tlv_curConst = list_TypeConstituents.at(iTypeConst)->p4();
293 
294  //final check (nan & inf)
295  if (std::isnan(tlv_curConst.Pt()) || std::isinf(tlv_curConst.Pt())) continue;
296 
297  //ready to calc stuff
298  //basically update each of the prepared sum_* and num_* variables above,
299  // the sum HLV and the pointers to 1st, 2nd, 3rd leading constituents of current type
300  tlv_TypeConstituents += tlv_curConst;
301 
302  //helpers to reduce function calls
303  double hlp_Et = tlv_curConst.Et();
304  double hlp_Et2 = hlp_Et * hlp_Et;
305  double hlp_DeltaR = tlv_Reference.DeltaR(tlv_curConst);
306 
307  // update Sum of Et, Et^2, E and E^2
308  sum_Et += hlp_Et;
309  sum_Et2 += hlp_Et2;
310  // update Sum of Et (and E) times DeltaR, DeltaR', Angle
311  sum_EtxDR += hlp_Et * hlp_DeltaR;
312  // update Multiplicities
313  num_EFOs++;
314  }//end loop over selected EFOs
315 
316 
317 
321 
322  // naming string
323  std::string prefixVARType = "";
324 
326  //if there are no EFOs of this type in the seed, all other variables cannot be calculated to have any reasonable value
327  if( num_EFOs == 0 ) {
328  return StatusCode::SUCCESS;
329  }
330 
332  prefixVARType = m_varTypeName_PID;
333 
334  // Sorted by highest BDT score
335  for(unsigned int iTypeConst=0; iTypeConst<n_Constituents_Type; iTypeConst++) {
336 
337  double value_BDT = list_TypeConstituents_SortBDT[iTypeConst]->getBDTValue();
338  if( std::isnan(value_BDT) || std::isinf(value_BDT) ) continue;
339 
340  //correct BDT value based on BDT cut
341  if(tauConstituentType != PanTau::TauConstituent::t_Charged) {
342  double mvaCorrection = 0.0;
343  double etaCurConst = list_TypeConstituents_SortBDT[iTypeConst]->p4().Eta();
344  int etaBinIndex = m_HelperFunctions.getBinIndex(m_Config_CellBased_BinEdges_Eta, std::abs(etaCurConst));
345  int numTrack = inSeed->getTauJet()->nTracks();
346  if(numTrack == 1) { mvaCorrection = m_Config_CellBased_EtaBinned_Pi0MVACut_1prong.at(etaBinIndex); }
347  else { mvaCorrection = m_Config_CellBased_EtaBinned_Pi0MVACut_3prong.at(etaBinIndex); }
348 
349  value_BDT = value_BDT - mvaCorrection;
350  }
351 
352  std::string iConst = m_HelperFunctions.convertNumberToString(static_cast<double>(iTypeConst+1));
353  tauFeatureMap->addFeature("CellBased_" + curTypeName + "_" + prefixVARType + "_BDTValues_BDTSort_" + iConst, value_BDT);
354 
355  }
356 
359  //only execute if the constituent type is neutral
360  if(PanTau::TauConstituent::isNeutralType(tauConstituentType)) {
361 
362  TLorentzVector totalTLV_SumShots = TLorentzVector(0., 0., 0., 0.);
363  unsigned int totalPhotonsInSeed = 0;
364 
365  std::vector<TLorentzVector> allShotTLVs = std::vector<TLorentzVector>(0);
366 
367  for(unsigned int iConst=0; iConst<list_TypeConstituents_SortBDT.size(); iConst++) {
368 
369  PanTau::TauConstituent* curConst = list_TypeConstituents_SortBDT.at(iConst);
370  TLorentzVector tlv_CurConst = curConst->p4();
371  std::vector<PanTau::TauConstituent*> shotConstituents = curConst->getShots();
372  unsigned int nShots = shotConstituents.size();
373 
374  unsigned int totalPhotonsInNeutral = 0;
375  TLorentzVector tlv_SumShots = TLorentzVector(0., 0., 0., 0.);
376 
377  for(unsigned int iShot=0; iShot<nShots; iShot++) {
378  PanTau::TauConstituent* curShot = shotConstituents.at(iShot);
379  totalPhotonsInNeutral += curShot->getNPhotonsInShot();
380  tlv_SumShots += curShot->p4();
381  allShotTLVs.push_back(curShot->p4());
382  }//end loop over shots
383  totalTLV_SumShots += tlv_SumShots;
384  totalPhotonsInSeed += totalPhotonsInNeutral;
385 
386  std::string iConstStr = m_HelperFunctions.convertNumberToString(static_cast<double>(iConst+1));
387 
388  tauFeatureMap->addFeature("CellBased_" + curTypeName + "_" + prefixVARType + "_nPhotons_BDTSort_" + iConstStr, totalPhotonsInNeutral);
389 
390  if(tlv_CurConst.Et() > 0.) tauFeatureMap->addFeature("CellBased_" + curTypeName + "_" + prefixVARType + "_EtSumShotsOverConstEt_BDTSort_" + iConstStr, tlv_SumShots.Et() / tlv_CurConst.Et());
391 
392  }//end loop over constituents in tau
393 
394  //number of shots in seed
395  tauFeatureMap->addFeature("CellBased_" + curTypeName + "_" + prefixVARType + "_NPhotonsInSeed", totalPhotonsInSeed);
396 
397  }//end if check for shot info dumping
398 
399 
401  prefixVARType = m_varTypeName_Ratio;
402 
403  if(curTypeName != curTypeName_All) addFeatureWrtSeedEnergy(tauFeatureMap, "CellBased_" + curTypeName + "_" + prefixVARType + "_EtOver", sum_Et, variants_SeedEt);
404 
405  if(tlv_1st_BDT.Pt() != 0) addFeatureWrtSeedEnergy(tauFeatureMap, "CellBased_" + curTypeName + "_" + prefixVARType + "_1stBDTEtOver", tlv_1st_BDT.Et(), variants_SeedEt);
406 
407  if(tlv_1st_BDT.Pt() != 0 && sum_Et > 0.) tauFeatureMap->addFeature("CellBased_" + curTypeName + "_" + prefixVARType + "_1stBDTEtOverTypeEt", tlv_1st_BDT.Et() / sum_Et);
408 
410  prefixVARType = m_varTypeName_StdDev;
411 
412  double stddev_Et = m_HelperFunctions.stddev(sum_Et2, sum_Et, num_EFOs);
413 
414  if(stddev_Et > 0.) addFeatureWrtSeedEnergy(tauFeatureMap, "CellBased_" + curTypeName + "_" + prefixVARType + "_Et_Wrt", stddev_Et, variants_SeedEt);
415 
417  // Moment wrt X = Sum( Et * X ) / Sum(Et)
418  // ==> Named as Eflow_EFOType_JetMoment_EtX" when using Et as weight
419  // ==> Named as Eflow_EFOType_JetMoment_EX" when using E as weight
420  prefixVARType = m_varTypeName_JetMoment;
421 
422  if(sum_Et > 0.) {
423  //Using transverse energy
424  tauFeatureMap->addFeature("CellBased_" + curTypeName + "_" + prefixVARType + "_EtDR", sum_EtxDR / sum_Et);
425  tauFeatureMap->addFeature("CellBased_" + curTypeName + "_" + prefixVARType + "_EtDRxTotalEt", (sum_EtxDR / sum_Et) * variants_SeedEt.at("EtAllConsts"));
426  }
427 
428  return StatusCode::SUCCESS;
429 }
430 
431 
433  const std::map<std::string, double>& variants_SeedEt) const {
434 
435  // Prepare some short notations for variables
436  PanTau::TauFeature* tauFeatures = inSeed->getFeatures();
437 
438  //et: EFO Type
439  int et_Charged = PanTau::TauConstituent::t_Charged;
440  int et_Pi0Neut = PanTau::TauConstituent::t_Pi0Neut;
441  int et_Neutral = PanTau::TauConstituent::t_Neutral;
442 
443  bool foundIt;
444  std::vector<PanTau::TauConstituent*> list_NeutralConstituents = inSeed->getConstituentsOfType(et_Neutral, foundIt);
445 
446  // Prepare the list of names for EFO Types &
447  // the 4 momenta of the different sub systems
448  // (ie. charged, neutral subsystem, etc...)
449  std::string name_EFOType[PanTau::TauConstituent::t_nTypes];
450  double num_EFOs[PanTau::TauConstituent::t_nTypes];
451  TLorentzVector tlv_System[PanTau::TauConstituent::t_nTypes];
452  TLorentzVector tlv_1stEFO[PanTau::TauConstituent::t_nTypes];
453  TLorentzVector tlv_2ndEFO[PanTau::TauConstituent::t_nTypes];
454 
455  // get input objects to calc combined features
456  bool tlv_Sys_OK[PanTau::TauConstituent::t_nTypes];
457  bool tlv_1st_OK[PanTau::TauConstituent::t_nTypes];
458 
459  //initialize arrays with default values
460  for(unsigned int iType=0; iType<(unsigned int)PanTau::TauConstituent::t_nTypes; iType++) {
461  name_EFOType[iType] = "";
462  num_EFOs[iType] = 0.;
463  tlv_System[iType] = TLorentzVector();
464  tlv_1stEFO[iType] = TLorentzVector();
465  tlv_2ndEFO[iType] = TLorentzVector();
466  tlv_Sys_OK[iType] = false;
467  tlv_1st_OK[iType] = false;
468  }
469 
470  for(int iType=0; iType<static_cast<int>(PanTau::TauConstituent::t_nTypes); iType++) {
472 
473  tlv_System[iType] = inSeed->getSubsystemHLV(iType, tlv_Sys_OK[iType]);
474  if (!tlv_Sys_OK[iType]) continue;
475 
476  std::vector<TauConstituent*> typeConstituents = inSeed->getConstituentsOfType(iType, tlv_Sys_OK[iType]);
477  if (typeConstituents.empty()) tlv_Sys_OK[iType] = false;
478  if (!tlv_Sys_OK[iType]) continue;
479 
480  num_EFOs[iType] = typeConstituents.size();
481 
482  if (!typeConstituents.empty()) {
483  tlv_1stEFO[iType] = typeConstituents.at(0)->p4();
484  tlv_1st_OK[iType] = true;
485  } else {
486  tlv_1st_OK[iType] = false;
487  }
488 
489  if (typeConstituents.size() > 1) {
490  tlv_2ndEFO[iType] = typeConstituents.at(1)->p4();
491  }
492  }
493 
494  // From the extracted input, calc combined features
495  std::string prefixVARType = m_varTypeName_Combined;
496 
497  // Combined Type-vs-Type Features
498  // Loop over all EFO types...
499  // for every type, loop over all other types (but neglect permutations, i.e. A,B is the same as B,A)
500  // calculate ratios, angles etc...
501 
502  for(int iType=0; iType<PanTau::TauConstituent::t_nTypes; iType++) {
503 
504  if(iType == static_cast<int>(PanTau::TauConstituent::t_NoType)) continue;
505  int type_Denom = iType;
506 
507  for(int jType=0; jType<PanTau::TauConstituent::t_nTypes; jType++) {
508 
509  if(jType == static_cast<int>(PanTau::TauConstituent::t_NoType)) continue;
510  int type_Nom = jType;
511 
512  if(jType == iType) continue;
513 
514  std::string typeName_Nom = PanTau::TauConstituent::getTypeName((PanTau::TauConstituent::Type)type_Nom);
515  std::string typeName_Denom = PanTau::TauConstituent::getTypeName((PanTau::TauConstituent::Type)type_Denom);
516 
517  double sum_Et_Nom = 0.0;
518  double sum_Et_Denom = 0.0;
519  if(tlv_Sys_OK[type_Nom] && tlv_Sys_OK[type_Denom]) {
520  sum_Et_Nom = tlv_System[type_Nom].Et();
521  sum_Et_Denom = tlv_System[type_Denom].Et();
522  }
523 
524  // Fraction of leading EFO of system A wrt complete system B
525  // this is not symmetric wrt system A and B, hence do this for all combinations
526  if(tlv_1st_OK[type_Nom]) {
527  if(tlv_1stEFO[type_Nom].Et() > 0. && sum_Et_Denom > 0.) {
528  tauFeatures->addFeature("CellBased_" + prefixVARType + "_Log1st" + typeName_Nom + "EtOver" + typeName_Denom + "Et", std::log10(tlv_1stEFO[type_Nom].Et() / sum_Et_Denom) );
529  }
530  }
531 
532  //following features symmetric in system A-B, hence skip multi calculation
533  if(jType <= iType) continue;
534 
535  //Energy ratios between systems
536  if(sum_Et_Denom > 0. && sum_Et_Nom > 0.) {
537  tauFeatures->addFeature("CellBased_" + prefixVARType + "_Log" + typeName_Nom + "EtOver" + typeName_Denom + "Et", std::log10(sum_Et_Nom / sum_Et_Denom) );
538  }//end check for div by zero
539 
540  //Angles between systems
541  if(tlv_Sys_OK[type_Nom] && tlv_Sys_OK[type_Denom]) {
542  tauFeatures->addFeature("CellBased_" + prefixVARType + "_Angle" + typeName_Nom + "To" + typeName_Denom, tlv_System[type_Nom].Angle( tlv_System[type_Denom].Vect()) );
543  }//end check for valid system pointer
544 
545  if(tlv_1st_OK[type_Nom] && tlv_1st_OK[type_Denom]) {
546  //Delta R between 1st and 1st EFO
547  tauFeatures->addFeature("CellBased_" + prefixVARType + "_DeltaR1st" + typeName_Nom + "To1st" + typeName_Denom, tlv_1stEFO[type_Nom].DeltaR( tlv_1stEFO[type_Denom] ) );
548 
549  //Angles between 1st and 1st EFO
550  tauFeatures->addFeature("CellBased_" + prefixVARType + "_Angle1st" + typeName_Nom + "To1st" + typeName_Denom, tlv_1stEFO[type_Nom].Angle( tlv_1stEFO[type_Denom].Vect() ) );
551  } //end check for valid leading efo
552 
553  }//end loop over system B
554  }//end loop over system A
555 
556 
557  // Combined Selected-Type Features
558 
559  //setup arrays for combination of selected charged and neutral combinations
560  const int cTypes = 1;
561  const int nTypes = 2;
562  int index_charged[cTypes] = {et_Charged};
563  int index_neutral[nTypes] = {et_Pi0Neut, et_Neutral};
564 
565  for(int cType=0; cType<cTypes; cType++) {
566  for(int nType=0; nType<nTypes; nType++) {
567 
568  int et_c = index_charged[cType];
569  int et_n = index_neutral[nType];
570 
573 
574  if(!tlv_Sys_OK[et_c] || !tlv_Sys_OK[et_n]) continue;
575 
576  //mean Et fraction of charged+neutral system wrt total ET
577  if(num_EFOs[et_c] + num_EFOs[et_n] > 0.) {
578  double mean_cTypenTypeEt = ( tlv_System[et_c].Et() + tlv_System[et_n].Et() ) / (num_EFOs[et_c] + num_EFOs[et_n]);
579  addFeatureWrtSeedEnergy(tauFeatures, "CellBased_" + prefixVARType + "_Mean" + name_cType + name_nType + "Et_Wrt", mean_cTypenTypeEt, variants_SeedEt);
580  }
581 
582  //invariant masses
583  tauFeatures->addFeature("CellBased_" + prefixVARType + "_InvMass" + name_cType + name_nType, ( tlv_System[et_c] + tlv_System[et_n] ).M() );
584 
585  }//end loop neutral types
586  }//end loop charged types
587 
588  return StatusCode::SUCCESS;
589 }
590 
PanTau::Tool_FeatureExtractor::addCombinedFeatures
StatusCode addCombinedFeatures(PanTau::PanTauSeed *inSeed, const std::map< std::string, double > &variants_SeedEt) const
Definition: Tool_FeatureExtractor.cxx:432
PanTauSeed.h
PanTau::Tool_FeatureExtractor::calculateBasicFeatures
StatusCode calculateBasicFeatures(PanTau::PanTauSeed *inSeed) const
Definition: Tool_FeatureExtractor.cxx:147
PanTau::Tool_FeatureExtractor::fillVariantsSeedEt
static void fillVariantsSeedEt(const std::vector< PanTau::TauConstituent * > &tauConstituents, std::map< std::string, double > &variants_SeedEt)
Definition: Tool_FeatureExtractor.cxx:72
PanTau::TauConstituent::t_Neutral
@ t_Neutral
Definition: TauConstituent.h:45
PanTau::TauConstituent::Type
Type
Type enumeration to specify type of this tau constituent.
Definition: TauConstituent.h:42
PanTau::PanTauSeed::getFeatures
const PanTau::TauFeature * getFeatures() const
Definition: PanTauSeed.h:217
PanTau::PanTauSeed::getTauJet
const xAOD::TauJet * getTauJet() const
Definition: PanTauSeed.h:215
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
PanTau::PanTauSeed::getSubsystemHLV
TLorentzVector getSubsystemHLV(int tauConstituent_Type, bool &foundit)
Definition: PanTauSeed.cxx:359
PanTau::PanTauSeed::getConstituentsAsList_All
const std::vector< PanTau::TauConstituent * > & getConstituentsAsList_All() const
Definition: PanTauSeed.h:222
PanTau::TauConstituent::t_Charged
@ t_Charged
Definition: TauConstituent.h:44
PanTau::PanTauSeed::getConstituentsOfType
std::vector< PanTau::TauConstituent * > getConstituentsOfType(int tauConstituent_Type, bool &foundit)
Definition: PanTauSeed.cxx:338
met::DeltaR
@ DeltaR
Definition: METRecoCommon.h:11
PanTau::PanTauSeed::t_NoValidInputTau
@ t_NoValidInputTau
Definition: PanTauSeed.h:34
HelperFunctions.h
xAOD::TauJet_v3::nTracks
size_t nTracks(TauJetParameters::TauTrackFlag flag=TauJetParameters::TauTrackFlag::classifiedCharged) const
Definition: TauJet_v3.cxx:488
skel.it
it
Definition: skel.GENtoEVGEN.py:407
PanTau::Tool_FeatureExtractor::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: Tool_FeatureExtractor.cxx:40
asg
Definition: DataHandleTestTool.h:28
PanTau::TauFeature::addFeature
bool addFeature(const std::string &name, const double value)
adds a new feature
Definition: TauFeature.cxx:44
PanTau::TauConstituent::p4
virtual FourMom_t p4() const
The full 4-momentum of the particle as a TLorentzVector.
Definition: TauConstituent.cxx:100
PanTau::TauConstituent::getNPhotonsInShot
int getNPhotonsInShot() const
Definition: TauConstituent.cxx:252
athena.value
value
Definition: athena.py:124
PanTau::Tool_FeatureExtractor::Tool_FeatureExtractor
Tool_FeatureExtractor(const std::string &name)
Definition: Tool_FeatureExtractor.cxx:34
PanTau::Tool_FeatureExtractor::addFeatureWrtSeedEnergy
static void addFeatureWrtSeedEnergy(PanTau::TauFeature *targetMap, const std::string &featName, double numerator, const std::map< std::string, double > &denominatorMap)
Definition: Tool_FeatureExtractor.cxx:94
PanTau::TauFeature
Definition: TauFeature.h:19
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:77
TauConstituent.h
PanTau::TauConstituent::isNeutralType
static bool isNeutralType(int tauConstituentType)
Definition: TauConstituent.cxx:169
PanTau::TauConstituent::AllConstituentsName
static std::string AllConstituentsName()
Definition: TauConstituent.h:56
PanTau::TauConstituent::getTypeName
std::vector< std::string > getTypeName() const
Definition: TauConstituent.cxx:180
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
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
PanTau::Tool_FeatureExtractor::varTypeName_Shots
static const std::string varTypeName_Shots()
Definition: Tool_FeatureExtractor.h:97
Vertex.h
Tool_FeatureExtractor.h
PanTau::Tool_FeatureExtractor::calculateFeatures
StatusCode calculateFeatures(PanTau::PanTauSeed *inSeed, int tauConstituentType, const std::map< std::string, double > &variants_SeedEt) const
Definition: Tool_FeatureExtractor.cxx:241
WriteCellNoiseToCool.FullName
FullName
Definition: WriteCellNoiseToCool.py:514
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
PanTau::HelperFunctions::bindToolHandle
static StatusCode bindToolHandle(ToolHandle< T > &, std::string)
Definition: Reconstruction/PanTau/PanTauAlgs/PanTauAlgs/HelperFunctions.h:56
PanTau::PanTauSeed::t_NoConstituentsAtAll
@ t_NoConstituentsAtAll
Definition: PanTauSeed.h:35
PanTau::TauConstituent::isOfType
bool isOfType(TauConstituent::Type aType) const
Definition: TauConstituent.cxx:213
PanTau::TauConstituent::t_Pi0Neut
@ t_Pi0Neut
Definition: TauConstituent.h:46
TrackParticle.h
python.PyAthena.v
v
Definition: PyAthena.py:154
PanTau::TauFeature::addVecFeature
bool addVecFeature(const std::string &name, const std::vector< double > &value)
adds a new vector feature
Definition: TauFeature.cxx:57
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
Tool_InformationStore.h
PanTau::Tool_FeatureExtractor::execute
virtual StatusCode execute(PanTau::PanTauSeed *inSeed) const override
Definition: Tool_FeatureExtractor.cxx:108
sortTauConstituentEt
bool sortTauConstituentEt(const PanTau::TauConstituent *u, const PanTau::TauConstituent *v)
Definition: Tool_FeatureExtractor.cxx:29
PanTau::PanTauSeed::isOfTechnicalQuality
bool isOfTechnicalQuality(int pantauSeed_TechnicalQuality) const
Definition: PanTauSeed.cxx:329
PanTau::TauConstituent::t_NoType
@ t_NoType
Definition: TauConstituent.h:43
sortTauConstituentMVA
bool sortTauConstituentMVA(const PanTau::TauConstituent *u, const PanTau::TauConstituent *v)
Definition: Tool_FeatureExtractor.cxx:24
TauJet.h
PanTau::PanTauSeed::t_NoSelectedConstituents
@ t_NoSelectedConstituents
Definition: PanTauSeed.h:36
PanTau::Tool_FeatureExtractor::addConstituentMomenta
StatusCode addConstituentMomenta(PanTau::PanTauSeed *inSeed) const
Definition: Tool_FeatureExtractor.cxx:197
ReadCalibFromCool.typeName
typeName
Definition: ReadCalibFromCool.py:477
PanTau::PanTauSeed::getProtoMomentumCore
TLorentzVector getProtoMomentumCore() const
Definition: PanTauSeed.h:219
TauFeature.h
PanTau::TauConstituent::t_nTypes
@ t_nTypes
Definition: TauConstituent.h:51
PanTau::TauConstituent
Definition: TauConstituent.h:25
DiTauMassTools::Angle
double Angle(const VectorType1 &vec1, const VectorType2 &vec2)
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:61
PanTau::PanTauSeed::getConstituentsAsList_Core
const std::vector< PanTau::TauConstituent * > & getConstituentsAsList_Core() const
Definition: PanTauSeed.h:221
PanTau::TauConstituent::getCharge
int getCharge() const
Definition: TauConstituent.cxx:222
PanTau::TauConstituent::getShots
const std::vector< TauConstituent * > & getShots() const
Definition: TauConstituent.cxx:237
PanTau::PanTauSeed
Definition: PanTauSeed.h:24