Re: Creating a root file containing only one histogram

From: Philippe Canal <pcanal_at_fnal.gov>
Date: Thu, 17 Mar 2011 12:04:50 -0500


Hi,

What is varzen? Why do you dereference it when is it zero (thus leading to the segmentation fault)? What is the histogram supposed to contains? Do you really mean to add it to the TTree, in this case rather than one histogram in the file, you will get one histogram in each entry of the TTree (tree_moon)?

Cheers,
Philippe

PS. never ever using gROOT->Reset in a function.

On 3/17/11 11:50 AM, Michelle Mesquita Medeiros wrote:
> Hello ROOTers,
>
> I'm trying to create a root file containing only one histogram with 100 bins and errors bars using a variable I have in a lot of
> others root files. Does someone knows how to do this? I wrote the script below, but it's not working...
>
> void separ()
> {
> gROOT->Reset();
> TChain *chain = new TChain("sim");
>
> chain->Add("/home/michelle/Documents/NEWERFILES/newer46.root");
> chain->Add("/home/michelle/Documents/NEWERFILES/newer47.root");
> [...]
>
> chain->SetBranchStatus("*",0);
> chain->SetBranchStatus("varzen",1);
>
> TTree *varzen = 0;
> chain->SetBranchAddress("varzen",&varzen);
>
> TFile *var = new TFile("var.root","recreate");
> TTree *tree_moon = chain->CloneTree(0);
>
> TH1F *hvar = new TH1F("hvar","var",100,0.0,10.0);
> tree_moon->Branch("hvar",&hvar);
>
> for (Int_t i=0; i < chain->GetEntries(); i++)
> {
> chain->GetEvent(i);
> hvar->Fill(varzen->GetEntries());
> tree_moon->Fill();
> }
> hvar->Draw("E");
>
> tree_moon->Print();
> var->Write();
> delete chain;
> delete var;
> }
>
> When I compile it I have the error:
>
> *** Break *** segmentation violation
> Root > Function separ() busy flag cleared
>
> Thanks in advance,
>
> ****************************************
> Michelle Mesquita de Medeiros
> Instituto de Física - UFG
> e-mail: medeiros_at_fnal.gov
> medeiros_at_posgrad.ufg.br
> michelle_mmed_at_yahoo.com.br
> ****************************************
>
>
Received on Thu Mar 17 2011 - 18:04:56 CET

This archive was generated by hypermail 2.2.0 : Thu Mar 17 2011 - 23:50:02 CET