Professional Documents
Culture Documents
Gem Sim Tutorial
Gem Sim Tutorial
Software Session
Rémi Eté
CERN, Geneva
4 September 2012
1 GemSim Software
2 Geant4
3 GemSim Architecture
4 Modules
5 Extras
7 Conclusion
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)
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
• 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.
• In our case for GemSim, we can not simulate the avanlanche process in GEM
detector. Work forwarded to Garfield !
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
• Uses a messenger as a UI
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() ;
steering file
## gemsim.steer steering file ##
/GemSim/detector/geometryModel RoughGemGeometry
terminal
$ ./gemsim gemsim.steer
Output :
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
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
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
• Uses a messenger as a UI
steering file
## gemsim.steer steering file ##
...
Gemsim/PhysicsList/name gemsim # default is QGSP_FTFP_BERT
...
Terminal
$ ./gemsim gemsim.steer
Execution example
$ ./gemsim gemsim.steer # only steering file
$ ./gemsim -m gemsim.mac # only mac file
$ ./gemsim -m gemsim.mac gemsim.steer # both
Messengers are classes which define directories and commands for the user.
For different type of command and how to define directories and commands, see
Geant4 developer’s manual !
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) ;
…
}
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 ;
}
• Aims to store analysis variables at different execution level (Run, Event , ...)
• A factory design pattern is used to provide an analysis pointer and store them
GemTrackingAction :
GemTrackingAction : :GemTrackingAction() {
analysis = AnalysisFactory : :GetAnalysis("TrackingAnalysis") ;
}
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") ;
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]
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 ;
};
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/
• 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
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
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
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
0.04
• Many efforts had been done to
0.035
Ratio de sensibitlite
avoid hardcoding and provide
0.03
generic modules
0.025