drawData.C
1 |
void fitH(TH1F *h, TF1 *g)
|
---|---|
2 |
{ |
3 |
Double_t rmax, rmin; |
4 |
|
5 |
Int_t i = h->GetMaximumBin(); |
6 |
while(h->GetBinContent(i) > 0.5*h->GetMaximum()) { |
7 |
rmax = h->GetBinCenter(i+1);
|
8 |
i++; |
9 |
} |
10 |
|
11 |
i = h->GetMaximumBin(); |
12 |
while(h->GetBinContent(i) > 0.5*h->GetMaximum()) { |
13 |
rmin = h->GetBinLowEdge(i-1);
|
14 |
i--; |
15 |
} |
16 |
|
17 |
//cout << "########" << endl << rmin << " " << rmax << endl;
|
18 |
g->SetParLimits(1,rmin,rmax);
|
19 |
g->SetRange(rmin,rmax); |
20 |
h->Fit("g","R"); |
21 |
//ofile << g->GetParameter(1) << endl;
|
22 |
} |
23 |
|
24 |
// main macro function
|
25 |
// ===================
|
26 |
void drawData()
|
27 |
{ |
28 |
Int_t par1,par2,par3,par4; |
29 |
|
30 |
par3=1;
|
31 |
|
32 |
TString inFilename("/home/muzalevsky/work/exp1803/data/exp1804/h5_14/out40cal.root");
|
33 |
TString inTreeName("tree");
|
34 |
TString outPdfDir("pdf");
|
35 |
|
36 |
// Open the input file
|
37 |
// ========================================================================
|
38 |
TFile *f1 = new TFile(inFilename, "READ"); |
39 |
if (f1->IsZombie()) {
|
40 |
cerr << "Could not open file '" << inFilename << "'" << endl; |
41 |
return;
|
42 |
} else {
|
43 |
cerr << "Input file '" << inFilename << "' opened." << endl; |
44 |
} |
45 |
// ========================================================================
|
46 |
|
47 |
// Get the input tree
|
48 |
// ========================================================================
|
49 |
TTree *t1 = (TTree*)f1->Get(inTreeName); |
50 |
if (t1 == NULL) { |
51 |
cerr << "Could not find tree '" << inTreeName << "' in file '" << inFilename << "'" << endl; |
52 |
return;
|
53 |
} else {
|
54 |
cerr << "Input tree '" << inTreeName << "' found." << endl; |
55 |
} |
56 |
////t1->SetMakeClass(1);
|
57 |
// ========================================================================
|
58 |
|
59 |
/*
|
60 |
if (par1) {
|
61 |
|
62 |
cerr << "Processing 'par1' part." << endl;
|
63 |
|
64 |
TFile *f = new TFile("/home/muzalevsky/work/exp1803/data/exp1804/h5_14/out.root");
|
65 |
TTree *t = (TTree*)f->Get("tree");
|
66 |
TCanvas *c1 = new TCanvas();
|
67 |
c1->Divide(2,2);
|
68 |
c1->cd(1);
|
69 |
c1_1->SetLogz();
|
70 |
// t->Draw("F5[0]+F3[0] : tF5[0]-tF3[0] >> (500,100,700,500,100,4000)","","col");
|
71 |
t->Draw("F5[]+F3[] : tF5[]-tF3[] >> (500,100,700,500,100,4000)","","col");
|
72 |
|
73 |
c1->cd(2);
|
74 |
c1_2->SetLogz();
|
75 |
t->Draw("SQX_R : CsI_R","SQX_R>1.15 && CsI_R>0","col");
|
76 |
|
77 |
c1->cd(3);
|
78 |
//c1_3->SetLogz();
|
79 |
// t->Draw("F5[0]+F3[0] : tF5[0]-tF3[0]","(F5[0]+F3[0])>300 && (F5[0]+F3[0])<700 && (tF5[0]-tF3[0])>540 && (tF5[0]-tF3[0])<640","col");
|
80 |
t->Draw("F5[]+F3[] : tF5[]-tF3[]","(F5[]+F3[])>300 && (F5[]+F3[])<700 && (tF5[]-tF3[])>540 && (tF5[]-tF3[])<640","");
|
81 |
|
82 |
//c1->cd(4);
|
83 |
//t->Draw("SQX_R:CsI_R","SQX_R>1.15 && CsI_R>0 && (F5[]+F3[])>300 && (F5[]+F3[])<700 && (tF5[]-tF3[])>540 && (tF5[]-tF3[])<640","");
|
84 |
|
85 |
} // end of 'par1' part
|
86 |
|
87 |
if (par2) {
|
88 |
|
89 |
cerr << "Processing 'par2' part." << endl;
|
90 |
|
91 |
TCanvas *c2 = new TCanvas();
|
92 |
c2->Divide(2,2);
|
93 |
c1_1->SetLogz();
|
94 |
c2->cd(1);
|
95 |
TH2F *h1 = new TH2F("h1","TOF",500,100.,1000.,500,0.,7000.);
|
96 |
t->Draw("NeEvent.F5[0]+NeEvent.F3[0] : NeEvent.tF5[0]-NeEvent.tF3[0] >> h1","","col");
|
97 |
c2->Update();
|
98 |
|
99 |
c2->cd(2);
|
100 |
TH2F *h2 = new TH2F("h2","TOF cut",100,600.,750.,100,300.,800.);
|
101 |
c1_2->SetLogz();
|
102 |
t->Draw("NeEvent.F5[0]+NeEvent.F3[0]:NeEvent.tF5[0]-NeEvent.tF3[0] >> h2","","col");
|
103 |
c2->Update();
|
104 |
|
105 |
c2->cd(3);
|
106 |
t->Draw("NeEvent.SQX_R[0]","NeEvent.SQX_R[0]>0 && NeEvent.SQX_R[0]<2000","");
|
107 |
c2->Update();
|
108 |
|
109 |
c2->cd(4);
|
110 |
t->Draw("NeEvent.SQX_R[]","NeEvent.tF5[]-NeEvent.tF3[] > 600 && NeEvent.tF5[]-NeEvent.tF3[] < 750 && NeEvent.F5[]+NeEvent.F3[]>300 && NeEvent.F5[]+NeEvent.F3[]<800 && NeEvent.SQX_R[]>0","");
|
111 |
|
112 |
TCanvas *c1 = new TCanvas();
|
113 |
c1->Divide(2,2);
|
114 |
c1->cd(1);
|
115 |
t->Draw("NeEvent.SQX_R[]:NeEvent.CsI_R[]","","");
|
116 |
c1->cd(2);
|
117 |
t->Draw("NeEvent.SQX_R[0]:NeEvent.CsI_R[0]","","");
|
118 |
c1->cd(3);
|
119 |
t->Draw("NeEvent.SQX_R[0]","NeEvent.SQX_R[0]>0 && NeEvent.SQX_R[0]<2000","");
|
120 |
c1->cd(4);
|
121 |
t->Draw("NeEvent.SQX_R[0]:NeEvent.CsI_R[0]","NeEvent.SQX_R[0]>200 && NeEvent.CsI_R[0]>100","");
|
122 |
|
123 |
} // end of 'par2' part
|
124 |
*/
|
125 |
if (par3) {
|
126 |
|
127 |
cerr << "Processing 'par3' part." << endl;
|
128 |
|
129 |
TH1I *hmulX = new TH1I("hmulX","x multiplicity",4,1,5); |
130 |
TH1I *hmulY = new TH1I("hmulY","y multiplicity",4,1,5); |
131 |
|
132 |
TH2F *h1; |
133 |
TH2F *h2; |
134 |
|
135 |
|
136 |
TFile *f1 = new TFile("/home/muzalevsky/work/exp1803/data/exp1804/h5_14/out40cal.root"); |
137 |
TTree *t1 = (TTree*)f1->Get("tree");
|
138 |
TCanvas *c2 = new TCanvas("c2","Si amp^times",1800,1000); |
139 |
c2->Divide(2,2); |
140 |
c2->cd(1);
|
141 |
gPad->SetLogz(); |
142 |
//t1->Draw("SQY_L[4]:tSQY_L[4]>>htemp1(400,1000,1400,100,0,90)","tSQY_L[4]>0 && SQY_L[4]>0","box",5000000,0);
|
143 |
t1->Draw("SQX_L[8]:tSQX_L[8]>>htemp1(400,200,600,100,0,90)","tSQX_L[8]>0 && SQX_L[8]>0","box",20000000,0); |
144 |
h1 = (TH2F*)gPad->GetPrimitive("htemp1");
|
145 |
//cout << h1 << endl;
|
146 |
//c2->cd(3);
|
147 |
h1->Draw(); |
148 |
|
149 |
|
150 |
c2->cd(2);
|
151 |
gPad->SetLogz(); |
152 |
//c2_2->SetLogz();
|
153 |
//t1->Draw("SQY_L[4]:tSQY_L[4]>>htemp2(400,1000,1400,100,0,90)","tSQY_L[4]>0 && SQY_L[4]>0 && multY_L>1","box",5000000,0);
|
154 |
t1->Draw("SQX_L[8]:tSQX_L[8]>>htemp2(400,200,600,100,0,90)","tSQX_L[8]>0 && SQX_L[8]>0 && multY_L>1","box",20000000,0); |
155 |
h2 = (TH2F*)gPad->GetPrimitive("htemp2");
|
156 |
h2->Draw(); |
157 |
|
158 |
//h2->Draw();
|
159 |
c2->cd(3);
|
160 |
gPad->SetLogz(); |
161 |
//t1->Draw("SQY_L[]:tSQY_L[]>>htemp3(400,1000,1400,100,0,90)","tSQY_L[]>0 && SQY_L[]>0","col",5000000,0);
|
162 |
t1->Draw("SQX_L[]:tSQX_L[]>>htemp3(400,200,600,100,0,90)","tSQX_L[]>0 && SQX_L[]>0","col",500000,0); |
163 |
//t1->Draw("SQY_L[12]:tSQY_L[12]","multY_L==2","",4000000,0);
|
164 |
|
165 |
c2->cd(4);
|
166 |
gPad->SetLogz(); |
167 |
//t1->Draw("SQY_L[]:tSQY_L[]>>htemp4(400,1000,1400,100,0,90)","multY_L==1 && tSQY_L[]>0 && SQY_L[]>0","col",5000000,0);
|
168 |
t1->Draw("SQX_L[]:tSQX_L[]>>htemp4(400,200,600,100,0,90)","multY_L==1 && tSQX_L[]>0 && SQX_L[]>0","col",500000,0); |
169 |
|
170 |
} // end of 'par3' part
|
171 |
|
172 |
|
173 |
|
174 |
/*if (par4) {
|
175 |
|
176 |
cerr << "Processing 'par4' part." << endl;
|
177 |
|
178 |
// Open output text file
|
179 |
// ========================================================================
|
180 |
// TString outTxtFilename("/home/muzalevsky/work/exp1803/data/exp1804/h5_14/positionstest.txt");
|
181 |
TString outTxtFilename("tParY_L.clb");
|
182 |
ofstream outcalfile;
|
183 |
outcalfile.open(outTxtFilename.Data());
|
184 |
if (!outcalfile.is_open()) {
|
185 |
cerr << "Could not open output text file'" << outTxtFilename << "'" << endl;
|
186 |
return;
|
187 |
} else {
|
188 |
cerr << "Opened output text file '" << outTxtFilename << "'" << endl;
|
189 |
}
|
190 |
|
191 |
|
192 |
// ========================================================================
|
193 |
|
194 |
//TH1::AddDirectory(kFALSE);
|
195 |
|
196 |
// Create a Gaussian function
|
197 |
TF1* g = new TF1("g", "gaus", 1000., 1200.);
|
198 |
//g->SetParLimits(0, 1., 1e+7);
|
199 |
g->SetParLimits(1, 1000., 1200.);
|
200 |
g->SetParLimits(2, 1., 50.);
|
201 |
|
202 |
Int_t nhists = 16;
|
203 |
Int_t ncanvases = nhists/4;
|
204 |
Double_t shift,zeroLevel;
|
205 |
|
206 |
TH1F *hX[32];
|
207 |
TH1F *hY[16];
|
208 |
TH2F *h2D[32];
|
209 |
|
210 |
TH1F* h = new TH1F("h","temp hist", 140,1020.,1160.);
|
211 |
TH2F *h2 = new TH2F("h2","temp 2d hist",140,1020.,1160.,400,0.,90.);
|
212 |
|
213 |
TString hname,h2name;
|
214 |
//for(Int_t i=0;i<nhists;i++) {
|
215 |
// TString hname;
|
216 |
// hname.Form("h%d",i+1);
|
217 |
// hX[i] = new TH1F(hname.Data(),"title",1200,0,1200);
|
218 |
// }
|
219 |
|
220 |
outcalfile << 2 << endl << nhists<< endl;
|
221 |
|
222 |
// Create canvases
|
223 |
// ========================================================================
|
224 |
TCanvas* c[4]; // works only if ncanvases==8
|
225 |
for(Int_t i=0; i<4; i++) {
|
226 |
TString cName;
|
227 |
cName.Form("c_%d",i);
|
228 |
c[i] = new TCanvas(cName.Data(),"calibrated spectra",1000,1000);
|
229 |
c[i]->Divide(2,2);
|
230 |
}
|
231 |
|
232 |
TCanvas* c2[4]; // works only if ncanvases==8
|
233 |
for(Int_t i=0; i<4; i++) {
|
234 |
TString cName;
|
235 |
cName.Form("c2_%d",i);
|
236 |
c2[i] = new TCanvas(cName.Data(),"2-dim calibrated spectra",1000,1000);
|
237 |
c2[i]->Divide(2,2);
|
238 |
}
|
239 |
cerr << "Canvases created." << endl;
|
240 |
// ========================================================================
|
241 |
|
242 |
for (Int_t i=0;i<nhists;i++)
|
243 |
{
|
244 |
|
245 |
cerr << "i=" << i << endl;
|
246 |
|
247 |
|
248 |
hname.Form("h%d",i);
|
249 |
|
250 |
TString cut;
|
251 |
cut.Form("SQY_L[%d]>14",i);
|
252 |
//cut.Form("tSQX_L[%d]>1000 && tSQX_L[%d]<1600",i,i,i);
|
253 |
|
254 |
TString vary1;
|
255 |
//vary1.Form("tSQX_L[%d]>>(200,1000,1200)",i);
|
256 |
vary1.Form("tSQY_L[%d]>>h%d(200,1000,1200)",i,i);
|
257 |
|
258 |
Int_t count = i/4;
|
259 |
Int_t nPad = (i%4)+1;
|
260 |
|
261 |
c[count]->cd(nPad);
|
262 |
t1->Draw(vary1.Data(),cut.Data(),"",10000000,0);
|
263 |
|
264 |
hX[i] = (TH1F*)gPad->GetPrimitive(hname.Data());
|
265 |
hX[i]->SetTitle(hname.Data());
|
266 |
fitH(hX[i],g);
|
267 |
if(i==0) {
|
268 |
zeroLevel = g->GetParameter(1);
|
269 |
shift = 0;
|
270 |
}
|
271 |
shift = zeroLevel - g->GetParameter(1);
|
272 |
outcalfile
|
273 |
<< setprecision(4) << shift*0.3 << "\t"
|
274 |
<< setprecision(4) << "0.3" << "\t\t" //E=a+bN
|
275 |
<< "0" << endl;
|
276 |
|
277 |
|
278 |
c[count]->Update();
|
279 |
|
280 |
c2[count]->cd(nPad);
|
281 |
|
282 |
h2name.Form("h2_%d",i);
|
283 |
TString cut1;
|
284 |
cut1.Form("tSQX_L[%d]>900 && tSQX_L[%d]<1600",i,i);
|
285 |
|
286 |
TString vary;
|
287 |
vary.Form("SQY_L[%d]:tSQY_L[%d]>>h2_%d(400,1000.,1400.,100,0.,90)",i,i,i);
|
288 |
gPad->SetLogz();
|
289 |
t1->Draw(vary.Data(),"","col",100000,0);
|
290 |
|
291 |
|
292 |
h2D[i] = (TH2F*)gPad->GetPrimitive(h2name.Data());
|
293 |
TString title;
|
294 |
title.Form("2-dim %d",i);
|
295 |
h2D[i]->SetTitle(title.Data());
|
296 |
//h2D[i]->Draw();
|
297 |
|
298 |
c2[count]->Update();
|
299 |
|
300 |
}
|
301 |
|
302 |
// Export canvases into output PDF files
|
303 |
// ========================================================================
|
304 |
for (Int_t iCanv=0; iCanv<ncanvases; iCanv++) {
|
305 |
TString outFilename;
|
306 |
outFilename.Form("%s/canv_%d.pdf", outPdfDir.Data(), iCanv);
|
307 |
c[iCanv]->SaveAs(outFilename);
|
308 |
outFilename.Form("%s/canv2_%d.pdf", outPdfDir.Data(), iCanv);
|
309 |
c2[iCanv]->SaveAs(outFilename);
|
310 |
}
|
311 |
cerr << "Exported canvases into output PDF files." << endl;
|
312 |
// ========================================================================
|
313 |
|
314 |
|
315 |
} // end of 'par4' part*/
|
316 |
|
317 |
} |