Back to home page

EIC code displayed by LXR

 
 

    


Warning, /DD4hep/doc/usermanuals/DDG4/sections/Setup.tex is written in an unsupported language. File is not indexed.

0001 
0002 %=============================================================================
0003 \section{Setting up DDG4}
0004 \label{sec:ddg4-implementation-setup}
0005 %=============================================================================
0006 
0007 \noindent
0008 \DDG offers several possibilities to configure a simulation application
0009 using
0010 \begin{itemize}\itemcompact
0011 \item XML files,
0012 \item by coding a setup script loaded from the \tts{ROOT} interpreter 
0013         with the AClick mechanism.
0014 \item by creating a setup script using \tts{python} and 
0015         \tts{ROOT}'s reflection mechanism exposed by \tts{PyROOT}.
0016 \end{itemize}
0017 The following subsection describe these different mechanism. An attempt was made
0018 to match the naming conventions of all approaches where possible.
0019 
0020 %=============================================================================
0021 \subsection{Setting up DDG4 using XML}
0022 \label{sec:ddg4-implementation-setup-xml}
0023 %=============================================================================
0024 
0025 \noindent
0026 A special plugin was developed to enable the configuration of \DDG using
0027 XML structures. These files are parsed identically to the geometry setup
0028 in \DDhep the only difference is the name of the root-element, which for 
0029 \DDG is \tts{<geant4\_setup>}. 
0030 The following code snippet shows the basic structure of a \DDG setup file:
0031 \begin{unnumberedcode}
0032 <geant4_setup>
0033   <physicslist>          ,,,  </physicslist>  <!-- Definition of the physics list          -->
0034   <actions>              ...  </actions>      <!-- The list of global actions              -->
0035   <phases>               ...  </phases>       <!-- The definition of the various phases    -->
0036   <filters>              ...  </filters>      <!-- The list of global filter actions       -->
0037   <sequences>            ...  </sequences>    <!-- The list of defined sequences           -->
0038   <sensitive_detectors>  ...  </sensitive_detectors>  <!-- The list of sensitive detectors -->
0039   <properties>           ...  </properties>   <!-- Free format option sequences            -->
0040 </geant4_setup>
0041 \end{unnumberedcode}
0042 To setup a \DDG4 application any number of xml setup files may be interpreted 
0043 iteratively. In the following subsections the content of these first level sub-trees will
0044 be discussed.
0045 
0046 %=============================================================================
0047 \subsubsection{Setup of the Physics List}
0048 \label{sec:ddg4-setup-xml-physicslist}
0049 %=============================================================================
0050 
0051 \noindent
0052 The main tag to setup a physics list is \tts{<physicslist>} with the 
0053 \tts{name} attribute defining the instance of the \tts{Geant4PhysicsList} object.
0054 An example code snippet is shown below in Figure~\ref{fig:ddg4-setup-xml-physicslist}.
0055 
0056 \begin{code}
0057 <geant4_setup>
0058   <physicslist name="Geant4PhysicsList/MyPhysics.0">
0059 
0060     <extends name="QGSP_BERT"/>                    <!-- Geant4 basic Physics list -->
0061 
0062     <particles>                                    <!-- Particle constructors     -->
0063       <construct name="G4Geantino"/>
0064       <construct name="G4ChargedGeantino"/>
0065       <construct name="G4Electron"/>
0066       <construct name="G4Gamma"/>
0067       <construct name="G4BosonConstructor"/>
0068       <construct name="G4LeptonConstructor"/>
0069       <construct name="G4MesonConstructor"/>
0070       <construct name="G4BaryonConstructor"/>
0071       ...
0072     </particles>
0073 
0074     <processes>                                    <!-- Process constructors      -->
0075       <particle name="e[+-]" cut="1*mm">
0076         <process name="G4eMultipleScattering"  ordAtRestDoIt="-1"       ordAlongSteptDoIt="1"
0077                                                ordPostStepDoIt="1"/>
0078         <process name="G4eIonisation"          ordAtRestDoIt="-1"       ordAlongSteptDoIt="2"
0079                                                ordPostStepDoIt="2"/>
0080       </particle>
0081       <particle name="mu[+-]">
0082         <process name="G4MuMultipleScattering" ordAtRestDoIt="-1"       ordAlongSteptDoIt="1"     
0083                                                ordPostStepDoIt="1"/>
0084         <process name="G4MuIonisation"         ordAtRestDoIt="-1"       ordAlongSteptDoIt="2"
0085                                                ordPostStepDoIt="2"/>
0086       </particle>
0087       ...
0088     </processes>
0089 
0090     <physics>                                      <!-- Physics constructors      -->
0091       <construct name="G4EmStandardPhysics"/>
0092       <construct name="HadronPhysicsQGSP"/>
0093       ...
0094     </physics>
0095     
0096   </physicslist>
0097 </geant4_setup>
0098 \end{code}
0099 \begin{figure}[h]
0100 \caption{XML snippet showing the configuration of a physics list.}
0101 \label{fig:ddg4-setup-xml-physicslist}
0102 \end{figure}
0103 
0104 \begin{itemize}\itemcompact
0105 \item To base all these constructs on an already existing predefined Geant4 physics list
0106     use the \tts{<extends>} tag with the attribute containing the name of the physics list
0107     as shown in line 4.
0108 \item To trigger a call to a \bold{particle constructors} (line 7-14), use the \tts{<particles>} section 
0109     and define the Geant4 particle constructor to be called by name. To trigger a call to
0110 \item \bold{physics process constructors}, as shown in line 19-30, 
0111     Define for each particle matching the name pattern (regular expression!) and the 
0112     default cut value for the corresponding processes. The attributes ordXXXX correspond
0113     to the arguments of the Geant4 call \\
0114     \tts{G4ProcessManager::AddProcess(process,ordAtRestDoIt, ordAlongSteptDoIt,ordPostStepDoIt);}
0115     The processes themself are created using the ROOT plugin mechanism.
0116     To trigger a call to
0117 \item \bold{physics constructors}, as shown in line 34-35, use the \tts{<physics>} section.
0118 \end{itemize}
0119 If only a predefined physics list is used, which probably already satisfies very many use cases,
0120 all these section collapse to:
0121 \begin{code}
0122 <geant4_setup>
0123   <physicslist name="Geant4PhysicsList/MyPhysics.0">
0124     <extends name="QGSP_BERT"/>                    <!-- Geant4 basic Physics list -->
0125   </physicslist>
0126 </geant4_setup>
0127 \end{code}
0128 
0129 %=============================================================================
0130 \subsubsection{Setup of Global Geant4 Actions}
0131 \label{sec:ddg4-setup-xml-geant4-actions}
0132 %=============================================================================
0133 
0134 \noindent
0135 Global actions must be defined in the \tts{<actions>} section as shown in the following snippet:
0136 \begin{code}
0137 <geant4_setup>
0138   <actions>
0139     <action name="Geant4TestRunAction/RunInit">
0140       <properties Property_int="12345"
0141           Property_double="-5e15"
0142           Property_string="Startrun: Hello_2"/>
0143      </action>
0144     <action name="Geant4TestEventAction/UserEvent_2"
0145             Property_int="1234"
0146             Property_double="5e15"
0147             Property_string="Hello_2" />
0148   </actions>
0149 </geant4_setup>
0150 \end{code}
0151 The default properties of \bold{every} \tts{Geant4Action} object are:
0152 \begin{unnumberedcode}
0153 Name        [string]                Action name
0154 OutputLevel [int]                   Flag to customize the level of printout
0155 Control     [boolean]               Flag if the UI messenger should be installed.
0156 \end{unnumberedcode}
0157 The \tts{name} attribute of an action child is a qualified name: The first part
0158 denotes the type of the plugin (i.e. its class), the second part the name of the instance.
0159 Within one collection the instance \tts{name} must be unique.
0160 Properties of Geant4Actions are set by placing them as attributes into the
0161 \tts{<properties>} section.
0162 
0163 %=============================================================================
0164 \subsubsection{Setup of Geant4 Filters}
0165 \label{sec:ddg4-setup-xml-geant4-filters}
0166 %=============================================================================
0167 \noindent
0168 Filters are special actions called by \tts{Geant4Sensitive}s. 
0169 Filters may be global or anonymous i.e. reusable by several sensitive detector
0170 sequences as illustrated in Section~\ref{sec:ddg4-setup-xml-geant4-sequences}. 
0171 The setup is analogous to the setup of global actions:
0172 \begin{code}
0173   <filters>
0174     <filter name="GeantinoRejectFilter/GeantinoRejector"/>
0175     <filter name="ParticleRejectFilter/OpticalPhotonRejector">
0176       <properties particle="opticalphoton"/>
0177     </filter>
0178     <filter name="ParticleSelectFilter/OpticalPhotonSelector">
0179       <properties particle="opticalphoton"/>
0180     </filter>
0181     <filter name="EnergyDepositMinimumCut">
0182       <properties Cut="10*MeV"/>
0183     </filter>
0184     <!--        ... next global filter ...       -->
0185   </filters>
0186 \end{code}
0187 Global filters are accessible from the \tts{Geant4Kernel} object.
0188 
0189 %=============================================================================
0190 \subsubsection{Geant4 Action Sequences}
0191 \label{sec:ddg4-setup-xml-geant4-sequences}
0192 %=============================================================================
0193 
0194 \noindent
0195 \tts{Geant4 Action Sequences} by definition are \tts{Geant4Action} objects.
0196 Hence, they share the setup mechanism with properties etc. For the setup
0197 mechanism two different types of sequences are known to \DDG:
0198 {\it{Action sequences}} and {\it{Sensitive detector sequences}}. Bot are declared in
0199 the \tts{sequences} section:
0200 \begin{code}
0201 <geant4_setup>
0202   <sequences>
0203     <sequence name="Geant4EventActionSequence/EventAction"> <!-- Sequence "EventAction" of type
0204                                                                  "Geant4EventActionSequence" -->
0205       <action name="Geant4TestEventAction/UserEvent_1">     <!-- Anonymous action                   -->
0206         <properties Property_int="01234"                    <!-- Properties go inline               -->
0207             Property_double="1e11"
0208             Property_string="'Hello_1'"/>
0209       </action>
0210       <action name="UserEvent_2"/>                          <!-- Global action defined in "actions" -->
0211                                                             <!-- Only the name is referenced here   -->
0212       <action name="Geant4Output2ROOT/RootOutput">          <!-- ROOT I/O action                    -->
0213         <properties Output="simple.root"/>                  <!-- Output file property               -->
0214       </action>
0215       <action name="Geant4Output2LCIO/LCIOOutput">          <!-- LCIO output action                 -->
0216         <properties Output="simple.lcio"/>                  <!-- Output file property               -->
0217       </action>
0218     </sequence>
0219 
0220 
0221     <sequence sd="SiTrackerBarrel" type="Geant4SensDetActionSequence">
0222       <filter name="GeantinoRejector"/>
0223       <filter name="EnergyDepositMinimumCut"/>
0224       <action name="Geant4SimpleTrackerAction/SiTrackerBarrelHandler"/>
0225     </sequence>
0226     <sequence sd="SiTrackerEndcap" type="Geant4SensDetActionSequence">
0227       <filter name="GeantinoRejector"/>
0228       <filter name="EnergyDepositMinimumCut"/>
0229       <action name="Geant4SimpleTrackerAction/SiTrackerEndcapHandler"/>
0230     </sequence>
0231     <!--    ... next sequence ...     -->
0232   </sequences>
0233 </geant4_setup>
0234 \end{code}
0235 Here firstly the \bold{EventAction} sequence is defined with its members. 
0236 Secondly a sensitive detector sequence is defined for the subdetector
0237 \tts{SiTrackerBarrel} of type \tts{Geant4SensDetActionSequence}.
0238 The sequence uses two filters: \tts{GeantinoRejector} to not generate hits
0239 from geantinos and \tts{EnergyDepositMinimumCut} to enforce a minimal energy deposit.
0240 These filters are global i.e. they may be applied by many subdetectors.
0241 The setup of global filters is described in 
0242 Section~\ref{sec:ddg4-setup-xml-geant4-filters}.
0243 Finally the action \tts{SiTrackerEndcapHandler} of type \tts{Geant4SimpleTrackerAction}
0244 is chained, which collects the deposited energy and 
0245 creates a collection of hits. The \tts{Geant4SimpleTrackerAction} is a template
0246 callback to illustrate the usage of sensitive elements in \DDG.
0247 The resulting hit collection of these handlers by default have the same name as the
0248 object instance name.
0249 Analogous below the sensitive detector sequence for the subdetector 
0250 \tts{SiTrackerEndcap} is shown, which reuses the same filter actions, but will build its own
0251 hit collection.
0252 
0253 \noindent
0254 \bold{Please note:}
0255 \begin{itemize}\itemcompact
0256 \item \bold{It was already mentioned, but once again}: Event-, run-, generator-, tracking-,
0257     stepping- and stacking actions sequences have predefined names! 
0258     These names are fixed and part of the \bold{common knowledge}, they cannot be altered.
0259     Please refer to 
0260     Section~\ref{sec:ddg4-user-manual-implementation-geant4action-sequences} 
0261     for the names of the global action sequences.
0262 \item the sensitive detector sequences are matched by the attribute \tts{sd} to the 
0263     subdetectors created with the \DDhep detector description package. Values must match!
0264 \item In the event that several xml files are parsed it is absolutely vital that 
0265     the \tts{<actions>} section is interpreted \bold{before} the \tts{sequences}.
0266 \item For each XML file several \tts{<sequences>} are allowed.
0267 \noindent
0268 \end{itemize}
0269 
0270 %=============================================================================
0271 \subsubsection{Setup of Geant4 Sensitive Detectors}
0272 \label{sec:ddg4-setup-xml-geant4-sensitive detectors}
0273 %=============================================================================
0274 \begin{code}
0275   <geant4_setup>
0276     <sensitive_detectors>
0277       <sd name="SiTrackerBarrel" 
0278           type="Geant4SensDet" 
0279           ecut="10.0*MeV" 
0280           verbose="true" 
0281           hit_aggregation="position">
0282       </sd>
0283       <!-- ...  next sensitive detector ... -->
0284     </sensitive_detectors>
0285   </geant4_setup>
0286 \end{code}
0287 
0288 
0289 
0290 %=============================================================================
0291 \subsubsection{Miscellaneous Setup of Geant4 Objects}
0292 \label{sec:ddg4-setup-xml-geant4-objects}
0293 %=============================================================================
0294 
0295 \noindent
0296 This section is used for the flexible setup of auxiliary objects such as the 
0297 electromagnetic fields used in Geant4:
0298 \begin{code}
0299   <geant4_setup>
0300     <properties>
0301       <attributes name="geant4_field"
0302             id="0"
0303             type="Geant4FieldSetup"
0304             object="GlobalSolenoid"
0305             global="true"
0306             min_chord_step="0.01*mm"
0307             delta_chord="0.25*mm"
0308             delta_intersection="1e-05*mm"
0309             delta_one_step="0.001*mm"
0310             eps_min="5e-05*mm"
0311             eps_max="0.001*mm"
0312             largest_step = "10*m"
0313             stepper="HelixSimpleRunge"
0314             equation="Mag_UsualEqRhs">
0315       </attributes>
0316       ...
0317     </properties>
0318   </geant4_setup>
0319 \end{code}
0320 Important are the tags \tts{type} and \tts{object}, which are used to firstly
0321 define the plugin to be called and secondly define the object from the \DDhep
0322 description to be configured for the use within Geant4.
0323 
0324 %=============================================================================
0325 \subsubsection{Setup of Geant4 Phases}
0326 \label{sec:ddg4-setup-xml-geant4-phases}
0327 %=============================================================================
0328 
0329 \noindent
0330 Phases are configured as shown below.
0331 However, the use is \bold{discouraged},
0332 since it is not yet clear if there are appropriate use cases!
0333 \begin{code}
0334   <phases>
0335     <phase type="RunAction/begin">
0336       <action name="RunInit"/>
0337       <action name="Geant4TestRunAction/UserRunInit">
0338     <properties Property_int="1234"
0339             Property_double="5e15"
0340             Property_string="'Hello_2'"/>
0341       </action>
0342     </phase>
0343     <phase type="EventAction/begin">
0344       <action name="UserEvent_2"/>
0345     </phase>
0346     <phase type="EventAction/end">
0347       <action name="UserEvent_2"/>
0348     </phase>
0349     ...
0350   </phases>
0351 \end{code}
0352 
0353 \newpage
0354 %=============================================================================
0355 \subsection{Setting up DDG4 using ROOT-CINT}
0356 \label{sec:ddg4-implementation-setup-root-cint}
0357 %=============================================================================
0358 
0359 \noindent
0360 The setup of \DDG directly from the the ROOT interpreter using the AClick
0361 mechanism is very simple, but mainly meant for purists (like me ;-)),
0362 since it is nearly equivalent to the explicit setup within a \tts{C++} 
0363 main program.
0364 The following code section shows how to do it. For explanation the code
0365 segment is discussed below line by line.
0366 \begin{code}
0367 #include "DDG4/Geant4Config.h"
0368 #include "DDG4/Geant4TestActions.h"
0369 #include "DDG4/Geant4TrackHandler.h"
0370 #include <iostream>
0371 
0372 using namespace std;
0373 using namespace DD4hep;
0374 using namespace DD4hep::Simulation;
0375 using namespace DD4hep::Simulation::Test;
0376 using namespace DD4hep::Simulation::Setup;
0377 
0378 #if defined(__MAKECINT__)
0379 #pragma link C++ class Geant4RunActionSequence;
0380 #pragma link C++ class Geant4EventActionSequence;
0381 #pragma link C++ class Geant4SteppingActionSequence;
0382 #pragma link C++ class Geant4StackingActionSequence;
0383 #pragma link C++ class Geant4GeneratorActionSequence;
0384 #pragma link C++ class Geant4Action;
0385 #pragma link C++ class Geant4Kernel;
0386 #endif
0387 
0388 SensitiveSeq::handled_type* setupDetector(Kernel& kernel, const std::string& name)   {
0389   SensitiveSeq sd = SensitiveSeq(kernel,name);
0390   Sensitive  sens = Sensitive(kernel,"Geant4TestSensitive/"+name+"Handler",name);
0391   sd->adopt(sens);
0392   sens = Sensitive(kernel,"Geant4TestSensitive/"+name+"Monitor",name);
0393   sd->adopt(sens);
0394   return sd;
0395 }
0396 
0397 void exampleAClick()  {
0398   Geant4Kernel& kernel = Geant4Kernel::instance(LCDD::getInstance());
0399   kernel.loadGeometry("file:../DD4hep.trunk/DDExamples/CLICSiD/compact/compact.xml");
0400   kernel.loadXML("DDG4_field.xml");
0401 
0402   GenAction gun(kernel,"Geant4ParticleGun/Gun");
0403   gun["energy"] = 0.5*GeV;                          // Set properties
0404   gun["particle"] = "e-";
0405   gun["multiplicity"] = 1;
0406   kernel.generatorAction().adopt(gun);
0407 
0408   Action run_init(kernel,"Geant4TestRunAction/RunInit");
0409   run_init["Property_int"] = 12345;
0410   kernel.runAction().callAtBegin  (run_init.get(),&Geant4TestRunAction::begin);
0411   kernel.eventAction().callAtBegin(run_init.get(),&Geant4TestRunAction::beginEvent);
0412   kernel.eventAction().callAtEnd  (run_init.get(),&Geant4TestRunAction::endEvent);
0413 
0414   Action evt_1(kernel,"Geant4TestEventAction/UserEvent_1");
0415   evt_1["Property_int"] = 12345;                    // Set properties
0416   evt_1["Property_string"] = "Events";
0417   kernel.eventAction().adopt(evt_1);
0418 
0419   EventAction evt_2(kernel,"Geant4TestEventAction/UserEvent_2");
0420   kernel.eventAction().adopt(evt_2);
0421 
0422   kernel.runAction().callAtBegin(evt_2.get(),&Geant4TestEventAction::begin);
0423   kernel.runAction().callAtEnd  (evt_2.get(),&Geant4TestEventAction::end);
0424  
0425   setupDetector(kernel,"SiVertexBarrel");
0426   setupDetector(kernel,"SiVertexEndcap");
0427   // .... more subdetectors here .....
0428   setupDetector(kernel,"LumiCal");
0429   setupDetector(kernel,"BeamCal");
0430 
0431   kernel.configure();
0432   kernel.initialize();
0433   kernel.run();
0434   std::cout << "Successfully executed application .... " << std::endl;
0435   kernel.terminate();
0436 }
0437 \end{code}
0438 
0439 \noindent
0440 \begin{tabular} {l||p{0cm}}
0441 \docline{Line}{}
0442 \docline{1}{The header file \tts{Geant4Config.h} contains a set of wrapper
0443     classes to easy the creation of objects using the plugin mechanism and setting
0444     properties to \tts{Geant4Action} objects. These helpers and the corresponding 
0445     functionality are not included in the wrapped classes themselves to not 
0446     clutter the code with stuff only used for the setup.
0447     All contained objects are in the namespace \tts{DD4hep::Simulation::Setup}}.
0448 \docline{6-10}{Save yourself specifying all the namespaces objects are in....}
0449 \docline{13-19}{CINT processing pragmas. 
0450     Classes defined here will be available at the ROOT prompt
0451     after this AClick is loaded.}
0452 \docline{22-29}{Sampler to fill the sensitive detector sequences for each 
0453     subdetector with two entries: a handler and a monitor action.
0454     Please note, that this here is example code and in real life specialized actions
0455     will have to be provided for each subdetector.}
0456 \docline{31}{Let's go for it. here the entry point starts....}
0457 \docline{32}{Create the \tts{Geant4Kernel} object.}
0458 \docline{33}{Load the geometry into \DDhep.}
0459 \docline{34}{Redefine the setup of the sensitive detectors.}
0460 \docline{36-40}{Create the generator action of type \tts{Geant4ParticleGun} with name
0461     \tts{Gun}, set non-default properties and activate the configured object
0462     by attaching it to the \tts{Geant4Kernel}.}
0463 \docline{42-46}{Create a user defined begin-of-run action callback, set the properties
0464     and attach it to the begin of run calls. To collect statistics extra member functions
0465     are registered to be called at the beginning and the end of each event.}
0466 \docline{48-51}{Create a user defined event action routine, set its properties
0467     and attach it to the event action sequence.}
0468 \docline{53-54}{Create a second event action and register it to the event action sequence.
0469     This action will be called after the previously created action.}
0470 \docline{56-57}{For this event action we want to receive callbacks at start- 
0471     and end-of-run to produce additional summary output.}
0472 \docline{59-63}{Call the sampler routine to attach test actions to the subdetectors defined.}
0473 \docline{65-66}{Configure, initialize and run the Geant4 application.
0474     Most of the Geant4 actions will only be created here and the action sequences
0475     created before will be attached now.}
0476 \docline{69}{Terminate the Geant4 application and exit.}
0477 \end{tabular}
0478 
0479 \newpage
0480 \noindent
0481 CINT currently cannot handle pointers to member functions~\footnote{This may change
0482 in the future once ROOT uses \tts{clang} and \tts{cling} as the interpreting engine.}. 
0483 Hence the above AClick only works in compiled mode. To invoke the compilation the following 
0484 action is necessary from the ROOT prompt:
0485 
0486 
0487 \begin{code}
0488 $> root.exe
0489   *******************************************
0490   *                                         *
0491   *        W E L C O M E  to  R O O T       *
0492   *                                         *
0493   *   Version   5.34/10    29 August 2013   *
0494   *                                         *
0495   *  You are welcome to visit our Web site  *
0496   *          http://root.cern.ch            *
0497   *                                         *
0498   *******************************************
0499 
0500 ROOT 5.34/10 (heads/v5-34-00-patches@v5-34-10-5-g0e8bac8, Sep 04 2013, 11:52:19 on linux)
0501 
0502 CINT/ROOT C/C++ Interpreter version 5.18.00, July 2, 2010
0503 Type ? for help. Commands must be C++ statements.
0504 Enclose multiple statements between { }.
0505 root [0] .X initAClick.C
0506 .... Setting up the CINT include pathes and the link statements.
0507 
0508 root [1] .L ../DD4hep.trunk/DDG4/examples/exampleAClick.C+
0509 Info in <TUnixSystem::ACLiC>: creating shared library ....exampleAClick_C.so
0510 .... some Cint warnings concerning member function pointers .....
0511 
0512 root [2] exampleAClick()
0513 .... and it starts ...
0514 \end{code}
0515 
0516 \noindent
0517 The above scripts are present in the DDG4/example directory located in svn.
0518 The initialization script \tts{initAClick.C} may require customization
0519 to cope with the installation paths.
0520 
0521 %=============================================================================
0522 \subsection{Setting up DDG4 using Python}
0523 \label{sec:ddg4-implementation-setup-python}
0524 %=============================================================================
0525 
0526 \noindent
0527 Given the reflection interface of ROOT, the setup of the simulation interface
0528 using DD4hep is of course also possible using the python interpreted language.
0529 In the following code example the setup of Geant4 using the \tts{ClicSid} 
0530 example is shown using python~\footnote{For comparison, the same example was 
0531 used to illustrate the setup using XML files.}.
0532 
0533 \begin{code}
0534 import DDG4
0535 from SystemOfUnits import *
0536 
0537 """
0538 
0539    DD4hep example setup using the python configuration
0540 
0541    @author  M.Frank
0542    @version 1.0
0543 
0544 """
0545 def run():
0546   kernel = DDG4.Kernel()
0547   kernel.loadGeometry("file:../DD4hep.trunk/DDExamples/CLICSiD/compact/compact.xml")
0548   kernel.loadXML("DDG4_field.xml")
0549 
0550   lcdd = kernel.lcdd()
0551   print '+++   List of sensitive detectors:'
0552   for i in lcdd.detectors(): 
0553     o = DDG4.DetElement(i.second)
0554     sd = lcdd.sensitiveDetector(o.name())
0555     if sd.isValid():
0556       print '+++  %-32s type:%s'%(o.name(), sd.type(), )
0557 
0558   # Configure Run actions
0559   run1 = DDG4.RunAction(kernel,'Geant4TestRunAction/RunInit')
0560   run1.Property_int    = 12345
0561   run1.Property_double = -5e15*keV
0562   run1.Property_string = 'Startrun: Hello_2'
0563   print run1.Property_string, run1.Property_double, run1.Property_int
0564   run1.enableUI()
0565   kernel.registerGlobalAction(run1)
0566   kernel.runAction().add(run1)
0567 
0568   # Configure Event actions
0569   evt2 = DDG4.EventAction(kernel,'Geant4TestEventAction/UserEvent_2')
0570   evt2.Property_int    = 123454321
0571   evt2.Property_double = 5e15*GeV
0572   evt2.Property_string = 'Hello_2 from the python setup'
0573   evt2.enableUI()
0574   kernel.registerGlobalAction(evt2)
0575 
0576   evt1 = DDG4.EventAction(kernel,'Geant4TestEventAction/UserEvent_1')
0577   evt1.Property_int=01234
0578   evt1.Property_double=1e11
0579   evt1.Property_string='Hello_1'
0580   evt1.enableUI()
0581 
0582   kernel.eventAction().add(evt1)
0583   kernel.eventAction().add(evt2)
0584 
0585   # Configure I/O
0586   evt_root = DDG4.EventAction(kernel,'Geant4Output2ROOT/RootOutput')
0587   evt_root.Control = True
0588   evt_root.Output = "simple.root"
0589   evt_root.enableUI()
0590 
0591   evt_lcio = DDG4.EventAction(kernel,'Geant4Output2LCIO/LcioOutput')
0592   evt_lcio.Output = "simple_lcio"
0593   evt_lcio.enableUI()
0594 
0595   kernel.eventAction().add(evt_root)
0596   kernel.eventAction().add(evt_lcio)
0597 
0598   # Setup particle gun
0599   gun = DDG4.GeneratorAction(kernel,"Geant4ParticleGun/Gun")
0600   gun.Energy   = 0.5*GeV
0601   gun.particle = 'e-'
0602   gun.multiplicity = 1
0603   gun.enableUI()
0604   kernel.generatorAction().add(gun)
0605 
0606   # Setup global filters for use in sensitive detectors
0607   f1 = DDG4.Filter(kernel,'GeantinoRejectFilter/GeantinoRejector')
0608   f2 = DDG4.Filter(kernel,'ParticleRejectFilter/OpticalPhotonRejector')
0609   f2.particle = 'opticalphoton'
0610   f3 = DDG4.Filter(kernel,'ParticleSelectFilter/OpticalPhotonSelector') 
0611   f3.particle = 'opticalphoton'
0612   f4 = DDG4.Filter(kernel,'EnergyDepositMinimumCut')
0613   f4.Cut = 10*MeV
0614   f4.enableUI()
0615   kernel.registerGlobalFilter(f1)
0616   kernel.registerGlobalFilter(f2)
0617   kernel.registerGlobalFilter(f3)
0618   kernel.registerGlobalFilter(f4)
0619 
0620   # First the tracking detectors
0621   seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/SiVertexBarrel')
0622   act = DDG4.SensitiveAction(kernel,'Geant4SimpleTrackerAction/SiVertexBarrelHandler','SiVertexBarrel')
0623   seq.add(act)
0624   seq.add(f1)
0625   seq.add(f4)
0626   act.add(f1)
0627 
0628   seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/SiVertexEndcap')
0629   act = DDG4.SensitiveAction(kernel,'Geant4SimpleTrackerAction/SiVertexEndcapHandler','SiVertexEndcap')
0630   seq.add(act)
0631   seq.add(f1)
0632   seq.add(f4)
0633 
0634   seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/SiTrackerBarrel')
0635   act = DDG4.SensitiveAction(kernel,'Geant4SimpleTrackerAction/SiTrackerBarrelHandler','SiTrackerBarrel')
0636   seq.add(act)
0637   seq.add(f1)
0638   seq.add(f4)
0639 
0640   seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/SiTrackerEndcap')
0641   act = DDG4.SensitiveAction(kernel,'Geant4SimpleTrackerAction/SiTrackerEndcapHandler','SiTrackerEndcap')
0642   seq.add(act)
0643 
0644   seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/SiTrackerForward')
0645   act = DDG4.SensitiveAction(kernel,'Geant4SimpleTrackerAction/SiTrackerForwardHandler','SiTrackerForward')
0646   seq.add(act)
0647 
0648   # Now the calorimeters
0649   seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/EcalBarrel')
0650   act = DDG4.SensitiveAction(kernel,'Geant4SimpleCalorimeterAction/EcalBarrelHandler','EcalBarrel')
0651   seq.add(act)
0652 
0653   seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/EcalEndcap')
0654   act = DDG4.SensitiveAction(kernel,'Geant4SimpleCalorimeterAction/EcalEndCapHandler','EcalEndcap')
0655   seq.add(act)
0656 
0657   seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/HcalBarrel')
0658   act = DDG4.SensitiveAction(kernel,'Geant4SimpleCalorimeterAction/HcalBarrelHandler','HcalBarrel')
0659   act.adoptFilter(kernel.globalFilter('OpticalPhotonRejector'))
0660   seq.add(act)
0661 
0662   act = DDG4.SensitiveAction(kernel,'Geant4SimpleCalorimeterAction/HcalOpticalBarrelHandler','HcalBarrel')
0663   act.adoptFilter(kernel.globalFilter('OpticalPhotonSelector'))
0664   seq.add(act)
0665 
0666   seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/HcalEndcap')
0667   act = DDG4.SensitiveAction(kernel,'Geant4SimpleCalorimeterAction/HcalEndcapHandler','HcalEndcap')
0668   seq.add(act)
0669 
0670   seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/HcalPlug')
0671   act = DDG4.SensitiveAction(kernel,'Geant4SimpleCalorimeterAction/HcalPlugHandler','HcalPlug')
0672   seq.add(act)
0673 
0674   seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/MuonBarrel')
0675   act = DDG4.SensitiveAction(kernel,'Geant4SimpleCalorimeterAction/MuonBarrelHandler','MuonBarrel')
0676   seq.add(act)
0677 
0678   seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/MuonEndcap')
0679   act = DDG4.SensitiveAction(kernel,'Geant4SimpleCalorimeterAction/MuonEndcapHandler','MuonEndcap')
0680   seq.add(act)
0681 
0682   seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/LumiCal')
0683   act = DDG4.SensitiveAction(kernel,'Geant4SimpleCalorimeterAction/LumiCalHandler','LumiCal')
0684   seq.add(act)
0685 
0686   seq = DDG4.SensitiveSequence(kernel,'Geant4SensDetActionSequence/BeamCal')
0687   act = DDG4.SensitiveAction(kernel,'Geant4SimpleCalorimeterAction/BeamCalHandler','BeamCal')
0688   seq.add(act)
0689 
0690   # Now build the physics list:
0691   phys = kernel.physicsList()
0692   phys.extends = 'FTFP_BERT'
0693   #phys.transportation = True
0694   phys.decays  = True
0695   phys.enableUI()
0696 
0697   ph = DDG4.PhysicsList(kernel,'Geant4PhysicsList/Myphysics')
0698   ph.addParticleConstructor('G4BosonConstructor')
0699   ph.addParticleConstructor('G4LeptonConstructor')
0700   ph.addParticleProcess('e[+-]','G4eMultipleScattering',-1,1,1)
0701   ph.addPhysicsConstructor('G4OpticalPhysics')
0702   ph.enableUI()
0703   phys.add(ph)
0704 
0705   phys.dump()
0706 
0707   kernel.configure()
0708   kernel.initialize()
0709   kernel.run()
0710   kernel.terminate()
0711 
0712 if __name__ == "__main__":
0713   run()
0714 
0715 \end{code}
0716 
0717 \newpage
0718 %=============================================================================
0719 \subsection{A Simple Example}
0720 \label{sec:ddg4-implementation-simple-example}
0721 %=============================================================================
0722 \noindent
0723 Bla-bal.
0724 
0725 \newpage
0726