I am a beginner, This is related to assignment work.
For one root tree file (here pp1.root), I can use the below code. If I am having 10 root files and I need to read each file one by one to get the statistical parameters.
void pbtrue()
{
TFile *f = new TFile("pp1.root");
TTree *T1 = (TTree*)f->Get("T1");
int Tcharged ;
int Neg_charged ;
int Posi_charged ;
int delta_charge;
T1->SetBranchAddress("Totalcharge",&Tcharged);
T1->SetBranchAddress("negativecharge",&Neg_charged);
T1->SetBranchAddress("positivecharge",&Posi_charged);
T1->SetBranchAddress("deltacharge",&delta_charge);
int nentries = T1->GetEntries();
cout<< "Entries : "<<nentries<<endl;
double sumT=0.0;
double sumN=0.0;
double sumP=0.0;
double sumD=0.0;
double meanT=0.0;
double meanN=0.0;
double meanP=0.0;
double meanD=0.0;
for (int i=0;i<nentries;i ) {
T1->GetEntry(i);
sumT = Tcharged;
sumN = Neg_charged;
sumP = Posi_charged;
sumD = delta_charge;
meanT=sumT/nentries;
meanN=sumN/nentries;
meanP=sumP/nentries;
meanD=sumD/nentries;
}
cout << "mean of Total charge : "<<meanT<<endl;
cout << "mean of Negative charge : "<<meanN<<endl;
cout << "mean of positive charge : "<<meanP<<endl;
cout << "mean of delta charge : "<<meanD<<endl;
The way I have to do the calculation is by reading each root file one by one. Every root file contains the same branches and same variables. Please help me to do this.
CodePudding user response:
Now I can able to do this using string,
.
.
.
for(int i=1 ;i<=100; i)
{
string filename="pp" to_string(i) ".root";
TFile *f = new TFile(filename.c_str());
.
.
.
.
so it will read pp1.root,pp2.root,......pp100.root .