LOGO

RestFrames  v1.0.1
RestFrames HEP Event Analysis Software Library
example_Zll.C
Go to the documentation of this file.
1 // RestFrames: particle physics event analysis library
3 // --------------------------------------------------------------------
4 // Copyright (c) 2014-2019, Christopher Rogan
13 //
14 // This file is part of RestFrames.
15 //
16 // RestFrames is free software; you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation; either version 2 of the License, or
19 // (at your option) any later version.
20 //
21 // RestFrames is distributed in the hope that it will be useful,
22 // but WITHOUT ANY WARRANTY; without even the implied warranty of
23 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 // GNU General Public License for more details.
25 //
26 // You should have received a copy of the GNU General Public License
27 // along with RestFrames. If not, see <http://www.gnu.org/licenses/>.
29 
30 #if (!defined(__CINT__) && !defined(__CLING__))
31 #define COMPILER
32 #endif
33 #if defined(__MAKECINT__) || defined(__ROOTCLING__) || defined(COMPILER)
34 #include "RestFrames/RestFrames.hh"
35 #else
36 RestFrames::RFKey ensure_autoload(1);
37 #endif
38 
39 using namespace RestFrames;
40 
41 void example_Zll(const std::string& output_name = "output_Zll.root"){
42 
43  double mZ = 91.188; // GeV, PDG 2016
44  double wZ = 2.495;
45 
46  // Number of events to generate
47  int Ngen = 100000;
48 
50  g_Log << LogInfo << "Initializing generator frames and tree..." << LogEnd;
52  LabGenFrame LAB_Gen("LAB_Gen","LAB");
53  ResonanceGenFrame Z_Gen("Z_Gen","Z");
54  VisibleGenFrame Lp_Gen("Lp_Gen","#it{l}^{+}");
55  VisibleGenFrame Lm_Gen("Lm_Gen","#it{l}^{-}");
56 
57  //-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//
58 
59  LAB_Gen.SetChildFrame(Z_Gen);
60  Z_Gen.AddChildFrame(Lp_Gen);
61  Z_Gen.AddChildFrame(Lm_Gen);
62 
63  if(LAB_Gen.InitializeTree())
64  g_Log << LogInfo << "...Successfully initialized generator tree" << LogEnd;
65  else
66  g_Log << LogError << "...Failed initializing generator tree" << LogEnd;
67 
68  //-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//
69 
70  // Set Z pole mass and width
71  Z_Gen.SetMass(mZ); Z_Gen.SetWidth(wZ);
72 
73  // set lepton pT and eta cuts
74  Lp_Gen.SetPtCut(15.); Lp_Gen.SetEtaCut(2.5);
75  Lm_Gen.SetPtCut(15.); Lm_Gen.SetEtaCut(2.5);
76 
77  if(LAB_Gen.InitializeAnalysis())
78  g_Log << LogInfo << "...Successfully initialized generator analysis" << std::endl << LogEnd;
79  else
80  g_Log << LogError << "...Failed initializing generator analysis" << LogEnd;
83 
85  g_Log << LogInfo << "Initializing reconstruction frames and trees..." << LogEnd;
87  LabRecoFrame LAB("LAB","LAB");
88  DecayRecoFrame Z("Z","Z");
89  VisibleRecoFrame Lp("Lp","#it{l}^{+}");
90  VisibleRecoFrame Lm("Lm","#it{l}^{-}");
91 
92  //-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//
93 
94  LAB.SetChildFrame(Z);
95  Z.AddChildFrame(Lp);
96  Z.AddChildFrame(Lm);
97 
98  if(LAB.InitializeTree())
99  g_Log << LogInfo << "...Successfully initialized reconstruction trees" << LogEnd;
100  else
101  g_Log << LogError << "...Failed initializing reconstruction trees" << LogEnd;
102 
103  if(LAB.InitializeAnalysis())
104  g_Log << LogInfo << "...Successfully initialized analyses" << LogEnd;
105  else
106  g_Log << LogError << "...Failed initializing analyses" << LogEnd;
107 
110 
111  TreePlot* tree_plot = new TreePlot("TreePlot","TreePlot");
112 
113  // generator tree
114  tree_plot->SetTree(LAB_Gen);
115  tree_plot->Draw("GenTree", "Generator Tree", true);
116 
117  // reco tree
118  tree_plot->SetTree(LAB);
119  tree_plot->Draw("RecoTree", "Reconstruction Tree");
120 
121  //-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//-//
122 
123  // Declare observables for histogram booking
124  HistPlot* hist_plot = new HistPlot("HistPlot","Z #rightarrow #it{l}^{+} #it{l}^{-}");
125 
126  const HistPlotVar& MZ = hist_plot->GetNewVar("MZ", "M_{Z}", 70., 110., "[GeV]");
127  const HistPlotVar& cosZ = hist_plot->GetNewVar("cosZ","cos #theta_{Z}", -1., 1.);
128  const HistPlotVar& dphiZ = hist_plot->GetNewVar("dphiZ", "#Delta #phi_{Z}", 0., 2.*acos(-1.));
129 
130  hist_plot->AddPlot(MZ);
131  hist_plot->AddPlot(cosZ);
132  hist_plot->AddPlot(dphiZ);
133  hist_plot->AddPlot(cosZ, MZ);
134 
135  for(int igen = 0; igen < Ngen; igen++){
136  if(igen%((std::max(Ngen,10))/10) == 0)
137  g_Log << LogInfo << "Generating event " << igen << " of " << Ngen << LogEnd;
138 
139  // generate event
140  LAB_Gen.ClearEvent(); // clear the gen tree
141 
142  double PTZ = mZ*gRandom->Rndm();
143  LAB_Gen.SetTransverseMomentum(PTZ); // give the Z some Pt
144  double PzZ = mZ*(2.*gRandom->Rndm()-1.);
145  LAB_Gen.SetLongitudinalMomentum(PzZ); // give the Z some Pz
146 
147  LAB_Gen.AnalyzeEvent(); // generate a new event
148 
149  // analyze event
150  LAB.ClearEvent(); // clear the reco tree
151 
152  Lp.SetLabFrameFourVector(Lp_Gen.GetFourVector(), 1); // Set lepton 4-vec and charge
153  Lm.SetLabFrameFourVector(Lm_Gen.GetFourVector(),-1); // Set lepton 4-vec and charge
154 
155  LAB.AnalyzeEvent(); // analyze the event
156 
157  // calculate observables
158  MZ = Z.GetMass();
159  cosZ = Z.GetCosDecayAngle();
160  dphiZ = LAB.GetDeltaPhiDecayPlanes(Z);
161 
162  hist_plot->Fill();
163  }
164 
165  hist_plot->Draw();
166 
167  TFile fout(output_name.c_str(),"RECREATE");
168  fout.Close();
169  hist_plot->WriteOutput(output_name);
170  hist_plot->WriteHist(output_name);
171  tree_plot->WriteOutput(output_name);
172 
173 }
174 
175 # ifndef __CINT__ // main function for stand-alone compilation
176 int main(){
177  example_Zll();
178  return 0;
179 }
180 #endif
RestFrames::TreePlot::Draw
void Draw(const std::string &name="", const std::string &title="", bool invert_colors=false, bool invert_node_colors=false)
Draws tree.
Definition: TreePlot.cc:127
RestFrames::HistPlot::WriteHist
void WriteHist(const std::string &filename)
Stores all histograms in root file.
Definition: HistPlot.cc:581
RestFrames::HistPlot
Definition: HistPlot.hh:44
RestFrames::RFPlot::WriteOutput
void WriteOutput(const std::string &filename)
Stores all plots in root file.
Definition: RFPlot.cc:59
RestFrames.hh
RestFrames::VisibleRecoFrame
Definition: VisibleRecoFrame.hh:41
RestFrames::ResonanceGenFrame
Definition: ResonanceGenFrame.hh:40
RestFrames::LabRecoFrame
Definition: LabRecoFrame.hh:44
RestFrames::HistPlot::GetNewVar
HistPlotVar const & GetNewVar(const std::string &name, const std::string &title, double minval, double maxval, const std::string &unit="")
Defines new variable for plotting.
Definition: HistPlot.cc:86
RestFrames::VisibleGenFrame
Definition: VisibleGenFrame.hh:41
RestFrames::HistPlot::Fill
void Fill(double weight=1.)
Fills an entry for every variable according to each's current value.
Definition: HistPlot.cc:242
RestFrames::TreePlot::SetTree
void SetTree(const RestFrame &frame)
Sets a tree that shows how a frame is connected to its children.
Definition: TreePlot.cc:160
RestFrames::TreePlot
Definition: TreePlot.hh:50
RestFrames::LabGenFrame
Definition: LabGenFrame.hh:41
RestFrames::RFKey
Definition: RFKey.hh:38
RestFrames::HistPlotVar
Definition: HistPlotVar.hh:40
RestFrames::HistPlot::AddPlot
void AddPlot(const HistPlotVar &var, RestFrames::RFList< const HistPlotCategory > cats=RestFrames::RFList< const RestFrames::HistPlotCategory >(), bool invert_colors=false)
Defines new 1D plot.
Definition: HistPlot.cc:102
RestFrames::DecayRecoFrame
Definition: DecayRecoFrame.hh:43
RestFrames::HistPlot::Draw
void Draw(bool invert_colors=false)
Draws every histogram.
Definition: HistPlot.cc:272