ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/OSUT3Analysis/Configuration/scripts/makeBNTreePlot.py
Revision: 1.4
Committed: Wed Jun 5 14:04:47 2013 UTC (11 years, 10 months ago) by wulsin
Content type: text/x-python
Branch: MAIN
Changes since 1.3: +3 -1 lines
Log Message:
run in batch mode to prevent pop-up windows

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 TCut, TFile, TH1D, TTree, TStopwatch, TChain, 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 h = TH1D(hist['histName'], hist['histName'], hist['nbins'], hist['xMin'], hist['xMax'])
51 cut = TCut(hist['cutString'])
52
53 ch.Draw(hist['varToPlot']+">>"+hist['histName'], cut)
54
55 inputFile.cd("OSUAnalysis/"+hist['channel'])
56 h.Write()
57 inputFile.Close()
58 print "Histogram " + hist['histName'] + " has been added to " + condor_dir + "/"+ dataset + ".root"
59
60 #merge output if composite dataset
61 for composite_dataset in composite_datasets:
62 component_datasets_list = ""
63 component_dataset_file_path = ""
64 for component_dataset in composite_dataset_definitions[composite_dataset]:
65 component_dataset_dir = "%s/%s" % (condor_dir,component_dataset)
66 component_dataset_file_path = component_dataset_dir + ".root"
67 if os.path.isfile(component_dataset_file_path):
68 component_datasets_list += " " + component_dataset_file_path
69 composite_dataset_dir = "%s/%s" % (condor_dir,composite_dataset)
70 command = "mergeHists -p %s %s" % (composite_dataset_dir, component_datasets_list)
71 print "Merging output for composite dataset: " + composite_dataset
72 os.system(command)
73
74 watch.Stop()
75 watch.Print()
76
77
78
79