fStack = ROOT.gMC.GetStack() if not deepCopy : fStack.SetEnergyCut(100.*u.MeV) if eventDisplay: # Set cuts for storing the trajectories, can only be done after initialization of run (?!) trajFilter = ROOT.FairTrajFilter.Instance() trajFilter.SetStepSizeCut(1*u.mm); trajFilter.SetVertexCut(-20*u.m, -20*u.m,ship_geo.target.z0-1*u.m, 20*u.m, 20*u.m, 200.*u.m) trajFilter.SetMomentumCutP(0.1*u.GeV) trajFilter.SetEnergyCut(0., 400.*u.GeV) trajFilter.SetStorePrimaries(ROOT.kTRUE) trajFilter.SetStoreSecondaries(ROOT.kTRUE) # manipulate G4 geometry to enable magnetic field in active shielding, VMC can't do it. if ship_geo.muShieldDesign != 1: import geomGeant4 geomGeant4.setMagnetField() # ('dump') for printout of mag fields if debug > 0: geomGeant4.printWeightsandFields() if inactivateMuonProcesses : mygMC = ROOT.TGeant4.GetMC() mygMC.ProcessGeantCommand("/process/inactivate muPairProd") mygMC.ProcessGeantCommand("/process/inactivate muBrems") mygMC.ProcessGeantCommand("/process/inactivate muIoni") mygMC.ProcessGeantCommand("/particle/select mu+") mygMC.ProcessGeantCommand("/particle/process/dump") import G4processes gProcessTable = G4processes.G4ProcessTable.GetProcessTable() procmu = gProcessTable.FindProcess('muIoni','mu+') procmu.SetVerboseLevel(2) # -----Start run---------------------------------------------------- run.Run(nEvents) # -----Runtime database---------------------------------------------
if eventDisplay: # Set cuts for storing the trajectories, can only be done after initialization of run (?!) trajFilter = ROOT.FairTrajFilter.Instance() trajFilter.SetStepSizeCut(1 * u.mm) trajFilter.SetVertexCut(-20 * u.m, -20 * u.m, ship_geo.target.z0 - 1 * u.m, 20 * u.m, 20 * u.m, 200. * u.m) trajFilter.SetMomentumCutP(0.1 * u.GeV) trajFilter.SetEnergyCut(0., 400. * u.GeV) trajFilter.SetStorePrimaries(ROOT.kTRUE) trajFilter.SetStoreSecondaries(ROOT.kTRUE) # manipulate G4 geometry to enable magnetic field in active shielding, VMC can't do it. if hasattr(ship_geo, "muShieldDesign"): if ship_geo.muShieldDesign != 1: import geomGeant4 geomGeant4.setMagnetField() # ('dump') for printout of mag fields if debug > 0: geomGeant4.printWeightsandFields() if inactivateMuonProcesses: mygMC = ROOT.TGeant4.GetMC() mygMC.ProcessGeantCommand("/process/inactivate muPairProd") mygMC.ProcessGeantCommand("/process/inactivate muBrems") mygMC.ProcessGeantCommand("/process/inactivate muIoni") mygMC.ProcessGeantCommand("/particle/select mu+") mygMC.ProcessGeantCommand("/particle/process/dump") import G4processes gProcessTable = G4processes.G4ProcessTable.GetProcessTable() procmu = gProcessTable.FindProcess('muIoni', 'mu+') procmu.SetVerboseLevel(2) # -----Start run---------------------------------------------------- run.Run(nEvents) # -----Runtime database---------------------------------------------
def generate(inputFile, geoFile, nEvents, outFile, lofi=False): """Generate muon background and transport it through the geometry. Parameters ---------- inputFile : str File with muon ntuple geoFile : str File with the muon shield parameters (not with the geometry config!) nEvents : int Number of events to read from inputFile outFile : str File in which `cbmsim` tree is saved lofi : bool, optional Determine fidelity. If True all non-essential Geant4 processes will be deactivated """ firstEvent = 0 dy = 10. vessel_design = 5 shield_design = 8 mcEngine = 'TGeant4' sameSeed = 1 theSeed = 1 # provisionally for making studies of various muon background sources inactivateMuonProcesses = lofi phiRandom = False # only relevant for muon background generator followMuon = True # only transport muons for a fast muon only background print 'FairShip setup to produce', nEvents, 'events' r.gRandom.SetSeed(theSeed) ship_geo = ConfigRegistry.loadpy('$FAIRSHIP/geometry/geometry_config.py', Yheight=dy, tankDesign=vessel_design, muShieldDesign=shield_design, muShieldGeo=geoFile) run = r.FairRunSim() run.SetName(mcEngine) # Transport engine run.SetOutputFile(outFile) # Output file # user configuration file default g4Config.C run.SetUserConfig('g4Config.C') modules = shipDet_conf.configure(run, ship_geo) primGen = r.FairPrimaryGenerator() primGen.SetTarget(ship_geo.target.z0 + 50 * u.m, 0.) MuonBackgen = r.MuonBackGenerator() MuonBackgen.Init(inputFile, firstEvent, phiRandom) MuonBackgen.SetSmearBeam(3 * u.cm) # beam size mimicking spiral if sameSeed: MuonBackgen.SetSameSeed(sameSeed) primGen.AddGenerator(MuonBackgen) nEvents = min(nEvents, MuonBackgen.GetNevents()) print 'Process ', nEvents, ' from input file, with Phi random=', phiRandom if followMuon: modules['Veto'].SetFastMuon() run.SetGenerator(primGen) run.SetStoreTraj(r.kFALSE) run.Init() geomGeant4.setMagnetField() if inactivateMuonProcesses: mygMC = r.TGeant4.GetMC() mygMC.ProcessGeantCommand('/process/inactivate muPairProd') mygMC.ProcessGeantCommand('/process/inactivate muBrems') mygMC.ProcessGeantCommand('/process/inactivate muIoni') mygMC.ProcessGeantCommand('/process/inactivate msc') mygMC.ProcessGeantCommand('/process/inactivate Decay') mygMC.ProcessGeantCommand('/process/inactivate CoulombScat') mygMC.ProcessGeantCommand('/process/inactivate muonNuclear') mygMC.ProcessGeantCommand('/process/inactivate StepLimiter') mygMC.ProcessGeantCommand('/process/inactivate specialCutForMuon') run.Run(nEvents) print 'Macro finished succesfully.'
run.Init() fStack = ROOT.gMC.GetStack() if not deepCopy : fStack.SetEnergyCut(100.*u.MeV) if eventDisplay: # Set cuts for storing the trajectories, can only be done after initialization of run (?!) trajFilter = ROOT.FairTrajFilter.Instance() trajFilter.SetStepSizeCut(10*u.cm); trajFilter.SetVertexCut(-20*u.m, -20*u.m,ship_geo.target.z0-1*u.m, 20*u.m, 20*u.m, 100.*u.m) trajFilter.SetMomentumCutP(0.1*u.GeV) trajFilter.SetEnergyCut(0., 400.*u.GeV) trajFilter.SetStorePrimaries(ROOT.kTRUE) trajFilter.SetStoreSecondaries(ROOT.kTRUE) # manipulate G4 geometry to enable magnetic field in active shielding, VMC can't do it. if ship_geo.muShieldDesign != 1: import geomGeant4 geomGeant4.setMagnetField() geomGeant4.printWeightsandFields() if inactivateMuonProcesses : mygMC = ROOT.TGeant4.GetMC() mygMC.ProcessGeantCommand("/process/inactivate muPairProd") mygMC.ProcessGeantCommand("/process/inactivate muBrems") mygMC.ProcessGeantCommand("/process/inactivate muIoni") mygMC.ProcessGeantCommand("/particle/select mu+") mygMC.ProcessGeantCommand("/particle/process/dump") import G4processes gProcessTable = G4processes.G4ProcessTable.GetProcessTable() procmu = gProcessTable.FindProcess('muIoni','mu+') procmu.SetVerboseLevel(2) # -----Start run---------------------------------------------------- run.Run(nEvents)
run.Init() fStack = ROOT.gMC.GetStack() if not deepCopy : fStack.SetEnergyCut(100.*u.MeV) if eventDisplay: # Set cuts for storing the trajectories, can only be done after initialization of run (?!) trajFilter = ROOT.FairTrajFilter.Instance() trajFilter.SetStepSizeCut(10*u.cm); trajFilter.SetVertexCut(-20*u.m, -20*u.m,ship_geo.target.z0-1*u.m, 20*u.m, 20*u.m, 100.*u.m) trajFilter.SetMomentumCutP(0.5*u.GeV) trajFilter.SetEnergyCut(0., 400.*u.GeV) trajFilter.SetStorePrimaries(ROOT.kTRUE) trajFilter.SetStoreSecondaries(ROOT.kTRUE) # manipulate G4 geometry to enable magnetic field in active shielding, VMC can't do it. if ship_geo.muShieldDesign == 2: import geomGeant4 geomGeant4.setMagnetField() # -----Start run---------------------------------------------------- run.Run(nEvents) # -----Runtime database--------------------------------------------- kParameterMerged = ROOT.kTRUE parOut = ROOT.FairParRootFileIo(kParameterMerged) parOut.open(parFile) rtdb.setOutput(parOut) rtdb.saveOutput() # for the moment, it blocks when using Genie, no idea why rtdb.printParamContexts() # ------------------------------------------------------------------------ run.CreateGeometryFile("geofile_full."+tag+".root") # -----Finish------------------------------------------------------- timer.Stop() rtime = timer.RealTime()