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

In This Package:

IBDn-sim-rootio.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 import sys, os
00004 import GaudiPython as gp
00005 from GaudiKernel import SystemOfUnits as units
00006 
00007 try:
00008     io = sys.argv[1]
00009 except IndexError:
00010     io = "output"
00011 
00012 input = False
00013 if "input" == io: 
00014     input = True
00015 output = not input
00016 use_aes = True
00017 
00018 gen_location = "/Event/Gen/GenHeader"
00019 sim_location = "/Event/Sim/SimHeader"
00020 
00021 if output:
00022     seed = sys.argv[2]
00023     nEvents = sys.argv[3]
00024     GaudiIOfile = "AD-neutron-Gaudi-"+nEvents+"evts-ws"+seed+".root"
00025     RootOutputfile = "AD-neutron-Root-"+nEvents+"evts-ws"+seed+".root"
00026     print "\tSeed of Neutron is:", seed
00027     print "\tNumber of events is:", nEvents
00028     print "\tGaudi output file is:", GaudiIOfile
00029     print "\tROOT output file is:", RootOutputfile
00030 
00031 if input:
00032     GaudiIOfile = sys.argv[2]
00033     print "\tGaudi input file is:", GaudiIOfile
00034     nEvents = sys.argv[3]
00035     print "\tTake ", nEvents, " from:", GaudiIOfile
00036     RootOutputfile = sys.argv[4]
00037     print "\tROOT output file is:", RootOutputfile
00038 
00039 if use_aes:
00040     iapp = gp.iService("ApplicationMgr")
00041     iapp.SvcMapping = [
00042         'EvtDataSvc/EventDataArchiveSvc',
00043         'DybDataSvc/EventDataSvc', 
00044         #"EvtDataSvc/EventDataSvc",
00045         "DetDataSvc/DetectorDataSvc",
00046         "HistogramSvc/HistogramDataSvc",
00047         "HbookCnv::PersSvc/HbookHistSvc",
00048         "RootHistCnv::PersSvc/RootHistSvc",
00049         "EvtPersistencySvc/EventPersistencySvc",
00050         "DetPersistencySvc/DetectorPersistencySvc",
00051         "HistogramPersistencySvc/HistogramPersistencySvc",
00052         ]
00053 
00054 if not input:
00055     import xmldetdesc
00056     print "\tBuilding detector.\n"
00057     xmldetdesc.config()
00058 
00059 app = gp.AppMgr(outputlevel=4)
00060 
00061 msg = app.service("MessageSvc")
00062 #msg.Format = "\--%-F%40W%S%7W%R%T %23W%t\n \-> %0W%M"
00063 msg.Format = "% F%25W%S%7W%R%T %0W%M"
00064 msg.useColors = False
00065 msg.fatalColorCode=['red','white']
00066 msg.errorColorCode=['red']
00067 msg.warningColorCode=['yellow']
00068 msg.debugColorCode=['blue']
00069 msg.verboseColorCode=['cyan']
00070 
00071 app.EvtMax = int(nEvents)
00072 
00073 if input:
00074     app.EvtSel =""              # yeah, I know, it's weird.
00075 else:
00076     app.EvtSel = "NONE"
00077 
00078 if input:
00079     #app.ExtSvc += [ "RootIOEvtSelector/EventSelector" ]
00080     app.ExtSvc += [ "DybEvtSelector/EventSelector" ]
00081 if output:
00082     app.ExtSvc += [ "DybStorageSvc" ]
00083     dss = app.service("DybStorageSvc")
00084     dss.OutputLevel = 4
00085     
00086 app.ExtSvc += [ "RootIOCnvSvc" ]
00087 
00088 per = app.service("EventPersistencySvc")
00089 per.CnvServices = [ "RootIOCnvSvc" ]
00090 
00091 eds = app.service("EventDataService")
00092 eds.OutputLevel = 4
00093 
00094 rio = app.property("RootIOCnvSvc")
00095 rio.OutputLevel = 4
00096 
00097 iomap = { "default": GaudiIOfile }
00098 
00099 if input:
00100     rio.InputStreams = iomap
00101 if output:
00102     rio.OutputStreams = iomap
00103 
00104 app.TopAlg = [ ]
00105 
00106 if not input:
00107     
00108     volume = "/dd/Structure/Sites/db-rock/db-ows/db-curtain/db-iws/db-ade1/db-sst1/db-oil1/db-oav1/db-lso1"
00109     
00110     # Set up timerator
00111     tim = app.property("ToolSvc.GtTimeratorTool")
00112     tim.LifeTime = int(1*units.second)
00113 
00114     # Set up positioner
00115     poser = app.property("ToolSvc.GtPositionerTool")
00116     poser.OutputLevel = 4
00117     poser.Strategy = "FullVolume"
00118     poser.Volume = volume
00119     poser.Mode = "Uniform"
00120     # poser.Mode = "Smeared"
00121     poser.Spread = 2.5*units.meter
00122     poser.Position = [0, 0, 0*units.meter]
00123 
00124     # Set up gun (Or a generator)
00125     # gun = app.property("ToolSvc.GtGunGenTool")
00126     gun = app.property("ToolSvc.GtHepEvtGenTool")
00127     # gun.Volume = volume
00128     gun.OutputLevel = 4
00129     import os
00130     path=os.getenv("PATH")
00131     for dir in path.split(":"):
00132         if os.path.exists(dir + "/InverseBeta.exe"):
00133             gun.HepEvtDataSource = dir + "/InverseBeta.exe -seed " + seed +" -neutron_only -n " + nEvents + " |"
00134             break
00135         continue
00136     # from math import sin, cos, pi
00137     # pmt_column_number = 9
00138     # angle = (2*pmt_column_number - 1)*pi/24.0
00139     # gun.Direction = [ cos(angle),sin(angle),0 ] # aim for PMT 
00140     # gun.Direction = [ 1, 0, 0 ] # aim for a PMT
00141     # gun.DirectionSpread = 3
00142     # print 'gun.Direction=',gun.Direction
00143     
00144     trans = app.property("ToolSvc.GtTransformTool")
00145     trans.Volume = volume
00146                 
00147     app.TopAlg += [ "GaudiSequencer/GenSeq" ]
00148     genseq = app.algorithm("GenSeq")
00149     genseq.Members = [ "GtGenerator/GenAlg", "GtHepMCDumper/GenDump" ]
00150 
00151     # set up gentools
00152     gen = app.algorithm("GenAlg")
00153     gen.OutputLevel = 4
00154     gen.GenTools = [ "GtHepEvtGenTool", "GtPositionerTool", 
00155                      "GtTimeratorTool", "GtTransformTool" ]
00156     gen.GenName = "IBD neutron"
00157     # gen.Location = "/Event/Gen/GenHeader" # this is default anyways
00158 
00159     # print " GtDumper"
00160     gendump = app.algorithm("GenDump")
00161     # gendump.Location = "/Event/Gen/GenHeader"  # this is default anyways.
00162 
00163     app.ExtSvc += ["GiGa"]
00164 
00165     modularPL = app.property("GiGa.GiGaPhysListModular")
00166     modularPL.OutputLevel = 4
00167     modularPL.CutForElectron = 100*units.micrometer
00168     modularPL.CutForPositron = 100*units.micrometer
00169     modularPL.CutForGamma = 1*units.millimeter
00170     modularPL.PhysicsConstructors = [ 
00171         "DsPhysConsGeneral",
00172         "DsPhysConsOptical",
00173         "DsPhysConsEM",
00174         "DsPhysConsElectroNu",
00175         "DsPhysConsHadron",
00176         "DsPhysConsIon"
00177         ]
00178     
00179     # in DsPhysConsOptical.cc these properties are declared.
00180     optical = app.property("GiGa.GiGaPhysListModular.DsPhysConsOptical")
00181     
00182     # optical.UseScintillation = False  
00183     # false option will kill all optical photons, should be true all the time
00184     
00185     # optical.UseRayleigh = True       # enable rayleigh scattering
00186     
00187     optical.CerenPhotonScaleWeight=4.0  
00188     # scale photon yield down and scale QE up
00189     
00190     optical.ScintPhotonScaleWeight=4.0
00191     
00192     gggeo = app.service("GiGaGeo")
00193     gggeo.OutputLevel = 4
00194     gggeo.XsizeOfWorldVolume = 2.4*units.kilometer
00195     gggeo.YsizeOfWorldVolume = 2.4*units.kilometer
00196     gggeo.ZsizeOfWorldVolume = 2.4*units.kilometer
00197 
00198     giga = app.service("GiGa")
00199     giga.OutputLevel = 4
00200     giga.PhysicsList = "GiGaPhysListModular"
00201 
00202     giga.SteppingAction = "GiGaStepActionSequence"
00203     stepseq = app.property("GiGa.GiGaStepActionSequence")
00204     stepseq.OutputLevel = 4
00205     stepseq.Members = ["HistorianStepAction","UnObserverStepAction"]
00206     
00207     TH2DE="TH2DE"       # TH2DE is the fastest
00208     # TH2DE="TouchableToDetectorElementFast"
00209     historian = app.property("GiGa.GiGaStepActionSequence.HistorianStepAction")
00210     historian.TouchableToDetelem = TH2DE
00211     historian.TrackSelection = "(pdg == 2112)"
00212     # historian.TrackSelection = "any"
00213     historian.VertexSelection = "(pdg == 2112)"
00214     # historian.VertexSelection = "any"
00215 
00216     params = {
00217         'start' :"(start > 0)", # Same as 'firstvtx'
00218         'track1':"(id==1)",
00219         'track2':"(id==2)",
00220         'GD':    "MaterialName == '/dd/Materials/GdDopedLS'",
00221         'LS':    "MaterialName == '/dd/Materials/LiquidScintillator'",
00222         'MO':   "MaterialName == '/dd/Materials/MineralOil'",
00223         'IAV':   "DetectorElementName == 'db-iav1'",
00224         'OAV':   "DetectorElementName == 'db-oav1'",
00225         'IWS': "MaterialName == '/dd/Materials/IwsWater'",
00226         'OWS': "MaterialName == '/dd/Materials/OwsWater'",
00227         'lastvtx': "IsStopping == 1",
00228         'firstvtx': "IsStarting == 1",
00229         'NeutronTrk': "pdg == 2112",
00230         'NeutronMom': "creator == 2112",
00231         'Gamma': "pdg == 22",
00232         'Muon': "(pdg == 13 or pdg == -13)"
00233         }
00234     
00235     unobs = app.property("GiGa.GiGaStepActionSequence.UnObserverStepAction")
00236     unobs.TouchableToDetelem = TH2DE
00237     
00238     unobs.Stats=[
00239         
00240         ["MuonTrkLengthInOws", "dx", "%(Muon)s and %(OWS)s"%params],
00241         ["MuonTrkLengthInIws", "dx", "%(Muon)s and %(IWS)s"%params],
00242         ["MuonTrkLengthInLS", "dx", "%(Muon)s and %(LS)s"%params],
00243         ["MuonTrkLengthInGdLS","dx", "%(Muon)s and %(GD)s"%params],
00244         ["dEInn","dE", "(pdg!=20022) and %(IWS)s"%params],
00245         ["dEOut","dE", "(pdg!=20022) and %(OWS)s"%params],
00246         ["MuonStop", "dx",  "%(Muon)s and %(lastvtx)s"%params],
00247         
00248         ["EDepInGdLS", "dE", "%(GD)s"%params],
00249         ["EDepInLS", "dE", "%(LS)s"%params],
00250         ["EDepInIAV", "dE", "%(IAV)s"%params],
00251         ["EDepInOAV", "dE", "%(OAV)s"%params],
00252         ["EDepInOIL", "dE", "%(MO)s"%params],
00253 
00254         ["QEDepInGdLS", "qdE", "%(GD)s"%params],
00255         ["QEDepInLS", "qdE", "%(LS)s"%params],
00256         ["QEDepInIAV", "qdE", "%(IAV)s"%params],
00257         ["QEDepInOAV", "qdE", "%(OAV)s"%params],
00258         ["QEDepInOIL", "qdE", "%(MO)s"%params],
00259 
00260         ["tQESumGdLS", "qEt", "%(GD)s"%params],
00261         ["xQESumGdLS", "qEx", "%(GD)s"%params],
00262         ["yQESumGdLS", "qEy", "%(GD)s"%params],
00263         ["zQESumGdLS", "qEz", "%(GD)s"%params],
00264 
00265         ["tQESumLS", "qEt", "%(LS)s"%params],
00266         ["xQESumLS", "qEx", "%(LS)s"%params],
00267         ["yQESumLS", "qEy", "%(LS)s"%params],
00268         ["zQESumLS", "qEz", "%(LS)s"%params],
00269 
00270         ["tQESumMO", "qEt", "%(MO)s"%params],
00271         ["xQESumMO", "qEx", "%(MO)s"%params],
00272         ["yQESumMO", "qEy", "%(MO)s"%params],
00273         ["zQESumMO", "qEz", "%(MO)s"%params],
00274 
00275         ["tGen",   "t","%(NeutronTrk)s and %(firstvtx)s"%params],
00276         ["xGen",   "x","%(NeutronTrk)s and %(firstvtx)s"%params],
00277         ["yGen",   "y","%(NeutronTrk)s and %(firstvtx)s"%params],
00278         ["zGen",   "z","%(NeutronTrk)s and %(firstvtx)s"%params],
00279 
00280         ["tCap",   "t","%(NeutronTrk)s and %(lastvtx)s"%params],
00281         ["xCap",   "x","%(NeutronTrk)s and %(lastvtx)s"%params],
00282         ["yCap",   "y","%(NeutronTrk)s and %(lastvtx)s"%params],
00283         ["zCap",   "z","%(NeutronTrk)s and %(lastvtx)s"%params],
00284 
00285         ["capTarget", "capTargetZ","%(track1)s and %(lastvtx)s"%params],
00286         
00287         # track 1
00288         ["pdgId_Trk1","pdg","%(track1)s and %(start)s"%params],
00289         ["t_Trk1",    "t" , "%(track1)s and %(start)s"%params],
00290         ["x_Trk1",    "x", "%(track1)s and %(start)s"%params],
00291         ["y_Trk1",    "y", "%(track1)s and %(start)s"%params],
00292         ["z_Trk1",    "z", "%(track1)s and %(start)s"%params],
00293         ["tEnd_Trk1",    "t" , "%(track1)s and %(lastvtx)s"%params],
00294         ["xEnd_Trk1",    "x", "%(track1)s and %(lastvtx)s"%params],
00295         ["yEnd_Trk1",    "y", "%(track1)s and %(lastvtx)s"%params],
00296         ["zEnd_Trk1",    "z", "%(track1)s and %(lastvtx)s"%params],
00297         ["e_Trk1",    "E",  "%(track1)s and %(start)s"%params],
00298         ["p_Trk1",    "p",  "%(track1)s and %(start)s"%params],
00299         ["ke_Trk1",   "KE", "%(track1)s and %(start)s"%params],
00300         ["vx_Trk1",   "lvx","%(track1)s and %(start)s"%params],
00301         ["vy_Trk1",   "lvy","%(track1)s and %(start)s"%params],
00302         ["vz_Trk1",   "lvz","%(track1)s and %(start)s"%params],
00303         ["TrkLength_GD_Trk1",  "dx","%(track1)s and %(GD)s"%params],
00304         ["TrkLength_iAV_Trk1", "dx","%(track1)s and %(IAV)s"%params],
00305         ["TrkLength_LS_Trk1",  "dx","%(track1)s and %(LS)s"%params],
00306         ["TrkLength_oAV_Trk1", "dx","%(track1)s and %(OAV)s"%params],
00307         ["TrkLength_Oil_Trk1", "dx","%(track1)s and %(MO)s"%params],
00308         # track 2
00309         ["pdgId_Trk2","pdg","%(track2)s and %(start)s"%params],
00310         ["t_Trk2",    "t" , "%(track2)s and %(start)s"%params],
00311         ["x_Trk2",    "x", "%(track2)s and %(start)s"%params],
00312         ["y_Trk2",    "y", "%(track2)s and %(start)s"%params],
00313         ["z_Trk2",    "z", "%(track2)s and %(start)s"%params],
00314         ["tEnd_Trk2",    "t" , "%(track2)s and %(lastvtx)s"%params],
00315         ["xEnd_Trk2",    "x", "%(track2)s and %(lastvtx)s"%params],
00316         ["yEnd_Trk2",    "y", "%(track2)s and %(lastvtx)s"%params],
00317         ["zEnd_Trk2",    "z", "%(track2)s and %(lastvtx)s"%params],
00318         ["e_Trk2",    "E",  "%(track2)s and %(start)s"%params],
00319         ["p_Trk2",    "p",  "%(track2)s and %(start)s"%params],
00320         ["ke_Trk2",   "KE", "%(track2)s and %(start)s"%params],
00321         ["vx_Trk2",   "lvx","%(track2)s and %(start)s"%params],
00322         ["vy_Trk2",   "lvy","%(track2)s and %(start)s"%params],
00323         ["vz_Trk2",   "lvz","%(track2)s and %(start)s"%params],
00324         ["TrkLength_GD_Trk2",  "dx","%(track2)s and %(GD)s"%params],
00325         ["TrkLength_iAV_Trk2", "dx","%(track2)s and %(IAV)s"%params],
00326         ["TrkLength_LS_Trk2",  "dx","%(track2)s and %(LS)s"%params],
00327         ["TrkLength_oAV_Trk2", "dx","%(track2)s and %(OAV)s"%params],
00328         ["TrkLength_Oil_Trk2", "dx","%(track2)s and %(MO)s"%params]
00329         ]
00330 
00331     # Make Geant4 sing!
00332     ggrm = app.property("GiGa.GiGaMgr")
00333     ggrm.Verbosity = 0
00334     event_ac_cmds = app.property("GiGa.GiGaEventActionCommand")
00335     verbosity_cmds = [
00336         "/control/verbose 0",
00337         "/run/verbose 0",
00338         "/event/verbose 2",
00339         "/tracking/verbose 2",
00340         "/geometry/navigator/verbose 0"
00341         ]
00342     silent_cmds = [
00343         "/control/verbose 0",
00344         "/run/verbose 0",
00345         "/event/verbose 0",
00346         "/tracking/verbose 0",
00347         "/geometry/navigator/verbose 0"
00348         ]
00349     
00350     event_ac_cmds.BeginOfEventCommands = silent_cmds
00351     giga.EventAction = "GiGaEventActionCommand"
00352 
00353     app.TopAlg += [ "GaudiSequencer/GenSeq" ]
00354     app.TopAlg += [ "GaudiSequencer/SimSeq" ]
00355     simseq = app.algorithm("SimSeq")
00356     simseq.Members = [ "GiGaInputStream/GGInStream" ]
00357     
00358     ggin = app.algorithm("GGInStream")
00359     ggin.OutputLevel = 4
00360     ggin.ExecuteOnce = True
00361     ggin.ConversionSvcName = "GiGaGeo"
00362     ggin.DataProviderSvcName = "DetectorDataSvc"
00363     ggin.StreamItems = [ "/dd/Structure/Sites/db-rock",
00364                          "/dd/Geometry/AdDetails/AdSurfacesAll",
00365                          "/dd/Geometry/AdDetails/AdSurfacesNear"
00366                          ]
00367     
00368     simseq.Members = [ "GiGaInputStream/GGInStream", "DsPushKine/PushKine", 
00369                        "DsPullEvent/PullEvent" 
00370                        ]
00371     
00372     pull = app.algorithm("PullEvent")
00373     pull.OutputLevel = 4 
00374     push = app.algorithm("PushKine")
00375     push.Converter = "HepMCtoG4"
00376     # push.Location = "/Event/Gen/GenHeader" # default anyway
00377     
00378     # Class name to use is set in DetDesc xml's "sensdet" attribute.
00379     pmtsd = app.property("GiGaGeo.DsPmtSensDet")
00380     pmtsd.OutputLevel = 4
00381 
00382     app.TopAlg += [ 'DetSimVali/dsv' ]
00383     dsv = app.algorithm("dsv")
00384     dsv.Volume = volume
00385     dsv.OutputLevel = 4
00386     histsvc = app.service("THistSvc")
00387     histsvc.Output =["file1 DATAFILE='../mc_ntuple/"+RootOutputfile+"' OPT='RECREATE' TYP='ROOT' "]
00388 
00389     pass
00390 
00391 
00392 if input:
00393     rioes = app.service("RootIOEvtSelector")
00394     rioes.OutputLevel = 4
00395     app.TopAlg += [ 'DetSimVali/dsv' ]
00396     dsv = app.algorithm("dsv")
00397     dsv.Volume = volume
00398     dsv.OutputLevel = 4
00399     histsvc = app.service("THistSvc")
00400     histsvc.Output =["file1 DATAFILE='../mc_ntuple/"+RootOutputfile+"' OPT='RECREATE' TYP='ROOT' "]
00401     
00402 if output:
00403     app.TopAlg += [ 'DybStoreAlg/dsa' ]
00404     dsa = app.algorithm("dsa")
00405     dsa.OutputLevel = 1
00406     dybstrgsvs = app.service("DybStoreSvc")
00407 
00408 # Run...
00409 app.initialize()
00410 app.run(app.EvtMax)
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:56:26 2011 for DetSimValidation by doxygen 1.4.7