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

In This Package:

readCo60data.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # Usage:
00004 #  nuwa.py -n -1 --dbconf=tmp_offline_db:offline_db -m "Quickstart.Calibrate" -m "Quickstart.CalculateCalibStats" -m "getCo60ES -d 2 -r 39329" <rawdatafile>
00005 #
00006 # jpochoa, June 2013
00007 
00008 # load stuff
00009 import os,math
00010 from DybPython.DybPythonAlg import DybPythonAlg
00011 from GaudiPython import SUCCESS, FAILURE
00012 from GaudiPython import gbl
00013 
00014 from ROOT import TF1
00015 from ROOT import TObject
00016 
00017 Detector = gbl.DayaBay.Detector
00018 ServiceMode = gbl.ServiceMode
00019 DetectorId = gbl.DetectorId
00020 FeeChannelId = gbl.DayaBay.FeeChannelId
00021 AdPmtSensor = gbl.DayaBay.AdPmtSensor
00022 Context = gbl.Context 
00023 TH1F = gbl.TH1F
00024 TParameter = gbl.TParameter
00025 TH2F = gbl.TH2F
00026 Trigger = gbl.DayaBay.Trigger
00027 
00028 # Algorithm
00029 class getCo60ESAlg(DybPythonAlg):
00030     "Template Python Algorithm"
00031     def __init__(self,name):
00032         DybPythonAlg.__init__(self,name)
00033         self.det = None
00034         self.runno = None
00035         return
00036 
00037     def initialize(self):
00038         status = DybPythonAlg.initialize(self)
00039         if status.isFailure(): return status
00040         self.info("initializing")
00041         
00042         # global variables
00043         self.Nevts=0;
00044         self.prevTimeSec=0;
00045         self.prevTimeNanoSec=0;
00046         self.firstTimeSec=0;
00047         self.firstTimeNanoSec=0;
00048         self.lastTimeSec=0;
00049         self.lastTimeNanoSec=0;
00050 
00051         #  Statistics Service
00052         self.statsSvc = self.svc('IStatisticsSvc','StatisticsSvc')
00053         if self.statsSvc == None:
00054             self.error("Failed to initialize statistics service.")
00055             return FAILURE
00056         
00057         # energy histogram
00058         self.stats["/file0/Co60energy/h_e"] = TH1F("h_e","",100,0,740);
00059         self.stats["/file0/Co60energy/h_e"].GetXaxis().SetTitle("Q_{corr}^{nominal} (PEs)");
00060 
00061         self.stats["/file0/Co60energy/h_n"] = TH1F("h_n","",193,-0.5,192.5);
00062         self.stats["/file0/Co60energy/h_n"].GetXaxis().SetTitle("N_{hit}");
00063         
00064         return SUCCESS
00065 
00066     def execute(self):
00067         #self.info("executing")
00068         evt = self.evtSvc()
00069 
00070         # Access the Calib Readout Header.
00071         # This is a container for calibrated data
00072         calibHdr = evt["/Event/CalibReadout/CalibReadoutHeader"]
00073         if calibHdr == None:
00074             self.error("Failed to get current calib readout header")
00075             return FAILURE
00076         
00077         # Access the Readout.  This is the calibrated data from one trigger.
00078         calibReadout = calibHdr.calibReadout()
00079         if calibReadout == None:
00080             self.error("Failed to get calibrated readout from header")
00081             return FAILURE
00082 
00083         #  Remove events that are too close to other events in the same hall
00084         triggerTime = calibReadout.triggerTime()
00085         triggerTimeSec=triggerTime.GetSec()
00086         triggerTimeNanoSec=triggerTime.GetNanoSec()
00087 
00088         deltat=(triggerTimeSec-self.prevTimeSec)+1e-9*(triggerTimeNanoSec-self.prevTimeNanoSec)
00089         
00090         self.prevTimeSec=triggerTimeSec
00091         self.prevTimeNanoSec=triggerTimeNanoSec
00092 
00093         if deltat<200e-6:
00094             return SUCCESS;
00095 
00096         # Avoid irrelevant triggers (from other detectors and/or non-Physics)
00097         triggerType = calibReadout.triggerType();
00098         if triggerType & Trigger.kCalib != Trigger.kNone:
00099             return SUCCESS;
00100         if triggerType & Trigger.kRandom != Trigger.kNone:
00101             return SUCCESS;
00102         detId = Detector(calibHdr.context().GetSite(),calibHdr.context().GetDetId());
00103         if detId.isAD()!=1:
00104             return SUCCESS;
00105         if calibHdr.context().GetDetId()!=self.det:
00106             return SUCCESS;
00107 
00108         # Increment counter and record times
00109         self.Nevts+=1
00110         self.lastTimeSec=triggerTimeSec
00111         self.lastTimeNanoSec=triggerTimeNanoSec;
00112         if self.Nevts==1:
00113             self.firstTimeSec=triggerTimeSec;
00114             self.firstTimeNanoSec=triggerTimeNanoSec;
00115                     
00116         # Access the Calibrated Statistics Data Header.
00117         calibStats = evt["/Event/Data/CalibStats"]
00118         if calibStats == None:
00119             self.debug("No calibrated statistics!")
00120             return FAILURE
00121         
00122         # Access variables from CalibStats
00123         Qnominal = calibStats.get('NominalCharge').value()                
00124         nPMT = calibStats.get('nActivePMTs').value()
00125         nHit = calibStats.get('nHit').value()
00126         
00127         # fill histogram
00128         corrE=Qnominal*192/nPMT
00129         corrN=nHit*192/nPMT
00130         self.stats["/file0/Co60energy/h_e"].Fill(corrE);
00131         self.stats["/file0/Co60energy/h_n"].Fill(corrN);
00132         
00133         return SUCCESS
00134 
00135     def finalize(self):
00136         self.info("finalizing")
00137 
00138         # save first and last times (for normalization)
00139         print "trying to save estas ondas"
00140         self.stats["/file0/Co60energy/firstTimeSec"] = TParameter(int)("firstTimeSec",self.firstTimeSec)
00141         self.stats["/file0/Co60energy/firstTimeNanoSec"] = TParameter(int)("firstTimeNanoSec",self.firstTimeNanoSec)
00142         self.stats["/file0/Co60energy/lastTimeSec"] = TParameter(int)("lastTimeSec",self.lastTimeSec)
00143         self.stats["/file0/Co60energy/lastTimeNanoSec"] = TParameter(int)("lastTimeNanoSec",self.lastTimeNanoSec)
00144         
00145         # finalize--
00146         status = DybPythonAlg.finalize(self)
00147         return status
00148 
00149 
00150 #####  Job Configuration for nuwa.py ########################################
00151 
00152 det = None
00153 runno = None
00154 
00155 def configure( argv=[] ):
00156     """ Template job module """
00157     # Process module command line arguments here
00158     from optparse import OptionParser
00159     parser = OptionParser() 
00160 
00161     # Example module option
00162     parser.add_option("-d","--det",
00163                       default=1,
00164                       type="int",
00165                       help="DetectorId of AD with Co60 [default: %default]")
00166 
00167     parser.add_option("-r","--runno",
00168                       default=0,
00169                       type="int",
00170                       help="Run number [default: %default]")
00171     
00172     (options,args) = parser.parse_args(args=argv)
00173 
00174     # Must save option so it can be use in 'run()' function
00175     global det,runno
00176     det = options.det
00177     runno = options.runno
00178     print " Set DetectorId to ", det
00179     print " Set run to ", runno
00180     
00181     return
00182 
00183 def run(app):
00184     '''
00185     Configure and add the algorithm to job
00186     '''
00187     # Add Python algorithm to job here
00188     myAlg = getCo60ESAlg("MyCo60ESAlg")
00189     # Retrieve module option, and set in algorithm
00190     global det
00191     global runno
00192     myAlg.det = det
00193     myAlg.runno = runno
00194     app.ExtSvc += ["StatisticsSvc","DybPmtCalibSvc"]
00195     # Add algorithm to job
00196     app.addAlgorithm(myAlg)
00197     pass
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 09:55:28 for Co60Auto by doxygen 1.7.4