How do I properly use a conversion specifier in Root? Below is what I have right now, but I am getting an error message. What am I doing wrong?
for(int i=1; i<8257; i++){
TH2I *h2 = (TH2I*)f->Get(Form("ch_ADC_max_all"));
TH1D *h1 = h2->ProjectionY("ch%i_ADC" % i,i,i);
error: invalid operands to binary expression ('const char *' and 'int') TH1D *h1 = h2->ProjectionY("ch%i_ADC" % i,i,i);
Thank you!
I don’t understand what you’re trying to do, but Form
works this way:
Use something like:
TH2I *h2 = (TH2I*)f->Get("ch_ADC_max_all");
for (int i=1; i<8257; i++) {
TH1D *h1 = h2->ProjectionY(Form("ch%d_ADC",i));
This will call:
TH1D *h1 = h2->ProjectionY(Form("ch0_ADC");
TH1D *h1 = h2->ProjectionY(Form("ch1_ADC");
TH1D *h1 = h2->ProjectionY(Form("ch2_ADC");
TH1D *h1 = h2->ProjectionY(Form("ch3_ADC");
...
And will complains because you replace (redefine) h1 at every loop iteration…
I have a 2D histo with 8000 bins, and I need to make 8000 individual 1D histos from it (then analyze the histo, and move on to the next one).
I’m afraid I can’t write them all out explicitly because there are too many!
Try:
TH1D *h1;
TH2I *h2 = (TH2I*)f->Get("ch_ADC_max_all");
for (int i=1; i<7999; i++) {
h1 = h2->ProjectionY(Form("ch%d_ADC",i), i, i+1);
Cheers, Bertrand.
use Form()
, as in the previous example…
It works! It all works! Thank you very much!!!
system
Closed
April 26, 2017, 2:20pm
9
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.