ATLAS Offline Software
TrackClassifier.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
8 
9 #include <numeric>
10 
11 namespace FlavorTagDiscriminants {
12 TrackClassifier :: TrackClassifier (const std::string& name) : AsgTool (name)
13 {
14  declareProperty( "NNModelFilepath", m_NNModelFilepath = "neural_net.json", "Trained and exported ltwnn model");
15 }
16 
18 
20 {
21  // load the trained model
22  ATH_MSG_INFO ("Loading lwtnn model for track classification: " << m_NNModelFilepath);
23  std::string shortPathToModelFile = m_NNModelFilepath;
24  std::string fullPathToModelFile = PathResolverFindCalibFile(shortPathToModelFile);
25  std::ifstream inFileNN(fullPathToModelFile);
26  lwt::GraphConfig config(lwt::parse_json_graph(inFileNN));
27  m_lwtnn_network.reset(new lwt::LightweightGraph(config));
28  inFileNN.close();
29 
30  return StatusCode::SUCCESS;
31 }
32 
34  uint8_t val;
35  bool ok = track->summaryValue(val, info);
36  if (!ok) throw std::logic_error("problem getting track summary value");
37  return val;
38 }
39 
40 
42 {
43  std::map<std::string, double> track_outputs = ComputeScore( track, jet );
44  double HF_score = track_outputs["FromB"]+track_outputs["FromBC"]+track_outputs["FromC"];
45  return HF_score;
46 }
47 
48 
49 std::map<std::string, double> TrackClassifier::ComputeScore(const xAOD::TrackParticle* track, const xAOD::Jet* jet) const
50 {
51  double dphi = -(jet->p4()).DeltaPhi(track->p4());
52  double deta = -(jet->eta() - track->eta());
53  double dr = (track->p4()).DeltaR(jet->p4());
54  double ptfrac = (track->pt())/(jet->pt());
55 
56  static const SG::AuxElement::ConstAccessor<float> AMVFWeightPVAcc ("AMVFWeightPV");
57 
58  // Build dictionary of inputs for lwtnn to use
59  // It is ok to fill this with more variables than the model uses
60  // as long as no variables are missing
61  std::map<std::string, double> track_inputs{
62  {"eta_btagJes", (double) jet->eta()},
63  {"log_pt_btagJes", (double) std::log(jet->pt())},
64  {"dphi", (double) dphi},
65  {"deta", (double) deta},
66  {"log_dr", (double) std::log(dr)},
67  {"log_ptfrac", (double) std::log(ptfrac)},
68  {"qOverP", (double) track->qOverP()},
69  {"numberOfPixelHits", (double) get(track, xAOD::numberOfPixelHits)},
70  {"numberOfSCTHits", (double) get(track, xAOD::numberOfSCTHits)},
71  {"numberOfInnermostPixelLayerHits", (double) get(track, xAOD::numberOfInnermostPixelLayerHits)},
72  {"numberOfNextToInnermostPixelLayerHits", (double) get(track, xAOD::numberOfNextToInnermostPixelLayerHits)},
73  {"numberOfInnermostPixelLayerSharedHits", (double) get(track, xAOD::numberOfInnermostPixelLayerSharedHits)},
74  {"numberOfInnermostPixelLayerSplitHits", (double) get(track, xAOD::numberOfInnermostPixelLayerSplitHits)},
75  {"numberOfPixelSharedHits", (double) get(track, xAOD::numberOfPixelSharedHits)},
76  {"numberOfPixelSplitHits", (double) get(track, xAOD::numberOfPixelSplitHits)},
77  {"numberOfSCTSharedHits", (double) get(track, xAOD::numberOfSCTSharedHits)},
78  {"numberOfPixelHoles", (double) get(track, xAOD::numberOfPixelHoles)},
79  {"numberOfSCTHoles", (double) get(track, xAOD::numberOfSCTHoles)},
80  {"AMVFWeightPV", (double) AMVFWeightPVAcc(*track)}
81  };
82 
83  // Set up the nodes used for inputs
84  std::map<std::string, std::map<std::string, double> > inputs {
85  {"track_inputs", track_inputs}
86  };
87 
88  // Evaluate the network
90 
91  std::map<std::string, double> track_outputs{
92  {"Pileup",(double) discriminant["Pileup"]},
93  {"Fake",(double) discriminant["Fake"]},
94  {"Primary",(double) discriminant["Primary"]},
95  {"FromB",(double) discriminant["FromB"]},
96  {"FromBC",(double) discriminant["FromBC"]},
97  {"FromC",(double) discriminant["FromC"]},
98  {"FromTau",(double) discriminant["FromTau"]},
99  {"OtherSecondary",(double) discriminant["OtherSecondary"]}
100  };
101 
102  return track_outputs;
103 }
104 
105 
106 bool TrackClassifier::pass_cut(const double score, const xAOD::Jet* jet) const
107 {
108  static constexpr float const& MeVtoGeV = 1e-3;
109  double pt=jet->pt()*MeVtoGeV;
110  bool pass=false;
111 
112  if(pt>=std::prev(m_WPcuts.end())->first){
113  if(score > std::prev(m_WPcuts.end())->second)
114  pass=true;
115  }
116  else{
117  for(auto it = m_WPcuts.begin(); it != std::prev(m_WPcuts.end()); ++it){
118  auto nit = std::next(it);
119  if(pt>=it->first && pt<nit->first){
120  if(score > nit->second){
121  pass=true;
122  break;
123  }
124  }
125  }
126  }
127 
128  return pass;
129 }
130 
131 
133 {
134  double HF_nnScore = compute_HF_Score( track, jet );
135  return pass_cut(HF_nnScore, jet);
136 }
137 
138 }
grepfile.info
info
Definition: grepfile.py:38
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
xAOD::numberOfPixelHoles
@ numberOfPixelHoles
number of pixel layers on track with absence of hits [unit8_t].
Definition: TrackingPrimitives.h:261
xAOD::numberOfInnermostPixelLayerSplitHits
@ numberOfInnermostPixelLayerSplitHits
number of Pixel 0th layer barrel hits split by cluster splitting
Definition: TrackingPrimitives.h:240
FlavorTagDiscriminants::TrackClassifier::m_WPcuts
const std::map< double, double > m_WPcuts
Definition: TrackClassifier.h:49
xAOD::numberOfSCTSharedHits
@ numberOfSCTSharedHits
number of SCT hits shared by several tracks [unit8_t].
Definition: TrackingPrimitives.h:272
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
xAOD::uint8_t
uint8_t
Definition: Muon_v1.cxx:557
FlavorTagDiscriminants
This file contains "getter" functions used for accessing tagger inputs from the EDM.
Definition: AssociationEnums.h:11
FlavorTagDiscriminants::TrackClassifier::ComputeScore
virtual std::map< std::string, double > ComputeScore(const xAOD::TrackParticle *track, const xAOD::Jet *jet) const override
Definition: TrackClassifier.cxx:49
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
met::DeltaR
@ DeltaR
Definition: METRecoCommon.h:11
skel.it
it
Definition: skel.GENtoEVGEN.py:396
test_pyathena.pt
pt
Definition: test_pyathena.py:11
CP::MeVtoGeV
constexpr float MeVtoGeV
Definition: IsolationCloseByCorrectionTool.cxx:33
xAOD::numberOfPixelHits
@ numberOfPixelHits
these are the pixel hits, including the b-layer [unit8_t].
Definition: TrackingPrimitives.h:259
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:55
python.TurnDataReader.dr
dr
Definition: TurnDataReader.py:112
FlavorTagDiscriminants::TrackClassifier::TrackClassifier
TrackClassifier(const std::string &name)
Definition: TrackClassifier.cxx:12
FlavorTagDiscriminants::TrackClassifier::~TrackClassifier
virtual ~TrackClassifier()
Definition: TrackClassifier.cxx:17
FlavorTagDiscriminants::TrackClassifier::selectTrack
virtual bool selectTrack(const xAOD::TrackParticle *track, const xAOD::Jet *jet) const override
Definition: TrackClassifier.cxx:132
postInclude.inputs
inputs
Definition: postInclude.SortInput.py:15
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
FlavorTagDiscriminants::TrackClassifier::m_NNModelFilepath
std::string m_NNModelFilepath
Definition: TrackClassifier.h:44
FlavorTagDiscriminants::TrackClassifier::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: TrackClassifier.cxx:19
xAOD::numberOfPixelSharedHits
@ numberOfPixelSharedHits
number of Pixel all-layer hits shared by several tracks [unit8_t].
Definition: TrackingPrimitives.h:262
xAOD::SummaryType
SummaryType
Enumerates the different types of information stored in Summary.
Definition: TrackingPrimitives.h:228
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
fillPileUpNoiseLumi.next
next
Definition: fillPileUpNoiseLumi.py:52
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
FlavorTagDiscriminants::TrackClassifier::get
int get(const xAOD::TrackParticle *part, xAOD::SummaryType info) const
Definition: TrackClassifier.cxx:33
TrackClassifier.h
FlavorTagDiscriminants::TrackClassifier::m_lwtnn_network
std::unique_ptr< lwt::LightweightGraph > m_lwtnn_network
Definition: TrackClassifier.h:43
xAOD::numberOfPixelSplitHits
@ numberOfPixelSplitHits
number of Pixel all-layer hits split by cluster splitting [unit8_t].
Definition: TrackingPrimitives.h:263
xAOD::double
double
Definition: CompositeParticle_v1.cxx:159
xAOD::numberOfSCTHoles
@ numberOfSCTHoles
number of SCT holes [unit8_t].
Definition: TrackingPrimitives.h:270
FlavorTagDiscriminants::TrackClassifier::compute_HF_Score
virtual double compute_HF_Score(const xAOD::TrackParticle *track, const xAOD::Jet *jet) const override
Definition: TrackClassifier.cxx:41
xAOD::numberOfNextToInnermostPixelLayerHits
@ numberOfNextToInnermostPixelLayerHits
these are the hits in the 1st pixel barrel layer
Definition: TrackingPrimitives.h:248
PathResolver.h
TauJetParameters::discriminant
@ discriminant
Definition: TauJetParameters.h:166
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
FlavorTagDiscriminants::TrackClassifier::pass_cut
bool pass_cut(const double score, const xAOD::Jet *jet) const
Definition: TrackClassifier.cxx:106
PathResolverFindCalibFile
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Definition: PathResolver.cxx:431
xAOD::score
@ score
Definition: TrackingPrimitives.h:513
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
lwtDev::parse_json_graph
GraphConfig parse_json_graph(std::istream &json)
Definition: parse_json.cxx:71
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
DeMoScan.first
bool first
Definition: DeMoScan.py:536
config
std::vector< std::string > config
Definition: fbtTestBasics.cxx:74
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
xAOD::numberOfInnermostPixelLayerSharedHits
@ numberOfInnermostPixelLayerSharedHits
number of Pixel 0th layer barrel hits shared by several tracks.
Definition: TrackingPrimitives.h:239
xAOD::numberOfSCTHits
@ numberOfSCTHits
number of hits in SCT [unit8_t].
Definition: TrackingPrimitives.h:268
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
ValueMap
std::map< std::string, double > ValueMap
Definition: TauDecayModeNNClassifier.cxx:22
AuxElement.h
Base class for elements of a container that can have aux data.
xAOD::numberOfInnermostPixelLayerHits
@ numberOfInnermostPixelLayerHits
these are the hits in the 0th pixel barrel layer
Definition: TrackingPrimitives.h:237