Title: CBM Simulation
1CBM Simulation Analysis FrameworkSimulation
Part
2Outline
- Software distribution
- Adding Modules and Detectors
- What to implement ?
- Creating the library
- Creating the simulation Macro
- The output file structure
3Software distribution
- The CBM software is distributed via anonymous CVS
- CVS login
- cvs -d pserveranonymous_at_www-linux.gsi.de/misc/
cbmsim/CVS/cbmrepos login -    password  Please type nothing just press
enter - CVS Checkout
- cvs -d pserveranonymous_at_www-linux.gsi.de/misc/
cbmsim/CVS/cbmrepos checkout cbm_vmc - CVS Update
- cvs -d pserveranonymous_at_www-linux.gsi.de/misc/
cbmsim/CVS/cbmrepos update
4Building the software
- make
- in the cbm_vmc directory will build everything
- in sub-directory will build only the
corresponding library - make analysis
- This will build only the Geant3 part of the
software for the - simulation and the analysis part which is
independent of the MC - engine.
- After a CVS update it is recommoneded to use make
clean first and then make.
5CBM Analysis and Simulation Framework
Urqmd
G3
G4
FLUKA
Pluto
Magnet
ROOT
Ion Generator
Generators
Geometry Manager
Target
Virtual MC
Particle Generator
PIPE
ASCII
Cave
Run Manager
Module
Mixed Generator
Detector
Tasks List
STS
Magnetic Field
Delta
IO Manager
TRD
Tracking
TOF
digitizers
Field Map
RICH
6What is needed to add a detector or a Module ?
- Material definitions
- Geometry definitions
- Create a detector (or Module) class
- Create the library
- Create a ROOT macro
- Run the Simulation macro
7Material Definition
- carbondioxide
- COMPONENTS
- 1.9768e-3
- 2
- elC
- 0.27
- elO
- 0.73
- fi
- TRDgas
- COMPONENTS
- 5.4476e-3
- 2
- elXe
- 0.85
- carbondioxide
- 0.15
Material name
Composition
Density
Single element
Fractional mass
Mixture of Composite
8Geometry definition
Volume name
- AlPlate1S3R
- 0
- world
- -162.912 0 986.742
- 0.986643 0 0.162895 0 1 0 -0.162895 0 0.986643
- aluminium
- BOX
- 40.8947
- 440.536
- 0.1
- fi
-
Sensitivity flag (0,1)
Mother volume
Transformations
Material
Shape name
Shape parameters
9Creating a Module class definition
- ifndef MABGNET_H
- define MABGNET_H
- include "CBMModule.h"
- class CBMMagnet public CBMModule
- public
- CBMMagnet(const char name, const char
Title"CBM Magnet") - CBMMagnet()
- virtual CBMMagnet()
- ClassDef(CBMMagnet,1) //CBMMagnet
-
- endif //MABGNET_H
10Creating a Module class Implementation
- include "CBMMagnet.h"
- CBMMagnetCBMMagnet(const char name, const
char Title) - CBMModule(name ,Title)
-
-
- CBMMagnetCBMMagnet()
- CBMMagnetCBMMagnet()
- ClassImp(CBMMagnet)
11Creating a detector class definition (1)
- Class Definition for MyDet Class
- ifndef MYDET_H
- define MYDET_H
- include "CBMDetector.h"
- class CBMVolume
- class CBMMyDet public CBMDetector
- CBMMyDet()
- CBMMyDet(const char name, Bool_t Active)
- virtual CBMMyDet()
12Creating a detector class definition (2)
- virtual ConstructGeometry()
- virtual void Initialize()
- virtual void Register()
- virtual Bool_t ProcessHits(CBMVolume v0)
- virtual void EndOfEvent()
- virtual void Print() const
- virtual void Reset()
- ClassDef(CBMMyDet,1) //CBMMyDet
- private
- TClonesArray MyDetPoint
- //
- endif //RICH_H
13Detector Constructor
- CBMTrackerCBMTracker(const char name, Bool_t
Active) - CBMDetector(name,Active),
-
- fTrackerCollection new TClonesArray("CBMSTSPo
int")
14ConstructGeometry()
- If the CBM standard ASCII format for detector or
module description is used, you do not need to
implements this function - If you use another format or need additional
information to be added, then you have to
overwrite this function, e.g. TRD and RICH
15ConstructGeometry() - Example 1
- void CBMCaveConstructGeometry()
- TGeoMCGeometry vmcGeo(TGeoMCGeometry )
TGeoMCGeometryInstance() - if(vmcGeo0) vmcGeo new TGeoMCGeometry("CBM
Geometry", "cbm") - world0 2000 world1 2000
world2 2000 - TString Name"air"
- TGeoMedium air 0
- Int_t nair 0
- if ( (air gGeoManager-gtGetMedium(Name.Data()
)) ) nair air-gtGetId() - TString name("world")
- Int_t VolId vmcGeo-gtGsvolu(name.Data(),
"BOX", nair , world, 3) - CBMVolume aVolnew CBMVolume(name,0,1)
- CBMDetectorvList-gtaddVolume( aVol )
- TGeoVolume volgGeoManager-gtGetVolume(VolId)
- gGeoManager-gtSetTopVolume(vol)
16ConstructGeometry() - Example 2
- void CBMRichConstructGeometry()
- CBMModuleConstructGeometry()
- // optical properties
- TGeoMedium richGas gGeoManager-gtGetMedium("RI
CHgas") - const Int_t NUMENTRIES 2
- Double_t ppckovNUMENTRIES 4.1E-10, 2.07E-9
- //rich gas
- Double_t rindexGasNUMENTRIES 1.000298,
1.000298 //N2 - Double_t absorptionGasNUMENTRIES 1.0e03,
1.0e03 - Double_t efficiencyGasNUMENTRIES 1.,1.
- gMC-gtSetCerenkov (richGas-gtGetId(),NUMENTRIES,ppc
kov, absorptionGas,efficiencyGas,rindexGas)
17Initialize()
- If you do not need any special initialization of
your detector, then do not implement this method.
Otherwise use - MyDetInitialize()
-
- CBMDetectorInitialize() // Has to be called
- .....Your Code
18Register()
- This method is called internally from the
initialized function - void CBMTrackerRegister()
-
- // Registers the hits collection in Root
manager. - //This will create a branch STSPoint in the
output tree - CBMRootManagerInstance()-gtRegister("STSPoint
","STS", fTrackerCollection)
19AddHit()
- This method is called usually from the
ProcessHit() to add a new object to the container
(TClonesArray) - CBMSTSPoint CBMTrackerAddHit()
-
- // Creates a new hit in the TClonesArray.
- TClonesArray ref fTrackerCollection
- Int_t size ref.GetEntriesFast()
- return new(refsize) CBMSTSPoint()
-
20ProcessHits(CBMVolume v) (1)
- This Method is call from the Stepping in each
event - Bool_t CBMTrackerProcessHits(CBMVolume v)
-
- // Creates hits (in stepping).
- Double_t edep gMC-gtEdep()
- if (edep0.0) return kFALSE
- // cut on energy
- if (gMC-gtEtot() lt 0.05 ) return kFALSE
-
- CBMSTSPoint mcPoint AddHit()
- mcPoint-gtSetTrackID (gMC-gtGetStack()-gtGetCurrent
TrackNumber()) - // Chamber no
- mcPoint-gtSetDetectorID(v-gtgetMCid())
21ProcessHits(CBMVolume v) (2)
- mcPoint-gtSetELoss (edep) // Energy
deposit - mcPoint-gtSetEtot(gMC-gtEtot()) // total Energy
- mcPoint-gtSetTime( gMC-gtTrackTime())
- mcPoint-gtSetLength(gMC-gtTrackLength() )
- TLorentzVector pos // Position
- gMC-gtTrackPosition(pos)
- mcPoint-gtSetPos (TVector3(pos.X(), pos.Y(),
pos.Z())) - TLorentzVector mom // Momentum
- gMC-gtTrackMomentum(mom)
- mcPoint-gtSetMom (TVector3(mom.X(), mom.Y(),
mom.Z())) - return kTRUE
22ProcessHits(CBMVolume v)
- Bool_t CBMRichProcessHits(CBMVolume v)
-
- TParticle part gMC-gtGetStack()-gtGetCurrentTrac
k() - Int_t gcode part-gtGetPdgCode()
- if (gcode 50000050) //check if a Cerenkov
photon - .............................
- return kTRUE
- else
- return kFALSE
-
-
23EndOfEvent()
- This method is called at the end of processing an
event - void CBMTrackerEndOfEvent()
-
- // Prints hits collection (if verbose)
- if (fVerboseLevelgt0) Print()
- Reset()
24Reset()
- This method is called after processing an event
- void CBMTrackerReset()
-
- // Reset hits collection
- fTrackerCollection-gtClear()
-
25Additional Methods in the CBMDetector
- These Methods can be overloaded in your detector
- virtual void BeginEvent()
- virtual void BeginPrimary()
- virtual void PreTrack()
- virtual void PostTrack()
- virtual void FinishPrimary()
26Creating the Library
- Create a directory MyDet
- In this directory create two other directories
src and include - download the Makefile from the webpage and copy
it to MyDet, put the name of your package (MyDet)
in the Makefile http//www-linux.gsi.de/cbmsim/cb
m_vmc_doc/Makefile_example.htm - geant4vmc Makefile PACKAGE
 The name of your package - Calling Make will create a libMyDet.so in
cbm_vmc/lib directory
27Simulation Macro
- Load the Libraries
- Create the Run Manager
- Choose Simulation engine
- Choose an output file name
- Create Modules and detectors and add them to the
Run Manager - Create and Set the Event generator(s)
- Create and set the Magnetic field
- Initialize and run the simulation
28Simulation Macro loading Libs
// Load basic ROOT libraries gROOT-gtLoadMacro("
../basiclibs.C") basiclibs() // Load CBM
modular libraries gSystem-gtLoad("libCbm")
gSystem-gtLoad("libPassive") gSystem-gtLoad("li
bGen") gSystem-gtLoad("libSTS")
gSystem-gtLoad("libTrd") gSystem-gtLoad("libTof
") gSystem-gtLoad("libRich") gSystem-gtLoad("li
bITrack")
29Simulation Macro
-
- //create the Run Manager Class
- CBMRun fRun new CBMRun()
-
- // set the MC version used
- fRun-gtSetName("TGeant4") //for G3 use
"TGeant3" -
- // chose an output file name
- fRun-gtSetOutputFile("test.root")
30Simulation Macro- Create Modules
- CBMModule Cave new CBMCave("WORLD")
- fRun-gtAddModule(Cave)
- CBMModule Target new CBMTarget("Target")
- Target-gtSetGeometryFileName("PASSIVE/TARGET",
"v03a") - fRun-gtAddModule(Target)
- CBMModule Pipe new CBMPIPE("PIPE")
- Pipe-gtSetGeometryFileName("PASSIVE/PIPE",
"v03a") - fRun-gtAddModule(Pipe)
- CBMModule Magnet new CBMMagnet("MAGNET")
- Magnet-gtSetGeometryFileName("PASSIVE/MAGNET",
"v03a") - fRun-gtAddModule(Magnet)
31Simulation Macro- Create Detectors
- CBMDetector STS new CBMTracker("STS", kTRUE)
- STS-gtSetGeometryFileName("STS/STS", "v03c")
- fRun-gtAddModule(STS)
- CBMDetector TOF new CBMTof("TOF", kTRUE )
- TOF-gtSetGeometryFileName("TOF/TOF", "v03_v10")
- fRun-gtAddModule(TOF)
- CBMDetector TRD new CBMTRD("TRD",kFALSE )
- TRD-gtSetGeometryFileName("TRD/TRD", "v04b_9" )
- fRun-gtAddModule(TRD)
32Simulation Macro-Event Generators
- CBMUrqmdGenerator fGen1 new CBMUrqmdGenerator("0
0-03fm.100ev.f14") - CBMPlutoGenerator fGen2 new CBMPlutoGenerator("j
psi.root") - CBMParticleGenerator fGen3 new
CBMParticleGenerator() - // use SetVertex, SetMomentum, ... etc , to set
the parameters of this Generator - //name, z, a , q , e(GeV), m
- CBMNewIon fIon new CBMNewIon("My_Au", 79, 197,
79, 25.,183.47324) - fRungtAddNewIon(fIon)
- CBMIonGenerator fGen4 new CBMIonGenerator(fIon)
- // use SetVertex, SetMomentum, ... etc , to set
the parameters of this Generator - CBMAsciiGenerator fGen5 new CBMAsciiGenerator(fil
ename.txt)
33Event Generators-Mixing generators
- CBMMixedGen fGen new CBMMixedGen("Mix")
- fGen-gtAddGenerator(fGen1)
- fGen-gtAddGenerator(fGen2)
- fGen-gtAddGenerator(fGen3)
- fGen-gtAddGenerator(fGen4)
- fGen-gtAddGenerator(fGen5)
- fRun-gtSetGenerator(fGen)
34Simulation Macro-Magnetic Field
- // setting a field map
- CBMFieldMap fMagField new CBMFieldMap("FIELD.v03
b.map") - // setting a constant field
- CBMConstField fMagFieldnew CBMConstField()
- fMagField-gtSetFieldXYZ(0, 10 ,0 ) // values are
in kG - // MinX-74, MinY-39,MinZ-22 ,MaxX74, MaxY39
,MaxZ160 ) - fMagField-gtSetFieldRegions(-74, -39 ,-22 , 74, 39
, 160 ) // values are in cm - fRun-gtSetField(fMagField)
35Simulation Macro- Run Simulation
- fRun-gtInit() // Initialize the simulation
- Simulation
- 1. Initialize the VMC (Simulation)
- 2. Initialize Tasks (if they are used in
Simulation) - fRun-gtRun(NoOfEvent) //Run the Simulation
36Reading Output files
- The Simulation output files are ROOT files, the
data in the TTree can be accessed in plain ROOT
(using TBrowser or Tree Viewer). - If you write a macro to read the file you have to
load the CBM libraries. - if you want to visualize the geometry, you have
to load the ROOT TGeo library. - i.e. gSystem-gtLoad("libGeom") is needed to be
able to browse the geometry
37Output File
CBMMCApplication
Geometry
Folder Structure
Output Tree
38The CBM VMC Application
- To get the Application from Macro
- Tfile f("test.root")
- CBMMCApplication fcbmf.Get("CBM")
- To get the Application in compiled code
- CBMMCApplication fcbmCBMMCApplicationInstance(
)
39The CBM VMC Application
- fcbm-gtGetDetector(const char DetName)
- Returns a pointer to the detector "DetName"
- fcbm-gt CBMMagField GetField()
- Returns the magnetic field used for this
simulation - fcbm-gt CBMGenerator GetGenerator()
- Returns the event generator used for this
simulation
40The Magnetic Field
- To get the Magnetic field
- CBMMagField fMag fcbm-gt CBMMagField
GetField() - Now to reconstruct the field in Memory
- if you a const Field was used in simulation, this
will be done automatically. - if a field map was used
- CBMFieldMap fMap dynamic_castlt CBMFieldMap gt
(fMag) - fMap-gtInit() will reconstruct the field in
moemory - In both cases you can now use
- fcbm-gtGetFieldValue( const Double_t Point3,
Double_t Bfield3 ) - This will get the field value Bfield3 at
Point3
41The Output Tree
Detector Braches
Stack
42Reading from the Tree
- To access a branch from the Tree
- Get a pointer to the ROOT Manager
- CBMRootManager fManager CBMRootManagerInstance
() - Let the ROOT manager activate your branch
- fManager-gtActivateBranch(const char BrName)
- BrName The branch name
- e.g
- TClonesArray STSpts
- (TClonesArray ) fManger-gtActivateBranch("STSPoi
nt")