def main(): ### get the dipole dipole = GetDipole() rlist = [[464.685, -2.89186, z1inner], [549.413, -0.553007, z4inner]] trkpoints = GetTrackPoints(rlist) trackline = GetTrackLine(rlist) extendedline = GetExtendedTrackLine(rlist) ### get the sensors sensors = [] for index, row in df.iterrows(): detid = row["detid"] layerid = row["layerid"] sensors.append(GetSensor(detid, layerid)) print(xBoundaries) ### draw cnv = TCanvas("cnv", "", 500, 500) view = TView.CreateView(1) view.SetRange(-600, -500, 2500, +600, +500, 4500) view.ShowAxis() for sensor in sensors: sensor.Draw() dipole.Draw() extendedline.Draw() trackline.Draw() trkpoints.Draw() cnv.SaveAs("sensors.pdf") cnv.SaveAs("sensors.root")
def seed3dfitSVD(name,r1,r2,r3,r4,dodraw): g = TGraph2D() g.SetMarkerSize(3) g.SetMarkerStyle(20) g.SetMarkerColor(ROOT.kRed) g.SetLineColor(ROOT.kRed) g.SetPoint(0,r1[2],r1[1],r1[0]) g.SetPoint(1,r2[2],r2[1],r2[0]) g.SetPoint(2,r3[2],r3[1],r3[0]) g.SetPoint(3,r4[2],r4[1],r4[0]) g.GetXaxis().SetRangeUser(290,340) g.GetYaxis().SetRangeUser(-0.8,+0.8) g.GetZaxis().SetRangeUser( 0 if(isel(r1[0])) else xPsideL, xEsideR if(isel(r1[0])) else 0 ) x = np.array([r1[0],r2[0],r3[0],r4[0]]) y = np.array([r1[1],r2[1],r3[1],r4[1]]) z = np.array([r1[2],r2[2],r3[2],r4[2]]) data = np.concatenate((x[:, np.newaxis], y[:, np.newaxis], z[:, np.newaxis]), axis=1) # Calculate the mean of the points, i.e. the 'center' of the cloud datamean = data.mean(axis=0) # Do an SVD on the mean-centered data (Singular Value Decomposition) uu, dd, vv = np.linalg.svd(data - datamean) # Now vv[0] contains the first principal component, i.e. the direction # vector of the 'best fit' line in the least squares sense. # Now generate some points along this best fit line, for plotting. # I use -7, 7 since the spread of the data is roughly 14 # and we want it to have mean 0 (like the points we did # the svd on). Also, it's a straight line, so we only need 2 points. # linepts = vv[0] * np.mgrid[-7:7:2j][:, np.newaxis] linepts = vv[0] * np.mgrid[-50:50:2j][:, np.newaxis] # shift by the mean to get the line in the right place linepts += datamean if(dodraw): lfit = TPolyLine3D() for point in linepts: lfit.SetNextPoint(point[2],point[1],point[0]) lfit.SetLineColor(ROOT.kBlue) cnv = TCanvas("","",2000,2000) view = TView.CreateView(1) xviewmin = 0 if(isel(r1[0])) else xPsideL xviewmax = xEsideR if(isel(r1[0])) else 0 view.SetRange(290,-0.8, xviewmin , 340,+0.8,xviewmax) view.ShowAxis() g.Draw("p0") lfit.Draw("smae") cnv.SaveAs(name) return linepts, dd ## dd is a 1D array of the data singular values
def seed3dfit(name,r1,r2,r3,r4,dodraw): g = TGraph2D() g.SetMarkerSize(3) g.SetMarkerStyle(20) g.SetMarkerColor(ROOT.kRed) g.SetLineColor(ROOT.kRed) g.SetPoint(0,r1[2],r1[1],r1[0]) g.SetPoint(1,r2[2],r2[1],r2[0]) g.SetPoint(2,r3[2],r3[1],r3[0]) g.SetPoint(3,r4[2],r4[1],r4[0]) g.GetXaxis().SetRangeUser(290,340) g.GetYaxis().SetRangeUser(-0.8,+0.8) g.GetZaxis().SetRangeUser(0 if(isel(r1[0])) else xPsideL, xEsideR if(isel(r1[0])) else 0 ) x = np.array([r1[0],r2[0],r3[0],r4[0]]) y = np.array([r1[1],r2[1],r3[1],r4[1]]) z = np.array([r1[2],r2[2],r3[2],r4[2]]) # this will find the slope and x-intercept of a plane # parallel to the y-axis that best fits the data A_xz = np.vstack((x, np.ones(len(x)))).T # m_xz, c_xz = np.linalg.lstsq(A_xz, z,rcond=None)[0] result_xz = np.linalg.lstsq(A_xz, z,rcond=None) m_xz, c_xz = result_xz[0] residuals_xz = result_xz[1] # again for a plane parallel to the x-axis A_yz = np.vstack((y, np.ones(len(y)))).T # m_yz, c_yz = np.linalg.lstsq(A_yz, z,rcond=None)[0] result_yz = np.linalg.lstsq(A_yz, z,rcond=None) m_yz, c_yz = result_yz[0] residuals_yz = result_yz[1] if(dodraw): zz = np.array([300,310,320,330]) xx,yy = line3d(zz, m_xz,c_xz,m_yz,c_yz) lfit = TPolyLine3D() for i in range(4): lfit.SetNextPoint(zz[i],yy[i],xx[i]) lfit.SetLineColor(ROOT.kBlue) cnv = TCanvas("","",2000,2000) view = TView.CreateView(1) xviewmin = 0 if(isel(r1[0])) else xPsideL xviewmax = xEsideR if(isel(r1[0])) else 0 view.SetRange(290,-0.8, xviewmin , 340,+0.8,xviewmax) view.ShowAxis() g.Draw("p0") lfit.Draw("smae") cnv.SaveAs(name) return residuals_xz,residuals_yz
def draw(name,points,dodraw,particles="",window_yz=None,window_xz=None): if(not dodraw): return cnv = TCanvas("","",2000,2000) view = TView.CreateView(1) view.ShowAxis() # view.SetRange(-80,-50,0, +80,+50,350) if (particles=="electrons"): view.SetRange(0,-10,190, xEsideR,+10,340) elif(particles=="positrons"): view.SetRange(xPsideL,-10,190, 0,+10,340) else: view.SetRange(xPsideL,-10,190, xEsideR,+10,340) geom = getgeometry() ### get the geometry from the root file for g in geom: g.Draw() if(window_yz is not None): window_yz.Draw("same") if(window_xz is not None): window_xz.Draw("same") for layer in layers: points["Cls"][layer].Draw("same") cnv.SaveAs(name)
def drawall(name,pointsEside,pointsPside,dodraw): if(not dodraw): return cnv = TCanvas("","",2000,2000) view = TView.CreateView(1) view.ShowAxis() # view.SetRange(-80,-50,0, +80,+50,350) if (sides=="e-"): view.SetRange(0,-10,190, xEsideR,+10,340) elif(sides=="e+"): view.SetRange(xPsideL,-10,190, 0,+10,340) else: view.SetRange(xPsideL,-10,190, xEsideR,+10,340) geom = getgeometry() ### get the geometry from the root file for g in geom: g.Draw() for layer in layers: pointsEside["Cls"][layer].Draw("same") pointsPside["Cls"][layer].Draw("same") cnv.SaveAs(name)
from ROOT import TCanvas, TView, TPolyMarker3D, TPaveText from ROOT import gROOT, gBenchmark from math import cos, sin, pi gBenchmark.Start('tornado') d = 16 numberOfPoints = 200 numberOfCircles = 40 # create and open a canvas sky = TCanvas('sky', 'Tornado', 300, 10, 700, 500) sky.SetFillColor(14) # creating view view = TView.CreateView() rng = numberOfCircles * d view.SetRange(0, 0, 0, 4.0 * rng, 2.0 * rng, rng) polymarkers = [] for j in range(d, numberOfCircles * d, d): # create a PolyMarker3D pm3d = TPolyMarker3D(numberOfPoints) # set points for i in range(1, numberOfPoints): csin = sin(2 * pi / numberOfPoints * i) + 1 ccos = cos(2 * pi / numberOfPoints * i) + 1 esin = sin(2 * pi / (numberOfCircles * d) * j) + 1 x = j * (csin + esin)
def seed2dfit(name,r1,r2,r3,r4,dodraw): gxyz = TGraph2D() gxyz.SetMarkerSize(1) gxyz.SetMarkerStyle(24) gxyz.SetMarkerColor(ROOT.kBlack) gxyz.SetPoint(0,r1[2],r1[1],r1[0]) gxyz.SetPoint(1,r2[2],r2[1],r2[0]) gxyz.SetPoint(2,r3[2],r3[1],r3[0]) gxyz.SetPoint(3,r4[2],r4[1],r4[0]) gxyz.GetXaxis().SetRangeUser(290,340) gxyz.GetYaxis().SetRangeUser(-0.8,+0.8) gxyz.GetZaxis().SetRangeUser( 0 if(isel(r1[0])) else xPsideL, xEsideR if(isel(r1[0])) else 0 ) gxz = TGraph() gxz.SetMarkerSize(1) gxz.SetMarkerStyle(24) gxz.SetMarkerColor(ROOT.kBlack) gxz.SetPoint(0,r1[2],r1[0]) gxz.SetPoint(1,r2[2],r2[0]) gxz.SetPoint(2,r3[2],r3[0]) gxz.SetPoint(3,r4[2],r4[0]) gxz.GetXaxis().SetRangeUser(290,340) if(isel(r1[0])): gxz.GetYaxis().SetRangeUser(0,xEsideR) else: gxz.GetYaxis().SetRangeUser(xPsideL,0) gyz = TGraph() gyz.SetMarkerSize(1) gyz.SetMarkerStyle(24) gyz.SetMarkerColor(ROOT.kBlack) gyz.SetLineColor(ROOT.kRed) gyz.SetPoint(0,r1[2],r1[1]) gyz.SetPoint(1,r2[2],r2[1]) gyz.SetPoint(2,r3[2],r3[1]) gyz.SetPoint(3,r4[2],r4[1]) gyz.GetXaxis().SetRangeUser(290,340) gyz.GetYaxis().SetRangeUser(-0.8,+0.8) fxz = TF1("fxz","pol1",300,330) fitr_xz = gxz.Fit(fxz,"Q") fitf_xz = gxz.FindObject("fxz") fyz = TF1("fyz","pol1",300,330) fitr_yz = gyz.Fit(fyz,"Q") fitf_yz = gyz.FindObject("fyz") if(dodraw): lfit = TPolyLine3D() for z in [300,310,320,330]: x = fitf_xz.Eval(z) y = fitf_yz.Eval(z) lfit.SetNextPoint(z,y,x) lfit.SetLineColor(ROOT.kBlue) cnv = TCanvas("","",1500,500) cnv.Divide(3,1) cnv.cd(1) view = TView.CreateView(1) xviewmin = 0 if(isel(r1[0])) else xPsideL xviewmax = xEsideR if(isel(r1[0])) else 0 view.SetRange(290,-0.8, xviewmin , 340,+0.8,xviewmax) view.ShowAxis() gxyz.Draw("p0") lfit.Draw("smae") cnv.cd(2) gxz.Draw() cnv.cd(3) gyz.Draw() cnv.SaveAs(name) chi2_xz = fitf_xz.GetChisquare()/fitf_xz.GetNDF() chi2_yz = fitf_yz.GetChisquare()/fitf_yz.GetNDF() prob_xz = fitf_xz.GetProb() prob_yz = fitf_yz.GetProb() return chi2_xz,prob_xz,chi2_yz,prob_yz
from math import cos, sin, pi gROOT.Reset() gBenchmark.Start('tornado') d = 16 numberOfPoints = 200 numberOfCircles = 40 # create and open a canvas sky = TCanvas('sky', 'Tornado', 300, 10, 700, 500) sky.SetFillColor(14) # creating view view = TView(1) rng = numberOfCircles * d view.SetRange(0, 0, 0, 4.0 * rng, 2.0 * rng, rng) polymarkers = [] for j in range(d, numberOfCircles * d, d): # create a PolyMarker3D pm3d = TPolyMarker3D(numberOfPoints) # set points for i in xrange(1, numberOfPoints): csin = sin(2 * pi / numberOfPoints * i) + 1 ccos = cos(2 * pi / numberOfPoints * i) + 1 esin = sin(2 * pi / (numberOfCircles * d) * j) + 1 x = j * (csin + esin)