def fitsegment(self, nodes): if (len(nodes) <= 2): return next = NEXT(self.pgas) kf = nextfilter(next) if (self.radlen > 0.): self.msg.info('KF Simple radlen', self.radlen) kf = simplefilter(self.radlen) #kf = simplefilter(self.radlen) kf.clear() kf.setnodes(nodes) print " fitsegment nodes ", len(kf.nodes) # fit! x0true = nodes[0].getstate('true').vec x0 = KFVector(x0true) z0 = nodes[0].zrun dz = nodes[1].zrun - z0 if (dz == 0.): print ' Fit failed, not valid input nodes ', z0, dz return False, None zdir = dz / abs(dz) C1 = 1. * KFMatrixUnitary(5) state0 = KFData(x0, C1, z0 - 0.1 * zdir, pars={'uz': zdir}) ok, fchi, schi = kf.fit(state0) if (not ok): print " Fit Failed! " return False, None print ' Fit chi2 ', dz, fchi, schi return ok, kf
def FMatrix(self, xvec, zrun, pars=None): """ returns the F, transportation matrix, unitary by default """ n = xvec.Length() F = KFMatrixUnitary(n) debug('kfmodel.Fmatrix ', F) return F
def V0(xres, eres=0.001): """ creates a basic resolution matrix for mesurements """ #uu = KFMatrixUnitary(3) uu = KFMatrixUnitary(2) uu[0, 0] = xres * xres uu[1, 1] = xres * xres #uu[2,2]=eres*eres return uu
def createhits(digits,xres=0.1): """ from the list of digits (x,y,z,delta-ene), return a list of hits. Each hit is computed with a given resolution A hit is a KFData with a vector (x,y) and a cov-matrix. Hit also has an attribute with the delta-ene (dene) """ hits = [] for digit in digits: x,y,z,dene = digit x = x+random.gauss(0.,xres) y = y+random.gauss(0.,xres) V = (xres*xres)*KFMatrixUnitary(2) hit = KFData(KFVector([x,y]),V,zrun=z) hit.dene = dene hits.append(hit) # print 'createhits ',hits return hits
def FMatrix(self, x, dz): """ return the FMatrix """ n = x.Length() F = KFMatrixUnitary(n) F[0, 2] = dz F[1, 3] = dz if (self.eloss): tx, ty, ene0 = x[2], x[3], x[4] icost = sqrt(1. + tx * tx + ty * ty) ds = abs(dz) * icost dene, ds = self.eloss.deltae(ene0, ds) rat = (ene0 - dene) / ene0 #if (rat<=0): warning('ZlineModel.FMatrix e-ratio ',rat) F[4, 4] = max(rat, 0.01) F[4, 4] = 1. debug('ZLineMode.FMatrix x,dz,F ', (x, dz, F)) return F
def seedstate(nodes): """ from a list of nodes generate the seed state (a KFData (x,y,tx,ty,ene) and cov-matrix) where tx,ty are the tangent in the x,y axis """ x0 = nodes[0].hit.vec x1 = nodes[1].hit.vec z0 = nodes[0].zrun dz = nodes[1].zrun-z0 if (dz==0.): print ' Fit failed, not valid input nodes ',z0,dz #print ' node 0 ',nodes[0] #print ' node 1 ',nodes[1] return False,None ene = nodes[0].hit.ene tx,ty = (x0[0]-x1[0])/dz,(x0[1]-x1[1])/dz xx = KFVector([x0[0],x0[1],tx,ty,ene]) zdir = dz/abs(dz) C1 = 100.*KFMatrixUnitary(5) state0 = KFData(xx,C1,z0-0.1*zdir,pars={'uz':zdir}) #print "seedstate ",state0 return state0