Variable marker colour or rotation

I would like to plot my data in an unconventional way. What I have is polarization data, which includes a polarization degree and angle, and I would like to represent the angle either by rotating the markers or by changing their colour. The polarization degree would be represented by the position of the marker, and each marker on the graph would have a different colour or angle, depending on the polarization degree. Is there any quick way to do this, or would one have to manipulate each individual marker on the graph with code? Thanks.

You can use TNtuple and do:

ntuple->Draw(“px:py:pz”,"",“col”)

Thanks for the suggestion. Is there an example somewhere online of how to use that and what it would look like? I’m not sure how I would go about filling the ntuple. Thanks.

Yes, see: $ROOTSYS/tutorials/hsimple.C

Is there a simple example showing the complete use of ntuple including filling it and then drawing it? hsimple.C doesn’t seem to draw the ntuple part, and I tried inserting your draw statement into that file but it came back with an error message. Sorry for asking such a basic question, but I’ve never used ntuple before and I cannot find information about how to use it. Thanks.

send me te small example you end up with.

It’s actually just hsimple.C with an added line, because I didn’t really know what else to do.

#include <TFile.h>
#include <TNtuple.h>
#include <TH2.h>
#include <TProfile.h>
#include <TCanvas.h>
#include <TFrame.h>
#include <TROOT.h>
#include <TSystem.h>
#include <TRandom.h>
#include <TBenchmark.h>
#include <TInterpreter.h>

TFile *hsimple(Int_t get=0)
{
//  This program creates :
//    - a one dimensional histogram
//    - a two dimensional histogram
//    - a profile histogram
//    - a memory-resident ntuple
//
//  These objects are filled with some random numbers and saved on a file.
//  If get=1 the macro returns a pointer to the TFile of "hsimple.root"
//          if this file exists, otherwise it is created.
//  The file "hsimple.root" is created in $ROOTSYS/tutorials if the caller has
//  write access to this directory, otherwise the file is created in $PWD

   TString filename = "hsimple.root";
   TString dir = gSystem->UnixPathName(gInterpreter->GetCurrentMacroName());
   dir.ReplaceAll("hsimple.C","");
   dir.ReplaceAll("/./","/");
   TFile *hfile = 0;
   if (get) {
      // if the argument get =1 return the file "hsimple.root"
      // if the file does not exist, it is created
      if (!gSystem->AccessPathName(dir+"hsimple.root",kFileExists)) {
         hfile = TFile::Open(dir+"hsimple.root"); //in $ROOTSYS/tutorials
         if (hfile) return hfile;
      }
      //otherwise try $PWD/hsimple.root
      if (!gSystem->AccessPathName("hsimple.root",kFileExists)) {
         hfile = TFile::Open("hsimple.root"); //in current dir
         if (hfile) return hfile;
      }
   }
   //no hsimple.root file found. Must generate it !
   //generate hsimple.root in $ROOTSYS/tutorials if we have write access
   if (!gSystem->AccessPathName(dir,kWritePermission)) {
      filename = dir+"hsimple.root";
   } else if (!gSystem->AccessPathName(".",kWritePermission)) {
      //otherwise generate hsimple.root in the current directory
   } else {
      printf("you must run the script in a directory with write access\n");
      return 0;
   }
   (TFile*)gROOT->FindObject(filename); if (hfile) hfile->Close();
   hfile = (TFile*)gROOT->FindObject(filename); if (hfile) hfile->Close();
   hfile = new TFile(filename,"RECREATE","Demo ROOT file with histograms");

   // Create some histograms, a profile histogram and an ntuple
   TH1F *hpx = new TH1F("hpx","This is the px distribution",100,-4,4);
   hpx->SetFillColor(48);
   TH2F *hpxpy = new TH2F("hpxpy","py vs px",40,-4,4,40,-4,4);
   TProfile *hprof = new TProfile("hprof","Profile of pz versus px",100,-4,4,0,20);
   TNtuple *ntuple = new TNtuple("ntuple","Demo ntuple","px:py:pz:random:i");

   gBenchmark->Start("hsimple");
  
   // Create a new canvas.
   TCanvas *c1 = new TCanvas("c1","Dynamic Filling Example",200,10,700,500);
   c1->SetFillColor(42);
   c1->GetFrame()->SetFillColor(21);
   c1->GetFrame()->SetBorderSize(6);
   c1->GetFrame()->SetBorderMode(-1);


   // Fill histograms randomly
   gRandom->SetSeed();
   Float_t px, py, pz;
   const Int_t kUPDATE = 1000;
   for (Int_t i = 0; i < 25000; i++) {
      gRandom->Rannor(px,py);
      pz = px*px + py*py;
      Float_t random = gRandom->Rndm(1);
      hpx->Fill(px);
      hpxpy->Fill(px,py);
      hprof->Fill(px,pz);
      ntuple->Fill(px,py,pz,random,i);
      if (i && (i%kUPDATE) == 0) {
         if (i == kUPDATE) hpx->Draw();
         c1->Modified();
         c1->Update();
         if (gSystem->ProcessEvents())
            break;
      }
   }
   gBenchmark->Show("hsimple");

   ntuple->Draw("px:py:pz","col");
   // Save all objects in this file
   hpx->SetFillColor(0);
   hfile->Write();
   hpx->SetFillColor(48);
   c1->Modified();
   return hfile;
  
// Note that the file is automatically close when application terminates
// or when the file destructor is called.
}

Any information on how to proceed would be appreciated.

You missed one parameter in the Draw command. Here is a working (very simple) version.

void hsimple()
{
   hfile = new TFile("hsimple.root","RECREATE","ntuple example");

   TNtuple *ntuple = new TNtuple("ntuple","Demo ntuple","px:py:pz:random:i");

   TRandom3 random;
   Float_t px, py, pz;
   const Int_t kUPDATE = 1000;
   for (Int_t i = 0; i < 25000; i++) {
      random.Rannor(px,py);
      pz = px*px + py*py;
      Float_t rnd = random.Rndm(1);
      ntuple->Fill(px,py,pz,rnd,i);
   }
   
   gStyle->SetPalette(53);
   ntuple->SetMarkerStyle(20);
   ntuple->Draw("px:py:sqrt(pz)","", "col");

}

Thanks for the example. I have figured out that px and py are the x and y coordinates on the graph, and pz corresponds to the colour (higher numbers seem to produce a darker blue), but what is the purpose of rnd in the plot? What do the parameters passed to Draw correspond to (the first is the title, but what are the others)? Also, how can one plot colours other than blue? Thanks again.

rnd and i are just extra variable to show you can have as many columns as you want. May be you should read a bit the doc about TNtuple… Well, for what you want to do, I guess only 3 variables are enough right now.