00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 import ROOT
00014
00015 ROOT.gSystem.Load("libCLHEPRflx")
00016
00017 _ROOT = ROOT
00018
00019
00020 import xmldetdesc
00021 xmldetdesc.config()
00022
00023
00024 from GaudiKernel import SystemOfUnits as units
00025
00026
00027 from Gaudi.Configuration import *
00028 conf = ApplicationMgr()
00029 from DetHelpers.DetHelpersConf import PmtGeomInfoSvc
00030 pgisvc = PmtGeomInfoSvc("PmtGeomInfoSvc")
00031
00032 pgisvc.StreamItems = [ "/dd/Structure/DayaBay" ]
00033
00034
00035 from GaudiPython.GaudiAlgs import GaudiAlgo
00036 from GaudiPython import *
00037 class InitAlg(GaudiAlgo):
00038 """A dummy algorithm that does nothing but provide access to gaudi
00039 services"""
00040 def __init__(self,name):
00041 GaudiAlgo.__init__(self,name)
00042 print "Making InitAlg",name
00043
00044 def initialize(self):
00045 status = GaudiAlgo.initialize(self)
00046 return status
00047
00048 def execute(self):
00049 return SUCCESS
00050
00051
00052 from GaudiPython import AppMgr
00053 app = AppMgr()
00054
00055 app.EvtSel = "NONE"
00056 app.ExtSvc += [ "PmtGeomInfoSvc" ]
00057 initalg = InitAlg("InitAlg")
00058 app.setAlgorithms( [ initalg ] )
00059
00060
00061 app.run(1)
00062
00063
00064 ROOT = _ROOT
00065 del _ROOT
00066
00067
00068
00069 pmtSvc = initalg.svc("IPmtGeomInfoSvc","PmtGeomInfoSvc")
00070
00071
00072
00073
00074 import ROOT
00075
00076
00077
00078 output_st = raw_input("Choose to plot as contour (default), exact, exact2d: ")
00079 if output_st=='contour': output=0
00080 elif output_st=='exact': output=1
00081 elif output_st=='exact2d': output=2
00082 else: output=0
00083
00084 file_st = raw_input("ROOT file to read (default:electron.root): ")
00085 tree_st = raw_input("Tree file to read (default:DetSimValiTree): ")
00086 if not file_st: file_st = 'electron.root'
00087 if not tree_st: tree_st = 'DetSimValiTree'
00088 f = ROOT.TFile(file_st,'READ')
00089 tree = f.Get(tree_st)
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099 hist = [ROOT.TH2F('hist0','PMT Hits: DB site, AD1',24,1,25,8,1,9),
00100 ROOT.TH2F('hist1','PMT Hits: DB site, AD2',24,1,25,8,1,9),
00101 ROOT.TH2F('hist2','PMT Hits: LA site, AD1',24,1,25,8,1,9),
00102 ROOT.TH2F('hist3','PMT Hits: LA site, AD2',24,1,25,8,1,9),
00103 ROOT.TH2F('hist4','PMT Hits: far site, AD1',24,1,25,8,1,9),
00104 ROOT.TH2F('hist5','PMT Hits: far site, AD2',24,1,25,8,1,9),
00105 ROOT.TH2F('hist6','PMT Hits: far site, AD3',24,1,25,8,1,9),
00106 ROOT.TH2F('hist7','PMT Hits: far site, AD4',24,1,25,8,1,9)]
00107
00108 if output==1:
00109 gr = [ROOT.TGraph(),ROOT.TGraph(),ROOT.TGraph(),ROOT.TGraph(),
00110 ROOT.TGraph(),ROOT.TGraph(),ROOT.TGraph(),ROOT.TGraph()]
00111
00112 if output==2:
00113 gr = [ROOT.TGraph2D(),ROOT.TGraph2D(),ROOT.TGraph2D(),ROOT.TGraph2D(),
00114 ROOT.TGraph2D(),ROOT.TGraph2D(),ROOT.TGraph2D(),ROOT.TGraph2D()]
00115
00116 if (output==1 or output==2):
00117 gr[0].SetTitle('PMT Hits: DB site, AD1')
00118 gr[1].SetTitle('PMT Hits: DB site, AD2')
00119 gr[2].SetTitle('PMT Hits: LA site, AD1')
00120 gr[3].SetTitle('PMT Hits: LA site, AD2')
00121 gr[4].SetTitle('PMT Hits: far site, AD1')
00122 gr[5].SetTitle('PMT Hits: far site, AD2')
00123 gr[6].SetTitle('PMT Hits: far site, AD3')
00124 gr[7].SetTitle('PMT Hits: far site, AD4')
00125
00126 c = []
00127
00128
00129 meter = float(units.meter)
00130 degree = float(units.degree)
00131
00132
00133 entries = tree.GetEntries()
00134
00135 for j in xrange(entries):
00136 i = tree.LoadTree(j)
00137 if i < 0:
00138 break
00139
00140 nb = tree.GetEntry(j)
00141 if nb <=0:
00142 continue
00143
00144 SimHits = tree.SimHitsEntries
00145 pmtID = tree.sensID
00146 hitx = tree.hitx
00147 hity = tree.hity
00148 hitz = tree.hitz
00149 if SimHits<0:
00150 continue
00151
00152 for k in xrange(SimHits):
00153 site = pmtID[k]>>24
00154 det = ((site<<24)^pmtID[k])>>16
00155 ring = (((site<<24)|(det<<16))^pmtID[k])>>8
00156 col = (((site<<24)|(det<<16)|(ring<<8))^pmtID[k])
00157
00158 if (site==1) and (det==1): idx=0
00159 elif (site==1) and (det==2): idx=1
00160 elif (site==2) and (det==1): idx=2
00161 elif (site==2) and (det==2): idx=3
00162 elif (site==4) and (det==1): idx=4
00163 elif (site==4) and (det==2): idx=5
00164 elif (site==4) and (det==3): idx=6
00165 elif (site==4) and (det==4): idx=7
00166 else:
00167 print 'Unexpected site/AdID number - skipping this hit'
00168 continue
00169
00170
00171 pmtGeom = pmtSvc.get(pmtID[k])
00172 adDetector = pmtGeom.parentDetector()
00173 pmtDetector = pmtGeom.detectorElement()
00174
00175
00176 pmtHit = gbl.Gaudi.XYZPoint(hitx[k],hity[k],hitz[k])
00177 gpHit = pmtDetector.geometry().toGlobal(pmtHit)
00178 lpHit = adDetector.geometry().toLocal(gpHit)
00179
00180
00181
00182 x = lpHit.x() / meter
00183 y = lpHit.y() / meter
00184 z = lpHit.z() / meter
00185 rho = ROOT.TMath.Sqrt(x*x + y*y)
00186 phi = ROOT.TMath.ATan2(y,x) / degree
00187
00188 hist[idx].Fill(col,ring)
00189 NPoint = int(hist[idx].GetEntries())-1
00190 if output==1: gr[idx].SetPoint(NPoint,phi,z)
00191 if output==2: gr[idx].SetPoint(NPoint,x,y,z)
00192
00193 ROOT.gStyle.SetPalette(1)
00194 ROOT.gStyle.SetOptStat(11)
00195
00196
00197 for i in xrange(8):
00198 if hist[i].GetEntries()==0: continue
00199 c += [ROOT.TCanvas()]
00200
00201 if output==0:
00202 hist[i].GetXaxis().SetTitle('Column')
00203 hist[i].GetYaxis().SetTitle('Ring')
00204 hist[i].Draw('COLZ')
00205 elif output==1:
00206 gr[i].GetXaxis().SetTitle('#phi [deg]')
00207 gr[i].GetYaxis().SetTitle('Z [m]')
00208 gr[i].SetMarkerStyle(1)
00209 gr[i].SetMarkerColor(2)
00210 gr[i].Draw('AP')
00211 elif output==2:
00212 gr[i].GetXaxis().SetTitle('X [m]')
00213 gr[i].GetYaxis().SetTitle('Y [m]')
00214 gr[i].GetZaxis().SetTitle('Z [m]')
00215 gr[i].GetXaxis().SetTitleOffset(1.75)
00216 gr[i].GetYaxis().SetTitleOffset(1.75)
00217 gr[i].GetZaxis().SetTitleOffset(1)
00218 gr[i].SetMarkerStyle(1)
00219 gr[i].SetMarkerColor(2)
00220 gr[i].Draw('P')
00221 else: print 'Invalid draw command: problem with reading user input'