ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/Configuration/scripts/makeBNTreePlot.py
(Generate patch)

Comparing UserCode/OSUT3Analysis/Configuration/scripts/makeBNTreePlot.py (file contents):
Revision 1.3 by wulsin, Wed Jun 5 10:05:42 2013 UTC vs.
Revision 1.10 by wulsin, Wed Jun 12 09:03:07 2013 UTC

# Line 10 | Line 10 | import re
10   from optparse import OptionParser
11   from array import *
12   from decimal import *
13 + import subprocess
14  
15   from OSUT3Analysis.Configuration.configurationOptions import *
16   from OSUT3Analysis.Configuration.processingUtilities import *
17  
18 < from ROOT import TCut, TFile, TH1D, TTree, TStopwatch, TChain
18 > from ROOT import TChain, TCut, TDirectory, TFile, TH1D, TH2D, TStopwatch, TTree, gROOT  
19 >
20 > gROOT.SetBatch(True)  # This is to prevent pop-up graphical windows
21 >
22 >
23 > def MakeCondorSubmitFile(arguments, dataset):
24 >    p = subprocess.Popen(["which", "makeBNTreePlot.py"], stdout=subprocess.PIPE)
25 >    executable = p.communicate()[0]  # read the stdout of the command  
26 >    workdir = os.getcwd() + "/"
27 >    outdir = "condor/"+arguments.condorDir+"/"+dataset+"/"  
28 >    out = open(outdir+"/condorBNTree.sub", "w")
29 >    out.write("Executable              = " + executable + " \n")
30 >    out.write("Universe                = vanilla \n")
31 >    out.write("Getenv                  = True \n")
32 >    out.write("Arguments               = -D " + dataset + " -l " + arguments.localConfig + " -c " + arguments.condorDir + " \n")
33 >    out.write("Output                  = " + workdir + outdir + "condorBNTree_$(Process).out \n")
34 >    out.write("Error                   = " + workdir + outdir + "condorBNTree_$(Process).err \n")
35 >    out.write("Log                     = " + workdir + outdir + "condorBNTree_$(Process).log \n")
36 >    out.write("+IsLocalJob             = true \n")
37 >    out.write("Rank                    = TARGET.IsLocalSlot \n")
38 >    out.write("Queue 1 \n")
39 >    out.close()  
40 >
41 >
42 > def RunOnCondor(arguments, split_datasets):  
43 >    print "Running jobs on condor, instead of interactively."
44 >    ## print "Found condorDir = %s" % (condorDir)
45 >    ## print "Found split_datasets = "
46 >    ## print split_datasets
47 >
48 >    for dataset in split_datasets:  
49 >        MakeCondorSubmitFile(arguments, dataset)  
50 >        cmd = "condor_submit condor/"+arguments.condorDir+"/"+dataset+"/condorBNTree.sub"
51 >        os.system(cmd)
52 >        print "Submitting job: %s " % cmd
53 >
54 >    print "Once condor jobs have finished, merge the composite datasets and then make plots with:"  
55 >    print "    makeBNTreePlot.py -q -l " + arguments.localConfig + " -c " + arguments.condorDir  
56 >    print "    makePlots.py         -l " + arguments.localConfig + " -c " + arguments.condorDir  
57 >        
58 >    return
59 >
60  
61   watch = TStopwatch()
62  
# Line 24 | Line 66 | parser = set_commandline_arguments(parse
66  
67   if not arguments.localConfig:
68      sys.exit(" You must specify a localOptions.py file with -l")
69 < if arguments.localConfig:
69 > if arguments.localConfig:  
70      sys.path.append(os.getcwd())
71      exec("from " + arguments.localConfig.rstrip('.py') + " import *")
72   if not arguments.condorDir:
# Line 32 | Line 74 | if not arguments.condorDir:
74   if arguments.condorDir:
75      condor_dir = "condor/%s" % arguments.condorDir
76  
77 + if arguments.datasetName:  # If datasetName is specified on command line, then override the value from localConfig  
78 +    datasets = [
79 +        arguments.datasetName,
80 +    ]
81 +
82   #save a list of composite datasets
83   composite_datasets = get_composite_datasets(datasets, composite_dataset_definitions)
84   #save a list of datasets with composite datasets split up
85   split_datasets = split_composite_datasets(datasets, composite_dataset_definitions)
86  
87 + if arguments.quickMerge and arguments.runOnCondor:
88 +    print "Cannot use -q (--quickMerge) and -C (--runOnCondor) options simultaneously.  Please choose one or the other."
89 +    exit()  
90 +
91 + if arguments.runOnCondor:
92 +    RunOnCondor(arguments, split_datasets)
93 +    exit()    
94 +
95   #write new histogram to dataset
96 < for dataset in split_datasets:
97 <    for hist in input_histograms:
98 <        #chain trees together
99 <        ch = TChain("OSUAnalysis/"+hist['channel']+"/BNTree_"+hist['channel'])
100 <        ch.Add(condor_dir + "/" + dataset + "/hist_*.root")
101 <
102 <        inputFile = TFile(condor_dir + "/" + dataset + ".root", "UPDATE")
103 <        h = TH1D(hist['histName'], hist['histName'], hist['nbins'], hist['xMin'], hist['xMax'])
104 <        cut = TCut(hist['cutString'])
105 <  
106 <        ch.Draw(hist['varToPlot']+">>"+hist['histName'], cut)
107 <  
108 <        inputFile.cd("OSUAnalysis/"+hist['channel'])
109 <        h.Write()
110 <        inputFile.Close()
111 <        print "Histogram " + hist['histName'] + " has been added to " + condor_dir + "/"+ dataset + ".root"
96 > if not arguments.quickMerge:
97 >    for dataset in split_datasets:
98 >        for hist in input_histograms:
99 >            #chain trees together
100 >            ch = TChain("OSUAnalysis/"+hist['channel']+"/BNTree_"+hist['channel'])
101 >            ch.Add(condor_dir + "/" + dataset + "/hist_*.root")
102 >            print "Looping over chain with # entries = %f" % ch.GetEntries()  
103 >            
104 >            outputFile = TFile(condor_dir + "/" + dataset + ".root", "UPDATE")
105 >            if not outputFile or outputFile.IsZombie():  print "Could not open file: %s/%s.root" % (condor_dir, dataset)  
106 >            outputFile.cd("OSUAnalysis/"+hist['channel'])
107 >                
108 >            deleteString = hist['histName'] + ";*"  # delete all existing instances of the object
109 >            currentDir = outputFile.GetDirectory("OSUAnalysis/"+hist['channel']);
110 >            if not currentDir: print "Could not find directory OSUAnalysis/%s in file %s" % (hist['channel'], outputFile.GetName())  
111 >            currentDir.Delete(deleteString);
112 >            if 'nbinsY' in hist:  # only make a 2D histogram if the key "nbinsY" is defined  
113 >                h = TH2D(hist['histName'], hist['histName'],
114 >                         hist['nbins'],  hist['xMin'], hist['xMax'],
115 >                         hist['nbinsY'], hist['yMin'], hist['yMax'])
116 >            else:            
117 >                h = TH1D(hist['histName'], hist['histName'], hist['nbins'], hist['xMin'], hist['xMax'])
118 >            h.Sumw2()  # Needed to get weights correct.  
119 >            cut = TCut(hist['cutString'])
120 >            ch.Draw(hist['varToPlot']+">>"+hist['histName'], cut)  
121 >            h.Write()
122 >            outputFile.Close()
123 >            print "Histogram " + hist['histName'] + " has been added to " + condor_dir + "/"+ dataset + ".root"
124  
125   #merge output if composite dataset
126   for composite_dataset in composite_datasets:
# Line 74 | Line 141 | watch.Print()
141              
142  
143  
77

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines