Esempio n. 1
0
def MatrixInvertRoot(M, tol=1e-32):
    M_root = TMatrixD(np.shape(M)[0], np.shape(M)[1])
    for i in range(np.shape(M)[0]):
        for j in range(np.shape(M)[1]):
            M_root[i][j] = M[i,j]
    M_root.SetTol(tol)
    M_root.Invert()
    M_inv = np.zeros_like(M)
    for i in range(np.shape(M)[0]):
        for j in range(np.shape(M)[1]):
            M_inv[i,j] = M_root[i][j]
    return M_inv
Esempio n. 2
0
def Matrix(rows, cols, type='F'):

    if type == 'F':
        return TMatrixF(rows, cols)
    elif type == 'D':
        return TMatrixD(rows, cols)
    raise TypeError("No matrix for type '%s'" % type)
    def test1MatrixElementAssignment(self):
        """Matrix lookup has to be non-const to allow assigment"""

        m = TMatrixD(5, 5)
        self.assert_(not 'const' in type(m[0]).__name__)

        # test assignment
        m[1][2] = 3.
        self.assertEqual(m[1][2], 3.)

        m[1, 2] = 4.
        self.assertEqual(m[1][2], 4.)
Esempio n. 4
0
    def test08ElementAccess(self):
        """Test access to elements in matrix and array objects."""

        n = 3
        v = TVectorF(n)
        m = TMatrixD(n, n)

        for i in range(n):
            self.assertEqual(v[i], 0.0)

            for j in range(n):
                self.assertEqual(m[i][j], 0.0)
Esempio n. 5
0
def get_condition_number(unfoldingObject):

    probMatrix = unfoldingObject.GetProbabilityMatrix('ProbMatrix')
    # probabilityMatrix = unfoldingObject.GetProbabilityMatrix( probMatrix, TUnfold.kHistMapOutputVert)
    probMatrix.Print()
    # probMatrix.Draw('COLZ')
    raw_input()
    nBins = probMatrix.GetNbinsX()
    m = TMatrixD(nBins, nBins)
    for xbin in range(1, probMatrix.GetNbinsX()):
        for ybin in range(1, probMatrix.GetNbinsY()):
            m[xbin, ybin] = probMatrix.GetBinContent(xbin, ybin)
    svd = TDecompSVD(m)
    svd.Decompose()
    svd.Print()
    sig = svd.GetSig()
    sig.Print()
    nSig = len(sig)
    sigmaMax = sig[0]
    sigmaMin = sig[nSig - 2]
    condition = sigmaMax / max(0, sigmaMin)
    # condition = 1
    print condition
    return condition
Esempio n. 6
0
ex=np.array(len(data_y)*[0],dtype=np.float)
# ... and pass to TGraphErros object
gr=TGraphErrors(nPoints,data_x,data_y,ex,ey)
gr.SetTitle("TGraphErrors mit Fit")
gr.Draw("AP");

Pol=["pol1","pol2","pol3","pol4","pol5","pol6","pol7"]

# Polifit
for i in range(len(polynom)):
  gr.Fit(polynom[i],"V")
  c1.Update()
  gr.Draw('AP')
  fitrp = TVirtualFitter.GetFitter()
  nPar = fitrp.GetNumberTotalParameters()
  covmat = TMatrixD(nPar, nPar,fitrp.GetCovarianceMatrix())
  print('The Covariance Matrix is: ')
  covmat.Print()
  cormat = TMatrixD(covmat)
  for i in range(nPar):
    for j in range(nPar):
      cormat[i][j] = cormat[i][j] / (np.sqrt(covmat[i][i]) * np.sqrt(covmat[j][j]))
  print('The Correlation Matrix is: ')
  cormat.Print()
  raw_input('Press <ret> to continue -> ')

#Legendre Poly
for i in range(len(legendre)):
  gr.Fit(legendre[i],"V")
  
  c1.Update()
Esempio n. 7
0
    def process(self, event):
        if not eval(self.skimFunction):
            return True

        decayMode1 = -1
        decayMode2 = -1

        if self.cfg_ana.l1type == 'tau':
            decayMode1 = event.leg1.decayMode()
        if self.cfg_ana.l2type == 'tau':
            decayMode2 = event.leg2.decayMode()

        # RIC: some PF muons/electron can get the wrong mass assigned.
        # Peg their masses to the PDG values
        if self.cfg_ana.l1type == 'muon':
            mass1 = 0.10566  # PDG mass [GeV]
        elif self.cfg_ana.l1type == 'ele':
            mass1 = 0.51100e-3  # PDG mass [GeV]
        else:
            mass1 = event.leg1.mass()

        if self.cfg_ana.l2type == 'muon':
            mass2 = 0.10566  # PDG mass [GeV]
        elif self.cfg_ana.l2type == 'ele':
            mass2 = 0.51100e-3  # PDG mass [GeV]
        else:
            mass2 = event.leg2.mass()

        leg1 = measuredTauLepton(self.legType[self.cfg_ana.l1type],
                                 event.leg1.pt(), event.leg1.eta(),
                                 event.leg1.phi(), mass1, decayMode1)
        leg2 = measuredTauLepton(self.legType[self.cfg_ana.l2type],
                                 event.leg2.pt(), event.leg2.eta(),
                                 event.leg2.phi(), mass2, decayMode2)

        measuredLeptons = std.vector('svFitStandalone::MeasuredTauLepton')()

        # RIC: not really needed since SVfit internally sorts the inputs
        if hasattr(self.cfg_ana, 'order') and self.cfg_ana.order == '12':
            measuredLeptons.push_back(leg1)
            measuredLeptons.push_back(leg2)
        else:
            measuredLeptons.push_back(leg2)
            measuredLeptons.push_back(leg1)

        metcov = TMatrixD(2, 2)

        a_metcov = array.array('d', [
            event.diLepton.mvaMetSig(0, 0),
            event.diLepton.mvaMetSig(1, 0),
            event.diLepton.mvaMetSig(0, 1),
            event.diLepton.mvaMetSig(1, 1)
        ])

        metcov.SetMatrixArray(a_metcov)

        mex = event.diLepton.met().px()
        mey = event.diLepton.met().py()

        svfit = SVfitAlgo(measuredLeptons, mex, mey, metcov,
                          2 * self.cfg_ana.verbose)


        if hasattr(self.cfg_ana, 'integrateOverVisPtResponse') and \
            self.cfg_ana.integrateOverVisPtResponse:

            shift = not((self.cfg_ana.l1type == 'tau' and     \
                         leg1.decayMode() not in [0, 1, 10]) or \
                        (self.cfg_ana.l2type == 'tau' and     \
                         leg2.decayMode() not in [0, 1, 10]))
            svfit.shiftVisPt(shift, self.inputFile_visPtResolution)

        # add an additional logM(tau,tau) term to the nll
        # to suppress tails on M(tau,tau) (default is false)
        # svfit.addLogM(False)

        if self.cfg_ana.integration == 'VEGAS':
            svfit.integrateVEGAS()
        elif self.cfg_ana.integration == 'MarkovChain':
            svfit.integrateMarkovChain()
        else:
            print 'The integration method must be defined in the cfg as "integration".'
            print 'Options: [VEGAS, MarkovChain]'
            raise

        # debug
        if self.cfg_ana.verbose:
            if abs(event.diLepton.svfitMass() - svfit.mass()) > 0.01:
                print 'WARNING: run {RUN}, lumi {LUMI}, event {EVT}'.format(
                    RUN=str(event.run),
                    LUMI=str(event.lumi),
                    EVT=str(event.eventId))
                print 'precomputed svfit mass   ', event.diLepton.svfitMass()
                print 'svfit mass computed here ', svfit.mass()

        # method override
        event.diLepton.svfitMass = svfit.mass
        event.diLepton.svfitMassError = svfit.massUncert
        event.diLepton.svfitTransverseMass = svfit.transverseMass

        # add also the pt, eta and phi as computed by SVfit
        if self.cfg_ana.integration == 'MarkovChain':
            event.diLepton.svfitPt = svfit.pt
            event.diLepton.svfitPtError = svfit.ptUncert
            event.diLepton.svfitEta = svfit.eta
            event.diLepton.svfitPhi = svfit.phi
            event.diLepton.svfitMET = svfit.fittedMET
            event.diLepton.svfitTaus = svfit.fittedTauLeptons