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