TPolyMarker3D change default marker style to 20

Hi,

I want to change the TPolyMarker3D marker style by default when running:

root [0] tracks->Draw("dig_x:dig_y:dig_z:dig_adc","fitType==5")

The current markers make it to hard see. I attached the file needed to make attached plot.



digTrk200.root (1.84 MB)

root [1] tracks->SetMarkerStyle(20);
root [2] tracks->Draw("dig_x:dig_y:dig_z:dig_adc","fitType==5");

that works! Now I need to set the range in x,y,z i.e. -6<x<6, -6<y<6, -6<z<6??

I’ve tried various ways based on stuff i’ve read online. Here’s a snippet of what I do currently [which doesn’t set the range as desired].

TTree* noMaskDigits = (TTree*)noMaskDigitFile->Get("tracks");
TH3F *track3d = new TH3F("track3d","track3d",50,-6,6,50,-6,6,25,-6,6);
track3d->GetXaxis()->SetRange(-6,6);
track3d->GetYaxis()->SetRange(-6,6);
track3d->GetZaxis()->SetRange(-6,6);

char individ_eventCut[234];
noMaskDigits->SetMarkerStyle(20);
for (int run = 100002055; run <= 100002061; ++run)
{
	printf("////// event tracks for run: %d ////////\n",run);
	for (int eventID = 100; eventID < 200; ++eventID)
	{
		sprintf(individ_eventCut,"fitType==5&&run==%d&&eventID==%d",run,eventID);
		noMaskDigits->Draw("dig_x:dig_y:dig_z:dig_adc>>track3d",individ_eventCut);
		track3d->SetTitle(individ_eventCut);
		TView *view1 = TView::CreateView(1);
		view1->SetRange(-6,-6,-6,6,6,6);

		track3d->Draw();
		sprintf(buffChar,"run%d_eventID%d.png",run,eventID);
		c1->SetTheta(40);
		c1->Update();
		c1->SaveAs(buffChar);
	}
}

Try:

{
  const char *file_name = "digTrk200.root";
  const int first_run = 100001855;
  const int last_run = 100001855;
  const int first_event = 90;
  const int last_event = 205;
  const bool show_stats = kTRUE; // kTRUE ... or ... kFALSE
  
  gStyle->SetPalette(55);
  
  // https://root-forum.cern.ch/t/ttree-draw-integral-depends-on-number-bins-bug/21203/7
  TDirectory *cwd = gDirectory; // we create histograms "here"
  TH3F *track3d = new TH3F("track3d", "track3d", 12, -6, 6, 12, -6, 6, 12, -6, 6);
  track3d->SetStats(show_stats);
  
  TFile *noMaskDigitFile = TFile::Open(file_name);
  TTree *noMaskDigits; noMaskDigitFile->GetObject("tracks", noMaskDigits);
  noMaskDigits->SetMarkerStyle(20);
  
  cwd->cd(); // go to the directory where histograms are
  TCanvas *c1 = new TCanvas("c1", "c1");
  
  for (int run = first_run; run <= last_run; run++)
    {
      std::cout << "////// event tracks for run: " << run << " ////////" << std::endl;
      for (int eventID = first_event; eventID <= last_event; eventID++)
        {
          TString individ_eventCut =
            TString::Format("fitType==5&&run==%d&&eventID==%d", run, eventID);
          track3d->SetTitle(individ_eventCut + ";dig_x;dig_y;dig_z");
          
          // https://root-forum.cern.ch/t/problem-with-tree-and-histogram/21240/12
          track3d->Reset("M"); // make sure it's "clean"
          if (!(track3d->TestBit(TH1::kNoStats))) {
            noMaskDigits->Project("track3d", "dig_z:dig_y:dig_x", individ_eventCut, "");
            ((TArrayF *)track3d)->Reset(); // "reset" histogram's bins' contents
          }
          noMaskDigits->Draw("dig_z:dig_y:dig_x:dig_adc>>+track3d", individ_eventCut, "col");
          
          c1->SetTheta(40);
          c1->Modified(); c1->Update();
          c1->SaveAs(TString::Format("run%d_eventID%d.png", run, eventID));
        }
    }
  
  std::cout << std::endl << "Incredible, isn't it." << std::endl << std::endl;
}

BTW. Another example can be found in this thread. For "e1:e2" draw expressions, which produce unbinned 2-d scatter-plots (TGraph), there is this thread.

Thanks Pepe! it works =D>

How can I draw a translucent circle (x^2+y^2=5^2, z=0) and a hexagon (inscribed by x^2+y^2=5^2, z=5) on the same plot as track?

Transparency is not available on all platform. For example it is not available with X11.

I see. I won’t be using x11, I’ll be creating pngs to form gifs and would like to depict a cartoon of our cathode & anode as a guide. How would I draw the circle & hexagon on these 3d plots?

root.cern.ch/doc/master/classTPolyLine3D.html


A few questions:

How can I get the [3D] aspect ratio to remain the same through the loop? the attached image is a .gif. if you don’t see it moving please download it and open with a browser to see how the aspect ratio change with c1->SetPhi()
Is there another way to plot a translucent polygon? Say, using a 3D surface that I force into a plane.
why do the polygons always appear on top of the tracks?

here’s the current code snippet that produces these plots…

////////////////////// draw noMask digit/tracks trees ///////////////////////////////////
printf("////////////////////// draw noMask digit/tracks trees ///////////////////////////////////\n");
const int first_run = 100002055;
const int last_run = 100002061;
const int first_event = 100;
const int last_event = 205;
const bool show_stats = kTRUE; // kTRUE ... or ... kFALSE

sprintf(noMaskDigitFileName,"/p/lscratche/jerbundg/data/thesisData/trees/digTrkTreeDir/noMask%d.driftVel%s_trk_dig.2k.trees.root",preamp,driftVel);
TFile* noMaskDigitFile = new TFile(noMaskDigitFileName);

gStyle->SetPalette(55);

// https://root-forum.cern.ch/t/ttree-draw-integral-depends-on-number-bins-bug/21203/7
TDirectory *cwd = gDirectory; // we create histograms "here"
TH3F *track3d = new TH3F("track3d", "track3d", 12, -5, 5, 12, -5, 5, 12, -1, 5);
track3d->SetStats(show_stats);

TTree *noMaskDigits; noMaskDigitFile->GetObject("tracks", noMaskDigits);
noMaskDigits->SetMarkerStyle(20);

cwd->cd(); // go to the directory where histograms are

for (int run = first_run; run <= last_run; run++)
{
	std::cout << "////// event tracks for run: " << run << " ////////" << std::endl;
	for (int eventID = first_event; eventID <= last_event; eventID++)
	{
		TString individ_eventCut =
		TString::Format("fitType==5&&run==%d&&eventID==%d", run, eventID);
		track3d->SetTitle(individ_eventCut + ";dig_x;dig_y;dig_z");

		// https://root-forum.cern.ch/t/problem-with-tree-and-histogram/21240/12
		track3d->Reset("M"); // make sure it's "clean"
		if (!(track3d->TestBit(TH1::kNoStats)))
		{
			noMaskDigits->Project("track3d", "dig_x:dig_y:dig_z", individ_eventCut, "");
			((TArrayF *)track3d)->Reset(); // "reset" histogram's bins' contents
		}
		noMaskDigits->Draw("dig_x:dig_y:dig_z:dig_adc>>track3d", individ_eventCut, "col");
		TPolyLine3D *pl_hex = new TPolyLine3D(5);
		pl_hex->SetLineColor(kSpring);
		pl_hex->SetLineWidth(2);
		for (int n = 0; n <= 6; ++n)
			pl_hex->SetPoint(n,
				5*TMath::Cos(n*60*TMath::Pi()/180),
				5*TMath::Sin(n*60*TMath::Pi()/180),
				5);
		pl_hex->Draw("same");
		TPolyLine3D *pl_circle = new TPolyLine3D(5);
		pl_circle->SetLineColor(kRed);
		pl_circle->SetLineWidth(2);
		for (int n = 0; n <= 60; ++n)
			pl_circle->SetPoint(n,
				5*TMath::Cos(n*6*TMath::Pi()/180),
				5*TMath::Sin(n*6*TMath::Pi()/180),
				0);
		pl_circle->Draw("same");
		for (int phi = 0; phi <= 360; phi+=10)
		{
			c1->SetPhi(phi+3);
			// c1->SetTheta(10);
			c1->Modified(); c1->Update();
			c1->SaveAs(TString::Format("run%d_eventID%d_phi%03d.png", run, eventID, phi));
		}
	}
}

With this kind of plot the pad margins are kept constant when you rotate the cube.

cf252.driftVel4.42_noMask2.nEv2k.trees.root (1.29 MB)I’m wanting to plot TPolyLine3D on the same canvas as a set of charge voxels, however when I uncomment the trk_n loop I get a segfault after the first trk_n loop iteration; why is this happening? I’ve attached cf252.driftVel4.42_noMask2.nEv2k.trees.root and digTrk200.root (in the original post).

// for (int trk_n = 1; trk_n < trackCount_hist->FindFirstBinAbove(0); ++trk_n)
// {
// 	pl_track->SetPoint(0,start_x[trk_n],start_y[trk_n],start_z[trk_n]);
// 	pl_track->SetPoint(1,end_x[trk_n],end_y[trk_n],end_z[trk_n]);
// 	pl_track->Draw("same");
// }
///////// digits plus track /////////
printf("///////// digits plus track /////////\n");
///////// initialize track tree /////////
printf("///////// initialize track tree /////////\n\n");
sprintf(noMaskTrackFileName,"/p/lscratche/jerbundg/data/thesisData/trees/%s.driftVel%s_noMask%d.nEv10k.trees.root",actinide,driftVel,preamp);
printf("noMaskTrackFileName: %s\n", noMaskTrackFileName);
TFile* noMaskTrackFile = new TFile(noMaskTrackFileName);
TTree *noMaskTracks; noMaskTrackFile->GetObject("tracks", noMaskTracks);
///////// initialize digit tree /////////
printf("///////// initialize digit tree /////////\n\n");
sprintf(noMaskDigitFileName,"/p/lscratche/jerbundg/data/thesisData/trees/digTrkTreeDir/noMask%d.driftVel%s_trk_dig.2k.trees.root",preamp,driftVel);
TFile* noMaskDigitFile = new TFile(noMaskDigitFileName);
TDirectory *cwd = gDirectory; // we create histograms "here"
TH3F *track3d = new TH3F("track3d", "track3d", 12, -5, 5, 12, -5, 5, 12, -1, 5);
track3d->SetStats(kTRUE);
TTree *noMaskDigits; noMaskDigitFile->GetObject("tracks", noMaskDigits);
noMaskDigits->SetMarkerStyle(20);
cwd->cd(); // go to the directory where histograms are
const int first_run = 100002055;
const int last_run = 100002061;
const int first_event = 0;
const int last_event = 2000;

TH1F* trackCount_hist = new TH1F("trackCount_hist","trackCount_hist",10,0,10);
TH1F* start_hist = new TH1F("start_hist","start_hist",1000,-20,20);
double start_x[10];
double start_y[10];
double start_z[10];
TH1F* end_hist = new TH1F("end_hist","end_hist",1000,-20,20);
double end_x[10];
double end_y[10];
double end_z[10];
TPolyLine3D *pl_track = new TPolyLine3D(2);
pl_track->SetLineColor(kYellow);
pl_track->SetLineWidth(2);

for (int run = first_run; run <= last_run; run++)
{
	std::cout << "////// event tracks for run: " << run << " ////////" << std::endl;
	for (int event_id = first_event; event_id <= last_event; event_id++)
	{
		char individ_eventCut[234];
		sprintf(individ_eventCut,"fitType==5&&run==%d&&eventID==%d&&trackCount==2", run, event_id);
		noMaskTracks->Draw("trackCount>>trackCount_hist",individ_eventCut);
		if (trackCount_hist->GetEntries()==0) continue;
		for (int trk_n = 1; trk_n < trackCount_hist->FindFirstBinAbove(0); ++trk_n)
		{
			sprintf(buffChar,"%s&&%d",individ_eventCut,trk_n);
			noMaskTracks->Draw("start.x()>>start_hist",buffChar);
			start_x[trk_n] = start_hist->GetMean();
			noMaskTracks->Draw("start.y()>>start_hist",buffChar);
			start_y[trk_n] = start_hist->GetMean();
			noMaskTracks->Draw("start.z()>>start_hist",buffChar);
			start_z[trk_n] = start_hist->GetMean();
			noMaskTracks->Draw("end.x()>>end_hist",buffChar);
			end_x[trk_n] = end_hist->GetMean();
			noMaskTracks->Draw("end.y()>>end_hist",buffChar);
			end_y[trk_n] = end_hist->GetMean();
			noMaskTracks->Draw("end.z()>>end_hist",buffChar);
			end_z[trk_n] = end_hist->GetMean();
		}

		track3d->SetTitle(individ_eventCut);
		// https://root-forum.cern.ch/t/problem-with-tree-and-histogram/21240/12
		track3d->Reset("M"); // make sure it's "clean"
		if (!(track3d->TestBit(TH1::kNoStats)))
		{
			noMaskDigits->Project("track3d", "dig_x:dig_y:dig_z", individ_eventCut, "");
			((TArrayF *)track3d)->Reset(); // "reset" histogram's bins' contents
		}
		noMaskDigits->Draw("dig_x:dig_y:dig_z:dig_adc>>track3d", individ_eventCut, "col");
		TPolyLine3D *pl_hex = new TPolyLine3D(5);
		pl_hex->SetLineColor(kSpring);
		pl_hex->SetLineWidth(2);
		for (int n = 0; n <= 6; ++n)
			pl_hex->SetPoint(n,
				5*TMath::Cos(n*60*TMath::Pi()/180),
				5*TMath::Sin(n*60*TMath::Pi()/180),
				5);
		pl_hex->Draw("same");
		TPolyLine3D *pl_circle = new TPolyLine3D(5);
		pl_circle->SetLineColor(kRed);
		pl_circle->SetLineWidth(2);
		for (int n = 0; n <= 60; ++n)
			pl_circle->SetPoint(n,
				5*TMath::Cos(n*6*TMath::Pi()/180),
				5*TMath::Sin(n*6*TMath::Pi()/180),
				0);
		pl_circle->Draw("same");
		// for (int trk_n = 1; trk_n < trackCount_hist->FindFirstBinAbove(0); ++trk_n)
		// {
		// 	pl_track->SetPoint(0,start_x[trk_n],start_y[trk_n],start_z[trk_n]);
		// 	pl_track->SetPoint(1,end_x[trk_n],end_y[trk_n],end_z[trk_n]);
		// 	pl_track->Draw("same");
		// }

		sprintf(buffChar,"run%d_eventID%d.png", run, event_id);
		c1->SaveAs(buffChar);
	}
}
for (int trk_n = 1; trk_n < trackCount_hist->FindFirstBinAbove(0); trk_n++)
  {
    // if (trk_n > 9) continue; // just a precaution (0 ... 9 are allowed)
    TPolyLine3D *pl_track = new TPolyLine3D(2);
    pl_track->SetLineColor(kYellow);
    pl_track->SetLineWidth(2);
    pl_track->SetPoint(0, start_x[trk_n], start_y[trk_n], start_z[trk_n]);
    pl_track->SetPoint(1, end_x[trk_n], end_y[trk_n], end_z[trk_n]);
    pl_track->Draw();
  }

BTW. For your “track3d” histogram, the projected/drawn “x” and “z” axes are swapped with respect to the histogram axes. You need to Project/Draw “z:y:x”, and NOT “x:y:z”, in order to have the same axes meaning as in the histogram (see my previous post in this thread). And for the “statistics” logic to wok, you should have “>>+track3d” instead of “>>track3d” (again, see my previous post in this thread).