# How to Initialize Muon Vectors

**URL:** <https://root-forum.cern.ch/t/how-to-initialize-muon-vectors/37899>\
**Category:** Newbie\
**Tags:** rdataframe\
**Created:** [February 9, 2020, 4:52am UTC](https://root-forum.cern.ch/t/how-to-initialize-muon-vectors/37899 "2020-02-09T04:52:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![usernew](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/u/ccd318/32.png) [@usernew](https://root-forum.cern.ch/u/usernew)\
**Post date:** [February 9, 2020, 4:52am UTC](https://root-forum.cern.ch/t/how-to-initialize-muon-vectors/37899/1 "2020-02-09T04:52:53Z")

</div>

I am trying to reconstruct two Z bosons.  
I am using this tutorial as an example. [ROOT: tutorials/dataframe/df103\_NanoAODHiggsAnalysis.C File Reference](https://root.cern.ch/doc/master/df103__NanoAODHiggsAnalysis_8C.html)  
However, I am still not familiar in using ROOT data frame and I am writing it in terms of what I am familiar with.

What I do not understand is how can I define i1, i2, and idx that is shown in the ROOT tutorial?

In my tree, I have the BranchMuon and the variables in this branch are called Muon.PT, Muon.Eta, Muon.Phi and Muon.Charge, and Muon.Mass.

My attempt to follow the tutorial is constructing a muon vector and defining the variables (which generates errors but I am still learning how to work with it):

> #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
> 
> template
> 
> 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 selectMuon(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 \*histZMass = new TH1F(“mass”, “M\_{inv}(Z[1]); M\_inv (GeV/c^2); Events”, 50, 0.0, 1500);
> 
> TH1F \*histDiMuonMass = new TH1F(“mass”, “M\_{inv}(Z[3]Z[5]); M\_inv (GeV/c^2); Events”, 50, 0.0, 1500);
> 
> // Define variables
> 
> float\_t PT, Eta, Phi, Mass, Charge;
> 
> // Initializing the vectors
> 
> //vector\<const Muon\*\> _muons = new vector\<const Muon_\>();;
> 
> MuonVector muon(PT, Eta, Phi, Mass, Charge);
> 
> // Loop over all events
> 
> for(Int\_t entry = 0; entry \< numberOfEntries; ++entry)
> 
> {
> 
> ```
> // Load selected branches with data from specified event
> 
> treeReader->ReadEntry(entry);
> 
>          
> 
> // Select leptons with pT > 10 GeV and |eta| < 2.5
> 
> CollectionFilter(*branchMuon, *muons, 10.0, 2.5);
> 
> muon1 = (*muon)[0];
> 
> muon2 = (*muon)[1];
> 
> if(muon1->Charge != muon2->Charge)
> 
> {
> 
> ROOT::Math::PtEtaPhiMVector m1(PT[0], Eta[0], Phi[0], Mass[0]);
> 
> ROOT::Math:PtEtaPhiMVector m2(PT[1], Eta[1], Phi[1], Mass[1]);
> 
> const mass = (m1 + m2).M();
> 
> }
> 
>   
> 
> TLorentzVector dimuon = (muon1 + muon2);
> 
> histDiMuonMass->Fill(mass);   
> 
> ```
> 
> }
> 
> // - - - - - - - - - - - - - - Drawing the Histograms - - - - - - - - - - - - - - - - - - - - - -
> 
> } // end of event for loop
> 
> histDiMuonMass-\>Draw();
> 
> }

How can I define the two muon vectors? How can I write idx, i1 and i2?

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [February 10, 2020, 8:05am UTC](https://root-forum.cern.ch/t/how-to-initialize-muon-vectors/37899/2 "2020-02-10T08:05:17Z")

</div>

> [@usernew](#):
>
> I used Madgraph to create a simulation of some events.

Additional variables should be added at that step I guess: is creation time.

---

<div class="post-metadata">

**Author:** ![usernew](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/u/ccd318/32.png) [@usernew](https://root-forum.cern.ch/u/usernew)\
**Post date:** [February 11, 2020, 8:29am UTC](https://root-forum.cern.ch/t/how-to-initialize-muon-vectors/37899/3 "2020-02-11T08:29:32Z")

</div>

I dont think there is any documentation on that suggestion. Are you familiar with the process?

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [February 11, 2020, 8:42am UTC](https://root-forum.cern.ch/t/how-to-initialize-muon-vectors/37899/4 "2020-02-11T08:42:02Z")

</div>

> [@usernew](#):
>
> Are you familiar with the process?

Not really as you are using an external tool (Madgraph) to generate your TTree. May be you should contact the Madgraph support or the author of the program you are using.

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [February 25, 2020, 8:49am UTC](https://root-forum.cern.ch/t/how-to-initialize-muon-vectors/37899/5 "2020-02-25T08:49:40Z")

</div>

Closed on February 25, 2020, 8:49am UTC

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