/ElectroWeakAnalysis/WENu/macros/PlotCombiner.cc

https://github.com/aivanov-cern/cmssw · C++ · 1161 lines · 855 code · 52 blank · 254 comment · 122 complexity · 60f55b9a6a6ce00a85788ee2418c21e2 MD5 · raw file

  1. /*
  2. Macro to make the plots .......................................
  3. Instructions:
  4. a. set up an input file that looks like the following:
  5. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  6. # zee or wenu
  7. wenu
  8. # file name, type (sig, qcd, bce, gje, ewk), weight
  9. histos_wenu.root sig 1.46
  10. histos_q20_30.root qcd 0
  11. histos_q30_80.root qcd 100.
  12. histos_q80_170.root qcd 0
  13. histos_b20_30.root bce 0
  14. histos_b30_80.root bce 0
  15. histos_b80_170.root bce 0
  16. histos_zee.root ewk 0
  17. histos_wtaunu.root ewk 0
  18. histos_ztautau.root ewk 0
  19. histos_gj15.root gje 0
  20. histos_gj20.root gje 0
  21. histos_gj25.root gje 10.12
  22. histos_gj30.root gje 0
  23. histos_gj35.root gje 0
  24. histos_wmunu.root ewk 0
  25. histos_ttbar.root ewk 0
  26. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  27. lines that start with # are considered to be comments
  28. line 2 has wenu or zee. From line 4 the list of the histo files are listed
  29. (first word) then a type that could be sig,qcd,bce, gj or ewk in order to
  30. discriminate among different sources of bkgs and finally the weight that we
  31. want to weight the histogram entries. This particular example is for Wenu. For
  32. Zee one has to put type sig in the zee file and ewk in the Wenu file. The order
  33. of the files is arbitrary. Files with weight 0 will be ignored.
  34. After you have set up this code you run a root macro to combine the plots.
  35. You can do (not recommended - it actually crushes - to be debugged)
  36. root -b PlotCombiner.cc
  37. or to compile it within root (recommended)
  38. root -b
  39. root [1] .L PlotCombiner.cc++
  40. root [2] PlotCombiner()
  41. and you finally get the plots.
  42. For the ABCD method:
  43. ^^^^^^^^^^^^^^^^^^^^
  44. you have to insert in the 2nd line instead of wenu or zee the keyword abcd(...)
  45. The files should contain ewk samples, sig samples and qcd samples (but also read
  46. later). The only absolutely necessary files are the sig ones.
  47. Example:
  48. abcd(I=0.95,dI=0.01,Fz=0.6,dFz=0.01,FzP=0.56, dFzP=0.2,ewkerror=0.1,METCut=30.,mc)
  49. These parameters keep the same notation as in the note. The last parameter (data)
  50. can take 3 values:
  51. data: calculate in ABCD as in data. This means that the histograms denoted with
  52. sig,qcd,bce,gje are used as of the same kind and ewk as the MC ewk.
  53. The background is substructed as in data
  54. mcOnly: here we ignore all the input parameters I, dI etc. All parameters are taken
  55. from MC by forcing Fqcd=1
  56. mc: <THIS IS WHAT ONE NORMALLY USES> input mc samples, calculation of statistical
  57. and systematics as in CMS AN 2009/004, systematic and statistic error
  58. calculation. This option also creates the plots of the variation of the
  59. signal prediction vs the parameter variation. In order to set the limits of
  60. the desired variation you have to edit the values in line 113 of this code
  61. (they are hardwired in the code)
  62. TO DO:
  63. functionalities to plot more kind of plots, e.g. efficiencies
  64. Further Questions/Contact:
  65. nikolaos.rompotis @ cern.ch
  66. Nikolaos Rompotis - 29 June 09
  67. 18 Sept 09: 1st updgrade: input files in a text file
  68. 28 May 10: bug in IMET corrected, thanks to Sadia Khalil
  69. Imperial College London
  70. */
  71. #include <iostream>
  72. #include <fstream>
  73. #include <vector>
  74. #include <string>
  75. #include "TString.h"
  76. #include "TROOT.h"
  77. #include "TStyle.h"
  78. #include "TH1F.h"
  79. #include "TFile.h"
  80. #include "TCanvas.h"
  81. #include "TGraph.h"
  82. #include "TLegend.h"
  83. void plotMaker(TString histoName, TString typeOfplot,
  84. vector<TString> file, vector<TString> type,
  85. vector<double> weight, TString xtitle);
  86. void abcd(vector<TString> file, vector<TString> type, vector<double> weight,
  87. double METCut, double I, double dI, double Fz, double dFz,
  88. double FzP, double dFzP, double ewkerror,
  89. double data, double mc, double mcOnly);
  90. double searchABCDstring(TString abcdString, TString keyword);
  91. double Trionym(double a, double b, double c, double sum);
  92. double CalcABCD
  93. (double I, double Fz, double FzP, double K, double ewk,
  94. double Na_, double Nb_, double Nc_, double Nd_,
  95. double Ea_, double Eb_, double Ec_, double Ed_);
  96. // values for systematics plots: it is fraction of the MC value
  97. const double EWK_SYST_MIN = 0.3;
  98. const double EWK_SYST_MAX = 0.3;
  99. //
  100. const double I_SYST_MIN = 0.05;
  101. const double I_SYST_MAX = 0.05;
  102. //
  103. const double FZ_SYST_MIN = 0.1;
  104. const double FZ_SYST_MAX = 0.1;
  105. //
  106. const double FZP_SYST_MIN = 0.1;
  107. const double FZP_SYST_MAX = 0.1;
  108. //
  109. const double K_SYST_MIN = 0.8;
  110. const double K_SYST_MAX = 0.8;
  111. using namespace std;
  112. void PlotCombiner()
  113. {
  114. // read the file
  115. ifstream input("inputFiles");
  116. int i = 0;
  117. TString typeOfplot = "";
  118. vector<TString> types;
  119. vector<TString> files;
  120. vector<double> weights;
  121. if (input.is_open()) {
  122. std::string myline;
  123. while (! input.eof()) {
  124. getline(input, myline);
  125. TString line(myline);
  126. TString c('#');
  127. TString empty(' ');
  128. if (line[0] != c) {
  129. ++i;
  130. if (i==1) typeOfplot=line;
  131. else {
  132. // read until you find 3 words
  133. TString fname("");
  134. TString ftype("");
  135. TString fw("");
  136. int lineSize = (int) line.Length();
  137. int j=0;
  138. while (j<lineSize) {
  139. if(line[j] != empty) fname += line[j];
  140. else break;
  141. ++j;
  142. }
  143. while (j<lineSize) {
  144. if(line[j] != empty) ftype += line[j];
  145. else if(ftype.Length()==3) break;
  146. ++j;
  147. }
  148. while (j<lineSize) {
  149. if(line[j] != empty) fw += line[j];
  150. else{ if(fw.Length()>0) break;}
  151. ++j;
  152. }
  153. if (fname.Length() == 0) break;
  154. files.push_back(fname);
  155. types.push_back(ftype);
  156. double w = fw.Atof();
  157. weights.push_back(w);
  158. if (w>0)
  159. std::cout << fname << ", " << ftype << ", "<< w << std::endl;
  160. }
  161. }
  162. }
  163. input.close();
  164. }
  165. else {
  166. std::cout << "File with name inputFile was not found" << std::endl;
  167. return;
  168. }
  169. // now you can launch the jobs
  170. if (typeOfplot == "wenu") {
  171. cout << "wenu plot maker" << endl;
  172. // ====================
  173. // =====> WHICH HISTOS TO PLOT
  174. // ====================
  175. plotMaker("h_met", typeOfplot, files, types, weights, "MET (GeV)");
  176. }
  177. else if (typeOfplot == "zee"){
  178. cout << "zee plot maker" << endl;
  179. // ====================
  180. // =====> WHICH HISTOS TO PLOT
  181. // ====================
  182. plotMaker("h_mee", typeOfplot, files, types, weights, "M_{ee} (GeV)");
  183. }
  184. else if (typeOfplot(0,4) == "abcd") {
  185. // now read the parameters of the ABCD method
  186. // look for parameter I and dI
  187. double I = searchABCDstring(typeOfplot, "I");
  188. double dI= searchABCDstring(typeOfplot, "dI");
  189. // look for parameter Fz
  190. double Fz = searchABCDstring(typeOfplot, "Fz");
  191. double dFz= searchABCDstring(typeOfplot, "dFz");
  192. // look for parameter FzP
  193. double FzP = searchABCDstring(typeOfplot, "FzP");
  194. double dFzP= searchABCDstring(typeOfplot, "dFzP");
  195. // look for the MET cut
  196. double METCut =searchABCDstring(typeOfplot, "METCut");
  197. // do you want data driven only?
  198. double data = searchABCDstring(typeOfplot, "data");
  199. double mc = searchABCDstring(typeOfplot, "mc");
  200. double mcOnly = searchABCDstring(typeOfplot, "mcOnly");
  201. // what is the ewk error?
  202. double ewkerror = searchABCDstring(typeOfplot, "ewkerror");
  203. // sanity check:
  204. if (METCut<0 || (data<-0.7 && mc<-0.7 && mcOnly<-0.7)) {
  205. cout << "Error in your configurtion!" << endl;
  206. if (METCut <0) cout << "Error in MET Cut" << endl;
  207. else cout << "You need to specify one mc or data or mcOnly"
  208. << endl;
  209. abort();
  210. }
  211. if (mc>-0.7 && mc <0 && ewkerror<0) {
  212. cout << "You have specified mc option, but you have forgotten"
  213. << " to set the ewkerror!" << endl;
  214. abort();
  215. }
  216. // ===============================
  217. // =====> ABCD METHOD FOR BKG SUBTRACTION
  218. // ===============================
  219. cout << "doing ABCD with input: " << typeOfplot << endl;
  220. abcd(files, types, weights, METCut, I, dI, Fz, dFz, FzP, dFzP,
  221. ewkerror, data, mc, mcOnly);
  222. }
  223. // force the program to abort in order to clear the memory
  224. // and avoid further use of the interpreter after
  225. abort();
  226. }
  227. void abcd( vector<TString> file, vector<TString> type, vector<double> weight,
  228. double METCut, double I, double dI, double Fz, double dFz,
  229. double FzP, double dFzP, double ewkerror,
  230. double data, double mc, double mcOnly)
  231. {
  232. gROOT->Reset();
  233. gROOT->ProcessLine(".L tdrstyle.C");
  234. gROOT->ProcessLine("setTDRStyle()");
  235. //
  236. std::cout << "Trying ABCD method for Background subtration" << std::endl;
  237. //
  238. // histogram names to use:
  239. TString histoName_Ba("h_met_EB");
  240. TString histoName_Bb("h_met_inverse_EB");
  241. TString histoName_Ea("h_met_EE");
  242. TString histoName_Eb("h_met_inverse_EE");
  243. //
  244. // find one file and get the dimensions of your histogram
  245. int fmax = (int) file.size();
  246. int NBins = 0; double min = 0; double max = -1;
  247. for (int i=0; i<fmax; ++i) {
  248. if (weight[i]>0) {
  249. // cout << "Loading file " << file[i] << endl;
  250. TFile f(file[i]);
  251. TH1F *h = (TH1F*) f.Get(histoName_Ba);
  252. NBins = h->GetNbinsX();
  253. min = h->GetBinLowEdge(1);
  254. max = h->GetBinLowEdge(NBins+1);
  255. break;
  256. }
  257. }
  258. if (NBins ==0 || (max<min)) {
  259. std::cout << "PlotCombiner::abcd error: Could not find valid histograms in file"
  260. << std::endl;
  261. abort();
  262. }
  263. cout << "Histograms with "<< NBins <<" bins and range " << min << "-" << max << endl;
  264. //
  265. // Wenu Signal .......................................................
  266. TH1F h_wenu("h_wenu", "h_wenu", NBins, min, max);
  267. TH1F h_wenu_inv("h_wenu_inv", "h_wenu_inv", NBins, min, max);
  268. for (int i=0; i<fmax; ++i) {
  269. if (type[i] == "sig" && weight[i]>0 ) {
  270. TFile f(file[i]);
  271. //
  272. TH1F *h_ba = (TH1F*) f.Get(histoName_Ba);
  273. h_wenu.Add(h_ba, weight[i]);
  274. TH1F *h_ea = (TH1F*) f.Get(histoName_Ea);
  275. h_wenu.Add(h_ea, weight[i]);
  276. //
  277. TH1F *h_bb = (TH1F*) f.Get(histoName_Bb);
  278. h_wenu_inv.Add(h_bb, weight[i]);
  279. TH1F *h_eb = (TH1F*) f.Get(histoName_Eb);
  280. h_wenu_inv.Add(h_eb, weight[i]);
  281. }
  282. }
  283. // QCD Bkgs
  284. TH1F h_qcd("h_qcd", "h_qcd", NBins, min, max);
  285. TH1F h_qcd_inv("h_qcd_inv", "h_qcd_inv", NBins, min, max);
  286. for (int i=0; i<fmax; ++i) {
  287. if ((type[i] == "qcd" || type[i] == "bce"
  288. || type[i] == "gje") && weight[i]>0) {
  289. TFile f(file[i]);
  290. //
  291. TH1F *h_ba = (TH1F*) f.Get(histoName_Ba);
  292. h_qcd.Add(h_ba, weight[i]);
  293. TH1F *h_ea = (TH1F*) f.Get(histoName_Ea);
  294. h_qcd.Add(h_ea, weight[i]);
  295. //
  296. TH1F *h_bb = (TH1F*) f.Get(histoName_Bb);
  297. h_qcd_inv.Add(h_bb, weight[i]);
  298. TH1F *h_eb = (TH1F*) f.Get(histoName_Eb);
  299. h_qcd_inv.Add(h_eb, weight[i]);
  300. }
  301. }
  302. //
  303. TH1F h_ewk("h_ewk", "h_ewk", NBins, min, max);
  304. TH1F h_ewk_inv("h_ewk_inv", "h_ewk_inv", NBins, min, max);
  305. for (int i=0; i<fmax; ++i) {
  306. if ( type[i] == "ewk" && weight[i]>0) {
  307. TFile f(file[i]);
  308. //
  309. TH1F *h_ba = (TH1F*) f.Get(histoName_Ba);
  310. h_ewk.Add(h_ba, weight[i]);
  311. TH1F *h_ea = (TH1F*) f.Get(histoName_Ea);
  312. h_ewk.Add(h_ea, weight[i]);
  313. //
  314. TH1F *h_bb = (TH1F*) f.Get(histoName_Bb);
  315. h_ewk_inv.Add(h_bb, weight[i]);
  316. TH1F *h_eb = (TH1F*) f.Get(histoName_Eb);
  317. h_ewk_inv.Add(h_eb, weight[i]);
  318. }
  319. }
  320. //
  321. // calculate the METCut position
  322. //
  323. // this is calculated as a low edge bin of your input histogram
  324. // METCut = min + (max-min)*IMET/NBins
  325. int IMET = int ((METCut - min)/(max-min) * double(NBins));
  326. // check whether it is indeed a low egde position
  327. double metCalc = min + (max-min)*double(IMET)/double(NBins);
  328. if (metCalc < METCut || metCalc > METCut) {
  329. std::cout << "PlotCombiner:abcd: your MET Cut is not in low egde bin position"
  330. << std::endl;
  331. }
  332. cout << "MET Cut in " << METCut << "GeV corresponds to bin #" << IMET << endl;
  333. // Calculate the population in the ABCD Regions now
  334. // signal
  335. double a_sig = h_wenu.Integral(IMET,NBins+1);
  336. double b_sig = h_wenu.Integral(0,IMET-1);
  337. double c_sig = h_wenu_inv.Integral(0,IMET-1);
  338. double d_sig = h_wenu_inv.Integral(IMET,NBins+1);
  339. // qcd
  340. double a_qcd = h_qcd.Integral(IMET,NBins+1);
  341. double b_qcd = h_qcd.Integral(0,IMET-1);
  342. double c_qcd = h_qcd_inv.Integral(0,IMET-1);
  343. double d_qcd = h_qcd_inv.Integral(IMET,NBins+1);
  344. // ewk
  345. double a_ewk = h_ewk.Integral(IMET,NBins+1);
  346. double b_ewk = h_ewk.Integral(0,IMET-1);
  347. double c_ewk = h_ewk_inv.Integral(0,IMET-1);
  348. double d_ewk = h_ewk_inv.Integral(IMET,NBins+1);
  349. ////////////////////////////////////////////////
  350. //
  351. // now the parameters of the method
  352. if (data < 0 && data >-0.75) { // select value -0.5 that gives the
  353. // string parser
  354. // now everything is done from data + input
  355. std::cout << "Calculating ABCD Result and Stat Error Assuming DATA"
  356. << std::endl << "Summary: in this implementation we have assumed"
  357. << " that what real 'data' appear with type sig in the input"
  358. << std::endl << "No systematics available with this type of"
  359. << " calculation. If you need systematics try one of the other"
  360. << " options" << std::endl;
  361. double A = (1.0-I)*(FzP-Fz);
  362. double B = I*(FzP+1.0)*(FzP*(c_sig-c_ewk)-(d_sig-d_ewk)) +
  363. (1+Fz)*(1-I)*((a_sig-a_ewk)-dFzP*(b_sig-b_ewk));
  364. double C = I*(1.+Fz)*(1.+FzP)*((d_sig-d_ewk)*(b_sig-b_ewk) - (a_sig-a_ewk)*(c_sig-c_ewk));
  365. //
  366. // signal calculation:
  367. double S = Trionym(A,B,C, a_sig+b_sig);
  368. // the errors now:
  369. // calculate the statistical error now:
  370. double ApI=0, ApFz=0, ApFzP=0, ApNa=0, ApNb=0, ApNc=0, ApNd=0;
  371. double BpI=0, BpFz=0, BpFzP=0, BpNa=0, BpNb=0, BpNc=0, BpNd=0;
  372. double CpI=0, CpFz=0, CpFzP=0, CpNa=0, CpNb=0, CpNc=0, CpNd=0;
  373. double SpI=0, SpFz=0, SpFzP=0, SpNa=0, SpNb=0, SpNc=0, SpNd=0;
  374. //
  375. double Na = a_sig, Nb = b_sig, Nc=c_sig, Nd = d_sig;
  376. double Ea = a_ewk, Eb = b_ewk, Ec=c_ewk, Ed = d_ewk;
  377. if (A != 0) {
  378. ApI = -(FzP-Fz);
  379. ApFz = -(1.0-I);
  380. ApFzP = (1.0-I);
  381. ApNa = 0.0;
  382. ApNb = 0.0;
  383. ApNc = 0.0;
  384. ApNd = 0.0;
  385. BpI = (FzP+1.0)*(Fz*(Nc-Ec)-(Nd-Ed))-(1.0+Fz)*((Na-Ea)-FzP*(Nb-Eb));
  386. BpFz = I*(FzP+1.0)*(Nc-Ec)+(1.0-I)*((Na-Ea)-FzP*(Nb-Eb));
  387. BpFzP = I*(Fz*(Nc-Ec)-(Nd-Ed))-(1.0-I)*(1.0+Fz)*(Nb-Eb);
  388. BpNa = (1.0-I)*(1.0+Fz);
  389. BpNb = -(1.0-I)*(1.0+Fz)*FzP;
  390. BpNc = I*(FzP+1.0)*Fz;
  391. BpNd = -I*(FzP+1.0);
  392. CpI = (1.0+Fz)*(1.0+FzP)*((Nd-Ed)*(Nb-Eb)-(Na-Ea)*(Nc-Ec));
  393. CpFz = I*(1.0+FzP)*((Nd-Ed)*(Nb-Eb)-(Na-Ea)*(Nc-Ec));
  394. CpFzP = I*(1.0+Fz)*((Nd-Ed)*(Nb-Eb)-(Na-Ea)*(Nc-Ec));
  395. CpNa = -I*(1.0+Fz)*(1.0+FzP)*(Nc-Ec);
  396. CpNb = I*(1.0+Fz)*(1.0+FzP)*(Nd-Ed);
  397. CpNc = -I*(1.0+Fz)*(1.0+FzP)*(Na-Ea);
  398. CpNd = I*(1.0+Fz)*(1.0+FzP)*(Nb-Eb);
  399. SpI = (-BpI + (B*BpI -2.0*ApI*C -2.0*A*CpI) /fabs(2.0*A*S+B)- 2.0*ApI*S) /(2.0*A);
  400. SpFz = (-BpFz + (B*BpFz -2.0*ApFz*C -2.0*A*CpFz) /fabs(2.0*A*S+B)- 2.0*ApFz*S) /(2.0*A);
  401. SpFzP = (-BpFzP + (B*BpFzP -2.0*ApFzP*C -2.0*A*CpFzP)/fabs(2.0*A*S+B)- 2.0*ApFzP*S)/(2.0*A);
  402. SpNa = (-BpNa + (B*BpNa -2.0*ApNa*C -2.0*A*CpNa) /fabs(2.0*A*S+B)- 2.0*ApNa*S) /(2.0*A);
  403. SpNb = (-BpNb + (B*BpNb -2.0*ApNb*C -2.0*A*CpNb) /fabs(2.0*A*S+B)- 2.0*ApNb*S) /(2.0*A);
  404. SpNc = (-BpNc + (B*BpNc -2.0*ApNc*C -2.0*A*CpNc) /fabs(2.0*A*S+B)- 2.0*ApNc*S) /(2.0*A);
  405. SpNd = (-BpNd + (B*BpNd -2.0*ApNd*C -2.0*A*CpNd) /fabs(2.0*A*S+B)- 2.0*ApNd*S) /(2.0*A);
  406. }
  407. else {
  408. BpI = (FzP+1.0)*(Fz*(Nc-Ec)-(Nd-Ed))-(1.0+Fz)*((Na-Ea)-FzP*(Nb-Eb));
  409. BpFz = I*(FzP+1.0)*(Nc-Ec)+(1.0-I)*((Na-Ea)-FzP*(Nb-Eb));
  410. BpFzP = I*(Fz*(Nc-Ec)-(Nd-Ed))-(1.0-I)*(1.0+Fz)*(Nb-Eb);
  411. BpNa = (1.0-I)*(1.0+Fz);
  412. BpNb = -(1.0-I)*(1.0+Fz)*FzP;
  413. BpNc = I*(FzP+1.0)*Fz;
  414. BpNd = -I*(FzP+1.0);
  415. CpI = (1.0+Fz)*(1.0+FzP)*((Nd-Ed)*(Nb-Eb)-(Na-Ea)*(Nc-Ec));
  416. CpFz = I*(1.0+FzP)*((Nd-Ed)*(Nb-Eb)-(Na-Ea)*(Nc-Ec));
  417. CpFzP = I*(1.0+Fz)*((Nd-Ed)*(Nb-Eb)-(Na-Ea)*(Nc-Ec));
  418. CpNa = -I*(1.0+Fz)*(1.0+FzP)*(Nc-Ec);
  419. CpNb = I*(1.0+Fz)*(1.0+FzP)*(Nd-Ed);
  420. CpNc = -I*(1.0+Fz)*(1.0+FzP)*(Na-Ea);
  421. CpNd = I*(1.0+Fz)*(1.0+FzP)*(Nb-Eb);
  422. SpI = -CpI/B+C*BpI/(B*B);
  423. SpFz = -CpFz/B+C*BpFz/(B*B);
  424. SpFzP = -CpFzP/B+C*BpFzP/(B*B);
  425. SpNa = -CpNa/B+C*BpNa/(B*B);
  426. SpNb = -CpNb/B+C*BpNb/(B*B);
  427. SpNc = -CpNc/B+C*BpNc/(B*B);
  428. SpNd = -CpNd/B+C*BpNd/(B*B);
  429. }
  430. double DS;
  431. DS = sqrt( SpI*dI*SpI*dI + SpFz*dFz*SpFz*dFz + SpFzP*dFzP*SpFzP*dFzP +
  432. SpNa*SpNa*Na + SpNb*SpNb*Nb + SpNc*SpNc*Nc + SpNd*SpNd*Nd );
  433. // warning: S here denotes the method prediction ..........
  434. cout << "********************************************************" << endl;
  435. cout << "Signal Prediction: " << S << "+-" << DS << "(stat)" << endl;
  436. cout << "********************************************************" << endl;
  437. cout << "Parameters used in calculation: " << endl;
  438. cout << "I= " << I << "+-" << dI << endl;
  439. cout << "Fz= " << Fz << "+-" << dFz << endl;
  440. cout << "FzP=" << FzP << "+-" << dFzP << endl;
  441. cout << endl;
  442. cout << "ABCD Regions population:" << endl;
  443. cout << "A: N=" << Na << ", sig=" << a_sig << ", qcd=" << a_qcd
  444. << ", ewk=" << a_ewk << endl;
  445. cout << "B: N=" << Nb << ", sig=" << b_sig << ", qcd=" << b_qcd
  446. << ", ewk=" << b_ewk << endl;
  447. cout << "C: N=" << Nc << ", sig=" << c_sig << ", qcd=" << c_qcd
  448. << ", ewk=" << c_ewk << endl;
  449. cout << "D: N=" << Nd << ", sig=" << d_sig << ", qcd=" << d_qcd
  450. << ", ewk=" << d_ewk << endl;
  451. cout << endl;
  452. //
  453. cout << "Statistical Error Summary: " << endl;
  454. cout << "due to Fz = "<< SpFz*dFz<< ", ("<<SpFz*dFz*100./S << "%)"<< endl;
  455. cout << "due to FzP= "<< SpFzP*dFzP
  456. << ", ("<<SpFzP*dFzP*100./S << "%)"<< endl;
  457. cout << "due to I = "<< SpI*dI
  458. << ", ("<<SpI*dI*100./S << "%)"<< endl;
  459. cout << "due to Na = "<< SpNa*sqrt(Na)
  460. << ", ("<< SpNa*sqrt(Na)*100./S << "%)"<< endl;
  461. cout << "due to Nb = "<< SpNb*sqrt(Nb)
  462. << ", ("<< SpNb*sqrt(Nb)*100./S << "%)"<< endl;
  463. cout << "due to Nc = "<< SpNc*sqrt(Nc)
  464. << ", ("<< SpNc*sqrt(Nc)*100./S << "%)"<< endl;
  465. cout << "due to Nd = "<< SpNd*sqrt(Nd)
  466. << ", ("<< SpNd*sqrt(Nd)*100./S << "%)"<< endl;
  467. cout << "Total Statistical Error: "
  468. << DS << ", (" << DS*100./S << "%)"<< endl;
  469. cout << "Stat Error percentages are wrt S prediction, not S mc" << endl;
  470. }
  471. //
  472. //
  473. // this is the main option of the algorithm: the one implemented in the
  474. // Analysis Note
  475. //
  476. if (mc < 0 && mc >-0.75) { // select value -0.5 that gives the
  477. // string parser
  478. //////// STATISTICAL ERROR CALCULATION /////////////////////////////
  479. double A = (1.0-I)*(FzP-Fz);
  480. double B = I*(FzP+1.0)*(FzP*(c_sig+c_qcd)-(d_sig+d_qcd)) +
  481. (1+Fz)*(1-I)*((a_sig+a_qcd)-dFzP*(b_sig+b_qcd));
  482. double C = I*(1.+Fz)*(1.+FzP)*((d_sig+d_qcd)*(b_sig+b_qcd) -
  483. (a_sig+a_qcd)*(c_sig+c_qcd));
  484. //
  485. // signal calculation:
  486. double S = Trionym(A,B,C, a_sig+b_sig);
  487. //
  488. double ApI=0, ApFz=0, ApFzP=0, ApNa=0, ApNb=0, ApNc=0, ApNd=0;
  489. double BpI=0, BpFz=0, BpFzP=0, BpNa=0, BpNb=0, BpNc=0, BpNd=0;
  490. double CpI=0, CpFz=0, CpFzP=0, CpNa=0, CpNb=0, CpNc=0, CpNd=0;
  491. double SpI=0, SpFz=0, SpFzP=0, SpNa=0, SpNb=0, SpNc=0, SpNd=0;
  492. //
  493. double Na = a_sig+a_qcd+a_ewk, Nb = b_sig+b_qcd+b_ewk;
  494. double Nc=c_sig+c_qcd+c_ewk, Nd = d_sig+d_qcd+d_ewk;
  495. double Ea = a_ewk, Eb = b_ewk, Ec=c_ewk, Ed = d_ewk;
  496. if (A != 0) {
  497. ApI = -(FzP-Fz);
  498. ApFz = -(1.0-I);
  499. ApFzP = (1.0-I);
  500. ApNa = 0.0;
  501. ApNb = 0.0;
  502. ApNc = 0.0;
  503. ApNd = 0.0;
  504. BpI = (FzP+1.0)*(Fz*(Nc-Ec)-(Nd-Ed))-(1.0+Fz)*((Na-Ea)-FzP*(Nb-Eb));
  505. BpFz = I*(FzP+1.0)*(Nc-Ec)+(1.0-I)*((Na-Ea)-FzP*(Nb-Eb));
  506. BpFzP = I*(Fz*(Nc-Ec)-(Nd-Ed))-(1.0-I)*(1.0+Fz)*(Nb-Eb);
  507. BpNa = (1.0-I)*(1.0+Fz);
  508. BpNb = -(1.0-I)*(1.0+Fz)*FzP;
  509. BpNc = I*(FzP+1.0)*Fz;
  510. BpNd = -I*(FzP+1.0);
  511. CpI = (1.0+Fz)*(1.0+FzP)*((Nd-Ed)*(Nb-Eb)-(Na-Ea)*(Nc-Ec));
  512. CpFz = I*(1.0+FzP)*((Nd-Ed)*(Nb-Eb)-(Na-Ea)*(Nc-Ec));
  513. CpFzP = I*(1.0+Fz)*((Nd-Ed)*(Nb-Eb)-(Na-Ea)*(Nc-Ec));
  514. CpNa = -I*(1.0+Fz)*(1.0+FzP)*(Nc-Ec);
  515. CpNb = I*(1.0+Fz)*(1.0+FzP)*(Nd-Ed);
  516. CpNc = -I*(1.0+Fz)*(1.0+FzP)*(Na-Ea);
  517. CpNd = I*(1.0+Fz)*(1.0+FzP)*(Nb-Eb);
  518. SpI = (-BpI + (B*BpI -2.0*ApI*C -2.0*A*CpI) /fabs(2.0*A*S+B)- 2.0*ApI*S) /(2.0*A);
  519. SpFz = (-BpFz + (B*BpFz -2.0*ApFz*C -2.0*A*CpFz) /fabs(2.0*A*S+B)- 2.0*ApFz*S) /(2.0*A);
  520. SpFzP = (-BpFzP + (B*BpFzP -2.0*ApFzP*C -2.0*A*CpFzP)/fabs(2.0*A*S+B)- 2.0*ApFzP*S)/(2.0*A);
  521. SpNa = (-BpNa + (B*BpNa -2.0*ApNa*C -2.0*A*CpNa) /fabs(2.0*A*S+B)- 2.0*ApNa*S) /(2.0*A);
  522. SpNb = (-BpNb + (B*BpNb -2.0*ApNb*C -2.0*A*CpNb) /fabs(2.0*A*S+B)- 2.0*ApNb*S) /(2.0*A);
  523. SpNc = (-BpNc + (B*BpNc -2.0*ApNc*C -2.0*A*CpNc) /fabs(2.0*A*S+B)- 2.0*ApNc*S) /(2.0*A);
  524. SpNd = (-BpNd + (B*BpNd -2.0*ApNd*C -2.0*A*CpNd) /fabs(2.0*A*S+B)- 2.0*ApNd*S) /(2.0*A);
  525. }
  526. else {
  527. BpI = (FzP+1.0)*(Fz*(Nc-Ec)-(Nd-Ed))-(1.0+Fz)*((Na-Ea)-FzP*(Nb-Eb));
  528. BpFz = I*(FzP+1.0)*(Nc-Ec)+(1.0-I)*((Na-Ea)-FzP*(Nb-Eb));
  529. BpFzP = I*(Fz*(Nc-Ec)-(Nd-Ed))-(1.0-I)*(1.0+Fz)*(Nb-Eb);
  530. BpNa = (1.0-I)*(1.0+Fz);
  531. BpNb = -(1.0-I)*(1.0+Fz)*FzP;
  532. BpNc = I*(FzP+1.0)*Fz;
  533. BpNd = -I*(FzP+1.0);
  534. CpI = (1.0+Fz)*(1.0+FzP)*((Nd-Ed)*(Nb-Eb)-(Na-Ea)*(Nc-Ec));
  535. CpFz = I*(1.0+FzP)*((Nd-Ed)*(Nb-Eb)-(Na-Ea)*(Nc-Ec));
  536. CpFzP = I*(1.0+Fz)*((Nd-Ed)*(Nb-Eb)-(Na-Ea)*(Nc-Ec));
  537. CpNa = -I*(1.0+Fz)*(1.0+FzP)*(Nc-Ec);
  538. CpNb = I*(1.0+Fz)*(1.0+FzP)*(Nd-Ed);
  539. CpNc = -I*(1.0+Fz)*(1.0+FzP)*(Na-Ea);
  540. CpNd = I*(1.0+Fz)*(1.0+FzP)*(Nb-Eb);
  541. SpI = -CpI/B+C*BpI/(B*B);
  542. SpFz = -CpFz/B+C*BpFz/(B*B);
  543. SpFzP = -CpFzP/B+C*BpFzP/(B*B);
  544. SpNa = -CpNa/B+C*BpNa/(B*B);
  545. SpNb = -CpNb/B+C*BpNb/(B*B);
  546. SpNc = -CpNc/B+C*BpNc/(B*B);
  547. SpNd = -CpNd/B+C*BpNd/(B*B);
  548. }
  549. double DS;
  550. DS = sqrt( SpI*dI*SpI*dI + SpFz*dFz*SpFz*dFz + SpFzP*dFzP*SpFzP*dFzP +
  551. SpNa*SpNa*Na + SpNb*SpNb*Nb + SpNc*SpNc*Nc + SpNd*SpNd*Nd );
  552. ////////////////////////////////////////////////////////////////////////
  553. // SYSTEMATICS CALCULATION /////////////////////////////////////////////
  554. ////////////////////////////////////////////////////////////////////////
  555. // recalculate the basic quantities
  556. double Imc = (a_sig + b_sig) / (a_sig + b_sig + c_sig + d_sig);
  557. double dImc = sqrt(Imc*(1-Imc)/(a_sig + b_sig + c_sig + d_sig));
  558. double Fzmc = a_sig/b_sig;
  559. double e =a_sig/(a_sig + b_sig);
  560. double de = sqrt(e*(1-e)/(a_sig + b_sig));
  561. double alpha = de/(2.*Fzmc-e);
  562. double dFzmc = alpha/(1-alpha);
  563. double FzPmc = d_sig/c_sig;
  564. double ep =d_sig/(c_sig + d_sig);
  565. double dep = sqrt(ep*(1-ep)/(c_sig + d_sig));
  566. double alphap = dep/(2.*FzPmc-ep);
  567. double dFzPmc = alphap/(1-alphap);
  568. //
  569. // calculate the K parameter as it is in MC:
  570. double KMC = (d_qcd/c_qcd)/(a_qcd/b_qcd);
  571. double SMC = a_sig + b_sig;
  572. //
  573. double dfz = Fz -Fzmc;
  574. double di = I - Imc;
  575. double dfzp = FzP - FzPmc;
  576. double fk = fabs(1-KMC);
  577. ////////////////////////////////////////////////////////////////////////
  578. // ewk error: this error has to be inserted by hand
  579. double fm = 1.-ewkerror;
  580. double fp = 1.+ewkerror;
  581. double S_EWK_PLUS = CalcABCD(Imc, Fzmc, FzPmc, KMC, fp, Na, Nb, Nc, Nd, Ea,Eb,Ec,Ed);
  582. double S_EWK_MINUS = CalcABCD(Imc, Fzmc, FzPmc, KMC, fm, Na, Nb, Nc, Nd, Ea,Eb,Ec,Ed);
  583. // error in K
  584. double S_K= CalcABCD(Imc, Fzmc, FzPmc, 1., 1., Na, Nb, Nc, Nd, Ea,Eb,Ec,Ed);
  585. // error in Fz
  586. double S_FZ= CalcABCD(Imc, Fz, FzPmc, KMC, 1., Na, Nb, Nc, Nd, Ea,Eb,Ec,Ed);
  587. // error in FzP
  588. double S_FZP= CalcABCD(Imc, Fzmc, FzP, KMC, 1., Na, Nb, Nc, Nd, Ea,Eb,Ec,Ed);
  589. // error in I
  590. double S_I = CalcABCD(I, Fzmc, FzPmc, KMC, 1., Na, Nb, Nc, Nd, Ea,Eb,Ec,Ed);
  591. //
  592. // sanity tets
  593. //cout << "Smc=" << SMC<< ", " << CalcABCD(Imc, Fzmc, FzPmc, KMC, 1., Na, Nb, Nc, Nd, Ea,Eb,Ec,Ed)
  594. // << endl;
  595. //abort();
  596. //
  597. // ************ plots for the systematics calculation ****************
  598. // ewk plot
  599. int const POINTS = 10;
  600. int const allPOINTS = 2*POINTS;
  601. TGraph g_ewk(allPOINTS);
  602. TGraph g_fz(allPOINTS);
  603. TGraph g_fzp(allPOINTS);
  604. TGraph g_k(allPOINTS);
  605. TGraph g_i(allPOINTS);
  606. //
  607. double ewk_syst_min = EWK_SYST_MIN; // because this is just fraction
  608. double i_syst_min = Imc*(1.-I_SYST_MIN);
  609. double fz_syst_min = Fzmc*(1.-FZ_SYST_MIN);
  610. double fzp_syst_min = FzPmc*(1.-FZP_SYST_MIN);
  611. double k_syst_min = KMC*(1.-K_SYST_MIN);
  612. //
  613. double ewk_syst_max = EWK_SYST_MAX; // because this is just fraction
  614. double i_syst_max = Imc*I_SYST_MAX;
  615. double fz_syst_max = Fzmc*FZ_SYST_MAX;
  616. double fzp_syst_max = FzPmc*FZP_SYST_MAX;
  617. double k_syst_max = KMC*K_SYST_MAX;
  618. //
  619. // negative points
  620. for (int i=0; i<POINTS; ++i) {
  621. double x_ewk = 1.-ewk_syst_min + (ewk_syst_min)*i/POINTS;
  622. double x_fz = fz_syst_min + (Fzmc-fz_syst_min)*i/POINTS;
  623. double x_fzp = fzp_syst_min + (FzPmc-fzp_syst_min)*i/POINTS;
  624. double x_k = k_syst_min + (KMC-k_syst_min)*i/POINTS;
  625. double x_i = i_syst_min + (Imc-i_syst_min)*i/POINTS;
  626. //
  627. double y_ewk= CalcABCD(Imc, Fzmc, FzPmc, KMC, x_ewk, Na, Nb, Nc, Nd, Ea,Eb,Ec,Ed);
  628. double y_fz = CalcABCD(Imc, x_fz, FzPmc, KMC, 1., Na, Nb, Nc, Nd, Ea,Eb,Ec,Ed);
  629. double y_fzp= CalcABCD(Imc, Fzmc, x_fzp, KMC, 1., Na, Nb, Nc, Nd, Ea,Eb,Ec,Ed);
  630. double y_k = CalcABCD(Imc, Fzmc, FzPmc, x_k, 1., Na, Nb, Nc, Nd, Ea,Eb,Ec,Ed);
  631. double y_i = CalcABCD(x_i, Fzmc, FzPmc, KMC, 1., Na, Nb, Nc, Nd, Ea,Eb,Ec,Ed);
  632. //
  633. g_ewk.SetPoint(i,(x_ewk-1.)*100., 100.*fabs(y_ewk-SMC)/SMC);
  634. g_fz.SetPoint(i,(x_fz-Fzmc)*100./Fzmc, 100.*fabs(y_fz-SMC)/SMC);
  635. g_fzp.SetPoint(i,(x_fzp-FzPmc)*100./FzPmc, 100.*fabs(y_fzp-SMC)/SMC);
  636. g_i.SetPoint(i,(x_i-Imc)*100./Imc, 100.*fabs(y_i-SMC)/SMC);
  637. g_k.SetPoint(i,(x_k-KMC)*100./KMC, 100.*fabs(y_k-SMC)/SMC);
  638. }
  639. //
  640. // positive points
  641. for (int i=0; i<=POINTS; ++i) {
  642. double x_ewk = 1.+ewk_syst_max*i/POINTS;
  643. double x_fz = Fzmc+fz_syst_max*i/POINTS;
  644. double x_fzp = FzPmc+fzp_syst_max*i/POINTS;
  645. double x_k = KMC+k_syst_max*i/POINTS;
  646. double x_i = Imc+i_syst_max*i/POINTS;
  647. //
  648. double y_ewk= CalcABCD(Imc, Fzmc, FzPmc, KMC, x_ewk, Na, Nb, Nc, Nd, Ea,Eb,Ec,Ed);
  649. double y_fz = CalcABCD(Imc, x_fz, FzPmc, KMC, 1., Na, Nb, Nc, Nd, Ea,Eb,Ec,Ed);
  650. double y_fzp= CalcABCD(Imc, Fzmc, x_fzp, KMC, 1., Na, Nb, Nc, Nd, Ea,Eb,Ec,Ed);
  651. double y_k = CalcABCD(Imc, Fzmc, FzPmc, x_k, 1., Na, Nb, Nc, Nd, Ea,Eb,Ec,Ed);
  652. double y_i = CalcABCD(x_i, Fzmc, FzPmc, KMC, 1., Na, Nb, Nc, Nd, Ea,Eb,Ec,Ed);
  653. //
  654. g_ewk.SetPoint(i+POINTS,(x_ewk-1.)*100., 100.*fabs(y_ewk-SMC)/SMC);
  655. g_fz.SetPoint(i+POINTS,(x_fz-Fzmc)*100./Fzmc, 100.*fabs(y_fz-SMC)/SMC);
  656. g_fzp.SetPoint(i+POINTS,(x_fzp-FzPmc)*100./FzPmc, 100.*fabs(y_fzp-SMC)/SMC);
  657. g_i.SetPoint(i+POINTS,(x_i-Imc)*100./Imc, 100.*fabs(y_i-SMC)/SMC);
  658. g_k.SetPoint(i+POINTS,(x_k-KMC)*100./KMC, 100.*fabs(y_k-SMC)/SMC);
  659. }
  660. TString yaxis("(S-S_{mc})/S_{mc} (%)");
  661. TCanvas c;
  662. g_ewk.SetLineWidth(2);
  663. g_ewk.GetXaxis()->SetTitle("EWK Variation (%)");
  664. g_ewk.GetYaxis()->SetTitle(yaxis);
  665. g_ewk.Draw("AL");
  666. c.Print("ewk_syst_variation.C");
  667. //
  668. g_fz.SetLineWidth(2);
  669. g_fz.GetXaxis()->SetTitle("F_{z} Variation (%)");
  670. g_fz.GetYaxis()->SetTitle(yaxis);
  671. g_fz.Draw("AL");
  672. c.Print("fz_syst_variation.C");
  673. //
  674. g_fzp.SetLineWidth(2);
  675. g_fzp.GetXaxis()->SetTitle("F_{z}' Variation (%)");
  676. g_fzp.GetYaxis()->SetTitle(yaxis);
  677. g_fzp.Draw("AL");
  678. c.Print("fzp_syst_variation.C");
  679. //
  680. g_i.SetLineWidth(2);
  681. g_i.GetXaxis()->SetTitle("I Variation (%)");
  682. g_i.GetYaxis()->SetTitle(yaxis);
  683. g_i.Draw("AL");
  684. c.Print("i_syst_variation.C");
  685. //
  686. g_k.SetLineWidth(2);
  687. g_k.GetXaxis()->SetTitle("K Variation (%)");
  688. g_k.GetYaxis()->SetTitle(yaxis);
  689. g_k.Draw("AL");
  690. c.Print("k_syst_variation.C");
  691. //
  692. // ******************************************************************
  693. //
  694. //
  695. //
  696. double err_ewk = std::max(fabs(SMC-S_EWK_PLUS),fabs(SMC-S_EWK_MINUS));
  697. double err_fz = fabs(SMC-S_FZ);
  698. double err_fzp = fabs(SMC-S_FZP);
  699. double err_i = fabs(SMC-S_I);
  700. double err_k = fabs(SMC-S_K);
  701. //
  702. double DS_syst = sqrt(err_ewk*err_ewk + err_fz*err_fz + err_fzp*err_fzp+
  703. err_i*err_i + err_k*err_k);
  704. //
  705. cout << "********************************************************" << endl;
  706. cout << "Signal Prediction: " << S << "+-" << DS << "(stat) +-"
  707. << DS_syst << "(syst)" << endl;
  708. cout << "stat error: " << 100.*DS/S <<"%" << endl;
  709. cout << "syt error: " << 100.*DS_syst/S<< "%" << endl;
  710. cout << "********************************************************" << endl;
  711. cout << "Parameters used in calculation: " << endl;
  712. cout << "I= " << I << "+-" << dI << endl;
  713. cout << "Fz= " << Fz << "+-" << dFz << endl;
  714. cout << "FzP=" << FzP << "+-" << dFzP << endl;
  715. cout << "EWK error assumed to be: " << ewkerror << endl;
  716. cout << endl;
  717. cout << "ABCD Regions population:" << endl;
  718. cout << "A: N=" << Na << ", sig=" << a_sig << ", qcd=" << a_qcd
  719. << ", ewk=" << a_ewk << endl;
  720. cout << "B: N=" << Nb << ", sig=" << b_sig << ", qcd=" << b_qcd
  721. << ", ewk=" << b_ewk << endl;
  722. cout << "C: N=" << Nc << ", sig=" << c_sig << ", qcd=" << c_qcd
  723. << ", ewk=" << c_ewk << endl;
  724. cout << "D: N=" << Nd << ", sig=" << d_sig << ", qcd=" << d_qcd
  725. << ", ewk=" << d_ewk << endl;
  726. cout << endl;
  727. cout << "Parameters from MC: " << endl;
  728. cout << "I= " << Imc << "+-" << dImc << endl;
  729. cout << "Fz= " << Fzmc << "+-" << dFzmc << endl;
  730. cout << "FzP=" << FzPmc << "+-" << dFzPmc << endl;
  731. cout << endl;
  732. cout << "Real value of K=" << KMC << endl;
  733. cout << "Real value of Signal=" << SMC << endl;
  734. cout << endl;
  735. cout << "Difference Measured - MC value (% wrt MC value except K=1): "
  736. << endl;
  737. cout << "Fz : " << dfz << ", (" << dfz*100./Fzmc << "%)" << endl;
  738. cout << "FzP: " << dfzp << ", (" << dfzp*100./FzPmc << "%)" << endl;
  739. cout << "I : " << di << ", (" << di*100./Imc << "%)" << endl;
  740. cout << "K : " << fk << ", (" << fk*100./1. << "%)" << endl;
  741. cout << endl;
  742. //
  743. cout << "DETAILS OF THE CALCULATION" << endl;
  744. cout << "^^^^^^^^^^^^^^^^^^^^^^^^^^" << endl;
  745. cout << "Statistical Error Summary: " << endl;
  746. cout << "due to Fz = "<< SpFz*dFz<< ", ("<<SpFz*dFz*100./S << "%)"<< endl;
  747. cout << "due to FzP= "<< SpFzP*dFzP
  748. << ", ("<<SpFzP*dFzP*100./S << "%)"<< endl;
  749. cout << "due to I = "<< SpI*dI
  750. << ", ("<<SpI*dI*100./S << "%)"<< endl;
  751. cout << "due to Na = "<< SpNa*sqrt(Na)
  752. << ", ("<< SpNa*sqrt(Na)*100./S << "%)"<< endl;
  753. cout << "due to Nb = "<< SpNb*sqrt(Nb)
  754. << ", ("<< SpNb*sqrt(Nb)*100./S << "%)"<< endl;
  755. cout << "due to Nc = "<< SpNc*sqrt(Nc)
  756. << ", ("<< SpNc*sqrt(Nc)*100./S << "%)"<< endl;
  757. cout << "due to Nd = "<< SpNd*sqrt(Nd)
  758. << ", ("<< SpNd*sqrt(Nd)*100./S << "%)"<< endl;
  759. cout << "Total Statistical Error: "
  760. << DS << ", (" << DS*100./S << "%)"<< endl;
  761. cout << "Stat Error percentages are wrt S prediction, not S mc" << endl;
  762. cout << endl;
  763. cout << "Systematic Error Summary:" << endl;
  764. cout << "due to k = " << err_k << " ( " << err_k*100./S << "%)" << endl;
  765. cout << "due to Fz = " << err_fz << " ( " << err_fz*100./S << "%)" << endl;
  766. cout << "due to FzP = " << err_fzp << " ( " << err_fzp*100./S << "%)" << endl;
  767. cout << "due to I = " << err_i << " ( " << err_i*100./S << "%)" << endl;
  768. cout << "due to EWK = " << err_ewk << " ( " << err_ewk*100./S << "%)" << endl;
  769. cout << "Syst Error percentages are wrt S prediction, not S mc" << endl;
  770. }
  771. //
  772. //
  773. if (mcOnly < 0 && mcOnly >-0.75) { // select value -0.5 that gives the
  774. // string parser
  775. cout << "=======================================================" << endl;
  776. cout << "Calculating ABCD Result and Stat Error Assuming MC ONLY" << endl;
  777. cout << "=======================================================" << endl;
  778. cout << "All input parameters that the user have inserted will be "
  779. << "ignored and recalculated from MC" << endl;
  780. cout << "This option will not give you systematics estimation" << endl;
  781. // recalculate the basic quantities
  782. I = (a_sig + b_sig) / (a_sig + b_sig + c_sig + d_sig);
  783. dI = sqrt(I*(1-I)/(a_sig + b_sig + c_sig + d_sig));
  784. Fz = a_sig/b_sig;
  785. double e =a_sig/(a_sig + b_sig);
  786. double de = sqrt(e*(1-e)/(a_sig + b_sig));
  787. double alpha = de/(2.*Fz-e);
  788. dFz = alpha/(1-alpha);
  789. FzP = d_sig/c_sig;
  790. double ep =d_sig/(c_sig + d_sig);
  791. double dep = sqrt(ep*(1-ep)/(c_sig + d_sig));
  792. double alphap = dep/(2.*FzP-ep);
  793. dFzP = alphap/(1-alphap);
  794. //
  795. double KMC = (d_qcd/c_qcd)/(a_qcd/b_qcd);
  796. //
  797. // now everything is done from data + input
  798. double A = (1.0-I)*(FzP-Fz);
  799. double B = I*(FzP+1.0)*(FzP*(c_sig+c_qcd)-(d_sig+d_qcd)) +
  800. (1+Fz)*(1-I)*((a_sig+a_qcd)-dFzP*(b_sig+b_qcd));
  801. double C = I*(1.+Fz)*(1.+FzP)*((d_sig+d_qcd)*(b_sig+b_qcd) -
  802. (a_sig+a_qcd)*(c_sig+c_qcd));
  803. //
  804. // signal calculation:
  805. double S = Trionym(A,B,C, a_sig+b_sig);
  806. // the errors now:
  807. // calculate the statistical error now:
  808. double ApI=0, ApFz=0, ApFzP=0, ApNa=0, ApNb=0, ApNc=0, ApNd=0;
  809. double BpI=0, BpFz=0, BpFzP=0, BpNa=0, BpNb=0, BpNc=0, BpNd=0;
  810. double CpI=0, CpFz=0, CpFzP=0, CpNa=0, CpNb=0, CpNc=0, CpNd=0;
  811. double SpI=0, SpFz=0, SpFzP=0, SpNa=0, SpNb=0, SpNc=0, SpNd=0;
  812. //
  813. double Na = a_sig+a_qcd+a_ewk, Nb = b_sig+b_qcd+b_ewk;
  814. double Nc=c_sig+c_qcd+c_ewk, Nd = d_sig+d_qcd+d_ewk;
  815. double Ea = a_ewk, Eb = b_ewk, Ec=c_ewk, Ed = d_ewk;
  816. if (A != 0) {
  817. ApI = -(FzP-Fz);
  818. ApFz = -(1.0-I);
  819. ApFzP = (1.0-I);
  820. ApNa = 0.0;
  821. ApNb = 0.0;
  822. ApNc = 0.0;
  823. ApNd = 0.0;
  824. BpI = (FzP+1.0)*(Fz*(Nc-Ec)-(Nd-Ed))-(1.0+Fz)*((Na-Ea)-FzP*(Nb-Eb));
  825. BpFz = I*(FzP+1.0)*(Nc-Ec)+(1.0-I)*((Na-Ea)-FzP*(Nb-Eb));
  826. BpFzP = I*(Fz*(Nc-Ec)-(Nd-Ed))-(1.0-I)*(1.0+Fz)*(Nb-Eb);
  827. BpNa = (1.0-I)*(1.0+Fz);
  828. BpNb = -(1.0-I)*(1.0+Fz)*FzP;
  829. BpNc = I*(FzP+1.0)*Fz;
  830. BpNd = -I*(FzP+1.0);
  831. CpI = (1.0+Fz)*(1.0+FzP)*((Nd-Ed)*(Nb-Eb)-(Na-Ea)*(Nc-Ec));
  832. CpFz = I*(1.0+FzP)*((Nd-Ed)*(Nb-Eb)-(Na-Ea)*(Nc-Ec));
  833. CpFzP = I*(1.0+Fz)*((Nd-Ed)*(Nb-Eb)-(Na-Ea)*(Nc-Ec));
  834. CpNa = -I*(1.0+Fz)*(1.0+FzP)*(Nc-Ec);
  835. CpNb = I*(1.0+Fz)*(1.0+FzP)*(Nd-Ed);
  836. CpNc = -I*(1.0+Fz)*(1.0+FzP)*(Na-Ea);
  837. CpNd = I*(1.0+Fz)*(1.0+FzP)*(Nb-Eb);
  838. SpI = (-BpI + (B*BpI -2.0*ApI*C -2.0*A*CpI) /fabs(2.0*A*S+B)- 2.0*ApI*S) /(2.0*A);
  839. SpFz = (-BpFz + (B*BpFz -2.0*ApFz*C -2.0*A*CpFz) /fabs(2.0*A*S+B)- 2.0*ApFz*S) /(2.0*A);
  840. SpFzP = (-BpFzP + (B*BpFzP -2.0*ApFzP*C -2.0*A*CpFzP)/fabs(2.0*A*S+B)- 2.0*ApFzP*S)/(2.0*A);
  841. SpNa = (-BpNa + (B*BpNa -2.0*ApNa*C -2.0*A*CpNa) /fabs(2.0*A*S+B)- 2.0*ApNa*S) /(2.0*A);
  842. SpNb = (-BpNb + (B*BpNb -2.0*ApNb*C -2.0*A*CpNb) /fabs(2.0*A*S+B)- 2.0*ApNb*S) /(2.0*A);
  843. SpNc = (-BpNc + (B*BpNc -2.0*ApNc*C -2.0*A*CpNc) /fabs(2.0*A*S+B)- 2.0*ApNc*S) /(2.0*A);
  844. SpNd = (-BpNd + (B*BpNd -2.0*ApNd*C -2.0*A*CpNd) /fabs(2.0*A*S+B)- 2.0*ApNd*S) /(2.0*A);
  845. }
  846. else {
  847. BpI = (FzP+1.0)*(Fz*(Nc-Ec)-(Nd-Ed))-(1.0+Fz)*((Na-Ea)-FzP*(Nb-Eb));
  848. BpFz = I*(FzP+1.0)*(Nc-Ec)+(1.0-I)*((Na-Ea)-FzP*(Nb-Eb));
  849. BpFzP = I*(Fz*(Nc-Ec)-(Nd-Ed))-(1.0-I)*(1.0+Fz)*(Nb-Eb);
  850. BpNa = (1.0-I)*(1.0+Fz);
  851. BpNb = -(1.0-I)*(1.0+Fz)*FzP;
  852. BpNc = I*(FzP+1.0)*Fz;
  853. BpNd = -I*(FzP+1.0);
  854. CpI = (1.0+Fz)*(1.0+FzP)*((Nd-Ed)*(Nb-Eb)-(Na-Ea)*(Nc-Ec));
  855. CpFz = I*(1.0+FzP)*((Nd-Ed)*(Nb-Eb)-(Na-Ea)*(Nc-Ec));
  856. CpFzP = I*(1.0+Fz)*((Nd-Ed)*(Nb-Eb)-(Na-Ea)*(Nc-Ec));
  857. CpNa = -I*(1.0+Fz)*(1.0+FzP)*(Nc-Ec);
  858. CpNb = I*(1.0+Fz)*(1.0+FzP)*(Nd-Ed);
  859. CpNc = -I*(1.0+Fz)*(1.0+FzP)*(Na-Ea);
  860. CpNd = I*(1.0+Fz)*(1.0+FzP)*(Nb-Eb);
  861. SpI = -CpI/B+C*BpI/(B*B);
  862. SpFz = -CpFz/B+C*BpFz/(B*B);
  863. SpFzP = -CpFzP/B+C*BpFzP/(B*B);
  864. SpNa = -CpNa/B+C*BpNa/(B*B);
  865. SpNb = -CpNb/B+C*BpNb/(B*B);
  866. SpNc = -CpNc/B+C*BpNc/(B*B);
  867. SpNd = -CpNd/B+C*BpNd/(B*B);
  868. }
  869. double DS;
  870. DS = sqrt( SpI*dI*SpI*dI + SpFz*dFz*SpFz*dFz + SpFzP*dFzP*SpFzP*dFzP +
  871. SpNa*SpNa*Na + SpNb*SpNb*Nb + SpNc*SpNc*Nc + SpNd*SpNd*Nd );
  872. // warning: S here denotes the method prediction ..........
  873. cout << "********************************************************" << endl;
  874. cout << "Signal Prediction: " << S << "+-" << DS << "(stat)" << endl;
  875. cout << "********************************************************" << endl;
  876. cout << "Parameters used in calculation: " << endl;
  877. cout << "I= " << I << "+-" << dI << endl;
  878. cout << "Fz= " << Fz << "+-" << dFz << endl;
  879. cout << "FzP=" << FzP << "+-" << dFzP << endl;
  880. cout << endl;
  881. cout << "ABCD Regions population:" << endl;
  882. cout << "A: N=" << Na << ", sig=" << a_sig << ", qcd=" << a_qcd
  883. << ", ewk=" << a_ewk << endl;
  884. cout << "B: N=" << Nb << ", sig=" << b_sig << ", qcd=" << b_qcd
  885. << ", ewk=" << b_ewk << endl;
  886. cout << "C: N=" << Nc << ", sig=" << c_sig << ", qcd=" << c_qcd
  887. << ", ewk=" << c_ewk << endl;
  888. cout << "D: N=" << Nd << ", sig=" << d_sig << ", qcd=" << d_qcd
  889. << ", ewk=" << d_ewk << endl;
  890. cout << "K value from MC: " << KMC << endl;
  891. cout << endl;
  892. cout << "Statistical Error Summary: " << endl;
  893. cout << "due to Fz = "<< SpFz*dFz<< ", ("<<SpFz*dFz*100./S << "%)"<< endl;
  894. cout << "due to FzP= "<< SpFzP*dFzP
  895. << ", ("<<SpFzP*dFzP*100./S << "%)"<< endl;
  896. cout << "due to I = "<< SpI*dI
  897. << ", ("<<SpI*dI*100./S << "%)"<< endl;
  898. cout << "due to Na = "<< SpNa*sqrt(Na)
  899. << ", ("<< SpNa*sqrt(Na)*100./S << "%)"<< endl;
  900. cout << "due to Nb = "<< SpNb*sqrt(Nb)
  901. << ", ("<< SpNb*sqrt(Nb)*100./S << "%)"<< endl;
  902. cout << "due to Nc = "<< SpNc*sqrt(Nc)
  903. << ", ("<< SpNc*sqrt(Nc)*100./S << "%)"<< endl;
  904. cout << "due to Nd = "<< SpNd*sqrt(Nd)
  905. << ", ("<< SpNd*sqrt(Nd)*100./S << "%)"<< endl;
  906. cout << "Total Statistical Error: "
  907. << DS << ", (" << DS*100./S << "%)"<< endl;
  908. cout << "Stat Error percentages are wrt S prediction, not S mc" << endl;
  909. }
  910. }
  911. void plotMaker(TString histoName, TString wzsignal,
  912. vector<TString> file, vector<TString> type,
  913. vector<double> weight, TString xtitle)
  914. {
  915. gROOT->Reset();
  916. gROOT->ProcessLine(".L tdrstyle.C");
  917. gROOT->ProcessLine("setTDRStyle()");
  918. // automatic recognition of histogram dimension
  919. int NBins = 0; double min = 0; double max = -1;
  920. for (int i=0; i< (int) file.size(); ++i) {
  921. if (weight[i]>0) {
  922. TFile f(file[i]);
  923. TH1F *h = (TH1F*) f.Get(histoName);
  924. NBins = h->GetNbinsX();
  925. min = h->GetBinLowEdge(1);
  926. max = h->GetBinLowEdge(NBins+1);
  927. break;
  928. }
  929. }
  930. if (NBins ==0 || (max<min)) {
  931. std::cout << "PlotCombiner::abcd error: Could not find valid histograms in file"
  932. << std::endl;
  933. abort();
  934. }
  935. cout << "Histograms with "<< NBins <<" bins and range " << min << "-" << max << endl;
  936. // Wenu Signal .......................................................
  937. TH1F h_wenu("h_wenu", "h_wenu", NBins, min, max);
  938. int fmax = (int) file.size();
  939. for (int i=0; i<fmax; ++i) {
  940. if (type[i] == "sig" && weight[i]>0) {
  941. TFile f(file[i]);
  942. TH1F *h = (TH1F*) f.Get(histoName);
  943. h_wenu.Add(h, weight[i]);
  944. }
  945. }
  946. // Bkgs ..............................................................
  947. //
  948. // QCD light flavor
  949. TH1F h_qcd("h_qcd", "h_qcd", NBins, min, max);
  950. for (int i=0; i<fmax; ++i) {
  951. if (type[i] == "qcd" && weight[i]>0) {
  952. TFile f(file[i]);
  953. TH1F *h = (TH1F*) f.Get(histoName);
  954. h_qcd.Add(h, weight[i]);
  955. }
  956. }
  957. // QCD heavy flavor
  958. TH1F h_bce("h_bce", "h_bce", NBins, min, max);
  959. for (int i=0; i<fmax; ++i) {
  960. if (type[i] == "bce" && weight[i]>0) {
  961. TFile f(file[i]);
  962. TH1F *h = (TH1F*) f.Get(histoName);
  963. h_bce.Add(h, weight[i]);
  964. }
  965. }
  966. // QCD Gjets
  967. TH1F h_gj("h_gj", "h_gj", NBins, min, max);
  968. for (int i=0; i<fmax; ++i) {
  969. if (type[i] == "gje" && weight[i]>0) {
  970. TFile f(file[i]);
  971. TH1F *h = (TH1F*) f.Get(histoName);
  972. h_gj.Add(h, weight[i]);
  973. }
  974. }
  975. // Other EWK bkgs
  976. TH1F h_ewk("h_ewk", "h_ewk", NBins, min, max);
  977. for (int i=0; i<fmax; ++i) {
  978. if (type[i] == "ewk" && weight[i]>0) {
  979. TFile f(file[i]);
  980. TH1F *h = (TH1F*) f.Get(histoName);
  981. h_ewk.Add(h, weight[i]);
  982. }
  983. }
  984. //
  985. // ok now decide how to plot them:
  986. // first the EWK bkgs
  987. h_ewk.SetFillColor(3);
  988. //
  989. // then the gjets
  990. h_gj.Add(&h_ewk);
  991. h_gj.SetFillColor(1);
  992. // thent the QCD dijets
  993. h_bce.Add(&h_qcd);
  994. h_bce.Add(&h_gj);
  995. h_bce.SetFillColor(2);
  996. // and the signal at last
  997. TH1F h_tot("h_tot", "h_tot", NBins, min, max);
  998. h_tot.Add(&h_bce);
  999. h_tot.Add(&h_wenu);
  1000. h_wenu.SetLineColor(4); h_wenu.SetLineWidth(2);
  1001. //
  1002. TCanvas c;
  1003. h_tot.GetXaxis()->SetTitle(xtitle);
  1004. h_tot.Draw("PE");
  1005. h_bce.Draw("same");
  1006. h_gj.Draw("same");
  1007. h_ewk.Draw("same");
  1008. h_wenu.Draw("same");
  1009. // the Legend
  1010. TLegend leg(0.6,0.65,0.95,0.92);
  1011. if (wzsignal == "wenu")
  1012. leg.AddEntry(&h_wenu, "W#rightarrow e#nu","l");
  1013. else
  1014. leg.AddEntry(&h_wenu, "Z#rightarrow ee","l");
  1015. leg.AddEntry(&h_tot, "Signal + Bkg","p");
  1016. leg.AddEntry(&h_bce, "dijets","f");
  1017. leg.AddEntry(&h_gj, "#gamma + jets","f");
  1018. leg.AddEntry(&h_ewk, "EWK+t#bar t", "f");
  1019. leg.Draw("same");
  1020. c.Print("test.png");
  1021. }
  1022. //
  1023. // reads the ABCD string and returns its value
  1024. // value is whatever it exists after the = sign and
  1025. // before the comma or the parenthesis
  1026. //
  1027. // if the string is not contained returns -1
  1028. // if there is no value, but the string is contained -0.5
  1029. // if there is an error in the algorithm return -99 and print error
  1030. // else returns its value
  1031. double searchABCDstring(TString abcdString, TString keyword)
  1032. {
  1033. int size = keyword.Sizeof();
  1034. int existsEntry = abcdString.Index(keyword);
  1035. //
  1036. if (existsEntry==-1) return -1.;
  1037. //
  1038. TString previousVal = abcdString(existsEntry-1);
  1039. if (!(previousVal == "," || previousVal == " " ||
  1040. previousVal == "(" )) return -1.;
  1041. //
  1042. TString afterVal = abcdString(existsEntry+size-1);
  1043. //std::cout << "afterVal=" << afterVal << std::endl;
  1044. if (afterVal =="," || afterVal==")") return -0.5;
  1045. else if (afterVal != "=") return -1.;
  1046. //
  1047. // now find the comma or the parenthesis after the = sign
  1048. int comma = abcdString.Index(",",existsEntry);
  1049. //std::cout << "first comma=" << comma << std::endl;
  1050. if (comma<0) comma = abcdString.Index(")",existsEntry);
  1051. if (comma<0) {
  1052. std::cout << "Error in parcing abcd line, chech syntax "
  1053. << std::endl;
  1054. return -99.;
  1055. }
  1056. TString svalue=abcdString(existsEntry+size,comma-existsEntry-size);
  1057. std::cout << "Found ABCD parameter "<< keyword
  1058. << " with value " << svalue << endl;
  1059. // convert this to a float
  1060. double value = svalue.Atof();
  1061. return value;
  1062. }
  1063. double Trionym(double a, double b, double c, double sum)
  1064. {
  1065. if (a==0) {
  1066. return -c/b;
  1067. }
  1068. double D2 = b*b - 4.*a*c;
  1069. //return (-b + sqrt(D2)) / (2.*a);
  1070. if (D2 > 0) {
  1071. double s1 = (-b + sqrt(D2)) / (2.*a);
  1072. double s2 = (-b - sqrt(D2)) / (2.*a);
  1073. double solution = fabs(s1-sum)<fabs(s2-sum)?s1:s2;
  1074. return solution;
  1075. }
  1076. else {
  1077. return -1.;
  1078. }
  1079. }
  1080. //
  1081. // the naming of the variables and the order is in this way for historical
  1082. // reasons
  1083. // your complains for different Nd_ and nd to G.Daskalakis :P
  1084. //
  1085. double CalcABCD
  1086. (double I, double Fz, double FzP, double K, double ewk,
  1087. double Na_, double Nb_, double Nc_, double Nd_ ,
  1088. double Ea_, double Eb_, double Ec_, double Ed_)
  1089. {
  1090. double A, B, C;
  1091. A = (1.0-I)*(FzP-K*Fz);
  1092. B = I*(FzP+1.0)*(K*Fz*(Nc_-ewk*Ec_)-(Nd_-ewk*Ed_))+
  1093. (1.0-I)*(1.0+Fz)*(K*(Na_-ewk*Ea_)-FzP*(Nb_-ewk*Eb_));
  1094. C = I*(1.0+Fz)*(1.0+FzP)*((Nd_-ewk*Ed_)*(Nb_-ewk*Eb_)-
  1095. K*(Na_-ewk*Ea_)*(Nc_-ewk*Ec_));
  1096. //
  1097. return Trionym(A, B, C, Na_+Nb_-Ea_-Eb_);
  1098. }