| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

pmtCoords.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # An example script showing how to access the PMT and detector geometry
00003 #
00004 # The script starts up a Gaudi application that does nothing but
00005 # initialize the Gaudi system.
00006 # Once the system is initialized, we have access to Gaudi Services,
00007 # such as the PMT Geometry.
00008 #
00009 # dandwyer@caltech.edu 2008-07-31
00010 
00011 # Load ROOT.  Be sure to do this before loading Gaudi.
00012 import ROOT
00013 # Need CLHEP classes for geometry
00014 ROOT.gSystem.Load("libCLHEPRflx")
00015 # GaudiPython overwrites ROOT, so save a reference
00016 _ROOT = ROOT
00017 
00018 # Configure the detector geometry
00019 import xmldetdesc
00020 xmldetdesc.config()
00021 
00022 # Get units information
00023 from GaudiKernel import SystemOfUnits as units
00024 
00025 # Set configuration for the PMT Geometry Service
00026 from Gaudi.Configuration import *
00027 conf = ApplicationMgr()
00028 from DetHelpers.DetHelpersConf import PmtGeomInfoSvc
00029 pgisvc = PmtGeomInfoSvc("PmtGeomInfoSvc")
00030 #pgisvc.OutputLevel = 1
00031 pgisvc.StreamItems = [ "/dd/Structure/DayaBay" ]
00032 
00033 # Add a dummy algorithm to initialize gaudi 
00034 from GaudiPython.GaudiAlgs import GaudiAlgo
00035 from GaudiPython import *
00036 class InitAlg(GaudiAlgo):
00037     """A dummy algorithm that does nothing but provide access to gaudi
00038     services"""
00039     def __init__(self,name):
00040         GaudiAlgo.__init__(self,name)
00041         print "Making InitAlg",name
00042 
00043     def initialize(self):
00044         status = GaudiAlgo.initialize(self)
00045         return status
00046 
00047     def execute(self):
00048         return SUCCESS
00049 
00050 # Prepare Application
00051 from GaudiPython import AppMgr
00052 app = AppMgr()
00053 
00054 app.EvtSel = "NONE"
00055 app.ExtSvc += [ "PmtGeomInfoSvc" ]
00056 initalg = InitAlg("InitAlg")
00057 app.setAlgorithms( [ initalg ] )
00058 
00059 # Run Application (which does nothing but initialize gaudi)
00060 app.run(1)
00061 
00062 # GaudiPython overwrites ROOT, so restore from saved reference
00063 ROOT = _ROOT
00064 del _ROOT
00065 
00066 # Get the pmt geometry service
00067 #pmtSvc = initalg.pgis
00068 pmtSvc = initalg.svc("IPmtGeomInfoSvc","PmtGeomInfoSvc")
00069 
00070 #################################################################
00071 # From here on out, we treat this like a normal ROOT script.
00072 
00073 # PMT ID for DYB Site AD1, Ring 1, Column 1
00074 site = 0x01 # 0x01 (DYB), 0x02 (LA), or 0x04 (FAR)
00075 ad =   1    # 1-2 (near sites), 1-4 (far sites)
00076 ring = 1    # 1-8
00077 col =  1    # 1-24
00078 
00079 pmtid =  (site<<24) | (ad<<16) | (ring<<8) | col
00080 
00081 # PMT Path for same AD, but Ring 8, Column 1
00082 pmtPath = "/dd/Structure/AdPmtStructure/db-ad/db-ad1-ring8-column1"
00083 
00084 # Get the geometry info for the two pmts
00085 pmtGeom_1_1 = pmtSvc.get(pmtid)
00086 pmtGeom_8_1 = pmtSvc.get(pmtPath)
00087 
00088 # Get position relative to AD center
00089 pmtPos_1_1 = pmtGeom_1_1.localPosition()
00090 pmtPos_8_1 = pmtGeom_8_1.localPosition()
00091 print "="*60
00092 print "\n\n"
00093 print "Daya Bay Site, AD1"
00094 print ""
00095 print "In AD Coordinate System:"
00096 print "  PMT (Ring 1, Column 1) X Y Z [mm]: ",pmtPos_1_1.x(),pmtPos_1_1.y(),pmtPos_1_1.z()
00097 print "  PMT (Ring 8, Column 1) X Y Z [mm]: ",pmtPos_8_1.x(),pmtPos_8_1.y(),pmtPos_8_1.z()
00098 
00099 # Get position relative in global coordinates of the entire experiment
00100 pmtGPos_1_1 = pmtGeom_1_1.globalPosition()
00101 pmtGPos_8_1 = pmtGeom_8_1.globalPosition()
00102 print ""
00103 print "In Global Coordinate System of the entire experiment:"
00104 print "  PMT (Ring 1, Column 1) X Y Z [mm]: ",pmtGPos_1_1.x(),pmtGPos_1_1.y(),pmtGPos_1_1.z()
00105 print "  PMT (Ring 8, Column 1) X Y Z [mm]: ",pmtGPos_8_1.x(),pmtGPos_8_1.y(),pmtGPos_8_1.z()
00106 
00107 # Get the AD position in Global Coordinates
00108 adDetector = pmtGeom_1_1.parentDetector()
00109 adName = adDetector.name()
00110 # Detector origin in local coords: 0,0,0 by definition
00111 origin = gbl.Gaudi.XYZPoint(0,0,0)
00112 # Transform to global coordinates
00113 adPos = adDetector.geometry().toGlobal(origin)
00114 print ""
00115 print "Daya Bay Site AD1"
00116 print "  Path:", adName
00117 print "  Global Coordinates X Y Z [mm]:",adPos.x(),adPos.y(),adPos.z()
00118 print "\n\n"
00119 print "="*60
00120 
00121 
00122 #####################################
00123 
00124 # Draw a picture of the AD PMTs in ROOT
00125 nRings = 8
00126 nColumns = 24
00127 nPMTs = nRings*nColumns
00128 pmtHist = ROOT.TH3F("pmtHist",
00129                     "PMT Positions",
00130                     200,-2.5,2.5,
00131                     200,-2.5,2.5,
00132                     200,-2.5,2.5)
00133 
00134 site = 0x01 # 0x01 (DYB), 0x02 (LA), or 0x04 (FAR)
00135 ad =   1    # 1-2 (near sites), 1-4 (far sites)
00136 meter = float(units.meter)
00137 for ring in range(1,nRings+1):
00138     for col in range(1,nColumns+1):
00139         pmtid =  (site<<24) | (ad<<16) | (ring<<8) | col
00140         pos = pmtSvc.get(pmtid).localPosition()
00141         # Add pmt positions in meters
00142         point = (ring-1)*nColumns + (col-1)
00143         [x,y,z] = [pos.x()/meter, pos.y()/meter, pos.z()/meter]
00144         #print "Point, ring, col: ",point,ring,col,x,y,z
00145         pmtHist.Fill(x,y,z)
00146         
00147 #Draw the figure
00148 pmtHist.SetMarkerStyle(8)
00149 pmtHist.SetMarkerSize(1)
00150 pmtHist.SetMarkerColor(4)
00151 pmtHist.GetXaxis().SetTitle("X [m]")
00152 pmtHist.GetYaxis().SetTitle("Y [m]")
00153 pmtHist.GetZaxis().SetTitle("Z [m]")
00154 pmtHist.GetXaxis().SetTitleOffset(1.75)
00155 pmtHist.GetYaxis().SetTitleOffset(1.75)
00156 pmtHist.GetZaxis().SetTitleOffset(1)
00157 pmtHist.Draw()
00158 
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:15:09 2011 for DetHelpers by doxygen 1.4.7