piedra
July 6, 2015, 11:24am
1
[ I’m using ROOT 6.02/05 ]
Hi,
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) {}
ClassDef(AnalysisWZ,1);
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);
};
#endif
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);
awz.Loop(sample);
}
# ifndef __CINT__
int main()
{
runWZ("WZJets_PHYS14");
return 0;
}
# endif
I get this error,
In file included from AnalysisWZ.C:2:0,
from runWZ.C:1:
AnalysisWZ.h:18:18: error: expected ‘)’ before ‘’ token
AnalysisWZ(Tree tree=0) : AnalysisBase(tree) {}
^
runWZ.C: In function ‘void runWZ(TString)’:
runWZ.C:13:24: error: no matching function for call to 'AnalysisWZ::AnalysisWZ(TTree &)’
AnalysisWZ awz(latino);
^
runWZ.C:13:24: note: candidates are:
In file included from AnalysisWZ.C:2:0,
from runWZ.C:1:
AnalysisWZ.h:14:7: note: AnalysisWZ::AnalysisWZ()
class AnalysisWZ : public AnalysisBase
^
AnalysisWZ.h:14:7: note: candidate expects 0 arguments, 1 provided
AnalysisWZ.h:14:7: note: constexpr AnalysisWZ::AnalysisWZ(const AnalysisWZ&)
AnalysisWZ.h:14:7: note: no known conversion for argument 1 from 'TTree ’ to ‘const AnalysisWZ&’
AnalysisWZ.h:14:7: note: constexpr AnalysisWZ::AnalysisWZ(AnalysisWZ&&)
AnalysisWZ.h:14:7: note: no known conversion for argument 1 from ‘TTree*’ to ‘AnalysisWZ&&’
Any help is welcome.
Thanks,
Jonatan
In the “AnalysisWZ.h”, try to move:
ClassDef(AnalysisWZ,1);
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”
piedra
July 6, 2015, 12:13pm
3
Thank you,
But with the modified versions (see attachments) I continue getting exactly the same errors.
Cheers,
Jonatan
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).
piedra
July 6, 2015, 12:32pm
5
Sorry, here it goes.
AnalysisBase.h (77.8 KB)
piedra
July 6, 2015, 12:34pm
6
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.
piedra
July 6, 2015, 12:41pm
8
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).
piedra
July 6, 2015, 12:59pm
10
AnalysisBase.C is attached.
Hi Wile,
I am afraid it does not help…
g++ -o runWZ runWZ.C root-config --cflags --glibs
In file included from AnalysisWZ.h:4:0,
from AnalysisWZ.C:3,
from runWZ.C:2:
AnalysisBase.h:985:1: error: redefinition of ‘AnalysisBase::AnalysisBase(TTree*)’
AnalysisBase::AnalysisBase(TTree tree) : fChain(0)
^
In file included from AnalysisBase.C:2:0,
from AnalysisWZ.C:2,
from runWZ.C:2:
AnalysisBase.h:985:1: note: 'AnalysisBase::AnalysisBase(TTree )’ previously defined here
AnalysisBase::AnalysisBase(TTree *tree) : fChain(0)
^
In file included from AnalysisWZ.h:4:0,
from AnalysisWZ.C:3,
from runWZ.C:2:
AnalysisBase.h:1000:1: error: redefinition of ‘AnalysisBase::~AnalysisBase()’
AnalysisBase::~AnalysisBase()
…
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”.)
piedra
July 6, 2015, 1:16pm
12
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).
piedra
July 6, 2015, 1:39pm
14
Thanks a lot Wile,
I had to remove an “include” to make the second solution also work. Indeed I will use that one
Best!
Jonatan