ATLAS Offline Software
CombinerTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
10 
13 #include "xAODJet/Jet.h"
14 
15 namespace Analysis
16 {
17 
18 CombinerTool::CombinerTool( const std::string& t, const std::string& n, const IInterface* p ) :
19  AthAlgTool( t, n, p )
20 {
21  declareInterface<ICombinerTool>( this );
22 }
23 
25 {}
26 
28 {
29  return StatusCode::SUCCESS;
30 }
31 
33 {
34  return StatusCode::SUCCESS;
35 }
36 
40 // std::vector<double> CombinerTool::simpleCombine(const JetTagInfoBase* iTagInfo) const
41 // {
42 // std::vector<double> likelihood;
43 // // just to make sure
44 // if (iTagInfo==0) {
45 // ATH_MSG_ERROR("#BTAG# Never give a NULL pointer to JetTagTools/CombinerTool::simpleCombine(...)! Fix it! I segfault!");
46 // }
47 // if (iTagInfo->isValid())
48 // {
49 // likelihood = iTagInfo->tagLikelihood();
50 
51 // /** sum the likelihood vector for normalization */
52 // double sum( 0. );
53 // for ( std::vector<double>::iterator lhItr = likelihood.begin();
54 // lhItr != likelihood.end(); ++lhItr )
55 // {
56 // sum += ( *lhItr );
57 // }
58 
59 // for ( std::vector<double>::iterator lhItr = likelihood.begin();
60 // lhItr != likelihood.end(); ++lhItr )
61 // {
62 // ( *lhItr ) /= sum;
63 // }
64 // }
65 // else
66 // {
67 // // if not valid return -1. as sig and bkg
68 // likelihood.push_back(-1.);
69 // likelihood.push_back(-1.);
70 // }
71 // return likelihood;
72 // }
73 
77 std::vector<double> CombinerTool::simpleCombine(const xAOD::Jet& particleJet, const std::string& infoKey) const
78 {
79  std::vector<double> likelihood;
80  if (particleJet.tagInfo(infoKey) == 0)
81  {
82  // no combine possible so we also dont know how many event types (normally 2: sig and bkg)
83  likelihood.push_back(-1.);
84  likelihood.push_back(-1.);
85  return likelihood;
86  }
87  else
88  {
89  return simpleCombine(particleJet.tagInfo(infoKey));
90  }
91 }
92 
96 std::vector<double> CombinerTool::simpleCombine( const xAOD::Jet& particleJet,
97  const std::vector<std::string>& combineTheseTaggers ) const
98 {
99  bool combine(true);
100  std::vector<double> likelihood;
102  if ( particleJet.jetTagInfoVector().size() == 0 )
103  {
104  ATH_MSG_WARNING("#BTAG# JetTagInfoBase vector is ZERO. Nothing to combine!");
105  combine = false;
106  }
107 
109  if ( particleJet.tagInfo("TruthInfo") != 0 && particleJet.jetTagInfoVector().size() == 1 )
110  {
111  ATH_MSG_DEBUG("#BTAG# The only object in ITagInfo vector is TruthInfo. No combine possible.");
112  combine = false;
113  }
114 
122  if (combine)
123  {
124  bool firstValidTagger(true);
125  int count(0);
126  for ( std::vector<std::string>::const_iterator strItr = combineTheseTaggers.begin(); strItr != combineTheseTaggers.end(); ++strItr )
127  {
128  ATH_MSG_VERBOSE("#BTAG# Combining likelihood from these taggers " << *strItr);
129  const JetTagInfoBase* infoObject(particleJet.tagInfo(*strItr));
130  if ( infoObject != 0 )
131  {
132  if (infoObject->isValid())
133  {
134  if (firstValidTagger)
135  {
136  likelihood.resize( infoObject->tagLikelihood().size() );
137  for ( std::vector<double>::iterator itr = likelihood.begin() ;
138  itr != likelihood.end() ; ++itr )
139  {
140  ( *itr ) = 1.;
141  }
142  firstValidTagger=false;
143  }
144  count++;
145  const std::vector<double>& tmpVector = infoObject->tagLikelihood();
146 
147  unsigned int numInputFiles( 0 );
148  for ( std::vector<double>::const_iterator tmpItr = tmpVector.begin();
149  tmpItr != tmpVector.end(); ++tmpItr )
150  {
151  if (likelihood.size()>=numInputFiles+1)
152  {
153  likelihood[ numInputFiles ] *= tmpVector[ numInputFiles ];
154  }
155  numInputFiles++;
156  }
157  }
158  else
159  ATH_MSG_DEBUG("#BTAG# TagTool " << *strItr << " does exist but is not valid.");
160  }
161  else
162  ATH_MSG_DEBUG("#BTAG# TagTool " << *strItr << " does not exist.");
163  }
164 
166  if (count == 0)
167  {
168  // no combine possible so we also dont know how many event types (normally 2: sig and bkg)
169  likelihood.clear();
170  likelihood.resize(0); // also resize because i am not 100% sure what clear() does to a resized vector :-)
171  likelihood.push_back(-1.);
172  likelihood.push_back(-1.);
173  }
175  else if (count > 0)
176  {
177  double sum( 0. );
178  for ( std::vector<double>::iterator lhItr = likelihood.begin();
179  lhItr != likelihood.end(); ++lhItr )
180  {
181  sum += ( *lhItr );
182  }
183 
184  for ( std::vector<double>::iterator lhItr = likelihood.begin();
185  lhItr != likelihood.end(); ++lhItr )
186  {
187  ( *lhItr ) /= sum;
188  }
189  }
190  }
191  else
192  {
193  // no combine possible so we also dont know how many event types (normally 2: sig and bkg)
194  likelihood.push_back(-1.);
195  likelihood.push_back(-1.);
196  }
197  return likelihood;
198 }
199 
200 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
Jet.h
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
Analysis::CombinerTool::initialize
StatusCode initialize()
AlgTool initailize method.
Definition: CombinerTool.cxx:27
JetTagInfoBase.h
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
Analysis::ITagInfo::tagLikelihood
virtual const std::vector< double > & tagLikelihood(void) const =0
set the weight for one tagger
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
JetTagInfoBase
Definition: JetTagInfoBase.h:56
FlavorTagDiscriminants::combine
size_t combine(size_t lhs, size_t rhs)
Definition: hash.h:21
Analysis::CombinerTool::CombinerTool
CombinerTool(const std::string &, const std::string &, const IInterface *)
Definition: CombinerTool.cxx:18
convertTimingResiduals.sum
sum
Definition: convertTimingResiduals.py:55
CombinerTool.h
beamspotman.n
n
Definition: beamspotman.py:731
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
Analysis::CombinerTool::finalize
StatusCode finalize()
AlgTool finalize method.
Definition: CombinerTool.cxx:32
Analysis
The namespace of all packages in PhysicsAnalysis/JetTagging.
Definition: BTaggingCnvAlg.h:20
Analysis::CombinerTool::simpleCombine
virtual std::vector< double > simpleCombine(const xAOD::Jet &particleJet, const std::string &infoKey) const
all tools used same samples (1 signal, N background) to create the LH histograms
Definition: CombinerTool.cxx:77
Analysis::ITagInfo::isValid
virtual bool isValid() const =0
returns the infoType of the info objects.
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
AthAlgTool
Definition: AthAlgTool.h:26
Analysis::CombinerTool::~CombinerTool
virtual ~CombinerTool()
Definition: CombinerTool.cxx:24