Hi,
I need to plot a histogram from a big text file, and i don’t know how to do that since i am New in Root
Can someone help with a code to do this?
I’ve attached the file
Nouf
MyData.txt (674 KB)
Hi,
I need to plot a histogram from a big text file, and i don’t know how to do that since i am New in Root
Can someone help with a code to do this?
I’ve attached the file
Nouf
MyData.txt (674 KB)
I see your file has 20 columns and more than 7000 lines … it does not look like an histogram … more an ntuple.
Can you be more precise on the type of final object you want to obtain ?
Yes, it is ntuple
You need to specify the names of all ntuple columns (and the types of variables).
[code]{
TFile *f = TFile::Open(“MyData.root”, “RECREATE”);
TTree *t = new TTree(“t”, “My Data tree”);
t->ReadFile(“MyData.txt”, “tdc[10]/s:adc[10]/s”);
TH1F *h_tdc = new TH1F(“h_tdc”, “TDC histogram;tdc value;counts”,
4096, 0, 4096);
TH1F h_adc = new TH1F(“h_adc”, “ADC histogram;adc value;counts”,
4096, 0, 4096);
#if 1 / 0 or 1 /
t->Project(“h_tdc”, “tdc”);
t->Project(“h_adc”, “adc”);
#else / 0 or 1 /
t->Draw(“tdc >> h_tdc”, “”, “goff”);
t->Draw(“adc >> h_adc”, “”, “goff”);
#endif / 0 or 1 */
f->Write();
TCanvas *c = new TCanvas(“c”, “c”);
c->Divide(1, 2);
c->cd(1);
gPad->SetLogy(1);
h_tdc->Draw();
c->cd(2);
gPad->SetLogy(1);
h_adc->Draw();
c->cd(0);
}[/code]
i got this
where do you think the problem ?
Do you have the “MyData.txt” file in the same subdirectory in which you run the ROOT macro?
yes
any help?
"Error in TTree::ReadFile: Cannot open file: MyData.txt"
this whatt i have
Thank you … I got it