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.

855 lines
42 KiB

  1. //Definition of paths used for the Selection of the B+->K*+(K+pi0)mumu analysis
  2. //Renata Kopecna
  3. #ifndef PATHS_HPP
  4. #define PATHS_HPP
  5. #include "GlobalFunctions.hh"
  6. #include "Utils.hpp"
  7. ////////////////////////////////////////////////////////////////////////
  8. ///
  9. /// FILE NAMES
  10. ///
  11. /// Function returning the string with adress to an input file,
  12. /// either stripped or preselected for all years, polarities and data/MC/MCref/PHSP
  13. ///
  14. /// GetInputFile(int/string year, string magnet, bool preSelected, bool MC,
  15. /// bool ReferenceChannel, bool PHSP, bool smallSample)
  16. /// Return fileName of selected options
  17. ///
  18. ///
  19. /// GetInputFileBkg(int/string year, string magnet, bool preSelected,
  20. /// bool ReferenceChannel, bool B0, bool K1, bool Inc)
  21. ///
  22. /// Return fileName of selected options for PiZero background study
  23. ///
  24. ///
  25. /// GetHistosFile(int/string year, string magnet, bool preSelected, bool MC,
  26. /// bool ReferenceChannel, bool PHSP, bool smallSample)
  27. ///
  28. /// Return histogram fileName of selected options
  29. ///
  30. ///
  31. /// GetHistosFileBkg(int/string year, string magnet, bool preSelected,
  32. /// bool ReferenceChannel, bool B0, bool K1, bool Inc)
  33. ///
  34. /// Return histogram fileName of selected options for PiZero background study
  35. ///
  36. ///
  37. /// GetBDTinputFile(int/string year, bool MC,
  38. /// bool ReferenceChannel, bool PHSP, bool KshortDecayInVelo)
  39. ///
  40. /// Return ROOTfile used as BDT input
  41. ///
  42. ///
  43. /// GetBDToutputFile([int/string year,] int Run, bool Selection, bool MC,
  44. /// bool ReferenceChannel, bool PHSP, bool SplitInQ2, bool UseLowQ2Range)
  45. ///
  46. /// Return ROOTfile used as BDT output
  47. ///
  48. ///
  49. /// GetControlPlots(string year, bool ReferenceChannel, bool PHSP,bool KshortDecayInVelo, bool sWeightUse, int canvas)
  50. /// Returns name of control plots for reweighting;
  51. /// case canvas = 1: Distributions
  52. /// case canvas = 2: firstMCweight
  53. /// case canvas = 3: seconMCweight
  54. /// case canvas = 4: weight Correlation
  55. ///
  56. ///string GetMassFitFile(year, magnet, Run,
  57. /// MC, Preselected, TM,
  58. /// UseOnlyJpsiEvents, UseOnlyMuMuEvents,
  59. /// GetShapeFromMC, SignalType, BckGndType, ConstrainParameters,
  60. /// KshortDecaysInVelo, UseLowQ2Range,
  61. /// TMVAcut, randomSubset,
  62. /// fixedMassRegion, yieldOverFullRange)
  63. ///
  64. /// returns the path of the MassFitFile based on the paramters
  65. ///
  66. /// Overloaded with a simle version for quickFit and basic fits
  67. ///
  68. ///string GetMassFitFile(year, magnet, Run,
  69. /// Preselected, TM,
  70. /// UseOnlyJpsiEvents, UseOnlyMuMuEvents,
  71. /// GetShapeFromMC, SignalType, BckGndType, ConstrainParameters,
  72. /// KshortDecaysInVelo, UseLowQ2Range,
  73. /// TMVAcut,
  74. /// fixedMassRegion)
  75. /// returns the path of MassFit files used for estimating efficiencies
  76. /// based on GetMassFitFile
  77. ///
  78. ///
  79. ///string GetEfficiencyFile(effType , year, string, Run,
  80. /// UseOnlyJpsiEvents, UseOnlyMuMuEvents,
  81. /// KshortDecayInVelo, UseLowQ2Range,
  82. /// useFancyFit)
  83. ///
  84. /// returns path to the file where efficiency information is stored
  85. ///
  86. /// Overloaded with versions without run/year
  87. ///
  88. /// string GetBDTScanFile(year, string, Run,
  89. /// KshortDecayInVelo, UseLowQ2Range,
  90. /// useFancyFit)
  91. ///
  92. /// returns path to the file where BDT cut scanns are stored
  93. ///
  94. ///
  95. ////////////////////////////////////////////////////////////////////////
  96. //Forward declarations from Utils.hpp
  97. string correct_magnet_string(string magnet);
  98. bool checkMC(bool &MC, bool ReferenceChannel, bool PHSP, bool mutuallyExclusive);
  99. bool checkQ2Range(bool UseOnlyJpsi, bool UseOnlyMuMu);
  100. bool checkTM(bool MC, bool &TM, bool &nonTM, bool Preselected);
  101. bool checkKshort(bool &KshortDecaysInVelo);
  102. bool checkRefYear(string year);
  103. string getTMtag(string customTMbranch);
  104. string getTMtag(string customTMbranch, bool gammaTM);
  105. //get address of stripped data
  106. string getOriginalFiles(string year, string magnet, bool MC, bool ReferenceChannel, bool PHSP, bool smallSample){
  107. string path = path_to_data + "/data/";
  108. string yearMag = year + magnet;
  109. string subDecay = Kst2Kspiplus ? "KshortPiplus" :"KplusPi0" ;
  110. if(!MC) return path + yearMag+ "/*B2Kstmumu*" + string(smallSample ? "13" : "") + ".root";
  111. else{
  112. yearMag = subDecay + "/" + yearMag;
  113. string folder = "MC/" + string(ReferenceChannel ? "Ref" : "");
  114. if (PHSP) folder = "PHSP/";
  115. string name = ReferenceChannel ? "/*B2KstJpsi" : "/*B2Kstmumu";
  116. return path + folder + yearMag + name+ string(UsePIDgen ? "PIDgen" : "") + string(smallSample ? "_0" : "_*")+".root";
  117. }
  118. }
  119. //Overloaded in case year is int or string
  120. string GetInputFile(string year, string magnet, bool preSelected, bool MC, bool ReferenceChannel, bool PHSP, bool smallSample){
  121. //sanity checks
  122. if (!checkMC(MC,ReferenceChannel,PHSP,true)) return "";
  123. magnet = correct_magnet_string(magnet);
  124. if (preSelected && smallSample) smallSample = false;
  125. string subDecay = Kst2Kspiplus ? "KshortPiplus" : "KplusPi0Resolved";
  126. string yearMag = year + magnet;
  127. string name = Kst2Kspiplus ? "_piplus" : (Kst2Kpluspi0Resolved ? "_pi0Resolved" : "_pi0Merged");
  128. string folder = "/Tuples/" + string(ReferenceChannel ? "RefMC" : "MC");
  129. if (PHSP) folder = "/Tuples/PHSP/";
  130. if (!preSelected) return getOriginalFiles(year,magnet,MC,ReferenceChannel,PHSP,smallSample);
  131. else{ //get address of preselected data
  132. // Kst2Kpluspi0Resolved case
  133. if(!MC) return thePath + "/Tuples/Data/" + yearMag + "/" + yearMag + name + ".root";
  134. else return thePath + folder + "/" + yearMag + "/" + yearMag + name + ".root";
  135. }
  136. coutERROR("Something when wrong, returning and empty string.");
  137. return "";
  138. }
  139. string GetInputFile(int year, string magnet, bool preSelected, bool MC, bool ReferenceChannel, bool PHSP, bool smallSample){
  140. return GetInputFile(std::to_string(year), magnet, preSelected, MC, ReferenceChannel, PHSP, smallSample);
  141. }
  142. string GetInputFileBkg(string year, string magnet, bool preSelected, bool ReferenceChannel, bool B0, bool K1, bool Inc){
  143. //sanity checks
  144. if (B0+K1+Inc != 1){
  145. cout << B0+K1+Inc << endl;
  146. coutERROR("Chose only one from B0, K1 and Inclusive samples!");
  147. return ""; //select precisely one!
  148. }
  149. if (magnet == "Down") magnet = "down";
  150. if (magnet == "Up") magnet = "up";
  151. if (!preSelected){
  152. if(B0){
  153. if(ReferenceChannel) return path_to_output_KplusPizero + "/Tuples/MC/BackgroundSamples/B0toKstJpsi/" + year + magnet + "/*B0toKstJpsi*.root";
  154. else return path_to_output_KplusPizero + "/Tuples/MC/BackgroundSamples/B0toKstMuMu/" + year + magnet + "/*B0toKstMuMu*.root";
  155. }
  156. else if(K1){
  157. if(ReferenceChannel) return path_to_output_KplusPizero + "/Tuples/MC/BackgroundSamples/BtoK1Jpsi/" + year + magnet + "/*BtoK1Jpsi*.root";
  158. else return path_to_output_KplusPizero + "/Tuples/MC/BackgroundSamples/BtoK1MuMu/" + year + magnet + "/*BtoK1MuMu*.root";
  159. }
  160. else if(Inc){
  161. if(ReferenceChannel) return path_to_output_KplusPizero + "/Tuples/MC/BackgroundSamples/BtoXJpsi/" + year + magnet + "/*BtoXJpsi*.root";
  162. else return path_to_output_KplusPizero + "/Tuples/MC/BackgroundSamples/BtoXMuMu/" + year + magnet + "/*BtoXMuMu*.root";
  163. }
  164. }
  165. else {
  166. if(B0){
  167. if(ReferenceChannel) return path_to_output_KplusPizero + "/Tuples/MC/BackgroundSamples/B0toKstJpsi/" + year + magnet + "/" + year + magnet + "_pi0Resolved.root";
  168. else return path_to_output_KplusPizero + "/Tuples/MC/BackgroundSamples/B0toKstMuMu/" + year + magnet + "/" + year + magnet + "_pi0Resolved.root";
  169. }
  170. else if(K1){
  171. if(ReferenceChannel) return path_to_output_KplusPizero + "/Tuples/MC/BackgroundSamples/BtoK1Jpsi/" + year + magnet + "/" + year + magnet + "_pi0Resolved.root";
  172. else return path_to_output_KplusPizero + "/Tuples/MC/BackgroundSamples/BtoK1MuMu/" + year + magnet + "/" + year + magnet + "_pi0Resolved.root";
  173. }
  174. else if(Inc){
  175. if(ReferenceChannel) return path_to_output_KplusPizero + "/Tuples/MC/BackgroundSamples/BtoXJpsi/" + year + magnet + "/" + year + magnet + "_pi0Resolved.root";
  176. else return path_to_output_KplusPizero + "/Tuples/MC/BackgroundSamples/BtoXMuMu/" + year + magnet + "/" + year + magnet + "_pi0Resolved.root";
  177. }
  178. }
  179. return "";
  180. }
  181. string GetInputFileBkg(int year, string magnet, bool preSelected, bool ReferenceChannel, bool B0, bool K1, bool Inc){
  182. return GetInputFileBkg(std::to_string(year), magnet, preSelected, ReferenceChannel, B0, K1, Inc);
  183. }
  184. string GetInputFile(string year, string magnet, bool preSelected, bool MC, bool ReferenceChannel, bool PHSP, bool B0, bool K1, bool Inc, bool smallSample){
  185. if (B0 || K1 || Inc)
  186. return GetInputFileBkg(year, magnet, preSelected, ReferenceChannel, B0, K1, Inc);
  187. else return GetInputFile(year, magnet, preSelected, MC, ReferenceChannel, PHSP, smallSample);
  188. }
  189. string GetHistosFile(string year, string magnet, bool MC, bool ReferenceChannel, bool PHSP, bool smallSample){
  190. std::string inputName = GetInputFile(year, magnet, true, MC, ReferenceChannel, PHSP, smallSample);
  191. smallSample ? replace(inputName, "_small.root", "_histos_small.root") : replace(inputName, ".root", "_histos.root");
  192. return inputName;
  193. }
  194. string GetHistosFile(int year, string magnet, bool MC, bool ReferenceChannel, bool PHSP, bool smallSample){
  195. return GetHistosFile(std::to_string(year), magnet, MC, ReferenceChannel, PHSP, smallSample);
  196. }
  197. string GetHistosFileBkg(string year, string magnet, bool ReferenceChannel, bool B0, bool K1, bool Inc){
  198. std::string inputName = GetInputFileBkg(year,magnet,true,ReferenceChannel,B0, K1, Inc);
  199. smallSample ? replace(inputName, "_small.root", "_histos_small.root") : replace(inputName, ".root", "_histos.root");
  200. return inputName;
  201. }
  202. string GetHistosFileBkg(int year, string magnet, bool ReferenceChannel, bool B0, bool K1, bool Inc){
  203. return GetHistosFileBkg(std::to_string(year), magnet, ReferenceChannel, B0, K1, Inc);
  204. }
  205. ////////////////////////////////////////////////////////////////////////
  206. ///
  207. /// Generator level files
  208. ///
  209. ////////////////////////////////////////////////////////////////////////
  210. string GetGenLevelFile(bool ReferenceChannel, bool PHSP){ //TODO
  211. string tag = string(ReferenceChannel ? "_RefChan" : "") + string(PHSP ? "_PHSP" : "");
  212. return thePath + string(PHSP ? "/Tuples/PHSP/EvtGen/" : "/Tuples/MC/EvtGen/") + "MCTruth" + tag + ".root";
  213. }
  214. ////////////////////////////////////////////////////////////////////////
  215. ///
  216. /// BDT files
  217. ///
  218. ////////////////////////////////////////////////////////////////////////
  219. string GetBDTinputFile(string year, bool MC, bool ReferenceChannel, bool PHSP, bool KshortDecayInVelo){
  220. //sanity checks
  221. if (PHSP) MC = true; //if PHSP, set MC to true
  222. //Carefull! Reference channel can be also in data, when reweighted by RefChannel
  223. string subDecay = Kst2Kspiplus ? "KshortPiplus" : "KplusPi0Resolved";
  224. //get address of preselected data
  225. string trackType = SplitDDandLL ? (KshortDecayInVelo ? "_LL" : "_DD") : "";
  226. string folder = MC ? string(PHSP ? "/Tuples/PHSP/" : "/Tuples/MC/") : "/Tuples/Data/";
  227. string tag = string(ReferenceChannel ? "_Ref" : "_") + string(PHSP ? "PHSP" : "");
  228. return thePath + folder + year + tag + subDecay + trackType + "_BDTinput.root";
  229. }
  230. string GetBDTinputFile(int year, bool MC, bool ReferenceChannel, bool PHSP, bool KshortDecayInVelo){
  231. return GetBDTinputFile(to_string(year),MC,ReferenceChannel,PHSP, KshortDecayInVelo);
  232. }
  233. //This file constains the BDTresponse branch. It is the output of the TMVAClassApp file. Does not contain any cut to the BDTresponse yet
  234. string GetBDToutputFile(string year, int Run, bool MC, bool ReferenceChannel, bool PHSP, bool KshortDecayInVelo, bool UseLowQ2Range, bool reweighted){
  235. //sanity checks
  236. if (PHSP) MC = true; //if PHSP, set MC to true
  237. // Carefull! Reference channel can be also in data, when reweighted by RefChannel
  238. if (MC && ReferenceChannel && !checkRefYear(year)) return "";
  239. string subDecay = Kst2Kspiplus ? "KshortPiplus" : "KplusPi0Resolved";
  240. if (!SplitInQ2 && UseLowQ2Range) UseLowQ2Range = false; //Cannot use lowQ2 if it's not split
  241. //get address of BTD input data
  242. string stringSplitInQ2 = SplitInQ2? (UseLowQ2Range ? "_lowQ2" : "_highQ2") : "";
  243. //DD or LL track type string
  244. string trackType = SplitDDandLL ? (KshortDecayInVelo ? "_LL" : "_DD") : "";
  245. string reweight = (MC && reweighted) ? "_withTMeffWeights" : "";
  246. string runYear = to_string(Run) + (year == "-1" ? "" : string("_" + year));
  247. //Set folder and tags correctly
  248. string folder = MC ? string(PHSP ? "/Tuples/PHSP/" : "/Tuples/MC/") : "/Tuples/Data/";
  249. string tag = PHSP ? "_PHSP" : (string(ReferenceChannel ? "_Ref" : "_") + string(MC ? "MC" : ""));
  250. return thePath + folder + subDecay + trackType + tag + "_BDToutput_Run" + runYear+ stringSplitInQ2+reweight+".root";
  251. }
  252. string GetBDToutputFile(int year, int Run, bool MC, bool ReferenceChannel, bool PHSP, bool KshortDecayInVelo, bool UseLowQ2Range, bool reweighted){
  253. return GetBDToutputFile(std::to_string(year), Run,MC,ReferenceChannel,PHSP,KshortDecayInVelo,UseLowQ2Range, reweighted);
  254. }
  255. string GetBDToutputFile(int Run, bool MC, bool ReferenceChannel, bool PHSP, bool KshortDecayInVelo, bool UseLowQ2Range, bool reweighted){
  256. return GetBDToutputFile(-1,Run,MC,ReferenceChannel,PHSP,KshortDecayInVelo,UseLowQ2Range, reweighted);
  257. }
  258. //this one is used in MVA.cpp to save the configuration of the TMVA
  259. string GetBDTConfigFile(bool SplitYears, int year, int Run, bool KShortDecaysInVelo, int nConfiguration, bool UseLowQ2Range, string customTMbranch, bool gammaTM){
  260. string yr = string(SplitYears ? to_string(year) : "") ;
  261. string rn = string(SplitYears ? "" : string("_Run"+to_string(Run)));
  262. string KshortTag = string(SplitDDandLL ? (string(KShortDecaysInVelo ? "_LL" : "_DD")) : "");
  263. string q2Split = string(SplitInQ2 ? string(UseLowQ2Range ? "_lowQ2" : "_highQ2") : "");
  264. return thePath + "/Config/BDTout_" + yr + "_B2Kstmumu_" + TheDecay + q2Split + KshortTag + "_Config_" + to_string(nConfiguration) + rn + ".root" ;
  265. }
  266. ////////////////////////////////////////////////////////////////////////
  267. ///
  268. /// Final selection files
  269. ///
  270. ////////////////////////////////////////////////////////////////////////
  271. //After the cut is applied, these files contain the final selection
  272. string GetFinalOutputFile(string year, int Run, bool MC, bool ReferenceChannel, bool PHSP, bool KshortDecayInVelo, bool UseLowQ2Range){
  273. std::string output = GetBDToutputFile(stoi(year),Run,MC,ReferenceChannel,PHSP,KshortDecayInVelo,UseLowQ2Range,false);
  274. replace(output, "BDToutput", "BDToutputSelection");
  275. return output;
  276. }
  277. string GetFinalOutputFile(int year, int Run, bool MC, bool ReferenceChannel, bool PHSP, bool KshortDecayInVelo, bool UseLowQ2Range){
  278. return GetFinalOutputFile(std::to_string(year), Run, MC, ReferenceChannel, PHSP, KshortDecayInVelo, UseLowQ2Range);
  279. }
  280. string GetFinalOutputFile(int Run, bool MC, bool ReferenceChannel, bool PHSP, bool KshortDecayInVelo, bool UseLowQ2Range){
  281. return GetFinalOutputFile(-1, Run, MC, ReferenceChannel, PHSP, KshortDecayInVelo, UseLowQ2Range);
  282. }
  283. ////////////////////////////////////////////////////////////////////////
  284. ///
  285. /// Mass Fit files
  286. ///
  287. ////////////////////////////////////////////////////////////////////////
  288. //Mass fit files
  289. //Define path names outside fo functions; it is useful when one needs to access the information inside the canvas/rootfile, especially for the Bmass
  290. string GetControlPlots(string year, bool ReferenceChannel, bool PHSP, bool KshortDecayInVelo, bool sWeightUse, int canvas){
  291. string trackType = SplitDDandLL ? (KshortDecayInVelo ? "_LL" : "_DD") : "";
  292. std::string appendix;
  293. if ((canvas == 1 || canvas == 4) && (PHSP || ReferenceChannel))
  294. return "";
  295. // no need to reprint the nTrack distribution of data in the case of PHSP or RefChannel reweighting
  296. //save correlation plot p_T(B):nTracks (data tuple) only if Signal MC
  297. if (canvas == 2 || canvas == 3 ){
  298. if(ReferenceChannel)appendix.append("Ref");
  299. else if(PHSP) appendix.append("PHSP");
  300. else appendix.append("MC");
  301. }
  302. if (sWeightUse == false) appendix.append("_nosWeight");
  303. string canvasName = "";
  304. switch(canvas) {
  305. case 1 : canvasName = "_" + firstMCweight + "Distributions";
  306. break;
  307. case 2 :canvasName = "_" + firstMCweight + "Weights_";
  308. break;
  309. case 3 :canvasName = "_" + seconMCweight + "Weights_";
  310. break;
  311. case 4 :canvasName = "_" + firstMCweight + "_" + seconMCweight + "_Correlation";
  312. break;
  313. }
  314. return thePath + "/MassFits/weightPlots/" + year + "_" + TheDecay + trackType+ canvasName + appendix + "_" + ".root";
  315. }
  316. string GetMassFitFile(std::string year, string magnet, int Run,
  317. bool MC, bool Preselected, bool TM, bool PHSP, //input/output file selection
  318. bool UseOnlyJpsiEvents, bool UseOnlyMuMuEvents, //signal/reference
  319. bool GetShapeFromMC, string SignalType, string BckGndType, bool ConstrainParameters, //shape from MC?
  320. bool KshortDecaysInVelo, bool UseLowQ2Range, //LL/DD? // q2 range
  321. Double_t TMVAcut, int randomSubset, //TMVA options
  322. bool fixedMassRegion, bool yieldOverFullRange, //fit range options
  323. string sExtraVar, int nExtraBin, //Efficiency in different variable, binned
  324. bool removeMultiple, bool weighted, bool weightedFromPi0, string whichWeight, bool notTM, string customTMbranch, bool gammaTM, bool InclusiveSample
  325. ){
  326. //If Run==0, fit per year is done, otherwise whole Run is fitted
  327. //if TMVA cut == -1.0, no cut is applied
  328. //sanity checks
  329. checkMC(MC,false,PHSP,false);
  330. if (!checkTM(MC,TM,notTM,Preselected)) return "";
  331. if (!checkQ2Range(UseOnlyJpsiEvents,UseOnlyMuMuEvents)) return "";
  332. magnet = correct_magnet_string(magnet);
  333. checkKshort(KshortDecaysInVelo);
  334. if (!SplitInQ2 && UseLowQ2Range) UseLowQ2Range = false; //Cannot use lowQ2 if it's not split
  335. if (TMVAcut > -1.0 && !Preselected)Preselected = true; //TMVA cut can be only aplied on preselected data
  336. string yearRun = string((Run != 0) ? ("Run" + to_string(Run)) : (year));
  337. string polarity = (magnet == "both" ? "" : ("_"+magnet));
  338. string trackType = SplitDDandLL ? (KshortDecaysInVelo ? "_LL" : "_DD") : "";
  339. string resonance = (UseOnlyJpsiEvents ? "_JpsiOnly" : (UseOnlyMuMuEvents ? "_mumu" : ""));
  340. string splitInQ2 = SplitInQ2? (UseLowQ2Range ? "_lowQ2" : "_highQ2") : "";
  341. string fitModel = SignalType + "_" + BckGndType;
  342. string TMtype = "";
  343. if (MC) TMtype = string(TM ? "_TM" : (notTM ? "_notTM" : "_all")) + getTMtag(customTMbranch,gammaTM);
  344. coutDebug("TM type: " + TMtype);
  345. string dataType = string(MC ? (InclusiveSample ? "_IncMC" : "_MC") : "") + string(UseDTF ? "_DTF" : "") + string(Preselected ? "" : "_stripped")+ TMtype +(PHSP ? "_PHSP" : "");
  346. string cutResponse = (TMVAcut==-1) ? "" : ("_TMVA"+to_string(TMVAcut));
  347. string constrains = string(ConstrainParameters ? "_constrained" : "") + string(GetShapeFromMC ? "_fixShape" : "");
  348. string fixedMRegion = fixedMassRegion ? "_fixedMassWindow" : "";
  349. string yieldRange = yieldOverFullRange ? "_fullRangeYield" : "";
  350. string subset = (randomSubset != 0 ? (randomSubset == -1 ? "_subset1" : "_subset2" ) : "");
  351. string extraVar = (sExtraVar != "" ? ("_" + sExtraVar + "_" + to_string(nExtraBin)) : "");
  352. string removeMult = removeMultiple ? "_removedMultiple" : "";
  353. string weight = string(weighted ? "_weighted" : "") + string(weightedFromPi0 ? "_TMweight_"+whichWeight : "");
  354. string dir = thePath + "/Efficiencies/MassFits/" + dataType + "/" + resonance + "/"+ yearRun + "/" + fitModel + "/" ;
  355. string command = "mkdir -p " + dir; //It's stupid but it shouldn't take too much time extra to create two folders instead of one
  356. system(command.c_str());
  357. replace(dir,"Efficiencies/MassFits", "MassFits");
  358. command = "mkdir -p " + dir;
  359. system(command.c_str());
  360. return dir + yearRun + polarity + "_" + TheDecay + trackType + resonance + splitInQ2 + "_BplusMassModel_"
  361. + fitModel + dataType + TMtype + weight +removeMult + cutResponse + constrains + fixedMRegion + yieldRange +subset + extraVar + ".root";
  362. }
  363. //Simple version for quickFit
  364. string GetMassFitFile(std::string year, bool MC, bool UseOnlyJpsiEvents, bool UseOnlyMuMuEvents, bool KshortDecaysInVelo,
  365. bool GetShapeFromMC, string SignalType, string BckGndType, bool ConstrainParameters, //shape from MC?
  366. bool fixedMassRegion, bool weighted){ //fit range options
  367. return GetMassFitFile(year,"both",0,
  368. MC,true, true,false,
  369. UseOnlyJpsiEvents, UseOnlyMuMuEvents,
  370. GetShapeFromMC, SignalType, BckGndType,ConstrainParameters,
  371. KshortDecaysInVelo,false,
  372. -1.0, 0,
  373. fixedMassRegion, false,"",-1,false,weighted,false,"",false,"",true, false);
  374. }
  375. //Simple version for basic fits
  376. string GetMassFitFile(std::string year, int Run, bool MC, bool PHSP, //input/output file selection
  377. bool UseOnlyJpsiEvents, bool UseOnlyMuMuEvents, //signal/reference
  378. bool GetShapeFromMC, string SignalType, string BckGndType, bool ConstrainParameters, //shape from MC?
  379. bool KshortDecaysInVelo, bool UseLowQ2Range, //LL/DD? // q2 range
  380. Double_t TMVAcut, //TMVA options
  381. bool fixedMassRegion, //fit range options
  382. bool removeMultiple
  383. ){ //fit range options
  384. return GetMassFitFile(year,"both", Run,
  385. MC, true, MC, PHSP,
  386. UseOnlyJpsiEvents, UseOnlyMuMuEvents,
  387. GetShapeFromMC, SignalType, BckGndType,ConstrainParameters,
  388. KshortDecaysInVelo, UseLowQ2Range,
  389. TMVAcut, 0, fixedMassRegion, false, "", -1, removeMultiple,
  390. MC, false, "", //TODO: test if weighting works as it should
  391. false, "", gammaTMdefault, false);
  392. }
  393. ////////////////////////////////////////////////////////////////////////
  394. ///
  395. /// Efficiency files
  396. ///
  397. ////////////////////////////////////////////////////////////////////////
  398. string GetEfficiencyMassFitFile(std::string year, string magnet,int Run,
  399. bool Preselected, bool TM, bool PHSP, //input/output file selection
  400. bool UseOnlyJpsiEvents, bool UseOnlyMuMuEvents, //signal/reference
  401. bool GetShapeFromMC, string SignalType, string BckGndType, bool ConstrainParameters, //shape from MC?
  402. bool KshortDecaysInVelo, bool UseLowQ2Range, //LL/DD? // q2 range
  403. Double_t TMVAcut, //TMVA options
  404. bool fixedMassRegion, //fit range options
  405. string sExtraVar, int nExtraBin, //Efficiency in different variable, binned
  406. bool removeMultiple, bool weighted, bool weightedFromPi0, string whichWeight,
  407. string customTMbranch, bool gammaTM
  408. ){
  409. string filePath = GetMassFitFile(year,magnet, Run,
  410. true, Preselected, TM, PHSP,
  411. UseOnlyJpsiEvents, UseOnlyMuMuEvents,
  412. GetShapeFromMC, SignalType, BckGndType,ConstrainParameters,
  413. KshortDecaysInVelo, UseLowQ2Range,
  414. TMVAcut, 0,
  415. fixedMassRegion, false, sExtraVar, nExtraBin,
  416. removeMultiple, weighted, weightedFromPi0, whichWeight,
  417. false, customTMbranch, gammaTM, false);
  418. replace(filePath,"MassFits", "Efficiencies/MassFits");
  419. return filePath;
  420. }
  421. //The name is a bit stupid, but it's also used for the simultaneous B+ mass fit
  422. string GetEfficiencyPi0MassFitFile(bool fromPi0, string year, string magnet, int Run,
  423. string customTMbranch, bool gammaTM,
  424. int nBins, bool fixSigma, bool fixMass,
  425. bool useFancyFit, bool simFit, bool binnedFit,
  426. bool UseOnlyMuMuEvents, bool PHSP, bool RemoveMultiple, bool weighted, bool weightedFromPi0, string whichWeight, string sExtraVar, int nExtraBin){
  427. string yearRun = (Run != 0) ? ("Run" + to_string(Run)) : (year);
  428. string polarity = (magnet == "both" ? "" : ("_"+magnet));
  429. string MCtype = string(PHSP? "PHSP" : (!UseOnlyMuMuEvents ? "RefMC" : "MC")); //Possibly TODO
  430. string extraVar = (sExtraVar != "" ? ("_" + sExtraVar + "_" + to_string(nExtraBin)) : "");
  431. string removeMult = RemoveMultiple ? "_removedMultiple" : "";
  432. string weight = string(weighted ? "_weighted" : "") + string(weightedFromPi0 ? "_TMweight_"+whichWeight : "");
  433. if (customTMbranch == "") customTMbranch = TMbranch; //TODO: think about this one, will change customTMbranch for usage also elsewhere, but if it's empty, TMbranch usage is assumed
  434. string binning = "nBins_" + to_string(nBins);
  435. if (useFancyFit && !binnedFit) binning = "";
  436. string constrains = string(fixMass ? "_fixMass" : "") + string(fixSigma ? "_fixSigma" : "");
  437. string customTMtag = getTMtag(customTMbranch,gammaTM);
  438. string fitType = string(useFancyFit ? "_fancyFit" + string(simFit ? "_simFit" : "") + string(binnedFit ? "_binnedFit" : "") : "");
  439. string TMdir = fromPi0 ? "TM_from_Pi0" : "TM_from_Bplus";
  440. string dir =thePath+"/Efficiencies/MassFits/"+TMdir+"/"+MCtype+"/"+yearRun+"/";
  441. string command = "mkdir -p " + dir;
  442. system(command.c_str());
  443. return dir + yearRun + polarity + "_" + TheDecay + "_" + customTMtag + constrains + fitType + binning + "_Efficiency" + weight + removeMult +"_" + extraVar + ".root";
  444. }
  445. string GetEfficiencyFile(string effType, string year, string magnet, int Run, //input/output file selection
  446. bool UseOnlyJpsiEvents, bool UseOnlyMuMuEvents, bool PHSP, bool KshortDecayInVelo,
  447. bool RemoveMultiple, bool weighted, bool weightedFromPi0, string whichWeight,
  448. bool UseLowQ2Range, bool useFancyFit, string sExtraVar,
  449. string customTMbranch, bool gammaTM,
  450. int nBins, bool fixSigma, bool fixMass, bool simFit, bool binnedFit, bool sigEff){
  451. //TODO add an if in the path depending on splitting in Q2 bin
  452. string trackType = SplitDDandLL ? (KshortDecayInVelo ? "_LL" : "_DD") : "";
  453. string resonance = (UseOnlyJpsiEvents ? "_JpsiOnly" : (UseOnlyMuMuEvents ? "_mumu" : ""));
  454. string phaseSpace= PHSP ? "_PHSP" : "";
  455. string splitInQ2 = SplitInQ2? (UseLowQ2Range ? "_lowQ2" : "_highQ2") : "";
  456. string polarity = (magnet == "both" ? "" : ("_"+magnet));
  457. string yearRun = (Run != 0) ? ("Run" + to_string(Run)) : (year);
  458. string extraVar = (sExtraVar != "" ? "_" + sExtraVar : "");
  459. string remove = RemoveMultiple ? "_AloneOnly_" : "" ;
  460. string weight = string(weighted ? "_weighted" : "") + string(weightedFromPi0 ? "_TMweight_"+whichWeight : "");
  461. string binning = (nBins == -1 ? "" : "_nBins" + to_string(nBins) );
  462. string constrains = string(fixMass ? "_fixMass" : "") + string(fixSigma ? "_fixSigma" : "");
  463. string customTMtag = getTMtag(customTMbranch,gammaTM);
  464. string isSigEff = (sigEff ? "" : "_BKG/");
  465. string fitType = string(useFancyFit ? "_fancy" + string(simFit ? "_simFit" : "") + string(binnedFit ? "_binnedFit" : "") : "");
  466. string dir =thePath+"/Efficiencies/"+resonance+"/"+phaseSpace+"/"+effType+"/" + yearRun +"/" + isSigEff;
  467. string command = "mkdir -p " + dir;
  468. system(command.c_str());
  469. return dir + TheDecay + trackType + resonance + phaseSpace + customTMtag + constrains + binning + weight + splitInQ2+ "_" + effType + remove +"Efficiency_" + yearRun + polarity + fitType + extraVar + ".root";
  470. }
  471. string GetEfficiencyFileTM(string effType, string year, string magnet, int Run, //input/output file selection
  472. bool UseOnlyJpsiEvents, bool UseOnlyMuMuEvents, bool PHSP, bool KshortDecayInVelo,
  473. bool RemoveMultiple, bool weighted, bool weightedFromPi0, string whichWeight,
  474. bool UseLowQ2Range, bool useFancyFit, string sExtraVar, bool sigEff,
  475. string customTMbranch, bool gammaTM){
  476. return GetEfficiencyFile(effType, year, magnet, Run, UseOnlyJpsiEvents, UseOnlyMuMuEvents, PHSP, KshortDecayInVelo, RemoveMultiple, weighted, weightedFromPi0, whichWeight, UseLowQ2Range, useFancyFit, sExtraVar, customTMbranch, gammaTM, -1, false, false, false, false, sigEff);
  477. }
  478. string GetEfficiencyFilePi0TM(string year, int Run, //input/output file selection
  479. bool UseOnlyJpsiEvents, bool UseOnlyMuMuEvents, bool PHSP,
  480. bool weightedFromPi0, string whichWeight,
  481. bool useFancyFit, string sExtraVar, bool sigEff){
  482. if (useFancyFit) return GetEfficiencyFile("TM_from_Pi0", year, "both", Run, UseOnlyJpsiEvents, UseOnlyMuMuEvents, PHSP, false, false, false, weightedFromPi0, whichWeight, false, useFancyFit, sExtraVar,"", gammaTMdefault, -1, true, true, true, false, sigEff);
  483. else return GetEfficiencyFile("TM_from_Pi0", year, "both", Run, UseOnlyJpsiEvents, UseOnlyMuMuEvents, PHSP, false, false, false, weightedFromPi0, whichWeight, false, useFancyFit, sExtraVar,"", gammaTMdefault, 40,true,true, false, false, sigEff);
  484. }
  485. string GetEfficiencyFile(string effType, string year, string magnet, int Run, //input/output file selection
  486. bool UseOnlyJpsiEvents, bool UseOnlyMuMuEvents, bool PHSP,
  487. bool KshortDecayInVelo, bool RemoveMultiple, bool weighted, bool UseLowQ2Range,
  488. bool useFancyFit, string sExtraVar,
  489. string customTMbranch, bool gammaTM
  490. ){
  491. return GetEfficiencyFile(effType, year, magnet, Run,
  492. UseOnlyJpsiEvents, UseOnlyMuMuEvents,
  493. PHSP, KshortDecayInVelo, RemoveMultiple, weighted,
  494. false, "",
  495. UseLowQ2Range, useFancyFit, sExtraVar,
  496. customTMbranch, gammaTM,
  497. -1, false, false, false, false,true);
  498. }
  499. //Default efficiency files used in BDTcutScanner, for different year and run
  500. string GetEfficiencyFile(string effType, string year, string magnet, int Run,
  501. bool UseOnlyJpsiEvents, bool UseOnlyMuMuEvents, bool PHSP,
  502. bool KshortDecayInVelo, bool RemoveMultiple, bool weighted, bool UseLowQ2Range,
  503. bool useFancyFit, string sExtraVar
  504. ){
  505. return GetEfficiencyFile(effType, year, magnet, Run,
  506. UseOnlyJpsiEvents, UseOnlyMuMuEvents,
  507. PHSP, KshortDecayInVelo, RemoveMultiple, weighted,
  508. UseLowQ2Range, useFancyFit, sExtraVar, "", gammaTMdefault);
  509. }
  510. //Defualt efficiency files used in BDTcutScanner, for different year
  511. string GetEfficiencyFile(string effType, string year, string magnet,
  512. bool UseOnlyJpsiEvents, bool UseOnlyMuMuEvents,bool PHSP,
  513. bool KshortDecayInVelo, bool RemoveMultiple, bool weighted, bool UseLowQ2Range,
  514. bool useFancyFit, string sExtraVar){
  515. return GetEfficiencyFile(effType, year, magnet, 0,
  516. UseOnlyJpsiEvents, UseOnlyMuMuEvents,
  517. PHSP, KshortDecayInVelo, RemoveMultiple, weighted,
  518. UseLowQ2Range, useFancyFit, sExtraVar, "", gammaTMdefault);
  519. }
  520. //Defualt efficiency files used in BDTcutScanner, for different run
  521. string GetEfficiencyFile(string effType, string magnet, int Run,
  522. bool UseOnlyJpsiEvents, bool UseOnlyMuMuEvents,bool PHSP,
  523. bool KshortDecayInVelo, bool RemoveMultiple, bool weighted, bool UseLowQ2Range,
  524. bool useFancyFit, string sExtraVar){
  525. return GetEfficiencyFile(effType, "", magnet, Run,
  526. UseOnlyJpsiEvents, UseOnlyMuMuEvents,
  527. PHSP, KshortDecayInVelo, RemoveMultiple, weighted,
  528. UseLowQ2Range, useFancyFit, sExtraVar, "", gammaTMdefault);
  529. }
  530. string GetBDTScanFile(string year, string magnet, int Run, //input/output file selection
  531. bool KshortDecayInVelo, bool UseLowQ2Range,
  532. bool fineScan){
  533. string trackType = SplitDDandLL ? (KshortDecayInVelo ? "_LL" : "_DD") : "";
  534. string splitInQ2 = SplitInQ2? (UseLowQ2Range ? "_lowQ2" : "_highQ2") : "";
  535. string polarity = (magnet == "both" ? "" : ("_"+magnet));
  536. string yearRun = (Run != 0) ? ("Run" + to_string(Run)) : (year);
  537. return thePath + "/Tuples/FinalSelection/" + TheDecay + "_BDTscan" + trackType + splitInQ2+ "_" + yearRun + polarity + (fineScan ? "_fine" : "") + ".root";
  538. }
  539. string GetBDTScanBackgroundFitFile(string year, int Run, //input/output file selection
  540. bool KshortDecayInVelo, bool UseLowQ2Range,
  541. double TMVAcut){
  542. string trackType = SplitDDandLL ? (KshortDecayInVelo ? "_LL" : "_DD") : "";
  543. string splitInQ2 = SplitInQ2? (UseLowQ2Range ? "_lowQ2" : "_highQ2") : "";
  544. string yearRun = (Run != 0) ? ("Run" + to_string(Run)) : (year);
  545. string cutResponse = (TMVAcut==-1) ? "" : ("_TMVA"+to_string(TMVAcut));
  546. string dir = thePath + "/BkgFits/"+ yearRun + "/";
  547. string command = "mkdir -p " + dir; //It's stupid but it shouldn't take too much time extra to create two folders instead of one
  548. system(command.c_str());
  549. return dir + TheDecay + "_BkgFit" + trackType + splitInQ2+ "_" + yearRun + cutResponse + ".root";
  550. }
  551. string GetTMVAplotsFolder(int year, int Run, bool SplitYears, bool KshortDecaysInVelo,int nConfiguration, bool UseLowQ2Range, string customTMbranch, bool gammaTM){
  552. //string TMfolder = "";
  553. string TMfolder = getTMtag(customTMbranch,gammaTM);
  554. TMfolder.erase(TMfolder.begin()); //remove the _ at the beginning
  555. return thePath + "/TMVAplots/" + string(SplitYears ? to_string(year) : ("Run" + to_string(Run)))+"/"
  556. + string(SplitDDandLL ? (KshortDecaysInVelo ? "LL/" : "DD/") : "")
  557. + string(SplitInQ2 ? (UseLowQ2Range ? "LowQ2/" : "HighQ2/") : "")
  558. + "Config" + to_string(nConfiguration) + "/" + TMfolder + "/";
  559. //Ready for the file name
  560. }
  561. string GetTMVAplotsFolder(int year, int Run, bool SplitYears, bool KshortDecaysInVelo,int nConfiguration, bool UseLowQ2Range){
  562. return thePath + "/TMVAplots/" + string(SplitYears ? to_string(year) : ("Run" + to_string(Run)))+"/"
  563. + string(SplitDDandLL ? (KshortDecaysInVelo ? "LL/" : "DD/") : "")
  564. + string(SplitInQ2 ? (UseLowQ2Range ? "LowQ2/" : "HighQ2/") : "")
  565. + "Config" + to_string(nConfiguration) + "/";
  566. //Ready for the file name
  567. }
  568. string getResolutionFile(string year, int Run, bool TM, bool RemoveMultiple, double TMVAcut, bool ReferenceChannel, bool PHSP, bool KshortDecayInVelo){
  569. string trackType = SplitDDandLL ? (KshortDecayInVelo ? "_LL" : "_DD") : "";
  570. string cutResponse = (TMVAcut==-1) ? "" : ("_TMVA"+to_string(TMVAcut));
  571. string MCtype = string(PHSP? "PHSP" : (ReferenceChannel ? "RefMC" : "MC"));
  572. string removeMult = RemoveMultiple ? "_removedMultiple" : "";
  573. string sTM = string(TM ? "_TM" + getTMtag("",gammaTMdefault): "");
  574. return thePath + "/Resolution/"+MCtype +"/"+ year+ "/" + TheDecay + trackType + "_" + MCtype +"_Run" + to_string(Run) +"_" + year + sTM + cutResponse + removeMult + ".root";
  575. }
  576. string returnFileAddress(string year, int Run, string magnet, bool Preselected, bool BDTed, bool MC, bool ReferenceChannel, bool PHSP, bool KshortDecayInVelo){
  577. bool UseLowQ2Range = false; //keeping in case
  578. if (magnet == "both"){
  579. if (BDTed) return GetFinalOutputFile(year,Run,MC,ReferenceChannel,PHSP,KshortDecayInVelo,UseLowQ2Range);
  580. else return GetBDTinputFile(year,MC,ReferenceChannel,PHSP,KshortDecayInVelo);
  581. }
  582. else return GetInputFile(year,magnet,Preselected,MC,ReferenceChannel,PHSP,false);
  583. }
  584. ////////////////////////////////////////////////////////////////////////
  585. ///
  586. /// TM control plots
  587. ///
  588. ////////////////////////////////////////////////////////////////////////
  589. std::string dataTypeString(bool MC, bool Reference, bool PHSP, bool B0, bool K1, bool Inc){
  590. if (!MC) return "Data";
  591. else{
  592. if (PHSP) return "PHSP";
  593. else{
  594. if (B0) return Reference ? "B0toKstJpsi" : "B0toKstMuMu";
  595. else if (K1) return Reference ? "BtoK1Jpsi" : "BtoK1MuMu";
  596. else if (Inc) return Reference ? "BtoXJpsi" : "BtoXMuMu";
  597. else return Reference ? "RefMC" : "SigMC";
  598. }
  599. }
  600. }
  601. string getTMplotsFolder(string year, bool Reference, bool PHSP, bool B0, bool K1, bool Inc){
  602. string MCtype = dataTypeString(true,Reference, PHSP, B0, K1, Inc);
  603. string dir = thePath + "/TMplots/"+ MCtype +"/";
  604. string command = "mkdir -p " + dir;
  605. system(command.c_str());
  606. dir += year + "/";
  607. command = "mkdir -p " + dir;
  608. system(command.c_str());
  609. return dir;
  610. }
  611. string getTMplotsPath(string name, string year, bool Reference, bool PHSP, bool B0, bool K1, bool Inc){
  612. return getTMplotsFolder(year,Reference, PHSP, B0, K1, Inc) + year + "_" + TheDecay + "_" + name + ".eps";
  613. }
  614. ////////////////////////////////////////////////////////////////////////
  615. ///
  616. /// Restore preselected data from backups
  617. ///
  618. ////////////////////////////////////////////////////////////////////////
  619. bool restore_from_backup(string year, string magnet, bool MC, bool ReferenceChannel, bool PHSP){
  620. string string_input = GetInputFile(year,magnet,true, MC, ReferenceChannel, PHSP, false);
  621. string backup_file = string_input;
  622. replace(backup_file,".root","_backup.root");
  623. if (MC) replace(backup_file,"_backup.root","_TMbackup.root");
  624. string command = "mv " + backup_file + " " + string_input;
  625. coutDebug(command);
  626. system(command.c_str());
  627. return 1;
  628. }
  629. bool restore_allYears_from_backup(bool MC, bool ReferenceChannel, bool PHSP){
  630. for (auto &year :yearsVector(MC,ReferenceChannel,PHSP,12) ){
  631. restore_from_backup(year,"down",MC,ReferenceChannel,PHSP);
  632. restore_from_backup(year,"up",MC,ReferenceChannel,PHSP);
  633. }
  634. return 1;
  635. }
  636. bool restore_allData_from_backup(){
  637. restore_allYears_from_backup(false,false,false);
  638. return 1;
  639. }
  640. int restore_allMCsig_from_backup(){
  641. restore_allYears_from_backup(true,false,false);
  642. return 1;
  643. }
  644. int restore_allMCref_from_backup(){
  645. restore_allYears_from_backup(true,true,false);
  646. return 1;
  647. }
  648. int restore_allPHSP_from_backup(){
  649. restore_allYears_from_backup(true,false,true);
  650. return 1;
  651. }
  652. int restore_allMC_from_backup(){
  653. restore_allYears_from_backup(true,false,false);
  654. restore_allYears_from_backup(true,true, false);
  655. restore_allYears_from_backup(true,false,true);
  656. return 1;
  657. }
  658. //Create backup
  659. bool create_backup(string year, string magnet, bool MC, bool ReferenceChannel, bool PHSP){
  660. string string_input = GetInputFile(year,magnet,true, MC, ReferenceChannel, PHSP, false);
  661. string backup_file = string_input;
  662. replace(backup_file,".root","_backup.root");
  663. if (MC) replace(backup_file,"_backup.root","_TMbackup.root");
  664. string command = "cp " + string_input + " " + backup_file;
  665. coutDebug(command);
  666. system(command.c_str());
  667. return 1;
  668. }
  669. bool create_allYears_backup(bool MC, bool ReferenceChannel, bool PHSP){
  670. for (auto &year :yearsVector(MC,ReferenceChannel,PHSP,12) ){
  671. create_backup(year,"down",MC,ReferenceChannel,PHSP);
  672. create_backup(year,"up",MC,ReferenceChannel,PHSP);
  673. }
  674. return 1;
  675. }
  676. bool create_allData_backup(){
  677. create_allYears_backup(false,false,false);
  678. return 1;
  679. }
  680. int create_allMCsig_backup(){
  681. create_allYears_backup(true,false,false);
  682. return 1;
  683. }
  684. int create_allMCref_backup(){
  685. create_allYears_backup(true,true,false);
  686. return 1;
  687. }
  688. int create_allPHSP_backup(){
  689. create_allYears_backup(true,false,true);
  690. return 1;
  691. }
  692. int create_allMC_backup(){
  693. create_allYears_backup(true,false,false);
  694. create_allYears_backup(true,true, false);
  695. create_allYears_backup(true,false,true);
  696. return 1;
  697. }
  698. //TODO:check this
  699. bool create_backup_MCsig(string year, string magnet){
  700. string string_input = GetInputFile(year,magnet,true,false,false,false,false);
  701. string command = "cp " + string_input + " ";
  702. replace(string_input,".root","_backup.root");
  703. command += string_input;
  704. coutDebug(command);
  705. system(command.c_str());
  706. return 1;
  707. }
  708. int create_backup_All_MCsig(){
  709. for (auto &year: yearsData(12)){
  710. create_backup_MCsig (year,"down");
  711. create_backup_MCsig (year,"up");
  712. }
  713. return 1;
  714. }
  715. #endif // PATHS_HPP