I am trying to calculate the dimuon invariant mass. I wanted to follow one of the ROOT tutorials that started something like this:
// Create dataframe from NanoAOD files
ROOT::RDataFrame df(“Delphes;5”,
"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, {“Muon.PT”, “Muon.Eta”, “Muon.Phi”, “mu_mass”});
// 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();
// Produce plot
However, the problem was that I did not have a Branch that contained the muon mass to be used in this line:
auto df_mass = df_os.Define(“Dimuon_mass”, InvariantMass, {“Muon.PT”, “Muon.Eta”, “Muon.Phi”, “mu_mass”})
So, I had to add the branch to my existing tree by writing:
void upd()
{
TFile *f = new TFile("tag_1_delphes_events.root","update"); TTree *T = (TTree*)f->Get("Delphes"); //float px,py; //float pt; float mu_mass; TBranch *MuonMass = T->Branch("mu_mass",&mu_mass,"mu_mass/F"); //T->SetBranchAddress("px",&px); //T->SetBranchAddress("py",&py); Long64_t nentries = T->GetEntries(); for (Long64_t i=0;i<nentries;i++) { T->GetEntry(i); mu_mass = 0.1; MuonMass->Fill(); } T->Print(); T->Write(); delete f; }
which ended up working fine. But, when running the full code, I ran into this error:
Processing invariantmass.C…
Warning in TClass::Init: no dictionary for class HepMCEvent is available
Warning in TClass::Init: no dictionary for class Event is available
Warning in TClass::Init: no dictionary for class Weight is available
Warning in TClass::Init: no dictionary for class GenParticle is available
Warning in TClass::Init: no dictionary for class SortableObject is available
Warning in TClass::Init: no dictionary for class Track is available
Warning in TClass::Init: no dictionary for class Tower is available
Warning in TClass::Init: no dictionary for class Jet is available
Warning in TClass::Init: no dictionary for class MissingET is available
Warning in TClass::Init: no dictionary for class Electron is available
Warning in TClass::Init: no dictionary for class Photon is available
Warning in TClass::Init: no dictionary for class Muon is available
Warning in TClass::Init: no dictionary for class ScalarHT is available
terminate called after throwing an instance of ‘std::runtime_error’
what(): Cannot call operator + on vectors of different sizes.
Did I have to add the branch in another way to fix the error. Did it have to be added as a vector. How should I fix this error?
Many thank!
Please read tips for efficient and successful posting and posting code
ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided