-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAnalysis.C
1398 lines (1216 loc) · 75.5 KB
/
Analysis.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
//
// Analysis.C
//
// A simple AA analysis code.
// Created by Ivan Heredia de la Cruz on 4/25/16.
// Developed by Leonardo Cristella
//
// root -l
// .x myPDF.cxx+
// .x allOtherNeededClasses.cxx+
// .x Analysis.C+
//
// or
// time root -l -b -q run_Analysys.sh > log.txt
//
// or
// root -l -b load_Analysys.sh
// to load libraries and run with custom flags
//
#include "RooGlobalFunc.h"
#include "RooRealVar.h"
#include "RooDataSet.h"
#include "TCanvas.h"
#include "TAxis.h"
#include "RooPlot.h"
#include "TROOT.h"
#include "TMath.h"
#include "TH2.h"
#include "RooFitResult.h"
#include <vector>
#include <utility> // std::make_pair
#include "TLegend.h"
#include "RooConstVar.h"
#include "RooGenericPdf.h"
#include "RooExtendPdf.h"
#include "RooAddPdf.h"
#include "RooProdPdf.h"
#include "RooAddition.h"
#include "RooMinuit.h"
#include "RooHistPdf.h"
#include "RooDataHist.h"
//#include "RooNDKeysPdf.h"
#include "RooBinning.h"
#include "RooGaussian.h"
#include <sys/time.h> // for timeval
#include <sys/times.h> // for tms
//#include <time.h>
//#include <ctime>
#include "TSystem.h" // to get number of CPUs
#include "TStyle.h" // to use gStyle
#include <TFile.h>
#include <TNtupleD.h>
#include "TPaveText.h"
#include "TPaletteAxis.h"
#include "myPDF.h"
#include "Dalitz_contour.h"
#include "effMasses.h"
#include "Angles_contour.h"
#include "sqDalitz_contour.h"
#include "twoDFit.C"
#include "twoD_chiSquare.C"
#include "initialAmpVal.h"
using namespace RooFit ;
//#define TIME_INFO
#ifdef TIME_INFO
timeval start, stop;
clock_t startCPU, stopCPU;
tms startProc, stopProc;
#endif
Float_t TH2_offset = 1.6;
void setBinning(const TH2* hist, Float_t& xMin, Float_t& xMax, Float_t& yMin, Float_t& yMax, RooBinning*& xRooBinning, RooBinning*& yRooBinning) {
xMin = hist->GetXaxis()->GetXmin(); xMax = hist->GetXaxis()->GetXmax(); Int_t xBins = hist->GetNbinsX();
yMin = hist->GetYaxis()->GetXmin(); yMax = hist->GetYaxis()->GetXmax(); Int_t yBins = hist->GetNbinsY();
const TArrayD* xArray = hist->GetXaxis()->GetXbins(); const Double_t* xBinning = 0;
const TArrayD* yArray = hist->GetYaxis()->GetXbins(); const Double_t* yBinning = 0;
if (xArray) {
xBinning = xArray->GetArray();
if (xBinning) {
xMin = xBinning[0]; xMax = xBinning[xBins];
}
}
if (yArray) {
yBinning = yArray->GetArray();
if (yBinning) {
yMin = yBinning[0]; yMax = yBinning[yBins];
}
}
xRooBinning = new RooBinning(xBins,xMin,xMax);
if (xBinning) xRooBinning = new RooBinning(xBins,xBinning);
yRooBinning = new RooBinning(yBins,yMin,yMax);
if (yBinning) yRooBinning = new RooBinning(yBins,yBinning);
}
void setXY(const RooArgSet* varsSet, RooRealVar*& x, RooRealVar*& y) {
TIterator* iter = varsSet->createIterator(); // now iter does not point to x yet
x = (RooRealVar*)varsSet->first(); iter->Next(); // now iter points to x
y = (RooRealVar*)iter->Next();
}
void chi2N_hist(TFile* file, const TString errTH2_name, const TH2F* TH2, const RooAbsPdf* pdf, const RooRealVar* x, const RooRealVar* y, const TString method, const TString dir, const TString extension) {
const TH2F* errTH2 = (TH2F*)file->Get( errTH2_name ) ;
if (!errTH2) {
cout <<"\nHistogram \"" <<errTH2_name <<"\" not found in TFile \"" <<file->GetName() <<"\"\nChi2 histogram will not be calculated." <<endl;
} else {
TH2F* chi2N_TH2 = twoD_chiSquare(TH2, errTH2, pdf, x, y) ;
TCanvas* chi2N_C = new TCanvas("chi2N_"+errTH2_name+"_C",TString::Format("chi2N for %s",errTH2->GetTitle()),800,600) ;
chi2N_TH2->Draw("colz"); //chi2N_hist->SetMaximum(1.5);
chi2N_C->Update();
TPaletteAxis *palette = (TPaletteAxis*)chi2N_TH2->GetListOfFunctions()->FindObject("palette");
palette->SetX1NDC(0.91); palette->SetX2NDC(0.96);
chi2N_C->Modified(); chi2N_C->Update();
chi2N_C->SaveAs(TString::Format("%s/%s_%s%s",dir.Data(),chi2N_TH2->GetName(),method.Data(),extension.Data()));
}
}
void plotting(const RooDataHist* hist, const TString name, const RooRealVar* x, const RooRealVar* y, const RooBinning* xRooBinning, const RooBinning* yRooBinning, const RooAbsPdf* pdf, const TString pdfTitle, const Int_t xOrder, const TString xName, const TString xTitle, const Int_t yOrder, const TString yName, const TString yTitle, const Float_t chi2N, const TString method, const TString dir, const TString extension) {
TString pdfName = name+"PDF";
Int_t xBins = xRooBinning->numBins(); Float_t xMin = xRooBinning->binLow(0); Float_t xMax = xRooBinning->binHigh(xBins-1);
Int_t yBins = yRooBinning->numBins(); Float_t yMin = yRooBinning->binLow(0); Float_t yMax = yRooBinning->binHigh(yBins-1);
TH2F* TH2_fromHist = (TH2F*)hist->createHistogram(name+"TH2_fromHist", *x, Binning(*xRooBinning), YVar(*y, Binning(*yRooBinning)) ) ;
TH2_fromHist->SetTitle(hist->GetTitle()); TH2_fromHist->SetTitleOffset(TH2_offset,"XY");
TH2_fromHist->Draw("LEGO");
Int_t binDivision = 40;
cout <<"Using " <<binDivision <<" binDivision to plot " <<pdfTitle <<endl;
TH2F* pdf_TH2 = (TH2F*)pdf->createHistogram("", *x, Binning(binDivision*xBins,xMin,xMax), YVar(*y, Binning(binDivision*yBins,yMin,yMax)) ) ;
//TF2* tf2 = (TF2*)pdf->asTF( RooArgSet(*x,*y) ); TH2F* pdf_TH2 = (TH2F*)tf2->GetHistogram(); // Moneta's fix
pdf_TH2->SetName(pdfName+"_TH2"); pdf_TH2->SetTitle(hist->GetTitle()); pdf_TH2->SetTitleOffset(TH2_offset,"XY");
cout <<"Plotting " <<pdf_TH2->GetName() <<endl;
pdf_TH2->SetLineColor(kRed);
//pdf_TH2->Draw("SURF2"); TH2_fromHist->Draw("LEGO same");
//pdf_TH2->Draw("LEGO2"); TH2_fromHist->Draw("LEGO same");
TH2_fromHist->Draw("LEGO"); pdf_TH2->Draw("SURF2 same"); TH2_fromHist->Draw("LEGO same");
//TH2_fromHist->Draw("LEGO"); pdf_TH2->Draw("SURF3 same"); //TH2_fromHist->SetMaximum( 1.2*TH2_fromHist->GetMaximum() );
//pdf_TH2->Draw("SURF3"); TH2_fromHist->Draw("LEGO same"); pdf_TH2->SetMaximum( 1.5*pdf_TH2->GetMaximum() );
if (method.Contains("fit",TString::kIgnoreCase)) {
TPaveText* fitInfo = new TPaveText(0.78,0.8,0.99,0.9,"NDC");
fitInfo->AddText("Fit function:");
fitInfo->AddText(TString::Format("- pol_{%d}[%s] * pol_{%d}[%s]",xOrder,xTitle.Data(),yOrder,yTitle.Data()));
if (chi2N)
fitInfo->AddText(TString::Format("- #chi^{2}/n.d.f. = %.3f",chi2N));
fitInfo->SetTextAlign(12); fitInfo->SetShadowColor(0); fitInfo->SetFillColor(0);
fitInfo->Draw();
}
gPad->SaveAs(TString::Format("%s/%s_%s%s",dir.Data(),pdf_TH2->GetName(),method.Data(),extension.Data()));
//return;
// Projections
//TH1D* TH2_proj[] = {relEffTH2->ProjectionX(name+"_"+xName,1,xBins), relEffTH2->ProjectionY(name+"_"+yName,1,xBins)};
TH1D* TH2_proj[] = {TH2_fromHist->ProjectionX(name+"_"+xName), TH2_fromHist->ProjectionY(name+"_"+yName)};
//(TH1F*)pdf->createHistogram(name+"_"xName, x, Binning(1*xBins,xMin,xMax) ) ; // not working with message: function value is NAN
TString projectionName = pdfName+"_";
TH1D* pdf_proj[] = {pdf_TH2->ProjectionX(projectionName+xName),pdf_TH2->ProjectionY(projectionName+yName)};
for (Int_t iProj=0; iProj<2; ++iProj) {
TH2_proj[iProj]->SetTitle(TString::Format("Projection of %s",TH2_fromHist->GetTitle()));
TH2_proj[iProj]->SetMarkerStyle(20); TH2_proj[iProj]->SetLineColor(kBlack); TH2_proj[iProj]->SetTitleOffset(1);
//TH2_proj[iProj]->SetMinimum(0);
TH2_proj[iProj]->Draw();
pdf_proj[iProj]->Scale((1/pdf_proj[iProj]->Integral())*binDivision*(TH2_proj[iProj]->Integral()));
pdf_proj[iProj]->SetLineColor(kRed); pdf_proj[iProj]->Draw("same");
gPad->SaveAs(TString::Format("%s/%s_%s%s",dir.Data(),TH2_proj[iProj]->GetName(),method.Data(),extension.Data()));
}
}
void Analysis(Int_t nEvt = 10000, Bool_t generating = kTRUE, Bool_t fitting = kFALSE, Bool_t bkgFlag = kFALSE, Bool_t effFlag = kFALSE, Bool_t B0BarFlag = kTRUE, Int_t bkgMassOrd = 1, Int_t bkgAngOrd = 1, Int_t effMassOrd = 1, Int_t effAngOrd = 1)
{
cout <<"\nNOTE: With cut-based efficiency the linear interpolation (effOrd=1) of masses does not work" <<endl;
cout <<endl;
SysInfo_t* s = new SysInfo_t();
gSystem->GetSysInfo(s);
Int_t nCPU = s->fCpus;
/*
LHCb strategy:
As in the Belle analysis, our amplitude model includes all known K*0 -> K+pi- resonances with nominal mass within or slightly above the kinematic limit (1593 MeV) in B0 -> psi' K+ pi- decays: K*_0(800), K*_0(1430) for J = 0; K*(892), K*(1410) and K*(1680) for J = 1; K*_2(1430) for J = 2; and K*_3(1780) for J = 3.
*/
// Helicity amplitudes values
// Ivan values
//const Double_t aIvan = 0.64; const Double_t bIvan = 0.;
//vector< pair<TString, pair< pair<Double_t, Double_t>, pair<Double_t, Double_t> > > > Kstar_spin;
vector< pair<TString, pair<const Double_t, const Double_t> > > Kstar_spin;
vector< pair<TString, pair<const Double_t, const Double_t> > > Zc_spin;
map< TString, pair<Double_t, Double_t> > helJ_map;
cout <<"Adding K*(892)..." <<endl;
Kstar_spin.push_back( make_pair("892_1", make_pair(M892,G892) ) ) ;
helJ_map["892_1_0"] = make_pair(K892_1_0_a,K892_1_0_b); helJ_map["892_1_p1"] = make_pair(K892_1_p1_a,K892_1_p1_b); helJ_map["892_1_m1"] = make_pair(K892_1_m1_a,K892_1_m1_b); // from Belle
//helJ_map["892_1_0"] = make_pair(0.775,0.); helJ_map["892_1_p1"] = make_pair(0.159,1.563); helJ_map["892_1_m1"] = make_pair(0.612,2.712); // from EvtGen
cout <<"Adding K*(800)_0..." <<endl;
Kstar_spin.push_back( make_pair("800_0", make_pair(M800,G800) ) ) ;
helJ_map["800_0_0"] = make_pair(K800_0_0_a,K800_0_0_b);
cout <<"Adding K*(1410)..." <<endl;
Kstar_spin.push_back( make_pair("1410_1", make_pair(M1410,G1410) ) ) ;
helJ_map["1410_1_0"] = make_pair(K1410_1_0_a,K1410_1_0_b); helJ_map["1410_1_p1"] = make_pair(K1410_1_p1_a,K1410_1_p1_b); helJ_map["1410_1_m1"] = make_pair(K1410_1_m1_a,K1410_1_m1_b);
cout <<"Adding K*(1430)_0..." <<endl;
Kstar_spin.push_back( make_pair("1430_0", make_pair(M1430_0,G1430_0) ) ) ;
helJ_map["1430_0_0"] = make_pair(K1430_0_0_a,K1430_0_0_b);
//helJ_map["1430_0_0"] = make_pair(1.,0.);
cout <<"Adding K*(1430)_2..." <<endl;
Kstar_spin.push_back( make_pair("1430_2", make_pair(M1430_2,G1430_2) ) ) ;
helJ_map["1430_2_0"] = make_pair(K1430_2_0_a,K1430_2_0_b); helJ_map["1430_2_p1"] = make_pair(K1430_2_p1_a,K1430_2_p1_b); helJ_map["1430_2_m1"] = make_pair(K1430_2_m1_a,K1430_2_m1_b);
/*
cout <<"Adding K*(1680)..." <<endl;
Kstar_spin.push_back( make_pair("1680_1", make_pair(M1680,G1680) ) ) ;
helJ_map["1680_1_0"] = make_pair(K1680_1_0_a,K1680_1_0_b); helJ_map["1680_1_p1"] = make_pair(K1680_1_p1_a,K1680_1_p1_b); helJ_map["1680_1_m1"] = make_pair(K1680_1_m1_a,K1680_1_m1_b);
cout <<"Adding K*(1780)_3..." <<endl;
Kstar_spin.push_back( make_pair("1780_3", make_pair(M1780_3,G1780_3) ) ) ;
helJ_map["1780_3_0"] = make_pair(K1780_3_0_a,K1780_3_0_b); helJ_map["1780_3_p1"] = make_pair(K1780_3_p1_a,K1780_3_p1_b); helJ_map["1780_3_m1"] = make_pair(K1780_3_m1_a,K1780_3_m1_b);
cout <<"Adding K*(1950)_0..." <<endl;
Kstar_spin.push_back( make_pair("1950_0", make_pair(M1950_0,G1950_0) ) ) ;
helJ_map["1950_0_0"] = make_pair(K1950_0_0_a,K1950_0_0_b);
cout <<"Adding K*(1980)_2..." <<endl;
Kstar_spin.push_back( make_pair("1980_2", make_pair(M1980_2,G1980_2) ) ) ;
helJ_map["1980_2_0"] = make_pair(K1980_2_0_a,K1980_2_0_b); helJ_map["1980_2_p1"] = make_pair(K1980_2_p1_a,K1980_2_p1_b); helJ_map["1980_2_m1"] = make_pair(K1980_2_m1_a,K1980_2_m1_b);
cout <<"Adding K*(2045)_4..." <<endl;
Kstar_spin.push_back( make_pair("2045_4", make_pair(M2045_4,G2045_4) ) ) ;
helJ_map["2045_4_0"] = make_pair(K2045_4_0_a,K2045_4_0_b); helJ_map["2045_4_p1"] = make_pair(K2045_4_p1_a,K2045_4_p1_b); helJ_map["2045_4_m1"] = make_pair(K2045_4_m1_a,K2045_4_m1_b);
*/
/*
cout <<"Adding K*(2380)_5..." <<endl;
Kstar_spin.push_back( make_pair("2380_5", make_pair(M2380_5,G2380_5) ) ) ;
helJ_map["2380_5_0"] = make_pair(1.,0.); helJ_map["2380_5_p1"] = make_pair(0.,0.); helJ_map["2380_5_m1"] = make_pair(0.,0.);
*/
/*
cout <<"Adding Z(4200)..." <<endl;
Zc_spin.push_back( make_pair("4200_1", make_pair(MZ4200,GZ4200) ) ) ;
helJ_map["4200_1_0"] = make_pair(Z4200_1_0_a,Z4200_1_0_b); helJ_map["4200_1_m1"] = make_pair(Z4200_1_m1_a,Z4200_1_m1_b); //helJ_map["4200_1_p1"] = make_pair(Z4200_1_p1_a,Z4200_1_p1_b); // parity conservation
cout <<"Adding Z(4430)..." <<endl;
Zc_spin.push_back( make_pair("4430_1", make_pair(MZ4430,GZ4430) ) ) ;
helJ_map["4430_1_0"] = make_pair(Z4430_1_0_a,Z4430_1_0_b); helJ_map["4430_1_m1"] = make_pair(Z4430_1_m1_a,Z4430_1_m1_b); //helJ_map["4430_1_p1"] = make_pair(Z4430_1_p1_a,Z4430_1_p1_b); // parity conservation
*/
TString Hel = ""; //Hel = "_hel0"; //Hel = "_noHel0";
if (Hel.Contains("_hel0"))
cout <<"with helicity=0 amplitude only\n" <<endl;
else if (Hel.Contains("_noHel0"))
cout <<"without helicity=0 amplitude\n" <<endl;
vector< RooRealVar* > amplitudeRooRealVar;
vector< TString > varNames;
RooArgSet amplitudeVars("amplitudeVars_set");
Double_t aMax = +9999.;
// set boundaries:
Double_t aMin = 0.; //aMin = -aMax;
Double_t bMin = -TMath::Pi(); //-9999.; //bMin = -TMath::Pi();
Double_t bMax = -bMin;
TString helJ[] = {"m1","0","p1"} ;
Int_t nKstars = Kstar_spin.size();
for (Int_t iKstar_S=0; iKstar_S<nKstars; ++iKstar_S)
for (Int_t iHelJ=0; iHelJ<3; ++iHelJ) {
if (Kstar_spin[iKstar_S].first.Contains("_0") && !helJ[iHelJ].EqualTo("0")) continue ;
TString name = Kstar_spin[iKstar_S].first + "_" + helJ[iHelJ] ;
if (helJ_map.find(name) != helJ_map.end()) {
if (Hel.Contains("_hel0") && !helJ[iHelJ].EqualTo("0"))
helJ_map.find(name)->second.first = 0.; // switching off any amplitude with helicity != 0
else if (Hel.Contains("_noHel0") && helJ[iHelJ].EqualTo("0"))
helJ_map.find(name)->second.first = 0.; // switching off the amplitude with helicity == 0
pair<Double_t, Double_t> a_b = helJ_map.find(name)->second ;
TString aName = "a"+name; TString bName = "b"+name;
//a_b.first = aIvan; a_b.second = bIvan;
amplitudeRooRealVar.push_back( new RooRealVar(aName,aName, a_b.first, aMin, aMax) ) ; varNames.push_back( aName ) ;
amplitudeRooRealVar.push_back( new RooRealVar(bName,bName, a_b.second, bMin, bMax) ); varNames.push_back( bName ) ;
}
else {
cout <<"Element \"" <<name <<"\" not found in map helJ_map, please check map filling." <<endl;
return ;
}
}
Int_t nZc = Zc_spin.size();
for (Int_t iZc_S=0; iZc_S<nZc; ++iZc_S)
for (Int_t iHelJ=0; iHelJ<2; ++iHelJ) { // parity conservation
if (Zc_spin[iZc_S].first.Contains("_0") && !helJ[iHelJ].EqualTo("0")) continue ;
TString name = Zc_spin[iZc_S].first + "_" + helJ[iHelJ] ;
if (helJ_map.find(name) != helJ_map.end()) {
if (Hel.Contains("_hel0") && !helJ[iHelJ].EqualTo("0"))
helJ_map.find(name)->second.first = 0.; // switching off any amplitude with helicity != 0
else if (Hel.Contains("_noHel0") && helJ[iHelJ].EqualTo("0"))
helJ_map.find(name)->second.first = 0.; // switching off the amplitude with helicity == 0
pair<Double_t, Double_t> a_b = helJ_map.find(name)->second ;
TString aName = "a"+name; TString bName = "b"+name;
//a_b.first = aIvan; a_b.second = bIvan;
amplitudeRooRealVar.push_back( new RooRealVar(aName,aName, a_b.first, aMin, aMax) ) ; varNames.push_back( aName ) ;
amplitudeRooRealVar.push_back( new RooRealVar(bName,bName, a_b.second, bMin, bMax) ); varNames.push_back( bName ) ;
}
else {
cout <<"Element \"" <<name <<"\" not found in map helJ_map, please check map filling." <<endl;
return ;
}
}
Int_t NAmpl = amplitudeRooRealVar.size();
if (NAmpl > 0)
for (Int_t iVar=0; iVar<NAmpl; ++iVar) {
amplitudeVars.add( *amplitudeRooRealVar[iVar] ) ;
}
else {
cout <<"amplitudeRooRealVar is empty! Please check" <<endl;
return;
}
// B^0 -> psi(nS) K* -> mu+ mu- K- pi+
TString massKPi_name = "massKPi"; TString mass2KPi_name = massKPi_name; mass2KPi_name.ReplaceAll("mass","mass2");
TString massKPi_title = "m(K^{-}#pi^{+})";
Float_t massKPi_min = 0.6, massKPi_max = 2.2;
RooRealVar massKPi(massKPi_name, massKPi_title+" [GeV]", TMath::Sqrt(0.7),massKPi_min,massKPi_max);
//RooRealVar massKPi(massKPi_name,"m(K^{-}#pi^{+}) [GeV]",TMath::Sqrt(0.7),0.,9.2);
TString mass2KPi_title = massKPi_title; mass2KPi_title.ReplaceAll("m(","m^{2}(");
RooFormulaVar mass2KPiFor(mass2KPi_name+"For",mass2KPi_title+" [GeV^{2}]","pow(massKPi,2)",massKPi);
RooRealVar mass2KPi(mass2KPi_name,mass2KPiFor.getTitle(),TMath::Power(massKPi.getVal(),2),TMath::Power(massKPi.getMin(),2),TMath::Power(massKPi.getMax(),2));
TString massPsiPi_name = "massMuMuPi"; TString mass2PsiPi_name = massPsiPi_name; mass2PsiPi_name.ReplaceAll("mass","mass2");
TString massPsiPi_title = "m(#psi#pi^{+})";
Float_t massPsiPi_min = 3.2, massPsiPi_max = 4.9;
RooRealVar massPsiPi(massPsiPi_name,massPsiPi_title+" [GeV]",4,massPsiPi_min,massPsiPi_max);
//RooRealVar massPsiPi(massPsiPi_name,massPsiPi_title+" [GeV]",4,0.,99.9);
TString mass2PsiPi_title = massPsiPi_title; mass2PsiPi_title.ReplaceAll("m(","m^{2}(");
RooFormulaVar mass2PsiPiFor(mass2PsiPi_name+"For",mass2PsiPi_title+" [GeV^{2}]","pow(massMuMuPi,2)",massPsiPi);
RooRealVar mass2PsiPi(mass2PsiPi_name,mass2PsiPiFor.getTitle(),TMath::Power(massPsiPi.getVal(),2),TMath::Power(massPsiPi.getMin(),2),TMath::Power(massPsiPi.getMax(),2));
TString massVars_name = "massVars"; RooArgSet massVars(massKPi, massPsiPi, massVars_name);
RooArgSet mass2Fors(mass2KPiFor, mass2PsiPiFor);
TString mass2Vars_name = "mass2Vars"; RooArgSet mass2Vars(mass2KPi, mass2PsiPi, mass2Vars_name);
TString cosMuMu_title = "cos(#theta_{#psi})";
RooRealVar cosMuMu("cosMuMu",cosMuMu_title,0.,-1,1); // cosine of the psi(nS) helicity angle
TString cosKstar_title = "cos(#theta_{K*})";
RooRealVar cosKstar("cosKstar",cosKstar_title,0.,-1,1); // cosine of the K* helicity angle
TString phi_title = "#phi";
RooRealVar phi("phi",phi_title,0.25,-TMath::Pi(),TMath::Pi());
//RooRealVar phi("phi","#phi",0.25,-2*TMath::Pi(),2*TMath::Pi());
TString angleVars_name = "angleVars";
RooArgSet angleVars(cosMuMu, phi, angleVars_name);
RooArgSet kinematicVars(massVars, angleVars);
RooArgSet kinematicVars_m2(mass2Vars, angleVars);
TString sqDalitz_name = "sqDalitz"; RooArgSet sqDalitz(mass2KPi, cosKstar, sqDalitz_name);
TString sqDalitz1_name = "sqDalitz1"; RooArgSet sqDalitz1(massKPi, cosKstar, sqDalitz1_name);
TString sqDalitz_v2_name = "sqDalitz_v2"; RooArgSet sqDalitz_v2(mass2PsiPi, cosKstar, sqDalitz_v2_name);
TString sqDalitz1_v2_name = "sqDalitz1_v2"; RooArgSet sqDalitz1_v2(massPsiPi, cosKstar, sqDalitz1_v2_name);
// not accessible on cmssusyX
TString path = "/lustre/home/nsur/AAFit_files/";
//"/lustrehome/cristella/work/Z_analysis/exclusive/clean_14ott/original/CMSSW_5_3_22/src/UserCode/MuMuPiKPAT/test/sanjay/selector/";
//path = "/lustre/home/adrianodif/RootFiles/Z4430/";
//TString inputFileName = "MC_K892_JPsi_Bd2MuMuKpi_2p0Sig_4p0to6p0SB.root"; Bool_t tmva = kFALSE;
TString inputFileName = "MC_K892_JPsi_Bd2MuMuKpi_B0massConstraint.root"; Bool_t tmva = kFALSE;
inputFileName = "Data_JPsi_2p0Sig_6p0to9p0SB.root"; tmva = kFALSE;
TString bdtCut = "0p00"; //bdtCut = "-0p03";
TString bdtCut_long = "withBDTCutAt"+bdtCut;
//inputFileName = "TMVApp_data_"+bdtCut_long+"_JPsi_2p0Sig_6p0to9p0SB.root";
if (inputFileName.Contains("TMVA")) {
tmva = kTRUE;
path.Append("TMVA/");
}
TString prefix = "", postfix = "";
if (inputFileName.Contains("MC")) {
prefix = "Generated "; postfix = "Gen";
}
TString fullInputFileName = path+inputFileName ;
TFile *inputFile = TFile::Open( fullInputFileName ); //inputFile = 0;
//TFile *inputFile = TFile::Open( inputFileName );
TString datasetsPath = "datasets";
RooDataSet *dataToFit = 0;
RooRealVar B0beauty("B0beauty","B^{0} beauty",0,-1.5,1.5);
RooArgSet kinematicVars_withBeauty(kinematicVars, B0beauty, TString::Format("%s_with%s",kinematicVars.GetName(),B0beauty.GetName())) ;
inputFile = 0;
if (!inputFile) {
cout <<"Warning: unable to open file \"" <<fullInputFileName <<"\"" <<endl;
} else {
//TTree *BkgTree = (TTree*)f->Get("BkgTree");
TNtupleD* dataNTuple = (TNtupleD*)inputFile->Get("AAVars");
//dataNTuple->Print() ;
RooDataSet *data = new RooDataSet("data"+postfix, prefix+"data", dataNTuple, kinematicVars);
cout <<"\nImported TTree with " <<data->numEntries() <<" entries and the following variables:" <<endl ;
data->printArgs(cout) ; cout <<"\n" ;
//cout <<"\n"; kinematicVars.Print("extras") ;
cout <<"\nImporting dataNTuple..." <<endl;
RooDataSet *data_B0 = new RooDataSet("data"+postfix+"_B0_B0massConstraint",prefix+"B0 data", dataNTuple, kinematicVars_withBeauty, "B0beauty > 0");
cout <<"\nImported TTree with " <<data_B0->numEntries() <<" B0" <<endl ;
data_B0->write(TString::Format("%s/%s.txt",datasetsPath.Data(),data_B0->GetName()));
RooDataSet *data_B0bar = new RooDataSet("data"+postfix+"_B0bar_B0massConstraint",prefix+"B0bar data", dataNTuple, kinematicVars_withBeauty, "B0beauty < 0");
cout <<"\nImported TTree with " <<data_B0bar->numEntries() <<" B0bar" <<endl ;
data_B0bar->write(TString::Format("%s/%s.txt",datasetsPath.Data(),data_B0bar->GetName()));
/*
RooRealVar testVar = phi;
RooPlot* test_frame = testVar.frame(Name(testVar.getTitle()+"_frame"),Title("Projection of "+testVar.getTitle())) ;
data_B0->plotOn(test_frame); data_B0bar->plotOn(test_frame, LineColor(kRed)); test_frame->Draw() ; return;
*/
dataToFit = data;
//dataToFit = data_B0;
//dataToFit = data_B0bat;
}
//return ;
const Double_t dRadB0 = 5.0; const Double_t dRadKs = 1.5;
myPDF* sigPDF = 0;
/*
sigPDF = new myPDF("signal_pdf","Signal pdf", massKPi, cosMuMu, cosKstar, phi,
a892m1, b892m1, a892z, b892z, a892p1, b892p1) ;
*/
TString psi_nS = "1"; //psi_nS = "2";
TString sigName, sigTitle;
if (nKstars>0) {
sigName = "Kstar_", sigTitle = "K*s signal";
if (nKstars == 1) {
sigName.Append(Kstar_spin.front().first);
sigTitle.ReplaceAll("K*s","K*");
} else {
sigName.ReplaceAll("Kstar_","Kstars");
for (Int_t iKstar_S=0; iKstar_S<nKstars; ++iKstar_S)
sigName.Append("__"+Kstar_spin[iKstar_S].first);
}
sigName.Append(Hel);
}
if (nZc>0) {
sigName.Append("_Zc_");
sigTitle.Append( "_Zcs signal");
if (nZc == 1) {
sigName.Append(Zc_spin.front().first);
sigTitle.ReplaceAll("_Zcs","_Zc");
} else {
sigName.ReplaceAll("_Zc_","_Zcs_");
for (Int_t iZc_S=0; iZc_S<nZc; ++iZc_S)
sigName.Append("__"+Zc_spin[iZc_S].first);
}
sigName.Append(Hel);
}
pair<TString, TString> sigPDF_varNameTitle[4] = {make_pair(massKPi.GetName(),massKPi_title), make_pair(cosMuMu.GetName(),cosMuMu.GetTitle()), make_pair(massPsiPi.GetName(),massPsiPi_title), make_pair(phi.GetName(),phi.GetTitle())};
sigPDF = new myPDF(sigName, sigTitle,
//massKPi, cosMuMu, massPsiPi, phi,
(RooRealVar&)(kinematicVars[sigPDF_varNameTitle[0].first]), (RooRealVar&)(kinematicVars[sigPDF_varNameTitle[1].first]), (RooRealVar&)(kinematicVars[sigPDF_varNameTitle[2].first]), (RooRealVar&)(kinematicVars[sigPDF_varNameTitle[3].first]),
B0beauty,
Kstar_spin, Zc_spin, varNames, amplitudeVars, psi_nS, dRadB0, dRadKs) ;
if (sigPDF && !nKstars && !nZc ) {
cout <<"sigPDF set up with no K* or Zc! Please check" <<endl;
return ;
}
//cout <<"\nsigPDF->getVal() = " <<sigPDF->getVal() <<endl; return;
RooConstVar mBd("mBd", "m(B^{0})", MBd) ;
RooConstVar m2Bd("m2Bd", "m^{2}(B^{0})", MBd2) ;
RooConstVar mKaon("mKaon", "m(K^{-})", MKaon) ;
RooConstVar m2Kaon("m2Kaon", "m^{2}(K^{-})", MKaon2) ;
RooConstVar mPion("mPion", "m(#pi^{+})", MPion) ;
RooConstVar m2Pion("m2Pion", "m^{2}(#pi^{+})", MPion2) ;
Double_t massMuMu = 0. ;
if (psi_nS.EqualTo("1")) {
massMuMu = MJpsi ;
//massPsiPi.setMax(4.8);
massPsiPi_title.ReplaceAll("#psi","J/#psi");
massPsiPi.SetTitle( massPsiPi.getTitle().ReplaceAll("#psi","J/#psi") );
cosMuMu_title.ReplaceAll("#psi","J/#psi");
cosMuMu.SetTitle(cosMuMu_title);
} else if (psi_nS.EqualTo("2")) {
massMuMu = MPsi2S ;
//massPsiPi.setMin(3.7);
massPsiPi_title.ReplaceAll("#psi","#psi'");
massPsiPi.SetTitle( massPsiPi.getTitle().ReplaceAll("#psi","#psi'") );
} else {
cout <<"psi_nS is neither 1 nor 2, please check it." <<endl;
return ;
}
RooConstVar mPsi("mPsi", "m(#mu^{+}#mu^{-})", massMuMu);
RooConstVar m2Psi("m2Psi", "m^{2}(#mu^{+}#mu^{-})", TMath::Power(massMuMu,2));
const Double_t smearing = 0. ;
RooConstVar smear("smear", "smear", smearing) ;
// B^{0} -> psi(nS) #pi^{+} K^{-}
//RooAbsPdf* BdToPsiPiK_PHSP = new RooGenericPdf("BdToPsiPiK_PHSP","3-body PHSP","sqrt( pow(massKPi,4) + pow(mPion,4) + pow(mKaon,4) - 2*pow(massKPi,2)*pow(mPion,2) - 2*pow(massKPi,2)*pow(mKaon,2) - 2*pow(mPion,2)*pow(mKaon,2) ) * sqrt( pow(mBd,4) + pow(massKPi,4) + pow(mPsi,4) - 2*pow(mBd,2)*pow(massKPi,2) - 2*pow(mBd,2)*pow(mPsi,2) - 2*pow(massKPi,2)*pow(mPsi,2) ) / (massKPi)", RooArgSet(massKPi,mPion,mKaon,mBd,mPsi)); // variables name used in the formula must be = name of the RooVariables in the list
//cout <<"\nBdToPsiPiK_PHSP.getVal() =\n" <<BdToPsiPiK_PHSP->getVal() <<endl; return;
RooAbsPdf* BdToPsiPiK_PHSP = new RooGenericPdf("BdToPsiPiK_PHSP","3-body PHSP","sqrt( pow(mass2KPiFor,2) + pow(m2Pion,2) + pow(m2Kaon,2) - 2*mass2KPiFor*m2Pion - 2*mass2KPiFor*m2Kaon - 2*m2Pion*m2Kaon ) * sqrt( pow(m2Bd,2) + pow(mass2KPiFor,2) + pow(m2Psi,2) - 2*m2Bd*mass2KPiFor - 2*m2Bd*m2Psi - 2*mass2KPiFor*m2Psi ) / sqrt(mass2KPiFor)", RooArgSet(mass2KPiFor,m2Pion,m2Kaon,m2Bd,m2Psi)); // variables name used in the formula must be = RooVariables name in the RooArgSet
//cout <<"\nBdToPsiPiK_PHSP.getVal() =\n" <<BdToPsiPiK_PHSP->getVal() <<endl; return;
RooAbsPdf* bkgPDF = BdToPsiPiK_PHSP; bkgPDF = 0;
RooRealVar nSig("nSig", "n_{SIG}", 0, 0, 2E6);
//nSig.setVal( 10*nSig.getVal() ); // Does not work on the fly
Float_t purity = 0.8;
if (tmva) purity = 0.75;
RooRealVar nBkg("nBkg", "n_{BKG}", nSig.getVal() * (1-purity), 0, 2E6);
//RooExtendPdf *extendedBkgPDF = new RooExtendPdf("extendedBkgPDF", "Signal 0 PDF", *bkgPDF, nBkg) ;
//RooPlot* test_frame = massKPi.frame() ; test_frame->SetTitle( "Projection of "+massKPi.getTitle() ); extendedBkgPDF->plotOn(test_frame) ; test_frame->Draw() ; return;
TString modelName, modelTitle;
RooAbsPdf* model = 0;
if (sigPDF) {
cout <<"Building " <<sigPDF->GetTitle() <<endl;
nSig.setVal( nEvt );
model = (RooAbsPdf*)sigPDF;
if (bkgPDF) { // in case of efficiency model will be overridden
cout <<"\nAdding " <<bkgPDF->GetTitle() <<endl;
nSig.setVal( nEvt/2 ); nBkg.setVal( nEvt/2 );
model = (RooAbsPdf*) new RooAddPdf("","",RooArgList(*sigPDF,*bkgPDF),RooArgList(nSig,nBkg)) ;
model->SetName( TString::Format("%s__plus__%s",sigPDF->GetName(),bkgPDF->GetName()) );
model->SetTitle( TString::Format("%s + %s",sigPDF->GetTitle(),bkgPDF->GetTitle()) );
}
} else if (bkgPDF) {
cout <<"Building " <<bkgPDF->GetTitle() <<endl;
nBkg.setVal( nEvt );
//modelTitle = TString::Format("%s*(%s)",nBkg.GetTitle(),bkgPDF->GetTitle());
model = bkgPDF ;
} else {
cout <<"Neither sigPDF nor bkgPDF is != 0! Please check";
return;
}
modelName = model->GetName();
RooRealVar nEvents("nEvents","nEvents",nSig.getVal() + nBkg.getVal()) ; nEvents.setConstant(kTRUE);
RooFormulaVar sigFrac("sigFraction",TString::Format("%s fraction",nSig.GetTitle()),"nSig/nEvents",RooArgSet(nSig,nEvents));
RooFormulaVar bkgFrac("bkgFraction",TString::Format("%s fraction",nBkg.GetTitle()),"nBkg/nEvents",RooArgSet(nBkg,nEvents));
TString noKinConstr = "_noKinConstr";
//model->SetName( model->GetName()+noKinConstr );
// Dalitz boundary
//Dalitz_contour* kinCheck = new Dalitz_contour("kinCheck","kinematic check", massKPi, massPsiPi, kFALSE, psi_nS) ;
//RooProdPdf* modelWithKinCheck = new RooProdPdf(modelName,model->GetTitle(),RooArgSet(*kinCheck,*model)) ; model = modelWithKinCheck;
TString dir = "./plots/";
if (psi_nS.EqualTo("1"))
dir.Append("JPsi");
else if (psi_nS.EqualTo("2"))
dir.Append("psi2S");
TString extension = ".png"; //extension.Prepend("_test");
gStyle->SetOptStat( 10 ) ;
TString anglesScatt_name = "planesAngle_vs_cos_psi2S_helicityAngle";
Bool_t DalitzEff = kFALSE;
RooAbsPdf* null = 0;
RooProdPdf* sbsModel = 0;
RooConstVar half = RooConstVar("half", "half", 0.5);
RooConstVar fixSig = RooConstVar("fixSig", "fixSig", purity);
if (bkgFlag) { // Model background from sidebands
//TString bkgFileName = path+"Data_JPsi_2p0Sig_4p0to6p0SB.root";
//TString bkgFileName = path+"Data_JPsi_2p0Sig_5p0to9p0SB.root";
TString bkgFileName = path+"Data_JPsi_2p0Sig_6p0to9p0SB.root";
if (tmva)
bkgFileName = path+"TMVApp_data_"+bdtCut_long+"_JPsi_2p0Sig_6p0to9p0SB.root";
cout <<"\nOpening \"" <<bkgFileName <<endl;
TFile *bkgFile = TFile::Open(bkgFileName);
const Int_t nVars = 2;
TString sb_name[] = {"sbs","leftSb","rightSb"};
pair<RooAbsPdf*, Float_t> sbPdf[nVars][3] = {{make_pair(null,0.),make_pair(null,0.),make_pair(null,0.)},{make_pair(null,0.),make_pair(null,0.),make_pair(null,0.)}};
/*
// with fit function
const Int_t m2KPi_order_bkg = 6, m2PsiPi_order_bkg = 4;
const Int_t cosMuMu_order_bkg = 6, phi_order_bkg = 6;
const Int_t mKPi_order_bkg = 5, mPsiPi_order_bkg = 4, cosKstar_order_bkg = 7;
*/
// with RooHistPdf
const Int_t m2KPi_order_bkg = bkgMassOrd, m2PsiPi_order_bkg = bkgMassOrd;
const Int_t mKPi_order_bkg = bkgMassOrd, mPsiPi_order_bkg = bkgMassOrd;
const Int_t cosMuMu_order_bkg = bkgAngOrd, phi_order_bkg = bkgAngOrd;
pair< pair<TString, pair<RooArgSet*,pair<Int_t,Int_t> > >, pair<TString,pair< pair<TString,TString>,pair<TString,TString> > > > bkgHisto_names[] = {make_pair( make_pair("psi2SPi_vs_KPi_dalitz",make_pair(&mass2Vars,make_pair(m2KPi_order_bkg,m2PsiPi_order_bkg))), make_pair("bkgDalitz",make_pair(make_pair("m2KPi",mass2KPi_title),make_pair("m2PsiPi",mass2PsiPi_title)))), make_pair(make_pair(anglesScatt_name,make_pair(&angleVars,make_pair(cosMuMu_order_bkg,phi_order_bkg))), make_pair("bkgAngles",make_pair(make_pair("cosMuMu",cosMuMu_title),make_pair("phi",phi_title))))};
// if you use &mass2Fors you get "ERROR:InputArguments -- RooAbsDataStore::initialize(RelEff_psi2SPi_vs_KPi_B0constr): Data set cannot contain non-fundamental types"
bkgHisto_names[0] = make_pair( make_pair("psi2SPi_vs_KPi_masses",make_pair(&massVars,make_pair(mKPi_order_bkg,mPsiPi_order_bkg))), make_pair("bkgMasses",make_pair(make_pair("mKPi",massKPi_title),make_pair("mPsiPi",massPsiPi_title)))); // need to apply Dalitz border in TMVAClassificationApplication.C
//bkgHisto_names[0] = make_pair(make_pair("cos_Kstar_helicityAngle_fromMasses_vs_KPiMassSq",make_pair(&sqDalitz,make_pair(m2KPi_order_bkg,cosKstar_order_bkg))), make_pair("bkgSqDalitz",make_pair(make_pair("m2KPi",mass2KPi_title),make_pair("cosKstar",cosKstar_title)))); DalitzEff = kTRUE;
//bkgHisto_names[0] = make_pair(make_pair("cos_Kstar_helicityAngle_fromMasses_vs_KPiMass",make_pair(&sqDalitz1,make_pair(mKPi_order_bkg,cosKstar_order_bkg))), make_pair("bkgSqDalitz1",make_pair(make_pair("mKPi",massKPi_title),make_pair("cosKstar",cosKstar_title)))); DalitzEff = kFALSE;
//
//bkgHisto_names[0] = make_pair(make_pair("cos_Kstar_helicityAngle_fromMasses_vs_psiPiMassSq",make_pair(&sqDalitz_v2,make_pair(m2PsiPi_order_bkg,cosKstar_order_bkg))), make_pair("bkgSqDalitz_v2",make_pair(make_pair("m2PsiPi",mass2PsiPi_title),make_pair("cosKstar",cosKstar_title)))); DalitzEff = kTRUE;
//bkgHisto_names[0] = make_pair(make_pair("cos_Kstar_helicityAngle_fromMasses_vs_psiPiMass",make_pair(&sqDalitz1_v2,make_pair(mPsiPi_order_bkg,cosKstar_order_bkg))), make_pair("bkgSqDalitz1_v2",make_pair(make_pair("mPsiPi",massPsiPi_title),make_pair("cosKstar",cosKstar_title)))); DalitzEff = kFALSE;
// bkgFile = 0;
if (bkgFile)
for (Int_t iVars = 0; iVars < 2; ++iVars) {
RooArgSet* bkgVars = bkgHisto_names[iVars].first.second.first ;
// Set x and y vars
RooRealVar* x = 0, *y = 0;
setXY(bkgVars, x, y);
//x->printMultiline(cout,99); y->printMultiline(cout,99); //return;
for (Int_t iSb=0; iSb < 1; ++iSb) {
TString histName = bkgHisto_names[iVars].first.first+"_"+sb_name[iSb];
if (tmva) histName.Append("_BDT");
else {
histName.ReplaceAll("_masses","");
histName.ReplaceAll(sb_name[iSb],"");
histName.Append("hardCuts_1B0_sidebands_B0massC");
}
const TH2F* sbTH2 = (TH2F*)bkgFile->Get( histName ) ;
if (!sbTH2) {
cout <<"WARNING! No TH2F \"" <<histName <<"\" found in TFile \"" <<bkgFile->GetName() <<"\".\nSkipping " <<histName <<" evaluation" <<endl;
continue; }
Float_t xMin = 0, xMax = 0; RooBinning* xRooBinning = 0;
Float_t yMin = 0, yMax = 0; RooBinning* yRooBinning = 0;
setBinning(sbTH2,xMin,xMax,yMin,yMax,xRooBinning,yRooBinning);
cout <<"Setting TH2 range to vars ..." <<endl;
x->setRange(xMin,xMax);
y->setRange(yMin,yMax);
// with RooHistPDF
cout <<"Creating RooDataHist from " <<sbTH2->GetName() <<" ..." <<endl;
RooDataHist* bkgHist = new RooDataHist(sbTH2->GetName(), sbTH2->GetTitle(), *bkgVars, sbTH2) ;
TString bkgName = bkgHisto_names[iVars].second.first+"_"+sb_name[iSb];
TString bkgType = bkgName; bkgType.ReplaceAll("bkg","");
TString first = TString(bkgType,1);
if (!bkgType.EqualTo("Dalitz")) first.ToLower();
TString bkgtype = bkgType; bkgtype.Remove(0,1); bkgtype.Prepend(first);
TString pdfTitle = "bkg("+bkgtype+") pdf";
TString method = "map";
Int_t xOrder = bkgHisto_names[iVars].first.second.second.first;
Int_t yOrder = bkgHisto_names[iVars].first.second.second.second;
if (xOrder) method = "interp"+TString::Itoa(xOrder,10); // with RooHistPdf xOrder = yOrder (see previous comment in this commit)
RooHistPdf* bkgHistPdf = new RooHistPdf(bkgName+"PDF_"+method, pdfTitle, *bkgVars, *bkgHist, xOrder) ;
//RooHistPdf* bkgHistPdf = new RooHistPdf(bkgName+"PDF", pdfTitle, *bkgVars, *bkgHist, xOrder) ;
//If last argument is zero, the weight for the bin enclosing the coordinates contained in 'bin' is returned. For higher values, the result is interpolated in the real dimensions of the dataset with an order of interpolation equal to the value provided (more than ? does not work for Dalitz efficiencies, ? for masses efficiencies, ? for angles)
bkgHistPdf->setUnitNorm(kTRUE);
sbPdf[iVars][iSb].first = bkgHistPdf;
// sbPdf[iVars][iSb].first = twoDFit(*x, *y, sbTH2, psi_nS.Atoi(), xOrder, yOrder, sbPdf[iVars][iSb].second); method = "ROOTfit"; // ROOT fit
//sbPdf[iVars][iSb].first = twoDFit(*x, *y, bkgHist, psi_nS.Atoi(), xOrder, yOrder, sbPdf[iVars][iSb].second); method = "RooFit"; // RooFit fit
const Float_t chi2N = sbPdf[iVars][iSb].second;
RooAbsPdf* kinematicCheck(0), *bkgWithKinCheck(0);
if (bkgVars->GetName() == massVars_name || bkgVars->GetName() == mass2Vars_name)
kinematicCheck = new Dalitz_contour("Dalitz_kinCheck","kinematic check for Dalitz", *x, *y, DalitzEff, psi_nS) ;
else if (bkgVars->GetName() == sqDalitz_name || bkgVars->GetName() == sqDalitz1_name)
kinematicCheck = new sqDalitz_contour("sqDalitz_kinCheck","kinematic check for square Dalitz", *x, *y, DalitzEff, psi_nS.Atoi()) ;
else if (bkgVars->GetName() == angleVars_name)
kinematicCheck = new Angles_contour("angles_kinCheck","kinematic check for angles", *x, *y) ;
//
if (kinematicCheck) {
cout <<"Multiplying " <<bkgHistPdf->GetTitle() <<" by " <<kinematicCheck->GetTitle() <<endl;
bkgWithKinCheck = new RooProdPdf(TString::Format("%s_withKinCheck",bkgHistPdf->GetName()),TString::Format("%s with kinematic check",bkgHistPdf->GetTitle()),RooArgSet(*kinematicCheck,*sbPdf[iVars][iSb].first)) ;
if (bkgWithKinCheck)
sbPdf[iVars][iSb].first = bkgWithKinCheck;
}
TString sbErrTH2_name = sbTH2->GetName(); sbErrTH2_name.Append("_err");
// chi2N_hist(bkgFile, sbErrTH2_name, sbTH2, sbPdf[iVars][iSb].first, x, y, method, dir+"/bkg", extension);
plotting(bkgHist, bkgName, x, y, xRooBinning, yRooBinning, sbPdf[iVars][iSb].first, pdfTitle, xOrder, bkgHisto_names[iVars].second.second.first.first, bkgHisto_names[iVars].second.second.first.second, yOrder, bkgHisto_names[iVars].second.second.second.first, bkgHisto_names[iVars].second.second.second.second, chi2N, method, dir+"/bkg", extension);
} // for (Int_t iSb=0; iSb < 3; ++iSb)
} // for (Int_t iVars=0; iVars < nVars; ++iVars)
else
cout <<"WARNING! TFile \"" <<bkgFileName <<"\" could not be opened.\nSkipping background computation" <<endl;
//return;
RooAbsPdf* sbsPdf[] = {sbPdf[0][0].first, sbPdf[1][0].first};
TString sbsName[] = {"Masses","Angles"};
/*
for (Int_t iVar=0; iVar<2; ++iVar) // this to use leftSb + rightSb instead of totalSbs pdf
if (sbPdf[iVar][1].first && sbPdf[iVar][2].first)
sbsPdf[iVar] = new RooAddPdf("sbs"+sbsName[iVar]+"Pdf","sidebands "+sbsName[iVar]+" p.d.f.",*sbPdf[iVar][1].first,*sbPdf[iVar][2].first,half) ;
*/
if (sbsPdf[0] && sbsPdf[1]) {
sbsModel = new RooProdPdf(TString::Format("%s_X_%s",sbsPdf[0]->GetName(),sbsPdf[1]->GetName()),"sidebands p.d.f.",RooArgSet(*sbsPdf[0],*sbsPdf[1]));
//cout <<"\nsbsModel->getVal() = " <<sbsModel->getVal() <<endl; return;
}
//return;
} // if (bkgFlag)
// Masses and angles efficiencies
//TString effFileName = path+"officialMC_noPtEtaCuts_JPsi_Bd2MuMuKPi_2p0Sig_4p0to6p0SB.root";
//TString effFileName = path+"officialMC_noPtEtaCuts_JPsi_Bd2MuMuKPi_2p0Sig_5p0to9p0SB.root";
TString effFileName = path+"officialMC_noPtEtaCuts_JPsi_Bd2MuMuKPi_2p0Sig_6p0to9p0SB.root";
if (tmva) effFileName = path+"TMVApp_MC_"+bdtCut_long+"_JPsi_2p0Sig_6p0to9p0SB.root";
cout <<"\nOpening \"" <<effFileName <<endl;
TFile *effFile = TFile::Open(effFileName);
RooAbsPdf* pdfToCorrect = sigPDF;
TString pdfToCorr_name = pdfToCorrect->GetName();
RooProdPdf* modelWithEff = 0;
/*
// with fit function
const Int_t m2KPi_order_relEff = 5, m2PsiPi_order_relEff = 4, cosMuMu_order_relEff = 5, phi_order_relEff = 5;
const Int_t mKPi_order_relEff = 4, mPsiPi_order_relEff = 4, cosKstar_order_relEff = 4;
*/
// with RooHistPdf
const Int_t m2KPi_order_relEff = effMassOrd, m2PsiPi_order_relEff = effMassOrd;
const Int_t mKPi_order_relEff = effMassOrd, mPsiPi_order_relEff = effMassOrd;
const Int_t cosMuMu_order_relEff = effAngOrd, phi_order_relEff = effAngOrd;
pair< pair<TString, pair<RooArgSet*,pair<Int_t,Int_t> > >, pair<TString,pair< pair<TString,TString>,pair<TString,TString> > > > effHisto_names[] = {make_pair( make_pair("RelEff_psi2SPi_vs_KPi_B0constr_Dalitz",make_pair(&mass2Vars,make_pair(m2KPi_order_relEff,m2PsiPi_order_relEff))), make_pair("relEffDalitz",make_pair(make_pair("m2KPi",mass2KPi_title),make_pair("m2PsiPi",mass2PsiPi_title)))), make_pair(make_pair("RelEff_"+anglesScatt_name,make_pair(&angleVars,make_pair(cosMuMu_order_relEff,phi_order_relEff))), make_pair("relEffAngles",make_pair(make_pair("cosMuMu",cosMuMu_title),make_pair("phi",phi_title))))}; DalitzEff = kTRUE;
// if you use &mass2Fors you get "ERROR:InputArguments -- RooAbsDataStore::initialize(RelEff_psi2SPi_vs_KPi_B0constr): Data set cannot contain non-fundamental types"
//effHisto_names[0] = make_pair(make_pair("RelEff_psi2SPi_vs_KPi_B0constr",make_pair(&massVars,make_pair(mKPi_order_relEff,mPsiPi_order_relEff))), make_pair("relEffMasses",make_pair(make_pair("mKPi",massKPi_title),make_pair("mPsiPi",massPsiPi_title)))); DalitzEff = kFALSE;
effHisto_names[0] = make_pair(make_pair("RelEff_psi2SPi_vs_KPi",make_pair(&massVars,make_pair(mKPi_order_relEff,mPsiPi_order_relEff))), make_pair("relEffMasses",make_pair(make_pair("mKPi",massKPi_title),make_pair("mPsiPi",massPsiPi_title)))); DalitzEff = kFALSE;
//effHisto_names[0] = make_pair(make_pair("RelEff_cos_Kstar_helicityAngle_vs_KPiSq_varBins",make_pair(&sqDalitz,make_pair(m2KPi_order_relEff,cosKstar_order_relEff))), make_pair("relEffSqDalitz",make_pair(make_pair("m2KPi",mass2KPi_title),make_pair("cosKstar",cosKstar_title)))); DalitzEff = kTRUE;
pair<RooAbsPdf*, Float_t> effPdf[] = {make_pair(null,0.),make_pair(null,0.)};
//effFile = 0;
if (effFile && effFlag)
for (Int_t iEff=0; iEff <2 ; ++iEff) {
TString effName = effHisto_names[iEff].second.first;
TString histName = effHisto_names[iEff].first.first;
if (tmva) histName.Append("_"+bdtCut_long);
else histName.Append("_hardCuts_1B0");
//histName.ReplaceAll("RelEff","RelEffInv"); effName.ReplaceAll("relEff","relInvEff");
const TH2F* relEffTH2 = (TH2F*)effFile->Get( histName ) ;
if (!relEffTH2) {
cout <<"WARNING! No TH2F \"" <<histName <<"\" found in TFile \"" <<effFile->GetName() <<"\".\nSkipping " <<effName <<" correction" <<endl;
continue; }
Float_t xMin = 0, xMax = 0; RooBinning* xRooBinning = 0;
Float_t yMin = 0, yMax = 0; RooBinning* yRooBinning = 0;
setBinning(relEffTH2,xMin,xMax,yMin,yMax,xRooBinning,yRooBinning);
RooArgSet* effVars = effHisto_names[iEff].first.second.first ;
// Set x and y vars
RooRealVar* x = 0, *y = 0;
setXY(effVars, x, y);
x->setRange(xMin,xMax);
y->setRange(yMin,yMax);
// with RooHistPDF
RooDataHist* relEffHist = new RooDataHist(relEffTH2->GetName(), relEffTH2->GetTitle(), *effVars, relEffTH2) ;
/* // already done in the PROOF macro
for (Int_t iBin=0; iBin<relEffHist->numEntries(); ++iBin) { // remove bins whose center is out of Dalitz border
*effVars = *(relEffHist->get( iBin ));
//cout <<"x = " <<mass2KPi.getVal() <<", y = " <<mass2PsiPi.getVal() <<":\noriginal value = " <<relEffHist->weight(*effVars) <<", corrected value = " <<Dalitz_contour_host(mass2KPi.getVal(), mass2PsiPi.getVal(), kTRUE, psi_nS.Atoi()) * relEffHist->weight(*effVars) <<endl;
if (!Dalitz_contour_host(x->getVal(), y->getVal(), DalitzEff, psi_nS.Atoi()))
relEffHist->set(*effVars, 0, 0);
}
*/
TString effType = effName; effType.ReplaceAll("relEff","");
TString first = TString(effType,1); first.ToLower();
TString efftype = effType; efftype.Remove(0,1); efftype.Prepend(first);
TString pdfTitle = "#epsilon_{rel}("+efftype+") pdf";
TString method = "map";
Int_t xOrder = effHisto_names[iEff].first.second.second.first;
Int_t yOrder = effHisto_names[iEff].first.second.second.second;
if (xOrder) method = "interp"+TString::Itoa(xOrder,10); // with RooHistPdf xOrder = yOrder (see previous comment in this commit)
RooHistPdf* relHistPdf = new RooHistPdf(effName+"PDF_"+method,pdfTitle, *effVars, *relEffHist, xOrder) ; //If last argument is zero, the weight for the bin enclosing the coordinates contained in 'bin' is returned. For higher values, the result is interpolated in the real dimensions of the dataset with an order of interpolation equal to the value provided (more than 10 does not work for Dalitz efficiencies, 9 for masses efficiencies, 10 for angles)
relHistPdf->setUnitNorm(kTRUE);
/*
// with RooNDKeysPDF
RooRealVar binContent("binContent","binContent",1,0,99);
effVars->add(binContent);
RooDataSet* relEffSet = new RooDataSet(relEffTH2->GetName(), relEffTH2->GetTitle(), *effVars, WeightVar("binContent"));
//RooDataSet* relEffSet = new RooDataSet(relEffTH2->GetName(), relEffTH2->GetTitle(), *effVars);
for (Int_t i=0; i<=xBins+1; ++i)
for (Int_t j=0; j<=yBins+1; ++j) {
x->setVal( relEffTH2->GetXaxis()->GetBinCenter(i) );
y->setVal( relEffTH2->GetYaxis()->GetBinCenter(j) );
binContent.setVal( relEffTH2->GetBinContent(i,j) );
//cout <<"x = " <<x->getVal() <<", y = " <<y->getVal() <<", w = " <<binContent.getVal() <<endl;
relEffSet->add( *effVars );
//relEffSet->add( *effVars, binContent.getVal() );
}
relEffSet->printArgs(cout); cout <<"; "; relEffSet->printValue(cout); cout <<"; relEffSet->isWeighted() = " <<relEffSet->isWeighted() <<" and relEffSet->sumEntries() = " <<relEffSet->sumEntries() <<endl;
//TH2F* relEffTH2_fromSet = (TH2F*)relEffSet->createHistogram("relEffTH2_fromSet", *x, Binning(*xRooBinning), YVar(*y, Binning(*yRooBinning)) ) ;
TH2F* relEffTH2_fromSet = (TH2F*)relEffSet->createHistogram(*x, *y, xBins, yBins, "", "relEffTH2_fromSet") ;
relEffTH2_fromSet->Draw("LEGO");
return;
RooNDKeysPdf* relHistPdf = new RooNDKeysPdf("relHistPdf","relHistPdf", *effVars, *relEffSet, "amdv");
*/
effPdf[iEff].first = relHistPdf;
// effPdf[iEff].first = twoDFit(*x, *y, relEffTH2, psi_nS.Atoi(), xOrder, yOrder, effPdf[iEff].second); method = "ROOTfit";
const Float_t chi2N = effPdf[iEff].second;
RooAbsPdf* kinematicCheck(0), *effWithKinCheck(0);
if (effVars->GetName() == massVars_name || effVars->GetName() == mass2Vars_name)
kinematicCheck = new Dalitz_contour("Dalitz_kinCheck","kinematic check for Dalitz", *x, *y, DalitzEff, psi_nS) ;
else if (effVars->GetName() == sqDalitz_name)
kinematicCheck = new sqDalitz_contour("sqDalitz_kinCheck","kinematic check for square Dalitz", *x, *y, DalitzEff, psi_nS.Atoi()) ;
else if (effVars->GetName() == angleVars_name)
kinematicCheck = new Angles_contour("angles_kinCheck","kinematic check for angles", *x, *y) ;
//
if (kinematicCheck) {
cout <<"Multiplying " <<relHistPdf->GetTitle() <<" by " <<kinematicCheck->GetTitle() <<endl;
effWithKinCheck = new RooProdPdf(TString::Format("%s_withKinCheck",relHistPdf->GetName()),TString::Format("%s with kinematic check",relHistPdf->GetTitle()),RooArgSet(*kinematicCheck,*effPdf[iEff].first)) ;
if (effWithKinCheck)
effPdf[iEff].first = effWithKinCheck;
}
TString effErrTH2_name = relEffTH2->GetName(); effErrTH2_name.ReplaceAll("Eff","EffErr");
chi2N_hist(effFile, effErrTH2_name, relEffTH2, effPdf[iEff].first, x, y, method, dir+"/eff", extension);
//return;
//relEffTH2->Draw("LEGO");
plotting(relEffHist, effName, x, y, xRooBinning, yRooBinning, effPdf[iEff].first, pdfTitle, xOrder, effHisto_names[iEff].second.second.first.first, effHisto_names[iEff].second.second.first.second, yOrder, effHisto_names[iEff].second.second.second.first, effHisto_names[iEff].second.second.second.second, chi2N, method, dir+"/eff", extension);
/*
x->setVal(4.75); y->setVal(16.);
cout <<"\neffPdf[iEff].first->getVal(" <<x->getVal() <<", " <<y->getVal() <<") = " <<effPdf[iEff].first->getVal() <<endl;
cout <<"with relHistPdf->haveUnitNorm() = " <<relHistPdf->haveUnitNorm() <<endl;
if (relHistPdf->haveUnitNorm()) {
relHistPdf->setUnitNorm(kFALSE);
cout <<"\neffPdf[iEff].first->getVal(" <<x->getVal() <<"," <<y->getVal() <<") = " <<effPdf[iEff].first->getVal() <<endl;
cout <<"with relHistPdf->haveUnitNorm() = " <<relHistPdf->haveUnitNorm() <<endl;
} else {
relHistPdf->setUnitNorm(kTRUE);
cout <<"\neffPdf[iEff].first->getVal(" <<x->.getVal() <<"," <<y->getVal() <<") = " <<effPdf[iEff].first->getVal() <<endl;
cout <<"with relHistPdf->haveUnitNorm() = " <<relHistPdf->haveUnitNorm() <<endl;
}
*/
if (iEff==0) {
if (effVars != &massVars) {
method = "derivedFromFit";
/*
void deriveMassesPdf(const RooArgSet* massVars, const TString massKPi_name, const TString massPsiPi_name, RooAbsPdf& *pdf, const TString thName, const Int_t xOrder, const TString xName, const TString xTitle, const Int_t yOrder, const TString yName, const TString yTitle, const Float_t chi2N, const TString method, const TString dir, const TString extension) {}
TString massesTH_name = "RelEff_psi2SPi_vs_KPi_B0constr";
deriveMassesPdf(&massVars, massKPi_name, massPsiPi_name, massesTH_name, xOrder, const TString xName, const TString xTitle, yOrder, const TString yName, const TString yTitle, chi2N, method, dir, extension);
*/
if (kTRUE) { // insert effVars == (m2(K Pi),cos(theta(K*))) check)
x = (RooRealVar*)(massVars.find(massKPi_name));
y = (RooRealVar*)(massVars.find(massPsiPi_name));
effPdf[iEff].first = new sqDalitzToMassesPdf("sqDalitzToMassesPdf","sqDalitzToMassesPdf", *x, *y, effPdf[iEff].first, (RooRealVar*)effVars->find(mass2KPi_name), (RooRealVar*)effVars->find("cosKstar"), massMuMu);
TH2F* relEffMassesTH2 = (TH2F*)effFile->Get("RelEff_psi2SPi_vs_KPi_B0constr");
if (!relEffMassesTH2) {
cout <<"WARNING! No TH2F \"RelEff_psi2SPi_vs_KPi_B0constr\" found in TFile \"" <<effFile->GetName() <<"\".\nSkipping masses efficiency correction" <<endl;
} else {
setBinning(relEffMassesTH2,xMin,xMax,yMin,yMax,xRooBinning,yRooBinning);
effName = "relEffMasses";
relEffHist = new RooDataHist(relEffMassesTH2->GetName(), relEffMassesTH2->GetTitle(), massVars, relEffMassesTH2) ;
plotting(relEffHist, effName, x, y, xRooBinning, yRooBinning, effPdf[iEff].first, pdfTitle, xOrder, effHisto_names[iEff].second.second.first.first, effHisto_names[iEff].second.second.first.second, yOrder, effHisto_names[iEff].second.second.second.first, effHisto_names[iEff].second.second.second.second, 0, method, dir, extension);
}
} else {
// do the same for effVars == (m2(K Pi),m2(J/psi Pi))
}
} // if (effVars != &massVars)
/*
// Creating the efficiency as function of masses from the efficiency as function of squared masses, in order to allow the multiplication with sigPDF
if (DalitzEff) {
effMasses* massesEffPdf_fromDalitz = new effMasses(TString::Format("%s_fromDalitz",effPdf[iEff].first->GetName()), effPdf[iEff].first->GetTitle(), massKPi, massPsiPi, &mass2KPi, &mass2PsiPi, effPdf[iEff].first);
//TH1F* massesEffPdf_fromDalitz_mKPTH1 = (TH1F*)massesEffPdf_fromDalitz->createHistogram("massesEffPdf_fromDalitz_mKPTH1", massKPi) ; // not working with message: p.d.f normalization integral is zero or negative
TH2F* massesEffPdf_fromDalitz_TH2 = (TH2F*)massesEffPdf_fromDalitz->createHistogram("", massKPi, Binning(1*xBins,massKPi_min,massKPi_max), YVar(massPsiPi, Binning(1*yBins,massPsiPi_min,massPsiPi_max)) ) ; massesEffPdf_fromDalitz_TH2->SetName("massesEffPdf_fromDalitz_TH2"); massesEffPdf_fromDalitz_TH2->SetTitleOffset(TH2_offset,"XY");
massesEffPdf_fromDalitz_TH2->Draw("LEGO");
gPad->SaveAs(TString::Format("%s/%s%s",dir.Data(),massesEffPdf_fromDalitz_TH2->GetName(),extension.Data()));
modelWithEff = new RooProdPdf(pdfToCorr_name.Append("__withMassesEff"),TString::Format("(%s)*#epsilon(masses)",pdfToCorrect->GetTitle()),RooArgSet(*pdfToCorrect,*massesEffPdf_fromDalitz)) ;
}
*/
//massKPi.setVal(2.); massPsiPi.setVal(4.);
//cout <<"massKPi = " <<massKPi.getVal() <<", mass2KPi = " <<mass2KPi.getVal() <<", massPsiPi = " <<massPsiPi.getVal() <<", mass2PsiPi = " <<mass2PsiPi.getVal() <<endl;
//cout <<"effPdf[iEff].first->getVal() = " <<effPdf[iEff].first->getVal() <<", effPdf[iEff].first->getValV() = " <<effPdf[iEff].first->getValV() <<endl;
//cout <<"pdfToCorrect->getVal() = " <<pdfToCorrect->getVal() <<", pdfToCorrect->getValV() = " <<pdfToCorrect->getValV() <<endl;
//cout <<"massKPi = " <<massKPi.getVal() <<", mass2KPi = " <<mass2KPi.getVal() <<", massPsiPi = " <<massPsiPi.getVal() <<", mass2PsiPi = " <<mass2PsiPi.getVal() <<endl;
} // if (iEff==0)
//modelWithEff = new RooProdPdf(pdfToCorr_name.Append("__with"+effType+"Eff"),TString::Format("%s * #epsilon("+efftype+")",pdfToCorrect->GetTitle()),RooArgSet(*pdfToCorrect,*effPdf[iEff].first)) ; model = modelWithEff; // replacing sigPdf * eff(M) * eff(A) with sigPdf * [eff(M) * eff(A)] seems to improve the generation time
} // for (Int_t iEff=0; iEff < 2; ++iEff)
else
cout <<"WARNING! TFile \"" <<effFileName <<"\" could not be opened.\nSkipping efficiency correction" <<endl;
//return;
RooProdPdf* effModel = 0;
if (effPdf[0].first && effPdf[1].first)
effModel = new RooProdPdf(TString::Format("%s_X_%s",effPdf[0].first->GetName(),effPdf[1].first->GetName()),TString::Format("%s * %s",effPdf[0].first->GetTitle(),effPdf[1].first->GetTitle()),RooArgSet(*effPdf[0].first,*effPdf[1].first));
if ((model != modelWithEff) && effModel) {
std::cout<<"\nMultiplying " <<effModel->GetTitle() <<" to " <<pdfToCorrect->GetTitle() <<std::endl;
modelWithEff = new RooProdPdf(TString::Format("%s__with__%s",pdfToCorr_name.Data(),effModel->GetName()),TString::Format("%s * (%s)",pdfToCorrect->GetTitle(),effModel->GetTitle()),*pdfToCorrect,*effModel) ;
model = modelWithEff;
}
// adding background
RooAddPdf* modelWithBkgHist = 0;
if (sbsModel) {
std::cout<<"\nAdding " <<(1 - fixSig.getVal())*100 <<"\% of bkg to pdf" <<std::endl;
modelWithBkgHist = new RooAddPdf(TString::Format("%s__with__%s",model->GetName(),sbsModel->GetName()),TString::Format("%s + %s",model->GetTitle(),sbsModel->GetTitle()),*model,*sbsModel,fixSig) ;
model = modelWithBkgHist;
}
cout <<"\nmodel->getVal() = " <<model->getVal() <<endl;
//return;
Int_t nLegendEntries = 0;
TString selection = "cutBased";
if (tmva) selection = bdtCut_long;
selection.Prepend("__");
if (generating) {
if (B0BarFlag)
B0beauty.setVal(-1.1);
else
B0beauty.setVal(+1.1);
B0beauty.setConstant(kTRUE);
// Generate toy data from pdf and plot data and p.d.f on frame
cout <<"\nGenerating " <<nEvents.getVal() <<" events according to " <<model->GetTitle() <<" pdf for " <<model->GetName() <<" with " <<B0beauty.getTitle() <<" = " <<B0beauty.getVal() <<endl;
cout <<"\nNOTE: Generation time does not scale with number of events up to at least 10k events, from 100k yes" <<endl;
#ifdef TIME_INFO
timeval genTime;
gettimeofday(&start, NULL);
startCPU = times(&startProc);
#endif
//
TString dataGenName = "Generated_data_from_PDF"; TString dataGen_Name = dataGenName;
RooDataSet* dataGenPDF = model->generate(kinematicVars, nEvents.getVal(), Verbose(kTRUE), Name(dataGenName)) ; dataGenPDF->SetTitle(dataGenName.ReplaceAll("_"," "));
//RooDataSet* dataGenPDFB0 = model->generate(kinematicVars_withBeauty, nEvents.getVal(), Verbose(kTRUE), Name(dataGenName)) ; dataGenPDFB0->SetTitle(dataGenName.ReplaceAll("_"," "));
// RooArgSet genSet = kinematicVars; genSet = kinematicVars_withBeauty;
// RooDataSet* dataGenPDF = model->generate(genSet, nEvents.getVal(), Verbose(kTRUE), Name(dataGenName)) ; dataGenPDF->SetTitle(dataGenName.ReplaceAll("_"," "));
//
#ifdef TIME_INFO
stopCPU = times(&stopProc);
gettimeofday(&stop, NULL);
timersub(&stop, &start, &genTime);
Double_t genTimeCPU = (stopCPU - startCPU)*10000;
Double_t genTimeProc = (stopProc.tms_utime - startProc.tms_utime)*10000 ;
cout <<"\n" <<nEvents.getVal() <<" events have been genrated in\n" ;
cout <<"Wallclock time: " << genTime.tv_sec + genTime.tv_usec/1000000.0 << " seconds\n" ;
cout <<"Total CPU time: " << (genTimeCPU / CLOCKS_PER_SEC) <<" seconds\n" ;
cout <<"My processes time: " << (genTimeProc / CLOCKS_PER_SEC) << " seconds (differences due to other users' processes on the same CPU)" << endl ;
//if (nEvents.getVal() > 100000)
// dataGenPDF->write(TString::Format("%s/%s.txt",datasetsPath.Data(),model->GetName()));
#endif
TString flavour = "B0";
if (B0BarFlag) flavour.Append("bar");
dataGenPDF->write(TString::Format("%s/%s/%s%s.txt",datasetsPath.Data(),flavour.Data(),model->GetName(),selection.Data()));
//dataGenPDFB0->write(TString::Format("%s/%s/%s%s__B0Flag.txt",datasetsPath.Data(),flavour.Data(),model->GetName(),selection.Data()));
cout << "\nGeneration done..." << endl;
//return;
dataToFit = dataGenPDF;
}
cout <<"\nPlotting data..." <<endl;
TString plotName = model->GetName();
Float_t rightMargin = 0.12;
Float_t cos_limit = 1.02; Float_t cos_margin = 0.02;
Float_t phi_limit = 3.2; Float_t phi_margin = 0.05;