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.10 by wulsin, Wed Jun 12 09:03:07 2013 UTC vs.
Revision 1.13 by wulsin, Thu Jun 13 08:34:22 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 58 | Line 64 | def RunOnCondor(arguments, split_dataset
64      return
65  
66  
67 < watch = TStopwatch()
67 > watch  = TStopwatch()
68 > watch1 = TStopwatch()
69 >
70  
71   parser = OptionParser()
72   parser = set_commandline_arguments(parser)
# Line 95 | Line 103 | if arguments.runOnCondor:
103   #write new histogram to dataset
104   if not arguments.quickMerge:
105      for dataset in split_datasets:
106 <        for hist in input_histograms:
107 <            #chain trees together
108 <            ch = TChain("OSUAnalysis/"+hist['channel']+"/BNTree_"+hist['channel'])
109 <            ch.Add(condor_dir + "/" + dataset + "/hist_*.root")
110 <            print "Looping over chain with # entries = %f" % ch.GetEntries()  
111 <            
112 <            outputFile = TFile(condor_dir + "/" + dataset + ".root", "UPDATE")
113 <            if not outputFile or outputFile.IsZombie():  print "Could not open file: %s/%s.root" % (condor_dir, dataset)  
114 <            outputFile.cd("OSUAnalysis/"+hist['channel'])
115 <                
116 <            deleteString = hist['histName'] + ";*"  # delete all existing instances of the object
117 <            currentDir = outputFile.GetDirectory("OSUAnalysis/"+hist['channel']);
118 <            if not currentDir: print "Could not find directory OSUAnalysis/%s in file %s" % (hist['channel'], outputFile.GetName())  
119 <            currentDir.Delete(deleteString);
120 <            if 'nbinsY' in hist:  # only make a 2D histogram if the key "nbinsY" is defined  
121 <                h = TH2D(hist['histName'], hist['histName'],
122 <                         hist['nbins'],  hist['xMin'], hist['xMax'],
123 <                         hist['nbinsY'], hist['yMin'], hist['yMax'])
124 <            else:            
125 <                h = TH1D(hist['histName'], hist['histName'], hist['nbins'], hist['xMin'], hist['xMax'])
126 <            h.Sumw2()  # Needed to get weights correct.  
127 <            cut = TCut(hist['cutString'])
128 <            ch.Draw(hist['varToPlot']+">>"+hist['histName'], cut)  
129 <            h.Write()
130 <            outputFile.Close()
131 <            print "Histogram " + hist['histName'] + " has been added to " + condor_dir + "/"+ dataset + ".root"
106 >        if BNTreeUseScript:
107 >            chainName = "OSUAnalysis/" + BNTreeChannel + "/BNTree_" + BNTreeChannel
108 >            command = "root -l -b -q '" + BNTreeScript + "+(\"" + condor_dir + "\",\"" + dataset + "\",\"" + chainName + "\")'"  
109 >            print "About to execute command:  " + command  
110 >            os.system(command)
111 >        else:
112 >            for hist in input_histograms:
113 >                #chain trees together
114 >                ch = TChain("OSUAnalysis/"+hist['channel']+"/BNTree_"+hist['channel'])
115 >                ch.Add(condor_dir + "/" + dataset + "/hist_*.root")
116 >                print ("Looping over chain with # entries = %f; split time = " % ch.GetEntries()),
117 >                watch1.Stop(); watch1.Print(); watch1.Start()
118 >
119 >                outputFile = TFile(condor_dir + "/" + dataset + ".root", "UPDATE")
120 >                if not outputFile or outputFile.IsZombie():  print "Could not open file: %s/%s.root" % (condor_dir, dataset)  
121 >                outputFile.cd("OSUAnalysis/"+hist['channel'])
122 >
123 >                deleteString = hist['histName'] + ";*"  # delete all existing instances of the object
124 >                currentDir = outputFile.GetDirectory("OSUAnalysis/"+hist['channel']);
125 >                if not currentDir: print "Could not find directory OSUAnalysis/%s in file %s" % (hist['channel'], outputFile.GetName())  
126 >                currentDir.Delete(deleteString);
127 >                if 'nbinsY' in hist:  # only make a 2D histogram if the key "nbinsY" is defined  
128 >                    h = TH2D(hist['histName'], hist['histName'],
129 >                             hist['nbins'],  hist['xMin'], hist['xMax'],
130 >                             hist['nbinsY'], hist['yMin'], hist['yMax'])
131 >                else:            
132 >                    h = TH1D(hist['histName'], hist['histName'], hist['nbins'], hist['xMin'], hist['xMax'])
133 >                h.Sumw2()  # Needed to get weights correct.  
134 >                cut = TCut(hist['cutString'])
135 >                ch.Draw(hist['varToPlot']+">>"+hist['histName'], cut)  
136 >                h.Write()
137 >                outputFile.Close()
138 >                print "Histogram " + hist['histName'] + " has been added to " + condor_dir + "/"+ dataset + ".root"
139  
140   #merge output if composite dataset
141   for composite_dataset in composite_datasets:
# Line 136 | Line 151 | for composite_dataset in composite_datas
151      print "Merging output for composite dataset: " + composite_dataset
152      os.system(command)
153        
154 + print ("Total time: "),
155   watch.Stop()
156   watch.Print()
157              

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines