ROOT Version: 5.34.36
Platform: Ubuntu 16.04 and 14.04
__
#include "TROOT.h"
#include "TMath.h"
#include "TCanvas.h"
#include "TFile.h"
#include "TTree.h"
#include "TGraph.h"
#include "TBrowser.h"
#include "TH1.h"
#include "TF1.h"
#include "TH2.h"
#include "TRandom.h"
#include "TStopwatch.h"
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
void analy(){ /// fecha linha 175
Int_t mm=0;
// read a tree already done
const char *files[] = {"Samp_tree_1000.root", "Samp_tree_1001.root", "Samp_tree_1002.root", "Samp_tree_1003.root", "Samp_tree_1004.root",
"Samp_tree_1005.root", "Samp_tree_1006.root", "Samp_tree_1007.root", "Samp_tree_1008.root", "Samp_tree_1009.root",
"Samp_tree_1010.root", "Samp_tree_1011.root", "Samp_tree_1012.root", "Samp_tree_1013.root", "Samp_tree_1014.root",
"Samp_tree_1015.root", "Samp_tree_1016.root", "Samp_tree_1017.root", "Samp_tree_1018.root", "Samp_tree_1019.root",
"Samp_tree_1020.root", "Samp_tree_1021.root", "Samp_tree_1022.root", "Samp_tree_1023.root", "Samp_tree_1024.root",
"Samp_tree_1025.root", "Samp_tree_1026.root", "Samp_tree_1027.root", "Samp_tree_1028.root", "Samp_tree_1029.root",
"Samp_tree_1030.root", "Samp_tree_1031.root", "Samp_tree_1032.root", "Samp_tree_1033.root", "Samp_tree_1034.root",
"Samp_tree_1035.root", "Samp_tree_1036.root", "Samp_tree_1037.root", "Samp_tree_1038.root", "Samp_tree_1039.root",
"Samp_tree_1040.root", "Samp_tree_1041.root", "Samp_tree_1042.root", "Samp_tree_1043.root", "Samp_tree_1044.root",
"Samp_tree_1045.root", "Samp_tree_1046.root", "Samp_tree_1047.root", "Samp_tree_1048.root", "Samp_tree_1049.root",
"Samp_tree_1050.root", "Samp_tree_1051.root", "Samp_tree_1052.root", "Samp_tree_1053.root", "Samp_tree_1054.root",
"Samp_tree_1055.root", "Samp_tree_1056.root", "Samp_tree_1057.root", "Samp_tree_1058.root", "Samp_tree_1059.root",
"Samp_tree_1060.root", "Samp_tree_1061.root", "Samp_tree_1062.root", "Samp_tree_1063.root", "Samp_tree_1064.root",
"Samp_tree_1065.root", "Samp_tree_1066.root", "Samp_tree_1067.root", "Samp_tree_1068.root", "Samp_tree_1069.root",
"Samp_tree_1070.root", "Samp_tree_1071.root", "Samp_tree_1072.root", "Samp_tree_1073.root", "Samp_tree_1074.root",
"Samp_tree_1075.root", "Samp_tree_1076.root", "Samp_tree_1077.root", "Samp_tree_1078.root", "Samp_tree_1079.root",
"Samp_tree_1080.root", "Samp_tree_1081.root", "Samp_tree_1082.root", "Samp_tree_1083.root", "Samp_tree_1084.root",
"Samp_tree_1085.root", "Samp_tree_1086.root", "Samp_tree_1087.root", "Samp_tree_1088.root", "Samp_tree_1089.root",
"Samp_tree_1090.root", "Samp_tree_1091.root", "Samp_tree_1092.root", "Samp_tree_1093.root", "Samp_tree_1094.root",
"Samp_tree_1095.root", "Samp_tree_1096.root", "Samp_tree_1097.root", "Samp_tree_1098.root"};
const int n = sizeof(files) / sizeof(char*);
for (int i = 0; i < n; i++) { //fecha linha 50 (176)
TChain chain("Samp");
chain.Add(files[i]);
//cout << "n " << n << endl;
//cout<<"entry1 = " << chain.GetEntry(i) << endl;
}
/* TFile *f_gamos = TFile::Open(files[i]);
// if ((!f_gamos) || f_gamos->IsZombie()) { delete f_gamos; continue; } // just a precaution
TTree *t; f_gamos->GetObject("Samp", t);
// if (!t) { delete f_gamos; continue; } // just a precaution*/
//t->Print();
// definition of variables
Int_t n_entries=0, EventID=0;
Double_t EventAEnerDep=0.0, EventAEnerLost=0.0, EventInitKinEn;
std::vector<int> *StepNumber=0;
std::vector<int> *StepEventID = 0;
std::vector<double> *StepFinKinEn=0;
std::vector<double> *StepInKinEn=0;
std::vector<double> *StepAcEnDep=0;
std::vector<double> *StepAcEnLost=0;
std::vector<string> *StepFinLogVol;//=0;
std::vector<string> *StepInitLogVol;//=0;
// carry out the same variables defined
chain.SetBranchAddress("Event_EventID",&EventID);
chain.SetBranchAddress("Event_AccumulatedEnergyDeposited",&EventAEnerDep);
chain.SetBranchAddress("Event_AccumulatedEnergyLost",&EventAEnerLost);
chain.SetBranchAddress("Event_InitialKineticEnergy",&EventInitKinEn);
chain.SetBranchAddress("Step_StepNumber", &StepNumber);
chain.SetBranchAddress("Step_EventID",&StepEventID);
chain.SetBranchAddress("Step_AccumulatedEnergyDeposited",&StepAcEnDep);
chain.SetBranchAddress("Step_AccumulatedEnergyLost",&StepAcEnLost);
chain.SetBranchAddress("Step_FinalKineticEnergy",&StepFinKinEn);
chain.SetBranchAddress("Step_InitialKineticEnergy",&StepInKinEn);
chain.SetBranchAddress("Step_FinalLogicalVolume", &StepFinLogVol);
chain.SetBranchAddress("Step_InitialLogicalVolume", &StepInitLogVol);
///////////////// fill histogram and load tree
int nbins = 100;
gStyle->SetOptStat(1111111);
TCanvas * c1 = new TCanvas("c1", "c1", 800, 600);
TH1F *h = new TH1F("h", "h", nbins, 0., 0.0455);
n_entries=chain.GetEntries();
for (Int_t j=0; j<n_entries;j++){ //run in all tree //////fecha linha 174
chain.GetEntry(j);
cout<<"entries vector = "<<n_entries<<endl;
cout<<"Entry = "<<j<<endl;
cout<<"size = "<<StepFinLogVol->size()-1<<endl;
//cout<<"EventID = "<<EventID<<endl;
// cout<<"EventAEnerDep = "<<EventAEnerDep<<endl;
// cout<<"EventAEnerLost = "<<EventAEnerLost<<endl;
// cout<<"StepEventID = "<<StepEventID->size()<<endl;
// cout<<"StepFinKinEn = "<<StepFinKinEn->size()<<endl;
//cout<<"Value Vol(before) = "<<StepFinLogVol->at(i)<<endl;
if(StepFinLogVol->size()!=0){ //load the branches of the tree ///fecha linha 150
Int_t contador=0;
cout<<endl;
while (StepFinLogVol->at(contador) !="control" && contador < StepFinLogVol->size()-1){ /// fecha linha 133
contador++;
//h->Fill(StepFinKinEn->at(contador));
/*cout<<"entry vector = "<<contador<<endl;
cout<<"volume = "<<StepFinLogVol->at(contador)<<endl;
//h->Fill(StepFinKinEn->at(contador));
cout<<"StepInKinEn = "<<StepInKinEn->at(contador)<<endl;
cout<<"StepFinKinEn = "<<StepFinKinEn->at(contador)<<endl;
cout<<endl;
cout<<"#####"<<endl;
cout<<"EnLost by Step = "<<StepInKinEn->at(contador)-StepFinKinEn->at(contador)<<endl;
cout<<"StepAcEnLost = "<<StepAcEnLost->at(contador)<<endl;*/
}
Double_t sum=0;
if (StepFinLogVol->at(contador) !="control") { // fecha linha 143
for(Int_t l=0;l<StepNumber->size();l++){ /// fecha linha 140
sum = sum + StepAcEnLost->at(l);
}
//h->Fill(sum); //enter in control
//h->Fill(StepAcEnLost->at(contador));
}
if (StepFinLogVol->at(contador) =="control") {mm++;} //h->Fill(StepInKinEn->at(contador));}
cout<<endl;
//h->Fill(EventAEnerLost); //deu certo!!
}
//
// for (Int_t k=0;k<StepEventID->size();k++){ //run all vector in the event /// fecha na linha 174
//
// if(StepFinLogVol->at(k) != "control"){ //StepFinLogVol->at(j) == "control" ///fecha linha 172
// cout<<"StepEventID = "<<StepEventID->at(j)<<endl;
// cout<<"StepEventID = "<<StepEventID->size()<<endl;
// cout<<"StepFinKinEn = "<<StepFinKinEn->at(j)<<endl;
// cout<<"StepInKinEn(Val) = "<<StepInKinEn->at(j)<<endl;
//cout<<"k = "<<k<<endl;
// cout<<"StepFinKinEn1 = "<<StepFinKinEn->size()<<endl;
// cout<<"Vol_Val = "<<StepFinLogVol->size()<<endl;
// cout<<"Vol_Val = "<<StepFinLogVol->at(j)<<endl;
//cout<<"StepNumber = "<<StepNumber->at(j)<<endl;
//cout<<endl;
//h->Fill(EventAEnerLost);
// h->Fill(StepFinKinEn->at(k));
// h->Fill(StepAcEnLost->at(k));
// }
//
// }
}
//h->Fill(sum); //enter in control
cout<< "numero de partículas no controlo = "<< mm<<endl;
//cout<<"size = "<<contador<<endl;
h->SetNameTitle("energy", "Step Energy Lost;EKin;Counts"); //Kinetic Energy Energy Lost
h->SetFillColor(0);
h->Draw("");
}
I´m produced in GAMOS a input file that generated the 99 files in the code above. In this code I must read all files and using some branches to produce an histogram like those in attached. I use the same code above (Is the same code used above without the TChain).
Event_ELost1.pdf (14.6 KB)
Step_ELost1.pdf (14.6 KB)
When I put the TChain the result was wrong, so my question is what is wrong, how can I used th TChain in this case? I put here bellow the link with some of the files.
https://drive.google.com/drive/folders/1GjKyC3d94Qvz3H-OA0omL8D-BYr-0fV-?usp=sharing
I think that the entries appears in the histogram with this code is only of some files not the sum of the entries of all files.
Best regards