Fork me on GitHub

WorkBook/TutorialBologna: HZZ.C

File HZZ.C, 6.3 KB (added by Michele Selvaggi, 8 years ago)
Line 
1/*
2Prints complete input particle arborescence for the first 100 events. Useful for debugging purposes.
3root -l examples/Example5.C'("delphes_output.root")'
4*/
5
6#ifdef __CLING__
7R__LOAD_LIBRARY(libDelphes)
8#include "classes/DelphesClasses.h"
9#include "external/ExRootAnalysis/ExRootTreeReader.h"
10#include "external/ExRootAnalysis/ExRootResult.h"
11#else
12class ExRootTreeReader;
13class ExRootResult;
14#endif
15
16
17template<typename T>
18void CollectionFilter(const TClonesArray& inColl ,vector<T*>& outColl, Double_t ptMin=30, Double_t etaMax=2.5)
19{
20
21 const TObject *object;
22
23 for (Int_t i = 0; i < inColl.GetEntriesFast(); i++)
24 {
25
26 object = inColl.At(i);
27 const T *t = static_cast<const T*>(object);
28
29 if(t->P4().Pt() < ptMin) continue;
30 if(TMath::Abs(t->P4().Eta()) > etaMax) continue;
31
32 outColl.push_back(t);
33
34 }
35}
36
37
38//------------------------------------------------------------------------------
39
40void HZZ(const char *inputFile)
41{
42 gSystem->Load("libDelphes");
43
44 // Create chain of root trees
45 TChain chain("Delphes");
46 chain.Add(inputFile);
47
48 // Create object of class ExRootTreeReader
49 ExRootTreeReader *treeReader = new ExRootTreeReader(&chain);
50 Long64_t numberOfEntries = treeReader->GetEntries();
51
52 // Get pointers to branches used in this analysis
53 TClonesArray *branchParticle = treeReader->UseBranch("Particle");
54 TClonesArray *branchElectron = treeReader->UseBranch("Electron");
55 TClonesArray *branchMuon = treeReader->UseBranch("Muon");
56
57 // Book histograms
58 TH1F *histMinMass = new TH1F("mass_min", "", 50, 00.0, 140.0);
59 TH1F *histMaxMass = new TH1F("mass_max", "", 50, 00.0, 140.0);
60 TH1F *histMass = new TH1F("mass", "", 50, 100, 150);
61
62 TH1F *histMinMassGen = new TH1F("mass_min_gen", "", 50, 0.0, 140.0);
63 TH1F *histMaxMassGen = new TH1F("mass_max_gen", "", 50, 00.0, 140.0);
64 TH1F *histMassGen = new TH1F("mass_gen", "", 50, 100, 150);
65
66 // Define variables
67 const Electron *elec1, *elec2;
68 const Muon *muon1, *muon2;
69
70 const GenParticle *gen_elec1, *gen_elec2;
71 const GenParticle *gen_muon1, *gen_muon2;
72
73 vector<const Electron*> *electrons = new vector<const Electron*>();;
74 vector<const Muon*> *muons = new vector<const Muon*>();;
75
76 Double_t massMin, massMax, mass, massEE, massMM;
77 Double_t gen_massMin, gen_massMax, gen_mass, gen_massEE, gen_massMM;
78
79 // Loop over all events
80 for(Int_t entry = 0; entry < numberOfEntries; ++entry)
81 {
82 // Load selected branches with data from specified event
83 treeReader->ReadEntry(entry);
84
85 electrons -> clear();
86 muons -> clear();
87
88 // Select leptons with pT > 10 GeV and |eta| < 2.5
89 CollectionFilter(*branchElectron, *electrons , 10.0 , 2.5);
90 CollectionFilter(*branchMuon , *muons , 10.0 , 2.5);
91
92 // Select event with at least 2 electrons and 2 muons
93 if(electrons->size() < 2) continue;
94 if(muons->size() < 2) continue;
95
96 // Define leading and subleading leptons
97 elec1 = electrons->at(0);
98 elec2 = electrons->at(1);
99 muon1 = muons->at(0);
100 muon2 = muons->at(1);
101
102 // Define leading and subleading leptons at gen level
103 gen_elec1 = (GenParticle*) elec1->Particle.GetObject();
104 gen_elec2 = (GenParticle*) elec2->Particle.GetObject();
105 gen_muon1 = (GenParticle*) muon1->Particle.GetObject();
106 gen_muon2 = (GenParticle*) muon2->Particle.GetObject();
107
108 // Delect events with opposite charge leptons
109 if(elec1->Charge == elec2->Charge) continue;
110 if(muon1->Charge == muon2->Charge) continue;
111
112 // Define electron pair invariant mass
113 massEE = ((elec1->P4()) + (elec2->P4())).M();
114 gen_massEE = ((gen_elec1->P4()) + (gen_elec2->P4())).M();
115
116 // Define muon pair invariant mass
117 massMM = ((muon1->P4()) + (muon2->P4())).M();
118 gen_massMM = ((gen_muon1->P4()) + (gen_muon2->P4())).M();
119
120 // Define the four leptons invariant mass
121 mass = ((elec1->P4()) + (elec2->P4()) + (muon1->P4()) + (muon2->P4())).M();
122 gen_mass = ((gen_elec1->P4()) + (gen_elec2->P4()) + (gen_muon1->P4()) + (gen_muon2->P4())).M();
123
124 // Define the minimum invariant mass between m_ee and m_mumu
125 massMin = min( massEE, massMM );
126 gen_massMin = min( gen_massEE, gen_massMM );
127
128 // Define the maximum invariant mass between m_ee and m_mumu
129 massMax = max( massEE, massMM );
130 gen_massMax = max( gen_massEE, gen_massMM );
131
132
133 // Fill the above quantities in histograms
134 histMinMass -> Fill(massMin);
135 histMaxMass -> Fill(massMax);
136 histMass -> Fill(mass);
137
138 histMinMassGen -> Fill(gen_massMin);
139 histMaxMassGen -> Fill(gen_massMax);
140 histMassGen -> Fill(gen_mass);
141
142
143 } // end of event loop
144
145 // Plot all the above observables
146
147 TCanvas *c1 = new TCanvas("c1","multipads",1200,600);
148 gStyle->SetOptStat(0);
149 c1->Divide(2,1);
150
151 c1->cd(1);
152
153 histMaxMassGen -> SetLineWidth(2);
154 histMaxMassGen -> SetLineColor(kBlue);
155 histMaxMassGen -> SetLineStyle(2);
156
157 histMaxMassGen -> GetXaxis()->SetTitle("m(l^{+}l^{-}) [GeV]");
158
159 histMaxMass -> SetLineWidth(2);
160 histMaxMass -> SetLineColor(kBlue);
161
162 histMinMassGen -> SetLineWidth(2);
163 histMinMassGen -> SetLineColor(kRed);
164 histMinMassGen -> SetLineStyle(2);
165
166 histMinMass -> SetLineWidth(2);
167 histMinMass -> SetLineColor(kRed);
168
169 histMaxMassGen -> Draw("hist");
170 histMaxMass -> Draw("hist same");
171 histMinMassGen -> Draw("hist same");
172 histMinMass -> Draw("hist same");
173
174 TLegend *leg1 = new TLegend(0.32,0.65,0.70,0.85);
175
176 leg1->AddEntry(histMaxMass, "max( m(e_{1}, e_{2}) , m(#mu_{1}, #mu_{2}) ) (reco)", "l");
177 leg1->AddEntry(histMaxMassGen, "max( m(e_{1}, e_{2}) , m(#mu_{1}, #mu_{2}) ) (gen)", "l");
178 leg1->AddEntry(histMinMass, "min( m(e_{1}, e_{2}) , m(#mu_{1}, #mu_{2}) ) (reco)", "l");
179 leg1->AddEntry(histMinMassGen, "min( m(e_{1}, e_{2}) , m(#mu_{1}, #mu_{2}) ) (gen)", "l");
180
181 leg1->SetBorderSize(0);
182 leg1->SetShadowColor(0);
183 leg1->SetFillColor(0);
184 leg1->Draw();
185
186 c1->cd(2);
187
188 histMassGen -> SetLineWidth(2);
189 histMassGen -> SetLineStyle(2);
190
191 histMassGen -> GetXaxis()->SetTitle("m(e^{+}e^{-}#mu^{+}#mu^{-}) [GeV]");
192
193 histMass -> SetLineWidth(2);
194
195 histMassGen -> Draw("hist");
196 histMass -> Draw("hist same");
197
198 TLegend *leg2 = new TLegend(0.55,0.65,0.89,0.85);
199
200 leg2->AddEntry(histMass, "m(e^{+}e^{-}#mu^{+}#mu^{-}) (reco)", "l");
201 leg2->AddEntry(histMassGen, "m(e^{+}e^{-}#mu^{+}#mu^{-}) (gen)", "l");
202
203 leg2->SetBorderSize(0);
204 leg2->SetShadowColor(0);
205 leg2->SetFillColor(0);
206 leg2->Draw();
207
208 TString fname(inputFile);
209 fname.ReplaceAll("root", "png");
210
211 c1->Print(fname,"png");
212
213}