00001
00002 '''
00003 Mix the geant4-pre-simulated events, and do the following full dayabay nearsite simulation
00004
00005 usage:
00006 nuwa.py --history off -n50 -o fifteen.root -m "Sandglass" > log
00007
00008 More examples:
00009 nuwa.py -R 1 -n2000000 -o DYB_hour1.root -m "Sandglass -w 2011-02-03T00:00:00" > log
00010
00011 Nov. 26, 2010 Created by Zhe Wang
00012
00013 **********************
00014
00015 (1) Updated the mixing rates using ZHAN Liang's recommendations in DOCDB#5962
00016 (2) For FMCP11a: -f should run from 0 to 4999.
00017 (3) Increase AD multiplicity trigger threshold to > 30
00018 Mar. 29, 2011 Modified by C.-J. Lin
00019
00020 '''
00021
00022 import GaudiKernel.SystemOfUnits as units
00023 from LoadingProc.Assembler import Assembler
00024
00025 class ConfigureSandglass:
00026
00027 '''
00028 Configure a testing ground for LoadingProc to mix SimHeader and ReadoutHeader input.
00029 '''
00030
00031 def __init__(self,argv):
00032 self.parse_args(argv)
00033 return
00034
00035 def parse_args(self,argv):
00036 from optparse import OptionParser
00037 import time
00038 parser = OptionParser(usage=self.__doc__)
00039 default_time_format = '%Y-%m-%dT%H:%M:%S'
00040 parser.add_option("-w","--start-time",
00041 help="Date string to set simulation start, assumed UTC",
00042 default=time.strftime(default_time_format,time.localtime()))
00043 parser.add_option("-F","--time-format",
00044 help="Format for parsing time (see man date), " \
00045 + "default is '%s'"%default_time_format \
00046 + " ('[YYYY]-[MM]-[DD]T[HH]:[MM]:[SS]')",
00047 default=default_time_format)
00048 parser.add_option("-g","--generator",
00049 help="A python module with a function of GetGnrtr returning a Gnrtr object.",
00050 default="1223")
00051 parser.add_option("-T","--top-stage",
00052 help="Kinematic, Detector, Electronic, TrigRead or SingleLoader",
00053 default="SingleLoader")
00054 parser.add_option("-s","--seed",
00055 help="Random seed for generators",
00056 default=1234567)
00057 parser.add_option("-f","--frac",
00058 help="Starting position of input streams",
00059 default=0.0)
00060
00061 (options,args) = parser.parse_args(args=argv)
00062 self.opts = options
00063 self.args = args
00064
00065
00066 timeformat = self.opts.time_format
00067 print "Using time format =",timeformat
00068
00069 try:
00070 datestring = self.opts.start_time
00071 except AttributeError:
00072 self.start_time_seconds = 0
00073 else:
00074
00075
00076 t = time.strptime(datestring,timeformat)
00077 self.start_time_seconds = time.mktime(t) - time.timezone
00078 print 'Start time in human readable format',self.opts.start_time
00079 print 'Start time in seconds UTC =',self.start_time_seconds
00080 print 'Top stage =',self.opts.top_stage
00081
00082 return
00083
00084
00085 def load(self,
00086 datapath = "data/",
00087 filename = "IBD_DYB_AD1_acrylic.root",
00088 rate = 1.0,
00089 MyMode = "random",
00090 MyStart = 0,
00091 MyStep = 1):
00092
00093 extension = filename[-5:]
00094 modulename = filename[:-5]
00095 if extension != ".list" and extension != ".root":
00096 print "Invalid input data file ", filename
00097
00098 from LoadingProc.LoadingProcConf import LoadingProc
00099 load = LoadingProc("LoadingProc."+modulename)
00100 load.StartSec = self.start_time_seconds
00101 load.StartNano = 0
00102 load.Distribution = "Exponential"
00103 load.Rate = rate
00104 load.HsAssembler = modulename+"Assem"
00105
00106 assem = Assembler(toolname = modulename+"Assem",
00107 filename = datapath+filename,
00108 mode = MyMode,
00109 start = MyStart,
00110 step = MyStep)
00111
00112
00113 load.ThisStageName = "Detector"
00114 load.LowerStageName = ""
00115
00116 self.stage_cfg.DetectorSequence.Members.append(load)
00117
00118 def configureLoadingProc(self):
00119
00120 frac = int(self.opts.frac)
00121 '''Configure the LoadingProc stage'''
00122
00123 self.load( datapath = "data/", filename = "IBD_DayaBayAD1.list", rate = 4334.0/(24.*60.*60.) , MyMode = "random")
00124 self.load( datapath = "data/", filename = "IBD_DayaBayAD2.list", rate = 4334.0/(24.*60.*60.) , MyMode = "random")
00125
00126 self.load( datapath = "data/", filename = "U238-gds_DayaBayAD1.list", rate = 3.2 , MyMode = "sequential", MyStart=40*frac)
00127 self.load( datapath = "data/", filename = "U238-lso_DayaBayAD1.list", rate = 3.4 , MyMode = "sequential", MyStart=50*frac)
00128 self.load( datapath = "data/", filename = "U238-PMT_DayaBayAD1.list", rate = 3978.0 , MyMode = "sequential", MyStart=17000*frac)
00129 self.load( datapath = "data/", filename = "U238-sst_DayaBayAD1.list", rate = 376.0 , MyMode = "sequential", MyStart=1600*frac)
00130 self.load( datapath = "data/", filename = "U238-gds_DayaBayAD2.list", rate = 3.2 , MyMode = "sequential", MyStart=40*frac)
00131 self.load( datapath = "data/", filename = "U238-lso_DayaBayAD2.list", rate = 3.4 , MyMode = "sequential", MyStart=50*frac)
00132 self.load( datapath = "data/", filename = "U238-PMT_DayaBayAD2.list", rate = 3978.0 , MyMode = "sequential", MyStart=17000*frac)
00133 self.load( datapath = "data/", filename = "U238-sst_DayaBayAD2.list", rate = 376.0 , MyMode = "sequential", MyStart=1600*frac)
00134
00135 self.load( datapath = "data/", filename = "Th232-gds_DayaBayAD1.list",rate = 0.76 , MyMode = "sequential", MyStart=10*frac)
00136 self.load( datapath = "data/", filename = "Th232-lso_DayaBayAD1.list",rate = 0.81 , MyMode = "sequential", MyStart=11*frac)
00137 self.load( datapath = "data/", filename = "Th232-PMT_DayaBayAD1.list",rate = 2018.0 , MyMode = "sequential", MyStart=8800*frac)
00138 self.load( datapath = "data/", filename = "Th232-sst_DayaBayAD1.list",rate = 1332.0 , MyMode = "sequential", MyStart=6000*frac)
00139 self.load( datapath = "data/", filename = "Th232-gds_DayaBayAD2.list",rate = 0.76 , MyMode = "sequential", MyStart=10*frac)
00140 self.load( datapath = "data/", filename = "Th232-lso_DayaBayAD2.list",rate = 0.81 , MyMode = "sequential", MyStart=11*frac)
00141 self.load( datapath = "data/", filename = "Th232-PMT_DayaBayAD2.list",rate = 2018.0 , MyMode = "sequential", MyStart=8800*frac)
00142 self.load( datapath = "data/", filename = "Th232-sst_DayaBayAD2.list",rate = 1332.0 , MyMode = "sequential", MyStart=6000*frac)
00143
00144 self.load( datapath = "data/", filename = "K40-gds_DayaBayAD1.list", rate = 5.2 , MyMode = "sequential", MyStart=70*frac)
00145 self.load( datapath = "data/", filename = "K40-lso_DayaBayAD1.list", rate = 5.6 , MyMode = "sequential", MyStart=80*frac)
00146 self.load( datapath = "data/", filename = "K40-PMT_DayaBayAD1.list", rate = 817.0 , MyMode = "sequential", MyStart=3600*frac)
00147 self.load( datapath = "data/", filename = "K40-sst_DayaBayAD1.list", rate = 311.0 , MyMode = "sequential", MyStart=1400*frac)
00148 self.load( datapath = "data/", filename = "K40-gds_DayaBayAD2.list", rate = 5.2 , MyMode = "sequential", MyStart=70*frac)
00149 self.load( datapath = "data/", filename = "K40-lso_DayaBayAD2.list", rate = 5.6 , MyMode = "sequential", MyStart=80*frac)
00150 self.load( datapath = "data/", filename = "K40-PMT_DayaBayAD2.list", rate = 817.0 , MyMode = "sequential", MyStart=3600*frac)
00151 self.load( datapath = "data/", filename = "K40-sst_DayaBayAD2.list", rate = 311.0 , MyMode = "sequential", MyStart=1400*frac)
00152
00153 self.load( datapath = "data/", filename = "Co60-PMT_DayaBayAD1.list", rate = 1.46 , MyMode = "sequential", MyStart=10*frac)
00154 self.load( datapath = "data/", filename = "Co60-sst_DayaBayAD1.list", rate = 48.0 , MyMode = "sequential", MyStart=600*frac)
00155 self.load( datapath = "data/", filename = "Co60-PMT_DayaBayAD2.list", rate = 1.46 , MyMode = "sequential", MyStart=10*frac)
00156 self.load( datapath = "data/", filename = "Co60-sst_DayaBayAD2.list", rate = 48.0 , MyMode = "sequential", MyStart=600*frac)
00157
00158 self.load( datapath = "data/", filename = "Muon.list", rate = 523.0, MyMode = "sequential", MyStart=150000*frac)
00159
00160
00161
00162 def configureElectronic(self):
00163 '''Configure the Electronics stage'''
00164
00165 import ElecSim
00166 es = ElecSim.Configure(use_push_algs = False)
00167
00168
00169
00170
00171 from ElecSimProc.ElecSimProcConf import ElecSimProc
00172 esp = ElecSimProc()
00173 esp.PmtTool = "EsPmtEffectPulseTool"
00174 esp.RpcTool = "EsIdealPulseTool"
00175 esp.FeeTool = "EsIdealFeeTool"
00176 esp.FecTool = "EsIdealFecTool"
00177 esp.Detectors = ["DayaBayAD1","DayaBayAD2","DayaBayIWS","DayaBayOWS"]
00178
00179 from ElecSim.ElecSimConf import EsIdealFeeTool
00180 feeTool = EsIdealFeeTool()
00181 feeTool.LinearityThreshold = 20000
00182 feeTool.EnableESumH = False
00183 feeTool.EnableESumL = False
00184 feeTool.EnableESumTotal = False
00185
00186 esp.ThisStageName = "Electronic"
00187 esp.LowerStageName = "Detector"
00188
00189 self.stage_cfg.ElectronicSequence.Members.append(esp)
00190 return
00191
00192 def configureTrigRead(self):
00193 '''Configure the Trigger and Readout stage'''
00194 from TrigReadProc.TrigReadProcConf import TrigReadProc
00195 tsp = TrigReadProc()
00196
00197
00198
00199 from TrigSim.TrigSimConf import TsMultTriggerTool
00200 nhit = TsMultTriggerTool()
00201 nhit.NHitTriggerThreshold={"DayaBayAD1":30,
00202 "DayaBayAD2":30,
00203 "DayaBayIWS":10,
00204 "DayaBayOWS":10,
00205 "LingAoAD1":30,
00206 "LingAoAD2":30,
00207 "LingAoIWS":10,
00208 "LingAoOWS":10,
00209 "FarAD1":30,
00210 "FarAD2":30,
00211 "FarAD3":30,
00212 "FarAD4":30,
00213 "FarIWS":10,
00214 "FarOWS":10}
00215
00216 tsp.ThisStageName = "TrigRead"
00217 tsp.LowerStageName = "Electronic"
00218
00219 self.stage_cfg.TrigReadSequence.Members.append(tsp)
00220 return
00221
00222 def configureSingleLoader(self):
00223 '''Configure the SingleLoader stage'''
00224 from SingleLoader.SingleLoaderConf import SingleLoader
00225 sll = SingleLoader()
00226 sll.ThisStageName = "SingleLoader"
00227 sll.LowerStageName = "TrigRead"
00228
00229 self.stage_cfg.SingleLoaderSequence.Members.append(sll)
00230
00231 def configureSim15(self):
00232 from Stage.StageConf import Sim15
00233 sim15=Sim15()
00234 sim15.TopStage = self.opts.top_stage
00235
00236
00237 from DybEventMgr.DybEventMgrConf import ArchiveTrimSvc
00238 trimSvc = ArchiveTrimSvc()
00239 trimSvc.DefaultWindowSeconds = 0
00240
00241
00242 from Gaudi.Configuration import ApplicationMgr
00243 theApp = ApplicationMgr()
00244 theApp.TopAlg.append(sim15)
00245
00246 def configure(self):
00247 from Stage import Configure as StageConfigure
00248 self.stage_cfg = StageConfigure()
00249
00250 stagedic={'Detector':2,'Electronic':3,'TrigRead':4,'SingleLoader':5}
00251
00252 if not self.opts.top_stage in stagedic:
00253 print 'Error, wrong top stage parameter', self.opts.top_stage
00254 print 'Valid stage is Detector, Electronic, TrigRead or SingleLoader'
00255
00256 for stg,idx in stagedic.iteritems():
00257 if idx <= stagedic[self.opts.top_stage]:
00258 self.stage_cfg.addStages([stg])
00259
00260 for stg in self.stage_cfg.stages:
00261
00262 pass
00263
00264 if stagedic[self.opts.top_stage]>=2:
00265 self.configureLoadingProc()
00266 if stagedic[self.opts.top_stage]>=3:
00267 self.configureElectronic()
00268 if stagedic[self.opts.top_stage]>=4:
00269 self.configureTrigRead()
00270 if stagedic[self.opts.top_stage]>=5:
00271 self.configureSingleLoader()
00272
00273 self.configureSim15()
00274
00275 return
00276
00277 def configure(argv=[]):
00278 cfc = ConfigureSandglass(argv)
00279 cfc.configure()
00280 return
00281
00282 if __name__ == "__main__":
00283 configure()
00284 pass