Pads in canvas aren't updating

In an effort to not have to generate several histograms by hand, in the attached file I attempt to use TChains and draw from them from multiple sources. However, I appear to be having a problem with everything in the canvases produced to update, except for the pad with the histogram itself. Titles over the histogram appear to be correct. The problem is that when the main function makeResponseGraphsNew() is called, the function produceMVAGraphs() which it repeatedly calls doesn’t seem to change output after the first instance.

As can be seen in the attached file, I have lines commented out from previous attempts at correcting this behavior. The problem could be one of pointers, but I thought that by declaring objects as opposed to pointers towards objects, memory would be cleared once a function completes?

makeResponseGraphsNew.C (5.0 KB)

_ROOT Version:_6.14/02
Compiler: gcc version 8.1.1 20180712 (Red Hat 8.1.1-5) (GCC)

We cannot run your example. The data files are missing.

So some of these files are quite large, on the order of gigabytes. However, I am attaching one of the smaller files. When opened, it will complain that the trees friended to it aren’t around, but that isn’t where the problem lies. Also, for the macro as above to work, paths will have to written out by the user.

backgroundCut-refinedHiCal2A-part_all.root (2.3 MB)

So I found a typo in the file which produces the last attached file. Let me see if correcting it and regenerating the file helps with the issue.

So even after making the correction to the ROOT file above, the problem still persists. Attached are updated files.

backgroundCut-refinedHiCal2A-part_all.root (1.9 MB)
makeResponseGraphsNew.C (8.8 KB)

It would be great if you could make your macro working directly. I downloaded you two file. Ruun the macro. and I get:

root [0] 
Processing makeResponseGraphsNew.C...
Error in <TFile::TFile>: file backgroundCut_New/refinedHiCal2A/backgroundCut-refinedHiCal2A-part_all.root does not exist

Does this forum let you attach directories in addition to files? What needs to be done is in the directory in which you have the macro, create the paths
then place the ROOT macro at the end of the first path.

But here, I’m attaching a version of the macro with shorter paths. Just make sure the macro and ROOT files are in the same directory.

makeResponseGraphsNew.C (9.5 KB)

I took your latest macro and I still get:

Processing makeResponseGraphsNew.C...
Warning in <TClass::Init>: no dictionary for class AnitaEventSummary::PayloadLocation is available
Error in <TFile::TFile>: file sampleKLCoeffs_New/refinedHiCal2A/KLCoeffs-refinedHiCal2A-part_78.root does not exist

The forum let you attach files. It helps a lot if we do not have to edit the macro showing the problem. I have the macro and the root file in the same folder.

So the forum lets you attach files, but it doesn’t let you attach directories, placing files into those directories.

makeResponseGraphsNew.C (10.0 KB)

So I just ran the attached version of this macro in the same directory containing the ROOT file above. I also get the Error you got last, but that error is different from the Error you got later. It’s a red herring. The root file KLCoeffs-refinedHiCal2A-part_all.root was made using

hadd -f -k sampleKLCoeffs_New/refinedHiCal2A/KLCoeffs-refinedHiCal2A-part_all.root sampleKLCoeffs_New/refinedHiCal2A/KLCoeffs-refinedHiCal2A-part_{78..152}.root

Although I got the same Error you got last, the macro still ran to completion.

Can you provide a macro running without errors ?

Ok I have cleaned up your macro. Still produce errors… file missing

void produceMVASampleGraphs(TString MVAType, TString sampleType) {

   int ww = 600;  //  Canvas width.
   int wh = int(0.78 * ww);  // Canvas height.

   //  Create TChain from which to plot.
   auto sampleChain = new TChain(sampleType + "ResponseTree");

   if (sampleType.EqualTo("thermal") || sampleType.EqualTo("signal")) {
      sampleChain->Add("backgroundCut-" + sampleType + "-part_all-0.root");
      sampleChain->Add("backgroundCut-" + sampleType + "-part_all-1.root");
      sampleChain->Add("backgroundCut-" + sampleType + "-part_all-2.root");
      sampleChain->Add("backgroundCut-" + sampleType + "-part_all-3.root");
   } else sampleChain->Add("backgroundCut-" + sampleType + "-part_all.root");

   //  Create canvases for response plots.
   auto  cResponse = new TCanvas("cResponse" + MVAType + sampleType, "Canvas for " + MVAType + " " + sampleType + ".", 200, 0, ww, wh);
   auto cWeightedResponse = new TCanvas("cWeightedResponse" + MVAType + sampleType, "Canvas for weighted " + MVAType + " " + sampleType + ".", 200, 0, ww, wh);

   auto cCutResponse = new TCanvas("cCutResponse" + MVAType + sampleType, "Canvas for " + MVAType + " " + sampleType + " satisfying cut.", 200, 0, ww, wh);
   auto cWeightedCutResponse = new TCanvas("cWeightedCutResponse" + MVAType + sampleType, "Canvas for weighted " + MVAType + " " + sampleType + " satisfying cut.", 200, 0, ww, wh);

   sampleChain->Draw("unweighted." + MVAType);
   cResponse->SaveAs(MVAType + "_" + sampleType + ".png");

   sampleChain->Draw("weighted." + MVAType);
   cWeightedResponse->SaveAs(MVAType + "_" + sampleType + "Weighted.png");

   sampleChain->Draw("unweighted." + MVAType, "unweighted." + MVAType + " > 0");
   cCutResponse->SaveAs(MVAType + "_" + sampleType + "_cut.png");

   sampleChain->Draw("weighted." + MVAType, "weighted." + MVAType + " > 0");
   cWeightedCutResponse->SaveAs(MVAType + "_" + sampleType + "Weighted_cut.png");

void produceMVAGraphs(TString MVAType) {
   produceMVASampleGraphs(MVAType, "refinedHiCal2A");

void makeResponseGraphsNew() {

So as far as I can tell, the problem I’m having has nothing to do with the errors regarding missing files. The problem is that in the PNG files produced, what is shown in the histograms only corresponds some of the data. For example, files containing the phrase “BDT” should only range between -1 to 1. However, that’s not what’s in the PNG files. It looks like the pads from the files containing “Fisher” are being copied over. Those aren’t limited to a range of -1 to 1.

When I sun the macro I sent you I get 4 canvases and 4 png. They are the same.
Here are the png:

No, those appear to be as expected. Please add back the other produceMVAGraphs() under makeResponseGraphsNew() that you deleted in cleaning up the macro. You should then see duplicates.

Ok I can add those lines but with so many errors of data file missing I would not be surprise that all the plot are the same. Can you provide some script without errors ?

From what I’m seeing, the errors you’re getting appear to be

  1. The ROOT file I have provided is apparently friended with the files used to produce it with had. I can provide those 70-odd files, if you want, but the data is the same.

  2. Special classes were used to save the data. To suppress that error, you would need to compile them from here:
    But for the macro being discussed on this forum, these really aren’t neccessary.

Even with these errors resolved, you should still see the problem I am having with the PNGs produced. Please add back those lines.

:frowning: … ok running this buggy macro now …

result here:

Thank you for adding those lines back in. So the PNG files indeed show the problem I have been having: the files ending in *_cut.png, *Weighted.png, *Weighted_cut.png, and just *.png are all just repeats of those first 4 PNG files you generated. That’s the problem.

Opening the ROOT file and using TTree::Draw() on branches of interest, this should not be the case.