BOSS 7.0.5
BESIII Offline Software System
Loading...
Searching...
No Matches
DocaEangle/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
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 eangle";
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],Id_doca1[TotalNo],Id_doca2[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("Id_doca", Id_doca1);
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("Id_doca", Id_doca2);
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(Id_doca1[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<<"doca"<<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 lgd[i][k/2] ->Draw();
106
107 histname.str("");
108 histname<<"doca"<<i<<"_"<<file[k]<<"-"<<file[k+1];
109 //cout<<"histname: "<<histname.str().c_str()<<endl;
110 if(NormFlag) h[i][k/2] = new TH2F(histname.str().c_str(),"",100,0,NumSlices,100,histmin,histmax);
111 else h[i][k/2] = new TH2F(histname.str().c_str(),"",100,0,NumSlices,100,(Norm1+Norm2)/2-delta,(Norm1+Norm2)/2+delta);
112 h[i][k/2] -> GetYaxis()->SetTitle("gain");
113 h[i][k/2] -> GetYaxis()->SetTitleOffset(1.);
114 h[i][k/2] -> GetXaxis()->SetTitle("eangle");
115 c[i][k/2] = new TCanvas(histname.str().c_str(),histname.str().c_str(),800,600);
116 h[i][k/2] -> Draw();
117
118 cut.str("");
119 cut<<"Id_doca=="<<i;
120 cout<<"cut: "<<cut.str().c_str()<<endl;
121
122 ss1.str("");
123 if(NormFlag) ss1<<"Out_gain/"<<Norm1<<":Ip_eangle";
124 else ss1<<"Out_gain"<<":Ip_eangle";
125 tree1->Draw(ss1.str().c_str(),cut.str().c_str(),"sameLP");
126 ss2.str("");
127 if(NormFlag) ss2<<"Out_gain/"<<Norm2<<":Ip_eangle";
128 else ss2<<"Out_gain"<<":Ip_eangle";
129 tree2->Draw(ss2.str().c_str(),cut.str().c_str(),"sameLP");
130 }
131 }
132
133 TFile* g = new TFile("gainVsEangle.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("gainVsEangle.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("gainVsEangle.ps");
158 }
159 cc->Print("gainVsEangle.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()
char * file
Definition: DQA_TO_DB.cxx:15
TFile * f1
const int NumSlices
const int PadNo2
const int CanvasX
const int Ipadx
const double delta
const int Ipady
void gainVsEangle()
const double histmax
const double histmin
const int gainmin
const int PadNo1
const int CanvasY
const int gainmax
const int TotalNo
TString LegendName
legend Draw()
mg GetYaxis() -> SetRangeUser(0.8, 1.02)
mg GetXaxis() -> SetRangeUser(0.5, 1.9)
Char_t cut[200]
Definition: eff.cxx:63