# Problem with drawing cloned histogram

**URL:** <https://root-forum.cern.ch/t/problem-with-drawing-cloned-histogram/19720>\
**Category:** ROOT\
**Created:** [August 18, 2015, 9:59pm UTC](https://root-forum.cern.ch/t/problem-with-drawing-cloned-histogram/19720 "2015-08-18T21:59:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dwielane](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dwielane/32/12354_2.png) [@dwielane](https://root-forum.cern.ch/u/dwielane)\
**Post date:** [August 18, 2015, 9:59pm UTC](https://root-forum.cern.ch/t/problem-with-drawing-cloned-histogram/19720/1 "2015-08-18T21:59:41Z")

</div>

Dear ROOTers  
I have problem with drawing histogram. Inside of my class i have assignment operator where i make clone of histogram:

```auto
	fHisto = (TH1*)other.fHisto->Clone();
```

Later in macro I made something like

```auto
MyClass *A = new MyClassA();
MyClass B = *A;
delete A;
B->GetHistogram()->Draw();
```

However when I try to draw such histogram I get only white space with title. I call TCanvas::Update - but it doesn’t help. What is more strange - histogram contain data but those data cannot be drawn, also in fit panel new histograms are not available in list. Is it possible that this is some conflict of object names?

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [August 19, 2015, 6:37am UTC](https://root-forum.cern.ch/t/problem-with-drawing-cloned-histogram/19720/2 "2015-08-19T06:37:43Z")

</div>

Hi,

this is more subtle than that: this is a C++ matter.  
In your code you are not invoking an assignment operator (operator=) but a copy constructor (MyClass(const MyClass&)). Did you implement one?

Cheers,  
Danilo

---

<div class="post-metadata">

**Author:** ![dwielane](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dwielane/32/12354_2.png) [@dwielane](https://root-forum.cern.ch/u/dwielane)\
**Post date:** [August 19, 2015, 1:41pm UTC](https://root-forum.cern.ch/t/problem-with-drawing-cloned-histogram/19720/3 "2015-08-19T13:41:32Z")

</div>

Hi,  
I have also copy ctor that works in the same way :

```auto
	if(other.fHisto)
		fHisto = (TH1*)other.fHisto->Clone();
```

… and still have the same issue ☹

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [August 19, 2015, 1:49pm UTC](https://root-forum.cern.ch/t/problem-with-drawing-cloned-histogram/19720/4 "2015-08-19T13:49:57Z")

</div>

Hi,

this is an example I quickly put together: is it doing what you are trying to achieve?

```auto
// includes only necessary for aclic. Aclic necessary only when using ROOT5
#include "TH1F.h"
#include <iostream>

class MyClass{
public:
   MyClass():fHisto(new TH1F("h","h",64,-2,2)){
      fHisto->FillRandom("gaus");
   }
   MyClass(const MyClass& other){
      fHisto = (TH1*)other.fHisto->Clone();
   }
   ~MyClass(){
      cout << this << " " << fHisto << endl;
      delete fHisto;
   }
   TH1* GetHistogram() const{return fHisto;}
private:
   TH1* fHisto = nullptr;
};

void test(){
   auto A = new MyClass();
   MyClass B = *A;
   delete A;
   B.GetHistogram()->DrawClone();
}
```

---

<div class="post-metadata">

**Author:** ![dwielane](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dwielane/32/12354_2.png) [@dwielane](https://root-forum.cern.ch/u/dwielane)\
**Post date:** [August 19, 2015, 3:24pm UTC](https://root-forum.cern.ch/t/problem-with-drawing-cloned-histogram/19720/5 "2015-08-19T15:24:28Z")

</div>

Yes, this is what I want to get, but I would like to use “Draw” instead of “DrawClone”. I also don’t know why my code (witch is almost like yours) don’t draw content of such histogram even with DrawClone (I only see white space with title and frames).

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [August 19, 2015, 3:29pm UTC](https://root-forum.cern.ch/t/problem-with-drawing-cloned-histogram/19720/6 "2015-08-19T15:29:40Z")

</div>

Hi,

the DrawClone is there just to let the primitive (the histo in this case) survive after the scope of the test function.

Danilo
