Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Draw.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Draw.C
1 #include "/phenix/u/shlim/Style.h"
2 
3 void Draw(const int runnumber=28, const int segnumber=200){
4 
5  int bPOST_ALIGN = false;
6  int bPRE_ALIGN = false;
7 
8  float z_min = 200;
9  float z_max = 800;
10  float x_min = 200;
11  float x_max = 500;
12 
13  gStyle->SetOptStat(0);
14 
15  const int nColor[4] = {1, 2, 4, 8};
16 
17  TFile *infile = new TFile(Form("MvtxQAHisto-%08d-%04d.root",runnumber,segnumber),"read");
18 
19  TH2F *h2d_hit[4];
20  TH2F *h2d_hit_trk[4];
21  TH1F *h1d_hit_per_evt[4];
22  TH1F *h1d_hit_x[4];
23  TH1F *h1d_hit_y[4];
24  TH1F *h1d_hit_trk_x[4];
25  TH1F *h1d_hit_trk_y[4];
26 
27  TH1F *h1d_clus_size_x[4];
28  TH1F *h1d_clus_size_z[4];
29  TH2F *h2d_clus[4];
30  TH1F *h1d_clus_per_evt[4];
31 
32  TH1F *h1d_clus_res_x[4];
33  TH1F *h1d_clus_res_z[4];
34  TProfile *h1p_clus_res_x[4];
35  TProfile *h1p_clus_res_z[4];
36 
37  TF1 *f1p_clus_res_x[4];
38  TF1 *f1p_clus_res_z[4];
39 
40 
41  for (int ichip=0; ichip<4; ichip++){
42  h2d_hit[ichip] = (TH2F*)infile->Get(Form("h2d_hit_chip%d",ichip));
43  h2d_hit_trk[ichip] = (TH2F*)infile->Get(Form("h2d_hit_trk_chip%d",ichip));
44  h1d_hit_per_evt[ichip] = (TH1F*)infile->Get(Form("h1d_hit_per_evt_chip%d",ichip));
45 
46  h1d_hit_x[ichip] = (TH1F*)h2d_hit[ichip]->ProjectionX(Form("h1d_hit_x_chip%d",ichip));
47  h1d_hit_y[ichip] = (TH1F*)h2d_hit[ichip]->ProjectionY(Form("h1d_hit_y_chip%d",ichip));
48  h1d_hit_x[ichip]->SetLineColor(1);
49  h1d_hit_y[ichip]->SetLineColor(1);
50 
51  h1d_hit_trk_x[ichip] = (TH1F*)h2d_hit_trk[ichip]->ProjectionX(Form("h1d_hit_trk_x_chip%d",ichip));
52  h1d_hit_trk_y[ichip] = (TH1F*)h2d_hit_trk[ichip]->ProjectionY(Form("h1d_hit_trk_y_chip%d",ichip));
53  h1d_hit_trk_x[ichip]->SetLineColor(1);
54  h1d_hit_trk_y[ichip]->SetLineColor(1);
55 
56  h2d_clus[ichip] = (TH2F*)infile->Get(Form("h2d_clus_chip%d",ichip));
57 
58  h1d_clus_size_x[ichip] = (TH1F*)infile->Get(Form("h1d_clus_size_x_chip%d",ichip));
59  h1d_clus_size_z[ichip] = (TH1F*)infile->Get(Form("h1d_clus_size_z_chip%d",ichip));
60 
61  h1d_clus_per_evt[ichip] = (TH1F*)infile->Get(Form("h1d_clus_per_evt_chip%d",ichip));
62 
63  h1d_clus_size_x[ichip]->SetLineColor(1);
64  h1d_clus_size_z[ichip]->SetLineColor(2);
65 
66  h1d_clus_res_x[ichip] = (TH1F*)infile->Get(Form("h1d_clus_res_x_chip%d",ichip));
67  h1d_clus_res_z[ichip] = (TH1F*)infile->Get(Form("h1d_clus_res_z_chip%d",ichip));
68 
69  h1d_clus_res_x[ichip]->SetLineColor(nColor[ichip]);
70  h1d_clus_res_z[ichip]->SetLineColor(nColor[ichip]);
71 
72  h1p_clus_res_x[ichip] = (TProfile*)infile->Get(Form("h1p_clus_res_x_chip%d",ichip));
73  h1p_clus_res_z[ichip] = (TProfile*)infile->Get(Form("h1p_clus_res_z_chip%d",ichip));
74 
75  h1p_clus_res_x[ichip]->SetLineColor(nColor[ichip]);
76  h1p_clus_res_z[ichip]->SetLineColor(nColor[ichip]);
77  }
78 
79  TH1F *h1d_clus_eff = (TH1F*)infile->Get("h1d_clus_eff");
80  TH1F *h1d_clus_associated = (TH1F*)infile->Get("h1d_clus_associated");
81 
82  TCanvas *c0 = new TCanvas("c0","c0",1.1*2*400,400);
83  c0->Divide(2,1);
84 
85  c0->cd(1);
86  SetPadStyle();
87  gPad->SetLogy();
88 
89  htmp = (TH1F*)gPad->DrawFrame(0,1,50,1.5*h1d_hit_per_evt[0]->GetMaximum());
90  SetHistoStyle();
91 
92  for (int ichip=0; ichip<4; ichip++){
93  h1d_hit_per_evt[ichip]->SetLineColor(nColor[ichip]);
94  h1d_hit_per_evt[ichip]->SetLineWidth(2);
95  h1d_hit_per_evt[ichip]->Draw("same");
96  }
97 
98  c0->cd(2);
99  SetPadStyle();
100  gPad->SetLogy();
101 
102  htmp = (TH1F*)gPad->DrawFrame(0,1,10,1.5*h1d_clus_per_evt[0]->GetMaximum());
103  SetHistoStyle();
104 
105  for (int ichip=0; ichip<4; ichip++){
106  h1d_clus_per_evt[ichip]->SetLineColor(nColor[ichip]);
107  h1d_clus_per_evt[ichip]->SetLineWidth(2);
108  h1d_clus_per_evt[ichip]->Draw("same");
109  }
110 
111  //return;
112  //
113  //
114  ofstream fpre;
115  if ( bPRE_ALIGN ){
116  char fname[300];
117  sprintf(fname,"beamcenter/beamcenter_%08d.txt",runnumber);
118  fpre.open(fname);
119  }
120 
121  TCanvas *c1 = new TCanvas("c1","c1",150*1.1*3,150*4);
122  c1->Divide(3,4);
123 
124  for (int ichip=0; ichip<4; ichip++){
125 
126  c1->cd(3*ichip+1);
127  SetPadStyle();
128  gPad->SetLogz();
129 
130  htmp = (TH1F*)h2d_hit[ichip];
131  SetHistoStyle();
132 
133  htmp->Draw("col2");
134 
135  c1->cd(3*ichip+2);
136  SetPadStyle();
137 
138  htmp = (TH1F*)h1d_hit_x[ichip];
139  SetHistoStyle();
140  htmp->Draw();
141 
142  TF1 *fx = new TF1("fx","gaus",z_min,z_max);
143  htmp->Fit(fx,"R0Q");
144  //fx->Draw("same");
145 
146  fx->SetRange(fx->GetParameter(1)-fx->GetParameter(2), fx->GetParameter(1)+fx->GetParameter(2));
147  htmp->Fit(fx,"R0Q");
148  fx->Draw("same");
149 
150  /*
151  TF1 *fxx = new TF1("fxx","gaus(0)+gaus(3)",0,1024);
152  fxx->SetParameter(0,fx->GetParameter(0));
153  fxx->SetParameter(1,fx->GetParameter(1));
154  fxx->SetParameter(2,fx->GetParameter(2));
155  fxx->SetParameter(3,0.1*fx->GetParameter(0));
156  fxx->FixParameter(4,fx->GetParameter(1));
157  fxx->SetParameter(5,10.0*fx->GetParameter(2));
158  htmp->Fit(fxx,"R0");
159  fxx->Draw("same");
160  */
161 
162  c1->cd(3*ichip+3);
163  SetPadStyle();
164 
165  htmp = (TH1F*)h1d_hit_y[ichip];
166  SetHistoStyle();
167  htmp->Draw();
168 
169  TF1 *fy = new TF1("fy","gaus",x_min,x_max);
170  htmp->Fit(fy,"R0Q");
171  //fy->Draw("same");
172  //
173  fy->SetRange(fy->GetParameter(1)-fy->GetParameter(2), fy->GetParameter(1)+fy->GetParameter(2));
174  htmp->Fit(fy,"R0Q");
175  fy->Draw("same");
176 
177  /*
178  TF1 *fyy = new TF1("fyy","gaus(0)+gaus(3)",0,1024);
179  fyy->SetParameter(0,fy->GetParameter(0));
180  fyy->SetParameter(1,fy->GetParameter(1));
181  fyy->SetParameter(2,fy->GetParameter(2));
182  fyy->SetParameter(3,0.1*fy->GetParameter(0));
183  fyy->SetParameter(4,fy->GetParameter(1));
184  fyy->SetParameter(5,10.0*fy->GetParameter(2));
185  htmp->Fit(fyy,"R0Q");
186  fyy->Draw("same");
187  */
188 
189  double offset_xx = fx->GetParameter(1);
190  double offset_yy = fy->GetParameter(1);
191  /*
192  if ( fabs(fxx->GetParameter(0))<fabs(fxx->GetParameter(3)) ){
193  offset_xx = fxx->GetParameter(4);
194  }
195 
196  if ( fabs(fyy->GetParameter(0))<fabs(fyy->GetParameter(3)) ){
197  offset_yy = fyy->GetParameter(4);
198  }
199  */
200 
201  if ( bPRE_ALIGN ){
202  fpre << ichip << " 0 " << ichip << " " << offset_yy << " " << -2.2*ichip/(28e-4) << " " << offset_xx << endl;
203  cout << ichip << " 0 " << ichip << " " << offset_yy << " " << -2.2*ichip/(28e-4) << " " << offset_xx << endl;
204  }
205 
206 
207  /*
208  cout
209  << "CHIP: " << ichip
210  << ", x: " << fx->GetParameter(1)
211  << ", sx: " << fx->GetParameter(2)
212  << ", y: " << fy->GetParameter(1)
213  << ", sy: " << fy->GetParameter(2)
214  << endl;
215  */
216 
217  }//
218 
219  if ( bPRE_ALIGN ){
220  fpre.close();
221  }
222 
223  TCanvas *c3 = new TCanvas("c3","c3",200*1.1*2,200*2);
224  c3->Divide(2,2);
225 
226  for (int ichip=0; ichip<4; ichip++){
227  c3->cd(ichip+1);
228  SetPadStyle();
229  gPad->SetLogy();
230 
231  htmp = (TH1F*)gPad->DrawFrame(0,5,10,1.5*h1d_clus_size_x[ichip]->GetMaximum());
232  SetHistoStyle();
233 
234  h1d_clus_size_x[ichip]->Draw("same");
235  h1d_clus_size_z[ichip]->Draw("same");
236 
237 
238  }
239 
240  TCanvas *c4 = new TCanvas("c4","c4",300*1.1*2,300*2);
241  c4->Divide(2,2);
242 
243  c4->cd(1);
244  SetPadStyle();
245  gPad->SetLogy();
246 
247  htmp = (TH1F*)gPad->DrawFrame(-6,1,6,1.5*h1d_clus_res_z[0]->GetMaximum());
248  SetHistoStyle("dz (pixel, 28 #mum)");
249 
250  for (int ichip=0; ichip<4; ichip++){
251  h1d_clus_res_z[ichip]->SetLineWidth(2);
252  h1d_clus_res_z[ichip]->Draw("same");
253  }
254 
255  c4->cd(2);
256  SetPadStyle();
257  //gPad->SetLogy();
258 
259  htmp = (TH1F*)gPad->DrawFrame(0,-2.5,1024,+2.5);
260  SetHistoStyle();
261  SetHistoStyle("Column index","dz (pixel, 28 #mum)");
262 
263  for (int ichip=0; ichip<4; ichip++){
264  h1p_clus_res_z[ichip]->Draw("same");
265 
266  f1p_clus_res_z[ichip] = new TF1(Form("f1p_clus_res_z_%d",ichip),"pol1",z_min,z_max);
267  h1p_clus_res_z[ichip]->Fit(f1p_clus_res_z[ichip],"R0Q");
268  f1p_clus_res_z[ichip]->SetLineColor(nColor[ichip]);
269  if ( bPOST_ALIGN )
270  f1p_clus_res_z[ichip]->Draw("same");
271  }
272 
273  c4->cd(3);
274  SetPadStyle();
275  gPad->SetLogy();
276 
277  htmp = (TH1F*)gPad->DrawFrame(-6,1,6,1.5*h1d_clus_res_x[0]->GetMaximum());
278  SetHistoStyle("dx (pixel, 28 #mum)");
279 
280  for (int ichip=0; ichip<4; ichip++){
281  h1d_clus_res_x[ichip]->SetLineWidth(2);
282  h1d_clus_res_x[ichip]->Draw("same");
283  }
284 
285  c4->cd(4);
286  SetPadStyle();
287  //gPad->SetLogy();
288 
289  htmp = (TH1F*)gPad->DrawFrame(0,-2.5,512,+2.5);
290  SetHistoStyle("Row index","dx (pixel, 28 #mum)");
291 
292  for (int ichip=0; ichip<4; ichip++){
293  h1p_clus_res_x[ichip]->Draw("same");
294 
295  f1p_clus_res_x[ichip] = new TF1(Form("f1p_clus_res_x_%d",ichip),"pol1",x_min,x_max);
296  h1p_clus_res_x[ichip]->Fit(f1p_clus_res_x[ichip],"R0Q");
297  f1p_clus_res_x[ichip]->SetLineColor(nColor[ichip]);
298  if ( bPOST_ALIGN )
299  f1p_clus_res_x[ichip]->Draw("same");
300  }
301 
302  if ( bPOST_ALIGN ){
303  char fname[300];
304  sprintf(fname,"beamcenter/beamcenter_%08d.txt",runnumber);
305  ifstream fpar;
306  fpar.open(fname);
307  int tmp_layer, tmp_stave, tmp_chip;
308  double tmp_xx, tmp_yy, tmp_zz;
309 
310  double par_xx[4], par_yy[4], par_zz[4];
311 
312  while ( fpar >> tmp_layer >> tmp_stave >> tmp_chip >> tmp_xx >> tmp_yy >> tmp_zz ){
313  par_xx[tmp_chip] = tmp_xx;
314  par_yy[tmp_chip] = tmp_yy;
315  par_zz[tmp_chip] = tmp_zz;
316  }
317  fpar.close();
318 
319  ofstream fpar_out;
320  sprintf(fname,"beamcenter/beamcenter_%08d.txt",runnumber);
321  fpar_out.open(fname);
322 
323  for (int ichip=0; ichip<4; ichip++){
324  cout
325  << ichip << " "
326  << "0 "
327  << ichip << " "
328  << par_xx[ichip] + (f1p_clus_res_x[ichip]->Eval(par_xx[0]) - f1p_clus_res_x[0]->Eval(par_xx[0])) << " "
329  << par_yy[ichip] << " "
330  << par_zz[ichip] + (f1p_clus_res_z[ichip]->Eval(par_zz[0]) - f1p_clus_res_z[0]->Eval(par_zz[0]))
331  << endl;
332 
333  fpar_out
334  << ichip << " "
335  << "0 "
336  << ichip << " "
337  << par_xx[ichip] + (f1p_clus_res_x[ichip]->Eval(par_xx[0]) - f1p_clus_res_x[0]->Eval(par_xx[0])) << " "
338  << par_yy[ichip] << " "
339  << par_zz[ichip] + (f1p_clus_res_z[ichip]->Eval(par_zz[0]) - f1p_clus_res_z[0]->Eval(par_zz[0]))
340  << endl;
341  }
342  fpar_out.close();
343  }
344 
345 
346  /*
347  TCanvas *c3 = new TCanvas("c3","c3",150*1.1*4,150*2);
348  c3->Divide(4,2);
349 
350  for (int ichip=0; ichip<4; ichip++){
351 
352  c3->cd(ichip+1);
353  SetPadStyle();
354  gPad->SetLogy();
355 
356  htmp = (TH1F*)h1d_hit_trk_x[ichip];
357  SetHistoStyle();
358 
359  TF1 *fx = new TF1("fx","gaus",-5,5);
360  htmp->Fit(fx,"R0Q");
361 
362  double sum = 0;
363  for (int ii=0; ii<21; ii++){
364  sum += fx->Eval(-10+ii);
365  }
366 
367  cout << "Noise R x: " << (htmp->Integral()-sum)/htmp->Integral() << endl;
368 
369  htmp->SetAxisRange(-50,50);
370  htmp->Draw("");
371  fx->Draw("same");
372 
373  c3->cd(ichip+5);
374  SetPadStyle();
375  gPad->SetLogy();
376 
377  htmp = (TH1F*)h1d_hit_trk_y[ichip];
378  SetHistoStyle();
379 
380  TF1 *fy = new TF1("fy","gaus",-5,5);
381  htmp->Fit(fy,"R0Q");
382 
383  sum = 0;
384  for (int ii=0; ii<21; ii++){
385  sum += fy->Eval(-10+ii);
386  }
387 
388  cout << "Noise R y: " << (htmp->Integral()-sum)/htmp->Integral() << endl;
389 
390  htmp->SetAxisRange(-50,50);
391  htmp->Draw("");
392  fy->Draw("same");
393 
394  //cout << "Noise R y: " << (htmp->GetEntries()-fy->Integral(-10,10))/htmp->GetEntries() << endl;
395  }//
396 
397  int nevents = h1d_clus_associated->Integral(h1d_clus_associated->FindBin(3),h1d_clus_associated->GetNbinsX());
398 
399  h1d_clus_eff->Sumw2();
400  h1d_clus_eff->Scale(1./nevents);
401 
402  TCanvas *c5 = new TCanvas("c5","c5",1.1*400,400);
403  SetPadStyle();
404 
405  htmp = (TH1F*)gPad->DrawFrame(-0.5,0.95,3.5,1.02);
406  SetHistoStyle();
407 
408  h1d_clus_eff->SetLineWidth(2);
409  h1d_clus_eff->SetLineColor(1);
410  h1d_clus_eff->Draw("same");
411 
412  */
413 
414 
415 }