--- UserCode/OSUT3Analysis/Configuration/scripts/makeBNTreePlot.py 2013/06/11 11:40:12 1.9 +++ UserCode/OSUT3Analysis/Configuration/scripts/makeBNTreePlot.py 2013/06/12 09:15:32 1.12 @@ -50,11 +50,17 @@ def RunOnCondor(arguments, split_dataset cmd = "condor_submit condor/"+arguments.condorDir+"/"+dataset+"/condorBNTree.sub" os.system(cmd) print "Submitting job: %s " % cmd + + print "Once condor jobs have finished, merge the composite datasets and then make plots with:" + print " makeBNTreePlot.py -q -l " + arguments.localConfig + " -c " + arguments.condorDir + print " makePlots.py -l " + arguments.localConfig + " -c " + arguments.condorDir return -watch = TStopwatch() +watch = TStopwatch() +watch1 = TStopwatch() + parser = OptionParser() parser = set_commandline_arguments(parser) @@ -80,41 +86,44 @@ composite_datasets = get_composite_datas #save a list of datasets with composite datasets split up split_datasets = split_composite_datasets(datasets, composite_dataset_definitions) +if arguments.quickMerge and arguments.runOnCondor: + print "Cannot use -q (--quickMerge) and -C (--runOnCondor) options simultaneously. Please choose one or the other." + exit() + if arguments.runOnCondor: RunOnCondor(arguments, split_datasets) - exit() - -print "Running interactively instead" - + exit() #write new histogram to dataset -for dataset in split_datasets: - for hist in input_histograms: - #chain trees together - ch = TChain("OSUAnalysis/"+hist['channel']+"/BNTree_"+hist['channel']) - ch.Add(condor_dir + "/" + dataset + "/hist_*.root") - print "Looping over chain with # entries = %f" % ch.GetEntries() - - outputFile = TFile(condor_dir + "/" + dataset + ".root", "UPDATE") - if not outputFile or outputFile.IsZombie(): print "Could not open file: %s/%s.root" % (condor_dir, dataset) - outputFile.cd("OSUAnalysis/"+hist['channel']) - - deleteString = hist['histName'] + ";*" # delete all existing instances of the object - currentDir = outputFile.GetDirectory("OSUAnalysis/"+hist['channel']); - if not currentDir: print "Could not find directory OSUAnalysis/%s in file %s" % (hist['channel'], outputFile.GetName()) - currentDir.Delete(deleteString); - if 'nbinsY' in hist: # only make a 2D histogram if the key "nbinsY" is defined - h = TH2D(hist['histName'], hist['histName'], - hist['nbins'], hist['xMin'], hist['xMax'], - hist['nbinsY'], hist['yMin'], hist['yMax']) - else: - h = TH1D(hist['histName'], hist['histName'], hist['nbins'], hist['xMin'], hist['xMax']) - h.Sumw2() # Needed to get weights correct. - cut = TCut(hist['cutString']) - ch.Draw(hist['varToPlot']+">>"+hist['histName'], cut) - h.Write() - outputFile.Close() - print "Histogram " + hist['histName'] + " has been added to " + condor_dir + "/"+ dataset + ".root" +if not arguments.quickMerge: + for dataset in split_datasets: + for hist in input_histograms: + #chain trees together + ch = TChain("OSUAnalysis/"+hist['channel']+"/BNTree_"+hist['channel']) + ch.Add(condor_dir + "/" + dataset + "/hist_*.root") + print ("Looping over chain with # entries = %f; split time = " % ch.GetEntries()), + watch1.Stop(); watch1.Print(); watch1.Start() + + outputFile = TFile(condor_dir + "/" + dataset + ".root", "UPDATE") + if not outputFile or outputFile.IsZombie(): print "Could not open file: %s/%s.root" % (condor_dir, dataset) + outputFile.cd("OSUAnalysis/"+hist['channel']) + + deleteString = hist['histName'] + ";*" # delete all existing instances of the object + currentDir = outputFile.GetDirectory("OSUAnalysis/"+hist['channel']); + if not currentDir: print "Could not find directory OSUAnalysis/%s in file %s" % (hist['channel'], outputFile.GetName()) + currentDir.Delete(deleteString); + if 'nbinsY' in hist: # only make a 2D histogram if the key "nbinsY" is defined + h = TH2D(hist['histName'], hist['histName'], + hist['nbins'], hist['xMin'], hist['xMax'], + hist['nbinsY'], hist['yMin'], hist['yMax']) + else: + h = TH1D(hist['histName'], hist['histName'], hist['nbins'], hist['xMin'], hist['xMax']) + h.Sumw2() # Needed to get weights correct. + cut = TCut(hist['cutString']) + ch.Draw(hist['varToPlot']+">>"+hist['histName'], cut) + h.Write() + outputFile.Close() + print "Histogram " + hist['histName'] + " has been added to " + condor_dir + "/"+ dataset + ".root" #merge output if composite dataset for composite_dataset in composite_datasets: @@ -130,6 +139,7 @@ for composite_dataset in composite_datas print "Merging output for composite dataset: " + composite_dataset os.system(command) +print ("Total time: "), watch.Stop() watch.Print()