forked from erc-asymow/TemplateStudies
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjac2.cpp
More file actions
1310 lines (1188 loc) · 51.4 KB
/
jac2.cpp
File metadata and controls
1310 lines (1188 loc) · 51.4 KB
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 <ROOT/RDataFrame.hxx>
#include "TFile.h"
#include "TRandom3.h"
#include "TVector.h"
#include "TVectorT.h"
#include "TMath.h"
#include "TF1.h"
#include "TF2.h"
#include <TMatrixD.h>
#include <TStopwatch.h>
#include <ROOT/RVec.hxx>
#include <iostream>
#include <boost/program_options.hpp>
#include <Eigen/Core>
#include <Eigen/Dense>
using Eigen::MatrixXd;
using Eigen::VectorXd;
using namespace std;
using namespace ROOT;
typedef ROOT::VecOps::RVec<double> RVecD;
using ROOT::RDF::RNode;
using namespace boost::program_options;
std::vector<std::string> helicities = {"A0", "A1", "A2", "A3", "A4"};
constexpr double MW = 80.;
constexpr double GW = 2.0;
constexpr double MASSSHIFT = 0.01;
constexpr int NMAX = 200;
//constexpr int NMASS = 20;
constexpr int NMASS = 10;
constexpr double DELTAM = 0.200;
enum pdf_type { pdf_x=0, pdf_y, corr_x, corr_y, A0_x, A0_y, A1_x, A1_y, A2_x, A2_y, A3_x, A3_y, A4_x, A4_y, unknown};
auto get_pdf_type = [](const std::string& name) {
if (name=="A0_x") return pdf_type::A0_x;
else if(name=="A0_y") return pdf_type::A0_y;
else if(name=="A1_x") return pdf_type::A1_x;
else if(name=="A1_y") return pdf_type::A1_y;
else if(name=="A2_x") return pdf_type::A2_x;
else if(name=="A2_y") return pdf_type::A2_y;
else if(name=="A3_x") return pdf_type::A3_x;
else if(name=="A3_y") return pdf_type::A3_y;
else if(name=="A4_x") return pdf_type::A4_x;
else if(name=="A4_y") return pdf_type::A4_y;
else return pdf_type::unknown;
};
auto cheb = [](double x, double scale, double offset, unsigned int n, unsigned int m){
double den = 0.;
double num = 0.;
for(unsigned int i = 0; i <= n ; i++){
int sign = i%2==0 ? +1 :-1;
double xj = (TMath::Cos((n-i)*TMath::Pi()/n) + offset)*scale;
if(x==xj) return 1.0;// protect from nan
double val = sign/(x-xj);
if(i==0 || i==n) val *= 0.5;
den += val;
if(i==m) num = val;
}
//std::cout << x << "==>" << num << "," << den << std::endl;
return num/den;
};
int main(int argc, char* argv[])
{
TStopwatch sw;
sw.Start();
ROOT::EnableImplicitMT();
variables_map vm;
try
{
options_description desc{"Options"};
desc.add_options()
("help,h", "Help screen")
("nevents", value<long>()->default_value(1000), "number of events")
("degs_corr_x", value<int>()->default_value(2), "max degree in x of corrxy")
("degs_corr_y", value<int>()->default_value(2), "max degree in y of corrxy")
("degs_A0_x", value<int>()->default_value(2), "max degree in x for A0")
("degs_A0_y", value<int>()->default_value(2), "max degree in y for A0")
("degs_A1_x", value<int>()->default_value(2), "max degree in x for A1")
("degs_A1_y", value<int>()->default_value(2), "max degree in y for A1")
("degs_A2_x", value<int>()->default_value(2), "max degree in x for A2")
("degs_A2_y", value<int>()->default_value(2), "max degree in y for A2")
("degs_A3_x", value<int>()->default_value(2), "max degree in x for A3")
("degs_A3_y", value<int>()->default_value(2), "max degree in y for A3")
("degs_A4_x", value<int>()->default_value(2), "max degree in x for A4")
("degs_A4_y", value<int>()->default_value(2), "max degree in y for A4")
("max_x", value<double>()->default_value(0.4), "range in x")
("max_y", value<double>()->default_value(2.5), "range in y")
("tag", value<std::string>()->default_value(""), "tag name")
("run", value<std::string>()->default_value("closure"), "run type")
("do_jac_vs_mass", bool_switch()->default_value(false), "compute jacobians for three mass values")
("smear", bool_switch()->default_value(false), "smear")
//("getbin_extTH2_corr", bool_switch()->default_value(false), "get bin corr(x,y)")
//("inter_extTH2_corr", bool_switch()->default_value(false), "interpol corr(x,y)")
//("toyTF2_corr", bool_switch()->default_value(false), "toy TF2 corr(x,y)")
("seed", value<int>()->default_value(4357), "seed")
("fit_qt_y", bool_switch()->default_value(false), "fit qt vs y")
("unweighted", bool_switch()->default_value(false), "unweighted")
("fullphasespace", bool_switch()->default_value(false), "fullphasespace")
("clip", bool_switch()->default_value(false), "clip")
("relativistic", bool_switch()->default_value(false), "relativistic");
store(parse_command_line(argc, argv, desc), vm);
notify(vm);
if (vm.count("help")){
std::cout << desc << '\n';
return 0;
}
if (vm.count("nevents")) std::cout << "Number of events: " << vm["nevents"].as<long>() << '\n';
if (vm.count("tag")) std::cout << "Tag: " << vm["tag"].as<std::string>() << '\n';
if (vm.count("run")) std::cout << "Run: " << vm["run"].as<std::string>() << '\n';
if (vm.count("degs_corr_y")) std::cout << "Degree in x of corrxy: " << vm["degs_corr_x"].as<int>() << '\n';
if (vm.count("degs_corr_y")) std::cout << "Degree in y of corrxy: " << vm["degs_corr_y"].as<int>() << '\n';
for(auto hel : helicities){
if (vm.count("degs_"+hel+"_x")) std::cout << "Degree in x of "+hel+": " << vm["degs_"+hel+"_x"].as<int>() << '\n';
if (vm.count("degs_"+hel+"_y")) std::cout << "Degree in y of "+hel+": " << vm["degs_"+hel+"_y"].as<int>() << '\n';
}
}
catch (const error &ex)
{
std::cerr << ex.what() << '\n';
}
long nevents = vm["nevents"].as<long>();
std::string tag = vm["tag"].as<std::string>();
std::string run = vm["run"].as<std::string>();
int degs_corr_x = vm["degs_corr_x"].as<int>();
int degs_corr_y = vm["degs_corr_y"].as<int>();
int degs_A0_x = vm["degs_A0_x"].as<int>();
int degs_A0_y = vm["degs_A0_y"].as<int>();
int degs_A1_x = vm["degs_A1_x"].as<int>();
int degs_A1_y = vm["degs_A1_y"].as<int>();
int degs_A2_x = vm["degs_A2_x"].as<int>();
int degs_A2_y = vm["degs_A2_y"].as<int>();
int degs_A3_x = vm["degs_A3_x"].as<int>();
int degs_A3_y = vm["degs_A3_y"].as<int>();
int degs_A4_x = vm["degs_A4_x"].as<int>();
int degs_A4_y = vm["degs_A4_y"].as<int>();
bool do_jac_vs_mass = vm["do_jac_vs_mass"].as<bool>();
bool smear = vm["smear"].as<bool>();
//bool getbin_extTH2_corr = vm["getbin_extTH2_corr"].as<bool>();
//bool inter_extTH2_corr = vm["inter_extTH2_corr"].as<bool>();
//bool toyTF2_corr = vm["toyTF2_corr"].as<bool>();
bool fit_qt_y = vm["fit_qt_y"].as<bool>();
int seed = vm["seed"].as<int>();
if(vm.count("degs_corr_x")) tag += std::string(Form("_UL_%d", degs_corr_x));
if(vm.count("degs_corr_y")) tag += std::string(Form("_%d", degs_corr_y));
if(vm.count("degs_A0_x")) tag += std::string(Form("_A0_%d", degs_A0_x));
if(vm.count("degs_A0_y")) tag += std::string(Form("_%d", degs_A0_y));
if(vm.count("degs_A1_x")) tag += std::string(Form("_A1_%d", degs_A1_x));
if(vm.count("degs_A1_y")) tag += std::string(Form("_%d", degs_A1_y));
if(vm.count("degs_A2_x")) tag += std::string(Form("_A2_%d", degs_A2_x));
if(vm.count("degs_A2_y")) tag += std::string(Form("_%d", degs_A2_y));
if(vm.count("degs_A3_x")) tag += std::string(Form("_A3_%d", degs_A3_x));
if(vm.count("degs_A3_y")) tag += std::string(Form("_%d", degs_A3_y));
if(vm.count("degs_A4_x")) tag += std::string(Form("_A4_%d", degs_A4_x));
if(vm.count("degs_A4_y")) tag += std::string(Form("_%d", degs_A4_y));
const double deltapOp = 0.015;
const double deltakOk = 0.0002;
const double deltah = 0.001;
double max_x = vm["max_x"].as<double>();
double max_y = vm["max_y"].as<double>();
bool unweighted = vm["unweighted"].as<bool>();
bool fullphasespace = vm["fullphasespace"].as<bool>();
bool clip = vm["clip"].as<bool>();
bool relativistic = vm["relativistic"].as<bool>();
bool do_cheb_as_modifiers = false;
if(run=="corr") do_cheb_as_modifiers = true;
int nbins_rap = 24;
double rap_low = 0.0;
//int nbins_rap = 48;
//double rap_low = -2.4;
double rap_high = +2.4;
//int nbins_pt = 35;
int nbins_pt = 30;
//double pt_low = 25.;
double pt_low = 26.;
//double pt_high = 60.;
double pt_high = 56.;
if(fit_qt_y){
nbins_rap = 13;
rap_low = -max_y;
rap_high = +max_y;
nbins_pt = 15;
pt_low = 0.;
pt_high = +max_x;
}
auto degs = [degs_corr_x,degs_corr_y,degs_A0_x,degs_A0_y,degs_A1_x,degs_A1_y,degs_A2_x,degs_A2_y,degs_A3_x,degs_A3_y,degs_A4_x,degs_A4_y]
(const pdf_type& pdf){
switch(pdf){
case pdf_type::corr_x: // corr(x,.)
if(degs_corr_x>0) return degs_corr_x;
else return 2;
case pdf_type::corr_y: // corr(.,y)
if(degs_corr_y>0) return degs_corr_y;
else return 2;
case pdf_type::A0_x: // A0(x,.)
if(degs_A0_x>0) return degs_A0_x;
else return 2;
case pdf_type::A0_y: // A0(.,y)
if(degs_A0_y>0) return degs_A0_y;
else return 2;
case pdf_type::A1_x: // A1(x,.)
if(degs_A1_x>0) return degs_A1_x;
else return 2;
case pdf_type::A1_y: // A1(.,y)
if(degs_A1_y>0) return degs_A1_y;
else return 2;
case pdf_type::A2_x: // A2(x,.)
if(degs_A2_x>0) return degs_A2_x;
else return 2;
case pdf_type::A2_y: // A2(.,y)
if(degs_A2_y>0) return degs_A2_y;
else return 2;
case pdf_type::A3_x: // A3(x,.)
if(degs_A3_x>0) return degs_A3_x;
else return 2;
case pdf_type::A3_y: // A3(.,y)
if(degs_A3_y>0) return degs_A3_y;
else return 2;
case pdf_type::A4_x: // A4(x,.)
if(degs_A4_x>0) return degs_A4_x;
else return 2;
case pdf_type::A4_y: // A4(.,y)
if(degs_A4_y>0) return degs_A4_y;
else return 2;
default: return 1;
}
};
unsigned int njacs = 0;
unsigned int first_jac_corrxy = 0;
unsigned int first_jac_A0xy = 0;
unsigned int first_jac_A1xy = 0;
unsigned int first_jac_A2xy = 0;
unsigned int first_jac_A3xy = 0;
unsigned int first_jac_A4xy = 0;
unsigned int njacs_corrxy_x = 0;
unsigned int njacs_corrxy_y = 0;
unsigned int njacs_A0_x = 0;
unsigned int njacs_A0_y = 0;
unsigned int njacs_A1_x = 0;
unsigned int njacs_A1_y = 0;
unsigned int njacs_A2_x = 0;
unsigned int njacs_A2_y = 0;
unsigned int njacs_A3_x = 0;
unsigned int njacs_A3_y = 0;
unsigned int njacs_A4_x = 0;
unsigned int njacs_A4_y = 0;
//A1(.,0)=0 & odd
//A3(.,0)=0 & even
//A4(.,0)=0 & odd + A4(0,.)!=0
if(run=="full"){
assert( degs(pdf_type::A3_y)%2 == 0 );
njacs_corrxy_x = degs(pdf_type::corr_x);
njacs_corrxy_y = degs(pdf_type::corr_y)/2 + 1;
njacs_A0_x = degs(pdf_type::A0_x) ;
njacs_A0_y = degs(pdf_type::A0_y)/2 + 1;
njacs_A1_x = degs(pdf_type::A1_x);
njacs_A1_y = (degs(pdf_type::A1_y)+1)/2;
njacs_A2_x = degs(pdf_type::A2_x);
njacs_A2_y = degs(pdf_type::A2_y)/2 + 1;
njacs_A3_x = degs(pdf_type::A3_x);
njacs_A3_y = degs(pdf_type::A3_y)/2;
njacs_A4_x = degs(pdf_type::A4_x) + 1;
njacs_A4_y = (degs(pdf_type::A4_y)+1)/2;
}
else if(run=="corr"){
njacs_corrxy_x = degs(pdf_type::corr_x) + 1 - int(clip);
njacs_corrxy_y = degs(pdf_type::corr_y)/2 + 1 - int(clip);
njacs_A0_x = degs(pdf_type::A0_x) + 1 - int(clip);
njacs_A0_y = degs(pdf_type::A0_y)/2 + 1 - int(clip);
njacs_A1_x = degs(pdf_type::A1_x) + 1 - int(clip);
njacs_A1_y = degs(pdf_type::A1_y)/2 + 1 - int(clip);
njacs_A2_x = degs(pdf_type::A2_x) + 1 - int(clip);
njacs_A2_y = degs(pdf_type::A2_y)/2 + 1 - int(clip);
njacs_A3_x = degs(pdf_type::A3_x) + 1 - int(clip);
njacs_A3_y = degs(pdf_type::A3_y)/2 + 1 - int(clip);
njacs_A4_x = degs(pdf_type::A4_x) + 1 - int(clip);
njacs_A4_y = degs(pdf_type::A4_y)/2 + 1 - int(clip);
}
else if(run=="grid"){
njacs_corrxy_x = degs(pdf_type::corr_x);
njacs_corrxy_y = degs(pdf_type::corr_y);
njacs_A0_x = njacs_corrxy_x;
njacs_A0_y = njacs_corrxy_y;
njacs_A1_x = njacs_corrxy_x;
njacs_A1_y = njacs_corrxy_y;
njacs_A2_x = njacs_corrxy_x;
njacs_A2_y = njacs_corrxy_y;
njacs_A3_x = njacs_corrxy_x;
njacs_A3_y = njacs_corrxy_y;
njacs_A4_x = njacs_corrxy_x;
njacs_A4_y = njacs_corrxy_y;
}
unsigned int njacs_corrxy = njacs_corrxy_x*njacs_corrxy_y;
unsigned int njacs_A0xy = njacs_A0_x*njacs_A0_y;
unsigned int njacs_A1xy = njacs_A1_x*njacs_A1_y;
unsigned int njacs_A2xy = njacs_A2_x*njacs_A2_y;
unsigned int njacs_A3xy = njacs_A3_x*njacs_A3_y;
unsigned int njacs_A4xy = njacs_A4_x*njacs_A4_y;
njacs += njacs_corrxy;
first_jac_A0xy = njacs;
njacs += njacs_A0xy;
first_jac_A1xy = njacs;
njacs += njacs_A1xy;
first_jac_A2xy = njacs;
njacs += njacs_A2xy;
first_jac_A3xy = njacs;
njacs += njacs_A3xy;
first_jac_A4xy = njacs;
njacs += njacs_A4xy;
auto toy_mass = [&](double Q, double M, double G){
if (relativistic){
double gamma = TMath::Sqrt(M*M*(M*M+G*G));
double k = 2*TMath::Sqrt2()*M*G*gamma/TMath::Pi()/TMath::Sqrt(M*M+gamma);
return k/((Q*Q-M*M)*(Q*Q-M*M)+M*M*G*G);
}
return 1./TMath::Pi()/(1 + (Q-M)*(Q-M)/(G*G/4))*2./G; // non-relativistic
};
TF1* tf1toy_x = new TF1("toy_x", "[0]*x/TMath::Power(x*x+[1], 1.0)", 0.0, max_x);
double p0_x = +2.35e-03;
tf1toy_x->SetParameter(0, 1.0);
tf1toy_x->SetParameter(1, p0_x);
double int_toy_x = tf1toy_x->Integral(0.0, max_x);
tf1toy_x->SetParameter(0, 1.0/int_toy_x);
auto toy_x = [&](double x)->double{
return x/TMath::Power(x*x + p0_x, 1.0)/int_toy_x;
};
TF1* tf1toy_y = new TF1("toy_y", "[2]/TMath::Sqrt(2*TMath::Pi()*[1])*TMath::Exp(-0.5*(x-[0])*(x-[0])/[1])", -max_y, max_y);
double sigma2_y = 4.0*4.0;
tf1toy_y->SetParameter(0, 0.0);
tf1toy_y->SetParameter(1, sigma2_y);
tf1toy_y->SetParameter(2, 1.0);
double int_toy_y = tf1toy_y->Integral(-max_y, max_y);
tf1toy_y->SetParameter(2, 1.0/int_toy_y);
auto toy_y = [&](double y)->double{
return 1.0/int_toy_y/TMath::Sqrt(2*TMath::Pi()*sigma2_y)*TMath::Exp(-0.5*y*y/sigma2_y);
};
/*
TFile* fWJets = TFile::Open("WJets.root","READ");
TH2F* th2_corrxy = 0;
*/
TF2* tf2toy_corrxy = new TF2("toy_corrxy","0.1*(1.0 - 0.3*y*y)*TMath::Erf(5.0*x) + 1.0", 0., max_x, -max_y, +max_y);
auto toy_corrxy = [](double x, double y)->double{
return 0.1*(1.0 - 0.3*y*y)*TMath::Erf(5.0*x) + 1.0;
};
//if(fWJets!=nullptr && !fWJets->IsZombie()){
// std::cout << "WJets file found! Taking h2 as corrxy" << std::endl;
// th2_corrxy = fWJets->Get<TH2F>("h2");
//}
TF2* tf2toy_A0 = new TF2("toy_A0", "2*x*x*(1 - 0.01*y*y)", 0., max_x, -max_y, max_y);
TF2* tf2toy_A1 = new TF2("toy_A1", "(0.5*x + 2*x*x)*( 0.05*y + 0.002*y*y*y)", 0., max_x, -max_y, max_y);
TF2* tf2toy_A2 = new TF2("toy_A2", "2*x*x*(1 - 0.01*y*y)", 0., max_x, -max_y, max_y);
//TF2* tf2toy_A3 = new TF2("toy_A3", "(x + x*x + x*x*x)*(1 - 0.01*y*y)", 0., max_x, -max_y, max_y);
TF2* tf2toy_A3 = new TF2("toy_A3", "0.3*(x + x*x + x*x*x)*(0.1*y*y)", 0., max_x, -max_y, max_y);
TF2* tf2toy_A4 = new TF2("toy_A4", "(1-x)*(y + y*y*y/10.)/5", 0., max_x, -max_y, max_y);
//auto toy_A0 = [](double x, double y)->double{ return 2*x*x*(1 - 0.01*y*y); };
//auto toy_A1 = [](double x, double y)->double{ return (0.5*x + 2*x*x)*(0.05*y + 0.002*y*y*y); };
//auto toy_A2 = [](double x, double y)->double{ return 2*x*x*(1 - 0.01*y*y); };
//auto toy_A3 = [](double x, double y)->double{ return 0.3*(x + x*x + x*x*x)*(0.1*y*y); };
//auto toy_A4 = [](double x, double y)->double{ return (1-x)*(y + y*y*y/10.)/5; };
string f_realistic_inputs_name = "fout_syst_wp_x0p40_y3p50_V1.root";
int flip_CS = 1;
if(f_realistic_inputs_name.find("wp")!=string::npos)
flip_CS = -1;
TFile* f_realistic_inputs = TFile::Open(f_realistic_inputs_name.c_str(), "READ");
TH2D* h_pdf_UL = (TH2D*)f_realistic_inputs->Get("UL/h_pdf_UL");
int nbinsX_UL = int(max_x/h_pdf_UL->GetXaxis()->GetBinWidth(1));
int nbinsY_UL = int(max_y/h_pdf_UL->GetYaxis()->GetBinWidth(1));
//cout << nbinsX_UL << ":" << nbinsY_UL << endl;
TH2D* h_pdf_UL_gen = new TH2D("h_pdf_UL_gen", "", nbinsX_UL, 0.0, max_x, nbinsY_UL, 0., max_y);
for(int ibx=1; ibx<=h_pdf_UL_gen->GetXaxis()->GetNbins();ibx++){
double ix = h_pdf_UL_gen->GetXaxis()->GetBinCenter(ibx);
for(int iby=1; iby<=h_pdf_UL_gen->GetYaxis()->GetNbins();iby++){
double iy = h_pdf_UL_gen->GetYaxis()->GetBinCenter(iby);
double in_val = h_pdf_UL->GetBinContent( h_pdf_UL->FindBin(ix,iy) );
h_pdf_UL_gen->SetBinContent(ibx,iby, TMath::Max(in_val, 0.0) );
}
}
// scale to be a pdf in [-y_max,y_max]
h_pdf_UL->Scale(0.5);
h_pdf_UL_gen->Scale(0.5);
// needed to compute fIntegral
double xx,yy;
h_pdf_UL_gen->GetRandom2(xx,yy, 0);
//cout << xx << ", " << yy << endl;
TH2D* h_pdf_A0 = (TH2D*)f_realistic_inputs->Get("A0/h_pdf_A0");
TH2D* h_pdf_A1 = (TH2D*)f_realistic_inputs->Get("A1/h_pdf_A1");
TH2D* h_pdf_A2 = (TH2D*)f_realistic_inputs->Get("A2/h_pdf_A2");
TH2D* h_pdf_A3 = (TH2D*)f_realistic_inputs->Get("A3/h_pdf_A3");
TH2D* h_pdf_A4 = (TH2D*)f_realistic_inputs->Get("A4/h_pdf_A4");
auto toy_UL = [h_pdf_UL](double x, double y)->double{
return h_pdf_UL->GetBinContent( h_pdf_UL->FindBin(x, TMath::Abs(y)) );
};
auto toy_A0 = [h_pdf_A0](double x, double y)->double{ return h_pdf_A0->GetBinContent( h_pdf_A0->FindBin(x, TMath::Abs(y)) );};
auto toy_A1 = [h_pdf_A1, flip_CS](double x, double y)->double{
if(y<0)
return -flip_CS*h_pdf_A1->GetBinContent( h_pdf_A1->FindBin(x, TMath::Abs(y)) );
return flip_CS*h_pdf_A1->GetBinContent( h_pdf_A1->FindBin(x, TMath::Abs(y)) );
};
auto toy_A2 = [h_pdf_A2](double x, double y)->double{ return h_pdf_A2->GetBinContent( h_pdf_A2->FindBin(x, TMath::Abs(y)) );};
auto toy_A3 = [h_pdf_A3](double x, double y)->double{ return h_pdf_A3->GetBinContent( h_pdf_A3->FindBin(x, TMath::Abs(y)) );};
auto toy_A4 = [h_pdf_A4,flip_CS](double x, double y)->double{
if(y<0)
return -flip_CS*h_pdf_A4->GetBinContent( h_pdf_A4->FindBin(x, TMath::Abs(y)) );
return flip_CS*h_pdf_A4->GetBinContent( h_pdf_A4->FindBin(x, TMath::Abs(y)) );
};
auto toy_UL_fast = [h_pdf_UL](int ibin)->double{
if(ibin==-99) return 0.0;
return h_pdf_UL->GetBinContent( ibin );
};
auto toy_A0_fast = [h_pdf_A0](int ibin)->double{
if(ibin==-99) return 0.0;
return h_pdf_A0->GetBinContent( ibin );
};
auto toy_A1_fast = [h_pdf_A1,flip_CS](double y, int ibin)->double{
if(ibin==-99) return 0.0;
if(y<0)
return -flip_CS*h_pdf_A1->GetBinContent( ibin );
return flip_CS*h_pdf_A1->GetBinContent( ibin );
};
auto toy_A2_fast = [h_pdf_A2](int ibin)->double{
if(ibin==-99) return 0.0;
return h_pdf_A2->GetBinContent( ibin );
};
auto toy_A3_fast = [h_pdf_A3](int ibin)->double{
if(ibin==-99) return 0.0;
return h_pdf_A3->GetBinContent( ibin );
};
auto toy_A4_fast = [h_pdf_A4,flip_CS](double y, int ibin)->double{
if(ibin==-99) return 0.0;
if(y<0)
return -flip_CS*h_pdf_A4->GetBinContent( ibin );
return flip_CS*h_pdf_A4->GetBinContent( ibin );
};
// preprare inputs
if(true){
TFile* fout = TFile::Open(("root/input_"+tag+".root").c_str(), "RECREATE");
TTree* tree = new TTree("tree", "tree");
double corr_xy[NMAX*NMAX];
for(int k = 0; k<=degs(pdf_type::corr_x); k++){
double x = (TMath::Cos((degs(pdf_type::corr_x)-k)*TMath::Pi()/degs(pdf_type::corr_x))+1.0)*0.5*max_x;
for(int l = 0; l<=degs(pdf_type::corr_y); l++){
int idx = (degs(pdf_type::corr_y)+1)*k + l;
tree->Branch(Form("corrxy_%d_%d", k,l), &(corr_xy[idx]), Form("corrxy_%d_%d/D", k,l));
double y = TMath::Cos((degs(pdf_type::corr_y)-l)*TMath::Pi()/degs(pdf_type::corr_y))*max_y;
//corr_xy[idx] = toy_x(x)*toy_y(y);
//if(getbin_extTH2_corr) corr_xy[idx] *= th2_corrxy->GetBinContent( th2_corrxy->FindBin(TMath::Abs(y), x) );
//else if(inter_extTH2_corr) corr_xy[idx] *= th2_corrxy->Interpolate(TMath::Abs(y),x);
//else if(toyTF2_corr)
//corr_xy[idx] *= toy_corrxy(x,y);
corr_xy[idx] = toy_UL(x,y);
}
}
// for A0 we sample in [-max_y,max_y]
double A0_xy[NMAX];
for(int m = 0; m<=degs(pdf_type::A0_x); m++){
double x = (TMath::Cos((degs(pdf_type::A0_x)-m)*TMath::Pi()/degs(pdf_type::A0_x))+1.0)*0.5*max_x;
for(int n = 0; n<=degs(pdf_type::A0_y); n++){
int idx = (degs(pdf_type::A0_y)+1)*m + n;
tree->Branch(Form("A0_xy_%d_%d", m,n), &(A0_xy[idx]), Form("A0_xy_%d_%d/D", m,n));
double y = TMath::Cos((degs(pdf_type::A0_y)-n)*TMath::Pi()/degs(pdf_type::A0_y))*max_y;
A0_xy[idx] = toy_A0(x,y);
}
}
// for A1 we sample in [0,max_y]
double A1_xy[NMAX];
for(int m = 0; m<=degs(pdf_type::A1_x); m++){
double x = (TMath::Cos((degs(pdf_type::A1_x)-m)*TMath::Pi()/degs(pdf_type::A1_x))+1.0)*0.5*max_x;
for(int n = 0; n<=degs(pdf_type::A1_y); n++){
int idx = (degs(pdf_type::A1_y)+1)*m + n;
tree->Branch(Form("A1_xy_%d_%d", m,n), &(A1_xy[idx]), Form("A1_xy_%d_%d/D", m,n));
double y = TMath::Cos((degs(pdf_type::A1_y)-n)*TMath::Pi()/degs(pdf_type::A1_y))*max_y;
A1_xy[idx] = toy_A1(x,y);
}
}
// for A2 we sample in [-max_y,max_y]
double A2_xy[NMAX];
for(int m = 0; m<=degs(pdf_type::A2_x); m++){
double x = (TMath::Cos((degs(pdf_type::A2_x)-m)*TMath::Pi()/degs(pdf_type::A2_x))+1.0)*0.5*max_x;
for(int n = 0; n<=degs(pdf_type::A2_y); n++){
int idx = (degs(pdf_type::A2_y)+1)*m + n;
tree->Branch(Form("A2_xy_%d_%d", m,n), &(A2_xy[idx]), Form("A2_xy_%d_%d/D", m,n));
double y = TMath::Cos((degs(pdf_type::A2_y)-n)*TMath::Pi()/degs(pdf_type::A2_y))*max_y;
A2_xy[idx] = toy_A2(x,y);
}
}
// for A3 we sample in [-max_y,max_y]
double A3_xy[NMAX];
for(int m = 0; m<=degs(pdf_type::A3_x); m++){
double x = (TMath::Cos((degs(pdf_type::A3_x)-m)*TMath::Pi()/degs(pdf_type::A3_x))+1.0)*0.5*max_x;
for(int n = 0; n<=degs(pdf_type::A3_y); n++){
int idx = (degs(pdf_type::A3_y)+1)*m + n;
tree->Branch(Form("A3_xy_%d_%d", m,n), &(A3_xy[idx]), Form("A3_xy_%d_%d/D", m,n));
double y = TMath::Cos((degs(pdf_type::A3_y)-n)*TMath::Pi()/degs(pdf_type::A3_y))*max_y;
A3_xy[idx] = toy_A3(x,y);
}
}
// for A4 we sample in [0,max_y]
double A4_xy[NMAX];
for(int m = 0; m<=degs(pdf_type::A4_x); m++){
double x = (TMath::Cos((degs(pdf_type::A4_x)-m)*TMath::Pi()/degs(pdf_type::A4_x))+1.0)*0.5*max_x;
for(int n = 0; n<=degs(pdf_type::A4_y); n++){
int idx = (degs(pdf_type::A4_y)+1)*m + n;
tree->Branch(Form("A4_xy_%d_%d", m,n), &(A4_xy[idx]), Form("A4_xy_%d_%d/D", m,n));
double y = TMath::Cos((degs(pdf_type::A4_y)-n)*TMath::Pi()/degs(pdf_type::A4_y))*max_y;
A4_xy[idx] = toy_A4(x,y);
}
}
tree->Fill();
tree->Write();
fout->Close();
if(nevents<0) return 0;
}
// We prepare an input tree to run on
TFile* fout = TFile::Open(("root/histos_"+tag+"_"+run+".root").c_str(), "RECREATE");
ROOT::RDataFrame d(nevents);
unsigned int nslots = d.GetNSlots();
std::vector<TRandom3*> rans = {};
for(unsigned int i = 0; i < nslots; i++){
rans.emplace_back( new TRandom3(seed + i*10) );
}
auto dlast = std::make_unique<RNode>(d);
std::vector<ROOT::RDF::RResultPtr<double> > sums = {};
dlast = std::make_unique<RNode>(dlast->DefineSlot("PS",[&, h_pdf_UL_gen](unsigned int nslot)->RVecD{
RVecD out;
bool accept = false;
double Q{0.0};
double cos{0.0};
double phi{0.0};
double x{0.0};
double y{0.0};
double pt{0.0};
double eta{0.0};
while(!accept){
Q = TMath::Tan(rans[nslot]->Uniform(-TMath::Pi()*0.5, +TMath::Pi()*0.5))*(GW/2) + MW;
while(Q < 50.0){
Q = TMath::Tan(rans[nslot]->Uniform(-TMath::Pi()*0.5, +TMath::Pi()*0.5))*(GW/2) + MW;
}
cos = rans[nslot]->Uniform(-1.0, 1.0);
phi = rans[nslot]->Uniform(-TMath::Pi(), +TMath::Pi());
x = rans[nslot]->Uniform(0.0, fullphasespace ? 0.45 : max_x);
y = rans[nslot]->Uniform(fullphasespace ? -4.0 : -max_y, fullphasespace ? 4.0 : max_y);
if(unweighted){
double xx = max_x*2;
double yy = max_y*2;
//cout << xx << ", " << yy << endl;
while(xx>max_x || TMath::Abs(yy)>max_y){
h_pdf_UL_gen->GetRandom2(xx,yy, rans[nslot]);
x = xx;
y = std::copysign(yy, rans[nslot]->Uniform(-1,1));
//cout << "GetRandom2: " << x << ", " << y << endl;
}
}
double qT2 = x*x*Q*Q;
double qT = TMath::Sqrt(qT2);
double XT = TMath::Sqrt(qT2 + Q*Q);
double Q0 = XT*TMath::CosH(y);
double Q3 = XT*TMath::SinH(y);
double sin = TMath::Sqrt(1-cos*cos);
Eigen::Matrix4d A;
A << Q0/Q, -qT/Q, 0.0, -Q3/Q,
-qT*Q0/Q/XT, XT/Q, 0.0, qT*Q3/Q/XT,
0.0, 0.0, 1.0, 0.0,
-Q3/XT, 0.0, 0.0, Q0/XT;
Eigen::Vector4d p4_CS;
p4_CS << Q/2, Q/2*sin*TMath::Cos(phi), Q/2*sin*TMath::Sin(phi), Q/2*cos ;
Eigen::Vector4d p4_lab = A.inverse()*p4_CS;
pt = TMath::Sqrt(p4_lab(1)*p4_lab(1) + p4_lab(2)*p4_lab(2));
eta = TMath::ASinH(p4_lab(3)/pt);
accept |= (pt>=pt_low && pt<=pt_high && TMath::Abs(eta)<=rap_high ) ;
//accept = true;
}
out.emplace_back( Q );
out.emplace_back( cos );
out.emplace_back( phi );
out.emplace_back( x );
out.emplace_back( y );
out.emplace_back( pt );
out.emplace_back( TMath::Abs(eta) );
//out.emplace_back( eta );
double pt_smear = rans[nslot]->Gaus(pt*(1.0 + deltakOk), pt*deltapOp);
double eta_smear = eta + rans[nslot]->Gaus(0.0, deltah);
out.emplace_back( pt_smear );
out.emplace_back( TMath::Abs(eta_smear) );
return out;
} ));
dlast = std::make_unique<RNode>(dlast->Define("Q", [](RVecD PS){return PS.at(0);}, {"PS"}));
dlast = std::make_unique<RNode>(dlast->Define("cos", [](RVecD PS){return PS.at(1);}, {"PS"}));
dlast = std::make_unique<RNode>(dlast->Define("phi", [](RVecD PS){return PS.at(2);}, {"PS"}));
dlast = std::make_unique<RNode>(dlast->Define("x", [](RVecD PS){return PS.at(3);}, {"PS"}));
dlast = std::make_unique<RNode>(dlast->Define("y", [](RVecD PS){return PS.at(4);}, {"PS"}));
dlast = std::make_unique<RNode>(dlast->Define("pt", [](RVecD PS){return PS.at(5);}, {"PS"}));
dlast = std::make_unique<RNode>(dlast->Define("eta", [](RVecD PS){return PS.at(6);}, {"PS"}));
dlast = std::make_unique<RNode>(dlast->Define("pt_smear", [](RVecD PS){return PS.at(7);}, {"PS"}));
dlast = std::make_unique<RNode>(dlast->Define("eta_smear", [](RVecD PS){return PS.at(8);}, {"PS"}));
dlast =std::make_unique<RNode>(dlast->Define("xybin", [h_pdf_UL](double x, double y)->int{
if(x > 0.4 && TMath::Abs(y) > 4.0 )
return h_pdf_UL->FindBin( 0.40, 4.0 );
if(x > 0.4 )
return h_pdf_UL->FindBin( 0.40, TMath::Abs(y) );
if( TMath::Abs(y) > 4.0 )
return h_pdf_UL->FindBin( x, 4.0 );
return h_pdf_UL->FindBin( x, TMath::Abs(y) );
}, {"x", "y"}));
dlast = std::make_unique<RNode>(dlast->Define("weights_mass",
[&](double Q)->RVecD{
RVecD out;
double gen = 1./TMath::Pi()/(1 + (Q-MW)*(Q-MW)/(GW*GW/4))*2./GW; //conversion factor
out.emplace_back( toy_mass(Q,MW,GW)/gen );
out.emplace_back( toy_mass(Q,MW+MASSSHIFT,GW)/gen );
out.emplace_back( toy_mass(Q,MW-MASSSHIFT,GW)/gen );
for(unsigned int i=0; i<NMASS; i++)
out.emplace_back( toy_mass(Q, MW - DELTAM*0.5 + DELTAM/(NMASS-1)*i,GW)/gen );
return out;
}, {"Q"}));
dlast = std::make_unique<RNode>(dlast->Define("corrxy_vec",
[&](double x, double y)->RVecD{
RVecD out;
for(unsigned int k = (do_cheb_as_modifiers ? 0 : 1); k<=degs(pdf_type::corr_x) - int(clip); k++){
double corrx = cheb(x, 0.5*max_x, 1.0, degs(pdf_type::corr_x), k);
unsigned int deg = degs(pdf_type::corr_y);
unsigned int mid_deg = deg/2;
for(unsigned int l = (clip ? 1 : 0); l<=mid_deg; l++){
double cheb_l = cheb(y, max_y, 0.0, deg, l) + cheb(y, max_y, 0.0, deg, deg-l) ;
double alpha_l = l<mid_deg ? 1.0 : (deg%2==0 ? 0.5 : 1.0);
if(fullphasespace && (x>max_x || TMath::Abs(y)>max_y))
out.emplace_back(0.0);
else
out.emplace_back( corrx*(cheb_l*alpha_l) );
}
}
return out;
}, {"x","y"} ));
for(auto hel : helicities){
dlast = std::make_unique<RNode>(dlast->Define(hel+"xy_vec",
[&,hel](double x, double y)->RVecD{
RVecD out;
bool is_odd = !do_cheb_as_modifiers && (hel=="A1" || hel=="A4");
unsigned int k0 = (do_cheb_as_modifiers || hel=="A4") ? 0 : 1;
for(unsigned int k = k0; k<=degs(get_pdf_type(hel+"_x")) - int(clip); k++){
double Ax = cheb(x, 0.5*max_x, 1.0, degs(get_pdf_type(hel+"_x")), k);
unsigned int deg = degs(get_pdf_type(hel+"_y"));
unsigned int up_deg = is_odd ? (deg+1)/2 : deg/2+1 ;
bool set_mid_to_zero = run=="full" && hel=="A3";
if(set_mid_to_zero) up_deg--;
for(unsigned int l = (clip ? 1 : 0); l<up_deg; l++){
double cheb_l = (cheb(y, max_y, 0.0, deg, l) + (is_odd? -1 : +1)*cheb(y, max_y, 0.0, deg, deg-l)) ;
double alpha_l = (!is_odd && l==(up_deg-1) && deg%2==0 && !set_mid_to_zero) ? 0.5 : 1.0;
if(fullphasespace && (x>max_x || TMath::Abs(y)>max_y))
out.emplace_back(0.0);
else
out.emplace_back( Ax*(cheb_l*alpha_l) );
}
}
return out;
}, {"x","y"} ));
}
std::vector<ROOT::RDF::RResultPtr<TH1D> > histos1D;
std::vector<ROOT::RDF::RResultPtr<TH2D> > histos2D;
std::vector<ROOT::RDF::RResultPtr<TH2D> > histosJac;
double poi_val[NMAX];
int poi_cat[NMAX];
unsigned int poi_idx[NMAX];
unsigned int poi_counter = 0;
double points_x[ NMAX ];
double points_y[ NMAX ];
unsigned int n_pdfx = 0;
unsigned int n_pdfy = 0;
if(run!="grid"){
n_pdfx = degs(pdf_type::corr_x);
n_pdfy = degs(pdf_type::corr_y)/2 + 1;
for(unsigned int i = 0; i<n_pdfx; i++){
points_x[i] = (TMath::Cos((degs(pdf_type::corr_x)-(i+1))*TMath::Pi()/degs(pdf_type::corr_x))+1.0)*0.5*max_x;
}
for(unsigned int j = 0; j<n_pdfy; j++){
points_y[j] = TMath::Cos((degs(pdf_type::corr_y)-j)*TMath::Pi()/degs(pdf_type::corr_y))*max_y;
}
}
else{
n_pdfx = degs(pdf_type::corr_x);
n_pdfy = degs(pdf_type::corr_y);
}
if(true){
TFile* fin = TFile::Open(("root/input_"+tag+".root").c_str(), "READ");
if(fin==nullptr) return 0;
TTree* tree = fin->Get<TTree>("tree");
double corr_xy[NMAX*NMAX];
for(int k = 0; k<=degs(pdf_type::corr_x); k++){
for(int l = 0; l<=degs(pdf_type::corr_y); l++){
int idx = (degs(pdf_type::corr_y)+1)*k + l;
tree->SetBranchAddress(Form("corrxy_%d_%d", k,l), &(corr_xy[idx]));
}
}
double A0_xy[NMAX];
for(int m = 0; m<=degs(pdf_type::A0_x); m++){
for(int n = 0; n<=degs(pdf_type::A0_y); n++){
int idx = (degs(pdf_type::A0_y)+1)*m + n;
tree->SetBranchAddress(Form("A0_xy_%d_%d", m,n), &(A0_xy[idx]));
}
}
double A1_xy[NMAX];
for(int m = 0; m<=degs(pdf_type::A1_x); m++){
for(int n = 0; n<=degs(pdf_type::A1_y); n++){
int idx = (degs(pdf_type::A1_y)+1)*m + n;
tree->SetBranchAddress(Form("A1_xy_%d_%d", m,n), &(A1_xy[idx]));
}
}
double A2_xy[NMAX];
for(int m = 0; m<=degs(pdf_type::A2_x); m++){
for(int n = 0; n<=degs(pdf_type::A2_y); n++){
int idx = (degs(pdf_type::A2_y)+1)*m + n;
tree->SetBranchAddress(Form("A2_xy_%d_%d", m,n), &(A2_xy[idx]));
}
}
double A3_xy[NMAX];
for(int m = 0; m<=degs(pdf_type::A3_x); m++){
for(int n = 0; n<=degs(pdf_type::A3_y); n++){
int idx = (degs(pdf_type::A3_y)+1)*m + n;
tree->SetBranchAddress(Form("A3_xy_%d_%d", m,n), &(A3_xy[idx]));
}
}
double A4_xy[NMAX];
for(int m = 0; m<=degs(pdf_type::A4_x); m++){
for(int n = 0; n<=degs(pdf_type::A4_y); n++){
int idx = (degs(pdf_type::A4_y)+1)*m + n;
tree->SetBranchAddress(Form("A4_xy_%d_%d", m,n), &(A4_xy[idx]));
}
}
tree->GetEntry(0);
fin->Close();
RVecD corrxy_in;
RVecD A0xy_in;
RVecD A1xy_in;
RVecD A2xy_in;
RVecD A3xy_in;
RVecD A4xy_in;
RVecD points_x_in;
RVecD points_y_in;
if(run!="grid"){
int k0 = do_cheb_as_modifiers ? 0 : 1;
int l0 = 0; //clip ? 1 : 0;
for(int k = k0; k<(njacs_corrxy_x+k0); k++){
for(int l = l0; l<njacs_corrxy_y; l++){
int idx = (degs(pdf_type::corr_y) + 1)*k + l;
corrxy_in.emplace_back( corr_xy[idx] );
poi_val[poi_counter] = corr_xy[idx];
poi_cat[poi_counter] = -1;
poi_idx[poi_counter] = idx;
poi_counter++;
}
}
for(int k = k0; k<(njacs_A0_x+k0); k++){
for(int l = l0; l<njacs_A0_y; l++){
int idx = (degs(pdf_type::A0_y)+1)*k + l;
A0xy_in.emplace_back( A0_xy[idx] );
poi_val[poi_counter] = A0_xy[idx];
poi_cat[poi_counter] = 0;
poi_idx[poi_counter] = idx;
poi_counter++;
}
}
for(int k = k0; k<(njacs_A1_x+k0); k++){
for(int l = l0; l<njacs_A1_y; l++){
int idx = (degs(pdf_type::A1_y)+1)*k + l;
A1xy_in.emplace_back( A1_xy[idx] );
poi_val[poi_counter] = A1_xy[idx];
poi_cat[poi_counter] = 1;
poi_idx[poi_counter] = idx;
poi_counter++;
}
}
for(int k = k0; k<(njacs_A2_x+k0); k++){
for(int l = l0; l<njacs_A2_y; l++){
int idx = (degs(pdf_type::A2_y)+1)*k + l;
A2xy_in.emplace_back( A2_xy[idx] );
poi_val[poi_counter] = A2_xy[idx];
poi_cat[poi_counter] = 2;
poi_idx[poi_counter] = idx;
poi_counter++;
}
}
for(int k = k0; k<(njacs_A3_x+k0); k++){
for(int l = l0; l<njacs_A3_y; l++){
int idx = (degs(pdf_type::A3_y)+1)*k + l;
A3xy_in.emplace_back( A3_xy[idx] );
poi_val[poi_counter] = A3_xy[idx];
poi_cat[poi_counter] = 3;
poi_idx[poi_counter] = idx;
poi_counter++;
}
}
for(int k = 0; k<njacs_A4_x; k++){
for(int l = l0; l<njacs_A4_y; l++){
int idx = (degs(pdf_type::A4_y)+1)*k + l;
A4xy_in.emplace_back( A4_xy[idx] );
poi_val[poi_counter] = A4_xy[idx];
poi_cat[poi_counter] = 4;
poi_idx[poi_counter] = idx;
poi_counter++;
}
}
}
else if(run=="grid"){
points_x_in.emplace_back(0.0);
points_x[0] = 0.0;
for(unsigned int i = 1; i<=n_pdfx; i++){
double val = max_x/n_pdfx*i;
points_x[i] = val;
points_x_in.emplace_back( val );
}
points_y_in.emplace_back(0.0);
points_y[0] = 0.0;
for(unsigned int j = 1; j<=n_pdfy; j++){
double val = max_y/n_pdfy*j;
points_y[j] = val;
points_y_in.emplace_back( val );
}
// unpol
for(int k = 0; k<n_pdfx; k++){
for(int l = 0; l<n_pdfy; l++){
poi_cat[poi_counter] = -1;
poi_idx[poi_counter] = n_pdfy*k + l;
poi_counter++;
}
}
// A0
for(int k = 0; k<n_pdfx; k++){
for(int l = 0; l<n_pdfy; l++){
poi_cat[poi_counter] = 0;
poi_idx[poi_counter] = n_pdfy*k + l;
poi_counter++;
}
}
// A1
for(int k = 0; k<n_pdfx; k++){
for(int l = 0; l<n_pdfy; l++){
poi_cat[poi_counter] = 1;
poi_idx[poi_counter] = n_pdfy*k + l;
poi_counter++;
}
}
// A2
for(int k = 0; k<n_pdfx; k++){
for(int l = 0; l<n_pdfy; l++){
poi_cat[poi_counter] = 2;
poi_idx[poi_counter] = n_pdfy*k + l;
poi_counter++;
}
}
// A3
for(int k = 0; k<n_pdfx; k++){
for(int l = 0; l<n_pdfy; l++){
poi_cat[poi_counter] = 3;
poi_idx[poi_counter] = n_pdfy*k + l;
poi_counter++;
}
}
// A4
for(int k = 0; k<n_pdfx; k++){
for(int l = 0; l<n_pdfy; l++){
poi_cat[poi_counter] = 4;
poi_idx[poi_counter] = n_pdfy*k + l;
poi_counter++;
}
}
}
// mass
poi_val[poi_counter] = 0.0;
poi_cat[poi_counter] = 5;
poi_idx[poi_counter] = 0;
poi_counter++;
dlast = std::make_unique<RNode>(dlast->Define("harmonics", [&](double x, double y, double cos, double phi) -> RVecD{
RVecD out;
double cosS = cos;//y>0 ? cos : -cos;
double phiS = phi;//y>0 ? phi : -phi;
double sinS = TMath::Sqrt(1-cosS*cosS);
out.emplace_back( 1.0 + cosS*cosS );
out.emplace_back( 0.5*(1-3*cosS*cosS) );
out.emplace_back( 2*sinS*cosS*TMath::Cos(phiS) );
out.emplace_back( 0.5*sinS*sinS*TMath::Cos(2*phiS) );
out.emplace_back( sinS*TMath::Cos(phiS) );
out.emplace_back( cosS );
//out = {1.0, 0., 0., 0., 0., 0., 0.};
return out;
} , {"x", "y", "cos", "phi"} ));
dlast = std::make_unique<RNode>(dlast->Define("weights_mctruth", [&](double x, double y, RVecD har, int ibin)->RVecD {
RVecD out;
double norm{3./16/TMath::Pi()};
//double UL = toy_x(x)*toy_y(y);
double UL = toy_UL_fast(ibin);
if(unweighted) UL = 1.0;
//double UL = toy_UL(x,y);
//if(getbin_extTH2_corr) UL *= th2_corrxy->GetBinContent( th2_corrxy->FindBin(TMath::Abs(y),x) );
//else if(inter_extTH2_corr) UL *= th2_corrxy->Interpolate(TMath::Abs(y),x);
//else if(toyTF2_corr)
//UL *= toy_corrxy(x,y);
double A0 = toy_A0_fast(ibin);
double A1 = toy_A1_fast(y,ibin);
double A2 = toy_A2_fast(ibin);
double A3 = toy_A3_fast(ibin);
double A4 = toy_A4_fast(y,ibin);
//cout << "\tULtoy =" << UL << endl;
//cout << "\tA0toy =" << A0 << endl;
//cout << "\tA1toy =" << A1 << endl;
//cout << "\tA2toy =" << A2 << endl;
//cout << "\tA3toy =" << A3 << endl;
//cout << "\tA4toy =" << A4 << endl;
double norm_UL = norm*UL;
double norm_PiAi = norm*(har.at(0)+A0*har.at(1)+A1*har.at(2)+A2*har.at(3)+A3*har.at(4)+A4*har.at(5));
out.emplace_back( UL*norm_PiAi); // full weight
//out.emplace_back( UL ); // full weight
out.emplace_back( UL*norm_PiAi); // weight for corr