001 #include "JetTagTools/TrackCounting.h"
002
003 #include "CLHEP/Vector/ThreeVector.h"
004
005 #include "GaudiKernel/IToolSvc.h"
006
007 #include "JetEvent/Jet.h"
008 #include "JetTagEvent/TrackAssociation.h"
009 #include "JetTagInfo/TrackCountingInfo.h"
010 #include "JetTagInfo/TruthInfo.h"
011 #include "JetTagInfo/TrackGrade.h"
012 #include "JetTagInfo/TrackGradesDefinition.h"
013 #include "JetTagTools/TrackSelector.h"
014 #include "JetTagTools/GradedTrack.h"
015 #include "JetTagTools/SVForIPTool.h"
016 #include "JetTagTools/ITrackGradeFactory.h"
017
018 #include "Navigation/NavigationToken.h"
019 #include "ITrackToVertex/ITrackToVertex.h"
020 #include "TrkVertexFitterInterfaces/ITrackToVertexIPEstimator.h"
021
022 #include <cmath>
023 #include <sstream>
024 #include <algorithm>
025
026 namespace Analysis {
027
028 typedef std::vector<double> FloatVec;
029 typedef std::vector<double>::iterator FloatVecIter;
030
031 TrackCounting::TrackCounting(const std::string& name, const std::string& n, const IInterface* p)
032 : AthAlgTool(name,n,p),
033 m_trackToVertexTool("Reco::TrackToVertex"),
034 m_trackSelectorTool("Analysis::TrackSelector"),
035 m_secVxFinderNameForV0Removal("InDetVKalVxInJetTool"),
036 m_secVxFinderNameForIPSign("InDetVKalVxInJetTool"),
037 m_SVForIPTool("Analysis::SVForIPTool"),
038 m_trackGradeFactory("Analysis::BasicTrackGradeFactory"),
039 m_unbiasIPEstimation(false){
040
041 declareInterface<ITagTool>(this);
042
043 declareProperty("SignWithSvx", m_SignWithSvx = false);
044 declareProperty("SVForIPTool", m_SVForIPTool);
045
046
047 declareProperty("trackGradePartitions", m_trackGradePartitionsDefinition);
048 m_trackGradePartitionsDefinition.push_back("Good");
049 declareProperty("RejectBadTracks", m_RejectBadTracks = false);
050
051
052 declareProperty("trackSelectorTool", m_trackSelectorTool);
053 declareProperty("trackToVertexTool", m_trackToVertexTool);
054 declareProperty("trackGradeFactory", m_trackGradeFactory);
055
056
057 declareProperty("writeInfo", m_writeInfo = true);
058
059 declareProperty("truthMatchingName", m_truthMatchingName = "TruthInfo");
060 declareProperty("purificationDeltaR", m_purificationDeltaR = 0.8);
061
062 declareProperty("SecVxFinderNameForV0Removal", m_secVxFinderNameForV0Removal);
063 declareProperty("SecVxFinderNameForIPSign", m_secVxFinderNameForIPSign);
064
065 declareProperty("TrackToVertexIPEstimator",m_trackToVertexIPEstimator);
066 declareProperty("unbiasIPEstimation",m_unbiasIPEstimation);
067 }
068
069 TrackCounting::~TrackCounting(){
070 for (size_t i = 0; i < m_trackGradePartitions.size(); i++)
071 delete m_trackGradePartitions.at(i);
072 }
073
074
075 StatusCode TrackCounting::initialize() {
076
077
078 if ( m_trackToVertexTool.retrieve().isFailure() ) {
079 ATH_MSG_FATAL("#BTAG# Failed to retrieve tool " << m_trackToVertexTool);
080 return StatusCode::FAILURE;
081 } else {
082 ATH_MSG_DEBUG("#BTAG# Retrieved tool " << m_trackToVertexTool);
083 }
084
085 if(m_SVForIPTool.retrieve().isFailure()) {
086 ATH_MSG_FATAL( "#BTAG# Failed to retrieve tool " << m_SVForIPTool);
087 } else {
088 ATH_MSG_DEBUG("#BTAG# Retrieved tool " << m_SVForIPTool);
089 }
090
091 if(m_trackToVertexIPEstimator.retrieve().isFailure()) {
092 ATH_MSG_FATAL( "#BTAG# Failed to retrieve tool " << m_trackToVertexIPEstimator);
093 } else {
094 ATH_MSG_DEBUG("#BTAG# Retrieved tool " << m_trackToVertexIPEstimator);
095 }
096
097
098 if ( m_trackSelectorTool.retrieve().isFailure() ) {
099 ATH_MSG_FATAL( "#BTAG# Failed to retrieve tool " << m_trackSelectorTool);
100 return StatusCode::FAILURE;
101 } else {
102 ATH_MSG_DEBUG("#BTAG# Retrieved tool " << m_trackSelectorTool);
103 }
104
105
106 if ( m_trackGradeFactory.retrieve().isFailure() ) {
107 ATH_MSG_FATAL( "#BTAG# Failed to retrieve tool " << m_trackGradeFactory);
108 return StatusCode::FAILURE;
109 } else {
110 ATH_MSG_DEBUG("#BTAG# Retrieved tool " << m_trackGradeFactory);
111 }
112
113
114 int nbPart = m_trackGradePartitionsDefinition.size();
115 ATH_MSG_DEBUG("#BTAG# Defining " << nbPart <<" track partitions: ");
116 for(int i=0;i<nbPart;i++) {
117 TrackGradePartition* part(0);
118 try {
119 part = new TrackGradePartition(m_trackGradePartitionsDefinition[i], *m_trackGradeFactory);
120 }
121 catch(std::string error) {
122 ATH_MSG_ERROR("#BTAG# Reported error " << error);
123 ATH_MSG_ERROR("#BTAG# List of categories provided to TrackCounting by jO : ");
124
125 for (int l=0;l<nbPart;l++) {
126 ATH_MSG_ERROR("#BTAG# string " << m_trackGradePartitionsDefinition[l]);
127 }
128
129 ATH_MSG_ERROR("#BTAG# List of categories provided by the TrackGradeFactory " << m_trackGradeFactory);
130
131 const TrackGradesDefinition &trackFactoryGradesDefinition = m_trackGradeFactory->getTrackGradesDefinition();
132 const std::vector<TrackGrade> &gradeList = trackFactoryGradesDefinition.getList();
133
134 std::vector<TrackGrade>::const_iterator listIter=gradeList.begin();
135 std::vector<TrackGrade>::const_iterator listEnd=gradeList.end();
136
137 for ( ; listIter !=listEnd ; ++listIter ) {
138 ATH_MSG_ERROR("#BTAG# n. " << (*listIter).gradeNumber() << " string " << (*listIter).gradeString());
139 }
140
141 ATH_MSG_ERROR("#BTAG# Terminating now... ");
142 return StatusCode::FAILURE;
143 }
144 ATH_MSG_INFO("#BTAG# " << (*part));
145 m_trackGradePartitions.push_back(part);
146 }
147 return StatusCode::SUCCESS;
148 }
149
150
151 StatusCode TrackCounting::finalize() {
152
153 return StatusCode::SUCCESS;
154 }
155
156
157 void TrackCounting::tagJet(Jet& jetToTag) {
158
159
160 std::string author = jetToTag.jetAuthor();
161 ATH_MSG_VERBOSE("#BTAG# Using jet type " << author);
162
163 m_tracksInJet.clear();
164 int nbPart = m_trackGradePartitionsDefinition.size();
165
166 std::vector<const Trk::TrackParticleBase*> TrkFromV0;
167 Hep3Vector SvxDirection;
168 bool canUseSvxDirection=false;
169
170
171 if (m_SignWithSvx) {
172 m_SVForIPTool->getDirectionFromSecondaryVertexInfo(SvxDirection,canUseSvxDirection,
173 jetToTag,m_secVxFinderNameForIPSign,m_priVtx->recVertex());
174 }
175
176
177 if (m_RejectBadTracks) {
178 m_SVForIPTool->getTrkFromV0FromSecondaryVertexInfo(TrkFromV0,
179 jetToTag,m_secVxFinderNameForV0Removal);
180 }
181
182 ATH_MSG_VERBOSE("#BTAG# TrkFromV0 : number of reconstructed bad tracks: " << TrkFromV0.size());
183
184
185 int nbTrack = 0;
186 m_trackSelectorTool->primaryVertex(m_priVtx->recVertex().position());
187 m_trackSelectorTool->prepare();
188 std::vector<const Rec::TrackParticle*>* trackVector = jetToTag.getAssociation<TrackAssociation>("Tracks")->tracks();
189 std::vector<const Rec::TrackParticle*>::iterator jetItr;
190 for( jetItr = trackVector->begin(); jetItr != trackVector->end() ; ++jetItr ) {
191 const Rec::TrackParticle * aTemp = *jetItr;
192 nbTrack++;
193 if( m_trackSelectorTool->selectTrack(aTemp) ) {
194
195 TrackGrade * theGrade = m_trackGradeFactory->getGrade(*aTemp,
196 jetToTag.hlv() );
197
198 ATH_MSG_VERBOSE("#BTAG# result of selectTrack is OK, grade= " << (std::string)(*theGrade));
199
200 bool tobeUsed = false;
201 for(int i=0;i<nbPart;i++) {
202 if (std::find( (m_trackGradePartitions[i]->grades()).begin(),
203 (m_trackGradePartitions[i]->grades()).end(),
204 *theGrade )
205 != (m_trackGradePartitions[i]->grades()).end()) tobeUsed = true;
206 }
207
208 if (std::find(TrkFromV0.begin(),TrkFromV0.end(),aTemp) != TrkFromV0.end()) {
209 ATH_MSG_VERBOSE("#BTAG# Bad track in jet, pt = " << aTemp->pt() << " eta = " << aTemp->eta() << " phi = " << aTemp->phi());
210 if (m_RejectBadTracks) tobeUsed = false;
211 }
212 if (tobeUsed) m_tracksInJet.push_back(GradedTrack(aTemp, *theGrade));
213 delete theGrade;
214 theGrade=0;
215 }
216 }
217
218 delete trackVector;
219 ATH_MSG_VERBOSE("#BTAG# #tracks = " << nbTrack);
220 ATH_MSG_VERBOSE("#BTAG# the z of the primary Vertex= " << m_priVtx->recVertex().position().z());
221
222
223 Hep3Vector jetDirection(jetToTag.px(),jetToTag.py(),jetToTag.pz());
224 Hep3Vector unit = jetDirection.unit();
225 if (m_SignWithSvx && canUseSvxDirection) {
226 unit = SvxDirection.unit();
227 ATH_MSG_DEBUG("#BTAG# Using direction from sec vertex finder tool '"
228 << m_secVxFinderNameForIPSign << "': "
229 << " phi: " << unit.phi()
230 << " theta: " << unit.theta()
231 << " instead of jet direction phi: " << jetDirection.phi()
232 << " theta: " << jetDirection.theta());
233 }
234
235 FloatVec vectD0Signi;
236 FloatVec vectD0Signi_abs;
237
238 const int nbTrackMean = 3;
239 vectD0Signi.reserve(nbTrackMean);
240 vectD0Signi_abs.reserve(nbTrackMean);
241
242 for (std::vector<GradedTrack>::iterator trkItr = m_tracksInJet.begin();
243 trkItr != m_tracksInJet.end(); ++trkItr) {
244 const Rec::TrackParticle* trk = (*trkItr).track;
245
246 double d0wrtPriVtx(0.);
247 double d0ErrwrtPriVtx(1.);
248 double signOfIP(1.);
249
250
251 const Trk::ImpactParametersAndSigma* myIPandSigma = m_trackToVertexIPEstimator->estimate(trk,m_priVtx,m_unbiasIPEstimation);
252 if(myIPandSigma==0) {
253 ATH_MSG_WARNING("#BTAG# trackToVertexIPEstimator failed !");
254 } else {
255 d0wrtPriVtx=myIPandSigma->IPd0;
256 d0ErrwrtPriVtx=myIPandSigma->sigmad0;
257 delete myIPandSigma;
258 myIPandSigma=0;
259 }
260
261
262 signOfIP=m_trackToVertexIPEstimator->get2DLifetimeSignOfTrack(trk->definingParameters(),unit,m_priVtx->recVertex());
263
264
265 double sd0 = signOfIP*fabs(d0wrtPriVtx);
266 double sd0significance = signOfIP*fabs(d0wrtPriVtx/d0ErrwrtPriVtx);
267
268 vectD0Signi.push_back(sd0significance);
269 vectD0Signi_abs.push_back( fabs(sd0significance) );
270
271 ATH_MSG_VERBOSE("#BTAG# TrackCounting: Trk: grade= " << (std::string)(*trkItr).grade
272 << " Eta= " << trk->eta() << " Phi= " << trk->phi() << " pT= " << trk->pt()
273 << " d0= " << sd0
274 << "+-" << d0ErrwrtPriVtx
275 << " d0sig= " << sd0significance );
276
277 }
278
279
280
281 sort( vectD0Signi.begin(), vectD0Signi.end(), m_greater<float> );
282 sort( vectD0Signi_abs.begin(), vectD0Signi_abs.end(), m_greater<float> );
283
284
285
286 std::string instanceName("TrackCounting2D");
287 TrackCountingInfo* infoTrackCounting = NULL;
288
289 if(m_writeInfo) {
290 infoTrackCounting = new TrackCountingInfo(instanceName);
291
292 int ntrk = vectD0Signi.size();
293 infoTrackCounting->setnTracks( ntrk );
294
295 ATH_MSG_VERBOSE("#BTAG# Filling TrackCountingInfo...");
296 ATH_MSG_DEBUG("#BTAG# " << ntrk << " tracks used for TrackCounting, ordered ip2d significance / |ip2d significance|:" );
297 for(uint i=0; i<vectD0Signi.size(); i++){
298 ATH_MSG_DEBUG("#BTAG# trk " << i+1 << "/" << ntrk << ": " << vectD0Signi.at(i) << " / " << vectD0Signi_abs.at(i));
299 }
300 if( ntrk>=2 ){
301 ATH_MSG_DEBUG("#BTAG# filling 2nd / 2nd abs: " << vectD0Signi.at(1) << " / " << vectD0Signi_abs.at(1));
302 infoTrackCounting->setd0sig_2nd( vectD0Signi.at(1) );
303 infoTrackCounting->setd0sig_abs_2nd( vectD0Signi_abs.at(1) );
304 }
305 if( ntrk>=3 ){
306 ATH_MSG_DEBUG("#BTAG# filling 3rd / 3rd abs: " << vectD0Signi.at(2) << " / " << vectD0Signi_abs.at(2));
307 infoTrackCounting->setd0sig_3rd( vectD0Signi.at(2) );
308 infoTrackCounting->setd0sig_abs_3rd( vectD0Signi_abs.at(2) );
309 }
310 }
311
312
313
314
315
316 if(infoTrackCounting){
317 std::vector<double> v_tofill;
318 double tofill = exp(-20.);
319 if(vectD0Signi.size()>=2){
320 tofill = exp(vectD0Signi.at(1));
321 infoTrackCounting->makeValid();
322 }
323 v_tofill.push_back( tofill );
324 v_tofill.push_back(1.);
325 infoTrackCounting->setTagLikelihood( v_tofill );
326 jetToTag.addInfo( infoTrackCounting );
327 }
328
329 m_tracksInJet.clear();
330
331 return;
332 }
333
334 }
335
336
337
| Due to the LXR bug, the updates fail sometimes to remove references to deleted files. The Saturday's full rebuilds fix these problems |
|
This page was automatically generated by the
LXR engine.
|
|