Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "11.05.2004CBM Software week- M. Al-Turany 1 CBM Simulation & Analysis Framework Simulation Part M. Al-Turany, D. Bertini."— Presentation transcript:

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

2 11.05.2004CBM Software week- M. Al-Turany 2 Outline Software distribution Adding Modules and Detectors –What to implement ? –Creating the library –Creating the simulation Macro –The output file structure

3 11.05.2004CBM Software week- M. Al-Turany 3 Software distribution The CBM software is distributed via anonymous CVS CVS login cvs -d :pserver:anonymous@www-linux.gsi.de:/misc/cbmsim/CVS/cbmrepos login password: Please type nothing just press enter CVS Checkout cvs -d :pserver:anonymous@www-linux.gsi.de:/misc/cbmsim/CVS/cbmrepos checkout cbm_vmc CVS Update cvs -d :pserver:anonymous@www-linux.gsi.de:/misc/cbmsim/CVS/cbmrepos update

4 11.05.2004CBM Software week- M. Al-Turany 4 Building 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.

5 11.05.2004CBM Software week- M. Al-Turany 5 ROOT Run Manager Virtual MC G3G4FLUKA Pluto Ion Generator Particle Generator ASCII PIPE Target STS TRD Cave TOF Magnet RICH Generators Mixed Generator Urqmd Magnetic Field Module Detector Geometry Manager IO Manager Tasks List Delta Tracking Field Map CBM Analysis and Simulation Framework digitizers

6 11.05.2004CBM Software week- M. Al-Turany 6 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

7 11.05.2004CBM Software week- M. Al-Turany 7 Material 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

8 11.05.2004CBM Software week- M. Al-Turany 8 Geometry 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 Material Shape name Shape parameters

9 11.05.2004CBM Software week- M. Al-Turany 9 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

10 11.05.2004CBM Software week- M. Al-Turany 10 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 11.05.2004CBM Software week- M. Al-Turany 11 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();

12 11.05.2004CBM Software week- M. Al-Turany 12 Creating a detector class – definition (2) virtualConstructGeometry(); 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

13 11.05.2004CBM Software week- M. Al-Turany 13 Detector Constructor CBMTracker::CBMTracker(const char * name, Bool_t Active) : CBMDetector(name,Active), { fTrackerCollection = new TClonesArray("CBMSTSPoint"); }

14 11.05.2004CBM Software week- M. Al-Turany 14 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

15 11.05.2004CBM Software week- M. Al-Turany 15 ConstructGeometry() - 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); }

16 11.05.2004CBM Software week- M. Al-Turany 16 ConstructGeometry() - 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); }

17 11.05.2004CBM Software week- M. Al-Turany 17 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 }

18 11.05.2004CBM Software week- M. Al-Turany 18 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); }

19 11.05.2004CBM Software week- M. Al-Turany 19 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(); }

20 11.05.2004CBM Software week- M. Al-Turany 20 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());

21 11.05.2004CBM Software week- M. Al-Turany 21 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; }

22 11.05.2004CBM Software week- M. Al-Turany 22 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; }

23 11.05.2004CBM Software week- M. Al-Turany 23 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(); }

24 11.05.2004CBM Software week- M. Al-Turany 24 Reset() This method is called after processing an event void CBMTracker::Reset() { // Reset hits collection fTrackerCollection->Clear(); }

25 11.05.2004CBM Software week- M. Al-Turany 25 Additional 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();

26 11.05.2004CBM Software week- M. Al-Turany 26 Creating 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 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

27 11.05.2004CBM Software week- M. Al-Turany 27 Simulation 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

28 11.05.2004CBM Software week- M. Al-Turany 28 Simulation 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");

29 11.05.2004CBM Software week- M. Al-Turany 29 Simulation 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");

30 11.05.2004CBM Software week- M. Al-Turany 30 Simulation Macro- Create Modules CBMModule *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);

31 11.05.2004CBM Software week- M. Al-Turany 31 Simulation 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);

32 11.05.2004CBM Software week- M. Al-Turany 32 Simulation Macro-Event 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);

33 11.05.2004CBM Software week- M. Al-Turany 33 Event 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);

34 11.05.2004CBM Software week- M. Al-Turany 34 Simulation 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);

35 11.05.2004CBM Software week- M. Al-Turany 35 Simulation 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

36 11.05.2004CBM Software week- M. Al-Turany 36 Reading 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

37 11.05.2004CBM Software week- M. Al-Turany 37 Output File CBMMCApplication Geometry Folder Structure Output Tree

38 11.05.2004CBM Software week- M. Al-Turany 38 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();

39 11.05.2004CBM Software week- M. Al-Turany 39 The 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

40 11.05.2004CBM Software week- M. Al-Turany 40 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 (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]

41 11.05.2004CBM Software week- M. Al-Turany 41 The Output Tree Detector Braches Stack

42 11.05.2004CBM Software week- M. Al-Turany 42 Reading 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");


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

Similar presentations


Ads by Google