-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathBFit2.cxx
1345 lines (1256 loc) · 54.6 KB
/
BFit2.cxx
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
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
2013-12-07 Shane Caldwell
Made from fit_beta_singles.cxx.
Will modify as necessary to validate against B_monte_carlo output.
2014-02-26
Making a standalone C++ version of B_fit.cpp, which is a ROOT program.
Big difference: this program does not output plots to screen. Instead it saves them to a
subdirectory of the ROOT file that is given to it.
2014-06-29
Just now noting this: Program now (as of like easrly March) uses the CSVtoStruct.h/cxx
*/
#include <unistd.h>
#include "stdio.h"
#include <iostream>
#include <iomanip>
#include <cstring>
#include "time.h"
#include "TROOT.h"
#include "TString.h"
#include "TStyle.h"
#include "TMath.h"
#include "TFitResult.h"
#include "TMatrixDSym.h"
#include "TFile.h"
#include "TF1.h"
#include "TH1.h"
#include "TCanvas.h"
#include "TLegend.h"
#include "TPaveStats.h"
#include "Fit/FitConfig.h"
//#include "include/bdn.h"
//#include "include/sb135.h"
//#include "bdn_cases.h"
#include "bdnHistograms.h"
#include "CSVtoStruct.h"
#include "BFit2Model.h"
using namespace std;
//#include "TVirtualFitter.h"
/////////////////////////////////////////////////////////////////////////////
// Global variables
/////////////////////////////////////////////////////////////////////////////
char parNames[30][5] = {"nCyc", "dt", "DC", "r1", "r2", "r3", "p", "rho", "epsT", "epsU", "epsV", "epsW", "epsX", "epsY", "epsZ", "gT1", "gT2", "gT3", "gU1", "gU2", "gU3"};
// Structs
BDNCase_t stBDNCases[FILE_ROWS_BDN];
BFitCase_t stBFitCases[FILE_ROWS_BFit];
Int_t iBDNCaseIndex, iBFitCaseIndex; // global index to identify case
Int_t iNumStructs_BDN, iNumStructs_BFit;
// These never change during fitting and are set in BFit()
Int_t nPars; // number of model parameters
Double_t iota; // tiny number for avoiding divide-by-0
Double_t tCap, tBac, tCyc; // cycle times
Double_t t1, t2, t3; // radioactive half-lives
//Double_t tZeroArg[1], tCycArg[1]; // specifc time values 1-element array for passing by reference
Int_t nCycles; // number of cycles in dataset -- don't confuse with parameter indec nCyc
Int_t nCapMax; // number of injections per cycle
bool b134sbFlag = 0; // flag for 134sb cases which get special treatment
// These change only when the parameters change during fitting and are set in yAll()
Int_t nParChanges; // counts # of times pars have changed
Double_t *lastPar; // holds most recent paramter values for comparison
Double_t tT1, tT2, tT3, tU1, tU2, tU3; // modified lifetimes
Double_t aT1, aT2, aT3, aU1, aU2, aU3; // Decay factors for one capture interval tCap
Double_t eU1tCyc, eU2tCyc, eU3tCyc; // background decay at end of cycle: exp(-tCyc/tU1), ...
Double_t tT1U2, tT1U3, tU1U2, tU1U3, tT2U3, tU2U3; // Coefficients used in Y2 and Y3
Double_t cT1, cU1, cU2, cZT2, cZU2, cZU3, cXT1, cXU2, cXU3, cYU1, cYU2, cYU3, ThetaU, ThetaY; // various products of lifetimes
//Double_t ST1_1cap, SW11_1cap, SZ11_1cap, ST2_1cap, SW22_1cap, SZ12_1cap, SZ22_1cap; // specific values of the SigmaT, SigmaW, and SigmaZ functions
Double_t *sigmaT1, *sigmaT2, *sigmaT3;
Double_t *sigmaV1, *sigmaV2, *sigmaV3;
Double_t *sigmaW1, *sigmaW2, *sigmaW3;
Double_t *sigmaZ1, *sigmaZ2, *sigmaZ3;
Double_t *sigmaX2, *sigmaX3;
Double_t *sigmaY2, *sigmaY3;
Double_t *sY2v1, *sY2w1, *sY2z1;
Double_t *sY3v2, *sY3w2, *sY3z2, *sY3x2, *sY3v1, *sY3w1, *sY3z1;
Double_t *timeOfCapt;
Double_t Gamma_T1_U2, Gamma_T2_U3;
Double_t Gamma_U1_U2, Gamma_U2_U3;
Double_t *I_V1_Y2, *I_V2_Y3;
Double_t *I_W1_Y2, *I_W2_Y3;
Double_t *I_Z1_Y2, *I_Z2_Y3;
Double_t *I_X1_Y2, *I_X2_Y3;
Double_t *I_Y2_Y3;
Double_t *Y2InitialValues, *Y3InitialValues;
Double_t ampT1, ampT2, ampT3; // amplitudes of the T pops
Double_t ampV1, ampV2, ampV3; // amplitudes of the V pops
Double_t ampW1, ampW2, ampW3; // amplitudes of the W pops
Double_t ampZ1, ampZ2, ampZ3; // amplitudes of the Z pops
Double_t ampX2, ampX3; // amplitudes of the X pops
Double_t ampY2ptA, ampY2ptB; // amplitudes for Y2
Double_t ampY3fromV2, ampY3fromW2, ampY3fromZ2, ampY3fromX2, ampY3fromY2_ST1, ampY3fromY2_SW11, ampY3fromY2_SZ11; // amplitudes for Y3
Double_t V10, V20, V30, W10, W20, W30, Z10, Z20, Z30, X20, X30, Y20, Y30, U10, U20, U30; // initial value (t=0) for each pop
// These change for every function call and are set in yAll()
Int_t nCap; // current injection number
Double_t eU10, eU20, eU30; // decay from t=0 for background parts: exp(-t/tT1), ...
Double_t eT1nCap, eT2nCap, eT3nCap, eU1nCap, eU2nCap, eU3nCap; // decay from last injection for capture parts: exp(-(t-tB-(nCap-1)*tA)/tT1), ...
Double_t T1val, T2val, T3val, U1val, U2val, U3val, V1val, V2val, V3val, W1val, W2val, W3val, Z1val, Z2val, Z3val, X2val, X3val, Y2val, Y3val; // value of each pop
/////////////////////////////////////////////////////////////////////////////
// Functions
Double_t intErr (TF1*, Double_t*, Double_t, Double_t);
void HistPrep (TH1*, Int_t, Int_t, char*);
void FuncPrep (TF1*, Double_t*, Int_t, Int_t, Int_t);
int BFit ();
// MAIN FUNCTION
int main (int argc, char *argv[]) {
char *csvBDNCases, *csvBFitCases;
csvBDNCases = "BDNCases.csv_transposed";
csvBFitCases = "BFitCases.csv_transposed";
cout << endl << "Importing metadata from CSV files..." << endl;
iNumStructs_BDN = CSVtoStruct_BDN (csvBDNCases, stBDNCases);
cout << "Imported " << iNumStructs_BDN << " BDN cases" << endl;
iNumStructs_BFit = CSVtoStruct_BFit (csvBFitCases, stBFitCases);
cout << "Imported " << iNumStructs_BFit << " BFit cases" << endl;
iBDNCaseIndex = FindStructIndex ( stBDNCases, sizeof(BDNCase_t), iNumStructs_BDN, argv[1] );
iBFitCaseIndex = FindStructIndex ( stBFitCases, sizeof(BFitCase_t), iNumStructs_BFit, argv[2] );
if ( iBDNCaseIndex == -1 || iBFitCaseIndex == -1 )
{ // One of the read-ins failed and already printed a message about it
cout << "How to run this program:" << endl;
cout << "'./BFit <BDN case code> <B_fit case code>'" << endl;
cout << "where valid case codes are listed in the CSV files." << endl << endl;
return -1; // error return
}
cout << "Performing BFit with BDN case " << stBDNCases[iBDNCaseIndex].pcsCaseCode << " and BFit case " << stBFitCases[iBFitCaseIndex].pcsCaseCode << endl << endl;
return BFit(); // return status of BFit
}
int BFit () {
// Timer for debugging code
clock_t timer, timerStart, timerStop;
timerStart = clock();
cout << "BFit started. Timer = "<< (Float_t)timerStart/CLOCKS_PER_SEC << " sec." << endl;
int iReturn = SUCCESS;
using namespace BFitNamespace;
using namespace TMath;
TFile *outfile = new TFile("BFit.root","recreate");
// Local copies of the relevant metadata structs
BDNCase_t stBDNCase = stBDNCases[iBDNCaseIndex];
BFitCase_t stBFitCase = stBFitCases[iBFitCaseIndex];
//printf("Bdn Case index = %d, BFit case index = %d\n", iBDNCaseIndex, iBFitCaseIndex);
// Assign global variables
nPars = stBFitCase.iNPars;
tCap = 1000.0 * stBDNCase.dCaptureTime; // Time between BPT captures (ms)
tBac = 1000.0 * stBDNCase.dBackgroundTime; // Time spent in background measurment, per cycle (ms)
tCyc = 1000.0 * stBDNCase.dCycleTime; // Time between BPT ejections (ms)
t1 = 1000.0 * stBDNCase.dLifetime1[0]; // radioactive lifetime (1/e) in ms
t2 = 1000.0 * stBDNCase.dLifetime2[0]; // radioactive lifetime (1/e) in ms
t3 = 1000.0 * stBDNCase.dLifetime3[0]; // radioactive lifetime (1/e) in ms
nCycles = stBDNCase.nCycles; // Number of cycles in dataset
iota = 1e-9;
// printf(" iota = %.4e\n",iota);
// printf(" iota = %32.16f\n",iota);
// printf("1000000 + iota = %32.16f\n",1000000+iota);
// return 0;
nCapMax = Ceil((tCyc-tBac)/tCap);
//printf("nCapMax=%d\n",nCapMax);
// Array to hold injection times
timeOfCapt = new Double_t [nCapMax+1];
Int_t k;
for (k=0; k<nCapMax+1; k++)
timeOfCapt[k] = tBac + k*tCap;
// Arrays to hold the sigma values in each [index] tooth:
// Zero index not used (+1 element), for notational consistency
sigmaT1 = new Double_t [nCapMax+1];
sigmaT2 = new Double_t [nCapMax+1];
sigmaT3 = new Double_t [nCapMax+1];
sigmaV1 = new Double_t [nCapMax+1];
sigmaV2 = new Double_t [nCapMax+1];
sigmaV3 = new Double_t [nCapMax+1];
sigmaW1 = new Double_t [nCapMax+1];
sigmaW2 = new Double_t [nCapMax+1];
sigmaW3 = new Double_t [nCapMax+1];
sigmaZ1 = new Double_t [nCapMax+1];
sigmaZ2 = new Double_t [nCapMax+1];
sigmaZ3 = new Double_t [nCapMax+1];
sigmaX2 = new Double_t [nCapMax+1];
sigmaX3 = new Double_t [nCapMax+1];
sigmaY2 = new Double_t [nCapMax+1];
sigmaY3 = new Double_t [nCapMax+1];
sY2v1 = new Double_t [nCapMax+1];
sY2w1 = new Double_t [nCapMax+1];
sY2z1 = new Double_t [nCapMax+1];
sY3v2 = new Double_t [nCapMax+1];
sY3w2 = new Double_t [nCapMax+1];
sY3z2 = new Double_t [nCapMax+1];
sY3x2 = new Double_t [nCapMax+1];
sY3v1 = new Double_t [nCapMax+1];
sY3w1 = new Double_t [nCapMax+1];
sY3z1 = new Double_t [nCapMax+1];
sigmaT1[0] = sigmaT2[0] = sigmaT3[0] = 0.0; // zero index not used -- set to zero for definiteness
sigmaV1[0] = sigmaV2[0] = sigmaV3[0] = 0.0; // zero index not used -- set to zero for definiteness
sigmaW1[0] = sigmaW2[0] = sigmaW3[0] = 0.0; // zero index not used -- set to zero for definiteness
sigmaZ1[0] = sigmaZ2[0] = sigmaZ3[0] = 0.0; // zero index not used -- set to zero for definiteness
sigmaX2[0] = sigmaX3[0] = 0.0; // zero index not used -- set to zero for definiteness
sigmaY2[0] = sigmaY3[0] = 0.0; // zero index not used -- set to zero for definiteness
sY2v1[0] = sY2w1[0] = sY2z1[0] = 0.0; // zero index not used -- set to zero for definiteness
sY3v2[0] = sY3w2[0] = sY3z2[0] = sY3x2[0] = 0.0; // zero index not used -- set to zero for definiteness
sY3v1[0] = sY3w1[0] = sY3z1[0] = 0.0; // zero index not used -- set to zero for definiteness
// Arrays to hold partial integrals of functions through [index] teeth:
// Zero index used only as an initializer (+1 element),
// but don't need an element for the last tooth (-1 element)
// These are integrals of the feeding terms into the Y2 and Y3 populations
// I_V1_Y2 = new Double_t [nCapMax];
// I_W1_Y2 = new Double_t [nCapMax];
// I_Z1_Y2 = new Double_t [nCapMax];
// I_V2_Y3 = new Double_t [nCapMax];
// I_W2_Y3 = new Double_t [nCapMax];
// I_Z2_Y3 = new Double_t [nCapMax];
// I_X2_Y3 = new Double_t [nCapMax];
// I_Y2_Y3 = new Double_t [nCapMax];
// I_V1_Y2[0] = I_V2_Y3[0] = 0.0; // zero index used as init value of zero
// I_W1_Y2[0] = I_W2_Y3[0] = 0.0; // zero index used as init value of zero
// I_Z1_Y2[0] = I_Z2_Y3[0] = 0.0; // zero index used as init value of zero
// I_X2_Y3[0] = 0.0; // zero index used as init value of zero
// I_Y2_Y3[0] = 0.0; // zero index used as init value of zero
// Arrays to hold initial values of Y pops... I think these will be deprecated
// Y2InitialValues = new Double_t [nCapMax];
// Y3InitialValues = new Double_t [nCapMax];
// Print message
TString separator = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
cout << endl << separator << endl;
cout << "BETA SINGLES MODEL" << endl << separator << endl;
cout << "Case: " << stBDNCase.pcsCaseCode << endl;
cout << "File: " << stBDNCase.pcsFilePath << endl;
cout << "Histogram: " << stBFitCase.pcsHistName << endl;
printf("Total cycle time\t= %10.3f s\n", stBDNCase.dCycleTime);
printf("Background time\t\t= %10.3f s\n", stBDNCase.dBackgroundTime);
printf("Capture cycle time\t= %10.3f s\n", stBDNCase.dCaptureTime);
printf("Last capture time\t= %10.3f s\n", stBDNCase.dLastCaptureTime);
cout << stBDNCase.pcsSpecies1Name; printf(" halflife\t\t= %10.3f s (lifetime %10.3f s)\n", stBDNCase.dHalfLife1[0], stBDNCase.dLifetime1[0]);
cout << stBDNCase.pcsSpecies2Name; printf(" halflife\t\t= %10.3f s (lifetime %10.3f s)\n", stBDNCase.dHalfLife2[0], stBDNCase.dLifetime2[0]);
cout << stBDNCase.pcsSpecies3Name; printf(" halflife\t\t= %10.3f s (lifetime %10.3f s)\n", stBDNCase.dHalfLife3[0], stBDNCase.dLifetime3[0]);
cout << separator << endl;
// Get histogram from ROOT file
TFile *f = new TFile(stBDNCase.pcsFilePath);
TH1D *h = (TH1D*)f->Get(stBFitCase.pcsHistName);
Double_t dBinWidth = stBFitCase.pdSeed[dt];
Double_t dNBins = tCyc/dBinWidth;// # of bins covered by funtion //h->GetNbinsX();
Double_t pointsPerBin = 20;
Double_t nPoints = pointsPerBin * dNBins;
Double_t dRebinFactor = dBinWidth/(h->GetBinWidth(1));
// printf("dBinWidth=%f, GetBinWidth=%f, dRebinFactor=%f\n", dBinWidth, h->GetBinWidth(1), dRebinFactor);
// Double_t dRebinFactor = stBFitCase.iBinWidth/(h->GetBinWidth(1));
Double_t binZero = (1.0/dRebinFactor)*(0.0 - tCycMin) + 1.0;
Double_t binCap = (1.0/dRebinFactor)*(tBac - tCycMin) + 1.0;
Double_t binCycle = (1.0/dRebinFactor)*(tCyc - tCycMin) + 1.0;
TH1D *h1 = (TH1D*)h->Rebin(dRebinFactor,stBFitCase.pcsHistName);
TH1D *h2 = (TH1D*)h->Rebin(dRebinFactor,stBFitCase.pcsHistName);
cout << "HISTOGRAM REBINNED" << endl;
cout << " Number of hist bins = " << dNBins << endl;
cout << " Number of fn points = " << nPoints << endl;
cout << " Number of pts/bin = " << pointsPerBin << endl;
cout << separator << endl;
if (stBFitCase.bDoFit) cout << "Doing fit with option string: " << stBFitCase.pcsOptions << endl;
else cout << "Not fitting! Drawing functions using parameter seed values." << endl;
cout << separator << endl;
// Define functions
// Double_t tMax = 1000.0 * stBDNCase.dCycleTime;
// Species populations
TF1 *fyDC = new TF1("fyDC", yDC, 0.0, tCyc, nPars);
TF1 *fyT1 = new TF1("fyT1", yT1, 0.0, tCyc, nPars);
TF1 *fyT2 = new TF1("fyT2", yT2, 0.0, tCyc, nPars);
TF1 *fyT3 = new TF1("fyT3", yT3, 0.0, tCyc, nPars);
TF1 *fyU1 = new TF1("fyU1", yU1, 0.0, tCyc, nPars);
TF1 *fyU2 = new TF1("fyU2", yU2, 0.0, tCyc, nPars);
TF1 *fyU3 = new TF1("fyU3", yU3, 0.0, tCyc, nPars);
//**************************************************************************
// This one fits the data:
TF1 *fyAll = new TF1("fyAll",yAll, 0.0, tCyc, nPars);
//**************************************************************************
// Beta rates to be used by TF1::Integral() and TF1::IntegralError()
TF1 *frDC = new TF1("frDC", rDC, 0.0, tCyc, nPars);
TF1 *frT1 = new TF1("frT1", rT1, 0.0, tCyc, nPars);
TF1 *frT2 = new TF1("frT2", rT2, 0.0, tCyc, nPars);
TF1 *frT3 = new TF1("frT3", rT3, 0.0, tCyc, nPars);
TF1 *frU1 = new TF1("frU1", rU1, 0.0, tCyc, nPars);
TF1 *frU2 = new TF1("frU2", rU2, 0.0, tCyc, nPars);
TF1 *frU3 = new TF1("frU3", rU3, 0.0, tCyc, nPars);
TF1 *frAll = new TF1("frAll",rAll, 0.0, tCyc, nPars);
// Offset functions for plotting
TF1 *foT1 = new TF1("foT1", oT1, 0.0, tCyc, nPars);
TF1 *foT2 = new TF1("foT2", oT2, 0.0, tCyc, nPars);
TF1 *foT3 = new TF1("foT3", oT3, 0.0, tCyc, nPars);
TF1 *foU1 = new TF1("foU1", oU1, 0.0, tCyc, nPars);
TF1 *foU2 = new TF1("foU2", oU2, 0.0, tCyc, nPars);
TF1 *foU3 = new TF1("foU3", oU3, 0.0, tCyc, nPars);
// Initiailize function to fit the data
char pcsLifetime1ParName[100]; sprintf(pcsLifetime1ParName,"%s radioactive lifetime (1/e)", stBDNCase.pcsSpecies1Name);
char pcsLifetime2ParName[100]; sprintf(pcsLifetime2ParName,"%s radioactive lifetime (1/e)", stBDNCase.pcsSpecies2Name);
char pcsLifetime3ParName[100]; sprintf(pcsLifetime3ParName,"%s radioactive lifetime (1/e)", stBDNCase.pcsSpecies3Name);
fyAll->SetParName(nCyc,"# Cyc's");
fyAll->SetParName(DC,"DC rate");
fyAll->SetParName(r1,"Rate 1");
fyAll->SetParName(r2,"Rate 2");
fyAll->SetParName(r3,"Rate 3");
fyAll->SetParName(p,"Capt eff");
fyAll->SetParName(rho,"Capt ret");
fyAll->SetParName(epsT,"T eff");
fyAll->SetParName(epsU,"U eff");
fyAll->SetParName(epsV,"V eff");
fyAll->SetParName(epsW,"W eff");
fyAll->SetParName(epsX,"X eff");
fyAll->SetParName(epsY,"Y eff");
fyAll->SetParName(epsZ,"Z eff");
// fyAll->SetParName(tau1,pcsLifetime1ParName);//"Lifetime 1");//pcsSpecies1ParName);
// fyAll->SetParName(tau2,pcsLifetime2ParName);//"Lifetime 2");//pcsSpecies2ParName);
// fyAll->SetParName(tau3,pcsLifetime3ParName);//"Lifetime 3");//pcsSpecies3ParName);
fyAll->SetParName(gammaT1,"T1 loss");
fyAll->SetParName(gammaT2,"T2 loss");
fyAll->SetParName(gammaT3,"T3 loss");
fyAll->SetParName(gammaU1,"U1 loss");
fyAll->SetParName(gammaU2,"U2 loss");
fyAll->SetParName(gammaU3,"U3 loss");
fyAll->SetParName(dt,"Bin width");
// Initial parameter values and initial step sizes
// err contains initial step sizes now, will contain error estimates later.
Int_t *tog;
Double_t *par;
Double_t *err;
tog = stBFitCase.pbToggle;
par = stBFitCase.pdSeed;
err = stBFitCase.pdStep;
Int_t index;
par[nCyc] = nCycles;
// Special cases -- modifications to parameters -- catch right after param import
if (!strcmp(stBDNCases[iBDNCaseIndex].pcsCaseCode,"134sb01") ||
!strcmp(stBDNCases[iBDNCaseIndex].pcsCaseCode,"134sb02") ||
!strcmp(stBDNCases[iBDNCaseIndex].pcsCaseCode,"134sb03") ||
!strcmp(stBDNCases[iBDNCaseIndex].pcsCaseCode,"134sb0103"))
{
b134sbFlag = 1;
par[gammaT3] = par[gammaT2];
}
// Initialize global lastPar to values that guarantee computation of parameter-dependent variables in first eval of yAll
lastPar = new Double_t [nPars];
memcpy(lastPar,par,nPars*sizeof(Double_t));
// printf("\n\n[lastPar = %f, %f, %f, ...]\n\n",lastPar[0],lastPar[1],lastPar[2]);
// for (index = 0; index < nPars; index++) lastPar[index] = -1.0;
// Initialize parameter-dependent variables
BFitNamespace::ComputeParameterDependentVars(par);
// Place initial par values into fitting function
fyAll->SetParameters(par);
fyAll->SetParErrors(err);
//if (stBFitCase.pbToggle[rho]) fyAll->SetParLimits(rho,0,1);
// Print seed values that are assigned to the fit function
cout << "PARAMETER SEED VALUES" << endl << separator << endl;
cout << setw(14) << "Par name" << setw(10) << "Varying?" << "\t" << "Par init val and step" << endl << separator << endl;
for (index = 0; index < nPars; index++) {
cout << setw(14) << fyAll->GetParName(index) << setw(10) << tog[index] << "\t" << fyAll->GetParameter(index) << " +/- " << fyAll->GetParError(index) << endl;
}
cout << separator << endl;
// if (!strcmp(stBDNCases[iBDNCaseIndex].pcsCaseCode,"134sb01") ||
// !strcmp(stBDNCases[iBDNCaseIndex].pcsCaseCode,"134sb02") ||
// !strcmp(stBDNCases[iBDNCaseIndex].pcsCaseCode,"134sb03") ||
// !strcmp(stBDNCases[iBDNCaseIndex].pcsCaseCode,"134sb0103"))
// {
// b134sbFlag = 1;
// fyAll->SetParameter(gammaT3, stBFitCase.pdSeed[gammaT2]);
// par
// cout << "134-Sb data detected. Forcing gammaT3 = gammaT2. YOU SHOULD GUARANTEE THAT X3 = Y3 = 0. You can set epsX = epsY = 0." << endl << endl;
// }
if (b134sbFlag) cout << "134-Sb data detected. Forcing gammaT3 = gammaT2. YOU SHOULD GUARANTEE THAT X3 = Y3 = 0. You can set epsX = epsY = 0." << endl << endl;
else cout << endl;
// Initialize all functions to parameter seed values
fyDC -> SetParameters(par);
fyT1 -> SetParameters(par);
fyT2 -> SetParameters(par);
fyT3 -> SetParameters(par);
fyU1 -> SetParameters(par);
fyU2 -> SetParameters(par);
fyU3 -> SetParameters(par);
frDC -> SetParameters(par);
frT1 -> SetParameters(par);
frT2 -> SetParameters(par);
frT3 -> SetParameters(par);
frU1 -> SetParameters(par);
frU2 -> SetParameters(par);
frU3 -> SetParameters(par);
frAll -> SetParameters(par);
foT1 -> SetParameters(par);
foT2 -> SetParameters(par);
foT3 -> SetParameters(par);
foU1 -> SetParameters(par);
foU2 -> SetParameters(par);
foU3 -> SetParameters(par);
if (stBFitCase.bDoFit) {
// Fix the parameters that are supposed to be fixed
for (index = 0; index < nPars; index++) {
if (tog[index] == 0) fyAll->FixParameter(index, stBFitCase.pdSeed[index]);
}
if (b134sbFlag && tog[gammaT2]==0) fyAll->FixParameter(gammaT3, stBFitCase.pdSeed[gammaT2]);
// Print initial parameters: (see similar code in yAll() in BFit2Model.cxx)
if (nParChanges == 0) {
printf("Ini pars ( 0): ",nParChanges);
for (index = 0; index < nPars; index++) {
if (stBFitCases[iBFitCaseIndex].pbToggle[index]) printf("%s=%.4e ",parNames[index],par[index]);
}
printf("\n");
}
// Do fit and get results
timer = clock();
// TVirtualFitter::SetDefaultFitter("Minuit2");
// TVirtualFitter *fitter;
//
TFitResultPtr fit = h1->Fit(fyAll,stBFitCase.pcsOptions);
timer = clock() - timer;
printf("\nFitting done in %d clicks (%f seconds).\n", timer, (Float_t)timer/CLOCKS_PER_SEC);
printf("Fit status = %d\n",fit->Status());
printf("Cov status = %d\n",fit->CovMatrixStatus());
TMatrixDSym cov = fit->GetCovarianceMatrix();
// Double_t *cov2 = fit->GetCovarianceMatrix();
// Int_t ii=0, jj=0;
Double_t *covArray = new Double_t [nPars*nPars];
covArray = cov.GetMatrixArray();
// for (Int_t ii=0; ii<8; ii++) {
// // printf("%.3e ",cov.GetMatrixArray()[ii]);
// for (Int_t jj=0; jj<8; jj++) {
// // printf("%.6e ", cov[ii][jj]);
// printf("%.6e ", covArray[ii+jj*nPars] );
// }
// cout << endl;
// }
fit->Print("V");
// Get parameter values from fit
for (index = 0; index < nPars; index++) {
par[index] = fyAll->GetParameter(index);
err[index] = fyAll->GetParError(index);
// printf("%12s err = %f\n", fyAll->GetParName(index), err[index]);
}
// par is now up to date...
// Set other functions to parameter values from fit
BFitNamespace::ComputeParameterDependentVars(par);
fyDC -> SetParameters(par);
fyT1 -> SetParameters(par);
fyT2 -> SetParameters(par);
fyT3 -> SetParameters(par);
fyU1 -> SetParameters(par);
fyU2 -> SetParameters(par);
fyU3 -> SetParameters(par);
frDC -> SetParameters(par);
frT1 -> SetParameters(par);
frT2 -> SetParameters(par);
frT3 -> SetParameters(par);
frU1 -> SetParameters(par);
frU2 -> SetParameters(par);
frU3 -> SetParameters(par);
frAll -> SetParameters(par);
foT1 -> SetParameters(par);
foT2 -> SetParameters(par);
foT3 -> SetParameters(par);
foU1 -> SetParameters(par);
foU2 -> SetParameters(par);
foU3 -> SetParameters(par);
//// Calculate integrals and errors (OLD WAY -- doesn't work for arbitrary # of varying params)
// //Double_t N_beta_2_calc = par[p]*par[r2]*(T-Tb-t2*(1-Exp(-(T-Tb)/t2)));
// Double_t N_beta_1 = frT1->Integral(Tb,T);
// Double_t N_beta_2 = frT2->Integral(Tb,T);
// Double_t N_beta_3 = frT3->Integral(Tb,T);
//
// Double_t dNdp1 = par[r1]*(T-Tb-par[tauT1]*(1-Exp(-(T-Tb)/par[tauT1])));
// Double_t dNdr1 = par[p] *(T-Tb-par[tauT1]*(1-Exp(-(T-Tb)/par[tauT1])));
// Double_t dNdt1 = par[p]*par[r1]*(((T-Tb)/par[tauT1]+1)*Exp(-(T-Tb)/par[tauT1])-1);
// Double_t N_beta_1_err = sqrt(dNdp1*dNdp1*err[p]*err[p] + dNdr1*dNdr1*err[r1]*err[r1] + dNdt1*dNdt1*err[tauT1]*err[tauT1] + 2.0*dNdp1*dNdr1*cov[p][r1]);
//
// Double_t dNdp2 = par[r2]*(T-Tb-par[tauT2]*(1-Exp(-(T-Tb)/par[tauT2])));
// Double_t dNdr2 = par[p] *(T-Tb-par[tauT2]*(1-Exp(-(T-Tb)/par[tauT2])));
// Double_t dNdt2 = par[p]*par[r2]*(((T-Tb)/par[tauT2]+1)*Exp(-(T-Tb)/par[tauT2])-1);
// Double_t N_beta_2_err = sqrt(dNdp2*dNdp2*err[p]*err[p] + dNdr2*dNdr2*err[r2]*err[r2] + dNdt2*dNdt2*err[tauT2]*err[tauT2] + 2.0*dNdp2*dNdr2*cov[p][r2]);
//
// Double_t dNdp3 = par[r3]*(T-Tb-par[tauT3]*(1-Exp(-(T-Tb)/par[tauT3])));
// Double_t dNdr3 = par[p] *(T-Tb-par[tauT3]*(1-Exp(-(T-Tb)/par[tauT3])));
// Double_t dNdt3 = par[p]*par[r3]*(((T-Tb)/par[tauT3]+1)*Exp(-(T-Tb)/par[tauT3])-1);
// Double_t N_beta_3_err = sqrt(dNdp3*dNdp3*err[p]*err[p] + dNdr3*dNdr3*err[r3]*err[r3] + dNdt3*dNdt3*err[tauT3]*err[tauT3]+ 2.0*dNdp3*dNdr3*cov[p][r3]);
//
// printf("\n");
// printf("N_beta_1 (detected) = %f +/- %f\n", N_beta_1, N_beta_1_err);
// printf("N_beta_2 (detected) = %f +/- %f\n", N_beta_2, N_beta_2_err);
// printf("N_beta_3 (detected) = %f +/- %f\n", N_beta_3, N_beta_3_err);
// printf("\n");
if (0) {
for (Int_t iPar = 0; iPar < nPars; iPar++) {
// grads[iPar] = frT2->GradientPar(iPar,par,0.0001);
printf("%12s val = %f, err = %f\n", fyAll->GetParName(iPar), par[iPar], err[iPar]);
}
TF1 *fInt = new TF1("frT2", rT2, 0.0, tCyc, nPars);
sleep(1.5);
Double_t grads[nPars];
printf("\n");
Double_t timeVar[1] = {0.0};
// fInt->GradientPar(timeVar,grads,0.001);
// fInt->GradientPar(par,grads,0.001);
for (Int_t iPar = 0; iPar < nPars; iPar++) {
// grads[iPar] = frT2->GradientPar(iPar,par,0.0001);
printf("%s grad = %.24f\n", parNames[iPar], grads[iPar]);
}
printf("\n");
Double_t par1[nPars], par2[nPars];
memcpy(par1,par,nPars*sizeof(Double_t));
memcpy(par2,par,nPars*sizeof(Double_t));
par2[r2] = par2[r2]*1.1;
fInt->SetParameters(par1);
Double_t fr_int_1 = fInt->Integral(0.0, tCyc);
fInt->SetParameters(par2);
Double_t fr_int_2 = fInt->Integral(0.0, tCyc);
sleep(0.25);
printf("int1 = %f, int2 = %f\n", fr_int_1, fr_int_2);
}
// Estimate # of betas detected and error
T1_integral = frT1->Integral( 0.0, tCyc);
T2_integral = frT2->Integral( 0.0, tCyc);
T3_integral = frT3->Integral( 0.0, tCyc);
U1_integral = frU1->Integral( 0.0, tCyc);
U2_integral = frU2->Integral( 0.0, tCyc);
U3_integral = frU3->Integral( 0.0, tCyc);
DC_integral = frDC->Integral( 0.0, tCyc);
All_integral = frAll->Integral( 0.0, tCyc);
Integral_sum = DC_integral + T1_integral + T2_integral + T3_integral + U1_integral + U2_integral + U3_integral;
timer = clock() - timer;
printf("\nIntegrals computed in %d clicks (%f seconds).\n", timer, (Float_t)timer/CLOCKS_PER_SEC);
if (stBFitCase.bComputeOtherIntegrals) {
U1_integral_trap_empty = frU1->Integral( 0.0, tBac);
U2_integral_trap_empty = frU2->Integral( 0.0, tBac);
U3_integral_trap_empty = frU3->Integral( 0.0, tBac);
U1_integral_trap_full = frU1->Integral( tBac, tCyc);
U2_integral_trap_full = frU2->Integral( tBac, tCyc);
U3_integral_trap_full = frU3->Integral( tBac, tCyc);
timer = clock() - timer;
printf("Other integrals computed in %d clicks (%f seconds).\n", timer, (Float_t)timer/CLOCKS_PER_SEC);
}
// T1_integral_error = frT1->IntegralError( 0.0, tCyc, par, cov.GetMatrixArray() );
// printf("Getting rT2 integral error in 5 seconds...\n"); sleep(1);
// printf("Getting rT2 integral error in 4 seconds...\n"); sleep(1);
// printf("Getting rT2 integral error in 3 seconds...\n"); sleep(1);
// printf("Getting rT2 integral error in 2 seconds...\n"); sleep(1);
// printf("Getting rT2 integral error in 1 seconds...\n"); sleep(1);
// T2_integral_error = frT2->IntegralError( 0.0, tCyc, par, cov.GetMatrixArray() );
// T1_integral_error = intErr( frT1, covArray, 0.0, tCyc );
T1_integral_error = intErr( frT1, covArray, 0.0, tCyc );
T2_integral_error = intErr( frT2, covArray, 0.0, tCyc );
T3_integral_error = intErr( frT3, covArray, 0.0, tCyc );
U1_integral_error = intErr( frU1, covArray, 0.0, tCyc );
U2_integral_error = intErr( frU2, covArray, 0.0, tCyc );
U3_integral_error = intErr( frU3, covArray, 0.0, tCyc );
DC_integral_error = intErr( frDC, covArray, 0.0, tCyc );
All_integral_error = intErr( frAll, covArray, 0.0, tCyc );
// All_integral_error = frAll->IntegralError( 0.0, tCyc, par, cov.GetMatrixArray() );
// T3_integral_error = frT3->IntegralError( 0.0, tCyc, par, cov.GetMatrixArray() );
// U1_integral_error = frU1->IntegralError( 0.0, tCyc, par, cov.GetMatrixArray() );
// U2_integral_error = frU2->IntegralError( 0.0, tCyc, par, cov.GetMatrixArray() );
// U3_integral_error = frU3->IntegralError( 0.0, tCyc, par, cov.GetMatrixArray() );
// DC_integral_error = frDC->IntegralError( 0.0, tCyc, par, cov.GetMatrixArray() );
// All_integral_error = frAll->IntegralError( 0.0, tCyc, par, cov.GetMatrixArray() );
// printf("tCyc=%f\n",tCyc);
// T1_integral_error = frT1->IntegralError( 0.0, 1000*tCyc);
// T2_integral_error = frT2->IntegralError( 0.0, tCyc);
// T3_integral_error = frT3->IntegralError( 0.0, tCyc);
// U1_integral_error = frU1->IntegralError( 0.0, tCyc);
// U2_integral_error = frU2->IntegralError( 0.0, tCyc);
// U3_integral_error = frU3->IntegralError( 0.0, tCyc);
// DC_integral_error = frDC->IntegralError( 0.0, tCyc);
// All_integral_error = frAll->IntegralError( 0.0, tCyc);
Integral_sum_error = Sqrt( Power(DC_integral_error,2.0) + Power(T1_integral_error,2.0) + Power(T2_integral_error,2.0) + Power(T3_integral_error,2.0) + Power(U1_integral_error,2.0) + Power(U2_integral_error,2.0) + Power(U3_integral_error,2.0) );
timer = clock() - timer;
printf("Errors computed in %d clicks (%f seconds).\n", timer, (Float_t)timer/CLOCKS_PER_SEC);
cout << endl << separator << endl;
printf("NUMBER OF BETAS DETECTED, by population:\n");
cout << separator << endl;
printf("T1 integral = %.1f +/- %.1f\n", T1_integral, T1_integral_error);
printf("U1 integral = %.1f +/- %.1f\n", U1_integral, U1_integral_error);
printf("T2 integral = %.1f +/- %.1f\n", T2_integral, T2_integral_error);
printf("U2 integral = %.1f +/- %.1f\n", U2_integral, U2_integral_error);
printf("T3 integral = %.1f +/- %.1f\n", T3_integral, T3_integral_error);
printf("U3 integral = %.1f +/- %.1f\n", U3_integral, U3_integral_error);
printf("DC integral = %.1f +/- %.1f\n", DC_integral, DC_integral_error);
cout << separator << endl;
printf("Sum of above = %.1f +/- %.1f <-- no cov in unc\n", Integral_sum, Integral_sum_error);
printf("All integral = %.1f +/- %.1f\n", All_integral, All_integral_error);
if (stBFitCase.bComputeOtherIntegrals) {
cout << separator << endl;
printf("U1 with trap emtpy = %.1f; trap full = %.1f\n", U1_integral_trap_empty, U1_integral_trap_full);
printf("U2 with trap emtpy = %.1f; trap full = %.1f\n", U2_integral_trap_empty, U2_integral_trap_full);
printf("U3 with trap emtpy = %.1f; trap full = %.1f\n", U3_integral_trap_empty, U3_integral_trap_full);
// printf("All untrapped with trap empty = %f (bin %f to bin %f)\n", h1->Integral(binZero, binCap-1) - par[DC]*tBac, binZero, binCap);
// printf("All data area in histogram = %f\n", h1->Integral(binZero, binCycle-1));
// printf("All data area in histogram = %f\n", h1->Integral());
}
cout << separator << endl << endl;
} // end if (stBFitCase.bDoFit)
// Draw
Double_t yMin, yMax, yRange;
fyAll->SetLineColor(kBlack);
fyDC->SetLineColor(kBlack);
foT1->SetLineColor(kGreen);
foT2->SetLineColor(kBlue);
foT3->SetLineColor(kRed);
foU1->SetLineColor(kGreen);
foU2->SetLineColor(kBlue);
foU3->SetLineColor(kRed);
h1->SetLineColor(16);
// h2->SetLineColor(16);
fyDC->SetLineStyle(2);
foU1->SetLineStyle(2);
foU2->SetLineStyle(2);
foU3->SetLineStyle(2);
// Double_t nPoints = 2 * (1000.0 * stBDNCase.dCycleTime / dRebinFactor); // leading interger is number of points per bin
// Now defined above
fyAll->SetNpx(nPoints);
foT1->SetNpx(nPoints);
foT2->SetNpx(nPoints);
foT3->SetNpx(nPoints);
foU1->SetNpx(nPoints);
foU2->SetNpx(nPoints);
foU3->SetNpx(nPoints);
FuncPrep(fyAll,par,nPoints,kBlack,1);
FuncPrep(foT1,par,nPoints,kGreen,1);
FuncPrep(foT2,par,nPoints,kBlue,1);
FuncPrep(foT3,par,nPoints,kRed,1);
FuncPrep(foU1,par,nPoints,kGreen,7);
FuncPrep(foU2,par,nPoints,kBlue,7);
FuncPrep(foU3,par,nPoints,kRed,7);
Float_t wdth = 1.4;
fyAll->SetLineWidth(wdth);
foT1->SetLineWidth(wdth);
foT2->SetLineWidth(1.5*wdth);
foT3->SetLineWidth(wdth);
foU1->SetLineWidth(wdth);
foU2->SetLineWidth(wdth);
foU3->SetLineWidth(wdth);
Int_t bsmPlot = 0;
Float_t scale = 1.0;
//if (bsmPlot) scale = 2.0;
TCanvas *c_BFit = new TCanvas("c_BFit","Beta singles fit",scale*945,scale*600);
gStyle->SetOptStat("e");
gStyle->SetOptFit(1111);
h1 ->Draw("HIST");
fyAll ->Draw("SAME");
foU1->Draw("SAME");
foT1->Draw("SAME");
foU3->Draw("SAME");
foT3->Draw("SAME");
foU2->Draw("SAME");
foT2->Draw("SAME");
fyDC->Draw("SAME");
//c_B_fit->Update();
//Double_t xMin = h1->GetXaxis()->GetXmin();
//Double_t xMax = h1->GetXaxis()->GetXmax();
yMin = par[nCyc]*par[DC]*par[dt];
yMax = h1->GetMaximum();
// printf("\nY Range is %f to %f\n\n",yMin,yMax);
yRange = yMax - yMin;
yMin = yMin - 0.05*yRange;
yMax = yMax + 0.10*yRange;
//printf("Range = (%f,%f)\n", yMin, yMax);
h1->GetYaxis()->SetRangeUser(yMin,yMax);
// h2->GetYaxis()->SetRangeUser(yMin,yMax);
h1->GetXaxis()->SetRangeUser(-1000,tCyc+1000);
// h2->GetXaxis()->SetRangeUser(-1000,tCyc+1000);
if (bsmPlot) { // special case for a plot in Beta Singles Model appendix in my thesis
h1->SetXTitle("Cycle time (ms)");
h1->SetYTitle("Detections / 500 ms");
h1->SetTitle("Simulation vs Model, All populations");
h1->GetXaxis()->SetRangeUser(0,tCyc);
h1->GetYaxis()->SetTitleOffset(1.0);
TLegend *leg_1 = new TLegend(0.15, 0.62, 0.40, 0.87);
leg_1->AddEntry(h1 , "Data");
leg_1->AddEntry(fyDC, "DC");
char pcsT1Name[STRING_SIZE], pcsT2Name[STRING_SIZE], pcsT3Name[STRING_SIZE];
char pcsU1Name[STRING_SIZE], pcsU2Name[STRING_SIZE], pcsU3Name[STRING_SIZE];
sprintf(pcsT1Name,"Species 1, trapped");
sprintf(pcsT2Name,"Species 2, trapped");
sprintf(pcsT3Name,"Species 3, trapped");
sprintf(pcsU1Name,"Species 1, untrapped");
sprintf(pcsU2Name,"Species 2, untrapped");
sprintf(pcsU3Name,"Species 3, untrapped");
leg_1->AddEntry(foT1, pcsT1Name);
leg_1->AddEntry(foU1, pcsU1Name);
leg_1->AddEntry(foT2, pcsT2Name);
leg_1->AddEntry(foU2, pcsU2Name);
leg_1->AddEntry(foT3, pcsT3Name);
leg_1->AddEntry(foU3, pcsU3Name);
leg_1->AddEntry(fyAll , "Fit function (all species)");
leg_1->SetFillColor(0);
leg_1->Draw();
}
else { // normal case
TLegend *leg_1 = new TLegend(0.13, 0.69, 0.32, 0.94);
leg_1->AddEntry(h1 , "Data");
leg_1->AddEntry(fyDC, "DC");
char pcsT1Name[STRING_SIZE], pcsT2Name[STRING_SIZE], pcsT3Name[STRING_SIZE];
char pcsU1Name[STRING_SIZE], pcsU2Name[STRING_SIZE], pcsU3Name[STRING_SIZE];
strcpy(pcsT1Name, stBDNCase.pcsSpecies1Name); strcat(pcsT1Name, " trapped");
strcpy(pcsT2Name, stBDNCase.pcsSpecies2Name); strcat(pcsT2Name, " trapped");
strcpy(pcsT3Name, stBDNCase.pcsSpecies3Name); strcat(pcsT3Name, " trapped");
strcpy(pcsU1Name, stBDNCase.pcsSpecies1Name); strcat(pcsU1Name, " untrapped");
strcpy(pcsU2Name, stBDNCase.pcsSpecies2Name); strcat(pcsU2Name, " untrapped");
strcpy(pcsU3Name, stBDNCase.pcsSpecies3Name); strcat(pcsU3Name, " untrapped");
leg_1->AddEntry(foT1, pcsT1Name);
leg_1->AddEntry(foU1, pcsU1Name);
leg_1->AddEntry(foT2, pcsT2Name);
leg_1->AddEntry(foU2, pcsU2Name);
leg_1->AddEntry(foT3, pcsT3Name);
leg_1->AddEntry(foU3, pcsU3Name);
leg_1->AddEntry(fyAll , "Fit function (all species)");
leg_1->SetFillColor(0);
leg_1->Draw();
}
if (stBFitCase.bDoFit) {
char int_T1[100]; char int_T2[100]; char int_T3[100]; char int_U1[100]; char int_U2[100]; char int_U3[100]; char int_All[100];
// sprintf(int1,"T1 = %8.0f +/- %6.0f; U1 = %8.0f +/- %6.0f", T1_integral, T1_integral_error, U1_integral, U1_integral_error);
// sprintf(int2,"T2 = %8.0f +/- %6.0f; U2 = %8.0f +/- %6.0f", T2_integral, T2_integral_error, U2_integral, U2_integral_error);
// sprintf(int3,"T3 = %8.0f +/- %6.0f; U3 = %8.0f +/- %6.0f", T3_integral, T3_integral_error, U3_integral, U3_integral_error);
sprintf(int_T1,"%8.0f +/- %6.0f", T1_integral, T1_integral_error);
sprintf(int_U1,"%8.0f +/- %6.0f", U1_integral, U1_integral_error);
sprintf(int_T2,"%8.0f +/- %6.0f", T2_integral, T2_integral_error);
sprintf(int_U2,"%8.0f +/- %6.0f", U2_integral, U2_integral_error);
sprintf(int_T3,"%8.0f +/- %6.0f", T3_integral, T3_integral_error);
sprintf(int_U3,"%8.0f +/- %6.0f", U3_integral, U3_integral_error);
sprintf(int_All,"%8.0f +/- %6.0f", All_integral, All_integral_error);
TLegend *calc = new TLegend(.13, 0.50, 0.32, 0.69);
calc->AddEntry(foT1, int_T1);
calc->AddEntry(foU1, int_U1);
calc->AddEntry(foT2, int_T2);
calc->AddEntry(foU2, int_U2);
calc->AddEntry(foT3, int_T3);
calc->AddEntry(foU3, int_U3);
calc->AddEntry(fyAll, int_All);
calc->SetTextSize(0.02);
calc->SetFillColor(0);
calc->Draw();
} // end if (stBFitCase.bDoFit)
gPad->Update();
TPaveStats *stats_1 = (TPaveStats*)h1->FindObject("stats");
stats_1->SetX1NDC(.32);
stats_1->SetX2NDC(.55);
stats_1->SetY1NDC(.69);
stats_1->SetY2NDC(.94);
gPad->Update();
c_BFit->Modified();
outfile->WriteTObject(c_BFit);
outfile->WriteTObject(h1);
if (stBFitCase.bMonteCarlo) {
TH1D *h_DDC = (TH1D*)f->Get("h_DDC_cyctime");
TH1D *h_DT1 = (TH1D*)f->Get("h_DT1_cyctime");
TH1D *h_DT2 = (TH1D*)f->Get("h_DT2_cyctime");
TH1D *h_DT3 = (TH1D*)f->Get("h_DT3_cyctime");
TH1D *h_DU1 = (TH1D*)f->Get("h_DU1_cyctime");
TH1D *h_DU2 = (TH1D*)f->Get("h_DU2_cyctime");
TH1D *h_DU3 = (TH1D*)f->Get("h_DU3_cyctime");
h2->SetLineColor(kBlack);
if (stBFitCase.bHasDDC) h_DDC->SetLineColor(kBlack);
// h_DT1->SetLineColor(kGreen);
// h_DU1->SetLineColor(kGreen);
// h_DT2->SetLineColor(kBlue);
// h_DU2->SetLineColor(kBlue);
// h_DT3->SetLineColor(kRed);
// h_DU3->SetLineColor(kRed);
if (stBFitCase.bHasDDC) h_DDC->SetLineStyle(7);
// h_DU1->SetLineStyle(7);
// h_DU2->SetLineStyle(7);
// h_DU3->SetLineStyle(7);
if (stBFitCase.bHasDDC) h_DDC->Rebin(dRebinFactor);
// h_DT1->Rebin(dRebinFactor);
// h_DT2->Rebin(dRebinFactor);
// h_DT3->Rebin(dRebinFactor);
// h_DU1->Rebin(dRebinFactor);
// h_DU2->Rebin(dRebinFactor);
// h_DU3->Rebin(dRebinFactor);
//
// fyT1->SetLineColor(kGreen);
// fyT2->SetLineColor(kBlue);
// fyT3->SetLineColor(kRed);
fyU1->SetLineColor(kGreen);
fyU2->SetLineColor(kBlue);
fyU3->SetLineColor(kRed);
// fyU1->SetLineStyle(7);
// fyU2->SetLineStyle(7);
// fyU3->SetLineStyle(7);
// fyT1->SetNpx(nPoints);
// fyT2->SetNpx(nPoints);
// fyT3->SetNpx(nPoints);
fyU1->SetNpx(nPoints);
fyU2->SetNpx(nPoints);
fyU3->SetNpx(nPoints);
h2->GetYaxis()->SetRangeUser(0,yMax);
h2->GetXaxis()->SetRangeUser(-1000,tCyc+1000);
// TCanvas *c_decays_cyctime = new TCanvas("c_decays_cyctime","Decays versus cycle time",945,600);
// h2->Draw();
// fyAll->Draw("SAME");
// if (stBFitCase.bHasDDC) fyDC->Draw("SAME");
// fyT1->Draw("SAME");
// fyT2->Draw("SAME");
// fyT3->Draw("SAME");
// fyU1->Draw("SAME");
// fyU2->Draw("SAME");
// fyU3->Draw("SAME");
// if (stBFitCase.bHasDDC) h_DDC->Draw("SAME");
// h_DT1->Draw("SAME");
// h_DT2->Draw("SAME");
// h_DT3->Draw("SAME");
// h_DU1->Draw("SAME");
// h_DU2->Draw("SAME");
// h_DU3->Draw("SAME");
// gPad->Update();
// TPaveStats *stats_2 = (TPaveStats*)h2->FindObject("stats");
// stats_2->SetX1NDC(.13);
// stats_2->SetX2NDC(.32);
// stats_2->SetY1NDC(.80);
// stats_2->SetY2NDC(.88);
// gPad->Update();
// c_decays_cyctime->Modified();
// outfile->WriteTObject(c_decays_cyctime);
printf("T1 entries: %10d\n",(Int_t)h_DT1->GetEntries());
printf("U1 entries: %10d\n",(Int_t)h_DU1->GetEntries());
printf("T2 entries: %10d\n",(Int_t)h_DT2->GetEntries());
printf("U2 entries: %10d\n",(Int_t)h_DU2->GetEntries());
printf("T3 entries: %10d\n",(Int_t)h_DT3->GetEntries());
printf("U3 entries: %10d\n",(Int_t)h_DU3->GetEntries());
if (stBFitCase.bHasDDC) printf("DC entries: %10d\n",(Int_t)h_DDC->GetEntries());
printf("Total entries: %10d\n",(Int_t)h1->GetEntries());
if (stBFitCase.bHasVWXY) { // used for Monte Carlo data where V, W, X, Y pops are known
TH1D *h_DV1 = (TH1D*)f->Get("h_DV1_cyctime");
TH1D *h_DV2 = (TH1D*)f->Get("h_DV2_cyctime");
TH1D *h_DV3 = (TH1D*)f->Get("h_DV3_cyctime");
TH1D *h_DW1 = (TH1D*)f->Get("h_DW1_cyctime");
TH1D *h_DW2 = (TH1D*)f->Get("h_DW2_cyctime");
TH1D *h_DW3 = (TH1D*)f->Get("h_DW3_cyctime");
TH1D *h_DZ1 = (TH1D*)f->Get("h_DZ1_cyctime");
TH1D *h_DZ2 = (TH1D*)f->Get("h_DZ2_cyctime");
TH1D *h_DZ3 = (TH1D*)f->Get("h_DZ3_cyctime");
TH1D *h_DX2 = (TH1D*)f->Get("h_DX2_cyctime");
TH1D *h_DX3 = (TH1D*)f->Get("h_DX3_cyctime");
TH1D *h_DY2 = (TH1D*)f->Get("h_DY2_cyctime");
TH1D *h_DY3 = (TH1D*)f->Get("h_DY3_cyctime");
HistPrep(h_DT1,dRebinFactor,dBinWidth,"T");
HistPrep(h_DT2,dRebinFactor,dBinWidth,"T");
HistPrep(h_DT3,dRebinFactor,dBinWidth,"T");
HistPrep(h_DV1,dRebinFactor,dBinWidth,"V");
HistPrep(h_DV2,dRebinFactor,dBinWidth,"V");
HistPrep(h_DV3,dRebinFactor,dBinWidth,"V");
HistPrep(h_DW1,dRebinFactor,dBinWidth,"W");
HistPrep(h_DW2,dRebinFactor,dBinWidth,"W");
HistPrep(h_DW3,dRebinFactor,dBinWidth,"W");
HistPrep(h_DZ1,dRebinFactor,dBinWidth,"Z");
HistPrep(h_DZ2,dRebinFactor,dBinWidth,"Z");
HistPrep(h_DZ3,dRebinFactor,dBinWidth,"Z");
HistPrep(h_DX2,dRebinFactor,dBinWidth,"X");
HistPrep(h_DX3,dRebinFactor,dBinWidth,"X");
HistPrep(h_DY2,dRebinFactor,dBinWidth,"Y");
HistPrep(h_DY3,dRebinFactor,dBinWidth,"Y");
/* h_DV1 ->Rebin(dRebinFactor);
h_DV2 ->Rebin(dRebinFactor);
h_DV3 ->Rebin(dRebinFactor);
h_DW1 ->Rebin(dRebinFactor);
h_DW2 ->Rebin(dRebinFactor);
h_DW3 ->Rebin(dRebinFactor);
h_DZ1 ->Rebin(dRebinFactor);
h_DZ2 ->Rebin(dRebinFactor);
h_DZ3 ->Rebin(dRebinFactor);
h_DX2 ->Rebin(dRebinFactor);
h_DX3 ->Rebin(dRebinFactor);
h_DY2 ->Rebin(dRebinFactor);
h_DY3 ->Rebin(dRebinFactor);
h_DV1->SetLineColor(kBlack);
h_DV2->SetLineColor(kBlack);
h_DV3->SetLineColor(kBlack);
h_DX2->SetLineColor(kBlack);
h_DY2->SetLineColor(kBlack);
h_DX3->SetLineColor(kBlack);
h_DY3->SetLineColor(kBlack);
*/
// h_DX2->SetLineStyle(8);
// h_DY2->SetLineStyle(3);
// h_DX3->SetLineStyle(8);
// h_DY3->SetLineStyle(3);
TH1D *h_DU2_1 = (TH1D*)h_DU2->Rebin(1,"h_DU2_1");
TH1D *h_DU3_1 = (TH1D*)h_DU3->Rebin(1,"h_DU3_1");
h_DU2_1->SetLineStyle(1);
h_DU3_1->SetLineStyle(1);
h_DU2_1->SetLineColor(kBlack);
h_DU3_1->SetLineColor(kBlack);
TF1 *fyV1 = new TF1("fyV1", yV1, 0.0, tCyc, nPars);
TF1 *fyV2 = new TF1("fyV2", yV2, 0.0, tCyc, nPars);
TF1 *fyV3 = new TF1("fyV3", yV3, 0.0, tCyc, nPars);
TF1 *fyW1 = new TF1("fyW1", yW1, 0.0, tCyc, nPars);
TF1 *fyW2 = new TF1("fyW2", yW2, 0.0, tCyc, nPars);
TF1 *fyW3 = new TF1("fyW3", yW3, 0.0, tCyc, nPars);
TF1 *fyZ1 = new TF1("fyZ1", yZ1, 0.0, tCyc, nPars);
TF1 *fyZ2 = new TF1("fyZ2", yZ2, 0.0, tCyc, nPars);
TF1 *fyZ3 = new TF1("fyZ3", yZ3, 0.0, tCyc, nPars);
TF1 *fyX2 = new TF1("fyX2", yX2, 0.0, tCyc, nPars);
TF1 *fyX3 = new TF1("fyX3", yX3, 0.0, tCyc, nPars);
TF1 *fyY2 = new TF1("fyY2", yY2, 0.0, tCyc, nPars);
TF1 *fyY3 = new TF1("fyY3", yY3, 0.0, tCyc, nPars);
FuncPrep(fyT1,par,nPoints,kGreen,2);//9);
FuncPrep(fyT2,par,nPoints,kBlue,2);//9);
FuncPrep(fyT3,par,nPoints,kRed,2);//9);
FuncPrep(fyV1,par,nPoints,kGreen,2);//9);
FuncPrep(fyV2,par,nPoints,kBlue,2);//9);
FuncPrep(fyV3,par,nPoints,kRed,2);//9);
FuncPrep(fyW1,par,nPoints,kGreen,2);//2);
FuncPrep(fyW2,par,nPoints,kBlue,2);//2);
FuncPrep(fyW3,par,nPoints,kRed,2);//2);
FuncPrep(fyZ1,par,nPoints,kGreen,2);//8);
FuncPrep(fyZ2,par,nPoints,kBlue,2);//8);
FuncPrep(fyZ3,par,nPoints,kRed,2);//8);
FuncPrep(fyX2,par,nPoints,kBlue,2);//5);
FuncPrep(fyX3,par,nPoints,kRed,2);//5);
FuncPrep(fyY2,par,nPoints,kBlue,2);
FuncPrep(fyY3,par,nPoints,kRed,2);
/* fyV1->SetParameters(par);
fyV2->SetParameters(par);
fyV3->SetParameters(par);
fyW1->SetParameters(par);
fyW2->SetParameters(par);
fyW3->SetParameters(par);
fyZ1->SetParameters(par);
fyZ2->SetParameters(par);
fyZ3->SetParameters(par);
fyX2->SetParameters(par);
fyX3->SetParameters(par);
fyY2->SetParameters(par);
fyY3->SetParameters(par);
fyV1->SetNpx(nPoints);
fyV2->SetNpx(nPoints);
fyV3->SetNpx(nPoints);
fyW1->SetNpx(nPoints);
fyW2->SetNpx(nPoints);
fyW3->SetNpx(nPoints);
fyZ1->SetNpx(nPoints);
fyZ2->SetNpx(nPoints);
fyZ3->SetNpx(nPoints);
fyX2->SetNpx(nPoints);
fyX3->SetNpx(nPoints);
fyY2->SetNpx(nPoints);
fyY3->SetNpx(nPoints);
fyV1->SetLineColor(kGreen);
fyV2->SetLineColor(kBlue);
fyV3->SetLineColor(kRed);
fyW1->SetLineColor(kGreen);
fyW2->SetLineColor(kBlue);
fyW3->SetLineColor(kRed);
fyZ1->SetLineColor(kGreen);