Report problems to ATLAS LXR Team (with time and IP address indicated)

The LXR Cross Referencer

source navigation ]
diff markup ]
identifier search ]
general search ]
 
 
Architecture: linux ]
Version: head ] [ nightly ] [ GaudiDev ]
  Links to LXR source navigation pages for stable releases [ 12.*.* ]   [ 13.*.* ]   [ 14.*.* ]   [ 15.*.* ] 

001 #include "JetTagTools/JetProbTag.h"
002 
003 #include "CLHEP/Vector/ThreeVector.h"
004 #include "CLHEP/Vector/LorentzVector.h"
005 #include "CLHEP/GenericFunctions/Erf.hh"
006 
007 #include "GaudiKernel/IToolSvc.h"
008 
009 #include "JetEvent/Jet.h"
010 #include "JetTagEvent/TrackAssociation.h"
011 #include "Particle/TrackParticle.h"
012 #include "JetTagInfo/JetProbInfoBase.h"
013 #include "JetTagInfo/IPInfoPlus.h"
014 #include "Navigation/NavigationToken.h"
015 #include "JetTagInfo/TruthInfo.h"
016 #include "ITrackToVertex/ITrackToVertex.h"
017 #include "JetTagTools/TrackSelector.h"
018 #include "JetTagTools/GradedTrack.h"
019 #include "JetTagInfo/TrackGrade.h"
020 #include "JetTagCalibration/CalibrationBroker.h"
021 
022 #include "JetTagInfo/TrackGradesDefinition.h"
023 #include "JetTagTools/ITrackGradeFactory.h"
024 
025 #include "JetTagInfo/SvxSummary.h"
026 
027 #include "GaudiKernel/ITHistSvc.h"
028 #include "JetTagTools/HistoHelperRoot.h"
029 
030 #include "TrkParticleBase/TrackParticleBase.h"
031 #include "JetTagTools/SVForIPTool.h"
032 #include "TrkVertexFitterInterfaces/ITrackToVertexIPEstimator.h"
033 
034 #include <TH1.h>
035 #include <TF1.h>
036 
037 #include <map>
038 #include <algorithm>
039 #include <cmath>
040 
041 namespace Analysis {
042 
043   typedef std::vector<double> FloatVec;
044   typedef std::vector<double>::iterator FloatVecIter;
045 
046   JetProbTag::JetProbTag(const std::string& t, const std::string& n, const IInterface* p)
047     : AthAlgTool(t,n,p),
048       m_runModus("analysis"),
049       m_trackToVertexTool("Reco::TrackToVertex"),
050       m_trackSelectorTool("Analysis::TrackSelector"),
051       m_calibrationTool("BTagCalibrationBroker"),
052       m_secVxFinderNameForV0Removal("InDetVKalVxInJetTool"),
053       m_secVxFinderNameForIPSign("InDetVKalVxInJetTool") ,
054       m_SVForIPTool("Analysis::SVForIPTool"),
055       m_trackGradeFactory("Analysis::BasicTrackGradeFactory"),
056       m_unbiasIPEstimation(false)
057   {
058     declareInterface<ITagTool>(this);
059     declareProperty("Runmodus",       m_runModus);
060 
061     declareProperty("trackSelectorTool", m_trackSelectorTool);
062     declareProperty("trackToVertexTool", m_trackToVertexTool);
063     declareProperty("trackGradeFactory",m_trackGradeFactory);
064  
065     declareProperty("impactParameterView", m_impactParameterView = "2D");
066 
067     // track categories:
068     declareProperty("trackGradePartitions", m_trackGradePartitionsDefinition);
069     m_trackGradePartitionsDefinition.push_back("Good+Shared");
070 
071     declareProperty("UseNegIP",      m_negIP = true);
072     declareProperty("UsePosIP",      m_posIP = true);
073     declareProperty("flipIPSign",    m_flipIP = false);
074 
075     declareProperty("RejectBadTracks", m_RejectBadTracks = false);
076     declareProperty("SignWithSvx",     m_SignWithSvx     = false);
077     declareProperty("SecVxFinderNameForV0Removal",m_secVxFinderNameForV0Removal);
078     declareProperty("SecVxFinderNameForIPSign",m_secVxFinderNameForIPSign);
079     declareProperty("SVForIPTool",m_SVForIPTool);
080 
081     declareProperty("calibrationTool",  m_calibrationTool);
082 
083     // information to persistify:
084     declareProperty("originalTPCollectionName", m_originalTPCollectionName = "TrackParticleCandidate");
085     declareProperty("writeInfoBase", m_writeInfoBase = true);
086     declareProperty("infoPlusName", m_infoPlusName = "IPInfoPlus");
087     declareProperty("jetCollectionList", m_jetCollectionList);
088     declareProperty("jetWithInfoPlus", m_jetWithInfoPlus);
089     m_jetWithInfoPlus.push_back("Cone4H1Tower");
090 
091     // for making reference histograms:
092     declareProperty("checkOverflows", m_checkOverflows = false); 
093     declareProperty("jetPtMinRef", m_jetPtMinRef = 15.*GeV);
094     declareProperty("isolationDeltaR", m_isolationDeltaR = 0.8);
095     declareProperty("useTrueFlavour", m_useTrueFlavour = false); 
096     declareProperty("referenceType", m_referenceType = "ALL"); // B, UDSG, ALL
097     declareProperty("truthMatchingName", m_truthMatchingName = "TruthInfo");
098     declareProperty("purificationDeltaR", m_purificationDeltaR = 0.8);
099 
100     declareProperty("TrackToVertexIPEstimator",m_trackToVertexIPEstimator);
101     declareProperty("unbiasIPEstimation",m_unbiasIPEstimation);
102 
103     // for using histograms vs fit
104     declareProperty("UseHistograms", m_useHistograms = true);
105     declareProperty("FitExpression", m_fitExpression);
106     m_fitExpression = "([0]*exp(-(x-[1])*(x-[1])/([2]*[2]))+[4]*exp(x/[3])+[6]*exp(x/[5]))/[7]";
107     declareProperty("FitParams", m_fitParams);
108     m_fitParams.push_back(6.409557e-01);  // [0] - resolGaussNorm
109     m_fitParams.push_back(0.0);           // [1] - resolGaussMu
110     m_fitParams.push_back(8.52013e-01);   // [2] - resolGaussSigma
111     m_fitParams.push_back(3.0468256e-01); // [3] - resolExpo1Norm
112     m_fitParams.push_back(9.67762e-01);   // [4] - resolExpo1Lambda
113     m_fitParams.push_back(3.5389101e-03); // [5] - resolExpo2Norm
114     m_fitParams.push_back(5.84975e+00);   // [6] - resolExpo2Lambda
115     m_fitParams.push_back(1.599066);      // [7] - resolGlobalNorm
116   }
117 
118   JetProbTag::~JetProbTag() {
119   }
120 
121 
122   StatusCode JetProbTag::initialize() {
123 
124     /** retrieving TrackToVertex: */
125     if ( m_trackToVertexTool.retrieve().isFailure() ) {
126       ATH_MSG_FATAL("#BTAG# Failed to retrieve tool " << m_trackToVertexTool);
127     } else {
128       ATH_MSG_INFO("#BTAG# Retrieved tool " << m_trackToVertexTool);
129     }
130 
131     /** retrieving SVForIPTool: */
132     if (m_SVForIPTool.retrieve().isFailure() ) {
133       ATH_MSG_FATAL("#BTAG# Failed to retrieve tool " << m_SVForIPTool);
134     } else {
135       ATH_MSG_INFO("#BTAG# Retrieved tool " << m_SVForIPTool);
136     }
137 
138      /** retrieving the track grade factory */
139     if ( m_trackGradeFactory.retrieve().isFailure() ) {
140       ATH_MSG_FATAL("#BTAG# Failed to retrieve tool " << m_trackGradeFactory);
141     } else {
142       ATH_MSG_INFO("#BTAG# Retrieved tool " << m_trackGradeFactory);
143     }
144 
145     /** creation of TrackSelector: (private instance) */
146     if ( m_trackSelectorTool.retrieve().isFailure() ) {
147       ATH_MSG_FATAL("#BTAG# Failed to retrieve tool " << m_trackSelectorTool);
148     } else {
149       ATH_MSG_INFO("#BTAG# Retrieved tool " << m_trackSelectorTool);
150     }
151 
152     if (m_trackToVertexIPEstimator.retrieve().isFailure() ) {
153       ATH_MSG_FATAL("#BTAG# Failed to retrieve tool " << m_trackToVertexIPEstimator);
154     } else {
155       ATH_MSG_INFO("#BTAG# Retrieved tool " << m_trackToVertexIPEstimator);
156     }
157     
158     /** prepare the track partitions: */
159     int nbPart = m_trackGradePartitionsDefinition.size();
160     ATH_MSG_INFO("#BTAG#  Defining " << nbPart <<" track partitions: ");
161     for(int i=0;i<nbPart;i++) {
162       TrackGradePartition* part(0);
163       try 
164       {
165         part = new TrackGradePartition(m_trackGradePartitionsDefinition[i],
166                                        *m_trackGradeFactory);
167       }
168       catch (std::string error)
169       {
170         ATH_MSG_ERROR("#BTAG# Reported error " << error);
171 
172         ATH_MSG_ERROR("#BTAG#  List of categories provided to IPTag by jO : ");
173         for (int l=0;l<nbPart;l++) {
174           ATH_MSG_ERROR(" string " << m_trackGradePartitionsDefinition[i]);
175         }
176  
177         ATH_MSG_ERROR("#BTAG#  List of categories provided by the TrackGradeFactory " << m_trackGradeFactory);
178 
179         const TrackGradesDefinition & trackFactoryGradesDefinition = m_trackGradeFactory->getTrackGradesDefinition();
180 
181         const std::vector<TrackGrade> & gradeList = trackFactoryGradesDefinition.getList();
182 
183         std::vector<TrackGrade>::const_iterator listIter=gradeList.begin();
184         std::vector<TrackGrade>::const_iterator listEnd=gradeList.end();
185 
186         for ( ; listIter !=listEnd ; ++listIter )
187         {
188           ATH_MSG_ERROR("#BTAG# n. " << (*listIter).gradeNumber() << " string " << (*listIter).gradeString());
189         }
190 
191         ATH_MSG_ERROR("#BTAG#  Terminating now... ");
192         
193         return StatusCode::FAILURE;
194       }
195       
196 
197       ATH_MSG_INFO((*part));
198       m_trackGradePartitions.push_back(part);
199     }
200 
201     /** retrieving calibrationTool: */
202     if(m_runModus=="analysis") {
203       if ( m_calibrationTool.retrieve().isFailure() ) {
204         ATH_MSG_FATAL("#BTAG# Failed to retrieve tool " << m_calibrationTool);
205       } else {
206         ATH_MSG_INFO("#BTAG# Retrieved tool " << m_calibrationTool);
207       }
208     }
209 
210     /** register calibration histograms: */
211     if(m_runModus=="analysis") {
212       ATH_MSG_DEBUG("#BTAG# of TrackGradePartitions: " << m_trackGradePartitions.size());
213       for(unsigned int i=0; i<m_trackGradePartitions.size();i++) {
214         ATH_MSG_DEBUG("#BTAG# TrackGradePartitions: " << i << " - # of Grades: "<< m_trackGradePartitions[i]->grades().size());
215         for(unsigned int g=0; g<m_trackGradePartitions[i]->grades().size(); g++){
216           std::string hName;
217           hName = ((std::string)m_trackGradePartitions[i]->grades()[g])+"/Resol";
218           ATH_MSG_DEBUG("#BTAG# Registering histogram " << hName 
219                         << " for track grade " << ((std::string)m_trackGradePartitions[i]->grades()[g])
220                         ); 
221           m_calibrationTool->registerHistogram("JetProb", hName);
222         }
223       }
224       m_calibrationTool->printStatus();
225     }
226 
227     /** book calibration histograms in reference mode: */ 
228     if(m_runModus=="reference") {
229       const TrackGradesDefinition & trackFactoryGradesDefinition = m_trackGradeFactory->getTrackGradesDefinition();
230       const std::vector<TrackGrade> & gradeList = trackFactoryGradesDefinition.getList();
231       std::vector<TrackGrade>::const_iterator listBegin=gradeList.begin();
232       std::vector<TrackGrade>::const_iterator listEnd=gradeList.end();
233       // retrieve histohelper:
234       ITHistSvc* myHistoSvc;
235       if( service( "THistSvc", myHistoSvc ).isSuccess() ) {
236         ATH_MSG_DEBUG("#BTAG# " << name() << ": HistoSvc loaded successfully.");
237         m_histoHelper = new HistoHelperRoot(myHistoSvc);
238         m_histoHelper->setCheckOverflows(m_checkOverflows);
239         for(uint j=0;j<m_jetCollectionList.size();j++) {
240           for(std::vector<TrackGrade>::const_iterator listIter=listBegin ; listIter !=listEnd ; ++listIter) {
241             const TrackGrade & grd = (*listIter);
242             //if(grd==TrackGrade::Undefined) continue;
243             std::string hName = "/RefFileJetProb" + m_jetCollectionList[j] + "/"
244                               + (std::string)grd + "/Resol"; 
245             ATH_MSG_VERBOSE("#BTAG# booking for JetProb: " << hName);
246             //use bins with variable size
247             const int nd0bins = 100;
248             double d0limits[nd0bins+1] = {0};
249             double d0min = -40;
250             double d0max = 40;
251             for(int i=0; i<=nd0bins; i++){
252               if(i<nd0bins/2) d0limits[i] = d0min * pow(10, -(4.*i)/nd0bins);
253               if(i>nd0bins/2) d0limits[i] = d0max * pow(10, -(4.*(nd0bins-i))/nd0bins);
254             }
255             m_histoHelper->bookHisto(hName,"d0 significance",nd0bins, d0limits);
256           }
257         }
258       } else {
259         ATH_MSG_ERROR("#BTAG# " << name() << ": HistoSvc could NOT bo loaded.");
260       }
261     }
262 
263     return StatusCode::SUCCESS;
264   }                                                    
265 
266 
267   StatusCode JetProbTag::finalize() {
268     for (size_t i = 0; i < m_trackGradePartitions.size(); i++)
269       delete m_trackGradePartitions[i];
270     return StatusCode::SUCCESS;
271   }
272 
273   void JetProbTag::tagJet(Jet& jetToTag) {
274 
275     /** author to know which jet algorithm: */
276     std::string author = jetToTag.jetAuthor();
277 
278     /* Do not keep the InfoPlus for all jet collection */
279     bool keepInfoPlus = false;
280     if (std::find( m_jetWithInfoPlus.begin(), 
281                    m_jetWithInfoPlus.end(), 
282                    author ) != m_jetWithInfoPlus.end()) keepInfoPlus = true;
283 
284     /** retrieve the original TP collection for persistence: */
285     if(m_runModus == "analysis" && keepInfoPlus) {
286       if (evtStore()->retrieve(m_originalTPCollection, m_originalTPCollectionName).isFailure()) {
287         ATH_MSG_ERROR("#BTAG# " << m_originalTPCollectionName << " not found in StoreGate.");
288         return;
289       } else {
290         ATH_MSG_VERBOSE("#BTAG# TrackParticleContainer " << m_originalTPCollectionName << " found.");
291       }
292     }
293 
294     /** for reference mode: */
295     bool jetIsOkForReference = false;
296     if(m_runModus == "reference") {
297       // here we require a jet selection:
298       if( jetToTag.pt()>m_jetPtMinRef && fabs(jetToTag.eta())<2.5 ) {
299         if(!m_useTrueFlavour) {
300           jetIsOkForReference = true;
301         } else {
302           // and also a truth match:
303           const TruthInfo* mcinfo = jetToTag.tagInfo<TruthInfo>(m_truthMatchingName);
304           double deltaRmin(0.);
305           if( mcinfo ) {
306             std::string label = mcinfo->jetTruthLabel();
307             // for purification: require no b or c quark closer than dR=m_purificationDeltaR
308             double deltaRtoClosestB = mcinfo->deltaRMinTo("B");
309             double deltaRtoClosestC = mcinfo->deltaRMinTo("C");
310             deltaRmin = deltaRtoClosestB < deltaRtoClosestC ? deltaRtoClosestB : deltaRtoClosestC;
311             double deltaRtoClosestT = mcinfo->deltaRMinTo("T");
312             deltaRmin = deltaRtoClosestT < deltaRmin ? deltaRtoClosestT : deltaRmin;
313             if ( (    "B"==m_referenceType &&   "B"==label ) ||  // b-jets    
314                  ( "UDSG"==m_referenceType && "N/A"==label ) ||  // light jets
315                  (  "ALL"==m_referenceType && // all jets: b + purified light jets
316                     ( "B"==label || ( "N/A"==label && deltaRmin > m_purificationDeltaR ) ) )
317                  ) jetIsOkForReference = true;
318           } else {
319             ATH_MSG_WARNING("#BTAG# No TruthInfo ! Cannot run on reference mode !");
320           }
321         }
322       }
323     }
324 
325     int nbPart = m_trackGradePartitionsDefinition.size();
326 
327     std::vector<const Trk::TrackParticleBase*> TrkFromV0;
328 
329     Hep3Vector SvxDirection;
330     bool canUseSvxDirection=false;
331 
332     if (m_SVForIPTool) {
333       if (m_SignWithSvx) {
334         m_SVForIPTool->getDirectionFromSecondaryVertexInfo(SvxDirection,canUseSvxDirection,//output
335                                                            jetToTag,m_secVxFinderNameForIPSign,m_priVtx->recVertex());//input
336       }
337       
338       // bad tracks from V0s, conversions, interactions:
339       m_SVForIPTool->getTrkFromV0FromSecondaryVertexInfo(TrkFromV0,//output
340                                                          jetToTag,m_secVxFinderNameForV0Removal);//input
341     }
342 
343     /** extract the TrackParticles from the jet and apply track selection: */
344     int nbClus = 0;
345     int nbTrak = 0;
346     if (m_trackSelectorTool) {
347       m_trackSelectorTool->primaryVertex(m_priVtx->recVertex().position());
348       m_trackSelectorTool->prepare();
349     }
350     //JBdV does the jet have bad Trk ?
351     int numberOfBadTracks = 0;
352     std::vector<const Rec::TrackParticle*>* trackVector = jetToTag.getAssociation<TrackAssociation>("Tracks")->tracks();
353     for (std::vector<const Rec::TrackParticle*>::iterator jetItr = trackVector->begin(); jetItr != trackVector->end() ; ++jetItr ) {
354       const Rec::TrackParticle * aTemp = *jetItr;
355       nbTrak++;
356       if( m_trackSelectorTool && m_trackSelectorTool->selectTrack(aTemp) ) {
357 
358         TrackGrade * theGrade = m_trackGradeFactory->getGrade(*aTemp,
359                                                               jetToTag.hlv() );
360         
361         ATH_MSG_VERBOSE("#BTAG#  result of selectTrack is OK, grade= "
362              << (std::string)(*theGrade));
363 
364         bool tobeUsed = false;
365         for(int i=0;i<nbPart;i++) {
366           if (std::find((m_trackGradePartitions[i]->grades()).begin(), (m_trackGradePartitions[i]->grades()).end(), *theGrade) 
367               != (m_trackGradePartitions[i]->grades()).end()) tobeUsed = true;
368         }
369         // Is it a bad track ?
370         std::string suffix = "g";
371         if (std::find(TrkFromV0.begin(),TrkFromV0.end(),aTemp) != TrkFromV0.end()) {
372           suffix = "b";
373           numberOfBadTracks++;
374           ATH_MSG_VERBOSE("#BTAG# Bad track in jet, pt = " << aTemp->pt() << " eta = " << aTemp->eta() << " phi = " << aTemp->phi());
375           if (m_RejectBadTracks) tobeUsed = false;
376         }
377         if (tobeUsed) m_tracksInJet.push_back(GradedTrack(aTemp, *theGrade));
378         delete theGrade;
379         theGrade = 0;
380       }
381     }
382     delete trackVector; trackVector=0;
383 
384     ATH_MSG_VERBOSE("#BTAG#  #clusters = " << nbClus << " #tracks = " << nbTrak);
385     ATH_MSG_VERBOSE("#BTAG# The z of the primary = "<<m_priVtx->recVertex().position().z());
386 
387     /** jet direction: */
388     Hep3Vector jetDirection(jetToTag.px(),jetToTag.py(),jetToTag.pz());
389     Hep3Vector unit = jetDirection.unit();
390     //JBdV Try
391     if (m_SignWithSvx && canUseSvxDirection) unit = SvxDirection.unit();
392 
393     FloatVec vectD0;
394     FloatVec vectD0Signi;
395     std::vector<TrackGrade> vectGrades;
396     std::vector<const Rec::TrackParticle*> vectTP;
397     std::vector<bool> vectFromV0;
398     FloatVec trackProbs;
399     // reserve approximate space (optimization):
400     const int nbTrackMean = 3;
401     vectD0.reserve(nbTrackMean);
402     vectD0Signi.reserve(nbTrackMean);
403     vectGrades.reserve(nbTrackMean);
404     vectTP.reserve(nbTrackMean);
405     vectFromV0.reserve(nbTrackMean);
406     trackProbs.reserve(nbTrackMean);
407 
408     for (std::vector<GradedTrack>::iterator trkItr = m_tracksInJet.begin(); trkItr != m_tracksInJet.end(); ++trkItr) {
409       const Rec::TrackParticle* trk = (*trkItr).track;
410 
411       bool isFromV0 = (std::find(TrkFromV0.begin(),TrkFromV0.end(),trk) != TrkFromV0.end());
412 
413       /** track parameters defined at the primary vertex:
414           temp: can use d0/z0 at perigee for comparison with CBNT */
415       double d0wrtPriVtx(0.);
416       double d0ErrwrtPriVtx(1.);
417       /* use new Tool for "unbiased" IP estimation */
418       const Trk::ImpactParametersAndSigma* myIPandSigma(0);
419       if (m_trackToVertexIPEstimator) { 
420         myIPandSigma = m_trackToVertexIPEstimator->estimate(trk,m_priVtx,m_unbiasIPEstimation);
421       }
422       if(0==myIPandSigma) {
423         ATH_MSG_WARNING("#BTAG# JetProbTAG: trackToVertexIPEstimator failed !");
424       } else {
425         d0wrtPriVtx=myIPandSigma->IPd0;
426         d0ErrwrtPriVtx=myIPandSigma->sigmad0;
427         delete myIPandSigma;
428         myIPandSigma=0;
429       }
430 
431       /** sign of the impact parameter */
432       double signOfIP(1.);
433       if (m_trackToVertexIPEstimator) {
434         if(m_impactParameterView=="2D" || m_impactParameterView=="1D") {
435           signOfIP = m_trackToVertexIPEstimator->get2DLifetimeSignOfTrack(trk->definingParameters(),
436                                                                         unit,m_priVtx->recVertex());
437         }
438         if(m_impactParameterView=="3D") {
439           signOfIP = m_trackToVertexIPEstimator->get3DLifetimeSignOfTrack(trk->definingParameters(),
440                                                                         unit,m_priVtx->recVertex());
441         }
442       }
443       
444       /** fill reference histograms: */
445       if( m_runModus == "reference" && jetIsOkForReference && signOfIP < 0 ) {
446         const TrackGradesDefinition & trackFactoryGradesDefinition = m_trackGradeFactory->getTrackGradesDefinition();
447         const std::vector<TrackGrade> & gradeList = trackFactoryGradesDefinition.getList();
448         std::vector<TrackGrade>::const_iterator listIter=gradeList.begin();
449         std::vector<TrackGrade>::const_iterator listEnd=gradeList.end();
450         for ( ; listIter !=listEnd ; ++listIter ) {
451           const TrackGrade & grd = (*listIter);
452           //if(grd==TrackGrade::Undefined) continue;
453           ATH_MSG_DEBUG("#BTAG#   filling ref histo for grade " << (std::string)grd);
454           if( grd==(*trkItr).grade ) { // check the grade of current track
455             ATH_MSG_DEBUG("#BTAG#   track is of required grade ");
456             const std::string suffix = "_" + (std::string)grd;
457             std::string hName = "/RefFileJetProb" + author + "/"
458                               + (std::string)grd + "/Resol";
459             float val = fabs(d0wrtPriVtx/d0ErrwrtPriVtx);
460             ATH_MSG_DEBUG("#BTAG#   histo JetProb: " << hName << " " << val);
461             double binwidthminus = (m_histoHelper->getHisto1D(hName))->GetBinWidth(m_histoHelper->getHisto1D(hName)->FindBin(-val));
462             double binweightminus = 1./binwidthminus;
463             double binwidthplus = (m_histoHelper->getHisto1D(hName))->GetBinWidth(m_histoHelper->getHisto1D(hName)->FindBin(+val));
464             double binweightplus = 1./binwidthplus;
465             m_histoHelper->fillHistoWithWeight(hName,-val,binweightminus);
466             m_histoHelper->fillHistoWithWeight(hName,+val,binweightplus);
467           }
468         }
469       }
470 
471       if( m_runModus == "analysis"){
472         /** select sign of IP, flip for negative tags */
473         if(signOfIP > 0  && !m_posIP) continue;
474         if(signOfIP <= 0 && !m_negIP) continue;
475         if(m_flipIP) signOfIP *= -1;
476 
477         /** significances */
478         double sIP = signOfIP*fabs(d0wrtPriVtx);
479         double significance= signOfIP*fabs(d0wrtPriVtx/d0ErrwrtPriVtx);
480 
481         /** track grade and jet author*/
482         ATH_MSG_VERBOSE("#BTAG# Track Grade...");
483         TrackGrade grd = (*trkItr).grade;
484         std::string trkName = author+":"+(std::string)grd;
485 
486         /** compute track probablity: */
487         ATH_MSG_VERBOSE("#BTAG# Compute trackProb...");
488         double trackProb = this->m_getTrackProb(significance, trkName);
489         if(trackProb >= 100){
490           ATH_MSG_WARNING("#BTAG# Error code " << trackProb << " returned when trying to compute track probability...");
491           continue;
492         }
493         if(trackProb>1){ // Should not occure now
494           ATH_MSG_DEBUG("#BTAG# Correcting floating point precision: " << trackProb << " returned when computing track probability...");
495           trackProb=1.;
496         }
497 
498         vectD0.push_back(sIP);
499         vectD0Signi.push_back(significance);
500         vectGrades.push_back((*trkItr).grade);
501         vectTP.push_back(trk);
502         vectFromV0.push_back(isFromV0);
503         trackProbs.push_back(trackProb);
504         ATH_MSG_VERBOSE("#BTAG# trackProb = " << trackProb); 
505 
506         ATH_MSG_VERBOSE("#BTAG# JetProbTAG: Trk " 
507                         << " d0= " << sIP 
508                         << "+-" << d0ErrwrtPriVtx
509                         << " sigd0= " << significance
510                         << " trackProb= " << trackProb
511                         );
512       }
513     } // endloop on tracks
514 
515     JetProbInfoBase* infoBase(0);
516     IPInfoPlus* infoPlus(0);
517     bool isIPInfoPlusAlreadyThere = false;
518     if(m_runModus=="analysis") {
519       std::string instanceName("JetProb");
520       if(m_flipIP) instanceName += "Neg";
521 
522       // -- fill new base info class ... 
523       if(m_writeInfoBase) {
524         infoBase = new JetProbInfoBase(instanceName);
525         infoBase->nbTracks(vectTP.size());
526       }
527       // -- fill extended info class ...
528       uint nbt = vectTP.size();
529       if(keepInfoPlus && nbt > 0) {
530         ATH_MSG_VERBOSE("#BTAG# Filling IPInfoPlus...");
531         infoPlus = const_cast<IPInfoPlus*>(jetToTag.tagInfo<IPInfoPlus>(m_infoPlusName));
532         if(infoPlus) {
533           ATH_MSG_VERBOSE("#BTAG# Previous IPInfoPlus " << m_infoPlusName << " found...");
534           isIPInfoPlusAlreadyThere = true;
535           // iterate on tracks and fill track weights
536           for(uint i=0;i<nbt;i++) {
537             if(m_flipIP) {
538               infoPlus->updateTrackWeight(vectTP[i],"JPneg",trackProbs[i]);
539             } else { 
540               infoPlus->updateTrackWeight(vectTP[i],"JP",trackProbs[i]);
541             }
542           }
543         } else {
544           infoPlus = new IPInfoPlus(m_infoPlusName);
545           if(infoPlus) {
546             ATH_MSG_VERBOSE("#BTAG# " << m_infoPlusName << " not found. New IPInfoPlus created...");
547             uint nbt = vectTP.size();
548             for(uint i=0;i<nbt;i++) {
549               IPTrackInfo tinfo(m_originalTPCollection, vectTP[i], 
550                                 vectGrades[i], vectFromV0[i],
551                                 vectD0[i], vectD0Signi[i],
552                                 0., 0.);
553               tinfo.resetW();
554               infoPlus->addTrackInfo(tinfo);
555               if(m_flipIP) {
556                 infoPlus->updateTrackWeight(vectTP[i],"JPneg",trackProbs[i]);
557               } else { 
558                 infoPlus->updateTrackWeight(vectTP[i],"JP",trackProbs[i]);
559               }
560             }
561           }
562         }
563       }
564     }
565 
566     /** compute jet prob: */
567     ATH_MSG_VERBOSE("#BTAG# Compute JetProb...");
568     double P0 = 1.;
569     for(unsigned int it=0;it<trackProbs.size();it++) {
570       P0*=trackProbs[it];
571     }
572     double PJet = 0.;
573     for(unsigned int it=0;it<trackProbs.size();it++) {
574       PJet += pow(-log(P0),it)/this->m_factorial(it);
575     }
576     PJet *= P0;
577     if (trackProbs.size() == 0) PJet = 1;
578     ATH_MSG_VERBOSE("#BTAG# JetProb: #tracks= " << trackProbs.size()
579          <<" P0= " << P0 << " Pj= " << PJet);
580 
581     std::vector<double> like;
582     like.clear();
583     like.push_back(PJet);
584     if (infoBase) infoBase->setTagLikelihood(like);
585 
586     /** tagging done. Fill the JetTag and return ... */
587     if (infoBase) jetToTag.addInfo(infoBase);
588     if (infoPlus && !isIPInfoPlusAlreadyThere) jetToTag.addInfo(infoPlus);
589     m_tracksInJet.clear();
590   }
591 
592   void JetProbTag::finalizeHistos()
593   {
594   }
595 
596   double JetProbTag::m_getTrackProb(double significance, std::string trkName) {
597 
598     if(m_useHistograms){
599       return m_getTrackProbFromHistograms(significance, trkName);
600     }else{
601       return m_getTrackProbFromFit(significance);
602     }
603   } 
604 
605   double JetProbTag::m_getTrackProbFromHistograms(double significance, std::string trkName){
606 
607     ATH_MSG_VERBOSE("#BTAG# Inside getTrackProbFromHistogram...");
608 
609     // find track grade and jet author by parsing trkName
610     std::string grd = "";
611     std::string author = "";
612     if(trkName!=""){
613       const std::string delim(":");
614       std::string::size_type sPos, sEnd, sLen;
615       sPos = trkName.find_first_not_of(delim);
616       if(sPos != std::string::npos){
617         sEnd = trkName.find_first_of(delim, sPos);
618         if(sEnd!=std::string::npos){
619           sLen = sEnd - sPos;
620           author = trkName.substr(sPos,sLen);
621           sPos = trkName.find_first_not_of(delim, sEnd);
622           if(sPos != std::string::npos){
623             sEnd = trkName.find_first_of(delim, sPos);
624             if(sEnd==std::string::npos){
625               sEnd = trkName.length();
626               sLen = sEnd - sPos;
627               grd = trkName.substr(sPos,sLen);
628             }
629           }  
630         }
631       }
632     }
633     if("" == author || "" == grd){
634       return 100.; // Parsing error
635     }
636     ATH_MSG_VERBOSE("#BTAG# Getting track probability: "
637          << " Name: " << trkName 
638          << " - grade: " << grd 
639          << " - Jet Author: " << author
640         );
641 
642     // find track grade partition
643     std::string part = "";
644     for(unsigned int tgp=0; tgp<m_trackGradePartitions.size(); tgp++){      
645       part = m_trackGradePartitions[tgp]->suffix();
646       if(part.find(grd) != std::string::npos){
647         break;
648       }
649       part = "";
650     }
651     if(""==part){
652       return 101.; // Track grade not found in track grade partitions
653     }
654     ATH_MSG_VERBOSE("#BTAG# Using track grade partition: " << part);
655 
656     // get grade list
657     std::vector<std::string> gradeList;
658     {
659       const std::string delimUds("_");
660       std::string::size_type sPos, sEnd, sLen;
661       sPos = part.find_first_not_of(delimUds);
662       while ( sPos != std::string::npos ) {
663         sEnd = part.find_first_of(delimUds, sPos);
664         if(sEnd==std::string::npos) sEnd = part.length();
665         sLen = sEnd - sPos;
666         std::string word = part.substr(sPos,sLen);
667         gradeList.push_back(word);
668         sPos = part.find_first_not_of(delimUds, sEnd);
669       }
670     }
671     if(gradeList.size() < 1){
672       return 102.; // grade partition parsing error
673     }
674     ATH_MSG_VERBOSE("#BTAG# Grade list contains " << gradeList.size() << " grades");
675 
676     // get resolution histogram
677     TH1* hresol = 0;
678     for(unsigned int g=0; g<gradeList.size(); g++){
679       std::string hName = gradeList[g]+"/Resol";
680       std::pair<TH1*, bool> rth = m_calibrationTool->retrieveHistogram("JetProb",author,hName);
681       if(!rth.first){
682         ATH_MSG_WARNING("#BTAG# Histogram pointer is not valid for: " 
683              << " jet author: " << author 
684              << " - track grade: " << gradeList[g] 
685              << " - histo name: " << hName 
686              << " - histo pointer: " << rth.first
687             );
688         return 103.; // histogram pointer is not valid! database error!
689       }
690       if(0 == hresol){
691         hresol = (TH1*)rth.first->Clone();
692         hresol->Scale(hresol->GetEntries()/hresol->Integral());
693       }else{
694         hresol->Add(rth.first, rth.first->GetEntries()/rth.first->Integral());
695       }
696       ATH_MSG_VERBOSE("#BTAG# Added histogram: "
697            << " jet author: " << author 
698            << " - track grade: " << gradeList[g] 
699            << " - histo name: " << hName 
700           );
701     }
702     if(0==hresol){
703       return 104.; // histgram pointer is not valid... gradeList empty?!
704     }
705 
706     // Smooth histogram
707     hresol->Smooth();
708 
709     // normalize histogram
710     hresol->Scale(1./hresol->Integral(0,hresol->GetNbinsX()+1,"width"));
711 
712     // Get track probability
713     double trkp = 1.;
714     int nbins = hresol->GetNbinsX();
715     double overflow = hresol->GetBinContent(nbins+1);
716     int bin = hresol->FindBin(significance);
717     if (bin > nbins) {
718       if (0. == overflow){
719         delete hresol;
720         return 105.; // No overflow (e.g. if not enough stat. to calibrate) : do not use the track (conservative)
721       }
722       trkp = overflow;
723     } else if (bin >= 1) {
724       double sigdn  = hresol->GetBinLowEdge(bin);
725       double sigup  = hresol->GetBinLowEdge(bin+1);
726       double trkpdn = hresol->Integral(bin, nbins,"width") + overflow;
727       double trkpup = overflow;
728       if (bin+1 <= nbins) trkpup += hresol->Integral(bin+1, nbins,"width");
729       trkp = trkpdn + (significance - sigdn) * (trkpup - trkpdn) / (sigup - sigdn);
730     }
731     delete hresol;
732     return trkp;
733   }
734 
735   double JetProbTag::m_getTrackProbFromFit(double significance){
736 
737     double sign = significance<0?-1:+1;
738     double S = -fabs(significance);
739     TF1 *F = new TF1("JetProbFitFunction", m_fitExpression.c_str());
740     for(unsigned int i=0; i<m_fitParams.size(); i++){
741       F->SetParameter(i, m_fitParams[i]);
742     }
743     double p = 0.5 - sign*F->Integral(S,0);
744     F->Clear();
745     delete F;
746 
747     if(p<0) p = 0;
748     if(p>1) p = 1;
749 
750     return p;
751   }
752 
753   double JetProbTag::m_factorial(int n) {
754     double fac = 1.;
755     if (n > 1) {
756       fac = n * this->m_factorial(n - 1);
757     }
758     return fac;
759   }
760 
761 }
762 

source navigation ] diff markup ] identifier search ] general search ]

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. Valid HTML 4.01!