/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

Compare.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 '''
00003    Compare one calibration result to another reference result
00004    Usage: nuwa.py -m Compare
00005    Zhe Wang, Aug. 18, 2011
00006 '''
00007 from GaudiPython import *  # gbl ...
00008 from DybPython.DybPythonAlg import DybPythonAlg
00009 from Table import Table
00010 
00011 class Compare(DybPythonAlg):
00012     def __init__(self,name):
00013         print "Make PlotOneframe:",name
00014         DybPythonAlg.__init__(self,name)
00015 
00016     def initialize(self):
00017         print "Init PlotOneframe:",self.name()
00018         status = DybPythonAlg.initialize(self)
00019         if status.isFailure(): return status
00020 
00021         # Cable Svc, that is all this needs
00022         from DataSvc.DataSvcConf import StaticCableSvc
00023         self.cableSvc = self.svc('ICableSvc','CableSvc')
00024 
00025         # Init context and svc mode
00026         from GaudiPython import gbl
00027         context = gbl.Context()
00028         context.SetSite(gbl.Site.kAll)
00029         context.SetSimFlag(1)   # data
00030         context.SetDetId(gbl.DetectorId.kAll)        
00031         context.SetTimeStamp(gbl.TimeStamp(1300000000,0))   # To do: Need to figure out the time more smartly
00032         svcMode = gbl.ServiceMode(context,0);
00033 
00034         # Get pmt sensor <-> cable map
00035         adPmtSensors = self.cableSvc.adPmtSensors(svcMode)
00036         poolPmtSensors = self.cableSvc.poolPmtSensors(svcMode);
00037         print "\n\n number of AD PMT sensors =",adPmtSensors.size()
00038         print "\n\n number of pool PMT sensors =",poolPmtSensors.size()
00039         
00040         # Name the two input files
00041         Name = "RollingGain"
00042         NameRef = "Random"
00043         
00044         # Edit this
00045         #  Aug. 1 AD1
00046         #File = '../0011596-0011596/Rolling01/pmtDataTable_01.txt'
00047         #FileRef = '../LED_runs/yuzy/0801_EH1_AD/pmtCalibTable_EH1_AD1_1.5e7_combinedrung11565t11575_LED.txt'
00048         #  Aug. 1 AD2
00049         #File = '../0011595-0011595/Rolling01/pmtDataTable_01.txt'
00050         #FileRef = '../LED_runs/yuzy/0801_EH1_AD/pmtCalibTable_EH1_AD2_1.5e7_combinedrung11551t11576_LED.txt'
00051 
00052         #  Aug. 13 AD1
00053         #File = '../0012312-0012312/Rolling01/pmtDataTable_01.txt'
00054         #FileRef = '../LED_runs/yuzy/0813_EH1_AD/AD1_12261.txt'
00055         #  Aug. 13 AD2
00056         #File = '../0012312-0012312/Rolling01/pmtDataTable_01.txt'
00057         #FileRef = '../LED_runs/yuzy/0813_EH1_AD/AD2_12278.txt'
00058 
00059         #  Aug. 14 AD1
00060         #File = '../0012313-0012313/Rolling01/pmtDataTable_01.txt'
00061         #FileRef = '../LED_runs/yuzy/0814-AD1-12313-AD2-12334.txt'
00062         #  Aug. 14 AD2
00063         #File = '../0012334-0012334/Rolling01/pmtDataTable_01.txt'
00064         #FileRef = '../LED_runs/yuzy/0814-AD1-12313-AD2-12334.txt'
00065 
00066         #  Aug. 17 AD1
00067         #File = '../0012492-0012577/Rolling01/pmtDataTable_01.txt'
00068         #FileRef = '../LED_runs/yuzy/0817-AD1-12493-AD2-12515.txt'
00069         #  Aug. 17 AD2
00070         #File = '../0012492-0012577/Rolling01/pmtDataTable_01.txt'
00071         #FileRef = '../LED_runs/yuzy/0817-AD1-12493-AD2-12515.txt'
00072 
00073         #  Aug. 19 AD1
00074         #File = '../0012658-0012658/Rolling01/pmtDataTable_01.txt'
00075         #FileRef = '../LED_runs/yuzy/0819-AD1-12658-AD2-12677.txt'
00076         #  Aug. 19 AD2
00077         #File = '../0012677-0012677/Rolling01/pmtDataTable_01.txt'
00078         #FileRef = '../LED_runs/yuzy/0819-AD1-12658-AD2-12677.txt'
00079 
00080         # 17094, AD1
00081         #File =    '../RG-Random-Compare/0017094-0017094-RG/Rolling01/pmtDataTable_04.txt'
00082         #FileRef = '../RG-Random-Compare/0017094-0017094-Random/Rolling01/pmtDataTable_01.txt'
00083         # 17094, AD2
00084         #File =    '../RG-Random-Compare/0017094-0017094-RG/Rolling01/pmtDataTable_02.txt'
00085         #FileRef = '../RG-Random-Compare/0017094-0017094-Random/Rolling01/pmtDataTable_02.txt'
00086         # 17094, IWS
00087         #File =    '../RG-Random-Compare/0017094-0017094-RG/Rolling01/pmtDataTable_06.txt'
00088         #FileRef = '../RG-Random-Compare/0017094-0017094-Random/Rolling01/pmtDataTable_06.txt'
00089         # 17094, OWS
00090         #File =    '../RG-Random-Compare/0017094-0017094-RG/Rolling01/pmtDataTable_01.txt'
00091         #FileRef = '../RG-Random-Compare/0017094-0017094-Random/Rolling01/pmtDataTable_03.txt'
00092         
00093         # 17268, AD1
00094         #File =    '../RG-Random-Compare/0017268-0017268-RG/Rolling01/pmtDataTable_02.txt'
00095         #FileRef = '../RG-Random-Compare/0017268-0017268-Random/Rolling01/pmtDataTable_01.txt'
00096         # 17268, IWS
00097         #File =    '../RG-Random-Compare/0017268-0017268-RG/Rolling01/pmtDataTable_07.txt'
00098         #FileRef = '../RG-Random-Compare/0017268-0017268-Random/Rolling01/pmtDataTable_05.txt'
00099         # 17268, OWS
00100         File =    '../RG-Random-Compare/0017268-0017268-RG/Rolling01/pmtDataTable_01.txt'
00101         FileRef = '../RG-Random-Compare/0017268-0017268-Random/Rolling01/pmtDataTable_02.txt'
00102         
00103         # Open and parse two tables
00104         table = Table()
00105         table.read( File )
00106         
00107         tableRef = Table()
00108         tableRef.read( FileRef )
00109 
00110         # Create a TTree to hold all useful variables
00111         from CalibTree import CalibTree
00112         calibt = CalibTree("comp.root")
00113 
00114         for rowIdx in range(table.nRows):
00115             calibt.reset()
00116             calibt.Time[0] = 0
00117 
00118             pmtId = gbl.DayaBay.DetectorSensor( int(table.columns['pmtID'][rowIdx]) )
00119             calibt.Site[0] = pmtId.site()
00120             calibt.Detector[0] = pmtId.detectorId()
00121 
00122             channelId = self.cableSvc.elecChannelId( pmtId, svcMode )
00123             calibt.Board[0] = channelId.board()
00124             calibt.Channel[0] = channelId.connector()
00125             
00126             if pmtId.isAD():
00127                 adPmtId = gbl.DayaBay.AdPmtSensor( int(table.columns['pmtID'][rowIdx]) )
00128                 calibt.Ring[0] = adPmtId.ring()
00129                 calibt.Column[0] = adPmtId.column()
00130 
00131             if pmtId.isWaterShield():
00132                 poolPmtId = gbl.DayaBay.PoolPmtSensor( int(table.columns['pmtID'][rowIdx]) )
00133                 calibt.Wall[0] = poolPmtId.wallNumber()
00134                 calibt.Spot[0] = poolPmtId.wallSpot()
00135                 calibt.Inward[0] = poolPmtId.inwardFacing()
00136                                                     
00137             calibt.Spe[0]      = float( table.columns['speHigh'][rowIdx]    )
00138             calibt.SpeErr[0]   = float( table.columns['gainErr'][rowIdx]    )
00139             calibt.SpeSigma[0] = float( table.columns['sigmaSpe'][rowIdx]   )
00140             calibt.Ped[0]      = float( table.columns['preAdc'][rowIdx]     )
00141             calibt.PedErr[0]   = float( table.columns['preAdcErr'][rowIdx]  )
00142             calibt.Nhit[0]     = int( table.columns['nhits'][rowIdx]        )
00143             calibt.Chi2ndf[0]  = float( table.columns['chi2ndf'][rowIdx]    )
00144             calibt.FitStat[0]  = int( table.columns['fitStat'][rowIdx]      )
00145 
00146             calibt.DarkRate[0]      = float( table.columns['darkRate'][rowIdx]     )
00147             calibt.DarkRateErr[0]   = float( table.columns['darkRateErr'][rowIdx]  )
00148             calibt.ElecRate[0]      = float( table.columns['elecNoiseRate'][rowIdx]     )
00149             calibt.ElecRateErr[0]   = float( table.columns['elecNoiseRateErr'][rowIdx]  )
00150 
00151             # Then search the reference table for the same channel
00152             for refIdx in range(tableRef.nRows):
00153                 refPmtId = gbl.DayaBay.DetectorSensor( int(tableRef.columns['pmtID'][refIdx]) )
00154                 if refPmtId == pmtId:
00155                     calibt.RefSpe[0]      = float( tableRef.columns['speHigh'][refIdx]    )
00156                     calibt.RefSpeSigma[0] = float( tableRef.columns['sigmaSpe'][refIdx]   )
00157                     break
00158             
00159             if calibt.Nhit[0] > 300:
00160                 calibt.fill()
00161 
00162         calibt.close()
00163 
00164         return SUCCESS
00165 
00166     def execute(self):
00167         return SUCCESS
00168 
00169     def finalize(self):
00170 
00171         # Draw the ps file
00172         from ROOT import gROOT, gDirectory, TCanvas, TFile, TTree, TPad, TLatex
00173         f = TFile("comp.root", "read")
00174         t = gDirectory.Get( 't' )
00175         
00176         name = "comp-17268-EH2-OWS-RG-vs-Random"
00177         #AD = True
00178         AD = False
00179 
00180         canv = TCanvas("canv",name)
00181         # Troublesome title pad
00182         TitlePad = TPad("TitlePad","Title pad",0,0.95,1,1)
00183         TitlePad.Draw()
00184         TitlePad.SetNumber(1)
00185                 
00186         # Plots pad
00187         PlotPad  = TPad("PlotPad", "Plot pad",0,0,1,0.95)
00188         PlotPad.Draw()
00189         PlotPad.SetNumber(2)
00190 
00191         # Add title
00192         canv.cd(1)
00193         l = TLatex()
00194         l.DrawLatex(0.3,0.5,"#scale[12]{"+name+"}")
00195 
00196         # Add plots
00197         PlotPad.Divide(3,2)
00198 
00199         if AD:
00200             PlotPad.cd(1)
00201             t.Draw("Ring:Column","(Spe)*(Ring>0)","colz")
00202             PlotPad.cd(2)
00203             t.Draw("Ring:Column","(RefSpe)*(Ring>0)","colz")
00204             PlotPad.cd(3)
00205             t.Draw("Ring:Column","(Spe-RefSpe)*(Ring>0)","colz")
00206             PlotPad.cd(4)
00207             t.Draw("Spe-RefSpe","(Ring>0)")
00208 
00209             t.SetMarkerStyle(21)
00210             t.SetMarkerSize(0.5)
00211             PlotPad.cd(5)
00212             t.Draw("Spe-RefSpe:Board*16+Channel","(Ring>0)")
00213             PlotPad.cd(6)
00214             t.Draw("Spe-RefSpe:Ring*24+Column","(Ring>0)")
00215         else:
00216             PlotPad.cd(1)
00217             t.Draw("Wall:Spot+Inward*15","(Spe)","colz")
00218             PlotPad.cd(2)
00219             t.Draw("Wall:Spot+Inward*15","(RefSpe)","colz")
00220             PlotPad.cd(3)
00221             t.Draw("Wall:Spot+Inward*15","(Spe-RefSpe)","colz")
00222             PlotPad.cd(4)
00223             t.Draw("Spe-RefSpe","")
00224 
00225             t.SetMarkerStyle(21)
00226             t.SetMarkerSize(0.5)
00227             PlotPad.cd(5)
00228             t.Draw("Spe-RefSpe:Wall*30+Spot+Inward*15","")
00229             PlotPad.cd(6)
00230             t.Draw("Spe-RefSpe:Wall*30+Spot+Inward*15","")
00231 
00232 
00233         canv.SaveAs(name+".ps")
00234         
00235         status = DybPythonAlg.finalize(self)
00236         return status
00237 
00238 def run(app):
00239     compare = Compare("Compare")
00240     app.addAlgorithm( compare )
00241     return
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 09:59:50 for RollingGainAuto by doxygen 1.7.4