As you can see, I set the error with SetBinError in my custom function and read it with GetBinError immediately after that, and they are surprisingly different.
void DirectlyAdd(TProfile* prof, TProfile* prof1, TProfile* prof2, const char* choice) {
//prof->Sumw2();
if (choice == "+") {
for (int bin = 1; bin <= prof1->GetNbinsX(); bin++) {
double value1 = prof1->GetBinContent(bin);
double value2 = prof2->GetBinContent(bin);
prof->Fill(prof1->GetBinCenter(bin), value1 + value2);
}
} else if (choice == "-") {
for (int bin = 1; bin <= prof1->GetNbinsX(); bin++) {
double value1 = prof1->GetBinContent(bin);
double value2 = prof2->GetBinContent(bin);
prof->Fill(prof1->GetBinCenter(bin), value1 - value2);
}
} else {
cout << "Please choose correct operator type: + or -" << endl;
}
for (int bin = 1; bin <= prof1->GetNbinsX(); bin++) {
double error1 = prof1->GetBinError(bin);
double error2 = prof2->GetBinError(bin);
const double Error = TMath::Sqrt(error1 * error1 + error2 * error2);
prof->SetBinError(bin, Error);
cout<<"error1: "<<error1<<" , "<<"error2: "<<error2<<" , "<<"Error theory1: "<<Error<<" , "<<"Error set: "<<prof->GetBinError(bin)<<endl;
}
}
Here are some of the outputs:
error1: 0.000180288 , error2: 9.53529e-05 , Error theory1: 0.000203951 , Error set: 0.000203623
error1: 0.000179972 , error2: 9.52053e-05 , Error theory1: 0.000203603 , Error set: 0.000203026
error1: 0.000179682 , error2: 9.50576e-05 , Error theory1: 0.000203277 , Error set: 0.000149299
error1: 0.00017947 , error2: 9.4921e-05 , Error theory1: 0.000203026 , Error set: 0.000129671
error1: 0.000179197 , error2: 9.47892e-05 , Error theory1: 0.000202723 , Error set: 0.000198568
error1: 0.000178895 , error2: 9.46458e-05 , Error theory1: 0.000202388 , Error set: 0.000183426
error1: 0.000178722 , error2: 9.45217e-05 , Error theory1: 0.000202178 , Error set: 0.000174146
error1: 0.000178543 , error2: 9.4421e-05 , Error theory1: 0.000201972 , Error set: 0.000195398
error1: 0.000178271 , error2: 9.42926e-05 , Error theory1: 0.000201672 , Error set: 2.57332e-05
error1: 0.000178117 , error2: 9.4196e-05 , Error theory1: 0.00020149 , Error set: 4.60081e-05
error1: 0.000177876 , error2: 9.40846e-05 , Error theory1: 0.000201226 , Error set: 7.52386e-05
error1: 0.000177716 , error2: 9.39796e-05 , Error theory1: 0.000201035 , Error set: 0.000141463
error1: 0.000177549 , error2: 9.38896e-05 , Error theory1: 0.000200845 , Error set: 0.000115294
error1: 0.000177326 , error2: 9.37938e-05 , Error theory1: 0.000200604 , Error set: 0.000176073
error1: 0.00017722 , error2: 9.37162e-05 , Error theory1: 0.000200474 , Error set: 0.000128674
error1: 0.000177058 , error2: 9.36299e-05 , Error theory1: 0.00020029 , Error set: 0.000347946
error1: 0.000176824 , error2: 9.35237e-05 , Error theory1: 0.000200034 , Error set: 8.87428e-05
error1: 0.000176775 , error2: 9.34838e-05 , Error theory1: 0.000199971 , Error set: 0.00033488
error1: 0.000176602 , error2: 9.34058e-05 , Error theory1: 0.000199782 , Error set: 0.000137488
error1: 0.0001765 , error2: 9.33391e-05 , Error theory1: 0.000199661 , Error set: 0.000138535
error1: 0.000176403 , error2: 9.32862e-05 , Error theory1: 0.00019955 , Error set: 0.000157256
error1: 0.000176261 , error2: 9.32243e-05 , Error theory1: 0.000199396 , Error set: 0.000167283
error1: 0.000176208 , error2: 9.31771e-05 , Error theory1: 0.000199327 , Error set: 0.000198607
error1: 0.00017611 , error2: 9.31416e-05 , Error theory1: 0.000199224 , Error set: 0.000166912
error1: 0.000176061 , error2: 9.31119e-05 , Error theory1: 0.000199167 , Error set: 7.92794e-05