BOSS 7.1.2
BESIII Offline Software System
Loading...
Searching...
No Matches
CheckRung/check/wiregVsWire_bylayer.cxx
Go to the documentation of this file.
1//This code can display wiregains from two files on one pad. One pad for one layer.
2
3//#include "filename.h"
4#include "TStyle.h"
5#include "TString.h"
6
7int wirebind[44] = {0,40,84,132,188,252,324,404,484,560,636,724,812,912,1012,1124,1236,1364,1492,1632,1772,1932,2092,2252,2412,2588,2764,2940,3116,3324,3532,3740,3948,4188,4428,4668,4908,5164,5420,5676,5932,6220,6508,6796};
8const int LayNoi = 0;
9const int LayNo = 43;
10const int WireNo = 6796;
11double wiregmin = 0.;
12double wiregmax = 3; //select good hits which are put in to calculate norm and to be drawn
13TString LegendName = "wiregen vs wire";
14const int Ipadx = 1;
15const int Ipady = 1;
16const int CanvasX = 800; //canvas size for ps file
17const int CanvasY = 600;
18bool NormFlag = true; //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
23using namespace std;
24
25vector<string>file;
26void pushNo()
27{
28 file.push_back("../../WireGain/wiregain.root");
29 file.push_back("wiregain.root");
30}
31
33{
34 pushNo();
35 const int FileNo = file.size();
36 TH2F*** h = new TH2F**[LayNo];
37 stringstream histname;
38 TCanvas*** c = new TCanvas**[LayNo];
39 TLegend*** lgd = new TLegend**[LayNo];
40 gStyle->SetOptStat(0);
41 gStyle->SetCanvasColor(10);
42 for(int i=0;i<LayNo;i++)
43 {
44 h[i] = new TH2F*[FileNo/2];
45 c[i] = new TCanvas*[FileNo/2];
46 lgd[i] = new TLegend*[FileNo/2];
47 }
48
49
50 TFile* f1;
51 TFile* f2;
52 TTree* tree1;
53 TTree* tree2;
54 double wireg1[WireNo],wireg2[WireNo],Norm1,Norm2;
55
56 stringstream ss_file1; //file name
57 stringstream ss_file2;
58 stringstream ss1; //picture's drawing content
59 stringstream ss2;
60 stringstream cut;
61 stringstream legendheader;
62
63
64 for(int k=0;k<FileNo;k+=2)
65 {
66 ss_file1.str("");
67 ss_file1<<file[k];
68 //cout<<ss_file1.str().c_str()<<endl;
69 f1=new TFile(ss_file1.str().c_str());
70 tree1=(TTree*)f1->Get("wiregcalib");
71 tree1->SetBranchAddress("wireg", wireg1);
72 //tree1->SetBranchAddress("mean", wireg1);
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 //cout<<ss_file2.str().c_str()<<endl;
81 f2=new TFile(ss_file2.str().c_str());
82 tree2=(TTree*)f2->Get("wiregcalib");
83 tree2->SetBranchAddress("wireg", wireg2);
84 //tree2->SetBranchAddress("mean", wireg2);
85 tree2->GetEntry(0);
86 tree2->SetMarkerStyle(20);
87 tree2->SetMarkerColor(2);
88 tree2->SetLineColor(2);
89
90
91 for(int i=LayNoi;i<LayNo;i++)
92 {
93 cout<<"layer= "<<i<<endl;
94 Norm1=0;
95 Norm2=0;
96 int k1=0;
97 int k2=0;
98 for(int j=wirebind[i];j<wirebind[i+1];j++)
99 {
100 //cout<<"wireg1["<<j<<"]= "<<wireg1[j]<<endl;
101 if(wireg1[j]>wiregmin && wireg1[j]<wiregmax) {Norm1 += wireg1[j];k1++;}
102 if(wireg2[j]>wiregmin && wireg2[j]<wiregmax) {Norm2 += wireg2[j];k2++;}
103 //if(NormFlag==true) {Norm1 += wireg1[j];k1++;}
104 //if(NormFlag==true) {Norm2 += wireg2[j];k2++;}
105 }
106 Norm1/= k1;
107 Norm2/= k2;
108 cout<<"Norm1= "<<Norm1<<" Norm2= "<<Norm2<<endl;
109
110 legendheader.str("");
111 legendheader<<"lay"<<i<<": "<<LegendName;
112 lgd[i][k/2] = new TLegend(.3, .75, .89, .89);
113 lgd[i][k/2] ->SetFillColor(10);
114 lgd[i][k/2] ->SetBorderSize(1);
115 lgd[i][k/2] ->SetHeader(legendheader.str().c_str());
116 histname.str("");
117 histname<<"lay"<<i<<"_"<<file[k]<<"-"<<file[k+1];
118 if(NormFlag) h[i][k/2] = new TH2F(histname.str().c_str(),"",100,wirebind[i],wirebind[i+1],100,histmin,histmax);
119 else h[i][k/2] = new TH2F(histname.str().c_str(),"",100,wirebind[i],wirebind[i+1],100,(Norm1+Norm2)/2-delta,(Norm1+Norm2)/2+delta);
120 h[i][k/2] -> GetYaxis()->SetTitle("wiregain");
121 h[i][k/2] -> GetYaxis()->SetTitleOffset(1.);
122 h[i][k/2] -> GetXaxis()->SetTitle("wire");
123 c[i][k/2] = new TCanvas(histname.str().c_str(),histname.str().c_str(),800,600);
124 h[i][k/2] -> Draw();
125
126 cut.str("");
127 //cut<<"wire>="<<wirebind[i]<<" && wire<"<<wirebind[i+1]<<" && wireg>"<<wiregmin<<" && wireg<"<<wiregmax;
128 cut<<"wire>="<<wirebind[i]<<" && wire<"<<wirebind[i+1]<<" && wireg/"<<Norm1<<" >"<<histmin<<" && wireg/"<<Norm1<<" <"<<histmax;
129 cout<<"cut: "<<cut.str().c_str()<<endl;
130
131 ss1.str("");
132 //if(NormFlag) ss1<<"wireg/"<<Norm1<<":wire";
133 if(NormFlag) ss1<<"wireg/"<<Norm1<<":wire";
134 else ss1<<"wireg"<<":wire";
135 tree1->Draw(ss1.str().c_str(),cut.str().c_str(),"sameLP");
136 lgd[i][k/2] ->AddEntry(tree1, ss_file1.str().c_str() , "p");
137 //f1->Close();
138
139 cut.str("");
140 cut<<"wire>="<<wirebind[i]<<" && wire<"<<wirebind[i+1]<<" && wireg/"<<Norm2<<" >"<<histmin<<" && wireg/"<<Norm2<<" <"<<histmax;
141 ss2.str("");
142 //if(NormFlag) ss2<<"wireg/"<<Norm2<<":wire";
143 if(NormFlag) ss2<<"wireg/"<<Norm2<<":wire";
144 else ss2<<"wireg"<<":wire";
145 tree2->Draw(ss2.str().c_str(),cut.str().c_str(),"sameLP");
146 lgd[i][k/2] ->AddEntry(tree2, ss_file2.str().c_str() , "p");
147 //f2->Close();
148 lgd[i][k/2] ->Draw();
149 }
150 }
151
152// TFile* g = new TFile("diff_wire.root","RECREATE");
153// for(int i=LayNoi;i<LayNo;i++)
154// {
155// for(int k=0;k<FileNo;k+=2)
156// {
157// c[i][k/2] -> Write();
158// }
159// }
160// g->Close();
161
162
163 TCanvas* c1 = new TCanvas("c1", "canvas", CanvasX, CanvasY);
164 c1->Divide(Ipadx,Ipady);
165 c1->Print("diff_wire.ps[");
166 for(int i=LayNoi;i<LayNo;i++)
167 {
168 for(int k=0;k<FileNo;k+=2)
169 {
170 c1->cd(k/2+1);
171 gPad->Clear();
172 c[i][k/2]->DrawClonePad();
173 c[i][k/2] -> Close();
174 lgd[i][k/2] ->Delete();
175 }
176 c1->Update();
177 c1->Print("diff_wire.ps");
178 }
179 c1->Print("diff_wire.ps]");
180 c1->Close();
181
182 delete c1;
183 for(int i=LayNoi;i<LayNo;i++)
184 {
185 for(int k=0;k<FileNo;k+=2)
186 {
187 delete h[i][k/2];
188 delete c[i][k/2];
189 }
190 }
191
192}
vector< string > file
f1 Close()
legend Draw()
mg GetYaxis() -> SetRangeUser(0.8, 1.02)
mg GetXaxis() -> SetRangeUser(0.5, 1.9)
TFile * f1