1 |
#!/usr/bin/env python
|
2 |
import sys
|
3 |
import os
|
4 |
import re
|
5 |
from optparse import OptionParser
|
6 |
from array import *
|
7 |
from decimal import *
|
8 |
|
9 |
from OSUT3Analysis.Configuration.configurationOptions import *
|
10 |
from OSUT3Analysis.Configuration.processingUtilities import *
|
11 |
|
12 |
from ROOT import TCut, TFile, TH1D, TTree, TStopwatch, TChain
|
13 |
|
14 |
watch = TStopwatch()
|
15 |
|
16 |
parser = OptionParser()
|
17 |
parser = set_commandline_arguments(parser)
|
18 |
(arguments, args) = parser.parse_args()
|
19 |
|
20 |
if not arguments.localConfig:
|
21 |
sys.exit(" You must specify a localOptions.py file with -l")
|
22 |
if arguments.localConfig:
|
23 |
sys.path.append(os.getcwd())
|
24 |
exec("from " + arguments.localConfig.rstrip('.py') + " import *")
|
25 |
if not arguments.condorDir:
|
26 |
sys.exit(" You must specify a condor directory with -c")
|
27 |
if arguments.condorDir:
|
28 |
condor_dir = "condor/%s" % arguments.condorDir
|
29 |
|
30 |
#save a list of composite datasets
|
31 |
composite_datasets = get_composite_datasets(datasets, composite_dataset_definitions)
|
32 |
#save a list of datasets with composite datasets split up
|
33 |
split_datasets = split_composite_datasets(datasets, composite_dataset_definitions)
|
34 |
|
35 |
#write new histogram to dataset
|
36 |
for dataset in split_datasets:
|
37 |
for hist in input_histograms:
|
38 |
#chain trees together
|
39 |
ch = TChain("OSUAnalysis/"+hist['channel']+"/BNTree_"+hist['channel'])
|
40 |
ch.Add(condor_dir + "/" + dataset + "/hist_*.root")
|
41 |
|
42 |
inputFile = TFile(condor_dir + "/" + dataset + ".root", "UPDATE")
|
43 |
h = TH1D(hist['histName'], hist['histName'], hist['nbins'], hist['xMin'], hist['xMax'])
|
44 |
cut = TCut(hist['cutString'])
|
45 |
|
46 |
ch.Draw(hist['varToPlot']+">>"+hist['histName'], cut)
|
47 |
|
48 |
inputFile.cd("OSUAnalysis/"+hist['channel'])
|
49 |
h.Write()
|
50 |
inputFile.Close()
|
51 |
print "Histogram " + hist['histName'] + " has been added to " + condor_dir + "/"+ dataset + ".root"
|
52 |
|
53 |
#merge output if composite dataset
|
54 |
for composite_dataset in composite_datasets:
|
55 |
component_datasets_list = ""
|
56 |
component_dataset_file_path = ""
|
57 |
for component_dataset in composite_dataset_definitions[composite_dataset]:
|
58 |
component_dataset_dir = "%s/%s" % (condor_dir,component_dataset)
|
59 |
component_dataset_file_path = component_dataset_dir + ".root"
|
60 |
if os.path.isfile(component_dataset_file_path):
|
61 |
component_datasets_list += " " + component_dataset_file_path
|
62 |
composite_dataset_dir = "%s/%s" % (condor_dir,composite_dataset)
|
63 |
command = "mergeHists -p %s %s" % (composite_dataset_dir, component_datasets_list)
|
64 |
print "Merging output for composite dataset: " + composite_dataset
|
65 |
os.system(command)
|
66 |
|
67 |
watch.Stop()
|
68 |
watch.Print()
|
69 |
|
70 |
|
71 |
|
72 |
|