# Creating multiple histograms from columnar dataset with different conditions

**URL:** <https://root-forum.cern.ch/t/creating-multiple-histograms-from-columnar-dataset-with-different-conditions/51584>\
**Category:** Newbie\
**Tags:** hist, root\
**Created:** [September 15, 2022, 11:44pm UTC](https://root-forum.cern.ch/t/creating-multiple-histograms-from-columnar-dataset-with-different-conditions/51584 "2022-09-15T23:44:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![PKimPhysics](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pkimphysics/32/30880_2.png) [@PKimPhysics](https://root-forum.cern.ch/u/PKimPhysics)\
**Post date:** [September 15, 2022, 11:44pm UTC](https://root-forum.cern.ch/t/creating-multiple-histograms-from-columnar-dataset-with-different-conditions/51584/1 "2022-09-15T23:44:20Z")

</div>

Hello everyone! I have basic knowledge of how to use ROOT but I can’t come up with a good idea to create a set of histograms, each containing cross-sections for a specific range of angles using a set of data we gathered. For example, I would like to fill a histogram with cross-sections in bins of energy that were measured between cosine angles of -1 to -0.9. The columns are lower bound cosine angle, upper bound cosine angle, lower bound energy, upper bound energy, and then the cross section. I would upload a text file containing the data but unfortunately I am a new user

I was contemplating if using the TDataFrame class would help in this case or creating some sort of loop to help sort it out, but I’m not exactly sure how to do this either. I’ll continue to look into this as well.

_ROOT Version:_ 6.26/06  
_Platform:_ Ubuntu 22.04.1  
_Compiler:_ Gpp-compiler for Atom

* * *

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [September 16, 2022, 7:36am UTC](https://root-forum.cern.ch/t/creating-multiple-histograms-from-columnar-dataset-with-different-conditions/51584/2 "2022-09-16T07:36:37Z")

</div>

Hi @PKimPhysics ,

and welcome to the ROOT forum.

See e.g. [this post](https://root-forum.cern.ch/t/looping-over-multiple-root-files-merging-them-and-plotting-a-particular-tree/51502/2) for a C++ example of something similar done with RDataFrame.

RDataFrame’s user guide is [here](https://root.cern/doc/master/classROOT_1_1RDataFrame.html) and there are a number of C++ and Python tutorials available [here](https://root.cern/doc/master/group __tutorial__ dataframe.html).

Basically you want to create a list/vector of RDataFrame results that you fill, in a loop, with several result histograms.

I hope this helps.  
Enrico

---

<div class="post-metadata">

**Author:** ![PKimPhysics](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pkimphysics/32/30880_2.png) [@PKimPhysics](https://root-forum.cern.ch/u/PKimPhysics)\
**Post date:** [September 16, 2022, 2:41pm UTC](https://root-forum.cern.ch/t/creating-multiple-histograms-from-columnar-dataset-with-different-conditions/51584/3 "2022-09-16T14:41:18Z")

</div>

Hi Enrico! Thanks for the advice. I will try this out and report back.

This might be a silly question (just wanting to make sure) but does this work with text files as long as I replace the .root with .txt?

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [September 16, 2022, 2:56pm UTC](https://root-forum.cern.ch/t/creating-multiple-histograms-from-columnar-dataset-with-different-conditions/51584/4 "2022-09-16T14:56:02Z")

</div>

RDataFrame can read CSV files as long as the column types are one of the supported ones: [ROOT: ROOT::RDF::RCsvDS Class Reference](https://root.cern/doc/master/classROOT_1_1RDF_1_1RCsvDS.html) , tutorial here: [ROOT: tutorials/dataframe/df014\_CSVDataSource.C File Reference](https://root.cern/doc/master/df014__CSVDataSource_8C.html)

---

<div class="post-metadata">

**Author:** ![PKimPhysics](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pkimphysics/32/30880_2.png) [@PKimPhysics](https://root-forum.cern.ch/u/PKimPhysics)\
**Post date:** [September 16, 2022, 4:55pm UTC](https://root-forum.cern.ch/t/creating-multiple-histograms-from-columnar-dataset-with-different-conditions/51584/5 "2022-09-16T16:55:16Z")

</div>

Thank you! I’ll see if I run into any problems.
