Code made by MakeClass(), how can I execute by macro?


_ROOT Version:Used CMSSW_10_1_0 cmsenv root
_Platform:SL6
Compiler: Not Provided


Dear experts,

I generated “HistoMaker.C” and “HistoMaker.h” file by using MakeClass().
I know I can loop events like in root session:

$ .L HistoMaker.C
$ HistoMaker t;
$ t.Loop();

I’d like to make macro to do above lines in one step. So I searched and created macro “run_HistoMaker.C” :

#include <iostream>
#include "TSystem.h"
using namespace std;

void run_HistoMaker()
{
    cout << "Running HistoMaker" << endl;
    //gSystem->CompileMacro("HistoMaker.C++","k");
    //gROOT->ProcessLine(".L HistoMaker.C");
    //gROOT->LoadMacro("HistoMaker.C++");
    HistoMaker t;
    t.Loop()
}

As you can see the commented line I tried 3 methods but all cases gives error :

error: unknown type name 'HistoMaker'
    HistoMaker t;

How can I solve this?

Regards,
Sang-il

1 Like

Try to #include "HistoMaker.C"

1 Like

Thanks! It seems work now.

BTW, what is best/recommended way to run the code generated by MakeClass()?
Now my macro is :

#include <iostream>
#include "TSystem.h"
#include "HistoMaker.C"

void run_HistoMaker()
{
    cout << "Running HistoMaker" << endl;
    //gROOT->LoadMacro("HistoMaker.h");
    //gROOT->ProcessLine(".L HistoMaker.C+");
    gSystem->CompileMacro("HistoMaker.C","k");
    gSystem->Exec("mkdir ./histos/");
        
    TChain *tree = new TChain("Events");
    tree->Add("../../skimmer/python/output_skim_Summer16MC_merged/Summer16.g1800*.root");
    HistoMaker t(tree);
    t.Loop();
}

And I’m getting several error like below :

[spak@naf-cms11 /nfs/dust/cms/user/spak/DisappearingTracks/analysis/plotter_work/EvtLoop]$ root run_HistoMaker.C 
root [0] 
Processing run_HistoMaker.C...
Running HistoMaker
Info in <TUnixSystem::ACLiC>: creating shared library /nfs/dust/cms/user/spak/DisappearingTracks/analysis/plotter_work/EvtLoop/HistoMaker_C.so
In file included from HistoMaker_C_ACLiC_dict dictionary payload:10:
In file included from ./HistoMaker.C:2:
/nfs/dust/cms/user/spak/DisappearingTracks/analysis/plotter_work/EvtLoop/HistoMaker.h:220:13: error: redefinition of 'HistoMaker'
HistoMaker::HistoMaker(TTree *tree) : fChain(0) 
            ^
/nfs/dust/cms/user/spak/DisappearingTracks/analysis/plotter_work/EvtLoop/HistoMaker.h:220:13: note: previous definition is here
HistoMaker::HistoMaker(TTree *tree) : fChain(0) 
            ^

but Loop() is running even though these errors.

With ROOT 6 this can be a bit tricky.
I guess the best idea (which should work with ROOT 5 and 6) is to create a simple local “rootlogon.C” file in your “current working directory”:

void rootlogon(void) { // rootlogon.C ...
  // std::cout << "... rootlogon.C ..." << std::endl;
  gROOT->LoadMacro("HistoMaker.C++");
} // ... rootlogon.C

and then the “run_HistoMaker.cxx” could look like this:

#include "HistoMaker.h"
#include "TSystem.h"
#include <iostream>

void run_HistoMaker()
{
  std::cout << "Running HistoMaker" << std::endl;
  gSystem->mkdir("./histos/", kTRUE);
  
  TChain *tree = new TChain("Events");
  tree->Add("../../skimmer/python/output_skim_Summer16MC_merged/Summer16.g1800*.root");
  HistoMaker t(tree);
  t.Loop();
  delete tree;
}

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.