Hello
I tried to create and fill a tree from .txt file.
Then I did all the code on a root session, with C++.
First I wrote a program that open .txt file and fill an static table, then I created a tree and I fill it with the data from a[size][n].
The problem that I had, Root didn’t fill the tree and it’s empty.
Here is the code.
Can you help me please ?
thank you
#include <iostream>
#include<fstream>
#include<cmath>
#include<vector>
using namespace std;
void ouvrirremplir(double a[][8],int size) // Cette fonction va nous remplir un tableau statique avec des données importés d'un fihier.txt
{
fstream f;
f.open("tracks-Jorge.txt",ios::in);
for(int i=0;i<size;i++)
{
f>>a[i][0]>>a[i][1]>>a[i][2]>>a[i][3]>>a[i][4]>>a[i][5]>>a[i][6]>>a[i][7];}
f.close();
for(int i=0;i<size;i++)
{
for(int j=0;j<8;j++)
{cout<<a[i][j]<<endl;}
}}
int main (){
int size=42548;//nombre de lignes dans notre fichier
double a[size][8];// 8 pour le nombre de colonnes
ouvrirremplir(a,size);
TFile *f=new TFile("simulation.root","RECREATE");
TTree *tree=new TTree("simulation","detecteur");
//creation des branches de notre arbre
double Ntracks(0),Nlayers(0),X(0),errX(0),Y(0),errY(0),Z(0),errZ(0);
tree->Branch("Candidates of track",&Ntracks,"candidates of track");
tree->Branch("Number of Layers",&Nlayers,"Number of Layers");
tree->Branch("X position",&X,"X position");
tree->Branch(" X error",&errX,"X error");
tree->Branch(" Y position",&Y," Y position");
tree->Branch(" Y error",&errY," Y error");
tree->Branch(" Z position",&Z," Z position");
tree->Branch(" Z error",&errZ," Z error");
// Maintenant on va remplir l'arbre
for(int i=0;i<size;i++)
{
Ntracks=a[i][0];
Nlayers=a[i][1];
X=a[i][2];
errX=a[i][3];
Y=a[i][4];
errY=a[i][5];
Z=a[i][6];
errZ=a[i][7];
tree->Fill();
}
f->Write();
f->Close();
return 0;}