TChain together with MakeClass


I have on /afs/ 2 root files and the MakeClass output from chaining them (test.C and test.h). I can’t get any histogram to appear when loading the test.C and looping over all events. If I use only one file to create test.C and .h then I get the histogram to appear, however I need to chain a lot of files for my analysis.
The way I created test.C and .h is this:
root [0] TChain* chain = new TChain(“RootNtupleMaker”);
root [0] chain->Add(“ZmumuJets_Pt15x20ChNtuple_2.root”);
root [0] chain->Add(“ZmumuJets_Pt15x20ChNtuple_8.root”);
root [0] RootNtupleMaker->MakeClass(“test”);
Then I quit root, edit test.C and try in root again:
.L test.C ;
test t

I have tried as well to re-chain everything in root and then do
test.Loop(chain) - it didn’t work any better. Is there something else I need to do before looping over the events?

Thank you for your help!


   Usually I replace the follwoing lines in .h (here my class name is qstar)

qstar::qstar(TTree tree)
//if parameter tree is not specified (or zero), connect the file
//used to generate this class and read the Tree.
if (tree == 0) {
TFile f = (TFile)gROOT->GetListOfFiles()->FindObject(“qstar.root”);
if (!f) {
f = new TFile(“qstar.root”);
tree = (TTree




// if parameter tree is not specified (or zero), connect the file
// used to generate this class and read the Tree.
TChain *chain = new TChain(“h101”); //<–h101 is tree name
for (Int_t ifil_os= 0; ifil_os <13; ifil_os++) {

    Char_t namefile_os[20];
    strcpy (namefile_os, "2TeV200Pt_PT_");
    Char_t numfile_os[4];
    sprintf (numfile_os,"%d",ifil_os+1);
    Char_t endfile_os[6];
    strcpy (endfile_os, ".root");

 TString mystring_os = "" ;

 chain-> Add(mystring_os+namefile_os+numfile_os+endfile_os);



And also change

qstar(TTree *tree=0);
to --> qstar();
in your class definiton.

I hope it will help

with best


Thank you for your reply, I have made the changes, but I get the same result, no histograms (empty or filled) are created. Is there something I need to change in the .C file as well?



I think you have to do

test t;
t.Loop(); instead of test.Loop();
is’t it???

Instead of running .C , usually I run .so (I make it by compiling .C and ,h). You can use my Makefile . Download it from the link given at the end.

Just change the line
PACKAGE = Alpgen
PACKAGE = Test //< – your class name

Then do “make” it will give a “” , if everything is ok in your .C and .h.

Then in root session do the following:

.L; p;

Depending what you are doing in .C /.h you have to add various header files in your .h file. (Just look my .h at the link).

Also make sure your $(ROOTSYS} is defined.

with best,

sorry made a mistake

In root session it should be:

Test p; (<-- earlier i wrote p;)

with best,

I can compile it, I can load .so, but p gives the error:
Error: Symbol test is not defined in current scope (tmpfile):1:
Error: Failed to evaluate test.sop
*** Interpreter error recovered ***
I have done as well .L test.C++ to compile it, all I see in root is this:
Info in TUnixSystem::ACLiC: creating shared library /localscratch2/oana/CMSSW_1_6_12/src/Leptoquark/RootNtupleMaker/test/./
In file included from /localscratch2/oana/CMSSW_1_6_12/src/Leptoquark/RootNtupleMaker/test/./test.C:2,
from /localscratch2/oana/CMSSW_1_6_12/src/Leptoquark/RootNtupleMaker/test/./filehPIKQW.h:32,
from /localscratch2/oana/CMSSW_1_6_12/src/Leptoquark/RootNtupleMaker/test/./filehPIKQW.cxx:16:
/localscratch2/oana/CMSSW_1_6_12/src/Leptoquark/RootNtupleMaker/test/./test.h:424: warning: unused parameter ‘entry’

I’ll just go line by line and compare it to your .h file, because I don’t know what else to do, it doesn’t give me any error from compiling it, so I can’t see what’s the difference and why it doesn’t work. The moment I add a chain it totally ignores whatever I have inside the .C file, it doesn’t create the histograms at all. :frowning:

Is there a way to merge the files in root so I bypass the chain step? Maybe that will save me some time…

Thank you for your help!!


As I mentioned earlier if you are able to make .so then


test p;
p.Loop(); (<— Earlier I wrote p; by mistake)

with best,

I have tried it, it didn’t create the histogram. Even if I want to fill it with just a number that is not given by anything inside my root files, it still doesn’t get created.

I have taken your example and compared line by line, I think it got changed in all the right places, but unfortunately it just refuses to create histograms when I use chain. It does print things out from the loop, but it never creates any histograms.



To avoid a long iteration, Could you post the shortest possible script reproducing your problem?



On afs/ I have 2 root ntuples, plus test.C and test.h which were created by MakeClass after I chained them. Please if possible copy them and see if in root they create a histogram or just the RootNtupleMaker tree. I just get the tree, no histogram. If however I create .C and .h from just ONE single file and loop over that file (or any other one, but just one, not several) then I get the histogram out.

Sushil was recommending changing inside the .h file, I have done those changes as well (see example.C and example.h in public), but unfortunately it doesn’t create any histogram either…

I’m sure I must be nissing something there, but I can’t see what.



When doing

.L test.C test t t.Loop()
I get one histogram “St” with 485 entries.


Then I don’t know, I am not getting any out on lxplus or my local pc - must be some issue with versions or setup of root…

Thanks and sorry for the extra spam!