0% found this document useful (0 votes)
40 views

Gem Sim Tutorial

- GemSim is a Geant4-based simulation software for gem-based detectors. It uses Geant4 to track particles through a detector geometry and produce output for further analysis. - It has a modular architecture and includes modules for defining the geometry, primary particles, and physics processes. Users can interface with the software using steering files and macro files to configure simulation parameters and run the application. - The software utilizes design patterns like abstract classes and factories to provide flexibility in defining different geometry models, physics lists, and extending functionality. Messenger classes provide the user interface and control access to the software.

Uploaded by

Renato Negrao
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

Gem Sim Tutorial

- GemSim is a Geant4-based simulation software for gem-based detectors. It uses Geant4 to track particles through a detector geometry and produce output for further analysis. - It has a modular architecture and includes modules for defining the geometry, primary particles, and physics processes. Users can interface with the software using steering files and macro files to configure simulation parameters and run the application. - The software utilizes design patterns like abstract classes and factories to provide flexibility in defining different geometry models, physics lists, and extending functionality. Messenger classes provide the user interface and control access to the software.

Uploaded by

Renato Negrao
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 39

GemSim software

Software Session

Rémi Eté

CERN, Geneva

4 September 2012

Rémi Eté (CERN, Geneva) GemSim software 4 September 2012 1 / 39


Outline

1 GemSim Software

2 Geant4

3 GemSim Architecture

4 Modules

5 Extras

6 Run the application

7 Conclusion

Rémi Eté (CERN, Geneva) GemSim software 4 September 2012 2 / 39


GemSim Software
What is it ?

Topic
• Software using Geant4 toolkit
• Written in C++
• Simulation for Gem based detector (single, double, triple)
• Macroscopic studies (no ionization)
• (will) Produce input file for Garfield
• Multiplateform software (Linux , Mac OS X , Windows)

Rémi Eté (CERN, Geneva) GemSim software 4 September 2012 3 / 39


GemSim Software
Needed Packages

Mandotory Packages
• Geant4 4.2.p2 (dev version)
→ Sucessfuly compiled and run with Geant4 9.5.p1
• log4cplus
→ Logging library for debug
• ROOT
→ Analysis framework and analysis libraries. Used to generate ROOT output file

More Packages...
• Doxygen
→ Generate a html documentation for classes.
• svn (SubVersion)
→ Versioning software. Checkout for only-reader user and commits for writer user

Rémi Eté (CERN, Geneva) GemSim software 4 September 2012 4 / 39


Geant4
What is it ?

• Toolkit for simulation of the passage of particles through the matter written in C++.
Made of libraries (.a and .so) you can link to your application.

• Define materials (NIST), processes , cross sections, geometry, user actions ,


particles, ...

• Simulation at macroscopic level. Used to track a scattered particle through a


detector. Ionization not well done.

• In our case for GemSim, we can not simulate the avanlanche process in GEM
detector. Work forwarded to Garfield !

Rémi Eté (CERN, Geneva) GemSim software 4 September 2012 5 / 39


Geant4
Sequential run

Runs
Run #1
Run #2 1 Run = Ne Number of Event

Run #Nr

Events
Event #1
1 Event = Nt Number of Tracks
Event #2

Event #Ne
Tracks
Stack New track 1 Track = Ns
Track #1
Track #2
Number of …
Steps Track #Nt

Track treated
Steps Step #1
Step #2

Track Trash
Track Priority Step#Ns
deleted
changed

Rémi Eté (CERN, Geneva) GemSim software 4 September 2012 6 / 39


Geant4
Mandatory classes

Rémi Eté (CERN, Geneva) GemSim software 4 September 2012 7 / 39


GemSim Architecture
Modules

Rémi Eté (CERN, Geneva) GemSim software 4 September 2012 8 / 39


Geometry
Topic

• Provide a generic module for geometry definition

• Define different types of geometry

• Uses abstraction to provide a geometry interface (AbstractGeometry )

• Uses a factory design pattern

• Uses a messenger as a UI

• Detector type can be set via the UI (steering file)

Rémi Eté (CERN, Geneva) GemSim software 4 September 2012 9 / 39


Geometry
Working Principle

GemGeometryConstruction
geometryModel = "Model_1" ;
GeometryFactory::GetGometryModel(geometryModel) ;

Ask for a
geometry type

GeometryFactory
AbstractModel *geomModel == NULL ;
if(model == "Model_1")
geomModel = new Model_1() ;
if(model == "Model_2")
geomModel = new Model_2() ;

Rémi Eté (CERN, Geneva) GemSim software 4 September 2012 10 / 39


Geometry
Class Diagram

Rémi Eté (CERN, Geneva) GemSim software 4 September 2012 11 / 39


Geometry
Example

steering file
## gemsim.steer steering file ##
/GemSim/detector/geometryModel RoughGemGeometry

terminal
$ ./gemsim gemsim.steer

Output :

Rémi Eté (CERN, Geneva) GemSim software 4 September 2012 12 / 39


Geometry
Extend it !

Example : New geometry class called "MyGeom"

You have to :
• Create the class MyGeom which inherits from AbstractGeometry
• Implement the pure virtual methods Build() and PlaceGeometry()
• Add a few lines in the GeometryFactory class to provide a geometry getter

Rémi Eté (CERN, Geneva) GemSim software 4 September 2012 13 / 39


Primaries
Topic

Topic
• Define the primary action for a run
• Uses a messenger as UI
• Differents settings can be done with the UI (mac file)

Class Diagram

Rémi Eté (CERN, Geneva) GemSim software 4 September 2012 14 / 39


Primaries
Example

Mac file
## gemsim.mac mac file ##
...
Gemsim/primaries/particleName mu- # default is gamma
GemSim/primaries/kineticEnergy 150 GeV # default is 1 GeV
...

Terminal
$ ./gemsim -m gemsim.mac

Rémi Eté (CERN, Geneva) GemSim software 4 September 2012 15 / 39


Physics Lists
Topic

• Provide a generic module for physics lists definition

• Uses abstraction to provide a geometry interface (G4VUserPhysicsList)

• Uses a factory design pattern

• Uses a messenger as a UI

• Physics list can be set via the UI (steering file)

Rémi Eté (CERN, Geneva) GemSim software 4 September 2012 16 / 39


Physics Lists
Class Diagram

Rémi Eté (CERN, Geneva) GemSim software 4 September 2012 17 / 39


Physics Lists
Example

steering file
## gemsim.steer steering file ##
...
Gemsim/PhysicsList/name gemsim # default is QGSP_FTFP_BERT
...

Terminal
$ ./gemsim gemsim.steer

Rémi Eté (CERN, Geneva) GemSim software 4 September 2012 18 / 39


Physics Lists
Extend it !

• GemPhysicsList class already created but not well implemented...

• Define specific particles in ConstructParticle() method.

• Define specific processes in ConstrcutProcess() method.

• Set the specific cuts in SetCuts() method.

Rémi Eté (CERN, Geneva) GemSim software 4 September 2012 19 / 39


User Interface
Topic

• Intermediate objects between the user and the program


• Provide a controlled access to the software
• Can change the default behavior the software
• Provides a set of commands
• Two types of file :
• steering file (.steer) : sets information at Pre_Init state like the geometry model or the
physics list to be used.
• mac file (.mac) : sets different types of information available whatever the Geant4
machine state

Execution example
$ ./gemsim gemsim.steer # only steering file
$ ./gemsim -m gemsim.mac # only mac file
$ ./gemsim -m gemsim.mac gemsim.steer # both

Rémi Eté (CERN, Geneva) GemSim software 4 September 2012 20 / 39


User Interface
Messengers

Messengers are classes which define directories and commands for the user.

A messenger is attached to another class on which it acts.

A messenger has 2 methods which has to be defined by the developer :


• SetNewValue(G4UIcommand *command, G4String newValue) : Set a new value
for a given command
• GetCurrentValue(G4UIcommand *command) : Get the current value for a given
command

Directories and commands definition declared in constructor.

For different type of command and how to define directories and commands, see
Geant4 developer’s manual !

Rémi Eté (CERN, Geneva) GemSim software 4 September 2012 21 / 39


User Interface
Example : Geometry model setting complete sequence

## steering file ## Steering file


...
/GemSim/detector/geometryModel GE1_1Station
...

GemDetectorMessenger
GemDetectorMessenger ::GemDetectorMessenger () {
detectorDir = new G4UIdirectory("/GemSim/detector/") ;
...
geometryModelCmd = new G4UIcmdWithAString("/GemSim/detector/geometryModel", this) ;
...
}

void GemDetectorMessenger ::
SetNewValue(G4UIcommand *command, G4String newValue) {
...
if(command == geometryModelCmd)
gemDetectorConstruction->SetGeometryModel(newValue) ;

}

Rémi Eté (CERN, Geneva) GemSim software 4 September 2012 22 / 39


User Interface
Example : Geometry model setting complete sequence

GemDetectorConstruction
G4VPhysicalVolume *GemDetectorConstruction ::Construct() {

AbstractGeometry* geometry = GeometryFactory::GetGeometryModel(model) ;
geometry->Build() ;
geometry->PlaceGeometry(rotationMatrix,translationVector,worldVolume) ;
...
}

GeometryFactory
GeometryFactory::GetGeometryModel(string model) {
AbstractGeometry *geometry = NULL ;
if(model == "GE1_1Station")
geometry = new GE1_1Station() ;

return geometry ;
}

Rémi Eté (CERN, Geneva) GemSim software 4 September 2012 23 / 39


User Interface
Messengers in GemSim

Here the list of messengers in use in GemSim :


• ControlMessenger attached to Control
• GemDetectorMessenger attached to GemDetectorConstruction
• GemEventMessenger attached to GemEventAction
• GemRunMessenger attached to GemRunAction
• GemStackingMessenger attached to GemStackingAction
• GemTrackingMessenger attached to GemTrackingAction
• GemPhysicsListMessenger attached to PhysicsListFactory
• GemPrimaryGeneratorMessenger attached to GemPrimaryGeneratorAction

Rémi Eté (CERN, Geneva) GemSim software 4 September 2012 24 / 39


Analysis
Topic

• Aims to store analysis variables at different execution level (Run, Event , ...)

• Define an interface for different type of Analysis

• A singleton design pattern is used for each analysis implementation

• A factory design pattern is used to provide an analysis pointer and store them

• Output file is written in root file with a given architecture :


• One output file is written.
• For each analysis type a TTree is created named by the analysis type.
• For a given analysis, each analysis variable is "branched" (TBranch)

Rémi Eté (CERN, Geneva) GemSim software 4 September 2012 25 / 39


Analysis
Class Diagram

Rémi Eté (CERN, Geneva) GemSim software 4 September 2012 26 / 39


Analysis
Example : Tracking analysis

GemTrackingAction :
GemTrackingAction : :GemTrackingAction() {
analysis = AnalysisFactory : :GetAnalysis("TrackingAnalysis") ;
}

void GemTrackingAction : :PostUserTrackingAction(const G4Track *aTrack) {


int id = aTrack->GetTrackID() ;
double trackLength = aTrack->GetTrackLength() ;
analysis->ClearAnalysisVariables() ; // initialize the analysis storage
analysis->PushBackAnalysisVariable("trackLength",trackLength) ;
analysis->PushBackAnalysisVariable("trackID",id) ;
analysis->AppendAnalysisVariables() ; // Store them all
}

Root output file :


GemSimAnalysis.root
→ TTree : TrackingAnalysis
→ TBranch : trackLength
→ TBranch : trackID

Rémi Eté (CERN, Geneva) GemSim software 4 September 2012 27 / 39


Extras
Logger

log4cplus package for debugging and logging.


Thread-Safe logger.
Simple to use.

Example :
using namespace log4cplus ;
Logger logFile = Logger : :getInstance("Logger") ;
LOG4CPLUS_TRACE(logFile,"This is a trace message") ;
LOG4CPLUS_DEBUG(logFile,"This is a debug message") ;
LOG4CPLUS_INFO (logFile,"This is an info message") ;
LOG4CPLUS_WARN (logFile,"This is a warning message") ;
LOG4CPLUS_ERROR(logFile,"This is an error message") ;
LOG4CPLUS_FATAL(logFile,"This is an fatal message") ;

Rémi Eté (CERN, Geneva) GemSim software 4 September 2012 28 / 39


Extras
Logger

Output in /path/to/gemsim/log/logfile.log
13 :19 :24 TRACE Logger - This is a trace message [main.cc :100]
13 :20 :44 DEBUG Logger - This is a debug message [main.cc :101]
13 :20 :53 INFO Logger - This is an info message [main.cc :102]
13 :21 :29 WARN Logger - This is a warning message [main.cc :103]
13 :22 :05 ERROR Logger - This is an error message [main.cc :104]
14 :23 :08 FATAL Logger - This is an fatal message [main.cc :105]

Remark : The logging usage is not well developed.


Many classes don’t have logFile instance in the prototype.

Developers : Please, USE THE LOGGING LIBRARIES TO DEBUG THE


SOFTWARE ! !

Rémi Eté (CERN, Geneva) GemSim software 4 September 2012 29 / 39


Extras
Code Documentation

Doxygen can build a html documentation from c++ (and lot of languages) files.

A documented class :
/* ! // ! symbol for doxygen
* class description
* This is an example of class to
* understand how the doxygen doc is generated
*/

class MyClass {
public :
/// method documentation
void aDocumentedMethod() ;
// comment
void aMethodWithoutDocumentation() ;
private :
/// attribute documentation
double aDocumentedAttribute ;
};

Rémi Eté (CERN, Geneva) GemSim software 4 September 2012 30 / 39


Extras
Code Documentation

To generate the documentation (for GemSim only) :

Terminal
$ make doc

To modify doxygen settings or to understand how it works for GemSim, read DoxyFile
in the main directory.
For more information : www.doxygen.org/

Developers : Please, DOCUMENT CLASSES AND PIECES OF CODE ! !.


Doxygen documentation is really useful for users if it’s complete...

Rémi Eté (CERN, Geneva) GemSim software 4 September 2012 31 / 39


Extras
Code Conventions

• Class name and methods with an upper case for the first letter. "MyClass" is good
but not "anotherclass".
• Attributes and instance of objects with an lower case for the first letter.
"anAttribute" is good but not "AnAttribute".
• For each new word in the class name an upper case for the first letter. "Myobject"
is not good but "MyObject" is.
• The first accolade ’{’ for a scope is on the same line as the method :
"void MyMethod() { " is good but ,
"void MyMethod()
{" is not.
• Private scope before public scope in class prototype.
• Split the different header types. See e.g. gemsim.cc
• Avoid hardcoded things. Use abstraction and interfaces for devinitions and
messengers for settings.
• Give a name for variable and methods which makes sense. If the method compute
the χ2 of a function then avoid ’DoIt()’. Choose ’ComputeChi2()’ instead ...
• And finally, please, document the code... :-)
Rémi Eté (CERN, Geneva) GemSim software 4 September 2012 32 / 39
Run the application
Principle

Two ways to run the application :


1 Batch mode :
Give a mac file in argument with ’-m’ option.
$ ./gemsim -m myMacFile.mac
2 Via the Geant4 User Interface (UI) : $ ./gemsim
After this, Geant4 is waiting for a command (Idle>)

Mac file contains a set of G4 (GemSim) commands to be executed.


• Tip :
Prepare your set of commands before in the mac file if there’s a lot. Otherwise use
the UI.
• Remark :
The UI mode allows you to open a window and visualize the detector.
Batch will close the application at the end of the run.
Steering file contains Pre_Init state commands like detector geometry, physics list
name, ROOT file name...

Rémi Eté (CERN, Geneva) GemSim software 4 September 2012 33 / 39


Run the application
Example 1 : Photon sensitivity

steeringfile.steer
## steeringfile.steer file. ##
## Set up the application with Pre_Init commands ##
/GemSim/PhysicsList/name QGSP_FTFP_BERT # is the default one ...
/GemSim/detector/geometryModel RoughGemGeometry # is the default one ...

macfile.mac
## macfile.mac file ##
## Run geant and gemsim commands ##
/GemSim/primaries/particleName gamma # is the default one ...
/GemSim/primaries/kineticEnergy 1 MeV # default is 1 GeV
/run/beamOn 100000 # Generate 1 run with 100000 Events

Terminal
$ ./gemsim -m macfile.mac steeringfile.steer

ROOT output
$ root -l GemSimAnalysis.root
$ root[0] new TBrowser

Rémi Eté (CERN, Geneva) GemSim software 4 September 2012 34 / 39


Run the application
Example 2 : Muons

steeringfile.steer
## steeringfile.steer file. ##
## Set up the application with Pre_Init commands ##
/GemSim/PhysicsList/name QGSP_FTFP_BERT # is the default one ...
/GemSim/detector/geometryModel RoughGemGeometry # is the default one ...

macfile.mac
## macfile.mac file ##
## Run geant and gemsim commands ##
/GemSim/primaries/particleName mu- # default is gamma
/GemSim/primaries/kineticEnergy 150 MeV # default is 1 GeV
/run/beamOn 100000 # Generate 1 run with 100000 Events

Terminal
$ ./gemsim -m macfile.mac steeringfile.steer

ROOT output
$ root -l GemSimAnalysis.root
$ root[0] new TBrowser

Rémi Eté (CERN, Geneva) GemSim software 4 September 2012 35 / 39


Run the application
Example 3 : Visualization

steeringfile.steer
## steeringfile.steer file. ##
/GemSim/PhysicsList/name QGSP_FTFP_BERT # is the default one ...
/GemSim/detector/geometryModel RoughGemGeometry # is the default one ...

macfile.mac
## macfile.mac file ##
/GemSim/primaries/particleName mu- # default is gamma
/GemSim/primaries/kineticEnergy 150 MeV # default is 1 GeV
/vis/open OGLI # open a vis window with OpenGL ...
/vis/drawVolume # ... and draw the detector
/vis/scene/add/axes 0 0 0 1 m # draw the cartesian axes at the origin
/vis/viewer/set/viewpointThetaPhi 45 45 # rotate the camera at angles 45°/45°
/vis/scene/add/hits # show hits at run time
/vis/scene/add/trajectories # show trajectories at run time

Terminal
$ ./gemsim steeringfile.steer
Idle> /control/execute macfile.mac
Idle> /run/beamOn

Rémi Eté (CERN, Geneva) GemSim software 4 September 2012 36 / 39


Conclusion

• GemSim is wimulation software


for GEM based detector
Sensibilite au photons
• Still in development and validation 0.05

with data 0.045

0.04
• Many efforts had been done to
0.035

Ratio de sensibitlite
avoid hardcoding and provide
0.03
generic modules
0.025

• Allows simulation and estimation 0.02

of background particles like 0.015

photons or neutrons 0.01

• Provide output for Garfield 0.005

simulation (to be well done...) 10-1 1 10 102 10


3
104
Energie [MeV]
• Estimation of background photon
sensitivity ∼ 1%

Rémi Eté (CERN, Geneva) GemSim software 4 September 2012 37 / 39


References

Basic information for G4 : http ://geant4.cern.ch/


Geant4 code documentation : http ://www.lcsim.org/software/geant4/doxygen/html/
ROOT : http ://root.cern.ch/drupal/
Log4cplus libraries : http ://log4cplus.sourceforge.net/
Doxygen : www.doxygen.org/
Subversion at CERN : http ://svn.web.cern.ch/svn/
Class diagram realised with BOUML.
GEM geometry :
https ://twiki.cern.ch/twiki/pub/MPGD/CmsGEMCollaboration/GEM_technical_proposal.pdf
Design Patterns : "Design Patterns explained : a new perspective on object oriented design". A.
Shalloway, J. R. Trott.

Rémi Eté (CERN, Geneva) GemSim software 4 September 2012 38 / 39


A 500 TEV GEANTINO ! ! ! ! !
Rémi Eté (CERN, Geneva) GemSim software 4 September 2012 39 / 39

You might also like