11.05.2004cbm software week- m. al-turany 1 cbm simulation & analysis framework simulation part...

42
11.05.2004 CBM Software week- M. Al-Turany 1 CBM Simulation & Analysis Framework CBM Simulation & Analysis Framework Simulation Part Simulation Part M. Al-Turany, D. Bertini

Upload: horatio-moore

Post on 02-Jan-2016

215 views

Category:

Documents


0 download

TRANSCRIPT

11.05.2004 CBM Software week- M. Al-Turany 1

CBM Simulation & Analysis FrameworkCBM Simulation & Analysis Framework

Simulation PartSimulation Part

M. Al-Turany, D. Bertini

11.05.2004 CBM Software week- M. Al-Turany 2

OutlineOutline

• Software distribution

• Adding Modules and Detectors– What to implement ?– Creating the library – Creating the simulation Macro– The output file structure

11.05.2004 CBM Software week- M. Al-Turany 3

Software distributionSoftware distribution

• The CBM software is distributed via anonymous CVS

• CVS logincvs -d :pserver:[email protected]:/misc/cbmsim/CVS/cbmrepos  login

    password:   Please type nothing just press enter

• CVS Checkout cvs -d :pserver:[email protected]:/misc/cbmsim/CVS/cbmrepos  checkout cbm_vmc

• CVS Updatecvs -d :pserver:[email protected]:/misc/cbmsim/CVS/cbmrepos  update

11.05.2004 CBM Software week- M. Al-Turany 4

Building the softwareBuilding the software

• make:– in the cbm_vmc directory will build everything– in sub-directory will build only the corresponding library

• make analysisThis 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.

11.05.2004 CBM Software week- M. Al-Turany 5

ROOT

Run Manager

Virtual MC

G3 G4 FLUKA

Pluto

Ion Generator

Particle Generator

ASCIIPIPE

Target

STS

TRD

Cave

TOF

Magnet

RICH

Generators

Mixed Generator

Urqmd

Magnetic

Field

Module

Detector

GeometryManager

IO Manager

Tasks ListDelta

Tracking

Field Map

CBM Analysis and Simulation FrameworkCBM Analysis and Simulation Framework

digitizers

11.05.2004 CBM Software week- M. Al-Turany 6

What is needed to add a detector or a Module ?What 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

11.05.2004 CBM Software week- M. Al-Turany 7

Material DefinitionMaterial Definitioncarbondioxide 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 nameComposition

Density

Single element Fractional mass

Mixture of Composite

11.05.2004 CBM Software week- M. Al-Turany 8

Geometry definitionGeometry definition

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

Volume name

Sensitivity flag (0,1)

Mother volume

Transformations

MaterialShape name

Shape parameters

11.05.2004 CBM Software week- M. Al-Turany 9

Creating a Module class – definition Creating 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

11.05.2004 CBM Software week- M. Al-Turany 10

Creating a Module class – Implementation Creating a Module class – Implementation

#include "CBMMagnet.h"

CBMMagnet::CBMMagnet(const char * name, const char *Title)

:CBMModule(name ,Title)

{

}

CBMMagnet::~CBMMagnet(){}

CBMMagnet::CBMMagnet(){}

ClassImp(CBMMagnet)

11.05.2004 CBM Software week- M. Al-Turany 11

Creating a detector class – definition (1)Creating 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();

11.05.2004 CBM Software week- M. Al-Turany 12

Creating a detector class – definition (2)Creating a detector class – definition (2)

virtual ConstructGeometry();virtual void Initialize();

virtual void Register(); virtual Bool_t ProcessHits(CBMVolume *v=0); virtual void EndOfEvent(); virtual void Print() const; virtual void Reset();

ClassDef(CBMMyDet,1) //CBMMyDet

private: TClonesArray *MyDetPoint;

}; //#endif //RICH_H

11.05.2004 CBM Software week- M. Al-Turany 13

Detector Constructor Detector Constructor

CBMTracker::CBMTracker(const char * name, Bool_t Active)

: CBMDetector(name,Active),

{

fTrackerCollection = new TClonesArray("CBMSTSPoint");

}

11.05.2004 CBM Software week- M. Al-Turany 14

ConstructGeometry()ConstructGeometry()

• 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

11.05.2004 CBM Software week- M. Al-Turany 15

ConstructGeometry() - Example 1ConstructGeometry() - Example 1

void CBMCave::ConstructGeometry() {

TGeoMCGeometry *vmcGeo=(TGeoMCGeometry *) TGeoMCGeometry::Instance();

if(vmcGeo==0) vmcGeo = new TGeoMCGeometry("CBM Geometry", "cbm");

world[0] = 2000; world[1] = 2000; world[2] = 2000;

TString Name="air";

TGeoMedium * air = 0;

Int_t nair = 0 ;

if ( (air = gGeoManager->GetMedium(Name.Data())) ) nair = air->GetId();

TString name("world");

Int_t VolId= vmcGeo->Gsvolu(name.Data(), "BOX", nair , world, 3);

CBMVolume *aVol=new CBMVolume(name,0,1);

CBMDetector::vList->addVolume( aVol );

TGeoVolume *vol=gGeoManager->GetVolume(VolId);

gGeoManager->SetTopVolume(vol);

}

11.05.2004 CBM Software week- M. Al-Turany 16

ConstructGeometry() - Example 2ConstructGeometry() - Example 2

void CBMRich::ConstructGeometry() { CBMModule::ConstructGeometry();

// optical properties TGeoMedium * richGas = gGeoManager->GetMedium("RICHgas") ; const Int_t NUMENTRIES = 2; Double_t ppckov[NUMENTRIES] = { 4.1E-10, 2.07E-9 };

//rich gas Double_t rindexGas[NUMENTRIES] = { 1.000298, 1.000298 }; //N2 Double_t absorptionGas[NUMENTRIES] = { 1.0e+03, 1.0e+03 }; Double_t efficiencyGas[NUMENTRIES] = {1.,1.}; gMC->SetCerenkov (richGas->GetId(),NUMENTRIES,ppckov,

absorptionGas,efficiencyGas,rindexGas); }

11.05.2004 CBM Software week- M. Al-Turany 17

Initialize()Initialize()

• If you do not need any special initialization of your detector, then do not implement this method. Otherwise use:

MyDet::Initialize()

{

CBMDetector::Initialize() // Has to be called

.....Your Code

}

11.05.2004 CBM Software week- M. Al-Turany 18

Register()Register()

• This method is called internally from the initialized function

void CBMTracker::Register()

{

// Registers the hits collection in Root manager.

//This will create a branch STSPoint in the output tree

CBMRootManager::Instance()->Register("STSPoint","STS", fTrackerCollection);

}

11.05.2004 CBM Software week- M. Al-Turany 19

AddHit()AddHit()

• This method is called usually from the ProcessHit() to add a new object to the container (TClonesArray)

CBMSTSPoint* CBMTracker::AddHit()

{

// Creates a new hit in the TClonesArray.

TClonesArray& ref = *fTrackerCollection;

Int_t size = ref.GetEntriesFast();

return new(ref[size]) CBMSTSPoint();

}

11.05.2004 CBM Software week- M. Al-Turany 20

ProcessHits(CBMVolume *v) (1)ProcessHits(CBMVolume *v) (1)

• This Method is call from the Stepping in each event

Bool_t CBMTracker::ProcessHits(CBMVolume *v)

{

// Creates hits (in stepping).

Double_t edep = gMC->Edep();

if (edep==0.0) return kFALSE;

// cut on energy

if (gMC->Etot() < 0.05 ) return kFALSE;

CBMSTSPoint* mcPoint = AddHit();

mcPoint->SetTrackID (gMC->GetStack()->GetCurrentTrackNumber());

// Chamber no

mcPoint->SetDetectorID(v->getMCid());

11.05.2004 CBM Software week- M. Al-Turany 21

ProcessHits(CBMVolume *v) (2)ProcessHits(CBMVolume *v) (2)

mcPoint->SetELoss (edep); // Energy deposit mcPoint->SetEtot(gMC->Etot()); // total Energy mcPoint->SetTime( gMC->TrackTime()); mcPoint->SetLength(gMC->TrackLength() ); TLorentzVector pos; // Position gMC->TrackPosition(pos); mcPoint->SetPos (TVector3(pos.X(), pos.Y(), pos.Z()));

TLorentzVector mom; // Momentum gMC->TrackMomentum(mom); mcPoint->SetMom (TVector3(mom.X(), mom.Y(), mom.Z())); return kTRUE;}

11.05.2004 CBM Software week- M. Al-Turany 22

ProcessHits(CBMVolume *v) ProcessHits(CBMVolume *v)

Bool_t CBMRich::ProcessHits(CBMVolume *v)

{

TParticle *part = gMC->GetStack()->GetCurrentTrack();

Int_t gcode = part->GetPdgCode();

if (gcode == 50000050) { //check if a Cerenkov photon

.............................

return kTRUE;

}else{

return kFALSE;

}

}

11.05.2004 CBM Software week- M. Al-Turany 23

EndOfEvent()EndOfEvent()

• This method is called at the end of processing an event

void CBMTracker::EndOfEvent()

{

// Prints hits collection (if verbose)

if (fVerboseLevel>0) Print();

Reset();

}

11.05.2004 CBM Software week- M. Al-Turany 24

Reset()Reset()

• This method is called after processing an event

void CBMTracker::Reset()

{

// Reset hits collection

fTrackerCollection->Clear();

}

11.05.2004 CBM Software week- M. Al-Turany 25

Additional Methods in the CBMDetectorAdditional 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();

11.05.2004 CBM Software week- M. Al-Turany 26

Creating the LibraryCreating 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/cbm_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

11.05.2004 CBM Software week- M. Al-Turany 27

Simulation MacroSimulation 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

11.05.2004 CBM Software week- M. Al-Turany 28

Simulation Macro – loading LibsSimulation Macro – loading Libs

// Load basic ROOT libraries

gROOT->LoadMacro("../basiclibs.C");

basiclibs();

// Load CBM modular libraries

gSystem->Load("libCbm");

gSystem->Load("libPassive");

gSystem->Load("libGen");

gSystem->Load("libSTS");

gSystem->Load("libTrd");

gSystem->Load("libTof");

gSystem->Load("libRich");

gSystem->Load("libITrack");

11.05.2004 CBM Software week- M. Al-Turany 29

Simulation MacroSimulation Macro

//create the Run Manager Class

CBMRun *fRun = new CBMRun();

// set the MC version used

fRun->SetName("TGeant4"); //for G3 use "TGeant3"

// chose an output file name

fRun->SetOutputFile("test.root");

11.05.2004 CBM Software week- M. Al-Turany 30

Simulation Macro- Create ModulesSimulation Macro- Create ModulesCBMModule *Cave= new CBMCave("WORLD");

fRun->AddModule(Cave);

CBMModule *Target= new CBMTarget("Target");

Target->SetGeometryFileName("PASSIVE/TARGET", "v03a");

fRun->AddModule(Target);

CBMModule *Pipe= new CBMPIPE("PIPE");

Pipe->SetGeometryFileName("PASSIVE/PIPE", "v03a");

fRun->AddModule(Pipe);

CBMModule *Magnet= new CBMMagnet("MAGNET");

Magnet->SetGeometryFileName("PASSIVE/MAGNET", "v03a");

fRun->AddModule(Magnet);

11.05.2004 CBM Software week- M. Al-Turany 31

Simulation Macro- Create DetectorsSimulation Macro- Create Detectors

CBMDetector *STS= new CBMTracker("STS", kTRUE);

STS->SetGeometryFileName("STS/STS", "v03c");

fRun->AddModule(STS);

CBMDetector *TOF= new CBMTof("TOF", kTRUE );

TOF->SetGeometryFileName("TOF/TOF", "v03_v10");

fRun->AddModule(TOF);

CBMDetector *TRD= new CBMTRD("TRD",kFALSE );

TRD->SetGeometryFileName("TRD/TRD", "v04b_9" );

fRun->AddModule(TRD);

11.05.2004 CBM Software week- M. Al-Turany 32

Simulation Macro-Simulation Macro-Event GeneratorsEvent Generators

CBMUrqmdGenerator *fGen1= new CBMUrqmdGenerator("00-03fm.100ev.f14");

CBMPlutoGenerator *fGen2= new CBMPlutoGenerator("jpsi.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);

fRun>AddNewIon(fIon);

CBMIonGenerator *fGen4= new CBMIonGenerator(fIon);

// use: SetVertex, SetMomentum, ... etc , to set the parameters of this Generator

CBMAsciiGenerator fGen5= new CBMAsciiGenerator(filename.txt);

11.05.2004 CBM Software week- M. Al-Turany 33

Event GeneratorsEvent Generators-Mixing generators-Mixing generators

CBMMixedGen *fGen= new CBMMixedGen("Mix");

fGen->AddGenerator(fGen1);

fGen->AddGenerator(fGen2);

fGen->AddGenerator(fGen3);

fGen->AddGenerator(fGen4);

fGen->AddGenerator(fGen5);

fRun->SetGenerator(fGen);

11.05.2004 CBM Software week- M. Al-Turany 34

Simulation Macro-Magnetic FieldSimulation Macro-Magnetic Field

// setting a field map

CBMFieldMap *fMagField= new CBMFieldMap("FIELD.v03b.map");

// setting a constant field

CBMConstField *fMagField=new CBMConstField();

fMagField->SetFieldXYZ(0, 10 ,0 ); // values are in kG

// MinX=-74, MinY=-39,MinZ=-22 ,MaxX=74, MaxY=39 ,MaxZ=160 );

fMagField->SetFieldRegions(-74, -39 ,-22 , 74, 39 , 160 ); // values are in cm

fRun->SetField(fMagField);

11.05.2004 CBM Software week- M. Al-Turany 35

Simulation Macro- Run SimulationSimulation Macro- Run Simulation

fRun->Init(); // Initialize the simulation

Simulation:

1. Initialize the VMC (Simulation)

2. Initialize Tasks (if they are used in Simulation)

fRun->Run(NoOfEvent); //Run the Simulation

11.05.2004 CBM Software week- M. Al-Turany 36

Reading Output filesReading 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->Load("libGeom") is needed to be able to browse the geometry

11.05.2004 CBM Software week- M. Al-Turany 37

Output FileOutput FileCBMMCApplication

Geometry

Folder Structure

Output Tree

11.05.2004 CBM Software week- M. Al-Turany 38

The CBM VMC Application The CBM VMC Application

• To get the Application from Macro :– Tfile f("test.root");– CBMMCApplication *fcbm=f.Get("CBM");

• To get the Application in compiled code:– CBMMCApplication *fcbm=CBMMCApplication::Instance();

11.05.2004 CBM Software week- M. Al-Turany 39

The CBM VMC ApplicationThe CBM VMC Application

• fcbm->GetDetector(const char *DetName); – Returns a pointer to the detector "DetName"

• fcbm-> CBMMagField* GetField()– Returns the magnetic field used for this simulation

• fcbm-> CBMGenerator* GetGenerator(); – Returns the event generator used for this simulation

11.05.2004 CBM Software week- M. Al-Turany 40

The Magnetic Field The Magnetic Field

• To get the Magnetic field:

CBMMagField * fMag = fcbm-> 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_cast< CBMFieldMap *> (fMag)

• fMap->Init() will reconstruct the field in moemory

• In both cases you can now use :– fcbm->GetFieldValue( const Double_t Point[3], Double_t *Bfield[3] )

This will get the field value Bfield[3] at Point[3]

11.05.2004 CBM Software week- M. Al-Turany 41

The Output TreeThe Output Tree

Detector BrachesStack

11.05.2004 CBM Software week- M. Al-Turany 42

Reading from the TreeReading from the Tree

• To access a branch from the Tree:– Get a pointer to the ROOT Manager:

CBMRootManager *fManager= CBMRootManager::Instance();

– Let the ROOT manager activate your branch:fManager->ActivateBranch(const char *BrName) ;

BrName : The branch name

e.g:

TClonesArray * STSpts=

(TClonesArray *) fManger->ActivateBranch("STSPoint");