I am trying to find the number of muons inside my TTree called Delphes. I have a Muon Branch inside the Delphes tree that gives different variables of the muons such as transverse momentum; however, it does not tell the number of muons generated.
After looking at some tutorials, I have attempted with the following:
//#ifdef __CLING__
//R__LOAD_LIBRARY(libDelphes)
#include "classes/DelphesClasses.h"
#include "external/ExRootAnalysis/ExRootTreeReader.h"
#include "external/ExRootAnalysis/ExRootResult.h"
//#else
class ExRootTreeReader;
class ExRootResult;
//#endif
#include "ROOT/RDataFrame.hxx"
#include "ROOT/RVec.hxx"
#include "TCanvas.h"
#include "TH1D.h"
#include "TLatex.h"
#include "Math/Vector4D.h"
#include "TStyle.h"
using namespace ROOT::VecOps;
void invariantmass()
{
//gSystem->Load("libDelphes");
// Create chain of root trees
//TChain chain("Delphes;2");
//chain.Add(inputFile);
// Create object of class ExRootTreeReader
ExRootTreeReader *treeReader = new ExRootTreeReader();
Int_t numberOfMuons = branchMuon->GetEntries();
cout << "There are " << numberOfMuons << " muons in run" << endl;
TClonesArray *branchMuon = treeReader->UseBranch("Muon");
// Enable multi-threading
ROOT::EnableImplicitMT();
// Create dataframe from NanoAOD files
ROOT::RDataFrame df("Delphes;2",
"tag_1_delphes_events.root");
// For simplicity, select only events with exactly two muons and require opposite charge
//auto df_2mu = df.Filter("nMuon == 2", "Events with exactly two muons");
auto df_os = df.Filter("Muon.Charge[0] != Muon.Charge[1]", "Muons with opposite charge");
// Compute invariant mass of the dimuon system
auto df_mass = df_os.Define("Dimuon_mass", InvariantMass<float>, {"Muon.PT", "Muon.Eta", "Muon.Phi", "m"});
// Make histogram of dimuon mass spectrum
auto h = df_mass.Histo1D({"Dimuon_mass", "Dimuon_mass", 30000, 0.25, 300}, "Dimuon_mass");
// Request cut-flow report
auto report = df_mass.Report();
}
I believe I had the code running before. But now,I end up with this error:
root [0]
Processing invariantmass.C...
In file included from input_line_8:1:
/mnt/c/1/MG5_aMC_v2_6_6/trisignal/Events/run_01/invariantmass.C:3:10: fatal error: 'classes/DelphesClasses.h' file not found
#include "classes/DelphesClasses.h"
^~~~~~~~~~~~~~~~~~~~~~~~~~
/mnt/c/1/MG5_aMC_v2_6_6/trisignal/Events/run_01/invariantmass.C:27:38: error: allocation of incomplete type 'ExRootTreeReader'
ExRootTreeReader *treeReader = new ExRootTreeReader();
^~~~~~~~~~~~~~~~
/mnt/c/1/MG5_aMC_v2_6_6/trisignal/Events/run_01/invariantmass.C:7:7: note: forward declaration of 'ExRootTreeReader'
class ExRootTreeReader;
^
/mnt/c/1/MG5_aMC_v2_6_6/trisignal/Events/run_01/invariantmass.C:28:27: error: use of undeclared identifier 'branchMuon'
Int_t numberOfMuons = branchMuon->GetEntries();
^
/mnt/c/1/MG5_aMC_v2_6_6/trisignal/Events/run_01/invariantmass.C:31:46: error: member access into incomplete type 'ExRootTreeReader'
TClonesArray *branchMuon = treeReader->UseBranch("Muon");
^
/mnt/c/1/MG5_aMC_v2_6_6/trisignal/Events/run_01/invariantmass.C:7:7: note: forward declaration of 'ExRootTreeReader'
class ExRootTreeReader;
^
with a segmentation violation.
How can I fix it? Is there a simpler way to do this?
EDIT: I found out that Delphes can tell you the number of Muons by the branch Muon_size.