All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sbndcode/sbndcode/gallery/galleryAnalysis/displayHitOverlays.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 import sys, os
3 # Prevent root from printing garbage on initialization.
4 if os.environ.has_key('TERM'):
5  del os.environ['TERM']
6 
7 # Hide command line arguments from ROOT module.
8 myargv = sys.argv
9 sys.argv = myargv[0:1]
10 #sys.argv.append( '-b' )
11 
12 from ROOT import TFile, TCanvas, TH1F, TH2F, TProfile, TLegend, TF1
13 from ROOT import gDirectory, gROOT, gPad, gApplication
14 #ROOT.gErrorIgnoreLevel = ROOT.kError
15 sys.argv = myargv
16 
17 #from validation_utilities import *
18 
19 # Get the object with a given name from a list of objects in the directory
20 def GetObject(name,list):
21  for i in list:
22  if i.GetName()==name:
23  return i.ReadObj()
24  return 0
25 
26 # Print help.
27 
28 def makePlots(inputHitFileName):
29  can = {}
30  canIdx = 0
31 
32  fitTrackPH = {}
33  allHitPH = {}
34 
35  ###########################################################################################################
36  # Open all the input root files.
37  hitTFile = TFile(inputHitFileName)
38  list1 = hitTFile.GetListOfKeys()
39 
40  print '==> In plotHits, using file name {0:s}'.format(inputHitFileName)
41 
42  # Go to directory for the TrackHitAna output
43  for i in list1:
44  if i.GetClassName() == 'TDirectoryFile':
45  if i.GetName() != "mcassociations":
46  continue
47  hitTFile.cd(i.GetName())
48  histogramList = gDirectory.GetListOfKeys()
49  can[canIdx] = TCanvas("MC vs Reco", "MC vs Reco", 800, 600)
50  can[canIdx].Divide(2,2)
51  nHitsPerPrimary = GetObject("NHitsPerPrimary", histogramList)
52  primaryRecoNHits = GetObject("PrimaryRecoNHits", histogramList)
53  deltaNHits = GetObject("DeltaNHits", histogramList)
54  primaryLength = GetObject("PrimaryLength", histogramList)
55  primaryRecLength = GetObject("PrimaryRecLength", histogramList)
56  deltaTrackLen = GetObject("DeltaTrackLen", histogramList)
57  can[canIdx].cd(1)
58  nHitsPerPrimary.SetLineColor(4)
59  nHitsPerPrimary.SetStats(0)
60  nHitsPerPrimary.Draw()
61  primaryRecoNHits.SetLineColor(2)
62  primaryRecoNHits.SetStats(0)
63  primaryRecoNHits.Draw("SAMES")
64  can[canIdx].cd(2)
65  deltaNHits.SetLineColor(4)
66  deltaNHits.SetStats(0)
67  deltaNHits.Draw()
68  can[canIdx].cd(3)
69  primaryLength.SetLineColor(4)
70  primaryLength.SetStats(0)
71  primaryLength.Draw()
72  primaryRecLength.SetLineColor(2)
73  primaryRecLength.SetStats(0)
74  primaryRecLength.Draw("SAMES")
75  can[canIdx].cd(4)
76  deltaTrackLen.SetLineColor(4)
77  deltaTrackLen.SetStats(0)
78  deltaTrackLen.Draw()
79  can[canIdx].Update()
80 
81  canIdx += 1
82 
83  can[canIdx] = TCanvas("Completeness", "Completeness", 800, 600)
84  can[canIdx].Divide(2,2)
85  primCompleteness = GetObject("PrimaryCompleteness", histogramList)
86  primCompVsNHits = GetObject("PrimaryCompVsLogHits", histogramList)
87  primCompVsLen = GetObject("PrimaryCompVsLen", histogramList)
88  primCompVsMom = GetObject("PrimaryCompVsMom", histogramList)
89  can[canIdx].cd(1)
90  primCompleteness.SetLineColor(4)
91  primCompleteness.SetStats(0)
92  primCompleteness.Draw()
93  can[canIdx].cd(2)
94  primCompVsNHits.SetLineColor(4)
95  primCompVsNHits.SetStats(0)
96  primCompVsNHits.Draw()
97  can[canIdx].cd(3)
98  primCompVsLen.SetLineColor(4)
99  primCompVsLen.SetStats(0)
100  primCompVsLen.Draw()
101  can[canIdx].cd(4)
102  primCompVsMom.SetLineColor(4)
103  primCompVsMom.SetStats(0)
104  primCompVsMom.Draw()
105  can[canIdx].Update()
106 
107  canIdx += 1
108 
109  can[canIdx] = TCanvas("Efficiency", "Efficiency", 800, 600)
110  can[canIdx].Divide(2,2)
111  primEfficiency = GetObject("PrimaryEfficiency", histogramList)
112  primEffVsNHits = GetObject("PrimaryEffVsLogHits", histogramList)
113  primEffVsLen = GetObject("PrimaryEffVsLen", histogramList)
114  primEffVsMom = GetObject("PrimaryEffVsMom", histogramList)
115  can[canIdx].cd(1)
116  primEfficiency.SetLineColor(4)
117  primEfficiency.SetStats(0)
118  primEfficiency.Draw()
119  can[canIdx].cd(2)
120  primEffVsNHits.SetLineColor(4)
121  primEffVsNHits.SetStats(0)
122  primEffVsNHits.Draw()
123  can[canIdx].cd(3)
124  primEffVsLen.SetLineColor(4)
125  primEffVsLen.SetStats(0)
126  primEffVsLen.Draw()
127  can[canIdx].cd(4)
128  primEffVsMom.SetLineColor(4)
129  primEffVsMom.SetStats(0)
130  primEffVsMom.Draw()
131  can[canIdx].Update()
132 
133  canIdx += 1
134 
135  can[canIdx] = TCanvas("Purity", "Purity", 800, 600)
136  can[canIdx].Divide(2,2)
137  primPurity = GetObject("PrimaryPurity", histogramList)
138  primPurVsNHits = GetObject("PrimaryPurityVsLogHits", histogramList)
139  primPurVsLen = GetObject("PrimaryPurVsLen", histogramList)
140  primPurVsMom = GetObject("PrimaryPurVsMom", histogramList)
141  can[canIdx].cd(1)
142  primPurity.SetLineColor(4)
143  primPurity.SetStats(0)
144  primPurity.Draw()
145  can[canIdx].cd(2)
146  primPurVsNHits.SetLineColor(4)
147  primPurVsNHits.SetStats(0)
148  primPurVsNHits.Draw()
149  can[canIdx].cd(3)
150  primPurVsLen.SetLineColor(4)
151  primPurVsLen.SetStats(0)
152  primPurVsLen.Draw()
153  can[canIdx].cd(4)
154  primPurVsMom.SetLineColor(4)
155  primPurVsMom.SetStats(0)
156  primPurVsMom.Draw()
157  can[canIdx].Update()
158 
159  canIdx += 1
160 
161 
162  gApplication.Run()
163 
164 
165 def main(argv):
166  infile='TrackAnalysis.root'
167  outdir= ''
168  release=''
169  calorimetry = 0
170  hit = 0
171  tracking = 0
172  momresol = 0
173  flash = 0
174  pid = 0
175 
176  args = argv[1:]
177 
178  if len(args) > 0 :
179  if args[0] == '--input' and len(args) > 1 :
180  infile = args[1]
181 
182  makePlots(infile)
183 
184  currdir = os.getcwd()
185  if outdir != currdir:
186  os.chdir(currdir)
187 
188 if __name__ == '__main__':
189  rc = main(sys.argv)
190  sys.exit(rc)
static std::string format(PyObject *obj, unsigned int pos, unsigned int indent, unsigned int maxlen, unsigned int depth)
Definition: fclmodule.cxx:374
do cd
bool Update(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, const TCSlice &slc, PFPStruct &pfp, bool prt)
Definition: PFPUtils.cxx:1057