def dump_event_info(tree, cut, is_reco=False): print 40 * "-" print "cut =", cut print "event numbers:" elist = TEventList('elist', 'elist') tree.Draw('>>elist', cut) for i in xrange(0, elist.GetN()): tree.GetEntry(elist.GetEntry(i)) if is_reco: event_number = tree.event_number weight = tree.event_weight lep_pt = tree.lep_pt lep_eta = tree.lep_eta else: event_number = tree.eventNumber weight = tree.mcEventWeight lep_pt = tree.lepton_pt lep_eta = tree.lepton_eta n_lep = tree.n_leptons print " event_number={}, met={:.2f}, meff={:.2f}, lep:".format( event_number, tree.met, tree.meff), for i, lpt in enumerate(lep_pt): print "(pt={:.2f}, eta={:.2f}),".format(lpt, lep_eta[i]), print # reset default is_reco = False
def makeList(sample): f1 = TFile.Open(indir+"signal.root") t1 = f1.Get("Nominal") t1.Draw(">>elist","mchannelnumber == "+sample) elist = TEventList() elist = ROOT.gDirectory.Get("elist") ef = TFile(outdir+"elist.root","recreate") elist.Write() return True
def buildArraysFromROOT(tree, allowedFeatures, cut, skipEvents, maxEvents, name): dataContainer = {} featureNames = [] eventCounter = -1 gROOT.Reset() # Get branch names for item in tree.GetListOfBranches(): featureName = item.GetName() if featureName in allowedFeatures: featureNames.append(featureName) dataContainer[featureName] = [] # Build the event list tcut = TCut(cut) tree.Draw(">>eventList", tcut) eventList = TEventList() eventList = gDirectory.Get("eventList") nSelectedEvents = eventList.GetN() # Event loop for i in range(0, nSelectedEvents): if (i < skipEvents): continue if (i % 100 == 0): sys.stdout.write("Reading %s: %d%% \r" % (tree.GetName(), 100 * i / (maxEvents + skipEvents))) sys.stdout.flush() if i >= (maxEvents + skipEvents): break selectedEvNum = eventList.GetEntry(i) tree.GetEntry(selectedEvNum) for feature in featureNames: dataContainer[feature].append(tree.__getattr__(feature)) sys.stdout.write("\n") # Make the numpy arrays outputArray = np.array([]) for feature in allowedFeatures: column = dataContainer[feature] feature_vector = np.asarray(column) feature_vector = feature_vector.reshape(feature_vector.size, 1) if outputArray.shape[0] == 0: outputArray = feature_vector else: outputArray = np.concatenate((outputArray, feature_vector), axis=1) imp = Imputer(missing_values=-999, strategy='mean', axis=0) imp.fit(outputArray) outputArray = imp.transform(outputArray) print name print "Events: ", outputArray.shape[0] print "Features: ", outputArray.shape[1] return outputArray
# Set up the axes for plotting figROC, axsROC = plt.subplots(2,3) axesROC = axsROC.ravel() figRecErr, axsRecErr = plt.subplots(2,3) axesRecErr = axsRecErr.ravel() # MAIN LOOP OVER SIGNAL SAMPLES axesCounter = 0 for cut in cutList: # Selections and numbers of events cutSignal = cut tcut = TCut(cutSignal) tree.Draw(">>eventList",tcut) eventList = TEventList() eventList = gDirectory.Get("eventList") nSignalEvents = eventList.GetN()/2 nBackgroundEvents = nSignalEvents print "=====================================" print "Selection: ",cutSignal, "with ",nSignalEvents," signal events and ",nBackgroundEvents," background events" # Build data arrays X_train_bg = X_train_bg_all[0:nBackgroundEvents,:] X_test_bg = X_test_bg_all[0:nBackgroundEvents,:] X_test_sig = buildArraysFromROOT(tree,susyFeaturesNtup,cutSignal,nSignalEvents,nSignalEvents,"TESTING SAMPLE (signal)") X_test_sig = min_max_scaler.transform(X_test_sig) # Set target equal to input - auto-encoder Y_train = X_train_bg
print " l_eq_subsam {}".format(l_eq_subsam[s]) print " ngenev {}".format(ngenev) ns += 1 # set min lum eq min_lum_eq = 999999. for s, sname in enumerate(snames): if (l_eq_subsam[s] < min_lum_eq): min_lum_eq = l_eq_subsam[s] print "min_lum_eq {}".format(min_lum_eq) config["isMixed"] = True #debug config["lumiFb"] = min_lum_eq json_str = json.dumps(config) els = [TEventList("el" + sname, "el" + sname) for sname in snames] n_ev_base = 0 t_sm = 1. for s, sname in enumerate(snames): if (s == len(snames) - 1): t_sm = times_sm #debug n_ev_sfrac = n_ev_subsam[s] * (min_lum_eq / l_eq_subsam[s]) * t_sm print "# {} events to use: {} ".format(sname, n_ev_sfrac) print tchain.Draw( ">>el{}".format(sname), "(Entry$ > {}) && ( Entry$ <= {} ) {}".format(n_ev_base, n_ev_base + n_ev_sfrac, extra_cut)) n_ev_base += n_ev_subsam[s] el = TEventList("el", "el") for list_to_add in els: el.Add(list_to_add)