# Dealing with macros and classes

Hi, I’d like to know how I couid “call a class” (I don’t know the exact lingo) from a macro.
Let me explain myself a bit. Usually, to analyze the contents of a tree I use the following:

```root -l file_to_analyze.root root [0] mytree->MakeClass("Analyze_my_tree")```
From there, I get two files: “Analyze_my_tree.C” and “Analyze_my_tree.h”. I write my code, mainly in “Analyze_my_tree.C::Loop()”, and then I create an object in ROOT and use the Loop method:

```root [1] .L Analyze_my_tree.C+ root [2] Analyze_my_tree t root [3] t.Loop()```
So far, no problem.
Now, I also have written a macro (“my_macro.C”). Essentially, it opens and reads data from a bunch of files, does a lot of computing, and finally gives me several arrays of parameters. What I want to do is, from my macro, be able to do the equivalent of the code above (i.e. Looping over the entries of mytree), using the arrays generated by the macro.
In fact, the Loop() essentially fills histograms using “histogram->Fill(variable,weight)”, where “weight” should be computed from the arrays of parameters.

I hope I’ve explained my problem clearly enough - what solution do you suggest?
(Thanks)

EDIT – Someone suggested the following technique: while in “my_macro.C”, save the arrays in a text file. In “Analyze_my_tree.C”, create the arrays again, and read their values from the text file. I think this is only a partial solution, as I (the user) will still have to manually enter prompt lines in ROOT, executing the macro, then loading the class, etc. instead of having everything automatically done in the macro.

Hi,

why don’t you fill your histograms at the end of my_class.C, manually opening the file and looping over the entries of the tree? It should be only a few more lines of code, plus the same lines you already wrote inside the Loop() method… I think…