Viewing/Creating Branches in Tree

Asked by User New on 2020-02-11

I used Madgraph to create a simulation of some events.

I then went on ROOT to view the tree and the branches of that event and run.
(In the prompt I typed TBrowser b)

When I look at the Tree and the branches
I only see the Muon Branch with the Muon.PT, Muon.Eta, Muon.Phi, etc. leaves.

Looking at different tutorials on plotting the histogram of the invariant mass of the Z boson, I see that the trees and branches have two different muons. For example, there are branches such as LooseMuonsEta1,
LooseMuonsPhi1, LooseMuonsPt1, LooseMuonsEta2, LooseMuonsPhi2,
LooseMuonsPt2

in which they can use SetPtEtaPhiM to create a TLorentzVector out of it and in turn find the invariant mass of the Z boson.

How can I create these (two) different branches to plot the invariant mass of the Z boson?

This is what I have attempted after reading some tutorials, but I ended up with an empty histogram.

> #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
>
> template<typename T>
>
> void CollectionFilter(const TClonesArray& inColl ,vector<T*>& outColl, Double_t ptMin=30, Double_t etaMax=2.5)
>
> {
>
> const TObject *object;
>
> for (Int_t i = 0; i < inColl.GetEntriesFast(); i++)
>
> {
>
> object = inColl.At(i);
>
> const T *t = static_cast<const T*>(object);
>
> if(t->P4().Pt() < ptMin) continue;
>
> if(TMath::Abs(t->P4().Eta()) > etaMax) continue;
>
> outColl.push_back(t);
>
> }
>
> }
>
> //-------------------------------------Looking at Leptons -----------------------------------------
>
> void numberOfMuons(const char *inputFile)
>
> {
>
> gSystem->Load("libDelphes");
>
> // Create chain of root trees
>
> TChain chain("Delphes");
>
> chain.Add(inputFile);
>
> // Create object of class ExRootTreeReader
>
> ExRootTreeReader *treeReader = new ExRootTreeReader(&chain);
>
> Long64_t numberOfEntries = treeReader->GetEntries();
>
> // Get pointers to branches used in this analysis

> TClonesArray *branchMuon = treeReader->UseBranch("Muon");
>
>
>
> // Book histograms
>
>
> TH1F *Zmass = new TH1F("mass", "M_{inv}(Z[1]); M_inv (GeV/c^2); Events", 50, 0.0, 150);
>
> TH1F *ZmassBkg = new TH1F("mass", "M_{inv}(Z[1]); M_inv (GeV/c^2); Events", 50, 0.0, 150);
>
> //Create NTuple
>
>
>
> TTree* tree =&chain;
>
> TTree* ntuple = new TTree("NTuple", "Finding Number of Particles");
>
> Int_t numberOfMuons;
>
> Int_t numberOfParticles;
>
> // Create local variables for the tree's branches
>
> Float_t MuonPT1;
>
> Float_t MuonEta1;
>
> Float_t MuonPhi1;
>
> Float_t MuonM;
>
> Float_t MuonPT2;
>
> Float_t MuonEta2;
>
> Float_t MuonPhi2;
>
>
>
> //Set the tree's branches to the local variables
>
>
>
> tree->SetBranchAddress("MuonPT1", &MuonPT1);
>
> tree->SetBranchAddress("MuonEta1", &MuonEta1);
>
> tree->SetBranchAddress("MuonPhi1", &MuonPhi1);
>
> tree->SetBranchAddress("MuonPT2", &MuonPT2);
>
> tree->SetBranchAddress("MuonEta2", &MuonEta2);
>
> tree->SetBranchAddress("MuonPhi2", &MuonPhi2);
>
>
>
> // Assign each variable to its own branch
>
> ntuple->Branch("numberOfMuons", &numberOfMuons, "numberOfMuons/I");
>
> // Loop over all events
>
> for(Int_t entry = 0; entry < numberOfEntries; ++entry)
>
> {
>
> // Load selected branches with data from specified event
>
> treeReader->ReadEntry(entry);
>
>
>

>
>
> //Muons
>
> for( Int_t i = 0; i < branchMuon->GetEntries(); ++i)
>
> {
>
>
>
> cout << "There are " << numberOfMuons << " muons in run" << endl;
>
> }
>
>
>
> if(abs(MuonPT1) < 20) continue;
>
> if(abs(MuonEta1) > 2.5) continue;
>
> if(abs(MuonPT2) < 20) continue;
>
> if(abs(MuonEta2) > 2.5) continue;
>
> TLorentzVector Muon1;
>
> Muon1.SetPtEtaPhiM(fabs(MuonPT1), MuonEta1, MuonPhi1, 0.1);
>
> TLorentzVector Muon2;
>
> Muon2.SetPtEtaPhiM(fabs(MuonPT2), MuonEta2, MuonPhi2, 0.1);
>
>
>
> TLorentzVector Z = Muon1 + Muon2;
>
>
>
> Zmass->Fill(Z.M());
>
>
>
> }
>
> Zmass->Draw();
>
> }
>
> ___

I would appreciate any guidance. Many thanks!

Question information

Language:
English Edit question
Status:
Answered
For:
MadGraph5_aMC@NLO Edit question
Assignee:
No assignee Edit question
Last query:
2020-02-12
Last reply:
2020-02-12

Hi,

I'm not a ROOT expert (not event user, I'm a theorist).
I guess that the difference in your root file is just that the tutorial is after Delphes while your ROOT file is done after the parton level.

Cheers,

Olivier

> On 11 Feb 2020, at 09:59, User New <email address hidden> wrote:
>
> New question #688664 on MadGraph5_aMC@NLO:
> https://answers.launchpad.net/mg5amcnlo/+question/688664
>
> I used Madgraph to create a simulation of some events.
>
> I then went on ROOT to view the tree and the branches of that event and run.
> (In the prompt I typed TBrowser b)
>
> When I look at the Tree and the branches
> I only see the Muon Branch with the Muon.PT, Muon.Eta, Muon.Phi, etc. leaves.
>
> Looking at different tutorials on plotting the histogram of the invariant mass of the Z boson, I see that the trees and branches have two different muons. For example, there are branches such as LooseMuonsEta1,
> LooseMuonsPhi1, LooseMuonsPt1, LooseMuonsEta2, LooseMuonsPhi2,
> LooseMuonsPt2
>
> in which they can use SetPtEtaPhiM to create a TLorentzVector out of it and in turn find the invariant mass of the Z boson.
>
> How can I create these (two) different branches to plot the invariant mass of the Z boson?
>
> This is what I have attempted after reading some tutorials, but I ended up with an empty histogram.
>
>> #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
>>
>> template<typename T>
>>
>> void CollectionFilter(const TClonesArray& inColl ,vector<T*>& outColl, Double_t ptMin=30, Double_t etaMax=2.5)
>>
>> {
>>
>> const TObject *object;
>>
>> for (Int_t i = 0; i < inColl.GetEntriesFast(); i++)
>>
>> {
>>
>> object = inColl.At(i);
>>
>> const T *t = static_cast<const T*>(object);
>>
>> if(t->P4().Pt() < ptMin) continue;
>>
>> if(TMath::Abs(t->P4().Eta()) > etaMax) continue;
>>
>> outColl.push_back(t);
>>
>> }
>>
>> }
>>
>> //-------------------------------------Looking at Leptons -----------------------------------------
>>
>> void numberOfMuons(const char *inputFile)
>>
>> {
>>
>> gSystem->Load("libDelphes");
>>
>> // Create chain of root trees
>>
>> TChain chain("Delphes");
>>
>> chain.Add(inputFile);
>>
>> // Create object of class ExRootTreeReader
>>
>> ExRootTreeReader *treeReader = new ExRootTreeReader(&chain);
>>
>> Long64_t numberOfEntries = treeReader->GetEntries();
>>
>> // Get pointers to branches used in this analysis
>
>> TClonesArray *branchMuon = treeReader->UseBranch("Muon");
>>
>>
>>
>> // Book histograms
>>
>>
>> TH1F *Zmass = new TH1F("mass", "M_{inv}(Z[1]); M_inv (GeV/c^2); Events", 50, 0.0, 150);
>>
>> TH1F *ZmassBkg = new TH1F("mass", "M_{inv}(Z[1]); M_inv (GeV/c^2); Events", 50, 0.0, 150);
>>
>> //Create NTuple
>>
>>
>>
>> TTree* tree =&chain;
>>
>> TTree* ntuple = new TTree("NTuple", "Finding Number of Particles");
>>
>> Int_t numberOfMuons;
>>
>> Int_t numberOfParticles;
>>
>> // Create local variables for the tree's branches
>>
>> Float_t MuonPT1;
>>
>> Float_t MuonEta1;
>>
>> Float_t MuonPhi1;
>>
>> Float_t MuonM;
>>
>> Float_t MuonPT2;
>>
>> Float_t MuonEta2;
>>
>> Float_t MuonPhi2;
>>
>>
>>
>> //Set the tree's branches to the local variables
>>
>>
>>
>> tree->SetBranchAddress("MuonPT1", &MuonPT1);
>>
>> tree->SetBranchAddress("MuonEta1", &MuonEta1);
>>
>> tree->SetBranchAddress("MuonPhi1", &MuonPhi1);
>>
>> tree->SetBranchAddress("MuonPT2", &MuonPT2);
>>
>> tree->SetBranchAddress("MuonEta2", &MuonEta2);
>>
>> tree->SetBranchAddress("MuonPhi2", &MuonPhi2);
>>
>>
>>
>> // Assign each variable to its own branch
>>
>> ntuple->Branch("numberOfMuons", &numberOfMuons, "numberOfMuons/I");
>>
>> // Loop over all events
>>
>> for(Int_t entry = 0; entry < numberOfEntries; ++entry)
>>
>> {
>>
>> // Load selected branches with data from specified event
>>
>> treeReader->ReadEntry(entry);
>>
>>
>>
>
>>
>>
>> //Muons
>>
>> for( Int_t i = 0; i < branchMuon->GetEntries(); ++i)
>>
>> {
>>
>>
>>
>> cout << "There are " << numberOfMuons << " muons in run" << endl;
>>
>> }
>>
>>
>>
>> if(abs(MuonPT1) < 20) continue;
>>
>> if(abs(MuonEta1) > 2.5) continue;
>>
>> if(abs(MuonPT2) < 20) continue;
>>
>> if(abs(MuonEta2) > 2.5) continue;
>>
>> TLorentzVector Muon1;
>>
>> Muon1.SetPtEtaPhiM(fabs(MuonPT1), MuonEta1, MuonPhi1, 0.1);
>>
>> TLorentzVector Muon2;
>>
>> Muon2.SetPtEtaPhiM(fabs(MuonPT2), MuonEta2, MuonPhi2, 0.1);
>>
>>
>>
>> TLorentzVector Z = Muon1 + Muon2;
>>
>>
>>
>> Zmass->Fill(Z.M());
>>
>>
>>
>> }
>>
>> Zmass->Draw();
>>
>> }
>>
>> ___
>
>
>
> I would appreciate any guidance. Many thanks!
>
>
>
> --
> You received this question notification because you are an answer
> contact for MadGraph5_aMC@NLO.

User New (usersnamemg) said : #2

What exactly does the muon branch tells us. Does it give us information about all the muons in each event or after a certain number of events?

I do not know.
Are you using ExRootAnalysis or another tool to convert your lhe file to your root file?
In any case I would suggest to read the documentation of that code.

Cheers,

Olivier

> On 12 Feb 2020, at 03:52, User New <email address hidden> wrote:
>
> Question #688664 on MadGraph5_aMC@NLO changed:
> https://answers.launchpad.net/mg5amcnlo/+question/688664
>
> Status: Answered => Open
>
> User New is still having a problem:
> What exactly does the muon branch tells us. Does it give us information
> about all the muons in each event or after a certain number of events?
>
> --
> You received this question notification because you are an answer
> contact for MadGraph5_aMC@NLO.

Can you help with this problem?

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

To post a message you must log in.