Insert line between points in a TH3F object

Hi , i want to insert a line between a series of points (x,y,z) in a TH3F object , in order to rappresent the path of a neutron in a material.

char name [20]; sprintf(name, "%s%d%s","neutrone",j,".root"); TFile *file_geom = new TFile(name,"recreate"); TH3F *hmsic = new TH3F(name,"Distribuzione spaziale",1000,-6,6,100,-6,6,100,-6,6);

after the creation of th3f i take the coordinates of the point.

[code]hmsic->SetMarkerColor(8);

hmsic->SetMarkerStyle(34);
hmsic->SetMarkerSize(1);
    hmsic->Fill(x,y,z);
hmsic->Draw();[/code]

For now I can fill the th3f but I do not know how to connect them with a line or tag them in the order of interaction.
Thank you

Maybe you could have a look at the TGraph2D class and its specific “LINE” drawing option (draws a 3D polyline; see also the THistPainter class description for additional, nonspecific to TGraph2D, valid 2D drawing options).

BTW. Your “hmsic” histogram contains about 10^7 bins in total (so it uses about 38 MiB RAM). Any operation on it, e.g. drawing, will take ages.

I have already tried to use tgraph2d but I had problems with sizing axes. Is there any way?

i’ve tried in this way but when i go in Tbrowser and select the file created , this does not open.

[code]TFile *file_geom = new TFile(name,“recreate”);
TCanvas *d1 = new TCanvas(name,“PolyLine3D & PolyMarker3D Window”,200,10,500,500);
TView3D *view = new TView3D();
view->SetRange(5,5,5,25,25,25);
x0=n->getx0();
y0=n->gety0();
z0=n->getz0();
vx=n->getvx();
vy=n->getvy();
vz=n->getvz();
TPolyLine3D * line = new TPolyLine3D;
TPolyMarker3D *pm3d1 = new TPolyMarker3D;
do {

phi= (2*M_PI)*gene.Rndm();
    theta= acos(-1 + 2*gene.Rndm());
FPP=FP*gene.Rndm();

x0=FP*sin(theta)*cos(phi);
y0=FP*sin(theta)*sin(phi);
z0=FP*cos(theta);

  line->SetPoint(j+c,x0,y0,z0);
  pm3d1->SetPoint(j+c,x0,y0,z0);
  line->SetLineColor(2); 
  line->SetLineColor( 5 );
  line->SetLineStyle( 4 );
   pm3d1->SetMarkerSize(2);
  pm3d1->SetMarkerColor(4);
   pm3d1->SetMarkerStyle(2);
  pm3d1->Draw();
  line->Draw();
  [/code]

thank you

[code]#include “TFile.h”
#include “TCanvas.h”
#include “TView3D.h”
#include “TPolyLine3D.h”
#include “TPolyMarker3D.h”
#include “TMath.h”
#include “TRandom.h”

void trial(void) {
TCanvas *d1 = new TCanvas(“trial”, “PolyLine3D & PolyMarker3D Window”,
200, 10, 500, 500);

TView3D *view = new TView3D();
view->SetRange(5, 5, 5, 25, 25, 25);

TPolyLine3D *line = new TPolyLine3D();
line->SetLineWidth(2);
line->SetLineColor(5);
line->SetLineStyle(4);

TPolyMarker3D *pm3d1 = new TPolyMarker3D();
pm3d1->SetMarkerSize(2);
pm3d1->SetMarkerColor(4);
pm3d1->SetMarkerStyle(2);

Double_t PI = TMath::Pi();
Double_t FP = 1;
Double_t phi, theta, x0, y0, z0;

gRandom->SetSeed(0);

for (Int_t jc = 0; jc < 10; jc++) {
phi= (2*PI)gRandom->Rndm();
theta= acos(-1 + 2
gRandom->Rndm());

x0=FP*sin(theta)*cos(phi);
y0=FP*sin(theta)*sin(phi);
z0=FP*cos(theta);

line->SetPoint(jc,x0,y0,z0);
pm3d1->SetPoint(jc,x0,y0,z0);

}

line->Draw();
pm3d1->Draw();

d1->Modified();
d1->Update();

TFile *file_geom = new TFile(“trial.root”, “recreate”);
// file_geom->cd();
d1->Write();
delete file_geom;
}[/code]
P.S. Next time prepare a complete ROOT macro which reproduces your problem.