calbet
June 29, 2017, 10:06am
1
Dear experts,
when I fill hist with “Tree->Draw(“var>>hist”)” line 82 of (1), I can’t manipulate the hist for example, I can’t do hist->SetColor(kRed) see line 100 of (1). Also the code is suppose to plot two histograms on the same canvas (line 103) but it draw only one. Do you see how to fix these issues?
Regards
(1)
/afs/cern.ch/user/c/calpas/www/comp.cc
root files:
/afs/cern.ch/user/c/calpas/www/r1.root
/afs/cern.ch/user/c/calpas/www/r2.root
Hi,
Please put your files in a publicly accessible location…
Cheers, Bertrand.
calbet
June 29, 2017, 10:28am
3
couet
June 29, 2017, 11:24am
4
your macro does not work:```
root [0]
Processing comp.C…
In file included from input_line_9:1:
/Users/couet/Downloads/comp.C:60:39: error: use of undeclared identifier 'vcolor’
hist[nfile][ndir]->SetLineColor(vcolor[nfile]);
calbet
June 29, 2017, 11:34am
5
Dear couet,
I fixed this, it should run fine now.
Regards
couet
June 29, 2017, 11:37am
6
You macro seems to be problematic . On mac with ROOT 6.10 it gives me:
root [0]
Processing comp.C...
file: r1.root
dir: ee
hist name: ee/cutflow
name: 0eehmupt
libc++abi.dylib: terminating with uncaught exception of type std::out_of_range: basic_string
calbet
June 29, 2017, 11:43am
7
Ok, can you please try now?
Regards
couet
June 29, 2017, 12:01pm
8
I get a canvas but still errors:
root [0]
Processing comp.C...
file: r1.root
dir: ee
hist name: ee/cutflow
name: ee0hmupt
file: r2.root
dir: ee
hist name: ee/cutflow
name: ee1hmupt
[/Users/couet/git/roottrunk-bin/lib/libCling.so] cling_runtime_internal_throwIfInvalidPointer (no debug info)
[<unknown binary>] (no debug info)
[/Users/couet/git/roottrunk-bin/lib/libCling.so] cling::Interpreter::RunFunction(clang::FunctionDecl const*, cling::Value*) (no debug info)
[/Users/couet/git/roottrunk-bin/lib/libCling.so] cling::Interpreter::EvaluateInternal(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cling::CompilationOptions, cling::Value*, cling::Transaction**, unsigned long) (no debug info)
[/Users/couet/git/roottrunk-bin/lib/libCling.so] cling::MetaSema::actOnxCommand(llvm::StringRef, llvm::StringRef, cling::Value*) (no debug info)
[/Users/couet/git/roottrunk-bin/lib/libCling.so] cling::MetaParser::isXCommand(cling::MetaSema::ActionResult&, cling::Value*) (no debug info)
[/Users/couet/git/roottrunk-bin/lib/libCling.so] cling::MetaParser::isCommand(cling::MetaSema::ActionResult&, cling::Value*) (no debug info)
[/Users/couet/git/roottrunk-bin/lib/libCling.so] cling::MetaParser::isMetaCommand(cling::MetaSema::ActionResult&, cling::Value*) (no debug info)
[/Users/couet/git/roottrunk-bin/lib/libCling.so] cling::MetaProcessor::process(llvm::StringRef, cling::Interpreter::CompilationResult&, cling::Value*, bool) (no debug info)
[/Users/couet/git/roottrunk-bin/lib/libCling.so] HandleInterpreterException(cling::MetaProcessor*, char const*, cling::Interpreter::CompilationResult&, cling::Value*) /Users/couet/git/roottrunk/core/metacling/src/TCling.cxx:1902
[/Users/couet/git/roottrunk-bin/lib/libCling.so] TCling::ProcessLine(char const*, TInterpreter::EErrorCode*) /Users/couet/git/roottrunk/core/metacling/src/TCling.cxx:2035
[/Users/couet/git/roottrunk-bin/lib/libCling.so] TCling::ProcessLineSynch(char const*, TInterpreter::EErrorCode*) /Users/couet/git/roottrunk/core/metacling/src/TCling.cxx:2884
[/Users/couet/git/roottrunk-bin/lib/libCore.so] TApplication::ExecuteFile(char const*, int*, bool) /Users/couet/git/roottrunk/core/base/src/TApplication.cxx:1137
[/Users/couet/git/roottrunk-bin/lib/libRint.so] TRint::ProcessLineNr(char const*, char const*, int*) /Users/couet/git/roottrunk/core/rint/src/TRint.cxx:756
[/Users/couet/git/roottrunk-bin/lib/libRint.so] TRint::Run(bool) /Users/couet/git/roottrunk/core/rint/src/TRint.cxx:416
[/Users/couet/git/roottrunk-bin/bin/root.exe] main /Users/couet/git/roottrunk/main/src/rmain.cxx:32
[/usr/lib/system/libdyld.dylib] start (no debug info)
[<unknown binary>] (no debug info)
Error in <HandleInterpreterException>: Trying to access a pointer that points to an invalid memory address..
Execution of your code was aborted.
In file included from input_line_9:1:
/Users/couet/Downloads/comp.C:95:7: warning: invalid memory pointer passed to a callee:
hmupt[nfile][nbdir]->SetLineColor(nfile);
^~~~~~~~~~~~~~~~~~~
root [1]
And this is the correct code:
canvastree->cd();
for(int nbfile=0; nbfile<nfile; nbfile++){
for(int nbdir=0; nbdir<ndir; nbdir++){
hmupt[nbfile][nbdir]->SetLineColor(nfile);
canvastree->cd();
hmupt[nbfile][nbdir]->Draw("hist&same");
}
}
calbet
June 29, 2017, 12:32pm
11
Hi Couet,
for me it runs file with root 6.08.
Regards
@calbet I just sent the solution…
calbet
June 29, 2017, 12:33pm
13
Hi Bellenot,
I add your suggestions, but I still have the same results, a canvas with one histogram instead of 2.
Regards
Here is what I see in the Canvas:
root [2] mupt->ls()
Canvas Name=mupt Title=mupt Option=
TCanvas fXlowNDC=0 fYlowNDC=0 fWNDC=1 fHNDC=1 Name= mupt Title= mupt Option=
OBJ: TList TList Doubly linked list : 0
TFrame X1= 31000.000000 Y1=0.000000 X2=75500.000000 Y2=1.050000
OBJ: TH1F hmupt[1][0] mu_pt : 0 at: 0x3005910
OBJ: TH1D ee0hmupt ee0hmupt : 0 at: 0x2f27480
OBJ: TH1D ee1hmupt ee1hmupt : 0 at: 0x2f0a6f0
OBJ: TPaveText title X1= 69937.501533 Y1=0.459375 X2=75500.001699 Y2=0.721875
calbet
June 29, 2017, 12:52pm
15
Hi Bellenot,
I’m confused. I created an array of histogram “TH1D *hmupt[2][1];”, I filled it with TTree->Draw(var>>hmupt), then I want to draw what I stored in the array. I did not created any TH1F.
Regards
couet
June 29, 2017, 1:10pm
16
The following command cannot work:
tree->Draw(Form("mu_pt>>hmupt[%d][%d]",nfile,ndir);
Because the string you pass to TTres::Draw
is not a piece of C++. It has its own syntax (see doc). Therefore you cannot use the pointer of the histogram in the string. You should use the name of the histogram. … Fix this first … you may have more issues after.
calbet
June 29, 2017, 2:26pm
17
Hi Couet,
I did (1) to parse the hist name as a char, please see (2) line 77 to 79 but still the same results. Do you see what is wrong?
Regards
(1)
string histname = hmupt[nfile][ndir]->GetName();
const char* histname_ = histname.c_str();
tree->Draw(“mu_pt>>histname_”);
(2)
http://calpas.web.cern.ch/calpas/comp.cc
couet
June 29, 2017, 2:31pm
18
We just noticed that one of your tree is empty.
Nope. This way: tree->Draw(Form("mu_pt>>%s",hmupt[nfile][ndir]->GetName()));
And as Olivier just said, the “nominal” tree, in the “r1.root” file has 0 entries, so you will never see any histogram from this tree…
This works for me:
for(int nbfile=0; nbfile<nfile; nbfile++){
for(int nbdir=0; nbdir<ndir; nbdir++){
hmupt[nbfile][nbdir]->SetLineColor(2+nbfile);
hmupt[nbfile][nbdir]->Draw("hist same");
}
}