BOSS 7.1.1
BESIII Offline Software System
Loading...
Searching...
No Matches
CheckRung/check/gainVsEangle.cxx
Go to the documentation of this file.
1//This code can display gains from two files vs eangle on one pad. One pad for one doca
2#include <vector>
3#include <string>
4
5using namespace std;
6
7vector<string>file;
8void pushNo()
9{
10 file.push_back("../../DocaEangle/docaeangle.root");
11 file.push_back("docaeangle.root");
12}
13
14#include "TStyle.h"
15#include "TString.h"
16
17const int PadNo1 = 0;
18const int PadNo2 = 40;
19const int TotalNo = 1600;
20const int NumSlices = 40;
21const int gainmin = 0;
22const int gainmax = 3;
23TString LegendName = "gain vs eangle";
24const int Ipadx = 1;
25const int Ipady = 1;
26const int CanvasX = 800; //canvas size for ps file
27const int CanvasY = 600;
28bool NormFlag = false; //true: nomalize wiregain for each layer
29const double histmin = 0.7; //Y axis range of histogram when NormFlag is true
30const double histmax = 1.3;
31const double delta = 0.15; //Y axis range of histogram when NormFlag is false
32
33
35{
36 pushNo();
37 const int FileNo = file.size();
38 TH2F*** h = new TH2F**[PadNo2];
39 TCanvas*** c = new TCanvas**[PadNo2];
40 TLegend*** lgd = new TLegend**[PadNo2];
41 gStyle->SetOptStat(0);
42 gStyle->SetCanvasColor(10);
43 for(int i=0;i<PadNo2;i++)
44 {
45 h[i] = new TH2F*[FileNo/2];
46 c[i] = new TCanvas*[FileNo/2];
47 lgd[i] = new TLegend*[FileNo/2];
48 }
49
50
51 TFile* f1;
52 TFile* f2;
53 TTree* tree1;
54 TTree* tree2;
55 double gain1[TotalNo],gain2[TotalNo],Id_doca1[TotalNo],Id_doca2[TotalNo],Norm1,Norm2;
56
57 stringstream histname; //histogram name
58 stringstream ss_file1; //file name
59 stringstream ss_file2;
60 stringstream ss1; //picture's drawing content
61 stringstream ss2;
62 stringstream cut;
63 stringstream legendheader;
64
65 for(int k=0;k<FileNo;k+=2)
66 {
67 ss_file1.str("");
68 ss_file1<<file[k];
69 f1=new TFile(ss_file1.str().c_str());
70 tree1=(TTree*)f1->Get("ddgcalib");
71 tree1->SetBranchAddress("Out_gain", gain1);
72 tree1->SetBranchAddress("Id_doca", Id_doca1);
73 tree1->GetEntry(0);
74 tree1->SetMarkerStyle(22);
75 tree1->SetMarkerColor(4);
76 tree1->SetLineColor(4);
77
78 ss_file2.str("");
79 ss_file2<<file[k+1];
80 f2=new TFile(ss_file2.str().c_str());
81 tree2=(TTree*)f2->Get("ddgcalib");
82 tree2->SetBranchAddress("Out_gain", gain2);
83 tree2->SetBranchAddress("Id_doca", Id_doca2);
84 tree2->GetEntry(0);
85 tree2->SetMarkerStyle(20);
86 tree2->SetMarkerColor(2);
87 tree2->SetLineColor(2);
88
89 for(int i=PadNo1;i<PadNo2;i++)
90 {
91 Norm1=0;
92 Norm2=0;
93 int k1=0;
94 int k2=0;
95
96 for(int j=0;j<TotalNo;j++)
97 {
98 if(Id_doca1[j]!=i) continue;
99 if(gain1[j]>gainmin && gain1[j]<gainmax) {Norm1 += gain1[j];k1++;}
100 if(gain2[j]>gainmin && gain2[j]<gainmax) {Norm2 += gain2[j];k2++;}
101 }
102 if(k1==0 || k2==0) {Norm1=1; Norm2=1;}
103 else {Norm1/= k1; Norm2/= k2;}
104 cout<<"Norm1= "<<Norm1<<" Norm2= "<<Norm2<<endl;
105
106 legendheader.str("");
107 legendheader<<"doca"<<i<<": "<<LegendName;
108 cout<<"legendheader: "<<legendheader.str().c_str()<<endl;
109 lgd[i][k/2] = new TLegend(.3, .75, .89, .89);
110 lgd[i][k/2] ->SetFillColor(10);
111 lgd[i][k/2] ->SetBorderSize(1);
112 lgd[i][k/2] ->SetHeader(legendheader.str().c_str());
113 lgd[i][k/2] ->AddEntry(tree1, ss_file1.str().c_str() , "p");
114 lgd[i][k/2] ->AddEntry(tree2, ss_file2.str().c_str() , "p");
115 lgd[i][k/2] ->Draw();
116
117 histname.str("");
118 histname<<"doca"<<i<<"_"<<file[k]<<"-"<<file[k+1];
119 //cout<<"histname: "<<histname.str().c_str()<<endl;
120 if(NormFlag) h[i][k/2] = new TH2F(histname.str().c_str(),"",100,0,NumSlices,100,histmin,histmax);
121 else h[i][k/2] = new TH2F(histname.str().c_str(),"",100,0,NumSlices,100,(Norm1+Norm2)/2-delta,(Norm1+Norm2)/2+delta);
122 h[i][k/2] -> GetYaxis()->SetTitle("gain");
123 h[i][k/2] -> GetYaxis()->SetTitleOffset(1.);
124 h[i][k/2] -> GetXaxis()->SetTitle("eangle");
125 c[i][k/2] = new TCanvas(histname.str().c_str(),histname.str().c_str(),800,600);
126 h[i][k/2] -> Draw();
127
128 cut.str("");
129 cut<<"Id_doca=="<<i;
130 cout<<"cut: "<<cut.str().c_str()<<endl;
131
132 ss1.str("");
133 if(NormFlag) ss1<<"Out_gain/"<<Norm1<<":Ip_eangle";
134 else ss1<<"Out_gain"<<":Ip_eangle";
135 tree1->Draw(ss1.str().c_str(),cut.str().c_str(),"sameLP");
136 ss2.str("");
137 if(NormFlag) ss2<<"Out_gain/"<<Norm2<<":Ip_eangle";
138 else ss2<<"Out_gain"<<":Ip_eangle";
139 tree2->Draw(ss2.str().c_str(),cut.str().c_str(),"sameLP");
140 }
141 }
142
143 TFile* g = new TFile("gainVsEangle.root","RECREATE");
144 for(int i=PadNo1;i<PadNo2;i++)
145 {
146 for(int k=0;k<FileNo;k+=2)
147 {
148 c[i][k/2] -> Write();
149 }
150 }
151 g->Close();
152
153 TCanvas* cc = new TCanvas("cc", "canvas", CanvasX, CanvasY);
154 cc->Divide(Ipadx,Ipady);
155 cc->Print("gainVsEangle.ps[");
156 for(int i=PadNo1;i<PadNo2;i++)
157 {
158 for(int k=0;k<FileNo;k+=2)
159 {
160 cc->cd(k/2+1);
161 gPad->Clear();
162 c[i][k/2]->DrawClonePad();
163 c[i][k/2] -> Close();
164 lgd[i][k/2] ->Delete();
165 }
166 cc->Update();
167 cc->Print("gainVsEangle.ps");
168 }
169 cc->Print("gainVsEangle.ps]");
170 cc->Close();
171
172 delete cc;
173 for(int i=PadNo1;i<PadNo2;i++)
174 {
175 for(int k=0;k<FileNo;k+=2)
176 {
177 delete h[i][k/2];
178 delete c[i][k/2];
179 }
180 }
181}
const int NumSlices
vector< string > file
const int CanvasX
const double delta
const double histmax
const double histmin
const int gainmin
const int CanvasY
const int gainmax
const int TotalNo
f1 Close()
curve Write()
legend Draw()
mg GetYaxis() -> SetRangeUser(0.8, 1.02)
mg GetXaxis() -> SetRangeUser(0.5, 1.9)
TFile * f1