ATLAS Offline Software
Loading...
Searching...
No Matches
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
15namespace Analysis
16{
17
18CombinerTool::CombinerTool( const std::string& t, const std::string& n, const IInterface* p ) :
19 AthAlgTool( t, n, p )
20{
21 declareInterface<ICombinerTool>( this );
22}
23
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
77std::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
96std::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}
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
StatusCode initialize()
AlgTool initailize method.
CombinerTool(const std::string &, const std::string &, const IInterface *)
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
StatusCode finalize()
AlgTool finalize method.
virtual const std::vector< double > & tagLikelihood(void) const =0
set the weight for one tagger
virtual bool isValid() const =0
returns the infoType of the info objects.
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
This is the abstract base class for additional information to be put into the JetTag class.
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:146
The namespace of all packages in PhysicsAnalysis/JetTagging.
Jet_v1 Jet
Definition of the current "jet version".