I am currently trying to write a code that will read in a general data set. I can get it read into a general array, such that the number of lines and columns are arbitrary.
The next step however is to create histograms of each read in column. In trying to do this I ran into a problem, namely I cannot create the histograms until I know how many columns of data there are, but I have to write the code not knowing how many columns of data. So I tried creating a general histogram so that I could create a loop and thus create as many as needed. However I cannot get it to work. Any thoughts would be useful. I also need to be able to do this with canvas’.
Thanks
-Paul
Here is a sample code
{
gROOT->Reset();
// these arrays would become 2 dimensional for multiple names
char h0[] = "hist";
char histogram_name[] = "histogram";
// this would go in a loop to create as many as needed
TH1F h0(histogram_name, histogram_name, 100, -3, 3);
//there would also need to be any given number of these
TCanvas *Canvas1= new TCanvas("Canvas1", "Canvas 1", 1);
Canvas1->Divide(1,2);
Canvas1->cd(1);
h0->Draw();
}
It is not clear what you are trying to do!
Do you want to read an ascii file?
If yes, may be have a look at TTree::readFile or TNtuple::ReadFile
see: root.cern.ch/root/htmldoc/TTree. … e:ReadFile
no I understand how to read in a ascii file. My question relates to creating TH1F’s
I read in an ascii file and I get an nxm array of type Float where n is the number of rows and m is the number of columns. Then I want to create a loop (for, while…) to create m TH1F s all with diffrent names so that each one corresponds to a column. However I cannot simply start creating the TH1F’s as follows:
I cannot do it that way because I do not know how many I want to create until after I have read in the text file as the number changes from file to file. so what I tried doing was something more along the lines of:
char h[] = “h”;
for( i=0;
i <=m;
i = i +1)
{
h[i] = “h”;
strcat(h[i], (char)m); // so now h[i] would be hm
TH1F *h[i] = new TH1F(Histo[i], Histo[i], 10, 0, 100);
}
this way I could vary m and Histo[i]
my problem comes in when I try to vary *h[i] no matter how I try it always gives me an error of some sort.
I hope that makes things a little more clear. Sorry for the confusion earlier.
Could you be more precise? What doesn’t work? Could you tell us what you’re trying to do, and if possible with a piece of code showing the problem?