Esempio n. 1
0
def FillRandom(layerid, detid, nhits):
    rnd = TRandom()
    rnd.SetSeed()
    suf = suffix(layerid, detid)
    for n in range(nhits):
        xtrk = rnd.Uniform(0, x_chip_sensitive)
        ytrk = rnd.Uniform(-y_chip_sensitive / 2, +y_chip_sensitive / 2)
        histos["h_hits" + suf].Fill(xtrk, ytrk)
Esempio n. 2
0
def bkgtracks(N):
    tracks = []
    resolution = 0.001  ## cm (10 um)
    rnd = TRandom()
    rnd.SetSeed()
    for i in range(N):
        R = cfgmap["Rbeampipe"] - cfgmap["Wbeampipe"]
        phi = rnd.Uniform(0, 2 * ROOT.TMath.Pi())
        x0 = R * ROOT.TMath.Cos(phi)
        y0 = R * ROOT.TMath.Sin(phi)
        z0 = cfgmap["zDipoleExit"]

        z4 = cfgmap["zLayer4"]
        x4 = rnd.Uniform(1.15 * cfgmap["xPsideL"], 1.15 * cfgmap["xEsideR"])
        y4 = rnd.Uniform(-1.15 * cfgmap["Hstave"] / 2,
                         1.15 * cfgmap["Hstave"] / 2)

        r0 = [x0, y0, z0]
        r4 = [x4, y4, z4]

        z1 = cfgmap["zLayer1"]
        x1 = xofz(r4, r0, z1) + rnd.Gaus(0, resolution)
        y1 = yofz(r4, r0, z1) + rnd.Gaus(0, resolution)

        z2 = cfgmap["zLayer2"]
        x2 = xofz(r4, r0, z2) + rnd.Gaus(0, resolution)
        y2 = yofz(r4, r0, z2) + rnd.Gaus(0, resolution)

        z3 = cfgmap["zLayer3"]
        x3 = xofz(r4, r0, z3) + rnd.Gaus(0, resolution)
        y3 = yofz(r4, r0, z3) + rnd.Gaus(0, resolution)

        z5 = 360
        x5 = xofz(r4, r0, z5)
        y5 = yofz(r4, r0, z5)

        line = TPolyLine3D()
        line.SetNextPoint(x0, y0, z0)
        line.SetNextPoint(x1, y1, z1)
        line.SetNextPoint(x2, y2, z2)
        line.SetNextPoint(x3, y3, z3)
        line.SetNextPoint(x4, y4, z4)
        line.SetNextPoint(x5, y5, z5)
        line.SetLineColor(ROOT.kRed)
        tracks.append(line)

    return tracks
Esempio n. 3
0
def GetContours(clusters, positions, h, hsig=None):
    contourspts = []
    contours = []
    bkgmarkers = []
    sigmarkers = []
    rnd = TRandom()
    rnd.SetSeed()
    for i in range(len(clusters)):
        cluster = clusters[i]
        position = positions[i]
        icol = int(rnd.Uniform(0, len(colors)))
        col = colors[icol]
        contourpts, contdata, contour = GetClusterContour(cluster, h, col)
        # marker,issig = GetClusterMarker(position,h,col,hsig)
        marker, issig = GetClusterMarker(position, h, ROOT.kGray + 1, hsig)
        contourspts.append(contourpts)
        contours.append(contour)
        if (issig): sigmarkers.append(marker)
        else: bkgmarkers.append(marker)
    return contourspts, bkgmarkers, sigmarkers, contours
sidesarr = getLogicSidesArr()

n = 0  ### init n
for n in range(Nevt):
    ## clear the output vectors
    clusters_xyz.clear()
    clusters_type.clear()
    clusters_id.clear()

    ### embed some noise ***clusters***
    ids = [
        1000, 2000, 3000, 4000
    ]  ## assuming there's no chance to have more than 1k noise clusters per layer
    layer2z = {1: 300, 2: 310, 3: 320, 4: 330}
    rnd = TRandom()
    rnd.SetSeed()
    for side in sidesarr:
        for kN in range(NnoiseClusters):
            for layer in layers:
                x = rnd.Uniform(xPsideL, xPsideR) if (
                    side == "Pside") else rnd.Uniform(xEsideL, xEsideR)
                y = rnd.Uniform(-0.75, +0.75)
                z = layer2z[layer]
                cluster = ROOT.TPolyMarker3D()
                cluster.SetNextPoint(x, y, z)
                clusters_xyz.push_back(cluster)
                clusters_type.push_back(-1)
                clusters_id.push_back(ids[layer - 1])
                ids[layer - 1] += 1

    ### embed background ***tracks***
def main():
    ##########################################################################################
    ##########################################################################################
    ##########################################################################################
    ### read fits to root file
    # fitsEx = GetFits()

    svd0Seed = ROOT.std.vector( float )()
    svd1Seed = ROOT.std.vector( float )()
    svd2Seed = ROOT.std.vector( float )()
    chi2xzSeed = ROOT.std.vector( float )()
    chi2yzSeed = ROOT.std.vector( float )()
    residxzSeed = ROOT.std.vector( float )()
    residyzSeed = ROOT.std.vector( float )()
    issigSeed = ROOT.std.vector( int )()
    iGenMatch = ROOT.std.vector( int )()
    x1Seed = ROOT.std.vector( float )()
    y1Seed = ROOT.std.vector( float )()
    z1Seed = ROOT.std.vector( float )()
    x2Seed = ROOT.std.vector( float )()
    y2Seed = ROOT.std.vector( float )()
    z2Seed = ROOT.std.vector( float )()
    x3Seed = ROOT.std.vector( float )()
    y3Seed = ROOT.std.vector( float )()
    z3Seed = ROOT.std.vector( float )()
    x4Seed = ROOT.std.vector( float )()
    y4Seed = ROOT.std.vector( float )()
    z4Seed = ROOT.std.vector( float )()
    pxSeed = ROOT.std.vector( float )()
    pySeed = ROOT.std.vector( float )()
    pzSeed = ROOT.std.vector( float )()
    eSeed  = ROOT.std.vector( float )()
    pxGen  = ROOT.std.vector( float )()
    pyGen  = ROOT.std.vector( float )()
    pzGen  = ROOT.std.vector( float )()
    eGen   = ROOT.std.vector( float )()
    qGen   = ROOT.std.vector( float )()
    iGen   = ROOT.std.vector( int )()
    tF = TFile("../data/root/seeds_"+proc+".root","RECREATE")
    tF.cd()
    tT = TTree("seeds","seeds")

    tT.Branch('svd0Seed',svd0Seed)
    tT.Branch('svd1Seed',svd1Seed)
    tT.Branch('svd2Seed',svd2Seed)
    tT.Branch('chi2xzSeed',chi2xzSeed)
    tT.Branch('chi2yzSeed',chi2yzSeed)
    tT.Branch('residxzSeed',residxzSeed)
    tT.Branch('residyzSeed',residyzSeed)
    tT.Branch('issigSeed',issigSeed)
    tT.Branch('iGenMatch',iGenMatch)
    tT.Branch('x1Seed',x1Seed)
    tT.Branch('y1Seed',y1Seed)
    tT.Branch('z1Seed',z1Seed)
    tT.Branch('x2Seed',x2Seed)
    tT.Branch('y2Seed',y2Seed)
    tT.Branch('z2Seed',z2Seed)
    tT.Branch('x3Seed',x3Seed)
    tT.Branch('y3Seed',y3Seed)
    tT.Branch('z3Seed',z3Seed)
    tT.Branch('x4Seed',x4Seed)
    tT.Branch('y4Seed',y4Seed)
    tT.Branch('z4Seed',z4Seed)
    tT.Branch('pxSeed',pxSeed)
    tT.Branch('pySeed',pySeed)
    tT.Branch('pzSeed',pzSeed)
    tT.Branch('eSeed',eSeed)
    tT.Branch('pxGen',pxGen)
    tT.Branch('pyGen',pyGen)
    tT.Branch('pzGen',pzGen)
    tT.Branch('eGen',eGen)
    tT.Branch('qGen',qGen)
    tT.Branch('iGen',iGen)


    histos = { "h_residuals_xz_sig": TH1D("residuals_xz_sig",";residuals_{xz};Tracks", 500,0,0.5),
            "h_residuals_yz_sig": TH1D("residuals_yz_sig",";residuals_{yz};Tracks", 500,0,500), 
            "h_residuals_xz_bkg": TH1D("residuals_xz_bkg",";residuals_{xz};Tracks", 500,0,0.5),
            "h_residuals_yz_bkg": TH1D("residuals_yz_bkg",";residuals_{yz};Tracks", 500,0,500),
            
            "h_svd_dd0_sig": TH1D("svd_dd0_sig",";svd_{dd0};Tracks", 500,21,24),
            "h_svd_dd0_bkg": TH1D("svd_dd0_bkg",";svd_{dd0};Tracks", 500,21,24), 
            "h_svd_dd1_sig": TH1D("svd_dd1_sig",";svd_{dd1};Tracks", 500,0,0.1),
            "h_svd_dd1_bkg": TH1D("svd_dd1_bkg",";svd_{dd1};Tracks", 500,0,0.1),
            "h_svd_dd2_sig": TH1D("svd_dd2_sig",";svd_{dd2};Tracks", 500,0,0.05),
            "h_svd_dd2_bkg": TH1D("svd_dd2_bkg",";svd_{dd2};Tracks", 500,0,0.05),
            
            "h_prob_xz_sig": TH1D("prob_xz_sig",";prob_{xz};Tracks", 500,0,1.0),
            "h_prob_yz_sig": TH1D("prob_yz_sig",";prob_{yz};Tracks", 500,0,1.0), 
            "h_prob_xz_bkg": TH1D("prob_xz_bkg",";prob_{xz};Tracks", 500,0,1.0),
            "h_prob_yz_bkg": TH1D("prob_yz_bkg",";prob_{yz};Tracks", 500,0,1.0),
            
            "h_chi2ndf_xz_sig": TH1D("chi2ndf_xz_sig",";chi2ndf_{xz};Tracks", 500,0,0.001),
            "h_chi2ndf_yz_sig": TH1D("chi2ndf_yz_sig",";chi2ndf_{yz};Tracks", 500,0,0.001), 
            "h_chi2ndf_xz_bkg": TH1D("chi2ndf_xz_bkg",";chi2ndf_{xz};Tracks", 500,0,0.001),
            "h_chi2ndf_yz_bkg": TH1D("chi2ndf_yz_bkg",";chi2ndf_{yz};Tracks", 500,0,0.001),
            
            "h_seed_resE" : TH1D("seed_resE", ";(E_{seed}-E_{gen})/E_{gen};Tracks",    100,-3,+3),
            "h_seed_resPz": TH1D("seed_resPz",";(Pz_{seed}-Pz_{gen})/Pz_{gen};Tracks", 100,-3,+3), 
            "h_seed_resPy": TH1D("seed_resPy",";(Py_{seed}-Py_{gen})/Py_{gen};Tracks", 100,-10,+10),
            
            "h_seed_resE_vs_x"  : TH2D("seed_resE_vs_x",  ";x;(E_{seed}-E_{gen})/E_{gen};Tracks",    100,detXmin,detXmax, 100,-5,+5),
            "h_seed_resPy_vs_x" : TH2D("seed_resPy_vs_x", ";x;(Py_{seed}-Py_{gen})/Py_{gen};Tracks", 100,detXmin,detXmax, 100,-10,+10),
            
            "h_N_sigacc":        TH1D("N_sigacc",        ";Track multiplicity;Events", 40,30,190),
            "h_N_all_seeds":     TH1D("N_all_seeds",     ";Track multiplicity;Events", 40,30,190),
            "h_N_matched_seeds": TH1D("N_matched_seeds", ";Track multiplicity;Events", 40,30,190),
            "h_N_good_seeds":    TH1D("N_good_seeds",    ";Track multiplicity;Events", 40,30,190),
            
            "h_seeding_score": TH1D("h_seeding_score", ";N_{seeds}^{matched}/N_{signa}^{in.acc} [%];Events", 20,91,101),
            "h_seeding_pool":  TH1D("h_seeding_pool",  ";N_{seeds}^{all}/N_{signa}^{in.acc} [%];Events", 50,90,590),
    }
    sidesarr = getLogicSidesArr()
    pdfname = "../output/pdf/seedingdemo_"+proc+".pdf"
    intfile = TFile("../data/root/rec_"+proc+".root","READ")
    intree = intfile.Get("res")
    nevents = intree.GetEntries()
    print("with %d events" % nevents)
    nmax = 100000
    n=0 ### init n
    for event in intree:
    Nsigall = 0
    Nsigacc = 0
    Nseeds = 0
    Nmatched = 0
    Ngood = 0
    
    ## clear the output vectors
    svd0Seed.clear()
    svd1Seed.clear()
    svd2Seed.clear()
    chi2xzSeed.clear()
    chi2yzSeed.clear()
    residxzSeed.clear()
    residyzSeed.clear()
    issigSeed.clear()
    iGenMatch.clear()
    x1Seed.clear()
    y1Seed.clear()
    z1Seed.clear()
    x2Seed.clear()
    y2Seed.clear()
    z2Seed.clear()
    x3Seed.clear()
    y3Seed.clear()
    z3Seed.clear()
    x4Seed.clear()
    y4Seed.clear()
    z4Seed.clear()
    
    pxSeed.clear()
    pySeed.clear()
    pzSeed.clear()
    eSeed.clear()
    
    pxGen.clear()
    pyGen.clear()
    pzGen.clear()
    eGen.clear()
    qGen.clear()
    iGen.clear()
    
    
    
    ### start the loop
    if(n>nmax): break
    
    ### draw?
    dodraw = (n<=NeventsToDraw)
    
    ### container for all clusters
    allpointsEside = initpoints()
    allpointsPside = initpoints()
    
    ## clusters' vectors are always written out (even if empty) for all gen tracks!
    ## each generated track in the vector always has 4 clusters accessed via TPolyMarker3D::GetPoint()
    for i in range(event.polm_clusters.size()):
        
        ###############################################################
        if(proc=="bppp"):
            if(sides=="e+" and event.qgen[i]<0): continue ## only positrons
            if(sides=="e-" and event.qgen[i]>0): continue ## only electrons
        if(proc=="trident" and event.qgen[i]<0): continue ## only positrons
        ###############################################################
        
        Nsigall += 1
        
        wgt  = event.wgtgen[i]
        pgen = event.pgen[i]
        ### cut on acceptance
        if(event.acctrkgen[i]!=1): continue
        
        Nsigacc += 1
        
        ### write the truth track momentum and its index
        pxGen.push_back(pgen.Px())
        pyGen.push_back(pgen.Py())
        pzGen.push_back(pgen.Pz())
        eGen.push_back(pgen.E())
        qGen.push_back(event.qgen[i])
        iGen.push_back(i)
        
        ### loop over all clusters of the track and put in the allpoints classified by the layer
        for jxy in range(event.polm_clusters[i].GetN()):
            rcls = [ ROOT.Double(), ROOT.Double(), ROOT.Double() ]
            event.polm_clusters[i].GetPoint(jxy,rcls[0],rcls[1],rcls[2]) ### the clusters
            if(rcls[0]>0): AddPoint(allpointsEside,rcls,True,i)
            if(rcls[0]<0): AddPoint(allpointsPside,rcls,True,i)
    Nsig4 = getNnon0(allpointsEside["Cls"][4])+getNnon0(allpointsPside["Cls"][4])
    
    
    ### embed some noise clusters
    rnd = TRandom()
    rnd.SetSeed()
    for kN in range(NnoiseClusters):
        for layer in layers:
            for side in sidesarr:
                x = 0
                if(side=="Pside"): x = rnd.Uniform(xPsideL,xPsideR)
                if(side=="Eside"): x = rnd.Uniform(xEsideL,xEsideR)
                y = rnd.Uniform(-0.75,+0.75)
                if(layer==1): z = 300
                if(layer==2): z = 310
                if(layer==3): z = 320
                if(layer==4): z = 330
                rnoise = [x,y,z]
                if(side=="Pside"): AddPoint(allpointsPside,rnoise)
                if(side=="Eside"): AddPoint(allpointsEside,rnoise)
    Nbkgsig4 = getNnon0(allpointsEside["Cls"][4])+getNnon0(allpointsPside["Cls"][4])
    
    
    ### just draw the full event
    drawall(pdfname+"(",allpointsEside,allpointsPside,dodraw)
    
    
    ### loop on the 2 sides
    for side in sidesarr:
        allpoints = allpointsEside if(side=="Eside") else allpointsPside
        
        ### the initial pool for pivot clusters
        Nall4 = getNnon0(allpoints["Cls"][4])
        
        ### loop over the clusters and start the seeding
        for j4 in range(Nall4):
            r4 = getpoint(allpoints["Cls"][4],j4)
            xpivot = r4[0]
            ### electron / positron?
            particlename = getparticlename(allpoints["Cls"][4],j4)
            ### get the yz window
            winpts_yz,winlin_yz = getyzwindow(allpoints["Cls"][4],j4)
            ### set the wide window starting from cluster_seed1 (window corners must be added clockwise!)
            winpts_xz_wide,winlin_xz_wide = getwidewindow(allpoints["Cls"][4],j4)
            ### discard all clusters which are not in the wide window
            widepoints = initpoints()
            trimwide(allpoints,widepoints,winpts_xz_wide,winpts_yz,xpivot)
            Nwide1 = getNnon0(widepoints["Cls"][1])
            # if(Nwide1<1): print("Failed Nwide1")
            ### draw the wide window
            draw(pdfname,widepoints,dodraw,particlename,winlin_yz,winlin_xz_wide)
            
            ### choose one cluster in layer 1 as the second seed
            for j1 in range(Nwide1):
                ### get the narrow window  (window corners must be added clockwise!)
                winpts_xz_narr,winlin_xz_narr = getnarrwindow(allpoints["Cls"][4],widepoints["Cls"][1],j4,j1)
                ### discard all clusters which are not in the narrow window
                narrpoints = initpoints()
                trimnarr(widepoints,narrpoints,winpts_xz_narr)
                Nnarr2 = getNnon0(narrpoints["Cls"][2])
                Nnarr3 = getNnon0(narrpoints["Cls"][3])
                
                ### check if there are at least 1 cluster in both layer 2 and layer 3 within the narrow window
                if(Nnarr2<1 or Nnarr3<1): continue
                
                ### draw the narrow window
                draw(pdfname,narrpoints,dodraw,particlename,None,winlin_xz_narr)
                
                ### get the seed - note: could be that there are several combinations but the seed momentum would be identical
                pseed = makeseed(allpoints["Cls"][4],widepoints["Cls"][1],j4,j1,particlename)
                # if(pseed.E()>Emax or pseed.E()<Emin): print("pseed.E()>Emax or pseed.E()<Emin")
                if(pseed.E()>Emax or pseed.E()<Emin): continue
                
                ### set the cluster in layer 1
                r1 = getpoint(widepoints["Cls"][1],j1)
                
                ### loop on the clusters in layer 2 and 3:
                for j2 in range(Nnarr2):
                # for j2 in range(narrpoints["Cls"][2].GetN()):
                r2 = getpoint(narrpoints["Cls"][2],j2)
                for j3 in range(Nnarr3):
                # for j3 in range(narrpoints["Cls"][3].GetN()):
                    r3 = getpoint(narrpoints["Cls"][3],j3)
                    Nseeds += 1
                    
                    issig1 = widepoints["IsSig"][1][j1]
                    issig2 = narrpoints["IsSig"][2][j2]
                    issig3 = narrpoints["IsSig"][3][j3]
                    issig4 = allpoints["IsSig"][4][j4]
                    
                    trkid4 = allpoints["TrkId"][4][j4]
                    trkid3 = narrpoints["TrkId"][3][j3]
                    trkid2 = narrpoints["TrkId"][2][j2]
                    trkid1 = widepoints["TrkId"][1][j1]
                    issig = (issig4 and issig1 and issig2 and issig3)
                    trkid = str(trkid4) if(trkid4==trkid1 and trkid1==trkid2 and trkid2==trkid3) else "mult"
                    issiguniq = (issig and trkid!="mult")
                    if(issiguniq): Nmatched += 1
        
                    ### two independent 2d fits
                    chi2_xz,prob_xz,chi2_yz,prob_yz = seed2dfit(pdfname,r1,r2,r3,r4,dodraw)
                    if(issiguniq):
                        histos["h_chi2ndf_xz_sig"].Fill(chi2_xz)
                        histos["h_chi2ndf_yz_sig"].Fill(chi2_yz)
                        histos["h_prob_xz_sig"].Fill(prob_xz)
                        histos["h_prob_yz_sig"].Fill(prob_yz)
                    else:
                        histos["h_chi2ndf_xz_bkg"].Fill(chi2_xz)
                        histos["h_chi2ndf_yz_bkg"].Fill(chi2_yz)
                        histos["h_prob_xz_bkg"].Fill(prob_xz)
                        histos["h_prob_yz_bkg"].Fill(prob_yz)
        
                    ### a single 3d fit
                    res_xz, res_yz = seed3dfit(pdfname,r1,r2,r3,r4,dodraw)
                    if(issiguniq):
                        histos["h_residuals_xz_sig"].Fill(res_xz)
                        histos["h_residuals_yz_sig"].Fill(res_yz)
                    else:
                        histos["h_residuals_xz_bkg"].Fill(res_xz)
                        histos["h_residuals_yz_bkg"].Fill(res_yz)
                        
                    ### a single 3d fit SVD
                    lfitpts, dd = seed3dfitSVD(pdfname,r1,r2,r3,r4,dodraw)
                    
                    ### set again the pseed according to lfit
                    cluster1 = TPolyMarker3D()
                    cluster2 = TPolyMarker3D()
                    cluster1.SetNextPoint(lfitpts[0][0],lfitpts[0][1],lfitpts[0][2])
                    cluster2.SetNextPoint(lfitpts[1][0],lfitpts[1][1],lfitpts[1][2])
                    if(isel(lfitpts[0][0])): pseed = makeseed(cluster2,cluster1,0,0,particlename)
                    else:                    pseed = makeseed(cluster1,cluster2,0,0,particlename)
                    if(pseed.E()>Emax or pseed.E()<Emin): continue
                    
                    ### the SVD alg
                    if(issiguniq):
                        histos["h_svd_dd0_sig"].Fill(dd[0])
                        histos["h_svd_dd1_sig"].Fill(dd[1])
                        histos["h_svd_dd2_sig"].Fill(dd[2])
                    else:
                        histos["h_svd_dd0_bkg"].Fill(dd[0])
                        histos["h_svd_dd1_bkg"].Fill(dd[1])
                        histos["h_svd_dd2_bkg"].Fill(dd[2])
                    
                    ### get the generated matched track momentum
                    pgen = TLorentzVector()
                    igen = -1
                    for k in range(iGen.size()):
                        if(iGen[k]==j4):
                            igen = k
                            break
                    
                    ### write out the good seeds
                    svd0Seed.push_back(dd[0])
                    svd1Seed.push_back(dd[1])
                    svd2Seed.push_back(dd[2])
                    chi2xzSeed.push_back(chi2_xz)
                    chi2yzSeed.push_back(chi2_yz)
                    residxzSeed.push_back(res_xz)
                    residyzSeed.push_back(res_yz)
                    issigSeed.push_back(issiguniq)
                    iGenMatch.push_back(igen)
                    x1Seed.push_back(r1[0])
                    y1Seed.push_back(r1[1])
                    z1Seed.push_back(r1[2])
                    x2Seed.push_back(r2[0])
                    y2Seed.push_back(r2[1])
                    z2Seed.push_back(r2[2])
                    x3Seed.push_back(r3[0])
                    y3Seed.push_back(r3[1])
                    z3Seed.push_back(r3[2])
                    x4Seed.push_back(r4[0])
                    y4Seed.push_back(r4[1])
                    z4Seed.push_back(r4[2])
                    pxSeed.push_back(pseed.Px())
                    pySeed.push_back(pseed.Py())
                    pzSeed.push_back(pseed.Pz())
                    eSeed.push_back(pseed.E())
                    
                    ### cut on some quality
                    isgood = (dd[1]<0.005 and dd[2]<0.0025)
                    if(not isgood): continue
                    Ngood += 1
                    
                    ### check perforrmance of seeding
                    pgen.SetPxPyPzE(pxGen[igen],pyGen[igen],pzGen[igen],eGen[igen])
                    resE = (pseed.E()-pgen.E())/pgen.E()
                    resPz = (pseed.Pz()-pgen.Pz())/pgen.Pz()
                    resPy = (pseed.Py()-pgen.Py())/pgen.Py()
                    histos["h_seed_resE"].Fill(resE)
                    histos["h_seed_resPz"].Fill(resPz)
                    histos["h_seed_resPy"].Fill(resPy)
                    histos["h_seed_resE_vs_x"].Fill(r4[0],resE)
                    histos["h_seed_resPy_vs_x"].Fill(r4[0],resPy)
                    
    histos["h_N_sigacc"].Fill(Nsigacc)       
    histos["h_N_all_seeds"].Fill(Nseeds)       
    histos["h_N_matched_seeds"].Fill(Nmatched)       
    histos["h_N_good_seeds"].Fill(Ngood)
    histos["h_seeding_score"].Fill(Nmatched/Nsigacc*100)
    histos["h_seeding_pool"].Fill(Nseeds/Nsigacc*100)
        
    if(dodraw):
        cnv = TCanvas("","",2000,2000)
        cnv.SaveAs(pdfname+")")
    print("Event: %g --> Nsigall=%g, Nsigacc=%g, Nseeds=%g, Nmatched=%g, Ngood=%g --> Seeds matching performance: Nmatched/Nsigacc=%5.1f%%" % (n,Nsigall,Nsigacc,Nseeds,Nmatched,Ngood,Nmatched/Nsigacc*100))

    tT.Fill()
    if(n%10==0 and n>0): print("  processed %d events" % n)
    n+=1
    print("Total events processed: ",n)










    cnv = TCanvas("","",1000,1000)
    cnv.Divide(2,2)
    cnv.cd(1)
    histos["h_chi2ndf_xz_sig"].SetLineColor(ROOT.kRed);   histos["h_chi2ndf_xz_sig"].Draw()
    histos["h_chi2ndf_xz_bkg"].SetLineColor(ROOT.kBlack); histos["h_chi2ndf_xz_bkg"].Draw("same")
    cnv.cd(2)
    histos["h_chi2ndf_yz_sig"].SetLineColor(ROOT.kRed);   histos["h_chi2ndf_yz_sig"].Draw()
    histos["h_chi2ndf_yz_bkg"].SetLineColor(ROOT.kBlack); histos["h_chi2ndf_yz_bkg"].Draw("same")
    cnv.cd(3)
    histos["h_prob_xz_sig"].SetLineColor(ROOT.kRed);   histos["h_prob_xz_sig"].Draw()
    histos["h_prob_xz_bkg"].SetLineColor(ROOT.kBlack); histos["h_prob_xz_bkg"].Draw("same")
    cnv.cd(4)
    histos["h_prob_yz_sig"].SetLineColor(ROOT.kRed);   histos["h_prob_yz_sig"].Draw()
    histos["h_prob_yz_bkg"].SetLineColor(ROOT.kBlack); histos["h_prob_yz_bkg"].Draw("same")
    cnv.SaveAs("../output/pdf/chi2ndf_"+proc+".pdf")

    cnv = TCanvas("","",1000,500)
    cnv.Divide(2,1)
    cnv.cd(1)
    histos["h_residuals_xz_sig"].SetLineColor(ROOT.kRed);   histos["h_residuals_xz_sig"].Draw()
    histos["h_residuals_xz_bkg"].SetLineColor(ROOT.kBlack); histos["h_residuals_xz_bkg"].Draw("same")
    cnv.cd(2)
    histos["h_residuals_yz_sig"].SetLineColor(ROOT.kRed);   histos["h_residuals_yz_sig"].Draw()
    histos["h_residuals_yz_bkg"].SetLineColor(ROOT.kBlack); histos["h_residuals_yz_bkg"].Draw("same")
    cnv.SaveAs("../output/pdf/resid3dfit_"+proc+".pdf")

    cnv = TCanvas("","",1500,500)
    cnv.Divide(3,1)
    cnv.cd(1)
    histos["h_svd_dd0_sig"].SetLineColor(ROOT.kRed);   histos["h_svd_dd0_sig"].Draw()
    histos["h_svd_dd0_bkg"].SetLineColor(ROOT.kBlack); histos["h_svd_dd0_bkg"].Draw("same")
    cnv.cd(2)
    histos["h_svd_dd1_sig"].SetLineColor(ROOT.kRed);   histos["h_svd_dd1_sig"].Draw()
    histos["h_svd_dd1_bkg"].SetLineColor(ROOT.kBlack); histos["h_svd_dd1_bkg"].Draw("same")
    cnv.cd(3)
    histos["h_svd_dd2_sig"].SetLineColor(ROOT.kRed);   histos["h_svd_dd2_sig"].Draw()
    histos["h_svd_dd2_bkg"].SetLineColor(ROOT.kBlack); histos["h_svd_dd2_bkg"].Draw("same")
    cnv.SaveAs("../output/pdf/svd3dfit_"+proc+".pdf")

    cnv = TCanvas("","",1000,1000)
    cnv.Divide(2,2)
    cnv.cd(1); histos["h_seed_resE"].Draw("hist")
    cnv.cd(2); histos["h_seed_resPy"].Draw("hist")
    cnv.cd(3); histos["h_seed_resE_vs_x"].Draw("col")
    cnv.cd(4); histos["h_seed_resPy_vs_x"].Draw("col")
    cnv.SaveAs("../output/pdf/seedsres_"+proc+".pdf")

    cnv = TCanvas("","",1500,500)
    cnv.Divide(3,1)
    cnv.cd(1)
    histos["h_N_sigacc"].SetLineColor(ROOT.kBlack); histos["h_N_sigacc"].Draw()
    histos["h_N_all_seeds"].SetLineColor(ROOT.kBlue); histos["h_N_all_seeds"].Draw("same")
    histos["h_N_matched_seeds"].SetLineColor(ROOT.kGreen); histos["h_N_matched_seeds"].Draw("same")
    histos["h_N_good_seeds"].SetLineColor(ROOT.kRed); histos["h_N_good_seeds"].Draw("same")
    cnv.cd(2)
    histos["h_seeding_pool"].Draw("hist")
    cnv.cd(3)
    histos["h_seeding_score"].Draw("hist")
    cnv.SaveAs("../output/pdf/seedsmult_"+proc+".pdf")

    tF.cd()
    tT.Write()
    tF.Write()
    tF.Close()


if __name__=="__main__":
    main()