ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/Configuration/scripts/makeBNTreePlot.py
Revision: 1.5
Committed: Wed Jun 5 16:11:17 2013 UTC (11 years, 10 months ago) by wulsin
Content type: text/x-python
Branch: MAIN
Changes since 1.4: +8 -5 lines
Log Message:
remove existing instances of histograms

File Contents

# Content
1 #!/usr/bin/env python
2
3 # Must specify options with -l argument, e.g.:
4 # > makeBNTreePlot.py -l sampleBNTreePlotConfig.py
5
6
7 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 from ROOT import TChain, TCut, TDirectory, TFile, TH1D, TStopwatch, TTree, gROOT
18
19 gROOT.SetBatch(True) # This is to prevent pop-up graphical windows
20
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 if arguments.localConfig:
30 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 #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 for hist in input_histograms:
45 #chain trees together
46 ch = TChain("OSUAnalysis/"+hist['channel']+"/BNTree_"+hist['channel'])
47 ch.Add(condor_dir + "/" + dataset + "/hist_*.root")
48
49 inputFile = TFile(condor_dir + "/" + dataset + ".root", "UPDATE")
50 inputFile.cd("OSUAnalysis/"+hist['channel'])
51
52 deleteString = hist['histName'] + ";*" # delete all existing instances of the object
53 currentDir = inputFile.GetDirectory("OSUAnalysis/"+hist['channel']);
54 currentDir.Delete(deleteString);
55
56 h = TH1D(hist['histName'], hist['histName'], hist['nbins'], hist['xMin'], hist['xMax'])
57 cut = TCut(hist['cutString'])
58 ch.Draw(hist['varToPlot']+">>"+hist['histName'], cut)
59 h.Write()
60 inputFile.Close()
61 print "Histogram " + hist['histName'] + " has been added to " + condor_dir + "/"+ dataset + ".root"
62
63 #merge output if composite dataset
64 for composite_dataset in composite_datasets:
65 component_datasets_list = ""
66 component_dataset_file_path = ""
67 for component_dataset in composite_dataset_definitions[composite_dataset]:
68 component_dataset_dir = "%s/%s" % (condor_dir,component_dataset)
69 component_dataset_file_path = component_dataset_dir + ".root"
70 if os.path.isfile(component_dataset_file_path):
71 component_datasets_list += " " + component_dataset_file_path
72 composite_dataset_dir = "%s/%s" % (condor_dir,composite_dataset)
73 command = "mergeHists -p %s %s" % (composite_dataset_dir, component_datasets_list)
74 print "Merging output for composite dataset: " + composite_dataset
75 os.system(command)
76
77 watch.Stop()
78 watch.Print()
79
80
81
82