Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
KFVertex.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file KFVertex.cxx
1 /*
2  * This file is part of KFParticle package
3  * Copyright (C) 2007-2019 FIAS Frankfurt Institute for Advanced Studies
4  * 2007-2019 Goethe University of Frankfurt
5  * 2007-2019 Ivan Kisel <I.Kisel@compeng.uni-frankfurt.de>
6  * 2007-2019 Maksym Zyzak
7  *
8  * KFParticle is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * KFParticle is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
22 
23 #include "KFVertex.h"
24 
25 #ifndef KFParticleStandalone
27 #endif
28 
29 KFVertex::KFVertex( const KFPVertex &vertex ): fIsConstrained(0)
30 {
33  vertex.GetXYZ( fP );
34  vertex.GetCovarianceMatrix( fC );
35  fChi2 = vertex.GetChi2();
36  fNDF = 2*vertex.GetNContributors() - 3;
37  fQ = 0;
39  fSFromDecay = 0;
40 }
41 
42 void KFVertex::SetBeamConstraint( float x, float y, float z,
43  float errX, float errY, float errZ )
44 {
49  fP[0] = x;
50  fP[1] = y;
51  fP[2] = z;
52  fC[0] = errX*errX;
53  fC[1] = 0;
54  fC[2] = errY*errY;
55  fC[3] = 0;
56  fC[4] = 0;
57  fC[5] = errZ*errZ;
58  fIsConstrained = 1;
59 }
60 
62 {
64  fIsConstrained = 0;
65 }
66 
67 void KFVertex::ConstructPrimaryVertex( const KFParticle *vDaughters[],
68  int nDaughters, Bool_t vtxFlag[],
69  float ChiCut )
70 {
85  if( nDaughters<2 ) return;
86  float constrP[3]={fP[0], fP[1], fP[2]};
87  float constrC[6]={fC[0], fC[1], fC[2], fC[3], fC[4], fC[5]};
88 
89  Construct( vDaughters, nDaughters, 0, -1 );
90 
91 // SetVtxGuess( fVtxGuess[0], fVtxGuess[1], fVtxGuess[2] );
92 
93  for( int i=0; i<nDaughters; i++ ) vtxFlag[i] = 1;
94 
95  Int_t nRest = nDaughters;
96 // while( nRest>2 )
97 // {
98 // float worstChi = 0.;
99 // Int_t worstDaughter = 0;
100 // for( Int_t it=0; it<nDaughters; it++ ){
101 // if( !vtxFlag[it] ) continue;
102 // const KFParticle &p = *(vDaughters[it]);
103 // //KFVertex tmp = *this - p;
104 // //float chi = p.GetDeviationFromVertex( tmp );
105 // float chi = p.GetDeviationFromVertex( *this );
106 // if( worstChi < chi ){
107 // worstChi = chi;
108 // worstDaughter = it;
109 // }
110 // }
111 // if( worstChi < ChiCut ) break;
112 // std::cout <<"worst 1 " << worstDaughter << " " << worstChi << std::endl;
113 // vtxFlag[worstDaughter] = 0;
114 // //*this -= *(vDaughters[worstDaughter]);
115 // nRest--;
116 // }
117 
118  for( Int_t it=0; it<nDaughters; it++ ){
119  const KFParticle &p = *(vDaughters[it]);
120  float chi = p.GetDeviationFromVertex( *this );
121  if( chi >= ChiCut ){
122  vtxFlag[it] = 0;
123  nRest--;
124  }
125  }
126 
127  if( nRest>=2 ) {// final refit
128 // SetVtxGuess( fP[0], fP[1], fP[2] );
129  if( fIsConstrained ){
130  fP[0] = constrP[0];
131  fP[1] = constrP[1];
132  fP[2] = constrP[2];
133  for( int i=0; i<6; i++ ) fC[i] = constrC[i];
134  }
135  int nDaughtersNew=0;
136  const KFParticle **vDaughtersNew=new const KFParticle *[nDaughters];
137  for( int i=0; i<nDaughters; i++ ){
138  if( vtxFlag[i] ) vDaughtersNew[nDaughtersNew++] = vDaughters[i];
139  }
140  Construct( vDaughtersNew, nDaughtersNew, 0, -1 );
141  if (vDaughtersNew) delete[] vDaughtersNew;
142  }
143 
144  if( nRest<=2 && GetChi2() > ChiCut*ChiCut*GetNDF() ) {
145  for( int i=0; i<nDaughters; i++ ) vtxFlag[i] = 0;
146  fNDF = -3;
147  fChi2 = 0;
148  }
149 }