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.

653 lines
29 KiB

  1. #include "../GlobalFunctions.hh"
  2. //////////////////////////////////////////////////////////////////////
  3. /// QuickChecker()
  4. ///
  5. /// Epicly flexible tool to quickly create basic plots for checking various features.
  6. ///
  7. /// All definitions happen in the AllBranches constructor, where used branches are defined.
  8. /// Cuts are also defined in the constructor, the strings are transferred to CopyTree.
  9. /// EpicOptimizer() doesn't need to be touched at all.
  10. ///
  11. ///
  12. /// Options to create either standalone years plots (Run==0),
  13. /// plots per Run (Run==1 || Run ==2) or both runs combined (Run==12)
  14. ///
  15. /// Possibility to run on stripped/preselected data/MC/PHSP/Ref.
  16. /// In the case of MC also possibility to run only on TruthMatched data.
  17. ///
  18. /// TODO: should add an option tfor sweighted and BDT-cutted data
  19. ///
  20. /// Standard output in data/MC/PHSP/Ref folder, year/run and preselection option in the name.
  21. ///
  22. /// Disclaimer: Probably leaky and not super-safe to you, so proceed with caution.
  23. ///
  24. ///
  25. /*******************************/
  26. class Int_branch{
  27. public:
  28. int BranchVar; //where to save the branch
  29. const char* BranchName; //Name of the branch
  30. Int_branch(); //default constructor
  31. Int_branch(int var, const char* name); //default constructor
  32. ~Int_branch(); //destuctor
  33. };
  34. Int_branch::Int_branch(int var, const char* name){ //here add what branches you wanna load
  35. BranchVar = var;
  36. BranchName = name;
  37. }
  38. /*******************************/
  39. class Float_branch{
  40. public:
  41. float BranchVar; //where to save the branch
  42. const char* BranchName; //Name of the branch
  43. Float_branch(); //default constructor
  44. ~Float_branch(); //destuctor
  45. Float_branch(float var, const char* name); //constructor
  46. };
  47. Float_branch::Float_branch(float var, const char* name){ //here add what branches you wanna load
  48. BranchVar = var;
  49. BranchName = name;
  50. }
  51. /*******************************/
  52. class Float_arr_branch{
  53. public:
  54. float *BranchVar; //where to save the branch
  55. const char* BranchName; //Name of the branch
  56. Float_arr_branch(); //default constructor
  57. Float_arr_branch(float *var, const char* name); //constructor
  58. ~Float_arr_branch(); //destuctor
  59. };
  60. Float_arr_branch::Float_arr_branch(float *var, const char* name){ //here add what branches you wanna load
  61. BranchVar = var;
  62. BranchName = name;
  63. }
  64. /*******************************/
  65. class Double_branch{
  66. public:
  67. double BranchVar; //where to save the branch
  68. const char* BranchName; //Name of the branch
  69. Double_branch(); //default constructor
  70. Double_branch(double var, const char* name); //constructor
  71. ~Double_branch(); //destuctor
  72. };
  73. Double_branch::Double_branch(double var, const char* name){ //here add what branches you wanna load
  74. BranchVar = var;
  75. BranchName = name;
  76. }
  77. /*******************************/
  78. class Double_arr_branch{
  79. public:
  80. double *BranchVar; //where to save the branch
  81. const char* BranchName; //Name of the branch
  82. Double_arr_branch(); //default constructor
  83. Double_arr_branch(double *var, const char* name); //constructor
  84. ~Double_arr_branch(); //destuctor
  85. };
  86. Double_arr_branch::Double_arr_branch(double *var, const char* name){ //here add what branches you wanna load
  87. BranchVar = var;
  88. BranchName = name;
  89. }
  90. /*******************************/
  91. class AllBranches{
  92. public:
  93. vector <Int_branch*> IntBranches;
  94. vector <Float_branch*> FloatBranches;
  95. vector <Float_arr_branch*> FloatArrBranches;
  96. vector <Double_branch*> DoubleBranches;
  97. vector <Double_arr_branch*> DoubleArrBranches;
  98. vector<std::string> Cuts;
  99. AllBranches(); //default constructor
  100. ~AllBranches(); //destuctor
  101. };
  102. AllBranches::AllBranches(){ //here add what branches you wanna load
  103. // int I_nTracks = 0;
  104. // IntBranches.push_back(new Int_branch(I_nTracks, "nTracks"));
  105. /*
  106. double D_K_star_plus_PT = 0.0;
  107. DoubleBranches.push_back(new Double_branch(D_K_star_plus_PT, "K_star_plus_PT"));
  108. Cuts.push_back("K_star_plus_PT > 1300");
  109. //Cuts.push_back("K_star_plus_PT < 300");
  110. */
  111. double D_B_plus_ThetaL = 0.0;
  112. DoubleBranches.push_back(new Double_branch(D_B_plus_ThetaL, "B_plus_ThetaL"));
  113. double D_B_plus_ThetaK = 0.0;
  114. DoubleBranches.push_back(new Double_branch(D_B_plus_ThetaK, "B_plus_ThetaK"));
  115. double D_B_plus_Phi = 0.0;
  116. DoubleBranches.push_back(new Double_branch(D_B_plus_Phi, "B_plus_Phi"));
  117. double D_B_plus_TRUEThetaL = 0.0;
  118. DoubleBranches.push_back(new Double_branch(D_B_plus_TRUEThetaL, "B_plus_TRUEThetaL"));
  119. double D_B_plus_TRUEThetaK = 0.0;
  120. DoubleBranches.push_back(new Double_branch(D_B_plus_TRUEThetaK, "B_plus_TRUEThetaK"));
  121. double D_B_plus_TRUEPhi = 0.0;
  122. DoubleBranches.push_back(new Double_branch(D_B_plus_TRUEPhi, "B_plus_TRUEPhi"));
  123. double D_B_plus_M = 0.0;
  124. DoubleBranches.push_back(new Double_branch(D_B_plus_M, "B_plus_M"));
  125. Cuts.push_back("B_plus_M < 600000000");
  126. /*
  127. double D_B_plus_M = 0.0;
  128. DoubleBranches.push_back(new Double_branch(D_B_plus_M, "B_plus_M"));
  129. Cuts.push_back("B_plus_M > 5000");
  130. Cuts.push_back("B_plus_M < 6000");
  131. float K_star_plus_M = 0;
  132. DoubleBranches.push_back(new Double_branch(K_star_plus_M,"K_star_plus_M"));
  133. Cuts.push_back("K_star_plus_M > 792");
  134. Cuts.push_back("K_star_plus_M <1050");
  135. double D_K_plus_PT = 0.0;
  136. DoubleBranches.push_back(new Double_branch(D_K_plus_PT, "K_plus_PT"));
  137. Cuts.push_back("K_plus_PT > 300");
  138. double D_B_plus_PT = 0.0;
  139. DoubleBranches.push_back(new Double_branch(D_B_plus_PT, "B_plus_PT"));
  140. Cuts.push_back("B_plus_PT > 2000");
  141. double K_star_plus_FDCHI2_OWNPV = 0.0;
  142. DoubleBranches.push_back(new Double_branch(K_star_plus_FDCHI2_OWNPV, "K_star_plus_FDCHI2_OWNPV"));
  143. Cuts.push_back("K_star_plus_FDCHI2_OWNPV > -100000");
  144. double B_plus_FDCHI2_OWNPV = 0.0;
  145. DoubleBranches.push_back(new Double_branch(B_plus_FDCHI2_OWNPV, "B_plus_FDCHI2_OWNPV"));
  146. Cuts.push_back("B_plus_FDCHI2_OWNPV > 121");
  147. double K_star_plus_FDCHI2_OWNPV = 0.0;
  148. DoubleBranches.push_back(new Double_branch(K_star_plus_FDCHI2_OWNPV, "K_star_plus_FDCHI2_OWNPV"));
  149. Cuts.push_back("K_star_plus_FDCHI2_OWNPV > -100000");
  150. int B_plus_Hlt2Topo3BodyBBDTDecision_TOS = 0.0;
  151. int B_plus_Hlt2TopoMu2BodyBBDTDecision_TOS = 0.0;
  152. int B_plus_Hlt2TopoMu3BodyBBDTDecision_TOS = 0.0;
  153. int B_plus_Hlt2TopoMuMu2BodyBBDTDecision_TOS = 0.0;
  154. int B_plus_Hlt2TopoMuMu3BodyBBDTDecision_TOS = 0.0;
  155. double D_pi_zero_resolved_TRUEP_X = 0.0;
  156. DoubleBranches.push_back(new Double_branch(D_pi_zero_resolved_TRUEP_X, "pi_zero_resolved_TRUEP_X"));
  157. Cuts.push_back("pi_zero_resolved_TRUEP_X > -100000");
  158. double D_pi_zero_resolved_TRUEP_Y = 0.0;
  159. DoubleBranches.push_back(new Double_branch(D_pi_zero_resolved_TRUEP_Y, "pi_zero_resolved_TRUEP_Y"));
  160. Cuts.push_back("pi_zero_resolved_TRUEP_Y > -100000");
  161. double D_pi_zero_resolved_TRUEP_Z = 0.0;
  162. DoubleBranches.push_back(new Double_branch(D_pi_zero_resolved_TRUEP_Z, "pi_zero_resolved_TRUEP_Z"));
  163. Cuts.push_back("pi_zero_resolved_TRUEP_Z > -100000");
  164. double D_pi_zero_resolved_ETA = 0.0;
  165. DoubleBranches.push_back(new Double_branch(D_pi_zero_resolved_ETA, "pi_zero_resolved_ETA"));
  166. Cuts.push_back("pi_zero_resolved_ETA > -100000");
  167. double D_pi_zero_resolved_PX = 0.0;
  168. DoubleBranches.push_back(new Double_branch(D_pi_zero_resolved_PX, "pi_zero_resolved_PX"));
  169. Cuts.push_back("pi_zero_resolved_PX > -100000");
  170. double D_pi_zero_resolved_PY = 0.0;
  171. DoubleBranches.push_back(new Double_branch(D_pi_zero_resolved_PY, "pi_zero_resolved_PY"));
  172. Cuts.push_back("pi_zero_resolved_PY > -100000");
  173. double D_pi_zero_resolved_PZ = 0.0;
  174. DoubleBranches.push_back(new Double_branch(D_pi_zero_resolved_PZ, "pi_zero_resolved_PZ"));
  175. Cuts.push_back("pi_zero_resolved_PZ> -100000");
  176. double D_K_star_plus_M_DTF = 0.0;
  177. DoubleBranches.push_back(new Double_branch(D_K_star_plus_M_DTF, "K_star_plus_M_DTF"));
  178. Cuts.push_back("K_star_plus_M_DTF > 792");
  179. Cuts.push_back("K_star_plus_M_DTF <1050");
  180. */
  181. /*
  182. float K_star_plus_M = 0;
  183. DoubleBranches.push_back(new Double_branch(K_star_plus_M,"K_star_plus_M"));
  184. Cuts.push_back("K_star_plus_M > 792");
  185. Cuts.push_back("K_star_plus_M <1050");
  186. */
  187. /*
  188. float F_B_plus_DTF_Kst_892_plus_M[20];
  189. FloatArrBranches.push_back(new Float_arr_branch(F_B_plus_DTF_Kst_892_plus_M,"B_plus_DTF_Kst_892_plus_M"));
  190. Cuts.push_back("B_plus_DTF_Kst_892_plus_M[0] > 792");
  191. Cuts.push_back("B_plus_DTF_Kst_892_plus_M[0] <1050");
  192. */
  193. //truthmatching
  194. //assign variables to TRUEID
  195. /* int B_plus_TRUEID= 0;;
  196. IntBranches.push_back(new Int_branch(B_plus_TRUEID, "B_plus_TRUEID"));
  197. Cuts.push_back("abs(B_plus_TRUEID) == " + to_string(TRUEID.B_PLUS));
  198. int K_star_plus_TRUEID= 0;
  199. IntBranches.push_back(new Int_branch(K_star_plus_TRUEID, "K_star_plus_TRUEID"));
  200. Cuts.push_back("abs(K_star_plus_TRUEID) == " + to_string(TRUEID.K_STAR_PLUS));
  201. int K_plus_TRUEID= 0;
  202. IntBranches.push_back(new Int_branch(K_plus_TRUEID, "K_plus_TRUEID"));
  203. Cuts.push_back("abs(K_plus_TRUEID) == " + to_string(TRUEID.K_PLUS));
  204. int pi_zero_TRUEID= 0;
  205. IntBranches.push_back(new Int_branch(pi_zero_TRUEID, "pi_zero_resolved_TRUEID"));
  206. Cuts.push_back("abs(pi_zero_resolved_TRUEID) == " + to_string(TRUEID.PI_ZERO));
  207. int gamma1_TRUEID= 0;
  208. IntBranches.push_back(new Int_branch(gamma1_TRUEID, "gamma1_TRUEID"));
  209. Cuts.push_back("abs(gamma1_TRUEID) == " + to_string(TRUEID.GAMMA));
  210. int gamma2_TRUEID= 0;
  211. IntBranches.push_back(new Int_branch(gamma2_TRUEID, "gamma2_TRUEID"));
  212. Cuts.push_back("abs(gamma2_TRUEID) == " + to_string(TRUEID.GAMMA));
  213. //assign variables to TRUE_MOTHER_ID
  214. int K_star_plus_MOTHER_ID= 0;
  215. IntBranches.push_back(new Int_branch(K_star_plus_MOTHER_ID, "K_star_plus_MC_MOTHER_ID"));
  216. Cuts.push_back("abs(K_star_plus_MC_MOTHER_ID) == " + to_string(TRUEID.B_PLUS));
  217. int K_plus_MOTHER_ID= 0;
  218. IntBranches.push_back(new Int_branch(K_plus_MOTHER_ID, "K_plus_MC_MOTHER_ID"));
  219. Cuts.push_back("abs(K_plus_MC_MOTHER_ID) == " + to_string(TRUEID.K_STAR_PLUS));
  220. int pi_zero_MOTHER_ID= 0;
  221. IntBranches.push_back(new Int_branch(pi_zero_MOTHER_ID, "pi_zero_resolved_MC_MOTHER_ID"));
  222. Cuts.push_back("abs(pi_zero_resolved_MC_MOTHER_ID) == " + to_string(TRUEID.K_STAR_PLUS));
  223. int gamma1_MOTHER_ID= 0;
  224. IntBranches.push_back(new Int_branch(gamma1_MOTHER_ID, "gamma1_MC_MOTHER_ID"));
  225. Cuts.push_back("abs(gamma1_MC_MOTHER_ID) == " + to_string(TRUEID.PI_ZERO));
  226. int gamma2_MOTHER_ID= 0;
  227. IntBranches.push_back(new Int_branch(gamma2_MOTHER_ID, "gamma2_MC_MOTHER_ID"));
  228. Cuts.push_back("abs(gamma2_MC_MOTHER_ID) == " + to_string(TRUEID.PI_ZERO));
  229. //assign variables to TRUE_GD_MOTHER_ID
  230. int K_plus_GD_MOTHER_ID= 0;
  231. IntBranches.push_back(new Int_branch(K_plus_GD_MOTHER_ID, "K_plus_MC_GD_MOTHER_ID"));
  232. Cuts.push_back("abs(K_plus_MC_GD_MOTHER_ID) == " + to_string(TRUEID.B_PLUS));
  233. int pi_zero_GD_MOTHER_ID= 0;
  234. IntBranches.push_back(new Int_branch(pi_zero_GD_MOTHER_ID, "pi_zero_resolved_MC_GD_MOTHER_ID"));
  235. Cuts.push_back("abs(pi_zero_resolved_MC_GD_MOTHER_ID) == " + to_string(TRUEID.B_PLUS));
  236. int gamma1_GD_MOTHER_ID= 0;
  237. IntBranches.push_back(new Int_branch(gamma1_GD_MOTHER_ID, "gamma1_MC_GD_MOTHER_ID"));
  238. Cuts.push_back("abs(gamma1_MC_GD_MOTHER_ID) == " + to_string(TRUEID.K_STAR_PLUS));
  239. int gamma2_GD_MOTHER_ID= 0;
  240. IntBranches.push_back(new Int_branch(gamma2_GD_MOTHER_ID, "gamma2_MC_GD_MOTHER_ID"));
  241. Cuts.push_back("abs(gamma2_MC_GD_MOTHER_ID) == " + to_string(TRUEID.K_STAR_PLUS));
  242. //assign variables to TRUE_GD_MOTHER_ID
  243. int gamma1_GD_GD_MOTHER_ID= 0;
  244. IntBranches.push_back(new Int_branch(gamma1_GD_GD_MOTHER_ID, "gamma1_MC_GD_GD_MOTHER_ID"));
  245. Cuts.push_back("abs(gamma1_MC_GD_GD_MOTHER_ID) == " + to_string(TRUEID.B_PLUS));
  246. int gamma2_GD_GD_MOTHER_ID= 0;
  247. IntBranches.push_back(new Int_branch(gamma2_GD_GD_MOTHER_ID, "gamma2_MC_GD_GD_MOTHER_ID"));
  248. Cuts.push_back("abs(gamma2_MC_GD_GD_MOTHER_ID) == " + to_string(TRUEID.B_PLUS));
  249. */
  250. }
  251. int EpicOptimizer(std::string year = "2012", std::string magnet = "down", int Run = 0, bool MC = false,
  252. bool ReferenceChannel = false, bool PHSP = false, bool preselected = true, bool truthMatched = false) {
  253. int MaxEntries = 1000000;
  254. //specify year(s)
  255. std::vector<std::string> years;
  256. if (!(Run == 0 || Run == 1 || Run == 2 || Run == 12)){
  257. cout << "[INFO]\t\tWrong run number, allowed options are 0 ,1, 2 or 12!" << endl;
  258. cout << "[INFO]\t\tUsing Run = 0, meaning year " << year << endl;
  259. Run = 0;
  260. }
  261. switch (Run){
  262. case (0): {
  263. years.push_back(year);
  264. break;
  265. }
  266. case (1): {
  267. years.push_back("2011");
  268. years.push_back("2012");
  269. break;
  270. }
  271. case (2): {
  272. years.push_back("2015");
  273. years.push_back("2016");
  274. break;
  275. }
  276. case (12): {
  277. years.push_back("2011");
  278. years.push_back("2012");
  279. years.push_back("2015");
  280. years.push_back("2016");
  281. break;
  282. }
  283. }
  284. if(ReferenceChannel && PHSP){
  285. std::cout << "[WARNING]\tCannot set boolean of reference channel and phase-space MC at the same time! Process Reference Channel!" << std::endl;
  286. PHSP = false;
  287. }
  288. TFile* output = 0;
  289. TChain* tree = 0;
  290. if (!preselected){
  291. if(Kst2Kpluspi0Resolved) tree=new TChain("b2KstKpi0mumuResolvedTuple/DecayTree");
  292. if(Kst2Kpluspi0Merged) tree=new TChain("b2KstKpi0mumuMergeddTuple/DecayTree");
  293. if(Kst2Kspiplus) tree=new TChain("b2KstKs0pimumu_Tuple/DecayTree");
  294. }
  295. else{
  296. if ((MC||ReferenceChannel||PHSP) && truthMatched) tree=new TChain("DecayTreeTruthMatched");
  297. else tree=new TChain("DecayTree");
  298. }
  299. for (std::vector<string>::iterator y = years.begin(); y != years.end(); ++y){ //load data for given years
  300. if (!preselected){ //load stripped data
  301. //Kst2Kpluspi0Resolved case
  302. if(Kst2Kpluspi0Resolved){
  303. if(!MC){
  304. if(smallSample) tree->Add(Form("%s/data/%s%s/*B2Kstmumu*13.root",path_to_data.c_str(), y->c_str(),magnet.c_str()));
  305. else{
  306. tree->Add(Form("%s/data/%s%s/*.root",path_to_data.c_str(), y->c_str(),magnet.c_str()));
  307. std::cout << "Adding " << Form("%s/data/%s%s/*B2Kstmumu*.root",path_to_data.c_str(), y->c_str(),magnet.c_str()) << endl;
  308. }
  309. }
  310. else{
  311. if(ReferenceChannel){
  312. if(smallSample) tree->Add(Form("%s/data/MC/RefKplusPi0/%s%s/*B2KstJpsi*1.root",path_to_data.c_str(), y->c_str(),magnet.c_str()));
  313. else tree->Add(Form("%s/data/MC/RefKplusPi0/%s%s/*B2KstJpsi*.root",path_to_data.c_str(), y->c_str(),magnet.c_str()));
  314. }
  315. else if(PHSP){
  316. if(smallSample) tree->Add(Form("%s/data/PHSP/KplusPi0/%s%s/*B2Kstmumu*1.root",path_to_data.c_str(), y->c_str(),magnet.c_str()));
  317. else tree->Add(Form("%s/data/PHSP/KplusPi0/%s%s/*B2Kstmumu*.root",path_to_data.c_str(), y->c_str(),magnet.c_str()));
  318. }
  319. else{
  320. if(smallSample) tree->Add(Form("%s/data/MC/KplusPi0/%s%s/*B2Kstmumu*1.root",path_to_data.c_str(), y->c_str(),magnet.c_str()));
  321. else tree->Add(Form("%s/data/MC/KplusPi0/%s%s/*B2Kstmumu*.root",path_to_data.c_str(), y->c_str(),magnet.c_str()));
  322. }
  323. }
  324. }
  325. //Kst2Kpluspi0Merged case
  326. if(Kst2Kpluspi0Merged){
  327. if(!MC){
  328. if(smallSample) tree->Add(Form("%s/data/%s%s/*B2Kstmumu*13.root",path_to_data.c_str(), y->c_str(),magnet.c_str()));
  329. else tree->Add(Form("%s/data/%s%s/*B2Kstmumu*.root",path_to_data.c_str(), y->c_str(),magnet.c_str()));
  330. }
  331. else{
  332. if(smallSample) tree->Add(Form("%s/data/MC/KplusPi0/%s%s/*B2Kstmumu*1.root",path_to_data.c_str(), y->c_str(),magnet.c_str()));
  333. else tree->Add(Form("%s/data/MC/KplusPi0/%s%s/*B2Kstmumu*.root",path_to_data.c_str(), y->c_str(),magnet.c_str()));
  334. }
  335. }
  336. //Kst2Kspiplus case
  337. if(Kst2Kspiplus){
  338. tree=new TChain("b2KstKs0pimumu_Tuple/DecayTree");
  339. if(!MC){
  340. if(smallSample) tree->Add(Form("%s/data/%s%s/*B2Kstmumu*23.root",path_to_data.c_str(), y->c_str(),magnet.c_str()));
  341. else tree->Add(Form("%s/data/%s%s/*B2Kstmumu*.root",path_to_data.c_str(), y->c_str(),magnet.c_str()));
  342. }
  343. else{
  344. if(ReferenceChannel){
  345. if(smallSample) tree->Add(Form("%s/data/MC/RefKshortPiplus/%s%s/*B2KstJpsi*13.root",path_to_data.c_str(), y->c_str(),magnet.c_str()));
  346. else tree->Add(Form("%s/data/MC/RefKshortPiplus/%s%s/*B2KstJpsi*.root",path_to_data.c_str(), y->c_str(),magnet.c_str()));
  347. }
  348. else if(PHSP){
  349. if(smallSample) tree->Add(Form("%s/data/PHSP/KshortPiplus/%s%s/*B2Kstmumu*1.root",path_to_data.c_str(), y->c_str(),magnet.c_str()));
  350. else tree->Add(Form("%s/data/PHSP/KshortPiplus/%s%s/*B2Kstmumu*.root",path_to_data.c_str(), y->c_str(),magnet.c_str()));
  351. }
  352. else{
  353. if(smallSample) tree->Add(Form("%s/data/MC/KshortPiplus/%s%s/*B2Kstmumu*1.root",path_to_data.c_str(), y->c_str(),magnet.c_str()));
  354. else tree->Add(Form("%s/data/MC/KshortPiplus/%s%s/*B2Kstmumu*.root",path_to_data.c_str(), y->c_str(),magnet.c_str()));
  355. }
  356. }
  357. }
  358. }
  359. else{ //load preselected data
  360. // Kst2Kpluspi0Resolved case
  361. if(Kst2Kpluspi0Resolved){
  362. if(!MC){
  363. tree->Add(Form("%s/data/%s%s/%s%s_pi0Resolved.root",path_to_output_KplusPizero.c_str(), y->c_str(),magnet.c_str(), y->c_str(),magnet.c_str()));
  364. cout << Form("%s/data/%s%s/%s%s_pi0Resolved.root",path_to_output_KplusPizero.c_str(), y->c_str(),magnet.c_str(), y->c_str(),magnet.c_str()) << endl;
  365. }
  366. else{
  367. if(ReferenceChannel){
  368. tree->Add(Form("%s/data/MC/RefKplusPi0/%s%s/%s%s_pi0Resolved.root",path_to_output_KplusPizero.c_str(), y->c_str(),magnet.c_str(), y->c_str(),magnet.c_str()));
  369. }
  370. else if (PHSP){
  371. tree->Add(Form("%s/data/PHSP/KplusPi0/%s%s/%s%s_pi0Resolved.root",path_to_output_KplusPizero.c_str(), y->c_str(),magnet.c_str(), y->c_str(),magnet.c_str()));
  372. }
  373. else{
  374. tree->Add(Form("%s/data/MC/KplusPi0/%s%s/%s%s_pi0Resolved.root",path_to_output_KplusPizero.c_str(), y->c_str(),magnet.c_str(), y->c_str(),magnet.c_str()));
  375. cout << Form("%s/data/MC/KplusPi0/%s%s/%s%s_pi0Resolved.root",path_to_output_KplusPizero.c_str(), y->c_str(),magnet.c_str(), y->c_str(),magnet.c_str()) << endl;
  376. }
  377. }
  378. }
  379. // Kst2Kpluspi0Merged case
  380. if(Kst2Kpluspi0Merged){
  381. if(!MC){
  382. tree->Add(Form("%s/data/%s%s/%s%s_pi0Merged.root",path_to_output_KplusPizero.c_str(), y->c_str(),magnet.c_str(), y->c_str(),magnet.c_str()));
  383. }
  384. else{
  385. if(ReferenceChannel){
  386. tree->Add(Form("%s/data/MC/RefKplusPi0/%s%s/%s%s_pi0Merged.root",path_to_output_KplusPizero.c_str(), y->c_str(),magnet.c_str(), y->c_str(),magnet.c_str()));
  387. }
  388. else if (PHSP){
  389. tree->Add(Form("%s/data/PHSP/KplusPi0/%s%s/%s%s_pi0Merged.root",path_to_output_KplusPizero.c_str(), y->c_str(),magnet.c_str(), y->c_str(),magnet.c_str()));
  390. }
  391. else{
  392. tree->Add(Form("%s/data/MC/KplusPi0/%s%s/%s%s_pi0Merged.root",path_to_output_KplusPizero.c_str(), y->c_str(),magnet.c_str(), y->c_str(),magnet.c_str()));
  393. }
  394. }
  395. }
  396. // Kst2Kspiplus case
  397. if(Kst2Kspiplus){
  398. if (!MC){
  399. tree->Add(Form("%s/data/%s%s/%s%s_piplus.root",path_to_output_KshortPiplus.c_str(), y->c_str(),magnet.c_str(), y->c_str(),magnet.c_str()));
  400. }
  401. else{
  402. if(ReferenceChannel){
  403. tree->Add(Form("%s/data/MC/RefKshortPiplus/%s%s/%s%s_piplus.root",path_to_output_KshortPiplus.c_str(), y->c_str(),magnet.c_str(), y->c_str(),magnet.c_str()));
  404. }
  405. else if (PHSP){
  406. tree->Add(Form("%s/data/PHSP/KshortPiplus/%s%s/%s%s_piplus.root",path_to_output_KplusPizero.c_str(), y->c_str(),magnet.c_str(), y->c_str(),magnet.c_str()));
  407. }
  408. else{
  409. tree->Add(Form("%s/data/MC/KshortPiplus/%s%s/%s%s_piplus.root",path_to_output_KshortPiplus.c_str(), y->c_str(),magnet.c_str(), y->c_str(),magnet.c_str()));
  410. }
  411. }
  412. }
  413. } //end of preselected data if
  414. } //end of the year loop
  415. // set branches here
  416. tree->SetBranchStatus("*",0);
  417. cout << "[INFO]\tOld tree entries: " << tree->GetEntries() << endl;
  418. AllBranches * AllB = NULL;
  419. AllB = new AllBranches();
  420. for (std::vector<Int_branch*>::iterator IB = AllB->IntBranches.begin(); IB != AllB->IntBranches.end(); ++IB){
  421. tree->SetBranchStatus((*IB)->BranchName,1);
  422. tree->SetBranchAddress((*IB)->BranchName,&(*IB)->BranchVar);
  423. }
  424. for (std::vector<Float_branch*>::iterator FB = AllB->FloatBranches.begin(); FB != AllB->FloatBranches.end(); ++FB){
  425. tree->SetBranchStatus((*FB)->BranchName,1);
  426. tree->SetBranchAddress((*FB)->BranchName,&(*FB)->BranchVar);
  427. }
  428. for (std::vector<Float_arr_branch*>::iterator FaB = AllB->FloatArrBranches.begin(); FaB != AllB->FloatArrBranches.end(); ++FaB){
  429. tree->SetBranchStatus((*FaB)->BranchName,1);
  430. tree->SetBranchAddress((*FaB)->BranchName,&(*FaB)->BranchVar);
  431. }
  432. for (std::vector<Double_branch*>::iterator DB = AllB->DoubleBranches.begin(); DB != AllB->DoubleBranches.end(); ++DB){
  433. tree->SetBranchStatus((*DB)->BranchName,1);
  434. tree->SetBranchAddress((*DB)->BranchName,&(*DB)->BranchVar);
  435. }
  436. for (std::vector<Double_arr_branch*>::iterator DaB = AllB->DoubleArrBranches.begin(); DaB != AllB->DoubleArrBranches.end(); ++DaB){
  437. tree->SetBranchStatus((*DaB)->BranchName,1);
  438. tree->SetBranchAddress((*DaB)->BranchName,&(*DaB)->BranchVar);
  439. }
  440. //parse cuts
  441. std::string AllCuts = "";
  442. if (AllB->Cuts.size()==0){
  443. cout << "[ERROR]\t No cuts selected, just copying the tree." << endl;
  444. return 0;
  445. }
  446. AllCuts = AllCuts + *AllB->Cuts.begin();
  447. cout << "[INFO]\t\t MaxEntries: " << MaxEntries << endl;
  448. cout << "[INFO]\t\t Appling cuts:" << endl;
  449. cout << "\t\t\t" << AllCuts << endl;
  450. for (vector<std::string>::iterator t = AllB->Cuts.begin()+1; t != AllB->Cuts.end(); ++t){
  451. AllCuts = AllCuts + " && " + *t ;
  452. cout << "\t\t\t" << *t << endl;
  453. }
  454. AllB->Cuts.clear();
  455. TTree* NewTree = tree->CopyTree( AllCuts.c_str(),"",MaxEntries,0 );
  456. cout << "[INFO]\tNew tree entries: " << NewTree->GetEntries() << endl;
  457. //Set the appropriate outputfile
  458. string path = "";
  459. if (Run==0) Run = std::stoi( year );
  460. // Kst2Kpluspi0Resolved case
  461. if(Kst2Kpluspi0Resolved){
  462. path = path_to_output_KplusPizero + "/data/";
  463. if(!MC){
  464. path =path+ to_string(Run) + magnet + "_" +(preselected ? "preselected" : "") + "_quickcheck_pi0Resolved.root";
  465. output = new TFile(path.c_str(),"RECREATE");
  466. }
  467. else{
  468. if(ReferenceChannel)path =path +"MC/RefKplusPi0";
  469. else if (PHSP) path =path +"PHSP/KplusPi0/";
  470. else path =path +"MC/KplusPi0/";
  471. path =path + to_string(Run) + magnet +(preselected ? "_preselected" : "") + (truthMatched ? "_TruthMatched" : "") + "_quickcheck_pi0Resolved.root";
  472. output = new TFile(path.c_str(),"RECREATE");
  473. }
  474. }
  475. // Kst2Kpluspi0Merged case
  476. if(Kst2Kpluspi0Merged){
  477. path = path_to_output_KplusPizero + "/data/";
  478. if(!MC){
  479. path =path+ to_string(Run) + magnet + "_" +(preselected ? "preselected" : "") + "_quickcheck_pi0Merged.root";
  480. output = new TFile(path.c_str(),"RECREATE");
  481. }
  482. else{
  483. if(ReferenceChannel)path =path +"MC/RefKplusPi0";
  484. else if (PHSP) path =path +"PHSP/KplusPi0/";
  485. else path =path +"MC/KplusPi0/";
  486. path =path + to_string(Run) + magnet +(preselected ? "_preselected" : "") + (truthMatched ? "_TruthMatched" : "") + "_quickcheck_pi0Merged.root";
  487. output = new TFile(path.c_str(),"RECREATE");
  488. }
  489. }
  490. // Kst2Kspiplus case //TODO: needs a check
  491. if(Kst2Kspiplus){
  492. path = path_to_output_KshortPiplus + "/data/";
  493. if(!MC){
  494. path =path+ to_string(Run) + magnet + "_" +(preselected ? "preselected" : "") + "_quickcheck_piplus.root";
  495. output = new TFile(path.c_str(),"RECREATE");
  496. }
  497. else{
  498. if(ReferenceChannel)path =path +"MC/RefKshortPiplus/";
  499. else if (PHSP) path =path +"PHSP/KshortPiplus/";
  500. else path =path +"MC/KshortPiplus/";
  501. path =path + to_string(Run) + magnet +(preselected ? "_preselected" : "") + (truthMatched ? "_TruthMatched" : "") + "_quickcheck_piplus.root";
  502. output = new TFile(path.c_str(),"RECREATE");
  503. }
  504. }
  505. output->cd();
  506. // Stupid arrays :)
  507. /*
  508. TCanvas *c1 = new TCanvas("c1", "", 10,10,800,800);
  509. c1->cd();
  510. NewTree->Draw("B_plus_DTF_Kst_892_plus_M[0]");
  511. output->cd();
  512. c1->Write();
  513. */
  514. NewTree->Write();
  515. output->Close();
  516. cout << "[INFO]\t\t New tree created." << endl;
  517. return 1;
  518. }
  519. int EpicOptimizerDataSeparate(string magnet = "down", bool preselected=false) {
  520. if ( EpicOptimizer( "2011" ,magnet,0, false, false,false,preselected,false) == 0) return 0;
  521. if ( EpicOptimizer( "2012" ,magnet,0, false, false,false,preselected,false) == 0) return 0;
  522. if ( EpicOptimizer( "2015" ,magnet,0, false, false,false,preselected,false) == 0) return 0;
  523. if ( EpicOptimizer( "2016" ,magnet,0, false, false,false,preselected,false) == 0) return 0;
  524. return 1;
  525. }
  526. int EpicOptimizerAllDataSeparate(bool preselected) {
  527. if ( EpicOptimizerDataSeparate("down",preselected) == 0) return 0;
  528. if ( EpicOptimizerDataSeparate("up",preselected) == 0) return 0;
  529. return 1;
  530. }
  531. int EpicOptimizerMCSeparate(string magnet = "down", bool preselected=false, bool truthMatched=false) {
  532. if ( EpicOptimizer( "2011" ,magnet,0, true, false,false,preselected,truthMatched) == 0) return 0;
  533. if ( EpicOptimizer( "2012" ,magnet,0, true, false,false,preselected,truthMatched) == 0) return 0;
  534. if ( EpicOptimizer( "2015" ,magnet,0, true, false,false,preselected,truthMatched) == 0) return 0;
  535. if ( EpicOptimizer( "2016" ,magnet,0, true, false,false,preselected,truthMatched) == 0) return 0;
  536. return 1;
  537. }
  538. int EpicOptimizerAllMCSeparate(bool preselected=false, bool truthMatched=false) {
  539. if ( EpicOptimizerMCSeparate("down",preselected, truthMatched) == 0) return 0;
  540. if ( EpicOptimizerMCSeparate("up", preselected, truthMatched) == 0) return 0;
  541. return 1;
  542. }
  543. int EpicOptimizerRefSeparate(string magnet = "down", bool preselected=false, bool truthMatched=false) {
  544. if ( EpicOptimizer( "2011" ,magnet,0, true, true,false,preselected,truthMatched) == 0) return 0;
  545. if ( EpicOptimizer( "2012" ,magnet,0, true, true,false,preselected,truthMatched) == 0) return 0;
  546. if ( EpicOptimizer( "2015" ,magnet,0, true, true,false,preselected,truthMatched) == 0) return 0;
  547. if ( EpicOptimizer( "2016" ,magnet,0, true, true,false,preselected,truthMatched) == 0) return 0;
  548. return 1;
  549. }
  550. int EpicOptimizerAllRefSeparate(bool preselected=false, bool truthMatched=false) {
  551. if ( EpicOptimizerRefSeparate("down",preselected, truthMatched) == 0) return 0;
  552. if ( EpicOptimizerRefSeparate("up", preselected, truthMatched) == 0) return 0;
  553. return 1;
  554. }
  555. int EpicOptimizerPHSPSeparate(string magnet = "down", bool preselected=false, bool truthMatched=false) {
  556. if ( EpicOptimizer( "2011" ,magnet,0, true, false,true,preselected,truthMatched) == 0) return 0;
  557. if ( EpicOptimizer( "2012" ,magnet,0, true, false,true,preselected,truthMatched) == 0) return 0;
  558. if ( EpicOptimizer( "2015" ,magnet,0, true, false,true,preselected,truthMatched) == 0) return 0;
  559. if ( EpicOptimizer( "2016" ,magnet,0, true, false,true,preselected,truthMatched) == 0) return 0;
  560. return 1;
  561. }
  562. int EpicOptimizerAllPHSPSeparate(bool preselected=false, bool truthMatched=false) {
  563. if ( EpicOptimizerPHSPSeparate("down",preselected, truthMatched) == 0) return 0;
  564. if ( EpicOptimizerPHSPSeparate("up", preselected, truthMatched) == 0) return 0;
  565. return 1;
  566. }