-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreateReducedSystematicsFile.C
180 lines (164 loc) · 6.59 KB
/
CreateReducedSystematicsFile.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
/****************************************************************************************************************************
****** provided by Gamma Conversion Group, PWGGA, *****
****** Daniel Mühlheim, [email protected] *****
*****************************************************************************************************************************/
#include <TString.h>
#include <TObject.h>
#include <TH1.h>
#include <TH2.h>
#include <TPad.h>
#include <TCanvas.h>
#include <TGraph.h>
#include <TGraphErrors.h>
#include <TGraphAsymmErrors.h>
#include <TGaxis.h>
#include <TLegend.h>
#include <TFrame.h>
#include <TSystem.h>
#include <TStyle.h>
#include <TLatex.h>
#include <TF1.h>
#include <TASImage.h>
#include <TMarker.h>
#include <TDatime.h>
#include <TArrow.h>
#include <TROOT.h>
#include <TObjString.h>
#include <TFile.h>
#include "TMath.h"
#include <Riostream.h>
#include <string>
#include <sstream>
#include <fstream>
#include <stdlib.h>
#include <fstream>
#include <math.h>
#include "CommonHeaders/PlottingGammaConversionHistos.h"
#include "CommonHeaders/PlottingGammaConversionAdditional.h"
#include "CommonHeaders/ConversionFunctionsBasicsAndLabeling.h"
using namespace std;
Int_t GetPosInVec( std::vector<TString> vec, TString lookup){
for(Int_t i=0; i<(Int_t)vec.size(); i++){
if(vec.at(i).CompareTo(lookup) == 0) return i;
}
cout << "ERROR in GetPosInVec, did not find '" << lookup.Data() << "'" << endl;
return -1;
}
void CreateReducedSystematicsFile( TString inputfileName = "",
TString fileNameWithErrorsToBeUsed = "",
Int_t nBinsPt = 0,
TString appendToSysName = "",
TString addUncName = "",
Double_t addPtIndUnc = -1
){
vector<TString> sysTaken;
vector<Double_t> fractionTaken;
ifstream fileSysNames(fileNameWithErrorsToBeUsed.Data());
string ll;
while (getline(fileSysNames,ll)){
istringstream lll(ll);
TString temp = "";
TString temp2 = "";
lll >> temp >> temp2;
Double_t fraction = 1;
if (temp2.CompareTo("") != 0){
fraction = (Double_t)temp2.Atof();
}
sysTaken.push_back(temp);
fractionTaken.push_back(fraction);
if( temp.IsNull() )
break;
cout << temp.Data() << "\t"<< temp2.Data()<< "\t" << fraction << endl;
}
vector<TString> ptSys[nBinsPt+1];
vector<Double_t> isTaken;
ifstream fileInput(inputfileName.Data());
Int_t iPt = 0;
string line;
while (getline(fileInput, line) && iPt < 100) {
istringstream ss(line);
TString temp = "";
TString tempBin = "";
Int_t iESource = 0;
cout << "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << endl;
cout << "\t*** reading line " << iPt << " ***" << endl;
while(ss && iESource < 100){
ss >> temp;
if(iPt > 0 && iESource == 0){
tempBin = temp;
if( tempBin.IsNull() ){
cout << "INFO: skipping pT " << tempBin.Atof() << endl;
break;
}
}
if( !(iPt==0 && temp.CompareTo("bin")==0) && !temp.IsNull() && iPt < (nBinsPt+1)){
ptSys[iPt].push_back(temp);
cout << temp.Data() << ", ";
Double_t valid = 0.;
if (iESource == 0){
valid = kTRUE;
} else {
for (Int_t so = 0; so < (Int_t)sysTaken.size(); so++){
if (temp.CompareTo(sysTaken.at(so)) == 0)
valid = fractionTaken.at(so);
}
}
isTaken.push_back(valid);
iESource++;
}
}
if(iPt == 0){
ptSys[iPt++].push_back("TotalError");
cout << "TotalError";
isTaken.push_back(0.);
iESource++;
} else if(!tempBin.IsNull() )
iPt++;
cout << "\n\t***" << iESource << " columns read ***" << endl;
cout << "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n" << endl;
}
TObjArray *tempArr = inputfileName.Tokenize(".");
TString outputfileName = (TString)((TObjString*)tempArr->At(0))->GetString()+"_red."+(TString)((TObjString*)tempArr->At(1))->GetString();
TString outputfileName2 = (TString)((TObjString*)tempArr->At(0))->GetString()+"_redSimple."+(TString)((TObjString*)tempArr->At(1))->GetString();
cout << "writing reduced file to " << outputfileName.Data() << " and "<< outputfileName2.Data() << endl;
fstream fCorr;
fstream fCorr2;
fCorr.open(outputfileName.Data(), ios::out);
fCorr2.open(outputfileName2.Data(), ios::out);
for (Int_t cPt = 0; cPt < nBinsPt+1; cPt++){
fCorr << ptSys[cPt].at(0) ;
if (cPt == 0) fCorr << " bin";
fCorr << "\t" ;
if (cPt != 0) fCorr2 << ptSys[cPt].at(0) << "\t";
Double_t sysErrTot = 0;
for (Int_t source = 1; source< (Int_t)ptSys[cPt].size(); source++){
if (isTaken.at(source) > 0.){
cout << source << "\t" << "needs to be multiplied with: " << isTaken.at(source) << endl;
if (cPt == 0)
fCorr << ptSys[cPt].at(source)<< appendToSysName.Data() << "\t";
else
fCorr << isTaken.at(source)*((TString)ptSys[cPt].at(source)).Atof() << "\t";
sysErrTot = sysErrTot+ isTaken.at(source)*isTaken.at(source)*((TString)ptSys[cPt].at(source)).Atof()*((TString)ptSys[cPt].at(source)).Atof();
}
}
if (addUncName.CompareTo("")){
if (cPt == 0){
fCorr << addUncName.Data()<< appendToSysName.Data() << "\t";
} else {
fCorr << addPtIndUnc << "\t";
sysErrTot = sysErrTot+addPtIndUnc*addPtIndUnc;
}
}
if (cPt == 0){
fCorr << "TotalErrorUncorr";
fCorr2 << "TotalErrorUncorr";
} else {
fCorr << TMath::Sqrt(sysErrTot) ;
fCorr2 << TMath::Sqrt(sysErrTot) ;
}
fCorr << endl;
fCorr2 << endl;
}
fCorr.close();
fCorr2.close();
}