BOSS 7.1.1
BESIII Offline Software System
Loading...
Searching...
No Matches
CosthetaSec/dEdxVsP.cxx
Go to the documentation of this file.
1//This code can display dE/dx from two files vs momentum on one pad.
2
3#include "TStyle.h"
4#include "TString.h"
5#include <vector>
6#include <string>
7
8using namespace std;
9
10vector<string>file;
11vector<string> str_name;
12void pushNo()
13{
14 file.push_back("dEdxVsP.root");
15 file.push_back("dEdxVsP.root");
16 str_name.push_back("positron");
17 str_name.push_back("electron");
18}
19
20
21
22const int no = 6; //The number of graphs you want to draw
23const int nbins = 50; //The number of momentum bins
24const double pMin = 0.1; //histogram range for momentum
25const double pMax = 2.2;
26const double chiMin = -1; //histogram range for chi mean
27const double chiMax = 1;
28const double chiSigmaMin = 0.5; //histogram range for chi sigma
29const double chiSigmaMax = 1.5;
30const double fitMeanMin = 520;
31const double fitMeanMax = 560;
32const double fitSigmaMin = 25;
33const double fitSigmaMax = 50;
34const double hitsMeanMin = 10;
35const double hitsMeanMax = 30;
36const double hitsSigmaMin = 0;
37const double hitsSigmaMax = 10;
38
39void dEdxVsP()
40{
41 pushNo();
42 const int FileNo = file.size();
43 string branchheader[FileNo] = {"pos_","neg_"};
44 TH2F** h = new TH2F*[no];
45 TCanvas** c = new TCanvas*[no];
46 TLegend** lgd = new TLegend*[no];
47 TGraphErrors*** gr = new TGraphErrors[no][FileNo];
48 for(int i =0;i<no;i++) gr[i] = new TGraphErrors*[FileNo];
49 gStyle->SetOptStat(0);
50 gStyle->SetCanvasColor(10);
51
52 TFile* f;
53 TTree* tree;
54
55 double chimean[FileNo][nbins],chimeanerr[FileNo][nbins],chisigma[FileNo][nbins];
56 double fitmean[FileNo][nbins],fitmeanerr[FileNo][nbins],fitsigma[FileNo][nbins];
57 double hits_mean[FileNo][nbins],hits_sigma[FileNo][nbins];
58 double pBin[FileNo][nbins];
59
60 stringstream ss;
61 stringstream branch;
62 for(int i=0;i<FileNo;i++)
63 {
64 ss.str("");
65 ss<<file[i];
66 f = new TFile(ss.str().c_str());
67 tree = (TTree*) f->Get("momInfor");
68 branch.str("");
69 branch<<branchheader[i]<<"chimean";
70 //cout<<branch.str().c_str()<<endl;
71 tree -> SetBranchAddress(branch.str().c_str(),chimean[i]);
72 branch.str("");
73 //cout<<branch.str().c_str()<<endl;
74 branch<<branchheader[i]<<"chimeanerr";
75 tree -> SetBranchAddress(branch.str().c_str(),chimeanerr[i]);
76 branch.str("");
77 branch<<branchheader[i]<<"chisigma";
78 tree -> SetBranchAddress(branch.str().c_str(),chisigma[i]);
79 branch.str("");
80 branch<<branchheader[i]<<"fitmean";
81 tree -> SetBranchAddress(branch.str().c_str(),fitmean[i]);
82 branch.str("");
83 branch<<branchheader[i]<<"fitmeanerr";
84 tree -> SetBranchAddress(branch.str().c_str(),fitmeanerr[i]);
85 branch.str("");
86 branch<<branchheader[i]<<"fitsigma";
87 tree -> SetBranchAddress(branch.str().c_str(),fitsigma[i]);
88 branch.str("");
89 branch<<"hits_mean";
90 tree -> SetBranchAddress(branch.str().c_str(),hits_mean[i]);
91 branch.str("");
92 branch<<"hits_sigma";
93 tree -> SetBranchAddress(branch.str().c_str(),hits_sigma[i]);
94 branch.str("");
95 branch<<"pBin";
96 tree -> SetBranchAddress(branch.str().c_str(),pBin[i]);
97 tree -> GetEntry(0);
98 }
99
100 //--------------------- chimean ------------------------------//
101 c[0] = new TCanvas("chimean","chimean",800,600);
102 c[0] -> SetGridx();
103 c[0] -> SetGridy();
104 h[0] = new TH2F("chimean","chimean",100,pMin,pMax,100,chiMin,chiMax);
105 h[0] -> GetYaxis()->SetTitle("#chi_{mean}");
106 //h[0] -> GetYaxis()->SetTitleOffset(.9);
107 h[0] -> GetXaxis()->SetTitle("momentum");
108 h[0] -> Draw();
109 lgd[0] = new TLegend(.65, .75, .89, .89);
110 lgd[0]->SetFillColor(10);
111 lgd[0]->SetBorderSize(1);
112
113 for(int i=0;i<FileNo;i++)
114 {
115 gr[0][i] = new TGraphErrors(nbins,pBin[i],chimean[i],0,chimeanerr[i]);
116 gr[0][i] -> SetMarkerStyle(20+i);
117 gr[0][i] -> SetMarkerColor(i+1);
118 gr[0][i] -> Draw("Psame");
119 lgd[0] -> AddEntry(gr[0][i], str_name[i].c_str() , "p");
120 }
121 lgd[0] -> Draw();
122
123 //--------------------- chisigma -----------------------------//
124 c[1] = new TCanvas("chisigma","chisigma",800,600);
125 c[1] -> SetGridx();
126 c[1] -> SetGridy();
127 h[1] = new TH2F("chisigma","chisigma",100,pMin,pMax,100,chiSigmaMin,chiSigmaMax);
128 h[1] -> GetYaxis()->SetTitle("#chi_{#sigma}");
129 //h[1] -> GetYaxis()->SetTitleOffset(.9);
130 h[1] -> GetXaxis()->SetTitle("momentum");
131 h[1] -> Draw();
132 lgd[1] = new TLegend(.65, .75, .89, .89);
133 lgd[1]->SetFillColor(10);
134 lgd[1]->SetBorderSize(1);
135
136 for(int i=0;i<FileNo;i++)
137 {
138 gr[1][i] = new TGraphErrors(nbins,pBin[i],chisigma[i],0,0);
139 gr[1][i] -> SetMarkerStyle(20+i);
140 gr[1][i] -> SetMarkerColor(i+1);
141 gr[1][i] -> Draw("Psame");
142 lgd[1] -> AddEntry(gr[1][i], str_name[i].c_str() , "p");
143 }
144 lgd[1] -> Draw();
145
146 //--------------------- fitmean -----------------------------//
147 c[2] = new TCanvas("fitmean","fitmean",800,600);
148 c[2] -> SetGridx();
149 c[2] -> SetGridy();
150 h[2] = new TH2F("fitmean","fitmean",100,pMin,pMax,100,fitMeanMin,fitMeanMax);
151 h[2] -> GetYaxis()->SetTitle("fitmean");
152 //h[2] -> GetYaxis()->SetTitleOffset(.9);
153 h[2] -> GetXaxis()->SetTitle("momentum");
154 h[2] -> Draw();
155 lgd[2] = new TLegend(.65, .75, .89, .89);
156 lgd[2]->SetFillColor(10);
157 lgd[2]->SetBorderSize(1);
158
159 for(int i=0;i<FileNo;i++)
160 {
161 gr[2][i] = new TGraphErrors(nbins,pBin[i],fitmean[i],0,0);
162 gr[2][i] -> SetMarkerStyle(20+i);
163 gr[2][i] -> SetMarkerColor(i+1);
164 gr[2][i] -> Draw("Psame");
165 lgd[2] -> AddEntry(gr[2][i], str_name[i].c_str() , "p");
166 }
167 lgd[2] -> Draw();
168
169 //--------------------- fitsigma -----------------------------//
170 c[3] = new TCanvas("fitsigma","fitsigma",800,600);
171 c[3] -> SetGridx();
172 c[3] -> SetGridy();
173 h[3] = new TH2F("fitsigma","fitsigma",100,pMin,pMax,100,fitSigmaMin,fitSigmaMax);
174 h[3] -> GetYaxis()->SetTitle("fitsigma");
175 //h[3] -> GetYaxis()->SetTitleOffset(.9);
176 h[3] -> GetXaxis()->SetTitle("momentum");
177 h[3] -> Draw();
178 lgd[3] = new TLegend(.65, .75, .89, .89);
179 lgd[3]->SetFillColor(10);
180 lgd[3]->SetBorderSize(1);
181
182 for(int i=0;i<FileNo;i++)
183 {
184 gr[3][i] = new TGraphErrors(nbins,pBin[i],fitsigma[i],0,0);
185 gr[3][i] -> SetMarkerStyle(20+i);
186 gr[3][i] -> SetMarkerColor(i+1);
187 gr[3][i] -> Draw("Psame");
188 lgd[3] -> AddEntry(gr[3][i], str_name[i].c_str() , "p");
189 }
190 lgd[3] -> Draw();
191
192 //---------------------used hits for dE/dx calculation -----------------------------//
193 c[4] = new TCanvas("hits_mean","hits_mean",800,600);
194 c[4] -> SetGridx();
195 c[4] -> SetGridy();
196 h[4] = new TH2F("hits_mean","hits_mean",100,pMin,pMax,100,hitsMeanMin,hitsMeanMax);
197 h[4] -> GetYaxis()->SetTitle("hits_mean");
198 //h[4] -> GetYaxis()->SetTitleOffset(.9);
199 h[4] -> GetXaxis()->SetTitle("momentum");
200 h[4] -> Draw();
201 lgd[4] = new TLegend(.65, .75, .89, .89);
202 lgd[4]->SetFillColor(10);
203 lgd[4]->SetBorderSize(1);
204
205 for(int i=0;i<FileNo;i++)
206 {
207 gr[4][i] = new TGraphErrors(nbins,pBin[i],hits_mean[i],0,0);
208 gr[4][i] -> SetMarkerStyle(20+i);
209 gr[4][i] -> SetMarkerColor(i+1);
210 gr[4][i] -> Draw("Psame");
211 lgd[4] -> AddEntry(gr[4][i], str_name[i].c_str() , "p");
212 }
213 lgd[4] -> Draw();
214
215 //---------------------sigma of used hits for dE/dx calculation -------------------------//
216 c[5] = new TCanvas("hits_sigma","hits_sigma",800,600);
217 c[5] -> SetGridx();
218 c[5] -> SetGridy();
219 h[5] = new TH2F("hits_sigma","hits_sigma",100,pMin,pMax,100,hitsSigmaMin,hitsSigmaMax);
220 h[5] -> GetYaxis()->SetTitle("hits_sigma");
221 //h[5] -> GetYaxis()->SetTitleOffset(.9);
222 h[5] -> GetXaxis()->SetTitle("momentum");
223 h[5] -> Draw();
224 lgd[5] = new TLegend(.65, .75, .89, .89);
225 lgd[5]->SetFillColor(10);
226 lgd[5]->SetBorderSize(1);
227
228 for(int i=0;i<FileNo;i++)
229 {
230 gr[5][i] = new TGraphErrors(nbins,pBin[i],hits_sigma[i],0,0);
231 gr[5][i] -> SetMarkerStyle(20+i);
232 gr[5][i] -> SetMarkerColor(i+1);
233 gr[5][i] -> Draw("Psame");
234 lgd[5] -> AddEntry(gr[5][i], str_name[i].c_str() , "p");
235 }
236 lgd[5] -> Draw();
237
238 TFile* g = new TFile("dEdxVsP_show.root","recreate");
239 for(int i=0;i<no;i++)
240 {
241 c[i]->Write();
242 }
243 g->Close();
244}
const double hitsMeanMin
const double chiSigmaMin
void dEdxVsP()
const double hitsSigmaMax
vector< string > file
const double hitsMeanMax
const double chiSigmaMax
const int nbins
const double fitMeanMax
const double hitsSigmaMin
void pushNo()
const double fitSigmaMin
const double chiMin
const double chiMax
const int no
const double fitMeanMin
const double pMin
const double fitSigmaMax
vector< string > str_name
const double pMax
legend Draw()
mg GetYaxis() -> SetRangeUser(0.8, 1.02)
mg GetXaxis() -> SetRangeUser(0.5, 1.9)
gr1 SetMarkerStyle(8)
legend AddEntry(gr3,"e+ Data oldPat","p")
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")
gr1 SetMarkerColor(1)
data GetEntry(0)
data SetBranchAddress("time",&time)
TGraph * gr