# A few new member functions for various classes

**URL:** <https://root-forum.cern.ch/t/a-few-new-member-functions-for-various-classes/59434>\
**Category:** Evolution Proposals, Apps & Ideas\
**Created:** [May 22, 2024, 2:35pm UTC](https://root-forum.cern.ch/t/a-few-new-member-functions-for-various-classes/59434 "2024-05-22T14:35:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![yus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/9fc348/32.png) [@yus](https://root-forum.cern.ch/u/yus)\
**Post date:** [May 22, 2024, 2:35pm UTC](https://root-forum.cern.ch/t/a-few-new-member-functions-for-various-classes/59434/1 "2024-05-22T14:35:35Z")

</div>

Hi,

I’d like to propose a few new member functions for various classes that would make our lives easier. I expect these will be rather easy to implement:

1. `TH1::SetLineAndMarkerColor(Color_t color)` which would set the color of **both** the line and the marker of a histogram. It is rather annoying to have to type

```auto
h->SetMarkerColor(kRed);
h->SetLineColor(h->GetMarkerColor());

```

all the time.

1. `TGraphErrors::AddPointAndError(Double_t x, Double_t y, Double_t ex, Double_t ey)` similarly to [`TGraph::AddPoint(Double_t x, Double_t y)`](https://root.cern.ch/doc/v630/classTGraph.html#a056c11b01569445bfcaf33079cf01f27)

I’d appreciate if these ideas could be considered in the near future!

---

<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:** [May 22, 2024, 3:00pm UTC](https://root-forum.cern.ch/t/a-few-new-member-functions-for-various-classes/59434/2 "2024-05-22T15:00:12Z")

</div>

Thanks for your suggestions !

For point one the two methods you mention are inherited from `TAttMarker` and `TAttLine`. It is true that the color is the only attribute common to the `TAttXXX` classes. The is four of them: `TAttMarker` `TAttLine` `TAttFill` and `TAttText`. `TH1` inherits from all of them. Does that mean we will have to make all the 2 by 2 possible combinations ? and also the all the possible 3 by 3 combinations ? and one to set all of them in one go ? Would it not be easier to put in your code a method doing the setting you are asking for ?

For point two it is true that there is no `AddPointError` like we have `SetPointError`

---

<div class="post-metadata">

**Author:** ![yus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/9fc348/32.png) [@yus](https://root-forum.cern.ch/u/yus)\
**Post date:** [May 22, 2024, 3:08pm UTC](https://root-forum.cern.ch/t/a-few-new-member-functions-for-various-classes/59434/3 "2024-05-22T15:08:52Z")

</div>

Thanks Olivier for a quick reply!

> [@couet](#):
>
> Would it not be easier to put in your code a method doing the setting you are asking for ?

Probably, but I feel like `TAttFill` and `TAttText` are used significantly less often than `TAttMarker` and `TAttLine`: almost each histogram with markers uses the lines for uncertainties, which have to have matching colors almost always. So maybe having only one combination (`TAttMarker` + `TAttLine`) is enough.

---

<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:** [May 22, 2024, 3:18pm UTC](https://root-forum.cern.ch/t/a-few-new-member-functions-for-various-classes/59434/4 "2024-05-22T15:18:20Z")

</div>

Yes you are probably right, but is not very generic. What about having a method:

`TH1::SetColor(Color_t linecolor, Color_t markercolor, Color_t Ffllcolor, Color_t textcolor)`

With by default: `linecolor = markercolor = fillcolor = textcolor = -1`  
if one of the color is \< 0 this method does not change the corresponding color if positive it set the color.

To do what you are looking for it will be enough to do:

```auto
h->SetColor(kRed, kRed);

```

---

<div class="post-metadata">

**Author:** ![yus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/9fc348/32.png) [@yus](https://root-forum.cern.ch/u/yus)\
**Post date:** [May 22, 2024, 3:21pm UTC](https://root-forum.cern.ch/t/a-few-new-member-functions-for-various-classes/59434/5 "2024-05-22T15:21:34Z")

</div>

> [@couet](#):
>
> `TH1::SetColor(Color_t linecolor, Color_t markercolor, Color_t Ffllcolor, Color_t textcolor)`

Thanks, that would be great!

---

<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:** [May 22, 2024, 4:28pm UTC](https://root-forum.cern.ch/t/a-few-new-member-functions-for-various-classes/59434/6 "2024-05-22T16:28:05Z")

</div>

PR here: [New Method TH1::SetColor by couet · Pull Request #15609 · root-project/root · GitHub](https://github.com/root-project/root/pull/15609)

---

<div class="post-metadata">

**Author:** ![ferhue](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ferhue/32/29462_2.png) [@ferhue](https://root-forum.cern.ch/u/ferhue)\
**Post date:** [May 22, 2024, 5:46pm UTC](https://root-forum.cern.ch/t/a-few-new-member-functions-for-various-classes/59434/7 "2024-05-22T17:46:11Z")

</div>

For the error, there is already a PR: [[TGraphErrors] add AddPointError method by arabusov · Pull Request #15232 · root-project/root · GitHub](https://github.com/root-project/root/pull/15232)
