Differences between Macro and Source file

Compared the the macro there are some changes in the source file which is needed for compilation. First of all you need to include the Header Files of the used Classes.

#include "TStopwatch.h"
#include "CbmRunSim.h"
#include "CbmModule.h"
#include "CbmMagnet.h"
#include "CbmPipe.h"
#include "CbmCave.h"
#include "CbmTarget.h"
#include "CbmDetector.h"
#include "CbmSts.h"
#include "CbmTof.h"
#include "CbmTrd.h"
#include "CbmEcal.h"
#include "CbmRich.h"
#include "CbmPrimaryGenerator.h"
#include "CbmUrqmdGenerator.h"
#include "CbmParticleGenerator.h"
#include "CbmIonGenerator.h"
#include "CbmRuntimeDb.h"
#include "CbmParRootFileIo.h"
#include "CbmEcalContFact.h"
#include "CbmTrdContFact.h"
#include "CbmRichContFact.h"
#include "CbmStsContFact.h"
#include "CbmTofContFact.h"
#include "CbmBaseContFact.h"
#include "CbmMuchContFact.h"
#include "CbmPassiveContFact.h"
#include "CbmFieldContFact.h"

In the Source file there has to be a main function which is not present in the macro run.C.

int main()
{
  TStopwatch timer; 
  timer.Start();
  gDebug=0;

You don't need to load the shared libraries because you link these library into your executable.

  // Load basic libraries
//  gROOT->LoadMacro("$VMCWORKDIR/gconfig/basiclibs.C");
//  basiclibs();

  // Load this example libraries
//  gSystem->Load("libGeoBase");
//  gSystem->Load("libParBase");
//  gSystem->Load("libField");
//  gSystem->Load("libCbm");
//  gSystem->Load("libPassive");
//  gSystem->Load("libSts");
//  gSystem->Load("libTof");
//  gSystem->Load("libRich");
//  gSystem->Load("libTrd");
//  gSystem->Load("libEcal");
//  gSystem->Load("libGen");

  CbmRunSim *fRun = new CbmRunSim();

The Container Factories in the normal CbmRoot are defined static outside of the Classes that they are created when loading the shared libraries. This doesn't work if you want to link against the CbmRoot libraries. Due to this the Container factories have to be created in the main routine.

  static CbmEcalContFact gCbmEcalContFact;
  static CbmTrdContFact gCbmTrdContFact;
  static CbmRichContFact gCbmRichContFact;
  static CbmStsContFact gCbmStsContFact;
  static CbmTofContFact gCbmTofContFact;
  static CbmBaseContFact gCbmBaseContFact;
  static CbmMuchContFact gCbmMuchContFact;
  static CbmPassiveContFact gCbmPassiveContFact;
  static CbmFieldContFact gCbmFieldContFact;

From here on there is no difference between the macro and the source file.

  // set the MC version used
  // ------------------------

  fRun->SetName("TGeant3");
  // Choose the Geant Navigation System
  // fRun->SetGeoModel("G3Native");
  
  fRun->SetOutputFile("auaumbias.root");

  // Set Material file Name
  //-----------------------

  fRun->SetMaterials("media.geo");
  
  // Create and add detectors
  //-------------------------

  CbmModule *Cave= new CbmCave("CAVE");
  Cave->SetGeometryFileName("cave.geo");
  fRun->AddModule(Cave);

  CbmModule *Pipe= new CbmPipe("PIPE");
  Pipe->SetGeometryFileName("pipe.geo");
  fRun->AddModule(Pipe);
  
  
  CbmModule *Magnet= new CbmMagnet("MAGNET");
  // 1- Active shielding Geometry
  Magnet->SetGeometryFileName("magnet_active.geo");
  // 2- Iron Magnet
  // Magnet->SetGeometryFileName("magnet_iron.geo");
  fRun->AddModule(Magnet);
  
  CbmDetector *Sts= new CbmSts("STS", kTRUE);
  Sts->SetGeometryFileName("sts.geo");
  fRun->AddModule(Sts);

  
  CbmModule *Target= new CbmTarget("Target");
  Target->SetGeometryFileName("target.geo");
  fRun->AddModule(Target);      

  CbmDetector *Tof= new CbmTof("TOF", kTRUE );
  Tof->SetGeometryFileName("tof.geo");
  fRun->AddModule(Tof);
   
  CbmDetector *Trd= new CbmTrd("TRD",kTRUE );
  Trd->SetGeometryFileName("trd_9.geo");
  fRun->AddModule(Trd);

/*
  CbmDetector *Rich= new CbmRich("RICH", kTRUE);
  Rich->SetGeometryFileName("rich.geo");
  fRun->AddModule(Rich);
*/

  //CbmDetector *Ecal= new CbmEcal("ECAL", kTRUE);
  //Ecal->SetGeometryFileName("ecal.geo");
  //fRun->AddModule(Ecal);


 // Create and Set Event Generator
 //-------------------------------

  CbmPrimaryGenerator* primGen = new CbmPrimaryGenerator();
  fRun->SetGenerator(primGen);

 // Urqmd  Generator
//  CbmUrqmdGenerator* urqmdGen = new CbmUrqmdGenerator("../../input/00-03fm.100ev.f14");
//  primGen->AddGenerator(urqmdGen);

 // Particle Generator
 //  CbmParticleGenerator* partGen = new CbmParticleGenerator(211, 10, 1., 1.,
 //  2);
 //  primGen->AddGenerator(partGen);
 
 // Ion Generator
     CbmIonGenerator *fIongen= new CbmIonGenerator(79, 197,79,1, 0.,0., 25, 0.,0.,-1.);
     primGen->AddGenerator(fIongen);


 // Field Map Definition
 // --------------------
  // 1- Reading the new field map in the old format

     // CbmFieldMap *fMagField= new CbmFieldMap("FIELD.v04_pavel.map");
   // Constant Field
     //  CbmConstField *fMagField=new CbmConstField();
     //  fMagField->SetFieldXYZ(0, 14 ,0 ); // values are in kG
     // MinX=-75, MinY=-40,MinZ=-12 ,MaxX=75, MaxY=40 ,MaxZ=124 );  // values are in cm
     //  fMagField->SetFieldRegions(-74, -39 ,-22 , 74, 39 , 160 );

  // 2- Reading the new field map in the new format

//  CbmField *fMagField= new CbmFieldMapSym3("FieldActive");
  // Active Shielding

//   fRun->SetField(fMagField);
   
 //  fRun->SetStoreTraj(kTRUE)
   
   fRun->Init();


 // -Trajectories Visualization (TGeoManager Only )
 // -----------------------------------------------

;
 // Set cuts for storing the trajectpries
  /* CbmTrajFilter* trajFilter = CbmTrajFilter::Instance();
     trajFilter->SetStepSizeCut(0.01); // 1 cm
     trajFilter->SetVertexCut(-2000., -2000., 4., 2000., 2000., 100.);
     trajFilter->SetMomentumCutP(10e-3); // p_lab > 10 MeV
     trajFilter->SetEnergyCut(0., 1.02); // 0 < Etot < 1.04 GeV
     trajFilter->SetStorePrimaries(kTRUE);
     trajFilter->SetStoreSecondaries(kTRUE);
   */


  // Fill the Parameter containers for this run
  //-------------------------------------------

  CbmRuntimeDb *rtdb=fRun->GetRuntimeDb();
  Bool_t kParameterMerged=kTRUE;
  CbmParRootFileIo* output=new CbmParRootFileIo(kParameterMerged);
  output->open("parfiles/testparams.root");
  rtdb->setOutput(output);
  rtdb->saveOutput();
  rtdb->print();

  // Transport nEvents
  // -----------------

  Int_t nEvents = 3;
  fRun->Run(nEvents);



  timer.Stop();
  Double_t rtime = timer.RealTime();
  Double_t ctime = timer.CpuTime();
 printf("RealTime=%f seconds, CpuTime=%f seconds\n",rtime,ctime);
}  

Changes in the CbmRoot source files

There are some changes in the source files of the CbmRoot framework which are necessary to link against the CbmRoot libraries. All necessary changes are described below and all the old and new source files are attached to this webpage.

Container factories

In all files inheriting from CbmContFact the construction of the static variable of this class outside the class has to be commented or deleted. For example see the first lines from CbmTrdContFact.cxx. Here the line
static CbmTrdContFact gCbmTrdContFact;
has to be commented

//*-- AUTHOR : Ilse Koenig
//*-- Created : 25/10/2004

/////////////////////////////////////////////////////////////
//
//  CbmTrdContFact
//
//  Factory for the parameter containers in libTrd
//
/////////////////////////////////////////////////////////////

using namespace std;
#include "CbmTrdContFact.h"
#include "CbmRuntimeDb.h"
#include "CbmGeoTrdPar.h"
#include <iostream>
#include <iomanip>

ClassImp(CbmTrdContFact)

static CbmTrdContFact gCbmTrdContFact;   // This line has to be commented

CbmTrdContFact::CbmTrdContFact() {
  // Constructor (called when the library is loaded)
  fName="CbmTrdContFact";
  fTitle="Factory for parameter containers in libTrd";
  setAllContainers();
  CbmRuntimeDb::instance()->addContFactory(this);

....

}

This has to be done in the following files:

  • sts/CbmStsContFact.cxx
  • trd/CbmTrdContFact.cxx
  • tof/CbmTofContFact.cxx
  • rich/CbmRichContFact.cxx
  • base/CbmBaseContFact.cxx
  • ecal/CbmEcalContFact.cxx
  • much/CbmMuchContFact.cxx
  • field/CbmFieldContFact.cxx
  • passive/CbmPassiveContFact.cxx

base/!CbmMCApplication.h

You have to comment out the definition of the GetEvent(Int_t event) function, because this function is defined but not implemented. This will be changed in the CVS in near future.

base/!CbmRunSim.cxx

In this file during the initilization normaly some ROOT macros are called to load the shared libraries of GEANT3. This calls doesn't work when the library is linked to an executable. To overcome this problem the needed libraries are explicitly linked to the executable. But the calls to the macros inside CbmRunSim::Init ave to be commented. In the moment this is only done for GEANT3. If one wants to link an executable with GEANT4 this has to be done.


    fOutFile=fRootManager->OpenOutFile(Outfname);
    if (strcmp(GetName(),"TGeant4") == 0 ) {
      TString g4LibMacro = work + "/gconfig/g4libs.C";
      gROOT->LoadMacro(g4LibMacro.Data());
      gROOT->ProcessLine("g4libs()");
      gSystem->Load("libCbmG4");
      TString g4Macro = work + "/gconfig/g4Config.C";
      fApp->InitMC(g4Macro.Data());
    }else{
     /*                                                                                           // The next 3 lines have to be commented out.
      TString g3LibMacro = work + "/gconfig/g3libs.C";
      gROOT->LoadMacro(g3LibMacro.Data());
      gROOT->ProcessLine("g3libs()");
      */
      TString g3Macro = work+"/gconfig/g3Config.C";
      fApp->InitMC(g3Macro.Data());
    }

base/!CbmMCApplikation.cxx

In this file normally the macro defining the physics for GEANT3 is called. Again this doesn't work when runing an executable. To vercome this problem the physics definition has to be hardcoded in this file. The changes in CbmMCApplication.cxx are shown below. One has also to include the following two header files
#include "TGeant3.h"
#include "TGeant3TGeo.h"

First the old version of the initilization

void CbmMCApplication::InitMC(const char* setup)
{

   cout << " CbmMCApplication::InitMC   " << endl;
// Initialize MC.
// ---
  gROOT->LoadMacro(setup);
  gInterpreter->ProcessLine("Config()");
  gMC->SetStack(fStack);
   gMC->Init();
  gMC->BuildPhysics();
  if (TString(gMC->GetName()) == "TGeant3")  mcVersion = 0 ; 
  else  mcVersion=1;
  

   fTrajFilter = CbmTrajFilter::Instance();
 // cout << " selected Geant  version " << mcVersion << endl;
  cout << " -I- CbmMCApplication:: Monte carlo Engine Initialisation " <<endl;
}

And now the changed version

void CbmMCApplication::InitMC(const char* setup)
{

   cout << " CbmMCApplication::InitMC   " << endl;
// Initialize MC.
// ---
//  gROOT->LoadMacro(setup);
//  gInterpreter->ProcessLine("Config()");
   CbmRunSim *fRun = CbmRunSim::Instance();
   TString* gModel = fRun->GetGeoModel();
   TGeant3* geant3 = NULL;
   if ( strncmp(gModel->Data(),"TGeo",4) == 0 ) {
     geant3
          = new  TGeant3TGeo("C++ Interface to Geant3");
      cout << "-I- G3Config: Geant3 with TGeo has been created."
           << endl;
   }else{
     geant3
          = new  TGeant3("C++ Interface to Geant3");
      cout << "-I- G3Config: Geant3 native has been created."
             << endl;
   }

   // ******* GEANT3 configuration for simulated Runs  *******
    geant3->SetTRIG(1);         //Number of events to be processed
    geant3->SetSWIT(4, 10);
    geant3->SetDEBU(0, 0, 1);
    geant3->SetDCAY(1);
    geant3->SetPAIR(1);
    geant3->SetCOMP(1);
    geant3->SetPHOT(1);
    geant3->SetPFIS(0); //
    geant3->SetDRAY(1);
    geant3->SetANNI(1);
    geant3->SetBREM(1);
    geant3->SetMUNU(1);
    geant3->SetCKOV(1);
    geant3->SetHADR(1);         //Select pure GEANH (HADR 1) or GEANH/NUCRIN (HADR 3)
    geant3->SetLOSS(1);
    geant3->SetMULS(1);
    geant3->SetRAYL(1);
    geant3->SetSTRA(0);
    geant3->SetAUTO(1);         //Select automatic STMIN etc... calc. (AUTO 1) or manual (AUTO 0)
    geant3->SetABAN(0);         //Restore 3.16 behaviour for abandoned tracks
    geant3->SetOPTI(2);         //Select optimisation level for GEANT geometry searches (0,1,2)
    geant3->SetERAN(5.e-7);


    Float_t cut =  1.e-3;        // 1MeV cut by default
    Float_t tofmax = 1.e10;
    // Float_t cut2 =  1.e-10; // 1 keV?
    Float_t cut2 = cut;
    Float_t cut3 =50.e-6 ; // Threshold for delta electrons
    // set cuts here 
    //             GAM ELEC NHAD CHAD MUON EBREM MUHAB EDEL MUDEL MUPA TOFMAX
//    geant3->SetCUTS(cut2, cut2, cut2, cut2, cut, cut2, cut2, cut3, cut2, cut2,
//                    tofmax);
    geant3->SetCUTS(cut2, cut2, cut2, cut2, cut, cut2, cut2, cut2, cut2, cut2,
                    tofmax);

  gMC->SetStack(fStack);
   gMC->Init();
  gMC->BuildPhysics();
  if (TString(gMC->GetName()) == "TGeant3")  mcVersion = 0 ; 
  else  mcVersion=1;
  

   fTrajFilter = CbmTrajFilter::Instance();
 // cout << " selected Geant  version " << mcVersion << endl;
  cout << " -I- CbmMCApplication:: Monte carlo Engine Initialisation " <<endl;
}

Makefile

The last thing which is needed is the Makefile which is shown below

all:   run

run:   
   gcc -g -c ${CFLAGS} -I/home/uhlig/cbm/build/include \
   -I/opt/hep_physics/root/include run.cxx
   gcc ${CFLAGS} -g run.o -o  run -L/home/uhlig/cbm/build/lib   \
   -L/opt/hep_physics/root/lib -L/opt/hep_physics/generators/lib   \
   -L${GEANT3LIBDIR} -L${GEANT4LIBDIR} -L${GEANT4VMCLIBDIR}   \
   -L/opt/hep_physics/root/lib -ldl -lGeom -lMinuit      \
   -lGeomPainter -lGui -lVMC -lPhysics -lEG -lEGPythia6 -lPythia6    \
   -lPluto  -ldummies -lgeant321 -lGeoBase -lParBase -lField    \
   -lCbm -lPassive -lSts -lTof -lRich -lTrd -lEcal -lGen -lMuch
   
clean:   
   rm run.o run   

This topic: Homepages > WebHome > CreateHomepageTopic > CbmRootFlorianUhlig
Topic revision: 2006-07-04, FlorianUhlig
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding CBM Wiki? Send feedback
Imprint (in German)
Privacy Policy (in German)