-
Notifications
You must be signed in to change notification settings - Fork 1
/
fit_opt_matrix_v2.C
603 lines (562 loc) · 20.7 KB
/
fit_opt_matrix_v2.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
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
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <vector>
#include <TFile.h>
#include <TNtuple.h>
#include <TH1.h>
#include <TH2.h>
#include <TCanvas.h>
#include <TRandom3.h>
#include <TStyle.h>
#include <TROOT.h>
#include <TMath.h>
#include <TBox.h>
#include <TPolyLine.h>
#include <TLegend.h>
#include <TMatrixD.h>
#include <TVectorD.h>
#include <TDecompSVD.h>
void fit_opt_matrix_v2() {
Double_t xMP = -0.126;
Int_t nSettings = 6;
Int_t FileID=-1;
Int_t maxFoils=3;
Int_t maxDel=5;
vector<int> runTot;
runTot.push_back(16023);
runTot.push_back(16024);
runTot.push_back(16029);
runTot.push_back(16031);
runTot.push_back(16033);
runTot.push_back(16034);
gROOT->Reset();
gStyle->SetOptStat(0);
gStyle->SetTitleOffset(1.,"Y");
gStyle->SetTitleOffset(.7,"X");
gStyle->SetLabelSize(0.04,"XY");
gStyle->SetTitleSize(0.05,"XY");
gStyle->SetPadLeftMargin(0.17);
//
string newcoeffsfilename="newfit_cafe.dat";
string oldcoeffsfilename="hsv_fit_global_no0.dat";
int nfit=0,npar,nfit_max=74577,npar_final=0,max_order=6,norder;
Int_t MaxPerBin=200;
Int_t MaxZtarPerBin=32000;
//
TH1F *hDelta = new TH1F("hDelta","Delta ",20,-10.,30.);
TH1F *hDeltarecon = new TH1F("hDeltarecon","Delta Recon % ",40,-10,30);
TH1F *hDeltadiff = new TH1F("hDeltadiff","Delta Diff % ",40,-1,1);
TH1F *hDeltanew = new TH1F("hDeltanew","Delta New Recon % ",40,-10,30);
TH1F *hDeltanewdiff = new TH1F("hDeltanewdiff","Delta New Diff % ",40,-1,1);
TH1F *hytar = new TH1F("hytar","ytar (cm)",70,-7.,7.);
TH1F *hytarrecon = new TH1F("hytarrecon","ytar recon(cm)",70,-7.,7.);
TH1F *hytarnew = new TH1F("hytarnew","ytar new(cm)",70,-7.,7.);
TH1F *hytardiff = new TH1F("hytardiff","ytar diff(cm)",70,-5.,5.);
TH1F *hytarnewdiff = new TH1F("hytarnewdiff","ytar new diff(cm)",70,-5.,5.);
TH1F *hxptar = new TH1F("hxptar","xptar ",100,-.12,.12);
TH1F *hxptarrecon = new TH1F("hxptarrecon","xptar recon",100,-.12,.12);
TH1F *hxptardiff = new TH1F("hxptardiff","xptar diff (mr)",100,-15,15);
TH1F *hxptarnew = new TH1F("hxptarnew","xptar new recon",100,-.12,.12);
TH1F *hxptarnewdiff = new TH1F("hxptarnewdiff","xptar new diff (mr)",100,-15,15);
TH1F *hyptar = new TH1F("hyptar","yptar ",100,-.1,.1);
TH1F *hyptarrecon = new TH1F("hyptarrecon","yptar recon ",100,-.1,.1);
TH1F *hyptardiff = new TH1F("hyptardiff","yptar diff (mr) ",100,-10,10);
TH1F *hyptarnew = new TH1F("hyptarnew","yptar new recon ",100,-.1,.1);
TH1F *hyptarnewdiff = new TH1F("hyptarnewdiff","yptar new diff (mr) ",100,-10,10);
//
ifstream oldcoeffsfile(oldcoeffsfilename.c_str());
ofstream newcoeffsfile(newcoeffsfilename.c_str());
vector<double> xptarcoeffs_old;
vector<double> yptarcoeffs_old;
vector<double> ytarcoeffs_old;
vector<double> deltacoeffs_old;
vector<int> xfpexpon_old;
vector<int> xpfpexpon_old;
vector<int> yfpexpon_old;
vector<int> ypfpexpon_old;
vector<int> xtarexpon_old;
vector<double> xptarcoeffs_fit;
vector<double> yptarcoeffs_fit;
vector<double> ytarcoeffs_fit;
vector<double> deltacoeffs_fit;
vector<int> xfpexpon_fit;
vector<int> xpfpexpon_fit;
vector<int> yfpexpon_fit;
vector<int> ypfpexpon_fit;
vector<int> xtarexpon_fit;
vector<double> xptarcoeffs_xtar;
vector<double> yptarcoeffs_xtar;
vector<double> ytarcoeffs_xtar;
vector<double> deltacoeffs_xtar;
vector<int> xfpexpon_xtar;
vector<int> xpfpexpon_xtar;
vector<int> yfpexpon_xtar;
vector<int> ypfpexpon_xtar;
vector<int> xtarexpon_xtar;
vector<double> xtartrue,ytartrue,xptartrue,yptartrue,deltatrue,angle,ztartrue;
vector<double> xfptrue,yfptrue,xpfptrue,ypfptrue;
TString currentline;
int num_recon_terms_old;
int num_recon_terms_fit;
int num_recon_terms_xtar;
num_recon_terms_old = 0;
num_recon_terms_fit = 0;
num_recon_terms_xtar = 0;
// add zero order term to fit
xptarcoeffs_fit.push_back(0.0);
ytarcoeffs_fit.push_back(0.0);
yptarcoeffs_fit.push_back(0.0);
deltacoeffs_fit.push_back(0.0);
xfpexpon_fit.push_back(0);
xpfpexpon_fit.push_back(0);
yfpexpon_fit.push_back(0);
ypfpexpon_fit.push_back(0);
xtarexpon_fit.push_back(0);
num_recon_terms_fit = 1;
//
while( currentline.ReadLine(oldcoeffsfile,kFALSE) && !currentline.BeginsWith(" ----") ){
TString sc1(currentline(1,16));
TString sc2(currentline(17,16));
TString sc3(currentline(33,16));
TString sc4(currentline(49,16));
xptarcoeffs_old.push_back(sc1.Atof());
ytarcoeffs_old.push_back(sc2.Atof());
yptarcoeffs_old.push_back(sc3.Atof());
deltacoeffs_old.push_back(sc4.Atof());
int expontemp[5];
for(int expon=0; expon<5; expon++){
TString stemp(currentline(66+expon,1));
expontemp[expon] = stemp.Atoi();
}
xfpexpon_old.push_back(expontemp[0]);
xpfpexpon_old.push_back(expontemp[1]);
yfpexpon_old.push_back(expontemp[2]);
ypfpexpon_old.push_back(expontemp[3]);
xtarexpon_old.push_back(expontemp[4]);
num_recon_terms_old++;
norder= expontemp[0]+expontemp[1]+expontemp[2]+expontemp[3]+expontemp[4];
if (expontemp[4]==0) {
xptarcoeffs_fit.push_back(sc1.Atof());
ytarcoeffs_fit.push_back(sc2.Atof());
yptarcoeffs_fit.push_back(sc3.Atof());
deltacoeffs_fit.push_back(sc4.Atof());
xfpexpon_fit.push_back(expontemp[0]);
xpfpexpon_fit.push_back(expontemp[1]);
yfpexpon_fit.push_back(expontemp[2]);
ypfpexpon_fit.push_back(expontemp[3]);
xtarexpon_fit.push_back(expontemp[4]);
cout << num_recon_terms_fit << " " << xptarcoeffs_fit[num_recon_terms_fit] << " " << ytarcoeffs_fit[num_recon_terms_fit] << " " << yptarcoeffs_fit[num_recon_terms_fit] << " " << deltacoeffs_fit[num_recon_terms_fit] << " " << xfpexpon_fit[num_recon_terms_fit] << " " << xpfpexpon_fit[num_recon_terms_fit] << " " << yfpexpon_fit[num_recon_terms_fit] << " " << ypfpexpon_fit[num_recon_terms_fit] << " " << xtarexpon_fit[num_recon_terms_fit] << " " << endl;
num_recon_terms_fit++;
} else {
xptarcoeffs_xtar.push_back(sc1.Atof());
ytarcoeffs_xtar.push_back(sc2.Atof());
yptarcoeffs_xtar.push_back(sc3.Atof());
deltacoeffs_xtar.push_back(sc4.Atof());
xfpexpon_xtar.push_back(expontemp[0]);
xpfpexpon_xtar.push_back(expontemp[1]);
yfpexpon_xtar.push_back(expontemp[2]);
ypfpexpon_xtar.push_back(expontemp[3]);
xtarexpon_xtar.push_back(expontemp[4]);
num_recon_terms_xtar++;
}
}
cout << "num recon terms in OLD matrix = " << num_recon_terms_old << endl;
cout << "num recon terms in fit matrix = " << num_recon_terms_fit << endl;
cout << "num recon terms in xtar matrix = " << num_recon_terms_xtar << endl;
npar= num_recon_terms_fit ;
//
TVectorD b_ytar(npar);
TVectorD b_yptar(npar);
TVectorD b_xptar(npar);
TVectorD b_delta(npar);
TMatrixD lambda(npar,nfit_max);
TMatrixD Ay(npar,npar);
//
const Int_t nysieve=11;
vector <Double_t> ys_cent;
for (Int_t nys=0;nys<nysieve;nys++) {
Double_t pos=nys*1.64-1.64*5;
ys_cent.push_back(pos);
}
for (int iSetting=0; iSetting<nSettings; iSetting++){
// Get info for that optics run
Int_t nrun = runTot[iSetting];
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 nfoils=0;
TString temp;
//
vector <Double_t> ztar_foil;
Int_t ndelcut=-1;
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,',');
nfoils = temp.Atoi();
temp.ReadToDelim(file_optics,',');
SieveFlag = temp.Atoi();
temp.ReadToDelim(file_optics);
ndelcut = temp.Atoi();
for (Int_t nf=0;nf<nfoils-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 << " " << nfoils << " " << SieveFlag << endl;
TString inputroot;
inputroot = Form("hist/Optics_%s_%d_fit_tree.root",OpticsID.Data(),FileID);
cout << " INfile = " << inputroot << endl;
TFile *fsimc = new TFile(inputroot);
TTree *FitTree = (TTree*)fsimc->Get("TFit");
//Declaration of leaves types
Double_t ys,xtar,xptar,yptar,ytar,delta,xptarT,yptarT,ytarT,ztarT,xtarT;
Double_t xfp,xpfp,yfp,ypfp,ysieveT,ysieve;
FitTree->SetBranchAddress("ys",&ysieve);
FitTree->SetBranchAddress("ysT",&ysieveT);
FitTree->SetBranchAddress("xtar",&xtar);
FitTree->SetBranchAddress("xtarT",&xtarT);
FitTree->SetBranchAddress("xptar",&xptar);
FitTree->SetBranchAddress("yptar",&yptar);
FitTree->SetBranchAddress("ytar",&ytar);
FitTree->SetBranchAddress("xptarT",&xptarT);
FitTree->SetBranchAddress("yptarT",&yptarT);
FitTree->SetBranchAddress("ytarT",&ytarT);
FitTree->SetBranchAddress("ztarT",&ztarT);
FitTree->SetBranchAddress("delta",&delta);
FitTree->SetBranchAddress("xpfp",&xpfp);
FitTree->SetBranchAddress("ypfp",&ypfp);
FitTree->SetBranchAddress("xfp",&xfp);
FitTree->SetBranchAddress("yfp",&yfp);
//
vector<Int_t > Ztar_Cnts;
vector<vector<vector<Int_t> > > Ztar_Ys_Delta_Cnts;
vector<Int_t> Max_Per_Run_Per_Foil;
Ztar_Cnts.resize(maxFoils);
Ztar_Ys_Delta_Cnts.resize(maxFoils);
Max_Per_Run_Per_Foil.resize(maxFoils);
for (Int_t nf=0;nf<maxFoils;nf++) {//max foils
Ztar_Ys_Delta_Cnts[nf].resize(maxDel);//max del cut
for (Int_t nd=0;nd<maxDel;nd++) {
Ztar_Ys_Delta_Cnts[nf][nd].resize(nysieve);
}
}
//
for (Int_t nf=0;nf<maxFoils;nf++) {//max foils
Max_Per_Run_Per_Foil[nf] = 10500;//check this number?
Ztar_Cnts[nf]=0;
for (Int_t nd=0;nd<maxDel;nd++) {//max del cut
for (Int_t ny=0;ny<nysieve;ny++) {
Ztar_Ys_Delta_Cnts[nf][nd][ny]=0;
}}}
Long64_t nentries = FitTree->GetEntries();
for (int i = 0; i < nentries; i++) {
FitTree->GetEntry(i);
//
if (TMath::Abs(delta) < 100. ) {
Double_t ytartemp = 0.0,yptartemp=0.0,xptartemp=0.0,deltatemp=0.0;
Double_t etemp;
for( int icoeffold=0; icoeffold<num_recon_terms_old; icoeffold++ ){
etemp=
pow( xfp / 100.0, xfpexpon_old[icoeffold] ) *
pow( yfp / 100.0, yfpexpon_old[icoeffold] ) *
pow( xpfp, xpfpexpon_old[icoeffold] ) *
pow( ypfp, ypfpexpon_old[icoeffold] ) *
pow( xtar/100., xtarexpon_old[icoeffold] );
deltatemp += deltacoeffs_old[icoeffold] * etemp;
ytartemp += ytarcoeffs_old[icoeffold] * etemp;
yptartemp += yptarcoeffs_old[icoeffold] * etemp;
xptartemp += xptarcoeffs_old[icoeffold] *etemp;
} // for icoeffold loop
hytarrecon->Fill(ytartemp*100.);
hyptarrecon->Fill(yptartemp);
hxptarrecon->Fill(xptartemp);
if ( delta>-15. && delta<30. ) {
//
Int_t found_nf=-1;
Int_t found_nd=-1;
Int_t found_ny=-1;
Bool_t good_bin=kFALSE;
for (Int_t nf=0;nf<nfoils;nf++) {
if (abs(ztarT-ztar_foil[nf])<2.5){
found_nf=nf;
}
}
for (Int_t nd=0;nd<ndelcut;nd++) {
if (delta >=delcut[nd]-delwidth[nd] && delta <delcut[nd]+delwidth[nd]) {
found_nd=nd;
}
}
for (Int_t ny=0;ny<nysieve;ny++) {
if (abs(ysieveT-ys_cent[ny])<.5) found_ny=ny;
}
if (found_nf!=-1 &&found_nd!=-1 && found_ny!=-1) {
good_bin=kTRUE;
}
if (good_bin && nfit < nfit_max && Ztar_Ys_Delta_Cnts[found_nf][found_nd][found_ny]< MaxPerBin && Ztar_Cnts[found_nf]< MaxZtarPerBin && Ztar_Cnts[found_nf]<Max_Per_Run_Per_Foil[found_nf]) {
//reconstruct it
Double_t ytar_xtar = 0.0,yptar_xtar=0.0,xptar_xtar=0.0;
for( int icoeff_xtar=0; icoeff_xtar<num_recon_terms_xtar; icoeff_xtar++ ){
etemp=
pow( xfp / 100.0, xfpexpon_xtar[icoeff_xtar] ) *
pow( yfp / 100.0, yfpexpon_xtar[icoeff_xtar] ) *
pow( xpfp, xpfpexpon_xtar[icoeff_xtar] ) *
pow( ypfp, ypfpexpon_xtar[icoeff_xtar] ) *
pow( xtar/100., xtarexpon_xtar[icoeff_xtar] );
ytar_xtar += ytarcoeffs_xtar[icoeff_xtar] * etemp;
yptar_xtar += yptarcoeffs_xtar[icoeff_xtar] * etemp;
xptar_xtar += xptarcoeffs_xtar[icoeff_xtar] *etemp;
}
for( int icoeff_fit=0; icoeff_fit<num_recon_terms_fit; icoeff_fit++ ){
etemp=
pow( xfp / 100.0, xfpexpon_fit[icoeff_fit] ) *
pow( yfp / 100.0, yfpexpon_fit[icoeff_fit] ) *
pow( xpfp, xpfpexpon_fit[icoeff_fit] ) *
pow( ypfp, ypfpexpon_fit[icoeff_fit] ) *
pow( xtar/100., xtarexpon_fit[icoeff_fit] );
if (nfit < nfit_max ) {
lambda[icoeff_fit][nfit] = etemp;
b_xptar[icoeff_fit] += (xptarT-xptar_xtar) * etemp;
b_yptar[icoeff_fit] += (yptarT-yptar_xtar) * etemp;
b_ytar[icoeff_fit] += (ytarT-ytar_xtar*100) /100.0 * etemp;
}
} // for icoeff_fit loop
////////////////////////////////////////////////////////////
hytar->Fill(ytar);
hyptar->Fill(yptar);
hxptar->Fill(xptar);
hytardiff->Fill(ytar-ytarT);
hyptardiff->Fill(1000.*(yptar-yptarT));
hxptardiff->Fill(1000.*(xptar-xptarT));
Ztar_Cnts[found_nf]++;
Ztar_Ys_Delta_Cnts[found_nf][found_nd][found_ny]++;
nfit++;
xfptrue.push_back( xfp );
yfptrue.push_back( yfp );
xpfptrue.push_back( xpfp );
ypfptrue.push_back( ypfp );
xtartrue.push_back( xtarT );//used to be xtar
xptartrue.push_back( xptarT );
ytartrue.push_back( ytarT );
yptartrue.push_back( yptarT );
ztartrue.push_back(ztarT);
angle.push_back(CentAngle*(22./7.)/180.0);
}
}
}
}
//
for (Int_t nf=0;nf<maxFoils;nf++) cout << " counts foil " << nf << " : " << Ztar_Cnts[nf] << endl;
//
for (Int_t nf=0;nf<nfoils;nf++) {
cout << " ztar = " << ztar_foil[nf] << endl;
for (Int_t nd=0;nd<ndelcut;nd++) {
cout << " Ndelta = " << delcut[nd] << endl;
for (Int_t ny=0;ny<nysieve;ny++) {
cout << Ztar_Ys_Delta_Cnts[nf][nd][ny] << " " ;
}
cout << endl;
}}
//
//
////////////////////
//end each run loop
////////////////////
}
//
if (nfit < nfit_max) {
cout << " nfit < nfit_max, set nfit_max = " << nfit << endl;
return;
}
//
cout << " number to fit = " << nfit << " max = " << nfit_max << endl;
for(int i=0; i<npar; i++){
for(int j=0; j<npar; j++){
Ay[i][j] = 0.0;
}
}
for( int ifit=0; ifit<nfit; ifit++){
if( ifit % 5000 == 0 ) cout << ifit << endl;
for( int ipar=0; ipar<npar; ipar++){
for( int jpar=0; jpar<npar; jpar++){
Ay[ipar][jpar] += lambda[ipar][ifit] * lambda[jpar][ifit];
}
}
}
TDecompSVD Ay_svd(Ay);
bool ok;
ok = Ay_svd.Solve( b_ytar );
cout << "ytar solution ok = " << ok << endl;
//b_ytar.Print();
ok = Ay_svd.Solve( b_yptar );
cout << "yptar solution ok = " << ok << endl;
//b_yptar.Print();
ok = Ay_svd.Solve( b_xptar );
cout << "xptar solution ok = " << ok << endl;
//b_xptar.Print();
///////////////////////////////////////////////////////////////////////////////////////////////
for( int ifit=0; ifit<nfit; ifit++){
Double_t ytarnew = 0.0,yptarnew=0.0,xptarnew=0.0,deltanew=0.0;
Double_t etemp;
for( int ipar=0; ipar<npar; ipar++){
etemp=lambda[ipar][ifit];
ytarnew += b_ytar[ipar] * etemp;
yptarnew += b_yptar[ipar] * etemp;
xptarnew += b_xptar[ipar] *etemp;
}
Double_t ytar_xtar = 0.0,yptar_xtar=0.0,xptar_xtar=0.0;
for( int icoeff_xtar=0; icoeff_xtar<num_recon_terms_xtar; icoeff_xtar++ ){
etemp=
pow( xfptrue.at(ifit) / 100.0, xfpexpon_xtar[icoeff_xtar] ) *
pow( yfptrue.at(ifit) / 100.0, yfpexpon_xtar[icoeff_xtar] ) *
pow( xpfptrue.at(ifit), xpfpexpon_xtar[icoeff_xtar] ) *
pow( ypfptrue.at(ifit), ypfpexpon_xtar[icoeff_xtar] ) *
pow( xtartrue.at(ifit)/100., xtarexpon_xtar[icoeff_xtar] );
ytar_xtar += ytarcoeffs_xtar[icoeff_xtar] * etemp;
yptar_xtar += yptarcoeffs_xtar[icoeff_xtar] * etemp;
xptar_xtar += xptarcoeffs_xtar[icoeff_xtar] *etemp;
}
hytarnew->Fill((ytarnew+ytar_xtar)*100.);
hyptarnew->Fill(yptarnew+yptar_xtar);
hxptarnew->Fill(xptarnew);
hytarnewdiff->Fill((ytarnew+ytar_xtar)*100.-ytartrue.at(ifit));
hyptarnewdiff->Fill(1000*(yptarnew+yptar_xtar-yptartrue.at(ifit)));
hxptarnewdiff->Fill(1000*(xptarnew+xptar_xtar-xptartrue.at(ifit)));
}
///////////////////////////////////////////////////////////////////////////////////////////////
// write out coeff
char coeffstring[100];
Double_t tt;
cout << "writing new coeffs file" << endl;
//newcoeffsfile << "! new fit to "<<endl;//+fname << endl;
//newcoeffsfile << " ---------------------------------------------" << endl;
for( int icoeff_fit=0; icoeff_fit<num_recon_terms_fit; icoeff_fit++ ){
newcoeffsfile << " ";
// tt=xptarcoeffs_fit[icoeff_fit];
tt=b_xptar[icoeff_fit] ;
sprintf( coeffstring, "%16.9g", tt );
newcoeffsfile << coeffstring;
// newcoeffsfile << " ";
sprintf( coeffstring, "%16.9g", b_ytar[icoeff_fit] );
newcoeffsfile << coeffstring;
sprintf( coeffstring, "%16.9g", b_yptar[icoeff_fit] );
//newcoeffsfile << " ";
newcoeffsfile << coeffstring;
sprintf( coeffstring, "%16.9g", deltacoeffs_fit[icoeff_fit] );
//newcoeffsfile << " ";
newcoeffsfile << coeffstring;
newcoeffsfile << " ";
newcoeffsfile << setw(1) << setprecision(1) << xfpexpon_fit[icoeff_fit];
newcoeffsfile << setw(1) << setprecision(1) << xpfpexpon_fit[icoeff_fit];
newcoeffsfile << setw(1) << setprecision(1) << yfpexpon_fit[icoeff_fit];
newcoeffsfile << setw(1) << setprecision(1) << ypfpexpon_fit[icoeff_fit];
newcoeffsfile << setw(1) << setprecision(1) << xtarexpon_fit[icoeff_fit];
newcoeffsfile << endl;
}
//
for( int icoeff_fit=0; icoeff_fit<num_recon_terms_xtar; icoeff_fit++ ){
newcoeffsfile << " ";
// tt=xptarcoeffs_fit[icoeff_fit];
tt=xptarcoeffs_xtar[icoeff_fit] ;
sprintf( coeffstring, "%16.9g", tt );
newcoeffsfile << coeffstring;
// newcoeffsfile << " ";
sprintf( coeffstring, "%16.9g", ytarcoeffs_xtar[icoeff_fit] );
newcoeffsfile << coeffstring;
sprintf( coeffstring, "%16.9g", yptarcoeffs_xtar[icoeff_fit] );
//newcoeffsfile << " ";
newcoeffsfile << coeffstring;
sprintf( coeffstring, "%16.9g", deltacoeffs_xtar[icoeff_fit] );
//newcoeffsfile << " ";
newcoeffsfile << coeffstring;
newcoeffsfile << " ";
newcoeffsfile << setw(1) << setprecision(1) << xfpexpon_xtar[icoeff_fit];
newcoeffsfile << setw(1) << setprecision(1) << xpfpexpon_xtar[icoeff_fit];
newcoeffsfile << setw(1) << setprecision(1) << yfpexpon_xtar[icoeff_fit];
newcoeffsfile << setw(1) << setprecision(1) << ypfpexpon_xtar[icoeff_fit];
newcoeffsfile << setw(1) << setprecision(1) << xtarexpon_xtar[icoeff_fit];
newcoeffsfile << endl;
}
//
newcoeffsfile << " ---------------------------------------------" << endl;
newcoeffsfile.close();
cout << "wrote new coeffs file" << endl;
//
TCanvas *cdiff = new TCanvas("cdiff","Old matrix Diff target",800,800);
cdiff->Divide(2,2);
cdiff->cd(1);
hytardiff->Draw();
hytardiff->Fit("gaus");
TF1 *fitcydiff=hytardiff->GetFunction("gaus");
cdiff->cd(2);
hyptardiff->Draw();
hyptardiff->Fit("gaus");
TF1 *fitcypdiff=hyptardiff->GetFunction("gaus");
cdiff->cd(3);
hxptardiff->Draw();
hxptardiff->Fit("gaus");
TF1 *fitcxpdiff=hxptardiff->GetFunction("gaus");
cdiff->cd(4);
// hDeltadiff->Draw();
//hDeltadiff->Fit("gaus");
//TF1 *fitcdeldiff=hDeltadiff->GetFunction("gaus");
//
TCanvas *cnewdiff = new TCanvas("cnewdiff","Newfit diff target",800,800);
cnewdiff->Divide(2,2);
cnewdiff->cd(1);
hytarnewdiff->Draw();
hytarnewdiff->Fit("gaus");
TF1 *fitcynewdiff=hytarnewdiff->GetFunction("gaus");
cnewdiff->cd(2);
hyptarnewdiff->Draw();
hyptarnewdiff->Fit("gaus");
TF1 *fitcypnewdiff=hyptarnewdiff->GetFunction("gaus");
cnewdiff->cd(3);
hxptarnewdiff->Draw();
hxptarnewdiff->Fit("gaus");
TF1 *fitcxpnewdiff=hxptarnewdiff->GetFunction("gaus");
cnewdiff->cd(4);
// hDeltanewdiff->Draw();
//hDeltanewdiff->Fit("gaus");
//TF1 *fitcdelnewdiff=hDeltanewdiff->GetFunction("gaus");
//
}