-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlotterProgram.cpp
422 lines (348 loc) · 12.1 KB
/
PlotterProgram.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
//Program adopted from "DataFitter", primary use for creating Figure 4 in Smolec. May be formed for general use later on?
//V1: Making program able to create figure 5 in smolec for sets A B C and D.
# include <iostream>
# include <fstream>
# include <math.h>
# include <iomanip>
# include <cmath>
# include <stdlib.h>
# include <cstdlib>
//# include <fstream.h>
# include <string.h>
# include <string>
//# include <dos.h> //For Sleep()
# include "TROOT.h"
# include "TFile.h"
# include "TTree.h"
# include "TBrowser.h"
# include "TH1.h"
# include "TH2.h"
# include "TH3.h"
# include "TRandom.h"
//Gauss user defined: [0]*exp((-(x-[1])*(x-[1]))/(2*[2]*[2]))
int main(){
//////Controls//////
int NumOfInputFiles = 4; //Number of input files plots are made for, useful for SetA through D.
int NumOfLines_1 = 387; //Number of lines in each input file including header if there is one
int NumOfLines_2 = 387;
int NumOfLines_3 = 387;
int NumOfLines_4 = 380;
char PNGFileName[50] = "Fig4_m06_L50"; //PNG output file name, do not include .png
char RootFileName[50] = "Fig4_m06_L50"; //Root output file name, do not include .root
char inputFileName1[50] = "ResonanceData_Fig5_FU_FO_SetA.dat";
char inputFileName2[50] = "ResonanceData_Fig5_FU_FO_SetB.dat";
char inputFileName3[50] = "ResonanceData_Fig5_FU_FO_SetC.dat";
char inputFileName4[50] = "ResonanceData_Fig5_FU_FO_SetD.dat";
char Label_1[10] = "SetA"; //Labels associated with input files, will be used as suffix to outfile names
char Label_2[10] = "SetB";
char Label_3[10] = "SetC";
char Label_4[10] = "SetD";
//Top plot of Fig4//
char PlotTitle_1[50] = "Frequency"; //Title of the plot
char xTitle_1[50] = "Teff"; //Title for x-axis, first column of data file
char yTitle_1[50] = "Frequency"; //Title for y-axis, second column of data file
double xLowerLimit_1 = 4000; //Limits for top plot in Fig4
double xUpperLimit_1 = 8000;
double yLowerLimit_1 = 0;
double yUpperLimit_1 = 5.0;
//Bottom plot of Fig4//
char PlotTitle_2[50] = "GrowthRate"; //Title of the plot
char xTitle_2[50] = "Teff"; //Title for x-axis, first column of data file
char yTitle_2[50] = "Growth Rate"; //Title for y-axis, second column of data file
double xLowerLimit_2 = 4000; //Limits for bottom plot in Fig4
double xUpperLimit_2 = 8000;
double yLowerLimit_2 = -2.0;
double yUpperLimit_2 = 0.5;
bool DataWithHeaders = true; //If true, will account for headers by using getline function
bool SavePlotAsPNG = true; //If true, will save plot with file name above.
bool SavePlotAsRootFile = true; //If true, will save plot in root file with name above.
////////////////////////////
//////Variables//////
ifstream inFile;
ofstream outFile;
int NumOfLines;
double xMax;
double xMin;
double yMax;
double yMin;
char line[100];
char header[100];
char Full_RootFileName[50];
char Full_PNGFileName[50];
//Dummy Variables//
double dummy1, dummy2, dummy3, dummy4, dummy5, dummy6, dummy7;
////////////////////////////
//////Main Program//////
for(int f = 0; f < NumOfInputFiles; f++){
//////Variables//////
if(f == 0){
const int nArray = NumOfLines_1 + 1;
}
if(f == 1){
const int nArray = NumOfLines_2 + 1;
}
if(f == 2){
const int nArray = NumOfLines_3 + 1;
}
if(f == 3){
const int nArray = NumOfLines_4 + 1;
}
double Teff[nArray];
double freq_FU[nArray];
double freq_FO[nArray];
double freq_2O[nArray];
double freq_ThirdO[nArray];
double freq_ForthO[nArray];
double growth_FU[nArray];
double growth_FO[nArray];
double growth_2O[nArray];
double growth_ThirdO[nArray];
double growth_ForthO[nArray];
double freq_BG1[nArray];
double freq_BG2[nArray];
double freq_BG3[nArray];
double freq_BG4[nArray];
double freq_BG5[nArray];
char inputFileName[50] = "";
/////////////////////
if(f == 0){
strcpy(inputFileName,inputFileName1);
if(DataWithHeaders){
NumOfLines = NumOfLines_1 - 1;
}
else{NumOfLines = NumOfLines_1;}
}
if(f == 1){
strcpy(inputFileName,inputFileName2);
if(DataWithHeaders){
NumOfLines = NumOfLines_2 - 1;
}
else{NumOfLines = NumOfLines_2;}
}
if(f == 2){
strcpy(inputFileName,inputFileName3);
if(DataWithHeaders){
NumOfLines = NumOfLines_3 - 1;
}
else{NumOfLines = NumOfLines_3;}
}
if(f == 3){
strcpy(inputFileName,inputFileName4);
if(DataWithHeaders){
NumOfLines = NumOfLines_4 - 1;
}
else{NumOfLines = NumOfLines_4;}
}
cout<<"Input file name: "<<inputFileName<<endl;
//Getting x,y from file//
inFile.open(inputFileName,ios::in);
if(inFile.is_open()){
cout<<"Input file was opened successfully"<<endl;
}
else{cout<<"Input file not found, check name?"<<endl;}
if(inFile.good()){
if(DataWithHeaders){
getline(inFile,header);
cout<<header<<endl;
}
for(int i = 0; i < NumOfLines; i++){
inFile>>Teff[i]>>freq_FU[i]>>freq_FO[i]>>freq_2O[i]>>freq_ThirdO[i]>>freq_ForthO[i]>>growth_FU[i]>>growth_FO[i]>>growth_2O[i]>>growth_ThirdO[i]>>growth_ForthO[i];
//inFile.ignore(50, '\n'); //This allows for only the defined lines to be read (unless data file is 50+ columns long)
cout<<setw(5)<<Teff[i]<<setw(10)<<freq_FU[i]<<setw(10)<<freq_FO[i]<<setw(10)<<freq_2O[i]<<setw(10)<<freq_ThirdO[i]<<setw(10)<<freq_ForthO[i]<<setw(10)<<growth_FU[i]<<setw(10)<<growth_FO[i]<<setw(10)<<growth_2O[i]<<setw(10)<<growth_ThirdO[i]<<setw(10)<<growth_ForthO[i]<<endl;
freq_BG1[i] = 1.5*freq_FU[i];
freq_BG2[i] = 2.0*freq_FU[i];
freq_BG3[i] = 2.5*freq_FU[i];
freq_BG4[i] = 3.5*freq_FU[i];
freq_BG5[i] = 4.5*freq_FU[i];
}
cout<<"************* End of file ********************"<<endl;
}
inFile.close();
//////Graphics//////
//Output file name creation//
if(f == 0){
strcpy(Full_RootFileName, RootFileName);
strcat(Full_RootFileName, "_");
strcat(Full_RootFileName, Label_1);
strcat(Full_RootFileName, ".root");
strcpy(Full_PNGFileName, PNGFileName);
strcat(Full_PNGFileName, "_");
strcat(Full_PNGFileName, Label_1);
strcat(Full_PNGFileName, ".png");
}
if(f == 1){
strcpy(Full_RootFileName, RootFileName);
strcat(Full_RootFileName, "_");
strcat(Full_RootFileName, Label_2);
strcat(Full_RootFileName, ".root");
strcpy(Full_PNGFileName, PNGFileName);
strcat(Full_PNGFileName, "_");
strcat(Full_PNGFileName, Label_2);
strcat(Full_PNGFileName, ".png");
}
if(f == 2){
strcpy(Full_RootFileName, RootFileName);
strcat(Full_RootFileName, "_");
strcat(Full_RootFileName, Label_3);
strcat(Full_RootFileName, ".root");
strcpy(Full_PNGFileName, PNGFileName);
strcat(Full_PNGFileName, "_");
strcat(Full_PNGFileName, Label_3);
strcat(Full_PNGFileName, ".png");
}
if(f == 3){
strcpy(Full_RootFileName, RootFileName);
strcat(Full_RootFileName, "_");
strcat(Full_RootFileName, Label_4);
strcat(Full_RootFileName, ".root");
strcpy(Full_PNGFileName, PNGFileName);
strcat(Full_PNGFileName, "_");
strcat(Full_PNGFileName, Label_4);
strcat(Full_PNGFileName, ".png");
}
//Plot creation//
TCanvas *c1 = new TCanvas("c1","Canvas 1",200,10,900,700);
c1->Divide(1,2);
c1->SetFillColor(10);
c1->SetGrid();
c1->GetFrame()->SetFillColor(10);
c1->GetFrame()->SetBorderSize(12);
c1->Range(0,0,1,1);
gStyle->SetOptStat(0);
c1->cd(1);
TH1F *hr1 = c1_1->DrawFrame(xLowerLimit_1,yLowerLimit_1,xUpperLimit_1,yUpperLimit_1);
hr1->SetTitle(PlotTitle_1);
hr1->SetXTitle(xTitle_1);
hr1->SetYTitle(yTitle_1);
//1.5vF//
TGraphErrors *gr6 = new TGraphErrors(NumOfLines,Teff,freq_BG1,0,0);
gr6->SetMarkerColor(kBlack);
gr6->SetMarkerSize(0.5);
gr6->SetMarkerStyle(7);
gr6->SetFillColor(kWhite);
gr6->SetName("gr6");
gr6->Draw("P");
//2.0vF//
TGraphErrors *gr7 = new TGraphErrors(NumOfLines,Teff,freq_BG2,0,0);
gr7->SetMarkerColor(kBlack);
gr7->SetMarkerSize(0.5);
gr7->SetMarkerStyle(7);
gr7->SetFillColor(kWhite);
gr7->SetName("gr7");
gr7->Draw("PSAME");
//2.5vF//
TGraphErrors *gr8 = new TGraphErrors(NumOfLines,Teff,freq_BG3,0,0);
gr8->SetMarkerColor(kBlack);
gr8->SetMarkerSize(0.5);
gr8->SetMarkerStyle(7);
gr8->SetName("gr8");
gr8->Draw("PSAME");
//3.5vF//
TGraphErrors *gr9 = new TGraphErrors(NumOfLines,Teff,freq_BG4,0,0);
gr9->SetMarkerColor(kBlack);
gr9->SetMarkerSize(0.5);
gr9->SetMarkerStyle(7);
gr9->SetFillColor(kWhite);
gr9->SetName("gr9");
gr9->Draw("PSAME");
//4.5vF//
TGraphErrors *gr10 = new TGraphErrors(NumOfLines,Teff,freq_BG5,0,0);
gr10->SetMarkerColor(kBlack);
gr10->SetMarkerSize(0.5);
gr10->SetMarkerStyle(7);
gr10->SetFillColor(kWhite);
gr10->SetName("gr10");
gr10->Draw("PSAME");
//FU//
TGraphErrors *gr1 = new TGraphErrors(NumOfLines,Teff,freq_FU,0,0);
gr1->SetMarkerColor(kRed);
gr1->SetMarkerSize(0.5);
gr1->SetMarkerStyle(20);
gr1->SetFillColor(kWhite);
gr1->SetName("gr1");
gr1->Draw("P");
//FO//
TGraphErrors *gr2 = new TGraphErrors(NumOfLines,Teff,freq_FO,0,0);
gr2->SetMarkerColor(kGreen);
gr2->SetMarkerSize(0.5);
gr2->SetMarkerStyle(24);
gr2->SetFillColor(kWhite);
gr2->SetName("gr2");
gr2->Draw("PSAME");
//2O//
TGraphErrors *gr3 = new TGraphErrors(NumOfLines,Teff,freq_2O,0,0);
gr3->SetMarkerColor(kBlue);
gr3->SetMarkerSize(0.5);
gr3->SetMarkerStyle(21);
gr3->SetFillColor(kWhite);
gr3->SetName("gr3");
gr3->Draw("PSAME");
//ThirdO//
TGraphErrors *gr4 = new TGraphErrors(NumOfLines,Teff,freq_ThirdO,0,0);
gr4->SetMarkerColor(kMagenta);
gr4->SetMarkerSize(0.5);
gr4->SetMarkerStyle(25);
gr4->SetFillColor(kWhite);
gr4->SetName("gr4");
gr4->Draw("PSAME");
//ForthO//
TGraphErrors *gr5 = new TGraphErrors(NumOfLines,Teff,freq_ForthO,0,0);
gr5->SetMarkerColor(kCyan);
gr5->SetMarkerSize(0.5);
gr5->SetMarkerStyle(22);
gr5->SetFillColor(kWhite);
gr5->SetName("gr5");
gr5->Draw("PSAME");
TLegend *leg = new TLegend(0.1,0.7,0.28,0.9);
leg->AddEntry("gr1","F","p");
leg->AddEntry("gr2","1O","p");
leg->AddEntry("gr3","2O","p");
leg->AddEntry("gr4","3O","p");
leg->AddEntry("gr5","4O","p");
leg->Draw();
c1->cd(2);
TH1F *hr2 = c1_2->DrawFrame(xLowerLimit_2,yLowerLimit_2,xUpperLimit_2,yUpperLimit_2);
hr2->SetTitle(PlotTitle_2);
hr2->SetXTitle(xTitle_2);
hr2->SetYTitle(yTitle_2);
TGraphErrors *gr11 = new TGraphErrors(NumOfLines,Teff,growth_FU,0,0);
gr11->SetMarkerColor(kRed);
gr11->SetMarkerSize(0.5);
gr11->SetMarkerStyle(20);
gr11->SetName("gr11");
gr11->Draw("P");
TGraphErrors *gr12 = new TGraphErrors(NumOfLines,Teff,growth_FO,0,0);
gr12->SetMarkerColor(kGreen);
gr12->SetMarkerSize(0.5);
gr12->SetMarkerStyle(24);
gr12->SetName("gr12");
gr12->Draw("PSAME");
TGraphErrors *gr13 = new TGraphErrors(NumOfLines,Teff,growth_2O,0,0);
gr13->SetMarkerColor(kBlue);
gr13->SetMarkerSize(0.5);
gr13->SetMarkerStyle(21);
gr13->SetName("gr13");
gr13->Draw("PSAME");
TGraphErrors *gr14 = new TGraphErrors(NumOfLines,Teff,growth_ThirdO,0,0);
gr14->SetMarkerColor(kMagenta);
gr14->SetMarkerSize(0.5);
gr14->SetMarkerStyle(25);
gr14->SetName("gr14");
gr14->Draw("PSAME");
TGraphErrors *gr15 = new TGraphErrors(NumOfLines,Teff,growth_ForthO,0,0);
gr15->SetMarkerColor(kCyan);
gr15->SetMarkerSize(0.5);
gr15->SetMarkerStyle(22);
gr15->SetName("gr15");
gr15->Draw("PSAME");
if(SavePlotAsPNG){
c1->SaveAs(Full_PNGFileName);
}
if(SavePlotAsRootFile){
TFile outfile1(Full_RootFileName, "RECREATE");
c1->Write();
outfile1.Close();
}
}
return 0;
}