Use a TCutG inside a macro

Hi, i’m trying to solve the following problem using a root macro:
i’ve got a TNutple with 3 vars, say x,y,z.
I want to plot x vs y in a bidim histo, and draw a TCutG on that;
after that i want to apply that cut, plotting the distribuition of z in a single histo.

How can i do that?

Thanks

Andrea

right now, i’m using [code]

gStyle->SetPalette(1);
TFile f=new TFile(“RootFiles/productionLq1.root”);
TNtuple
n1=(TNtuple*)f->Get(“Liquido1”);
TH1D *h1=new TH1D(“h1”,“h1”,2094,-0.5,2093.5);
TH2D *h2=new TH2D(“h2”,“h2”,2094,-0.5,2093.4,2094,-0.5,2093.5);
n1->Draw(“energyFast:energy >> h2”);
TCanvas *c1 = new TCanvas(“c1”,“Contours”,10,10,800,600);
h2->Draw(“colz”);
c1->Update();
cout<<“draw a cutG”<<endl;
gPad->WaitPrimitive();

TCutG mycutg;
mycutg = (TCutG
)gROOT->GetListOfSpecials()->FindObject(“CUTG”);
mycutg->SetName(“mycutg”);

n1->Draw("t>>h1","mycutg");

[/code]

but i get a segmentation violation error.

Andrea

It is likely that you did not create a TCutG with the mouse and the pointer mycutg is null.
Gry replacing

mycutg->SetName("mycutg"); by

if (mycutg) mycutg->SetName("mycutg"); and then investigate the cause in case mycutg is null.

Rene

The strange thing is that if i comment the last line

n1->Draw("t>>h1","mycutg");

there is no segmentation violation.
Brun, thanks for your reply: i will try that and then report the result.

Andrea

i tried that, i’m sure that mycutg is defined:
if i try cout<<mycutg->GetName()<<endl;
i get the name on the screen

Andrea

Hi,

What does valgrind say in your case (see valgrind.org and run as 'valgrind root.exe ')?
Can you provide a complete running example showing the problem? What is the stack trace in the failing case?

Philippe.

I tried to modify my code, including it in a standard c++ program.
Here is the code:


#include <iostream>
#include <TApplication.h>
#include <TCutG.h>
#include <TH1D.h>
#include <TH2D.h>
#include <TFile.h>
#include <TVectorD.h>
#include <TNtuple.h>
#include <TCanvas.h>
#include <TAxis.h>


using namespace std;

TApplication gui("gui",0,NULL);

main(){
  TFile *fin=new TFile("RootFiles/production6.run.root");
  TNtuple* n=(TNtuple*)fin->Get("Liquido1");
  TH2D *h2=new TH2D("h2","h2",2094,-0.5,2093.5,2094,-0.5,2093.5);
 
  /*  
  TVectorD *v=(TVectorD *)fin->Get("TVectorT<double>");
  double *vec=v->GetElements();
  double carica=vec[1];
  double time=v[0];
  double events=v[2];
  */
   n->Draw("energyFast:energy>>h2","energy > 90");
   h2->Draw();
   gui.Run(1);
   TCutG *gcut;
   gcut=(TCutG*) gPad->GetPrimitive("CUTG");
   gcut->SetName("cut");
   gcut->SetVarX("energy");
   gcut->SetVarY("energyFast");
   cout<<gcut->GetName()<<endl;

   TH1D *h1=new TH1D("h1","h1",2094,-0.5,2093.5); 
   n->Draw("t >> h1","cut");
   //h1->Scale(1/carica);
   h1->Draw();
   gui.Run(1);
}

The TNtuple has 3 var: t,energy,energyFast.
I draw a TH2 energyFast vs energy and draw there a TCutg; the istruction

cout<<gcut->GetName()<<endl;

works fine.
Then i want to draw the distribution of t, for those events with energy and energyFast inside my cut.
The error i get is:[quote]
Drawing using a C++ file currently requires that both the expression and the selection are files
"t >> h1" is not a file

[/quote]

You can file my root file here:

ge.infn.it/~celentan/out.root

Andrea

Hi,

Do you have a local file named ‘cut’?

Philippe.

yes, there is a file called “cut” in my directory (it is the binary file of the program)

[quote]yes, there is a file called “cut” in my directory (it is the binary file of the program)[/quote]This is the problem. You need to rename either the binary file or the cut.

Philippe.