ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/Configuration/scripts/makeBNTreePlot.py
Revision: 1.6
Committed: Thu Jun 6 14:24:21 2013 UTC (11 years, 10 months ago) by wulsin
Content type: text/x-python
Branch: MAIN
Changes since 1.5: +5 -2 lines
Log Message:
Apply Sumw2() before filling histogram

File Contents

# User Rev Content
1 jbrinson 1.1 #!/usr/bin/env python
2 wulsin 1.3
3     # Must specify options with -l argument, e.g.:
4     # > makeBNTreePlot.py -l sampleBNTreePlotConfig.py
5    
6    
7 jbrinson 1.1 import sys
8     import os
9     import re
10     from optparse import OptionParser
11     from array import *
12     from decimal import *
13    
14     from OSUT3Analysis.Configuration.configurationOptions import *
15     from OSUT3Analysis.Configuration.processingUtilities import *
16    
17 wulsin 1.5 from ROOT import TChain, TCut, TDirectory, TFile, TH1D, TStopwatch, TTree, gROOT
18 wulsin 1.4
19     gROOT.SetBatch(True) # This is to prevent pop-up graphical windows
20 jbrinson 1.1
21     watch = TStopwatch()
22    
23     parser = OptionParser()
24     parser = set_commandline_arguments(parser)
25     (arguments, args) = parser.parse_args()
26    
27     if not arguments.localConfig:
28     sys.exit(" You must specify a localOptions.py file with -l")
29 wulsin 1.6 if arguments.localConfig:
30 jbrinson 1.1 sys.path.append(os.getcwd())
31     exec("from " + arguments.localConfig.rstrip('.py') + " import *")
32     if not arguments.condorDir:
33     sys.exit(" You must specify a condor directory with -c")
34     if arguments.condorDir:
35     condor_dir = "condor/%s" % arguments.condorDir
36    
37 jbrinson 1.2 #save a list of composite datasets
38     composite_datasets = get_composite_datasets(datasets, composite_dataset_definitions)
39     #save a list of datasets with composite datasets split up
40     split_datasets = split_composite_datasets(datasets, composite_dataset_definitions)
41    
42     #write new histogram to dataset
43     for dataset in split_datasets:
44 jbrinson 1.1 for hist in input_histograms:
45 jbrinson 1.2 #chain trees together
46 jbrinson 1.1 ch = TChain("OSUAnalysis/"+hist['channel']+"/BNTree_"+hist['channel'])
47     ch.Add(condor_dir + "/" + dataset + "/hist_*.root")
48 wulsin 1.6 print "Looping over chain with # entries = %f" % ch.GetEntries()
49 jbrinson 1.2
50 jbrinson 1.1 inputFile = TFile(condor_dir + "/" + dataset + ".root", "UPDATE")
51 wulsin 1.5 inputFile.cd("OSUAnalysis/"+hist['channel'])
52    
53     deleteString = hist['histName'] + ";*" # delete all existing instances of the object
54 wulsin 1.6 currentDir = inputFile.GetDirectory("OSUAnalysis/"+hist['channel']);
55     if not currentDir: print "Could not find directory OSUAnalysis/%s" % hist['channel']
56 wulsin 1.5 currentDir.Delete(deleteString);
57    
58 jbrinson 1.1 h = TH1D(hist['histName'], hist['histName'], hist['nbins'], hist['xMin'], hist['xMax'])
59 wulsin 1.6 h.Sumw2() # Needed to get weights correct.
60 jbrinson 1.1 cut = TCut(hist['cutString'])
61 wulsin 1.5 ch.Draw(hist['varToPlot']+">>"+hist['histName'], cut)
62 jbrinson 1.1 h.Write()
63     inputFile.Close()
64     print "Histogram " + hist['histName'] + " has been added to " + condor_dir + "/"+ dataset + ".root"
65 jbrinson 1.2
66     #merge output if composite dataset
67     for composite_dataset in composite_datasets:
68     component_datasets_list = ""
69     component_dataset_file_path = ""
70     for component_dataset in composite_dataset_definitions[composite_dataset]:
71     component_dataset_dir = "%s/%s" % (condor_dir,component_dataset)
72     component_dataset_file_path = component_dataset_dir + ".root"
73     if os.path.isfile(component_dataset_file_path):
74     component_datasets_list += " " + component_dataset_file_path
75     composite_dataset_dir = "%s/%s" % (condor_dir,composite_dataset)
76     command = "mergeHists -p %s %s" % (composite_dataset_dir, component_datasets_list)
77     print "Merging output for composite dataset: " + composite_dataset
78     os.system(command)
79    
80 jbrinson 1.1 watch.Stop()
81     watch.Print()
82 jbrinson 1.2
83 jbrinson 1.1
84    
85