Inheritance problem

[ I’m using ROOT 6.02/05 ]


I am trying to write a class that inherits from another class created with MakeClass. The code that I have written is the following,

#ifndef AnalysisWZ_h
#define AnalysisWZ_h

#include "AnalysisBase.h"

#include <TH1.h>
#include <TLorentzVector.h>
#include <TStyle.h>
#include <TSystem.h>
#include <fstream>
#include <iostream>

class AnalysisWZ : public AnalysisBase
 public :

 AnalysisWZ(Tree *tree=0) : AnalysisBase(tree) {}


  void  Loop             (TString sample);
  float MuonIsolation    (int k);
  float ElectronIsolation(int k);
  bool  IsFiducialLepton (int k);
  bool  IsTightLepton    (int k);
  bool  IsIsolatedLepton (int k);
  void  FillHistograms   (int ichannel, int icut);
  void  Summary          (TString title);



When I try to run it with the following line

g++ -o runWZ runWZ.C `root-config --cflags --glibs`

which calls the macro runWZ.C

#include "AnalysisWZ.C"

TString local_path = "/gpfs/csic_projects/cms/piedra/latino/";

void runWZ(TString sample)
  TFile* file = new TFile(local_path + "latino_" + sample + ".root");
  TTree* latino = (TTree*)file->Get("latino");
  AnalysisWZ awz(latino);

# ifndef __CINT__
int main()
  return 0;
# endif

I get this error,

Any help is welcome.


In the “AnalysisWZ.h”, try to move:
to the bottom of your class declaration (i.e. as the last line, just before the final “};”).
In the “AnalysisWZ.h”, you are also missing:
#include “TTree.h”
#include "TString.h"
and in the “runWZ.C”:
#include “TFile.h”

Thank you,
But with the modified versions (see attachments) I continue getting exactly the same errors.

AnalysisWZ.h (684 Bytes)
runWZ.C (411 Bytes)

AnalysisBase.h is missing.

BTW. From what I can see -> you do not need “ClassDef(AnalysisWZ,1);” at all (try to remove it).

Sorry, here it goes.
AnalysisBase.h (77.8 KB)

And removing the “ClassDef” line does not help, unfortunately.

At least one bug (“TTree” not “Tree”):
AnalysisWZ(TTree *tree=0) : AnalysisBase(tree) {}

Also, AnalysisWZ.C is missing if I still need to reproduce it.

AnalysisWZ.C is attached.

Indeed! Silly bug… Thanks! After fixing it the new error is the following:

AnalysisWZ.C (14 KB)

You probably also have the “AnalysisBase.C” file which was automatically created by “TTree::MakeClass”, too.
In your “AnalysisWZ.C”, right BEFORE #include “AnalysisWZ.h” add:
#include “AnalysisBase.C”
(If this doesn’t help, I will need this “AnalysisBase.C” file, too).

AnalysisBase.C is attached.

Hi Wile,

I am afraid it does not help…

AnalysisBase.C (1.45 KB)

Make the beginning of your “AnalysisWZ.C” looking like this: [code]#include “AnalysisBase.C”
#if defined(AnalysisBase_cxx)
#undef AnalysisBase_cxx
#endif /* AnalysisBase_cxx */

#include “AnalysisWZ.h”[/code] … another possible solution is … instead of modifying your “AnalysisWZ.C”, simply add “AnalysisBase.C” to your compilation line: `root-config --cxx --cflags` -o runWZ runWZ.C AnalysisBase.C `root-config --glibs` (In any case, remove “ClassDef(AnalysisWZ,1);” from your “AnalysisWZ.h”.)

The patch on AnalysisWZ.C works!

But the other option, call AnalysisBase.C at compilation, doesn’t work.

For me both solutions work (I tried both of them with ROOT 5.34.32, 6.02.12 and 6.04.00).

Thanks a lot Wile,

I had to remove an “include” to make the second solution also work. Indeed I will use that one :slight_smile: