StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
PhaseSpacePlots.C
1 #include <string>
2 
3 using std::string;
4 
5 void PhaseSpacePlots() {
6 
7  string fileName1 = "rootFiles/B0JpsiKpi.root";
8  string fileName2 = "rootFiles/B0KpiJpsi.root";
9 
10  string decay1 = "B^{0} #rightarrow J/#psi K #pi";
11  string decay2 = "B^{0} #rightarrow K #pi J/#psi";
12 
13  string xLabel = "m^{2}(K#pi)";
14  string yLabel = "m^{2}(J/#psi #pi)";
15  int xInt1 = 1;
16  int yInt1 = 2;
17  int xInt2 = 3;
18  int yInt2 = 1;
19 
20  TLatex latex;
21  latex.SetTextSize(0.05);
22  latex.SetNDC(kTRUE);
23 
24  gROOT->SetStyle("Plain");
25  gStyle->SetOptStat(0);
26  TCanvas* theCanvas = new TCanvas("theCanvas", "", 1500, 600);
27  theCanvas->UseCurrentStyle();
28 
29  theCanvas->Divide(2,1);
30 
31  theCanvas->cd(1);
32  TH2D* plot1 = getDalitzPlot(fileName1, xInt1, yInt1, xLabel, yLabel);
33  plot1->Draw("colz");
34  latex.DrawLatex(0.3, 0.95, decay1.c_str());
35 
36  theCanvas->cd(2);
37  TH2D* plot2 = getDalitzPlot(fileName2, xInt2, yInt2, xLabel, yLabel);
38  plot2->Draw("colz");
39  latex.DrawLatex(0.3, 0.95, decay2.c_str());
40 
41  theCanvas->Print("PhaseSpacePlots.png");
42 
43 }
44 
45 TH2D* getDalitzPlot(string fileName, int xInt = 1, int yInt = 2,
46  string xLabel = "m^{2}_{23}",
47  string yLabel = "m^{2}_{13}") {
48 
49  TFile* theFile = new TFile(fileName.c_str(), "read");
50  if (!theFile) {return 0;}
51 
52  TTree* theTree = dynamic_cast<TTree*>(theFile->Get("dalitzTree"));
53  if (!theTree) {return 0;}
54 
55  double m12Sq(0.0), m23Sq(0.0), m13Sq(0.0);
56  theTree->SetBranchAddress("invMass12Sq", &m12Sq);
57  theTree->SetBranchAddress("invMass23Sq", &m23Sq);
58  theTree->SetBranchAddress("invMass13Sq", &m13Sq);
59 
60  // Turn off unneeded branches
61  theTree->SetBranchStatus("invMass12", 0);
62  theTree->SetBranchStatus("invMass23", 0);
63  theTree->SetBranchStatus("invMass13", 0);
64 
65  double m12SqMin = theTree->GetMinimum("invMass12Sq");
66  double m12SqMax = theTree->GetMaximum("invMass12Sq");
67 
68  double m23SqMin = theTree->GetMinimum("invMass23Sq");
69  double m23SqMax = theTree->GetMaximum("invMass23Sq");
70 
71  double m13SqMin = theTree->GetMinimum("invMass13Sq");
72  double m13SqMax = theTree->GetMaximum("invMass13Sq");
73 
74  // Default: xAxis = m23Sq, yAxis = m13Sq, for xInt = 1, yInt = 2
75  double xMin(m23SqMin), xMax(m23SqMax);
76  double yMin(m13SqMin), yMax(m13SqMax);
77 
78  if (xInt == 2) {
79  xMin = m13SqMin; xMax = m13SqMax;
80  } else if (xInt == 3) {
81  xMin = m12SqMin; xMax = m12SqMax;
82  }
83 
84  if (yInt == 1) {
85  yMin = m23SqMin; yMax = m23SqMax;
86  } else if (yInt == 3) {
87  yMin = m12SqMin; yMax = m12SqMin;
88  }
89 
90  // Round off limits to nearest "integer"
91  xMin = roundMin(xMin);
92  xMax = roundMax(xMax);
93  yMin = roundMin(yMin);
94  yMax = roundMax(yMax);
95 
96  TH2D* DPHist = new TH2D("DPHist", "", 100, xMin, xMax, 100, yMin, yMax);
97  DPHist->SetDirectory(0);
98 
99  DPHist->SetXTitle(xLabel.c_str());
100  DPHist->SetYTitle(yLabel.c_str());
101 
102  int N = theTree->GetEntries();
103  int i(0);
104 
105  for (i = 0; i < N; i++) {
106 
107  theTree->GetEntry(i);
108 
109  if (i%100000 == 0) {cout<<"i = "<<N-i<<endl;}
110 
111  double xVal = m23Sq;
112  double yVal = m13Sq;
113 
114  if (xInt == 2) {
115  xVal = m13Sq;
116  } else if (xInt == 3) {
117  xVal = m12Sq;
118  }
119 
120  if (yInt == 1) {
121  yVal = m23Sq;
122  } else if (yInt == 3) {
123  yVal = m12Sq;
124  }
125 
126  DPHist->Fill(xVal, yVal);
127 
128  }
129 
130  return DPHist;
131 
132 }
133 
134 double roundMin(double x) {
135 
136  double value = floor(x)*0.98;
137  return value;
138 
139 }
140 
141 double roundMax(double x) {
142 
143  double value = ceil(x)*1.02;
144  return value;
145 
146 }