Hi all, I’m trying to plot a (7,4) canvas using a branch of the tree. To be more specific, my tree looks something like this Tree[i][j] where i takes 7 values and for each i we have 4 values of j and in each section, I wanna plot let’s say X2[i][j] : X1[i][j] with a specific cut “m1<X[i][j]<m2” ; (m1, m2-> double).
but the m2 and m1 for every coordinate of the canvas are different. For example, (0,0) coordinate of the canvas has cut condition m1<X[i][j]<m2; whereas, (0,1) has cut condition m3<X[i][j]<m4; similarly, (3,4) has cut condition m5<X[i][j]<m6, etc.
Right now what I’m doing is :
It works well but time consuming and unnecessary long plotting routine AND amateur. So, I was wondering if there is some way where I can have the cut conditions in one file and then someway incorporate them conditions values inside tree->Draw() command within a for loop.
Thanks for your time. please do let me know if you need any more info to assist me.
@FoxWise thanks for your note. I’m not able to understand how the following line from your routine will going to work:
string cut = Form("%s<X[%d][%d]<%s", cuts[cut_idx++], i, j, cuts[cut_idx ++]);
cuts[cut_idx++] and cut[cut_idx ++] for %s<X<%s, I also don’t understand how that iterates over the subsequent values inside the ''cut" vector string. Can you please explain that? looking forward to hearing from you. Thanks.
p.s: this is the error I’m getting upon compiling:
/home/Desktop/caliboutput/correlationplot.c:73:55: error: cannot pass non-trivial object of type 'value_type' (aka 'std::__cxx11::basic_string<char>') to variadic function;
expected type from format string was 'char *' [-Wnon-pod-varargs]
string cut = Form("%s<PPACTSumX[%d][%d]<%s", cuts[cut_idx++], i, j, cuts[cut_idx ++]);
~~ ^~~~~~~~~~~~~~~
/home/Desktop/caliboutput/correlationplot.c:73:55: note: did you mean to call the c_str() method?
string cut = Form("%s<PPACTSumX[%d][%d]<%s", cuts[cut_idx++], i, j, cuts[cut_idx ++]);
^
.c_str()
/home/Desktop/caliboutput/correlationplot.c:73:78: error: cannot pass non-trivial object of type 'value_type' (aka 'std::__cxx11::basic_string<char>') to variadic function;
expected type from format string was 'char *' [-Wnon-pod-varargs]
string cut = Form("%s<PPACTSumX[%d][%d]<%s", cuts[cut_idx++], i, j, cuts[cut_idx ++]);
~~ ^~~~~~~~~~~~~~~~
/home/Desktop/caliboutput/correlationplot.c:73:78: note: did you mean to call the c_str() method?
string cut = Form("%s<PPACTSumX[%d][%d]<%s", cuts[cut_idx++], i, j, cuts[cut_idx ++]);
^
.c_str()
/home/Desktop/caliboutput/correlationplot.c:73:67: warning: multiple unsequenced modifications to 'cut_idx' [-Wunsequenced]
string cut = Form("%s<PPACTSumX[%d][%d]<%s", cuts[cut_idx++], i, j, cuts[cut_idx ++]);Preformatted text
But the error gives you a hint, what is going wrong.
/home/Desktop/caliboutput/correlationplot.c:73:78: note: did you mean to call the c_str() method?
I used std::string, while it expects C-style string const char*. So you can do the conversion using cuts[cut_idx++].c_str() instead of cuts[cut_idx++].
Or, even better, as @Wile_E_Coyote proposed, use TString which I guess would do the job for you.
cuts[cut_idx++] is equivalent to:
cuts[cut_idx];
cut_idx = cut_idx + 1;
so, every time it is called, you will get the next element. As in your example
m1<X[i][j]<m2; whereas, (0,1) has cut condition m3<X[i][j]<m4; similarly, (3,4) has cut condition m5<X[i][j]<m6, etc.