Angular analysis of B+->K*+(K+pi0)mumu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3684 lines
177 KiB

  1. //compare MC and data of BDT variables for B+->Kst+mumu
  2. //david gerick
  3. //Renata Kopecna
  4. #include "../GlobalFunctions.hh"
  5. #include "../nTrackWeights.cpp"
  6. #include "../LHCbStyle.h"
  7. //#include "MVA_b2kmm.cc"
  8. using namespace std;
  9. using namespace RooFit ;
  10. #include <algorithm> // std::max, min
  11. //////////////////////////////////////////////////////
  12. /// compareVariables()
  13. /// compute and plot a desired variable for given year and subdecay channel
  14. /// choose weither it is sWeighted, not weighted, weighted by nTracks or 2 * 1D reweighted by
  15. /// nTracks and B_plus_PT. The data sample can be sweighted, so the weighting
  16. /// only concerns the MC sample.
  17. /// Choose, weither to print the plots to pdf and root files.
  18. /// variables can be plotted in log(var) or log(1 - var), using the according booleans
  19. ///
  20. /// compareAll***()
  21. /// compare all variables given in the function and save the plots
  22. ///
  23. /// compareTrackMultiplicities()
  24. /// compare the distribution of different track types between Run I and Run II
  25. /// use sWeights and normalize the samples!
  26. ///
  27. /// compareAnglesInPHSP()
  28. /// see the effects of re-weighting of PHSP MC on the angular distributions
  29. ///
  30. /// compareAnglesInMC()
  31. /// see the effects of re-weighting of MC on the angular distributions
  32. ///
  33. /// compareAnglesInPHSPbeforeAndAfterBDTcut()
  34. /// see the effect of the BDT cut on the angular distributions of PHSP MC
  35. ///
  36. ///
  37. const bool CutInQ2 = false;
  38. double minQ2 = 15.0;
  39. double maxQ2 = 100.0;
  40. const bool CutInMuPt = false;
  41. double minPT = 1100.0; //2500
  42. double maxPT = 2500.0; //10000
  43. const bool separateCharge = false;
  44. bool plusCharge = false;
  45. int evalOperation(bool useTwoVars = false, int x = 0, int y = 0, std::string operation = "plus",bool bLogVar = false, bool bLog1minusVar = false){
  46. if (bLogVar){
  47. x = log(x);
  48. y = log(y);
  49. }
  50. else if (bLog1minusVar){
  51. x = log(1-x);
  52. y = log(1-y);
  53. }
  54. if (!useTwoVars) return x;
  55. if (operation == "max") return max(x,y);
  56. else if (operation == "min") return min(x,y);
  57. else if (operation == "abs") return abs(x-y);
  58. else if (operation == "plus") return x+y;
  59. else if (operation == "minus") return x-y;
  60. else{
  61. coutERROR("Wrong opetaion specified, returning 0!");
  62. return 0;
  63. }
  64. }
  65. double evalOperation(bool useTwoVars = false, double x = 0.0, double y = 0.0, std::string operation = "plus",bool bLogVar = false, bool bLog1minusVar = false){
  66. if (bLogVar){
  67. x = log(x);
  68. y = log(y);
  69. }
  70. else if (bLog1minusVar){
  71. x = log(1-x);
  72. y = log(1-y);
  73. }
  74. if (!useTwoVars) return x;
  75. if (operation == "max") return max(x,y);
  76. else if (operation == "min") return min(x,y);
  77. else if (operation == "abs") return abs(x-y);
  78. else if (operation == "plus") return x+y;
  79. else if (operation == "minus") return x-y;
  80. else{
  81. coutERROR("Wrong opetaion specified, returning 0!");
  82. return 0.;
  83. }
  84. }
  85. int compareVariables(int year = 2011, std::string variable = "B_plus_PT", bool sWeight = true, bool bWeighted = true, bool b2Dweighted = true,
  86. bool bLogVar = false, bool bLog1minusVar = false, bool bPrint = true, bool KshortDecayInVelo = true, std::string weightBranch = "CB", bool useTwoVars = false, string operation = "", string variable2 = "" , string xAxis = "") {
  87. //if 2D weighted, set boolean for 1D weighting false
  88. if(b2Dweighted)bWeighted = false;
  89. //We don't use more than two variables; here are the option of what to do with the variables
  90. //Tried some fanc ystuff, was too complicated to quickly write
  91. // max(x,y)
  92. // min(x,y)
  93. //abs(x-y)
  94. //x-y
  95. //x+y
  96. //where x,y can be both in log if bLogVar is true
  97. gStyle -> SetOptStat(0);
  98. gROOT->SetBatch(kTRUE);
  99. LHCbStyle();
  100. //lhcbStyle->SetOptTitle(1);
  101. //lhcbStyle->SetTitleSize(0.1,"x");
  102. //lhcbStyle->SetTitleSize(0.1,"y");
  103. //lhcbStyle->SetTitleSize(0.1,"z");
  104. bool varIsInt = false;
  105. if(variable == "nTracks") varIsInt = true;
  106. if(variable == "nSPDHits") varIsInt = true;
  107. if(variable == "nLongTracks") varIsInt = true;
  108. if(variable == "nVeloTracks") varIsInt = true;
  109. if(variable == "nTTracks") varIsInt = true;
  110. if(variable == "nDownstreamTracks") varIsInt = true;
  111. if(variable == "nUpstreamTracks") varIsInt = true;
  112. if(variable == "nPV") varIsInt = true;
  113. bool varIsInt2 = false;
  114. if(variable2 == "nTracks") varIsInt2 = true;
  115. if(variable2 == "nSPDHits") varIsInt2 = true;
  116. if(variable2 == "nLongTracks") varIsInt2 = true;
  117. if(variable2 == "nVeloTracks") varIsInt2 = true;
  118. if(variable2 == "nTTracks") varIsInt2 = true;
  119. if(variable2 == "nDownstreamTracks") varIsInt2 = true;
  120. if(variable2 == "nUpstreamTracks") varIsInt2 = true;
  121. if(variable2 == "nPV") varIsInt2 = true;
  122. ///for now hardcoded, but might be possible to include in input parameters if comparison between data and reference MC is needed
  123. const bool ReferenceChannel = true;
  124. ///for writting only the ratio and superposition
  125. const bool minimumPlot = true;
  126. ///print the LHCb tag and the legend onto plots?
  127. const bool print_legend = true;
  128. if(bLogVar && bLog1minusVar){
  129. coutERROR( "Only Log( var ) or Log( 1 - var ) option possible, but both flags were set for variable: " + variable);
  130. if (useTwoVars) coutERROR(" and variable " + variable2);
  131. return 0;
  132. }
  133. //put both magnet polarities into one TChain
  134. TChain * treeData = new TChain("DecayTree");
  135. TChain * treeMC = new TChain("DecayTreeTruthMatched");
  136. // Kst2Kpluspi0Resolved case
  137. if(Kst2Kpluspi0Resolved){
  138. if(ReferenceChannel){
  139. treeData->Add(Form("%s/Tuples/Data/%i_RefKplusPi0Resolved_BDTinput.root", path_to_output_KplusPizero.c_str(), year));
  140. treeMC->Add(Form("%s/Tuples/MC/%i_RefKplusPi0Resolved_BDTinput.root", path_to_output_KplusPizero.c_str(), year > 2016 ? 2016 : year));
  141. }
  142. else{
  143. treeData->Add(Form("%s/Tuples/Data/%i_KplusPi0Resolved_BDTinput.root", path_to_output_KplusPizero.c_str(), year));
  144. treeMC->Add(Form("%s/Tuples/MC/%i_KplusPi0Resolved_BDTinput.root", path_to_output_KplusPizero.c_str(), year == 2015 ? 2016 : year));
  145. }
  146. }
  147. // Kst2Kpluspi0Merged case
  148. else if(Kst2Kpluspi0Merged){
  149. if(ReferenceChannel){
  150. treeData->Add(Form("%s/Tuples/Data/%i_RefKplusPi0Merged_BDTinput.root", path_to_output_KplusPizero.c_str(), year));
  151. treeMC->Add(Form("%s/Tuples/MC/%i_KplusPi0MergedRef_BDTinput.root", path_to_output_KplusPizero.c_str(), year));
  152. }
  153. else{
  154. treeData->Add(Form("%s/Tuples/Data/%i_KplusPi0Merged_BDTinput.root", path_to_output_KplusPizero.c_str(), year));
  155. treeMC->Add(Form("%s/Tuples/MC/%i_KplusPi0Merged_BDTinput.root", path_to_output_KplusPizero.c_str(), year));
  156. }
  157. }
  158. // Kst2Kspiplus case
  159. else if(Kst2Kspiplus){
  160. if(ReferenceChannel){
  161. treeData->Add(Form("%s/Tuples/Data/%i_KshortPiplus_BDTinputRef.root", path_to_output_KshortPiplus.c_str(), year));
  162. treeMC->Add(Form("%s/Tuples/MC/%i_RefKshortPiplusRef_BDTinput.root", path_to_output_KshortPiplus.c_str(), year));
  163. }
  164. else{
  165. if(AlwaysUseRefChannelData)
  166. treeData->Add(Form("%s/Tuples/Data/%i_RefKshortPiplus%s_BDTinput.root", path_to_output_KshortPiplus.c_str(), year, (SplitDDandLL ? (KshortDecayInVelo ? "_LL" : "_DD") : "")));
  167. else
  168. treeData->Add(Form("%s/Tuples/Data/%i_KshortPiplus%s_BDTinput.root", path_to_output_KshortPiplus.c_str(), year, (SplitDDandLL ? (KshortDecayInVelo ? "_LL" : "_DD") : "")));
  169. treeMC->Add(Form("%s/Tuples/MC/%i_KshortPiplus%s_BDTinput.root", path_to_output_KshortPiplus.c_str(), year, (SplitDDandLL ? (KshortDecayInVelo ? "_LL" : "_DD") : "")));
  170. }
  171. }
  172. //initialize canvas for printing
  173. // TCanvas * c1 = new TCanvas("c1", "raw distributions");
  174. string varName = variable;
  175. string drawFormula;
  176. string drawFormTmp = "";
  177. if(bLogVar) drawFormula = Form("log( %s )", variable.c_str());
  178. else if(bLog1minusVar) drawFormula = Form("log(1 - %s)", variable.c_str());
  179. else drawFormula = variable;
  180. if (useTwoVars){
  181. if(bLogVar) drawFormTmp = Form("log( %s )", variable2.c_str());
  182. else if(bLog1minusVar) drawFormTmp = Form("log(1 - %s)", variable2.c_str());
  183. else drawFormTmp = variable2;
  184. if (operation.find("max") != std::string::npos){
  185. varName = "max_" + variable + "_" + variable2 + "_";
  186. drawFormula = "max(" + drawFormula + "," + drawFormTmp + ")";
  187. operation = "max";
  188. }
  189. else if (operation.find("min") != std::string::npos) {
  190. varName = "min_" + variable + "_" + variable2 + "_";
  191. drawFormula = "min(" + drawFormula + "," + drawFormTmp + ")";
  192. operation = "min";
  193. }
  194. else if (operation.find("abs") != std::string::npos) {
  195. varName = "abs_" + variable + "_" + variable2 + "_";
  196. drawFormula = "abs(" + drawFormula + "-" + drawFormTmp + ")";
  197. operation = "abs";
  198. }
  199. else if (operation.find("plus") != std::string::npos) {
  200. varName = variable + "+" + variable2;
  201. drawFormula = drawFormula + "+" + drawFormTmp;
  202. operation = "plus";
  203. }
  204. else if (operation.find("minus") != std::string::npos) {
  205. varName = variable + "-" + variable2;
  206. drawFormula = drawFormula + "-" + drawFormTmp;
  207. operation = "minus";
  208. }
  209. else{
  210. coutERROR("Ivalid mathematical formula given: " + operation);
  211. return 0;
  212. }
  213. }
  214. std::string histName = Form("%i%s%s", year,(SplitDDandLL ? (KshortDecayInVelo ? "LL" : "DD") : ""),varName.c_str());
  215. cout << "[INFO]\t\tUsing name for histograms " << histName << endl;
  216. cout << "[INFO]\t\tUsing draw formula " << Form("%s>>%sData", drawFormula.c_str(),histName.c_str()) << endl;
  217. //data: initialize histograms into objects
  218. treeData->Draw(Form("%s>>%sData", drawFormula.c_str(),histName.c_str()), "");
  219. TH1 * hist0varData = (TH1*)gPad->GetPrimitive(Form("%sData",histName.c_str()));
  220. //MC: initialize histograms into objects
  221. treeMC ->Draw(Form("%s>>%sMC", drawFormula.c_str(),histName.c_str()), "");
  222. TH1D * hist0varMC = (TH1D*)gPad->GetPrimitive(Form("%sMC",histName.c_str()));
  223. //Get min and max of x-range from both histograms:
  224. int nBins;
  225. double BinContent;
  226. int nBinMin, nBinMax;
  227. float Min;
  228. float Max;
  229. if(variable == "nTracks" || variable == "nSPDHits"){
  230. nBins= 60;
  231. Min = -0.5;
  232. Max = 599.5;
  233. }
  234. else if(variable == "nLongTracks" || variable == "nVeloTracks" || variable == "nTTracks" || variable == "nBackTracks"|| variable == "nMuonTracks"){
  235. nBins = 50;
  236. Min = -0.5;
  237. Max = 149.5;
  238. }
  239. else if(variable == "nDownstreamTracks" || variable == "nUpstreamTracks"){
  240. nBins = 50;
  241. Min = -0.5;
  242. Max = 49.5;
  243. }
  244. else if(variable == "nPV"){
  245. nBins = 8;
  246. Min = 0.5;
  247. Max = 8.5;
  248. }
  249. else {
  250. //get number of bins of both histograms and select larger number for new histogram
  251. int nBinsData = hist0varData->GetXaxis()->GetNbins();
  252. int nBinsMC = hist0varMC->GetXaxis()->GetNbins();
  253. if(nBinsData >= nBinsMC)nBins = nBinsData;
  254. else nBins = nBinsMC;
  255. //data
  256. nBinMin = 0;
  257. BinContent = 0.0;
  258. while(BinContent == 0.0){
  259. nBinMin++;
  260. BinContent = hist0varData->GetBinContent(nBinMin);
  261. }
  262. float MinData = hist0varData->GetXaxis()->GetBinLowEdge(nBinMin);
  263. nBinMax = nBinsData + 1;
  264. BinContent = 0.0;
  265. while(BinContent == 0.0){
  266. nBinMax--;
  267. BinContent = hist0varData->GetBinContent(nBinMax);
  268. }
  269. float MaxData = hist0varData->GetXaxis()->GetBinUpEdge(nBinMax);
  270. //MC
  271. nBinMin = 0;
  272. BinContent = 0.0;
  273. while(BinContent == 0.0){
  274. nBinMin++;
  275. BinContent = hist0varMC->GetBinContent(nBinMin);
  276. }
  277. float MinMC = hist0varMC->GetXaxis()->GetBinLowEdge(nBinMin);
  278. nBinMax = nBinsData + 1;
  279. BinContent = 0.0;
  280. while(BinContent == 0.0){
  281. nBinMax--;
  282. BinContent = hist0varMC->GetBinContent(nBinMax);
  283. }
  284. float MaxMC = hist0varMC->GetXaxis()->GetBinUpEdge(nBinMax);
  285. std::cout << "Found hist0varData bins: " << nBinsData << " from " << MinData << " to " << MaxData << std::endl;
  286. std::cout << "Found hist0varMC bins: " << nBinsMC << " from " << MinMC << " to " << MaxMC << std::endl;
  287. if(MinData <= MinMC)Min = MinData;
  288. else Min = MinMC;
  289. if(MaxData >= MaxMC)Max = MaxData;
  290. else Max = MaxMC;
  291. nBins/=2;
  292. }
  293. //default axis lable is the variable name:
  294. std::string xaxistitle = (xAxis == "" ? drawFormula : xAxis);
  295. //use MVA loader to get nicely formated variable name and units
  296. //manual intervention for ranges on X-axis
  297. if(Kst2Kspiplus){
  298. //B+
  299. if(strcmp(variable.c_str(), "B_plus_DIRA_OWNPV") == 0)Min = -20.;
  300. else if(strcmp(variable.c_str(), "B_plus_OWNPV_CHI2") == 0)Min = 1.;
  301. else if(strcmp(variable.c_str(), "B_plus_FD_OWNPV") == 0)Max = 150.;
  302. else if(strcmp(variable.c_str(), (UseDTF ? "B_plus_PT_DTF" : "B_plus_PT")) == 0)Max = 40000.;
  303. else if(strcmp(variable.c_str(), "B_plus_DOCA1") == 0)Max = 1000.;
  304. else if(strcmp(variable.c_str(), "B_plus_IP_OWNPV") == 0)Max = 0.12;
  305. else if(strcmp(variable.c_str(), "B_plus_NEW_ConePTasym") == 0)Max = 1.001;
  306. else if(strcmp(variable.c_str(), "B_plus_NEW_ConePT") == 0)Max = 40000.;
  307. else if(strcmp(variable.c_str(), "B_plus_NEW_ConePasym") == 0)Max = 1.001;
  308. else if(strcmp(variable.c_str(), "B_plus_NEW_ConeP") == 0)Max = 60000.;
  309. else if(strcmp(variable.c_str(), UseDTF ? "B_plus_ETA_DTF" :"B_plus_ETA" ) == 0)Max = 5.;
  310. //K*
  311. else if(strcmp(variable.c_str(), "K_star_plus_IPCHI2_OWNPV") == 0){
  312. Min = -5.;
  313. Max = 10.;
  314. }
  315. else if(strcmp(variable.c_str(), (UseDTF ? "K_star_plus_PT_DTF" : "K_star_plus_PT")) == 0)Max = 20000.;
  316. else if(strcmp(variable.c_str(), UseDTF ? "K_star_plus_ETA_DTF" :"K_star_plus_ETA" ) == 0)Max = 5.;
  317. //Ks0
  318. else if(strcmp(variable.c_str(), (UseDTF ? "K_short_PT_DTF" : "K_short_PT")) == 0)Max = 10000.;
  319. else if(strcmp(variable.c_str(), "K_short_FD_OWNPV") == 0 && SplitDDandLL && !KshortDecayInVelo)Max = 2500.;
  320. else if(strcmp(variable.c_str(), "K_short_FD_OWNPV") == 0 && SplitDDandLL && KshortDecayInVelo)Max = 700.;
  321. //pi+- from Ks0
  322. else if(strcmp(variable.c_str(), (UseDTF ? "Ks_pi_minus_PT_DTF" : "Ks_pi_minus_PT")) == 0)Max = 10000.;
  323. else if(strcmp(variable.c_str(), (UseDTF ? "Ks_pi_plus_PT_DTF" : "Ks_pi_plus_PT")) == 0)Max = 10000.;
  324. //pi+
  325. else if(strcmp(variable.c_str(), (UseDTF ? "pi_plus_PT_DTF" : "pi_plus_PT")) == 0)Max = 12000.;
  326. else if(strcmp(variable.c_str(), (UseDTF ? "pi_plus_ETA_DTF" : "pi_plus_ETA")) == 0)Max = 5.;
  327. else if(strcmp(variable.c_str(), "nLongTracks") == 0)Max = 110;
  328. }
  329. else{//Kplus pi0 channels
  330. if (Kst2Kpluspi0Merged){
  331. //B+
  332. if (strcmp(variable.c_str(), "B_plus_DIRA_OWNPV") == 0)Min = -20.;
  333. else if (strcmp(variable.c_str(), "B_plus_OWNPV_CHI2") == 0)Min = 1.;
  334. else if (strcmp(variable.c_str(), "B_plus_FD_OWNPV") == 0)Max = 200.;
  335. else if (strcmp(variable.c_str(), (UseDTF ? "B_plus_PT_DTF" : "B_plus_PT")) == 0)Max = 60000.;
  336. else if (strcmp(variable.c_str(), "B_plus_DOCA1") == 0)Max = 1000.;
  337. else if (strcmp(variable.c_str(), "B_plus_IP_OWNPV") == 0)Max = 0.12;
  338. else if (strcmp(variable.c_str(), "B_plus_NEW_ConePTasym") == 0)Max = 1.001;
  339. else if(strcmp(variable.c_str(), UseDTF ? "B_plus_ETA_DTF" :"B_plus_ETA" ) == 0)Max = 5.;
  340. //K*
  341. else if (strcmp(variable.c_str(), (UseDTF ? "K_star_plus_PT_DTF" : "K_star_plus_PT_")) == 0)Max = 30000.;
  342. else if (strcmp(variable.c_str(), "K_star_plus_IPCHI2_OWNPV") == 0)Max = 60.;
  343. else if (strcmp(variable.c_str(), "K_star_plus_IPCHI2_OWNPV") == 0)Min = -10.;
  344. else if(strcmp(variable.c_str(), (UseDTF ? "K_star_plus_ETA_DTF" :"K_star_plus_ETA") ) == 0)Max = 5.;
  345. //K+
  346. else if (strcmp(variable.c_str(), "K_plus_IPCHI2_OWNPV") == 0)Max = 40000.;
  347. else if (strcmp(variable.c_str(), "K_plus_IPCHI2_OWNPV") == 0)Min = -5.;
  348. else if (strcmp(variable.c_str(), (UseDTF ? "K_plus_PT_DTF" : "K_plus_PT")) == 0)Max = 20000.;
  349. else if (strcmp(variable.c_str(), (UseDTF ? "K_plus_ETA_DTF" : "K_plus_ETA")) == 0)Max = 5.;
  350. //pi0
  351. else if (strcmp(variable.c_str(), "pi_zero_merged_ETA") == 0)Min = 1.;
  352. else if (strcmp(variable.c_str(), (UseDTF ? "pi_zero_merged_ETA_DTF" : "pi_zero_merged_ETA")) == 0)Max = 5.;
  353. }
  354. else if (Kst2Kpluspi0Resolved){
  355. //B+
  356. if (strcmp(variable.c_str(), "B_plus_DIRA_OWNPV") == 0)Min = -20.;
  357. else if (strcmp(variable.c_str(), "B_plus_OWNPV_CHI2") == 0)Min = 1.;
  358. else if (strcmp(variable.c_str(), "B_plus_FD_OWNPV") == 0)Max = 200.;
  359. else if (!bLogVar && strcmp(variable.c_str(), (UseDTF ? "B_plus_PT_DTF" : "B_plus_PT")) == 0)Max = 60000.;
  360. else if (strcmp(variable.c_str(), "B_plus_DOCA1") == 0)Max = 1000.;
  361. else if (strcmp(variable.c_str(), "B_plus_IP_OWNPV") == 0)Max = 0.12;
  362. else if (strcmp(variable.c_str(), "B_plus_NEW_ConePTasym") == 0)Max = 1.001;
  363. else if (strcmp(variable.c_str(), (UseDTF ? "B_plus_ETA_DTF" :"B_plus_ETA" )) == 0)Max = 5.;
  364. //K*
  365. else if (strcmp(variable.c_str(), (UseDTF ? "K_star_plus_PT_DTF" : "K_star_plus_PT")) == 0)Max = 30000.;
  366. else if (strcmp(variable.c_str(), "K_star_plus_IPCHI2_OWNPV") == 0)Max = 60.;
  367. else if (strcmp(variable.c_str(), "K_star_plus_IPCHI2_OWNPV") == 0)Min = -60.;
  368. else if (strcmp(variable.c_str(), UseDTF ? "K_star_plus_ETA_DTF" :"K_star_plus_ETA" ) == 0)Max = 5.;
  369. //K+
  370. else if (strcmp(variable.c_str(), "K_plus_IPCHI2_OWNPV") == 0)Max = 40000.;
  371. else if (strcmp(variable.c_str(), "K_plus_IPCHI2_OWNPV") == 0)Min = 0.;
  372. else if (!bLogVar && strcmp(variable.c_str(), (UseDTF ? "K_plus_PT_DTF" : "K_plus_PT")) == 0)Max = 20000.;
  373. else if (strcmp(variable.c_str(), (UseDTF ? "K_plus_ETA_DTF" : "K_plus_ETA")) == 0)Max = 5.;
  374. //pi0
  375. else if (strcmp(variable.c_str(), (UseDTF ? "pi_zero_resolved_ETA_DTF" : "pi_zero_resolved_ETA")) == 0)Max = 5.;
  376. //gamma PT
  377. else if (strcmp(variable.c_str(), (UseDTF ? "gamma1_PT_DTF" : "gamma1_PT")) == 0) Max = 8.;
  378. else if (strcmp(variable.c_str(), (UseDTF ? "gamma2_PT_DTF" : "gamma2_PT")) == 0) Max = 8.;
  379. //mu
  380. //else if (strcmp(variable.c_str(), "mu_minus_IPCHI2_OWNPV") == 0){ Min = 0.; Max = 20.; }
  381. //else if (strcmp(variable.c_str(), "mu_plus_IPCHI2_OWNPV") == 0){ Min = 0.; Max = 20.; }
  382. if (useTwoVars){
  383. if (operation == "abs" && variable=="pi_zero_resolved_ETA_DTF") Max = 1.5;
  384. }
  385. }
  386. }
  387. //create new histograms to fill data from tree by looping over tree
  388. //same number of bins and same range to be able to divide the histograms!
  389. hist0varData = new TH1D("hist0varData", Form("%s from data", histName.c_str()), nBins, Min, Max);
  390. hist0varMC = new TH1D("hist0varMC", Form("%s from MC", histName.c_str()), nBins, Min, Max);
  391. std::cout << "Created hist0varData bins: " << nBins << " from " << Min << " to " << Max << std::endl;
  392. std::cout << "Created hist0varMC bins: " << nBins << " from " << Min << " to " << Max << std::endl;
  393. //default type of variables is double, if variable is integer, add name to list in line 71
  394. double dVariable = 100., dVariable2 = 100.;
  395. int iVariable = 100, iVariable2 = 100;
  396. double dSWeights = 1., MCWeights = 1.;
  397. double Q2 = 0.;
  398. double mu_minus_PT = 0.;
  399. double mu_minus_PT_MC = 0.;
  400. int B_plus_ID = 0;
  401. int B_plus_ID_MC = 0;
  402. double dVariable_oppCharge = 100.;
  403. int iVariable_oppCharge = 100;
  404. int TM = false;
  405. int TM_gammas = false;
  406. std::string variable_charge = variable;
  407. bool varIsMu = false;
  408. bool varIsKsPi = false;
  409. if (separateCharge){
  410. if (variable.find("mu") != std::string::npos){
  411. if (!replace(variable_charge, "plus","minus")){
  412. replace(variable_charge, "minus","plus");
  413. plusCharge = false;
  414. }
  415. else plusCharge = true;
  416. varIsMu = true;
  417. }
  418. if (variable.find("Ks_pi") != std::string::npos){
  419. if (!replace(variable_charge, "plus","minus")){
  420. replace(variable_charge, "minus","plus");
  421. plusCharge = false;
  422. }
  423. else plusCharge = true;
  424. varIsKsPi = true;
  425. }
  426. //add a string variable_charge with mu_oppCharge_XY
  427. }
  428. //deactivate all branches exept the one/two of interest!
  429. treeData->SetBranchStatus("*",0);
  430. treeData->SetBranchStatus("mu_minus_PT",1);
  431. treeData->SetBranchStatus(variable.c_str(),1);
  432. if (useTwoVars)treeData->SetBranchStatus(variable2.c_str(),1);
  433. if (sWeight) treeData->SetBranchStatus("N_Bplus_sw",1);
  434. if (separateCharge){
  435. treeData->SetBranchStatus("B_plus_ID",1);
  436. }
  437. treeMC->SetBranchStatus("*",0);
  438. treeMC->SetBranchStatus("Q2",1);
  439. treeMC->SetBranchStatus("mu_minus_PT",1);
  440. treeMC->SetBranchStatus(variable.c_str(),1);
  441. treeMC->SetBranchStatus("TMed",1);
  442. treeMC->SetBranchStatus("TM_gammas",1);
  443. if (useTwoVars)treeMC->SetBranchStatus(variable2.c_str(),1);
  444. if (separateCharge){
  445. treeMC->SetBranchStatus("B_plus_ID",1);
  446. }
  447. if(bWeighted) treeMC ->SetBranchStatus(Form("weight_%s", weightBranch.c_str()),1);
  448. else if(b2Dweighted)treeMC ->SetBranchStatus(Form("weight2D_%s",weightBranch.c_str()),1);
  449. //Data
  450. std::cout << "Loading " << treeData->GetEntries() << " data events!" << std::endl;
  451. if(varIsInt)treeData -> SetBranchAddress( variable.c_str() , &iVariable );
  452. else treeData -> SetBranchAddress( variable.c_str() , &dVariable );
  453. if (useTwoVars){
  454. if(varIsInt2)treeData -> SetBranchAddress( variable2.c_str() , &iVariable2 );
  455. else treeData -> SetBranchAddress( variable2.c_str() , &dVariable2 );
  456. }
  457. if (sWeight) treeData -> SetBranchAddress( "N_Bplus_sw" , &dSWeights );
  458. if(CutInMuPt)
  459. treeData -> SetBranchAddress( "mu_minus_PT" , &mu_minus_PT );
  460. if (separateCharge){ //TODO
  461. treeData -> SetBranchAddress( "B_plus_ID" , &B_plus_ID );
  462. if (varIsMu || varIsKsPi){ //load muplus/muminus branch too
  463. treeData->SetBranchStatus(variable_charge.c_str(),1);
  464. if(varIsInt2) treeData->SetBranchAddress(variable_charge.c_str(), &iVariable_oppCharge);
  465. else treeData->SetBranchAddress(variable_charge.c_str(), &dVariable_oppCharge);
  466. }
  467. }
  468. for(int i = 0; i < treeData->GetEntries(); i++){
  469. if(i%10000==0 && i != 0)std::cout << "Loading data event " << i << " / " << treeData->GetEntries() << std::endl;
  470. treeData->GetEntry(i);
  471. if(CutInMuPt){
  472. if(mu_minus_PT > maxPT || mu_minus_PT < minPT){
  473. continue;
  474. }
  475. }
  476. if (separateCharge){ //doesn't work for two variables!!!
  477. if (varIsMu || varIsKsPi){
  478. if (plusCharge && B_plus_ID == -521){
  479. if(varIsInt) hist0varData->Fill( evalOperation(useTwoVars, iVariable_oppCharge,iVariable2,operation,bLogVar,bLog1minusVar), dSWeights);
  480. else hist0varData->Fill( evalOperation(useTwoVars,dVariable_oppCharge,dVariable2,operation,bLogVar,bLog1minusVar), dSWeights);
  481. continue;
  482. }
  483. if (!plusCharge && B_plus_ID == 521){
  484. if(varIsInt) hist0varData->Fill( evalOperation(useTwoVars, iVariable_oppCharge,iVariable2,operation,bLogVar,bLog1minusVar), dSWeights);
  485. else hist0varData->Fill( evalOperation(useTwoVars,dVariable_oppCharge,dVariable2,operation,bLogVar,bLog1minusVar), dSWeights);
  486. continue;
  487. }
  488. }
  489. else {
  490. if (plusCharge && B_plus_ID == -521) continue;
  491. if (!plusCharge && B_plus_ID == 521) continue;
  492. }
  493. }
  494. if(varIsInt) hist0varData->Fill( evalOperation(useTwoVars, iVariable,iVariable2,operation,bLogVar,bLog1minusVar), dSWeights);
  495. else hist0varData->Fill( evalOperation(useTwoVars,dVariable,dVariable2,operation,bLogVar,bLog1minusVar), dSWeights);
  496. }
  497. if (!sWeight) hist0varData->Sumw2(); //TODO: check
  498. if(hist0varData->GetEntries() == 0){
  499. std::cout << "No DATA events found" << std::endl;
  500. return 0;
  501. }
  502. if(hist0varData->Integral() == 0){
  503. std::cout << "No DATA events included in the pre-defined range!" << std::endl;
  504. return 0;
  505. }
  506. //MC
  507. std::cout << "Loading " << treeMC->GetEntries() << " MC events!" << std::endl;
  508. //TODO: is it smart to "re-set" branch adress to the same variable as in the data case?
  509. if(varIsInt)treeMC -> SetBranchAddress( variable.c_str() , &iVariable );
  510. else treeMC -> SetBranchAddress( variable.c_str() , &dVariable );
  511. if (useTwoVars){
  512. if(varIsInt2)treeMC -> SetBranchAddress( variable2.c_str() , &iVariable2 );
  513. else treeMC -> SetBranchAddress( variable2.c_str() , &dVariable2 );
  514. }
  515. if(bWeighted) treeMC -> SetBranchAddress( Form("weight_%s", weightBranch.c_str()) , &MCWeights );
  516. else if(b2Dweighted)treeMC -> SetBranchAddress( Form("weight2D_%s",weightBranch.c_str()) , &MCWeights );
  517. if(CutInQ2)
  518. treeMC -> SetBranchAddress( "Q2" , &Q2 );
  519. if(CutInMuPt)
  520. treeMC -> SetBranchAddress( "mu_minus_PT" , &mu_minus_PT_MC );
  521. if (separateCharge){
  522. treeMC -> SetBranchAddress( "B_plus_ID" , &B_plus_ID_MC );
  523. if (varIsMu || varIsKsPi){
  524. treeMC->SetBranchStatus(variable_charge.c_str(),1);
  525. if(varIsInt2) treeMC->SetBranchAddress(variable_charge.c_str(), &iVariable_oppCharge);
  526. else treeMC->SetBranchAddress(variable_charge.c_str(), &dVariable_oppCharge);
  527. }
  528. }
  529. treeMC->SetBranchAddress("TMed",&TM);
  530. treeMC->SetBranchAddress("TM_gammas",&TM_gammas);
  531. hist0varMC->Sumw2();
  532. for(int i = 0; i < treeMC->GetEntries(); i++){
  533. if(i%10000==0 && i != 0)std::cout << "Loading MC event " << i << " / " << treeMC->GetEntries() << std::endl;
  534. treeMC->GetEntry(i);
  535. if (!isTM("TMed",TM,false,TM_gammas)) continue;
  536. if(CutInQ2){
  537. if(Q2 > maxQ2*1.0e6 || Q2 < minQ2*1.0e6){
  538. continue;
  539. }
  540. }
  541. if(CutInMuPt){
  542. if(mu_minus_PT_MC > maxPT || mu_minus_PT_MC < minPT){
  543. continue;
  544. }
  545. }
  546. if (separateCharge){ //doesn't work for two variables!!!
  547. if (varIsMu || varIsKsPi){
  548. if (plusCharge && B_plus_ID_MC == -521){ //TODO
  549. if(varIsInt) hist0varMC->Fill( evalOperation(useTwoVars, iVariable_oppCharge,iVariable2,operation,bLogVar,bLog1minusVar), MCWeights);
  550. else hist0varMC->Fill( evalOperation(useTwoVars,dVariable_oppCharge,dVariable2,operation,bLogVar,bLog1minusVar), MCWeights);
  551. continue;
  552. }
  553. if (!plusCharge && B_plus_ID_MC == 521){ //TODO
  554. if(varIsInt) hist0varMC->Fill( evalOperation(useTwoVars, iVariable_oppCharge,iVariable2,operation,bLogVar,bLog1minusVar), MCWeights);
  555. else hist0varMC->Fill( evalOperation(useTwoVars,dVariable_oppCharge,dVariable2,operation,bLogVar,bLog1minusVar), MCWeights);
  556. continue;
  557. }
  558. }
  559. else {
  560. if (plusCharge && B_plus_ID_MC == -521) continue;
  561. if (!plusCharge && B_plus_ID_MC == 521) continue;
  562. }
  563. }
  564. if(varIsInt) hist0varMC->Fill( evalOperation(useTwoVars, iVariable,iVariable2,operation,bLogVar,bLog1minusVar), MCWeights);
  565. else hist0varMC->Fill( evalOperation(useTwoVars,dVariable,dVariable2,operation,bLogVar,bLog1minusVar), MCWeights);
  566. }
  567. if (!bWeighted && !b2Dweighted) hist0varMC->Sumw2();
  568. if(hist0varMC->GetEntries() == 0){
  569. std::cout << "No MC events found" << std::endl;
  570. return 0;
  571. }
  572. if(hist0varMC->Integral() == 0){
  573. std::cout << "No MC events included in the pre-defined range!" << std::endl;
  574. return 0;
  575. }
  576. std::cout << "Loaded all events: Data and MC" << std::endl;
  577. std::cout << "DATA: " << hist0varData->GetEntries() << " events with weights in range: " << hist0varData->Integral() << std::endl;
  578. std::cout << "MC : " << hist0varMC->GetEntries() << " events with weights in range: " << hist0varMC->Integral() << std::endl;
  579. //make ratio:
  580. TH1D * hist0varDataClone = (TH1D*) hist0varData->Clone("hist0varDataClone");
  581. TH1D * hist0varMCclone = (TH1D*) hist0varMC->Clone("hist0varMCclone");
  582. TH1D * hist0ratio = (TH1D*) hist0varMC->Clone("hist0ratio");
  583. hist0varDataClone->SetTitle(Form("%i%s%s: data for %s [norm]", year, TheDecay.c_str(), (SplitDDandLL && Kst2Kspiplus ? (KshortDecayInVelo ? " (LL)" : " (DD)") : ""), drawFormula.c_str()));
  584. hist0varMCclone ->SetTitle(Form("%i%s%s: MC for %s [norm]", year, TheDecay.c_str(), (SplitDDandLL && Kst2Kspiplus ? (KshortDecayInVelo ? " (LL)" : " (DD)") : ""), drawFormula.c_str()));
  585. hist0ratio ->SetTitle(Form("%i%s%s: ratio MC/data for %s",year, TheDecay.c_str(), (SplitDDandLL && Kst2Kspiplus ? (KshortDecayInVelo ? " (LL)" : " (DD)") : ""), drawFormula.c_str()));
  586. //normalize the clones and the ratio histo
  587. hist0varDataClone->Scale(1 / hist0varDataClone->Integral());
  588. hist0ratio ->Scale(1 / hist0ratio->Integral());
  589. hist0varMCclone ->Scale(1 / hist0varMCclone->Integral());
  590. hist0ratio->Divide(hist0varDataClone);
  591. //set correct ranges for the histograms:
  592. double dNormalizedVariableMax = 0. , dRatioMax = 0., dNormalizedVariableMin = 100. , dRatioMin = 100.;
  593. for(int bin = 1; bin <= nBins; bin++){
  594. double dDataClone = hist0varDataClone->GetBinContent(bin);
  595. double dMCClone = hist0varMCclone->GetBinContent(bin);
  596. double dRatio = hist0ratio->GetBinContent(bin);
  597. if(dNormalizedVariableMax <= dDataClone)dNormalizedVariableMax = dDataClone;
  598. if(dNormalizedVariableMax <= dMCClone) dNormalizedVariableMax = dMCClone;
  599. if(dRatioMax <= dRatio) dRatioMax = dRatio;
  600. if(dNormalizedVariableMin >= dDataClone)dNormalizedVariableMin = dDataClone;
  601. if(dNormalizedVariableMin >= dMCClone) dNormalizedVariableMin = dMCClone;
  602. if(dRatioMin >= dRatio) dRatioMin = dRatio;
  603. }
  604. dNormalizedVariableMax *= 1.1;
  605. if(dNormalizedVariableMin < 0)dNormalizedVariableMin *= 1.1;
  606. else dNormalizedVariableMin = 0.001; //if minimum is positve, set minimum to just above 0 to remove label
  607. if(dRatioMax > 3.)dRatioMax = 3.;
  608. if(dRatioMax < 2.)dRatioMax = 2.;
  609. dRatioMax *= 1.1;
  610. std::cout << "[INFO]\t\tAll histograms and ratios created. Proceed with plotting to .eps and .root files!" << std::endl;
  611. //configurables for plotting
  612. float lowerPlotHeight = 0.6;
  613. //create two pads into one canvas
  614. TCanvas* c2= new TCanvas("c2", "ratio and superposition");
  615. float textsize = gStyle->GetTextSize();
  616. TPad *pad1 = new TPad("pad1", "ratio",0.0,lowerPlotHeight,1.0,1.0,0);
  617. TPad *pad2 = new TPad("pad2", "superposition",0.0,0.0,1.0,lowerPlotHeight,0);
  618. pad1->Draw();
  619. pad2->Draw();
  620. //modifiy pad for main plot
  621. pad1->Clear();
  622. pad1->SetBorderSize (0);
  623. pad1->SetBottomMargin(1e-6);
  624. pad1->SetTopMargin(pad1->GetTopMargin() / ( 1 - lowerPlotHeight) );
  625. pad1->cd();
  626. //some axis-modifications on the main plot
  627. TGaxis::SetExponentOffset(1e+9,1e+9,"y");//offset = pad size * 1e+7
  628. hist0ratio->GetXaxis()->SetNoExponent(); //<-- spoils MaxDigits settings, so don't use it on other axis
  629. hist0ratio->GetXaxis()->SetLabelSize(0.0);//don't print labels
  630. hist0ratio->GetXaxis()->SetRangeUser(Min, Max);
  631. hist0ratio->GetXaxis()->SetTickLength(hist0ratio->GetXaxis()->GetTickLength()/(1-lowerPlotHeight));
  632. hist0ratio->GetXaxis()->SetNdivisions(gStyle->GetNdivisions("X"));
  633. hist0ratio->GetYaxis()->SetTitle("ratio MC/data");
  634. hist0ratio->GetYaxis()->SetTitleSize(textsize/(1-lowerPlotHeight));
  635. hist0ratio->GetYaxis()->SetLabelSize(textsize/(1-lowerPlotHeight));
  636. hist0ratio->GetYaxis()->SetTickLength(hist0ratio->GetYaxis()->GetTickLength());
  637. hist0ratio->GetYaxis()->SetNdivisions(gStyle->GetNdivisions("Y"));
  638. hist0ratio->GetYaxis()->SetTitleOffset(1.06*(1-lowerPlotHeight));
  639. hist0ratio->GetYaxis()->SetRangeUser(0.001, 3);
  640. hist0ratio->Draw("E1");
  641. TLine * unityline = new TLine(Min, 1, Max, 1);
  642. unityline->SetLineStyle(2);
  643. unityline->SetLineColor(4);
  644. unityline->Draw("SAME");
  645. pad2->Clear();
  646. pad2->SetBorderSize (0);
  647. pad2->SetTopMargin (1e-6);
  648. pad2->SetBottomMargin(pad2->GetBottomMargin() / lowerPlotHeight );
  649. pad2->cd();
  650. TGaxis::SetExponentOffset(1e+9,1e+9,"x");//offset = pad size * 1e+7
  651. hist0varDataClone->GetXaxis()->SetTitleOffset(1.05);
  652. hist0varDataClone->GetXaxis()->SetTitleSize (textsize/lowerPlotHeight);
  653. hist0varDataClone->GetXaxis()->SetLabelSize (textsize/lowerPlotHeight);
  654. hist0varDataClone->GetXaxis()->SetTickLength (hist0ratio->GetXaxis()->GetTickLength()/(lowerPlotHeight/(1-lowerPlotHeight)));
  655. hist0varDataClone->GetXaxis()->SetNdivisions (gStyle->GetNdivisions("X"));
  656. hist0varDataClone->GetXaxis()->SetTitle(xaxistitle.c_str());
  657. hist0varDataClone->GetXaxis()->SetRangeUser(Min, Max);
  658. hist0varDataClone->GetYaxis()->SetRangeUser(dNormalizedVariableMin, dNormalizedVariableMax);
  659. hist0varDataClone->GetYaxis()->SetTitle("weighted events");
  660. hist0varDataClone->GetYaxis()->SetLabelSize (textsize/lowerPlotHeight);
  661. hist0varDataClone->GetYaxis()->SetTitleSize (textsize/lowerPlotHeight);
  662. hist0varDataClone->GetYaxis()->SetTickLength(hist0ratio->GetYaxis()->GetTickLength());
  663. hist0varDataClone->GetYaxis()->SetNdivisions (gStyle->GetNdivisions("Y"));
  664. hist0varDataClone->GetYaxis()->SetTitleOffset(1.06*lowerPlotHeight);
  665. hist0varDataClone->Draw("E1");
  666. hist0varMCclone->SetLineColor(2);
  667. hist0varMCclone->SetMarkerColor(2);
  668. //hist0varMCclone->GetYaxis()->SetTitle("weighted events");
  669. hist0varMCclone->Draw("E1SAME");
  670. //Legend and position...
  671. float LegendXposition = 0.4;
  672. float LegendYposition = 0.62;
  673. if(strcmp(variable.c_str(), "pi_plus_ETA") == 0)LegendXposition = 0.62;
  674. else if(strcmp(variable.c_str(), "B_plus_OWNPV_CHI2") == 0)LegendXposition = 0.2;
  675. else if(strcmp(variable.c_str(), "K_short_IPCHI2_OWNPV") == 0)LegendXposition = 0.2;
  676. else if(strcmp(variable.c_str(), "K_star_plus_IPCHI2_OWNPV") == 0)LegendXposition = 0.2;
  677. else if(strcmp(variable.c_str(), "mu_minus_IPCHI2_OWNPV") == 0)LegendXposition = 0.62;
  678. else if(strcmp(variable.c_str(), "mu_plus_IPCHI2_OWNPV") == 0)LegendXposition = 0.62;
  679. else if(strcmp(variable.c_str(), "pi_plus_IPCHI2_OWNPV") == 0)LegendXposition = 0.62;
  680. else if(strcmp(variable.c_str(), "K_short_DIRA_OWNPV") == 0)LegendXposition = 0.2;
  681. else if(strcmp(variable.c_str(), "K_short_FD_OWNPV") == 0 && SplitDDandLL && !KshortDecayInVelo)LegendXposition = 0.62;
  682. else if(strcmp(variable.c_str(), (UseDTF ? "B_plus_ETA_DTF" :"B_plus_ETA" )) == 0)LegendXposition = 0.62;
  683. else if(strcmp(variable.c_str(), (UseDTF ? "K_plus_ETA_DTF" :"K_plus_ETA")) == 0)LegendXposition = 0.62;
  684. else if(strcmp(variable.c_str(), (UseDTF ? "K_star_plus_ETA_DTF" :"K_star_plus_ETA")) == 0)LegendXposition = 0.62;
  685. else if(strcmp(variable.c_str(), (UseDTF ? "pi_zero_resolved_ETA_DTF" : "pi_zero_resolved_ETA")) == 0)LegendXposition = 0.62;
  686. else if(strcmp(variable.c_str(), (UseDTF ? "pi_zero_merged_ETA_DTF" : "pi_zero_merged_ETA")) == 0)LegendXposition = 0.62;
  687. else if(strcmp(variable.c_str(), "B_plus_NEW_ConePTasym") == 0)LegendXposition = 0.2;
  688. else if(strcmp(variable.c_str(), (UseDTF ? "gamma2_PT_DTF" : "gamma2_PT")) == 0)LegendXposition = 0.62;
  689. else if(strcmp(variable.c_str(), (UseDTF ? "gamma1_PT_DTF" : "gamma1_PT")) == 0)LegendXposition = 0.62;
  690. else if(strcmp(variable.c_str(), "gamma2_CL") == 0)LegendXposition = 0.2;
  691. else if(strcmp(variable.c_str(), "gamma1_CL") == 0)LegendXposition = 0.2;
  692. else if(strcmp(variable.c_str(), "K_plus_TRACK_CHI2NDOF") == 0)LegendXposition = 0.62;
  693. if(strcmp(variable.c_str(), "B_plus_DIRA_OWNPV") == 0)LegendXposition = 0.2;
  694. else if(strcmp(variable.c_str(), "B_plus_IPCHI2_OWNPV") == 0)LegendXposition = 0.62;
  695. else if(strcmp(variable.c_str(), "K_star_plus_IPCHI2_OWNPV") == 0)LegendXposition = 0.2;
  696. else if(strcmp(variable.c_str(), "mu_minus_IPCHI2_OWNPV") == 0)LegendXposition = 0.62;
  697. else if(strcmp(variable.c_str(), "mu_plus_IPCHI2_OWNPV") == 0)LegendXposition = 0.62;
  698. else if(strcmp(variable.c_str(), (UseDTF ? "B_plus_ETA_DTF" :"B_plus_ETA" )) == 0)LegendXposition = 0.62;
  699. else if(strcmp(variable.c_str(), (UseDTF ? "K_plus_ETA_DTF" :"K_plus_ETA")) == 0)LegendXposition = 0.52;
  700. else if(strcmp(variable.c_str(), (UseDTF ? "K_star_plus_ETA_DTF" :"K_star_plus_ETA")) == 0)LegendXposition = 0.62;
  701. else if(strcmp(variable.c_str(), "B_plus_NEW_ConePTasym") == 0)LegendXposition = 0.2;
  702. if (variable.find("gamma1_PT") != std::string::npos){
  703. LegendXposition = 0.45;
  704. LegendYposition = 0.3;
  705. }
  706. else if (variable.find("mu_minus_IPCHI2_OWNPV") != std::string::npos){
  707. LegendXposition = 0.45;
  708. LegendYposition = 0.3;
  709. } else if (variable.find("_CL") != std::string::npos){
  710. LegendXposition = 0.3;
  711. }
  712. else if (variable.find("K_plus_PT") != std::string::npos){
  713. LegendXposition = 0.62;
  714. }
  715. else if (variable.find("B_plus_PT") != std::string::npos){
  716. LegendXposition = 0.62;
  717. }
  718. else if (variable.find("nLongTracks") != std::string::npos){
  719. LegendXposition = 0.62;
  720. }
  721. if(print_legend){
  722. TLegend * leg = new TLegend(LegendXposition,LegendYposition,LegendXposition + 0.25, LegendYposition + 0.18);
  723. /*
  724. if(bLogVar) leg->SetHeader(Form("Log( %s )", variable.c_str()));
  725. else if(bLog1minusVar) leg->SetHeader(Form("Log( 1 - %s )", variable.c_str()));
  726. else leg->SetHeader(variable.c_str());
  727. */
  728. leg->AddEntry(hist0varDataClone,sWeight?"sWeighted data":"data", "lpe");
  729. if(b2Dweighted) leg->AddEntry(hist0varMCclone,"2 x 1D reweighted MC", "lpe");
  730. else if(bWeighted)leg->AddEntry(hist0varMCclone,"reweighted MC", "lpe");
  731. else leg->AddEntry(hist0varMCclone,"non-weighted MC", "lpe");
  732. leg->SetTextSize(0.04/lowerPlotHeight); // works fine
  733. leg->Draw("same");
  734. addLHCbtag(LegendXposition, LegendYposition + 0.27, "", 1, 1/lowerPlotHeight);
  735. }
  736. //Further plots, if needed!
  737. TCanvas * c3;
  738. TCanvas * c4;
  739. if (!minimumPlot){
  740. c3 = new TCanvas("c3", "ratio");
  741. c3->Clear();
  742. c3->cd();
  743. hist0ratio->GetYaxis()->SetRangeUser(0, dRatioMax);
  744. hist0ratio->GetYaxis()->SetTitle("ratio MC/data [norm.]");
  745. hist0ratio->Draw("E1");
  746. unityline->Draw("SAME");
  747. c4 = new TCanvas("c4", "overlay");
  748. c4->Clear();
  749. c4->cd();
  750. hist0varDataClone->GetYaxis()->SetRangeUser(0, dNormalizedVariableMax);
  751. hist0varDataClone->GetYaxis()->SetTitle("Weighted Decays / bin [norm.]");
  752. hist0varDataClone->Draw("E1");
  753. hist0varMCclone->SetLineColor(2);
  754. hist0varMCclone->SetMarkerColor(2);
  755. hist0varMCclone->GetYaxis()->SetTitle("Weighted Decays / bin [norm.]");
  756. hist0varMCclone->Draw("E1SAME");
  757. }
  758. std::string WeightingOptions = "";
  759. if(b2Dweighted)WeightingOptions.append("_2D_weighted");
  760. if(bWeighted)WeightingOptions.append("_weighted");
  761. if(ReferenceChannel)WeightingOptions.append("_Ref");
  762. if(!sWeight)WeightingOptions.append("_nosWeight");
  763. if (CutInQ2)WeightingOptions.append("_cutQ2"+to_string(minQ2)+"_"+to_string(maxQ2));
  764. if (CutInMuPt)WeightingOptions.append("_cutPT"+to_string(minPT)+"_"+to_string(maxPT));
  765. if (separateCharge){
  766. WeightingOptions.append("_actualCharge");
  767. if (plusCharge) WeightingOptions.append("Plus");
  768. else WeightingOptions.append("Minus");
  769. }
  770. if(bPrint){
  771. if (Kst2Kpluspi0Merged || Kst2Kpluspi0Resolved){
  772. c2->Print(Form("%s/ComparePlots/%i_%s_%s_MC_data%s_%s.eps", path_to_output_KplusPizero.c_str(), year, TheDecay.c_str(), varName.c_str(), WeightingOptions.c_str(),weightBranch.c_str()));
  773. //c2->Print(Form("%s/ComparePlots/%i_%s_%s_MC_data%s.jpg", path_to_output_KplusPizero.c_str(), year, TheDecay.c_str(), varName.c_str(), WeightingOptions.c_str()));
  774. //c2->SaveAs(Form("%s/ComparePlots/%i_%s_%s_MC_data%s.root", path_to_output_KplusPizero.c_str(), year, TheDecay.c_str(), varName.c_str(), WeightingOptions.c_str()));
  775. if (!minimumPlot){
  776. c3->Print(Form("%s/ComparePlots/%i_%s_%s_MC_data_ratio%s_%s.eps", path_to_output_KplusPizero.c_str(), year, TheDecay.c_str(), varName.c_str(), WeightingOptions.c_str(),weightBranch.c_str()));
  777. //c3->Print(Form("%s/ComparePlots/%i_%s_%s_MC_data_ratio%s.jpg", path_to_output_KplusPizero.c_str(), year, TheDecay.c_str(), varName.c_str(), WeightingOptions.c_str()));
  778. //c3->SaveAs(Form("%s/ComparePlots/%i_%s_%s_MC_data_ratio%s.root", path_to_output_KplusPizero.c_str(), year, TheDecay.c_str(), varName.c_str(), WeightingOptions.c_str()));
  779. c4->Print(Form("%s/ComparePlots/%i_%s_%s_MC_data_overlay%s_%s.eps", path_to_output_KplusPizero.c_str(), year, TheDecay.c_str(), varName.c_str(), WeightingOptions.c_str(),weightBranch.c_str()));
  780. //c4->Print(Form("%s/ComparePlots/%i_%s_%s_MC_data_overlay%s.jpg", path_to_output_KplusPizero.c_str(), year, TheDecay.c_str(), varName.c_str(), WeightingOptions.c_str()));
  781. //c4->SaveAs(Form("%s/ComparePlots/%i_%s_%s_MC_data_overlay%s.root", path_to_output_KplusPizero.c_str(), year, TheDecay.c_str(), varName.c_str(), WeightingOptions.c_str()));
  782. }
  783. }
  784. if (Kst2Kspiplus){
  785. c2->Print(Form("%s/ComparePlots/%i_%s%s_%s_MC_data%s_%s.eps", path_to_output_KshortPiplus.c_str(), year, TheDecay.c_str(), (SplitDDandLL ? (KshortDecayInVelo ? "_LL" : "_DD") : ""), varName.c_str(), WeightingOptions.c_str(),weightBranch.c_str()));
  786. //c2->SaveAs(Form("%s/ComparePlots/%i_%s%s_%s_MC_data%s.root", path_to_output_KshortPiplus.c_str(), year, TheDecay.c_str(), (SplitDDandLL ? (KshortDecayInVelo ? "_LL" : "_DD") : ""), varName.c_str(), WeightingOptions.c_str()));
  787. if (!minimumPlot){
  788. c3->Print(Form("%s/ComparePlots/%i_%s%s_%s_MC_data_ratio%s_%s.eps", path_to_output_KshortPiplus.c_str(), year, TheDecay.c_str(), (SplitDDandLL ? (KshortDecayInVelo ? "_LL" : "_DD") : ""), varName.c_str(), WeightingOptions.c_str(),weightBranch.c_str()));
  789. //c3->SaveAs(Form("%s/ComparePlots/%i_%s%s_%s_MC_data_ratio%s.root", path_to_output_KshortPiplus.c_str(), year, (SplitDDandLL ? (KshortDecayInVelo ? "_LL" : "_DD") : ""), TheDecay.c_str(), varName.c_str(), WeightingOptions.c_str()));
  790. c4->Print(Form("%s/ComparePlots/%i_%s%s_%s_MC_data_overlay%s_%s.eps", path_to_output_KshortPiplus.c_str(), year, (SplitDDandLL ? (KshortDecayInVelo ? "_LL" : "_DD") : ""), TheDecay.c_str(), varName.c_str(), WeightingOptions.c_str(),weightBranch.c_str()));
  791. //c4->SaveAs(Form("%s/ComparePlots/%i_%s%s_%s_MC_data_overlay%s.root", path_to_output_KshortPiplus.c_str(), year, (SplitDDandLL ? (KshortDecayInVelo ? "_LL" : "_DD") : ""), TheDecay.c_str(), varName.c_str(), WeightingOptions.c_str()));
  792. }
  793. }
  794. }
  795. c2->Close();
  796. if (!minimumPlot){
  797. c3->Close();
  798. c4->Close();
  799. }
  800. delete c2;
  801. if (!minimumPlot){
  802. delete c3;
  803. delete c4;
  804. }
  805. delete hist0ratio;
  806. delete hist0varData;
  807. delete hist0varDataClone;
  808. delete hist0varMC;
  809. delete hist0varMCclone;
  810. delete treeData;
  811. delete treeMC;
  812. std::cout << "[INFO]\t\tAll done with variable: " << varName << std::endl;
  813. return 1;
  814. }
  815. int compareVariablesKplusKshort(int year = 2011, std::string variable = "B_plus_PT", bool sWeightKplus = false,bool sWeightKshort = true, bool bWeighted = true, bool b2Dweighted = true,
  816. bool bLogVar = false, bool bLog1minusVar = false, bool bPrint = true, bool KshortDecayInVelo = true, std::string weightBranch = firstMCweight ) {
  817. //if 2D weighted, set boolean for 1D weighting false
  818. if(b2Dweighted)bWeighted = false;
  819. gStyle -> SetOptStat(0);
  820. gROOT->SetBatch(kTRUE);
  821. LHCbStyle();
  822. //lhcbStyle->SetOptTitle(1);
  823. //lhcbStyle->SetTitleSize(0.1,"x");
  824. //lhcbStyle->SetTitleSize(0.1,"y");
  825. //lhcbStyle->SetTitleSize(0.1,"z");
  826. ///by default all variables are assumed to be doubles. If variable is an integer, add to the following list:
  827. bool varIsInt = false;
  828. if(variable == "nTracks") varIsInt = true;
  829. if(variable == "nSPDHits") varIsInt = true;
  830. if(variable == "nLongTracks") varIsInt = true;
  831. if(variable == "nVeloTracks") varIsInt = true;
  832. if(variable == "nTTracks") varIsInt = true;
  833. if(variable == "nDownstreamTracks") varIsInt = true;
  834. if(variable == "nUpstreamTracks") varIsInt = true;
  835. ///for now hardcoded, but might be possible to include in input parameters if comparison between data and reference MC is needed
  836. const bool ReferenceChannel = false;
  837. ///for writting only the ratio and superposition
  838. const bool minimumPlot = true;
  839. if(bLogVar && bLog1minusVar){
  840. coutERROR("Only Log( var ) or Log( 1 - var ) option possible, but both flags were set for variable: " + variable);
  841. return 0;
  842. }
  843. //put both magnet polarities into one TChain
  844. TChain * treeDataKplus = new TChain("DecayTree");
  845. TChain * treeMCKplus = new TChain("DecayTreeTruthMatched");
  846. TChain * treeDataKshort = new TChain("DecayTree");
  847. TChain * treeMCKshort = new TChain("DecayTreeTruthMatched");
  848. // Kst2Kpluspi0Resolved c
  849. if(ReferenceChannel){
  850. treeDataKplus->Add(Form("%s/data/%i_KplusPi0Resolved_BDTinputRef.root", path_to_output_KplusPizero.c_str(), year));
  851. treeMCKplus->Add(Form("%s/data/MC/%i_RefKplusPi0Resolved_BDTinput.root", path_to_output_KplusPizero.c_str(), year));
  852. }
  853. else{
  854. treeDataKplus->Add(Form("%s/data/%i_KplusPi0Resolved_BDTinput.root", path_to_output_KplusPizero.c_str(), year));
  855. treeMCKplus->Add(Form("%s/data/MC/%i_KplusPi0Resolved_BDTinput.root", path_to_output_KplusPizero.c_str(), year));
  856. }
  857. // Kst2Kspiplus
  858. if(ReferenceChannel){
  859. treeDataKshort->Add(Form("%s/data/%i_KshortPiplus_BDTinputRef.root", path_to_output_KshortPiplus.c_str(), year));
  860. treeMCKshort->Add(Form("%s/data/MC/%i_RefKshortPiplusRef_BDTinput.root", path_to_output_KshortPiplus.c_str(), year));
  861. }
  862. else{
  863. treeDataKshort->Add(Form("%s/data/%i_KshortPiplus%s_BDTinput.root", path_to_output_KshortPiplus.c_str(), year, (KshortDecayInVelo ? "_LL" : "_DD" )));
  864. treeMCKshort->Add(Form("%s/data/MC/%i_KshortPiplus%s_BDTinput.root", path_to_output_KshortPiplus.c_str(), year, (KshortDecayInVelo ? "_LL" : "_DD")));
  865. }
  866. std::string histNameKplus = Form("%i%s%s", year,"",variable.c_str());
  867. std::string histNameKshort = Form("%i%s%s", year,((KshortDecayInVelo ? "LL" : "DD")),variable.c_str());
  868. //DataKplus: create histograms from trees
  869. if(bLogVar) treeDataKplus->Draw(Form("TMath::Log( %s )>>%sDataKplus", variable.c_str(),histNameKplus.c_str()), "");
  870. else if(bLog1minusVar) treeDataKplus->Draw(Form("TMath::Log(1 - %s)>>%sDataKplus",variable.c_str(),histNameKplus.c_str()), "");
  871. else treeDataKplus->Draw(Form("%s>>%sDataKplus", variable.c_str(),histNameKplus.c_str()), "");
  872. TH1 * hist0varDataKplus = (TH1*)gDirectory->Get(Form("%sDataKplus", histNameKplus.c_str()));
  873. //DataKshort: initialize histograms into objects
  874. if(bLogVar) treeDataKshort->Draw(Form("TMath::Log( %s )>>%sDataKshort", variable.c_str(),histNameKshort.c_str()), "");
  875. else if(bLog1minusVar) treeDataKshort->Draw(Form("TMath::Log(1 - %s)>>%sDataKshort",variable.c_str(),histNameKshort.c_str()), "");
  876. else treeDataKshort->Draw(Form("%s>>%sDataKshort", variable.c_str(),histNameKshort.c_str()), "");
  877. TH1 * hist0varDataKshort = (TH1*)gDirectory->Get(Form("%sDataKshort",histNameKshort.c_str()));
  878. //MCKplus: create histograms from trees
  879. if(bLogVar) treeMCKshort ->Draw(Form("TMath::Log( %s )>>%sMCKplus", variable.c_str(),histNameKshort.c_str()), "");
  880. else if(bLog1minusVar) treeMCKshort ->Draw(Form("TMath::Log(1 - %s)>>%sMCKplus", variable.c_str(),histNameKshort.c_str()), "");
  881. else treeMCKshort ->Draw(Form("%s>>%sMCKplus", variable.c_str(),histNameKshort.c_str()), "");
  882. TH1D * hist0varMCKplus = (TH1D*)gDirectory->Get(Form("%sMCKplus",histNameKshort.c_str()));
  883. //MCKshort: create histograms from trees
  884. if(bLogVar) treeMCKshort ->Draw(Form("TMath::Log( %s )>>%sMCKshort", variable.c_str(),histNameKshort.c_str()), "");
  885. else if(bLog1minusVar) treeMCKshort ->Draw(Form("TMath::Log(1 - %s)>>%sMCKshort", variable.c_str(),histNameKshort.c_str()), "");
  886. else treeMCKshort ->Draw(Form("%s>>%sMCKshort", variable.c_str(),histNameKshort.c_str()), "");
  887. TH1D * hist0varMCKshort = (TH1D*)gDirectory->Get(Form("%sMCKshort",histNameKshort.c_str()));
  888. //Get min and max of x-range from both histograms:
  889. int nBinsData, nBinsMC;
  890. double BinContentData, BinContentMC;
  891. int nBinMinData, nBinMaxData;
  892. int nBinMinMC, nBinMaxMC;
  893. float MinData, MaxData;
  894. float MinMC, MaxMC;
  895. if(variable == "nTracks" || variable == "nSPDHits"){
  896. nBinsData = 60;
  897. nBinsMC = 60;
  898. MinData = -0.5;
  899. MinMC = -0.5;
  900. MaxData = 599.5;
  901. MaxMC = 599.5;
  902. }
  903. else if(variable == "nLongTracks" || variable == "nVeloTracks" || variable == "nTTracks" || variable == "nBackTracks"|| variable == "nMuonTracks"){
  904. nBinsData = 50;
  905. nBinsMC = 50;
  906. MinData = -0.5;
  907. MinMC = -0.5;
  908. MaxData = 149.5;
  909. MaxMC = 149.5;
  910. }
  911. else if(variable == "nDownstreamTracks" || variable == "nUpstreamTracks"){
  912. nBinsData = 50;
  913. nBinsMC = 50;
  914. MinData = -0.5;
  915. MinMC = -0.5;
  916. MaxData = 49.5;
  917. MaxMC = 49.5;
  918. }
  919. else {
  920. //get number of bins of both histograms and select larger number for new histogram
  921. int nBinsDataKplus = hist0varDataKplus ->GetXaxis()->GetNbins();
  922. int nBinsDataKshort = hist0varDataKshort ->GetXaxis()->GetNbins();
  923. int nBinsMCKplus = hist0varMCKplus ->GetXaxis()->GetNbins();
  924. int nBinsMCKshort = hist0varMCKshort ->GetXaxis()->GetNbins();
  925. if(nBinsDataKplus >= nBinsDataKshort) nBinsData = nBinsDataKplus;
  926. else nBinsData = nBinsDataKshort;
  927. if(nBinsMCKplus >= nBinsMCKshort) nBinsMC = nBinsMCKplus;
  928. else nBinsMC = nBinsMCKshort;
  929. //DATA
  930. //Kplus
  931. nBinMinData = 0;
  932. BinContentData = 0;
  933. while(BinContentData == 0){
  934. nBinMinData++;
  935. BinContentData = hist0varDataKplus->GetBinContent(nBinMinData);
  936. }
  937. float MinDataKplus = hist0varDataKplus->GetXaxis()->GetBinLowEdge(nBinMinData);
  938. nBinMaxData = nBinsData + 1;
  939. BinContentData = 0;
  940. while(BinContentData == 0){
  941. nBinMaxData--;
  942. BinContentData = hist0varDataKplus->GetBinContent(nBinMaxData);
  943. }
  944. float MaxDataKplus = hist0varDataKplus->GetXaxis()->GetBinUpEdge(nBinMaxData);
  945. //Kshort
  946. nBinMinData = 0;
  947. BinContentData = 0;
  948. while(BinContentData == 0){
  949. nBinMinData++;
  950. BinContentData = hist0varDataKshort->GetBinContent(nBinMinData);
  951. }
  952. float MinDataKshort = hist0varDataKshort->GetXaxis()->GetBinLowEdge(nBinMinData);
  953. nBinMaxData = nBinsData + 1;
  954. BinContentData = 0;
  955. while(BinContentData == 0){
  956. nBinMaxData--;
  957. BinContentData = hist0varDataKshort->GetBinContent(nBinMaxData);
  958. }
  959. float MaxDataKshort = hist0varDataKshort->GetXaxis()->GetBinUpEdge(nBinMaxData);
  960. //MC
  961. //Kplus
  962. nBinMinMC = 0;
  963. BinContentMC = 0;
  964. while(BinContentMC == 0){
  965. nBinMinMC++;
  966. BinContentMC = hist0varMCKplus->GetBinContent(nBinMinMC);
  967. }
  968. float MinMCKplus = hist0varMCKplus->GetXaxis()->GetBinLowEdge(nBinMinMC);
  969. nBinMaxMC = nBinsMC + 1;
  970. BinContentMC = 0;
  971. while(BinContentMC == 0){
  972. nBinMaxMC--;
  973. BinContentMC = hist0varMCKplus->GetBinContent(nBinMaxMC);
  974. }
  975. float MaxMCKplus = hist0varMCKplus->GetXaxis()->GetBinUpEdge(nBinMaxMC);
  976. //Kshort
  977. nBinMinMC = 0;
  978. BinContentMC = 0;
  979. while(BinContentMC == 0){
  980. nBinMinMC++;
  981. BinContentMC = hist0varMCKshort->GetBinContent(nBinMinMC);
  982. }
  983. float MinMCKshort = hist0varMCKshort->GetXaxis()->GetBinLowEdge(nBinMinMC);
  984. nBinMaxMC = nBinsMC + 1;
  985. BinContentMC = 0;
  986. while(BinContentMC == 0){
  987. nBinMaxMC--;
  988. BinContentMC = hist0varMCKshort->GetBinContent(nBinMaxMC);
  989. }
  990. float MaxMCKshort = hist0varMCKshort->GetXaxis()->GetBinUpEdge(nBinMaxMC);
  991. std::cout << "Found hist0varDataKplus bins: " << nBinsData << " from " << MinDataKplus << " to " << MaxDataKplus << std::endl;
  992. std::cout << "Found hist0varDataKshort bins: " << nBinsData << " from " << MinDataKshort << " to " << MaxDataKshort << std::endl;
  993. std::cout << "Found hist0varMCKplus bins: " << nBinsMC << " from " << MinMCKplus << " to " << MaxMCKplus << std::endl;
  994. std::cout << "Found hist0varMCKshort bins: " << nBinsMC << " from " << MinMCKshort << " to " << MaxMCKshort << std::endl;
  995. if(MinDataKplus <= MinDataKshort)MinData = MinDataKplus ;
  996. else MinData = MinDataKshort;
  997. if(MaxDataKplus >= MaxDataKshort)MaxData = MaxDataKplus ;
  998. else MaxData = MaxDataKshort;
  999. if(MinMCKplus <= MinMCKshort)MinMC = MinMCKplus ;
  1000. else MinMC = MinMCKshort;
  1001. if(MaxMCKplus >= MaxMCKshort)MaxMC = MaxMCKplus ;
  1002. else MaxMC = MaxMCKshort;
  1003. nBinsData/=2;
  1004. nBinsMC/=2;
  1005. }
  1006. //default axis lable is the variable name:
  1007. std::string xaxistitle = variable;
  1008. //Load the MVA config from the txt file
  1009. MVA_variables vars("");
  1010. //rename xAxis for nTracks
  1011. if(strcmp(variable.c_str(), "nTracks") == 0){
  1012. xaxistitle = "Track Multiplicity";
  1013. std::cout << "[INFO]\tUsing Axis Label: " << xaxistitle << std::endl;
  1014. }
  1015. //use MVA loader to get nicely formated variable name and units
  1016. //manual intervention for ranges on X-axis
  1017. //B+
  1018. if(strcmp(variable.c_str(), "B_plus_DIRA_OWNPV") == 0)MinData = -20.;
  1019. else if(strcmp(variable.c_str(), "B_plus_OWNPV_CHI2") == 0)MinData = 1.;
  1020. else if(strcmp(variable.c_str(), "B_plus_FD_OWNPV") == 0)MaxData = 200.;
  1021. else if(strcmp(variable.c_str(), (UseDTF ? "B_plus_PT_DTF" : "B_plus_PT")) == 0)MaxData = 60000.;
  1022. else if(strcmp(variable.c_str(), "B_plus_DOCA1") == 0)MaxData = 1000.;
  1023. else if(strcmp(variable.c_str(), "B_plus_IP_OWNPV") == 0)MaxData = 0.12;
  1024. else if(strcmp(variable.c_str(), "B_plus_NEW_ConePTasym") == 0)MaxData = 1.;
  1025. else if(strcmp(variable.c_str(), UseDTF ? "B_plus_ETA_DTF" :"B_plus_ETA" ) == 0)MaxData = 5.;
  1026. //K*
  1027. else if(strcmp(variable.c_str(), "K_star_plus_IPCHI2_OWNPV") == 0)MinData = -7.;
  1028. else if(strcmp(variable.c_str(), "K_star_plus_IPCHI2_OWNPV") == 0)MaxData = 60.;
  1029. else if(strcmp(variable.c_str(), (UseDTF ? "K_star_plus_PT_DTF" : "K_star_plus_PT")) == 0)MaxData = 20000.;
  1030. else if(strcmp(variable.c_str(), UseDTF ? "K_star_plus_ETA_DTF" :"K_star_plus_ETA" ) == 0)MaxData = 5.;
  1031. //B+
  1032. if (strcmp(variable.c_str(), "B_plus_DIRA_OWNPV") == 0)MinMC = -20.;
  1033. else if (strcmp(variable.c_str(), "B_plus_OWNPV_CHI2") == 0)MinMC = 1.;
  1034. else if (strcmp(variable.c_str(), "B_plus_FD_OWNPV") == 0)MaxMC = 200.;
  1035. else if (strcmp(variable.c_str(), (UseDTF ? "B_plus_PT_DTF" : "B_plus_PT")) == 0)MaxMC = 60000.;
  1036. else if (strcmp(variable.c_str(), "B_plus_DOCA1") == 0)MaxMC = 1000.;
  1037. else if (strcmp(variable.c_str(), "B_plus_IP_OWNPV") == 0)MaxMC = 0.12;
  1038. else if (strcmp(variable.c_str(), "B_plus_NEW_ConePTasym") == 0)MaxMC = 1.;
  1039. else if (strcmp(variable.c_str(), (UseDTF ? "B_plus_ETA_DTF" :"B_plus_ETA" )) == 0)MaxMC = 5.;
  1040. //K*
  1041. else if (strcmp(variable.c_str(), (UseDTF ? "K_star_plus_PT_DTF" : "K_star_plus_PT")) == 0)MaxMC = 30000.;
  1042. else if (strcmp(variable.c_str(), "K_star_plus_IPCHI2_OWNPV") == 0)MaxMC = 60.;
  1043. else if (strcmp(variable.c_str(), "K_star_plus_IPCHI2_OWNPV") == 0)MinMC = -60.;
  1044. else if (strcmp(variable.c_str(), UseDTF ? "K_star_plus_ETA_DTF" :"K_star_plus_ETA" ) == 0)MaxMC = 5.;
  1045. //create new histograms to fill data from tree by looping over tree
  1046. //same number of bins and same range to be able to divide the histograms!
  1047. hist0varDataKplus = new TH1D("hist0varDataKplus ",Form("Kplus %s from data", variable.c_str()), nBinsData, MinData, MaxData);
  1048. hist0varDataKshort = new TH1D("hist0varDataKshort",Form("Kshort %s from data", variable.c_str()), nBinsData, MinData, MaxData);
  1049. hist0varMCKplus = new TH1D("hist0varMCKplus ", Form("Kplus %s from MC", variable.c_str()), nBinsMC, MinMC, MaxMC);
  1050. hist0varMCKshort = new TH1D("hist0varMCKshort", Form("Kshort %s from MC", variable.c_str()), nBinsMC, MinMC, MaxMC);
  1051. std::cout << "Created hist0varDataKplus bins: " << nBinsData << " from " << MinData << " to " << MaxData << std::endl;
  1052. std::cout << "Created hist0varDataKshort bins: " << nBinsData << " from " << MinData << " to " << MaxData << std::endl;
  1053. std::cout << "Created hist0varMCKplus bins: " << nBinsMC << " from " << MinMC << " to " << MaxMC << std::endl;
  1054. std::cout << "Created hist0varMCKshort bins: " << nBinsMC << " from " << MinMC << " to " << MaxMC << std::endl;
  1055. //default type of variables is double, if variable is integer, add name to list in line 71
  1056. double dVariableKplusData;
  1057. double dVariableKplusMC;
  1058. int iVariableKplusData;
  1059. int iVariableKplusMC;
  1060. double dSWeightsKplus = 1., MCWeightsKplus = 1.;
  1061. double dVariableKshortData;
  1062. double dVariableKshortMC;
  1063. int iVariableKshortData;
  1064. int iVariableKshortMC;
  1065. double dSWeightsKshort = 1., MCWeightsKshort = 1.;
  1066. //deactivate all branches exept the one of intrest!
  1067. treeDataKplus->SetBranchStatus("*",0);
  1068. treeDataKplus->SetBranchStatus(variable.c_str(),1);
  1069. if (sWeightKplus) treeDataKplus->SetBranchStatus("N_Bplus_sw",1);
  1070. treeDataKshort->SetBranchStatus("*",0);
  1071. treeDataKshort->SetBranchStatus(variable.c_str(),1);
  1072. if (sWeightKshort) treeDataKshort->SetBranchStatus("N_Bplus_sw",1);
  1073. treeMCKplus ->SetBranchStatus("*",0);
  1074. treeMCKplus ->SetBranchStatus(variable.c_str(),1);
  1075. if(bWeighted) treeMCKplus ->SetBranchStatus(Form("weight_%s", weightBranch.c_str()),1);
  1076. else if(b2Dweighted)treeMCKplus ->SetBranchStatus(Form("weight2D_%s",weightBranch.c_str()),1);
  1077. treeMCKshort ->SetBranchStatus("*",0);
  1078. treeMCKshort ->SetBranchStatus(variable.c_str(),1);
  1079. if(bWeighted) treeMCKshort ->SetBranchStatus(Form("weight_%s", weightBranch.c_str()),1);
  1080. else if(b2Dweighted)treeMCKshort ->SetBranchStatus(Form("weight2D_%s",weightBranch.c_str()),1);
  1081. //Data Kplus
  1082. std::cout << "Loading " << treeDataKplus->GetEntries() << " data events!" << std::endl;
  1083. if(varIsInt)treeDataKplus -> SetBranchAddress( variable.c_str() , &iVariableKplusData);
  1084. else treeDataKplus-> SetBranchAddress( variable.c_str() , &dVariableKplusData );
  1085. if (sWeightKplus) treeDataKplus -> SetBranchAddress( "N_Bplus_sw" , &dSWeightsKplus );
  1086. for(int i = 0; i < treeDataKplus->GetEntries(); i++){
  1087. if(i%10000==0 && i != 0)std::cout << "Loading data Kplus event " << i << " / " << treeDataKplus->GetEntries() << std::endl;
  1088. treeDataKplus->GetEntry(i);
  1089. if(varIsInt){
  1090. if(bLogVar) iVariableKplusData = TMath::Log(iVariableKplusData);
  1091. else if(bLog1minusVar) iVariableKplusData = TMath::Log(1-iVariableKplusData);
  1092. hist0varDataKplus->Fill(iVariableKplusData, dSWeightsKplus);
  1093. }
  1094. else{
  1095. if(bLogVar) dVariableKplusData = TMath::Log(dVariableKplusData);
  1096. else if(bLog1minusVar) dVariableKplusData = TMath::Log(1-dVariableKplusData);
  1097. hist0varDataKplus->Fill(dVariableKplusData, dSWeightsKplus);
  1098. }
  1099. }
  1100. if (!sWeightKplus) hist0varDataKplus->Sumw2();
  1101. //Data Kshort
  1102. std::cout << "Loading " << treeDataKshort->GetEntries() << " data Kshort events!" << std::endl;
  1103. if(varIsInt)treeDataKshort -> SetBranchAddress( variable.c_str() , &iVariableKshortData );
  1104. else treeDataKshort-> SetBranchAddress( variable.c_str() , &dVariableKshortData );
  1105. if (sWeightKshort) treeDataKshort -> SetBranchAddress( "N_Bplus_sw" , &dSWeightsKshort );
  1106. for(int i = 0; i < treeDataKshort->GetEntries(); i++){
  1107. if(i%10000==0 && i != 0)std::cout << "Loading data Kshort event " << i << " / " << treeDataKshort->GetEntries() << std::endl;
  1108. treeDataKshort->GetEntry(i);
  1109. if(varIsInt){
  1110. if(bLogVar) iVariableKshortData = TMath::Log(iVariableKshortData);
  1111. else if(bLog1minusVar) iVariableKshortData = TMath::Log(1-iVariableKshortData);
  1112. hist0varDataKshort->Fill(iVariableKshortData, dSWeightsKshort);
  1113. }
  1114. else{
  1115. if(bLogVar) dVariableKshortData = TMath::Log(dVariableKshortData);
  1116. else if(bLog1minusVar) dVariableKshortData = TMath::Log(1-dVariableKshortData);
  1117. hist0varDataKshort->Fill(dVariableKshortData, dSWeightsKshort);
  1118. }
  1119. }
  1120. if (!sWeightKshort) hist0varDataKshort->Sumw2();
  1121. //MC Kplus
  1122. std::cout << "Loading " << treeMCKplus->GetEntries() << " MC Kplus events!" << std::endl;
  1123. if(varIsInt)treeMCKplus -> SetBranchAddress( variable.c_str() , &iVariableKplusMC );
  1124. else treeMCKplus -> SetBranchAddress( variable.c_str() , &dVariableKplusMC );
  1125. if(bWeighted) treeMCKplus -> SetBranchAddress( Form("weight_%s", weightBranch.c_str()), &MCWeightsKplus );
  1126. else if(b2Dweighted)treeMCKplus -> SetBranchAddress( Form("weight2D_%s", weightBranch.c_str()), &MCWeightsKplus );
  1127. else hist0varMCKplus->Sumw2();
  1128. for(int i = 0; i < treeMCKplus->GetEntries(); i++){
  1129. if(i%10000==0 && i != 0)std::cout << "Loading MC Kplus event " << i << " / " << treeMCKplus->GetEntries() << std::endl;
  1130. treeMCKplus->GetEntry(i);
  1131. if(varIsInt){
  1132. if(bLogVar) iVariableKplusMC = TMath::Log(iVariableKplusMC);
  1133. else if(bLog1minusVar) iVariableKplusMC = TMath::Log(1-iVariableKplusMC);
  1134. hist0varMCKplus->Fill(iVariableKplusMC, MCWeightsKplus);
  1135. }
  1136. else{
  1137. if(bLogVar) dVariableKplusMC = TMath::Log(dVariableKplusMC);
  1138. else if(bLog1minusVar) dVariableKplusMC = TMath::Log(1-dVariableKplusMC);
  1139. hist0varMCKplus->Fill(dVariableKplusMC, MCWeightsKplus);
  1140. }
  1141. }
  1142. //MC Kshort
  1143. std::cout << "Loading " << treeMCKshort->GetEntries() << " MC Kshort events!" << std::endl;
  1144. if(varIsInt)treeMCKshort -> SetBranchAddress( variable.c_str() , &iVariableKshortMC );
  1145. else treeMCKshort -> SetBranchAddress( variable.c_str() , &dVariableKshortMC );
  1146. if(bWeighted) treeMCKplus -> SetBranchAddress( Form("weight_%s", weightBranch.c_str()), &MCWeightsKshort );
  1147. else if(b2Dweighted)treeMCKplus -> SetBranchAddress( Form("weight2D_%s", weightBranch.c_str()), &MCWeightsKshort );
  1148. else hist0varMCKshort->Sumw2();
  1149. for(int i = 0; i < treeMCKshort->GetEntries(); i++){
  1150. if(i%10000==0 && i != 0)std::cout << "Loading MC Kshort event " << i << " / " << treeMCKshort->GetEntries() << std::endl;
  1151. treeMCKshort->GetEntry(i);
  1152. if(varIsInt){
  1153. if(bLogVar) iVariableKshortMC = TMath::Log(iVariableKshortMC);
  1154. else if(bLog1minusVar) iVariableKshortMC = TMath::Log(1-iVariableKshortMC);
  1155. hist0varMCKshort->Fill(iVariableKshortMC, MCWeightsKshort);
  1156. }
  1157. else{
  1158. if(bLogVar) dVariableKshortMC = TMath::Log(dVariableKshortMC);
  1159. else if(bLog1minusVar) dVariableKshortMC = TMath::Log(1-dVariableKshortMC);
  1160. hist0varMCKshort->Fill(dVariableKshortMC, MCWeightsKshort);
  1161. }
  1162. }
  1163. //make ratio:
  1164. TH1D * hist0varDataCloneKplus = (TH1D*) hist0varDataKplus ->Clone("hist0varDataCloneKplus ");
  1165. TH1D * hist0varDataCloneKshort = (TH1D*) hist0varDataKshort->Clone("hist0varDataCloneKshort");
  1166. TH1D * hist0varMCcloneKplus = (TH1D*) hist0varMCKplus ->Clone("hist0varMCcloneKplus ");
  1167. TH1D * hist0varMCcloneKshort = (TH1D*) hist0varMCKshort->Clone("hist0varMCcloneKshort");
  1168. TH1D * hist0ratioData = (TH1D*) hist0varDataKplus ->Clone("hist0ratioData");
  1169. TH1D * hist0ratioMC = (TH1D*) hist0varMCKplus ->Clone("hist0ratioMC");
  1170. //Kplus
  1171. if(bLogVar){
  1172. hist0varDataCloneKplus ->SetTitle(Form("%i%s%s: data Kplus for Log(%s) [norm]", year, TheDecay.c_str(), "", variable.c_str()));
  1173. hist0varMCcloneKplus ->SetTitle(Form("%i%s%s: MC Kplus for Log(%s) [norm]", year, TheDecay.c_str(), "", variable.c_str()));
  1174. hist0ratioData ->SetTitle(Form("%i%s%s: ratio data Kplus/Kshort for Log(%s)", year, TheDecay.c_str(), KshortDecayInVelo ? " (LL)" : " (DD)", variable.c_str()));
  1175. }
  1176. else if(bLog1minusVar){
  1177. hist0varDataCloneKplus ->SetTitle(Form("%i%s%s: data Kplus for Log(1 - %s) [norm]", year, TheDecay.c_str(), (""), variable.c_str()));
  1178. hist0varMCcloneKplus ->SetTitle(Form("%i%s%s: MC Kplus for Log(1 - %s) [norm]", year, TheDecay.c_str(), (""), variable.c_str()));
  1179. hist0ratioData->SetTitle(Form("%i%s%s: ratio data Kplus/Kshort for Log(1 - %s)", year, TheDecay.c_str(), (KshortDecayInVelo ? " (LL)" : " (DD)"), variable.c_str()));
  1180. }
  1181. else{
  1182. hist0varDataCloneKplus ->SetTitle(Form("%i%s%s: data Kplus for %s [norm]", year, TheDecay.c_str(), (""), variable.c_str()));
  1183. hist0varMCcloneKplus ->SetTitle(Form("%i%s%s: MC Kplus for %s [norm]", year, TheDecay.c_str(), (""), variable.c_str()));
  1184. hist0ratioData->SetTitle(Form("%i%s%s: ratio data Kplus/Kshort for %s", year, TheDecay.c_str(), (KshortDecayInVelo ? " (LL)" : " (DD)"), variable.c_str()));
  1185. }
  1186. //Kshort
  1187. if(bLogVar){
  1188. hist0varDataCloneKshort->SetTitle(Form("%i%s%s: data Kshort for Log(%s) [norm]", year, TheDecay.c_str(), ((KshortDecayInVelo ? " (LL)" : " (DD)") ), variable.c_str()));
  1189. hist0varMCcloneKshort->SetTitle(Form("%i%s%s: MC Kshort for Log(%s) [norm]", year, TheDecay.c_str(), ( (KshortDecayInVelo ? " (LL)" : " (DD)")), variable.c_str()));
  1190. hist0ratioMC->SetTitle(Form("%i%s%s: ratio MC/data for Log(%s)", year, TheDecay.c_str(), ((KshortDecayInVelo ? " (LL)" : " (DD)") ), variable.c_str()));
  1191. }
  1192. else if(bLog1minusVar){
  1193. hist0varDataCloneKshort->SetTitle(Form("%i%s%s: data Kshort for Log(1 - %s) [norm]", year, TheDecay.c_str(), ( (KshortDecayInVelo ? " (LL)" : " (DD)") ), variable.c_str()));
  1194. hist0varMCcloneKshort->SetTitle(Form("%i%s%s: MC Kshort for Log(1 - %s) [norm]", year, TheDecay.c_str(), ((KshortDecayInVelo ? " (LL)" : " (DD)") ), variable.c_str()));
  1195. hist0ratioMC->SetTitle(Form("%i%s%s: ratio MC Kplus/Kshort for Log(1 - %s)", year, TheDecay.c_str(), ( (KshortDecayInVelo ? " (LL)" : " (DD)") ), variable.c_str()));
  1196. }
  1197. else{
  1198. hist0varDataCloneKshort->SetTitle(Form("%i%s%s: data Kshort for %s [norm]", year, TheDecay.c_str(), (KshortDecayInVelo ? " (LL)" : " (DD)") , variable.c_str()));
  1199. hist0varMCcloneKshort->SetTitle(Form("%i%s%s: MC Kshort for %s [norm]", year, TheDecay.c_str(), (KshortDecayInVelo ? " (LL)" : " (DD)") , variable.c_str()));
  1200. hist0ratioMC->SetTitle(Form("%i%s%s: ratio MC Kplus/Kshort for %s", year, TheDecay.c_str(), (KshortDecayInVelo ? " (LL)" : " (DD)") , variable.c_str()));
  1201. }
  1202. /// Sumw2 is already applied, so comment out the following 5 lines!
  1203. //Sumw2 uncertainties of all histos
  1204. //hist0varMC->Sumw2();
  1205. //hist0varMCclone->Sumw2();
  1206. //hist0varData->Sumw2();
  1207. //hist0varDataClone->Sumw2();
  1208. //hist0ratio->Sumw2();
  1209. //normalize the clones and the ratio histo
  1210. hist0varDataCloneKplus->Scale(1 / hist0varDataCloneKplus->Integral());
  1211. hist0varDataCloneKshort->Scale(1 / hist0varDataCloneKshort->Integral());
  1212. hist0ratioData ->Scale(1 / hist0ratioData->Integral());
  1213. hist0varMCcloneKplus ->Scale(1 / hist0varMCcloneKplus->Integral());
  1214. hist0varMCcloneKshort ->Scale(1 / hist0varMCcloneKshort->Integral());
  1215. hist0ratioMC ->Scale(1 / hist0ratioMC->Integral());
  1216. hist0ratioData->Divide(hist0varDataCloneKshort);
  1217. hist0ratioMC->Divide(hist0varMCcloneKshort);
  1218. //set correct ranges for the histograms:
  1219. //Data
  1220. double dNormalizedVariableMaxData = 0. , dRatioMaxData = 0., dNormalizedVariableMinData = 100. , dRatioMinData = 100.;
  1221. for(int bin = 1; bin <= nBinsData; bin++){
  1222. double dDataCloneKplus = hist0varDataCloneKplus->GetBinContent(bin);
  1223. double dDataCloneKshort = hist0varDataCloneKshort->GetBinContent(bin);
  1224. double dRatioData = hist0ratioData->GetBinContent(bin);
  1225. if(dNormalizedVariableMaxData <= dDataCloneKplus) dNormalizedVariableMaxData = dDataCloneKplus; //TODO (i nahore, fakt nechapu)
  1226. if(dNormalizedVariableMaxData <= dDataCloneKshort) dNormalizedVariableMaxData = dDataCloneKshort;
  1227. if(dRatioMaxData <= dRatioData) dRatioMaxData = dRatioData;
  1228. if(dNormalizedVariableMinData >= dDataCloneKplus) dNormalizedVariableMinData = dDataCloneKplus;
  1229. if(dNormalizedVariableMinData >= dDataCloneKshort) dNormalizedVariableMinData = dDataCloneKshort;
  1230. if(dRatioMinData >= dRatioData) dRatioMinData = dRatioData;
  1231. }
  1232. dNormalizedVariableMaxData *= 1.1;
  1233. if(dNormalizedVariableMinData < 0)dNormalizedVariableMinData *= 1.1;
  1234. else dNormalizedVariableMinData = 0.001; //if minimum is positve, set minimum to just above 0 to remove label
  1235. if(dRatioMaxData > 3.)dRatioMaxData = 3.;
  1236. if(dRatioMaxData < 2.)dRatioMaxData = 2.;
  1237. dRatioMaxData *= 1.1;
  1238. //set correct ranges for the histograms:
  1239. //MC
  1240. double dNormalizedVariableMaxMC = 0. , dRatioMaxMC = 0., dNormalizedVariableMinMC = 100. , dRatioMinMC = 100.;
  1241. for(int bin = 1; bin <= nBinsMC; bin++){
  1242. double dMCcloneKplus = hist0varMCcloneKplus->GetBinContent(bin);
  1243. double dMCcloneKshort = hist0varMCcloneKshort->GetBinContent(bin);
  1244. double dRatioMC = hist0ratioMC->GetBinContent(bin);
  1245. if(dNormalizedVariableMaxMC <= dMCcloneKplus) dNormalizedVariableMaxMC = dMCcloneKplus;
  1246. if(dNormalizedVariableMaxMC <= dMCcloneKshort) dNormalizedVariableMaxMC = dMCcloneKshort;
  1247. if(dRatioMaxMC <= dRatioMC) dRatioMaxMC = dRatioMC;
  1248. if(dNormalizedVariableMinMC >= dMCcloneKplus) dNormalizedVariableMinMC = dMCcloneKplus;
  1249. if(dNormalizedVariableMinMC >= dMCcloneKshort) dNormalizedVariableMinMC = dMCcloneKshort;
  1250. if(dRatioMinMC >= dRatioMC) dRatioMinMC = dRatioMC;
  1251. }
  1252. dNormalizedVariableMaxMC *= 1.1;
  1253. if(dNormalizedVariableMinMC < 0)dNormalizedVariableMinMC *= 1.1;
  1254. else dNormalizedVariableMinMC = 0.001; //if minimum is positve, set minimum to just above 0 to remove label
  1255. if(dRatioMaxMC > 3.)dRatioMaxMC = 3.;
  1256. if(dRatioMaxMC < 2.)dRatioMaxMC = 2.;
  1257. dRatioMaxMC *= 1.1;
  1258. //configurables for plotting
  1259. float lowerPlotHeight = 0.6;
  1260. /*********************************
  1261. *********************************
  1262. *
  1263. * DATA
  1264. *
  1265. *********************************
  1266. *********************************/
  1267. //create two pads into one canvas
  1268. TCanvas* c2= new TCanvas("c2", "ratio and superposition");
  1269. float textsize = gStyle->GetTextSize();
  1270. TPad *pad1 = new TPad("pad1", "ratio",0.0,lowerPlotHeight,1.0,1.0,0);
  1271. TPad *pad2 = new TPad("pad2", "superposition",0.0,0.0,1.0,lowerPlotHeight,0);
  1272. pad1->Draw();
  1273. pad2->Draw();
  1274. //modifiy pad for main plot
  1275. pad1->Clear();
  1276. pad1->SetBorderSize (0);
  1277. pad1->SetBottomMargin(1e-6);
  1278. pad1->SetTopMargin(pad1->GetTopMargin() / ( 1 - lowerPlotHeight) );
  1279. pad1->cd();
  1280. //some axis-modifications on the main plot
  1281. TGaxis::SetExponentOffset(1e+9,1e+9,"y");//offset = pad size * 1e+7
  1282. hist0ratioData->GetXaxis()->SetNoExponent(); //<-- spoils MaxDigits settings, so don't use it on other axis
  1283. hist0ratioData->GetXaxis()->SetLabelSize(0.0);//don't print labels
  1284. hist0ratioData->GetXaxis()->SetRangeUser(MinData, MaxData);
  1285. hist0ratioData->GetXaxis()->SetTickLength(hist0ratioData->GetXaxis()->GetTickLength()/(1-lowerPlotHeight));
  1286. hist0ratioData->GetXaxis()->SetNdivisions(gStyle->GetNdivisions("X"));
  1287. hist0ratioData->GetYaxis()->SetTitle("ratio data Kplus/Kshort");
  1288. hist0ratioData->GetYaxis()->SetTitleSize(textsize/(1-lowerPlotHeight));
  1289. hist0ratioData->GetYaxis()->SetLabelSize(textsize/(1-lowerPlotHeight));
  1290. hist0ratioData->GetYaxis()->SetTickLength(hist0ratioData->GetYaxis()->GetTickLength());
  1291. hist0ratioData->GetYaxis()->SetNdivisions(gStyle->GetNdivisions("Y"));
  1292. hist0ratioData->GetYaxis()->SetTitleOffset(1.06*(1-lowerPlotHeight));
  1293. hist0ratioData->GetYaxis()->SetRangeUser(0.001, 3);
  1294. hist0ratioData->Draw("E1");
  1295. TLine * unityline = new TLine(MinData, 1, MaxData, 1);
  1296. unityline->SetLineStyle(2);
  1297. unityline->SetLineColor(4);
  1298. unityline->Draw("SAME");
  1299. pad2->Clear();
  1300. pad2->SetBorderSize (0);
  1301. pad2->SetTopMargin (1e-6);
  1302. pad2->SetBottomMargin(pad2->GetBottomMargin() / lowerPlotHeight );
  1303. pad2->cd();
  1304. TGaxis::SetExponentOffset(1e+9,1e+9,"x");//offset = pad size * 1e+7
  1305. hist0varDataCloneKplus->GetXaxis()->SetTitleOffset(1.05);
  1306. hist0varDataCloneKplus->GetXaxis()->SetTitleSize (textsize/lowerPlotHeight);
  1307. hist0varDataCloneKplus->GetXaxis()->SetLabelSize (textsize/lowerPlotHeight);
  1308. hist0varDataCloneKplus->GetXaxis()->SetTickLength (hist0ratioData->GetXaxis()->GetTickLength()/(lowerPlotHeight/(1-lowerPlotHeight)));
  1309. hist0varDataCloneKplus->GetXaxis()->SetNdivisions (gStyle->GetNdivisions("X"));
  1310. hist0varDataCloneKplus->GetXaxis()->SetTitle(xaxistitle.c_str());
  1311. hist0varDataCloneKplus->GetXaxis()->SetRangeUser(MinData, MaxData);
  1312. hist0varDataCloneKplus->GetYaxis()->SetRangeUser(dNormalizedVariableMinData, dNormalizedVariableMaxData);
  1313. hist0varDataCloneKplus->GetYaxis()->SetTitle("weighted events");
  1314. hist0varDataCloneKplus->GetYaxis()->SetLabelSize (textsize/lowerPlotHeight);
  1315. hist0varDataCloneKplus->GetYaxis()->SetTitleSize (textsize/lowerPlotHeight);
  1316. hist0varDataCloneKplus->GetYaxis()->SetTickLength(hist0ratioData->GetYaxis()->GetTickLength());
  1317. hist0varDataCloneKplus->GetYaxis()->SetNdivisions (gStyle->GetNdivisions("Y"));
  1318. hist0varDataCloneKplus->GetYaxis()->SetTitleOffset(1.06*lowerPlotHeight);
  1319. hist0varDataCloneKplus->Draw("E1");
  1320. hist0varDataCloneKshort->SetLineColor(2);
  1321. hist0varDataCloneKshort->SetMarkerColor(2);
  1322. //hist0varMCclone->GetYaxis()->SetTitle("weighted events");
  1323. hist0varDataCloneKshort->Draw("E1SAME");
  1324. //Legend and position...
  1325. float LegendXposition = 0.4;
  1326. float LegendYposition = 0.62;
  1327. if(strcmp(variable.c_str(), "B_plus_DIRA_OWNPV") == 0)LegendXposition = 0.2;
  1328. else if(strcmp(variable.c_str(), "B_plus_IPCHI2_OWNPV") == 0)LegendXposition = 0.62;
  1329. else if(strcmp(variable.c_str(), "K_star_plus_IPCHI2_OWNPV") == 0)LegendXposition = 0.2;
  1330. else if(strcmp(variable.c_str(), "mu_minus_IPCHI2_OWNPV") == 0)LegendXposition = 0.62;
  1331. else if(strcmp(variable.c_str(), "mu_plus_IPCHI2_OWNPV") == 0)LegendXposition = 0.62;
  1332. else if(strcmp(variable.c_str(), (UseDTF ? "B_plus_ETA_DTF" :"B_plus_ETA" )) == 0)LegendXposition = 0.62;
  1333. else if(strcmp(variable.c_str(), (UseDTF ? "K_plus_ETA_DTF" :"K_plus_ETA")) == 0)LegendXposition = 0.52;
  1334. else if(strcmp(variable.c_str(), (UseDTF ? "K_star_plus_ETA_DTF" :"K_star_plus_ETA")) == 0)LegendXposition = 0.62;
  1335. else if(strcmp(variable.c_str(), "B_plus_NEW_ConePTasym") == 0)LegendXposition = 0.2;
  1336. if (variable.find("gamma1_PT") != std::string::npos){
  1337. LegendXposition = 0.5;
  1338. LegendYposition = 0.7;
  1339. }
  1340. else if (variable.find("mu_minus_IPCHI2_OWNPV") != std::string::npos){
  1341. LegendXposition = 0.5;
  1342. LegendYposition = 0.7;
  1343. } else if (variable.find("_CL") != std::string::npos){
  1344. LegendXposition = 0.3;
  1345. }
  1346. else if (variable.find("K_plus_PT") != std::string::npos){
  1347. LegendXposition = 0.62;
  1348. }
  1349. else if (variable.find("B_plus_PT") != std::string::npos){
  1350. LegendXposition = 0.62;
  1351. }
  1352. TLegend * leg = new TLegend(LegendXposition,LegendYposition,LegendXposition + 0.25, LegendYposition + 0.18);
  1353. /*
  1354. if(bLogVar) leg->SetHeader(Form("Log( %s )", variable.c_str()));
  1355. else if(bLog1minusVar) leg->SetHeader(Form("Log( 1 - %s )", variable.c_str()));
  1356. else leg->SetHeader(variable.c_str());
  1357. */
  1358. leg->AddEntry(hist0varDataCloneKplus,sWeightKplus? "sWeighted Kplus data" :" Kplus data" , "lpe");
  1359. leg->AddEntry(hist0varDataCloneKshort,sWeightKshort?"sWeighted Kshort data":" Kshort data", "lpe");
  1360. /*
  1361. if(b2Dweighted) leg->AddEntry(hist0varDataCloneKshort,"2 x 1D reweighted MC", "lpe"); //TODO
  1362. else if(bWeighted)leg->AddEntry(hist0varDataCloneKshort,"reweighted MC", "lpe");
  1363. else leg->AddEntry(hist0varDataCloneKshort,"non-weighted MC", "lpe");
  1364. */
  1365. leg->SetTextSize(0.04/lowerPlotHeight); // works fine
  1366. leg->Draw("same");
  1367. addLHCbtag(LegendXposition, LegendYposition + 0.27, "", 1, 1/lowerPlotHeight);
  1368. //Further plots, if needed!
  1369. TCanvas * c3;
  1370. TCanvas * c4;
  1371. if (!minimumPlot){
  1372. c3 = new TCanvas("c3", "ratio");
  1373. c3->Clear();
  1374. c3->cd();
  1375. hist0ratioData->GetYaxis()->SetRangeUser(0, dRatioMaxData);
  1376. hist0ratioData->GetYaxis()->SetTitle("ratio MC/data [norm.]");
  1377. hist0ratioData->Draw("E1");
  1378. unityline->Draw("SAME");
  1379. c4 = new TCanvas("c4", "overlay");
  1380. c4->Clear();
  1381. c4->cd();
  1382. hist0varDataCloneKplus->GetYaxis()->SetRangeUser(0, dNormalizedVariableMaxData);
  1383. hist0varDataCloneKplus->GetYaxis()->SetTitle("Weighted Decays / bin [norm.]");
  1384. hist0varDataCloneKplus->Draw("E1");
  1385. hist0varDataCloneKshort->SetLineColor(2);
  1386. hist0varDataCloneKshort->SetMarkerColor(2);
  1387. hist0varDataCloneKshort->GetYaxis()->SetTitle("Weighted Decays / bin [norm.]");
  1388. hist0varDataCloneKshort->Draw("E1SAME");
  1389. }
  1390. std::string WeightingOptions = "";
  1391. if(b2Dweighted)WeightingOptions.append("_2D_weighted");
  1392. if(bWeighted)WeightingOptions.append("_weighted");
  1393. if(ReferenceChannel)WeightingOptions.append("_Ref");
  1394. if (!sWeightKshort) WeightingOptions.append("_nosWeightKshort");
  1395. if (!sWeightKplus) WeightingOptions.append("_nosWeightKplus");
  1396. WeightingOptions.append("_KshortComparison");
  1397. if(bPrint){
  1398. c2->Print(Form("%s/ComparePlots/%i_%s%s_%s_%s.eps", path_to_output_KplusPizero.c_str(), year, TheDecay.c_str(), (KshortDecayInVelo ? "_LL" : "_DD"), variable.c_str(), WeightingOptions.c_str()));
  1399. //c2->SaveAs(Form("%s/ComparePlots/%i_%s%s_%s_MC_data%s.root", path_to_output_KplusPizero.c_str(), year, TheDecay.c_str(), (SplitDDandLL ? (KshortDecayInVelo ? "_LL" : "_DD") : ""), variable.c_str(), WeightingOptions.c_str()));
  1400. if (!minimumPlot){
  1401. c3->Print(Form("%s/ComparePlots/%i_%s%s_%s_ratio%s.eps", path_to_output_KplusPizero.c_str(), year, TheDecay.c_str(), (KshortDecayInVelo ? "_LL" : "_DD"), variable.c_str(), WeightingOptions.c_str()));
  1402. //c3->SaveAs(Form("%s/ComparePlots/%i_%s%s_%s_MC_data_ratio%s.root", path_to_output_KplusPizero.c_str(), year, (SplitDDandLL ? (KshortDecayInVelo ? "_LL" : "_DD") : ""), TheDecay.c_str(), variable.c_str(), WeightingOptions.c_str()));
  1403. c4->Print(Form("%s/ComparePlots/%i_%s%s_%s_overlay%s.eps", path_to_output_KplusPizero.c_str(), year, (KshortDecayInVelo ? "_LL" : "_DD"), TheDecay.c_str(), variable.c_str(), WeightingOptions.c_str()));
  1404. //c4->SaveAs(Form("%s/ComparePlots/%i_%s%s_%s_MC_data_overlay%s.root", path_to_output_KplusPizero.c_str(), year, (SplitDDandLL ? (KshortDecayInVelo ? "_LL" : "_DD") : ""), TheDecay.c_str(), variable.c_str(), WeightingOptions.c_str()));
  1405. }
  1406. }
  1407. c2->Close();
  1408. if (!minimumPlot){
  1409. c3->Close();
  1410. c4->Close();
  1411. }
  1412. delete c2;
  1413. if (!minimumPlot){
  1414. delete c3;
  1415. delete c4;
  1416. }
  1417. /*********************************
  1418. *********************************
  1419. *
  1420. * MC
  1421. *
  1422. *********************************
  1423. *********************************/
  1424. //create two pads into one canvas
  1425. TCanvas* c2MC= new TCanvas("c2MC", "ratio and superposition");
  1426. textsize = gStyle->GetTextSize();
  1427. c2MC->cd();
  1428. TPad *pad1MC = new TPad("pad1MC", "ratio",0.0,lowerPlotHeight,1.0,1.0,0);
  1429. TPad *pad2MC = new TPad("pad2MC", "superposition",0.0,0.0,1.0,lowerPlotHeight,0);
  1430. pad1MC->Draw();
  1431. pad2MC->Draw();
  1432. //modifiy pad for main plot
  1433. pad1MC->Clear();
  1434. pad1MC->SetBorderSize (0);
  1435. pad1MC->SetBottomMargin(1e-6);
  1436. pad1MC->SetTopMargin(pad1MC->GetTopMargin() / ( 1 - lowerPlotHeight) );
  1437. pad1MC->cd();
  1438. //some axis-modifications on the main plot
  1439. TGaxis::SetExponentOffset(1e+9,1e+9,"y");//offset = pad size * 1e+7
  1440. hist0ratioMC->GetXaxis()->SetNoExponent(); //<-- spoils MaxDigits settings, so don't use it on other axis
  1441. hist0ratioMC->GetXaxis()->SetLabelSize(0.0);//don't print labels
  1442. hist0ratioMC->GetXaxis()->SetRangeUser(MinMC, MaxMC);
  1443. hist0ratioMC->GetXaxis()->SetTickLength(hist0ratioMC->GetXaxis()->GetTickLength()/(1-lowerPlotHeight));
  1444. hist0ratioMC->GetXaxis()->SetNdivisions(gStyle->GetNdivisions("X"));
  1445. hist0ratioMC->GetYaxis()->SetTitle("ratio MC Kplus/Kshort");
  1446. hist0ratioMC->GetYaxis()->SetTitleSize(textsize/(1-lowerPlotHeight));
  1447. hist0ratioMC->GetYaxis()->SetLabelSize(textsize/(1-lowerPlotHeight));
  1448. hist0ratioMC->GetYaxis()->SetTickLength(hist0ratioMC->GetYaxis()->GetTickLength());
  1449. hist0ratioMC->GetYaxis()->SetNdivisions(gStyle->GetNdivisions("Y"));
  1450. hist0ratioMC->GetYaxis()->SetTitleOffset(1.06*(1-lowerPlotHeight));
  1451. hist0ratioMC->GetYaxis()->SetRangeUser(0.001, 3);
  1452. hist0ratioMC->Draw("E1");
  1453. TLine * unitylineMC = new TLine(MinMC, 1, MaxMC, 1);
  1454. unitylineMC->SetLineStyle(2);
  1455. unitylineMC->SetLineColor(4);
  1456. unitylineMC->Draw("SAME");
  1457. pad2MC->Clear();
  1458. pad2MC->SetBorderSize (0);
  1459. pad2MC->SetTopMargin (1e-6);
  1460. pad2MC->SetBottomMargin(pad2MC->GetBottomMargin() / lowerPlotHeight );
  1461. pad2MC->cd();
  1462. TGaxis::SetExponentOffset(1e+9,1e+9,"x");//offset = pad size * 1e+7
  1463. hist0varMCcloneKplus->GetXaxis()->SetTitleOffset(1.05);
  1464. hist0varMCcloneKplus->GetXaxis()->SetTitleSize (textsize/lowerPlotHeight);
  1465. hist0varMCcloneKplus->GetXaxis()->SetLabelSize (textsize/lowerPlotHeight);
  1466. hist0varMCcloneKplus->GetXaxis()->SetTickLength (hist0ratioMC->GetXaxis()->GetTickLength()/(lowerPlotHeight/(1-lowerPlotHeight)));
  1467. hist0varMCcloneKplus->GetXaxis()->SetNdivisions (gStyle->GetNdivisions("X"));
  1468. hist0varMCcloneKplus->GetXaxis()->SetTitle(xaxistitle.c_str());
  1469. hist0varMCcloneKplus->GetXaxis()->SetRangeUser(MinMC, MaxMC);
  1470. hist0varMCcloneKplus->GetYaxis()->SetRangeUser(dNormalizedVariableMinMC, dNormalizedVariableMaxMC);
  1471. hist0varMCcloneKplus->GetYaxis()->SetTitle("weighted events");
  1472. hist0varMCcloneKplus->GetYaxis()->SetLabelSize (textsize/lowerPlotHeight);
  1473. hist0varMCcloneKplus->GetYaxis()->SetTitleSize (textsize/lowerPlotHeight);
  1474. hist0varMCcloneKplus->GetYaxis()->SetTickLength(hist0ratioMC->GetYaxis()->GetTickLength());
  1475. hist0varMCcloneKplus->GetYaxis()->SetNdivisions (gStyle->GetNdivisions("Y"));
  1476. hist0varMCcloneKplus->GetYaxis()->SetTitleOffset(1.06*lowerPlotHeight);
  1477. hist0varMCcloneKplus->Draw("E1");
  1478. hist0varMCcloneKshort->SetLineColor(2);
  1479. hist0varMCcloneKshort->SetMarkerColor(2);
  1480. //hist0varMCclone->GetYaxis()->SetTitle("weighted events");
  1481. hist0varMCcloneKshort->Draw("E1SAME");
  1482. TLegend * legMC = new TLegend(LegendXposition,LegendYposition,LegendXposition + 0.25, LegendYposition + 0.18);
  1483. /*
  1484. if(bLogVar) legMC->SetHeader(Form("Log( %s )", variable.c_str()));
  1485. else if(bLog1minusVar) legMC->SetHeader(Form("Log( 1 - %s )", variable.c_str()));
  1486. else legMC->SetHeader(variable.c_str());
  1487. */
  1488. legMC->AddEntry(hist0varMCcloneKplus, "Kplus MC" , "lpe");
  1489. legMC->AddEntry(hist0varMCcloneKshort,"Kshort MC", "lpe");
  1490. /*
  1491. if(b2Dweighted) legMC->AddEntry(hist0varMCcloneKshort,"2 x 1D reweighted MC", "lpe"); //TODO
  1492. else if(bWeighted)legMC->AddEntry(hist0varMCcloneKshort,"reweighted MC", "lpe");
  1493. else legMC->AddEntry(hist0varMCcloneKshort,"non-weighted MC", "lpe");
  1494. */
  1495. legMC->SetTextSize(0.04/lowerPlotHeight); // works fine
  1496. legMC->Draw("same");
  1497. addLHCbtag(LegendXposition, LegendYposition + 0.27, "", 1, 1/lowerPlotHeight);
  1498. //Further plots, if needed!
  1499. TCanvas * c3MC;
  1500. TCanvas * c4MC;
  1501. if (!minimumPlot){
  1502. c3MC = new TCanvas("c3MC", "ratio");
  1503. c3MC->Clear();
  1504. c3MC->cd();
  1505. hist0ratioMC->GetYaxis()->SetRangeUser(0, dRatioMaxMC);
  1506. hist0ratioMC->GetYaxis()->SetTitle("ratio MC Kplus/Kshort [norm.]");
  1507. hist0ratioMC->Draw("E1");
  1508. unitylineMC->Draw("SAME");
  1509. c4MC = new TCanvas("c4MC", "overlay");
  1510. c4MC->Clear();
  1511. c4MC->cd();
  1512. hist0varMCcloneKplus->GetYaxis()->SetRangeUser(0, dNormalizedVariableMaxMC);
  1513. hist0varMCcloneKplus->GetYaxis()->SetTitle("Weighted Decays / bin [norm.]");
  1514. hist0varMCcloneKplus->Draw("E1");
  1515. hist0varMCcloneKshort->SetLineColor(2);
  1516. hist0varMCcloneKshort->SetMarkerColor(2);
  1517. hist0varMCcloneKshort->GetYaxis()->SetTitle("Weighted Decays / bin [norm.]");
  1518. hist0varMCcloneKshort->Draw("E1SAME");
  1519. }
  1520. WeightingOptions = "";
  1521. if(b2Dweighted)WeightingOptions.append("_2D_weighted");
  1522. if(bWeighted)WeightingOptions.append("_weighted");
  1523. if(ReferenceChannel)WeightingOptions.append("_Ref");
  1524. WeightingOptions.append("_KshortComparison");
  1525. if(bPrint){
  1526. c2MC->Print(Form("%s/ComparePlots/%i_%s%s_%s_%s_MC.eps", path_to_output_KplusPizero.c_str(), year, TheDecay.c_str(), (KshortDecayInVelo ? "_LL" : "_DD"), variable.c_str(), WeightingOptions.c_str()));
  1527. //c2MC->SaveAs(Form("%s/ComparePlots/%i_%s%s_%s_MC_data%s.root", path_to_output_KplusPizero.c_str(), year, TheDecay.c_str(), (SplitDDandLL ? (KshortDecayInVelo ? "_LL" : "_DD") : ""), variable.c_str(), WeightingOptions.c_str()));
  1528. if (!minimumPlot){
  1529. c3MC->Print(Form("%s/ComparePlots/%i_%s%s_%s_ratio%s_MC.eps", path_to_output_KplusPizero.c_str(), year, TheDecay.c_str(), (KshortDecayInVelo ? "_LL" : "_DD"), variable.c_str(), WeightingOptions.c_str()));
  1530. //c3MC->SaveAs(Form("%s/ComparePlots/%i_%s%s_%s_MC_data_ratio%s.root", path_to_output_KplusPizero.c_str(), year, (SplitDDandLL ? (KshortDecayInVelo ? "_LL" : "_DD") : ""), TheDecay.c_str(), variable.c_str(), WeightingOptions.c_str()));
  1531. c4MC->Print(Form("%s/ComparePlots/%i_%s%s_%s_overlay%s_MC.eps", path_to_output_KplusPizero.c_str(), year, (KshortDecayInVelo ? "_LL" : "_DD"), TheDecay.c_str(), variable.c_str(), WeightingOptions.c_str()));
  1532. //c4MC->SaveAs(Form("%s/ComparePlots/%i_%s%s_%s_MC_data_overlay%s.root", path_to_output_KplusPizero.c_str(), year, (SplitDDandLL ? (KshortDecayInVelo ? "_LL" : "_DD") : ""), TheDecay.c_str(), variable.c_str(), WeightingOptions.c_str()));
  1533. }
  1534. }
  1535. c2MC->Close();
  1536. if (!minimumPlot){
  1537. c3MC->Close();
  1538. c4MC->Close();
  1539. }
  1540. delete c2MC;
  1541. if (!minimumPlot){
  1542. delete c3MC;
  1543. delete c4MC;
  1544. }
  1545. delete hist0ratioData;
  1546. delete hist0ratioMC;
  1547. delete hist0varDataKplus;
  1548. delete hist0varDataCloneKplus;
  1549. delete hist0varDataKshort;
  1550. delete hist0varDataCloneKshort;
  1551. delete hist0varMCKplus;
  1552. delete hist0varMCcloneKplus;
  1553. delete hist0varMCKshort;
  1554. delete hist0varMCcloneKshort;
  1555. delete treeDataKshort;
  1556. delete treeDataKplus;
  1557. delete treeMCKplus;
  1558. delete treeMCKshort;
  1559. return 1;
  1560. }
  1561. /////////////////////////////////////////////////////
  1562. ///
  1563. /// comparison of all Kshort variables:
  1564. ///
  1565. /////////////////////////////////////////////////////
  1566. int compareAllKshorts(bool sWeight = true, bool bWeighted = true, bool b2DWeighted = true, int Run = 1, std::string weightBranch = firstMCweight){
  1567. checkRun(Run);
  1568. bool save2file = true;
  1569. bool SplitIntoDDandLL = true;
  1570. int nYear = (Run == 1 ? 2011 : 2015);
  1571. while(nYear < (Run == 1 ? 2013 : 2019)){
  1572. int iteration = 1;
  1573. bool KshortDecayInVelo = true;
  1574. while((SplitIntoDDandLL || iteration == 1) && iteration < 3){
  1575. compareVariables(nYear, "nTracks", sWeight, bWeighted, b2DWeighted, false, false, save2file, KshortDecayInVelo, weightBranch);
  1576. compareVariables(nYear, "B_plus_DIRA_OWNPV", sWeight, bWeighted, b2DWeighted, false, true, save2file, KshortDecayInVelo, weightBranch);
  1577. //compareVariables(nYear, "B_plus_OWNPV_CHI2", sWeight, bWeighted, b2DWeighted, false, false, save2file, KshortDecayInVelo, weightBranch);
  1578. compareVariables(nYear, "B_plus_IPCHI2_OWNPV", sWeight, bWeighted, b2DWeighted, true, false, save2file, KshortDecayInVelo, weightBranch);
  1579. compareVariables(nYear, "B_plus_ENDVERTEX_CHI2", sWeight, bWeighted, b2DWeighted, false, false, save2file, KshortDecayInVelo, weightBranch);
  1580. compareVariables(nYear, "B_plus_FD_OWNPV", sWeight, bWeighted, b2DWeighted, false, false, save2file, KshortDecayInVelo, weightBranch);
  1581. compareVariables(nYear, "B_plus_IP_OWNPV", sWeight, bWeighted, b2DWeighted, false, false, save2file, KshortDecayInVelo, weightBranch);
  1582. compareVariables(nYear, UseDTF?"B_plus_PT_DTF":"B_plus_PT", sWeight, bWeighted, b2DWeighted, false, false, save2file, KshortDecayInVelo, weightBranch);
  1583. //compareVariables(nYear, "B_plus_DOCA1", sWeight, bWeighted, b2DWeighted, false, false, save2file, KshortDecayInVelo, weightBranch);
  1584. compareVariables(nYear, "B_plus_NEW_ConePTasym", sWeight, bWeighted, b2DWeighted, false, false, save2file, KshortDecayInVelo, weightBranch);
  1585. //compareVariables(nYear, "B_plus_DTF_chi2", sWeight, bWeighted, b2DWeighted, false, false, save2file, KshortDecayInVelo, weightBranch);
  1586. //compareVariables(nYear, "K_star_plus_NEW_ConePTasym", sWeight, bWeighted, b2DWeighted, false, false, save2file, KshortDecayInVelo, weightBranch);
  1587. compareVariables(nYear, UseDTF?"K_star_plus_PT_DTF":"K_star_plus_PT", sWeight, bWeighted, b2DWeighted, false, false, save2file, KshortDecayInVelo, weightBranch);
  1588. compareVariables(nYear, "K_star_plus_IPCHI2_OWNPV", sWeight, bWeighted, b2DWeighted, true, false, save2file, KshortDecayInVelo, weightBranch);
  1589. compareVariables(nYear, "mu_plus_IPCHI2_OWNPV", sWeight, bWeighted, b2DWeighted, true, false, save2file, KshortDecayInVelo, weightBranch);
  1590. compareVariables(nYear, "mu_minus_IPCHI2_OWNPV", sWeight, bWeighted, b2DWeighted, true, false, save2file, KshortDecayInVelo, weightBranch);
  1591. //compareVariables(nYear, "mu_plus_NEW_ConePTasym", sWeight, bWeighted, b2DWeighted, false, false, save2file, KshortDecayInVelo, weightBranch);
  1592. //compareVariables(nYear, "mu_minus_NEW_ConePTasym", sWeight, bWeighted, b2DWeighted, false, false, save2file, KshortDecayInVelo, weightBranch);
  1593. compareVariables(nYear, "K_short_IPCHI2_OWNPV", sWeight, bWeighted, b2DWeighted, true, false, save2file, KshortDecayInVelo, weightBranch);
  1594. compareVariables(nYear, "K_short_FD_OWNPV", sWeight, bWeighted, b2DWeighted, false, false, save2file, KshortDecayInVelo, weightBranch);
  1595. compareVariables(nYear, UseDTF?"K_short_PT_DTF":"K_short_PT", sWeight, bWeighted, b2DWeighted, false, false, save2file, KshortDecayInVelo, weightBranch);
  1596. compareVariables(nYear, "K_short_DIRA_OWNPV", sWeight, bWeighted, b2DWeighted, false, true, save2file, KshortDecayInVelo, weightBranch);
  1597. compareVariables(nYear, "pi_plus_IPCHI2_OWNPV", sWeight, bWeighted, b2DWeighted, true, false, save2file, KshortDecayInVelo, weightBranch);
  1598. compareVariables(nYear, UseDTF?"pi_plus_PT_DTF":"pi_plus_PT", sWeight, bWeighted, b2DWeighted, false, false, save2file, KshortDecayInVelo, weightBranch);
  1599. //compareVariables(nYear, "Ks_pi_plus_PT"+(UseDTF?"_DTF":""), sWeight, bWeighted, b2DWeighted, false, false, save2file, KshortDecayInVelo, weightBranch);
  1600. //compareVariables(nYear, "Ks_pi_minus_PT"+(UseDTF?"_DTF":""),sWeight, bWeighted, b2DWeighted, false, false, save2file, KshortDecayInVelo, weightBranch);
  1601. KshortDecayInVelo = false;
  1602. iteration++;
  1603. }
  1604. nYear++;
  1605. }
  1606. return 1;
  1607. }
  1608. int compareAllKshortsWeightedAndUnweighted(){
  1609. //not weighted
  1610. compareAllKshorts(false, false);
  1611. //1D weighted
  1612. compareAllKshorts(true, false);
  1613. //2D weighted
  1614. compareAllKshorts(true, true);
  1615. return 1;
  1616. }
  1617. int compareKshortPreSelectionAndStrippingVariables(int Run = 1){
  1618. checkRun(Run);
  1619. bool sWeight = true;
  1620. bool bWeighted = true;
  1621. bool b2DWeighted = true;
  1622. bool save2file = true;
  1623. bool SplitIntoDDandLL = true;
  1624. int nYear = (Run == 1 ? 2011 : 2015);
  1625. std::string weightBranch = "nTracks";
  1626. while(nYear < (Run == 1 ? 2013 : 2019)){
  1627. int iteration = 1;
  1628. bool KshortDecayInVelo = true;
  1629. while((SplitIntoDDandLL || iteration == 1) && iteration < 3){
  1630. //pre selection PID cuts:
  1631. compareVariables(nYear, "pi_plus_PIDK", sWeight, bWeighted, b2DWeighted, false, false, save2file, KshortDecayInVelo, weightBranch);
  1632. compareVariables(nYear, "mu_plus_ProbNNmu", sWeight, bWeighted, b2DWeighted, false, false, save2file, KshortDecayInVelo, weightBranch);
  1633. compareVariables(nYear, "mu_minus_ProbNNmu", sWeight, bWeighted, b2DWeighted, false, false, save2file, KshortDecayInVelo, weightBranch);
  1634. //stripping
  1635. // compareVariables(nYear, "", sWeight, bWeighted, b2DWeighted, false, false, save2file, KshortDecayInVelo, weightBranch);
  1636. KshortDecayInVelo = false;
  1637. iteration++;
  1638. }
  1639. nYear++;
  1640. }
  1641. return 1;
  1642. }
  1643. int compareKshortMVAonly( bool sWeight = true, bool bWeighted = true, bool b2DWeighted = true, int Run = 1, std::string weightBranch = firstMCweight){
  1644. checkRun(Run);
  1645. bool save2file = true;
  1646. bool runDDandLLforAllVariables = true;
  1647. //Load the MVA config from the txt file
  1648. MVA_variables varsDD("DD");
  1649. MVA_variables varsLL("LL");
  1650. std::cout << "Get compare plots for these variables: " << std::endl;
  1651. std::cout << "DD tracks: " << std::endl;
  1652. varsDD.print();
  1653. std::cout << "LL tracks: " << std::endl;
  1654. varsLL.print();
  1655. bool bLogX = false, bLog1X = false;
  1656. int nYear = (Run == 1 ? 2011 : 2015);
  1657. while(nYear < (Run == 1 ? 2013 : 2019)){
  1658. //DD tracks
  1659. for(int i = 0, j = 0; i < varsDD.NumberOfVariables(); i++){
  1660. bLogX = false;
  1661. bLog1X = false;
  1662. if(strcmp(varsDD.AllVariables.at(i).Formula.c_str(), "log(x)") == 0){
  1663. bLogX = true;
  1664. bLog1X = false;
  1665. }
  1666. else if(strcmp(varsDD.AllVariables.at(i).Formula.c_str(), "log(1-x)") == 0){
  1667. bLogX = false;
  1668. bLog1X = true;
  1669. }
  1670. if(compareVariables(nYear, varsDD.AllBranches.at(j),sWeight, bWeighted, b2DWeighted, bLogX, bLog1X, save2file, false, weightBranch) == 0)return 0;
  1671. if(runDDandLLforAllVariables)
  1672. if(compareVariables(nYear, varsDD.AllBranches.at(j),sWeight, bWeighted, b2DWeighted, bLogX, bLog1X, save2file, true, weightBranch) == 0)return 0;
  1673. j += varsDD.AllVariables.at(i).NoBr;
  1674. }
  1675. //LL tracks
  1676. for(int i = 0, j = 0; i < varsLL.NumberOfVariables(); i++){
  1677. if(strcmp(varsLL.AllVariables.at(i).Formula.c_str(), "log(x)") == 0)bLogX = true;
  1678. else if(strcmp(varsLL.AllVariables.at(i).Formula.c_str(), "log(1-x)") == 0)bLog1X = true;
  1679. else{
  1680. bLogX = false;
  1681. bLog1X = false;
  1682. }
  1683. if(compareVariables(nYear, varsLL.AllBranches.at(j),sWeight, bWeighted, b2DWeighted, bLogX, bLog1X, save2file, true, weightBranch) == 0)return 0;
  1684. if(runDDandLLforAllVariables)
  1685. if(compareVariables(nYear, varsLL.AllBranches.at(j),sWeight, bWeighted, b2DWeighted, bLogX, bLog1X, save2file, false, weightBranch) == 0)return 0;
  1686. j += varsLL.AllVariables.at(i).NoBr;
  1687. }
  1688. for(int ddll = 0; ddll < 2; ddll++){
  1689. //also compare nPV and B_plus_PT (risk of running double, if used in MVA, but who cares :)
  1690. if(compareVariables(nYear, "nPV", sWeight, bWeighted, b2DWeighted, bLogX, bLog1X, save2file, ddll, weightBranch) == 0) return 0;
  1691. if(compareVariables(nYear, "nLongTracks", sWeight, bWeighted, b2DWeighted, bLogX, bLog1X, save2file, ddll, weightBranch) == 0) return 0;
  1692. if(compareVariables(nYear, (UseDTF ? "B_plus_PT_DTF" : "B_plus_PT"), sWeight, bWeighted, b2DWeighted, bLogX, bLog1X, save2file, ddll, weightBranch) == 0) return 0;
  1693. ////also compare pT and eta of all daughters
  1694. if(compareVariables(nYear, (UseDTF ? "Ks_pi_minus_PT_DTF" : "Ks_pi_minus_PT"), sWeight, bWeighted, b2DWeighted, bLogX, bLog1X, save2file, ddll, weightBranch) == 0) return 0;
  1695. if(compareVariables(nYear, (UseDTF ? "Ks_pi_plus_PT_DTF" : "Ks_pi_plus_PT"), sWeight, bWeighted, b2DWeighted, bLogX, bLog1X, save2file, ddll, weightBranch) == 0) return 0;
  1696. if(compareVariables(nYear, (UseDTF ? "K_star_plus_PT_DTF" : "K_star_plus_PT"), sWeight, bWeighted, b2DWeighted, bLogX, bLog1X, save2file, ddll, weightBranch) == 0) return 0;
  1697. if(compareVariables(nYear, (UseDTF ? "K_short_PT_DTF" : "K_short_PT"), sWeight, bWeighted, b2DWeighted, bLogX, bLog1X, save2file, ddll, weightBranch) == 0) return 0;
  1698. if(compareVariables(nYear, (UseDTF ? "pi_plus_PT_DTF" : "pi_plus_PT"), sWeight, bWeighted, b2DWeighted, bLogX, bLog1X, save2file, ddll, weightBranch) == 0) return 0;
  1699. if(compareVariables(nYear, (UseDTF ? "mu_plus_PT_DTF" : "mu_plus_PT"), sWeight, bWeighted, b2DWeighted, bLogX, bLog1X, save2file, ddll, weightBranch) == 0) return 0;
  1700. if(compareVariables(nYear, (UseDTF ? "mu_minus_PT_DTF" : "mu_minus_PT"), sWeight, bWeighted, b2DWeighted, bLogX, bLog1X, save2file, ddll, weightBranch) == 0) return 0;
  1701. if(compareVariables(nYear, (UseDTF ? "Ks_pi_minus_ETA_DTF" : "Ks_pi_minus_ETA"), sWeight, bWeighted, b2DWeighted, bLogX, bLog1X, save2file, ddll, weightBranch) == 0) return 0;
  1702. if(compareVariables(nYear, (UseDTF ? "Ks_pi_plus_ETA_DTF" : "Ks_pi_plus_ETA"), sWeight, bWeighted, b2DWeighted, bLogX, bLog1X, save2file, ddll, weightBranch) == 0) return 0;
  1703. if(compareVariables(nYear, (UseDTF ? "K_star_plus_ETA_DTF" : "K_star_plus_ETA"), sWeight, bWeighted, b2DWeighted, bLogX, bLog1X, save2file, ddll, weightBranch) == 0) return 0;
  1704. if(compareVariables(nYear, (UseDTF ? "K_short_ETA_DTF" : "K_short_ETA"), sWeight, bWeighted, b2DWeighted, bLogX, bLog1X, save2file, ddll, weightBranch) == 0) return 0;
  1705. if(compareVariables(nYear, (UseDTF ? "pi_plus_ETA_DTF" : "pi_plus_ETA"), sWeight, bWeighted, b2DWeighted, bLogX, bLog1X, save2file, ddll, weightBranch) == 0) return 0;
  1706. }
  1707. nYear++;
  1708. }
  1709. return 1;
  1710. }
  1711. /////////////////////////////////////////////////////
  1712. ///
  1713. /// comparison of all Kplus variables:
  1714. ///
  1715. /////////////////////////////////////////////////////
  1716. int compareMuIPKplusResolved(int Run = 1, std::string weightBranch = firstMCweight){
  1717. checkRun(Run);
  1718. bool save2file = true;
  1719. vector<int>years = yearsVectorInt(true,false,false,Run);
  1720. for (auto nYear: years){
  1721. /// mu
  1722. compareVariables(nYear, "mu_plus_IPCHI2_OWNPV", true, true, true, 1, 0, save2file, false, weightBranch);
  1723. compareVariables(nYear, "mu_minus_IPCHI2_OWNPV", true, true, true, 1, 0, save2file, false, weightBranch);
  1724. nYear++;
  1725. if (nYear==2013) nYear =2015;
  1726. }
  1727. return 1;
  1728. }
  1729. int compareAllKplusResolved(bool sWeight = true, bool bWeighted = true, bool b2DWeighted = false, int Run = 1, std::string weightBranch = firstMCweight){
  1730. checkRun(Run);
  1731. bool save2file = true;
  1732. weightBranch = firstMCweight + "_TM_rndGamma";
  1733. vector<int>years = yearsVectorInt(true,false,true,Run); //Set to PHSP, otherwise 2015 wouldn't be done
  1734. for (auto nYear: years){ //Why is this not a vector is beyond me
  1735. //Global
  1736. compareVariables(nYear, "nTracks", sWeight, bWeighted, b2DWeighted, 0, 0, save2file, false, weightBranch);
  1737. compareVariables(nYear, "nLongTracks", sWeight, bWeighted, b2DWeighted, 0, 0, save2file, false, weightBranch);
  1738. compareVariables(nYear, "nVeloTracks", sWeight, bWeighted, b2DWeighted, 0, 0, save2file, false, weightBranch);
  1739. compareVariables(nYear, "nTTracks", sWeight, bWeighted, b2DWeighted, 0, 0, save2file, false, weightBranch);
  1740. compareVariables(nYear, "nUpstreamTracks", sWeight, bWeighted, b2DWeighted, 0, 0, save2file, false, weightBranch);
  1741. compareVariables(nYear, "nDownstreamTracks", sWeight, bWeighted, b2DWeighted, 0, 0, save2file, false, weightBranch);
  1742. ///B+
  1743. compareVariables(nYear, "B_plus_DIRA_OWNPV", sWeight, bWeighted, b2DWeighted, 0, 1, save2file, false, weightBranch);
  1744. compareVariables(nYear, "B_plus_OWNPV_CHI2", sWeight, bWeighted, b2DWeighted, 1, 0, save2file, false, weightBranch);
  1745. compareVariables(nYear, "B_plus_FD_OWNPV", sWeight, bWeighted, b2DWeighted, 0, 0, save2file, false, weightBranch);
  1746. compareVariables(nYear, (UseDTF?"B_plus_PT_DTF":"B_plus_PT"), sWeight, bWeighted, b2DWeighted, 0, 0, save2file, false, weightBranch);
  1747. compareVariables(nYear, "B_plus_IP_OWNPV", sWeight, bWeighted, b2DWeighted, 0, 0, save2file, false, weightBranch);
  1748. compareVariables(nYear, "B_plus_IPCHI2_OWNPV", sWeight, bWeighted, b2DWeighted, 1, 0, save2file, false, weightBranch);
  1749. //compareVariables(nYear, "B_plus_DOCA1", sWeight, bWeighted, b2DWeighted, 0, 0, save2file, false, weightBranch);
  1750. compareVariables(nYear, "B_plus_NEW_ConePTasym", sWeight, bWeighted, b2DWeighted, 0, 0, save2file, false, weightBranch);
  1751. compareVariables(nYear, "B_plus_NEW_ConePT", sWeight, bWeighted, b2DWeighted, 0, 0, save2file, false, weightBranch);
  1752. compareVariables(nYear, "B_plus_NEW_ConePasym", sWeight, bWeighted, b2DWeighted, 0, 0, save2file, false, weightBranch);
  1753. compareVariables(nYear, "B_plus_NEW_ConeP", sWeight, bWeighted, b2DWeighted, 0, 0, save2file, false, weightBranch);
  1754. compareVariables(nYear, (UseDTF ? "B_plus_ETA_DTF":"B_plus_ETA"),sWeight, bWeighted, b2DWeighted, 0, 0, save2file, false, weightBranch);
  1755. /// K*
  1756. compareVariables(nYear, (UseDTF ? "K_star_plus_PT_DTF":"K_star_plus_PT"), sWeight, bWeighted, b2DWeighted, 0, 0, save2file, false, weightBranch);
  1757. compareVariables(nYear, (UseDTF ? "K_star_plus_ETA_DTF":"K_star_plus_ETA"), sWeight, bWeighted, b2DWeighted, 0, 0, save2file, false, weightBranch);
  1758. compareVariables(nYear, "K_star_plus_IPCHI2_OWNPV", sWeight, bWeighted, b2DWeighted, 0, 0, save2file, false, weightBranch);
  1759. /// mu
  1760. compareVariables(nYear, "mu_plus_IPCHI2_OWNPV", sWeight, bWeighted, b2DWeighted, 1, 0, save2file, false, weightBranch);
  1761. compareVariables(nYear, "mu_minus_IPCHI2_OWNPV", sWeight, bWeighted, b2DWeighted, 1, 0, save2file, false, weightBranch);
  1762. ///K+
  1763. compareVariables(nYear, "K_plus_IPCHI2_OWNPV", sWeight, bWeighted, b2DWeighted, 0, 0, save2file, false, weightBranch);
  1764. compareVariables(nYear, "K_plus_TRACK_CHI2NDOF", sWeight, bWeighted, b2DWeighted, 0, 0, save2file, false, weightBranch);
  1765. compareVariables(nYear, (UseDTF ? "K_plus_PT_DTF":"K_plus_PT"), sWeight, bWeighted, b2DWeighted, 0, 0, save2file, false, weightBranch);
  1766. compareVariables(nYear, (UseDTF ? "K_plus_ETA_DTF":"K_plus_ETA"),sWeight, bWeighted, b2DWeighted, 0, 0, save2file, false, weightBranch);
  1767. /// pi0
  1768. compareVariables(nYear, UseDTF ? "pi_zero_resolved_PT_DTF":"pi_zero_resolved_PT", sWeight, bWeighted, b2DWeighted, 0, 0, save2file, false, weightBranch);
  1769. compareVariables(nYear, UseDTF ? "pi_zero_resolved_ETA_DTF":"pi_zero_resolved_ETA", sWeight, bWeighted, b2DWeighted, 0, 0, save2file, false, weightBranch);
  1770. compareVariables(nYear, "pi_zero_resolved_CL", sWeight, bWeighted, b2DWeighted, 0, 0, save2file, false, weightBranch);
  1771. //compareVariables(nYear, "K_plus_PI0_ETA", sWeight, bWeighted, b2DWeighted, 0, 0, save2file, false, weightBranch); //TODO: check!!!
  1772. //gamma
  1773. compareVariables(nYear, (UseDTF ? "gamma1_PT_DTF":"gamma1_PT"), sWeight, bWeighted, b2DWeighted, 1, 0, save2file, false, weightBranch);
  1774. compareVariables(nYear, (UseDTF ? "gamma2_PT_DTF":"gamma2_PT"), sWeight, bWeighted, b2DWeighted, 1, 0, save2file, false, weightBranch);
  1775. compareVariables(nYear, "gamma1_CL", sWeight, bWeighted, b2DWeighted, 0, 0, save2file, false, weightBranch);
  1776. compareVariables(nYear, "gamma2_CL", sWeight, bWeighted, b2DWeighted, 0, 0, save2file, false, weightBranch);
  1777. compareVariables(nYear, "open_angle", sWeight, bWeighted, b2DWeighted, 0, 0, save2file, false, weightBranch);
  1778. nYear++;
  1779. }
  1780. return 1;
  1781. }
  1782. int compareAllKplusMerged(bool sWeight = true, bool bWeighted = true, bool b2DWeighted = false, int Run = 1, std::string weightBranch = firstMCweight){
  1783. checkRun(Run);
  1784. bool save2file = true;
  1785. int nYear = (Run == 1 ? 2011 : 2015);
  1786. while(nYear < (Run == 1 ? 2013 : 2018)){
  1787. ///B+
  1788. compareVariables(nYear, "B_plus_DIRA_OWNPV", sWeight, bWeighted, b2DWeighted, 0, 1, save2file, false, weightBranch);
  1789. compareVariables(nYear, "B_plus_OWNPV_CHI2", sWeight, bWeighted, b2DWeighted, 1, 0, save2file, false, weightBranch);
  1790. compareVariables(nYear, "B_plus_FD_OWNPV", sWeight, bWeighted, b2DWeighted, 0, 0, save2file, false, weightBranch);
  1791. compareVariables(nYear, (UseDTF ? "B_plus_PT_DTF":"B_plus_PT"), sWeight, bWeighted, b2DWeighted, 0, 0, save2file, false, weightBranch);
  1792. compareVariables(nYear, "B_plus_IP_OWNPV", sWeight, bWeighted, b2DWeighted, 0, 0, save2file, false, weightBranch);
  1793. //compareVariables(nYear, "B_plus_DOCA1", sWeight, bWeighted, b2DWeighted, 0, 0, save2file, false, weightBranch);
  1794. compareVariables(nYear, "B_plus_NEW_ConePTasym", sWeight, bWeighted, b2DWeighted, 0, 0, save2file, false, weightBranch);
  1795. compareVariables(nYear, (UseDTF ? "B_plus_ETA_DTF":"B_plus_ETA"),sWeight, bWeighted, b2DWeighted, 0, 0, save2file, false, weightBranch);
  1796. /// K*
  1797. compareVariables(nYear, (UseDTF ? "K_star_plus_PT_DTF":"K_star_plus_PT"), sWeight, bWeighted, b2DWeighted, 0, 0, save2file, false, weightBranch);
  1798. compareVariables(nYear, (UseDTF ? "K_star_plus_ETA_DTF":"K_star_plus_ETA"), sWeight, bWeighted, b2DWeighted, 0, 0, save2file, false, weightBranch);
  1799. compareVariables(nYear, "K_star_plus_IPCHI2_OWNPV", sWeight, bWeighted, b2DWeighted, 0, 0, save2file, false, weightBranch);
  1800. /// mu
  1801. compareVariables(nYear, "mu_plus_IPCHI2_OWNPV", sWeight, bWeighted, b2DWeighted, 1, 0, save2file, false, weightBranch);
  1802. compareVariables(nYear, "mu_minus_IPCHI2_OWNPV", sWeight, bWeighted, b2DWeighted, 1, 0, save2file, false, weightBranch);
  1803. ///K+
  1804. compareVariables(nYear, "K_plus_IPCHI2_OWNPV", sWeight, bWeighted, b2DWeighted, 0, 0, save2file, false, weightBranch);
  1805. compareVariables(nYear, "K_plus_TRACK_CHI2NDOF", sWeight, bWeighted, b2DWeighted, 0, 0, save2file, false, weightBranch);
  1806. compareVariables(nYear, (UseDTF ? "K_plus_PT_DTF":"K_plus_PT"), sWeight, bWeighted, b2DWeighted, 0, 0, save2file, false, weightBranch);
  1807. compareVariables(nYear, (UseDTF ? "K_plus_ETA_DTF":"K_plus_ETA"), sWeight, bWeighted, b2DWeighted, 0, 0, save2file, false, weightBranch);
  1808. /// pi0
  1809. compareVariables(nYear, (UseDTF ? "pi_zero_merged_ETA_DTF" : "pi_zero_merged_ETA"), sWeight, bWeighted, b2DWeighted, 0, 0, save2file, false, weightBranch);
  1810. nYear++;
  1811. }
  1812. return 1;
  1813. }
  1814. int compareKplusResolvedMVAonly(bool sWeight = true, bool bWeighted = true, bool b2DWeighted = true, int Run = 1, std::string weightBranch = firstMCweight){
  1815. checkRun(Run);
  1816. bool save2file = true;
  1817. weightBranch = firstMCweight + "_TM_rndGamma";
  1818. //Load the MVA config from the txt file
  1819. MVA_variables vars("");
  1820. std::cout << "Get compare plots for these variables: " << std::endl;
  1821. vars.print();
  1822. string operation = "";
  1823. bool bLogX = false, bLog1X = false;
  1824. vector<int>years = yearsVectorInt(true,false,true,Run); //Set to PHSP in order to process also 2015
  1825. for (auto nYear: years){
  1826. int k = 0; //check for all branches actually used
  1827. for(int i = 0; i < vars.NumberOfVariables(); i++){ //loop over used variables
  1828. bLogX = false;
  1829. bLog1X = false;
  1830. operation = "";
  1831. if ( vars.AllVariables.at(i).NoBr == 2){
  1832. cout << "[INFO]\tPlotting variable: " << vars.AllVariables.at(i).LaTeXName << endl;
  1833. if( vars.AllVariables.at(i).Formula.find("log(1")!= std::string::npos){
  1834. bLogX = false;
  1835. bLog1X = true;
  1836. }
  1837. else if( vars.AllVariables.at(i).Formula.find("log(x") != std::string::npos){
  1838. bLogX = true;
  1839. bLog1X = false;
  1840. }
  1841. if( vars.AllVariables.at(i).Formula.find("max") != std::string::npos) operation = "max";
  1842. else if( vars.AllVariables.at(i).Formula.find("min") != std::string::npos) operation = "min";
  1843. else if( vars.AllVariables.at(i).Formula.find("abs") != std::string::npos) operation = "abs";
  1844. if(compareVariables(nYear, vars.AllBranches.at(k),sWeight, bWeighted, b2DWeighted, bLogX, bLog1X, save2file, false, weightBranch, false, "","" , "") == 0)return 0;
  1845. if(compareVariables(nYear, vars.AllBranches.at(k+1),sWeight, bWeighted, b2DWeighted, bLogX, bLog1X, save2file, false, weightBranch, false, "","" , "" ) == 0)return 0;
  1846. compareVariables(nYear, vars.AllBranches.at(k),sWeight, bWeighted, b2DWeighted, bLogX, bLog1X, save2file, false, weightBranch, true, operation, vars.AllBranches.at(k+1), vars.AllVariables.at(i).LaTeXName);
  1847. k+=2;
  1848. }
  1849. else{
  1850. cout << "[INFO]\tPlotting variable: " << vars.AllBranches.at(k) << endl;
  1851. if( vars.AllVariables.at(i).Formula.find("log(x)") != std::string::npos){
  1852. bLogX = true;
  1853. bLog1X = false;
  1854. }
  1855. else if( vars.AllVariables.at(i).Formula.find("log(1-x)")!= std::string::npos){
  1856. bLogX = false;
  1857. bLog1X = true;
  1858. }
  1859. if(compareVariables(nYear, vars.AllBranches.at(k),sWeight, bWeighted, b2DWeighted, bLogX, bLog1X, save2file, false, weightBranch,false, "","", vars.AllVariables.at(i).LaTeXName) == 0)return 0;
  1860. k++;
  1861. }
  1862. }
  1863. //also compare nTracks and B_plus_PT (risk of running double, if used in MVA, but who cares :)
  1864. if(compareVariables(nYear, firstMCweight, sWeight, bWeighted, b2DWeighted, 0, 0, save2file, false, weightBranch) == 0)return 0;
  1865. if(compareVariables(nYear, seconMCweight, sWeight, bWeighted, b2DWeighted, 0, 0, save2file, false, weightBranch) == 0)return 0;
  1866. nYear++;
  1867. }
  1868. return 1;
  1869. }
  1870. int compareAllKplus(std::string weightBranch = firstMCweight){
  1871. NtrackWeightAllKplus(false, false, true);
  1872. if (compareAllKplusResolved (true, 0, 0, 1, weightBranch)==0) return 0;
  1873. if (compareAllKplusResolved (true, 0, 1, 1, weightBranch)==0) return 0;
  1874. if (compareAllKplusResolved (true, 1, 0, 1, weightBranch)==0) return 0;
  1875. if (compareAllKplusResolved (true, 1, 1, 1, weightBranch)==0) return 0;
  1876. if (compareAllKplusResolved (true, 0, 0, 2, weightBranch)==0) return 0;
  1877. if (compareAllKplusResolved (true, 0, 1, 2, weightBranch)==0) return 0;
  1878. if (compareAllKplusResolved (true, 1, 0, 2, weightBranch)==0) return 0;
  1879. if (compareAllKplusResolved (true, 1, 1, 2, weightBranch)==0) return 0;
  1880. if (compareKplusResolvedMVAonly (true, 0, 0, 1, weightBranch)==0) return 0;
  1881. if (compareKplusResolvedMVAonly (true, 0, 1, 1, weightBranch)==0) return 0;
  1882. if (compareKplusResolvedMVAonly (true, 1, 0, 1, weightBranch)==0) return 0;
  1883. if (compareKplusResolvedMVAonly (true, 1, 1, 1, weightBranch)==0) return 0;
  1884. if (compareKplusResolvedMVAonly (true, 0, 0, 2, weightBranch)==0) return 0;
  1885. if (compareKplusResolvedMVAonly (true, 0, 1, 2, weightBranch)==0) return 0;
  1886. if (compareKplusResolvedMVAonly (true, 1, 0, 2, weightBranch)==0) return 0;
  1887. if (compareKplusResolvedMVAonly (true, 1, 1, 2, weightBranch)==0) return 0;
  1888. return 1;
  1889. }
  1890. /////////////////////////////////////////////////////
  1891. ///
  1892. /// comparison of all variables:
  1893. ///
  1894. /////////////////////////////////////////////////////
  1895. int compareAll(int Run = 1){
  1896. if(Kst2Kspiplus) return compareKshortMVAonly(true,true, true, Run);
  1897. if(Kst2Kpluspi0Resolved)return compareKplusResolvedMVAonly(true,true, true, Run);
  1898. if(Kst2Kpluspi0Merged) return compareAllKplusMerged(true,true,true, Run);
  1899. coutERROR("Nothing processed! Incorrect decay string given!");
  1900. return 0;
  1901. }
  1902. /////////////////////////////////////////////////////
  1903. ///
  1904. /// comparison of track multiplicities between Run I and Run II
  1905. ///
  1906. /////////////////////////////////////////////////////
  1907. int compareTrackMultiplicities(bool KshortDecaysInVelo = false, bool MC = false, std::string weightBranch = firstMCweight){
  1908. //change hardcoded if the distributions should be compared unweighted, otherwise use 2 * 1D reweight in PT(B+) and nTracks
  1909. bool reweightMC = true;
  1910. bool sWeight = true;
  1911. gStyle -> SetOptStat(0);
  1912. gROOT->SetBatch(kTRUE);
  1913. LHCbStyle();
  1914. //lhcbStyle->SetOptTitle(1);
  1915. //create one tree per Run and add all years and magnet polarities into the same tree
  1916. TChain * treeRun1 = new TChain(MC ? "DecayTreeTruthMatched" : "DecayTree");
  1917. TChain * treeRun2 = new TChain(MC ? "DecayTreeTruthMatched" : "DecayTree");
  1918. // Kst2Kpluspi0Resolved case
  1919. if(Kst2Kpluspi0Resolved){
  1920. if(MC){
  1921. treeRun1->Add(Form("%s/data/MC/2011_KplusPi0Resolved_BDTinput%s.root", path_to_output_KplusPizero.c_str(), sWeight ? "" : "_nosWeight"));
  1922. treeRun1->Add(Form("%s/data/MC/2012_KplusPi0Resolved_BDTinput%s.root", path_to_output_KplusPizero.c_str(), sWeight ? "" : "_nosWeight"));
  1923. treeRun2->Add(Form("%s/data/MC/2015_KplusPi0Resolved_BDTinput%s.root", path_to_output_KplusPizero.c_str(), sWeight ? "" : "_nosWeight"));
  1924. treeRun2->Add(Form("%s/data/MC/2016_KplusPi0Resolved_BDTinput%s.root", path_to_output_KplusPizero.c_str(), sWeight ? "" : "_nosWeight"));
  1925. }
  1926. else{
  1927. treeRun1->Add(Form("%s/data/2011_KplusPi0Resolved_BDTinput%s.root", path_to_output_KplusPizero.c_str(), sWeight ? "" : "_nosWeight"));
  1928. treeRun1->Add(Form("%s/data/2012_KplusPi0Resolved_BDTinput%s.root", path_to_output_KplusPizero.c_str(), sWeight ? "" : "_nosWeight"));
  1929. treeRun2->Add(Form("%s/data/2015_KplusPi0Resolved_BDTinput%s.root", path_to_output_KplusPizero.c_str(), sWeight ? "" : "_nosWeight"));
  1930. treeRun2->Add(Form("%s/data/2016_KplusPi0Resolved_BDTinput%s.root", path_to_output_KplusPizero.c_str(), sWeight ? "" : "_nosWeight"));
  1931. }
  1932. }
  1933. // Kst2Kpluspi0Merged case
  1934. else if(Kst2Kpluspi0Merged){
  1935. if(MC){
  1936. coutERROR("No merged pi0 MC sample available!");
  1937. return 0;
  1938. treeRun1->Add(Form("%s/data/MC/2011_KplusPi0Merged_BDTinput%s.root", path_to_output_KplusPizero.c_str(), sWeight ? "" : "_nosWeight"));
  1939. treeRun1->Add(Form("%s/data/MC/2012_KplusPi0Merged_BDTinput%s.root", path_to_output_KplusPizero.c_str(), sWeight ? "" : "_nosWeight"));
  1940. treeRun2->Add(Form("%s/data/MC/2015_KplusPi0Merged_BDTinput%s.root", path_to_output_KplusPizero.c_str(), sWeight ? "" : "_nosWeight"));
  1941. treeRun2->Add(Form("%s/data/MC/2016_KplusPi0Merged_BDTinput%s.root", path_to_output_KplusPizero.c_str(), sWeight ? "" : "_nosWeight"));
  1942. }
  1943. else{
  1944. treeRun1->Add(Form("%s/data/2011_KplusPi0Merged_BDTinput%s.root", path_to_output_KplusPizero.c_str(), sWeight ? "" : "_nosWeight"));
  1945. treeRun1->Add(Form("%s/data/2012_KplusPi0Merged_BDTinput%s.root", path_to_output_KplusPizero.c_str(), sWeight ? "" : "_nosWeight"));
  1946. treeRun2->Add(Form("%s/data/2015_KplusPi0Merged_BDTinput%s.root", path_to_output_KplusPizero.c_str(), sWeight ? "" : "_nosWeight"));
  1947. treeRun2->Add(Form("%s/data/2016_KplusPi0Merged_BDTinput%s.root", path_to_output_KplusPizero.c_str(), sWeight ? "" : "_nosWeight"));
  1948. }
  1949. }
  1950. // Kst2Kspiplus case
  1951. else if(Kst2Kspiplus){
  1952. if(MC){
  1953. if(SplitDDandLL){
  1954. treeRun1->Add(Form("%s/data/MC/2011_KshortPiplus%s_BDTinput%s.root", path_to_output_KshortPiplus.c_str(), KshortDecaysInVelo ? "_LL" : "_DD", sWeight ? "" : "_nosWeight"));
  1955. treeRun1->Add(Form("%s/data/MC/2012_KshortPiplus%s_BDTinput%s.root", path_to_output_KshortPiplus.c_str(), KshortDecaysInVelo ? "_LL" : "_DD", sWeight ? "" : "_nosWeight"));
  1956. treeRun2->Add(Form("%s/data/MC/2015_KshortPiplus%s_BDTinput%s.root", path_to_output_KshortPiplus.c_str(), KshortDecaysInVelo ? "_LL" : "_DD", sWeight ? "" : "_nosWeight"));
  1957. treeRun2->Add(Form("%s/data/MC/2016_KshortPiplus%s_BDTinput%s.root", path_to_output_KshortPiplus.c_str(), KshortDecaysInVelo ? "_LL" : "_DD", sWeight ? "" : "_nosWeight"));
  1958. }
  1959. else{
  1960. treeRun1->Add(Form("%s/data/MC/2011_KshortPiplus_BDTinput%s.root", path_to_output_KshortPiplus.c_str(), sWeight ? "" : "_nosWeight"));
  1961. treeRun1->Add(Form("%s/data/MC/2012_KshortPiplus_BDTinput%s.root", path_to_output_KshortPiplus.c_str(), sWeight ? "" : "_nosWeight"));
  1962. treeRun2->Add(Form("%s/data/MC/2015_KshortPiplus_BDTinput%s.root", path_to_output_KshortPiplus.c_str(), sWeight ? "" : "_nosWeight"));
  1963. treeRun2->Add(Form("%s/data/MC/2016_KshortPiplus_BDTinput%s.root", path_to_output_KshortPiplus.c_str(), sWeight ? "" : "_nosWeight"));
  1964. }
  1965. }
  1966. else{
  1967. if(SplitDDandLL){
  1968. treeRun1->Add(Form("%s/data/2011_KshortPiplus%s_BDTinput%s.root", path_to_output_KshortPiplus.c_str(), KshortDecaysInVelo ? "_LL" : "_DD", sWeight ? "" : "_nosWeight"));
  1969. treeRun1->Add(Form("%s/data/2012_KshortPiplus%s_BDTinput%s.root", path_to_output_KshortPiplus.c_str(), KshortDecaysInVelo ? "_LL" : "_DD", sWeight ? "" : "_nosWeight"));
  1970. treeRun2->Add(Form("%s/data/2015_KshortPiplus%s_BDTinput%s.root", path_to_output_KshortPiplus.c_str(), KshortDecaysInVelo ? "_LL" : "_DD", sWeight ? "" : "_nosWeight"));
  1971. treeRun2->Add(Form("%s/data/2016_KshortPiplus%s_BDTinput%s.root", path_to_output_KshortPiplus.c_str(), KshortDecaysInVelo ? "_LL" : "_DD", sWeight ? "" : "_nosWeight"));
  1972. }
  1973. else{
  1974. treeRun1->Add(Form("%s/data/2011_KshortPiplus_BDTinput%s.root", path_to_output_KshortPiplus.c_str(), sWeight ? "" : "_nosWeight"));
  1975. treeRun1->Add(Form("%s/data/2012_KshortPiplus_BDTinput%s.root", path_to_output_KshortPiplus.c_str(), sWeight ? "" : "_nosWeight"));
  1976. treeRun2->Add(Form("%s/data/2015_KshortPiplus_BDTinput%s.root", path_to_output_KshortPiplus.c_str(), sWeight ? "" : "_nosWeight"));
  1977. treeRun2->Add(Form("%s/data/2016_KshortPiplus_BDTinput%s.root", path_to_output_KshortPiplus.c_str(), sWeight ? "" : "_nosWeight"));
  1978. }
  1979. }
  1980. }
  1981. else return 0;
  1982. //create vector with all requested variables that are compared between Run1 and Run2
  1983. std::vector<std::string> TrackTypes;
  1984. TrackTypes.push_back("nTracks");
  1985. TrackTypes.push_back("nLongTracks");
  1986. TrackTypes.push_back("nBackTracks");
  1987. TrackTypes.push_back("nDownstreamTracks");
  1988. TrackTypes.push_back("nTTracks");
  1989. TrackTypes.push_back("nUpstreamTracks");
  1990. TrackTypes.push_back("nVeloTracks");
  1991. std::vector<int> UpperLimits;
  1992. UpperLimits.push_back(500);
  1993. UpperLimits.push_back(125);
  1994. UpperLimits.push_back(75);
  1995. UpperLimits.push_back(75);
  1996. UpperLimits.push_back(150);
  1997. UpperLimits.push_back(45);
  1998. UpperLimits.push_back(300);
  1999. const unsigned int N = TrackTypes.size();
  2000. if(UpperLimits.size() != N){
  2001. coutWarning("Number of given upper limits for variable distributions does not match the number of varialbes!");
  2002. while(UpperLimits.size() < N)UpperLimits.push_back(100);
  2003. }
  2004. int nTracksRun1[N];
  2005. int nTracksRun2[N];
  2006. TH1D * histosRun1[N];
  2007. TH1D * histosRun2[N];
  2008. for(unsigned int tt = 0; tt < N; tt++){
  2009. //link all variables from TTree to the int:
  2010. treeRun1->SetBranchAddress(TrackTypes.at(tt).c_str(), &nTracksRun1[tt]);
  2011. treeRun2->SetBranchAddress(TrackTypes.at(tt).c_str(), &nTracksRun2[tt]);
  2012. histosRun1[tt] = new TH1D(Form("%s_Run1", TrackTypes.at(tt).c_str()), "2011 + 2012", (UpperLimits.at(tt) > 200) ? 100 : UpperLimits.at(tt) + 1 , -0.5 , UpperLimits.at(tt) + 0.5 );
  2013. histosRun2[tt] = new TH1D(Form("%s_Run2", TrackTypes.at(tt).c_str()), "2015 + 2016", (UpperLimits.at(tt) > 200) ? 100 : UpperLimits.at(tt) + 1 , -0.5 , UpperLimits.at(tt) + 0.5 );
  2014. histosRun1[tt]->SetMarkerStyle(20);
  2015. histosRun2[tt]->SetMarkerStyle(20);
  2016. histosRun1[tt]->SetMarkerColor(2);
  2017. histosRun2[tt]->SetMarkerColor(4);
  2018. histosRun1[tt]->SetLineColor(2);
  2019. histosRun2[tt]->SetLineColor(4);
  2020. histosRun1[tt]->GetXaxis()->SetTitle(TrackTypes.at(tt).c_str());
  2021. histosRun1[tt]->GetYaxis()->SetTitle("normalized events");
  2022. histosRun2[tt]->GetXaxis()->SetTitle(TrackTypes.at(tt).c_str());
  2023. histosRun2[tt]->GetYaxis()->SetTitle("normalized events");
  2024. }
  2025. //link weights!
  2026. double wRun1 = 1.0;
  2027. double wRun2 = 1.0;
  2028. if(MC){
  2029. if (reweightMC){ //if not, keep wRun1 and wRun2 = 1.0
  2030. treeRun1->SetBranchAddress(Form("weight2D_%s",weightBranch.c_str()), &wRun1);
  2031. treeRun2->SetBranchAddress(Form("weight2D_%s",weightBranch.c_str()), &wRun2);
  2032. }
  2033. }
  2034. else if (sWeight){
  2035. treeRun1->SetBranchAddress("N_Bplus_sw", &wRun1);
  2036. treeRun2->SetBranchAddress("N_Bplus_sw", &wRun2);
  2037. }
  2038. std::cout << "[INFO]\t\tAll variables linked and histograms created!" << std::endl;
  2039. unsigned int N_Run1 = treeRun1->GetEntries();
  2040. unsigned int N_Run2 = treeRun2->GetEntries();
  2041. std::cout << std::endl;
  2042. std::cout << "= = = = = = = = = = = = = = = = " << std::endl;
  2043. std::cout << std::endl;
  2044. std::cout << "[INFO]\t\tStart looping over dataset of Run 1" << std::endl;
  2045. std::cout << "[INFO]\t\tTotal of " << N_Run1 << " events!" << std::endl;
  2046. //fill Run1 histograms:
  2047. for(unsigned int i = 0; i < N_Run1; i++){
  2048. treeRun1->GetEntry(i);
  2049. if(i !=0 && i%1000 == 0)std::cout << "[LOOP]\t\tRun 1: Event [" << i + 1 << " / " << N_Run1 << "]" << std::endl;
  2050. for(unsigned int tt = 0; tt < N; tt++){
  2051. histosRun1[tt]->Fill(nTracksRun1[tt], wRun1);
  2052. }
  2053. }
  2054. std::cout << std::endl;
  2055. std::cout << "= = = = = = = = = = = = = = = = " << std::endl;
  2056. std::cout << std::endl;
  2057. std::cout << "[INFO]\t\tStart looping over dataset of Run 2" << std::endl;
  2058. std::cout << "[INFO]\t\tTotal of " << N_Run2 << " events!" << std::endl;
  2059. //fill Run2 histograms:
  2060. for(unsigned int ii = 0; ii < N_Run2; ii++){
  2061. treeRun2->GetEntry(ii);
  2062. if(MC && !reweightMC)wRun2 = 1.;
  2063. if(ii !=0 && ii%1000 == 0)std::cout << "[LOOP]\t\tRun 2: Event [" << ii + 1 << " / " << N_Run2 << "]" << std::endl;
  2064. for(unsigned int tt = 0; tt < N; tt++){
  2065. histosRun2[tt]->Fill(nTracksRun2[tt], wRun2);
  2066. }
  2067. }
  2068. //normalize all histograms:
  2069. for(unsigned int tt = 0; tt < N; tt++){
  2070. //histosRun1[tt]->Sumw2();
  2071. //histosRun2[tt]->Sumw2();
  2072. histosRun1[tt]->Scale(1. / N_Run1);
  2073. histosRun2[tt]->Scale(1. / N_Run2);
  2074. }
  2075. std::cout << std::endl;
  2076. std::cout << "= = = = = = = = = = = = = = = = " << std::endl;
  2077. std::cout << std::endl;
  2078. std::cout << "[INFO]\t\tSave histograms to file!" << std::endl;
  2079. //create new file for these comparison plots:
  2080. TFile * fOutput = NULL;
  2081. if(Kst2Kpluspi0Merged) fOutput = new TFile(Form("%s/ComparePlots/%s%s%s.root", path_to_output_KplusPizero.c_str(), TheDecay.c_str(), MC ? "_MC" : "", sWeight ? "" : "_nosWeight"), "RECREATE");
  2082. else if(Kst2Kpluspi0Resolved) fOutput = new TFile(Form("%s/ComparePlots/%s%s%s.root", path_to_output_KplusPizero.c_str(), TheDecay.c_str(), MC ? "_MC" : "", sWeight ? "" : "_nosWeight"), "RECREATE");
  2083. else if(Kst2Kspiplus){
  2084. if(SplitDDandLL) fOutput = new TFile(Form("%s/ComparePlots/%s%s%s%s.root", path_to_output_KshortPiplus.c_str(), TheDecay.c_str(), KshortDecaysInVelo ? "_LL" : "_DD", MC ? "_MC" : "", sWeight ? "" : "_nosWeight"), "RECREATE");
  2085. else fOutput = new TFile(Form("%s/ComparePlots/%s%s%s%s.root", path_to_output_KshortPiplus.c_str(), TheDecay.c_str(), KshortDecaysInVelo ? "_LL" : "_DD", MC ? "_MC" : "", sWeight ? "" : "_nosWeight"), "RECREATE");
  2086. }
  2087. else return 0;
  2088. if(fOutput == NULL){
  2089. coutERROR("Initializing of output file was not successful. Exit program!");
  2090. return 0;
  2091. }
  2092. TCanvas * c1;
  2093. float maxBinContent = 0.;
  2094. //plot Run1 and Run2 histograms into the same canvas and save to TFile
  2095. for(unsigned int tt = 0; tt < N; tt++){
  2096. maxBinContent = 0.;
  2097. for(int bin = 1; bin <= histosRun1[tt]->GetNbinsX(); bin++){
  2098. if(maxBinContent < histosRun1[tt]->GetBinContent(bin))maxBinContent = histosRun1[tt]->GetBinContent(bin);
  2099. }
  2100. for(int bin = 1; bin <= histosRun2[tt]->GetNbinsX(); bin++){
  2101. if(maxBinContent < histosRun2[tt]->GetBinContent(bin))maxBinContent = histosRun2[tt]->GetBinContent(bin);
  2102. }
  2103. c1 = new TCanvas("c1", "c1");
  2104. c1->Clear();
  2105. c1->SetName(TrackTypes.at(tt).c_str());
  2106. c1->SetTitle(TrackTypes.at(tt).c_str());
  2107. histosRun1[tt]->GetYaxis()->SetRangeUser(0, maxBinContent * 1.1);
  2108. histosRun1[tt]->Draw("E1");
  2109. histosRun2[tt]->Draw("E1SAME");
  2110. c1->BuildLegend(0.6, 0.7, 0.9, 0.9);
  2111. fOutput->cd();
  2112. c1->Write("",TObject::kWriteDelete);
  2113. c1->Close();
  2114. }
  2115. fOutput->Close();
  2116. return 1;
  2117. }
  2118. /////////////////////////////////////////////////////
  2119. ///
  2120. /// comparison of the angles between (2D-)weighted and non-weighted PHSP MC
  2121. ///
  2122. /////////////////////////////////////////////////////
  2123. int compareAnglesInPHSP(int year = 2011, bool sWeight = true, bool b2Dweighted = true, bool KshortDecayInVelo = true, std::string weightBranch = firstMCweight){
  2124. gStyle -> SetOptStat(0);
  2125. gROOT->SetBatch(kTRUE);
  2126. LHCbStyle();
  2127. //put both magnet polarities into one TChain
  2128. TChain * treePHSP = new TChain("DecayTreeTruthMatched");
  2129. if(Kst2Kpluspi0Resolved){
  2130. treePHSP->Add(Form("%s/data/PHSP/%i_KplusPi0ResolvedPHSP_BDTinput%s.root", path_to_output_KplusPizero.c_str(), year, sWeight ? "" : "_nosWeight"));
  2131. }
  2132. else if(Kst2Kspiplus){
  2133. treePHSP->Add(Form("%s/data/PHSP/%i_KshortPiplusPHSP%s_BDTinput%s.root", path_to_output_KshortPiplus.c_str(), year, SplitDDandLL ? (KshortDecayInVelo ? "_LL" : "_DD") : "", sWeight ? "" : "_nosWeight"));
  2134. }
  2135. int N = treePHSP->GetEntries();
  2136. if(N == 0){
  2137. std::cout << Form("[ERROR]\t\tNo events found in file data/PHSP/%i_%sPHSP%s_BDTinput.root", year, TheDecay.c_str(), (Kst2Kspiplus && SplitDDandLL ? (KshortDecayInVelo ? "_LL" : "_DD") : "")) << std::endl;
  2138. return 0;
  2139. }
  2140. //deactivate all branches exept the one of intrest!
  2141. treePHSP->SetBranchStatus("*",0);
  2142. treePHSP->SetBranchStatus("B_plus_ThetaK",1);
  2143. treePHSP->SetBranchStatus("B_plus_ThetaL",1);
  2144. treePHSP->SetBranchStatus("B_plus_Phi",1);
  2145. treePHSP->SetBranchStatus(Form("weight_%s",weightBranch.c_str()),1);
  2146. treePHSP->SetBranchStatus(Form("weight2D_%s",weightBranch.c_str()),1);
  2147. double angle[3];//ctk, ctl, phi;
  2148. double w, w2d;
  2149. treePHSP->SetBranchAddress("B_plus_ThetaK",&angle[0]);
  2150. treePHSP->SetBranchAddress("B_plus_ThetaL",&angle[1]);
  2151. treePHSP->SetBranchAddress("B_plus_Phi",&angle[2]);
  2152. treePHSP->SetBranchAddress(Form("weight_%s",weightBranch.c_str()),&w);
  2153. treePHSP->SetBranchAddress(Form("weight2D_%s",weightBranch.c_str()),&w2d);
  2154. //initialize histograms
  2155. int bins = 100;
  2156. double xLow[3] = {-1., -1., -TMath::Pi()};
  2157. double xHigh[3] = {+1., +1., +TMath::Pi()};
  2158. std::string theName[3] = {"cos(#theta_{K})", "cos(#theta_{L})", "#phi"};
  2159. std::string leName[3] = {"ctk", "ctl", "phi"};
  2160. TH1D * hRatio[3];
  2161. TH1D * hWeighted[3];
  2162. TH1D * hNoWeight[3];
  2163. for(int h = 0; h < 3; h++){
  2164. hRatio[h] = new TH1D(Form("hRatio_%s", leName[h].c_str()), Form("Ratio weighted to non-weighted (%s)", theName[h].c_str()), bins, xLow[h], xHigh[h]);
  2165. hWeighted[h] = new TH1D(Form("hWeighted_%s", leName[h].c_str()), Form("%sWeighted distribution of %s", (b2Dweighted ? "2D-" : ""), theName[h].c_str()), bins, xLow[h], xHigh[h]);
  2166. hNoWeight[h] = new TH1D(Form("hNoWeight_%s", leName[h].c_str()), Form("Non-weighted distribution of %s", theName[h].c_str()), bins, xLow[h], xHigh[h]);
  2167. }
  2168. //loop over events and save to histograms
  2169. for(int i = 0; i < N; i++){
  2170. if(i%10000==0 && i != 0)std::cout << "Loading data event " << i << " / " << N << std::endl;
  2171. treePHSP->GetEntry(i);
  2172. for(int a = 0; a < 3; a++){
  2173. if(a == 0 || a == 1){ //convert theta to cos(theta)
  2174. angle[a] = TMath::Cos(angle[a]);
  2175. }
  2176. hRatio[a] ->Fill(angle[a], b2Dweighted ? w2d : w);
  2177. hWeighted[a]->Fill(angle[a], b2Dweighted ? w2d : w);
  2178. hNoWeight[a]->Fill(angle[a], 1.0);
  2179. }
  2180. }
  2181. double varMax[3] = {-1.0e8,-1.0e8,-1.0e8};
  2182. double varMin[3] = {+1.0e8,+1.0e8,+1.0e8};
  2183. double ratioMax[3] = {-1.0e8,-1.0e8,-1.0e8};
  2184. double ratioMin[3] = {+1.0e8,+1.0e8,+1.0e8};
  2185. double val, weival, ratioval;
  2186. for(int h = 0; h < 3; h++){
  2187. //make ratio:
  2188. hRatio[h]->Divide(hNoWeight[h]);
  2189. //set correct ranges for the histograms:
  2190. for(int bin = 1; bin <= bins; bin++){
  2191. val = hNoWeight[h]->GetBinContent(bin);
  2192. weival = hWeighted[h]->GetBinContent(bin);
  2193. ratioval = hRatio[h] ->GetBinContent(bin);
  2194. if(varMax[h] <= val) varMax[h] = val;
  2195. if(varMax[h] <= weival) varMax[h] = weival;
  2196. if(ratioMax[h] <= ratioval)ratioMax[h] = ratioval;
  2197. if(varMin[h] >= val) varMin[h] = val;
  2198. if(varMin[h] >= weival) varMin[h] = weival;
  2199. if(ratioMin[h] >= ratioval)ratioMin[h] = ratioval;
  2200. }
  2201. varMax[h] *= 1.1;
  2202. if(varMin[h] < 0)varMin[h] *= 1.1;
  2203. else varMin[h] = 0.001; //if minimum is positve, set minimum to just above 0 to remove label
  2204. if(ratioMax[h] > 3.)ratioMax[h] = 3.;
  2205. if(ratioMax[h] < 2.)ratioMax[h] = 2.;
  2206. ratioMax[h] *= 1.1;
  2207. //configurables for plotting
  2208. float lowerPlotHeight = 0.6;
  2209. //create two pads into one canvas
  2210. TCanvas * theCanvas = new TCanvas(Form("theCanvas%s", leName[h].c_str()), Form("ratio and superposition of %s" , theName[h].c_str()));
  2211. float textsize = gStyle->GetTextSize();
  2212. TPad * pad1 = new TPad(Form("pad1%s", leName[h].c_str()), "ratio",0.0,lowerPlotHeight,1.0,1.0,0);
  2213. TPad * pad2 = new TPad(Form("pad2%s", leName[h].c_str()), "superposition",0.0,0.0,1.0,lowerPlotHeight,0);
  2214. pad1->Draw();
  2215. pad2->Draw();
  2216. //modifiy pad for main plot
  2217. pad1->Clear();
  2218. pad1->SetBorderSize (0);
  2219. pad1->SetBottomMargin(1e-6);
  2220. pad1->SetTopMargin(pad1->GetTopMargin() / ( 1 - lowerPlotHeight) );
  2221. pad1->cd();
  2222. //some axis-modifications on the main plot
  2223. TGaxis::SetExponentOffset(1e+9,1e+9,"y");//offset = pad size * 1e+7
  2224. hRatio[h]->GetXaxis()->SetNoExponent(); //<-- spoils MaxDigits settings, so don't use it on other axis
  2225. hRatio[h]->GetXaxis()->SetLabelSize(0.0);//don't print labels
  2226. hRatio[h]->GetXaxis()->SetRangeUser(xLow[h], xHigh[h]);
  2227. hRatio[h]->GetXaxis()->SetTickLength(hRatio[h]->GetXaxis()->GetTickLength()/(1-lowerPlotHeight));
  2228. hRatio[h]->GetXaxis()->SetNdivisions(gStyle->GetNdivisions("X"));
  2229. hRatio[h]->GetYaxis()->SetTitle("ratio (#omega / 1.0)");
  2230. hRatio[h]->GetYaxis()->SetTitleSize(textsize/(1-lowerPlotHeight));
  2231. hRatio[h]->GetYaxis()->SetLabelSize(textsize/(1-lowerPlotHeight));
  2232. hRatio[h]->GetYaxis()->SetTickLength(hRatio[h]->GetYaxis()->GetTickLength());
  2233. hRatio[h]->GetYaxis()->SetNdivisions(gStyle->GetNdivisions("Y"));
  2234. hRatio[h]->GetYaxis()->SetTitleOffset(1.06*(1-lowerPlotHeight));
  2235. hRatio[h]->GetYaxis()->SetRangeUser(0.5, 1.5);
  2236. hRatio[h]->Draw("E1");
  2237. TLine * unityline = new TLine(xLow[h], 1, xHigh[h], 1);
  2238. unityline->SetLineStyle(2);
  2239. unityline->SetLineColor(4);
  2240. unityline->Draw("SAME");
  2241. pad2->Clear();
  2242. pad2->SetBorderSize (0);
  2243. pad2->SetTopMargin (1e-6);
  2244. pad2->SetBottomMargin(pad2->GetBottomMargin() / lowerPlotHeight );
  2245. pad2->cd();
  2246. TGaxis::SetExponentOffset(1e+9,1e+9,"x");//offset = pad size * 1e+7
  2247. hNoWeight[h]->GetXaxis()->SetTitleOffset(1.05);
  2248. hNoWeight[h]->GetXaxis()->SetTitleSize (textsize/lowerPlotHeight);
  2249. hNoWeight[h]->GetXaxis()->SetLabelSize (textsize/lowerPlotHeight);
  2250. hNoWeight[h]->GetXaxis()->SetTickLength (hRatio[h]->GetXaxis()->GetTickLength()/(lowerPlotHeight/(1-lowerPlotHeight)));
  2251. hNoWeight[h]->GetXaxis()->SetNdivisions (gStyle->GetNdivisions("X"));
  2252. hNoWeight[h]->GetXaxis()->SetTitle(theName[h].c_str());
  2253. hNoWeight[h]->GetXaxis()->SetRangeUser(xLow[h], xHigh[h]);
  2254. hNoWeight[h]->GetYaxis()->SetRangeUser(varMin[h], varMax[h]);
  2255. hNoWeight[h]->GetYaxis()->SetTitle("events");
  2256. hNoWeight[h]->GetYaxis()->SetLabelSize (textsize/lowerPlotHeight);
  2257. hNoWeight[h]->GetYaxis()->SetTitleSize (textsize/lowerPlotHeight);
  2258. hNoWeight[h]->GetYaxis()->SetTickLength(hRatio[h]->GetYaxis()->GetTickLength());
  2259. hNoWeight[h]->GetYaxis()->SetNdivisions (gStyle->GetNdivisions("Y"));
  2260. hNoWeight[h]->GetYaxis()->SetTitleOffset(1.06*lowerPlotHeight);
  2261. hNoWeight[h]->Draw("E1");
  2262. hWeighted[h]->SetLineColor(2);
  2263. hWeighted[h]->SetMarkerColor(2);
  2264. hWeighted[h]->Draw("E1SAME");
  2265. //Legend and position...
  2266. float LegendXposition = 0.4;
  2267. float LegendYposition = 0.3;
  2268. TLegend * leg = new TLegend(LegendXposition,LegendYposition,LegendXposition + 0.25, LegendYposition + 0.18);
  2269. leg->AddEntry(hWeighted[h],Form("%sweighted PHSP MC",(b2Dweighted ? "2#upoint1D-" : "")), "lpe");
  2270. leg->AddEntry(hNoWeight[h],"non-weighted PHSP MC", "lpe");
  2271. leg->SetTextSize(0.04/lowerPlotHeight); // works fine
  2272. leg->Draw("same");
  2273. addLHCbtag(LegendXposition, LegendYposition + 0.27, "simulation", 1, 1/lowerPlotHeight);
  2274. if (Kst2Kspiplus)theCanvas->Print(Form("%s/ComparePlots/%i_%s%s_Comparison%sWeights_%s%s.eps", path_to_output_KshortPiplus.c_str(), year, TheDecay.c_str(), (SplitDDandLL ? (KshortDecayInVelo ? "_LL" : "_DD") : ""), (b2Dweighted ? "2D" : ""), leName[h].c_str(), sWeight ? "" : "_nosWeight"));
  2275. else theCanvas->Print(Form("%s/ComparePlots/%i_%s_Comparison%sWeights_%s%s.eps", path_to_output_KplusPizero.c_str(), year, TheDecay.c_str(), (b2Dweighted ? "2D" : ""), leName[h].c_str(), sWeight ? "" : "_nosWeight"));
  2276. theCanvas->Close();
  2277. delete theCanvas;
  2278. delete hNoWeight[h];
  2279. delete hWeighted[h];
  2280. delete hRatio[h];
  2281. }
  2282. delete treePHSP;
  2283. return 1;
  2284. }
  2285. int compareAllAnglesInPHSP(int Run = 1){
  2286. bool b2Dweights = true;
  2287. std::vector<int>years;
  2288. if(Run == 1){
  2289. years.push_back(2011);
  2290. years.push_back(2012);
  2291. }
  2292. if(Run == 2){
  2293. years.push_back(2015);
  2294. years.push_back(2016);
  2295. years.push_back(2017);
  2296. years.push_back(2018);
  2297. }
  2298. for(int y = 0; y < years.size(); y++){
  2299. if(compareAnglesInPHSP(years.at(y), true, b2Dweights, false, firstMCweight) == 0){
  2300. coutERROR("Failed to compare angles for " + to_string(years.at(y)) + (Kst2Kspiplus && SplitDDandLL ? " (DD tracks)" : ""));
  2301. return 0;
  2302. }
  2303. if(Kst2Kspiplus && SplitDDandLL){
  2304. if(compareAnglesInPHSP(years.at(y), true, b2Dweights, true, firstMCweight) == 0){
  2305. coutERROR("Failed to compare angles for " + to_string(years.at(y)) + " (LL tracks)");
  2306. return 0;
  2307. }
  2308. }
  2309. }
  2310. return 1;
  2311. }
  2312. /////////////////////////////////////////////////////
  2313. ///
  2314. /// comparison of the angles between (2D-)weighted and non-weighted signal MC
  2315. ///
  2316. /////////////////////////////////////////////////////
  2317. int compareAnglesInMC(int year = 2011, bool sWeight = true, bool b2Dweighted = true, bool KshortDecayInVelo = true, std::string weightBranch = firstMCweight){
  2318. gStyle -> SetOptStat(0);
  2319. gROOT->SetBatch(kTRUE);
  2320. LHCbStyle();
  2321. //put both magnet polarities into one TChain
  2322. TChain * treeMC = new TChain("DecayTreeTruthMatched");
  2323. if(Kst2Kpluspi0Resolved){
  2324. treeMC->Add(Form("%s/data/MC/%i_KplusPi0Resolved_BDTinput%s.root", path_to_output_KplusPizero.c_str(), year, sWeight ? "" : "_nosWeight"));
  2325. }
  2326. else if(Kst2Kspiplus){
  2327. treeMC->Add(Form("%s/data/MC/%i_KshortPiplus%s_BDTinput%s.root", path_to_output_KshortPiplus.c_str(), year, SplitDDandLL ? (KshortDecayInVelo ? "_LL" : "_DD") : "", sWeight ? "" : "_nosWeight"));
  2328. }
  2329. int N = treeMC->GetEntries();
  2330. if(N == 0){
  2331. std::cout << Form("[ERROR]\t\tNo events found in file data/MC/%i_%s%s_BDTinput.root", year, TheDecay.c_str(), (Kst2Kspiplus && SplitDDandLL ? (KshortDecayInVelo ? "_LL" : "_DD") : "")) << std::endl;
  2332. return 0;
  2333. }
  2334. //deactivate all branches exept the one of intrest!
  2335. treeMC->SetBranchStatus("*",0);
  2336. treeMC->SetBranchStatus("B_plus_ThetaK",1);
  2337. treeMC->SetBranchStatus("B_plus_ThetaL",1);
  2338. treeMC->SetBranchStatus("B_plus_Phi",1);
  2339. treeMC->SetBranchStatus(Form("weight_%s",weightBranch.c_str()),1);
  2340. treeMC->SetBranchStatus(Form("weight2D_%s",weightBranch.c_str()),1);
  2341. double angle[3];//ctk, ctl, phi;
  2342. double w, w2d;
  2343. treeMC->SetBranchAddress("B_plus_ThetaK",&angle[0]);
  2344. treeMC->SetBranchAddress("B_plus_ThetaL",&angle[1]);
  2345. treeMC->SetBranchAddress("B_plus_Phi",&angle[2]);
  2346. treeMC->SetBranchAddress(Form("weight_%s",weightBranch.c_str()),&w);
  2347. treeMC->SetBranchAddress(Form("weight2D_%s",weightBranch.c_str()),&w2d);
  2348. //initialize histograms
  2349. int bins = 100;
  2350. double xLow[3] = {-1., -1., -TMath::Pi()};
  2351. double xHigh[3] = {+1., +1., +TMath::Pi()};
  2352. std::string theName[3] = {"cos(#theta_{K})", "cos(#theta_{L})", "#phi"};
  2353. std::string leName[3] = {"ctk", "ctl", "phi"};
  2354. TH1D * hRatio[3];
  2355. TH1D * hWeighted[3];
  2356. TH1D * hNoWeight[3];
  2357. for(int h = 0; h < 3; h++){
  2358. hRatio[h] = new TH1D(Form("hRatio_%s", leName[h].c_str()), Form("Ratio weighted to non-weighted (%s)", theName[h].c_str()), bins, xLow[h], xHigh[h]);
  2359. hWeighted[h] = new TH1D(Form("hWeighted_%s", leName[h].c_str()), Form("%sre-weighted distribution of %s", (b2Dweighted ? "2D-" : ""), theName[h].c_str()), bins, xLow[h], xHigh[h]);
  2360. hNoWeight[h] = new TH1D(Form("hNoWeight_%s", leName[h].c_str()), Form("Non-weighted distribution of %s", theName[h].c_str()), bins, xLow[h], xHigh[h]);
  2361. }
  2362. //loop over events and save to histograms
  2363. for(int i = 0; i < N; i++){
  2364. if(i%10000==0 && i != 0)std::cout << "Loading data event " << i << " / " << N << std::endl;
  2365. treeMC->GetEntry(i);
  2366. for(int a = 0; a < 3; a++){
  2367. if(a == 0 || a == 1){ //convert theta to cos(theta)
  2368. angle[a] = TMath::Cos(angle[a]);
  2369. }
  2370. hRatio[a] ->Fill(angle[a], b2Dweighted ? w2d : w);
  2371. hWeighted[a]->Fill(angle[a], b2Dweighted ? w2d : w);
  2372. hNoWeight[a]->Fill(angle[a], 1.0);
  2373. }
  2374. }
  2375. double varMax[3] = {-1.0e8,-1.0e8,-1.0e8};
  2376. double varMin[3] = {+1.0e8,+1.0e8,+1.0e8};
  2377. double ratioMax[3] = {-1.0e8,-1.0e8,-1.0e8};
  2378. double ratioMin[3] = {+1.0e8,+1.0e8,+1.0e8};
  2379. double val, weival, ratioval;
  2380. for(int h = 0; h < 3; h++){
  2381. //make ratio:
  2382. hRatio[h]->Divide(hNoWeight[h]);
  2383. //set correct ranges for the histograms:
  2384. for(int bin = 1; bin <= bins; bin++){
  2385. val = hNoWeight[h]->GetBinContent(bin);
  2386. weival = hWeighted[h]->GetBinContent(bin);
  2387. ratioval = hRatio[h] ->GetBinContent(bin);
  2388. if(varMax[h] <= val) varMax[h] = val;
  2389. if(varMax[h] <= weival) varMax[h] = weival;
  2390. if(ratioMax[h] <= ratioval)ratioMax[h] = ratioval;
  2391. if(varMin[h] >= val) varMin[h] = val;
  2392. if(varMin[h] >= weival) varMin[h] = weival;
  2393. if(ratioMin[h] >= ratioval)ratioMin[h] = ratioval;
  2394. }
  2395. varMax[h] *= 1.1;
  2396. if(varMin[h] < 0)varMin[h] *= 1.1;
  2397. else varMin[h] = 0.001; //if minimum is positve, set minimum to just above 0 to remove label
  2398. if(ratioMax[h] > 3.)ratioMax[h] = 3.;
  2399. if(ratioMax[h] < 2.)ratioMax[h] = 2.;
  2400. ratioMax[h] *= 1.1;
  2401. //configurables for plotting
  2402. float lowerPlotHeight = 0.6;
  2403. //create two pads into one canvas
  2404. TCanvas * theCanvas = new TCanvas(Form("theCanvas%s", leName[h].c_str()), Form("ratio and superposition of %s" , theName[h].c_str()));
  2405. float textsize = gStyle->GetTextSize();
  2406. TPad * pad1 = new TPad(Form("pad1%s", leName[h].c_str()), "ratio",0.0,lowerPlotHeight,1.0,1.0,0);
  2407. TPad * pad2 = new TPad(Form("pad2%s", leName[h].c_str()), "superposition",0.0,0.0,1.0,lowerPlotHeight,0);
  2408. pad1->Draw();
  2409. pad2->Draw();
  2410. //modifiy pad for main plot
  2411. pad1->Clear();
  2412. pad1->SetBorderSize (0);
  2413. pad1->SetBottomMargin(1e-6);
  2414. pad1->SetTopMargin(pad1->GetTopMargin() / ( 1 - lowerPlotHeight) );
  2415. pad1->cd();
  2416. //some axis-modifications on the main plot
  2417. TGaxis::SetExponentOffset(1e+9,1e+9,"y");//offset = pad size * 1e+7
  2418. hRatio[h]->GetXaxis()->SetNoExponent(); //<-- spoils MaxDigits settings, so don't use it on other axis
  2419. hRatio[h]->GetXaxis()->SetLabelSize(0.0);//don't print labels
  2420. hRatio[h]->GetXaxis()->SetRangeUser(xLow[h], xHigh[h]);
  2421. hRatio[h]->GetXaxis()->SetTickLength(hRatio[h]->GetXaxis()->GetTickLength()/(1-lowerPlotHeight));
  2422. hRatio[h]->GetXaxis()->SetNdivisions(gStyle->GetNdivisions("X"));
  2423. hRatio[h]->GetYaxis()->SetTitle("ratio (#omega / 1.0)");
  2424. hRatio[h]->GetYaxis()->SetTitleSize(textsize/(1-lowerPlotHeight));
  2425. hRatio[h]->GetYaxis()->SetLabelSize(textsize/(1-lowerPlotHeight));
  2426. hRatio[h]->GetYaxis()->SetTickLength(hRatio[h]->GetYaxis()->GetTickLength());
  2427. hRatio[h]->GetYaxis()->SetNdivisions(gStyle->GetNdivisions("Y"));
  2428. hRatio[h]->GetYaxis()->SetTitleOffset(1.06*(1-lowerPlotHeight));
  2429. hRatio[h]->GetYaxis()->SetRangeUser(0.5, 1.5);
  2430. hRatio[h]->Draw("E1");
  2431. TLine * unityline = new TLine(xLow[h], 1, xHigh[h], 1);
  2432. unityline->SetLineStyle(2);
  2433. unityline->SetLineColor(4);
  2434. unityline->Draw("SAME");
  2435. pad2->Clear();
  2436. pad2->SetBorderSize (0);
  2437. pad2->SetTopMargin (1e-6);
  2438. pad2->SetBottomMargin(pad2->GetBottomMargin() / lowerPlotHeight );
  2439. pad2->cd();
  2440. TGaxis::SetExponentOffset(1e+9,1e+9,"x");//offset = pad size * 1e+7
  2441. hNoWeight[h]->GetXaxis()->SetTitleOffset(1.05);
  2442. hNoWeight[h]->GetXaxis()->SetTitleSize (textsize/lowerPlotHeight);
  2443. hNoWeight[h]->GetXaxis()->SetLabelSize (textsize/lowerPlotHeight);
  2444. hNoWeight[h]->GetXaxis()->SetTickLength (hRatio[h]->GetXaxis()->GetTickLength()/(lowerPlotHeight/(1-lowerPlotHeight)));
  2445. hNoWeight[h]->GetXaxis()->SetNdivisions (gStyle->GetNdivisions("X"));
  2446. hNoWeight[h]->GetXaxis()->SetTitle(theName[h].c_str());
  2447. hNoWeight[h]->GetXaxis()->SetRangeUser(xLow[h], xHigh[h]);
  2448. hNoWeight[h]->GetYaxis()->SetRangeUser(varMin[h], varMax[h]);
  2449. hNoWeight[h]->GetYaxis()->SetTitle("events");
  2450. hNoWeight[h]->GetYaxis()->SetLabelSize (textsize/lowerPlotHeight);
  2451. hNoWeight[h]->GetYaxis()->SetTitleSize (textsize/lowerPlotHeight);
  2452. hNoWeight[h]->GetYaxis()->SetTickLength(hRatio[h]->GetYaxis()->GetTickLength());
  2453. hNoWeight[h]->GetYaxis()->SetNdivisions (gStyle->GetNdivisions("Y"));
  2454. hNoWeight[h]->GetYaxis()->SetTitleOffset(1.06*lowerPlotHeight);
  2455. hNoWeight[h]->Draw("E1");
  2456. hWeighted[h]->SetLineColor(2);
  2457. hWeighted[h]->SetMarkerColor(2);
  2458. hWeighted[h]->Draw("E1SAME");
  2459. //Legend and position...
  2460. float LegendXposition = 0.4;
  2461. float LegendYposition = 0.3;
  2462. TLegend * leg = new TLegend(LegendXposition,LegendYposition,LegendXposition + 0.25, LegendYposition + 0.18);
  2463. leg->AddEntry(hWeighted[h],Form("%sweighted signal MC",(b2Dweighted ? "2#upoint1D-" : "")), "lpe");
  2464. leg->AddEntry(hNoWeight[h],"non-weighted signal MC", "lpe");
  2465. leg->SetTextSize(0.04/lowerPlotHeight); // works fine
  2466. leg->Draw("same");
  2467. addLHCbtag(LegendXposition, LegendYposition + 0.27, "simulation", 1, 1/lowerPlotHeight);
  2468. if (Kst2Kspiplus)theCanvas->Print(Form("%s/ComparePlots/%i_%s%s_Comparison_SignalMC%sWeights_%s%s.eps", path_to_output_KshortPiplus.c_str(), year, TheDecay.c_str(), (SplitDDandLL ? (KshortDecayInVelo ? "_LL" : "_DD") : ""), (b2Dweighted ? "2D" : ""), leName[h].c_str(), sWeight ? "" : "_nosWeight"));
  2469. else theCanvas->Print(Form("%s/ComparePlots/%i_%s_Comparison_SignalMC%sWeights_%s%s.eps", path_to_output_KplusPizero.c_str(), year, TheDecay.c_str(), (b2Dweighted ? "2D" : ""), leName[h].c_str(), sWeight ? "" : "_nosWeight"));
  2470. theCanvas->Close();
  2471. delete theCanvas;
  2472. delete hNoWeight[h];
  2473. delete hWeighted[h];
  2474. delete hRatio[h];
  2475. }
  2476. delete treeMC;
  2477. return 1;
  2478. }
  2479. int compareAllAnglesInMC(int Run = 1){
  2480. bool b2Dweights = true;
  2481. std::vector<int>years = yearsVectorInt(true,false,false,Run);
  2482. for(int y = 0; y < years.size(); y++){
  2483. if(compareAnglesInMC(years.at(y), true, b2Dweights, false, firstMCweight) == 0){
  2484. coutERROR("Failed to compare angles for " + to_string(years.at(y)) + (Kst2Kspiplus && SplitDDandLL ? " (DD tracks)" : ""));
  2485. return 0;
  2486. }
  2487. if(Kst2Kspiplus && SplitDDandLL){
  2488. if(compareAnglesInMC(years.at(y), true, b2Dweights, true, firstMCweight) == 0){
  2489. coutERROR("Failed to compare angles for " + to_string(years.at(y)) + " (LL tracks)");
  2490. return 0;
  2491. }
  2492. }
  2493. }
  2494. return 1;
  2495. }
  2496. /////////////////////////////////////////////////////
  2497. ///
  2498. /// comparison of the angles in PHSP MC before and after the BDT cut
  2499. ///
  2500. /////////////////////////////////////////////////////
  2501. int compareAnglesInPHSPbeforeAndAfterBDTcut(int year = 2011, bool bweighted = true, bool b2Dweighted = true, bool KshortDecayInVelo = true, std::string weightBranch = firstMCweight){
  2502. gStyle -> SetOptStat(0);
  2503. gROOT->SetBatch(kTRUE);
  2504. LHCbStyle();
  2505. bool NormalizedRatio = false;
  2506. std::string weighzzz = "";
  2507. if(bweighted){
  2508. weighzzz = "weighted";
  2509. }
  2510. if(b2Dweighted){
  2511. bweighted = true;
  2512. weighzzz = "2*1D-weighted";
  2513. }
  2514. //put both magnet polarities into one TChain
  2515. TChain * treePHSP[2];
  2516. treePHSP[0] = new TChain("DecayTreeTruthMatched");
  2517. treePHSP[1] = new TChain("SelectionOutput");
  2518. if(Kst2Kpluspi0Resolved){
  2519. treePHSP[0]->Add(Form("%s/data/PHSP/%i_KplusPi0ResolvedPHSP_BDTinput.root", path_to_output_KplusPizero.c_str(), year));
  2520. treePHSP[1]->Add(Form("%s/data/PHSP/KplusPi0Resolved_PHSP_BDToutputSelection_Run%i_%i.root", path_to_output_KplusPizero.c_str(), (year > 2012 ? 2 : 1), year));
  2521. }
  2522. else if(Kst2Kspiplus){
  2523. treePHSP[0]->Add(Form("%s/data/PHSP/%i_KshortPiplusPHSP%s_BDTinput.root", path_to_output_KshortPiplus.c_str(), year, (SplitDDandLL ? (KshortDecayInVelo ? "_LL" : "_DD") : "")));
  2524. treePHSP[1]->Add(Form("%s/data/PHSP/KshortPiplus%s_PHSP_BDToutputSelection_Run%i_%i.root", path_to_output_KshortPiplus.c_str(), (SplitDDandLL ? (KshortDecayInVelo ? "_LL" : "_DD") : ""), (year > 2012 ? 2 : 1), year));
  2525. }
  2526. int Nb = treePHSP[0]->GetEntries();
  2527. int Na = treePHSP[1]->GetEntries();
  2528. if(Nb == 0){
  2529. std::cout << Form("[ERROR]\t\tNo events found in file data/PHSP/%i_%sPHSP%s_BDTinput.root", year, TheDecay.c_str(), (Kst2Kspiplus && SplitDDandLL ? (KshortDecayInVelo ? "_LL" : "_DD") : "")) << std::endl;
  2530. return 0;
  2531. }
  2532. if(Na == 0){
  2533. std::cout << Form("[ERROR]\t\tNo events found in file data/PHSP/%s%sPHSP_BDToutputSelection_Run%i_%i.root", TheDecay.c_str(), (Kst2Kspiplus && SplitDDandLL ? (KshortDecayInVelo ? "_LL" : "_DD") : ""), (year > 2012 ? 2 : 1), year) << std::endl;
  2534. return 0;
  2535. }
  2536. double angle[3][2];//ctk, ctl, phi;
  2537. double w[2], w2d[2];
  2538. for(int i = 0; i < 2; i++){
  2539. //deactivate all branches exept the one of intrest!
  2540. treePHSP[i]->SetBranchStatus("*",0);
  2541. treePHSP[i]->SetBranchStatus("B_plus_ThetaK",1);
  2542. treePHSP[i]->SetBranchStatus("B_plus_ThetaL",1);
  2543. treePHSP[i]->SetBranchStatus("B_plus_Phi",1);
  2544. treePHSP[i]->SetBranchStatus(Form("weight_%s",weightBranch.c_str()),1);
  2545. treePHSP[i]->SetBranchStatus(Form("weight2D_%s",weightBranch.c_str()),1);
  2546. treePHSP[i]->SetBranchAddress("B_plus_ThetaK",&angle[0][i]);
  2547. treePHSP[i]->SetBranchAddress("B_plus_ThetaL",&angle[1][i]);
  2548. treePHSP[i]->SetBranchAddress("B_plus_Phi",&angle[2][i]);
  2549. treePHSP[i]->SetBranchAddress(Form("weight_%s",weightBranch.c_str()),&w[i]);
  2550. treePHSP[i]->SetBranchAddress(Form("weight2D_%s",weightBranch.c_str()),&w2d[i]);
  2551. }
  2552. //initialize histograms
  2553. int bins = 40;//100;
  2554. double xLow[3] = {-1., -1., -TMath::Pi()};
  2555. double xHigh[3] = {+1., +1., +TMath::Pi()};
  2556. std::string theName[3] = {"cos(#theta_{K})", "cos(#theta_{L})", "#phi"};
  2557. std::string leName[3] = {"ctk", "ctl", "phi"};
  2558. TH1D * hRatio[3];
  2559. TH1D * hBefore[3];
  2560. TH1D * hAfter[3];
  2561. for(int h = 0; h < 3; h++){
  2562. hRatio [h] = new TH1D(Form("hRatio_%s" , leName[h].c_str()), Form("Ratio of %s after/before%s", theName[h].c_str(), (bweighted ? (" ("+weighzzz+")").c_str() : "")), bins, xLow[h], xHigh[h]);
  2563. hBefore[h] = new TH1D(Form("hBefore_%s", leName[h].c_str()), Form("%s before BDT%s", theName[h].c_str(), (bweighted ? (" ("+weighzzz+")").c_str() : "")), bins, xLow[h], xHigh[h]);
  2564. hAfter [h] = new TH1D(Form("hAfter_%s" , leName[h].c_str()), Form("%s after BDT%s", theName[h].c_str(), (bweighted ? (" ("+weighzzz+")").c_str() : "")), bins, xLow[h], xHigh[h]);
  2565. hRatio [h]->Sumw2();
  2566. hBefore[h]->Sumw2();
  2567. hAfter [h]->Sumw2();
  2568. }
  2569. //loop over events and save to histograms
  2570. for(int i = 0; i < Na; i++){
  2571. if(i%10000==0 && i != 0)std::cout << "Loading data event " << i << " / " << Na << std::endl;
  2572. treePHSP[1]->GetEntry(i);
  2573. for(int a = 0; a < 3; a++){
  2574. if(a == 0 || a == 1){ //convert theta to cos(theta)
  2575. angle[a][1] = TMath::Cos(angle[a][1]);
  2576. }
  2577. hRatio[a]->Fill(angle[a][1], bweighted ? (b2Dweighted ? w2d[1] : w[1]) : 1.);
  2578. hAfter[a]->Fill(angle[a][1], bweighted ? (b2Dweighted ? w2d[1] : w[1]) : 1.);
  2579. }
  2580. }
  2581. //loop over events and save to histograms
  2582. for(int i = 0; i < Nb; i++){
  2583. if(i%10000==0 && i != 0)std::cout << "Loading data event " << i << " / " << Nb << std::endl;
  2584. treePHSP[0]->GetEntry(i);
  2585. for(int a = 0; a < 3; a++){
  2586. if(a == 0 || a == 1){ //convert theta to cos(theta)
  2587. angle[a][0] = TMath::Cos(angle[a][0]);
  2588. }
  2589. hBefore[a]->Fill(angle[a][0], bweighted ? (b2Dweighted ? w2d[0] : w[0]) : 1.);
  2590. }
  2591. }
  2592. double varMax[3] = {-1.0e8,-1.0e8,-1.0e8};
  2593. double varMin[3] = {+1.0e8,+1.0e8,+1.0e8};
  2594. double ratioMax[3] = {-1.0e8,-1.0e8,-1.0e8};
  2595. double ratioMin[3] = {+1.0e8,+1.0e8,+1.0e8};
  2596. double valb, vala, ratioval;
  2597. for(int h = 0; h < 3; h++){
  2598. if(NormalizedRatio)
  2599. hRatio [h]->Scale(hBefore[h]->Integral()/hRatio[h]->Integral());
  2600. //make ratio:
  2601. hRatio[h]->Divide(hBefore[h]);
  2602. //set correct ranges for the histograms:
  2603. for(int bin = 1; bin <= bins; bin++){
  2604. valb = hBefore[h]->GetBinContent(bin);
  2605. vala = hAfter[h] ->GetBinContent(bin);
  2606. ratioval = hRatio[h] ->GetBinContent(bin);
  2607. if(varMax[h] <= vala) varMax[h] = vala;
  2608. if(varMax[h] <= valb) varMax[h] = valb;
  2609. if(ratioMax[h] <= ratioval)ratioMax[h] = ratioval;
  2610. if(varMin[h] >= vala) varMin[h] = vala;
  2611. if(varMin[h] >= valb) varMin[h] = valb;
  2612. if(ratioMin[h] >= ratioval)ratioMin[h] = ratioval;
  2613. }
  2614. varMax[h] *= 1.1;
  2615. if(varMin[h] < 0)varMin[h] *= 1.1;
  2616. else varMin[h] = 0.001; //if minimum is positve, set minimum to just above 0 to remove label
  2617. if(ratioMax[h] > 3.)ratioMax[h] = 3.;
  2618. if(ratioMax[h] < 2.)ratioMax[h] = 2.;
  2619. ratioMax[h] *= 1.1;
  2620. //configurables for plotting
  2621. float lowerPlotHeight = 0.6;
  2622. //create two pads into one canvas
  2623. TCanvas * theCanvas = new TCanvas(Form("theCanvas%s", leName[h].c_str()), Form("ratio and superposition of %s" , theName[h].c_str()));
  2624. float textsize = gStyle->GetTextSize();
  2625. TPad * pad1 = new TPad(Form("pad1%s", leName[h].c_str()), "ratio",0.0,lowerPlotHeight,1.0,1.0,0);
  2626. TPad * pad2 = new TPad(Form("pad2%s", leName[h].c_str()), "superposition",0.0,0.0,1.0,lowerPlotHeight,0);
  2627. pad1->Draw();
  2628. pad2->Draw();
  2629. //modifiy pad for main plot
  2630. pad1->Clear();
  2631. pad1->SetBorderSize (0);
  2632. pad1->SetBottomMargin(1e-6);
  2633. pad1->SetTopMargin(pad1->GetTopMargin() / ( 1 - lowerPlotHeight) );
  2634. pad1->cd();
  2635. //some axis-modifications on the main plot
  2636. TGaxis::SetExponentOffset(1e+9,1e+9,"y");//offset = pad size * 1e+7
  2637. hRatio[h]->GetXaxis()->SetNoExponent(); //<-- spoils MaxDigits settings, so don't use it on other axis
  2638. hRatio[h]->GetXaxis()->SetLabelSize(0.0);//don't print labels
  2639. hRatio[h]->GetXaxis()->SetRangeUser(xLow[h], xHigh[h]);
  2640. hRatio[h]->GetXaxis()->SetTickLength(hRatio[h]->GetXaxis()->GetTickLength()/(1-lowerPlotHeight));
  2641. hRatio[h]->GetXaxis()->SetNdivisions(gStyle->GetNdivisions("X"));
  2642. hRatio[h]->GetYaxis()->SetTitle("ratio");
  2643. hRatio[h]->GetYaxis()->SetTitleSize(textsize/(1-lowerPlotHeight));
  2644. hRatio[h]->GetYaxis()->SetLabelSize(textsize/(1-lowerPlotHeight));
  2645. hRatio[h]->GetYaxis()->SetTickLength(hRatio[h]->GetYaxis()->GetTickLength());
  2646. hRatio[h]->GetYaxis()->SetNdivisions(gStyle->GetNdivisions("Y"));
  2647. hRatio[h]->GetYaxis()->SetTitleOffset(1.06*(1-lowerPlotHeight));
  2648. if(NormalizedRatio)
  2649. hRatio[h]->GetYaxis()->SetRangeUser(0.5, 1.5);
  2650. else
  2651. hRatio[h]->GetYaxis()->SetRangeUser(0.5, 1.0);
  2652. hRatio[h]->Draw("E1");
  2653. TLine * unityline = new TLine(xLow[h], 1, xHigh[h], 1);
  2654. unityline->SetLineStyle(2);
  2655. unityline->SetLineColor(4);
  2656. if(NormalizedRatio)
  2657. unityline->Draw("SAME");
  2658. pad2->Clear();
  2659. pad2->SetBorderSize (0);
  2660. pad2->SetTopMargin (1e-6);
  2661. pad2->SetBottomMargin(pad2->GetBottomMargin() / lowerPlotHeight );
  2662. pad2->cd();
  2663. TGaxis::SetExponentOffset(1e+9,1e+9,"x");//offset = pad size * 1e+7
  2664. hBefore[h]->GetXaxis()->SetTitleOffset(1.05);
  2665. hBefore[h]->GetXaxis()->SetTitleSize (textsize/lowerPlotHeight);
  2666. hBefore[h]->GetXaxis()->SetLabelSize (textsize/lowerPlotHeight);
  2667. hBefore[h]->GetXaxis()->SetTickLength (hRatio[h]->GetXaxis()->GetTickLength()/(lowerPlotHeight/(1-lowerPlotHeight)));
  2668. hBefore[h]->GetXaxis()->SetNdivisions (gStyle->GetNdivisions("X"));
  2669. hBefore[h]->GetXaxis()->SetTitle(theName[h].c_str());
  2670. hBefore[h]->GetXaxis()->SetRangeUser(xLow[h], xHigh[h]);
  2671. hBefore[h]->GetYaxis()->SetRangeUser(varMin[h], varMax[h]);
  2672. hBefore[h]->GetYaxis()->SetTitle("events");
  2673. hBefore[h]->GetYaxis()->SetLabelSize (textsize/lowerPlotHeight);
  2674. hBefore[h]->GetYaxis()->SetTitleSize (textsize/lowerPlotHeight);
  2675. hBefore[h]->GetYaxis()->SetTickLength(hRatio[h]->GetYaxis()->GetTickLength());
  2676. hBefore[h]->GetYaxis()->SetNdivisions (gStyle->GetNdivisions("Y"));
  2677. hBefore[h]->GetYaxis()->SetTitleOffset(1.06*lowerPlotHeight);
  2678. hBefore[h]->Draw("E1");
  2679. hAfter[h]->SetLineColor(2);
  2680. hAfter[h]->SetMarkerColor(2);
  2681. hAfter[h]->Draw("E1SAME");
  2682. //Legend and position...
  2683. float LegendXposition = 0.4;
  2684. float LegendYposition = 0.3;
  2685. TLegend * leg = new TLegend(LegendXposition,LegendYposition,LegendXposition + 0.25, LegendYposition + 0.18);
  2686. leg->AddEntry(hAfter[h],"After BDT cut", "lpe");
  2687. leg->AddEntry(hBefore[h],"Before BDT cut", "lpe");
  2688. leg->SetTextSize(0.04/lowerPlotHeight); // works fine
  2689. leg->Draw("same");
  2690. addLHCbtag(LegendXposition, LegendYposition + 0.27, "simulation", 1, 1/lowerPlotHeight);
  2691. if (Kst2Kspiplus)theCanvas->Print(Form("%s/ComparePlots/%i_%s%s_Comparison%sBeforeAndAfterBDTcut_%s.eps", path_to_output_KshortPiplus.c_str(), year, TheDecay.c_str(), (SplitDDandLL ? (KshortDecayInVelo ? "_LL" : "_DD") : ""), (b2Dweighted ? "2D" : ""), leName[h].c_str()));
  2692. else theCanvas->Print(Form("%s/ComparePlots/%i_%s_Comparison%sBeforeAndAfterBDTcut_%s.eps", path_to_output_KplusPizero.c_str(), year, TheDecay.c_str(), (b2Dweighted ? "2D" : ""), leName[h].c_str()));
  2693. theCanvas->Close();
  2694. delete theCanvas;
  2695. delete hAfter [h];
  2696. delete hBefore[h];
  2697. delete hRatio [h];
  2698. }
  2699. delete treePHSP[0];
  2700. delete treePHSP[1];
  2701. return 1;
  2702. }
  2703. int compareAllPHSPAnglesBeforeAndAfterBDT(int Run = 1){
  2704. bool bWeights = true;
  2705. bool b2Dweights = true;
  2706. std::vector<int>years = yearsVectorInt(true,false,true,Run);
  2707. for(int y = 0; y < years.size(); y++){
  2708. if(compareAnglesInPHSPbeforeAndAfterBDTcut(years.at(y), bWeights, b2Dweights, false) == 0){
  2709. coutERROR("Failed to compare angles for " + to_string(years.at(y)) + (Kst2Kspiplus && SplitDDandLL ? " (DD tracks)" : "") );
  2710. return 0;
  2711. }
  2712. if(Kst2Kspiplus && SplitDDandLL){
  2713. if(compareAnglesInPHSPbeforeAndAfterBDTcut(years.at(y), bWeights, b2Dweights, true) == 0){
  2714. coutERROR("Failed to compare angles for " + to_string(years.at(y)) + " (LL tracks)" );
  2715. return 0;
  2716. }
  2717. }
  2718. }
  2719. return 1;
  2720. }
  2721. /////////////////////////////////////////////////////
  2722. ///
  2723. /// comparison of nTracks and B_plus_PT between signal and reference channel MC
  2724. ///
  2725. /////////////////////////////////////////////////////
  2726. int compareNTracksAndBplusPT(int year = 2011, bool KshortDecayInVelo = true){
  2727. gROOT->SetBatch(kTRUE);
  2728. gStyle -> SetOptStat(0);
  2729. LHCbStyle();
  2730. bool NormalizedRatio = true;
  2731. if(year > 2012){
  2732. std::cout << "No Reference MC for Run II available. Abort!" << std::endl;
  2733. return 0;
  2734. }
  2735. //put both magnet polarities into one TChain
  2736. TChain * treeMC[2];
  2737. treeMC[0] = new TChain("DecayTreeTruthMatched");
  2738. treeMC[1] = new TChain("DecayTreeTruthMatched");
  2739. if(Kst2Kpluspi0Resolved){
  2740. treeMC[0]->Add(Form("%s/data/MC/%i_KplusPi0Resolved_BDTinput.root", path_to_output_KplusPizero.c_str(), year));
  2741. treeMC[1]->Add(Form("%s/data/MC/%i_RefKplusPi0Resolved_BDTinput.root", path_to_output_KplusPizero.c_str(), year));
  2742. }
  2743. else if(Kst2Kspiplus){
  2744. treeMC[0]->Add(Form("%s/data/MC/%i_KshortPiplus%s_BDTinput.root", path_to_output_KshortPiplus.c_str(), year, (SplitDDandLL ? (KshortDecayInVelo ? "_LL" : "_DD") : "")));
  2745. treeMC[1]->Add(Form("%s/data/MC/%i_KshortPiplusRef%s_BDTinput.root", path_to_output_KshortPiplus.c_str(), year, (SplitDDandLL ? (KshortDecayInVelo ? "_LL" : "_DD") : "")));
  2746. }
  2747. int N[2];
  2748. N[0] = treeMC[0]->GetEntries();
  2749. N[1] = treeMC[1]->GetEntries();
  2750. if(N[0] == 0){
  2751. std::cout << Form("[ERROR]\t\tNo events found in file data/MC/%i_%s%s_BDTinput.root", year, TheDecay.c_str(), (Kst2Kspiplus && SplitDDandLL ? (KshortDecayInVelo ? "_LL" : "_DD") : "")) << std::endl;
  2752. return 0;
  2753. }
  2754. if(N[1] == 0){
  2755. std::cout << Form("[ERROR]\t\tNo events found in file data/MC/%i_%sRef%s_BDTinput.root", year, TheDecay.c_str(), (Kst2Kspiplus && SplitDDandLL ? (KshortDecayInVelo ? "_LL" : "_DD") : "")) << std::endl;
  2756. return 0;
  2757. }
  2758. const int nVars = 2;
  2759. double var[nVars][2];//nTracks, B_plus_PT;
  2760. int varNtracks[2];
  2761. std::string theName[nVars] = {"nTracks", "p_{T}(B^{+})"};
  2762. std::string leName[nVars] = {"nTracks", "B_plus_PT"};
  2763. double xLow[nVars] = {-0.5 , 0.};
  2764. double xHigh[nVars] = {599.5, 60000.};
  2765. for(int i = 0; i < 2; i++){
  2766. //deactivate all branches exept the one of intrest!
  2767. treeMC[i]->SetBranchStatus("*",0);
  2768. treeMC[i]->SetBranchStatus("nTracks",1);
  2769. treeMC[i]->SetBranchStatus(UseDTF ? "B_plus_PT_DTF" : "B_plus_PT",1);
  2770. treeMC[i]->SetBranchAddress("nTracks",&varNtracks[i]);
  2771. treeMC[i]->SetBranchAddress(UseDTF ? "B_plus_PT_DTF" : "B_plus_PT",&var[1][i]);
  2772. }
  2773. //initialize histograms
  2774. int bins = 100;
  2775. TH1D * hRatio[nVars];
  2776. TH1D * hSignal[nVars];
  2777. TH1D * hRefere[nVars];
  2778. for(int h = 0; h < nVars; h++){
  2779. hRatio [h] = new TH1D(Form("hRatio_%s" , leName[h].c_str()), Form("Ratio of %s signal/ref", theName[h].c_str()), bins, xLow[h], xHigh[h]);
  2780. hSignal[h] = new TH1D(Form("hSignal_%s", leName[h].c_str()), Form("%s (Signal)", theName[h].c_str()), bins, xLow[h], xHigh[h]);
  2781. hRefere[h] = new TH1D(Form("hRefere_%s", leName[h].c_str()), Form("%s (Ref)" , theName[h].c_str()), bins, xLow[h], xHigh[h]);
  2782. hRatio [h]->Sumw2();
  2783. hSignal[h]->Sumw2();
  2784. hRefere[h]->Sumw2();
  2785. }
  2786. //loop over events and save to histograms
  2787. for(int n = 0; n < 2; n++){
  2788. for(int i = 0; i < N[n]; i++){
  2789. if(i%1000==0 && i != 0)std::cout << "Loading data event " << i << " / " << N[n] << std::endl;
  2790. treeMC[n]->GetEntry(i);
  2791. for(int v = 0; v < nVars; v++){
  2792. if(v == 0){ //use int link to variable (only nTracks)
  2793. if(n == 0){
  2794. hRatio [v]->Fill(varNtracks[n], 1.);
  2795. hSignal[v]->Fill(varNtracks[n], 1.);
  2796. }
  2797. else{
  2798. hRefere[v]->Fill(varNtracks[n], 1.);
  2799. }
  2800. }
  2801. else{ //use double link to variable
  2802. if(n == 0){
  2803. hRatio [v]->Fill(var[v][n], 1.);
  2804. hSignal[v]->Fill(var[v][n], 1.);
  2805. }
  2806. else{
  2807. hRefere[v]->Fill(var[v][n], 1.);
  2808. }
  2809. }
  2810. }
  2811. }
  2812. }
  2813. double varMax[3] = {-1.0e8,-1.0e8,-1.0e8};
  2814. double varMin[3] = {+1.0e8,+1.0e8,+1.0e8};
  2815. double ratioMax[3] = {-1.0e8,-1.0e8,-1.0e8};
  2816. double ratioMin[3] = {+1.0e8,+1.0e8,+1.0e8};
  2817. double valb, vala, ratioval;
  2818. for(int h = 0; h < nVars; h++){
  2819. if(NormalizedRatio){
  2820. hSignal[h]->Scale(1./hSignal[h]->Integral());
  2821. hRefere[h]->Scale(1./hRefere[h]->Integral());
  2822. hRatio [h]->Scale(1./hRatio[h] ->Integral());
  2823. }
  2824. //make ratio:
  2825. hRatio[h]->Divide(hRefere[h]);
  2826. //set correct ranges for the histograms:
  2827. for(int bin = 1; bin <= bins; bin++){
  2828. valb = hRefere[h]->GetBinContent(bin);
  2829. vala = hSignal[h]->GetBinContent(bin);
  2830. ratioval = hRatio[h] ->GetBinContent(bin);
  2831. if(varMax[h] <= vala) varMax[h] = vala;
  2832. if(varMax[h] <= valb) varMax[h] = valb;
  2833. if(ratioMax[h] <= ratioval)ratioMax[h] = ratioval;
  2834. if(varMin[h] >= vala) varMin[h] = vala;
  2835. if(varMin[h] >= valb) varMin[h] = valb;
  2836. if(ratioMin[h] >= ratioval)ratioMin[h] = ratioval;
  2837. }
  2838. varMax[h] *= 1.1;
  2839. if(varMin[h] < 0)varMin[h] *= 1.1;
  2840. else varMin[h] = 0.001; //if minimum is positve, set minimum to just above 0 to remove label
  2841. if(ratioMax[h] > 3.)ratioMax[h] = 3.;
  2842. if(ratioMax[h] < 2.)ratioMax[h] = 2.;
  2843. ratioMax[h] *= 1.1;
  2844. //configurables for plotting
  2845. float lowerPlotHeight = 0.6;
  2846. //create two pads into one canvas
  2847. TCanvas * theCanvas = new TCanvas(Form("theCanvas%s", leName[h].c_str()), Form("ratio and superposition of %s" , theName[h].c_str()));
  2848. float textsize = gStyle->GetTextSize();
  2849. TPad * pad1 = new TPad(Form("pad1%s", leName[h].c_str()), "ratio",0.0,lowerPlotHeight,1.0,1.0,0);
  2850. TPad * pad2 = new TPad(Form("pad2%s", leName[h].c_str()), "superposition",0.0,0.0,1.0,lowerPlotHeight,0);
  2851. pad1->Draw();
  2852. pad2->Draw();
  2853. //modifiy pad for main plot
  2854. pad1->Clear();
  2855. pad1->SetBorderSize (0);
  2856. pad1->SetBottomMargin(1e-6);
  2857. pad1->SetTopMargin(pad1->GetTopMargin() / ( 1 - lowerPlotHeight) );
  2858. pad1->cd();
  2859. //some axis-modifications on the main plot
  2860. TGaxis::SetExponentOffset(1e+9,1e+9,"y");//offset = pad size * 1e+7
  2861. hRatio[h]->GetXaxis()->SetNoExponent(); //<-- spoils MaxDigits settings, so don't use it on other axis
  2862. hRatio[h]->GetXaxis()->SetLabelSize(0.0);//don't print labels
  2863. hRatio[h]->GetXaxis()->SetRangeUser(xLow[h], xHigh[h]);
  2864. hRatio[h]->GetXaxis()->SetTickLength(hRatio[h]->GetXaxis()->GetTickLength()/(1-lowerPlotHeight));
  2865. hRatio[h]->GetXaxis()->SetNdivisions(gStyle->GetNdivisions("X"));
  2866. hRatio[h]->GetYaxis()->SetTitle("ratio");
  2867. hRatio[h]->GetYaxis()->SetTitleSize(textsize/(1-lowerPlotHeight));
  2868. hRatio[h]->GetYaxis()->SetLabelSize(textsize/(1-lowerPlotHeight));
  2869. hRatio[h]->GetYaxis()->SetTickLength(hRatio[h]->GetYaxis()->GetTickLength());
  2870. hRatio[h]->GetYaxis()->SetNdivisions(gStyle->GetNdivisions("Y"));
  2871. hRatio[h]->GetYaxis()->SetTitleOffset(1.06*(1-lowerPlotHeight));
  2872. if(NormalizedRatio)
  2873. hRatio[h]->GetYaxis()->SetRangeUser(0.5, 1.5);
  2874. else
  2875. hRatio[h]->GetYaxis()->SetRangeUser(0.5, 1.0);
  2876. hRatio[h]->Draw("E1");
  2877. TLine * unityline = new TLine(xLow[h], 1, xHigh[h], 1);
  2878. unityline->SetLineStyle(2);
  2879. unityline->SetLineColor(4);
  2880. if(NormalizedRatio)
  2881. unityline->Draw("SAME");
  2882. pad2->Clear();
  2883. pad2->SetBorderSize (0);
  2884. pad2->SetTopMargin (1e-6);
  2885. pad2->SetBottomMargin(pad2->GetBottomMargin() / lowerPlotHeight );
  2886. pad2->cd();
  2887. TGaxis::SetExponentOffset(1e+9,1e+9,"x");//offset = pad size * 1e+7
  2888. hRefere[h]->GetXaxis()->SetTitleOffset(1.05);
  2889. hRefere[h]->GetXaxis()->SetTitleSize (textsize/lowerPlotHeight);
  2890. hRefere[h]->GetXaxis()->SetLabelSize (textsize/lowerPlotHeight);
  2891. hRefere[h]->GetXaxis()->SetTickLength (hRatio[h]->GetXaxis()->GetTickLength()/(lowerPlotHeight/(1-lowerPlotHeight)));
  2892. hRefere[h]->GetXaxis()->SetNdivisions (gStyle->GetNdivisions("X"));
  2893. hRefere[h]->GetXaxis()->SetTitle(theName[h].c_str());
  2894. hRefere[h]->GetXaxis()->SetRangeUser(xLow[h], xHigh[h]);
  2895. hRefere[h]->GetYaxis()->SetRangeUser(varMin[h], varMax[h]);
  2896. hRefere[h]->GetYaxis()->SetTitle("events");
  2897. hRefere[h]->GetYaxis()->SetLabelSize (textsize/lowerPlotHeight);
  2898. hRefere[h]->GetYaxis()->SetTitleSize (textsize/lowerPlotHeight);
  2899. hRefere[h]->GetYaxis()->SetTickLength(hRatio[h]->GetYaxis()->GetTickLength());
  2900. hRefere[h]->GetYaxis()->SetNdivisions (gStyle->GetNdivisions("Y"));
  2901. hRefere[h]->GetYaxis()->SetTitleOffset(1.06*lowerPlotHeight);
  2902. hRefere[h]->Draw("E1");
  2903. hSignal[h]->SetLineColor(2);
  2904. hSignal[h]->SetMarkerColor(2);
  2905. hSignal[h]->Draw("E1SAME");
  2906. //Legend and position...
  2907. float LegendXposition = 0.65;
  2908. float LegendYposition = 0.35;
  2909. TLegend * leg = new TLegend(LegendXposition,LegendYposition,LegendXposition + 0.25, LegendYposition + 0.18);
  2910. leg->AddEntry(hSignal[h],"Signal", "lpe");
  2911. leg->AddEntry(hRefere[h],"Referenz", "lpe");
  2912. leg->SetTextSize(0.04/lowerPlotHeight); // works fine
  2913. leg->Draw("same");
  2914. addLHCbtag(LegendXposition, LegendYposition + 0.27, "simulation", 1, 1/lowerPlotHeight);
  2915. if (Kst2Kspiplus)theCanvas->Print(Form("%s/ComparePlots/%i_%s%s_Comparison_Signal_vs_Ref_%s.eps", path_to_output_KshortPiplus.c_str(), year, TheDecay.c_str(), (SplitDDandLL ? (KshortDecayInVelo ? "_LL" : "_DD") : ""), leName[h].c_str()));
  2916. else theCanvas->Print(Form("%s/ComparePlots/%i_%s_Comparison_Signal_vs_Ref_%s.eps", path_to_output_KplusPizero.c_str(), year, TheDecay.c_str(), leName[h].c_str()));
  2917. theCanvas->Close();
  2918. delete theCanvas;
  2919. delete hSignal [h];
  2920. delete hRefere[h];
  2921. delete hRatio [h];
  2922. }
  2923. delete treeMC[0];
  2924. delete treeMC[1];
  2925. std::cout << "ALL GOOD" << std::endl;
  2926. return 1;
  2927. }
  2928. int compareAllNtracksAndBplusPT(int Run = 1){
  2929. std::vector<int>years = yearsVectorInt(true,false,false,Run);
  2930. for(int y = 0; y < years.size(); y++){
  2931. if(compareNTracksAndBplusPT(years.at(y), false) == 0){
  2932. coutERROR("Failed to compare nTracks and B_plus_PT for " + to_string(years.at(y)) + (Kst2Kspiplus && SplitDDandLL ? " (DD tracks)" : "") );
  2933. return 0;
  2934. }
  2935. if(Kst2Kspiplus && SplitDDandLL){
  2936. if(compareNTracksAndBplusPT(years.at(y), true) == 0){
  2937. coutERROR("Failed to compare nTracks and B_plus_PT for " + to_string(years.at(y)) + " (LL tracks)");
  2938. return 0;
  2939. }
  2940. }
  2941. }
  2942. return 1;
  2943. }
  2944. /////////////////////////////////////////////////////
  2945. ///
  2946. /// comparison Kplus and Kshort
  2947. ///
  2948. /////////////////////////////////////////////////////
  2949. int compareAllKplusKshort(bool sWeightKplus = false,bool sWeightKshort = true, bool bWeighted = true, bool b2DWeighted = false, int Run = 1, bool KshortDecayInVelo = true, std::string weightBranch = "nTracks"){
  2950. checkRun(Run);
  2951. bool save2file = true;
  2952. int nYear = (Run == 1 ? 2011 : 2015); //#TODO somehow 2011 throws out a segfault
  2953. while(nYear < (Run == 1 ? 2013 : 2018)){
  2954. //Global
  2955. compareVariablesKplusKshort(nYear, "nTracks", sWeightKplus, sWeightKshort, bWeighted, b2DWeighted, 0, 0, save2file, KshortDecayInVelo, weightBranch);
  2956. compareVariablesKplusKshort(nYear, "nLongTracks", sWeightKplus, sWeightKshort, bWeighted, b2DWeighted, 0, 0, save2file, KshortDecayInVelo, weightBranch);
  2957. compareVariablesKplusKshort(nYear, "nVeloTracks", sWeightKplus, sWeightKshort, bWeighted, b2DWeighted, 0, 0, save2file, KshortDecayInVelo, weightBranch);
  2958. compareVariablesKplusKshort(nYear, "nTTracks", sWeightKplus, sWeightKshort, bWeighted, b2DWeighted, 0, 0, save2file, KshortDecayInVelo, weightBranch);
  2959. compareVariablesKplusKshort(nYear, "nUpstreamTracks", sWeightKplus, sWeightKshort, bWeighted, b2DWeighted, 0, 0, save2file, KshortDecayInVelo, weightBranch);
  2960. compareVariablesKplusKshort(nYear, "nDownstreamTracks", sWeightKplus, sWeightKshort, bWeighted, b2DWeighted, 0, 0, save2file, KshortDecayInVelo, weightBranch);
  2961. ///B+
  2962. compareVariablesKplusKshort(nYear, (UseDTF?"B_plus_PT_DTF":"B_plus_PT"), sWeightKplus, sWeightKshort, bWeighted, b2DWeighted, 0, 0, save2file, KshortDecayInVelo, weightBranch);
  2963. compareVariablesKplusKshort(nYear, "B_plus_DIRA_OWNPV", sWeightKplus, sWeightKshort, bWeighted, b2DWeighted, 0, 1, save2file, KshortDecayInVelo, weightBranch);
  2964. compareVariablesKplusKshort(nYear, "B_plus_OWNPV_CHI2", sWeightKplus, sWeightKshort, bWeighted, b2DWeighted, 1, 0, save2file, KshortDecayInVelo, weightBranch);
  2965. compareVariablesKplusKshort(nYear, "B_plus_FD_OWNPV", sWeightKplus, sWeightKshort, bWeighted, b2DWeighted, 0, 0, save2file, KshortDecayInVelo, weightBranch);
  2966. compareVariablesKplusKshort(nYear, "B_plus_IP_OWNPV", sWeightKplus, sWeightKshort, bWeighted, b2DWeighted, 0, 0, save2file, KshortDecayInVelo, weightBranch);
  2967. compareVariablesKplusKshort(nYear, "B_plus_IPCHI2_OWNPV", sWeightKplus, sWeightKshort, bWeighted, b2DWeighted, 1, 0, save2file, KshortDecayInVelo, weightBranch);
  2968. compareVariablesKplusKshort(nYear, (UseDTF ? "B_plus_ETA_DTF":"B_plus_ETA"), sWeightKplus, sWeightKshort, bWeighted, b2DWeighted, 0, 0, save2file, KshortDecayInVelo, weightBranch);
  2969. /// K*
  2970. compareVariablesKplusKshort(nYear, (UseDTF ? "K_star_plus_PT_DTF":"K_star_plus_PT"), sWeightKplus, sWeightKshort, bWeighted, b2DWeighted, 0, 0, save2file, KshortDecayInVelo, weightBranch);
  2971. compareVariablesKplusKshort(nYear, (UseDTF ? "K_star_plus_ETA_DTF":"K_star_plus_ETA"), sWeightKplus, sWeightKshort, bWeighted, b2DWeighted, 0, 0, save2file, KshortDecayInVelo, weightBranch);
  2972. compareVariablesKplusKshort(nYear, "K_star_plus_IPCHI2_OWNPV", sWeightKplus, sWeightKshort, bWeighted, b2DWeighted, 0, 0, save2file, KshortDecayInVelo, weightBranch);
  2973. /// mu
  2974. compareVariablesKplusKshort(nYear, "mu_plus_IPCHI2_OWNPV", sWeightKplus, sWeightKshort, bWeighted, b2DWeighted, 1, 0, save2file, KshortDecayInVelo, weightBranch);
  2975. compareVariablesKplusKshort(nYear, "mu_minus_IPCHI2_OWNPV", sWeightKplus, sWeightKshort, bWeighted, b2DWeighted, 1, 0, save2file, KshortDecayInVelo, weightBranch);
  2976. nYear++;
  2977. }
  2978. return 1;
  2979. }
  2980. int compareAllKplusAllRunsAndWeights(bool bWeighted = true, bool b2DWeighted = false){
  2981. if (compareAllKplusKshort (true, true, bWeighted, b2DWeighted, 1, true) ==0) return 0;
  2982. if (compareAllKplusKshort (true, true, bWeighted, b2DWeighted, 1, false) ==0) return 0;
  2983. // if (compareAllKplusKshort (true, false, bWeighted, b2DWeighted, 1)==0) return 0;
  2984. // if (compareAllKplusKshort (false, true, bWeighted, b2DWeighted, 1)==0) return 0;
  2985. if (compareAllKplusKshort (false, false, bWeighted, b2DWeighted, 1, true) ==0) return 0;
  2986. if (compareAllKplusKshort (false, false, bWeighted, b2DWeighted, 1, false) ==0) return 0;
  2987. if (compareAllKplusKshort (true, true, bWeighted, b2DWeighted, 2)==0) return 0;
  2988. if (compareAllKplusKshort (true, true, bWeighted, b2DWeighted, 2)==0) return 0;
  2989. // if (compareAllKplusKshort (true, false, bWeighted, b2DWeighted, 2)==0) return 0;
  2990. // if (compareAllKplusKshort (false, true, bWeighted, b2DWeighted, 2)==0) return 0;
  2991. if (compareAllKplusKshort (false, false, bWeighted, b2DWeighted, 2, true) ==0) return 0;
  2992. if (compareAllKplusKshort (false, false, bWeighted, b2DWeighted, 2, false) ==0) return 0;
  2993. return 1;
  2994. }