ATLAS Offline Software
VrtSecMulti.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
7 //
8 // Header include
10 //-------------------------------------------------
11 // Other stuff
15 #include "MVAUtils/BDT.h"
16 
17 #include "boost/graph/bron_kerbosch_all_cliques.hpp"
18 #include "TMath.h"
19 #include "TH1.h"
20 
21 #include <algorithm>
22 //
23 
24 
25 namespace Rec{
26 
27 
28  std::vector<xAOD::Vertex*> NewVrtSecInclusiveTool::getVrtSecMulti( workVectorArrxAOD * xAODwrk,
29  const xAOD::Vertex & primVrt,
30  compatibilityGraph_t& compatibilityGraph )
31  const
32  {
33 
34  const double probVrtMergeLimit=0.01;
35 
36  int i,j;
37  int inpNPart=xAODwrk->inpTrk.size();
38  std::vector<const xAOD::NeutralParticle*> neutralPartDummy(0);
39  ATH_MSG_DEBUG( "getVrtSecMulti() called with NPart=" << inpNPart);
40 
41  std::vector<xAOD::Vertex*> finalVertices(0);
42 
43  if( inpNPart < 2 ) { return finalVertices;} // 0,1 track => nothing to do!
44 
45  selGoodTrkParticle( xAODwrk, primVrt);
46  int nTracks = xAODwrk->listSelTracks.size();
47 
48  if( nTracks < 2 ) { return finalVertices;} // 0,1 selected track => nothing to do!
49 
50  ATH_MSG_DEBUG( "Number of selected tracks = " <<nTracks);
51 
52  if(m_fillHist){
53  Hists& h = getHists();
54  h.m_hb_ntrksel->Fill( (double) nTracks, m_w_1);
55  }
56 
57 //
58 // inpTrk[] - input track list
59 // listSelTracks[] - list of good tracks in jet for vertex search
60 //------------------------------------------------------------
61 // Initial track list ready
62 // Find 2track vertices
63 //
64 
65  std::map<long int,std::vector<double>> foundVrt2t;
66  select2TrVrt(xAODwrk->listSelTracks, primVrt, foundVrt2t, compatibilityGraph);
67 
68 //---
69  ATH_MSG_DEBUG(" Defined edges in the graph="<< num_edges(compatibilityGraph));
70  if(num_edges(compatibilityGraph)==0){ return finalVertices;} //No vertices!
71 
72 //
73 // m_Incomp[] - main vector of pointers for multivertex search
74 //-----------------------------------------------------------------------------------------------------
75 // Secondary track list is ready
76 // Creation of initial vertex set
77 //
78 
79 
80  std::unique_ptr<std::vector<WrkVrt>> wrkVrtSet = std::make_unique<std::vector<WrkVrt>>();
81  WrkVrt newvrt; newvrt.Good=true;
82  std::unique_ptr<Trk::IVKalState> state = m_fitSvc->makeState();
83  StatusCode sc;
84  long int NPTR=0, nth=2; // VK nth=2 to speed up PGRAPH when it's used
85 
86 
87  std::vector< std::vector<int> > allCliques;
88  bron_kerbosch_all_cliques(compatibilityGraph, clique_visitor(allCliques));
89  for(int cq=0; cq<(int)allCliques.size();cq++){
90  newvrt.selTrk.clear();
91  NPTR=allCliques[cq].size();
92  for(i=0;i<NPTR;i++){ newvrt.selTrk.push_back(allCliques[cq][i]);}
93 //==================================================
94  xAODwrk->tmpListTracks.clear();
95  TLorentzVector vpsum;
96  for(i=0;i<NPTR;i++) {
97  xAODwrk->tmpListTracks.push_back( xAODwrk->listSelTracks.at(newvrt.selTrk[i]) );
98  vpsum += xAODwrk->listSelTracks.at(newvrt.selTrk[i])->p4();
99  }
100  std::vector<double> iniVrtPos=estimVrtPos(nTracks,newvrt.selTrk,foundVrt2t);
101  m_fitSvc->setApproximateVertex(iniVrtPos[0], iniVrtPos[1], iniVrtPos[2], *state); /*Use as starting point*/
102  sc=m_fitSvc->VKalVrtFit(xAODwrk->tmpListTracks, neutralPartDummy,
103  newvrt.vertex, newvrt.vertexMom, newvrt.vertexCharge, newvrt.vertexCov,
104  newvrt.chi2PerTrk, newvrt.trkAtVrt, newvrt.chi2,
105  *state, false);
106  if( sc.isFailure() ) continue; /* Bad fit - goto next solution */
107  ATH_MSG_VERBOSE("Found IniVertex="<<newvrt.vertex[0]<<", "<<newvrt.vertex[1]<<", "<<newvrt.vertex[2]);
108  ATH_MSG_VERBOSE("with Chi2="<<newvrt.chi2<<" Ntrk="<<NPTR<<" trk1,2="<<newvrt.selTrk[0]<<", "<<newvrt.selTrk[1]);
109  if(NPTR==2 && newvrt.chi2>10.) continue; /* Bad 2track vertex */
110  if(newvrt.chi2PerTrk.size()==2) newvrt.chi2PerTrk[0]=newvrt.chi2PerTrk[1]=newvrt.chi2/2.;
111  newvrt.Good = true;
112  newvrt.projectedVrt=MomProjDist(newvrt.vertex, primVrt, newvrt.vertexMom); //3D SV-PV distance
113  wrkVrtSet->push_back(newvrt);
114  }
115 //==================================================================================
116 // boost::adjacency_list<boost::listS, boost::vecS, boost::undirectedS>::vertex_iterator vertexIt, vertexEnd;
117 // boost::adjacency_list<boost::listS, boost::vecS, boost::undirectedS>::adjacency_iterator neighbourIt, neighbourEnd;
118 // tie(vertexIt, vertexEnd) = vertices(compatibilityGraph);
119 // for (; vertexIt != vertexEnd; ++vertexIt) { std::cout << *vertexIt << " is connected with ";
120 // tie(neighbourIt, neighbourEnd) = adjacent_vertices(*vertexIt, compatibilityGraph);
121 // for (; neighbourIt != neighbourEnd; ++neighbourIt) std::cout << *neighbourIt << " "; std::cout << "\n"; }
122 //==================================================================================
123  if((*wrkVrtSet).empty())return finalVertices;
124  if(msgLvl(MSG::DEBUG))printWrkSet(wrkVrtSet.get(),"Initial Vertices");
125  //
126  //--Count track participation in different vertices
127  std::vector<int> trkNPairs(nTracks,0);
128  for(auto &vrt : (*wrkVrtSet)){
129  int ntInV=vrt.selTrk.size()-1;
130  for(auto &trk : vrt.selTrk)trkNPairs.at(trk) += ntInV;
131  }
132 //
133 //- Resolve all overlapped vertices
134 //
135  state = m_fitSvc->makeState();
136  std::multimap<double,std::pair<int,int>> vrtWithCommonTrk;
137  while(true){
138  int nSoluI=(*wrkVrtSet).size();
139  vrtWithCommonTrk.clear();
140  unsigned int nTComMax=0;
141  for(int iv=0; iv<nSoluI-1; iv++ ){
142  if(!(*wrkVrtSet)[iv].Good) continue;
143  if( (*wrkVrtSet)[iv].selTrk.size()<nTComMax) continue; // Optimisation. Only biggest overlap matters
144  for(int jv=iv+1; jv<nSoluI; jv++){
145  if(!(*wrkVrtSet)[jv].Good) continue;
146  if( (*wrkVrtSet)[jv].selTrk.size()<nTComMax) continue; // Optimisation. Only biggest overlap matters
147  unsigned int nTCom=nTrkCommon( wrkVrtSet.get(), iv, jv);
148  if(!nTCom) continue;
149  if(nTCom<nTComMax) continue;
150  double sumChi2=(*wrkVrtSet)[iv].chi2+(*wrkVrtSet)[jv].chi2;
151  sumChi2=std::min(sumChi2,999.)*1.e-3;
152  vrtWithCommonTrk.emplace(nTCom+sumChi2,std::make_pair(iv,jv));
153  nTComMax=std::max(nTComMax,nTCom);
154  } }
155  if(vrtWithCommonTrk.empty())break;
156  //============================== DEBUG output
157  //for(auto ku : vrtWithCommonTrk)std::cout<<" nCom="<<ku.first<<" v1="<<ku.second.first<<" v2="<<ku.second.second<<'\n';
158  //if(msgLvl(MSG::DEBUG))printWrkSet(wrkVrtSet.get(),"Overlapped Vertex Cleaning");
159  //===========================================
160  unsigned int nTCom=(*vrtWithCommonTrk.rbegin()).first;
161  WrkVrt & v1 = (*wrkVrtSet)[(*vrtWithCommonTrk.rbegin()).second.first];
162  WrkVrt & v2 = (*wrkVrtSet)[(*vrtWithCommonTrk.rbegin()).second.second];
163  //--First check if one vertex is fully contained in another
164  if( nTCom==v1.selTrk.size() || nTCom==v2.selTrk.size() ){
165  if(nTCom==v1.selTrk.size()){v1.Good = false; continue;}
166  if(nTCom==v2.selTrk.size()){v2.Good = false; continue;}
167  }
168  //--Then check if 2 vertices with common tracks can be simply merged
169  if( nTCom>1 && TMath::Prob( v1.chi2, 2*v1.selTrk.size()-3) > probVrtMergeLimit
170  && TMath::Prob( v2.chi2, 2*v2.selTrk.size()-3) > probVrtMergeLimit){
171  double prbV=mergeAndRefitVertices( v1, v2, newvrt, xAODwrk->listSelTracks, *state);
172  if(prbV>probVrtMergeLimit){
173  v1.Good = false; v2.Good = false;
174  newvrt.Good = true;
175  newvrt.projectedVrt=MomProjDist(newvrt.vertex, primVrt, newvrt.vertexMom); //3D SV-PV distance
176  std::swap(v1,newvrt); //Replace v1 by new vertex
177  continue;
178  } }
179  //--If not mergeable - refine them
180  refineVerticesWithCommonTracks( v1, v2, xAODwrk->listSelTracks, *state);
181  }
182  if(m_fillHist){
183  int cvgood=0; for(const auto& vrt:(*wrkVrtSet)) if(vrt.Good)cvgood++;
184  Hists& h = getHists();
185  h.m_hb_rawVrtN->Fill( (float)cvgood, m_w_1);
186  }
187 //
188 //-Clean duplicated 1track vertices if they exist
189 //
191  for(auto &v1t : (*wrkVrtSet)){
192  if(v1t.selTrk.size()!=1 || !v1t.Good)continue;
193  int ind_t=v1t.selTrk[0];
194  if(trkNPairs[ind_t]<2){ v1t.Good=false; continue; } //Remove 1tr-vertex if track crosses only one other track
195  if( xAODwrk->listSelTracks[ind_t]->pt()<m_cutPt*2){ v1t.Good=false; continue; }; //Tighten track_pt cut for 1-track vertex
196  for(auto &vrt :(*wrkVrtSet)){ // Check if the track is present in another vertex, including other 1-track ones
197  if(!vrt.Good || &v1t==&vrt)continue;
198  if(std::find(vrt.selTrk.begin(),vrt.selTrk.end(),ind_t) != vrt.selTrk.end()){ v1t.Good=false; break; }
199  } }
200  }
201 //
202 //-Remove all bad vertices from the working set
203 //
204  int tmpV=0; while( tmpV<(int)(*wrkVrtSet).size() )if( !(*wrkVrtSet)[tmpV].Good ) { (*wrkVrtSet).erase((*wrkVrtSet).begin()+tmpV);} else {tmpV++;}
205  if((*wrkVrtSet).empty())return finalVertices;
206  if(msgLvl(MSG::DEBUG))printWrkSet(wrkVrtSet.get(),"Intermediate Vertices");
207  for( auto &tmpV : (*wrkVrtSet) ) tmpV.projectedVrt=MomProjDist(tmpV.vertex, primVrt, tmpV.vertexMom ); //Setup ProjectedVrt
208 //----------------------------------------------------------------------------
209 
210 //----------------------------------------------------------------------------
211 //
212 // Final check/merge for close vertices
213 //
214  int foundV1=-1, foundV2=-1;
215  std::vector<double> checkedDst(0);
216  double minDistVV=minVrtVrtDist( wrkVrtSet.get(), foundV1, foundV2, checkedDst); //recalculate VV distances
217  if(m_fillHist){
218  Hists& h = getHists();
219  h.m_hb_distVV->Fill( minDistVV, m_w_1);
220  }
221  while ( minDistVV < m_vertexMergeCut) {
222  if(foundV1<foundV2) { int tmp=foundV1; foundV1=foundV2; foundV2=tmp;}
223  double probV=mergeAndRefitVertices( (*wrkVrtSet)[foundV1], (*wrkVrtSet)[foundV2], newvrt, xAODwrk->listSelTracks, *state, 0);
224  ATH_MSG_DEBUG( "Merged vertex prob=" << probV<<" Vrt1="<<foundV1<<" Vrt2="<<foundV2<<" dst="<<minDistVV);
225  if(probV<probVrtMergeLimit){ //--- If merged vertex is bad - try to remove the worst track
226  int pos=std::max_element(newvrt.chi2PerTrk.begin(),newvrt.chi2PerTrk.end())-newvrt.chi2PerTrk.begin();
227  newvrt.detachedTrack=newvrt.selTrk[pos];
228  newvrt.selTrk.erase(newvrt.selTrk.begin()+pos);
229  probV = refitVertex( newvrt, xAODwrk->listSelTracks, *state, false);
230  ATH_MSG_DEBUG( "Attempt to improve prob=" << probV);
231  }
232  if(probV>probVrtMergeLimit && newvrt.vertexMom.M()<m_vrtMassLimit){ // Good merged vertex found
233  newvrt.projectedVrt=MomProjDist(newvrt.vertex, primVrt, newvrt.vertexMom);
234  std::swap((*wrkVrtSet)[foundV1],newvrt);
235  (*wrkVrtSet)[foundV2].Good=false; //Drop vertex
236  (*wrkVrtSet)[foundV2].selTrk.clear(); //Clean dropped vertex
237  } else checkedDst.push_back(minDistVV);
238  minDistVV=minVrtVrtDist( wrkVrtSet.get(), foundV1, foundV2, checkedDst);
239  }
240 //
241 // Try to improve vertices with big Chi2 if something went wrong. Just precaution.
242  for(int iv=0; iv<(int)wrkVrtSet->size(); iv++) {
243  if(!(*wrkVrtSet)[iv].Good ) continue; //don't work on vertex which is already bad
244  if( (*wrkVrtSet)[iv].selTrk.size()<3 ) continue;
245  double tmpProb=TMath::Prob( (*wrkVrtSet)[iv].chi2, 2*(*wrkVrtSet)[iv].selTrk.size()-3 ); //Chi2 of the original vertex
246  if(tmpProb<m_globVrtProbCut){
247  ATH_MSG_DEBUG( "BAD vertex found prob=" << tmpProb);
248  tmpProb=improveVertexChi2( (*wrkVrtSet)[iv], xAODwrk->listSelTracks, *state, false);
249  (*wrkVrtSet)[iv].projectedVrt=MomProjDist((*wrkVrtSet)[iv].vertex, primVrt, (*wrkVrtSet)[iv].vertexMom);
250  }
251  }
252 //
253 //-Modify too heavy vertices
254  for(auto & iv : (*wrkVrtSet)){
255  if( iv.vertexMom.M()>m_vrtMassLimit ) {
256  ATH_MSG_DEBUG( "Heavy vertex found Mass=" << iv.vertexMom.M());
257  int it_bad=mostHeavyTrk(iv,xAODwrk->listSelTracks);
258  if(it_bad>-1){
259  iv.selTrk.erase( iv.selTrk.begin() + it_bad );
260  refitVertex(iv, xAODwrk->listSelTracks, *state, false);
261  iv.projectedVrt=MomProjDist(iv.vertex, primVrt, iv.vertexMom);
262  } } }
263 //--------------------------------------------------------------------------------------------------------
264 // Final vertex selection/cleaning
265 //
266  double signif3D=0., signif2D=0.;
267 
268 //----- Vertices with >1 tracks
269  for(int iv=0; iv<(int)wrkVrtSet->size(); iv++) {
270  WrkVrt & curVrt=(*wrkVrtSet)[iv];
271  nth=(*wrkVrtSet)[iv].selTrk.size();
272  if(nth == 1) continue; // 1track vertices for later...
273  if(!curVrt.Good ) continue; //don't work on vertex which is already bad
274  (*wrkVrtSet)[iv].Good = false; /* Make all vertices bad for futher selection */
275  if(nth < 1) continue; /* Definitely bad vertices */
276  if((*wrkVrtSet)[iv].projectedVrt<0.) continue; /* Remove vertices behind primary one */
277  if( TMath::Prob( curVrt.chi2, 2*nth-3)<m_globVrtProbCut) continue; /* Bad Chi2 of refitted vertex */
278 //-----------------------------------------------------------------------------------------
279  vrtVrtDist(primVrt,curVrt.vertex, curVrt.vertexCov, signif3D);
280  if(m_fillHist){
281  Hists& h = getHists();
282  if(nth==2 && curVrt.vertexCharge==0) h.m_hb_massPiPi1->Fill(curVrt.vertexMom.M(), m_w_1);
283  h.m_hb_sig3DTot->Fill( signif3D, m_w_1);
284  if(nth==2)h.m_hb_sig3D2tr->Fill( signif3D, m_w_1);
285  if(nth >2)h.m_hb_sig3DNtr->Fill( signif3D, m_w_1);
286  }
287 //
288 //--- Check V0s and conversions. Necessity must be checked in physics applications
289 #if 0
290  if(nth==2 && curVrt.vertexCharge==0 && curVrt.detachedTrack<0){
291  double mass_PiPi = curVrt.vertexMom.M();
292  double mass_PPi = massV0(curVrt.trkAtVrt,m_massP,m_massPi);
293  double mass_EE = massV0(curVrt.trkAtVrt,m_massE,m_massE);
294  if(m_fillHist){
295  Hists& h = getHists();
296  h.m_hb_massPiPi->Fill( mass_PiPi, m_w_1);
297  h.m_hb_massPPi ->Fill( mass_PPi, m_w_1);
298  if( curVrt.vertex.perp()>20.)h.m_hb_massEE ->Fill( mass_EE, m_w_1);
299  }
300  if( std::abs(mass_PiPi-m_massK0) < 22.) continue;
301  if( std::abs(mass_PPi-m_massLam) < 8.) continue;
302  if( mass_EE < 60. && curVrt.vertex.perp() > 20.) continue;
303  }
304 #endif
305 //---
306  if(signif3D<m_selVrtSigCut) continue; //Main PV-SV distance quality cut
307  if(curVrt.vertex.perp() > m_maxSVRadiusCut) continue; // Too far from interaction point
308  curVrt.Good = true; /* Vertex is absolutely good */
309  }
310  if(msgLvl(MSG::DEBUG))printWrkSet(wrkVrtSet.get(),"Final Vertices");
311 //-------------------------------------------
312 // Debug ntuple filling and BDT application
313 //
314  std::vector<double> impact,impactError;
315  for(int iv=0; iv<(int)wrkVrtSet->size(); iv++) {
316  WrkVrt & curVrt=(*wrkVrtSet)[iv];
317  nth=curVrt.selTrk.size();
318  if(!curVrt.Good || nth<2) continue;
319  double minPtT=1.e6, minSig3DT=1.e6, maxSig3DT=0.;
320  int ntrkBC=0,ntrkI=0,sumIBLHits=0,sumBLHits=0;
321  for(i=0;i<nth;i++) {
322  j=curVrt.selTrk[i]; //Track number
323  minPtT=std::min( minPtT, xAODwrk->listSelTracks[j]->pt());
324  m_fitSvc->VKalGetImpact(xAODwrk->listSelTracks[j], primVrt.position(), 1, impact, impactError);
325  double SigR2 = impact[0]*impact[0]/impactError[0];
326  double SigZ2 = impact[1]*impact[1]/impactError[2];
327  minSig3DT=std::min( minSig3DT, sqrt( SigR2 + SigZ2) );
328  maxSig3DT=std::max( maxSig3DT, sqrt( SigR2 + SigZ2) );
329  sumIBLHits += std::max(getIBLHit(xAODwrk->listSelTracks[j]),0);
330  sumBLHits += std::max(getBLHit(xAODwrk->listSelTracks[j]),0);
331  if(m_fillHist) {
332  ntrkBC += getIdHF(xAODwrk->listSelTracks[j]);
333  ntrkI += getG4Inter(xAODwrk->listSelTracks[j]);
334  }
335  }
336  float vProb=TMath::Prob(curVrt.chi2, 2*nth-3);
337  float cosSVPVM=projSV_PV(curVrt.vertex, primVrt, curVrt.vertexMom);
338  float vrtR=curVrt.vertex.perp();
339  TLorentzVector SVPV(curVrt.vertex.x()-primVrt.x(),curVrt.vertex.y()-primVrt.y(),curVrt.vertex.z()-primVrt.z(), 10.);
340  if(m_fillHist){
341  Hists& h = getHists();
342  if( nth>1 ){
343  vrtVrtDist(primVrt,curVrt.vertex, curVrt.vertexCov, signif3D);
344  float Dist2D=vrtVrtDist2D(primVrt,curVrt.vertex, curVrt.vertexCov, signif2D);
345  h.m_curTup->NVrtTrk [h.m_curTup->nNVrt] = nth;
346  h.m_curTup->NVrtTrkHF [h.m_curTup->nNVrt] = ntrkBC;
347  h.m_curTup->NVrtTrkI [h.m_curTup->nNVrt] = ntrkI;
348  h.m_curTup->NVrtProb [h.m_curTup->nNVrt] = vProb;
349  h.m_curTup->NVrtSig3D [h.m_curTup->nNVrt] = signif3D;
350  h.m_curTup->NVrtSig2D [h.m_curTup->nNVrt] = signif2D;
351  h.m_curTup->NVrtDist2D[h.m_curTup->nNVrt] = vrtR<20. ? Dist2D : vrtR;
352  h.m_curTup->NVrtM [h.m_curTup->nNVrt] = curVrt.vertexMom.M();
353  h.m_curTup->NVrtPt [h.m_curTup->nNVrt] = curVrt.vertexMom.Pt();
354  h.m_curTup->NVrtEta [h.m_curTup->nNVrt] = SVPV.Eta();
355  h.m_curTup->NVrtIBL [h.m_curTup->nNVrt] = sumIBLHits;
356  h.m_curTup->NVrtBL [h.m_curTup->nNVrt] = sumBLHits;
357  h.m_curTup->NVrtCosSPM[h.m_curTup->nNVrt] = cosSVPVM;
358  h.m_curTup->NVrtCh [h.m_curTup->nNVrt] = curVrt.vertexCharge;
359  h.m_curTup->NVMinPtT [h.m_curTup->nNVrt] = minPtT;
360  h.m_curTup->NVMinS3DT [h.m_curTup->nNVrt] = minSig3DT;
361  h.m_curTup->NVrtBDT [h.m_curTup->nNVrt] = 1.1;
362  h.m_curTup->NVrtHR1 [h.m_curTup->nNVrt] = xAODwrk->listSelTracks[curVrt.selTrk[0]]->radiusOfFirstHit();
363  h.m_curTup->NVrtHR2 [h.m_curTup->nNVrt] = xAODwrk->listSelTracks[curVrt.selTrk[1]]->radiusOfFirstHit();
364  if( h.m_curTup->nNVrt < DevTuple::maxNVrt-1 )h.m_curTup->nNVrt++;
365  }
366  }
367 //-------------------BDT based rejection
368  if(nth==2){
369  float curVrtPt=std::min(curVrt.vertexMom.Pt(), (double)m_vrt2TrPtLimit);
370  float rhit0=xAODwrk->listSelTracks[curVrt.selTrk[0]]->radiusOfFirstHit();
371  float rhit1=xAODwrk->listSelTracks[curVrt.selTrk[1]]->radiusOfFirstHit();
372  std::vector<float> VARS(10);
373  VARS[0]=vProb;
374  VARS[1]=log(curVrtPt);
375  VARS[2]=log(std::max(minPtT,m_cutPt));
376  VARS[3]=log(vrtR<20. ? SVPV.Perp() : vrtR);
377  VARS[4]=log(std::max(minSig3DT,m_trkSigCut));
378  VARS[5]=log(maxSig3DT);
379  VARS[6]=curVrt.vertexMom.M();
380  VARS[7]=sqrt(std::abs(1.-cosSVPVM*cosSVPVM));
381  VARS[8]=SVPV.Eta();
382  VARS[9]=std::max(rhit0,rhit1);
383  float wgtSelect=m_SV2T_BDT->GetGradBoostMVA(VARS);
384  curVrt.BDT=wgtSelect;
385  if(m_fillHist){
386  Hists& h = getHists();
387  h.m_hb_fakeSVBDT->Fill(wgtSelect,1.);
388  h.m_curTup->NVrtBDT[h.m_curTup->nNVrt-1] = wgtSelect;
389  }
390  if(wgtSelect<m_v2tFinBDTCut) {
391  curVrt.Good = false; // Disable 2-track vertex with bad BDT score
392  if(m_multiWithOneTrkVrt){ // Check if linked 1-track vertex exists and disable it
393  for(auto it : curVrt.selTrk){
394  for(auto &vtmp : (*wrkVrtSet)){
395  if(vtmp.selTrk.size()!=1 || (!vtmp.Good)) continue;
396  if(it==vtmp.detachedTrack)vtmp.Good=false;
397  } } }
398  }
399  }
400  } //End vertex set loop
401 //
402 //-- Debug ntuple for 1track vertex is filled here
403 //
405  Hists& h = getHists();
406  for(auto & vrt : (*wrkVrtSet)) {
407  if( !vrt.Good || vrt.selTrk.size() != 1 ) continue; // Good 1track vertices
408  const auto *xaodtp=xAODwrk->listSelTracks[vrt.selTrk[0]];
409  m_fitSvc->VKalGetImpact(xaodtp, primVrt.position(), 1, impact, impactError);
410  double SigR2 = std::abs(impact[0]*impact[0]/impactError[0]);
411  double SigZ2 = std::abs(impact[1]*impact[1]/impactError[2]);
412  float dist2D=vrtVrtDist2D(primVrt,vrt.vertex, vrt.vertexCov, signif2D);
413  h.m_curTup->NVrtTrk [h.m_curTup->nNVrt] = 1;
414  h.m_curTup->NVrtTrkHF [h.m_curTup->nNVrt] = getIdHF(xaodtp);
415  h.m_curTup->NVrtProb [h.m_curTup->nNVrt] = trkNPairs[vrt.selTrk[0]];
416  h.m_curTup->NVrtSig3D [h.m_curTup->nNVrt] = 0.;
417  h.m_curTup->NVrtSig2D [h.m_curTup->nNVrt] = signif2D;
418  h.m_curTup->NVrtDist2D[h.m_curTup->nNVrt] = dist2D;
419  h.m_curTup->NVrtM [h.m_curTup->nNVrt] = vrt.vertexMom.M();
420  h.m_curTup->NVrtPt [h.m_curTup->nNVrt] = vrt.vertexMom.Pt();
421  h.m_curTup->NVrtCosSPM[h.m_curTup->nNVrt] = 0.;
422  h.m_curTup->NVrtCh [h.m_curTup->nNVrt] = vrt.vertexCharge;
423  h.m_curTup->NVMinPtT [h.m_curTup->nNVrt] = xaodtp->pt();
424  h.m_curTup->NVMinS3DT [h.m_curTup->nNVrt] = sqrt(SigR2 + SigZ2);
425  h.m_curTup->NVrtBDT [h.m_curTup->nNVrt] = 1.1;
426  h.m_curTup->NVrtIBL [h.m_curTup->nNVrt] = std::max(getIBLHit(xaodtp),0);
427  h.m_curTup->NVrtBL [h.m_curTup->nNVrt] = std::max(getBLHit (xaodtp),0);
428  if( h.m_curTup->nNVrt < DevTuple::maxNVrt-1 )h.m_curTup->nNVrt++;
429  } }
430 //-------------------------------------------
431 //Sorting and check
432  std::multimap<double,WrkVrt,std::greater<double>> goodVertexMap;
433  int nNtrVrt=0;
434  for(auto & iv : (*wrkVrtSet) ) {
435  nth=iv.selTrk.size();
436  if(nth==1)iv.BDT=-2.; //To move 1-track vertices to the end of the vertex list later
437  double selector=iv.BDT;
438  if(nth==1) selector=iv.BDT+std::min(iv.vertexMom.Pt()*1.e-5,1.);
439  else if(nth>2) selector=iv.BDT+iv.vertexMom.M()*1.e-5;
440  if( iv.Good && nth>0 ) {
441  goodVertexMap.emplace(selector,iv); // add it and sort in the map
442  if(nth>1)nNtrVrt++;
443  }
444  }
445  if(nNtrVrt==0){ //--- No good vertices at all
446  if(m_fillHist) {
447  Hists& h = getHists();
448  h.m_curTup->nNVrt=0;
449  }
450  return finalVertices;
451  }
452 //
453 //-------------------------------------------
454 // Final vertex refit for full covariance matrix and xAOD::Vertex creation
455 //
456  static const SG::AuxElement::Decorator<float> wgtBDT("wgtBDT");
457  static const SG::AuxElement::Decorator<int> nTrksDec("nTracks");
458  static const SG::AuxElement::Decorator<int> vChrgTot("vCharge");
459  int n1trVrt=0; // Final number of good 1-track vertices
460  for(auto & iv : goodVertexMap){
461  WrkVrt & curVrt=iv.second;
462  nth=curVrt.selTrk.size();
463  xAODwrk->tmpListTracks.clear();
464  for(auto t : curVrt.selTrk)xAODwrk->tmpListTracks.push_back( xAODwrk->listSelTracks[t] );
465  if(m_fillHist){
466  Hists& h = getHists();
467  h.m_hb_totmass->Fill(curVrt.vertexMom.M(), m_w_1);
468  h.m_hb_r2d->Fill( curVrt.vertex.perp(), m_w_1);
469  }
470 //--- Re-fit with full error matrix and xAOD::Vertex creation
471  xAOD::Vertex * tmpVertex=nullptr;
472  if(nth>1){ //-- Common case with full refit
473  tmpVertex=m_fitSvc->fit(xAODwrk->tmpListTracks,curVrt.vertex,*state);
474  } else if(nth==1){ //-- Special case for 1-track vertex
475  tmpVertex=new (std::nothrow) xAOD::Vertex();
476  if(!tmpVertex)continue;
477  tmpVertex->makePrivateStore();
478  tmpVertex->setPosition(curVrt.vertex);
479  std::vector<float> floatErrMtx(6);
480  for(int i=0; i<6; i++) floatErrMtx[i]=curVrt.vertexCov[i];
481  tmpVertex->setCovariance(floatErrMtx);
482  tmpVertex->setFitQuality(curVrt.chi2, (float)(nth*2-3));
483  std::vector<Trk::VxTrackAtVertex> & tmpVTAV=tmpVertex->vxTrackAtVertex(); tmpVTAV.clear();
484  AmgSymMatrix(5) CovMtxP;
485  CovMtxP.setIdentity();
486  Trk::Perigee * tmpMeasPer = new (std::nothrow) Trk::Perigee( 0.,0.,
487  curVrt.trkAtVrt[0][0],
488  curVrt.trkAtVrt[0][1],
489  curVrt.trkAtVrt[0][2],
490  Trk::PerigeeSurface(curVrt.vertex),
491  std::move(CovMtxP) );
492  tmpVTAV.emplace_back( 1., tmpMeasPer );
494  const xAOD::TrackParticleContainer* cont = (const xAOD::TrackParticleContainer* ) (xAODwrk->tmpListTracks[0]->container() );
495  TEL.setStorableObject(*cont);
496  tmpVertex->addTrackAtVertex(TEL,1.);
497  n1trVrt++;
498  }
499  if(tmpVertex){
500  wgtBDT (*tmpVertex) =curVrt.BDT;
501  nTrksDec(*tmpVertex) =curVrt.selTrk.size();
502  vChrgTot(*tmpVertex) =curVrt.vertexCharge;
503  finalVertices.push_back(tmpVertex);
504  }
505  }
506  if(m_fillHist){
507  Hists& h = getHists();
508  h.m_hb_goodvrtN->Fill( finalVertices.size()+0.1, m_w_1);
509  h.m_hb_goodvrt1N->Fill( n1trVrt+0.1, m_w_1);
510  }
511 //-----------------------------------------------------------------------------------
512 // Saving of results
513 //
514  return finalVertices;
515 
516  }
517 
518 } //end namespace
519 
520 
Rec::NewVrtSecInclusiveTool::getIdHF
int getIdHF(const xAOD::TrackParticle *TP) const
Definition: Reconstruction/VKalVrt/NewVrtSecInclusiveTool/src/Utilities.cxx:243
Rec::NewVrtSecInclusiveTool::m_vrtMassLimit
float m_vrtMassLimit
Definition: NewVrtSecInclusiveTool.h:156
Rec::NewVrtSecInclusiveTool::vrtVrtDist2D
static double vrtVrtDist2D(const xAOD::Vertex &primVrt, const Amg::Vector3D &secVrt, const std::vector< double > &vrtErr, double &signif)
Definition: Reconstruction/VKalVrt/NewVrtSecInclusiveTool/src/Utilities.cxx:92
Rec::NewVrtSecInclusiveTool::refineVerticesWithCommonTracks
double refineVerticesWithCommonTracks(WrkVrt &v1, WrkVrt &v2, std::vector< const xAOD::TrackParticle * > &allTrackList, Trk::IVKalState &istate) const
Definition: MultiUtilities.cxx:100
python.SystemOfUnits.second
int second
Definition: SystemOfUnits.py:120
xAOD::Vertex_v1::x
float x() const
Returns the x position.
xAOD::Vertex_v1::setPosition
void setPosition(const Amg::Vector3D &position)
Sets the 3-position.
Rec::NewVrtSecInclusiveTool::m_globVrtProbCut
double m_globVrtProbCut
Definition: NewVrtSecInclusiveTool.h:152
Rec::NewVrtSecInclusiveTool::getIBLHit
static int getIBLHit(const xAOD::TrackParticle *Part)
Definition: Reconstruction/VKalVrt/NewVrtSecInclusiveTool/src/Utilities.cxx:215
xAOD::Vertex_v1::setFitQuality
void setFitQuality(float chiSquared, float numberDoF)
Set the 'Fit Quality' information.
Definition: Vertex_v1.cxx:150
Rec::NewVrtSecInclusiveTool::getBLHit
static int getBLHit(const xAOD::TrackParticle *Part)
Definition: Reconstruction/VKalVrt/NewVrtSecInclusiveTool/src/Utilities.cxx:224
Rec::NewVrtSecInclusiveTool::m_maxSVRadiusCut
double m_maxSVRadiusCut
Definition: NewVrtSecInclusiveTool.h:153
max
#define max(a, b)
Definition: cfImp.cxx:41
Rec::NewVrtSecInclusiveTool::selGoodTrkParticle
void selGoodTrkParticle(workVectorArrxAOD *xAODwrk, const xAOD::Vertex &primVrt) const
Definition: Reconstruction/VKalVrt/NewVrtSecInclusiveTool/src/CutTrk.cxx:21
Rec::NewVrtSecInclusiveTool::Hists
Definition: NewVrtSecInclusiveTool.h:101
Rec::NewVrtSecInclusiveTool::getVrtSecMulti
std::vector< xAOD::Vertex * > getVrtSecMulti(workVectorArrxAOD *inpParticlesxAOD, const xAOD::Vertex &primVrt, compatibilityGraph_t &compatibilityGraph) const
Definition: VrtSecMulti.cxx:28
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
Rec::NewVrtSecInclusiveTool::WrkVrt::vertexCov
std::vector< double > vertexCov
Definition: NewVrtSecInclusiveTool.h:286
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
Trk::PerigeeSurface
Definition: PerigeeSurface.h:43
Trk::ParametersT
Dummy class used to allow special convertors to be called for surfaces owned by a detector element.
Definition: EMErrorDetail.h:25
Rec::NewVrtSecInclusiveTool::WrkVrt::vertexCharge
long int vertexCharge
Definition: NewVrtSecInclusiveTool.h:285
Rec::workVectorArrxAOD::listSelTracks
std::vector< const xAOD::TrackParticle * > listSelTracks
Definition: GNNVertexFitterTool.h:52
Rec::NewVrtSecInclusiveTool::MomProjDist
static double MomProjDist(const Amg::Vector3D &SV, const xAOD::Vertex &PV, const TLorentzVector &Direction)
Definition: MultiUtilities.cxx:260
Rec::NewVrtSecInclusiveTool::WrkVrt::trkAtVrt
std::vector< std::vector< double > > trkAtVrt
Definition: NewVrtSecInclusiveTool.h:288
skel.it
it
Definition: skel.GENtoEVGEN.py:423
AthCommonMsg< AlgTool >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
Rec::NewVrtSecInclusiveTool::mergeAndRefitVertices
double mergeAndRefitVertices(WrkVrt &v1, WrkVrt &v2, WrkVrt &newvrt, std::vector< const xAOD::TrackParticle * > &AllTrackList, Trk::IVKalState &istate, int robKey=0) const
Definition: MultiUtilities.cxx:151
xAOD::Vertex_v1::position
const Amg::Vector3D & position() const
Returns the 3-pos.
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
xAOD::Vertex_v1::setCovariance
void setCovariance(const std::vector< float > &value)
Sets the covariance matrix as a simple vector of values.
Rec::NewVrtSecInclusiveTool::select2TrVrt
void select2TrVrt(std::vector< const xAOD::TrackParticle * > &SelectedTracks, const xAOD::Vertex &primVrt, std::map< long int, std::vector< double >> &vrt, compatibilityGraph_t &compatibilityGraph) const
Definition: Sel2TrkVertices.cxx:31
AmgSymMatrix
#define AmgSymMatrix(dim)
Definition: EventPrimitives.h:52
Rec::NewVrtSecInclusiveTool::massV0
static double massV0(const std::vector< std::vector< double > > &TrkAtVrt, double massP, double massPi)
Definition: Reconstruction/VKalVrt/NewVrtSecInclusiveTool/src/Utilities.cxx:176
TrkVKalVrtFitter.h
Rec::NewVrtSecInclusiveTool::estimVrtPos
static std::vector< double > estimVrtPos(int nTrk, std::deque< long int > &selTrk, std::map< long int, std::vector< double >> &vrt)
Definition: Reconstruction/VKalVrt/NewVrtSecInclusiveTool/src/Utilities.cxx:365
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
Rec::NewVrtSecInclusiveTool::m_cutPt
double m_cutPt
Definition: NewVrtSecInclusiveTool.h:146
Rec::workVectorArrxAOD::tmpListTracks
std::vector< const xAOD::TrackParticle * > tmpListTracks
Definition: NewVrtSecInclusiveTool.h:66
Rec::NewVrtSecInclusiveTool::WrkVrt::chi2
double chi2
Definition: NewVrtSecInclusiveTool.h:289
Rec::NewVrtSecInclusiveTool::m_fitSvc
ToolHandle< Trk::TrkVKalVrtFitter > m_fitSvc
Definition: NewVrtSecInclusiveTool.h:180
Rec::NewVrtSecInclusiveTool::m_multiWithOneTrkVrt
bool m_multiWithOneTrkVrt
Definition: NewVrtSecInclusiveTool.h:172
xAOD::Vertex_v1::addTrackAtVertex
void addTrackAtVertex(const ElementLink< TrackParticleContainer > &tr, float weight=1.0)
Add a new track to the vertex.
Definition: Vertex_v1.cxx:314
Rec::NewVrtSecInclusiveTool::mostHeavyTrk
static int mostHeavyTrk(WrkVrt V, std::vector< const xAOD::TrackParticle * > AllTracks)
Definition: MultiUtilities.cxx:26
Rec::NewVrtSecInclusiveTool::WrkVrt::vertex
Amg::Vector3D vertex
Definition: NewVrtSecInclusiveTool.h:283
Rec::clique_visitor
Definition: NewVrtSecInclusiveTool.h:366
SG::Decorator
Helper class to provide type-safe access to aux data.
Definition: Decorator.h:58
lumiFormat.i
int i
Definition: lumiFormat.py:92
Rec
Name: MuonSpContainer.h Package : offline/Reconstruction/MuonIdentification/muonEvent.
Definition: FakeTrackBuilder.h:10
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
Rec::NewVrtSecInclusiveTool::m_selVrtSigCut
double m_selVrtSigCut
Definition: NewVrtSecInclusiveTool.h:154
Rec::NewVrtSecInclusiveTool::m_massPi
double m_massPi
Definition: NewVrtSecInclusiveTool.h:183
Rec::NewVrtSecInclusiveTool::m_massP
double m_massP
Definition: NewVrtSecInclusiveTool.h:184
chi2
double chi2(TH1 *h0, TH1 *h1)
Definition: comparitor.cxx:522
Rec::NewVrtSecInclusiveTool::m_vrt2TrPtLimit
float m_vrt2TrPtLimit
Definition: NewVrtSecInclusiveTool.h:158
xAOD::Vertex_v1::z
float z() const
Returns the z position.
Rec::NewVrtSecInclusiveTool::WrkVrt::BDT
double BDT
Definition: NewVrtSecInclusiveTool.h:292
BDT.h
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
DataVector< xAOD::TrackParticle_v1 >
WriteCalibToCool.swap
swap
Definition: WriteCalibToCool.py:94
Rec::NewVrtSecInclusiveTool::WrkVrt::selTrk
std::deque< long int > selTrk
Definition: NewVrtSecInclusiveTool.h:282
min
#define min(a, b)
Definition: cfImp.cxx:40
Rec::NewVrtSecInclusiveTool::m_massK0
double m_massK0
Definition: NewVrtSecInclusiveTool.h:186
Rec::NewVrtSecInclusiveTool::m_trkSigCut
double m_trkSigCut
Definition: NewVrtSecInclusiveTool.h:155
Rec::workVectorArrxAOD
Definition: GNNVertexFitterTool.h:51
Rec::workVectorArrxAOD::inpTrk
std::vector< const xAOD::TrackParticle * > inpTrk
Definition: NewVrtSecInclusiveTool.h:67
SG::AuxElement::makePrivateStore
void makePrivateStore()
Create a new (empty) private store for this object.
Definition: AuxElement.cxx:172
Rec::NewVrtSecInclusiveTool::improveVertexChi2
double improveVertexChi2(WrkVrt &vertex, std::vector< const xAOD::TrackParticle * > &allTracks, Trk::IVKalState &istate, bool ifCovV0) const
Definition: MultiUtilities.cxx:195
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
NewVrtSecInclusiveTool.h
ReadCellNoiseFromCoolCompare.v2
v2
Definition: ReadCellNoiseFromCoolCompare.py:364
Rec::NewVrtSecInclusiveTool::compatibilityGraph_t
boost::adjacency_list< boost::listS, boost::vecS, boost::undirectedS > compatibilityGraph_t
Definition: NewVrtSecInclusiveTool.h:278
Rec::NewVrtSecInclusiveTool::m_w_1
double m_w_1
Definition: NewVrtSecInclusiveTool.h:99
Trk::vertex
@ vertex
Definition: MeasurementType.h:21
python.selector.AtlRunQuerySelectorLhcOlc.selector
selector
Definition: AtlRunQuerySelectorLhcOlc.py:611
Rec::NewVrtSecInclusiveTool::minVrtVrtDist
double minVrtVrtDist(std::vector< WrkVrt > *WrkVrtSet, int &indexV1, int &indexV2, std::vector< double > &check) const
Definition: MultiUtilities.cxx:70
h
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
Rec::NewVrtSecInclusiveTool::vrtVrtDist
static double vrtVrtDist(const xAOD::Vertex &primVrt, const Amg::Vector3D &secVrt, const std::vector< double > &vrtErr, double &signif)
Definition: Reconstruction/VKalVrt/NewVrtSecInclusiveTool/src/Utilities.cxx:59
Rec::NewVrtSecInclusiveTool::WrkVrt::vertexMom
TLorentzVector vertexMom
Definition: NewVrtSecInclusiveTool.h:284
Rec::NewVrtSecInclusiveTool::m_vertexMergeCut
float m_vertexMergeCut
Definition: NewVrtSecInclusiveTool.h:163
GeoPrimitivesHelpers.h
Rec::NewVrtSecInclusiveTool::getHists
Hists & getHists() const
Definition: NewVrtSecInclusiveTool.cxx:362
Rec::NewVrtSecInclusiveTool::m_v2tFinBDTCut
float m_v2tFinBDTCut
Definition: NewVrtSecInclusiveTool.h:162
DeMoScan.first
bool first
Definition: DeMoScan.py:534
DEBUG
#define DEBUG
Definition: page_access.h:11
xAOD::Vertex_v1::y
float y() const
Returns the y position.
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
Rec::NewVrtSecInclusiveTool::getG4Inter
static int getG4Inter(const xAOD::TrackParticle *TP)
Definition: Reconstruction/VKalVrt/NewVrtSecInclusiveTool/src/Utilities.cxx:294
Rec::NewVrtSecInclusiveTool::WrkVrt::detachedTrack
int detachedTrack
Definition: NewVrtSecInclusiveTool.h:291
Rec::NewVrtSecInclusiveTool::projSV_PV
static double projSV_PV(const Amg::Vector3D &SV, const xAOD::Vertex &PV, const TLorentzVector &Direction)
Definition: Reconstruction/VKalVrt/NewVrtSecInclusiveTool/src/Utilities.cxx:53
xAOD::Vertex_v1::vxTrackAtVertex
std::vector< Trk::VxTrackAtVertex > & vxTrackAtVertex()
Non-const access to the VxTrackAtVertex vector.
Definition: Vertex_v1.cxx:181
Rec::NewVrtSecInclusiveTool::m_SV2T_BDT
std::unique_ptr< MVAUtils::BDT > m_SV2T_BDT
Definition: NewVrtSecInclusiveTool.h:175
Rec::NewVrtSecInclusiveTool::refitVertex
double refitVertex(WrkVrt &Vrt, std::vector< const xAOD::TrackParticle * > &SelectedTracks, Trk::IVKalState &istate, bool ifCovV0) const
Definition: MultiUtilities.cxx:221
Rec::NewVrtSecInclusiveTool::printWrkSet
void printWrkSet(const std::vector< WrkVrt > *WrkSet, const std::string &name) const
Definition: Reconstruction/VKalVrt/NewVrtSecInclusiveTool/src/Utilities.cxx:26
Rec::NewVrtSecInclusiveTool::m_fillHist
bool m_fillHist
Definition: NewVrtSecInclusiveTool.h:170
Rec::NewVrtSecInclusiveTool::DevTuple::maxNVrt
static constexpr int maxNVrt
Definition: NewVrtSecInclusiveTool.h:203
Rec::NewVrtSecInclusiveTool::m_massE
double m_massE
Definition: NewVrtSecInclusiveTool.h:185
AnalysisMisc.h
Rec::NewVrtSecInclusiveTool::WrkVrt
Definition: NewVrtSecInclusiveTool.h:281
Rec::NewVrtSecInclusiveTool::WrkVrt::Good
bool Good
Definition: NewVrtSecInclusiveTool.h:281
Rec::NewVrtSecInclusiveTool::m_massLam
double m_massLam
Definition: NewVrtSecInclusiveTool.h:187
Rec::NewVrtSecInclusiveTool::nTrkCommon
static int nTrkCommon(std::vector< WrkVrt > *WrkVrtSet, int indexV1, int indexV2)
Definition: MultiUtilities.cxx:48