Re: Project a TNtuple into an TH1F

From: Pascal Girard (girard@jlab.org)
Date: Thu Feb 04 1999 - 20:48:30 MET


Re Hi,

Sorry if I wasn't clear . I'm reading a succession of file with TNtuple.
my problem is to prevent the Histogram to disappear  , when I'll close the
"current" file,
to read the next one.
The complete code of what i'm doing is following.

If I don't use this DSDEDT->Add(DSDEDT, current) procedure,
But something like

FromFile->Draw("MSMass>>+DSDEDT",cut,"goff");


The Histogram DSDEDT stays in the memory whit the ntuple I'm curently reading.
When I close the current file to read the next one, the Histogram "disappears".
Adding all the histograms in a single one seems to work. Technicly , I have what I
want to. However I think theire is a better way to do so. As you said, Rene , the
"Add()" thing
is a little bit dangerous and heavy. My first thougt was the + option (in
MSMass>>+DSDEDT)
would allow the Histogram to "stay" in memory after I close the file, but it didn't
work out.

thank you again

Pascal

//_____________________________________________________________
//_____________________________________________________________

the histogram DSDEDT is define as private in a class :

TH1F* DSDEDT;

....

Theire is a member of this class for its memory allocation :
//_____________________________________________________________
int PiAna::ResHisto(char* title){

  DSDEDT = new TH1F("DSDEDT",title,120,-0.1,0.6);
  return 1;
}


Then a Tfile  is open to write out this histo :
//_____________________________________________________________
void PiAna::OpenResFile(char* particle, float angle, float E) {

  char file[20];
  sprintf(file,"%sT_%2.2fE_%2.2f",particle,angle,E);
  FileFlag = OpenFile(file);


}

with
//_____________________________________________________________
int PiAna::OpenFile(char* outfile) {
  // output file name determination and opening

  int i;
  char *strtemp  = outfile;
  char tempo[255];
  for (i=1;(!((TUnixSystem*)gSystem)->AccessPathName(outfile));i++) {
    cout <<outfile<< " already exists" <<endl;
    sprintf(tempo,"%s.%d",strtemp,i);
    outfile = tempo;
  }

  out = new TFile(outfile,"new");
  cout<<"ROOT Output file : "<<outfile<<endl;;
  return 1;
}

(out is pivate in the class : TFile *out;)

//_____________________________________________________________

The pre-existing TNtuple are stored on Tfiles , I open them and project them this
way
int  PiAna::LoopOnFile() {
  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();
    }
  }
return 1;
}

//_____________________________________________________________

void PiAna::ProjNT(TFile* TF){

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

  return;
}

//_____________________________________________________________
//_____________________________________________________________

the succesive steps are :

  OpenResFile(particle,  angle,  (E*1000.));
  HResFlag = ResHisto(title);
  LoopOnFile();
  out->cd();
  DSDEDT->Write();
  out->Write();





Rene Brun wrote:

> Hi Pascal,
> Could you make clear what is your problem?
> Provide a simple macro that does not work.
> In your example below, you have an extremely dangerous construct with
> the statement;
> DSDEDT->Add(..)
> Where is DSDEDT defined?
>
> Also, remember that when you create an histogram, this histogram is
> automatically added to the list of objects in memory associated to teh
> current file.
>
> Rene Brun
>
>



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