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