Re: Project a TNtuple into an TH1F

From: Pascal Girard (girard@jlab.org)
Date: Thu Feb 04 1999 - 16:57:08 MET


Hi Rooters,


I switch to the 2.20 version , and this might have been part of the
problem,
However I'm still not able to obtain the Histogram resulting from the
projection.
Nevertheless I thing this problem rather come from the directory where
the Histogram is set than
the Draw() object itself :

I'm openning a succesion of files where the a TNtuple has been filled
for each run.


  TFile *InNT;
  char file[15];
  for (int i=11400;i<11900;i++) {
    sprintf(file,"HistoRun.%d",i);
    if ( !((TUnixSystem*)gSystem)->AccessPathName(file) ) {
      cout<<"Opening "<<file<<endl;
      InNT = new TFile (file,"read");
      ProjNT(InNT);
      InNT->Close();


and then I'm projection this TNtuple into the TH1F,
My guess would be that the TH1F stays in the directory associated with
the NTtuple it comes from.
(even with the "+" in ->Draw("MSMass>>+DSDEDT"....) )
To bypass this problem, I've been obliged to declare a new TH1F
"current" to project the TNtuple
and then to copy "current" into a "repository" TH1F :



 void PiAna::ProjNT(TFile* TF){

  TH1F* current = new TH1F("current","tmp",120,-0.1,0.6);
  TNtuple *FromFile;
  TF->cd();  //optional
  FromFile = (TNtuple*) TF->Get("Neutral_Events");
  FromFile->Draw("MSMass>>current",cut,"goff");
  DSDEDT->Add(DSDEDT,current);
  current->Delete();

  return;
}

This works, I obtain the same result than interactively but is king of
"heavy"

thanks for your concerne

Pascal


> Pascal,
> I cannot reproduce this problem. I assume you are using 2.20 or higher.
>
> Always use TTree::Draw. Project is an interface to Draw.
>
> I tested your example interactively and in batch mode without
> problems.
>
> Rene Brun
>
> Pascal Girard wrote:
> >
> > Hi all,
> >
> > I'm trying to project a TNtuple in to a pre-define
> > TH1F from a c++ code.
> > I Have seen on roottalk some references to this issue,
> > but It seems it doesn't work for me :
> >
> > I define a TH1F* RES :
> >
> > TH1F* RES;
> > RES = new TH1F("DEDT",title,120,-0.1,0.6);
> >
> > ...
> >
> > I read a TNtuple from file :
> >
> > TNtuple *FromFile;
> > FromFile = (TNtuple*) TF->Get("Neutral_Events");
> > FromFile->Project("DEDT","MSMass",cut,"goff");
> >
> > ...
> >
> > when I visualize DEDT , it's empty.
> >
> > I tryed the Draw solution :
> >
> > > TH1F *h1 = new TH1F(..
> > >
> > > The TTree::Draw function (in the form "m>>+h1") fills an histogram
> > > with the name "h1". In your case h1 is the name of the pointer,
> > > not the name of the histogram ("blat").
> > > It is a good practice to have the pointer_name = histogram_name.
> > > Your program will work with:
> > > TH1F *h1 = new TH1F("blat", "quat", 20, 4.5, 6);
> > > ntuple->Draw("m>>+blat", "(4.5 > h1->Draw();
> > > or
> > > TH1F *blat = new TH1F("blat", "quat", 20, 4.5, 6);
> > > ntuple->Draw("m>>+blat", "(4.5 > blat->Draw();
> > >
> > > Rene Brun
> >
> > But It doesn't recognise the "goff" option and try to open a canvas from a
> > batch job. And the final result is an empty histogram.
> >
> > In interactive root (on HP), Project(...) doesn't seems to work,
> > however
> > the Draw solution does.
> >
> > Any suggestions ?
> >
> > thanks
> >
> > Pascal
> >
> >
> >
>
>



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:28 MET