Hi,
i can’t fill the tree named phi0tree. why?
#include <TFile.h>
#include <TObjArray.h>
#include <TGraph.h>
#include <TObject.h>
#include <TCint.h>
#include <TGraphErrors.h>
#include <TMultiGraph.h>
#include <TMarker.h>
#include <TTree.h>
#include <TBranch.h>
#include <TFolder.h>
#include <TString.h>
#include <TH2.h>
#include <TCanvas.h>
#include <TLegend.h>
#include <iostream>
#include <sstream>
using namespace std;
void prendi(string title,string cosa,TTree *atree);
void shooter(bool zpe2)
{
string Energy ="3GeV";
const char *Direction[6];
Direction[0] ="theta0";
Direction[1] ="theta15";
Direction[2] ="theta30";
Direction[3] ="theta45";
Direction[4] ="theta60";
const char *Phi[3];
Phi[0] ="phi0";
Phi[1] ="phi30";
Phi[2] ="phi90";
TFile *newfile0 =new TFile("datishooter.root","recreate");
delete newfile0;
double meanPE =0;
double sigma_of_the_mean =0;
double sigma =0;
double sigma_on_sqr_mean =0;
TTree *pretree = new TTree("phi","phi");
pretree->Branch("meanPE",&meanPE,"meanPE/D");
pretree->Branch("sigma",&sigma,"sigma/D");
pretree->Branch("sigma_of_the_mean",&sigma_of_the_mean,"sigma_of_the_mean/D");
pretree->Branch("sigma_on_sqr_mean",&sigma_on_sqr_mean,"sigma_on_sqr_mean/D");
string cosa;
if (zpe2==0)
{
cosa="PE_totali";
}
else
{
cosa="PE_totali_random";
}
for(int e=0;e<3;e++)
{
if(e==0)
{
TTree *phi0tree =pretree->CloneTree();
ostringstream filetitle;
filetitle<<"Shootermu"<<Energy<<Direction[0]<<Phi[e]<<"TotalData.root";
cout<<filetitle.str()<<endl;
phi0tree->SetName(Phi[0]);
prendi(filetitle.str().c_str(),cosa,phi0tree);
TFile *fatto =TFile::Open("datishooter.root","update");
phi0tree->Write();
delete phi0tree;
delete fatto;
}
}
}
/********************************************************************************************
*********************************************************************************************/
void prendi(string title,string cosa,TTree *atree)
{
int PE=0;
TFile *myfile =TFile::Open(title.c_str());
cout<<"title "<<title<<endl;
double meanPE =0;
double sigma_of_the_mean =0;
double sigma =0;
double sigma_on_sqr_mean =0;
TTree *oldtree =(TTree*)myfile->Get(cosa.c_str());
oldtree->SetBranchAddress("PEtot3",&PE);
cout<<"cosa "<<cosa<<endl;
int nent =oldtree->GetEntries();
cout<<"nent "<<nent<<endl;
TH1F *primo =new TH1F("tot3","tot3",nent,0,nent);
for(int g=0; g<nent;g++)
{
oldtree->GetEntry(g);
//cout<<"PE "<<PE<<endl;
primo->Fill(PE);
}
meanPE =(double)primo->GetMean();
cout<<"mean "<<meanPE<<endl;
sigma =(double)primo->GetRMS();
cout<<"sigma "<<sigma<<endl;
sigma_of_the_mean =sigma/(pow(nent-2,0.5));
cout<<"sigma_of_the_mean "<<sigma_of_the_mean<<endl;//<==i know from these couts that the values exist and are correct.
sigma_on_sqr_mean =sigma/pow(meanPE,0.5);
cout<<"sigma_on_sqr_mean "<<sigma_on_sqr_mean<<endl;
atree->Fill();
delete myfile;
}
Thank you
Amir[/code]