forked from hszumila/cafe_optics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot_ytar_cuts.C
202 lines (197 loc) · 6.04 KB
/
plot_ytar_cuts.C
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
#include <TString.h>
#include <TLegend.h>
#include <TFile.h>
#include <TNtuple.h>
#include <TH1.h>
#include <TH2.h>
#include <TCanvas.h>
#include <TStyle.h>
#include <TROOT.h>
#include <TCutG.h>
#include <TMath.h>
#include <TProfile.h>
#include <TObjArray.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <iomanip>
#include <fstream>
using namespace std;
void plot_ytar_cuts(Int_t nrun=1814,Int_t FileID=-2) {
gROOT->Reset();
gStyle->SetOptStat(0);
gStyle->SetOptFit(11);
gStyle->SetTitleOffset(1.,"Y");
gStyle->SetTitleOffset(.7,"X");
gStyle->SetLabelSize(0.04,"XY");
gStyle->SetTitleSize(0.06,"XY");
gStyle->SetPadLeftMargin(0.14);
const Int_t Number=3;
Double_t Red[Number] = { 1.0,0.0,0.0};
Double_t Blue[Number] = { 1.0,0.0,1.0};
Double_t Green[Number] = { 0.0,1.0,0.0};
Double_t Len[Number] = { 0.0,.5,1.0};
Int_t nb=50;
TColor::CreateGradientColorTable(Number,Len,Red,Green,Blue,nb);
// Get info for that optics run
TString OpticsFile = "list_of_optics_run.dat";
ifstream file_optics(OpticsFile.Data());
TString opticsline;
TString OpticsID="";
Int_t RunNum=0.;
Double_t CentAngle=0.;
Int_t SieveFlag=1;
Int_t NumFoil=0;
TString temp;
//
vector <Double_t> ztar_foil;
Int_t ndelcut;
vector<Double_t > delcut;
vector<Double_t > delwidth;
if (file_optics.is_open()) {
//
cout << " Open file = " << OpticsFile << endl;
while (RunNum!=nrun ) {
temp.ReadToDelim(file_optics,',');
cout << temp << endl;
if (temp.Atoi() == nrun) {
RunNum = temp.Atoi();
} else {
temp.ReadLine(file_optics);
}
}
if (RunNum==nrun) {
temp.ReadToDelim(file_optics,',');
OpticsID = temp;
temp.ReadToDelim(file_optics,',');
CentAngle = temp.Atof();
temp.ReadToDelim(file_optics,',');
NumFoil = temp.Atoi();
temp.ReadToDelim(file_optics,',');
SieveFlag = temp.Atoi();
temp.ReadToDelim(file_optics);
ndelcut = temp.Atoi();
for (Int_t nf=0;nf<NumFoil-1;nf++) {
temp.ReadToDelim(file_optics,',');
ztar_foil.push_back(temp.Atof());
}
temp.ReadToDelim(file_optics);
ztar_foil.push_back(temp.Atof());
for (Int_t nd=0;nd<ndelcut-1;nd++) {
temp.ReadToDelim(file_optics,',');
delcut.push_back(temp.Atof());
}
temp.ReadToDelim(file_optics);
delcut.push_back(temp.Atof());
for (Int_t nw=0;nw<ndelcut-1;nw++) {
temp.ReadToDelim(file_optics,',');
delwidth.push_back(temp.Atof());
}
temp.ReadToDelim(file_optics);
delwidth.push_back(temp.Atof());
}
} else {
cout << " No file = " << OpticsFile << endl;
}
cout << RunNum << " " << OpticsID << " " << CentAngle << " " << NumFoil << " " << SieveFlag << endl;
if (NumFoil==0) return;
//
TString inputroot;
TFile *fhistroot;
TString outputpdf;
inputroot=Form("hist/Optics_%s_%d_hist_v2.root",OpticsID.Data(),FileID);
outputpdf = Form("plots/Optics_%s_%d_ytar_cuts",OpticsID.Data(),FileID);
cout << " infile root = " << inputroot << endl;
fhistroot = new TFile(inputroot);
//
TH2F *fhist;
fhist = (TH2F*)fhistroot->Get("hYtarDelta");
TString YtarDeltaCutFile;
YtarDeltaCutFile=Form("cuts/ytar_delta_%s_%d_cut.root",OpticsID.Data(),FileID);
TFile *fYtarDeltaCut;
vector <TCutG*> ytar_delta_cut;
fYtarDeltaCut = new TFile(YtarDeltaCutFile);
cout << "Ytar Cut file = " << YtarDeltaCutFile << endl;
for (Int_t nc=0;nc<NumFoil;nc++) {
fYtarDeltaCut->cd();
TCutG* tempcut = (TCutG*)gROOT->FindObject(Form("delta_vs_ytar_cut_foil%d",nc));
if (tempcut) {
Int_t npt = tempcut->GetN();
cout << "hYtarDelta_cut = " << nc << " npts = " << npt << endl;
ytar_delta_cut.push_back(tempcut);
} else {
cout << " No hYtarDelta_cut = " << nc << endl;
}
}
//
vector<vector<TH2F*> > hYsXs_DelCut;
vector<TH2F*> temp2d;
TH2F* th;
for (Int_t nc=0;nc<NumFoil;nc++) {
for (Int_t nd=0;nd<ndelcut;nd++) {
th = (TH2F*)fhistroot->Get(Form("hYsXs_Foil_%d_DelCut_%d",nc,nd));
if (!th) {
cout << " no hist : "<< Form("hYsXs_Foil_%d_DelCut_%d",nc,nd) << endl;
return;
}
temp2d.push_back(th);
}
hYsXs_DelCut.push_back(temp2d);
temp2d.clear();
}
//
TLine* xs_line[11];
TText* xs_text[11];
TLine* ys_line[11];
TText* ys_text[11];
for (Int_t nys=0;nys<11;nys++) {
Double_t pos=nys*2.5-2.5*5;
Double_t ypos=nys*1.64-1.64*5;
xs_line[nys]= new TLine(-12.,pos,12.,pos);
xs_text[nys]= new TText(-14,pos,Form("%d",nys));
xs_text[nys]->SetTextColor(2);
xs_line[nys]->SetLineColor(2);
xs_line[nys]->SetLineWidth(1);
ys_line[nys]= new TLine(ypos,-15.,ypos,15);
ys_text[nys]= new TText(ypos,-17,Form("%d",nys));
ys_text[nys]->SetTextColor(2);
ys_line[nys]->SetLineColor(2);
ys_line[nys]->SetLineWidth(1);
}
/*
TCanvas* can2d[NumFoil][ndelcut];
for (Int_t nc=0;nc<NumFoil;nc++) {
for (Int_t nd=0;nd<ndelcut;nd++) {
can2d[nc][nd] = new TCanvas(Form("Can2d_%d_%d",nc,nd),Form("Foil %d Del %d",nc,nd), 700,700);
can2d[nc][nd]->Divide(1,1);
can2d[nc][nd]->cd(1);
hYsXs_DelCut[nc][nd]->Draw("colz");
hYsXs_DelCut[nc][nd]->SetMinimum(1);
for (Int_t nys=0;nys<11;nys++) { xs_line[nys]->Draw();}
for (Int_t nys=0;nys<11;nys++) { xs_text[nys]->Draw();}
for (Int_t nys=0;nys<11;nys++) { ys_line[nys]->Draw();}
for (Int_t nys=0;nys<11;nys++) { ys_text[nys]->Draw();}
TString end = ".pdf";
if (nc==0 && nd==0) end=".pdf(";
if (nc==NumFoil-1&& nd==ndelcut-1) end=".pdf)";
can2d[nc][nd]->Print(outputpdf+end);
}}
*/
//
TCanvas *canCut = new TCanvas("canCut","canCut",700,700);
canCut->Divide(1,1);
canCut->cd(1);
fhist->Draw("colz");
gPad->SetLogz(); //optional
//fhist->SetMinimum(100);
TCutG*t;
for (Int_t nf=0;nf<NumFoil;nf++) {
if (ytar_delta_cut[nf]) ytar_delta_cut[nf]->Draw("same");
if (ytar_delta_cut[nf]) ytar_delta_cut[nf]->SetLineColor(1);
}
outputpdf = Form("plots/Optics_%s_%d_ytar_cuts",OpticsID.Data(),FileID);
canCut->Print(outputpdf+".pdf");
//
}