MakeClass generated Files being used for more than one Tree


I have yet another small problem:)
I used the MakeClass to generate a macro and a header file and programmed my Analyzing code in the macro file. The Problem is, the header file only works with
My root files are organized like this:


where x goes from 1 to … and in each directory is a root file, a macro and the correpsonding header file

Up until now I had no problem with this but now it is getting annoying because every time I change something in the macro file, I have to overwrite it in each directory. The goal is to have one Analyze macro and header file in the measurements directory and specify the root file when executing.
So it should be like .L Analyse.C(“rawfile_date/rawfile_date.root”)

I tried these two variants (the one commented out is the second one)

[code]#define Analyze_cxx
#include “Analyze.h”
#include <TH2.h>
#include <TStyle.h>
#include <TCanvas.h>

void start(Char_t *subdir, Char_t *Input)
//TString dir = subdir+"/Analyze.h";
//#include dir;
Analyze a;

void Analyze::Loop()

this is from the makro file.

In the header file I simply replaced all the all the explicit root file names with “Input” (without the “”). I marked the positions

[code]#ifndef Analyze_h
#define Analyze_h

#include <TROOT.h>
#include <TChain.h>
#include <TFile.h>

class Analyze {
public :
TTree *fChain; //!pointer to the analyzed TTree or TChain
Int_t fCurrent; //!current Tree number in a TChain

// Declaration of leaf types
UInt_t event_number;

// List of branches
TBranch *b_event_number; //!

Analyze(TTree *tree=0);
virtual ~Analyze();
virtual Int_t Cut(Long64_t entry);
virtual Int_t GetEntry(Long64_t entry);
virtual Long64_t LoadTree(Long64_t entry);
virtual void Init(TTree *tree);
virtual void Loop();
virtual Bool_t Notify();
virtual void Show(Long64_t entry = -1);


#ifdef Analyze_cxx
Analyze::Analyze(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(Input);
if (!f) {
f = new TFile(Input);
tree = (TTree


if (!fChain) return;
delete fChain->GetCurrentFile();

Int_t Analyze::GetEntry(Long64_t entry)
// Read contents of entry.
if (!fChain) return 0;
return fChain->GetEntry(entry);
Long64_t Analyze::LoadTree(Long64_t entry)
// Set the environment to read one entry
if (!fChain) return -5;
Long64_t centry = fChain->LoadTree(entry);
if (centry < 0) return centry;
if (!fChain->InheritsFrom(TChain::Class())) return centry;
TChain chain = (TChain)fChain;
if (chain->GetTreeNumber() != fCurrent) {
fCurrent = chain->GetTreeNumber();
return centry;

void Analyze::Init(TTree *tree)
// The Init() function is called when the selector needs to initialize
// a new tree or chain. Typically here the branch addresses and branch
// pointers of the tree will be set.
// It is normally not necessary to make changes to the generated
// code, but the routine can be extended by the user if needed.
// Init() will be called many times when running on PROOF
// (once per file to be processed).

// Set branch addresses and branch pointers
if (!tree) return;
fChain = tree;
fCurrent = -1;

fChain->SetBranchAddress(“event_number”, &event_number, &b_event_number);


Bool_t Analyze::Notify()
// The Notify() function is called when a new file is opened. This
// can be either for a new TTree in a TChain or when when a new TTree
// is started when using PROOF. It is normally not necessary to make changes
// to the generated code, but the routine can be extended by the
// user if needed. The return value is currently not used.

return kTRUE;

void Analyze::Show(Long64_t entry)
// Print contents of entry.
// If entry is not specified, print current entry
if (!fChain) return;
Int_t Analyze::Cut(Long64_t entry)
// This function may be called from Loop.
// returns 1 if entry is accepted.
// returns -1 otherwise.
return 1;
#endif // #ifdef Analyze_cxx

I hope you guys can help :slight_smile:

Thank you


I recommend that you use MakeProxy with your code in myanalysis.C and the driver script:void start(Char_t *subdir, Char_t *Input) { gSystem->cd(subdir); TFile *file = TFile::Open(input); TTree *tree; tree->GetObject("Datensatz"); tree->Draw("../myanalysis.C+"); }See the documentation for TTree::Draw and TTree::MakeProxy for details and see $ROOTSYS/tutorials/tree/h1analysisProxy.[hC] for an example.


Thank you,

I will have a look :slight_smile: