From d430c07f4842a7c6bac5c07bfdfa6af2afd3ba10 Mon Sep 17 00:00:00 2001 From: lintao <lintao51@gmail.com> Date: Wed, 16 Sep 2020 22:05:46 +0800 Subject: [PATCH] WIP: update. --- docs/simulation-tutorial/index.html | 200 ++++++++++++++++++++++++++-- 1 file changed, 189 insertions(+), 11 deletions(-) diff --git a/docs/simulation-tutorial/index.html b/docs/simulation-tutorial/index.html index c8273f43..6f1fdeed 100644 --- a/docs/simulation-tutorial/index.html +++ b/docs/simulation-tutorial/index.html @@ -53,6 +53,21 @@ <div class="reveal"> <div class="slides"> + +--- + +type: slide +slideOptions: + transition: slide + # theme: white + controls: true + showSlideNumber: 'all' + navigationMode: 'linear' + center: false + # disableLayout: true + +--- + # Tutorial on CEPCSW simulation Author: Tao Lin @@ -65,7 +80,7 @@ Indico: https://indico.ihep.ac.cn/event/12341/other-view?view=standard * As Users * Run a simple simulation job in CEPCSW - * Understand and Customize the simulation job + * Understand and Customize the simulation * Analyze the simulation output * As Developers * Understand the simulation framework @@ -77,33 +92,197 @@ Indico: https://indico.ihep.ac.cn/event/12341/other-view?view=standard ## Run simulation in CEPCSW * The simulation is run by following command: - ```bash -./run.sh Examples/options/tut_detsim.py +$ ./run.sh Examples/options/tut_detsim.py +``` +* The job option: `Examples/options/tut_detsim.py`. <!-- .element: style="color:yellow; " --> +* :writing_hand: copy the job option into your current directory. Edit your job option in the later exercises. +```bash +$ cp Examples/options/tut_detsim.py my_detsim.py ``` - -* Here, `run.sh` is a common wrapper, which will invoke the Gaudi framework. -* The job option `Examples/options/tut_detsim.py` is to run the simulation. --- ### What's inside the job option? * Random Number Service * Use `Seeds` option to control the random number sequences. -* Event Data Service +* Event Data Service and PODIO writer * Geometry Service * Different detector options could be loaded here via `compact` option. -* Physics Generator or Particle Gun -* Detector simulation framework +* Physics generator algorithm +* Detector simulation algorithm + + +--- + +#### Save detector response into ROOT file +```python +from Configurables import PodioOutput +out = PodioOutput("outputalg") +out.filename = "test-detsim10-seed42.root" +out.outputCommands = ["keep *"] +``` +* The EDM4hep format is used in the detector response. +* All the collections created in simulation will be saved. +* :writing_hand: modify the output file name. --- -## Customize the primary particles +#### Random Number +```python +from Configurables import RndmGenSvc, HepRndm__Engine_CLHEP__RanluxEngine_ + +# rndmengine = HepRndm__Engine_CLHEP__RanluxEngine_() # The default engine in Gaudi +rndmengine = HepRndm__Engine_CLHEP__HepJamesRandom_() # The default engine in Geant4 +rndmengine.SetSingleton = True +rndmengine.Seeds = [42] + +``` + +* Seed is used to initialize the state of the random number engine. +* If two job set the same seed, the outputs will be same. +* :writing_hand: modify the seed and see the difference. + +--- + +#### Geometry / Detector Description +```python +geometry_option = "CepC_v4-onlyVXD.xml" + +geometry_path = os.path.join(os.getenv("DETCEPCV4ROOT"), + "compact", geometry_option) + +from Configurables import GeoSvc +geosvc = GeoSvc("GeoSvc") +geosvc.compact = geometry_path +``` +* The compact file is in XML format, which describes the detector. +* :writing_hand: change the geometry path and run simulation again. +``` +geometry_path = "Detector/DetEcalMatrix/compact/det.xml" +``` + +--- + +#### Customize primary particles +##### Particle Gun +```python +gun = GtGunTool("GtGunTool") +gun.Particles = ["pi+", "pi-"] +gun.EnergyMins = [100., 100] # GeV +gun.EnergyMaxs = [100., 100] # GeV + +gun.ThetaMins = [0, 0] # deg +gun.ThetaMaxs = [180., 180] # deg + +gun.PhiMins = [0., 0.] # deg +gun.PhiMaxs = [360., 360.] # deg +``` + +* Particle name can be found in [`$ROOTSYS/etc/pdg_table.txt`](https://github.com/root-project/root/blob/master/etc/pdg_table.txt) +* :writing_hand: change the particles, energies and directions. + +---- + +##### event generators +```python +stdheprdr = StdHepRdr("StdHepRdr") +stdheprdr.Input = "/cefs/data/stdhep/CEPC250/2fermions/E250.Pbhabha.e0.p0.whizard195/bhabha.e0.p0.00001.stdhep" + +genalg = GenAlgo("GenAlgo") +genalg.GenTools = ["StdHepRdr"] + +``` +* There are several readers to read the output of event generators in different formats + * StdHep: `StdHepRdr`, lcio: `SLCIORdr`, HepMC: `HepMCRdr`. +* :writing_hand: use the different readers to load different samples. +* [The existing samples could be found here.](http://cepcsoft.ihep.ac.cn/guides/Generation/docs/ExistingSamples/) + +--- + +#### Customize Geant4 using [built-in commands](http://geant4-userdoc.web.cern.ch/geant4-userdoc/UsersGuides/ForApplicationDeveloper/html/Control/AllResources/Control/UIcommands/_.html) +##### :writing_hand: Turn on the verbose during tracking +```python +detsimalg.RunCmds = [ + "/tracking/verbose 1", +] +# Or +detsimalg.RunMacs = [ + "run.mac", +] +``` +```bash +# Below is the content of run.mac +/tracking/verbose 1 +``` + +* Each step will be print out. Remeber to redirect the output to a file. +```bash +$ ./run.sh tut_detsim.py >& mylog +``` + +---- + +##### Geant4 tracking output +``` +********************************************************************************************************* +* G4Track Information: Particle = gamma, Track ID = 1, Parent ID = 0 +********************************************************************************************************* + +Step# X(mm) Y(mm) Z(mm) KinE(MeV) dE(MeV) StepLeng TrackLeng NextVolume ProcName + 0 0 0 0 1e+05 0 0 0 pWorld initStep + 1 1.03e+03 1.8e+04 1.1e-12 0 0 1.8e+04 1.8e+04 pWorld conv + +********************************************************************************************************* +* G4Track Information: Particle = e+, Track ID = 4, Parent ID = 1 +********************************************************************************************************* + +Step# X(mm) Y(mm) Z(mm) KinE(MeV) dE(MeV) StepLeng TrackLeng NextVolume ProcName + 0 1.03e+03 1.8e+04 1.1e-12 2.91e+04 0 0 0 pWorld initStep + 1 1.04e+03 1.8e+04 -0.00523 2.91e+04 0.0117 54.9 54.9 pWorld eIoni + 2 1.04e+03 1.81e+04 -0.00912 2.91e+04 0.00604 38.7 93.6 pWorld eIoni + 3 1.06e+03 1.84e+04 -0.0404 2.91e+04 0.0634 321 415 pWorld eIoni + 4 1.06e+03 1.84e+04 -0.0416 2.91e+04 0.00234 13.1 428 pWorld eIoni + +``` +<!-- .element: style="color:yellow; font-size:small" --> + +* From this output, you can see the current track and its stepping information. +* Particle name, current track ID, parent track ID +* Step position, deposit energy + +---- + +##### :writing_hand: Visualize using Geant4 + +* Enable following command in your job option: +```python +detsimalg.VisMacs = ["Examples/options/vis.mac"] +``` +* :warning: If your X Server supports the G4 OpenGL, the detector will be shown. + * Try [Xming X Server](https://sourceforge.net/projects/xming/) in Windows. +* :notebook: [Visualization in Geant4 Documentation](http://geant4-userdoc.web.cern.ch/geant4-userdoc/UsersGuides/ForApplicationDeveloper/html/Visualization/visualization.html) + * G4 UI commands during visualization +``` +/vis/scene/add/axes 0 0 0 3 m +/vis/scene/add/magneticField +``` + +---- + + +##### Snapshot: The Qt based Geant4 visualization + + + +:writing_hand: Play with Geant4 Visualization +<!-- .element: style="color:yellow" --> --- ## Analyze the simulation output + --- ## CEPCSW Simulation Framework @@ -117,7 +296,6 @@ Indico: https://indico.ihep.ac.cn/event/12341/other-view?view=standard ## Simulate a simple detector - </div> </div> -- GitLab