calcRes.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #include <TMath.h>
  2. #include "../Utils/Funcs.cc"
  3. void calcRes(TString inName, TString outName)
  4. {
  5. TFile *fi = new TFile(inName.Data(),"read");
  6. // Input histograms
  7. TProfile *p_res2RXNEvsRXNW[3], *p_res3RXNEvsRXNW[3];
  8. TProfile *p_res2TPCEvsTPCW[4], *p_res3TPCEvsTPCW[4];
  9. TProfile *p_res2RXNEvsTPCM[3], *p_res3RXNEvsTPCM[3];
  10. TProfile *p_res2RXNWvsTPCM[3], *p_res3RXNWvsTPCM[3];
  11. for (int iGap=0; iGap<4; iGap++)
  12. {
  13. p_res2TPCEvsTPCW[iGap] = (TProfile*) fi->Get(Form("p_res2TPCEvsTPCW_gap%i",iGap));
  14. p_res3TPCEvsTPCW[iGap] = (TProfile*) fi->Get(Form("p_res3TPCEvsTPCW_gap%i",iGap));
  15. }
  16. for (int irxn=0; irxn<3; irxn++)
  17. {
  18. p_res2RXNEvsRXNW[irxn] = (TProfile*) fi->Get(Form("p_res2RXNEvsRXNW_%i",irxn));
  19. p_res3RXNEvsRXNW[irxn] = (TProfile*) fi->Get(Form("p_res3RXNEvsRXNW_%i",irxn));
  20. // p_res2RXNEvsTPCM[irxn] = (TProfile*) fi->Get(Form("p_res2RXNEvsTPCM_%i",irxn));
  21. // p_res3RXNEvsTPCM[irxn] = (TProfile*) fi->Get(Form("p_res3RXNEvsTPCM_%i",irxn));
  22. // p_res2RXNWvsTPCM[irxn] = (TProfile*) fi->Get(Form("p_res2RXNWvsTPCM_%i",irxn));
  23. // p_res3RXNWvsTPCM[irxn] = (TProfile*) fi->Get(Form("p_res3RXNWvsTPCM_%i",irxn));
  24. }
  25. // Output histograms
  26. TH1F *hres2TPC[4], *hres3TPC[4];
  27. TH1F *hres2RXN[3], *hres3RXN[3];
  28. TH1F *hres2RXNfull[3], *hres3RXNfull[3];
  29. for (int iGap=0; iGap<4; iGap++)
  30. {
  31. hres2TPC[iGap] = new TH1F(Form("hres2TPC_gap%i",iGap),Form("hres2TPC_gap%i",iGap),10,0,100);
  32. hres3TPC[iGap] = new TH1F(Form("hres3TPC_gap%i",iGap),Form("hres3TPC_gap%i",iGap),10,0,100);
  33. }
  34. for (int irxn=0; irxn<3; irxn++)
  35. {
  36. hres2RXN[irxn] = new TH1F(Form("hres2RXN_part%i",irxn),Form("hres2RXN_part%i",irxn),10,0,100);
  37. hres3RXN[irxn] = new TH1F(Form("hres3RXN_part%i",irxn),Form("hres3RXN_part%i",irxn),10,0,100);
  38. hres2RXNfull[irxn] = new TH1F(Form("hres2RXNfull_part%i",irxn),Form("hres2RXNfull_part%i",irxn),10,0,100);
  39. hres3RXNfull[irxn] = new TH1F(Form("hres3RXNfull_part%i",irxn),Form("hres3RXNfull_part%i",irxn),10,0,100);
  40. }
  41. // 2-sub TPC method
  42. Double_t res, res2;
  43. for (int iGap=0; iGap<4; iGap++)
  44. {
  45. for (int ibin = 0; ibin<hres2TPC[iGap]->GetNbinsX(); ibin++)
  46. {
  47. res2 = p_res2TPCEvsTPCW[iGap]->GetBinContent(ibin+1);
  48. if (res2 > 0) res = TMath::Sqrt(res2);
  49. hres2TPC[iGap]->SetBinContent(ibin+1,res);
  50. hres2TPC[iGap]->SetBinError(ibin+1,p_res2TPCEvsTPCW[iGap]->GetBinError(ibin+1));
  51. }
  52. for (int ibin = 0; ibin<hres3TPC[iGap]->GetNbinsX(); ibin++)
  53. {
  54. res2 = p_res3TPCEvsTPCW[iGap]->GetBinContent(ibin+1);
  55. if (res2 > 0) res = TMath::Sqrt(res2);
  56. hres3TPC[iGap]->SetBinContent(ibin+1,res);
  57. hres3TPC[iGap]->SetBinError(ibin+1,p_res3TPCEvsTPCW[iGap]->GetBinError(ibin+1));
  58. }
  59. }
  60. for (int irxn=0; irxn<3; irxn++)
  61. {
  62. for (int ibin = 0; ibin<hres2RXN[irxn]->GetNbinsX(); ibin++)
  63. {
  64. res2 = p_res2RXNEvsRXNW[irxn]->GetBinContent(ibin+1);
  65. if (res2 > 0) res = TMath::Sqrt(res2);
  66. hres2RXN[irxn]->SetBinContent(ibin+1,res);
  67. hres2RXN[irxn]->SetBinError(ibin+1,p_res2RXNEvsRXNW[irxn]->GetBinError(ibin+1));
  68. }
  69. for (int ibin = 0; ibin<hres3RXN[irxn]->GetNbinsX(); ibin++)
  70. {
  71. res2 = p_res3RXNEvsRXNW[irxn]->GetBinContent(ibin+1);
  72. if (res2 > 0) res = TMath::Sqrt(res2);
  73. hres3RXN[irxn]->SetBinContent(ibin+1,res);
  74. hres3RXN[irxn]->SetBinError(ibin+1,p_res3RXNEvsRXNW[irxn]->GetBinError(ibin+1));
  75. }
  76. }
  77. Double_t chi;
  78. for (int irxn=0; irxn<3; irxn++)
  79. {
  80. for (int ibin = 0; ibin<hres2RXNfull[irxn]->GetNbinsX(); ibin++)
  81. {
  82. res2 = p_res2RXNEvsRXNW[irxn]->GetBinContent(ibin+1);
  83. if (res2 > 0)
  84. {
  85. res = TMath::Sqrt(res2);
  86. chi = GetChi(res,1,50);
  87. chi *= TMath::Sqrt(2.);
  88. res = GetRes(chi,1);
  89. hres2RXNfull[irxn]->SetBinContent(ibin+1,res);
  90. hres2RXNfull[irxn]->SetBinError(ibin+1,p_res2RXNEvsRXNW[irxn]->GetBinError(ibin+1));
  91. }
  92. }
  93. for (int ibin = 0; ibin<hres3RXNfull[irxn]->GetNbinsX(); ibin++)
  94. {
  95. res2 = p_res3RXNEvsRXNW[irxn]->GetBinContent(ibin+1);
  96. if (res2 > 0)
  97. {
  98. res = TMath::Sqrt(res2);
  99. chi = GetChi(res,1,50);
  100. chi *= TMath::Sqrt(2.);
  101. res = GetRes(chi,1);
  102. hres3RXNfull[irxn]->SetBinContent(ibin+1,res);
  103. hres3RXNfull[irxn]->SetBinError(ibin+1,TMath::Sqrt(2)*p_res3RXNEvsRXNW[irxn]->GetBinError(ibin+1));
  104. }
  105. }
  106. }
  107. std::cout << " ResV2_Full <cosLR>" << std::endl;
  108. for (int ibin=0; ibin<hres2RXNfull[0]->GetNbinsX();ibin++)
  109. {
  110. std::cout << hres2RXNfull[0]->GetBinContent(ibin+1) << " " << p_res2RXNEvsRXNW[0]->GetBinContent(ibin+1) << std::endl;
  111. }
  112. TFile *fo = new TFile(outName.Data(),"recreate");
  113. fo->cd();
  114. for (int iGap=0; iGap<4; iGap++)
  115. {
  116. hres2TPC[iGap]->Write();
  117. hres3TPC[iGap]->Write();
  118. }
  119. for (int irxn=0; irxn<3; irxn++)
  120. {
  121. hres2RXN[irxn]->Write();
  122. hres3RXN[irxn]->Write();
  123. }
  124. for (int irxn=0; irxn<3; irxn++)
  125. {
  126. hres2RXNfull[irxn]->Write();
  127. hres3RXNfull[irxn]->Write();
  128. }
  129. fo->Close();
  130. }