SND@LHC Software
Loading...
Searching...
No Matches
run_simEcal.py
Go to the documentation of this file.
1#!/usr/bin/env python
2from __future__ import print_function
3momentum = 1
4import ROOT,os,sys,getopt,time
5import shipunit as u
6import shipRoot_conf
7import ShipGeoConfig
8
9mcEngine = "TGeant3"
10simEngine = "Pythia8" # "Genie" # Ntuple
11nEvents = 2000
12inclusive = False # True = all processes if False only ccbar -> HNL
13deepCopy = False # False = copy only stable particles to stack, except for HNL events
14eventDisplay = False
15inputFile = None
16theSeed = int(10000 * time.time() % 10000000)
17
18if momentum>5 : nEvents=1000
19if momentum>20 : nEvents=500
20
21print("FairShip setup for",simEngine,"to produce",nEvents,"events")
22if simEngine == "Ntuple" and not inputFile :
23 print('input file required if simEngine = Ntuple')
24if simEngine == "Pythia6" and not inputFile :
25 print('pythia6 requires inputfile')
26ROOT.gRandom.SetSeed(theSeed) # this should be propagated via ROOT to Pythia8 and Geant4VMC
28ship_geo = ShipGeoConfig.Config().loadpy("$FAIRSHIP/geometry/geometry_config.py")
29
30# Output file name
31outFile ="geant.root"
32
33# rm older files !!!
34os.system("rm params.root")
35# Parameter file name
36parFile="params.root"
37
38# In general, the following parts need not be touched
39# ========================================================================
40
41# -----Timer--------------------------------------------------------
42timer = ROOT.TStopwatch()
43timer.Start()
44# ------------------------------------------------------------------------
45
46# -----Create simulation run----------------------------------------
47run = ROOT.FairRunSim()
48run.SetName(mcEngine) # Transport engine
49run.SetOutputFile(outFile) # Output file
50rtdb = run.GetRuntimeDb()
51# -----Create geometry----------------------------------------------
52import shipDet_conf
54# -----Create PrimaryGenerator--------------------------------------
55primGen=ROOT.FairPrimaryGenerator()
56boxGen=ROOT.FairBoxGenerator(22,1);
57boxGen.SetPRange(momentum, momentum)
58boxGen.SetPhiRange(0,0)
59boxGen.SetThetaRange(0,0)
60#boxGen.SetXYZ(0,0,-9900)
61boxGen.SetXYZ(0,0,2400)
62primGen.AddGenerator(boxGen)
63run.SetGenerator(primGen)
64
65# ------------------------------------------------------------------------
66
67#---Store the visualiztion info of the tracks, this make the output file very large!!
68#--- Use it only to display but not for production!
69if eventDisplay: run.SetStoreTraj(ROOT.kTRUE)
70else: run.SetStoreTraj(ROOT.kFALSE)
71# -----Initialize simulation run------------------------------------
72run.Init()
73fStack = ROOT.gMC.GetStack()
74#fStack.SetEnergyCut(.3*u.MeV)
75# ------------------------------------------------------------------------
76if simEngine != "Genie" and simEngine != "Ntuple":
77# -----Runtime database---------------------------------------------
78 kParameterMerged = ROOT.kTRUE
79 parOut = ROOT.FairParRootFileIo(kParameterMerged)
80 parOut.open(parFile)
81 rtdb.setOutput(parOut)
82 rtdb.saveOutput() # for the moment, it blocks when using Genie, no idea why
83 rtdb.printParamContexts()
84# -----Start run----------------------------------------------------
85run.Run(nEvents)
86# ------------------------------------------------------------------------
87run.CreateGeometryFile("geofile_full.root")
88# -----Finish-------------------------------------------------------
89timer.Stop()
90rtime = timer.RealTime()
91ctime = timer.CpuTime()
92print(' ')
93print("Macro finished succesfully.")
94print("Output file is ", outFile)
95print("Parameter file is ",parFile)
96print("Real time ",rtime, " s, CPU time ",ctime,"s")
97
98# ------------------------------------------------------------------------
configure(run, ship_geo)
configure(darkphoton=None)