-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFitCDFLikelihoodPbPb.C
1880 lines (1655 loc) · 92 KB
/
FitCDFLikelihoodPbPb.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
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
#include "fstream"
#include "TLatex.h"
#include "TROOT.h"
#include "TH1F.h"
#include "TSystem.h"
#include "TMath.h"
#include "TFile.h"
#include "AliDielectronBtoJPSItoEle.h"
#include "AliDielectronBtoJPSItoEleCDFfitFCN.h"
#include "AliDielectronBtoJPSItoEleCDFfitHandler.h"
#include "TNtuple.h"
#include "TF1.h"
#include "TDatabasePDG.h"
#include "TCanvas.h"
#include "TFitResult.h"
#include "TFitter.h"
#include "TMinuit.h"
#include "TLegend.h"
// NEW PID SETTINGS
// Input files containing TNtuple for both data and MC.
// The Ntuple can be produced using the method
// MakeNtupleFromDstFilteredTree() and running on the
// standard output of the AliReducedAnalysisFilterTrees
//
TString inputDistr = "./NtuplePP5TeV_DATA_OS.root"; //
TString inputDistrMC = "./NtuplePP5TeV_MC_all.root"; // only prompt J/psi
enum fitParameters {
// x background
kWResolution=0, kWPosL, kWNegL, kWSymL, kLPos, kLNeg, kLSym,
// fb ,fsig
kFb, kFsig,
// signal invariant mass
kMean, kNexp, kSigma, kAlpha, kNormSig,
// background invariant mass
kNormBkg, kMeanBkg, kSlopeBkg, kConstBkg,
// resolution FF
kWG1FF, kWG2FF, kMeanG1FF, kResG1FF, kMeanG2FF, kResG2FF, kAlphaResFF, kLambdaResFF, kNormPowerLawFF,
// resolution FS
kWG1FS, kWG2FS, kMeanG1FS, kResG1FS, kMeanG2FS, kResG2FS, kAlphaResFS, kLambdaResFS, kNormPowerLawFS,
// resolution SS
kWG1SS, kWG2SS, kMeanG1SS, kResG1SS, kMeanG2SS, kResG2SS, kAlphaResSS, kLambdaResSS, kNormPowerLawSS,
// additional parameters background
kLSym1, kWSym1L,
// additional parameters mass
kx4PolMass, kx5PolMass,
// total number of parameters
kNumPar
};
AliDielectronBtoJPSItoEleCDFfitHandler* fithandler=0x0;
const int numParam = kNumPar;
Double_t paramInputValues[numParam];
Bool_t useExpoBkgMass = kFALSE; // use exponential function for background (if false polynomial function is used)
Int_t kPolynOrd = 3; // polyn. order for invariant mass bkg (3, 4, or 5)
TString fitParameterNames[numParam]={
// x background
"WeightResolution", "WPosLm", "WNegLm", "WSymLm", "LPos", "LNeg", "LSym",
// fb ,fsig
"Fb", "Fsig",
// signal invariant mass
"Mean", "Nexp", "Sigma", "Alpha", "NormSig",
// background invariant mass
useExpoBkgMass ? "NormBkg" : "xPolynOrd0",useExpoBkgMass ? "MeanBkg" : "xPolynOrd1", useExpoBkgMass ? "SlopeBkg" : "xPolynOrd2", useExpoBkgMass ? "ConstBkg" : "xPolynOrd3",
// resolution FF
"WG1FF", "WG2FF", "MeanG1FF", "ResG1FF", "MeanG2FF", "ResG2FF", "AlphaResFF", "LambdaResFF", "NormPowerLawFF",
// resolution FS
"WG1FS", "WG2FS", "MeanG1FS", "ResG1FS", "MeanG2FS", "ResG2FS", "AlphaResFS", "LambdaResFS", "NormPowerLawFS",
// resolution SS
"WG1SS", "WG2SS", "MeanG1SS", "ResG1SS", "MeanG2SS", "ResG2SS", "AlphaResSS", "LambdaResSS", "NormPowerLawSS",
// additional parameters background (extra symmetric part, if needed)
"LSym1", "WSym1L",
// additional parameters mass (polynomial bkg)
"xPolynOrd4", "xPolynOrd5",
};
Int_t invMassSignalParam[]={kMean, kNexp, kSigma, kAlpha, kNormSig}; // inv mass signal parameters
Int_t invMassBkgExpoParam[]={kNormBkg, kMeanBkg, kSlopeBkg, kConstBkg, kx4PolMass, kx5PolMass}; // inv mass bkg parameters
//Int_t psProperBkgParam[]={kWPosL, kWNegL, kWSymL, kLPos, kLNeg, kLSym}; // x-background parameters to be fitted
Int_t psProperBkgParam[]={kWPosL, kWNegL, kWSymL, kWSym1L, kLPos, kLNeg, kLSym, kLSym1}; // x-background parameters to be fitted [+additional symmetric part]
Int_t resolutionParamFF[]={kWG1FF, kMeanG1FF, kResG1FF, kWG2FF, kMeanG2FF, kResG2FF, kAlphaResFF, kLambdaResFF, kNormPowerLawFF}; // resol parameters (FF)
Int_t resolutionParamFS[]={kWG1FS, kMeanG1FS, kResG1FS, kWG2FS, kMeanG2FS, kResG2FS, kAlphaResFS, kLambdaResFS, kNormPowerLawFS}; // resol parameters (FS)
Int_t resolutionParamSS[]={kWG1SS, kMeanG1SS, kResG1SS, kWG2SS, kMeanG2SS, kResG2SS, kAlphaResSS, kLambdaResSS, kNormPowerLawSS}; // resol parameters (SS)
// all parameters
Int_t allParam[]={kWResolution, kWPosL, kWNegL, kWSymL, kLPos, kLNeg, kLSym,
kFb, kFsig, kMean, kNexp, kSigma, kAlpha, kNormSig, kNormBkg, kMeanBkg, kSlopeBkg, kConstBkg,
kWG1FF, kWG2FF, kMeanG1FF, kResG1FF, kMeanG2FF, kResG2FF, kAlphaResFF, kLambdaResFF, kNormPowerLawFF,
kWG1FS, kWG2FS, kMeanG1FS, kResG1FS, kMeanG2FS, kResG2FS, kAlphaResFS, kLambdaResFS, kNormPowerLawFS,
kWG1SS, kWG2SS, kMeanG1SS, kResG1SS, kMeanG2SS, kResG2SS, kAlphaResSS, kLambdaResSS, kNormPowerLawSS,
kWSym1L, kLSym1,kx4PolMass, kx5PolMass};
// all parameters (x-backgroud)
Int_t psProperBkgParamAll[]={kWPosL, kWNegL, kWSymL, kWSym1L, kLPos, kLNeg, kLSym, kLSym1}; // x-background parameters (all)
//
enum fitMode {kExtrFb=0, kFitChi2XResolFF, kFitChi2XResolFS, kFitChi2XResolSS, kFitXBkg, kFitChi2SigMass, kFitChi2BkgMass, kFitBkgMass, kFitXBkgMVA, kFitXBkgMVAChi2};
// fit mode option used in the method FitCDFLikelihoodPbPb:
// kExtrFb -> likelihood fit to extract Fsig / Fb
// kFitChi2XResolFF (FS, SS) -> chi2 fit of x-resolution functions (MC) for different candidate's types
// kFitXBkg -> likelihood fit for pseudo-proper decay length background determination
// kFitXBkgMVA (use unbinned likelihood) -> likelihood fit for pseudo-proper decay length background determination separately for candidate's type - pt - mass range (for MVA)
// kFitXBkgMVAChi2 (use chi2) -> likelihood fit for pseudo-proper decay length background determination separately for candidate's type - pt - mass range (for MVA)
// kFitChi2SigMass -> chi2 fit to fix invariant mass signal shape (MC)
// kFitChi2BkgMass -> chi2 fit to fix invariant mass background shape (signal fixed from MC)
// kFitBkgMass -> likelihood fit to fix invariant mass background shape (signal fixed from MC)
//
// all fitted parameters are saved in a file which can be re-used as input to set starting parameters.
//
Double_t Fb =0.0;
Double_t Fsig =0.2;
Double_t weightType[] = {0.,0.,0.};
Double_t weightTypeSignal[] = {0.,0.,0.};
void AddNtupla(TNtuple *ntToFill, TNtuple *ntNew, Double_t ptmin=0., Double_t pmax=200., Double_t mMin = 2., Double_t mMax = 6., Double_t centmin=-1, Double_t centmax=-1);
void SaveParameters(TString filename, Int_t param[], Int_t size);
void SaveParameters(TString filename, Int_t param[], Int_t size, Double_t paramValues[]);
void SetStartingParameters(TString filename);
void SetReleasedParameters(Int_t param[], Int_t npar);
Double_t CDFResolutionFunction(Double_t *x, Double_t *par);
TF1 *SetupResolutionFunction(TString name, Int_t resolutionParam[], Int_t type);
Double_t InvariantMassSignalFunction(Double_t *x, Double_t *par);
TF1* SetupInvariantMassSignalFunction(TString name, Double_t lowEd, Double_t upEd);
Double_t InvariantMassSignalPlusBkgExpoFunction(Double_t *x, Double_t *par);
TF1 *SetupInvariantMassSignalPlusBkgFunction(TString name, Double_t lowEd, Double_t upEd, Bool_t isExpo);
TF1 *SetupBackgroundFunction(TString name, Double_t bkgParam[],TString type);
void SaveFunctions(TString resType, Double_t ptMin, Double_t ptMax, Double_t bandLow, Double_t bandUp);
Double_t CDFxBackgroundFunction(Double_t *x, Double_t *par);
Double_t GetAverageFunctions(Double_t *x, Double_t *par);
Double_t GetAverageFunctionsSignal(Double_t *x, Double_t *par);
void GetParameters(TString filename, Float_t parameters[]);
Double_t GetMeanMass(TNtuple *ntCp, Double_t massMin, Double_t massMax, Double_t ptMin, Double_t ptMax,Int_t type);
Double_t*** ComputeWeightsForInterpolation(TNtuple *ntOrig, Bool_t kQuadratic, Bool_t excludeExt);
Double_t ***LoadResolutionParameters(Double_t ptLimits[]);
void LoadBackgroundFunctionsAndWeights(AliDielectronBtoJPSItoEleCDFfitFCN *likeObj,TString filename, TNtuple *ntCand, Bool_t Quadratic, Bool_t excludeExt);
void FitCDFLikelihoodMVA(TString resType, Double_t ptMin, Double_t ptMax, Double_t bandLow, Double_t bandUp, Bool_t kQuadratic, Double_t centmin=-1, Double_t centmax=-1, Bool_t fixFsig=kFALSE, Bool_t useMixedEvent=kFALSE);
void FitCDFLikelihoodPbPb(Int_t fitmode, Double_t ptMin, Double_t ptMax, Double_t bandLow=2.2, Double_t bandUp=4.0, TString resType="FF;FS",Double_t centmin=-1, Double_t centmax = -1, Bool_t useMixedEvent=kFALSE);
// global var
AliDielectronBtoJPSItoEleCDFfitFCN *likely_obj = 0x0;
AliDielectronBtoJPSItoEleCDFfitFCN *likely_obj_proj = 0x0;
Bool_t computeIntMass = kTRUE;
const Int_t kNbinsMax = 10;
Double_t ptEdges[]={1.5,3.0}; // pt range(s)
//Double_t ptEdges[]={1.5,3.0,5.,10.}; // pt range(s)
Double_t massBins[]={2.5, 2.8, 3.2, 3.6}; // low mass (0) - interp. region (1) - high mass (2)
//Double_t massBins[]={2.70, 2.75, 2.82, 3.2, 3.26, 3.4}; // low mass (0) - interp. region (1) - high mass (2)
Int_t extrRegion = 1; // interp. region
Int_t kPtBins = sizeof(ptEdges)/sizeof(Double_t)-1;
Int_t kMassBins = sizeof(massBins)/sizeof(Double_t)-1;
Int_t kTypes = 3;
Float_t nCandPtMassWnd[kNbinsMax][kNbinsMax][kNbinsMax];
Float_t nCandPtMassWndSignal[kNbinsMax][kNbinsMax];
void FitCDFLikelihoodPbPb(Int_t fitmode, Double_t ptMin, Double_t ptMax, Double_t bandLow, Double_t bandUp, TString resType, Double_t centmin, Double_t centmax,Bool_t useMixedEvent){
///////////////////////////////////////////////////////////////////
//
// Example macro to read local N-Tuples of JPSI
// and bkg candidates and perform log-likelihood
// minimization using the minimization handler class
// origin: [email protected]
//
///////////////////////////////////////////////////////////////////
// Set inv mass / pt limits
//inv mass functions normalized to 1 between bandLow - bandUp
//
// projection of pseudoproper decay length functions drawn in the signal region
Double_t bandLowSignal=2.92;
Double_t bandUpSignal=3.16;
if(kPtBins == 1) {ptEdges[0] = ptMin; ptEdges[1] = ptMax;}
ifstream filenameEdges(Form("inputFiles_%1.1f_%1.1f/massEdges.txt",ptMin,ptMax));
if(filenameEdges) { for(int im=0; im<kMassBins+1; im++) { filenameEdges >> massBins[im]; /*printf("mass %f \n",massBins[im]);*/} }
//
TNtuple *nt=new TNtuple("ntuplaSigna_new","NtuplaSignal","Xdecaytime:Mass:Type:Pt");
TString inputFileName = inputDistr;
//if(fitmode == kFitChi2XResolFF || fitmode == kFitChi2XResolFS || fitmode==kFitChi2XResolSS || fitmode == kFitChi2SigMass) { inputFileName = inputDistrMC; centmin = -1; centmax = -1; }
if(fitmode == kFitChi2XResolFF || fitmode == kFitChi2XResolFS || fitmode==kFitChi2XResolSS || fitmode == kFitChi2SigMass) {
inputFileName = inputDistrMC;
if(fitmode == kFitChi2SigMass) {centmin = -1; centmax = -1;}
}
TFile f(inputFileName);
TFile ftemplate(Form("inputFiles_%1.1f_%1.1f/XtemplateNonPromptJpsi.root",kPtBins > 1 ? ptEdges[0] : ptMin, kPtBins > 1 ? ptEdges[kPtBins] : ptMax)); //template non-prompt J/psi
TH1F *hCsiMCEvtGen = (TH1F*)ftemplate.Get("psTemplate");
Double_t integral = 0;
for(int i=1;i<hCsiMCEvtGen->GetNbinsX()+1; i++) integral += (hCsiMCEvtGen->GetBinContent(i)*hCsiMCEvtGen->GetBinWidth(i));
hCsiMCEvtGen->Scale(1./integral);
Double_t* x=0x0; Double_t* m=0x0; Double_t *pt =0x0; Int_t* type=0; Int_t n=0;
AliDielectronBtoJPSItoEle* aBtoJPSItoEle =new AliDielectronBtoJPSItoEle();
// set all starting parameters
SetStartingParameters(Form("inputFiles_%1.1f_%1.1f/startingParameters.root",kPtBins > 1 ? ptEdges[0] : ptMin, kPtBins > 1 ? ptEdges[kPtBins] : ptMax));
// set inv mass signal parameters
if(fitmode != kFitChi2SigMass) SetStartingParameters(Form("inputFiles_%1.1f_%1.1f/InvariantMassSignalMC.root",kPtBins > 1 ? ptEdges[0]: ptMin, kPtBins > 1 ? ptEdges[kPtBins] : ptMax));
// set inv mass signal parameters
if(fitmode < kFitChi2SigMass || fitmode > kFitBkgMass) {
TString resTypeSt = resType;
resTypeSt.ReplaceAll(";","_");
if(useMixedEvent) SetStartingParameters(Form("inputFiles_%1.1f_%1.1f/InvariantMassBkgME%s_.root",kPtBins > 1 ? ptEdges[0]: ptMin, kPtBins > 1 ? ptEdges[kPtBins] : ptMax,resTypeSt.Data()));
else SetStartingParameters(Form("inputFiles_%1.1f_%1.1f/InvariantMassBkgExpoChi2Fit.root",kPtBins > 1 ? ptEdges[0]: ptMin, kPtBins > 1 ? ptEdges[kPtBins] : ptMax));
}
//if(fitmode < kFitChi2SigMass) SetStartingParameters(Form("inputFiles_%1.1f_%1.1f/InvariantMassBkgExpoChi2Fit.root",kPtBins > 1 ? ptEdges[0]: ptMin, kPtBins > 1 ? ptEdges[kPtBins] : ptMax));
//if(fitmode < kFitChi2SigMass) SetStartingParameters(Form("inputFiles_%1.1f_%1.1f/InvariantMassBkgME.root",kPtBins > 1 ? ptEdges[0]: ptMin, kPtBins > 1 ? ptEdges[kPtBins] : ptMax));
// set resol parameters -> overwrite only resolution parameters
//
if(fitmode == kFitXBkg || fitmode == kFitXBkgMVA || fitmode == kExtrFb || fitmode == kFitXBkgMVAChi2){
SetStartingParameters(Form("inputFiles_%1.1f_%1.1f/XResolParametersFF_%1.1f_%1.1f.root",kPtBins > 1 ? ptEdges[0]: ptMin, kPtBins > 1 ? ptEdges[kPtBins] : ptMax, ptMin, ptMax));
SetStartingParameters(Form("inputFiles_%1.1f_%1.1f/XResolParametersFS_%1.1f_%1.1f.root",kPtBins > 1 ? ptEdges[0]: ptMin, kPtBins > 1 ? ptEdges[kPtBins] : ptMax, ptMin, ptMax));
SetStartingParameters(Form("inputFiles_%1.1f_%1.1f/XResolParametersSS_%1.1f_%1.1f.root",kPtBins > 1 ? ptEdges[0]: ptMin, kPtBins > 1 ? ptEdges[kPtBins] : ptMax, ptMin, ptMax));
//
if( !(ptMin==1.5 && ptMax==10.0) ){
if(!resType.Contains(";")) SetStartingParameters(Form("inputFiles_1.5_10.0/bkgPtIntegrated/XBkgParameters_mass%1.1f_%1.1f_resType%s_pt1.5_10.0.root",bandLow,bandUp,resType.Data()));
else SetStartingParameters(Form("inputFiles_1.5_10.0/bkgPtIntegrated/XBkgParameters_mass%1.1f_%1.1f_resTypeFF_pt1.5_10.0.root",bandLow,bandUp));
}else{
// starting parameters for centrality (10-30%)
if(centmin==10 && centmax==30){
TString massR;
if(bandLow < 3.0) { massR = "L";
if(bandLow == 2.6) massR.Append("1"); else massR.Append("2"); }
if(bandLow > 3.0) { massR = "H";
if(bandUp == 3.6) massR.Append("2"); else massR.Append("1"); }
SetStartingParameters(Form("startingParametersBkg/XBkgParameters_mass%s_%s_pt1.5_10.0.root",massR.Data(),resType.Data()));
}
}
}
TNtuple *ntOrig=0x0;
ntOrig=(TNtuple*)f.Get("fNtupleJPSI");
if(fitmode==kFitXBkg) {AddNtupla(nt,ntOrig,ptMin,ptMax,2.2,2.6,centmin,centmax); AddNtupla(nt,ntOrig,ptMin,ptMax,3.2,4.0,centmin,centmax); } // add candidates within low+high mass sidebands (pp)
else AddNtupla(nt,ntOrig,ptMin,ptMax,bandLow,bandUp,centmin,centmax); // add candidates in [bandLow, bandUp]
// if resolution function is fitted the corresponding candidate's type is considered
if(fitmode == kFitChi2XResolFF) resType="FF";
else if(fitmode == kFitChi2XResolFS) resType="FS";
else if(fitmode == kFitChi2XResolSS) resType="SS";
aBtoJPSItoEle->SetResTypeAnalysis(resType);
aBtoJPSItoEle->ReadCandidates(nt,x,m,pt,type,n,bandLow,bandUp); // read N-Tuples
printf("+++\n+++ Number of total candidates (prim J/psi + secondary J/psi + bkg) ---> %d candidates \n+++\n",n);
aBtoJPSItoEle->SetFitHandler(x,m,pt,type,n); // Set the fit handler with given values of x, m, # of candidates
aBtoJPSItoEle->CloneMCtemplate(hCsiMCEvtGen); // clone MC template and copy internally
// in this way any model can be setted from outside
aBtoJPSItoEle->SetCsiMC(); // Pass the MC template to the CDF fit function
//AliDielectronBtoJPSItoEleCDFfitHandler*
fithandler = aBtoJPSItoEle->GetCDFFitHandler(); // Get the fit handler
//
// Set some fit options through the handler class
//
if(fitmode==kExtrFb || fitmode==kFitXBkg || fitmode == kFitXBkgMVA || fitmode==kFitBkgMass || fitmode == kFitXBkgMVAChi2) fithandler->SetPrintStatus(kTRUE);
fithandler->SetCrystalBallFunction(kTRUE);
fithandler->SetExponentialFunction(useExpoBkgMass); // kFALSE - polynomial function used
Double_t massLow = (TDatabasePDG::Instance()->GetParticle(443)->Mass()) - bandLow;
Double_t massHigh = bandUp - (TDatabasePDG::Instance()->GetParticle(443)->Mass());
fithandler->SetMassWndLow(massLow);
fithandler->SetMassWndHigh(massHigh);
switch(fitmode)
{
case kExtrFb:
// 2D likelihood fit for fB extraction
paramInputValues[kFb] = 0.10; paramInputValues[kFsig] = 0.010;
paramInputValues[kWSym1L]=0.; paramInputValues[kLSym1]=0.; //bkg Only
fithandler->SetParamStartValues(paramInputValues);
for(int ipar=0; ipar<kNumPar; ipar++) { if(ipar != kFb && ipar !=kFsig) fithandler->FixParam(ipar,kTRUE); }
break;
case kFitXBkg:
case kFitXBkgMVA:
case kFitXBkgMVAChi2:
// likelihood fit for fixing x-bkg parameters (common to all candidate's types)
paramInputValues[kFsig]=0.; paramInputValues[kFb]=0.; //bkg Only
if(ptMin > 3.) { paramInputValues[kWSym1L]=0.; paramInputValues[kLSym1]=0.; } //bkg Only
fithandler->SetParamStartValues(paramInputValues);
SetReleasedParameters(psProperBkgParam,sizeof(psProperBkgParam)/sizeof(Int_t));
if(ptMin > 3.){
fithandler->FixParam(kLPos,kTRUE);
fithandler->FixParam(kLNeg,kTRUE);
// fithandler->FixParam(kLSym,kTRUE);
fithandler->FixParam(kLSym1,kTRUE);
fithandler->FixParam(kWSym1L,kTRUE);
}
break;
case kFitBkgMass:
// likelihood fit to fix inv. mass background shape
paramInputValues[kFsig]=0.2; paramInputValues[kFb]=0.2; //sig+bkg
fithandler->SetParamStartValues(paramInputValues);
Int_t size = sizeof(invMassBkgExpoParam)/sizeof(Int_t);
invMassBkgExpoParam[size] = kFsig;
SetReleasedParameters(invMassBkgExpoParam,size+1);
if(kPolynOrd == 3){
/// fix higher polyn. x^4 and x^5
fithandler->FixParam(kx4PolMass,kTRUE);
fithandler->FixParam(kx5PolMass,kTRUE);
printf("3th polyn. for bkg \n");
}else if(kPolynOrd == 4){
fithandler->FixParam(kx5PolMass,kTRUE); printf("4th polyn. for bkg \n");
}else {printf("5th polyn. for bkg \n");}
break;
}
//fill histos from Ntupla
Int_t nbinsMass = (Int_t)((bandUp - bandLow)/0.04);
TH1F *histMass = new TH1F("histMass","Invariant Mass; InvMass[GeV]; Entries/40MeV",nbinsMass,bandLow,bandUp);
histMass->SetLineColor(1);
histMass->SetMarkerColor(1);
histMass->SetMarkerStyle(20);
histMass->SetMarkerSize(0.7);
Double_t bwidth = 40.; Int_t nbinsX = 300;
if(fitmode == kFitChi2XResolFF || fitmode == kFitChi2XResolFS || fitmode == kFitChi2XResolSS) { bwidth = 10.; nbinsX = 1200; }
TH1F *histpsproper = new TH1F("psproper_decay_length",Form("psproper_decay_length_distrib(%1.1f < M < %1.1f GeV/c^{2});pseudoproper decay length [#mum];Entries/%1.0f#mum",bandLow,bandUp,bwidth),nbinsX,-6000.,6000.);
histpsproper->SetLineColor(1);
histpsproper->SetMarkerColor(1);
histpsproper->SetMarkerStyle(20);
histpsproper->SetMarkerSize(0.7);
Double_t maxWd = 2*6000.; Double_t nBins = 2*300.;
TH1F *histpsproperFF = new TH1F("psproper_decay_length_FF",Form("psproper_decay_length_distrib_FF(%1.1f < M < %1.1f GeV/c^{2});pseudoproper decay length for FF [#mum];Entries/%1.0f#mum",bandLow,bandUp,2.*maxWd/nBins),(Int_t)nBins,-1.*maxWd,maxWd);
histpsproperFF->SetLineColor(1);
histpsproperFF->SetMarkerColor(1);
histpsproperFF->SetMarkerStyle(20);
histpsproperFF->SetMarkerSize(0.7);
TH1F *histpsproperFS = new TH1F("psproper_decay_length_FS",Form("psproper_decay_length_distrib_FS(%1.1f < M < %1.1f GeV/c^{2});pseudoproper decay length for FS [#mum];Entries/%1.0f#mum",bandLow,bandUp,2.*maxWd/nBins),(Int_t)nBins,-1.*maxWd,maxWd);
histpsproperFS->SetLineColor(1);
histpsproperFS->SetMarkerColor(1);
histpsproperFS->SetMarkerStyle(20);
histpsproperFS->SetMarkerSize(0.7);
TH1F *histpsproperSS = new TH1F("psproper_decay_length_SS",Form("psproper_decay_length_distrib_SS(%1.1f < M < %1.1f GeV/c^{2});pseudoproper decay length for SS [#mum];Entries/%1.0f#mum",bandLow,bandUp,2.*maxWd/nBins),(Int_t)nBins,-1.*maxWd,maxWd);
histpsproperSS->SetLineColor(1);
histpsproperSS->SetMarkerColor(1);
histpsproperSS->SetMarkerStyle(20);
histpsproperSS->SetMarkerSize(0.7);
TH1F *histpsproperSignal = new TH1F("psproper_decay_length_signal",Form("psproper_decay_length_distrib(%1.2f < M < %1.2f GeV/c^{2});pseudoproper decay length [#mum];Entries/%1.0f#mum",bandLowSignal,bandUpSignal,bwidth),nbinsX,-6000.,6000.);
histpsproperSignal->SetLineColor(1);
histpsproperSignal->SetMarkerColor(1);
histpsproperSignal->SetMarkerStyle(20);
histpsproperSignal->SetMarkerSize(0.7);
Float_t mass =0.; Float_t psproper = 0.; Float_t typeCand = 0.; Int_t nb = 0;
Float_t ptCand = 0.;
TString arrType[]={"SS","FS","FF"};
nt->SetBranchAddress("Xdecaytime",&psproper);
nt->SetBranchAddress("Mass",&mass);
nt->SetBranchAddress("Type",&typeCand);
nt->SetBranchAddress("Pt",&ptCand);
Int_t fNcurrent=0; Double_t nCandSel = 0 ; Double_t nCandSelSignal=0.;
nb = (Int_t)nt->GetEvent(fNcurrent);
cout << nb << endl;
for(Int_t iev=0; iev<(nt->GetEntries()); iev++){
if(resType.Contains(arrType[(Int_t)typeCand]) && mass > bandLow && mass < bandUp){
nCandSel += 1;
weightType[(Int_t)typeCand] += 1.;
histMass->Fill(mass);
histpsproper->Fill(psproper);
if(mass > bandLowSignal && mass < bandUpSignal) {
histpsproperSignal->Fill(psproper);
weightTypeSignal[(Int_t)typeCand] += 1.;
nCandSelSignal += 1;
}
}
fNcurrent++;
nb = (Int_t) nt->GetEvent(fNcurrent);
}
likely_obj = fithandler->LikelihoodPointer();
likely_obj->SetAllParameters(paramInputValues);
likely_obj->ComputeMassIntegral();
if(fitmode==kExtrFb || fitmode==kFitXBkg || fitmode == kFitXBkgMVA || fitmode==kFitBkgMass || fitmode == kFitXBkgMVAChi2) likely_obj->PrintStatus();
if(fitmode==kFitChi2XResolFF || fitmode==kFitChi2XResolFS || fitmode==kFitChi2XResolSS){
// fit x-resolution using chi2. Parameters are saved in a file that can be
// used for 2D likelihood fit.
TF1 *resolutionFuncFit = 0x0;
if(fitmode==kFitChi2XResolFF) resolutionFuncFit = SetupResolutionFunction("resolutionFuncFF",resolutionParamFF,2);
else if(fitmode==kFitChi2XResolFS) resolutionFuncFit = SetupResolutionFunction("resolutionFuncFS",resolutionParamFF,1);
else if(fitmode==kFitChi2XResolSS) resolutionFuncFit = SetupResolutionFunction("resolutionFuncSS",resolutionParamFS,0);
///
resolutionFuncFit->SetParameter(10,histpsproper->GetEntries()*histpsproper->GetBinWidth(1));
// resolutionFuncFit->Print();
TCanvas *cResolFitChi2 = new TCanvas("XresolutionFit","XresolutionFit");
cResolFitChi2->SetLogy();
Double_t rangeResFit = 6000.;
if(fitmode==kFitChi2XResolSS){
resolutionFuncFit->FixParameter(1,resolutionFuncFit->GetParameter(1));
//resolutionFuncFit->FixParameter(2,resolutionFuncFit->GetParameter(2));
//resolutionFuncFit->FixParameter(6,resolutionFuncFit->GetParameter(6));
//resolutionFuncFit->FixParameter(7,resolutionFuncFit->GetParameter(7));
}
if(ptMin > 3.){
resolutionFuncFit->FixParameter(1,resolutionFuncFit->GetParameter(1));
resolutionFuncFit->FixParameter(4,resolutionFuncFit->GetParameter(4));
resolutionFuncFit->FixParameter(6,resolutionFuncFit->GetParameter(6));
//resolutionFuncFit->FixParameter(7,resolutionFuncFit->GetParameter(7));
}
TFitResultPtr rFitRes = histpsproper->Fit(resolutionFuncFit->GetName(),"S0L","L",-1.*rangeResFit,rangeResFit);
histpsproper->GetYaxis()->SetRangeUser(0.01,histpsproper->GetMaximum()*1.3);
histpsproper->DrawCopy("E");
resolutionFuncFit->Draw("same");
TLatex *latex = new TLatex();
latex->SetNDC();
latex->SetTextFont(42);
latex->SetTextSize(0.035);
latex->SetLineWidth(2);
latex->DrawLatex(0.57, 0.85, Form("#chi^{2}/dof = %4.3f ",(rFitRes->Chi2()/(Double_t)rFitRes->Ndf())));
latex->DrawLatex(0.57, 0.75, Form("%1.1f - %1.1f GeV/c",ptMin,ptMax));
if(fitmode==kFitChi2XResolFF) latex->DrawLatex(0.60, 0.80, "FF");
else if(fitmode==kFitChi2XResolFS) latex->DrawLatex(0.60, 0.80, "FS");
else if(fitmode==kFitChi2XResolSS) latex->DrawLatex(0.60, 0.80, "SS");
cResolFitChi2->SaveAs(Form("inputFiles_%1.1f_%1.1f/resolutionFit%s_%1.1f_%1.1f.pdf",kPtBins > 1 ? ptEdges[0]: ptMin, kPtBins > 1 ? ptEdges[kPtBins] : ptMax, resType.Data(),ptMin,ptMax));
// save parameters
if(fitmode==kFitChi2XResolFF) SaveParameters(Form("inputFiles_%1.1f_%1.1f/XResolParametersFF_%1.1f_%1.1f",kPtBins > 1 ? ptEdges[0]: ptMin, kPtBins > 1 ? ptEdges[kPtBins] : ptMax, ptMin, ptMax),resolutionParamFF,sizeof(resolutionParamFF)/sizeof(Int_t),resolutionFuncFit->GetParameters());
if(fitmode==kFitChi2XResolFS) SaveParameters(Form("inputFiles_%1.1f_%1.1f/XResolParametersFS_%1.1f_%1.1f",kPtBins > 1 ? ptEdges[0]: ptMin, kPtBins > 1 ? ptEdges[kPtBins] : ptMax, ptMin, ptMax),resolutionParamFS,sizeof(resolutionParamFS)/sizeof(Int_t),resolutionFuncFit->GetParameters());
if(fitmode==kFitChi2XResolSS) SaveParameters(Form("inputFiles_%1.1f_%1.1f/XResolParametersSS_%1.1f_%1.1f",kPtBins > 1 ? ptEdges[0]: ptMin, kPtBins > 1 ? ptEdges[kPtBins] : ptMax, ptMin, ptMax),resolutionParamSS,sizeof(resolutionParamSS)/sizeof(Int_t),resolutionFuncFit->GetParameters());
return;
}
if(fitmode==kFitChi2SigMass){
TF1 *invMassSignFuncFit = SetupInvariantMassSignalFunction("invMassSignalFunc", bandLow, bandUp);
TCanvas *cMassSigFitChi2 = new TCanvas("invMassSigFit","invMassSigFit");
invMassSignFuncFit->SetParameter(4, histMass->GetEntries());
histMass->Fit(invMassSignFuncFit->GetName(),"0","",bandLow,bandUp);
histMass->DrawCopy("E");
invMassSignFuncFit->Draw("same");
cMassSigFitChi2->SaveAs(Form("inputFiles_%1.1f_%1.1f/invariantMassSignalMC.pdf",kPtBins > 1 ? ptEdges[0]: ptMin, kPtBins > 1 ? ptEdges[kPtBins] : ptMax));
SaveParameters(Form("inputFiles_%1.1f_%1.1f/InvariantMassSignalMC",kPtBins > 1 ? ptEdges[0]: ptMin, kPtBins > 1 ? ptEdges[kPtBins] : ptMax),invMassSignalParam,sizeof(invMassSignalParam)/sizeof(Int_t),invMassSignFuncFit->GetParameters());
return;
}
if(fitmode==kFitChi2BkgMass){
Int_t sizeSig = sizeof(invMassSignalParam)/sizeof(Int_t);
Int_t sizeBkg = sizeof(invMassBkgExpoParam)/sizeof(Int_t);
// inv mass sig+bkg fit (signal fixed from MC)
TF1 *invMassSigPlusBkg = SetupInvariantMassSignalPlusBkgFunction("SignalPlusBkg", bandLow, bandUp, useExpoBkgMass);
invMassSigPlusBkg->SetParameter(sizeSig+sizeBkg+1, histMass->GetEntries()*histMass->GetBinWidth(1));
if(kPolynOrd == 3){
invMassSigPlusBkg->FixParameter(sizeSig+sizeBkg, 0.); // fix x^5 term
invMassSigPlusBkg->FixParameter(sizeSig+sizeBkg-1, 0.); // fix x^4 term
printf("3th polyn. for bkg \n");
}else if(kPolynOrd == 4){
invMassSigPlusBkg->FixParameter(sizeSig+sizeBkg, 0.); // fix x^5 term
printf("4th polyn. for bkg \n");
} else{
printf("5th polyn. for bkg \n");
}
TCanvas *cMassSigPlusBkgFitChi2 = new TCanvas("invMassSigPlusBkgFit","invMassSigPlusBkgFit");
TFitResultPtr rPsproperBackMass = histMass->Fit(invMassSigPlusBkg->GetName(),"S0","",bandLow,bandUp);
histMass->DrawCopy("E");
computeIntMass = kFALSE; // not needed for drawing
invMassSigPlusBkg->SetLineColor(1);
// draw signal part
TF1 *invMassSigOnly = SetupInvariantMassSignalPlusBkgFunction("Signal", bandLow, bandUp, useExpoBkgMass);
for(int ipar=0; ipar<sizeSig+sizeBkg+2;ipar++) {
if( (ipar < sizeSig+1) || (ipar == sizeSig+sizeBkg+1) ) invMassSigOnly->SetParameter(ipar, invMassSigPlusBkg->GetParameter(ipar));
else invMassSigOnly->SetParameter(ipar, 0.);
}
invMassSigOnly->SetLineColor(2);
invMassSigOnly->Draw("same");
// draw bkg part
TF1 *invMassBkgOnly = SetupInvariantMassSignalPlusBkgFunction("Background", bandLow, bandUp, useExpoBkgMass);
for(int ipar=0; ipar<sizeSig+sizeBkg+2;ipar++) {
if(ipar < sizeSig) invMassBkgOnly->SetParameter(ipar, 0.);
else invMassBkgOnly->SetParameter(ipar, invMassSigPlusBkg->GetParameter(ipar));
}
invMassBkgOnly->SetLineColor(8);
invMassBkgOnly->Draw("same");
invMassSigPlusBkg->Draw("same");
TLatex *tex2 = new TLatex();
tex2->SetNDC();
tex2->SetTextFont(42);
tex2->SetTextSize(0.035);
tex2->SetLineWidth(2);
tex2->DrawLatex(0.14, 0.72, Form("#chi^{2}/dof = %4.3f ",(rPsproperBackMass->Chi2()/(Double_t)rPsproperBackMass->Ndf())));
tex2->DrawLatex(0.14, 0.77, Form("Fsig = %4.3f +- %4.3f ",invMassSigPlusBkg->GetParameter(sizeSig), invMassSigPlusBkg->GetParError(sizeSig)));
tex2->DrawLatex(0.14, 0.82, Form("S[%1.2f-%1.2f GeV/c^{2}] = %4.1f +- %4.1f ",bandLowSignal,bandUpSignal,invMassSigOnly->Integral(bandLowSignal,bandUpSignal)/histMass->GetBinWidth(1), TMath::Sqrt(invMassSigOnly->Integral(bandLowSignal,bandUpSignal)/histMass->GetBinWidth(1))));
cMassSigPlusBkgFitChi2->SaveAs(Form("inputFiles_%1.1f_%1.1f/invariantMassOS_data.pdf",kPtBins > 1 ? ptEdges[0]: ptMin, kPtBins > 1 ? ptEdges[kPtBins] : ptMax));
// save bkg parameters
Double_t bkgParamInvMassFromFit[sizeBkg];
for(int ipar=0; ipar<sizeBkg; ipar++) bkgParamInvMassFromFit[ipar] = invMassSigPlusBkg->GetParameter(fitParameterNames[invMassBkgExpoParam[ipar]]);
SaveParameters(Form("inputFiles_%1.1f_%1.1f/InvariantMassBkgExpoChi2Fit",kPtBins > 1 ? ptEdges[0]: ptMin, kPtBins > 1 ? ptEdges[kPtBins] : ptMax),invMassBkgExpoParam,sizeBkg,bkgParamInvMassFromFit);
std::ofstream ofs;
TString stringmass=Form("%1.2f_%1.2f",bandLow,bandUp);
TString resTypeS = resType; resTypeS.ReplaceAll(";","_");
stringmass.Append(Form("_type%s",resTypeS.Data()));
//ofs.open (Form("fSIGPt%1.2f_%1.2f_%s.txt",ptMin,ptMax,stringmass.Data()), std::ofstream::out | std::ofstream::app);
ofs.open (Form("fSIGPt%1.2f_%1.2f_%s.txt",ptMin,ptMax,stringmass.Data()), std::ofstream::out);
ofs << Form("%f %f \n",invMassSigPlusBkg->GetParameter(sizeSig), invMassSigPlusBkg->GetParError(sizeSig));
ofs.close();
std::ofstream ofsSig2;
stringmass=Form("%1.2f_%1.2f",2.92,3.16);
stringmass.Append(Form("_type%s",resTypeS.Data()));
ofsSig2.open (Form("inputFiles_%1.1f_%1.1f/fSIGPt_%s.txt",ptMin,ptMax,stringmass.Data()), std::ofstream::out);
ofsSig2 << Form("%f \n",invMassSigOnly->Integral(2.92,3.16)/(invMassSigOnly->Integral(2.92,3.16)+invMassBkgOnly->Integral(2.92,3.16)));
ofsSig2.close();
std::ofstream ofsSig3;
stringmass=Form("%1.2f_%1.2f",bandLow,bandUp);
stringmass.Append(Form("_type%s",resTypeS.Data()));
ofsSig3.open (Form("inputFiles_%1.1f_%1.1f/fSIGPt_%s.txt",ptMin,ptMax,stringmass.Data()), std::ofstream::out);
ofsSig3 << Form("%f \n",invMassSigOnly->Integral(bandLow,bandUp)/(invMassSigOnly->Integral(bandLow,bandUp)+invMassBkgOnly->Integral(bandLow,bandUp)));
ofsSig3.close();
return;
}
if(fitmode == kFitXBkgMVAChi2){
Int_t sizeBkg = sizeof(psProperBkgParamAll)/sizeof(Int_t);
Double_t bkgStartingParameters[sizeBkg];
for(int iparam=0; iparam<sizeBkg; iparam++) bkgStartingParameters[iparam+1] = paramInputValues[psProperBkgParamAll[iparam]];
TF1 *psProperBkgFit = SetupBackgroundFunction("XBackground",bkgStartingParameters, resType);
psProperBkgFit->FixParameter(0,10.);
if(!(ptMin == 1.5 && ptMax == 10.0)){
if(ptMin > 1.0){
//
psProperBkgFit->FixParameter(5,psProperBkgFit->GetParameter(5));
if(!(resType.Contains("FS") && ptMin==3. && bandLow>3.)) psProperBkgFit->FixParameter(6,psProperBkgFit->GetParameter(6));
psProperBkgFit->FixParameter(8,psProperBkgFit->GetParameter(8));
if(resType.Contains("FF")) psProperBkgFit->FixParameter(7,psProperBkgFit->GetParameter(7));
if(resType.Contains("FS") && ptMin==3. && bandLow>3.) psProperBkgFit->FixParameter(7,psProperBkgFit->GetParameter(7));
}
}else{
psProperBkgFit->SetParameter(4,20.);
psProperBkgFit->SetParLimits(5, 0.0001,0.003);
psProperBkgFit->SetParLimits(6, 0.0001,0.003);
psProperBkgFit->SetParLimits(7, 0.001,0.1);
psProperBkgFit->SetParLimits(8, 0.00005,0.0003);
/*psProperBkgFit->SetParameter(4,20.);
psProperBkgFit->SetParLimits(5, 0.0001,0.005);
psProperBkgFit->SetParLimits(6, 0.0001,0.005);
psProperBkgFit->SetParLimits(7, 0.001,0.1);
psProperBkgFit->SetParLimits(8, 0.00005,0.0003);*/
}
//
if(resType.Contains("SS")) {
psProperBkgFit->FixParameter(5,psProperBkgFit->GetParameter(5));
psProperBkgFit->FixParameter(6,psProperBkgFit->GetParameter(6));
}
psProperBkgFit->SetParameter(10,histpsproper->GetEntries()/histpsproper->GetBinWidth(1));
psProperBkgFit->Print();
TCanvas *psTotCan = new TCanvas("pseudoProperDecayLengthBkgFitChi2","pseudoProperDecayLengthBkgFitChi2");
psTotCan->cd()->SetLogy();
histpsproper->Fit("XBackground","","L0");
for(int iparam=0; iparam<sizeBkg; iparam++) { paramInputValues[psProperBkgParamAll[iparam]] = psProperBkgFit->GetParameter(iparam+1); printf("param bkg %d -> %f \n",psProperBkgParamAll[iparam],paramInputValues[psProperBkgParamAll[iparam]]); }
fithandler->SetParamStartValues(paramInputValues);
likely_obj->SetAllParameters(paramInputValues);
for(int ipar=0; ipar<kNumPar; ipar++) fithandler->FixParam(ipar,kTRUE);
}
// likelihood fit minimization
aBtoJPSItoEle->DoMinimization();
Double_t FsigFromFit = fithandler->GetParameter(kFsig);
Double_t FbFromFit = fithandler->GetParameter(kFb);
Double_t FsigErr = fithandler->GetParameterError(kFsig);
Double_t FbErr = fithandler->GetParameterError(kFb);
printf("fb = %f #pm %f \n",FbFromFit,FbErr);
printf("fsig = %f #pm %f \n",FsigFromFit,FsigErr);
likely_obj->SetWeightType(weightType[2]/nCandSel,weightType[1]/nCandSel,weightType[0]/nCandSel);
printf("FF %f - FS %f - SS %f ncand %f \n",weightType[2], weightType[1], weightType[0], nCandSel);
// draw psproper total
TLegend *leg=new TLegend(0.17,0.72,0.42,0.88);
if(fitmode != kFitChi2SigMass && fitmode != kFitBkgMass){
TCanvas *psTotCan = new TCanvas("pseudoProperDecayLength","pseudoProperDecayLength");
psTotCan->SetLogy();
Double_t maximum = histpsproper->GetMaximum();
histpsproper->GetYaxis()->SetRangeUser(0.5*maximum/histpsproper->GetEntries(), maximum*1.50);
histpsproper->DrawCopy("E");
TLatex *tex = 0x0;
tex = new TLatex(0.54,0.876,Form("%2.1f < M(e^{+}e^{-}) < %2.1f GeV/c^{2}",bandLow,bandUp));
tex->SetNDC();
tex->SetTextFont(42);
tex->SetTextSize(0.035);
tex->SetLineWidth(2);
tex->Draw();
Double_t normTot = ((Double_t)histpsproper->GetEntries())*histpsproper->GetBinWidth(1);
TF1 *psproperTot = likely_obj->GetEvaluateCDFDecayTimeTotalDistrAllTypes(-1.e+04, 1.e+04,normTot);
psproperTot->SetLineColor(kBlack);
TFitResultPtr rPsproper = histpsproper->Fit(psproperTot->GetName(),"S0Q");
//legend
leg->SetBorderSize(0); leg->SetFillColor(0); leg->SetTextFont(42);
leg->SetFillStyle(0); leg->SetMargin(0.25);
leg->SetEntrySeparation(0.15);
if(fitmode == kExtrFb){
TLatex *lat=new TLatex;
lat->SetNDC(kTRUE);
lat->SetTextColor(1);lat->SetTextFont(42);lat->SetTextSize(.035);
lat->DrawLatex(0.53, 0.82, Form("#chi^{2}/dof = %4.3f ",(rPsproper->Chi2()/(Double_t)rPsproper->Ndf())));
lat->DrawLatex(0.53, 0.72, Form("F_{Sig}[%1.2f - %1.2f] = %4.3f #pm %4.3f", bandLow, bandUp, FsigFromFit, FsigErr));
lat->DrawLatex(0.53, 0.62, Form("F_{B}^{uncorrected} = %4.3f #pm %4.3f", FbFromFit, FbErr));
leg->AddEntry(psproperTot, "fit, all","l");
//prompt jpsi
Double_t normPrompt = (rPsproper->Parameter(0))*FsigFromFit*(1 - FbFromFit);
TF1 *prompt = likely_obj->GetResolutionFuncAllTypes(-1.e+04,1.e+04,normPrompt);
prompt->SetLineColor(2);
prompt->Draw("same");
leg->AddEntry(prompt, "fit, prompt J/#psi","l");
Double_t normSec = (rPsproper->Parameter(0))*FsigFromFit*FbFromFit;
TF1 *templateMC = likely_obj->GetFunBAllTypes(-1.e+04,1.e+04,normSec);
templateMC->SetLineColor(6);
templateMC->SetFillColor(6);
templateMC->SetFillStyle(3005);
templateMC->Draw("same");
leg->AddEntry(templateMC, "fit, secondary J/#psi","l");
Double_t normBkg = (rPsproper->Parameter(0))*(1 - FsigFromFit);
TF1 *psProperBack = (TF1*)(likely_obj->GetEvaluateCDFDecayTimeBkgDistrAllTypes(-1.e+04,1.e+04,normBkg));
psProperBack->SetName(Form("backFuncTotal_pt%1.1f_%1.1f_mass%1.1f_%1.1f",ptMin,ptMax,bandLow,bandUp));
psProperBack->SetLineColor(3);
psProperBack->SetLineWidth(2);
psProperBack->Draw("same");
leg->AddEntry(psProperBack, "fit, bkg","l");
}
if(fitmode == kFitXBkg || fitmode == kFitXBkgMVA || fitmode == kFitXBkgMVAChi2){
//bkg
// Double_t normBkg = (rPsproper->Parameter(0))*(1 - FsigFromFit);
Double_t normBkg = histpsproper->GetEntries()*histpsproper->GetBinWidth(1);
likely_obj->SetFMinus(fithandler->GetParameter(kWNegL));
likely_obj->SetResWeight(fithandler->GetParameter(kWResolution));
likely_obj->SetFPlus(fithandler->GetParameter(kWPosL));
likely_obj->SetFSym(fithandler->GetParameter(kWSymL));
likely_obj->SetFSym1(fithandler->GetParameter(kWSym1L));
likely_obj->SetLamPlus(fithandler->GetParameter(kLPos));
likely_obj->SetLamMinus(fithandler->GetParameter(kLNeg));
likely_obj->SetLamSym(fithandler->GetParameter(kLSym));
likely_obj->SetLamSym1(fithandler->GetParameter(kLSym1));
TF1 *psProperBack = likely_obj->GetEvaluateCDFDecayTimeBkgDistrAllTypes(-1.e+04,1.e+04,normBkg);
TFitResultPtr rPsproperBack = histpsproper->Fit(psProperBack->GetName(),"S0Q");
tex->DrawLatex(0.53, 0.82, Form("#chi^{2}/dof = %4.3f ",(rPsproperBack->Chi2()/(Double_t)rPsproperBack->Ndf())));
std::ofstream ofsbkg;
TString stringmass=Form("_mass%1.2f_%1.2f",bandLow,bandUp);
//for(int im=0; im<kMassBins+1; im++) stringmass.Append(Form("_m%d%1.2f",im+1,massBins[im]));
TString resTypeS = resType; resTypeS.ReplaceAll(";","_");
stringmass.Append(Form("_type%s",resTypeS.Data()));
ofsbkg.open (Form("xbkgChi2_Pt%1.2f_%1.2f%s.txt",kPtBins > 1 ? ptEdges[0]: ptMin, kPtBins > 1 ? ptEdges[kPtBins] : ptMax,stringmass.Data()), std::ofstream::out);
ofsbkg << Form("%f \n",(rPsproperBack->Chi2()/(Double_t)rPsproperBack->Ndf()));
ofsbkg.close();
Double_t normBkgPos = fithandler->GetParameter(kWPosL)/(fithandler->GetParameter(kWResolution)+fithandler->GetParameter(kWPosL)+fithandler->GetParameter(kWNegL)+fithandler->GetParameter(kWSymL)+fithandler->GetParameter(kWSym1L))*normBkg;
likely_obj->SetResWeight(0.);
likely_obj->SetFMinus(0.);
likely_obj->SetFSym(0.);
likely_obj->SetFSym1(0.);
TF1 *psProperBackPos = likely_obj->GetEvaluateCDFDecayTimeBkgDistrAllTypes(-1.e+04,1.e+04,normBkgPos);
psProperBackPos->SetName(Form("backFuncPos_pt%1.1f_%1.1f_mass%1.1f_%1.1f",ptMin,ptMax,bandLow,bandUp));
psProperBackPos->SetLineColor(4);
psProperBackPos->SetLineWidth(2);
psProperBackPos->Draw("same");
Double_t normBkgNeg = fithandler->GetParameter(kWNegL)/(fithandler->GetParameter(kWResolution)+fithandler->GetParameter(kWPosL)+fithandler->GetParameter(kWNegL)+fithandler->GetParameter(kWSymL)+fithandler->GetParameter(kWSym1L))*normBkg;
likely_obj->SetFMinus(fithandler->GetParameter(kWNegL));
likely_obj->SetResWeight(0.);
likely_obj->SetFPlus(0.);
likely_obj->SetFSym(0.);
likely_obj->SetFSym1(0.);
TF1 *psProperBackNeg = likely_obj->GetEvaluateCDFDecayTimeBkgDistrAllTypes(-1.e+04,1.e+04,normBkgNeg);
psProperBackNeg->SetName(Form("backFuncNeg_pt%1.1f_%1.1f_mass%1.1f_%1.1f",ptMin,ptMax,bandLow,bandUp));
psProperBackNeg->SetLineColor(kMagenta);
psProperBackNeg->SetLineWidth(2);
psProperBackNeg->Draw("same");
Double_t normBkgSym = fithandler->GetParameter(kWSymL)/(fithandler->GetParameter(kWResolution)+fithandler->GetParameter(kWPosL)+fithandler->GetParameter(kWNegL)+fithandler->GetParameter(kWSymL)+fithandler->GetParameter(kWSym1L))*normBkg;
likely_obj->SetFSym(fithandler->GetParameter(kWSymL));
likely_obj->SetResWeight(0.);
likely_obj->SetFPlus(0.);
likely_obj->SetFMinus(0.);
likely_obj->SetFSym1(0.);
TF1 *psProperBackSym = likely_obj->GetEvaluateCDFDecayTimeBkgDistrAllTypes(-1.e+04,1.e+04,normBkgSym);
psProperBackSym->SetName(Form("backFuncSym_pt%1.1f_%1.1f_mass%1.1f_%1.1f",ptMin,ptMax,bandLow,bandUp));
psProperBackSym->SetLineColor(kOrange);
psProperBackSym->SetLineWidth(2);
psProperBackSym->Draw("same");
Double_t normBkgSym1 = fithandler->GetParameter(kWSym1L)/(fithandler->GetParameter(kWResolution)+fithandler->GetParameter(kWPosL)+fithandler->GetParameter(kWNegL)+fithandler->GetParameter(kWSymL)+fithandler->GetParameter(kWSym1L))*normBkg;
likely_obj->SetFSym1(fithandler->GetParameter(kWSym1L));
likely_obj->SetResWeight(0.);
likely_obj->SetFPlus(0.);
likely_obj->SetFMinus(0.);
likely_obj->SetFSym(0.);
TF1 *psProperBackSym1 = likely_obj->GetEvaluateCDFDecayTimeBkgDistrAllTypes(-1.e+04,1.e+04,normBkgSym1);
psProperBackSym1->SetName(Form("backFuncSym_pt%1.1f_%1.1f_mass%1.1f_%1.1f",ptMin,ptMax,bandLow,bandUp));
psProperBackSym1->SetLineColor(kGray);
psProperBackSym1->SetLineWidth(2);
psProperBackSym1->Draw("same");
Double_t normBkgResolution = fithandler->GetParameter(kWResolution)/(fithandler->GetParameter(kWResolution)+fithandler->GetParameter(kWPosL)+fithandler->GetParameter(kWNegL)+fithandler->GetParameter(kWSymL)+fithandler->GetParameter(kWSym1L))*normBkg;
likely_obj->SetResWeight(fithandler->GetParameter(kWResolution));
likely_obj->SetFPlus(0.);
likely_obj->SetFMinus(0.);
likely_obj->SetFSym(0.);
likely_obj->SetFSym1(0.);
TF1 *psProperBackResol = likely_obj->GetEvaluateCDFDecayTimeBkgDistrAllTypes(-1.e+04,1.e+04,normBkgResolution);
psProperBackResol->SetName(Form("backFuncResolution_pt%1.1f_%1.1f_mass%1.1f_%1.1f",ptMin,ptMax,bandLow,bandUp));
psProperBackResol->SetLineColor(kRed);
psProperBackResol->SetLineWidth(2);
psProperBackResol->Draw("same");
// }
psProperBack->SetName(Form("backFuncTotal_pt%1.1f_%1.1f_mass%1.1f_%1.1f",ptMin,ptMax,bandLow,bandUp));
psProperBack->SetLineColor(3);
psProperBack->SetLineWidth(2);
psProperBack->Draw("same");
leg->AddEntry(psProperBack, "fit, bkg","l");
// TString resTypeS = resType; resTypeS.ReplaceAll(";","_");
if(fitmode == kFitXBkgMVA || fitmode == kFitXBkgMVAChi2) SaveParameters(Form("inputFiles_%1.1f_%1.1f/XBkgParameters_mass%1.1f_%1.1f_resType%s_pt%1.1f_%1.1f",ptEdges[0],ptEdges[kPtBins],bandLow,bandUp,resTypeS.Data(),ptMin,ptMax),psProperBkgParam,sizeof(psProperBkgParam)/sizeof(Int_t));
else SaveParameters(Form("inputFiles_%1.1f_%1.1f/XBkgParameters",ptMin,ptMax),psProperBkgParam,sizeof(psProperBkgParam)/sizeof(Int_t));
psTotCan->SaveAs(Form("inputFiles_%1.1f_%1.1f/XBkgProjection_mass%1.1f_%1.1f_types%s_pt%1.1f_%1.1f.pdf",kPtBins > 1 ? ptEdges[0]: ptMin, kPtBins > 1 ? ptEdges[kPtBins] : ptMax,bandLow,bandUp,resTypeS.Data(),ptMin,ptMax));
psTotCan->SaveAs(Form("inputFiles_%1.1f_%1.1f/XBkgProjection_mass%1.1f_%1.1f_types%s_pt%1.1f_%1.1f.root",kPtBins > 1 ? ptEdges[0]: ptMin, kPtBins > 1 ? ptEdges[kPtBins] : ptMax,bandLow,bandUp,resTypeS.Data(),ptMin,ptMax));
// save bkg function
if(fitmode == kFitXBkgMVA || fitmode == kFitXBkgMVAChi2) SaveFunctions(resType, ptMin, ptMax, bandLow, bandUp); // save functions for likelihood fit
}
leg->Draw("same");
if(fitmode == kExtrFb) { psproperTot->Draw("same"); psTotCan->SaveAs(Form("inputFiles_%1.1f_%1.1f/LikelihoodFitProjWholeMass.root",ptMin,ptMax)); }
}
Double_t FsigNew=0.; Double_t FsigNewErr=0.;
if(fitmode == kFitBkgMass || fitmode == kExtrFb){
// draw invariant mass
Double_t normMass =((Double_t)histMass->GetEntries())*histMass->GetBinWidth(1);
TF1 *invMassFunc = likely_obj->GetEvaluateCDFInvMassTotalDistr(bandLow,bandUp,normMass);
invMassFunc->SetLineColor(kBlack);
TCanvas *invMassCan = new TCanvas("invMassCanvas","invMassCanvas");
invMassCan->cd();
TFitResultPtr rMass = histMass->Fit(invMassFunc->GetName(),"S0Q");
histMass->DrawCopy("E");
invMassFunc->SetLineColor(1);
Double_t intTot = invMassFunc->Integral(bandLow,bandUp);
TLatex *lat=new TLatex;
lat->SetNDC(kTRUE);
lat->SetTextColor(1);lat->SetTextFont(42);lat->SetTextSize(.035);
if(fitmode == kFitBkgMass || fitmode == kExtrFb) lat->DrawLatex(0.53, 0.82, Form("#chi^{2}/dof = %4.2f ",(rMass->Chi2()/(Double_t)rMass->Ndf())));
invMassFunc->SetChisquare(rMass->Ndf());
invMassFunc->SetNDF(rMass->Ndf());
if(fitmode == kFitBkgMass || fitmode == kExtrFb) lat->DrawLatex(0.53, 0.72, Form("F_{Sig}[%1.2f - %1.2f] = %4.3f #pm %4.3f", bandLow, bandUp, FsigFromFit, FsigErr));
TLegend *legMass=new TLegend(0.17,0.72,0.42,0.88);
legMass->SetBorderSize(0); legMass->SetFillColor(0); legMass->SetTextFont(42);
legMass->SetFillStyle(0); legMass->SetMargin(0.25);
legMass->SetEntrySeparation(0.15);
TF1 *invMassSig = likely_obj->GetEvaluateCDFInvMassSigDistr(bandLow,bandUp,intTot*FsigFromFit);
TF1 *invMassBkg = likely_obj->GetEvaluateCDFInvMassBkgDistr(bandLow,bandUp,intTot*(1.-FsigFromFit));
invMassSig->SetLineColor(4);
invMassBkg->SetLineColor(3);
invMassSig->Draw("same");
legMass->AddEntry(invMassSig, "fit, signal","l");
if(fitmode == kFitBkgMass || fitmode == kExtrFb){
invMassBkg->Draw("same");
invMassFunc->Draw("same");
legMass->AddEntry(invMassBkg, "fit, background","l");
legMass->AddEntry(invMassFunc, "fit, all","l");
}
legMass->Draw("same");
Double_t integSig = invMassSig->Integral(bandLowSignal,bandUpSignal);
Double_t integBkg = invMassBkg->Integral(bandLowSignal,bandUpSignal);
FsigNew = integSig/(integSig+integBkg);
FsigNewErr = (FsigNew*FsigErr)/FsigFromFit;
if(fitmode == kFitBkgMass) SaveParameters(Form("inputFiles_%1.1f_%1.1f/InvMassBkgExpoLikelihoodFit",ptMin,ptMax),invMassBkgExpoParam,sizeof(invMassBkgExpoParam)/sizeof(Int_t));
if(fitmode == kExtrFb) invMassCan->SaveAs(Form("inputFiles_%1.1f_%1.1f/LikelihoodFitInvariantMass.root",ptMin,ptMax));
}
// save all parameters -> can be re-used as input
if(fitmode == kExtrFb) SaveParameters(Form("inputFiles_%1.1f_%1.1f/startingParametersLast",ptMin,ptMax),allParam,sizeof(allParam)/sizeof(Int_t));
if(fitmode == kExtrFb){
// draw pseudo-proper decay length projections under the signal region
AliDielectronBtoJPSItoEleCDFfitFCN *likely_obj_proj = 0x0;
AliDielectronBtoJPSItoEle* aBtoJPSItoEle_proj =new AliDielectronBtoJPSItoEle();
aBtoJPSItoEle_proj->SetResTypeAnalysis(resType);
for(int j =0; j < kNumPar; j++) {paramInputValues[j] = fithandler->GetParameter(j);}
paramInputValues[kFsig] = FsigNew;
Double_t* xx=0x0; Double_t* mm=0x0; Double_t *ppt=0; Int_t*tt=0; Int_t nn=0;
aBtoJPSItoEle_proj->ReadCandidates(nt,xx,mm,ppt,tt,nn,bandLowSignal,bandUpSignal,ptMin,ptMax);
aBtoJPSItoEle_proj->SetFitHandler(xx,mm,ppt,tt,nn);
aBtoJPSItoEle_proj->CloneMCtemplate(hCsiMCEvtGen);
aBtoJPSItoEle_proj->SetCsiMC();
AliDielectronBtoJPSItoEleCDFfitHandler* fithandler_proj = aBtoJPSItoEle_proj->GetCDFFitHandler();
fithandler_proj->SetPrintStatus(kTRUE);
fithandler_proj->SetParamStartValues(paramInputValues);
fithandler_proj->SetCrystalBallFunction(kTRUE);
fithandler_proj->SetMassWndLow((TDatabasePDG::Instance()->GetParticle(443)->Mass()) - bandLowSignal);
fithandler_proj->SetMassWndHigh(bandUpSignal - (TDatabasePDG::Instance()->GetParticle(443)->Mass()));
likely_obj_proj = fithandler_proj->LikelihoodPointer();
likely_obj_proj->SetAllParameters(paramInputValues);
likely_obj_proj->SetWeightType(weightTypeSignal[2]/nCandSelSignal,weightTypeSignal[1]/nCandSelSignal,weightTypeSignal[0]/nCandSelSignal);
likely_obj_proj->ComputeMassIntegral();
// likely_obj_proj->PrintStatus();
//
TCanvas *psSignalCan = new TCanvas("pseudoProperDecayLengthSignal","pseudoProperDecayLengthSignal");
psSignalCan->SetLogy();
Double_t maximum = histpsproperSignal->GetMaximum();
histpsproperSignal->GetYaxis()->SetRangeUser(0.5*maximum/histpsproperSignal->GetEntries(), maximum*1.50);
histpsproperSignal->GetXaxis()->SetRangeUser(-3000.,3000.);
histpsproperSignal->DrawCopy("E");
TLatex *tex = 0x0;
tex = new TLatex(0.54,0.876,Form("%2.1f < M(e^{+}e^{-}) < %2.1f GeV/c^{2}",bandLowSignal,bandUpSignal));
tex->SetNDC();
tex->SetTextFont(42);
tex->SetTextSize(0.035);
tex->SetLineWidth(2);
tex->Draw();
Double_t normPsSignal = ((Double_t)histpsproperSignal->GetEntries())*histpsproperSignal->GetBinWidth(1);
TF1 *psproperTot_sig = likely_obj_proj->GetEvaluateCDFDecayTimeTotalDistrAllTypes(-1.e+04, 1.e+04, normPsSignal);
psproperTot_sig->SetLineColor(kBlack);
psproperTot_sig->SetName("psProperTotal_sig");
TFitResultPtr rPsproper_sig = histpsproperSignal->Fit(psproperTot_sig->GetName(),"S0Q");
tex->SetNDC(kTRUE);
tex->SetTextColor(1);tex->SetTextFont(42);tex->SetTextSize(.035);
tex->DrawLatex(0.53, 0.82, Form("#chi^{2}/dof = %4.3f ",(rPsproper_sig->Chi2()/(Double_t)rPsproper_sig->Ndf())));
tex->DrawLatex(0.53, 0.72, Form("F_{Sig}(scaled)[%1.2f-%1.2f] = %4.3f #pm %4.3f", bandLowSignal, bandUpSignal, FsigNew,FsigNewErr));
tex->DrawLatex(0.53, 0.62, Form("F_{B}^{uncorrected} = %4.3f #pm %4.3f", FbFromFit, FbErr));
///
Double_t normPromptSig = (normPsSignal)*FsigNew*(1 - FbFromFit);
TF1 *prompt_sig = likely_obj_proj->GetResolutionFuncAllTypes(-1.e+04,1.e+04,normPromptSig);
prompt_sig->SetLineColor(2);
prompt_sig->Draw("same");
Double_t normSecSig = (normPsSignal)*FsigNew*FbFromFit;
TF1 *templateMC_sig = likely_obj_proj->GetFunBAllTypes(-1.e+04,1.e+04,normSecSig);
templateMC_sig->SetLineColor(6);
templateMC_sig->SetFillColor(6);
templateMC_sig->SetFillStyle(3005);
templateMC_sig->Draw("same");
Double_t normBkgSig = (normPsSignal)*(1 - FsigNew);
TF1 *psProperBack_sig = likely_obj_proj->GetEvaluateCDFDecayTimeBkgDistrAllTypes(-1.e+04,1.e+04,normBkgSig);
psProperBack_sig->SetLineColor(3);
psProperBack_sig->Draw("same");
psproperTot_sig->Draw("same");
leg->Draw("same");
psSignalCan->SaveAs(Form("inputFiles_%1.1f_%1.1f/LikelihoodFitProjSignalRegionMass.root",ptMin,ptMax));
}
return;
}
void FitCDFLikelihoodMVA(TString resType, Double_t ptMin, Double_t ptMax, Double_t bandLow, Double_t bandUp, Bool_t kQuadratic, Double_t centmin, Double_t centmax, Bool_t fixFsig, Bool_t useMixedEvent){
///////////////////////////////////////////////////////////////////
// Set inv mass / pt limits
//inv mass functions normalized to 1 between bandLow - bandUp
//
// projection of pseudoproper decay length functions drawn in the signal region
Double_t bandLowSignal=2.92;
Double_t bandUpSignal=3.16;
Double_t fsigFrom1D = -1.;
TString resTypeS = resType; resTypeS.ReplaceAll(";","_");
if(kPtBins == 1) {ptEdges[0] = ptMin; ptEdges[1] = ptMax;}
ifstream filenameEdges(Form("inputFiles_%1.1f_%1.1f/massEdges.txt",ptMin,ptMax));
if(filenameEdges) { for(int im=0; im<kMassBins+1; im++) { filenameEdges >> massBins[im]; /*printf("mass %f \n",massBins[im]);*/} }
if(fixFsig){
ifstream filenameFsig;
if(useMixedEvent) filenameFsig.open(Form("inputFiles_%1.1f_%1.1f/FractionOfSignalMass%s_.txt",ptMin,ptMax,resTypeS.Data()));
else filenameFsig.open(Form("inputFiles_%1.1f_%1.1f/fSIGPt_%1.2f_%1.2f_type%s.txt",ptMin,ptMax,bandLow,bandUp,resTypeS.Data()));
if(filenameFsig) {filenameFsig >> fsigFrom1D; printf("Fsig from 1D in %1.2f-%1.2f GeV/c^{2} -> %1.2f",bandLow,bandUp,fsigFrom1D); }
}
//
TFile f(inputDistr); // input: data
TFile ftemplate(Form("inputFiles_%1.1f_%1.1f/XtemplateNonPromptJpsi.root",ptMin,ptMax));
TH1F *hCsiMCEvtGen = (TH1F*)ftemplate.Get("psTemplate");
Double_t integral = 0;
for(int i=1;i<hCsiMCEvtGen->GetNbinsX()+1; i++) integral += (hCsiMCEvtGen->GetBinContent(i)*hCsiMCEvtGen->GetBinWidth(i));
hCsiMCEvtGen->Scale(1./integral);
Double_t* x=0x0; Double_t* m=0x0; Double_t *pt =0x0; Int_t* type=0; Int_t n=0;
AliDielectronBtoJPSItoEle* aBtoJPSItoEle =new AliDielectronBtoJPSItoEle();
TNtuple *ntOrig=0x0;
ntOrig=(TNtuple*)f.Get("fNtupleJPSI");
TNtuple *nt=new TNtuple("ntuplaSigna_new","NtuplaSignal","Xdecaytime:Mass:Type:Pt",10000000);
AddNtupla(nt,ntOrig,ptMin,ptMax,bandLow,bandUp,centmin,centmax); // add candidates in [bandLow, bandUp]
// set all starting parameters
SetStartingParameters(Form("inputFiles_%1.1f_%1.1f/startingParameters.root",ptMin,ptMax));
// set inv mass signal parameters
SetStartingParameters(Form("inputFiles_%1.1f_%1.1f/InvariantMassSignalMC.root",ptMin,ptMax));
// set inv mass signal parameters
//SetStartingParameters(Form("inputFiles_%1.1f_%1.1f/InvariantMassBkgExpoChi2Fit.root",ptMin,ptMax));
if(useMixedEvent) SetStartingParameters(Form("inputFiles_%1.1f_%1.1f/InvariantMassBkgME%s_.root",ptMin,ptMax,resTypeS.Data()));
else SetStartingParameters(Form("inputFiles_%1.1f_%1.1f/InvariantMassBkgExpoChi2Fit.root",ptMin,ptMax));
aBtoJPSItoEle->SetResTypeAnalysis(resType);
aBtoJPSItoEle->ReadCandidates(nt,x,m,pt,type,n,bandLow,bandUp); // read N-Tuples
printf("+++\n+++ Number of total candidates (prim J/psi + secondary J/psi + bkg) ---> %d candidates \n+++\n",n);
aBtoJPSItoEle->SetFitHandler(x,m,pt,type,n); // Set the fit handler with given values of x, m, # of candidates
aBtoJPSItoEle->CloneMCtemplate(hCsiMCEvtGen); // clone MC template and copy internally
// in this way any model can be setted from outside
aBtoJPSItoEle->SetCsiMC(); // Pass the MC template to the CDF fit function
fithandler = aBtoJPSItoEle->GetCDFFitHandler(); // Get the fit handler
//
// Set some fit options through the handler class
//
fithandler->SetPrintStatus(kTRUE);
fithandler->SetCrystalBallFunction(kTRUE);
fithandler->SetExponentialFunction(useExpoBkgMass); // kFALSE - polynomial function used
Double_t massLow = (TDatabasePDG::Instance()->GetParticle(443)->Mass()) - bandLow;
Double_t massHigh = bandUp - (TDatabasePDG::Instance()->GetParticle(443)->Mass());
fithandler->SetMassWndLow(massLow);
fithandler->SetMassWndHigh(massHigh);
// 2D likelihood fit for fB extraction
paramInputValues[kFb] = 0.10; paramInputValues[kFsig] = 0.010;
if(fixFsig) paramInputValues[kFsig] = fsigFrom1D;
fithandler->SetParamStartValues(paramInputValues);
for(int ipar=0; ipar<kNumPar; ipar++) { if(ipar != kFb && ipar !=kFsig) fithandler->FixParam(ipar,kTRUE); }
if(fixFsig) fithandler->FixParam(kFsig,kTRUE);
//for(int ipar=0; ipar<kNumPar; ipar++) { if(ipar != kFb) fithandler->FixParam(ipar,kTRUE); }
likely_obj = fithandler->LikelihoodPointer();
likely_obj->SetAllParameters(paramInputValues);
likely_obj->ComputeMassIntegral();
likely_obj->PrintStatus();
// MVA settings
likely_obj->SetMultivariateFit(kTRUE);
likely_obj->InitializeFunctions(kPtBins,kMassBins);
// masswindows
TArrayD *massWind =new TArrayD(kMassBins+1); // mass windows to define signal and adiacent regions
for(int im=0; im<kMassBins+1; im++) massWind->AddAt(massBins[im],im);
likely_obj->SetMassWindows(massWind);
TArrayD *ptWind = new TArrayD(kPtBins+1); // pt windows
for(int ipt=0; ipt<kPtBins+1; ipt++) ptWind->AddAt(ptEdges[ipt],ipt);
likely_obj->SetPtWindows(ptWind);
// set interpolation region
likely_obj->SetExtrapolationRegion(extrRegion);
//
//fill histos from Ntupla
Int_t nbinsMass = (Int_t)((bandUp - bandLow)/0.04);
TH1F *histMass = new TH1F("histMass","Invariant Mass; InvMass[GeV]; Entries/40MeV",nbinsMass,bandLow,bandUp);
histMass->SetLineColor(1);
histMass->SetMarkerColor(1);
histMass->SetMarkerStyle(20);
histMass->SetMarkerSize(0.7);
TH1F *histpsproper = new TH1F("psproper_decay_length",Form("psproper_decay_length_distrib(%1.1f < M < %1.1f GeV/c^{2});pseudoproper decay length [#mum];Entries/40#mum",bandLow,bandUp),300,-6000.,6000.);
histpsproper->SetLineColor(1);
histpsproper->SetMarkerColor(1);
histpsproper->SetMarkerStyle(20);
histpsproper->SetMarkerSize(0.7);
TH1F *histpsproperSignal = new TH1F("psproper_decay_length_signal",Form("psproper_decay_length_distrib(%1.2f < M < %1.2f GeV/c^{2});pseudoproper decay length [#mum];Entries/40#mum",bandLowSignal,bandUpSignal),300,-6000.,6000.);
histpsproperSignal->SetLineColor(1);