--- UserCode/OSUT3Analysis/Configuration/scripts/makeBNTreePlot.py 2013/06/12 09:15:32 1.12 +++ UserCode/OSUT3Analysis/Configuration/scripts/makeBNTreePlot.py 2013/06/13 09:35:44 1.14 @@ -1,7 +1,13 @@ #!/usr/bin/env python -# Must specify options with -l argument, e.g.: -# > makeBNTreePlot.py -l sampleBNTreePlotConfig.py +# Must specify options with -l argument, and condor directory with -c argument, e.g.: +# > makeBNTreePlot.py -l sampleBNTreePlotConfig.py -c myCondorDir + +# Additional arugments specify the running mode: +# -D : Run on a single dataset (typically for testing) +# -C: Submit jobs to run on condor over all datasets +# BNTreeUseScript=True (set in sampleBNTreePlotConfig.py): run BNTreeScript root macro (also set in sampleBNTreePlotConfig.py), +# which must take as arguments the condor directory, dataset, and channel import sys @@ -64,7 +70,15 @@ watch1 = TStopwatch() parser = OptionParser() parser = set_commandline_arguments(parser) + +### Only used by makeBNTreePlot.py (maybe move to another file?) +parser.add_option("-D", "--dataset", dest="datasetName", + help="Name of dataset (overrides value from local configuration file)") +parser.add_option("-C", "--runOnCondor", action="store_true", dest="runOnCondor", default=False, + help="Run on condor instead of interactively") + (arguments, args) = parser.parse_args() + if not arguments.localConfig: sys.exit(" You must specify a localOptions.py file with -l") @@ -97,33 +111,39 @@ if arguments.runOnCondor: #write new histogram to dataset 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" + if BNTreeUseScript: + chainName = "OSUAnalysis/" + BNTreeChannel + "/BNTree_" + BNTreeChannel + command = "root -l -b -q '" + BNTreeScript + "+(\"" + condor_dir + "\",\"" + dataset + "\",\"" + chainName + "\")'" + print "About to execute command: " + command + os.system(command) + else: + 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: