For loop is not working properly

Hello everyone,

In my experimental setup, I have seven plastic scintillators. To see their plot on one canvas I wrote the following code. As you can notice variable pla[7][20] contains the name of all plastics. Then, I am just looping this variable to plot the data from each plastic.

void bugTest()
{
  TChain *cal = new TChain("cal");
  cal -> Add("test.root"); // test file

  // name of plastic
  char pla[7][20] = {"F3PLA", "F5PLA", "F7PLA", "F8PLA", "F11PLA", "F11LONG", "F11VETO"};

  TCanvas *can = new TCanvas("can", "can", 750, 500);
  can -> Divide(3, 3);

  for (int i = 0; i < 7; i++)
  {
    TH1F *h = new TH1F();

    can -> cd(i + 1); // change canvas pad
    cal -> Draw( Form("%s_TR_raw>>h", pla[i]) ); // draw different plastic in loop
    cout << Form("%s_TR_raw>>h", pla[i]) << endl; // see what is happening with the string
  }
}

Here is the command line output of the code. Notice that with each loop, the string value is changing.

root [0] .x bugTest.cc 
F3PLA_TR_raw>>h
F5PLA_TR_raw>>h
F7PLA_TR_raw>>h
F8PLA_TR_raw>>h
F11PLA_TR_raw>>h
F11LONG_TR_raw>>h
F11VETO_TR_raw>>h

In the plot, however, I am not getting different spectrums. All canvas pads has F3PLA_TR_raw plot.

I have no idea why it not taking different value. Because a very next line the code cout << Form("%s_TR_raw>>h", pla[i]) << endl; is working totally fine.

Please help me with this. My root version is ROOT 6.20/02.

Thank you,
Divyang.

Can you provide the data file, so we can try?

Try with: cal->Draw(Form("%s_TR_raw", pla[i]));

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.