HistoCollector1D.cxx 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. #include "HistoCollector1D.h"
  2. //_________________
  3. HistoCollector1D::HistoCollector1D() {
  4. mFile = NULL;
  5. mQinvBins = 40;
  6. mQinvLo = 0.;
  7. mQinvHi = 0.4;
  8. if(!hQinvNum.empty()) {
  9. hQinvNum.clear();
  10. }
  11. if(!hQinvDen.empty()) {
  12. hQinvDen.clear();
  13. }
  14. mCorrFctnColor = 1;
  15. mCorrFctnLineWidth = 2;
  16. mCorrFctnMarkerStyle = 20;
  17. mCorrFctnMarkerSize = 1.8;
  18. mPartType = 4; //3-pions, 4-kaons
  19. mCentBins = 9;
  20. mKtBins = 24;
  21. }
  22. //_________________
  23. HistoCollector1D::~HistoCollector1D() {
  24. mFile->Close();
  25. delete mFile;
  26. }
  27. //_________________
  28. void HistoCollector1D::OpenFile() {
  29. std::cout << "Opening file: " << mFileName;
  30. mFile = TFile::Open(mFileName);
  31. if(mFile) {
  32. std::cout << "\t [DONE]" << std::endl;
  33. }
  34. else {
  35. std::cout << "\t [ERROR] file does not exist" << std::endl;
  36. }
  37. }
  38. //_________________
  39. void HistoCollector1D::LoadData() {
  40. OpenFile();
  41. ReadHistograms();
  42. }
  43. //_________________
  44. void HistoCollector1D::SetHistoStyle(TH1* histo, int charge) {
  45. switch(charge) {
  46. case 0:
  47. mCorrFctnColor = 2; //Red
  48. break;
  49. case 1:
  50. mCorrFctnColor = 4; //Blue
  51. break;
  52. case 2:
  53. mCorrFctnColor = 1; //Black
  54. break;
  55. default:
  56. mCorrFctnColor = 6; //Magenta
  57. };
  58. histo->SetLineColor(mCorrFctnColor);
  59. histo->SetMarkerColor(mCorrFctnColor);
  60. histo->SetLineWidth(mCorrFctnLineWidth);
  61. histo->SetMarkerSize(mCorrFctnMarkerSize);
  62. histo->SetMarkerStyle(mCorrFctnMarkerStyle);
  63. }
  64. //_________________
  65. void HistoCollector1D::ReadHistograms() {
  66. std::cout << "Retrieving histograms from file...";
  67. for(int iCharge=0; iCharge<2; iCharge++) {
  68. for(int iCent=0; iCent<mCentBins; iCent++) {
  69. for(int iKt=0; iKt<mKtBins; iKt++) {
  70. if(mPartType == 4) { //Kaons
  71. TH1F *hNumer = (TH1F*)mFile->Get(Form("hKaonQinvMixKt_%d_%d_Num_bin_%d",
  72. iCharge,iCent,iKt));
  73. TH1F *hDenom = (TH1F*)mFile->Get(Form("hKaonQinvMixKt_%d_%d_Den_bin_%d",
  74. iCharge,iCent,iKt));
  75. hQinvNum.push_back(hNumer);
  76. hQinvDen.push_back(hDenom);
  77. }
  78. if(mPartType == 3) { //Pions
  79. TH1F *hNumer = (TH1F*)mFile->Get(Form("hPionQinvMixKt_%d_%d_Num_bin_%d",
  80. iCharge,iCent,iKt));
  81. TH1F *hDenom = (TH1F*)mFile->Get(Form("hPionQinvMixKt_%d_%d_Den_bin_%d",
  82. iCharge,iCent,iKt));
  83. hQinvNum.push_back(hNumer);
  84. hQinvDen.push_back(hDenom);
  85. }
  86. }
  87. }
  88. }
  89. std::cout << "\t [DONE]" << std::endl;
  90. std::cout << Form("Number of histos in numerator: %d", hQinvNum.size())
  91. << std::endl
  92. << Form("Number of histos in denominator: %d", hQinvDen.size())
  93. << std::endl;
  94. }
  95. //_________________
  96. TH1F* HistoCollector1D::BuildCentCF(int charge, int binLo, int binHi) {
  97. TH1F *hNumSum = new TH1F("hNumSum","",mQinvBins, mQinvLo, mQinvHi);
  98. TH1F *hDenSum = new TH1F("hDenSum","",mQinvBins, mQinvLo, mQinvHi);
  99. TH1F *hRatio;
  100. hNumSum->Sumw2();
  101. hDenSum->Sumw2();
  102. TString sName = "h";
  103. sName += "CentCF_";
  104. sName += charge;
  105. sName += "_";
  106. sName += binLo;
  107. sName += "_";
  108. sName += binHi;
  109. hRatio = new TH1F(sName.Data(),"",mQinvBins,mQinvLo,mQinvHi);
  110. hRatio->Sumw2();
  111. if(charge<2) { //Positive or negative particles
  112. for(int iCent=binLo; iCent<=binHi; iCent++) {
  113. for(int iKt=0; iKt<mKtBins; iKt++) {
  114. hNumSum->Add(hQinvNum[charge*mCentBins*mKtBins + iCent*mKtBins + iKt]);
  115. hDenSum->Add(hQinvDen[charge*mCentBins*mKtBins + iCent*mKtBins + iKt]);
  116. }
  117. }
  118. }
  119. else { //Sum of charges
  120. for(int iCharge=0; iCharge<2; iCharge++) {
  121. for(int iCent=binLo; iCent<=binHi; iCent++) {
  122. for(int iKt=0; iKt<mKtBins; iKt++) {
  123. hNumSum->Add(hQinvNum[iCharge*mCentBins*mKtBins + iCent*mKtBins + iKt]);
  124. hDenSum->Add(hQinvDen[iCharge*mCentBins*mKtBins + iCent*mKtBins + iKt]);
  125. }
  126. }
  127. }
  128. }
  129. MakeCorrFctn1D(hRatio, hNumSum, hDenSum);
  130. delete hNumSum;
  131. delete hDenSum;
  132. SetHistoStyle(hRatio,charge);
  133. return hRatio;
  134. }
  135. //_________________
  136. TH1F* HistoCollector1D::BuildCentKtCF(int charge, int centBinLo, int centBinHi,
  137. int ktBinLo, int ktBinHi) {
  138. TH1F *hNumSum = new TH1F("hNumSum","",mQinvBins, mQinvLo, mQinvHi);
  139. TH1F *hDenSum = new TH1F("hDenSum","",mQinvBins, mQinvLo, mQinvHi);
  140. TH1F *hRatio;
  141. TString sName = "h";
  142. sName += "CentKtCF_";
  143. sName += charge;
  144. sName += "_";
  145. sName += centBinLo;
  146. sName += "_";
  147. sName += centBinHi;
  148. sName += "_";
  149. sName += ktBinLo;
  150. sName += "_";
  151. sName += ktBinHi;
  152. hRatio = new TH1F(sName.Data(),"",mQinvBins,mQinvLo,mQinvHi);
  153. if(charge<2) { //Positive or negative charge
  154. for(Int_t iCent=centBinLo; iCent<=centBinHi; iCent++) {
  155. for(Int_t iKt=ktBinLo; iKt<=ktBinHi; iKt++) {
  156. hNumSum->Add(hQinvNum[charge*mCentBins*mKtBins+iCent*mKtBins+iKt]);
  157. hDenSum->Add(hQinvDen[charge*mCentBins*mKtBins+iCent*mKtBins+iKt]);
  158. }
  159. }
  160. }
  161. else { //Sum of charges
  162. for(Int_t iCharge=0; iCharge<2; iCharge++) {
  163. for(Int_t iCent=centBinLo; iCent<=centBinHi; iCent++) {
  164. for(Int_t iKt=ktBinLo; iKt<=ktBinHi; iKt++) {
  165. hNumSum->Add(hQinvNum[iCharge*mCentBins*mKtBins+iCent*mKtBins+iKt]);
  166. hDenSum->Add(hQinvDen[iCharge*mCentBins*mKtBins+iCent*mKtBins+iKt]);
  167. }
  168. }
  169. }
  170. }
  171. MakeCorrFctn1D(hRatio,hNumSum,hDenSum);
  172. delete hNumSum;
  173. delete hDenSum;
  174. SetHistoStyle(hRatio,charge);
  175. return hRatio;
  176. }
  177. //_________________
  178. void HistoCollector1D::NormalizeQinv(TH1 *h) {
  179. Int_t mNbins = h->GetNbinsX();
  180. Int_t mHNbins = mNbins/2;
  181. Double_t scale = h->Integral(1, mNbins);
  182. scale -= h->Integral(1, mHNbins);
  183. h->Scale(1./scale);
  184. }
  185. //_________________
  186. void HistoCollector1D::MakeCorrFctn1D(TH1* hRat, TH1* hNum, TH1* hDen) {
  187. NormalizeQinv(hNum);
  188. NormalizeQinv(hDen);
  189. hRat->Divide(hNum,hDen);
  190. }
  191. //_________________
  192. TH1F* HistoCollector1D::BuildNumerCentKtCF(int charge, int centBinLo, int centBinHi,
  193. int ktBinLo, int ktBinHi) {
  194. TString sName = "h";
  195. sName += "NumCentKtCF_";
  196. sName += charge;
  197. sName += "_";
  198. sName += centBinLo;
  199. sName += "_";
  200. sName += centBinHi;
  201. sName += "_";
  202. sName += ktBinLo;
  203. sName += "_";
  204. sName += ktBinHi;
  205. TH1F *hNumSum = new TH1F("hNumSum","",mQinvBins, mQinvLo, mQinvHi);
  206. hNumSum->SetNameTitle(sName.Data(),sName.Data());
  207. if(charge<2) { //Positive or negative charge
  208. for(Int_t iCent=centBinLo; iCent<=centBinHi; iCent++) {
  209. for(Int_t iKt=ktBinLo; iKt<=ktBinHi; iKt++) {
  210. hNumSum->Add(hQinvNum[charge*mCentBins*mKtBins+iCent*mKtBins+iKt]);
  211. }
  212. }
  213. }
  214. else { //Sum of charges
  215. for(Int_t iCharge=0; iCharge<2; iCharge++) {
  216. for(Int_t iCent=centBinLo; iCent<=centBinHi; iCent++) {
  217. for(Int_t iKt=ktBinLo; iKt<=ktBinHi; iKt++) {
  218. hNumSum->Add(hQinvNum[iCharge*mCentBins*mKtBins+iCent*mKtBins+iKt]);
  219. }
  220. }
  221. }
  222. }
  223. return hNumSum;
  224. }
  225. //_________________
  226. TH1F* HistoCollector1D::BuildDenomCentKtCF(int charge, int centBinLo, int centBinHi,
  227. int ktBinLo, int ktBinHi) {
  228. TString sName = "h";
  229. sName += "DenCentKtCF_";
  230. sName += charge;
  231. sName += "_";
  232. sName += centBinLo;
  233. sName += "_";
  234. sName += centBinHi;
  235. sName += "_";
  236. sName += ktBinLo;
  237. sName += "_";
  238. sName += ktBinHi;
  239. TH1F *hDenSum = new TH1F("hDenSum","",mQinvBins, mQinvLo, mQinvHi);
  240. hDenSum->SetNameTitle(sName.Data(),sName.Data());
  241. if(charge<2) { //Positive or negative charge
  242. for(Int_t iCent=centBinLo; iCent<=centBinHi; iCent++) {
  243. for(Int_t iKt=ktBinLo; iKt<=ktBinHi; iKt++) {
  244. hDenSum->Add(hQinvDen[charge*mCentBins*mKtBins+iCent*mKtBins+iKt]);
  245. }
  246. }
  247. }
  248. else { //Sum of charges
  249. for(Int_t iCharge=0; iCharge<2; iCharge++) {
  250. for(Int_t iCent=centBinLo; iCent<=centBinHi; iCent++) {
  251. for(Int_t iKt=ktBinLo; iKt<=ktBinHi; iKt++) {
  252. hDenSum->Add(hQinvDen[iCharge*mCentBins*mKtBins+iCent*mKtBins+iKt]);
  253. }
  254. }
  255. }
  256. }
  257. return hDenSum;
  258. }