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