1 | // This program produces a ps file with
|
---|
2 | // two graphs in the same TPad, but
|
---|
3 | // with different axis.
|
---|
4 |
|
---|
5 | // The aim is to plot Nex and significance vs
|
---|
6 | // cut in alpha parameter.
|
---|
7 |
|
---|
8 | // As input, this macro needs a root file that is
|
---|
9 | // generated by the SupercutsONOFF programs.
|
---|
10 |
|
---|
11 | // It will read the histograms where Nex and significance
|
---|
12 | // vs alpha are stored and will plot this info in a single
|
---|
13 | // ps file.
|
---|
14 |
|
---|
15 | // The user must write
|
---|
16 |
|
---|
17 | // 1) Name of the root file with the info (Path included!!)
|
---|
18 |
|
---|
19 | // 2) Name of the output ps file (with path included!!)
|
---|
20 |
|
---|
21 | // Depending on the values to be plotted the axis scale
|
---|
22 | // as well as the axis offsets for labels might have to be
|
---|
23 | // modified. If I have time I will modify the program to
|
---|
24 | // make it automatic...
|
---|
25 |
|
---|
26 |
|
---|
27 |
|
---|
28 |
|
---|
29 | #include <string.h>
|
---|
30 | #include <iostream.h>
|
---|
31 | #include <fstream.h>
|
---|
32 | #include <iomanip.h>
|
---|
33 | #include <stdlib.h>
|
---|
34 | #include <math.h>
|
---|
35 |
|
---|
36 |
|
---|
37 | gROOT -> Reset();
|
---|
38 |
|
---|
39 | void SCNexSignificanceVSAlphaCut()
|
---|
40 | {
|
---|
41 |
|
---|
42 |
|
---|
43 |
|
---|
44 | char* SCRootFile = {"/.magic/magicserv01/scratch/Daniel/SuperCuts/Mrk421/2004_04_22/4slices_3520_nc/E800_1200_Opt/RootFileDynCuts.root"};
|
---|
45 |
|
---|
46 | char* output_ps_file = {"/.magic/magicserv01/scratch/Daniel/SuperCuts/Mrk421/2004_04_22/4slices_3520_nc/E800_1200_Opt/NexSignificanceVSCutinAlpha.ps"};
|
---|
47 |
|
---|
48 |
|
---|
49 |
|
---|
50 | char* ps_title =
|
---|
51 | {"Excess events (green) and significance (red) vs cut in alpha"};
|
---|
52 |
|
---|
53 |
|
---|
54 |
|
---|
55 |
|
---|
56 | // Name of the histograms (contained in root file) that contain the number of
|
---|
57 | // excess events and significance vs alpha cut
|
---|
58 |
|
---|
59 | TString ExcessEventsHistoName = ("NexVSAlphaTrainThetaRange0_1570mRad");
|
---|
60 | TString SignificanceHistoName = ("SignificanceVSAlphaTrainThetaRange0_1570mRad");
|
---|
61 |
|
---|
62 |
|
---|
63 | // Axis titles
|
---|
64 |
|
---|
65 | char* xaxis_title = "Cut in alpha (degrees)";
|
---|
66 | char* yaxis_title = "Excess events";
|
---|
67 | char* yaxis_2_title = "Significance";
|
---|
68 |
|
---|
69 | // Axis for plot
|
---|
70 |
|
---|
71 | const Double_t pad_xlow = 0;
|
---|
72 | const Double_t pad_ylow = 0;
|
---|
73 | const Double_t pad_xup = 30;
|
---|
74 | const Double_t pad_yup = 1000;
|
---|
75 |
|
---|
76 |
|
---|
77 |
|
---|
78 |
|
---|
79 | // Axis labels offsets for plot
|
---|
80 |
|
---|
81 | const Double_t xaxis_label_xoffset_pad = 8;
|
---|
82 | const Double_t xaxis_label_yoffset_pad = -300;
|
---|
83 | const Double_t yaxis_label_xoffset_pad = -5;
|
---|
84 | const Double_t yaxis_label_yoffset_pad = 1200;
|
---|
85 | const Double_t yaxis_2_label_xoffset_pad = 35;
|
---|
86 | const Double_t yaxis_2_label_yoffset_pad = 1200;
|
---|
87 |
|
---|
88 |
|
---|
89 |
|
---|
90 | // Vector of pointer to histograms that will be plotted
|
---|
91 | // Colors and marker types are also defined
|
---|
92 |
|
---|
93 |
|
---|
94 | const Int_t n_graphs = 2;
|
---|
95 | TGraph* graph_vector [n_graphs];
|
---|
96 | Int_t graph_colors_vector[n_graphs] = {3,2};
|
---|
97 | Int_t polimarker_style_vector[n_graphs] = {21,25};
|
---|
98 | char* additional_info_vector[n_graphs] =
|
---|
99 | {"Excess events", "Significance"};
|
---|
100 |
|
---|
101 |
|
---|
102 |
|
---|
103 | // TMP VARIABLES
|
---|
104 |
|
---|
105 | Int_t tmp_int = 0;
|
---|
106 |
|
---|
107 | TH1F* histo1;
|
---|
108 | TH1F* histo2;
|
---|
109 |
|
---|
110 |
|
---|
111 |
|
---|
112 | Double_t y_axis_2_min_value = 0.0;
|
---|
113 | Double_t y_axis_2_max_value = 0.0;
|
---|
114 |
|
---|
115 | Double_t graph_y_minmax_vector [n_graphs][2];
|
---|
116 | // It contains y values min and max for graphs that
|
---|
117 | // are plotted.
|
---|
118 |
|
---|
119 | Double_t graph_2_scale_factor = 0.0;
|
---|
120 |
|
---|
121 | // ******************************************************************
|
---|
122 | // Data is read from the histograms contained in the input root file
|
---|
123 | // and stored in vectors
|
---|
124 | // ******************************************************************
|
---|
125 |
|
---|
126 | TFile rootfile (SCRootFile, "READ");
|
---|
127 |
|
---|
128 | histo1 = (TH1F*) rootfile.Get(ExcessEventsHistoName);
|
---|
129 | histo2 = (TH1F*) rootfile.Get(SignificanceHistoName);
|
---|
130 |
|
---|
131 |
|
---|
132 |
|
---|
133 | // check that dimension is the same
|
---|
134 |
|
---|
135 | if (histo1 -> GetNbinsX() != histo2 -> GetNbinsX())
|
---|
136 | {
|
---|
137 | cout << "Dimension of histogram " << ExcessEventsHistoName
|
---|
138 | << " is not equal to dimension of histogram "<< SignificanceHistoName << endl
|
---|
139 | << "Aborting ..." << endl;
|
---|
140 |
|
---|
141 | Exit(1);
|
---|
142 | }
|
---|
143 |
|
---|
144 |
|
---|
145 | tmp_int = histo1 -> GetNbinsX();
|
---|
146 |
|
---|
147 | const Int_t vectors_dimension = tmp_int;
|
---|
148 |
|
---|
149 |
|
---|
150 | // Vectors that will be used to plot graphs are defined and filled
|
---|
151 |
|
---|
152 | Double_t alpha_cut_vector[vectors_dimension] = {0.0};
|
---|
153 | Double_t excess_events_vector[vectors_dimension] = {0.0};
|
---|
154 | Double_t significance_vector[vectors_dimension] = {0.0};
|
---|
155 |
|
---|
156 |
|
---|
157 | for (Int_t i = 0 ; i < vectors_dimension; i++)
|
---|
158 | {
|
---|
159 | alpha_cut_vector[i] = histo1-> GetBinCenter(i+1) + ((histo1->GetBinWidth(i+1))/2);
|
---|
160 | excess_events_vector[i] = histo1-> GetBinContent(i+1);
|
---|
161 | significance_vector[i] = histo2-> GetBinContent(i+1);
|
---|
162 | }
|
---|
163 |
|
---|
164 |
|
---|
165 |
|
---|
166 |
|
---|
167 | // Dynamic memory from is released and root file closed
|
---|
168 |
|
---|
169 | delete histo1;
|
---|
170 | delete histo2;
|
---|
171 |
|
---|
172 | rootfile.Close();
|
---|
173 |
|
---|
174 |
|
---|
175 | // Information retrieved from histos is displayed in terminal
|
---|
176 |
|
---|
177 | cout << endl
|
---|
178 | << "Cut in alpha, excess events and significance values retrieved from root file: "
|
---|
179 | << endl;
|
---|
180 |
|
---|
181 | for (Int_t i = 0 ; i < vectors_dimension; i++)
|
---|
182 | {
|
---|
183 | cout << alpha_cut_vector[i] << " "
|
---|
184 | << excess_events_vector[i] << " "
|
---|
185 | << significance_vector[i] << endl;
|
---|
186 | }
|
---|
187 |
|
---|
188 |
|
---|
189 |
|
---|
190 |
|
---|
191 |
|
---|
192 |
|
---|
193 | //******************************************************
|
---|
194 | // Graph 2 is scaled so that it can be plotted in the
|
---|
195 | // same TPad... kind of a trick in root.
|
---|
196 |
|
---|
197 | // First, values min and max are needed for the
|
---|
198 | // graphs to be plotted.
|
---|
199 |
|
---|
200 | graph_y_minmax_vector [0][0] = pad_ylow;
|
---|
201 | graph_y_minmax_vector [0][1] = find_max (excess_events_vector,
|
---|
202 | vectors_dimension);
|
---|
203 |
|
---|
204 | cout << " min set to : " << graph_y_minmax_vector [0][0] << endl;
|
---|
205 | cout << " max set to : " << graph_y_minmax_vector [0][1] << endl;
|
---|
206 |
|
---|
207 | graph_y_minmax_vector [1][0] = 0;
|
---|
208 |
|
---|
209 | graph_y_minmax_vector [1][1] = find_max (significance_vector,
|
---|
210 | vectors_dimension);
|
---|
211 | //TEST
|
---|
212 | /*
|
---|
213 | cout << graph_y_minmax_vector [0][1] << " "
|
---|
214 | << graph_y_minmax_vector [0][0] << endl;
|
---|
215 |
|
---|
216 | cout << graph_y_minmax_vector [1][1] << " "
|
---|
217 | << graph_y_minmax_vector [1][0] << endl;
|
---|
218 | */
|
---|
219 |
|
---|
220 |
|
---|
221 |
|
---|
222 | graph_2_scale_factor =
|
---|
223 | (graph_y_minmax_vector [0][1] -
|
---|
224 | graph_y_minmax_vector [0][0])/(graph_y_minmax_vector [1][1]
|
---|
225 | - graph_y_minmax_vector [1][0]);
|
---|
226 |
|
---|
227 | // cout << "scale factor : " << graph_2_scale_factor << endl;
|
---|
228 |
|
---|
229 | for (Int_t i = 0 ; i < vectors_dimension; i++)
|
---|
230 | {
|
---|
231 |
|
---|
232 | significance_vector[i] = ((graph_2_scale_factor * significance_vector[i])
|
---|
233 | + graph_y_minmax_vector [0][0]);
|
---|
234 | }
|
---|
235 |
|
---|
236 | // *********** END OF SCALING ********************************
|
---|
237 |
|
---|
238 | // Graphs are initialized and filled with vectors
|
---|
239 |
|
---|
240 |
|
---|
241 | // Graph i initialized and filled
|
---|
242 | graph_vector[0] = new TGraph(vectors_dimension,
|
---|
243 | alpha_cut_vector,
|
---|
244 | excess_events_vector);
|
---|
245 |
|
---|
246 |
|
---|
247 | graph_vector[1] = new TGraph(vectors_dimension,
|
---|
248 | alpha_cut_vector,
|
---|
249 | significance_vector);
|
---|
250 |
|
---|
251 | // Some properties of graphs are set
|
---|
252 |
|
---|
253 | for (Int_t i = 0; i < n_graphs; i++)
|
---|
254 | {
|
---|
255 | graph_vector[i]->SetTitle();
|
---|
256 | graph_vector[i]->SetFillColor(19);
|
---|
257 | graph_vector[i]->SetLineColor(graph_colors_vector[i]);
|
---|
258 | graph_vector[i]->SetLineWidth(1);
|
---|
259 | graph_vector[i]->SetMarkerColor(graph_colors_vector[i]);
|
---|
260 | graph_vector[i]->SetMarkerStyle(polimarker_style_vector[i]);
|
---|
261 | graph_vector[i]->SetMarkerSize(1);
|
---|
262 | }
|
---|
263 |
|
---|
264 |
|
---|
265 | // Graphgrams are plotted
|
---|
266 |
|
---|
267 |
|
---|
268 | TCanvas *Window = new TCanvas("Plot","Plot",600,600);
|
---|
269 |
|
---|
270 | gStyle->SetOptStat(0);
|
---|
271 | // So that statistic information is not printed
|
---|
272 |
|
---|
273 | Window -> SetFillColor(10);
|
---|
274 | gStyle -> SetFrameFillColor(10);
|
---|
275 | gStyle -> SetPadLeftMargin (0.15);
|
---|
276 | gStyle -> SetPadRightMargin (0.15);
|
---|
277 | gStyle -> SetPadTopMargin (0.05);
|
---|
278 | gStyle -> SetPadBottomMargin (0.15);
|
---|
279 |
|
---|
280 | TPaveText *title = new TPaveText (.05,.95,.95,.99);
|
---|
281 | title -> SetFillColor (38);
|
---|
282 | title -> AddText (ps_title);
|
---|
283 | title -> Draw();
|
---|
284 |
|
---|
285 |
|
---|
286 |
|
---|
287 |
|
---|
288 | /* TPad(const char *name, const char *title,
|
---|
289 | Double_t xlow, Double_t ylow,
|
---|
290 | Double_t xup, Double_t yup, Color_t color,
|
---|
291 | Short_t bordersize,Short_t bordermode)
|
---|
292 | : TVirtualPad(name,title,xlow,ylow,xup,yup,color,
|
---|
293 | bordersize,bordermode)
|
---|
294 | */
|
---|
295 |
|
---|
296 | TPad *pad = new TPad ("plot", "plot",0.0, 0.0, 1.0, 0.92,
|
---|
297 | 10, 0, 0);
|
---|
298 | // I do not want any border effect.
|
---|
299 | pad -> Draw();
|
---|
300 |
|
---|
301 |
|
---|
302 | // Axis and axis labels for pad1 are created and drawn.
|
---|
303 |
|
---|
304 | pad -> cd();
|
---|
305 | pad -> SetGrid(1,1); // Grid for x axis and for y axis.
|
---|
306 | pad -> DrawFrame(pad_xlow,pad_ylow,pad_xup,pad_yup);
|
---|
307 | // dimensions of the pad are set.
|
---|
308 |
|
---|
309 |
|
---|
310 |
|
---|
311 | // Labels of the graph are set
|
---|
312 |
|
---|
313 | TText *t = new TText();
|
---|
314 | t->SetTextFont(62);
|
---|
315 | t->SetTextColor(1);
|
---|
316 | t->SetTextSize(0.05);
|
---|
317 | t->SetTextAlign(11);
|
---|
318 |
|
---|
319 | // X axis
|
---|
320 | t->SetTextAngle(0);
|
---|
321 | t->DrawText(xaxis_label_xoffset_pad,
|
---|
322 | xaxis_label_yoffset_pad,
|
---|
323 | xaxis_title);
|
---|
324 | // Y axis
|
---|
325 | t->SetTextAngle(90);
|
---|
326 | t->DrawText(yaxis_2_label_xoffset_pad,
|
---|
327 | yaxis_2_label_yoffset_pad,
|
---|
328 | yaxis_2_title);
|
---|
329 |
|
---|
330 |
|
---|
331 |
|
---|
332 |
|
---|
333 | // Graphs are plotted in pad
|
---|
334 |
|
---|
335 |
|
---|
336 | for (Int_t j = 0; j < n_graphs; j++)
|
---|
337 | {
|
---|
338 |
|
---|
339 | pad -> cd();
|
---|
340 | graph_vector[j]-> Draw("LP");
|
---|
341 | // "A" option is removed in order to
|
---|
342 | //control de dimensionsn of the pad,
|
---|
343 | // by means of the " DrawFrame()" function.
|
---|
344 |
|
---|
345 | }
|
---|
346 |
|
---|
347 | // **************************************************
|
---|
348 | // Second Axis is drawn with its label
|
---|
349 |
|
---|
350 | // First of all we must look for units at
|
---|
351 | // bottom and top of axis. This is found
|
---|
352 |
|
---|
353 |
|
---|
354 | y_axis_2_min_value = ((pad_ylow - graph_y_minmax_vector [0][0])/
|
---|
355 | graph_2_scale_factor);
|
---|
356 |
|
---|
357 | y_axis_2_max_value = ((pad_yup - graph_y_minmax_vector [0][0])/
|
---|
358 | graph_2_scale_factor);
|
---|
359 |
|
---|
360 |
|
---|
361 |
|
---|
362 | TGaxis *axis = new TGaxis(gPad->GetUxmax(),gPad->GetUymin(),
|
---|
363 | gPad->GetUxmax(), gPad->GetUymax(),
|
---|
364 | y_axis_2_min_value,
|
---|
365 | y_axis_2_max_value,510,"+L");
|
---|
366 |
|
---|
367 | axis->SetLineColor(1);
|
---|
368 | axis->SetTextColor(1);
|
---|
369 | axis->Draw();
|
---|
370 |
|
---|
371 | // Y axis 2
|
---|
372 | t->SetTextAngle(90);
|
---|
373 | t->DrawText(yaxis_label_xoffset_pad,
|
---|
374 | yaxis_label_yoffset_pad,
|
---|
375 | yaxis_title);
|
---|
376 |
|
---|
377 | // Graph information is produced and drawn.
|
---|
378 |
|
---|
379 | // Spectrum names
|
---|
380 | /*
|
---|
381 | char info_string[150] = 0;
|
---|
382 | char info_string_tmp [20] = 0;
|
---|
383 | Double_t xpos = 0;
|
---|
384 | Double_t ypos = 0;
|
---|
385 | TText *tt = new TText();
|
---|
386 | tt->SetTextFont(62);
|
---|
387 | tt->SetTextSize(0.04);
|
---|
388 | tt->SetTextAlign(12);
|
---|
389 | tt->SetTextAngle(0);
|
---|
390 |
|
---|
391 | for (Int_t i = 0; i < n_graphs; i++)
|
---|
392 | {
|
---|
393 | if (i < 1)
|
---|
394 | {xpos = 0.15; ypos = 0.91;}
|
---|
395 | else
|
---|
396 | {xpos = 0.15; ypos = 0.85;}
|
---|
397 |
|
---|
398 | //xpos = 0.02 + i*0.12 + i*(i-1)*0.15; //for three curves
|
---|
399 | //xpos = 0.1 + i*0.4; // for two curves
|
---|
400 | strcpy(info_string, additional_info_vector[i]);
|
---|
401 | tt->SetTextColor(graph_colors_vector[i]);
|
---|
402 | Window -> cd();
|
---|
403 | tt->DrawText(xpos,ypos,info_string);
|
---|
404 | }
|
---|
405 | */
|
---|
406 |
|
---|
407 |
|
---|
408 | Window -> SaveAs(output_ps_file);
|
---|
409 |
|
---|
410 | }
|
---|
411 |
|
---|
412 |
|
---|
413 |
|
---|
414 |
|
---|
415 | // FUNCTION DEFINITIONS
|
---|
416 |
|
---|
417 |
|
---|
418 |
|
---|
419 |
|
---|
420 |
|
---|
421 | Double_t find_value (Double_t vector[], Int_t dimension, Int_t min_max)
|
---|
422 | {
|
---|
423 | Double_t value = vector[0];
|
---|
424 | if (min_max < 0.5) // we look for min
|
---|
425 | {
|
---|
426 | for (Int_t i = 1; i < dimension; i++)
|
---|
427 | {
|
---|
428 | if (value > vector[i])
|
---|
429 | {
|
---|
430 | value = vector[i];
|
---|
431 | }
|
---|
432 | }
|
---|
433 | }
|
---|
434 |
|
---|
435 | else // we look for max
|
---|
436 | {
|
---|
437 | for (Int_t i = 1; i < dimension; i++)
|
---|
438 | {
|
---|
439 | if (value < vector[i])
|
---|
440 | {
|
---|
441 | value = vector[i];
|
---|
442 | }
|
---|
443 | }
|
---|
444 | }
|
---|
445 |
|
---|
446 | return value;
|
---|
447 | }
|
---|
448 |
|
---|
449 |
|
---|
450 |
|
---|
451 | Double_t find_min (Double_t vector[], Int_t dimension)
|
---|
452 | {
|
---|
453 | Double_t min = 0.0;
|
---|
454 | min = find_value (vector, dimension, 0);
|
---|
455 | return min;
|
---|
456 | }
|
---|
457 |
|
---|
458 |
|
---|
459 |
|
---|
460 | Double_t find_max (Double_t vector[], Int_t dimension)
|
---|
461 | {
|
---|
462 | Double_t max = 0.0;
|
---|
463 | max = find_value (vector, dimension, 1);
|
---|
464 | return max;
|
---|
465 | }
|
---|
466 |
|
---|