13 %
FileID = {
'Rot45',
'THP',
'UIUC18',
'UpTilt5',
'ShowerDepth'};
14 FileID = {
'3rd_positionscan'};
28 FileList{
i} = [DataFolder FileList{i} '.lst_EMCalCalib.root.dat'];
38 DataSet =
struct(
'FileID',{},
'E',{},
'DE',{},
'data',{},
'accept',{});
69 DataSet(N_Runs).data = DataSet(N_Runs).data(total_E > DataSet(N_Runs).E/2, :);
70 DataSet(N_Runs).accept = ones(size(data, 1), 1);
77 DrawDataSet(DataSet, InitConst, 'Inputs
');
79 SaveCanvas([DataFolder 'EnergyCalibFIt
'],gcf);
92 total_E = ones(size(DataSet(i).data)) .*DataSet(i).E;
93 Fraction = DataSet(i).data ./ total_E;
94 MeanFraction = mean(Fraction, 1);
95 MeanFraction = reshape(MeanFraction, 8, 8);
97 SumFraction = [SumFraction; Fraction];
99 imagesc(0:7, 0:7, MeanFraction);
101 set(gca,'YDir
','normal
')
103 title(sprintf('%
s,
E = %.1
f GeV', DataSet(i).FileID, DataSet(i).E));
108 SaveCanvas([DataFolder 'EnergyCalibFIt
'],gcf);
116 MeanFraction = mean(SumFraction, 1);
117 MeanFraction = reshape(MeanFraction, 8, 8);
119 imagesc(0:7, 0:7, MeanFraction);
121 set(gca,'YDir
','normal
');
123 title(sprintf('Sum all
data'));
129 hist(reshape(MeanFraction,size(MeanFraction,1) * size(MeanFraction,2),1),100);
135 low_tower_IDs =reshape( MeanFraction<0.01, 1, Ndata);
136 % low_tower_IDs =reshape( MeanFraction<0.0001, 1, Ndata);
138 imagesc(0:7, 0:7, reshape(low_tower_IDs, 8, 8));
140 set(gca,'YDir
','normal
');
142 title(sprintf('Low hit towers
'));
146 SaveCanvas([DataFolder 'EnergyCalibFIt
'],gcf);
151 % InitConst_RunScale = [InitConst ones(1, N_Runs)];
152 InitConst_RunScale = [InitConst ];
153 % InitConst_RunScale = [InitConst ];
155 data_selection(InitConst_RunScale,10);
156 disp(object_function(InitConst_RunScale));
158 % disp(object_function(InitConst_RunScale, 2));
159 % disp(object_function(InitConst_RunScale, 1));
163 x = InitConst_RunScale;
165 options = optimset('Display
','iter
','TolX
',1, 'MaxFunEvals
', 100000,'MaxIter
',40000,'PlotFcns
',@optimplotfval );
168 disp(object_function(x));
170 x = fminsearch(@(x) object_function(x), x,...
174 options = optimset('Display
','iter
','TolX
',1, 'MaxFunEvals
', 100000,'MaxIter
',40000,'PlotFcns
',@optimplotfval );
177 disp(object_function(x));
179 x = fminsearch(@(x) object_function(x), x,...
184 options = optimset('Display
','iter
','TolX
',1, 'MaxFunEvals
', 100000,'MaxIter
',40000,'PlotFcns
',@optimplotfval );
187 disp(object_function(x));
189 x = fminsearch(@(x) object_function(x), x,...
197 calib_const = x(1:Ndata);
198 % E_scale = x((Ndata+1):(Ndata + N_Runs));
199 E_scale = ones(N_Runs);
208 title(sprintf('Calibration constant
'));
209 xlabel('Col * 8 + Row
');
210 ylabel('Calibration New /
Old');
214 imagesc(0:7, 0:7, reshape(calib_const, 8, 8));
216 set(gca,'YDir
','normal
')
218 title(sprintf('Calibration constant, New /
Old'));
226 title(sprintf('Energy scale constant,
mean = %.2
f', mean(E_scale)));
228 ylabel('Energy scale New /
Old');
229 set(gca,'YLim
',[0.5,1.5])
233 SaveCanvas([DataFolder 'EnergyCalibFIt
'],gcf);
240 % 10.19 8.47 8.96 9.77
241 % 9.74 9.96 10.00 9.87
242 % 9.25 9.83 9.32 10.10
243 % 9.59 9.39 10.06 9.62
245 % 9.43 9.34 9.39 9.55
250 % ModuleDensity = ModuleDensity(8:-1:1,:);
252 % ModuleDensity = [ModuleDensity(:,1) ModuleDensity(:,1) ModuleDensity(:,2) ModuleDensity(:,2) ModuleDensity(:,3) ModuleDensity(:,3) ModuleDensity(:,4) ModuleDensity(:,4)];
255 % imagesc(0:7, 0:7,ModuleDensity);
257 % set(gca,'YDir
','normal
')
259 % title(sprintf('Module Density (
g/
cm^3)
'));
260 % xlabel('Column ID
');
266 % imagesc(0:7, 0:7, reshape(calib_const, 8, 8));
268 % set(gca,'YDir
','normal
');
270 % title(sprintf('Calibration constant, New /
Old'));
271 % xlabel('Column ID
');
277 % [calib_const_col, calib_const_row]= meshgrid(0:7,0:7);
279 % calib_const_col = reshape(calib_const_col,1,64);
280 % calib_const_row = reshape(calib_const_row,1,64);
281 % % IDs = ~low_tower_IDs;
282 % IDs = (calib_const_col >=3 & calib_const_col<=5 & calib_const_row>=4 & calib_const_row<=6);
284 % dens = reshape(ModuleDensity,1, 8* 8);
287 % plot(calib_const(IDs),dens, 'o
');
288 % title(sprintf('THP 3x3, Calibration adjustment VS density
'));
289 % xlabel('Calibration constant, New /
Old');
290 % ylabel('Module Density
');
295 % IDs = ~low_tower_IDs;
296 % % IDs = (calib_const_col >=3 & calib_const_col<=5 & calib_const_row>=4 & calib_const_row<=6);
298 % dens = reshape(ModuleDensity,1, 8* 8);
301 % plot(calib_const(IDs),dens, 'o
');
302 % title(sprintf('All calibrated modules, Calibration adjustment VS density
'));
303 % xlabel('Calibration constant, New /
Old');
304 % ylabel('Module Density
');
306 % SaveCanvas([DataFolder 'EnergyCalibFIt
'],gcf);
312 DrawDataSet(DataSet,calib_const,'Optimized
');
313 SaveCanvas([DataFolder 'EnergyCalibFIt
'],gcf);
318 % filename = sprintf('%
s/calirbated_%d_%.0
f.dat
',DataFolder, DataSet(i).FileID, DataSet(i).E );
321 % total_E = sum( DataSet(i).data*InitConst', 2) ;
324 % dlmwrite(filename,[total_E calib_total_E]);
327 save([DataFolder 'fit.mat
']);
328 % save('goodfit.mat
');
332 [calib_const_col, calib_const_row]= meshgrid(0:7,0:7);
334 A = [reshape(calib_const_col,1,64); reshape(calib_const_row,1,64); calib_const];
336 fileID = fopen([DataFolder 'ShowerCalibFit_CablibConst.dat
'],'w
');
337 % fprintf(fileID,'%d - %d \
n',);
339 fprintf(fileID,'%d\
t%d\
t%
f\
n',A);