Cannot reproduce manual example

Asked by hprager on 2018-08-18

Hello,

I'm trying to reproduce the example of the manual (https://arxiv.org/pdf/1206.1599.pdf from p101) to understand how to get Root histograms using MA5 but I get a problem during the compilation. I'm using ROOT 6.12/06 and I get the following error message when I run "make"

-e --------------------------------------------------------
-e Building MadAnalysis Job
-e --------------------------------------------------------
-e --------------------------------------------------------
-e Compilation
-e --------------------------------------------------------
c++ -Wall -O3 -fPIC -I/home/hprager/Research/Softwares/MG5_aMC_v2_6_2/HEPTools/madanalysis5/madanalysis5/tools/ -I./ -pthread -std=c++11 -m64 -I/home/hprager/Research/Softwares/root/include -o Main/main.o -c Main/main.cpp
In file included from ./SampleAnalyzer/User/Analyzer/analysisList.h:1:0,
                 from Main/main.cpp:12:
./SampleAnalyzer/User/Analyzer/user.h:18:3: error: ‘TH1F’ does not name a type
   TH1F* myHisto;
   ^
Makefile:101: recipe for target 'Main/main.o' failed
make: *** [Main/main.o] Error 1

How can I solve this problem?
Also I was wondering if there is an easy way to get plots from the histos.saf files?

Cheers,
Hugo

************************************************************************************

Here are my user.h and user.cpp files:

#ifndef analysis_user_h
#define analysis_user_h

#include "SampleAnalyzer/Process/Analyzer/AnalyzerBase.h"

namespace MA5
{
class user : public AnalyzerBase
{
  INIT_ANALYSIS(user,"user")

 public:
  virtual bool Initialize(const MA5::Configuration& cfg, const std::map<std::string,std::string>& parameters);
  virtual void Finalize(const SampleFormat& summary, const std::vector<SampleFormat>& files);
  virtual bool Execute(SampleFormat& sample, const EventFormat& event);

 private:
  TH1F* myHisto;
};
}

#endif

#include "SampleAnalyzer/User/Analyzer/user.h"
using namespace MA5;
using namespace std;

// -----------------------------------------------------------------------------
// Initialize
// function called one time at the beginning of the analysis
// -----------------------------------------------------------------------------
bool user::Initialize(const MA5::Configuration& cfg, const std::map<std::string,std::string>& parameters)
{
  cout << "BEGIN Initialization" << endl;

  // Initializing the histogram
  myHisto = new TH1F("myHisto","cos#theta^{*}",15,-1,1);

  cout << "END Initialization" << endl;
  return true;
}

// -----------------------------------------------------------------------------
// Finalize
// function called one time at the end of the analysis
// -----------------------------------------------------------------------------
void user::Finalize(const SampleFormat& summary, const std::vector<SampleFormat>& files)
{
  cout << "BEGIN Finalization" << endl;

  // saving histos

  // Color of the canvas background
  gStyle->SetCanvasColor(0);
  // Turning off the border lines of the canvas
  gStyle->SetCanvasBorderMode(0);
  // Configuring statistics printing
  gStyle->SetOptStat(111110);
  // Creating the output root file
  TCanvas* myCanvas = new TCanvas("myCanvas","");
  // Setting background color
  myHisto->SetFillColor(kBlue);
  // Normalization of the histogram: L = 10 fb-1
  double nrm = summary.mc()->xsection() * 10000. /
  static_cast<float>(summary.nevents());
  myHisto->Scale(nrm);
  // Setting axis title
  myHisto->GetXaxis()->SetTitle("cos#theta^{*}");
  // Drawing histogram
  myHisto->Draw();
  // Saving plot
  myCanvas->SaveAs((outputName_+".eps").c_str());

  cout << "END Finalization" << endl;
}

// -----------------------------------------------------------------------------
// Execute
// function called each time one event is read
// -----------------------------------------------------------------------------
bool user::Execute(SampleFormat& sample, const EventFormat& event)
{

    // Initialization of three pointers to the lepton,

    // W and top quark
    const MCParticleFormat* top = 0;
    const MCParticleFormat* w = 0;
    const MCParticleFormat* lepton = 0;

    // Identification of the three particles of interest
    for (unsigned int i=0;i<event.mc()->particles().size();i++)
        {
        const MCParticleFormat* prt=&(event.mc()->particles()[i]);
        // The lepton is a final state particle
        if (!PHYSICS->IsFinalState(prt)) continue;
        // Lepton selection based on the PDG-id
        if ( std::abs(prt->pdgid())!=11 &&
             std::abs(prt->pdgid())!=13 ) continue;
        // Getting the mother of the lepton and checking if it is a W-boson
        const MCParticleFormat* mother = prt->mother1();
        if (mother==0) continue;
        if (std::abs(mother->pdgid())!=24) continue;
        // Getting the grand-mother of the lepton and checking if it is a top quark
        const MCParticleFormat* grandmother = mother->mother1();
        if (grandmother==0) continue;
        if (std::abs(grandmother->pdgid())!=6) continue;
        // Saving the selected particles
        lepton = prt;
        w = mother;
        top = grandmother;
        // Particles are found: breaking the loop
        break;
        }
    // Rejection of the event if the decay chain is not found
    if (lepton==0)
        {
        WARNING << "(t > b W > b l nu) decay chain not found!"
        << std::endl;
        return;
        }

    // Computing the observable; filling the histogram
    // Boosting the lepton four-momentum to the W rest frame
    MCParticleFormat lepton_new = *lepton;
    PHYSICS->ToRestFrame(lepton_new,w);
    // Boosting the W four-momentum to the top rest frame
    MCParticleFormat w_new = *w;
    PHYSICS->ToRestFrame(w_new,top);
    // Computing the observable; filling the histogram
    myHisto -> Fill( cos(lepton_new.angle(w_new)) );

}

Question information

Language:
English Edit question
Status:
Answered
For:
MadAnalysis 5 Edit question
Assignee:
No assignee Edit question
Last query:
2018-08-18
Last reply:
2018-08-27
Benjamin Fuks (fuks) said : #1

Hi Hugo,

MadAnalysis has changed a lot since 2012, and root is now optional. For this reason, please make sure you include the appropriate include in the header file,
  #include "SampleAnalyzer/Interfaces/root/RootMainHeaders.h"

Cheers,

Benjamin

> On 18 Aug 2018, at 18:23 , hprager <email address hidden> wrote:
>
> New question #672467 on MadAnalysis 5:
> https://answers.launchpad.net/madanalysis5/+question/672467
>
> Hello,
>
> I'm trying to reproduce the example of the manual (https://arxiv.org/pdf/1206.1599.pdf from p101) to understand how to get Root histograms using MA5 but I get a problem during the compilation. I'm using ROOT 6.12/06 and I get the following error message when I run "make"
>
> -e --------------------------------------------------------
> -e Building MadAnalysis Job
> -e --------------------------------------------------------
> -e --------------------------------------------------------
> -e Compilation
> -e --------------------------------------------------------
> c++ -Wall -O3 -fPIC -I/home/hprager/Research/Softwares/MG5_aMC_v2_6_2/HEPTools/madanalysis5/madanalysis5/tools/ -I./ -pthread -std=c++11 -m64 -I/home/hprager/Research/Softwares/root/include -o Main/main.o -c Main/main.cpp
> In file included from ./SampleAnalyzer/User/Analyzer/analysisList.h:1:0,
> from Main/main.cpp:12:
> ./SampleAnalyzer/User/Analyzer/user.h:18:3: error: ‘TH1F’ does not name a type
> TH1F* myHisto;
> ^
> Makefile:101: recipe for target 'Main/main.o' failed
> make: *** [Main/main.o] Error 1
>
> How can I solve this problem?
> Also I was wondering if there is an easy way to get plots from the histos.saf files?
>
> Cheers,
> Hugo
>
> ************************************************************************************
>
> Here are my user.h and user.cpp files:
>
>
> #ifndef analysis_user_h
> #define analysis_user_h
>
> #include "SampleAnalyzer/Process/Analyzer/AnalyzerBase.h"
>
> namespace MA5
> {
> class user : public AnalyzerBase
> {
> INIT_ANALYSIS(user,"user")
>
> public:
> virtual bool Initialize(const MA5::Configuration& cfg, const std::map<std::string,std::string>& parameters);
> virtual void Finalize(const SampleFormat& summary, const std::vector<SampleFormat>& files);
> virtual bool Execute(SampleFormat& sample, const EventFormat& event);
>
> private:
> TH1F* myHisto;
> };
> }
>
> #endif
>
>
>
> #include "SampleAnalyzer/User/Analyzer/user.h"
> using namespace MA5;
> using namespace std;
>
> // -----------------------------------------------------------------------------
> // Initialize
> // function called one time at the beginning of the analysis
> // -----------------------------------------------------------------------------
> bool user::Initialize(const MA5::Configuration& cfg, const std::map<std::string,std::string>& parameters)
> {
> cout << "BEGIN Initialization" << endl;
>
> // Initializing the histogram
> myHisto = new TH1F("myHisto","cos#theta^{*}",15,-1,1);
>
> cout << "END Initialization" << endl;
> return true;
> }
>
> // -----------------------------------------------------------------------------
> // Finalize
> // function called one time at the end of the analysis
> // -----------------------------------------------------------------------------
> void user::Finalize(const SampleFormat& summary, const std::vector<SampleFormat>& files)
> {
> cout << "BEGIN Finalization" << endl;
>
> // saving histos
>
> // Color of the canvas background
> gStyle->SetCanvasColor(0);
> // Turning off the border lines of the canvas
> gStyle->SetCanvasBorderMode(0);
> // Configuring statistics printing
> gStyle->SetOptStat(111110);
> // Creating the output root file
> TCanvas* myCanvas = new TCanvas("myCanvas","");
> // Setting background color
> myHisto->SetFillColor(kBlue);
> // Normalization of the histogram: L = 10 fb-1
> double nrm = summary.mc()->xsection() * 10000. /
> static_cast<float>(summary.nevents());
> myHisto->Scale(nrm);
> // Setting axis title
> myHisto->GetXaxis()->SetTitle("cos#theta^{*}");
> // Drawing histogram
> myHisto->Draw();
> // Saving plot
> myCanvas->SaveAs((outputName_+".eps").c_str());
>
> cout << "END Finalization" << endl;
> }
>
> // -----------------------------------------------------------------------------
> // Execute
> // function called each time one event is read
> // -----------------------------------------------------------------------------
> bool user::Execute(SampleFormat& sample, const EventFormat& event)
> {
>
> // Initialization of three pointers to the lepton,
>
> // W and top quark
> const MCParticleFormat* top = 0;
> const MCParticleFormat* w = 0;
> const MCParticleFormat* lepton = 0;
>
>
> // Identification of the three particles of interest
> for (unsigned int i=0;i<event.mc()->particles().size();i++)
> {
> const MCParticleFormat* prt=&(event.mc()->particles()[i]);
> // The lepton is a final state particle
> if (!PHYSICS->IsFinalState(prt)) continue;
> // Lepton selection based on the PDG-id
> if ( std::abs(prt->pdgid())!=11 &&
> std::abs(prt->pdgid())!=13 ) continue;
> // Getting the mother of the lepton and checking if it is a W-boson
> const MCParticleFormat* mother = prt->mother1();
> if (mother==0) continue;
> if (std::abs(mother->pdgid())!=24) continue;
> // Getting the grand-mother of the lepton and checking if it is a top quark
> const MCParticleFormat* grandmother = mother->mother1();
> if (grandmother==0) continue;
> if (std::abs(grandmother->pdgid())!=6) continue;
> // Saving the selected particles
> lepton = prt;
> w = mother;
> top = grandmother;
> // Particles are found: breaking the loop
> break;
> }
> // Rejection of the event if the decay chain is not found
> if (lepton==0)
> {
> WARNING << "(t > b W > b l nu) decay chain not found!"
> << std::endl;
> return;
> }
>
> // Computing the observable; filling the histogram
> // Boosting the lepton four-momentum to the W rest frame
> MCParticleFormat lepton_new = *lepton;
> PHYSICS->ToRestFrame(lepton_new,w);
> // Boosting the W four-momentum to the top rest frame
> MCParticleFormat w_new = *w;
> PHYSICS->ToRestFrame(w_new,top);
> // Computing the observable; filling the histogram
> myHisto -> Fill( cos(lepton_new.angle(w_new)) );
>
> }
>
>
>
> --
> You received this question notification because you are an answer
> contact for MadAnalysis 5.

Can you help with this problem?

Provide an answer of your own, or ask hprager for more information if necessary.

To post a message you must log in.