EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
plot_matscan.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file plot_matscan.C
1 vector<float> thetavec[5]; vector<float> phivec[5]; vector<float> x0vec_max[5]; vector<float> x0vec_min[5]; vector<float> lamda0vec[5];
2 int loaded = 0;
3 float ** thetaarr; float ** etaarr; float ** phiarr; float ** x0arr; float ** x0arr_copy; float ** x0Earr; float ** lamda0arr;
4 
5 TGraphErrors ** gr_th = new TGraphErrors*[5];
6 TGraphErrors ** gr_et = new TGraphErrors*[5];
7 
8 int color[] = {1,6,2,62,8,13};
9 
10 TString part[] = {"total","beampipe","barrel","forward","backward"};
11 const int size_part = sizeof(part)/sizeof(*part);
12 
13 
14 // Forward-delaring functions
15 void LoadData(const char *datfile);
16 void PrepareVariables();
17 void CreatePlots();
18 void PrettyTGraphErrors( TGraphErrors * gP , int color , int marker , float xmin , float xmax , float ymin , float ymax , TString xtit , TString ytit , TString tit );
19 // ========================================================================================================================================
21 
22  for(int i = 0 ; i < size_part ; i++) LoadData("data/matscan_"+part[i]+"_phiall.dat");
24  CreatePlots();
25 
26  // -------------------------------------------------
27  TLegend * leg = new TLegend(0.43,0.5,0.62,0.8);
28  leg -> SetLineColor(0);
29  for(int i = 0 ; i < size_part ; i++) leg -> AddEntry(gr_et[i],part[i]);
30 
31  // -------------------------------------------------
32  // Plotting results
33  TCanvas *c1 = new TCanvas("c1","material scan"); gPad -> SetTopMargin(0.03); gPad -> SetRightMargin(0.03);
34  gr_th[0]->SetMaximum(0.3);
35  gr_th[0]->Draw("ALE3");
36  for(int l = 0 ; l < loaded ; l++) gr_th[l] -> Draw("sameLE3");
37  leg -> Draw("same");
38 
39  TCanvas *c2 = new TCanvas("c2","material scan"); gPad -> SetTopMargin(0.03); gPad -> SetRightMargin(0.03);
40  gr_et[0]->Draw("ALE3");
41  for(int l = 0 ; l < loaded ; l++) gr_et[l] -> Draw("sameLE3");
42  leg -> Draw("same");
43 
44  // -------------------------------------------------
45 
46  TCanvas *c3 = new TCanvas("c3","material scan"); gPad -> SetTopMargin(0.03); gPad -> SetRightMargin(0.03);
47  gr_et[0]->Draw("ALE3");
48  leg -> Draw("same");
49 
50  TCanvas *c4 = new TCanvas("c4","material scan"); gPad -> SetTopMargin(0.03); gPad -> SetRightMargin(0.03);
51  gr_et[0]->Draw("ALE3");
52  gr_et[1]->Draw("SAMELE3");
53  leg -> Draw("same");
54 
55  TCanvas *c5 = new TCanvas("c5","material scan"); gPad -> SetTopMargin(0.03); gPad -> SetRightMargin(0.03);
56  gr_et[0]->Draw("ALE3");
57  gr_et[1]->Draw("SAMELE3");
58  gr_et[2]->Draw("SAMELE3");
59  leg -> Draw("same");
60 
61  TCanvas *c6 = new TCanvas("c6","material scan"); gPad -> SetTopMargin(0.03); gPad -> SetRightMargin(0.03);
62  gr_et[2]->Draw("ALE3");
63 
64  TCanvas *c7 = new TCanvas("c7","material scan"); gPad -> SetTopMargin(0.03); gPad -> SetRightMargin(0.03);
65  gr_et[3]->Draw("ALE3");
66 
67  // -------------------------------------------------
68  c1 -> Print("results1.pdf(");
69  c3 -> Print("results1.pdf" );
70  c4 -> Print("results1.pdf" );
71  c5 -> Print("results1.pdf" );
72  c2 -> Print("results1.pdf)");
73 
74  return;
75 }
76 // ========================================================================================================================================
77 void LoadData(const char *datfile){
78  FILE *f = fopen(datfile,"r");
79  if (!f){cout << "file " << datfile << " cannot be opened" << endl; return;}
80  float theta; float phi; float path; float x0; float lamda0;
81  float thetamin = 10000 ; float thetamax = -10000 ; float phimin = 10000 ; float phimax = -10000 ;
82  float x0min = 100000; float x0max = -100000; float lamda0min = 100000; float lamda0max = -100000;
83 
84  float previous_theta = -999.;
85  float previous_x0_max;
86  float previous_x0_min;
87 
88  int loaded_points = 0;
89 
90  while(fscanf(f,"%f %f %f %f %f",&theta,&phi,&path,&x0,&lamda0) != EOF){
91  if (theta > thetamax) thetamax = theta;
92  if (theta < thetamin) thetamin = theta;
93  if (phi > phimax) phimax = phi;
94  if (phi < phimin) phimin = phi;
95  if (x0 > x0max) x0max = x0;
96  if (x0 < x0min) x0min = x0;
97  if (lamda0 > lamda0max) lamda0max = lamda0;
98  if (lamda0 < lamda0min) lamda0min = lamda0;
99 
100  /*
101  if( loaded_points==0 ){
102  thetavec[loaded].push_back(theta);
103  phivec[loaded].push_back(phi);
104  x0vec_max[loaded].push_back(x0);
105  lamda0vec[loaded].push_back(lamda0);
106 
107  previous_theta = theta;
108  previous_x0_max = x0;
109  previous_x0_min = x0;
110  }
111  else{
112  */
113  if(theta != previous_theta){
114  thetavec[loaded].push_back(theta);
115  phivec[loaded].push_back(phi);
116  x0vec_max[loaded].push_back(x0);
117  x0vec_min[loaded].push_back(x0);
118  lamda0vec[loaded].push_back(lamda0);
119 
120  previous_theta = theta;
121  previous_x0_max = x0;
122  previous_x0_min = x0;
123  }
124  else{
125  if(x0 > previous_x0_max){
126  x0vec_max[loaded][x0vec_max[loaded].size()-1] = x0;
127  previous_x0_max = x0;
128  }
129  if(x0 < previous_x0_min){
130  x0vec_min[loaded][x0vec_min[loaded].size()-1] = x0;
131  previous_x0_min = x0;
132  }
133  }
134  //}
135 
136  loaded_points++;
137  }
138  loaded++;
139  fclose(f);
140 }
141 // ========================================================================================================================================
143  thetaarr = new float*[5];
144  etaarr = new float*[5];
145  phiarr = new float*[5];
146  x0arr = new float*[5];
147  x0arr_copy= new float*[5];
148  x0Earr = new float*[5];
149  lamda0arr = new float*[5];
150 
151  for(int l = 0 ; l < loaded ; l++){
152  thetaarr [l] = new float[thetavec [l].size()];
153  etaarr [l] = new float[thetavec [l].size()];
154  phiarr [l] = new float[phivec [l].size()];
155  x0arr [l] = new float[x0vec_max[l].size()];
156  x0arr_copy[l] = new float[x0vec_max[l].size()];
157  x0Earr [l] = new float[x0vec_max[l].size()];
158  lamda0arr [l] = new float[lamda0vec[l].size()];
159 
160  float x0min = 100.;
161 
162  for (int i=0; i<thetavec[l].size(); i++){
163  thetaarr [l][i] = 270. - thetavec[l][i];
164  etaarr [l][i] = -TMath::Log(TMath::Tan(thetaarr[l][i]/2.*TMath::Pi()/180.));
165  phiarr [l][i] = phivec[l][i];
166  x0arr [l][i] = (x0vec_max[l][i]+x0vec_min[l][i])/2.;
167  x0Earr [l][i] = (x0vec_max[l][i]-x0vec_min[l][i])/2.;
168  x0arr_copy[l][i] = (x0vec_max[l][i]+x0vec_min[l][i])/2.;
169  lamda0arr [l][i] = lamda0vec[l][i];
170  if(etaarr[l][i]!=etaarr[l][i]){etaarr[l][i] = -10.; x0arr[l][i] = -10.;}
171  if(x0arr [l][i] < x0min) x0min = x0arr[l][i];
172  }
173 
174  }
175 }
176 // ========================================================================================================================================
177 void CreatePlots(){
178  for(int l = 0 ; l < loaded ; l++){
179  gr_th[l] = new TGraphErrors(thetavec[l].size(),thetaarr[l],x0arr_copy[l],0,x0Earr[l]);
180  gr_et[l] = new TGraphErrors(thetavec[l].size(),etaarr [l],x0arr [l],0,x0Earr[l]);
181 
182  PrettyTGraphErrors( gr_th[l] , color[l] , 21 , -90, 270 , 999 , 999 , "#theta [deg]" , "radiation length (X/X_{0})" , "" );
183  PrettyTGraphErrors( gr_et[l] , color[l] , 21 , -4 , 4 , 0 , .25 , "#eta" , "radiation length (X/X_{0})" , "" );
184 
185  if(part[l]=="beampipe"){
186  gr_th[l] -> SetLineStyle(2);
187  gr_et[l] -> SetLineStyle(2);
188  }
189  }
190 }
191 // ========================================================================================================================================
192 void PrettyTGraphErrors( TGraphErrors * gP , int color , int marker , float xmin , float xmax , float ymin , float ymax , TString xtit , TString ytit , TString tit ){
193  gP -> GetXaxis() -> SetRangeUser(xmin,xmax);
194  gP -> SetMarkerSize(0.1);
195  gP -> SetLineColor(color);
196  gP -> SetFillColorAlpha(color,.3);
197  gP -> SetLineWidth(3);
198  gP -> SetMarkerColor(color);
199 
200  gP -> SetMinimum(0);
201 
202  if(ymax!=999) gP -> SetMaximum(ymax);
203  if(ymin!=999) gP -> SetMinimum(ymin);
204 
205  gP -> SetTitle(tit);
206  gP -> GetXaxis() -> SetTitle(xtit);
207  gP -> GetYaxis() -> SetTitle(ytit);
208 
209  gP -> GetXaxis() -> CenterTitle();
210  gP -> GetYaxis() -> CenterTitle();
211 }