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.

251 lines
12 KiB

  1. #include "../GlobalFunctions.hh"
  2. //////////////////////////////////////////////////////////////////////
  3. /// OptimizePreSelection()
  4. /// loops over all .root-files created by Preselection() defined in BDTSelection.cc.
  5. /// More kinematic, PID and some more cuts are applied and saved in a new file.
  6. ///
  7. int OptimizePreSelection(std::string year = "2012", std::string magnet = "down", bool MC = true, bool ReferenceChannel = false, bool PHSP = false) {
  8. if (!MC && PHSP){
  9. cout << "[INFO]\tIf you want to process PHSP MC, MC needs to be set true as well as PHSP. Abort." << endl;
  10. return 0;
  11. }
  12. TFile* input = 0;
  13. TFile* output = 0;
  14. TTree *tree;
  15. TTree *treeInit; //save also non-truthmatched tree
  16. // Kst2Kpluspi0Resolved case
  17. if(Kst2Kpluspi0Resolved){
  18. if(!MC){
  19. input = TFile::Open(Form("%s/data/%s%s/%s%s_pi0Resolved_loose.root",path_to_output_KplusPizero.c_str(), year.c_str(),magnet.c_str(),year.c_str(),magnet.c_str()));
  20. output = new TFile(Form("%s/data/%s%s/%s%s_pi0Resolved_new.root",path_to_output_KplusPizero.c_str(), year.c_str(),magnet.c_str(),year.c_str(),magnet.c_str()),"RECREATE");
  21. }
  22. else{
  23. if(ReferenceChannel){
  24. input = TFile::Open(Form("%s/data/MC/RefKplusPi0/%s%s/%s%s_pi0Resolved_loose.root",path_to_output_KplusPizero.c_str(), year.c_str(),magnet.c_str(),year.c_str(),magnet.c_str()));
  25. output = new TFile(Form("%s/data/MC/RefKplusPi0/%s%s/%s%s_pi0Resolved_new.root",path_to_output_KplusPizero.c_str(), year.c_str(),magnet.c_str(),year.c_str(),magnet.c_str()),"RECREATE");
  26. }
  27. else if(PHSP){
  28. input = TFile::Open(Form("%s/data/PHSP/KplusPi0/%s%s/%s%s_pi0Resolved_loose.root",path_to_output_KplusPizero.c_str(), year.c_str(),magnet.c_str(),year.c_str(),magnet.c_str()));
  29. output = new TFile(Form("%s/data/PHSP/KplusPi0/%s%s/%s%s_pi0Resolved_new.root",path_to_output_KplusPizero.c_str(), year.c_str(),magnet.c_str(),year.c_str(),magnet.c_str()),"RECREATE");
  30. }
  31. else{
  32. input = TFile::Open(Form("%s/data/MC/KplusPi0/%s%s/%s%s_pi0Resolved_loose.root",path_to_output_KplusPizero.c_str(), year.c_str(),magnet.c_str(),year.c_str(),magnet.c_str()));
  33. output = new TFile(Form("%s/data/MC/KplusPi0/%s%s/%s%s_pi0Resolved_new.root",path_to_output_KplusPizero.c_str(), year.c_str(),magnet.c_str(),year.c_str(),magnet.c_str()),"RECREATE");
  34. }
  35. }
  36. }
  37. // Kst2Kpluspi0Merged case
  38. if(Kst2Kpluspi0Merged){
  39. if(!MC){
  40. input = TFile::Open(Form("%s/data/%s%s/%s%s_pi0Merged.root",path_to_output_KplusPizero.c_str(), year.c_str(),magnet.c_str(),year.c_str(),magnet.c_str()));
  41. output = new TFile(Form("%s/data/%s%s/%s%s_pi0Merged_new.root",path_to_output_KplusPizero.c_str(), year.c_str(),magnet.c_str(),year.c_str(),magnet.c_str()),"RECREATE");
  42. }
  43. else{
  44. if(ReferenceChannel){
  45. input = TFile::Open(Form("%s/data/MC/RefKplusPi0/%s%s/%s%s_pi0Merged.root",path_to_output_KplusPizero.c_str(), year.c_str(),magnet.c_str(),year.c_str(),magnet.c_str()));
  46. output = new TFile(Form("%s/data/MC/RefKplusPi0/%s%s/%s%s_pi0Merged_new.root",path_to_output_KplusPizero.c_str(), year.c_str(),magnet.c_str(),year.c_str(),magnet.c_str()),"RECREATE");
  47. }
  48. else if (PHSP){
  49. input = TFile::Open(Form("%s/data/PHSP/KplusPi0/%s%s/%s%s_pi0Merged.root",path_to_output_KplusPizero.c_str(), year.c_str(),magnet.c_str(),year.c_str(),magnet.c_str()));
  50. output = new TFile(Form("%s/data/PHSP/KplusPi0/%s%s/%s%s_pi0Merged_new.root",path_to_output_KplusPizero.c_str(), year.c_str(),magnet.c_str(),year.c_str(),magnet.c_str()),"RECREATE");
  51. }
  52. else{
  53. input = TFile::Open(Form("%s/data/MC/KplusPi0/%s%s/%s%s_pi0Merged.root",path_to_output_KplusPizero.c_str(), year.c_str(),magnet.c_str(),year.c_str(),magnet.c_str()));
  54. output = new TFile(Form("%s/data/MC/KplusPi0/%s%s/%s%s_pi0Merged_new.root",path_to_output_KplusPizero.c_str(), year.c_str(),magnet.c_str(),year.c_str(),magnet.c_str()),"RECREATE");
  55. }
  56. }
  57. }
  58. // Kst2Kspiplus case
  59. if(Kst2Kspiplus){
  60. if (!MC){
  61. input = TFile::Open(Form("%s/data/%s%s/%s%s_piplus.root",path_to_output_KshortPiplus.c_str(), year.c_str(),magnet.c_str(),year.c_str(),magnet.c_str()));
  62. output = new TFile(Form("%s/data/%s%s/%s%s_piplus_new.root",path_to_output_KshortPiplus.c_str(), year.c_str(),magnet.c_str(),year.c_str(),magnet.c_str()),"RECREATE");
  63. }
  64. else{
  65. if(ReferenceChannel){
  66. input = TFile::Open(Form("%s/data/MC/RefKshortPiplus/%s%s/%s%s_piplus.root",path_to_output_KshortPiplus.c_str(), year.c_str(),magnet.c_str(),year.c_str(),magnet.c_str()));
  67. output = new TFile(Form("%s/data/MC/RefKshortPiplus/%s%s/%s%s_piplus_new.root",path_to_output_KshortPiplus.c_str(), year.c_str(),magnet.c_str(),year.c_str(),magnet.c_str()),"RECREATE");
  68. }
  69. else if(PHSP){
  70. input = TFile::Open(Form("%s/data/PHSP/KshortPiplus/%s%s/%s%s_piplus.root",path_to_output_KshortPiplus.c_str(), year.c_str(),magnet.c_str(),year.c_str(),magnet.c_str()));
  71. output = new TFile(Form("%s/data/PHSP/KshortPiplus/%s%s/%s%s_piplus_new.root",path_to_output_KshortPiplus.c_str(), year.c_str(),magnet.c_str(),year.c_str(),magnet.c_str()),"RECREATE");
  72. }
  73. else{
  74. input = TFile::Open(Form("%s/data/MC/KshortPiplus/%s%s/%s%s_piplus.root",path_to_output_KshortPiplus.c_str(), year.c_str(),magnet.c_str(),year.c_str(),magnet.c_str()));
  75. output = new TFile(Form("%s/data/MC/KshortPiplus/%s%s/%s%s_piplus_new.root",path_to_output_KshortPiplus.c_str(), year.c_str(),magnet.c_str(),year.c_str(),magnet.c_str()),"RECREATE");
  76. }
  77. }
  78. }
  79. string name = (MC ? "DecayTreeTruthMatched" : "DecayTree");
  80. input->cd();
  81. tree = (TTree*)input->Get(name.c_str());
  82. if (MC) treeInit = (TTree*)input->Get("DecayTree");
  83. tree->SetBranchStatus("*",1);
  84. cout << "[INFO]\tOld tuple contains " << tree->GetEntries() << " entries." << endl;
  85. vector<std::string> Cuts;
  86. string tmp_string = "";
  87. // Kst2Kpluspi0Resolved Cuts
  88. if(Kst2Kpluspi0Resolved){
  89. //don't copy old cone variables
  90. //tree->SetBranchStatus("*_1.00",0);
  91. //tree->SetBranchStatus("*_0.90",0);
  92. //tree->SetBranchStatus("*_0.80",0);
  93. //tree->SetBranchStatus("*_0.70",0);
  94. //tree->SetBranchStatus("*_0.60",0);
  95. //tree->SetBranchStatus("*_0.50",0);
  96. Cuts.push_back("B_plus_M_DTF > 5000");
  97. //Cuts.push_back("nTracks < 200");
  98. //Cuts.push_back("abs(J_psi_M - 3096) < 80");
  99. //Cuts.push_back("totCandidates < 5");
  100. //Cuts.push_back("abs(K_star_plus_M - 892) < 100");
  101. // Cuts.push_back("K_star_plus_PT_DTF > 1350");
  102. //// Cuts.push_back("mu_minus_ProbNNmu > 0.25");
  103. //Cuts.push_back("mu_plus_ProbNNmu > 0.25");
  104. // tmp_string = (UseDTF ? "K_star_plus_M_DTF > 792" : "K_star_plus_M > 792");
  105. // Cuts.push_back(tmp_string.c_str());
  106. // tmp_string = (UseDTF ? "K_star_plus_M_DTF < 1050" : "K_star_plus_M < 1050");
  107. // Cuts.push_back(tmp_string.c_str());
  108. // tmp_string = (UseDTF ? "K_star_plus_PT_DTF > 300 " : "K_star_plus_PT > 300");
  109. // Cuts.push_back(tmp_string.c_str());
  110. // tmp_string = "abs(" + string(UseDTF ? "K_star_plus_M_DTF" : "K_star_plus_M") + " - " + to_string(PDGMASS.K_STAR_PLUS) + ") < 150"; //remove non-resonant K+pi
  111. //cout << tmp_string << endl;
  112. //Cuts.push_back(tmp_string.c_str());
  113. }
  114. // Kst2Kpluspi0Merged cuts
  115. if(Kst2Kpluspi0Merged){
  116. //don't copy old cone variables
  117. tree->SetBranchStatus("*_1.00",0);
  118. tree->SetBranchStatus("*_0.90",0);
  119. tree->SetBranchStatus("*_0.80",0);
  120. tree->SetBranchStatus("*_0.70",0);
  121. tree->SetBranchStatus("*_0.60",0);
  122. tree->SetBranchStatus("*_0.50",0);
  123. //#TODO
  124. }
  125. // Kst2Kspiplus cuts
  126. if(Kst2Kspiplus){
  127. //#TODO
  128. }
  129. std::string AllCuts = "";
  130. if (Cuts.size()==0){
  131. cout << "[ERROR]\t No cuts selected, nothing to do." << endl;
  132. return 0;
  133. }
  134. AllCuts = AllCuts + *Cuts.begin();
  135. cout << "[INFO]\t\t Appling cuts:" << endl;
  136. cout << "\t\t\t" << AllCuts << endl;
  137. for (vector<std::string>::iterator t = Cuts.begin()+1;
  138. t != Cuts.end();
  139. ++t){
  140. AllCuts = AllCuts + " && " + *t ;
  141. cout << "\t\t\t" << *t << endl;
  142. }
  143. Cuts.clear();
  144. output->cd();
  145. TTree* NewTree = tree->CopyTree( AllCuts.c_str() );
  146. TTree* NewTreeInit;
  147. if (MC) NewTreeInit = treeInit->CopyTree( AllCuts.c_str() );
  148. output->Write();
  149. cout << "[INFO]\tNew tuple contains " << NewTree->GetEntries() << " entries." << endl;
  150. input->Close();
  151. output->Close();
  152. gROOT->Reset();
  153. cout << "[INFO]\t\t New tree created." << endl;
  154. return 1;
  155. }
  156. int OptimizePreSelectionAllData(Int_t Run = 1) {
  157. if(Run != 1 && Run != 2){
  158. std::cout << "[ERROR]\t\tInvalid Run number given: " << Run << ". Exit program!" << std::endl;
  159. return 0;
  160. }
  161. if ( OptimizePreSelection((Run == 1 ? "2011" : "2015"),"down", false, false, false) == 0) return 0;
  162. if ( OptimizePreSelection((Run == 1 ? "2011" : "2015"),"up" , false, false, false) == 0) return 0;
  163. if ( OptimizePreSelection((Run == 1 ? "2012" : "2016"),"down",false, false, false) == 0) return 0;
  164. if ( OptimizePreSelection((Run == 1 ? "2012" : "2016"),"up" ,false, false, false) == 0) return 0;
  165. return 1;
  166. }
  167. int OptimizePreSelectionAllMC(Int_t Run = 1) {
  168. if(Run != 1 && Run != 2){
  169. std::cout << "[ERROR]\t\tInvalid Run number given: " << Run << ". Exit program!" << std::endl;
  170. return 0;
  171. }
  172. if ( OptimizePreSelection((Run == 1 ? "2011" : "2015"),"down",true, false, false) == 0) return 0;
  173. if ( OptimizePreSelection((Run == 1 ? "2011" : "2015"),"up" ,true, false, false) == 0) return 0;
  174. if ( OptimizePreSelection((Run == 1 ? "2012" : "2016"),"down",true, false, false) == 0) return 0;
  175. if ( OptimizePreSelection((Run == 1 ? "2012" : "2016"),"up" ,true, false, false) == 0) return 0;
  176. return 1;
  177. }
  178. int OptimizePreSelectionAllRefChannel(Int_t Run = 1) {
  179. if(Run != 1){
  180. std::cout << "[ERROR]\t\tInvalid Run number given: " << Run << "." << std::endl;
  181. std::cout << "[ERROR]\t\tInvalid RefChannel available only for Run 1 at the moment! Exit program!" << std::endl;
  182. return 0;
  183. }
  184. if ( OptimizePreSelection((Run == 1 ? "2011" : "2015"),"down",true, true, false) == 0) return 0;
  185. if ( OptimizePreSelection((Run == 1 ? "2011" : "2015"),"up" ,true, true, false) == 0) return 0;
  186. if ( OptimizePreSelection((Run == 1 ? "2012" : "2016"),"down",true, true, false) == 0) return 0;
  187. if ( OptimizePreSelection((Run == 1 ? "2012" : "2016"),"up" ,true, true, false) == 0) return 0;
  188. return 1;
  189. }
  190. int OptimizePreSelectionAllPHSP(Int_t Run = 1) {
  191. if(Run != 1 && Run != 2){
  192. std::cout << "[ERROR]\t\tInvalid Run number given: " << Run << ". Exit program!" << std::endl;
  193. return 0;
  194. }
  195. if ( OptimizePreSelection((Run == 1 ? "2011" : "2015"),"down",true, false, true) == 0) return 0;
  196. if ( OptimizePreSelection((Run == 1 ? "2011" : "2015"),"up" ,true, false, true) == 0) return 0;
  197. if ( OptimizePreSelection((Run == 1 ? "2012" : "2016"),"down",true, false, true) == 0) return 0;
  198. if ( OptimizePreSelection((Run == 1 ? "2012" : "2016"),"up" ,true, false, true) == 0) return 0;
  199. return 1;
  200. }
  201. int OptimizePreSelectionAll( Int_t Run = 1) {
  202. if (OptimizePreSelectionAllData(Run)==0) return 0;
  203. if (OptimizePreSelectionAllMC(Run)==0) return 0;
  204. if (OptimizePreSelectionAllPHSP(Run)==0) return 0;
  205. if (OptimizePreSelectionAllRefChannel(Run)==0) return 0;
  206. return 1;
  207. }