ATLAS Offline Software
Loading...
Searching...
No Matches
TrackCounting.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7#include "GaudiKernel/IToolSvc.h"
8
9//#include "JetEvent/Jet.h"
19
23
24#include <cmath>
25#include <sstream>
26#include <algorithm>
27
28namespace Analysis {
29
30 typedef std::vector<double> FloatVec;
31 typedef std::vector<double>::iterator FloatVecIter;
32
33 TrackCounting::TrackCounting(const std::string& name, const std::string& n, const IInterface* p)
34 : AthAlgTool(name,n,p),
35 m_trackToVertexTool("Reco::TrackToVertex"),
36 m_trackSelectorTool("Analysis::TrackSelector"),
37 m_secVxFinderNameForV0Removal("InDetVKalVxInJetTool"),
38 m_secVxFinderNameForIPSign("InDetVKalVxInJetTool"),
39 m_SVForIPTool("Analysis::SVForIPTool"),
40 m_trackGradeFactory("Analysis::BasicTrackGradeFactory"),
42
43 declareInterface<ITagTool>(this);
44 // global configuration:
45 declareProperty("SignWithSvx", m_SignWithSvx = false);
46 declareProperty("SVForIPTool", m_SVForIPTool);
47
48 // track categories:
50 m_trackGradePartitionsDefinition.push_back("Good");
51 declareProperty("RejectBadTracks", m_RejectBadTracks = false);
52 declareProperty("flipIPSign", m_flipIP = false);
53
54 // tools:
55 declareProperty("trackSelectorTool", m_trackSelectorTool);
56 declareProperty("trackToVertexTool", m_trackToVertexTool);
57 declareProperty("trackGradeFactory", m_trackGradeFactory);
58
59 // information to persistify:
60 declareProperty("writeInfo", m_writeInfo = true);
61
62 declareProperty("truthMatchingName", m_truthMatchingName = "TruthInfo");
63 declareProperty("purificationDeltaR", m_purificationDeltaR = 0.8);
64
65 declareProperty("SecVxFinderNameForV0Removal", m_secVxFinderNameForV0Removal);
66 declareProperty("SecVxFinderNameForIPSign", m_secVxFinderNameForIPSign);
67
68 declareProperty("TrackToVertexIPEstimator",m_trackToVertexIPEstimator);
69 declareProperty("unbiasIPEstimation",m_unbiasIPEstimation);
70 }
71
73 for (size_t i = 0; i < m_trackGradePartitions.size(); i++)
74 delete m_trackGradePartitions.at(i);
75 }
76
77
79
81 if ( m_trackToVertexTool.retrieve().isFailure() ) {
82 ATH_MSG_FATAL("#BTAG# Failed to retrieve tool " << m_trackToVertexTool);
83 return StatusCode::FAILURE;
84 } else {
85 ATH_MSG_DEBUG("#BTAG# Retrieved tool " << m_trackToVertexTool);
86 }
87
88 if(m_SVForIPTool.retrieve().isFailure()) {
89 ATH_MSG_FATAL( "#BTAG# Failed to retrieve tool " << m_SVForIPTool);
90 } else {
91 ATH_MSG_DEBUG("#BTAG# Retrieved tool " << m_SVForIPTool);
92 }
93
94 if(m_trackToVertexIPEstimator.retrieve().isFailure()) {
95 ATH_MSG_FATAL( "#BTAG# Failed to retrieve tool " << m_trackToVertexIPEstimator);
96 } else {
97 ATH_MSG_DEBUG("#BTAG# Retrieved tool " << m_trackToVertexIPEstimator);
98 }
99
101 if ( m_trackSelectorTool.retrieve().isFailure() ) {
102 ATH_MSG_FATAL( "#BTAG# Failed to retrieve tool " << m_trackSelectorTool);
103 return StatusCode::FAILURE;
104 } else {
105 ATH_MSG_DEBUG("#BTAG# Retrieved tool " << m_trackSelectorTool);
106 }
107
109 if ( m_trackGradeFactory.retrieve().isFailure() ) {
110 ATH_MSG_FATAL( "#BTAG# Failed to retrieve tool " << m_trackGradeFactory);
111 return StatusCode::FAILURE;
112 } else {
113 ATH_MSG_DEBUG("#BTAG# Retrieved tool " << m_trackGradeFactory);
114 }
115
117 int nbPart = m_trackGradePartitionsDefinition.size();
118 ATH_MSG_DEBUG("#BTAG# Defining " << nbPart <<" track partitions: ");
119 for(int i=0;i<nbPart;i++) {
120 TrackGradePartition* part(0);
121 try {
123 }
124 catch(std::string error) {
125 ATH_MSG_ERROR("#BTAG# Reported error " << error);
126 ATH_MSG_ERROR("#BTAG# List of categories provided to TrackCounting by jO : ");
127
128 for (int l=0;l<nbPart;l++) {
129 ATH_MSG_ERROR("#BTAG# string " << m_trackGradePartitionsDefinition[l]);
130 }
131
132 ATH_MSG_ERROR("#BTAG# List of categories provided by the TrackGradeFactory " << m_trackGradeFactory);
133
134 const TrackGradesDefinition &trackFactoryGradesDefinition = m_trackGradeFactory->getTrackGradesDefinition();
135 const std::vector<TrackGrade> &gradeList = trackFactoryGradesDefinition.getList();
136
137 std::vector<TrackGrade>::const_iterator listIter=gradeList.begin();
138 std::vector<TrackGrade>::const_iterator listEnd=gradeList.end();
139
140 for ( ; listIter !=listEnd ; ++listIter ) {
141 ATH_MSG_ERROR("#BTAG# n. " << (*listIter).gradeNumber() << " string " << (*listIter).gradeString());
142 }
143
144 ATH_MSG_ERROR("#BTAG# Terminating now... ");
145 return StatusCode::FAILURE;
146 }
147 ATH_MSG_INFO("#BTAG# " << (*part));
148 m_trackGradePartitions.push_back(part);
149 }
150 return StatusCode::SUCCESS;
151 }
152
153
155
156 return StatusCode::SUCCESS;
157 }
158
159
161
163 std::string author = jetToTag.jetAuthor();
164 ATH_MSG_VERBOSE("#BTAG# Using jet type " << author);
165
166 m_tracksInJet.clear();
167 int nbPart = m_trackGradePartitionsDefinition.size();
168
169 std::vector<const Trk::Track*> TrkFromV0;
170 Amg::Vector3D SvxDirection;
171 bool canUseSvxDirection=false;
172
174 if (m_SignWithSvx) {
175 m_SVForIPTool->getDirectionFromSecondaryVertexInfo(SvxDirection,canUseSvxDirection,//output
176 jetToTag,m_secVxFinderNameForIPSign,m_priVtx->recVertex());//input
177 }
178
180 if (m_RejectBadTracks) {
181 m_SVForIPTool->getTrkFromV0FromSecondaryVertexInfo(TrkFromV0,//output
182 jetToTag,m_secVxFinderNameForV0Removal);//input
183 }
184
185 ATH_MSG_VERBOSE("#BTAG# TrkFromV0 : number of reconstructed bad tracks: " << TrkFromV0.size());
186
188 int nbTrack = 0;
189 std::vector<const xAOD::TrackParticle*>* trackVector = NULL;
190 const Analysis::TrackAssociation *trkInJet = jetToTag.getAssociation<TrackAssociation>("Tracks");
191 if(!trkInJet){
192 ATH_MSG_WARNING("#BTAG# Could not find tracks in jets");
193 }
194 else{
195 trackVector = jetToTag.getAssociation<TrackAssociation>("Tracks")->tracks();
196 std::vector<const xAOD::TrackParticle*>::iterator jetItr;
197 for( jetItr = trackVector->begin(); jetItr != trackVector->end() ; ++jetItr ) {
198 const xAOD::TrackParticle * aTemp = *jetItr;
199 nbTrack++;
200 if( m_trackSelectorTool->selectTrack(m_priVtx->recVertex().position(), aTemp) ) {
201
202 TrackGrade * theGrade = m_trackGradeFactory->getGrade(*aTemp,
203 jetToTag.p4() );
204
205 ATH_MSG_VERBOSE("#BTAG# result of selectTrack is OK, grade= " << (std::string)(*theGrade));
206
207 bool tobeUsed = false;
208 for(int i=0;i<nbPart;i++) {
209 if (std::find( (m_trackGradePartitions[i]->grades()).begin(),
210 (m_trackGradePartitions[i]->grades()).end(),
211 *theGrade )
212 != (m_trackGradePartitions[i]->grades()).end()) tobeUsed = true;
213 }
214 // is it a bad track ?
215 if (std::find(TrkFromV0.begin(),TrkFromV0.end(),*aTemp->track()) != TrkFromV0.end()) {
216 ATH_MSG_VERBOSE("#BTAG# Bad track in jet, pt = " << aTemp->pt() << " eta = " << aTemp->eta() << " phi = " << aTemp->phi());
217 if (m_RejectBadTracks) tobeUsed = false;
218 }
219 if (tobeUsed) m_tracksInJet.push_back(GradedTrack(aTemp, *theGrade));
220 delete theGrade;
221 theGrade=0;
222 }
223 } // end loop on trakparticles
224
225 delete trackVector;
226 }
227
228 ATH_MSG_VERBOSE("#BTAG# #tracks = " << nbTrack);
229 ATH_MSG_VERBOSE("#BTAG# the z of the primary Vertex= " << m_priVtx->recVertex().position().z());
230
232 Amg::Vector3D jetDirection(jetToTag.px(),jetToTag.py(),jetToTag.pz());
233 Amg::Vector3D unit = jetDirection.unit();
234 if (m_SignWithSvx && canUseSvxDirection) {
235 unit = SvxDirection.unit();
236 ATH_MSG_DEBUG("#BTAG# Using direction from sec vertex finder tool '"
238 << " phi: " << unit.phi()
239 << " theta: " << unit.theta()
240 << " instead of jet direction phi: " << jetDirection.phi()
241 << " theta: " << jetDirection.theta());
242 }
243
244 FloatVec vectD0Signi;
245 FloatVec vectD0Signi_abs;
246 // reserve approximate space (optimization):
247 const int nbTrackMean = 3;
248 vectD0Signi.reserve(nbTrackMean);
249 vectD0Signi_abs.reserve(nbTrackMean);
250
251 for (std::vector<GradedTrack>::iterator trkItr = m_tracksInJet.begin();
252 trkItr != m_tracksInJet.end(); ++trkItr) {
253 const xAOD::TrackParticle* trk = (*trkItr).track;
254
255 double d0wrtPriVtx(0.);
256 double d0ErrwrtPriVtx(1.);
257 double signOfIP(1.);
258
259 /* use new Tool for "unbiased" IP estimation */
261 if(myIPandSigma==0) {
262 ATH_MSG_WARNING("#BTAG# trackToVertexIPEstimator failed !");
263 } else {
264 d0wrtPriVtx=myIPandSigma->IPd0;
265 d0ErrwrtPriVtx=myIPandSigma->sigmad0;
266 delete myIPandSigma;
267 myIPandSigma=0;
268 }
269
271 signOfIP=m_trackToVertexIPEstimator->get2DLifetimeSignOfTrack(trk->perigeeParameters(),unit,m_priVtx->recVertex());
272
273 if (m_flipIP) signOfIP = -signOfIP; // A.X.
274
276 double sd0 = signOfIP*fabs(d0wrtPriVtx);
277 double sd0significance = signOfIP*fabs(d0wrtPriVtx/d0ErrwrtPriVtx);
278
279 vectD0Signi.push_back(sd0significance);
280 vectD0Signi_abs.push_back( fabs(sd0significance) );
281
282 ATH_MSG_VERBOSE("#BTAG# TrackCounting: Trk: grade= " << (std::string)(*trkItr).grade
283 << " Eta= " << trk->eta() << " Phi= " << trk->phi() << " pT= " << trk->pt()
284 << " d0= " << sd0
285 << "+-" << d0ErrwrtPriVtx
286 << " d0sig= " << sd0significance );
287
288 } // end loop on gradedtracks
289
290
292 sort( vectD0Signi.begin(), vectD0Signi.end(), m_greater<float> );
293 sort( vectD0Signi_abs.begin(), vectD0Signi_abs.end(), m_greater<float> );
294
295
297 std::string instanceName("TrackCounting2D");
298 if (m_flipIP) instanceName += "Neg";// A.X.
299 TrackCountingInfo* infoTrackCounting = NULL;
300
301 if(m_writeInfo) {
302 infoTrackCounting = new TrackCountingInfo(instanceName);
303
304 int ntrk = vectD0Signi.size();
305 infoTrackCounting->setnTracks( ntrk );
306
307 ATH_MSG_VERBOSE("#BTAG# Filling TrackCountingInfo...");
308 ATH_MSG_DEBUG("#BTAG# " << ntrk << " tracks used for TrackCounting, ordered ip2d significance / |ip2d significance|:" );
309 for(uint i=0; i<vectD0Signi.size(); i++){
310 ATH_MSG_DEBUG("#BTAG# trk " << i+1 << "/" << ntrk << ": " << vectD0Signi.at(i) << " / " << vectD0Signi_abs.at(i));
311 }
312 if( ntrk>=2 ){
313 ATH_MSG_DEBUG("#BTAG# filling 2nd / 2nd abs: " << vectD0Signi.at(1) << " / " << vectD0Signi_abs.at(1));
314 infoTrackCounting->setd0sig_2nd( vectD0Signi.at(1) );
315 infoTrackCounting->setd0sig_abs_2nd( vectD0Signi_abs.at(1) );
316 }
317 if( ntrk>=3 ){
318 ATH_MSG_DEBUG("#BTAG# filling 3rd / 3rd abs: " << vectD0Signi.at(2) << " / " << vectD0Signi_abs.at(2));
319 infoTrackCounting->setd0sig_3rd( vectD0Signi.at(2) );
320 infoTrackCounting->setd0sig_abs_3rd( vectD0Signi_abs.at(2) );
321 }
322 }
323
328 if(infoTrackCounting){
329 std::vector<double> v_tofill;
330 double tofill = exp(-20.);
331 if(vectD0Signi.size()>=2){
332 tofill = exp(vectD0Signi.at(1));
333 infoTrackCounting->makeValid();
334 }
335 v_tofill.push_back( tofill );
336 v_tofill.push_back(1.);
337 infoTrackCounting->setTagLikelihood( v_tofill );
338 jetToTag.addInfo( infoTrackCounting );
339 }
340
341 m_tracksInJet.clear();
342
343 return;
344 }
345
346}//end namespace
347
348
349
const PlainObject unit() const
This is a plugin that makes Eigen look like CLHEP & defines some convenience methods.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
unsigned int uint
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
virtual void makeValid()
sets the isValid flag to true, cannot be reversed!
Definition BaseTagInfo.h:77
virtual void setTagLikelihood(const std::vector< double > &)
Return and set methods for the likelihood.
Definition BaseTagInfo.h:85
Class to hold TrackCounting tagger results.
void setd0sig_2nd(float d0sig_2nd)
void setd0sig_abs_2nd(float d0sig_abs_2nd)
void setd0sig_3rd(float d0sig_3rd)
void setd0sig_abs_3rd(float d0sig_abs_3rd)
std::vector< TrackGradePartition * > m_trackGradePartitions
ToolHandle< Reco::ITrackToVertex > m_trackToVertexTool
TrackToVertex tool.
std::vector< GradedTrack > m_tracksInJet
The jet of TrackParticles to be tagged.
std::string m_secVxFinderNameForV0Removal
std::string m_truthMatchingName
std::string m_secVxFinderNameForIPSign
TrackCounting(const std::string &, const std::string &, const IInterface *)
std::vector< std::string > m_trackGradePartitionsDefinition
track classification.
ToolHandle< SVForIPTool > m_SVForIPTool
ToolHandle< ITrackGradeFactory > m_trackGradeFactory
ToolHandle for the ITrackGradeFactory tool.
virtual ~TrackCounting()
Implementations of the methods defined in the abstract base class.
const Trk::VxCandidate * m_priVtx
Storage for the primary vertex.
void tagJet(xAOD::Jet &jetToTag)
called by BJetBuilder
static bool m_greater(T a, T b)
sort algorithm for vectors
ToolHandle< TrackSelector > m_trackSelectorTool
Track selection cuts for TrackCounting.
bool m_writeInfo
write tagging info to info class
bool m_unbiasIPEstimation
option to unbias IP estimation (remove track from vertex)
bool m_RejectBadTracks
possibility to exclude Bad Tracks found with SVTagger and possibility to use the sign of the impact p...
ToolHandle< Trk::ITrackToVertexIPEstimator > m_trackToVertexIPEstimator
Tool for the estimation of the IPs to the Vertex.
const std::vector< TrackGrade > & getList() const
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
virtual FourMom_t p4() const
The full 4-momentum of the particle.
Definition Jet_v1.cxx:71
float py() const
The y-component of the jet's momentum.
Definition Jet_v1.cxx:94
float px() const
The x-component of the jet's momentum.
Definition Jet_v1.cxx:90
float pz() const
The z-component of the jet's momentum.
Definition Jet_v1.cxx:99
const Trk::Perigee & perigeeParameters() const
Returns the Trk::MeasuredPerigee track parameters.
const Trk::Track * track() const
Returns a pointer (which can be NULL) to the Trk::Track which was used to make this TrackParticle.
virtual double phi() const override final
The azimuthal angle ( ) of the particle (has range to .)
virtual double pt() const override final
The transverse momentum ( ) of the particle.
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
Eigen::Matrix< double, 3, 1 > Vector3D
The namespace of all packages in PhysicsAnalysis/JetTagging.
std::vector< double >::iterator FloatVecIter
std::vector< double > FloatVec
Jet_v1 Jet
Definition of the current "jet version".
TrackParticle_v1 TrackParticle
Reference the current persistent version: