Error: illegal pointer to class object

Hi ,
I am trying to plot certain variables from three different root files in the same canvas. But when I run the script I get the following error:

Error: illegal pointer to class object Get(chvar[ivar]) 0x0 12 overlap2.C:54:

When I remove line 54 the code works fine. It seems there is some problem with the root or some thing like which I am not smart enough to figure out. Please bail me out help will be appreciated. I have added the root file which is troubling me and the script
overlap2.C (2.77 KB)
J_1_40.root (12.1 KB)

Hi,

you are missing plenty of test on objects being 0. See:

  for (int ivar = 0; ivar<nvar; ++ivar) {

    strcpy(buf,chvar[ivar]);
    strcat(buf,"_teste5");
     printf("%s (%d)\n", chvar[ivar], ivar);
     TH1F* h1;
     if ((h1 = (TH1F*)f1->Get(chvar[ivar])))
         h1 = (TH1F*)h1->Clone(buf);
    
    strcpy(buf,chvar[ivar]);
    strcat(buf,"_teste4");
     TH1F* h2;
     if ((h2 = (TH1F*)f2->Get(chvar[ivar])))
        h2 = (TH1F*)h2->Clone(buf);
 


    strcpy(buf,chvar[ivar]);
    strcat(buf,"_teste6");
     TH1F *h3;
     if ((h3 = (TH1F*)f3->Get(chvar[ivar])))
        h3 = (TH1F*)h3->Clone(buf);

    // check here if h1, h2 and h3 are != 0
   
    // h1 might be 0
      double scalefactorT = 1/(h1->GetBinContent(h1->GetMaximumBin()));
        h1->Scale(scalefactorT);

    // h2 might be 0
     double scalefactorE = 1/(h2->GetBinContent(h2->GetMaximumBin()));
	h2->Scale(scalefactorE);

     // h3 might be 0
     double scalefactorJ = 1/(h3->GetBinContent(h3->GetMaximumBin()));
	h3->Scale(scalefactorJ);

Please fix your code and things should work.

Cheers, Fons.