From 89de937451c7b5ee61eb6cdc161f8e6a98b3b9a5 Mon Sep 17 00:00:00 2001 From: lintao <lintao51@gmail.com> Date: Wed, 16 Sep 2020 23:56:49 +0800 Subject: [PATCH] WIP: copy the slides from live note. --- docs/simulation-tutorial/index.html | 159 +++++++++++++++++++++------- 1 file changed, 120 insertions(+), 39 deletions(-) diff --git a/docs/simulation-tutorial/index.html b/docs/simulation-tutorial/index.html index da80bfd8..6a59e836 100644 --- a/docs/simulation-tutorial/index.html +++ b/docs/simulation-tutorial/index.html @@ -1,3 +1,4 @@ + <!doctype html> <html lang="en"> <head> @@ -7,7 +8,7 @@ <meta name="mobile-web-app-capable" content="yes"> - <meta name="description" content=" # Tutorial on CEPCSW simulation Author: Tao Lin Date: 17 Sept. 2020 Indico: https://indico.ihep.a"> + <meta name="description" content=" # Tutorial on CEPCSW simulation Tao Lin IHEP 17 Sept. 2020 [CEPCSW Tutorial, 2020, IHEP](https://"> <title>Tutorial on CEPCSW simulation - CodiMD</title> <link rel="icon" type="image/png" href="https://jupyter.ihep.ac.cn/favicon.png"> @@ -40,7 +41,7 @@ <link rel="stylesheet" href="https://jupyter.ihep.ac.cn/css/slide.css"> <!-- Printing and PDF exports --> - <script nonce="70b14f1d-a496-4359-aa9f-0907551b6dee"> + <script nonce="840f3704-7c5d-407c-bee3-d2af62757acb"> var link = document.createElement( 'link' ); link.rel = 'stylesheet'; link.type = 'text/css'; @@ -55,13 +56,14 @@ # Tutorial on CEPCSW simulation -Author: Tao Lin -Date: 17 Sept. 2020 -Indico: https://indico.ihep.ac.cn/event/12341/other-view?view=standard +Tao Lin +IHEP +17 Sept. 2020 +[CEPCSW Tutorial, 2020, IHEP](https://indico.ihep.ac.cn/event/12341/other-view?view=standard) --- -## What will you learn in this Tutorial? +## What will learn in this Tutorial? * As Users * Run a simple simulation job in CEPCSW @@ -71,16 +73,41 @@ Indico: https://indico.ihep.ac.cn/event/12341/other-view?view=standard * Understand the simulation framework * Learn basics on Geant4 simulation * Simulate with different detector options +* Note: the emoji :writing_hand: means exercises + +--- + +### CEPCSW Simulation Framework + + + +* The simulation chain is driven by Gaudi. +* Detector description is from DD4hep. +* Event Data Model is in EDM4hep format. +* Detector response is done by Geant4. + +---- + +#### Code is on GitHub +* Detector description: [See Detector](https://github.com/cepc/CEPCSW/tree/master/Detector) +* Event generator interface: [See Generator](https://github.com/cepc/CEPCSW/tree/master/Generator) +* Detector simulation: [See Simulation](https://github.com/cepc/CEPCSW/tree/master/Simulation) + * [DetSimInterface: Gaudi Tool interface](https://github.com/cepc/CEPCSW/tree/master/Simulation/DetSimInterface) + * [DetSimCore: integrate Gaudi and Geant4](https://github.com/cepc/CEPCSW/tree/master/Simulation/DetSimCore) + * [DetSimGeom: integrate with DD4hep](https://github.com/cepc/CEPCSW/tree/master/Simulation/DetSimGeom) + * [DetSimAna: collect data from Geant4](https://github.com/cepc/CEPCSW/tree/master/Simulation/DetSimAna) + * [DetSimSD: detector response](https://github.com/cepc/CEPCSW/tree/master/Simulation/DetSimSD) +* Job options: [See Examples/options](https://github.com/cepc/CEPCSW/tree/master/Examples/options) --- -## Run simulation in CEPCSW +### Run simulation in CEPCSW * The simulation is run by following command: ```bash $ ./run.sh Examples/options/tut_detsim.py ``` -* The job option: `Examples/options/tut_detsim.py`. <!-- .element: style="color:yellow; " --> +* 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 @@ -88,7 +115,7 @@ $ cp Examples/options/tut_detsim.py my_detsim.py --- -### What's inside the job option? +### What's inside the job option? * Random Number Service * Use `Seeds` option to control the random number sequences. * Event Data Service and PODIO writer @@ -103,14 +130,28 @@ $ cp Examples/options/tut_detsim.py my_detsim.py #### Save detector response into ROOT file ```python from Configurables import PodioOutput -out = PodioOutput("outputalg") -out.filename = "test-detsim10-seed42.root" -out.outputCommands = ["keep *"] +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. +--- + +#### Control how many events to be simulated +```python +from Configurables import ApplicationMgr +ApplicationMgr( TopAlg = [genalg, detsimalg, out], + EvtSel = 'NONE', + EvtMax = 10, + ExtSvc = [rndmengine, dsvc, geosvc], +) +``` +* :writing_hand: modify the `EvtMax` property and check the entries in the output. + + --- #### Random Number @@ -132,19 +173,19 @@ rndmengine.Seeds = [42] #### Geometry / Detector Description ```python -geometry_option = "CepC_v4-onlyVXD.xml" +geometry_option = "CepC_v4-onlyVXD.xml" -geometry_path = os.path.join(os.getenv("DETCEPCV4ROOT"), - "compact", geometry_option) +geometry_path = os.path.join(os.getenv("DETCEPCV4ROOT"), + "compact", geometry_option) from Configurables import GeoSvc -geosvc = GeoSvc("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" +geometry_path = "Detector/DetEcalMatrix/compact/det.xml" ``` --- @@ -152,8 +193,8 @@ geometry_path = "Detector/DetEcalMatrix/compact/det.xml" #### Customize primary particles ##### Particle Gun ```python -gun = GtGunTool("GtGunTool") -gun.Particles = ["pi+", "pi-"] +gun = GtGunTool("GtGunTool") +gun.Particles = ["pi+", "pi-"] gun.EnergyMins = [100., 100] # GeV gun.EnergyMaxs = [100., 100] # GeV @@ -169,13 +210,13 @@ gun.PhiMaxs = [360., 360.] # deg ---- -##### event generators +##### Event Generators ```python -stdheprdr = StdHepRdr("StdHepRdr") -stdheprdr.Input = "/cefs/data/stdhep/CEPC250/2fermions/E250.Pbhabha.e0.p0.whizard195/bhabha.e0.p0.00001.stdhep" +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"] +genalg = GenAlgo("GenAlgo") +genalg.GenTools = ["StdHepRdr"] ``` * There are several readers to read the output of event generators in different formats @@ -189,11 +230,11 @@ genalg.GenTools = ["StdHepRdr"] ##### :writing_hand: Turn on the verbose during tracking ```python detsimalg.RunCmds = [ - "/tracking/verbose 1", + "/tracking/verbose 1", ] # Or detsimalg.RunMacs = [ - "run.mac", + "run.mac", ] ``` ```bash @@ -203,7 +244,7 @@ detsimalg.RunMacs = [ * Each step will be print out. Remeber to redirect the output to a file. ```bash -$ ./run.sh tut_detsim.py >& mylog +$ ./run.sh my_detsim.py >& mylog ``` ---- @@ -230,7 +271,7 @@ Step# X(mm) Y(mm) Z(mm) KinE(MeV) dE(MeV) StepLeng TrackLeng NextVolu 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" --> +<!-- .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 @@ -242,7 +283,7 @@ Step# X(mm) Y(mm) Z(mm) KinE(MeV) dE(MeV) StepLeng TrackLeng NextVolu * Enable following command in your job option: ```python -detsimalg.VisMacs = ["Examples/options/vis.mac"] +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. @@ -261,27 +302,64 @@ detsimalg.VisMacs = ["Examples/options/vis.mac"]  :writing_hand: Play with Geant4 Visualization -<!-- .element: style="color:yellow" --> +<!-- .element: style="color:yellow" --> --- -## Analyze the simulation output +### Analyze the simulation output +* :writing_hand: Modify the geometry option and run the simulation +```python +geometry_option = "CepC_v4-onlyECAL.xml" +``` +* :writing_hand: Plot the `EcalBarrelCollection` in ROOT +``` +root [] events->Draw("EcalBarrelCollection.position.y:EcalBarrelCollection.position.x") +root [] events->Draw("EcalBarrelCollection.position.y:EcalBarrelCollection.position.x", "Entry$==0") +``` +<!-- .element: style="color:yellow; font-size:small" --> +---- ---- +#### See the branches in the `events` tree +``` +root [] events->Print() +*............................................................................* +*Br 146 :EcalBarrelCollection.cellID : * +* | ULong64_t cellID[EcalBarrelCollection_] * +*Entries : 10 : Total Size= 1398779 bytes File Size = 420214 * +*Baskets : 4 : Basket Size= 32000 bytes Compression= 3.33 * +*............................................................................* +*Br 147 :EcalBarrelCollection.energy : Float_t energy[EcalBarrelCollection_]* +*Entries : 10 : Total Size= 699855 bytes File Size = 163107 * +*Baskets : 3 : Basket Size= 32000 bytes Compression= 4.29 * +*............................................................................* +*Br 148 :EcalBarrelCollection.position.x : Float_t x[EcalBarrelCollection_] * +*Entries : 10 : Total Size= 699865 bytes File Size = 466951 * +*Baskets : 3 : Basket Size= 32000 bytes Compression= 1.50 * +*............................................................................* +*Br 149 :EcalBarrelCollection.position.y : Float_t y[EcalBarrelCollection_] * +*Entries : 10 : Total Size= 699865 bytes File Size = 469393 * +*Baskets : 3 : Basket Size= 32000 bytes Compression= 1.49 * +*............................................................................* +*Br 150 :EcalBarrelCollection.position.z : Float_t z[EcalBarrelCollection_] * +*Entries : 10 : Total Size= 699865 bytes File Size = 560229 * +*Baskets : 3 : Basket Size= 32000 bytes Compression= 1.25 * +*............................................................................* +``` +<!-- .element: style="color:yellow; font-size:small" --> -## CEPCSW Simulation Framework --- -## Geant4 Simulation Toolkit ---- +# Thank you for your attention -## Simulate a simple detector +* [Create issue](https://github.com/cepc/CEPCSW/issues): Report a bug +* [Pull Request](https://github.com/cepc/CEPCSW/pulls): Fix a bug or Implement a feature - </div> +Your contributions are welcome! +</div> </div> <div id="meta">{"type":"slide","slideOptions":{"transition":"slide","controls":true,"showSlideNumber":"all","navigationMode":"linear","center":false}}</div> @@ -294,9 +372,9 @@ detsimalg.VisMacs = ["Examples/options/vis.mac"] <span class="ui-lastchangeuser"> <i class="ui-user-icon small" style="background-image: url(https://www.gravatar.com/avatar/a696972a0dc29e70843f619695acb1e9?s=80&d=identicon);" data-toggle="tooltip" data-placement="right" title="lintao@ihep.ac.cn"></i></span> <span class="text-uppercase ui-status-lastchange"></span> - <span class="ui-lastchange text-uppercase" data-createtime="Mon Sep 14 2020 21:17:56 GMT+0800 (China Standard Time)" data-updatetime="Tue Sep 15 2020 23:02:45 GMT+0800 (China Standard Time)"></span> + <span class="ui-lastchange text-uppercase" data-createtime="Mon Sep 14 2020 21:17:56 GMT+0800 (China Standard Time)" data-updatetime="Wed Sep 16 2020 23:50:34 GMT+0800 (China Standard Time)"></span> </span> - <span class="pull-right">35 views <a href="#" class="ui-edit" title="Edit this note"><i class="fa fa-fw fa-pencil"></i></a><a class="ui-print" href="" title="Open print view"><i class="fa fa-fw fa-print"></i></a></span> + <span class="pull-right">230 views <a href="#" class="ui-edit" title="Edit this note"><i class="fa fa-fw fa-pencil"></i></a><a class="ui-print" href="" title="Open print view"><i class="fa fa-fw fa-print"></i></a></span> <br> </small> @@ -332,3 +410,6 @@ detsimalg.VisMacs = ["Examples/options/vis.mac"] </body> </html> + + + -- GitLab