82 if goodTracks.size() < 2:
return
84 PosDirCharge,CovMat,scalFac = {},{},{}
86 fitStatus = fittedTracks[tr].getFitStatus()
87 xx = fittedTracks[tr].getFittedState()
89 if not global_variables.pidProton
and abs(pid) == 2212:
90 pid = int(math.copysign(211,pid))
91 rep = ROOT.genfit.RKTrackRep(xx.getPDG())
92 state = ROOT.genfit.StateOnPlane(rep)
93 rep.setPosMom(state,xx.getPos(),xx.getMom())
94 PosDirCharge[tr] = {
'position':xx.getPos(),
'direction':xx.getDir(),\
95 'momentum':xx.getMom(),
'charge':xx.getCharge(),
'pdgCode':pid,
'state':xx,
'rep':rep,
'newstate':state}
96 CovMat[tr] = xx.get6DCov()
98 if len(PosDirCharge) < 2:
return
99 if len(PosDirCharge) > 4:
return
100 for t1
in PosDirCharge:
101 c1 = PosDirCharge[t1][
'charge']
102 for t2
in PosDirCharge:
103 if not t2>t1:
continue
105 if PosDirCharge[t2][
'charge'] == c1 :
continue
116 PosDirCharge[tr][
'rep'].extrapolateToPoint(PosDirCharge[tr][
'newstate'], newPos,
False)
118 ut.reportError(
'shipVertex: extrapolation did not worked')
121 self.
newPosDir[tr] = {
'position':PosDirCharge[tr][
'rep'].getPos(PosDirCharge[tr][
'newstate']),\
122 'direction':PosDirCharge[tr][
'rep'].getDir(PosDirCharge[tr][
'newstate']),\
123 'momentum':PosDirCharge[tr][
'rep'].getMom(PosDirCharge[tr][
'newstate'])}
126 dz = abs(zBefore-newPos[2])
129 ut.reportError(
"shipVertex::abort iteration, too many steps")
130 if global_variables.debug:
131 print(
'abort iteration, too many steps, pos=',newPos[0],newPos[1],newPos[2],
' doca=',doca,
'z before and dz',zBefore,dz)
137 scalFac[t1] = (PosDirCharge[t1][
'position'][2]-newPos[2])/PosDirCharge[t1][
'direction'][2]/PosDirCharge[t1][
'momentum'].Mag()
138 scalFac[t2] = (PosDirCharge[t2][
'position'][2]-newPos[2])/PosDirCharge[t2][
'direction'][2]/PosDirCharge[t2][
'momentum'].Mag()
144 if self.
sTree.GetBranch(
"fitTrack2MC"):
145 mctrack = self.
sTree.MCTrack[self.
sTree.fitTrack2MC[t1]]
146 mctrack2 = self.
sTree.MCTrack[self.
sTree.fitTrack2MC[t2]]
147 mcHNL = self.
sTree.MCTrack[mctrack.GetMotherId()]
160 detPlane = ROOT.genfit.DetPlane(ROOT.TVector3(0,0,HNLPos[2]),ROOT.TVector3(1,0,0),ROOT.TVector3(0,1,0))
161 plane = ROOT.genfit.RKTrackRep().makePlane(ROOT.TVector3(0,0,HNLPos[2]),ROOT.TVector3(1,0,0),ROOT.TVector3(0,1,0))
162 st1 = fittedTracks[t1].getFittedState()
163 st2 = fittedTracks[t2].getFittedState()
165 st1.extrapolateToPlane(plane)
167 ut.reportError(
"shipVertex::TwoTrackVertex: extrapolation does not worked")
170 st2.extrapolateToPlane(plane)
172 ut.reportError(
"shipVertex::TwoTrackVertex: extrapolation does not worked")
178 cov = ROOT.TMatrixDSym(10)
181 if i<5
and j<5: cov[i][j]=cov1[i][j]
182 if i>4
and j>4: cov[i][j]=cov2[i-5][j-5]
183 covInv = ROOT.TMatrixDSym()
184 ROOT.genfit.tools.invertMatrix(cov,covInv)
186 self.
y_data = np.array([0.,0.,0.,0.,0.,0.,0.,0.,0.,0.])
187 stVal1 = st1.getState()
188 stVal2 = st2.getState()
191 self.
y_data[i+5]=stVal2[i]
193 self.
Vy = np.zeros(100)
195 self.
Vy[i] = covInv[i//10][i%10]
198 gMinuit = ROOT.TMinuit(9)
200 gMinuit.SetFCN(tempFcn)
201 gMinuit.SetPrintLevel(-1)
202 rc = gMinuit.DefineParameter(0,
'X pos',HNLPos[0], 0.1,0,0)
203 rc = gMinuit.DefineParameter(1,
'Y pos',HNLPos[1], 0.1,0,0)
204 rc = gMinuit.DefineParameter(2,
'Z pos',HNLPos[2], 0.1,0,0)
205 rc = gMinuit.DefineParameter(3,
'tan1X',mom1[0]/mom1[2], 0.1,0,0)
206 rc = gMinuit.DefineParameter(4,
'tan1Y',mom1[1]/mom1[2], 0.1,0,0)
207 rc = gMinuit.DefineParameter(5,
'1/mom1',1./mom1.Mag(), 0.1,0,0)
208 rc = gMinuit.DefineParameter(6,
'tan2X',mom2[0]/mom2[2], 0.1,0,0)
209 rc = gMinuit.DefineParameter(7,
'tan2Y',mom2[1]/mom2[2], 0.1,0,0)
210 rc = gMinuit.DefineParameter(8,
'1/mom2',1./mom2.Mag(), 0.1,0,0)
216 gMinuit.mnexcm(
"HESSE", tmp, -1, err )
219 ut.reportError(
"shipVertex::minos does not work")
222 emat = array(
'd',[0,]*81)
223 gMinuit.mnemat(emat,9)
224 values = array(
'd',[0,]*9)
225 errors = array(
'd',[0,]*9)
226 dValue = ctypes.c_double()
227 dError = ctypes.c_double()
228 rc = gMinuit.GetParameter(0, dValue, dError)
229 values[0]=dValue.value
230 errors[0]=dError.value
231 rc = gMinuit.GetParameter(1, dValue, dError)
232 values[1]=dValue.value
233 errors[1]=dError.value
234 rc = gMinuit.GetParameter(2, dValue, dError)
235 values[2]=dValue.value
236 errors[2]=dError.value
237 rc = gMinuit.GetParameter(3, dValue, dError)
238 values[3]=dValue.value
239 errors[3]=dError.value
240 rc = gMinuit.GetParameter(4, dValue, dError)
241 values[4]=dValue.value
242 errors[4]=dError.value
243 rc = gMinuit.GetParameter(5, dValue, dError)
244 values[5]=dValue.value
245 errors[5]=dError.value
246 rc = gMinuit.GetParameter(6, dValue, dError)
247 values[6]=dValue.value
248 errors[6]=dError.value
249 rc = gMinuit.GetParameter(7, dValue, dError)
250 values[7]=dValue.value
251 errors[7]=dError.value
252 rc = gMinuit.GetParameter(8, dValue, dError)
253 values[8]=dValue.value
254 errors[8]=dError.value
259 HNLPosFit = ROOT.TVector3(xFit,yFit,zFit)
265 m1 = self.
PDG.GetParticle(PosDirCharge[t1][
'pdgCode']).Mass()
266 m2 = self.
PDG.GetParticle(PosDirCharge[t2][
'pdgCode']).Mass()
275 def getP(fitValues,cov,m1,m2):
282 px1 = a3/(a5*ROOT.TMath.Sqrt(1 + a3**2 + a4**2))
283 py1 = a4/(a5*ROOT.TMath.Sqrt(1 + a3**2 + a4**2))
284 pz1 = 1/(a5*ROOT.TMath.Sqrt(1 + a3**2 + a4**2))
285 px2 = a6/(a8*ROOT.TMath.Sqrt(1 + a6**2 + a7**2))
286 py2 = a7/(a8*ROOT.TMath.Sqrt(1 + a6**2 + a7**2))
287 pz2 = 1/(a8*ROOT.TMath.Sqrt(1 + a6**2 + a7**2))
291 E1 = ROOT.TMath.Sqrt(px1**2 + py1**2 + pz1**2 + m1**2)
292 E2 = ROOT.TMath.Sqrt(px2**2 + py2**2 + pz2**2 + m2**2)
293 M = ROOT.TMath.Sqrt(2*E1*E2+m1**2+m2**2-2*pz1*pz2*(1+a3*a6+a4*a7))
295 A5 = 1 + a3**2 + a4**2
296 A8 = 1 + a6**2 + a7**2
297 M_AtoP = ROOT.TMatrixD(4,6)
298 MT_AtoP = ROOT.TMatrixD(6,4)
299 covA = ROOT.TMatrixD(6,6)
300 M_AtoP[0][0] = (1.-a3*a3/A5)/(a5*ROOT.TMath.Sqrt(A5))
301 M_AtoP[0][1] = (-a3*a4/A5)/(a5*ROOT.TMath.Sqrt(A5))
302 M_AtoP[0][2] = (-a3)/(a5*a5*ROOT.TMath.Sqrt(A5))
303 M_AtoP[0][3] = (1.-a6*a6/A8)/(a8*ROOT.TMath.Sqrt(A8))
304 M_AtoP[0][4] = (-a6*a7/A8)/(a8*ROOT.TMath.Sqrt(A8))
305 M_AtoP[0][5] = (-a6)/(a8*a8*ROOT.TMath.Sqrt(A8))
307 M_AtoP[1][0] = (-a3*a4/A5)/(a5*ROOT.TMath.Sqrt(A5))
308 M_AtoP[1][1] = (1.-a4*a4/A5)/(a5*ROOT.TMath.Sqrt(A5))
309 M_AtoP[1][2] = (-a4)/(a5*a5*ROOT.TMath.Sqrt(A5))
310 M_AtoP[1][3] = (-a6*a7/A8)/(a8*ROOT.TMath.Sqrt(A8))
311 M_AtoP[1][4] = (1.-a7*a7/A8)/(a8*ROOT.TMath.Sqrt(A8))
312 M_AtoP[1][5] = (-a7)/(a8*a8*ROOT.TMath.Sqrt(A8))
314 M_AtoP[2][0] = (-a3/A5)/(a5*ROOT.TMath.Sqrt(A5))
315 M_AtoP[2][1] = (-a4/A5)/(a5*ROOT.TMath.Sqrt(A5))
316 M_AtoP[2][2] = (-1.)/(a5*a5*ROOT.TMath.Sqrt(A5))
317 M_AtoP[2][3] = (-a6/A8)/(a8*ROOT.TMath.Sqrt(A8))
318 M_AtoP[2][4] = (-a7/A8)/(a8*ROOT.TMath.Sqrt(A8))
319 M_AtoP[2][5] = (-1.)/(a8*a8*ROOT.TMath.Sqrt(A8))
321 a5a8 = a5*a8*ROOT.TMath.Sqrt(A5)*ROOT.TMath.Sqrt(A8)
323 M_AtoP[3][0] = (-2*a6/a5a8 + 2*a3*E2/(a5*a5*A5*E1))/MM
324 M_AtoP[3][1] = (-2*a7/a5a8 + 2*a4*E2/(a5*a5*A5*E1))/MM
325 M_AtoP[3][2] = (2*(1+a3*a6+a4*a7)/(a5*a5a8) - 2*(1.+a3*a3+a4*a4)*E2/(a5*a5*a5*A5*E1))/MM
326 M_AtoP[3][3] = (-2*a3/a5a8 + 2*a6*E1/(a8*a8*A8*E2))/MM
327 M_AtoP[3][4] = (-2*a4/a5a8 + 2*a7*E1/(a8*a8*A8*E2))/MM
328 M_AtoP[3][5] = (2*(1+a3*a6+a4*a7)/(a8*a5a8) - 2*(1.+a6*a6+a7*a7)*E1/(a8*a8*a8*A8*E2))/MM
332 MT_AtoP[j][i] = M_AtoP[i][j]
335 covA[i//6][i%6] = cov[i//6+3+(i%6+3)*9]
337 tmp = ROOT.TMatrixD(4,6)
338 tmp.Mult(M_AtoP,covA)
339 covP = ROOT.TMatrixD(4,4)
340 covP.Mult(tmp,MT_AtoP)
341 P = ROOT.TLorentzVector()
342 P.SetXYZM(Px,Py,Pz,M)
345 P,covP = getP(values,emat,m1,m2)
354 covV = array(
'd',[emat[0],emat[1],emat[2],emat[1+9],emat[2+9],emat[2+2*9]])
355 covP = array(
'd',[covP[0][0],covP[0][1],covP[0][2],covP[0][3],covP[1][1],covP[1][2],covP[1][3],covP[2][2],covP[2][3],covP[3][3]])
358 vx = ROOT.TLorentzVector(HNLPosFit,0)
359 particle = ROOT.ShipParticle(9900015,0,-1,-1,t1,t2,P,vx)
360 particle.SetCovV(covV)
361 particle.SetCovP(covP)
362 particle.SetDoca(doca)
363 nParts = particles.GetEntries()
364 particles[nParts] = particle