# Overlying Histograms TH1F on TProfile

**URL:** <https://root-forum.cern.ch/t/overlying-histograms-th1f-on-tprofile/37633>\
**Category:** Newbie\
**Created:** [January 20, 2020, 2:11am UTC](https://root-forum.cern.ch/t/overlying-histograms-th1f-on-tprofile/37633 "2020-01-20T02:11:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sergio\_fernandez](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/b4bc9f/32.png) [@sergio\_fernandez](https://root-forum.cern.ch/u/sergio_fernandez)\
**Post date:** [January 20, 2020, 2:11am UTC](https://root-forum.cern.ch/t/overlying-histograms-th1f-on-tprofile/37633/1 "2020-01-20T02:11:07Z")

</div>

Hi everyone

I want to draw 3 different histograms with the same name TH1F inside 3 chains on one TProfile histogram. Only appears the canvas.

```auto
#include "TFile.h"
#include "TProfile.h"
#include "TCanvas.h"
#include "TDirectory.h"
______________________________________________________
{  
TFile *f=new TFile("Test.root");
  TCanvas *c = new TCanvas("c","c",1000,1000);
  gDirectory->cd("run/XXX/TauMon/Expert");
  TProfile *h1;
  std::vector<TString>Hist=
    {
      "chain1",
      "chain2",
      "chain3",
     };
cout<<"5"<<endl;
  for (int i=0; i<Hist.size();i++){
            gDirectory->cd(Hist[i]+"/TypeOfHistogram/Efficiency");
            h1=(TProfile*)f->Get("MyHist");
         if (i>0){
      h1->Draw("same");
      gDirectory->cd("../../../");
                  }
                  else {
	   h1->Draw();
	   gDirectory->cd("../../../");
                        }
                                   } 
}

```

* * *

The error on terminal:

```auto
#0 0x00007f71cac9c687 in __GI___ waitpid (pid=11214, stat_loc=stat_loc
entry=0x7ffdae89c668, options=options
entry=0) at ../sysdeps/unix/sysv/linux/waitpid.c:30
#1 0x00007f71cac07067 in do_system (line=<optimised out>) at ../sysdeps/posix/system.c:149
#2 0x00007f71cb8ab1b3 in TUnixSystem::Exec (shellcmd=<optimised out>, this=0x561d391a7b80) at /home/ryse/Productos/root-6.18.00/core/unix/src/TUnixSystem.cxx:2106
#3 TUnixSystem::StackTrace (this=0x561d391a7b80) at /home/ryse/Productos/root-6.18.00/core/unix/src/TUnixSystem.cxx:2400
#4 0x00007f71c60a1055 in cling::MultiplexInterpreterCallbacks::PrintStackTrace() () from /home/ryse/Productos/test_build/lib/libCling.so
#5 0x00007f71c60a0a5b in cling_runtime_internal_throwIfInvalidPointer () from /home/ryse/Productos/test_build/lib/libCling.so
#6 0x00007f71cc061a87 in ?? ()
#7 0x0000000000000000 in ?? ()
Error in <TRint::HandleTermInput()>: cling::InvalidDerefException caught: Trying to dereference null pointer or trying to call routine taking non-null arguments

```

* * *

_ROOT Version:_ 6.18  
_Platform:_ ubtuntu 16.04  
_Compiler:_ GNU compiler

* * *

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [January 20, 2020, 1:36pm UTC](https://root-forum.cern.ch/t/overlying-histograms-th1f-on-tprofile/37633/2 "2020-01-20T13:36:25Z")

</div>

I cannot run your example but I see that the sting you give to `gDirectory->cd()` does not work. I can make it work with:

```auto
gDirectory->cd(Form("%s%s",Hist[i].Data(),"/TypeOfHistogram/Efficiency"));

```
