-
Notifications
You must be signed in to change notification settings - Fork 0
/
userAnalysis.py
84 lines (57 loc) · 2.44 KB
/
userAnalysis.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env python
# encoding: utf-8
"""
UserAnalysis.py
Created by Morten Dam Jørgensen on 2010-04-29.
Copyright (c) 2010 Niels Bohr Institute. All rights reserved.
"""
from GluinoAnalysis.histo import HistogramService, Histogram
import ROOT
import os, sys
import array
import math
class UserAnalysis(object):
"""docstring for UserAnalysis"""
def __init__(self, input):
super(UserAnalysis, self).__init__()
self.input = input
self.analysis(self.input) # Execute analysis
def analysis(self, input):
"""User Analysis method"""
print "Entering Analysis"
print "Jobs:"
print input["input"]
############## REQUIRED BY GluinoAnalysis ##################
# Add the input files to the ROOT chain
chain = ROOT.TChain("CollectionTree") ## Add your TTree name here
for inputFile in input["input"]:
chain.AddFile(inputFile)
# Intitialize histogramService
histoSrv = HistogramService()
## Use custom variables from configuration file in analysis...
if input.has_key("joboptions"):
options = {}
for opt in xrange(len(input["joboptions"])):
options[input["joboptions"][opt][0]] = input["joboptions"][opt][1]
print options
# Get the number of events to process
N_evts = chain.GetEntries()
if options.has_key("maxeventsperjob") and int(options["maxeventsperjob"]) > 0 and not N_evts == 0:
N_evts = int(options["maxeventsperjob"])
print "Events: %d selected out of %d" % (N_evts, chain.GetEntries())
########### END OF REQUIRED BY GluinoAnalysis #############
# Select all branches from ROOT files
chain.SetBranchStatus("*", 1)
# mAnaly = MortenAnalysisGamma(chain, histoSrv, userOptions=options)
## event loop
try:
for i in xrange(N_evts):
if i % int(N_evts/10.0) == 0:
print "At %d of %d events" % (i, N_evts)
chain.GetEntry(i)
for trk_i in xrange(chain.Trk_N):
print chain.Trk_p[trk_i]/1000.0
except:
print "Event loop error", sys.exc_info()
# Return histogram service for merging (REQUIRED)
self.histSrv = histoSrv.returnTree()