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.12 by wulsin, Wed Jun 12 09:15:32 2013 UTC vs.
Revision 1.14 by wulsin, Thu Jun 13 09:35:44 2013 UTC

# Line 1 | Line 1
1   #!/usr/bin/env python
2  
3 < # Must specify options with -l argument, e.g.:  
4 < # > makeBNTreePlot.py -l sampleBNTreePlotConfig.py  
3 > # Must specify options with -l argument, and condor directory with -c argument, e.g.:  
4 > # > makeBNTreePlot.py -l sampleBNTreePlotConfig.py -c myCondorDir
5 >
6 > # Additional arugments specify the running mode:
7 > # -D <dataset>:  Run on a single dataset (typically for testing)
8 > # -C:  Submit jobs to run on condor over all datasets
9 > # BNTreeUseScript=True (set in sampleBNTreePlotConfig.py):  run BNTreeScript root macro (also set in sampleBNTreePlotConfig.py),
10 > #    which must take as arguments the condor directory, dataset, and channel
11  
12  
13   import sys
# Line 64 | Line 70 | watch1 = TStopwatch()
70  
71   parser = OptionParser()
72   parser = set_commandline_arguments(parser)
73 +
74 + ###  Only used by makeBNTreePlot.py (maybe move to another file?)        
75 + parser.add_option("-D", "--dataset", dest="datasetName",        
76 +                  help="Name of dataset (overrides value from local configuration file)")        
77 + parser.add_option("-C", "--runOnCondor",  action="store_true", dest="runOnCondor", default=False,        
78 +                  help="Run on condor instead of interactively")        
79 +
80   (arguments, args) = parser.parse_args()
81 +
82  
83   if not arguments.localConfig:
84      sys.exit(" You must specify a localOptions.py file with -l")
# Line 97 | Line 111 | if arguments.runOnCondor:
111   #write new histogram to dataset
112   if not arguments.quickMerge:
113      for dataset in split_datasets:
114 <        for hist in input_histograms:
115 <            #chain trees together
116 <            ch = TChain("OSUAnalysis/"+hist['channel']+"/BNTree_"+hist['channel'])
117 <            ch.Add(condor_dir + "/" + dataset + "/hist_*.root")
118 <            print ("Looping over chain with # entries = %f; split time = " % ch.GetEntries()),
119 <            watch1.Stop(); watch1.Print(); watch1.Start()
120 <            
121 <            outputFile = TFile(condor_dir + "/" + dataset + ".root", "UPDATE")
122 <            if not outputFile or outputFile.IsZombie():  print "Could not open file: %s/%s.root" % (condor_dir, dataset)  
123 <            outputFile.cd("OSUAnalysis/"+hist['channel'])
124 <                
125 <            deleteString = hist['histName'] + ";*"  # delete all existing instances of the object
126 <            currentDir = outputFile.GetDirectory("OSUAnalysis/"+hist['channel']);
127 <            if not currentDir: print "Could not find directory OSUAnalysis/%s in file %s" % (hist['channel'], outputFile.GetName())  
128 <            currentDir.Delete(deleteString);
129 <            if 'nbinsY' in hist:  # only make a 2D histogram if the key "nbinsY" is defined  
130 <                h = TH2D(hist['histName'], hist['histName'],
131 <                         hist['nbins'],  hist['xMin'], hist['xMax'],
132 <                         hist['nbinsY'], hist['yMin'], hist['yMax'])
133 <            else:            
134 <                h = TH1D(hist['histName'], hist['histName'], hist['nbins'], hist['xMin'], hist['xMax'])
135 <            h.Sumw2()  # Needed to get weights correct.  
136 <            cut = TCut(hist['cutString'])
137 <            ch.Draw(hist['varToPlot']+">>"+hist['histName'], cut)  
138 <            h.Write()
139 <            outputFile.Close()
140 <            print "Histogram " + hist['histName'] + " has been added to " + condor_dir + "/"+ dataset + ".root"
114 >        if BNTreeUseScript:
115 >            chainName = "OSUAnalysis/" + BNTreeChannel + "/BNTree_" + BNTreeChannel
116 >            command = "root -l -b -q '" + BNTreeScript + "+(\"" + condor_dir + "\",\"" + dataset + "\",\"" + chainName + "\")'"  
117 >            print "About to execute command:  " + command  
118 >            os.system(command)
119 >        else:
120 >            for hist in input_histograms:
121 >                #chain trees together
122 >                ch = TChain("OSUAnalysis/"+hist['channel']+"/BNTree_"+hist['channel'])
123 >                ch.Add(condor_dir + "/" + dataset + "/hist_*.root")
124 >                print ("Looping over chain with # entries = %f; split time = " % ch.GetEntries()),
125 >                watch1.Stop(); watch1.Print(); watch1.Start()
126 >
127 >                outputFile = TFile(condor_dir + "/" + dataset + ".root", "UPDATE")
128 >                if not outputFile or outputFile.IsZombie():  print "Could not open file: %s/%s.root" % (condor_dir, dataset)  
129 >                outputFile.cd("OSUAnalysis/"+hist['channel'])
130 >
131 >                deleteString = hist['histName'] + ";*"  # delete all existing instances of the object
132 >                currentDir = outputFile.GetDirectory("OSUAnalysis/"+hist['channel']);
133 >                if not currentDir: print "Could not find directory OSUAnalysis/%s in file %s" % (hist['channel'], outputFile.GetName())  
134 >                currentDir.Delete(deleteString);
135 >                if 'nbinsY' in hist:  # only make a 2D histogram if the key "nbinsY" is defined  
136 >                    h = TH2D(hist['histName'], hist['histName'],
137 >                             hist['nbins'],  hist['xMin'], hist['xMax'],
138 >                             hist['nbinsY'], hist['yMin'], hist['yMax'])
139 >                else:            
140 >                    h = TH1D(hist['histName'], hist['histName'], hist['nbins'], hist['xMin'], hist['xMax'])
141 >                h.Sumw2()  # Needed to get weights correct.  
142 >                cut = TCut(hist['cutString'])
143 >                ch.Draw(hist['varToPlot']+">>"+hist['histName'], cut)  
144 >                h.Write()
145 >                outputFile.Close()
146 >                print "Histogram " + hist['histName'] + " has been added to " + condor_dir + "/"+ dataset + ".root"
147  
148   #merge output if composite dataset
149   for composite_dataset in composite_datasets:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines