Newer
Older
FairShipTools / TP_answers_referees / bg_rejection_with_IP.py
@Elena@SHiP_VM Elena@SHiP_VM on 23 Jun 2015 6 KB removed weights from the ip plots
from os.path import dirname, realpath, sep, pardir
import sys
sys.path.append(dirname(dirname(realpath(__file__))))
import os
os.chdir('../')
print os.getcwd()
from distribsForHNLandBG_byEvent import *

### NB: anche nei draw ci andrebbe NoB_!!!

tc = cutsWithDraw()
study = 'nu'
t = studies[study]['data']
cuts =     [ tc.recoed()[0], tc.notVetoed(1000.)[0], tc.ip(250.)[0] ]
tc.setNoB('NoB_')
tc.nu = True
print cuts
cuts =     [ tc.recoed()[0], tc.notVetoed(1000.)[0], tc.ip(250.)[0] ]
print cuts
cuts =     [ tc.recoed()[0] ]
t.Draw('NoB_IP0>>bgreco', "(weight*%s/%s)*("%(flux_nu, entries_nu)+"&&".join([c for c in cuts])+ ")", "norm")
cuts2 =     [ tc.recoed()[0], tc.notVetoed(1000.)[0] ]
t.Draw('NoB_IP0>>bgreconv', "(weight*%s/%s)*("%(flux_nu, entries_nu)+"&&".join([c for c in cuts2])+ ")", "normsame")
bgreconv = r.gDirectory.Get('bgreconv')
bgreconv.SetLineColor(r.kRed)
bgreconv.SetMarkerColor(r.kRed)
geo = studies[study]['geo']
ntot = studies[study]['ntot']
zmin = geo['Veto_5']['z']['pos']+geo['Veto_5']['z']['dim']
zmax = geo['Tr1_1']['z']['pos']-geo['Tr1_1']['z']['dim']
cuts3 = [ tc.recoed()[0], tc.notVetoed(1000.)[0], tc.redChi2(5.)[0], tc.ndf(25)[0], tc.fiducial(zmin, zmax, 250., 500.)[0], tc.goodtracks()[0], tc.ecal()[0], tc.muon1(1)[0], tc.muon2(1)[0], tc.doca(30.)[0] ]
t.Draw('NoB_IP0>>bgreconvcuts', "(weight*%s/%s)*("%(flux_nu, entries_nu)+"&&".join([c for c in cuts3])+ ")", "normsame")
bgreconvcuts = r.gDirectory.Get('bgreconvcuts')
bgreconvcuts.SetMarkerColor(r.kGreen)
bgreconvcuts.SetLineColor(r.kGreen)
bgreconvcuts.SetLineColor(r.kGreen+2)
bgreconvcuts.SetMarkerColor(r.kGreen+2)
c2 = r.TCanvas()
c2.cd()
cuts =     [ tc.recoed()[0]]
ntot = t.Draw('NoB_IP0>>bgtot', "(weight*%s/%s)*("%(flux_nu, entries_nu)+"&&".join([c for c in cuts])+ ")", "")
print ntot
w = t.GetHistogram().GetSumOfWeights()
print w
ccuts =     [ tc.recoed()[0], tc.ip(250.)[0] ]
nc = t.Draw('NoB_IP0>>bgtot', "(weight*%s/%s)*("%(flux_nu, entries_nu)+"&&".join([c for c in ccuts])+ ")", "")
print nc
wc = t.GetHistogram().GetSumOfWeights()
print wc
print wc/w
print w
print 1. - wc/w
nvcuts =     [ tc.recoed()[0], tc.notVetoed(1000.)[0] ]
nnv = t.Draw('NoB_IP0>>bgtot', "(weight*%s/%s)*("%(flux_nu, entries_nu)+"&&".join([c for c in nvcuts])+ ")", "")
print nnv
cnvcuts =     [ tc.recoed()[0], tc.notVetoed(1000.)[0], tc.ip(250.)[0] ]
nvw = t.GetHistogram().GetSumOfWeights()
print nvw
cnnv = t.Draw('NoB_IP0>>bgtot', "(weight*%s/%s)*("%(flux_nu, entries_nu)+"&&".join([c for c in cnvcuts])+ ")", "")
print cnnv
cnvw = t.GetHistogram().GetSumOfWeights()
print cnvw
print 1. - cnvw/nvw
print tc.noB

# Now without weights, after talking with Nico
print cuts
c3 = r.TCanvas()
c3.cd()
t.Draw('NoB_IP0>>bgreco(100,0.,1000.)', "(weight*%s/%s)*("%(flux_nu, entries_nu)+"&&".join([c for c in cuts])+ " && NoB_IP0 <= 1000.)", "norm")
t.Draw('NoB_IP0>>bgreconv(100,0.,1000.)', "(weight*%s/%s)*("%(flux_nu, entries_nu)+"&&".join([c for c in cuts2])+ " && NoB_IP0 <= 1000.)", "normsame")
cuts3 = [ tc.recoed()[0], tc.notVetoed(1000.)[0], tc.redChi2(5.)[0], tc.ndf(25)[0], tc.fiducial(zmin, zmax, 250., 500.)[0], tc.goodtracks()[0], tc.ecal()[0], tc.muon1(1)[0], tc.muon2(1)[0], tc.doca(30.)[0] ]
c4 = r.TCanvas()
c4.cd()
t.Draw('NoB_IP0>>bgreco2(100,0.,1000.)', "("+"&&".join([c for c in cuts])+ " && NoB_IP0 <= 1000.)", "norm")
t.Draw('NoB_IP0>>bgreconvcuts2(100,0.,1000.)', "("+"&&".join([c for c in cuts3])+ "&& NoB_IP0 <= 1000.)", "normsame")
t.Draw('NoB_IP0>>bgreconv2(100,0.,1000.)', "("+"&&".join([c for c in cuts2])+ " && NoB_IP0 <= 1000.)", "normsame")
c5 = r.TCanvas()
c5.cd()
cuts = [ tc.recoed()[0], tc.fiducial(zmin, zmax, 250., 500.)[0] ]
print cuts
t.Draw('NoB_IP0>>bgreco2(100,0.,1000.)', "("+"&&".join([c for c in cuts])+ " && NoB_IP0 <= 1000.)", "norm")
cuts = [ tc.recoed()[0], tc.fiducial(zmin, zmax, 250., 500.)[0], tc.goodtracks()[0] ]
t.Draw('NoB_IP0>>bgreco3(100,0.,1000.)', "("+"&&".join([c for c in cuts])+ " && NoB_IP0 <= 1000.)", "normsame")
cuts = [ tc.recoed()[0], tc.fiducial(zmin, zmax, 250., 500.)[0], tc.goodtracks()[0], tc.doca(30.)[0] ]
c6 = r.TCanvas()
t.Draw('NoB_IP0>>bgreco2(100,0.,1000.)', "("+"&&".join([c for c in cuts])+ " && NoB_IP0 <= 1000.)", "norm")
cuts = [ tc.recoed()[0], tc.fiducial(zmin, zmax, 250., 500.)[0], tc.goodtracks()[0], tc.doca(30.)[0], tc.redChi2(5.)[0] ]
t.Draw('NoB_IP0>>bgreco2(100,0.,1000.)', "("+"&&".join([c for c in cuts])+ " && NoB_IP0 <= 1000.)", "norm")
cuts = [ tc.recoed()[0], tc.fiducial(zmin, zmax, 250., 500.)[0], tc.goodtracks()[0], tc.doca(30.)[0], tc.redChi2(5.)[0], tc.ndf(25)[0] ]
t.Draw('NoB_IP0>>bgreco2(100,0.,1000.)', "("+"&&".join([c for c in cuts])+ " && NoB_IP0 <= 1000.)", "norm")
cuts = [ tc.recoed()[0], tc.fiducial(zmin, zmax, 250., 500.)[0], tc.goodtracks()[0], tc.doca(30.)[0], tc.redChi2(5.)[0], tc.ndf(25)[0], tc.muon1(1)[0], tc.muon2(1)[0] ]
t.Draw('NoB_IP0>>bgreco2(100,0.,1000.)', "("+"&&".join([c for c in cuts])+ " && NoB_IP0 <= 1000.)", "norm")
cuts = [ tc.recoed()[0], tc.fiducial(zmin, zmax, 250., 500.)[0], tc.goodtracks()[0], tc.doca(30.)[0], tc.redChi2(5.)[0], tc.ndf(25)[0], tc.muon1(1)[0], tc.muon2(1)[0], tc.ecal()[0] ]
t.Draw('NoB_IP0>>bgreco2(100,0.,1000.)', "("+"&&".join([c for c in cuts])+ " && NoB_IP0 <= 1000.)", "norm")
cuts = [ tc.recoed()[0], tc.fiducial(zmin, zmax, 250., 500.)[0], tc.goodtracks()[0], tc.doca(30.)[0], tc.redChi2(5.)[0], tc.ndf(25)[0], tc.muon1(1)[0], tc.muon2(1)[0], tc.ecal()[0], tc.notVetoed(1000.)[0] ]
t.Draw('NoB_IP0>>bgreco2(100,0.,1000.)', "("+"&&".join([c for c in cuts])+ " && NoB_IP0 <= 1000.)", "norm")
t.Draw('NoB_IP0>>bgreco2(100,0.,1000.)', "("+"&&".join([c for c in cuts])+ " && NoB_IP0 <= 1000. && nRecoed == 1)", "norm")
cuts = [tc.notVetoed(1000.)[0]]
t.Draw('NoB_IP0>>bgreco2(100,0.,1000.)', "("+"&&".join([c for c in cuts])+ " && NoB_IP0 <= 1000. && nRecoed == 1)", "norm")
t.Draw('NoB_IP0>>bgreco2(100,0.,1000.)', "("+"&&".join([c for c in cuts])+ " && NoB_IP0 <= 250. && nRecoed == 1)", "norm")
t.Draw('NoB_IP0>>bgreco2(100,0.,1000.)', "("+"&&".join([c for c in cuts])+ " && nRecoed == 1)", "norm")
t.Draw('NoB_IP0>>bgreco2(100,0.,1000.)', "("+"&&".join([c for c in cuts])+ " && nRecoed == 1)", "norm")
print 1.- 14./88
t.Draw('NoB_IP0>>bgreco2(100,0.,1000.)', "("+"&&".join([c for c in cuts])+ " && NoB_IP0 <= 250. && nRecoed == 1)", "norm")
t.Draw('NoB_IP0>>bgreco2(100,0.,1000.)', "("+"&&".join([c for c in cuts])+ " && NoB_IP0 <= 1000. && nRecoed == 1)", "norm")
cuts = [tc.recoed()[0]]
t.Draw('NoB_IP0>>bgreco2(100,0.,1000.)', "("+"&&".join([c for c in cuts])+ " && NoB_IP0 <= 1000.)", "norm")
cuts = [tc.notVetoed(1000.)[0]]
t.Draw('NoB_IP0>>bgrecocut(100,0.,1000.)', "("+"&&".join([c for c in cuts])+ " && NoB_IP0 <= 1000. && nRecoed == 1)", "norm same")