Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EnergyCalibFit.m
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file EnergyCalibFit.m
1 
2 clear all
3 close all
4 
5 %%
6 
7 % const double Es[] =
8 % { 2, 3 , 4, 8, 12 , 16 };
9 % const double runs[] =
10 % { 2042,2040, 2039, 2038, 2067, 2063 };
11 
13  2, 3 , 4, 8, 12 , 16
14  2042,2040, 2039, 2038, 2067, 2063
15 ];
17 
18 sim_const = 2.409/100;
19 sim_stat = 11.77/100;
20 Ndata = 20;
21 
22 %% Readin
23 % global DataSet
24 DataSet =struct('run',{},'E',{},'DE',{},'data',{});
25 
26 for i = 1:N_Runs
27 
28  DataSet(i).run = RunList(2,i);
29  DataSet(i).E = RunList(1,i);
30  DataSet(i).DE = sqrt( sim_const.^2 + sim_stat.^2./DataSet(i).E ) * DataSet(i).E;
31 
32  filename = sprintf('beam_0000%d-0000_DSTReader.root_DrawPrototype2EMCalTower_Prototype2_DSTReader.dat', DataSet(i).run );
33 
34  fprintf('processing %s\n', filename);
35 
36  data = textread(filename);
37  data = data(:,1:Ndata);
38 
39  total_E = sum(data, 2);
40  data = data(total_E>(DataSet(i).E * 0.5) & total_E<(DataSet(i).E * 1.5) , :);
41 
42  DataSet(i).data = data;
43 
44 end
45 
46 %%
47 DrawDataSet(DataSet, ones(1, Ndata), 'Inputs');
48 
49 SaveCanvas(['EnergyCalibFIt'],gcf);
50 %%
51 
52 disp(object_function(ones(1, Ndata + N_Runs -1),DataSet, 10));
53 disp(object_function(ones(1, Ndata + N_Runs -1),DataSet, 2));
54 disp(object_function(ones(1, Ndata + N_Runs -1),DataSet, 1));
55 
56 %%
57 
58 options = optimset('Display','iter','TolFun',10000, 'MaxFunEvals', 100000,'MaxIter',100000,'PlotFcns',@optimplotfval );
59 
60 x = fminsearch(@(x) object_function(x,DataSet, 10),ones(1, Ndata + N_Runs -1),...
61  options);
62 
63 %%
64 options = optimset('Display','iter','TolFun',1, 'MaxFunEvals', 100000,'MaxIter',100000,'PlotFcns',@optimplotfval );
65 
66 x = fminsearch(@(x) object_function(x,DataSet,3),x,...
67  options);
68 
69 %%
70 options = optimset('Display','iter','TolFun',1e-4, 'MaxFunEvals', 100000,'MaxIter',100000,'PlotFcns',@optimplotfval );
71 
72 x = fminsearch(@(x) object_function(x,DataSet,2),x,...
73  options);
74 
75 %%
76 
77 calib_const = abs(x(1:Ndata));
78 
79 DrawDataSet(DataSet,calib_const,'Optimized');
80 SaveCanvas(['EnergyCalibFIt'],gcf);
81 
82 %% Save out
83 
84 for i = 1:N_Runs
85  filename = sprintf('calirbated_%d.dat', DataSet(i).run );
86 
87 
88  total_E = sum( DataSet(i).data, 2) ;
90 
91  dlmwrite(filename,[total_E calib_total_E]);
92 end
93 
94 save('fit.mat');
95 % save('goodfit.mat');