HistoCollector3D.cxx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. #include "HistoCollector3D.h"
  2. //_________________
  3. HistoCollector3D::HistoCollector3D() {
  4. mFile = NULL;
  5. mQinvBins = 40;
  6. mQinvLo = 0.;
  7. mQinvHi = 0.4;
  8. if(!h3DNum.empty()) {
  9. h3DNum.clear();
  10. }
  11. if(!h3DDen.empty()) {
  12. h3DDen.clear();
  13. }
  14. if(!h3DQinv.empty()) {
  15. h3DQinv.clear();
  16. }
  17. mPartType = 4; //3-pions, 4-kaons
  18. mKtBins = 11;
  19. }
  20. //_________________
  21. HistoCollector3D::~HistoCollector3D() {
  22. mFile->Close();
  23. delete mFile;
  24. }
  25. //_________________
  26. void HistoCollector3D::OpenFile() {
  27. std::cout << "Opening file: " << mFileName;
  28. mFile = TFile::Open(mFileName);
  29. if(mFile) {
  30. std::cout << "\t [DONE]" << std::endl;
  31. }
  32. else {
  33. std::cout << "\t [ERROR] file does not exist" << std::endl;
  34. }
  35. }
  36. //_________________
  37. void HistoCollector3D::LoadData() {
  38. OpenFile();
  39. ReadHistograms();
  40. }
  41. //_________________
  42. void HistoCollector3D::ReadHistograms() {
  43. std::cout << "Retrieving histograms from file...";
  44. TH3F *hNumer = NULL;
  45. TH3F *hDenom = NULL;
  46. TH3F *hQinv = NULL;
  47. for(int iCharge=0; iCharge<2; iCharge++) {
  48. for(int iKt=0; iKt<mKtBins; iKt++) {
  49. if(mPartType == 4) { //Kaons
  50. //Numerator
  51. hNumer = (TH3F*)mFile->Get(Form("hKaonBPLCMSFrameKtCF_%d_Num_bin_%d",
  52. iCharge,iKt));
  53. hNumer->SetName(Form("hKaonKtCFNum_%d_%d,",iCharge,iKt));
  54. //Denominator
  55. hDenom = (TH3F*)mFile->Get(Form("hKaonBPLCMSFrameKtCF_%d_Den_bin_%d",
  56. iCharge,iKt));
  57. hDenom->SetName(Form("hKaonKtCFDen_%d_%d,",iCharge,iKt));
  58. //Qinv weight
  59. hQinv = (TH3F*)mFile->Get(Form("hKaonBPLCMSFrameKtCF_%d_Qinv_bin_%d",
  60. iCharge,iKt));
  61. hQinv->SetName(Form("hKaonKtCFQinv_%d_%d,",iCharge,iKt));
  62. //Add histograms to the vectors
  63. h3DNum.push_back(hNumer);
  64. h3DDen.push_back(hDenom);
  65. h3DQinv.push_back(hQinv);
  66. }
  67. if(mPartType == 3) { //Pions
  68. //Numerator
  69. hNumer = (TH3F*)mFile->Get(Form("hPionBPLCMSFrameKtCF_%d_Num_bin_%d",
  70. iCharge,iKt));
  71. hNumer->SetName(Form("hPionKtCFNum_%d_%d,",iCharge,iKt));
  72. //Denominator
  73. hDenom = (TH3F*)mFile->Get(Form("hPionBPLCMSFrameKtCF_%d_Den_bin_%d",
  74. iCharge,iKt));
  75. hDenom->SetName(Form("hPionKtCFDen_%d_%d,",iCharge,iKt));
  76. //Qinv weight
  77. hQinv = (TH3F*)mFile->Get(Form("hPionBPLCMSFrameKtCF_%d_Qinv_bin_%d",
  78. iCharge,iKt));
  79. hQinv->SetName(Form("hPionKtCFQinv_%d_%d,",iCharge,iKt));
  80. //Add histograms to the vectors
  81. h3DNum.push_back(hNumer);
  82. h3DDen.push_back(hDenom);
  83. h3DQinv.push_back(hQinv);
  84. }
  85. }
  86. }
  87. std::cout << "\t [DONE]" << std::endl;
  88. std::cout << Form("Number of histos in numerator: %d", h3DNum.size())
  89. << std::endl
  90. << Form("Number of histos in denominator: %d", h3DDen.size())
  91. << std::endl
  92. << Form("Number of histos in qinv: %d", h3DQinv.size())
  93. << std::endl;
  94. }
  95. //_________________
  96. TH3F* HistoCollector3D::BuildKt3DNum(int charge, int binLo, int binHi) {
  97. TString sName = "h";
  98. sName += "NumerKtCF_";
  99. sName += charge;
  100. sName += "_";
  101. sName += binLo;
  102. sName += "_";
  103. sName += binHi;
  104. TH3F *hNumSum = new TH3F(sName.Data(),sName.Data(),
  105. mQinvBins,mQinvLo,mQinvHi,
  106. mQinvBins,mQinvLo,mQinvHi,
  107. mQinvBins,mQinvLo,mQinvHi);
  108. hNumSum->Sumw2();
  109. if(charge<2) { //Positive or negative particles
  110. for(int iKt=binLo; iKt<=binHi; iKt++) {
  111. hNumSum->Add(h3DNum[charge*mKtBins + iKt]);
  112. }
  113. }
  114. else { //Sum of charges
  115. for(int iCharge=0; iCharge<2; iCharge++) {
  116. for(int iKt=binLo; iKt<=binHi; iKt++) {
  117. hNumSum->Add(h3DNum[iCharge*mKtBins + iKt]);
  118. }
  119. }
  120. }
  121. return hNumSum;
  122. }
  123. //_________________
  124. TH3F* HistoCollector3D::BuildKt3DDen(int charge, int binLo, int binHi) {
  125. TString sName = "h";
  126. sName += "DenomKtCF_";
  127. sName += charge;
  128. sName += "_";
  129. sName += binLo;
  130. sName += "_";
  131. sName += binHi;
  132. TH3F *hDenSum = new TH3F(sName.Data(),sName.Data(),
  133. mQinvBins,mQinvLo,mQinvHi,
  134. mQinvBins,mQinvLo,mQinvHi,
  135. mQinvBins,mQinvLo,mQinvHi);
  136. hDenSum->Sumw2();
  137. if(charge<2) { //Positive or negative particles
  138. for(int iKt=binLo; iKt<=binHi; iKt++) {
  139. hDenSum->Add(h3DDen[charge*mKtBins + iKt]);
  140. }
  141. }
  142. else { //Sum of charges
  143. for(int iCharge=0; iCharge<2; iCharge++) {
  144. for(int iKt=binLo; iKt<=binHi; iKt++) {
  145. hDenSum->Add(h3DDen[iCharge*mKtBins + iKt]);
  146. }
  147. }
  148. }
  149. return hDenSum;
  150. }
  151. //_________________
  152. TH3F* HistoCollector3D::BuildKt3DQinv(int charge, int binLo, int binHi) {
  153. TString sName = "h";
  154. sName += "QinvKtCF_";
  155. sName += charge;
  156. sName += "_";
  157. sName += binLo;
  158. sName += "_";
  159. sName += binHi;
  160. TH3F *hQinvSum = new TH3F(sName.Data(),sName.Data(),
  161. mQinvBins,mQinvLo,mQinvHi,
  162. mQinvBins,mQinvLo,mQinvHi,
  163. mQinvBins,mQinvLo,mQinvHi);
  164. hQinvSum->Sumw2();
  165. if(charge<2) { //Positive or negative particles
  166. for(int iKt=binLo; iKt<=binHi; iKt++) {
  167. hQinvSum->Add(h3DQinv[charge*mKtBins + iKt]);
  168. }
  169. }
  170. else { //Sum of charges
  171. for(int iCharge=0; iCharge<2; iCharge++) {
  172. for(int iKt=binLo; iKt<=binHi; iKt++) {
  173. hQinvSum->Add(h3DQinv[iCharge*mKtBins + iKt]);
  174. }
  175. }
  176. }
  177. return hQinvSum;
  178. }