systList=list(), ) if syst == "nominal": categoryDict[catStr].sampleDict[sample].hist = obj else: if syst not in categoryDict[catStr].sampleDict[sample].systList: categoryDict[catStr].sampleDict[sample].systList.append( BaseObject(syst, hist=obj, vary=varyMap[vary])) config = CardConfig(signal_name) shapeStr = "shapes * * {fileName} $CHANNEL/$PROCESS $CHANNEL/$PROCESS_$SYSTEMATIC\n" config.shapeStr = shapeStr.format(fileName=signal_name + "_shapes.root") dataCard = DataCard(config) cardDir = option.outputDir + "/" + dataCard.makeOutFileName("/", "") reader = FileReader() mkdir_p(option.outputDir) writeObjDict = {} binList = [] for catStr, cat in categoryDict.iteritems(): lnSystFile = lnSystElectronFile if 'isE' in catStr else lnSystMuonFile shapeSystFile = shapeSystElectronFile if 'isE' in catStr else shapeSystMuonFile bin = BaseObject( catStr, lnSystFile=lnSystFile, shapeSystFile=shapeSystFile, processList=list(), signalNames=[ signal_name, ], isSignal=lambda x: x == "sig", systList=list(),
plot_ydim = 2 # ____________________________________________________________ || arr = np.load(input_csv_path) arr_list, _ = preprocess_conditional_flow_data_cww(arr) ndim = 3 ncond = 1 # ____________________________________________________________ || nf_model = ConditionalRealNVP(num_coupling_layers=10, ndim=ndim, ncond=ncond) # ____________________________________________________________ || batch_trainer = MiniBatchTrainer() nf_optimizer = tf.keras.optimizers.Adam() mkdir_p(output_path) for i_epoch in range(n_epoch): idx_train = np.random.randint(0, len(arr_list), batch_size) x_train = np.concatenate([arr_list[idx].x for idx in idx_train]) condition_train = np.concatenate( [arr_list[idx].condition for idx in idx_train]) idx_batch = np.random.randint(0, x_train.shape[0], event_size) x_train = x_train[idx_batch] condition_train = condition_train[idx_batch] nf_model.direction = -1 with tf.GradientTape() as tape: nf_loss = nf_model.log_loss([x_train, condition_train]) grads = tape.gradient(nf_loss, nf_model.trainable_weights)
"etaL3", "etaL4", "phiL1", "phiL2", "phiL3", "phiL4", "idL1", "idL2", "idL3", "idL4", ] f = uproot.open(input_file_path) t = f[input_tree_path] model = tf.keras.models.load_model(model_path) df = t.pandas.df(branches=branches) x = np.reshape(df.massZ2.to_numpy() / scale, (1, df.shape[0])) inputs = np.apply_along_axis( lambda x: np.histogram(x, bins=bins, density=1.)[0], 1, x) pred = model.predict(inputs) ll = [ model.calculate_loss(pred, tf.constant([[b]], dtype=np.float32))[0] for b in plot_bins ] mkdir_p(plot_dir) plt.plot(bins, ll) plt.grid() plt.savefig(os.path.join(plot_dir, plot_png))
inputBinName=binName, signalNames=[ "Sig", ], ) for binName in binNames if "-Norm" not in binName and "comb" not in binName ] # ____________________________________________________________________________________________________________________________________________ || # syst lnSystReader = LogNormalSystReader() # ____________________________________________________________________________________________________________________________________________ || reader = FileReader() mkdir_p(os.path.abspath(outputDir)) rateParamDict = {} fakeRateDict = {} paramList = [] sel_bin_list = [] for ibin, bin in enumerate(binList): if option.verbose: print "-" * 20 if option.verbose: print bin.name histName = bin.inputBinName # bkg for bkgName in bkg_names: reader.openFile(inputDir, bkgName, TFileName)
print "Reading directory " + cardDir inputFile = ROOT.TFile( cardDir + "higgsCombineTest." + option.method + ".mH120.root", "READ") tree = inputFile.Get("limit") window_name = cardDir.split("/")[-2] window_value = int(window_name.split("_")[1][1:]) if expOnly: for i, entry in enumerate(tree): outDict[quantiles[i]][window_value] = getattr(entry, varName) else: raise RuntimeError # ________________________________________________________________ || # Draw limit with outDict # ________________________________________________________________ || mkdir_p(os.path.dirname(option.outputPath)) nPoints = len(outDict["central"]) outGraphDict = {} for plot in plots: W = 800 H = 600 T = 0.08 * H B = 0.12 * H L = 0.12 * W R = 0.04 * W c = ROOT.TCanvas("c", "c", 100, 100, W, H) if setLogY: c.SetLogy() c.SetFillColor(0) c.SetBorderMode(0) c.SetFrameFillStyle(0)
def init_job(self): mkdir_p(self.output_path)