Images not remaining on Canvas

Hi, I can’t fix a problem with Canvas visualization.
I can see images remaining on the canvas just if they come from 1d hist or a graph.
Instead, if I plot 2d hist, or much complicated things, I can still see pads and corrects labels etc, but no data on the screen.
In any case saving the canvas as an image I can clearly see everything.
This holds for my win-version of root5 and for the linux-version of the newer root.
Thanks in advance

Hi,

I don’t know what your code is, so it’s hard to tell. But I can guess: check the chapter on “Ownership” in the Users Manual. A TFile might be eating your histograms!

Cheers, Axel.

I you have a small script reproducing your problem post it here and we will make it work as you wish.

#include <cstdlib>
#include <cmath>
#include "TFile.h"
#include "TTree.h"
#include "TChain.h"
#include "TROOT.h"
#include "TCutG.h"
#include "TNtuple.h"
#include "TF1.h"
#include "TF2.h"
#include <string>
#include <TCut.h>
#include <TCanvas.h>
#include <TStyle.h>
#include "TPad.h" 
#include <TH1.h>
#include <TH2.h>
#include "TLinearFitter.h"
#include "TF1.h"
#include "TRandom.h"
#include <stdio.h>
using namespace std;

void support()
{

///////////////////////////////////////////////////////////////////
    ///////////	open all files & cuts	///////////////////////////
    ///////////////////////////////////////////////////////////////////
    TFile f("c1_renew.root");
    TTree *runf = (TTree*)gDirectory->Get("run");
    TFile g("c2_renew.root");
    TTree *rung = (TTree*)gDirectory->Get("run");
    TFile h("c3_renew.root");
    TTree *runh = (TTree*)gDirectory->Get("run");
    TFile i("c4_renew.root");
    TTree *runi = (TTree*)gDirectory->Get("run");
    TFile ff("build_coinc/c1_renew_nuovirun.root");
    TTree *runff = (TTree*)gDirectory->Get("run");
    TFile gg("build_coinc/c2_renew_nuovirun.root");
    TTree *rungg = (TTree*)gDirectory->Get("run");
    TFile hh("build_coinc/c3_renew_nuovirun.root");
    TTree *runhh = (TTree*)gDirectory->Get("run");
    TFile ii("build_coinc/c4_renew_nuovirun.root");
    TTree *runii = (TTree*)gDirectory->Get("run");
    
    TFile s("sim0_c12_a0_mod.root");
    TTree *h50 = (TTree*)gDirectory->Get("h50");
    h50->SetMarkerColor(2);
    TFile t("sim1_c12_a1_mod.root");
    TTree *h51 = (TTree*)gDirectory->Get("h50");
    h51->SetMarkerColor(2);
    TFile u("sim0_c34_a0_mod.root");
    TTree *h52 = (TTree*)gDirectory->Get("h50");
    h52->SetMarkerColor(2);
    TFile v("sim1_c34_a1_mod.root");
    TTree *h53 = (TTree*)gDirectory->Get("h50");
    h53->SetMarkerColor(2);


    TCanvas *cc = new TCanvas("cc","cc",10,10,1000,1000);
    gROOT->ProcessLine(".x litioc3.c");
    // ...
    cc->Close();
    
    
    TCut partc1 = "litioc3&&alfac1&&e3li7x>7.5&&e4alx>4.5";
    // ...
    
    // tet1lab = litio - tet2lab = alfa
    //c1
    TCut simth34 = "tet2lab>-17.4&&tet2lab<-11.2&&tet1lab>11.4&&tet1lab<17.7&&e1lab>7.5&&e2lab>4.5";
    TCut thc1="theta3x>11.3&&theta3x<17.3&&theta4x>11.5&&theta4x<17.6";
    
/// ...
    
    TCut q3="q3x<0.8&&q3x>-0.1";
// ...
    
    gStyle->SetPalette(1);
    gStyle->SetOptStat("e");
//    cc->Clear();

    gStyle->SetCanvasColor(0);
    gStyle->SetPadColor(0);
    gStyle->SetFrameBorderMode(0);
    gStyle->SetPalette(1);
    gStyle->SetFillColor(0);

    TCanvas *c1 = new TCanvas("c1","c1",10,10,900,600);
    
    c1->SetLeftMargin(0.25);
    c1->SetRightMargin(0.25);
    c1->SetTopMargin(0.25);
    c1->SetBottomMargin(0.25);
    c1->SetFrameFillColor(0);

    gStyle->SetPalette(1);
    gStyle->SetOptStat(11);
  

    TH2F *h1=new TH2F("h1","#theta_{cm} vs E_{11B} coinc 1+2",100,9.8,13.8,18,0,180);
    h1->SetYTitle("#theta_{cm} [#circ]");
    h1->SetXTitle("E_{11B} [MeV]");
    runf->Draw("t12x:(e12x-2.79+11.454)>>h1",partc1&&thc1&&q3a0&&ps);
  
    
    TH2F *h2=new TH2F("h2","#theta_{cm} vs E_{11B} coinc 3+4",100,9.8,13.8,18,0,180);
    h2->SetYTitle("#theta_{cm} [#circ]");
    h2->SetXTitle("E_{11B} [MeV]");
    runh->Draw("t12x:(e12x-2.79+11.454)>>h2",partc3&&thc3&&q3a0&&ps);

    TH2F *h11=new TH2F("h11","#theta_{cm} vs E_{11B} coinc 1+2",100,9.8,13.8,18,0,180);
    h11->SetYTitle("#theta_{cm} [#circ]");
    h11->SetXTitle("E_{11B} [MeV]");
    runf->Draw("t12x:(e12x-2.79+11.454+0.478)>>h11",partc1&&thc1&&q3a1&&ps);

   
    TH2F *h21=new TH2F("h21","#theta_{cm} vs E_{11B} coinc 3+4",100,9.8,13.8,18,0,180);
    h21->SetYTitle("#theta_{cm} [#circ]");
    h21->SetXTitle("E_{11B} [MeV]");
    runh->Draw("t12x:(e12x-2.79+11.454+0.478)>>h21",partc3&&thc3&&q3a1&&ps);


    c1->Clear();
    c1->Divide(2,2);
    c1->cd(1);
    h1->Draw();
    c1->cd(2);
    h2->Draw();
    c1->cd(3);
    h11->Draw();
    c1->cd(4);
    h21->Draw();
    c1->SaveAs("../figureprof/ecmthcm-solodati.gif");
 
    
}

It is hard to tell what is going wrong as we do not have the .root and .c files this macro uses.

Just looking at your macro you should get four plots of histograms filled by the TTree::Draw commands.

If I remove all the code I cannot run because of the missing files, that’s what I get: four empty plots (but that’s expected and not really useful).

I see also that you Draw the TTree four times and then clear the canvas to have a white space to produce the real plots you need. Instead of doing that, you should use the option “goff” in the TTree::draw commands. It will skip the final drawing and you not not need to clear the canvas.

I am not sure to understand why, at the beginning of your code, you create a canvas and close it … It seems a bit useless.

So, to summarise, if you can provide something reproducing your problem and we can run, it will be more useful.

After some tries, I understood the problem is only when I use the Draw command for my TFiles.
Using “goff” nothing changes. Moreover, lines, fits etc correctly remain on the Canvas.
I also get this warnings the first time I make the macro runs without quitting Root

Warning in <TStreamerInfo::BuildCheck>:
   The StreamerInfo for version 1 of class TObject read from the file c1_renew.r
   has a different checksum than the previously loaded StreamerInfo.
   Reading objects of type TObject from the file c1_renew.root
   (and potentially other files) might not work correctly.
   Most likely the version number of the class was not properly
   updated [See ClassDef(TObject,1)].
Warning in <TStreamerInfo::CompareContent>: The following data member of
the on-file layout version 1 of class 'TObject' differs from
the in-memory layout version 1:
   unsigned int fUniqueID; //
vs
   UInt_t fUniqueID; //
Warning in <TStreamerInfo::CompareContent>: The following data member of
the on-file layout version 1 of class 'TObject' differs from
the in-memory layout version 1:
   unsigned int fBits; //
vs
   UInt_t fBits; //
Warning in <TStreamerInfo::BuildCheck>:
   The StreamerInfo of class TCollection read from file c1_renew.root
   has the same version (=3) as the active class but a different checksum.
   You should update the version to ClassDef(TCollection,4).
   Do not try to write objects with the current class definition,
   the files will not be readable.

Warning in <TStreamerInfo::CompareContent>: The following data member of
the on-file layout version 3 of class 'TCollection' differs from
the in-memory layout version 3:
   int fSize; //
vs
   Int_t fSize; //
Warning in <TStreamerInfo::BuildCheck>:
   The StreamerInfo of class TTree read from file c1_renew.root
   has the same version (=19) as the active class but a different checksum.
   You should update the version to ClassDef(TTree,20).
   Do not try to write objects with the current class definition,
   the files will not be readable.

Warning in <TStreamerInfo::CompareContent>: The following data member of
the on-file layout version 19 of class 'TTree' differs from
the in-memory layout version 19:
   double fWeight; //
vs
   Double_t fWeight; //
Warning in <TStreamerInfo::CompareContent>: The following data member of
the on-file layout version 19 of class 'TTree' differs from
the in-memory layout version 19:
   int fTimerInterval; //
vs
   Int_t fTimerInterval; //
Warning in <TStreamerInfo::CompareContent>: The following data member of
the on-file layout version 19 of class 'TTree' differs from
the in-memory layout version 19:
   int fScanField; //
vs
   Int_t fScanField; //
Warning in <TStreamerInfo::CompareContent>: The following data member of
the on-file layout version 19 of class 'TTree' differs from
the in-memory layout version 19:
   int fUpdate; //
vs
   Int_t fUpdate; //
Warning in <TStreamerInfo::CompareContent>: The following data member of
the on-file layout version 19 of class 'TTree' differs from
the in-memory layout version 19:
   int fDefaultEntryOffsetLen; //
vs
   Int_t fDefaultEntryOffsetLen; //
Warning in <TStreamerInfo::CompareContent>: The following data member of
the on-file layout version 19 of class 'TTree' differs from
the in-memory layout version 19:
   int fNClusterRange; //
vs
   Int_t fNClusterRange; //
Warning in <TStreamerInfo::BuildCheck>:
   The StreamerInfo of class TAttMarker read from file c1_renew.root
   has the same version (=2) as the active class but a different checksum.
   You should update the version to ClassDef(TAttMarker,3).
   Do not try to write objects with the current class definition,
   the files will not be readable.

Warning in <TStreamerInfo::CompareContent>: The following data member of
the on-file layout version 2 of class 'TAttMarker' differs from
the in-memory layout version 2:
   short fMarkerColor; //
vs
   Color_t fMarkerColor; //
Warning in <TStreamerInfo::CompareContent>: The following data member of
the on-file layout version 2 of class 'TAttMarker' differs from
the in-memory layout version 2:
   short fMarkerStyle; //
vs
   Style_t fMarkerStyle; //
Warning in <TStreamerInfo::CompareContent>: The following data member of
the on-file layout version 2 of class 'TAttMarker' differs from
the in-memory layout version 2:
   float fMarkerSize; //
vs
   Size_t fMarkerSize; //
Warning in <TStreamerInfo::BuildCheck>:
   The StreamerInfo of class TBranch read from file c1_renew.root
   has the same version (=12) as the active class but a different checksum.
   You should update the version to ClassDef(TBranch,13).
   Do not try to write objects with the current class definition,
   the files will not be readable.

Warning in <TStreamerInfo::CompareContent>: The following data member of
the on-file layout version 12 of class 'TBranch' differs from
the in-memory layout version 12:
   int fCompress; //
vs
   Int_t fCompress; //
Warning in <TStreamerInfo::CompareContent>: The following data member of
the on-file layout version 12 of class 'TBranch' differs from
the in-memory layout version 12:
   int fBasketSize; //
vs
   Int_t fBasketSize; //
Warning in <TStreamerInfo::CompareContent>: The following data member of
the on-file layout version 12 of class 'TBranch' differs from
the in-memory layout version 12:
   int fEntryOffsetLen; //
vs
   Int_t fEntryOffsetLen; //
Warning in <TStreamerInfo::CompareContent>: The following data member of
the on-file layout version 12 of class 'TBranch' differs from
the in-memory layout version 12:
   int fWriteBasket; //
vs
   Int_t fWriteBasket; //
Warning in <TStreamerInfo::CompareContent>: The following data member of
the on-file layout version 12 of class 'TBranch' differs from
the in-memory layout version 12:
   int fOffset; //
vs
   Int_t fOffset; //
Warning in <TStreamerInfo::CompareContent>: The following data member of
the on-file layout version 12 of class 'TBranch' differs from
the in-memory layout version 12:
   int fMaxBaskets; //
vs
   Int_t fMaxBaskets; //
Warning in <TStreamerInfo::CompareContent>: The following data member of
the on-file layout version 12 of class 'TBranch' differs from
the in-memory layout version 12:
   int fSplitLevel; //
vs
   Int_t fSplitLevel; //
Warning in <TStreamerInfo::CompareContent>: The following data member of
the on-file layout version 12 of class 'TBranch' differs from
the in-memory layout version 12:
   int* fBasketBytes; //fMaxBaskets
vs
   Int_t* fBasketBytes; //fMaxBaskets
Warning in <TStreamerInfo::BuildCheck>:
   The StreamerInfo of class TLeaf read from file c1_renew.root
   has the same version (=2) as the active class but a different checksum.
   You should update the version to ClassDef(TLeaf,3).
   Do not try to write objects with the current class definition,
   the files will not be readable.

Warning in <TStreamerInfo::CompareContent>: The following data member of
the on-file layout version 2 of class 'TLeaf' differs from
the in-memory layout version 2:
   int fLen; //
vs
   Int_t fLen; //
Warning in <TStreamerInfo::CompareContent>: The following data member of
the on-file layout version 2 of class 'TLeaf' differs from
the in-memory layout version 2:
   int fLenType; //
vs
   Int_t fLenType; //
Warning in <TStreamerInfo::CompareContent>: The following data member of
the on-file layout version 2 of class 'TLeaf' differs from
the in-memory layout version 2:
   int fOffset; //
vs
   Int_t fOffset; //
Warning in <TStreamerInfo::CompareContent>: The following data member of
the on-file layout version 2 of class 'TLeaf' differs from
the in-memory layout version 2:
   bool fIsRange; //
vs
   Bool_t fIsRange; //
Warning in <TStreamerInfo::CompareContent>: The following data member of
the on-file layout version 2 of class 'TLeaf' differs from
the in-memory layout version 2:
   bool fIsUnsigned; //
vs
   Bool_t fIsUnsigned; //
Warning in <TStreamerInfo::BuildCheck>:
   The StreamerInfo of class TLeafF read from file c1_renew.root
   has the same version (=1) as the active class but a different checksum.
   You should update the version to ClassDef(TLeafF,2).
   Do not try to write objects with the current class definition,
   the files will not be readable.

Warning in <TStreamerInfo::CompareContent>: The following data member of
the on-file layout version 1 of class 'TLeafF' differs from
the in-memory layout version 1:
   float fMinimum; //
vs
   Float_t fMinimum; //
Warning in <TStreamerInfo::CompareContent>: The following data member of
the on-file layout version 1 of class 'TLeafF' differs from
the in-memory layout version 1:
   float fMaximum; //
vs
   Float_t fMaximum; //
Warning in <TStreamerInfo::BuildCheck>:
   The StreamerInfo of class TRefTable read from file c1_renew.root
   has the same version (=3) as the active class but a different checksum.
   You should update the version to ClassDef(TRefTable,4).
   Do not try to write objects with the current class definition,
   the files will not be readable.

Warning in <TStreamerInfo::CompareContent>: The following data member of
the on-file layout version 3 of class 'TRefTable' differs from
the in-memory layout version 3:
   int fSize; //
vs
   Int_t fSize; //
Warning in <TStreamerInfo::BuildCheck>:
   The StreamerInfo of class TObjArray read from file c1_renew.root
   has the same version (=3) as the active class but a different checksum.
   You should update the version to ClassDef(TObjArray,4).
   Do not try to write objects with the current class definition,
   the files will not be readable.

Warning in <TStreamerInfo::CompareContent>: The following data member of
the on-file layout version 3 of class 'TObjArray' differs from
the in-memory layout version 3:
   int fLowerBound; //
vs
   Int_t fLowerBound; //
Warning in <TStreamerInfo::CompareContent>: The following data member of
the on-file layout version 3 of class 'TObjArray' differs from
the in-memory layout version 3:
   int fLast; //
vs
   Int_t fLast; //
Info in <TCanvas::Print>: gif file prova.gif has been created

Hi,

Something is seriously wrong with your setup; these warnings are not normal at all. Do you have conflicting ROOT builds in your PATH? Let’s start with: where did you get ROOT from, and can you provide a reproducer that we can run ourselves?

Cheers, Axel

Sorry for the late answer, I had some problems in accessing my account.
I took Root from the official website, and the problem persist If I use Mac, Ubuntu and Win.
Other details:
1)It is not about the way I chain the data.
2)Figures remains on Canvas if I just use the command Draw as
run->Draw(“e1”)
while it doesn’t work if I use
TH1F *h1=new TH1F(“h1”,"",100,0,4096);
run->Draw(“e1>>h1”);
h1->Draw(“p”)

So now the best is to send us a little macro and the needed root file(s) reproducing your problem. It will allow to try it on our side.

b001.root (197,0 KB)
support.cc (1,3 KB)

As it is now the image does not remain on the canvas, while if I comment lines 54 and 55 (and uncomment 53) it remains on. In both cases the gif is created and shows the image correctly.

h1->DrawCopy("p"); … or … h1->SetDirectory(gROOT); h1->Draw("p");

1 Like

it works!!! :grin:

THAAAAANK YOU!!!