How to get start the program?

ROOT Version: root_v6.28.04
Platform: Win10
Compiler: MVSC2019


Hello,everyone! Recently I am using root while studying an example of Geant4.

Geant4\geant4-v11.2.0.beta\examples\advanced\brachytherapy

There are a folder of files which run with root in this example, but I can’t find the entrance of the program. Do anyone know how to run the program?

I only know how to open ROOT files and plot functions related to “void xx()” using the command line, like “root XX.root”. How do I open this folder-style ROOT? I hope someone can provide some guidance. Thank you!

Website rules that I can’t post the link of package online, How can I show the details of the program?

In the same “command line” window where you are able to do “root XX.root”, just do “root” instead, to start ROOT interactive session; you should see something like this:

$ root
   ------------------------------------------------------------------
  | Welcome to ROOT 6.26/10                        https://root.cern |
  | (c) 1995-2021, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for linuxx8664gcc on Nov 16 2022, 10:42:54                 |
  | From tags/v6-26-10@v6-26-10                                      |
  | With c++ (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0                   |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q'       |
   ------------------------------------------------------------------

root [0]

then at that prompt you can do

new TBrowser;

to open a browser window in which you can see the files and you can double-click .root files to open them; however, to run .C macros (inside the interactive session) you should do:

.x mymacro.C

Check out the ROOT primer, manuals, etc. for more.

1 Like

Thank you for your words, I know how to run in interactive session, but it doesn’t work in the geant4 tutorial. I post some of the C++ codes as following.

analysis.C

{
// For Flexi source
// eventually convert from ASCII output files to ROOT files
/*
gROOT->ProcessLine(".L convert.C");
ReadASCII("EnergyDeposition_Flexi_livermore.out", "brachytherapy_Flexi_livermore.root");
ReadASCII("EnergyDeposition_Flexi_penelope.out", "brachytherapy_Flexi_penelope.root");
ReadASCII("EnergyDeposition_Flexi_opt0.out", "brachytherapy_Flexi_opt0.root");
ReadASCII("EnergyDeposition_Flexi_opt3.out", "brachytherapy_Flexi_opt3.root");
ReadASCII("EnergyDeposition_Flexi_opt4.out", "brachytherapy_Flexi_opt4.root");
*/

// g(r) is calculated from the root files 
gROOT->ProcessLine(".L TG43_relative_dose.C");
Read("Flexi", "livermore");
Read("Flexi", "penelope");
Read("Flexi", "opt0");
Read("Flexi", "opt3");
Read("Flexi", "opt4");
//gROOT->ProcessLine(".x compare.C");
// or...
// plot all results with the alternative EM physics constructors
gROOT->ProcessLine(".x compare_all.C");
// use compare.C when only one physics approach is used

// For Oncura source
/*gROOT->ProcessLine(".L TG43_relative_dose.C");
Read("Oncura", "livermore");
Read("Oncura", "penelope");
Read("Oncura", "opt0");
Read("Oncura", "opt3");
Read("Oncura", "opt4");
gROOT->ProcessLine(".x compare_6711.C");
//or ...
// gROOT->ProcessLine(".x compare_6711_all.C");
*/
}

compare.C

{
// Read reference data in granero.txt
FILE *fg1=fopen("granero.txt", "r");
Int_t n_points_granero =13;
Float_t x1[n_points_granero], y1[n_points_granero];
Float_t x, y;
Int_t ncols_granero;
Int_t nlines1 =0;

while(1)
 {
  ncols_granero = fscanf(fg1,"%f %f",&x, &y);
  if (ncols_granero<0) break;
 // std::cout << "x " << x << std::endl;
  x1[nlines1]=x;
  y1[nlines1]=y;
  nlines1++;
}

fclose(fg1);

// Read the results of the brachytherapy advanced example
// FlexiSorceMacro.mac with 280 M events
FILE *fg2=fopen("geant4.txt", "r");
Int_t n_points_geant4 =398;
Float_t x2[n_points_geant4], y2[n_points_geant4];
Int_t ncols_geant4;
Int_t nlines2 =0;

while(1)
 {
  ncols_geant4 = fscanf(fg2,"%f %f",&x, &y);
  if (ncols_geant4<0) break;
 // std::cout << "x " << x << std::endl;
  x2[nlines2]=x;
  y2[nlines2]=y;
  nlines2++;
}

fclose(fg2);

TGraph *gr1 = new TGraph (nlines1, x1, y1);
TGraph *gr2 = new TGraph (nlines2, x2, y2);

TCanvas *c1 = new TCanvas("c1","Graph Draw Options",
                             200,10,600,400);

gPad->SetLogy();

// draw the graph with axis, continuous line, and put
// a * at each point
gr1->SetTitle("Dose rate distribution");
gr1-> GetXaxis()->SetTitle("Distance from the centre (cm)");
gr1->GetYaxis()->SetTitle("Normalised dose rate distribution");
gr1->SetLineWidth(1);
gr1->SetMarkerColor(1);
gr1->SetMarkerStyle(20);
gr1->Draw("AP");

gr2->SetLineWidth(1);
gr2->SetMarkerColor(2);
gr2->SetMarkerStyle(21);
gr2->SetMarkerSize(0.5);
gr2->SetLineColor(2);
gr2->Draw("CP");

TLegend *leg = new TLegend(0.3, 0.5, 0.6, 0.8);
leg->SetFillColor(0);
leg->AddEntry(gr1, "Reference data", "lp");
leg->AddEntry(gr2, "Geant4 - 280 M events", "lp");
leg->Draw();


}

convert.C

void ReadASCII(TString source_file_ascii, TString output_file_root)
{

// This macro converts the results of the simulation stored in ASCII files to ROOT files. 
  ifstream in;
  in.open(source_file_ascii);

  Float_t x,y,z, edep;
  Int_t nlines = 0;
  TFile *f = new TFile(output_file_root,"RECREATE");
  TH2F *h20 = new TH2F("h20","h20",801,-100.125,100.125, 801, -100.125, 100.125);

   while (1) {
      in >> x >> y >> z >> edep;
      if (!in.good()) break;
    //  if (edep !=0.) printf("x=%8f, y=%8f, edep=%8f\n",x,y,edep);

      h20->Fill(x,y,edep);
      nlines++;
   }
   printf(" found %d points\n",nlines);

   in.close();

   f->Write();
}

TG43_relative_dose.C

void Read(TString source, TString physics_list){
// Create output file geant4_dose.txt with the dose rate distribution, calculated
// with the simulation results containted in brachytherapy.root

gROOT -> Reset();
TString fileName="brachytherapy_"+source+"_"+physics_list+".root";
std::cout<< "Reading " << fileName << std::endl;
//const char * c = fileName.c_str();
TFile f(fileName);
					     
Double_t Seed_length = 0.35; //seed length in cm

Double_t EnergyMap[401]; //2D map of total energy in "radial distance (mm)" and "angle (5 degrees)"
Int_t Voxels[401]; //the number of voxels used to provide dose to each element of the energy map
Double_t normDose[401]; //Energy map divided by voxels used to make cell, normalised to energy deposition at 1cm, 90 degrees
Double_t GeomFunction[401]; //Geometry Function, normalised to the geometry function at the reference point
Double_t GeometryFunctionZero;  //Geometry function at reference point, 1cm and 90 degrees
Double_t beta;  //beta angle for Geometry Function calculation
Double_t R;     //radial distance in cm
Double_t K;     //polar angle in radians
Double_t Radial[401]; //radial dose function
Double_t radius; //radius (mm)
Int_t radInt; //nearest integer of radius (mm)
Int_t numberOfBins=801;

for (int i=0; i <401; i++)
 {
 EnergyMap[i]=0.;
 Voxels[i]=0.;
}

//Build Energy Deposition Map
for (int k=0; k< numberOfBins; k++)
 {
   for (int m=0; m< numberOfBins; m++) 
 {
   Double_t xx_histo = h20->GetXaxis()->GetBinCenter(k);
   Double_t yy_histo = h20->GetYaxis()->GetBinCenter(m);
   Double_t edep_histo=h20->GetBinContent(k, m);
   radius = sqrt(xx_histo*xx_histo+yy_histo*yy_histo);
 //  if ((edep_histo!=0) && radius < 12. && radius > 9) std::cout << "histo: " << xx_histo << ", " << yy_histo 
   //                                                             << ", radius: " << radius <<", edep: "<< edep_histo << std::endl;

    if (radius != 0){
		      radInt = TMath::Nint(4*radius);
		      if ((radInt>0)&&(radInt<=400))
			{
			 EnergyMap[radInt]+= edep_histo;
			 Voxels[radInt]+= 1;
                      //   if (radius < 12. && radius > 9 && edep_histo!=0)std::cout<< "Radius: " << radius << ", radInt:"<<radInt << ", EnergyMap: "<< EnergyMap[radInt]<< ", voxels: " << Voxels[radInt]<< std::endl;
                         
				}
			}

}}

//Create Normalised Dose Map
std::cout << "The energy deposition at the reference point is " << EnergyMap[40] << std::endl;
Double_t tempNormValue = EnergyMap[40]/Voxels[40]; 
//value at 1cm, 90 degrees, the normalisation point
std::cout << "Dose rate ditribution (distances in cm)" << std::endl;

ofstream myfile;
TString outputFileName ="geant4_dose_"+ source+"_"+physics_list+".txt";
//const char * cOutputFileName  = fileName.c_str();
myfile.open(outputFileName);
std::cout << "file " << outputFileName << " is created "<<std::endl; 

for (int i=0; i<=400; i++)
{
 R = double(i)/40; //distance in CM!!!
 if (Voxels[i]>0) normDose[i] = EnergyMap[i]/Voxels[i]/tempNormValue;
    else normDose[i] = 0;

 
            
 if (R>  0.05)
    {
   // cout << R << "     " << normDose[i] << endl;  
    myfile << R <<  "     " << normDose[i] << "\n";                     
    }
}

myfile.close();
}

Last file have a function that need arguments, I wonder if I should put the arguments in command line. And where is the entrance of the program?

Which function do you want to call from the command line ?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.