MakeClass and user-defined header files

Hi

I’d like to ask for some advice regarding the following:

I’ve constructed a root tree where, for each event, information such as number of particles, particle ID, pseudorapidity, charge etc. is stored.

I’ve called MakeClass on the tree, which generated the files Analyse.h and Analyse.C and enabled me to loop through the tree and read each event.

Now, through each loop, I’d like to store each particle’s info in a Particle object, so that at the end of each loop I’d get a vector for use in analysis.

My Particle class is very simple, with just a header file Particle.h containing the constructor, data members such as charge and eta, and inline functions such as setCharge(int x) and getCharge().

All its functions are implemented in Particle.h, so there’s no .cxx implementation file.

What would be the best way to incorporate this Particle.h file into the MakeClass-generated Analyse files?

Thanks for any help,
Rae

Hi,

you’re making your life harder than necessary - you could have stored the Particle objects in your tree directly. Now that you have an n-tuple type tree you’ll have to transfer the data from the tree to your objects yourself. In your Analysis.C’s Loop method, you should create a new Particle object for each particle that’s stored in the n-tuple, and fill it with the data from the n-tuple. Don’t forget to delet the Particle objects after each event.

Cheers, Axel.

Thank you for your reply, Axel.

Your suggestion was what I had been planning to do, but what I’m having trouble with is declaring the Particle object in Analyse.h (and hence creating it in Analyse.C). If this were just a normal C++ analysis class, I could just add #include “Particle.h”.

But within the ROOT framework, I’m wondering whether I would have to go through the steps described in Chapter 13 (“Adding a Class”) of the User Guide? (Specifically, “Adding a class with a shared library”?)
In that case, would I have to write an implementation file for Particle.h to use the ClassImp macro? (At the moment, all of Particle’s functions are implemented in Particle.h, so it doesn’t need a separate implementation file.)

I would be grateful for any suggestions.

Thanks,
Rae

Hi Rae,

simply #include the header - you don’t need a source file (nor a ClassImp macro call). You can build a library from Particle.h by compiling it with “.L Particle.h+”. Afterwards you can build “.L Analysis.C+”, where Analysis.C (or its .h) #include Particle.h.

Axel.