# Read the data in a TCanvas

**URL:** <https://root-forum.cern.ch/t/read-the-data-in-a-tcanvas/33448>\
**Category:** ROOT\
**Created:** [April 3, 2019, 11:27pm UTC](https://root-forum.cern.ch/t/read-the-data-in-a-tcanvas/33448 "2019-04-03T23:27:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![yingjie\_wei](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/4bbf92/32.png) [@yingjie\_wei](https://root-forum.cern.ch/u/yingjie_wei)\
**Post date:** [April 3, 2019, 11:27pm UTC](https://root-forum.cern.ch/t/read-the-data-in-a-tcanvas/33448/1 "2019-04-03T23:27:14Z")

</div>

* * *

_ROOT Version:_ Not Provided  
\_Platform: Centos 7  
_Compiler:_ Not Provided

* * *

[Sys\_Pt\_IsoSFNom\_All\_IsoFCLoose.root](https://root-forum.cern.ch/uploads/default/original/3X/a/6/a622131fa8c431c713e566b532c5a25b5f49c019.root) (21.8 KB)

There are several OBJ in my root file, and I want to read the data in TGraphAsymmtry. This problem is quite similar with [https://root-forum.cern.ch/t/convert-canvas-into-histogram-in-root/16322](https://root-forum.cern.ch/t/convert-canvas-into-histogram-in-root/16322)  
However, I used the code in the answer like:

```auto
(1). TFile *th1 = new TFile("Sys_Pt_IsoSFNom_All_IsoFCLoose.root")
(2).TCanvas *c1 = (TCanvas*)t1->Get("Sys_ p_{T} [GeV]_IsoSFNom_All_IsoFCLoose")
(there is a star before c1 and after TCanvas. It disappeared after I post it)
(3).c1->ls()
Canvas Name=Sys_ p_{T} [GeV]_IsoSFNom_All_IsoFCLoose Title=Sys_ p_{T} [GeV]_IsoSFNom_All_IsoFCLoose Option=
 TCanvas fXlowNDC=0 fYlowNDC=0 fWNDC=1 fHNDC=1 Name= Sys_ p_{T} [GeV]_IsoSFNom_All_IsoFCLoose Title= Sys_ p_{T} [GeV]_IsoSFNom_All_IsoFCLoose Option=
  OBJ: TList	TList	Doubly linked list : 0
   TFrame X1= 3.000000 Y1=0.001000 X2=500.000000 Y2=1000.000000
   OBJ: TH1F	Nom_ZmumuZmumuTPIsoIsoSFNomIsoFCLooseAllPtOCProbe	Z#rightarrow#mu#mu : 1 at: 0x3ba5ad0
   OBJ: TGraphAsymmErrors Total : 1 at: 0x3be5010
   OBJ: TGraphAsymmErrors isolBkg : 1 at: 0x3bebeb0
   OBJ: TGraphAsymmErrors Statistics : 1 at: 0x3bec550
   OBJ: TGraphAsymmErrors eta : 1 at: 0x3becbf0
   OBJ: TGraphAsymmErrors mass : 1 at: 0x3bed290
   OBJ: TGraphAsymmErrors Statistics (MC) : 1 at: 0x3bed930
   OBJ: TGraphAsymmErrors tpdR : 1 at: 0x3bedfd0
   OBJ: TGraphAsymmErrors probeQ : 1 at: 0x3bee670
   OBJ: TGraphAsymmErrors tagIsol : 1 at: 0x3beed10
   OBJ: TGraphAsymmErrors dRmuj : 1 at: 0x3bef3b0
   OBJ: TLegend	TPave X1= 40.746839 Y1=620.253547 X2=455.962026 Y2=835.443204
   Text X=0.190000 Y=0.900000 Text=#font[72]{ATLAS} Internal
   Text X=0.190000 Y=0.850000 Text=#sqrt{s} = 13 TeV, 44.3 fb^{-1}
   Text X=0.920000 Y=0.900000 Text=IsoFCLoose
   Text X=0.920000 Y=0.850000 Text=IsoSFNom
   Text X=0.500000 Y=0.850000 Text=
(4). TH1F *th1 = (TH1F*)c1->GetPrimitive("Total")
(there is a star before th1 and after TH1F. It disappeared after I post it)

```

and also

```auto
TGraphAsymmErrors *tg1 = (TGraphAsymmErrors*)c1->GetPrimitive("Total")

```

doesn’t work  
However, it said: nullptr.

Could you please help me?  
I want to read the data in the TGraphAsymmtry objects.

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [April 4, 2019, 6:51am UTC](https://root-forum.cern.ch/t/read-the-data-in-a-tcanvas/33448/2 "2019-04-04T06:51:41Z")

</div>

All your graphs have nonempty titles (e.g. “Total”, “isolBkg”) but all names are empty (i.e. `"`", so that you cannot “find” them):

```auto
new TCanvas();
((TGraphAsymmErrors*)(c1->GetListOfPrimitives()->At(1)))->Draw("ALP");

```

BTW. When you post “source code” or “output” here, do remember to enclose them into two lines which contain just three characters ``` (see how your post has been edited above).

---

<div class="post-metadata">

**Author:** ![yingjie\_wei](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/4bbf92/32.png) [@yingjie\_wei](https://root-forum.cern.ch/u/yingjie_wei)\
**Post date:** [April 4, 2019, 4:55pm UTC](https://root-forum.cern.ch/t/read-the-data-in-a-tcanvas/33448/3 "2019-04-04T16:55:03Z")

</div>

Many thanks Wile. It works well! And thanks for your instruction. This is my first time to post a question.  
Cheers

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [April 18, 2019, 4:55pm UTC](https://root-forum.cern.ch/t/read-the-data-in-a-tcanvas/33448/4 "2019-04-18T16:55:07Z")

</div>

Closed on April 18, 2019, 4:55pm UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
