Hi all,
Sorry for asking easy questions, I am quite new to this. I have a code that reads in a root file. Then calculate the number of scatters parallel and perpendicular to the beam line. When I run the code it outputs a root file which I open and I have a TH2F. I would also like a textfile which list the number of scatters in each direction. Is this possible? If so how?
I use these command in the code,
((TTreePlayer*)(tftree->GetPlayer()))->SetScanRedirect(true);
((TTreePlayer*)(tftree->GetPlayer()))->SetScanFileName(“output.txt”);
tftree->Scan(“proj_beam.proj_perp_beam”);
The textfile was created but looked like this (up to row 3059737)
-
0 * *
-
1 * *
-
2 * *
-
3 * *
-
4 * *
-
5 * *
-
6 * *
-
7 * *
-
8 * *
-
9 * *
-
10 * *
-
11 * *
-
12 * *
-
13 * *
-
14 * *
-
15 * *
This was the error message I get,
File <output.txt> created
Error in TTreeFormula::Compile: Bad numerical expression : “proj_beam.proj_perp_beam”
Thanks in advance, Chloe
Apparently “proj_beam.proj_perp_beam” does not exist in your TTree.
In order to see what’s available, try:
tftree->Print();
Note also, TH2F is NOT a TTree.
So now I have a macro that will output a textfile. I use the following commands,
root -l rootfile.root
root [0] .L outputtext.cpp
root [1] outputtext(myhist,“output.txt”)
But I get this error
Error: Symbol myhist is not defined in current scope (tmpfile):1:
*** Interpreter error recovered ***
This is what is loaded.
TFile** rootfile.root
TFile* rootfile.root
OBJ: TH2F myhist Perpendicular scatters -v- parallel scatters for all energies : 0 at: 0x105cb7bb0
KEY: TH2F myhist;1 Perpendicular scatters -v- parallel scatters for all energies
Can you someone tell me what I am doing wrong??
Thanks in advance, Chloe.
Before you use “myhist”, try to add:
TH2F *myhist = ((TH2F *)0);
gFile->GetObject(“myhist”, myhist);
or:
TH2F *myhist = ((TH2F *)(gROOT->FindObject(“myhist”)));
Do you mean into the code or command line?
root -l rootfile.root
root [0] TH2F *myhist = ((TH2F *)0);
root [1] gFile->GetObject(“myhist”, myhist);
root [2] .x outputtext.cpp(myhist, “output.txt”)
[quote=“Pepe Le Pew”]root -l rootfile.root
root [0] TH2F *myhist = ((TH2F *)0);
root [1] gFile->GetObject(“myhist”, myhist);
root [2] .x outputtext.cpp(myhist, “output.txt”)[/quote]
Thank you. I am now getting this error…
Error: Function outputtext(myhist,“output.txt”) is not defined in current scope :0:
*** Interpreter error recovered ***
That is the command I ran
.x outputtext.cpp(myhist, “output.txt”)
and I still get the error
Then try your original two-step approach:
root [2] .L outputtext.cpp
root [3] outputtext(myhist, “output.txt”)
[quote=“Pepe Le Pew”]Then try your original two-step approach:
root [2] .L outputtext.cpp
root [3] outputtext(myhist, “output.txt”)[/quote]
Still the same error
Error: Function outputtext(myhist,“output.txt”) is not defined in current scope (tmpfile):1:
*** Interpreter error recovered ***
So see what your “outputtext.cpp” file defines inside.
Solved!! Turned out outputtext was defined as TH1F instead of TH2F. It is always something silly.
Thank you very much for all your help.
Chloe