0

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.

Yunus Temurlenk
  • 4,085
  • 4
  • 18
  • 39
usernew
  • 125
  • 1
  • 13
  • did you try running the `TTree::Print()` method on your tree? Assumung your muon variables are tree branches with arrays, then the printout should tell you which variable has the number of entries: `*Br 17 :lep_n : lep_n/i *` → `*Br 20 :lep_pt : lep_pt[lep_n]/F *` – pseyfert Feb 17 '20 at 07:47
  • From the error message, you're missing the file `classes/DelphesClasses.h`. It could be you're running the tutorial from the wrong directory? or if `DelphesClasses.h` is the result of code generation, there may be steps of the tutorial you're skipping? (e.g. only running the last `root tutorial.C` instead of `make`?) – pseyfert Feb 17 '20 at 07:48
  • I am not really running a tutorial. I am running my own script which was just "inspired" by some tutorials. I do have the classes/DelphesClasses. h in the header. But I still get errors – usernew Feb 17 '20 at 09:10
  • 1
    sorry, i don't understand what you mean by "I do have the classes/DelphesClasses.h in the header" → I see the include in the code you posted and in the error message. The problem is that cling doesn't find the file on your filesystem. That might just be something as trivial as calling `root scripts/invariantmass.C` from the top level directory works but `root invariantmass.C` from the `scripts` directory doesn't because of the relative path from your current working directory to `classes`. (I made `scripts` as directory name up.) – pseyfert Feb 17 '20 at 10:01
  • Ok, I think I now what you mean. Is there a simpler way to achieve what I want though, without using treeReader, etc. – usernew Feb 17 '20 at 10:15

0 Answers0