-
Notifications
You must be signed in to change notification settings - Fork 0
/
CalculateReference.C
1886 lines (1649 loc) · 106 KB
/
CalculateReference.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
/****************************************************************************************************************************
****** provided by Gamma Conversion Group, PWG-GA *********
****** Daniel Mühlheim, [email protected] *********
****** Friederike Bock, [email protected] *********
*****************************************************************************************************************************/
#include <Riostream.h>
#include "TMath.h"
#include <stdlib.h>
#include <fstream>
#include <math.h>
#include <TROOT.h>
#include <TApplication.h>
#include <TPaveLabel.h>
#include <TSystem.h>
#include <TFrame.h>
#include <TStyle.h>
#include <TString.h>
#include "TGaxis.h"
#include "TFile.h"
#include "TH1F.h"
#include "TH1D.h"
#include "TH2F.h"
#include "TF1.h"
#include "TProfile.h"
#include "TRandom3.h"
#include "TVirtualFitter.h"
#include "TObject.h"
#include "TCanvas.h"
#include "TMultiGraph.h"
#include "TLegend.h"
#include "TDatabasePDG.h"
#include "TMinuit.h"
#include "TBenchmark.h"
#include "TRandom.h"
#include "TLatex.h"
#include "TASImage.h"
#include "TPostScript.h"
#include "TGraphErrors.h"
#include "TArrow.h"
#include "TGraphAsymmErrors.h"
#include "TGaxis.h"
#include "TMarker.h"
#include "TSpline.h"
#include "Math/WrappedTF1.h"
#include "Math/BrentRootFinder.h"
#include "CommonHeaders/PlottingGammaConversionHistos.h"
#include "CommonHeaders/PlottingGammaConversionAdditional.h"
#include "CommonHeaders/FittingGammaConversion.h"
#include "CommonHeaders/ExtractSignalBinning.h"
// #include "CommonHeaders/ConversionFunctionsBasicsAndLabeling.h"
#include "CommonHeaders/ConversionFunctions.h"
#include "CommonHeaders/CombinationFunctions.h"
#include "TFitResultPtr.h"
TGraphAsymmErrors *GetInterpolSpectrum2D(Int_t nDataPoints, TGraphAsymmErrors** graphs, Double_t* energies, Double_t dSqrts, Int_t nIterations, Int_t modus );
TH1D* ConvertYieldHisto(TH1D* input, Bool_t DivideBy2pi, Bool_t DivideByPt, Bool_t MultiplyBy2pi, Bool_t MultiplyByPt);
TF1* DoFitWithTsallis(TGraph* graph, TString name, TString particle, Double_t p0, Double_t p1, Double_t p2);
TF1* DoFitWithTCM(TGraph* graph, TString name, TString particle, Double_t p0, Double_t p1, Double_t p2, Double_t p3, Double_t p4 );
TF1* DoFitWithModHagedorn(TGraph* graph, TString name, TString particle, Double_t p0, Double_t p1, Double_t p2, Double_t p3, Double_t p4 );
void PlotInterpolationPtBins(TGraphErrors** gPtvSqrts,TGraphErrors** gPtvsEnergies, TF1** fPowerlaw, TF1** fPowerlawMC, TGraphAsymmErrors* gRpPb,Int_t fColumnPlot, Int_t fRowPlot,TString namePlot);
void PlotInterpolationSinglePtBin(TGraphErrors* gPtvSqrts,TGraphErrors* gPtvsEnergies, TF1* fPowerlaw, TF1* fPowerlawMC, TGraphAsymmErrors* gRpPb, Int_t ptBin, TString namePlot);
void PlotAlphavsPt(TGraphErrors* gAlpha, TGraphErrors* gAlphaSyst, TGraphErrors* gAlphaMC, TSpline* splineMC, TString method, TString thesisPlotLabel, TString namePlot);
void PlotWithFit(TCanvas* canvas, TCanvas* canvasRatio, TH2F* hist, TH2F* hist2, TGraphAsymmErrors* graph, TGraphAsymmErrors* graphRebin, TF1* fit, TString name, TString outputDir, TString suffix, TString energyCur);
void PlotWithFit(TCanvas *canvas, TCanvas* canvasRatio, TH2F* hist, TH2F* hist2, TGraphErrors* graph, TGraphErrors* graphRebin, TF1* fit, TString name, TString outputDir, TString suffix, TString energyCur);
void PlotGraphsOfAllEnergies( TCanvas* canvas, TH2F* hist, Int_t nDataSets, TGraphAsymmErrors** graphs, TF1** fits, TString* energies, TString name, TString outputDir, TString suffix );
void SetStyleTGraphErrorsForGraphs(TGraph* graph, TString XTitle, TString YTitle, Size_t xLableSize, Size_t xTitleSize, Size_t yLableSize, Size_t yTitleSize, Float_t xTitleOffset = 1, Float_t yTitleOffset = 1, Int_t xNDivisions = 510, Int_t yNDivisions = 510);
TGraphAsymmErrors* SetGraphErrors (TGraphAsymmErrors* graph, TGraphAsymmErrors* refGraph);
TGraphAsymmErrors* RemoveSysErrors (TGraphAsymmErrors* graph, TGraphAsymmErrors* refGraph);
void RemoveZerosAndPrint(TGraphErrors* graph, TString d){
cout << d.Data() << endl;
while (graph->GetY()[0] == 0. ) graph->RemovePoint(0);
graph->Print();
}
void RemoveZerosAndPrint(TGraphAsymmErrors* graph, TString d){
cout << d.Data() << endl;
while (graph->GetY()[0] == 0. ) graph->RemovePoint(0);
graph->Print();
}
TGraphErrors* graphAlpha = 0x0;
TGraphErrors** graphPtvsSqrts = 0x0;
TGraphErrors** gPtvsEnergiesSystem = 0x0;
TF1** fPowerlawSystem = 0x0;
TGraphErrors* graphAlphaMC = 0x0;
TGraphErrors** graphPtvsSqrtsMC = 0x0;
TGraphErrors** gPtvsEnergiesSystemMC = 0x0;
TF1** fPowerlawSystemMC = 0x0;
TSpline5* splineAlphaMC = 0x0;
TGraphErrors* graphDiffMCIntAndReal = 0x0;
TGraphErrors* graphAlphaStat = 0x0;
TGraphErrors** graphPtvsSqrtsStat = 0x0;
TGraphErrors** gPtvsEnergiesSystemStat = 0x0;
TF1** fPowerlawSystemStat = 0x0;
TGraphErrors* graphAlphaSyst = 0x0;
TGraphAsymmErrors* graphInterpolSyst = 0x0;
TGraphErrors** graphPtvsSqrtsSyst = 0x0;
TGraphErrors** gPtvsEnergiesSystemSyst = 0x0;
TF1** fPowerlawSystemSyst = 0x0;
TF1** fPowerlawSystemSystMC = 0x0;
TString detProcess = "";
TString mesonString = "";
void CalculateStatPlusSysErrors(TH1D* histStat, TH1D* histSys);
TGraphAsymmErrors* CalculateStatPlusSysErrors(TGraphAsymmErrors* graphStat, TGraphAsymmErrors* graphSys);
//________________________________________________________________________________________________________________________
void CalculateReference ( TString configFile = "",
Int_t nDataSets = 2,
TString meson = "Pi0",
TString suffix = "eps",
TString finalEnergy = "8TeV",
Double_t energy = 8000,
Int_t mode = 20,
Bool_t doSpecialBinning = kFALSE,
TString binningEnergy = "",
TString configfileExclusionErrors = "",
TString nameFileMCRef = "",
TString nameHistMCRef = "",
Int_t nTrials = 1000,
TString fitSelection = "",
TString addLabel = ""
){
//*************************************************************************************************
//*************************** general settings
//*************************************************************************************************
TH1::AddDirectory(kFALSE);
gROOT->Reset();
gROOT->SetStyle("Plain");
StyleSettingsThesis(suffix);
SetPlotStyle();
TString dateForOutput = ReturnDateStringForOutput();
TString modeName = ReturnTextReconstructionProcessWrite(mode);
TString collisionSystem = ReturnFullCollisionsSystem(finalEnergy);
TString collSystOut = ReturnCollisionEnergyOutputString(finalEnergy);
mesonString = ReturnMesonString (meson);
detProcess = ReturnFullTextReconstructionProcess(mode);
TString outputDir = Form("%s/%s/CalculateReference",suffix.Data(),dateForOutput.Data());
TString outputDirPlots = Form("%s/%s/CalculateReference/%s%s_%s",suffix.Data(), dateForOutput.Data(), modeName.Data(), addLabel.Data(), meson.Data());
gSystem->Exec("mkdir -p "+outputDirPlots);
Int_t exampleBin = 7;
Double_t dummyScaleFac = 1;
//*************************************************************************************************
//***************************** read configurarion file *******************************************
//*************************************************************************************************
TString nameFile[5] = {"", "", "", "", ""};
TString nameHist[4][5] = {{"", "", "", "", ""},{"", "", "", "", ""},{"", "", "", "", ""},{"", "", "", "", ""}};
TString nameFileSys[5] = {"", "", "", "", ""};
TString nameFileMC[5] = {"", "", "", "", ""};
TString nameHistMC[5] = {"", "", "", "", ""};
Int_t isHist[2][5] = {{0, 0, 0, 0, 0},{0, 0, 0, 0, 0}};
TString energyIndName[6] = {"", "", "", "", "", ""};
Double_t energyInd[6] = {0, 0, 0, 0, 0, 0};
Double_t scaleFactor[5] = {1, 1, 1, 1, 1};
Int_t nrOfTrigToBeComb = 0;
// number of triggers which are really used for the respective analysis
Int_t nEnergyRead = 0;
ifstream in(configFile.Data());
while(!in.eof() && nEnergyRead<nDataSets ){
cout << "read line:" << nEnergyRead+1 << endl;
in >> nameFile[nEnergyRead] >> isHist[0][nEnergyRead] >> nameHist[0][nEnergyRead] >> isHist[1][nEnergyRead] >> nameHist[1][nEnergyRead]
>> energyIndName[nEnergyRead] >> energyInd[nEnergyRead] >> scaleFactor[nEnergyRead] >> nameHist[2][nEnergyRead] >> nameHist[3][nEnergyRead] >> nameFileSys[nEnergyRead] >> nameFileMC[nEnergyRead] >> nameHistMC[nEnergyRead];
cout << nameFile[nEnergyRead] << "\t" << isHist[0][nEnergyRead] << "\t" << nameHist[0][nEnergyRead].Data() << "\t" << isHist[1][nEnergyRead] << "\t" << nameHist[1][nEnergyRead].Data()
<< "\t" << energyIndName[nEnergyRead].Data() << "\t" << energyInd[nEnergyRead] << "\t" << scaleFactor[nEnergyRead] << endl;
nEnergyRead++;
}
Double_t finalBinningPt[100];
Int_t maxNBins = 0;
Int_t startBin = 0;
Int_t maxNBinsAbs = 0;
if (doSpecialBinning){
maxNBins = GetBinning( finalBinningPt, maxNBinsAbs, meson.Data(), binningEnergy.Data(), mode, -1 , kFALSE, "0-100%");
startBin = GetStartBin( meson.Data(), binningEnergy.Data(), mode, -1, "0-100%" );
// exampleBin = ReturnSingleInvariantMassBinPlotting (meson.Data(), binningEnergy.Data(), mode, 0, dummyScaleFac);
if (maxNBins == 0){
cout << "The requested binning doesn't exist, aborting!" << endl;
return;
}
cout << maxNBins << "\t start Bin: " << startBin << endl;
cout << "Binning" << endl;
for (Int_t i = 0; i<maxNBins+1; i++){
cout << finalBinningPt[i] << "\t," ;
}
cout << endl;
}
vector<TString>* ptSysRemNames = new vector<TString>[5];
Bool_t enableSysExcl[5] = {kFALSE, kFALSE, kFALSE, kFALSE, kFALSE};
Int_t nTakeOutSys = 0;
TString currentString = "";
Int_t nCurrColumn = 0;
if (configfileExclusionErrors.CompareTo("") != 0){
ifstream in2(configfileExclusionErrors.Data());
while(!in2.eof() && nTakeOutSys<nDataSets ){
// cout << "read line:" << nTakeOutSys+1 << endl;
in2 >> currentString;
// cout << currentString << endl;
if (currentString.CompareTo("STOP") == 0){
cout << "found " << ptSysRemNames[nTakeOutSys].size() << " sys errors to be excluded." << endl;
nTakeOutSys++;
nCurrColumn = 0;
} else {
if (nCurrColumn == 0){
cout << "reading energy: " << currentString.Data() << endl;
if (currentString.CompareTo(energyIndName[nTakeOutSys].Data()) != 0){
cout << "wrong order in file, expecting: " << energyIndName[nTakeOutSys].Data() << endl;
return;
}
nCurrColumn++;
} else {
ptSysRemNames[nTakeOutSys].push_back(currentString);
enableSysExcl[nTakeOutSys] = kTRUE;
nCurrColumn++;
}
}
}
}
//*************************************************************************************************
//*************************** read input
//*************************************************************************************************
TFile* inputFile[5] = {NULL, NULL, NULL, NULL, NULL};
TH1D* histStat[5] = {NULL, NULL, NULL, NULL, NULL};
TH1D* histSyst[5] = {NULL, NULL, NULL, NULL, NULL};
TH1D* histComb[5] = {NULL, NULL, NULL, NULL, NULL};
TH1D* histRelStat[5] = {NULL, NULL, NULL, NULL, NULL};
TH1D* histRelSyst[5] = {NULL, NULL, NULL, NULL, NULL};
TH1D* histRelComb[5] = {NULL, NULL, NULL, NULL, NULL};
TH1D* histRelSystUncorr[5] = {NULL, NULL, NULL, NULL, NULL};
TH1D* histRelSystCorr[5] = {NULL, NULL, NULL, NULL, NULL};
TH1D* histRelCombUncorr[5] = {NULL, NULL, NULL, NULL, NULL};
TGraphAsymmErrors* graphStat[6] = {NULL, NULL, NULL, NULL, NULL, NULL};
TGraphAsymmErrors* graphSyst[6] = {NULL, NULL, NULL, NULL, NULL, NULL};
TGraphAsymmErrors* graphComb[6] = {NULL, NULL, NULL, NULL, NULL, NULL};
TGraphAsymmErrors* graphStatReb[6] = {NULL, NULL, NULL, NULL, NULL, NULL};
TGraphAsymmErrors* graphCombReb[6] = {NULL, NULL, NULL, NULL, NULL, NULL};
TGraphAsymmErrors* graphSystReb[6] = {NULL, NULL, NULL, NULL, NULL, NULL};
TF1* fitComb[6] = {NULL, NULL, NULL, NULL, NULL, NULL};
Bool_t haveDetailedSys[5] = {kFALSE, kFALSE, kFALSE, kFALSE, kFALSE};
Int_t nPtBinsSysAvailSingle[5] = {-1, -1, -1, -1, -1};
Int_t numberDetSysAvailSingle[5] = {-1, -1, -1, -1, -1};
vector<TString>** ptSysDetail = new vector<TString>*[5];
vector<Double_t>** ptSysSplit = new vector<Double_t>*[5];
TFile* inputFileMC[5] = {NULL, NULL, NULL, NULL, NULL};
Bool_t haveMC[5] = {kFALSE, kFALSE, kFALSE, kFALSE, kFALSE};
TH1D* histMC[6] = {NULL, NULL, NULL, NULL, NULL, NULL};
TGraphAsymmErrors* graphMC[6] = {NULL, NULL, NULL, NULL, NULL, NULL};
TF1* fitCombMC[6] = {NULL, NULL, NULL, NULL, NULL, NULL};
vector<Bool_t>* isTaken = new vector<Bool_t>[5];
for(Int_t iR=0; iR<5; iR++) {
ptSysDetail[iR] = new vector<TString>[50];
ptSysSplit[iR] = new vector<Double_t>[50];
}
Double_t minY = 1e100;
Double_t maxY = 0;
Double_t minX = 1e100;
Double_t maxX = 0;
for (Int_t i = 0; i < nDataSets; i++){
// read external detailed systematics file
ifstream fileSysErrDetailed;
fileSysErrDetailed.open(nameFileSys[i],ios_base::in);
// check if the file exists
if(fileSysErrDetailed.is_open()) {
haveDetailedSys[i] = kTRUE;
gSystem->Exec(Form("cp %s %s/SystematicErrorAveragedSingle_%s%s_%s.txt", nameFileSys[i].Data(), outputDir.Data(),meson.Data(),modeName.Data(), energyIndName[i].Data()));
} else{
haveDetailedSys[i] = kFALSE;
cout << "No single errors were found" << endl;
}
// read detailed file
if (haveDetailedSys[i]){
cout << nameFileSys[i] << endl;
Int_t iPtBin = 0;
string line;
Int_t iPtBinColumn = 0;
// format: ptSysDetail[$NEnergyRead][$PtBin].at($DetailedSys)
// $PtBin == 0: names of variations
// $DetailedSys == 0 && $PtBin != 0: pt-value
while (getline(fileSysErrDetailed, line) && iPtBin < 100) {
istringstream ss(line);
TString temp ="";
iPtBinColumn = 0;
while(ss && iPtBinColumn < 100){
ss >> temp;
if( !(iPtBin==0 && temp.CompareTo("bin")==0) && !temp.IsNull()){
ptSysDetail[i][iPtBin].push_back(temp);
iPtBinColumn++;
}
}
if(iPtBin == 0){
if (temp.CompareTo("TotalError") != 0){
cout << "adding name of for TotalError" << endl;
ptSysDetail[i][iPtBin++].push_back("TotalError");
iPtBinColumn++;
} else {
cout << "Nothing to be added" << endl;
}
}else iPtBin++;
}
nPtBinsSysAvailSingle[i] = iPtBin-1;
fileSysErrDetailed.close();
numberDetSysAvailSingle[i] = (Int_t)ptSysDetail[i][0].size()-1;
cout << numberDetSysAvailSingle[i] << " of individual errors:"<< endl;
for (Int_t k = 1; k < numberDetSysAvailSingle[i]+1; k++ ){
cout << ((TString)ptSysDetail[i][0].at(k)).Data() << "\t";
}
cout << endl;
for (Int_t counter = 0; counter < nPtBinsSysAvailSingle[i]; counter++){ // pt loop
for (Int_t k = 1; k < numberDetSysAvailSingle[i]+1; k++ ){ // sources loop
cout << ((TString)ptSysDetail[i][counter+1].at(k)) << "\t" ;
}
cout << endl;
}
for (Int_t k = 1; k < numberDetSysAvailSingle[i]; k++){
Bool_t isTakenCurrent = kTRUE;
cout << (TString)ptSysDetail[i][0].at(k) << endl;
if (enableSysExcl[i]){
for (Int_t b = 0; b < (Int_t)ptSysRemNames[i].size(); b++){
if (((TString)ptSysDetail[i][0].at(k)).CompareTo(ptSysRemNames[i].at(b)) == 0){
cout << "disabled sys: " << ptSysRemNames[i].at(b) << endl;
isTakenCurrent = kFALSE;
}
}
}
isTaken[i].push_back(isTakenCurrent);
}
cout << "matrix for sys err disabling" << endl;
for (Int_t k = 0; k < numberDetSysAvailSingle[i]-1; k++){
cout << isTaken[i].at(k) << "\t" ;
}
cout << endl;
for (Int_t counter = 1; counter < nPtBinsSysAvailSingle[i]+1; counter++){ // pt loop
Double_t correlatedError = 0;
Double_t uncorrelatedError = 0;
for (Int_t k = 1; k < numberDetSysAvailSingle[i]; k++){
// cout << ((TString)ptSysDetail[i][0].at(k)) << endl;
Double_t currentError = ((TString)ptSysDetail[i][counter].at(k)).Atof();
if (!isTaken[i].at(k-1)){
// cout << "correlated" << endl;
correlatedError = correlatedError+ currentError*currentError;
} else {
uncorrelatedError = uncorrelatedError + currentError*currentError;
}
}
correlatedError = TMath::Sqrt(correlatedError);
uncorrelatedError = TMath::Sqrt(uncorrelatedError);
Double_t ptCurr = ((TString)ptSysDetail[i][counter].at(0)).Atof();
Double_t totalError = ((TString)ptSysDetail[i][counter].at(numberDetSysAvailSingle[i])).Atof();
ptSysSplit[i][counter-1].push_back(ptCurr);
ptSysSplit[i][counter-1].push_back(correlatedError);
ptSysSplit[i][counter-1].push_back(uncorrelatedError);
ptSysSplit[i][counter-1].push_back(totalError);
cout << ptCurr<< "\t"<< correlatedError << "\t" << uncorrelatedError << "\t" << totalError << endl;
cout << ptSysSplit[i][counter-1].at(0) << "\t" << ptSysSplit[i][counter-1].at(1) << "\t"<< ptSysSplit[i][counter-1].at(2)<< "\t" << ptSysSplit[i][counter-1].at(3)<< endl;
}
}
// MC file reading if exisiting
if (nameFileMC[i].CompareTo("bla") != 0){
inputFileMC[i] = new TFile(nameFileMC[i]);
if (!inputFileMC[i]->IsZombie() && nameHistMC[i].CompareTo("bla") != 0){
histMC[i] = (TH1D*)inputFileMC[i]->Get(nameHistMC[i].Data());
if (histMC[i]){
haveMC[i] = kTRUE;
graphMC[i] = new TGraphAsymmErrors(histMC[i]);
while (graphMC[i]->GetX()[graphMC[i]->GetN()-1] > 30) graphMC[i]->RemovePoint(graphMC[i]->GetN()-1);
while (graphMC[i]->GetX()[0] < 0.1) graphMC[i]->RemovePoint(0);
fitCombMC[i] = DoFitWithTsallis(graphMC[i],Form("fitCombMC_%d",i),meson.Data(), graphMC[i]->GetY()[0],7.,0.2);
}
}
}
// Data file reading
inputFile[i] = new TFile(nameFile[i].Data());
if (isHist[0][i] && isHist[1][i]){
histStat[i] = (TH1D*)inputFile[i]->Get(nameHist[0][i].Data());
histStat[i]->Scale(scaleFactor[i]);
histSyst[i] = (TH1D*)inputFile[i]->Get(nameHist[1][i].Data());
histSyst[i]->Scale(scaleFactor[i]);
histComb[i] = (TH1D*)histStat[i]->Clone(Form("histComb_%d",i));
CalculateStatPlusSysErrors(histComb[i],histSyst[i]);
graphComb[i] = new TGraphAsymmErrors(histComb[i]);
graphStat[i] = new TGraphAsymmErrors(histStat[i]);
graphSyst[i] = new TGraphAsymmErrors(histSyst[i]);
histRelStat[i] = (TH1D*)histStat[i]->Clone(Form("Rel%s",nameHist[0][i].Data()));
histRelSyst[i] = (TH1D*)histSyst[i]->Clone(Form("Rel%s",nameHist[1][i].Data()));
histRelComb[i] = (TH1D*)histComb[i]->Clone(Form("Rel_histComb_%d",i));
histRelSystUncorr[i] = (TH1D*)histSyst[i]->Clone(Form("Rel%s_Uncorrelated",nameHist[1][i].Data()));
histRelSystCorr[i] = (TH1D*)histSyst[i]->Clone(Form("Rel%s_Correlated",nameHist[1][i].Data()));
histRelCombUncorr[i] = (TH1D*)histComb[i]->Clone(Form("Rel_histComb_%d_Uncorrelated",i));
for (Int_t j = 1; j< histRelStat[i]->GetNbinsX()+1;j++){
histRelStat[i]->SetBinContent(j,histRelStat[i]->GetBinError(j)/histRelStat[i]->GetBinContent(j));
histRelStat[i]->SetBinError(j, 0);
histRelSyst[i]->SetBinContent(j, histRelSyst[i]->GetBinError(j)/histRelSyst[i]->GetBinContent(j));
histRelSyst[i]->SetBinError(j, 0);
histRelComb[i]->SetBinContent(j, histRelComb[i]->GetBinError(j)/histRelComb[i]->GetBinContent(j));
histRelComb[i]->SetBinError(j, 0);
histRelSystUncorr[i]->SetBinContent(j, histRelSystUncorr[i]->GetBinError(j)/histRelSystUncorr[i]->GetBinContent(j));
histRelSystUncorr[i]->SetBinError(j, 0);
histRelSystCorr[i]->SetBinContent(j, 0);
histRelSystCorr[i]->SetBinError(j, 0);
histRelCombUncorr[i]->SetBinContent(j, histRelCombUncorr[i]->GetBinError(j)/histRelCombUncorr[i]->GetBinContent(j));
histRelCombUncorr[i]->SetBinError(j, 0);
}
if (haveDetailedSys[i] && enableSysExcl[i]){
for (Int_t iPt = 0; iPt < nPtBinsSysAvailSingle[i]; iPt++){
Double_t ptCurr = ptSysSplit[i][iPt].at(0);
Int_t binPt = histRelSyst[i]->FindBin(ptCurr);
Double_t stat = histRelStat[i]->GetBinContent(binPt);
Double_t newSys = histRelSystUncorr[i]->GetBinContent(binPt)*ptSysSplit[i][iPt].at(2)/ptSysSplit[i][iPt].at(3);
Double_t newComb = TMath::Sqrt(newSys*newSys + stat*stat);
histRelSystUncorr[i]->SetBinContent(binPt, newSys);
histRelCombUncorr[i]->SetBinContent(binPt, newComb);
cout << histRelSyst[i]->GetBinContent(binPt) << "\t" <<histRelComb[i]->GetBinContent(binPt) << "\t" << histRelSystUncorr[i]->GetBinContent(binPt) << "\t" << histRelCombUncorr[i]->GetBinContent(binPt) << endl;
histRelSystCorr[i]->SetBinContent(binPt, ptSysSplit[i][iPt].at(1)/100.);
histRelSystCorr[i]->SetBinError(binPt, 0);
}
}
} else if (!isHist[0][i] && !isHist[1][i]){
cout << "loading graph" << nameHist[0][i].Data() << endl;
graphStat[i] = (TGraphAsymmErrors*)inputFile[i]->Get(nameHist[0][i].Data());
graphStat[i]->GetYaxis()->SetRangeUser(graphStat[i]->GetY()[graphStat[i]->GetN()-1], graphStat[i]->GetY()[0]);
cout << "resetting y axis: " << graphStat[i]->GetY()[graphStat[i]->GetN()-1] << "\t" << graphStat[i]->GetY()[0] << endl;
ScaleGraph(graphStat[i],scaleFactor[i]);
cout << "statistical graph" << endl;
graphStat[i]->Print();
cout << "loading graph" << nameHist[1][i].Data() << endl;
graphSyst[i] = (TGraphAsymmErrors*)inputFile[i]->Get(nameHist[1][i].Data());
graphSyst[i]->GetYaxis()->SetRangeUser(graphSyst[i]->GetY()[graphSyst[i]->GetN()-1], graphSyst[i]->GetY()[0]);
cout << "resetting y axis: " << graphSyst[i]->GetY()[graphSyst[i]->GetN()-1] << "\t" << graphSyst[i]->GetY()[0] << endl;
ScaleGraph(graphSyst[i],scaleFactor[i]);
cout << "systematics graph" << endl;
graphSyst[i]->Print();
if (nameHist[2][i].CompareTo("bla")!= 0){
cout << "loading graph" << nameHist[2][i].Data() << endl;
graphComb[i] = (TGraphAsymmErrors*)inputFile[i]->Get(nameHist[2][i].Data());
ScaleGraph(graphComb[i],scaleFactor[i]);
} else {
graphComb[i] = CalculateStatPlusSysErrors(graphStat[i],graphSyst[i]);
}
// read binning from graphs
Double_t binningGraphs[100];
binningGraphs[0] = 0;
for (Int_t j = 0; j < graphStat[i]->GetN(); j++){
binningGraphs[j+1] = graphStat[i]->GetX()[j]-graphStat[i]->GetEXlow()[j];
cout << binningGraphs[j+1] << ",";
if (j == graphStat[i]->GetN()-1){
binningGraphs[j+2] = graphStat[i]->GetX()[j]+graphStat[i]->GetEXhigh()[j];
cout << binningGraphs[j+2];
}
}
cout << endl;
histRelStat[i] = new TH1D(Form("Rel%s",nameHist[0][i].Data()),Form("Rel%s",nameHist[0][i].Data()),graphStat[i]->GetN()+1, binningGraphs );
histRelComb[i] = new TH1D(Form("Rel_histComb_%d",i), Form("Rel_histComb_%d",i), graphStat[i]->GetN()+1, binningGraphs );
histRelSyst[i] = new TH1D(Form("Rel%s",nameHist[0][i].Data()),Form("Rel%s",nameHist[0][i].Data()),graphStat[i]->GetN()+1, binningGraphs );
histRelSystCorr[i] = new TH1D(Form("Rel%s_Correlated",nameHist[0][i].Data()),Form("Rel%s_Uncorrelated",nameHist[0][i].Data()),graphStat[i]->GetN()+1, binningGraphs );
histRelSystUncorr[i] = new TH1D(Form("Rel%s_Uncorrelated",nameHist[0][i].Data()),Form("Rel%s_Uncorrelated",nameHist[0][i].Data()),graphStat[i]->GetN()+1, binningGraphs );
histRelCombUncorr[i] = new TH1D(Form("Rel_histComb_%d_Uncorrelated",i), Form("Rel_histComb_%d_Uncorrelated",i), graphStat[i]->GetN()+1, binningGraphs );
for (Int_t j = 0; j< graphStat[i]->GetN(); j++){
Int_t binStat = histRelStat[i]-> FindBin(graphStat[i]->GetX()[j]);
if (graphStat[i]->GetY()[j] != 0){
histRelStat[i]->SetBinContent(binStat, (graphStat[i]->GetEYhigh()[j]+graphStat[i]->GetEYlow()[j])/(2*graphStat[i]->GetY()[j]));
histRelStat[i]->SetBinError(binStat, 0.);
} else {
histRelStat[i]->SetBinContent(binStat, 0);
histRelStat[i]->SetBinError(binStat, 0.);
}
}
for (Int_t j = 0; j< graphSyst[i]->GetN(); j++){
Int_t binSyst = histRelSyst[i]-> FindBin(graphSyst[i]->GetX()[j]);
if (graphSyst[i]->GetY()[j] != 0){
histRelSyst[i]->SetBinContent(binSyst, (graphSyst[i]->GetEYhigh()[j]+graphSyst[i]->GetEYlow()[j])/(2*graphSyst[i]->GetY()[j]));
histRelSyst[i]->SetBinError(binSyst, 0.);
histRelSystUncorr[i]->SetBinContent(binSyst, (graphSyst[i]->GetEYhigh()[j]+graphSyst[i]->GetEYlow()[j])/(2*graphSyst[i]->GetY()[j]));
histRelSystUncorr[i]->SetBinError(binSyst, 0.);
histRelSystCorr[i]->SetBinContent(binSyst, 0.);
histRelSystCorr[i]->SetBinError(binSyst, 0.);
} else {
histRelSyst[i]->SetBinContent(binSyst, 0);
histRelSyst[i]->SetBinError(binSyst, 0.);
histRelSystUncorr[i]->SetBinContent(binSyst, 0);
histRelSystUncorr[i]->SetBinError(binSyst, 0.);
histRelSystCorr[i]->SetBinContent(binSyst, 0.);
histRelSystCorr[i]->SetBinError(binSyst, 0.);
}
}
for (Int_t j = 0; j< graphComb[i]->GetN(); j++){
Int_t binComb = histRelComb[i]-> FindBin(graphComb[i]->GetX()[j]);
if (graphComb[i]->GetY()[j] != 0){
histRelComb[i]->SetBinContent(binComb, (graphComb[i]->GetEYhigh()[j]+graphComb[i]->GetEYlow()[j])/(2*graphComb[i]->GetY()[j]));
histRelComb[i]->SetBinError(binComb, 0.);
histRelCombUncorr[i]->SetBinContent(binComb, (graphComb[i]->GetEYhigh()[j]+graphComb[i]->GetEYlow()[j])/(2*graphComb[i]->GetY()[j]));
histRelCombUncorr[i]->SetBinError(binComb, 0.);
} else {
histRelComb[i]->SetBinContent(binComb, 0);
histRelComb[i]->SetBinError(binComb, 0.);
histRelCombUncorr[i]->SetBinContent(binComb, 0);
histRelCombUncorr[i]->SetBinError(binComb, 0.);
}
}
if (haveDetailedSys[i] && enableSysExcl[i]){
for (Int_t iPt = 0; iPt < nPtBinsSysAvailSingle[i]; iPt++){
Double_t ptCurr = ptSysSplit[i][iPt].at(0);
Int_t binPt = histRelSyst[i]->FindBin(ptCurr);
cout << histRelStat[i]->FindBin(ptCurr) << "\t"<< histRelSyst[i]->FindBin(ptCurr) << "\t" << histRelComb[i]->FindBin(ptCurr) << endl;
Double_t stat = histRelStat[i]->GetBinContent(binPt);
Double_t newSys = histRelSystUncorr[i]->GetBinContent(binPt)*ptSysSplit[i][iPt].at(2)/ptSysSplit[i][iPt].at(3);
Double_t newComb = TMath::Sqrt(newSys*newSys + stat*stat);
histRelSystUncorr[i]->SetBinContent(binPt, newSys);
histRelCombUncorr[i]->SetBinContent(binPt, newComb);
cout << histRelStat[i]->GetBinContent(binPt) << "\t" << histRelSyst[i]->GetBinContent(binPt) << "\t" <<histRelComb[i]->GetBinContent(binPt) << "\t" << histRelSystUncorr[i]->GetBinContent(binPt) << "\t" << histRelCombUncorr[i]->GetBinContent(binPt) << endl;
histRelSystCorr[i]->SetBinContent(binPt, ptSysSplit[i][iPt].at(1)/100.);
histRelSystCorr[i]->SetBinError(binPt, 0);
}
}
}
RemoveZerosAndPrint(graphComb[i],Form("graphComb_%d",i));
RemoveZerosAndPrint(graphStat[i],Form("graphStat_%d",i));
RemoveZerosAndPrint(graphSyst[i],Form("graphSyst_%d",i));
if (maxY < graphComb[i]->GetY()[0])
maxY = graphComb[i]->GetY()[0];
if (minY > graphComb[i]->GetY()[graphComb[i]->GetN()-1])
minY = graphComb[i]->GetY()[graphComb[i]->GetN()-1];
if (maxX < graphComb[i]->GetX()[graphComb[i]->GetN()-1])
maxX = graphComb[i]->GetX()[graphComb[i]->GetN()-1];
if (minX > graphComb[i]->GetX()[0])
minX = graphComb[i]->GetX()[0];
//*************************************************************************************************
//*************************** Fits
//*************************************************************************************************
if (nameHist[3][i].CompareTo("bla") != 0){
fitComb[i] = (TF1*)inputFile[i]->Get(nameHist[3][i].Data());
} else {
if(!fitSelection.CompareTo("TCM"))
fitComb[i] = DoFitWithTCM(graphComb[i],Form("fitComb_%d",i),meson.Data(), graphComb[i]->GetY()[0],7.,0.2,graphComb[i]->GetY()[0]/10,0.3);
else if(!fitSelection.CompareTo("oHag"))
fitComb[i] = DoFitWithModHagedorn(graphComb[i],Form("fitComb_%d",i),meson.Data(), graphComb[i]->GetY()[0],0.5,0.,0.4,6);
else
fitComb[i] = DoFitWithTsallis(graphComb[i],Form("fitComb_%d",i),meson.Data(), graphComb[i]->GetY()[0],7.,0.2);
}
if (doSpecialBinning){
graphCombReb[i] = new TGraphAsymmErrors(maxNBins-startBin);
graphSystReb[i] = new TGraphAsymmErrors(maxNBins-startBin);
graphStatReb[i] = new TGraphAsymmErrors(maxNBins-startBin);
for(Int_t j = startBin; j<maxNBins; j++){
Double_t ptCurrent = (finalBinningPt[j+1]+finalBinningPt[j])/2.;
Double_t relStatErr = histRelStat[i]->Interpolate(ptCurrent);
Double_t relCombErr = histRelCombUncorr[i]->Interpolate(ptCurrent);
Double_t relSystErr = histRelSystUncorr[i]->Interpolate(ptCurrent);
graphCombReb[i]->SetPoint(j-startBin,ptCurrent,fitComb[i]->Eval(ptCurrent));
if (relCombErr != 0){
graphCombReb[i]->SetPointError(j-startBin,(finalBinningPt[j+1]-finalBinningPt[j])/2.,(finalBinningPt[j+1]-finalBinningPt[j])/2.,
relCombErr*fitComb[i]->Eval(ptCurrent),relCombErr*fitComb[i]->Eval(ptCurrent));
} else {
graphCombReb[i]->SetPointError(j-startBin,(finalBinningPt[j+1]-finalBinningPt[j])/2.,(finalBinningPt[j+1]-finalBinningPt[j])/2.,
fitComb[i]->Eval(ptCurrent)*0.2,fitComb[i]->Eval(ptCurrent)*0.2);
}
graphSystReb[i]->SetPoint(j-startBin,ptCurrent,fitComb[i]->Eval(ptCurrent));
if (relSystErr != 0){
graphSystReb[i]->SetPointError(j-startBin,(finalBinningPt[j+1]-finalBinningPt[j])/2.,(finalBinningPt[j+1]-finalBinningPt[j])/2.,
relSystErr*fitComb[i]->Eval(ptCurrent),relSystErr*fitComb[i]->Eval(ptCurrent));
} else {
graphSystReb[i]->SetPointError(j-startBin,(finalBinningPt[j+1]-finalBinningPt[j])/2.,(finalBinningPt[j+1]-finalBinningPt[j])/2.,
fitComb[i]->Eval(ptCurrent)*0.2,fitComb[i]->Eval(ptCurrent)*0.2);
}
graphStatReb[i]->SetPoint(j-startBin,ptCurrent,fitComb[i]->Eval(ptCurrent));
if (relStatErr != 0){
graphStatReb[i]->SetPointError(j-startBin,(finalBinningPt[j+1]-finalBinningPt[j])/2.,(finalBinningPt[j+1]-finalBinningPt[j])/2.,
relStatErr*fitComb[i]->Eval(ptCurrent),relStatErr*fitComb[i]->Eval(ptCurrent));
} else {
graphStatReb[i]->SetPointError(j-startBin,(finalBinningPt[j+1]-finalBinningPt[j])/2.,(finalBinningPt[j+1]-finalBinningPt[j])/2.,
fitComb[i]->Eval(ptCurrent)*0.2,fitComb[i]->Eval(ptCurrent)*0.2);
}
}
graphCombReb[i]->Print();
} else {
if (i==0 ){
graphCombReb[i] = (TGraphAsymmErrors*)graphComb[i]->Clone(Form("graphCombReb_%d",i));
graphSystReb[i] = (TGraphAsymmErrors*)graphSyst[i]->Clone(Form("graphSystReb_%d",i));
graphStatReb[i] = (TGraphAsymmErrors*)graphStat[i]->Clone(Form("graphStatReb_%d",i));
for(Int_t j = 0; j<graphCombReb[i]->GetN(); j++){
// take out correlated uncertainty for interpolation
Double_t relCombErr = histRelCombUncorr[i]->GetBinContent(histRelCombUncorr[i]->FindBin(graphCombReb[i]->GetX()[j]));
Double_t relSystErr = histRelSystUncorr[i]->GetBinContent(histRelSystUncorr[i]->FindBin(graphCombReb[i]->GetX()[j]));
if (relCombErr != 0){
graphCombReb[i]->SetPointError(j,graphCombReb[i]->GetEXlow()[j],graphCombReb[i]->GetEXhigh()[j],
relCombErr*graphCombReb[i]->GetY()[j],relCombErr*graphCombReb[i]->GetY()[j]);
} else {
graphCombReb[i]->SetPointError(j,graphCombReb[i]->GetEXlow()[j],graphCombReb[i]->GetEXhigh()[j],
graphCombReb[i]->GetY()[j]*0.2,graphCombReb[i]->GetY()[j]*0.2);
}
if (relSystErr != 0){
graphSystReb[i]->SetPointError(j,graphSystReb[i]->GetEXlow()[j],graphSystReb[i]->GetEXhigh()[j],
relSystErr*graphSystReb[i]->GetY()[j],relSystErr*graphSystReb[i]->GetY()[j]);
} else {
graphSystReb[i]->SetPointError(j,graphSystReb[i]->GetEXlow()[j],graphSystReb[i]->GetEXhigh()[j],
graphSystReb[i]->GetY()[j]*0.2,graphSystReb[i]->GetY()[j]*0.2);
}
}
} else {
graphCombReb[i] = (TGraphAsymmErrors*)graphComb[0]->Clone(Form("graphCombReb_%d",i));
graphSystReb[i] = (TGraphAsymmErrors*)graphSyst[0]->Clone(Form("graphSystReb_%d",i));
graphStatReb[i] = (TGraphAsymmErrors*)graphStat[0]->Clone(Form("graphStatReb_%d",i));
for(Int_t j = 0; j<graphCombReb[i]->GetN(); j++){
Double_t relStatErr = histRelStat[i]->Interpolate(graphCombReb[i]->GetX()[j]);
// take out correlated uncertainty for interpolation
Double_t relCombErr = histRelCombUncorr[i]->Interpolate(graphCombReb[i]->GetX()[j]);
Double_t relSystErr = histRelSystUncorr[i]->Interpolate(graphCombReb[i]->GetX()[j]);
graphCombReb[i]->SetPoint(j,graphCombReb[i]->GetX()[j],fitComb[i]->Eval(graphCombReb[i]->GetX()[j]));
if (relCombErr != 0){
graphCombReb[i]->SetPointError(j,graphCombReb[i]->GetEXlow()[j],graphCombReb[i]->GetEXhigh()[j],
relCombErr*fitComb[i]->Eval(graphCombReb[i]->GetX()[j]),relCombErr*fitComb[i]->Eval(graphCombReb[i]->GetX()[j]));
} else {
graphCombReb[i]->SetPointError(j,graphCombReb[i]->GetEXlow()[j],graphCombReb[i]->GetEXhigh()[j],
fitComb[i]->Eval(graphCombReb[i]->GetX()[j])*0.2,fitComb[i]->Eval(graphCombReb[i]->GetX()[j])*0.2);
}
graphSystReb[i]->SetPoint(j,graphSystReb[i]->GetX()[j],fitComb[i]->Eval(graphSystReb[i]->GetX()[j]));
if (relSystErr != 0){
graphSystReb[i]->SetPointError(j,graphSystReb[i]->GetEXlow()[j],graphSystReb[i]->GetEXhigh()[j],
relSystErr*fitComb[i]->Eval(graphCombReb[i]->GetX()[j]),relSystErr*fitComb[i]->Eval(graphCombReb[i]->GetX()[j]));
} else {
graphSystReb[i]->SetPointError(j,graphSystReb[i]->GetEXlow()[j],graphSystReb[i]->GetEXhigh()[j],
fitComb[i]->Eval(graphSystReb[i]->GetX()[j])*0.2,fitComb[i]->Eval(graphSystReb[i]->GetX()[j])*0.2);
}
graphStatReb[i]->SetPoint(j,graphStatReb[i]->GetX()[j],fitComb[i]->Eval(graphStatReb[i]->GetX()[j]));
if (relStatErr != 0){
graphStatReb[i]->SetPointError(j,graphStatReb[i]->GetEXlow()[j],graphStatReb[i]->GetEXhigh()[j],
relStatErr*fitComb[i]->Eval(graphStatReb[i]->GetX()[j]),relStatErr*fitComb[i]->Eval(graphStatReb[i]->GetX()[j]));
} else {
graphStatReb[i]->SetPointError(j,graphStatReb[i]->GetEXlow()[j],graphStatReb[i]->GetEXhigh()[j],
fitComb[i]->Eval(graphStatReb[i]->GetX()[j])*0.2,fitComb[i]->Eval(graphStatReb[i]->GetX()[j])*0.2);
}
}
}
}
}
// return;
Int_t nDataSetsMC = nDataSets;
Int_t nMCBinsRemoved = 0;
Int_t exampleBinMC = exampleBin;
if (haveMC[0]){
if (nameFileMCRef.CompareTo("") != 0){
inputFileMC[nDataSets] = new TFile(nameFileMCRef);
if (!inputFileMC[nDataSets]->IsZombie() && nameHistMCRef.CompareTo("") != 0){
histMC[nDataSets] = (TH1D*)inputFileMC[nDataSets]->Get(nameHistMCRef.Data());
if (histMC[nDataSets]){
nDataSetsMC++;
haveMC[nDataSets] = kTRUE;
graphMC[nDataSets] = new TGraphAsymmErrors(histMC[nDataSets]);
while (graphMC[nDataSets]->GetX()[graphMC[nDataSets]->GetN()-1] > 30) graphMC[nDataSets]->RemovePoint(graphMC[nDataSets]->GetN()-1);
while (graphMC[nDataSets]->GetX()[0] < 0.1){
graphMC[nDataSets]->RemovePoint(0);
nMCBinsRemoved++;
}
fitCombMC[nDataSets] = DoFitWithTsallis(graphMC[nDataSets],Form("fitCombMC_%d",nDataSets),meson.Data(), graphMC[nDataSets]->GetY()[0],7.,0.2);
energyIndName[nDataSets] = finalEnergy;
energyInd[nDataSets] = energy;
}
}
}
exampleBinMC = histMC[0]->FindBin(graphCombReb[0]->GetX()[exampleBin])-nMCBinsRemoved-1;
}
//*************************************************************************************************
//*************************** extrapolate spectra stat errors only ********************************
//*************************************************************************************************
if (haveMC[0]){
TGraphAsymmErrors* graphFinalEnergyMC = GetInterpolSpectrum2D( nDataSetsMC,
graphMC,
energyInd,
energy,
100,
3
);
if( graphPtvsSqrtsMC && gPtvsEnergiesSystemMC && fPowerlawSystemMC ){
Int_t columns = 2;
Int_t rows = 2;
Int_t counter = 0;
while (columns*rows < graphMC[0]->GetN()){
if (counter%2 != 0) rows++;
else columns++;
counter++;
}
PlotInterpolationPtBins(graphPtvsSqrtsMC,gPtvsEnergiesSystemMC,fPowerlawSystemMC,0x0, graphFinalEnergyMC,columns, rows, Form("%s/%s_%s_MC_Pt_vs_Sqrts.%s",outputDirPlots.Data(),meson.Data(),modeName.Data(), suffix.Data()));
cout << "Example bin MC: " << exampleBinMC << endl;
if (exampleBinMC < 1)
exampleBinMC = maxNBins-2;
PlotInterpolationSinglePtBin(graphPtvsSqrtsMC[exampleBinMC],gPtvsEnergiesSystemMC[exampleBinMC], fPowerlawSystemMC[exampleBinMC], 0x0, graphFinalEnergyMC, exampleBinMC, Form("%s/%s_%s_MC_Pt_vs_Sqrts_SinglePtBin.%s",outputDirPlots.Data(),meson.Data(),modeName.Data(), suffix.Data()));
splineAlphaMC = new TSpline5("alphaMCSpline",graphAlphaMC);
} else {
cout << "ERROR: NULL pointer - returning..." << endl;
cout << graphAlphaMC << endl;
cout << graphPtvsSqrtsMC << endl;
cout << gPtvsEnergiesSystemMC << endl;
cout << fPowerlawSystemMC << endl;
return;
}
}
//*************************************************************************************************
//********************* extrapolate spectra combined errors without common*************************
//*************************************************************************************************
TGraphAsymmErrors* graphFinalEnergyComb1 = GetInterpolSpectrum2D( nDataSets,
graphCombReb,
energyInd,
energy,
nTrials,
0
);
if( graphPtvsSqrts && gPtvsEnergiesSystem && fPowerlawSystem ){
Int_t columns = 2;
Int_t rows = 2;
Int_t counter = 0;
while (columns*rows < graphCombReb[0]->GetN()){
if (counter%2 != 0) rows++;
else columns++;
counter++;
}
PlotInterpolationPtBins(graphPtvsSqrts, gPtvsEnergiesSystem, fPowerlawSystem, fPowerlawSystemSystMC, graphFinalEnergyComb1, columns, rows, Form("%s/%s_%s_CombUnCorr_Pt_vs_Sqrts.%s",outputDirPlots.Data(),meson.Data(),modeName.Data(), suffix.Data()));
cout << "Example bin data" << exampleBin << "\t" << graphCombReb[0]->GetN() << endl;
if (exampleBin >= graphCombReb[0]->GetN() )
exampleBin = graphCombReb[0]->GetN()-1;
PlotInterpolationSinglePtBin(graphPtvsSqrts[exampleBin], gPtvsEnergiesSystem[exampleBin], fPowerlawSystem[exampleBin], fPowerlawSystemSystMC[exampleBin], graphFinalEnergyComb1, exampleBin, Form("%s/%s_%s_CombUnCorr_Pt_vs_Sqrts_SinglePtBin.%s",outputDirPlots.Data(),meson.Data(),modeName.Data(), suffix.Data()));
} else {
cout << "ERROR: NULL pointer - returning..." << endl;
cout << graphAlpha << endl;
cout << graphPtvsSqrts << endl;
cout << gPtvsEnergiesSystem << endl;
cout << fPowerlawSystem << endl;
return;
}
graphFinalEnergyComb1->Print();
//*************************************************************************************************
//*************************** extrapolate spectra stat errors only ********************************
//*************************************************************************************************
TGraphAsymmErrors* graphFinalEnergyStat = GetInterpolSpectrum2D( nDataSets,
graphStatReb,
energyInd,
energy,
nTrials,
1
);
if( graphPtvsSqrtsStat && gPtvsEnergiesSystemStat && fPowerlawSystemStat ){
Int_t columns = 2;
Int_t rows = 2;
Int_t counter = 0;
while (columns*rows < graphCombReb[0]->GetN()){
if (counter%2 != 0) rows++;
else columns++;
counter++;
}
PlotInterpolationPtBins(graphPtvsSqrtsStat, gPtvsEnergiesSystemStat, fPowerlawSystemStat, 0x0, graphFinalEnergyStat, columns, rows, Form("%s/%s_%s_Stat_Pt_vs_Sqrts.%s",outputDirPlots.Data(), meson.Data(), modeName.Data(), suffix.Data()));
PlotInterpolationSinglePtBin(graphPtvsSqrtsStat[exampleBin], gPtvsEnergiesSystemStat[exampleBin], fPowerlawSystemStat[exampleBin], 0x0, graphFinalEnergyStat, exampleBin, Form("%s/%s_%s_Stat_Pt_vs_Sqrts_SinglePtBin.%s", outputDirPlots.Data(), meson.Data(), modeName.Data(), suffix.Data()));
}else{
cout << "ERROR: NULL pointer - returning..." << endl;
cout << graphAlphaStat << endl;
cout << graphPtvsSqrtsStat << endl;
cout << gPtvsEnergiesSystemStat << endl;
cout << fPowerlawSystemStat << endl;
return;
}
for (Int_t iPt = 0; iPt < graphFinalEnergyStat->GetN(); iPt++ ){
Double_t relSysError = graphFinalEnergyStat->GetEYhigh()[iPt]/graphFinalEnergyStat->GetY()[iPt];
Double_t newError = graphFinalEnergyComb1->GetY()[iPt] * relSysError;
graphFinalEnergyStat->SetPoint(iPt, graphFinalEnergyStat->GetX()[iPt], graphFinalEnergyComb1->GetY()[iPt]);
graphFinalEnergyStat->SetPointError(iPt, graphFinalEnergyStat->GetEXlow()[iPt], graphFinalEnergyStat->GetEXhigh()[iPt], newError, newError);
}
graphFinalEnergyStat->Print();
//*************************************************************************************************
//*************************** extrapolate spectra uncorr syst errors only *************************
//*************************************************************************************************
TGraphAsymmErrors* graphFinalEnergySyst = GetInterpolSpectrum2D( nDataSets,
graphSystReb,
energyInd,
energy,
nTrials,
2
);
TGraphAsymmErrors* graphFinalEnergyIntSyst = 0x0;
if( graphPtvsSqrtsSyst && gPtvsEnergiesSystemSyst && fPowerlawSystemSyst ){
Int_t columns = 2;
Int_t rows = 2;
Int_t counter = 0;
while (columns*rows < graphCombReb[0]->GetN()){
if (counter%2 != 0) rows++;
else columns++;
counter++;
}
PlotInterpolationPtBins(graphPtvsSqrtsSyst, gPtvsEnergiesSystemSyst, fPowerlawSystemSyst, 0x0, graphFinalEnergySyst, columns, rows, Form("%s/%s_%s_Syst_Pt_vs_Sqrts.%s", outputDirPlots.Data(), meson.Data(), modeName.Data(), suffix.Data()));
PlotInterpolationSinglePtBin(graphPtvsSqrtsSyst[exampleBin], gPtvsEnergiesSystemSyst[exampleBin], fPowerlawSystemSyst[exampleBin], 0x0, graphFinalEnergyStat, exampleBin, Form("%s/%s_%s_Syst_Pt_vs_Sqrts_SinglePtBin.%s", outputDirPlots.Data(), meson.Data(), modeName.Data(), suffix.Data()));
}else{
cout << "ERROR: NULL pointer - returning..." << endl;
cout << graphAlphaSyst << endl;
cout << graphPtvsSqrtsSyst << endl;
cout << gPtvsEnergiesSystemSyst << endl;
cout << fPowerlawSystemSyst << endl;
return;
}
for (Int_t iPt = 0; iPt < graphFinalEnergySyst->GetN(); iPt++ ){
Double_t relSysError = graphFinalEnergySyst->GetEYhigh()[iPt]/graphFinalEnergySyst->GetY()[iPt];
Double_t newError = graphFinalEnergyComb1->GetY()[iPt] * relSysError;
graphFinalEnergySyst->SetPoint(iPt, graphFinalEnergySyst->GetX()[iPt], graphFinalEnergyComb1->GetY()[iPt]);
graphFinalEnergySyst->SetPointError(iPt, graphFinalEnergySyst->GetEXlow()[iPt], graphFinalEnergySyst->GetEXhigh()[iPt], newError, newError);
}
graphFinalEnergySyst->Print();
cout << "calculating relative interpolation error" << endl;
if(graphInterpolSyst){
while (graphDiffMCIntAndReal->GetX()[graphDiffMCIntAndReal->GetN()-1] > graphFinalEnergySyst->GetX()[graphFinalEnergySyst->GetN()-1])
graphDiffMCIntAndReal->RemovePoint(graphDiffMCIntAndReal->GetN()-1);
graphDiffMCIntAndReal->Print();
TSpline5* splineRelDiffMC = new TSpline5("relDiffSpline",graphDiffMCIntAndReal);
graphFinalEnergyIntSyst = (TGraphAsymmErrors*)graphFinalEnergySyst->Clone("graphFinalEnergyInterpolationSyst");
for (Int_t iPt = 0; iPt < graphFinalEnergyIntSyst->GetN(); iPt++ ){
Double_t relSysError1 = TMath::Abs(graphInterpolSyst->GetY()[iPt]-graphFinalEnergyComb1->GetY()[iPt])/graphFinalEnergyComb1->GetY()[iPt];
Double_t relSysError2 = splineRelDiffMC->Eval(graphFinalEnergyIntSyst->GetX()[iPt]);
cout << graphFinalEnergyIntSyst->GetX()[iPt] << "\t"<< relSysError1 << "\t"<< relSysError2 << endl;
Double_t relSysError = TMath::Sqrt(relSysError1*relSysError1+relSysError2*relSysError2);
Double_t newError = graphFinalEnergyComb1->GetY()[iPt] * relSysError;
graphFinalEnergyIntSyst->SetPoint(iPt, graphFinalEnergyIntSyst->GetX()[iPt], graphFinalEnergyComb1->GetY()[iPt]);
graphFinalEnergyIntSyst->SetPointError(iPt, graphFinalEnergyIntSyst->GetEXlow()[iPt], graphFinalEnergyIntSyst->GetEXhigh()[iPt], newError, newError);
}
graphFinalEnergyIntSyst->Print();
}
TGraphAsymmErrors* graphFinalEnergyCombWOCorr = CalculateStatPlusSysErrors(graphFinalEnergyStat,graphFinalEnergySyst);
// plot alpha with proper errors
if (graphAlphaStat && graphAlphaSyst){
PlotAlphavsPt(graphAlphaStat, graphAlphaSyst, graphAlphaMC, splineAlphaMC, "pp", Form("%s, %s",mesonString.Data(), detProcess.Data()), Form("%s/%s_%s_Alpha_vs_Pt.%s", outputDirPlots.Data(),meson.Data(),modeName.Data(), suffix.Data()));
}
TF1* fitFinal;
if(!fitSelection.CompareTo("TCM"))
fitFinal = DoFitWithTCM(graphFinalEnergyCombWOCorr,Form("fitComb_%s%s",finalEnergy.Data(), addLabel.Data()),meson.Data(), graphFinalEnergyCombWOCorr->GetY()[0],7.,0.2,graphFinalEnergyCombWOCorr->GetY()[0]/10,0.3);
else if(!fitSelection.CompareTo("oHag"))
fitFinal = DoFitWithModHagedorn(graphFinalEnergyCombWOCorr,Form("fitComb_%s%s",finalEnergy.Data(), addLabel.Data()),meson.Data(), graphFinalEnergyCombWOCorr->GetY()[0],0.5,0.,0.4,6);
else
fitFinal = DoFitWithTsallis(graphFinalEnergyCombWOCorr,Form("fitComb_%s%s",finalEnergy.Data(), addLabel.Data()),meson.Data(), graphFinalEnergyCombWOCorr->GetY()[0],7,0.2);
graphCombReb[nDataSets] = graphFinalEnergyCombWOCorr;
graphComb[nDataSets] = graphFinalEnergyCombWOCorr;
graphStat[nDataSets] = graphFinalEnergyStat;
graphSyst[nDataSets] = graphFinalEnergySyst;
fitComb[nDataSets] = fitFinal;
energyIndName[nDataSets] = finalEnergy;
energyInd[nDataSets] = energy;
if (maxY < graphFinalEnergyCombWOCorr->GetY()[0])
maxY = graphFinalEnergyCombWOCorr->GetY()[0];
if (minY > graphFinalEnergyCombWOCorr->GetY()[graphFinalEnergyCombWOCorr->GetN()-1])
minY = graphFinalEnergyCombWOCorr->GetY()[graphFinalEnergyCombWOCorr->GetN()-1];
if (maxX < graphFinalEnergyCombWOCorr->GetX()[graphFinalEnergyCombWOCorr->GetN()-1])
maxX = graphFinalEnergyCombWOCorr->GetX()[graphFinalEnergyCombWOCorr->GetN()-1];
if (minX > graphFinalEnergyCombWOCorr->GetX()[0])
minX = graphFinalEnergyCombWOCorr->GetX()[0];
//*************************************************************************************************
//*************************** plotting
//*************************************************************************************************
TString axisLabel = "#frac{1}{2#pi #it{N}_{ev.}} #frac{d^{2}#it{N}}{#it{p}_{T}d#it{p}_{T}d#it{y}} (c/GeV)^{2}";
TString labelWriting = "InvYield";
if (maxY > 1000){
axisLabel = "#it{E} #frac{d^{3}#sigma}{d#it{p}^{3}} (pb GeV^{-2} #it{c}^{3} )";
labelWriting = "InvXSection";
}
TCanvas* canvasDummy2 = new TCanvas("canvasDummy2","",200,10,1200,1300); // gives the page size
DrawGammaCanvasSettings( canvasDummy2, 0.15, 0.01, 0.015, 0.08);
canvasDummy2->SetLogy();
canvasDummy2->SetLogx();
TCanvas* canvasDummy3 = new TCanvas("canvasDummy3","",200,10,1200,900); // gives the page size
DrawGammaCanvasSettings( canvasDummy3, 0.07, 0.01, 0.015, 0.08);
canvasDummy3->SetLogx();
TH2F * histo2DDummy = new TH2F("histo2DDummy","histo2DDummy",1000,minX/2,maxX*1.4,1000,minY/10,maxY*10);
SetStyleHistoTH2ForGraphs(histo2DDummy, "#it{p}_{T} (GeV/#it{c})",axisLabel, 0.032,0.04, 0.032,0.04, 0.85,1.65);
histo2DDummy->GetXaxis()->SetMoreLogLabels();
histo2DDummy->GetXaxis()->SetLabelOffset(-0.008);
TH2F * histo2DDummy2 = new TH2F("histo2DDummy","histo2DDummy",1000,minX/2,maxX*1.4,1000, 0.5, 1.5);
SetStyleHistoTH2ForGraphs(histo2DDummy2, "#it{p}_{T} (GeV/#it{c})","data/fit", 0.032,0.04, 0.032,0.04, 0.85,0.9);
histo2DDummy2->GetXaxis()->SetMoreLogLabels();
histo2DDummy2->GetXaxis()->SetLabelOffset(-0.008);
for (Int_t i = 0; i < nDataSets; i++){
PlotWithFit(canvasDummy2, canvasDummy3, histo2DDummy, histo2DDummy2, graphComb[i], graphCombReb[i], fitComb[i], Form("input_%s%s%s_withFit",meson.Data(), modeName.Data(), ((TString)ReturnCollisionEnergyOutputString(energyIndName[i].Data())).Data()), outputDirPlots, suffix, energyIndName[i]);
}
PlotWithFit(canvasDummy2, canvasDummy3, histo2DDummy, histo2DDummy2, graphFinalEnergyCombWOCorr, 0x0, fitFinal, Form("compare_%s%s%s_withFit", meson.Data(), modeName.Data(), collSystOut.Data()), outputDirPlots, suffix, energyIndName[nDataSets]);
PlotGraphsOfAllEnergies(canvasDummy2, histo2DDummy, nDataSets+1, graphCombReb, fitComb, energyIndName, Form("output%s%s_withFit",meson.Data(), modeName.Data()), outputDirPlots, suffix);
PlotGraphsOfAllEnergies(canvasDummy2, histo2DDummy, nDataSets+1, graphComb, fitComb, energyIndName, Form("output_orgBins_%s%s_withFit",meson.Data(), modeName.Data()), outputDirPlots, suffix);
// **************************************************************************************************
// ************************ prepare histos and graphs for writing ***********************************
// **************************************************************************************************
TH1D* histoFinalStat = NULL;
if (maxNBins > 0){
histoFinalStat = new TH1D(Form("histStatErr%s_%s_%s%s",modeName.Data(),meson.Data(),finalEnergy.Data(), addLabel.Data()),Form("histStatErr_%s_%s%s", meson.Data(), finalEnergy.Data(), addLabel.Data()),maxNBins,finalBinningPt);
for(Int_t i=0; i<graphFinalEnergyStat->GetN(); i++){
Int_t ptBin = histoFinalStat->FindBin(graphFinalEnergyStat->GetX()[i]);
histoFinalStat->SetBinContent(ptBin,graphFinalEnergyStat->GetY()[i]);
histoFinalStat->SetBinError(ptBin,graphFinalEnergyStat->GetEYhigh()[i]);
}
}
graphFinalEnergySyst->Print();
TGraphAsymmErrors* graphFinalEnergySystFull = (TGraphAsymmErrors*)graphFinalEnergySyst->Clone(Form("graphSystErr%s_%s_%s%s",modeName.Data(),meson.Data(),finalEnergy.Data(), addLabel.Data()));
for (Int_t iPt= 0; iPt< graphFinalEnergySystFull->GetN(); iPt++){
Double_t value = graphFinalEnergySyst->GetY()[iPt];
Double_t oldError = graphFinalEnergySyst->GetEYhigh()[iPt];
Double_t currentRelSys = oldError/value;
Double_t relCorrErr = histRelSystCorr[0]->Interpolate(graphFinalEnergySyst->GetX()[iPt]);
Double_t newRelSys = TMath::Sqrt(currentRelSys*currentRelSys+relCorrErr*relCorrErr);
Double_t newError = newRelSys*graphFinalEnergySyst->GetY()[iPt];
graphFinalEnergySystFull->SetPointError(iPt, graphFinalEnergySyst->GetEXlow()[iPt], graphFinalEnergySyst->GetEXhigh()[iPt], newError, newError);
}
TGraphAsymmErrors* graphFinalEnergyComb = CalculateStatPlusSysErrors(graphFinalEnergyStat,graphFinalEnergySystFull);
// **************************************************************************************************
// ************************* Plot relative errors ***************************************************
// **************************************************************************************************
Int_t nErrors = 3;
TGraphAsymmErrors* graphStatRel = CalculateRelErrUpAsymmGraph( graphFinalEnergyStat, Form("relativeStatError_%s_%s_%s%s", modeName.Data(), meson.Data(), finalEnergy.Data(), addLabel.Data()));
TGraphAsymmErrors* graphSystUncorrRel = CalculateRelErrUpAsymmGraph( graphFinalEnergySyst, Form("relativeUncorrSystError_%s_%s_%s%s", modeName.Data(), meson.Data(), finalEnergy.Data(), addLabel.Data()));
TGraphAsymmErrors* graphSystFullRel = CalculateRelErrUpAsymmGraph( graphFinalEnergySystFull, Form("relativeSystFullError_%s_%s_%s%s", modeName.Data(), meson.Data(), finalEnergy.Data(), addLabel.Data()));
TGraphAsymmErrors* graphSystInterRel = 0x0;
if (graphFinalEnergyIntSyst){
graphSystInterRel = CalculateRelErrUpAsymmGraph( graphFinalEnergyIntSyst, Form("relativeSystInterError_%s_%s_%s%s", modeName.Data(), meson.Data(), finalEnergy.Data(), addLabel.Data()));
nErrors++;
}
TCanvas* canvasRelErr = new TCanvas("canvasRelErr","",200,10,1350,900); // gives the page size
DrawGammaCanvasSettings( canvasRelErr, 0.08, 0.015, 0.02, 0.09);
// canvasRelErr->SetLogx();
TH2F * histo2DRelErr;
histo2DRelErr = new TH2F("histo2DRelErr","histo2DRelErr", 11000, 0.,
graphFinalEnergyStat->GetX()[graphFinalEnergyStat->GetN()-1]+ graphFinalEnergyStat->GetEXhigh()[graphFinalEnergyStat->GetN()-1], 1000, 0, 40.5);
SetStyleHistoTH2ForGraphs(histo2DRelErr, "#it{p}_{T} (GeV/#it{c})","Error (%)",0.035,0.04, 0.035,0.04, 1.,1.);
histo2DRelErr->Draw("copy");
TLegend* legendRelErr = GetAndSetLegend2(0.1, 0.94-(0.035*nErrors), 0.3, 0.94, 32);
DrawGammaSetMarkerTGraph(graphStatRel, 20, 1.4, kRed+2, kRed+2);
graphStatRel->Draw("p,same,z");
legendRelErr->AddEntry(graphStatRel,"stat Err","p");
DrawGammaSetMarkerTGraph(graphSystUncorrRel, 21, 1.4, kBlue+2, kBlue+2);
graphSystUncorrRel->Draw("p,same,z");
legendRelErr->AddEntry(graphSystUncorrRel,"uncorr syst Err","p");
DrawGammaSetMarkerTGraph(graphSystFullRel, 24, 1.4, kGreen+2, kGreen+2);
graphSystFullRel->Draw("p,same,z");
legendRelErr->AddEntry(graphSystFullRel,"full syst Err","p");
if (graphSystInterRel){
DrawGammaSetMarkerTGraph(graphSystInterRel, 25, 1.4, 807, 807);
graphSystInterRel->Draw("p,same,z,c");
legendRelErr->AddEntry(graphSystInterRel,"interpolation syst Err","p");
}
legendRelErr->Draw();