Error in Macro-based analysis

hi,
im trying to execute the following macro

/*
Simple macro showing how to access branches from the delphes output root file,
loop over events, and plot simple quantities such as the jet pt and the di-electron invariant
mass.

root -l examples/testExample1.C'("trainoutputsignal.root")'
*/

#ifdef __CLING__
R__LOAD_LIBRARY(libDelphes)
#include "classes/DelphesClasses.h"
#include "external/ExRootAnalysis/ExRootTreeReader.h"
#endif

//------------------------------------------------------------------------------

void testExample1(const char *inputfile)
{
  gSystem->Load("libDelphes");

  // Create chain of root trees
  TChain chain("Delphes");
  chain.Add("trainoutputsignal.root");

  // Create object of class ExRootTreeReader
  ExRootTreeReader *treeReader = new ExRootTreeReader(&chain);
  Long64_t numberOfEntries = treeReader->GetEntries();

  // Get pointers to branches used in this analysis
  TClonesArray *branchFatJet = treeReader->UseBranch("FatJet");
  TClonesArray *branchElectron = treeReader->UseBranch("Electron");
  TClonesArray *branchEvent = treeReader->UseBranch("Event");


  // Book histograms
  TH1 *histFatJetPT = new TH1F("fatjet_pt", "fatjet P_{T}", 100, 0.0, 800.0);
  TH1 *histMass = new TH1F("mass", "M_{inv}(e_{1}, e_{2})", 100, 40.0, 140.0);


  // Loop over all events
  for(Int_t entry = 0; entry < numberOfEntries; ++entry)
  {
    // Load selected branches with data from specified event
    treeReader->ReadEntry(entry);

    
    //HepMCEvent *event = (HepMCEvent*) branchEvent -> At(0);
    //LHEFEvent *event = (LHEFEvent*) branchEvent -> At(0);
    //Float_t weight = event->Weight;

    // If event contains at least 1 fatjet
    if(branchFatJet->GetEntries() > 0)
    {
      // Take first fatjet
      fatJet *fatjet = (fatJet*) branchFatJet->At(0);

      // Plot Fatjet transverse momentum
      histFatJetPT->Fill(Fatjet->PT);

      // Print fatjet transverse momentum
      cout << "FatJet pt: "<<Fatjet->PT << endl;
    }

    Electron *elec1, *elec2;

    // If event contains at least 2 electrons
    if(branchElectron->GetEntries() > 1)
    {
      // Take first two electrons
      elec1 = (Electron *) branchElectron->At(0);
      elec2 = (Electron *) branchElectron->At(1);

      // Plot their invariant mass
      histMass->Fill(((elec1->P4()) + (elec2->P4())).M());
    }
  }


  // Show resulting histograms
  histFatJetPT->Draw();
  histMass->Draw();
}

but when i run it. i get the error

how to fix this problem.?
thanx

Hi,
this error is not related to ROOT (nor Delphes), it’s a classic C++ coding mistake: as the interpreter says, fatJet is used without ever having been declared. Maybe you meant to use branchFatJet there? (I can’t really say: ExRootTreeReader is not a ROOT class, it’s from Delphes.

Cheers,
Enrico

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