34 const double probVrtMergeLimit=0.01;
37 int inpNPart=xAODwrk->inpTrk.size();
38 std::vector<const xAOD::NeutralParticle*> neutralPartDummy(0);
39 ATH_MSG_DEBUG(
"getVrtSecMulti() called with NPart=" << inpNPart);
41 std::vector<xAOD::Vertex*> finalVertices(0);
43 if( inpNPart < 2 ) {
return finalVertices;}
46 int nTracks = xAODwrk->listSelTracks.size();
48 if( nTracks < 2 ) {
return finalVertices;}
54 h.m_hb_ntrksel->Fill( (
double) nTracks,
m_w_1);
65 std::map<long int,std::vector<double>> foundVrt2t;
66 select2TrVrt(xAODwrk->listSelTracks, primVrt, foundVrt2t, compatibilityGraph);
69 ATH_MSG_DEBUG(
" Defined edges in the graph="<< num_edges(compatibilityGraph));
70 if(num_edges(compatibilityGraph)==0){
return finalVertices;}
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();
84 long int NPTR=0, nth=2;
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]);}
94 xAODwrk->tmpListTracks.clear();
97 xAODwrk->tmpListTracks.push_back( xAODwrk->listSelTracks.at(newvrt.selTrk[
i]) );
98 vpsum += xAODwrk->listSelTracks.at(newvrt.selTrk[
i])->p4();
100 std::vector<double> iniVrtPos=
estimVrtPos(nTracks,newvrt.selTrk,foundVrt2t);
101 m_fitSvc->setApproximateVertex(iniVrtPos[0], iniVrtPos[1], iniVrtPos[2], *state);
102 sc=
m_fitSvc->VKalVrtFit(xAODwrk->tmpListTracks, neutralPartDummy,
103 newvrt.vertex, newvrt.vertexMom, newvrt.vertexCharge, newvrt.vertexCov,
104 newvrt.chi2PerTrk, newvrt.trkAtVrt, newvrt.chi2,
106 if(
sc.isFailure() )
continue;
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;
110 if(newvrt.chi2PerTrk.size()==2) newvrt.chi2PerTrk[0]=newvrt.chi2PerTrk[1]=newvrt.chi2/2.;
112 newvrt.projectedVrt=
MomProjDist(newvrt.vertex, primVrt, newvrt.vertexMom);
113 wrkVrtSet->push_back(newvrt);
115 std::sort(wrkVrtSet->begin(),wrkVrtSet->end(),[](WrkVrt
a, WrkVrt
b){return a.selTrk.size()>b.selTrk.size();});
124 if((*wrkVrtSet).empty())
return finalVertices;
128 std::vector<int> trkNPairs(nTracks,0);
129 for(
auto &vrt : (*wrkVrtSet)){
130 int ntInV=vrt.selTrk.size()-1;
131 for(
auto &trk : vrt.selTrk)trkNPairs.at(trk) += ntInV;
137 std::multimap<double,std::pair<int,int>> vrtWithCommonTrk;
139 int nSoluI=(*wrkVrtSet).size();
140 vrtWithCommonTrk.clear();
141 unsigned int nTComMax=0;
142 for(
int iv=0; iv<nSoluI-1; iv++ ){
143 if(!(*wrkVrtSet)[iv].Good)
continue;
144 if( (*wrkVrtSet)[iv].selTrk.size()<nTComMax)
continue;
145 for(
int jv=iv+1; jv<nSoluI; jv++){
146 if(!(*wrkVrtSet)[jv].Good)
continue;
147 if( (*wrkVrtSet)[jv].selTrk.size()<nTComMax)
continue;
148 unsigned int nTCom=
nTrkCommon( wrkVrtSet.get(), iv, jv);
150 if(nTCom<nTComMax)
continue;
151 double sumChi2=(*wrkVrtSet)[iv].chi2+(*wrkVrtSet)[jv].chi2;
152 sumChi2=
std::min(sumChi2,999.)*1.e-3;
153 vrtWithCommonTrk.emplace(nTCom+sumChi2,std::make_pair(iv,jv));
156 if(vrtWithCommonTrk.empty())
break;
161 std::multimap<double,std::pair<int,int>>::reverse_iterator ovitr=vrtWithCommonTrk.rbegin();
162 for( ; ovitr!=vrtWithCommonTrk.rend(); ovitr++){
163 WrkVrt & v1 = (*wrkVrtSet)[(*ovitr).second.first];
164 WrkVrt &
v2 = (*wrkVrtSet)[(*ovitr).second.second];
165 if(!v1.Good)
continue;
166 if(!
v2.Good)
continue;
168 unsigned int nTCom=
nTrkCommon( wrkVrtSet.get(), (*ovitr).second.first, (*ovitr).second.second);
169 if(nTCom<nTComMax)
continue;
171 if( nTCom==v1.selTrk.size() || nTCom==
v2.selTrk.size() ){
172 if(nTCom==v1.selTrk.size()){v1.Good =
false;
continue;}
173 if(nTCom==
v2.selTrk.size()){
v2.Good =
false;
continue;}
176 if( nTCom>1 && TMath::Prob( v1.chi2, 2*v1.selTrk.size()-3) > probVrtMergeLimit
177 && TMath::Prob(
v2.chi2, 2*
v2.selTrk.size()-3) > probVrtMergeLimit){
179 if(prbV>probVrtMergeLimit){
180 v1.Good =
false;
v2.Good =
false;
182 newvrt.projectedVrt=
MomProjDist(newvrt.vertex, primVrt, newvrt.vertexMom);
191 int cvgood=0;
for(
const auto& vrt:(*wrkVrtSet))
if(vrt.Good)cvgood++;
193 h.m_hb_rawVrtN->Fill( (
float)cvgood,
m_w_1);
199 for(
auto &v1t : (*wrkVrtSet)){
200 if(v1t.selTrk.size()!=1 || !v1t.Good)
continue;
201 int ind_t=v1t.selTrk[0];
202 if(trkNPairs[ind_t]<2){ v1t.Good=
false;
continue; }
203 if( xAODwrk->listSelTracks[ind_t]->pt()<
m_cutPt*2){ v1t.Good=
false;
continue; };
204 for(
auto &vrt :(*wrkVrtSet)){
205 if(!vrt.Good || &v1t==&vrt)
continue;
206 if(
std::find(vrt.selTrk.begin(),vrt.selTrk.end(),ind_t) != vrt.selTrk.end()){ v1t.Good=
false;
break; }
212 int tmpV=0;
while( tmpV<(
int)(*wrkVrtSet).size() )
if( !(*wrkVrtSet)[tmpV].Good ) { (*wrkVrtSet).erase((*wrkVrtSet).begin()+tmpV);}
else {tmpV++;}
213 if((*wrkVrtSet).empty())
return finalVertices;
215 for(
auto &tmpV : (*wrkVrtSet) ) tmpV.projectedVrt=
MomProjDist(tmpV.vertex, primVrt, tmpV.vertexMom );
222 int foundV1=-1, foundV2=-1;
223 std::vector<double> checkedDst(0);
224 double minDistVV=
minVrtVrtDist( wrkVrtSet.get(), foundV1, foundV2, checkedDst);
227 h.m_hb_distVV->Fill( minDistVV,
m_w_1);
230 if(foundV1<foundV2) {
int tmp=foundV1; foundV1=foundV2; foundV2=
tmp;}
231 double probV=
mergeAndRefitVertices( (*wrkVrtSet)[foundV1], (*wrkVrtSet)[foundV2], newvrt, xAODwrk->listSelTracks, *state, 0);
232 ATH_MSG_DEBUG(
"Merged vertex prob=" << probV<<
" Vrt1="<<foundV1<<
" Vrt2="<<foundV2<<
" dst="<<minDistVV);
233 if(probV<probVrtMergeLimit){
234 int pos=std::max_element(newvrt.chi2PerTrk.begin(),newvrt.chi2PerTrk.end())-newvrt.chi2PerTrk.begin();
235 newvrt.detachedTrack=newvrt.selTrk[
pos];
236 newvrt.selTrk.erase(newvrt.selTrk.begin()+
pos);
237 probV =
refitVertex( newvrt, xAODwrk->listSelTracks, *state,
false);
240 if(probV>probVrtMergeLimit && newvrt.vertexMom.M()<
m_vrtMassLimit){
241 newvrt.projectedVrt=
MomProjDist(newvrt.vertex, primVrt, newvrt.vertexMom);
243 (*wrkVrtSet)[foundV2].Good=
false;
244 (*wrkVrtSet)[foundV2].selTrk.clear();
245 }
else checkedDst.push_back(minDistVV);
246 minDistVV=
minVrtVrtDist( wrkVrtSet.get(), foundV1, foundV2, checkedDst);
250 for(
int iv=0; iv<(
int)wrkVrtSet->size(); iv++) {
251 if(!(*wrkVrtSet)[iv].Good )
continue;
252 if( (*wrkVrtSet)[iv].selTrk.size()<3 )
continue;
253 double tmpProb=TMath::Prob( (*wrkVrtSet)[iv].
chi2, 2*(*wrkVrtSet)[iv].selTrk.size()-3 );
256 tmpProb=
improveVertexChi2( (*wrkVrtSet)[iv], xAODwrk->listSelTracks, *state,
false);
257 (*wrkVrtSet)[iv].projectedVrt=
MomProjDist((*wrkVrtSet)[iv].
vertex, primVrt, (*wrkVrtSet)[iv].vertexMom);
262 for(
auto & iv : (*wrkVrtSet)){
264 ATH_MSG_DEBUG(
"Heavy vertex found Mass=" << iv.vertexMom.M());
267 iv.selTrk.erase( iv.selTrk.begin() + it_bad );
268 refitVertex(iv, xAODwrk->listSelTracks, *state,
false);
269 iv.projectedVrt=
MomProjDist(iv.vertex, primVrt, iv.vertexMom);
274 double signif3D=0., signif2D=0.;
277 for(
int iv=0; iv<(
int)wrkVrtSet->size(); iv++) {
278 WrkVrt & curVrt=(*wrkVrtSet)[iv];
279 nth=(*wrkVrtSet)[iv].selTrk.size();
280 if(nth == 1)
continue;
281 if(!curVrt.Good )
continue;
282 (*wrkVrtSet)[iv].Good =
false;
283 if(nth < 1)
continue;
284 if((*wrkVrtSet)[iv].projectedVrt<0.)
continue;
287 vrtVrtDist(primVrt,curVrt.vertex, curVrt.vertexCov, signif3D);
290 if(nth==2 && curVrt.vertexCharge==0)
h.m_hb_massPiPi1->Fill(curVrt.vertexMom.M(),
m_w_1);
291 h.m_hb_sig3DTot->Fill( signif3D,
m_w_1);
292 if(nth==2)
h.m_hb_sig3D2tr->Fill( signif3D,
m_w_1);
293 if(nth >2)
h.m_hb_sig3DNtr->Fill( signif3D,
m_w_1);
298 if(nth==2 && curVrt.vertexCharge==0 && curVrt.detachedTrack<0){
299 double mass_PiPi = curVrt.vertexMom.M();
304 h.m_hb_massPiPi->Fill( mass_PiPi,
m_w_1);
305 h.m_hb_massPPi ->Fill( mass_PPi,
m_w_1);
306 if( curVrt.vertex.perp()>20.)
h.m_hb_massEE ->Fill( mass_EE,
m_w_1);
308 if( std::abs(mass_PiPi-
m_massK0) < 22.)
continue;
309 if( std::abs(mass_PPi-
m_massLam) < 8.)
continue;
310 if( mass_EE < 60. && curVrt.vertex.perp() > 20.)
continue;
322 std::vector<double> impact,impactError;
323 for(
int iv=0; iv<(
int)wrkVrtSet->size(); iv++) {
324 WrkVrt & curVrt=(*wrkVrtSet)[iv];
325 nth=curVrt.selTrk.size();
326 if(!curVrt.Good || nth<2)
continue;
327 double minPtT=1.e6, minSig3DT=1.e6, maxSig3DT=0.;
328 int ntrkBC=0,ntrkI=0,sumIBLHits=0,sumBLHits=0;
331 minPtT=
std::min( minPtT, xAODwrk->listSelTracks[j]->pt());
332 m_fitSvc->VKalGetImpact(xAODwrk->listSelTracks[j], primVrt.
position(), 1, impact, impactError);
333 double SigR2 = impact[0]*impact[0]/impactError[0];
334 double SigZ2 = impact[1]*impact[1]/impactError[2];
335 minSig3DT=
std::min( minSig3DT, sqrt( SigR2 + SigZ2) );
336 maxSig3DT=
std::max( maxSig3DT, sqrt( SigR2 + SigZ2) );
340 ntrkBC +=
getIdHF(xAODwrk->listSelTracks[j]);
341 ntrkI +=
getG4Inter(xAODwrk->listSelTracks[j]);
344 float vProb=TMath::Prob(curVrt.chi2, 2*nth-3);
345 float cosSVPVM=
projSV_PV(curVrt.vertex, primVrt, curVrt.vertexMom);
346 float vrtR=curVrt.vertex.perp();
347 TLorentzVector SVPV(curVrt.vertex.x()-primVrt.
x(),curVrt.vertex.y()-primVrt.
y(),curVrt.vertex.z()-primVrt.
z(), 10.);
351 vrtVrtDist(primVrt,curVrt.vertex, curVrt.vertexCov, signif3D);
352 float Dist2D=
vrtVrtDist2D(primVrt,curVrt.vertex, curVrt.vertexCov, signif2D);
353 h.m_curTup->NVrtTrk [
h.m_curTup->nNVrt] = nth;
354 h.m_curTup->NVrtTrkHF [
h.m_curTup->nNVrt] = ntrkBC;
355 h.m_curTup->NVrtTrkI [
h.m_curTup->nNVrt] = ntrkI;
356 h.m_curTup->NVrtProb [
h.m_curTup->nNVrt] = vProb;
357 h.m_curTup->NVrtSig3D [
h.m_curTup->nNVrt] = signif3D;
358 h.m_curTup->NVrtSig2D [
h.m_curTup->nNVrt] = signif2D;
359 h.m_curTup->NVrtDist2D[
h.m_curTup->nNVrt] = vrtR<20. ? Dist2D : vrtR;
360 h.m_curTup->NVrtM [
h.m_curTup->nNVrt] = curVrt.vertexMom.M();
361 h.m_curTup->NVrtPt [
h.m_curTup->nNVrt] = curVrt.vertexMom.Pt();
362 h.m_curTup->NVrtEta [
h.m_curTup->nNVrt] = SVPV.Eta();
363 h.m_curTup->NVrtIBL [
h.m_curTup->nNVrt] = sumIBLHits;
364 h.m_curTup->NVrtBL [
h.m_curTup->nNVrt] = sumBLHits;
365 h.m_curTup->NVrtCosSPM[
h.m_curTup->nNVrt] = cosSVPVM;
366 h.m_curTup->NVrtCh [
h.m_curTup->nNVrt] = curVrt.vertexCharge;
367 h.m_curTup->NVMinPtT [
h.m_curTup->nNVrt] = minPtT;
368 h.m_curTup->NVMinS3DT [
h.m_curTup->nNVrt] = minSig3DT;
369 h.m_curTup->NVrtBDT [
h.m_curTup->nNVrt] = 1.1;
370 h.m_curTup->NVrtHR1 [
h.m_curTup->nNVrt] = xAODwrk->listSelTracks[curVrt.selTrk[0]]->radiusOfFirstHit();
371 h.m_curTup->NVrtHR2 [
h.m_curTup->nNVrt] = xAODwrk->listSelTracks[curVrt.selTrk[1]]->radiusOfFirstHit();
378 float rhit0=xAODwrk->listSelTracks[curVrt.selTrk[0]]->radiusOfFirstHit();
379 float rhit1=xAODwrk->listSelTracks[curVrt.selTrk[1]]->radiusOfFirstHit();
380 std::vector<float> VARS(10);
382 VARS[1]=
log(curVrtPt);
384 VARS[3]=
log(vrtR<20. ? SVPV.Perp() : vrtR);
386 VARS[5]=
log(maxSig3DT);
387 VARS[6]=curVrt.vertexMom.M();
388 VARS[7]=sqrt(std::abs(1.-cosSVPVM*cosSVPVM));
391 float wgtSelect=
m_SV2T_BDT->GetGradBoostMVA(VARS);
392 curVrt.BDT=wgtSelect;
395 h.m_hb_fakeSVBDT->Fill(wgtSelect,1.);
396 h.m_curTup->NVrtBDT[
h.m_curTup->nNVrt-1] = wgtSelect;
401 for(
auto it : curVrt.selTrk){
402 for(
auto &vtmp : (*wrkVrtSet)){
403 if(vtmp.selTrk.size()!=1 || (!vtmp.Good))
continue;
404 if(
it==vtmp.detachedTrack)vtmp.Good=
false;
414 for(
auto & vrt : (*wrkVrtSet)) {
415 if( !vrt.Good || vrt.selTrk.size() != 1 )
continue;
416 const auto *xaodtp=xAODwrk->listSelTracks[vrt.selTrk[0]];
417 m_fitSvc->VKalGetImpact(xaodtp, primVrt.
position(), 1, impact, impactError);
418 double SigR2 = std::abs(impact[0]*impact[0]/impactError[0]);
419 double SigZ2 = std::abs(impact[1]*impact[1]/impactError[2]);
420 float dist2D=
vrtVrtDist2D(primVrt,vrt.vertex, vrt.vertexCov, signif2D);
421 h.m_curTup->NVrtTrk [
h.m_curTup->nNVrt] = 1;
422 h.m_curTup->NVrtTrkHF [
h.m_curTup->nNVrt] =
getIdHF(xaodtp);
423 h.m_curTup->NVrtProb [
h.m_curTup->nNVrt] = trkNPairs[vrt.selTrk[0]];
424 h.m_curTup->NVrtSig3D [
h.m_curTup->nNVrt] = 0.;
425 h.m_curTup->NVrtSig2D [
h.m_curTup->nNVrt] = signif2D;
426 h.m_curTup->NVrtDist2D[
h.m_curTup->nNVrt] = dist2D;
427 h.m_curTup->NVrtM [
h.m_curTup->nNVrt] = vrt.vertexMom.M();
428 h.m_curTup->NVrtPt [
h.m_curTup->nNVrt] = vrt.vertexMom.Pt();
429 h.m_curTup->NVrtCosSPM[
h.m_curTup->nNVrt] = 0.;
430 h.m_curTup->NVrtCh [
h.m_curTup->nNVrt] = vrt.vertexCharge;
431 h.m_curTup->NVMinPtT [
h.m_curTup->nNVrt] = xaodtp->pt();
432 h.m_curTup->NVMinS3DT [
h.m_curTup->nNVrt] = sqrt(SigR2 + SigZ2);
433 h.m_curTup->NVrtBDT [
h.m_curTup->nNVrt] = 1.1;
440 std::multimap<double,WrkVrt,std::greater<double>> goodVertexMap;
442 for(
auto & iv : (*wrkVrtSet) ) {
443 nth=iv.selTrk.size();
444 if(nth==1)iv.BDT=-2.;
447 else if(nth>2)
selector=iv.BDT+iv.vertexMom.M()*1.e-5;
448 if( iv.Good && nth>0 ) {
458 return finalVertices;
468 for(
auto & iv : goodVertexMap){
469 WrkVrt & curVrt=iv.second;
470 nth=curVrt.selTrk.size();
471 xAODwrk->tmpListTracks.clear();
472 for(
auto t : curVrt.selTrk)xAODwrk->tmpListTracks.push_back( xAODwrk->listSelTracks[
t] );
475 h.m_hb_totmass->Fill(curVrt.vertexMom.M(),
m_w_1);
476 h.m_hb_r2d->Fill( curVrt.vertex.perp(),
m_w_1);
481 tmpVertex=
m_fitSvc->fit(xAODwrk->tmpListTracks,curVrt.vertex,*state);
484 if(!tmpVertex)
continue;
487 std::vector<float> floatErrMtx(6);
488 for(
int i=0;
i<6;
i++) floatErrMtx[
i]=curVrt.vertexCov[
i];
491 std::vector<Trk::VxTrackAtVertex> & tmpVTAV=tmpVertex->
vxTrackAtVertex(); tmpVTAV.clear();
493 CovMtxP.setIdentity();
494 Trk::Perigee * tmpMeasPer =
new (std::nothrow)
Trk::Perigee( 0.,0.,
495 curVrt.trkAtVrt[0][0],
496 curVrt.trkAtVrt[0][1],
497 curVrt.trkAtVrt[0][2],
499 std::move(CovMtxP) );
500 tmpVTAV.emplace_back( 1., tmpMeasPer );
503 TEL.setStorableObject(*cont);
504 tmpVertex->addTrackAtVertex(TEL,1.);
508 wgtBDT (*tmpVertex) =curVrt.BDT;
509 nTrksDec(*tmpVertex) =curVrt.selTrk.size();
510 vChrgTot(*tmpVertex) =curVrt.vertexCharge;
511 finalVertices.push_back(tmpVertex);
516 h.m_hb_goodvrtN->Fill( finalVertices.size()+0.1,
m_w_1);
517 h.m_hb_goodvrt1N->Fill( n1trVrt+0.1,
m_w_1);
522 return finalVertices;