def analyze(datasets, inputDir='.'): gROOT.SetBatch() gStyle.SetOptStat(0) gStyle.SetOptTitle(0) canvas = TCanvas("c1", "c1", 800, 800) input_ele = TFile(inputDir + '/output_electrons.root', 'read') input_muon = TFile(inputDir + '/output_muons.root', 'read') input_fake = TFile(inputDir + '/output_fake.root', 'read') h_disc_ele = input_ele.Get('disc') h_disc_muon = input_muon.Get('disc') h_disc_fake = input_fake.Get('disc') h_sigma_ele = input_ele.Get('sigma') h_sigma_muon = input_muon.Get('sigma') h_sigma_fake = input_fake.Get('sigma') h_disc_signal = {} h_sigma_signal = {} for dataset in datasets: if not dataset.startswith('higgsino'): continue fin = TFile(inputDir + '/output_' + dataset + '.root', 'read') h_disc = fin.Get('disc') h_sigma = fin.Get('sigma') h_disc.SetDirectory(0) h_sigma.SetDirectory(0) h_disc_signal[dataset] = h_disc h_sigma_signal[dataset] = h_sigma fin.Close() roc_curves = { 'disc_%d_%s' % (i, sig) : getROC(h_disc_ele, h_disc_muon, h_disc_fake, h_disc_signal[sig], i) for i in [4, 5, 6] for sig in h_disc_signal } roc_curves.update( { 'sigma_%d_%s' % (i, sig) : getROC(h_sigma_ele, h_sigma_muon, h_sigma_fake, h_sigma_signal[sig], i) for i in [4, 5, 6] for sig in h_disc_signal } ) fout = TFile('durp.root', 'recreate') for curve_name in roc_curves: roc_curves[curve_name][0].Write(curve_name) print 'Optimal cut for', curve_name, '=', roc_curves[curve_name][1] m = TMarker(roc_curves[curve_name][2], roc_curves[curve_name][3], 29) m.Write(curve_name + '_optimal') fout.Close() for i in [4, 5, 6]: plotStack(h_disc_ele, h_disc_muon, h_disc_fake, h_disc_signal['higgsino_300_1000'], i, 'discriminant', canvas, rebin=5) plotStack(h_sigma_ele, h_sigma_muon, h_sigma_fake, h_sigma_signal['higgsino_300_1000'], i, 'sigma', canvas, rebin=5) for dataset in h_disc_signal: for i in [4, 5, 6]: wp = getWP(h_disc_ele, h_sigma_ele, h_disc_muon, h_sigma_muon, h_disc_fake, h_sigma_fake, h_disc_signal[dataset], h_sigma_signal[dataset], i) print dataset, '--', wp iClone = -1 print '\nComparing disc < 0.3 to fiducial map method:\n' printChanges('Electrons nLayers=4', h_sigma_ele, h_disc_ele, 0.3, 4, iClone) printChanges('Electrons nLayers=5', h_sigma_ele, h_disc_ele, 0.3, 5, iClone) printChanges('Electrons nLayers>=6', h_sigma_ele, h_disc_ele, 0.3, 6, iClone) printChanges('Muons nLayers=4', h_sigma_muon, h_disc_muon, 0.3, 4, iClone) printChanges('Muons nLayers=5', h_sigma_muon, h_disc_muon, 0.3, 5, iClone) printChanges('Muons nLayers>=6', h_sigma_muon, h_disc_muon, 0.3, 6, iClone) printChanges('Fakes nLayers=4', h_sigma_fake, h_disc_fake, 0.3, 4, iClone) printChanges('Fakes nLayers=5', h_sigma_fake, h_disc_fake, 0.3, 5, iClone) printChanges('Fakes nLayers>=6', h_sigma_fake, h_disc_fake, 0.3, 6, iClone) extra_samples = { 10 : ['0p' + str(i) for i in range(2, 10)] + [str(i) for i in range(0, 10)], 100 : [str(i*10) for i in range(2, 10)], 1000 : [str(i*100) for i in range(2, 10)], 10000 : [str(i*1000) for i in range(2, 10)], } for i in [4, 5, 6]: print 'NLAYERS: ', i for mass in range(100, 1000, 100): for lifetime in [10, 100, 1000, 10000]: datasetName = 'higgsino_%d_%d' % (mass, lifetime) change_string = printChanges('Higgsino_%dGeV_%dcm_94X' % (mass, lifetime), h_sigma_signal[datasetName], h_disc_signal[datasetName], 0.3, i, iClone) for extra_lifetime in extra_samples[lifetime]: print change_string.replace('Higgsino_%dGeV_%dcm_94X' % (mass, lifetime), 'Higgsino_%dGeV_%scm_94X' % (mass, extra_lifetime))
continue chi2 /= N if chi2 < minChi2 or minChi2 < 0.0: minChi2 = chi2 minChi2HitAndTOBDrop = i minChi2Index = copy.deepcopy(index) g.SetPoint(n, i, chi2) n += 1 print "(" + str(iteration + 1) + " / " + str( nIterations) + ") minimum chi2: " + str(minChi2) + " at " + str( minChi2HitAndTOBDrop) m = TMarker(minChi2HitAndTOBDrop, minChi2, 29) m.SetMarkerSize(3) hitDropGridLower = hitDropGrid[ minChi2Index - 1] if minChi2Index > 0 else hitDropGrid[ minChi2Index] - hitDropGrid[minChi2Index + 1] hitDropGridUpper = hitDropGrid[minChi2Index + 1] if minChi2Index < len( hitDropGrid) - 1 else hitDropGrid[minChi2Index] + hitDropGrid[ minChi2Index - 1] hitDropGrid = numpy.linspace(max(hitDropGridLower, 0.0), hitDropGridUpper, 5) foutMode = "update" if iteration > 0 else "recreate" fout = TFile.Open("hipChi2.root", foutMode) fout.cd() g.Write("chi2VsHitDropProbability_" + str(iteration)) m.Write("bestFitPoint_" + str(iteration)) fout.Close()