forked from CSEmbree/MyAnalysis
/
MyData.cxx
1289 lines (1051 loc) · 38.8 KB
/
MyData.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "MyData.h"
/******************************************************************
** Method Implementations
******************************************************************/
const string cn = " MyData::";
MyData::MyData()
{
debug=false;
normtot=false;
unitsxTeV=false;
unitsypb=false;
tableplusminus=false;
systcorrelationmatrix=false;
blogy=false; blogx=false;
bliny=true; blinx=true;
corrfrommatrix=false;
cov_matrix_ok=false;
dividebybinwidth=false;
plotsqrts=false;
scaley=1.; //allow constant scale of units if user wants
scalex=1.;
sqrts=0.; ymin=0.; ymax=0.;
datavector=0;
datavectorstat=0;
datavectorsyst=0;
datavectortoterr=0;
datavectorsystcomp.clear();
//xtdatavector=0;
//xtdatavectorstat=0;
//xtdatavectorsyst=0;
scale=1.;
msize=0.03;
markerstyle=0;
markercolor=0;
markersize=1.0;
if (debug) cout<<" MyData msize= "<<msize<<endl;
//cout<<" datavector= "<<datavector<<endl;
jetalgoR=0;
observable="";
//TString reaction;
jetcut=false;
lepcut=false;
deltaRLepJet=false;
neucut=false;
cutMtw=false;
drljcut=false;
njetcut=false;
njets=0;
Mtwcut=0.;
ptjetcut=0.;
ptlepcut=0.;
ptneucut=0.;
yjetmin=-999.; yjetmax=999.;
ylepmin=-999.; ylepmax=999.;
deltaRLepJet=0.;
setframexmin=false;
framexmin=0.;
incljets=false;
corrfilename="";
xunits="GeV"; //TODO - default, make generic
yunits="fb"; //TODO - default, make generic
}
//void MyData::ReadCorrelations(double myscale)
void MyData::ReadCorrelations()
{
if (debug) cout << " MyData::ReadCorrelations Read correlations corrfilename= "<<corrfilename<< endl;
if (debug) cout << " MyData::ReadCorrelations datavectortoterr: "<< endl;
if (debug) datavectortoterr->Print("all");
cov_matrixsyst = new TMatrixT<double>(datavectortoterr->GetN(), datavectortoterr->GetN());
cov_matrixtot = new TMatrixT<double>(datavectortoterr->GetN(), datavectortoterr->GetN());
corr_matrixsyst= new TMatrixT<double>(datavectortoterr->GetN(), datavectortoterr->GetN());
corr_matrixtot = new TMatrixT<double>(datavectortoterr->GetN(), datavectortoterr->GetN());
cov_matrix_ok=true;
ifstream infile(corrfilename, ios::in);
if(!infile){ // Check open
cout << " MyData::ReadCorrelations Can't open " << corrfilename <<endl;
infile.close();
exit (1);
} else {
if (debug) cout <<" MyData::ReadCorrelations: read data correlations file: " << corrfilename << endl;
}
char line[1024];
int row_num = 0;
while (1) {
if (!infile.good()) break;
infile.getline(line,sizeof(line),'\n');
if( line[0] == '%' ) continue;
std::string cpp_line(line);
std::vector<std::string> split_line; split_line.clear();
split_string(cpp_line, split_line, " ");
//if (debug) cout << " MyData::ReadCorrelations Read in correlation matrix, line " << line << endl;
std::vector<double> my_corr_row; my_corr_row.clear();
if( cpp_line.size() > 3 ) {
//if (debug) cout << "Dump numerical contents (should be identical):\n";
for(int ci = 2; ci < (int) split_line.size(); ci++) {
int col_num = ci-2;
double corr_val = atof( split_line.at(ci).c_str() );
double row_data_err = 0.5*(datavectortoterr->GetErrorYhigh(row_num) + datavectortoterr->GetErrorYlow(row_num));
double col_data_err = 0.5*(datavectortoterr->GetErrorYhigh(col_num) + datavectortoterr->GetErrorYlow(col_num));
// datavectortoterr
//if (debug) cout << " row_data_err "<<row_data_err<< " col_data_err "<<col_data_err<<endl;
// correlation matrix divided by total error in row/col
double cov_val = corr_val*row_data_err*col_data_err;
// my_corr_row.push_back(this_val);
// TMatrixT<double>
(*cov_matrixtot )(row_num, col_num) = cov_val;
(*corr_matrixtot)(row_num, col_num)= corr_val;
} /// loop over entries
if( debug ) cout << "\n";
row_num++;
} /// This is a row of the correlation matrix. Read it in.
}
if (debug) {
cout << " MyData::ReadCorrelation total correlation matrix: " << endl;
corr_matrixtot->Print();
cout << " MyData::ReadCorrelation covariance matrix: " << endl;
cov_matrixtot->Print();
}
}
//void MyData::ReadData(const char fname[200], const char dir[200], double myscale){
void MyData::ReadData(string fname, string dir, double myscale){
if (debug) cout << " MyData::ReadData:" << endl;
string mn = "ReadData:";
bool errorinpercent=false;
filename.Clear();
//filename=TString(fname);
filename=fname;
//filename.ReplaceAll(TString("data/"),TString(""));
filename.ReplaceAll(TString(".txt"),TString(""));
datavector = new TGraphAsymmErrors();
datavector->SetName(filename);
if (!datavector) cout<<" MyData::ReadData: can not create data vector "<<endl;
//datavector->Print();
datavectorsyst = new TGraphAsymmErrors();
TString fnamesyst(filename); fnamesyst+="syst";
datavectorsyst->SetName(fnamesyst);
if (!datavectorsyst) cout<<" MyData::ReadData: can not create data vector "<<endl;
//datavectorsyst->Print();
if (debug) cout << " MyData::ReadData Creating datavectorstat" << endl;
datavectorstat = new TGraphAsymmErrors();
TString fnamestat(filename); fnamestat+="stat";
datavectorstat->SetName(fnamestat);
if (!datavectorstat) cout<<" MyData::ReadData: can not create data vector "<<endl;
if (debug) cout << " MyData::ReadData Created it" << endl;
if (debug) cout << " MyData::ReadData: Creating datavectortot" << endl;
datavectortoterr = new TGraphAsymmErrors();
TString fnametot(filename); fnamestat+="tot";
datavectortoterr->SetName(fnametot);
if (!datavectortoterr) cout<<" MyData::ReadData: can not create data vector "<<endl;
if (debug) cout << " MyData::ReadData: Created it" << endl;
//datavectorstat->Print();
if (debug) cout << " MyData::Read: filename dir= " << TString(dir).Data() <<endl;
if (debug) cout << " MyData::Read: filename fname= " << fname.c_str() <<endl;
//TString fnametmp=TString(dir);
TString fnametmp=dir;
if(fnametmp.EqualTo("") == false) fnametmp+="/"; //add slash for file path if directory is not local
fnametmp+=TString(fname);
//fnametmp+=fname;
//if (debug)
cout<< " MyData::ReadData read file fname= "<<fnametmp.Data()<<endl;
ifstream infile(fnametmp.Data(), ios::in);
if(!infile){ // Check open
cerr << " MyData::ReadData: Can't open " << fnametmp.Data() <<"\n";
infile.close();
exit (1);
} else {
if (debug) cout <<" MyData::ReadData: read data file: " << fnametmp.Data() << endl;
}
//int iline=0;
int nsyst=0;
int isyst=0;
int nbin=-1;
int nbinold=-999;
char line[1024]; char option[1024]; char value[1024];
double doubleVal; float floatVal;
float mymin=0, mymax=0;
double xm=0., xl=0.,xh=0., y=0., ey=0.;
std::vector<double> eyh;
std::vector<double> eyl;
//std::vector< std::vector<double>> veceyl;
//std::vector< std::vector<double>> veceyh;
eyl.clear(); eyh.clear();
//veceyl.clear(); veceyh.clear();
const double BIG=1.e30;
miny=BIG; maxy=-BIG; minx=BIG; maxx=-BIG;
//bool nextlinereaddatavalues=false;
bool nextlinereaddatavalues=true;
bool newbin=true;
while ( infile.good() ) {
infile.getline(line,sizeof(line),'\n');
if(debug) cout<<cn<<mn<< "line = '"<< line <<"'"<<endl; //TEST
if (line[0] != '%' ){ // this is a comment line in the steering
switch(toupper(line[0])) {
case 'A': break;
case 'B': break;
case 'C':
if (strstr(line,"corrname")!=0) {
sscanf(line," %s %[^\n] ", option, value);
corrfrommatrix=true;
corrfilename=TString(dir);
corrfilename+="/";
corrfilename+=TString(value);
if (debug) cout<<cn<<mn<<" corrfilename= "<<corrfilename.Data()<<endl;
} else if (strstr(line,"COLUMNNAME")!=0) {
sscanf(line," %s %[^\n] ", option, value);
columnname=TString(value);
if (debug) cout<<cn<<mn<<" columnname= "<<columnname.Data()<<endl;
}
break;
case 'D':
if (strstr(line,"dividedbybinwidth")!=0) {
dividebybinwidth=true;
if (debug) cout<<cn<<mn<<" Divide by bin width is ON"<<endl;
} else if (strstr(line,"DRLJ")!=0) {
drljcut=true;
sscanf(line," %s %f ",option, &floatVal);
deltaRLepJet=floatVal;
}
break;
case 'E':
if (strstr(line,"ERRORINPERCENT")!=0) {
errorinpercent=true;
if (debug) cout<<cn<<mn<<" Errors given in percent "<<endl;
} else if (strstr(line,"EXP")!=0) {
sscanf(line," %s %[^\n] ", option, value);
experiment=TString(value);
}
break;
case 'F':
if (strstr(line,"framelogy")!=0) {
blogy=true; bliny=false;
} else if (strstr(line,"frameliny")!=0) {
blogy=false; bliny=true;
} else if (strstr(line,"framelogx")!=0) {
blogx=true; blinx=false;
} else if (strstr(line,"framelinx")!=0) {
blogx=false; blinx=true;
} else if (strstr(line,"framexmin")!=0) {
sscanf(line," %s %f ",option, &floatVal);
setframexmin=true;
framexmin=floatVal;
}
break;
case 'G': break;
case 'H': break;
case 'I': break;
case 'J':
if (strstr(line,"JETALGO")!=0) {
sscanf(line," %s %s ", option, value);
jetalgo=value;
} else if (strstr(line,"JETALGR")!=0) {
sscanf(line," %s %d ",option, &jetalgoR);
}
break;
case 'K': break;
case 'L':
if (strstr(line,"label")!=0) {
sscanf(line," %s %[^\n] ", option, value);
if (debug) cout<<cn<<mn<<" labelname= "<<value<<endl;
label=TString(value);
}
break;
case 'M':
if (strstr(line,"MTW")!=0) {
cutMtw=true;
sscanf(line," %s %f ", option, &floatVal);
Mtwcut=floatVal;
}
break;
case 'N':
if (strstr(line,"normtot")!=0) {
normtot=true;
} else if (strstr(line,"NAME")!=0) {
sscanf(line," %s %[^\n] ", option, value);
dataname=TString(value);
} else if (strstr(line,"NJETS")!=0) {
njetcut=true;
njets=0;
sscanf(line," %s %d ", option, &njets);
}
break;
case 'O':
if (strstr(line,"OBS")!=0) {
sscanf(line," %s %[^\n] ", option, value);
observable=TString(value);
if (debug) cout<<cn<<mn<<" observable= "<<observable.Data()<<endl;
if (observable.Contains("INCLJETS")) incljets=true;
if (incljets) cout<<cn<<mn<<" Variable for inclusive jets "<<endl;
}
break;
case 'P':
if (strstr(line,"PTJET")!=0) {
jetcut=true;
sscanf(line," %s %f ", option, &floatVal);
ptjetcut=floatVal;
} else if (strstr(line,"PTLEP")!=0) {
lepcut=true;
sscanf(line," %s %f ", option, &floatVal);
ptlepcut=floatVal;
} else if (strstr(line,"PTNEU")!=0) {
neucut=true;
sscanf(line," %s %f ", option, &floatVal);
ptneucut=floatVal;
} else if (strstr(line,"plotsqrts")!=0) {
plotsqrts = true;
}
break;
case 'Q': break;
case 'R':
if (strstr(line,"REACTION")!=0) {
sscanf(line," %s %[^\n] ", option, value);
reaction=TString(value);
}
break;
case 'S':
if (strstr(line,"SQRTS")!=0) {
sscanf(line," %s %f ", option, &floatVal);
sqrts=floatVal;
if (debug) cout<<cn<<mn<<" s = "<<floatVal<<endl;
} else if (strstr(line,"scaley")!=0) {
sscanf(line," %s %f ", option, &floatVal);
scaley = floatVal;
cerr<<cn<<mn<<" WARN: Deprecated setting 'scaley="<<scaley<<"' will scale data and theory!"<<endl;
} else if (strstr(line,"scalex")!=0) {
sscanf(line," %s %f ", option, &floatVal);
scalex = floatVal;
cerr<<cn<<mn<<" WARN: Deprecated setting 'scalex="<<scalex<<"' will scale data and theory!"<<endl;
} else if (strstr(line,"SYSTCORRELATIONMATRIX")!=0) { // flag that systematic correlation matrix set
systcorrelationmatrix=true;
if (systcorrelationmatrix) cout << " MyData::ReadData systcorrelationmatrix is defined \n";
} else if (strstr(line,"Syst_")!=0) { // systematics components
nsyst++;
// read in systematics commponents
if (debug) cout << " MyData::ReadData: nsyst= "<<nsyst<<endl;
std::string cpp_line(line);
std::vector<std::string> split_line; split_line.clear();
split_string(cpp_line, split_line, " ");
string name=split_line.at(0);
//for (int ci = 1; ci < (int) split_line.size(); ci++) {
// double val = atof( split_line.at(ci).c_str() );
//}
TGraphAsymmErrors* gtmp= new TGraphAsymmErrors();
gtmp->SetName(TString(name));
if (debug) cout<<cn<<mn<<" gtmp name= "<<gtmp->GetName()<<endl;
if (debug) gtmp->Print();
// read here correlation matrix
datavectorsystcomp.push_back(gtmp);
}
break;
case 'T':
if (strstr(line,"TABLEPLUSMINUS")!=0) {
tableplusminus=true;
if (tableplusminus) cout<<cn<<mn<<" Syst uncertainties with +/- values "<<endl;
} else if (strstr(line,"titlex")!=0) {
sscanf(line," %s %[^\n] ", option, value);
titlex=TString(value);
} else if (strstr(line,"titley")!=0) {
sscanf(line," %s %[^\n] ", option, value);
titley=TString(value);
}
break;
case 'U':
if (strstr(line,"unitxTeV")!=0) {
unitsxTeV=true;
} else if (strstr(line,"unitypb")!=0) {
unitsypb=true;
}
break;
case 'V': break;
case 'W': break;
case 'X':
if (strstr(line,"xunits")!=0) {
sscanf(line," %s %[^\n] ", option, value);
if (debug) cout<<cn<<mn<<" unit= "<<value<<endl;
xunits=TString(value);
}
break;
case 'Y':
if (strstr(line,"YRAP")!=0) {
sscanf(line," %s %f %f", option, &mymin,&mymax);
ymin=mymin; ymax=mymax;
if (debug) cout<<cn<<mn<<" ymin = "<<mymin<<", ymax = "<<mymax<<endl;
} else if (strstr(line,"YJET")!=0) {
jetcut=true;
sscanf(line," %s %f %f", option, &mymin,&mymax);
yjetmin=mymin; yjetmax=mymax;
if (debug) cout<<cn<<mn<<" ymin = "<<mymin<<", ymax = "<<mymax<<endl;
} else if (strstr(line,"YLEP")!=0) {
lepcut=true;
sscanf(line," %s %f %f", option, &mymin,&mymax);
ylepmin=mymin; ylepmax=mymax;
if (debug) cout<<cn<<mn<<" ymin= "<<mymin<<", ymax = "<<mymax<<endl;
} else if (strstr(line,"YEAR")!=0) {
sscanf(line," %s %d ", option, &year);
} else if (strstr(line,"yunits")!=0) {
sscanf(line," %s %[^\n] ", option, value);
if (debug) cout<<cn<<mn<<" unit= "<<value<<endl;
yunits=TString(value);
}
break;
case 'Z': break;
default:
//read in data
if (nextlinereaddatavalues) {
if (debug) cout<<" MyData::ReadData: found bin= "<<nbin<<" nbinold= "<<nbinold<<endl;
if (nbin!=nbinold) nbinold=nbin;
std::string cpp_line(line);
std::vector<std::string> split_line; split_line.clear();
split_string(cpp_line, split_line, " ");
//if (debug) cout << "Dump numerical contents (should be identical):\n";
//
// This code assumes that tables are formated
// with 5 column per line xm xl xh sigma sigma stat
// and then following lines with 2 colums for each systematic uncertainty
// or everything in one line with syst everything what follows after statistical uncertainty
//
if (split_line.size()>=5) {
if (split_line.size()>5) newbin=true;
if (split_line.size()==5) {
if (newbin) {newbin=false;
} else {newbin=true;}
if (isyst==0){newbin=true;}
}
if (newbin) {
nbin++;
eyl.clear(); eyh.clear();
isyst=0;
}
//if (newbin) cout<<" in splitline newbin on "<<endl;
//else cout<<" in splitline newbin off "<<endl;
if (debug) cout << " MyData::ReadData: read line mean xl xh sigma stat"<<endl;
for (int ci = 0; ci < (int) split_line.size(); ci++) {
double val = atof( split_line.at(ci).c_str() );
if (debug) cout<<" MyData::ReadData: ci= "<<ci<<" val= "<<val<<endl;
if (ci==0) xm=val;
if (ci==1) xl=val;
if (ci==2) xh=val;
if (ci==3) y=val;
if (ci==4) ey=val;
if (ci>=5) {
//cout<<" MyData::ReadData: isyst= "<<isyst<<" ci= "<<ci<<" mod= "<<(ci-5)%2<<endl;
if (tableplusminus) {
if ((ci-5)%2==0) {
isyst++;
eyh.push_back(atof( split_line.at(ci).c_str() ));
eyl.push_back(atof( split_line.at(ci+1).c_str() ));
}
} else {
isyst++;
eyh.push_back(atof( split_line.at(ci).c_str() ));
eyl.push_back(atof( split_line.at(ci).c_str() ));
}
}
}
}
if (tableplusminus&&split_line.size()==2) {
if (debug) cout << " MyData::ReadData read line syst= "<<isyst<<endl;
isyst++;
eyh.push_back( atof( split_line.at(0).c_str() ));
eyl.push_back( atof( split_line.at(1).c_str() ));
newbin=false;
}
//if (newbin) cout<<" end newbin on "<<endl;
//else cout<<" end newbin off "<<endl;
double myy=y, myey=ey;
if (errorinpercent) {myey *=y/100.;}
myy *=myscale; myey *=myscale;
if (miny>y) miny=myy;
if (maxy<y) maxy=myy;
if (minx>xl) minx=xl;
if (maxx<xh) maxx=xh;
float x= (xh+xl)/2.;
float b= (xh-xl)/2.;
if (debug) {
cout<<" MyData::ReadData: nbin= "<<nbin<<" isyst= "<<isyst
<<" x= "<<x<<" xl= "<<xl<<" xh= "<<xh<<" y= "<<myy<<" ey= " << myey << endl;
for (int i=0; i<(int)eyl.size(); i++) {
cout<<" MyData::ReadData: i= "<<i<<" eyh= "<<eyh[i]<<" eyl= "<<eyl[i]<<endl;
}
}
datavector->SetPoint(nbin ,xm, myy);
datavector->SetPointEXlow (nbin ,xm-x+b);
datavector->SetPointEXhigh(nbin,x+b-xm);
datavectortoterr->SetPoint(nbin ,xm, myy);
datavectortoterr->SetPointEXlow (nbin ,xm-x+b);
datavectortoterr->SetPointEXhigh(nbin,x+b-xm);
if (debug) {
cout<<" MyData::ReadData: datavector: "<<endl;
datavector->Print();
}
datavectorstat->SetPoint(nbin ,xm, myy);
datavectorstat->SetPointEXlow (nbin ,xm-x+b);
datavectorstat->SetPointEXhigh(nbin,x+b-xm);
datavectorstat->SetPointEYlow (nbin,myey);
datavectorstat->SetPointEYhigh(nbin,myey);
if (debug) {
cout<<" datavectorstat: "<<endl;
datavectorstat->Print();
}
if (debug) cout<<" MyData::ReadData: number of systematics= "<<eyl.size()<<endl;
if (debug) cout<<" MyData::ReadData: datavectorsystcomp.size() = "<<datavectorsystcomp.size()<<endl;
if (datavectorsystcomp.size()>0) {
for (int i=0; i<(int)eyl.size(); i++) {
if (debug) cout<<" MyData::ReadData: i= "<<i<<endl;
double myeyh=eyh[i], myeyl=eyl[i];
if (errorinpercent) {myeyh *=y/100.; myeyl *=y/100.;}
if (debug) cout<<" MyData::ReadData: huhu i= "<<i<<endl;
myeyl *=myscale; myeyh *=myscale;
if (debug) cout<<" MyData::ReadData: eyl.size()= "<<eyl.size()<<endl;
if (datavectorsystcomp.size()<i) {
cout<<" MyData::ReadData datavectorsystcomp["<<i<<"] not found "<<endl;
continue;
}
if (debug) cout<<" MyData::ReadData: nbin= "<<nbin<<" xm= "<<xm<<endl;
datavectorsystcomp[i]->SetPoint(nbin ,xm, myy);
datavectorsystcomp[i]->SetPointEXlow (nbin,xm-x+b);
datavectorsystcomp[i]->SetPointEXhigh(nbin,x+b-xm);
datavectorsystcomp[i]->SetPointEYlow (nbin,myeyl);
datavectorsystcomp[i]->SetPointEYhigh(nbin,myeyh);
}
}
}
}
}
}
//}
if (debug) cout<<cn<<mn<<" nsyst= "<<nsyst
<<" datavectorsystcomp.size()= "<<datavectorsystcomp.size()<<endl;
if (nsyst!=(int)datavectorsystcomp.size())
cout<<cn<<mn<<" something is wrong nsyst not equal vector size "<<endl;
if (debug) {
for (int i=0; i<nsyst; i++) {
cout<<"\n"<<cn<<mn<<" datavectsyst["<<i<<"]: "<<datavectorsystcomp[i]->GetName()<<endl;
datavectorsystcomp[i]->Print();
}
cout<<"\n"<<cn<<mn<<" datavectorstat "<<endl;
datavectorstat->Print();
}
for (int ibin=0; ibin<datavectorstat->GetN(); ibin++) {
double eytoth=datavectorstat->GetErrorYhigh(ibin);
double eytotl=datavectorstat->GetErrorYlow (ibin);
if (eytoth!=eytotl) cout<<cn<<mn<<" some is wrong eystath= "<<eytoth<<" eystatl= "<<eytotl<<endl;
for (int i=0; i<nsyst; i++) {
double meyh=datavectorsystcomp[i]->GetErrorYhigh(ibin);
double meyl=datavectorsystcomp[i]->GetErrorYlow (ibin);
eytoth = TMath::Sqrt(pow(eytoth, 2.) + pow(meyh, 2.));
eytotl = TMath::Sqrt(pow(eytotl, 2.) + pow(meyl, 2.));
//if (debug) cout<<" MyData::ReadData: ibin= "<<ibin<<" i= "<<i
// <<" eyh= "<<meyh<<" eyl= "<<meyl
// <<" eytoth= "<<eytoth<<" eytotl= "<<eytotl<<endl;
}
datavectortoterr->SetPointEYhigh(ibin,eytoth);
datavectortoterr->SetPointEYlow (ibin,eytotl);
}
if (debug) {
cout<<"\n"<<cn<<mn<<" datavectortoterr "<<endl;
datavectortoterr->Print();
}
//cout<<" fname= "<<fname<<endl;
if (corrfrommatrix) {
if (debug) cout<<cn<<mn<<" read corrfilename= "<<corrfilename<<endl;
this->ReadCorrelations();
} else {
int Nbin=datavectortoterr->GetN();
corr_matrixtot = new TMatrixT<double>(Nbin, Nbin);
corr_matrixsyst = new TMatrixT<double>(Nbin, Nbin);
//TMatrixT <double >*cov_matrixk = new TMatrixT<double>(nbin, nbin);
// need to do this since addition of matrices does not work either += or Plus()
double cov_matrixk[Nbin][Nbin];
for (int i=0; i<Nbin; i++) {
for (int j=0; j<Nbin; j++) {
cov_matrixk[Nbin][Nbin]=0.;
}
}
cov_matrixtot = new TMatrixT<double>(Nbin, Nbin);
cov_matrixsyst = new TMatrixT<double>(Nbin, Nbin);
if (datavectorsystcomp.size()==1) {
cout<<cn<<mn<<" use unit matrix as correlation matrix "<<endl;
cov_matrixtot->UnitMatrix();
cov_matrixsyst->UnitMatrix();
}
cov_matrix_ok=true;
//if (debug) {
// cout<<" MyData::ReadData: print unity matrix "<<nbin<<"x"<<nbin<<endl;
// cov_matrixtot->Print();
//}
if (datavectorsystcomp.size()>1) {
cout<<cn<<mn<<" calculate correlation matrix from uncertainty components "
<<" nsyst= "<<datavectorsystcomp.size()<<endl;
//
// put here something for statistical correlation matrix
// fetch stat uncertainty
// if (i==j) (*covMatStat_)[i][j] = pow( gstat->GetErrorYhigh(i), 2 );
//
for (int k=0; k<(int)datavectorsystcomp.size(); k++) {
for ( int ibin=0; ibin<nbin; ibin++ ){
for ( int jbin=0; jbin<nbin; jbin++ ){
double cov_val = 0.;
double iyval=0., jyval=0., xval=0.;
datavectorsystcomp[0]->GetPoint(ibin,xval,iyval);
datavectorsystcomp[0]->GetPoint(jbin,xval,jyval);
// could implement here something for +/- uncertainties
double ibin_err = 0.5*(datavectorsystcomp[k]->GetErrorYhigh(ibin) + datavectorsystcomp[k]->GetErrorYlow(ibin));
double jbin_err = 0.5*(datavectorsystcomp[k]->GetErrorYhigh(jbin) + datavectorsystcomp[k]->GetErrorYlow(jbin));
// relative uncertainties
//ibin_err=1;
//jbin_err=1;
//ibin_err/=iyval;
//jbin_err/=jyval;
if (debug) cout <<" k= "<<k<<" ibin= "<<ibin<<" ibin_err= "<<ibin_err
<<" jbin= "<<jbin<<" jbin_err= "<<jbin_err<<endl;
cov_val +=ibin_err*jbin_err;
//(*cov_matrixk)(ibin, jbin) = cov_val;
cov_matrixk[ibin][jbin]+=cov_val;
}
}
}
if (debug) cout<<cn<<mn<<" now fill covarince and correlation matrix "<<endl;
for (int i=0; i<nbin; i++) {
for (int j=0; j<nbin; j++) {
double eystath=0., eystatl=0., eystat=0.;
if (i==j) {
eystath=datavectorstat->GetErrorYhigh(i);
eystatl=datavectorstat->GetErrorYlow (i);
if (eystath!=eystatl) cout<<cn<<mn<<" some is wrong eystath= "<<eystath<<" eystatl= "<<eystatl<<endl;
eystat=0.5*(eystath+eystatl);
}
//if (debug) cout << " MyData::ReadData: systematic correlation matrix eystat= "<<eystat << endl;
(*cov_matrixsyst)(i,j)=cov_matrixk[i][j];
(*cov_matrixtot )(i,j)=sqrt(pow(eystat,2)+pow(cov_matrixk[i][j],2));
double sig=cov_matrixk[i][i]*cov_matrixk[j][j];
if (sig!=0.) sig=sqrt(sig);
(*corr_matrixsyst)(i,j)=cov_matrixk[i][j]/sig;
// is the below correct ? changed nothing see below
(*corr_matrixtot)(i,j) =sqrt(pow(eystat,2)+pow(cov_matrixk[i][j],2))/sqrt(pow(eystat,2)+pow(sig,2));
}
}
//(*cov_matrix)+=(*cov_matrixk);
//cov_matrix->Plus(*cov_matrix,*cov_matrixk);
if (debug) {
cout<<cn<<mn<<" using correlation matrix from uncertainties components " << endl;
cout<<cn<<mn<<" systematic correlation matrix: " << endl;
corr_matrixsyst->Print();
// total correllation matrix is not different, if from stat uncertainty (diagonal elements normalised out)
//cout << " MyData::ReadData: total correlation matrix: " << endl;
//corr_matrixtot->Print();
cout<<cn<<mn<<" print systematics covariance matrix: "<<endl;
cov_matrixsyst->Print();
cout<<cn<<mn<<" total covariance matrix "<<endl;
cov_matrixtot->Print();
}
}
}
// Perform any hard-coded scaling if the user requested it
if(debug) cout<<cn<<mn<<" Artifical scaling with scalx:"<<scalex<<"scaley:"<<scaley<<endl;
Scale(scalex, scaley); //TEST - turn back on
return;
}
void MyData::Print() {
cout<<"\n MyData::Print>>>>>>>>>>>>>>>>>>>>>>>>>>>> \n "<<endl;
if (debug) cout<<" debug flag on "<<endl;
cout<<" reaction= "<<reaction.Data()<<endl;
cout<<" observable= "<<observable.Data()<<endl;
cout<<" filename= "<<filename.Data()<<endl;
cout<<" name= "<<dataname.Data()<<endl;
//cout<<" titlex= "<<titlex.Data()<<endl;
//cout<<" titley= "<<titley.Data()<<endl;
cout<<" label= "<<label.Data()<<endl;
cout<<" s= "<<sqrts<<" GeV "<<endl;
cout<<" year= "<<year<<endl;
//cout<<" msize= "<<msize<<" markerstyle= "<<markerstyle<<" markercolor= "<<markercolor<<endl;
if (blogy) cout<<" axis y log-scale"<<endl;
if (bliny) cout<<" axis y lin-scale"<<endl;
if (blogx) cout<<" axis x log-scale"<<endl;
if (blinx) cout<<" axis x lin-scale"<<endl;
if (ymin!=0 || ymax!=0)
cout<<" ymin= "<<ymin<<" ymax= "<<ymax<<endl;
cout<<"\n Cuts: "<<endl;
cout<<" Jet "<<jetalgo.Data()<<" R = "<< float(jetalgoR)/10.<<endl;
if (njetcut) cout<<"\t Njets=> "<<njets<<endl;
if (jetcut) cout<<"\t Ptjet> "<<ptjetcut<<" GeV "<<yjetmin<<" <yjet< "<<yjetmax<<endl;
if (lepcut) cout<<"\t Ptlep> "<<ptlepcut<<" GeV "<<ylepmin<<" <ylep< "<<ylepmax<<endl;
if (neucut) cout<<"\t Ptneu> "<<ptneucut<<" GeV "<<" MTw> " <<Mtwcut<<" GeV"<<endl;
if (cutMtw) cout<<"\t Mtw> "<<Mtwcut<<" GeV "<<endl;
if (drljcut)cout<<"\t dRlepJet> "<<deltaRLepJet<<" GeV "<<endl;
if (systcorrelationmatrix) cout << " systcorrelationmatrix on \n";
if (tableplusminus) cout << " Table has +/- values on \n";
cout<<" columnname= "<<columnname.Data()<<endl;
//
//cout<<" datavector= "<<datavector<<endl;
if (!datavector){
cout<<"\n datavector not found "<<endl;
} else {
cout<<" datavector= "<<datavector->GetName()<<endl;
datavector->Print();
}
/*
if (!datavectorsyst){
cout<<" datavectorsyst not found "<<endl;
} else {
cout<<" datavectorsyst= "<<datavectorsyst->GetName()<<endl;
datavectorsyst->Print();
}
if (!datavectorstat){
cout<<" datavectorstat not found "<<endl;
} else {
cout<<" datavectorstat= "<<datavectorstat->GetName()<<endl;
datavectorstat->Print();
}
*/
cout<<" <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< \n "<<endl;
}
/*
void MyData::PrintXt() {
cout<<" MyData::PrintXt>>>>>>>>>>>>>>>>>>>>>>>>>>>> "<<endl;
if (debug) cout<<" debug flag on "<<endl;
cout<<" s= "<<sqrts<<" ymin= "<<ymin<<" ymax= "<<ymax<<endl;
cout<<jetalgo.Data()<<" R = "<< float(jetalgoR)/10.<<" year= "<<year<<endl;
cout<<" msize= "<<msize<<" markerstyle= "<<markerstyle<<" markercolor= "<<markercolor<<endl;
//cout<<" xtdatavector= "<<xtdatavector<<endl;
if (!xtdatavector){
cout<<" xtdatavector not found "<<endl;
} else {
cout<<" xtdatavector= "<<datavector->GetName()<<endl;
xtdatavector->Print();
}
cout<<" <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< "<<endl;
}
void MyData::DrawXt(char name[100], float x, float y){
if (debug) cout<<" DrawXt: name= "<<name<<" x= "<<x<<" y= "<<y<<endl;
this->TransformPtToXt();
this->DrawLegend(name,x,y);
if (debug)
this->PrintXt();
this->DrawDataXt();
return;
}
void MyData::TransformPtToXt(){
//
// transform dsigma/dpt to dsigma/dxt
//
//
xtdatavector = new TGraphAsymmErrors();
xtdatavectorstat= new TGraphAsymmErrors();
xtdatavectorsyst= new TGraphAsymmErrors();
TString fname("xt"); fname+=datavector->GetName();
xtdatavector->SetName(fname);
TString fnamestat= datavector->GetName(); fnamestat+="stat";
xtdatavectorstat->SetName(fnamestat);
TString fnamesyst= datavector->GetName(); fnamesyst+="stat";
xtdatavectorsyst->SetName(fnamesyst);
if (!datavector) {cout<<" Transform: datavector not found !"<<endl;}
double * X1 = datavector->GetX();
double * Y1 = datavector->GetY();
double * EXhigh = datavector->GetEXhigh();
double * EXlow = datavector->GetEXlow();
double * EYhigh = datavector->GetEYhigh();
double * EYlow = datavector->GetEYlow();
if (!datavectorsyst) {cout<<" Transform: datavectorsyst not found !"<<endl;}
double * EYhighsyst = datavectorsyst->GetEYhigh();
double * EYlowsyst = datavectorsyst->GetEYlow();
if (!datavectorstat) {cout<<" Transform: datavectorstat not found !"<<endl;}
double * EYhighstat = datavectorstat->GetEYhigh();
double * EYlowstat = datavectorstat->GetEYlow();
double ymean=(ymax-ymin)/2.;
//double fac=2.*exp(+ymean)/sqrts;
//double fac=2.*exp(-ymin)/sqrts;
double fac=2./sqrts;
if (debug)
cout<<" Transform: ymean= "<<ymean<<" sqrts= "<<sqrts<<" fac= "<<fac
<<" number of points= "<<datavector->GetN()<<endl;
for (int i=0; i<datavector->GetN(); i++) {
double x=X1[i]*fac;
double exl=EXlow[i]*fac;
double exh=EXhigh[i]*fac;
double facy=X1[i]*X1[i]*X1[i]/(2*3.141592654);
double y= Y1[i]*facy;
double eyl= EYlow[i]*facy;
double eyh= EYhigh[i]*facy;
double eylsyst= EYlowsyst[i]*facy;
double eyhsyst= EYhighsyst[i]*facy;
double eylstat= EYlowstat[i]*facy;
double eyhstat= EYhighstat[i]*facy;
//cout<<" i= "<<i<<" pt= "<<X1[i]<<" sigma= "<<Y1[i]<<" fac= "<<fac<<endl;
//cout<<" i= "<<i<<" x= "<<x<<" y= "<<y<<" facy="<<facy<<endl;
xtdatavector->SetPoint(i, x, y);
xtdatavector->SetPointError(i,exl,exh,eyl,eyh);
xtdatavectorstat->SetPoint(i, x, y);
xtdatavectorstat->SetPointError(i,exl,exh,eylstat,eyhstat);
xtdatavectorsyst->SetPoint(i, x, y);
xtdatavectorsyst->SetPointError(i,exl,exh,eylsyst,eyhsyst);
}
if (debug) cout<<" Transform finished ! "<<endl;
//xtdatavectorsyst->Print();
return;
}
*/
void MyData::PutData(TH1* hdata, double mys, double myymin, double myymax){
//
// input data in histogram
//
if (!hdata) cout<<" MyData:: PutData: hdata not found "<<endl;
ymin=myymin;
ymax=myymax;
sqrts=mys;
if (debug) cout<<" MyData::PutData: input data s= "<<sqrts
<<" ymin= "<<ymin<<" ymax= "<<ymax<<endl;
if (debug)
hdata->Print();
TGraphAsymmErrors* g1= new TGraphAsymmErrors();
if (!g1) cout<<" MyData:: PutData: graph g1 not created "<<endl;
// else g1->Print();
double x, y, ex, ey;
int iv=0;
for (int i=0; i<hdata->GetNbinsX(); i++) {
y=hdata->GetBinContent(i+1);
ey=hdata->GetBinError(i+1);
x=hdata->GetBinCenter(i+1);
ex=hdata->GetBinWidth(i+1)/2.;
if (y!=0 && ey!=0){
// cout << i<<" x,y = " << x << " " << y << " ex,ey = " << ex << " " << ey << endl;
g1->SetPoint(iv,x,y);
g1->SetPointError(iv,ex,ex,ey,ey);
iv++;
}
}
//g1->Print();