def split_in_bins_n_save (root_file, saving_dir, withTurbo, mother_particle = "Lc"): ybins = Imports.getYbins() #Rapidity bins ptbins = Imports.getPTbins() #Also vestige of using turbo output: the variables would be preseparated, so no need to do it ourselves if not withTurbo: particles = ["Lc", "Xic"] else: particles = [] particles.append(mother_particle) if not os.path.exists(saving_dir + "ybins/"): os.mkdir(saving_dir + "ybins/") if not os.path.exists(saving_dir + "ptbins/"): os.mkdir(saving_dir + "ptbins/") if not os.path.exists(saving_dir + "y_ptbins/"): os.mkdir(saving_dir + "y_ptbins/") extra_variables = [""] tree = root_file for particle in particles: if particle == "Lc": mass_cuts = "lcplus_MM < 2375" if particle == "Xic": mass_cuts = "lcplus_MM > 2375" print("Particle: " + particle) for ybin in ybins: ycuts = "lcplus_RAPIDITY >= {0} && lcplus_RAPIDITY < {1}".format(ybin[0], ybin[1]) allcuts = " {0} && {1}".format(ycuts, mass_cuts) strip_n_save(0,0, allcuts, "", saving_dir + "ybins/" + particle + "_ybin_{0}-{1}.root".format(ybin[0], ybin[1]), extra_variables,particle, bins = True, tree = tree) n = len(ptbins) i = 0 print("Files with y({0})".format(ybin)) for ptbin in ptbins: #FOR THE PROGRESSION BAR if i < n: j = (i + 1) / n sys.stdout.write('\r') sys.stdout.write("[%-20s] %d%%" % ('='*int(20*j), 100*j)) sys.stdout.flush() i += 1 ptcuts = "lcplus_PT >= {0} && lcplus_PT < {1}".format(ptbin[0], ptbin[1]) if (ybin[0] == 2.0): allcuts = " {0} && {1}".format(ptcuts, mass_cuts) strip_n_save(0,0, allcuts, "", saving_dir + "ptbins/" + particle + "_ptbin_{0}-{1}.root".format(ptbin[0], ptbin[1]), extra_variables, particle, bins = True,tree = tree) yptcut = ycuts + " && " + ptcuts allcuts = " {0} && {1}".format(yptcut, mass_cuts) strip_n_save(0,0, allcuts, "", saving_dir + "y_ptbins/" + particle + "_ybin_{0}-{1}_ptbin_{2}-{3}.root".format(ybin[0],ybin[1],ptbin[0],ptbin[1]), extra_variables, particle, bins = True, tree = tree) print("\n")
def split_in_bins_n_save(root_file, saving_dir, run, mother_particle="Lc"): ybins = Imports.getYbins() #Rapidity bins ptbins = Imports.getPTbins() if run == 1: particles = ["Lc", "Xic"] else: particles = [] particles.append(mother_particle) os.mkdir(saving_dir + "ybins/") os.mkdir(saving_dir + "ptbins/") os.mkdir(saving_dir + "y_ptbins/") tree = root_file for particle in particles: if particle == "Lc": mass_cuts = "lcplus_MM < 2375" if particle == "Xic": mass_cuts = "lcplus_MM > 2375" for ybin in ybins: ycuts = "lcplus_RAPIDITY >= {0} && lcplus_RAPIDITY < {1}".format( ybin[0], ybin[1]) allcuts = " {0} && {1}".format(ycuts, mass_cuts) Strip.strip_n_save(0, 0, allcuts, "", saving_dir + "ybins/" + particle + "_ybin_{0}-{1}.root".format(ybin[0], ybin[1]), extra_variables=[""], bins=True, tree=tree) for ptbin in ptbins: ptcuts = "lcplus_PT >= {0} && lcplus_PT < {1}".format( ptbin[0], ptbin[1]) if (ybin[0] == 2.0): allcuts = " {0} && {1}".format(ptcuts, mass_cuts) Strip.strip_n_save( 0, 0, allcuts, "", saving_dir + "ptbins/" + particle + "_ptbin_{0}-{1}.root".format(ptbin[0], ptbin[1]), extra_variables=[""], particle=mother_particle, bins=True, tree=tree) yptcut = ycuts + " && " + ptcuts allcuts = " {0} && {1}".format(yptcut, mass_cuts) Strip.strip_n_save(0, 0, allcuts, "", saving_dir + "y_ptbins/" + particle + "_ybin_{0}-{1}_ptbin_{2}-{3}.root".format( ybin[0], ybin[1], ptbin[0], ptbin[1]), extra_variables=[""], particle=mother_particle, bins=True, tree=tree)
import ROOT, os from ROOT import TChain, TCanvas, TH1 import Imports #directory = "/data/bfys/jdevries/gangadir/workspace/jdevries/LocalXML/" #directory = "/dcache/bfys/jdevries/ntuples/LcAnalysis/ganga/" #job = "78" ID = "" ybins = Imports.getYbins() ptbins = Imports.getPTbins() #cuts = "lcplus_P < 300000 && lcplus_OWNPV_CHI2 < 80 && pplus_ProbNNp > 0.5 && kminus_ProbNNk > 0.4 && piplus_ProbNNpi > 0.5 && pplus_P < 120000 && kminus_P < 115000 && piplus_P < 80000 && pplus_PIDp > 0 && kminus_PIDK > 0" cuts = "lcplus_P < 300000 && lcplus_OWNPV_CHI2 < 80 && pplus_P < 120000 && kminus_P < 115000 && piplus_P < 80000" #101:[285, 2017, "MagDown"] #dictionary = {95:[284, 2017, "MagUp", 2003842], 96:[284, 2017, "MagUp", 2006193], 97:[283, 2018, "MagUp", 2004731], 98:[278, 2018, "MagUp", 2007066], 102:[281, 2017, "MagDown", 2002494], 103:[279, 2018, "MagDown", 2000268], 104:[277, 2018, "MagDown", 2005446], 105:[281, 2016, "MagUp", 2007242], 106:[286, 2016, "MagUp", 2006283], 107:[290, 2016, "MagDown", 2009238], 108:[282, 2016, "MagDown", 2052337]} dictionary = {30:[27, 2012, "MagDown", 551509], 88:[25, 2012, "MagDown", 519998]} f_text = open("/dcache/bfys/scalo/run1_Selection_Eff_output_v2.txt", "w+") for job in dictionary: particle = "" #cuts = "lcplus_L0HadronDecision_TOS==1 && lcplus_Hlt1TrackAllL0Decision_TOS==1" n_subjobs = dictionary[job][0] year = dictionary[job][1] MagPol = dictionary[job][2] tot_entries = dictionary[job][3] if (job == 30): particle = "Xic" #ID = "26103090" ID = "25103029"
inputdir = "/dcache/bfys/jtjepkem/binned_files/" sweightsdir = "/data/bfys/cpawley/sWeights/" outputdir = "/data/bfys/cpawley/dalitz/" #Years, Mag pol and part. types hardcoded years = [2011, 2012, 2015, 2016, 2017, 2018] magPol = ["MagUp", "MagDown"] particle_types = ["Lc", "Xic"] #y and pt bins may vary - so we import them y_bin_temp = Imports.getYbins() y_bin = [] for y in y_bin_temp: y_bin.append("{}-{}".format(y[0], y[1])) pt_bin_temp = Imports.getPTbins() pt_bin = [] for pt in pt_bin_temp: pt_bin.append("{}-{}".format(pt[0], pt[1])) def invariantMass(p1, p2): # build invariant mass string m1 = p1 + "_M" ptot1 = p1 + "_P" px1 = p1 + "_PX" py1 = p1 + "_PY" pz1 = p1 + "_PZ" m2 = p2 + "_M" ptot2 = p2 + "_P" px2 = p2 + "_PX"
def split_in_bins_and_save(root_file, saving_directory, run, useful_variables, mother_particle = "Lc"): #Rapidity and transverse momentum ybins = Imports.getYbins() ptbins = Imports.getPTbins() if (run==1): particles = ["Lc","Xic"] else: particles = [] particles.append(mother_particle) if not os.path.exists(saving_directory + "ybins/"): os.makedirs(saving_directory + "ybins/") if not os.path.exists(saving_directory + "ptbins/"): os.makedirs(saving_directory + "ptbins/") if not os.path.exists(saving_directory + "y_ptbins/"): os.makedirs(saving_directory + "y_ptbins/") tree = root_file for particle in particles: if particle == "Lc": mass_cuts = "lcplus_MM < 2375" if particle == "Xic": mass_cuts = "lcplus_MM > 2375" for ybin in ybins: ycuts = "lcplus_RAPIDITY >= {0} && lcplus_RAPIDITY < {1}".format(ybin[0], ybin[1]) allcuts = " {0} && {1}".format(ycuts, mass_cuts) strip_and_save(0, 0, allcuts, "", saving_directory+"ybins/"+particle+"_ybin_{0}-{1}.root".format(ybin[0],ybin[1]), useful_variables, particle, bins = True, tree = tree) n = len(ptbins) i = 0 print("Files with y({0})".format(ybin)) for ptbin in ptbins: #Progress bar if(i<n): j = (i + 1) / n sys.stdout.write('\r') sys.stdout.write("[%-20s] %d%%" % ('='*int(20*j), 100*j)) sys.stdout.flush() i += 1 ptcuts = "lcplus_PT >= {0} && lcplus_PT < {1}".format(ptbin[0], ptbin[1]) if (ybin[0]==2.0): allcuts = " {0} && {1}".format(ptcuts, mass_cuts) strip_and_save(0, 0, allcuts, "", saving_directory + "ptbins/" + particle + "_ptbin_{0}-{1}.root".format(ptbin[0], ptbin[1]), useful_variables, particle, bins = True,tree = tree) ypt_cut = ycuts+"&&"+ptcuts allcuts = "{0} && {1}".format(ypt_cut, mass_cuts) strip_and_save(0, 0, allcuts, "", saving_directory + "y_ptbins/" + particle + "_ybin_{0}-{1}_ptbin_{2}-{3}.root".format(ybin[0],ybin[1],ptbin[0],ptbin[1]), useful_variables, particle, bins = True, tree = tree) print("\n")