HighLAND
DrawingTools.cxx
1 #include "DrawingTools.hxx"
2 #include "SystematicTools.hxx"
3 #include <iomanip>
4 #include <iostream>
5 #include <fstream>
6 
7 //********************************************************************
8 DrawingTools::DrawingTools(const std::string& file, Int_t T2KstyleIndex):DrawingToolsBase(file,T2KstyleIndex){
9 //********************************************************************
10 
11  _treeForSystErrors = NULL;
12 }
13 
14 //********************************************************************
15 DrawingTools::DrawingTools(Experiment& exp, Int_t T2KstyleIndex):DrawingToolsBase(exp.GetFilePath(),T2KstyleIndex){
16 //********************************************************************
17 
18  _treeForSystErrors = NULL;
19 }
20 
21 //********************************************************************
22 //void DrawingTools::PrintSummary(){
23 //********************************************************************
24 
25 /*
26 
27  std::cout << " - Avg relative systematic error: " << _avg_rel_syst_err << std::endl;
28  std::cout << " - Avg relative statistical error: " << _avg_rel_stat_err << std::endl;
29  std::cout << " - Avg relative total error: " << _avg_rel_total_err << std::endl;
30 */
31 //}
32 
33 
34 
35 //**************************************************
36 //void DrawingTools::PrintHisto(const std::string& name, const std::string& categ){
37 //**************************************************
38 
39 /*
40  std::cout << "-------------------------------------------------------" << std::endl;
41  std::cout << "Summary info for histo: " << name << std::endl;
42  std::cout << "-------------------------------------------------------" << std::endl;
43 
44  if (opt!=0){
45  std::map< std::string, std::map< std::string, bool > >::iterator it;
46  for (it= GetTrees().begin();it!=GetTrees().end();it++){
47  if (!TreeEnabled(it->first)) continue;
48  std::cout << "- tree: " << it->first << std::endl;
49  PrintSummary(it->first, name);
50  }
51 
52  }
53  else{
54  std::cout << "avg systematic error: " << std::endl;
55  std::map< std::string, std::map< std::string, bool > >::iterator it;
56  for (it= GetTrees().begin();it!=GetTrees().end();it++){
57  if (!TreeEnabled(it->first)) continue;
58  GetCounter(it->first, name).ComputeAvgErrors();
59  std::cout << " - " << it->first << "\t" << GetCounter(it->first, name).GetAvgRelSystError() << std::endl;
60  }
61  std::cout << "avg statistical error (default): " << GetCounter("default", name).GetAvgRelStatError() << std::endl;
62  if (CheckHistoConf("all_syst", name,"all")){
63  std::cout << "avg statistical error (all syst): " << GetCounter("all_syst", name).GetAvgRelStatError() << std::endl;
64  std::cout << "avg total error: " << GetCounter("all_syst", name).GetAvgRelTotalError() << std::endl;
65  }
66  }
67 
68  std::cout << "-------------------------------------------------------" << std::endl;
69 */
70 //}
71 
72 
73 
74 
75 //}
76 
77 //*********************************************************
78 std::string DrawingTools::GetCombinedCut(DataSample& sample, const std::string& cut){
79 //*********************************************************
80 
81  std::string cut1 = cut;
82  if (sample.GetCut() !="") cut1 = cut+" && ("+sample.GetCut()+")";
83  return cut1;
84 }
85 
86 //*********************************************************
87 void DrawingTools::Project(HistoStack* hs, const std::string& sample_name,DataSample& sample, const std::string& var, int nx, double* xbins, int ny, double* ybins, const std::string& categ,
88  const std::string& cut, const std::string& root_opt, const std::string& opt, double norm, bool scale_errors){
89 //*********************************************************
90 
91  std::string opt2 = opt + " EXP";
92  DrawingToolsBase::Project(hs, sample_name, sample.GetTree(),var,nx,xbins,ny,ybins,categ,GetCombinedCut(sample,cut),root_opt,opt2,norm,scale_errors);
93 }
94 
95 //*********************************************************
96 void DrawingTools::Project(HistoStack* hs1, HistoStack* hs2, DataSample* sample1, DataSample* sample2,
97  const std::string& var, int nx, double* xbins, int ny, double* ybins, const std::string& categ,
98  const std::string& cut, const std::string& root_opt, const std::string& opt, bool scale_errors, double norm, bool pot_norm){
99 //*********************************************************
100 
101  if (!sample1 || !sample2) return;
102 
103  // Get the normalisation factor between them
104  norm = GetNormalisationFactor(sample1, sample2, norm, pot_norm, opt);
105 
106  // Project the first sample with normalization 1 (or with area normalization) and the second sample normalized to the first
107  std::string opt2 = opt + " EXP";
108  DrawingToolsBase::Project(hs1,hs2,sample1->GetTree(), sample2->GetTree(), var,nx,xbins,ny,ybins,categ,cut,root_opt,opt2,norm,scale_errors);
109 }
110 
111 //*********************************************************
112 void DrawingTools::Project(HistoStack* hs1, HistoStack* hs2, SampleGroup& sampleGroup, const std::string& mcSampleName,
113  const std::string& var, int nx, double* xbins, int ny, double* ybins, const std::string& categ,
114  const std::string& cut, const std::string& root_opt, const std::string& opt, double norm, bool scale_errors){
115 //*********************************************************
116 
117  if (mcSampleName!="all"){
118  if (!sampleGroup.HasMCSample(mcSampleName)) return;
119  }
120 
121  std::string uopt = drawUtils::ToUpper(opt);
122 
123  // Project the first sample with normalization 1
124  DataSample* sample1 = NULL;
125  if (hs1){
126  sample1 = sampleGroup.GetDataSample();
127  if (sample1)
128  // Project(hs1, "sample1", *sample1,var,nx,xbins,ny,ybins,"all",cut,root_opt,opt+" NOSYS",1 ,scale_errors);
129  Project(hs1, "sample1", *sample1,var,nx,xbins,ny,ybins,"all",cut,root_opt,opt,1 ,scale_errors);
130  }
131 
132  if (hs2){
133  std::map< std::string, DataSample*>& mcSamples = sampleGroup.GetMCSamples();
134  std::map< std::string, DataSample*>::iterator it;
135  for (it = mcSamples.begin(); it != mcSamples.end(); it++) {
136  const std::string& mcSampleName2 = it->first;
137  if (mcSampleName2 != mcSampleName && mcSampleName!="all") continue;
138  DataSample* sample2 = it->second;
139  if (sample2){
140  // Get the normalisation factor between data and this MC sample
141  // If the input normalization factor is >=0 (default is -1) that factor will be applied even when data is present
142  double norm2 = GetNormalisationFactor(sample1, sample2, norm, true, opt);
143 
144  // Project the second sample normalized to the first one
145  hs2->SetCurrentSystGroup(sample2->GetSystGroup());
146  std::string syst_opt = sample2->GetSystOption();
147  Project(hs2, "sample2_"+mcSampleName2, *sample2,var,nx,xbins,ny,ybins,categ,cut,root_opt,opt+" "+syst_opt,norm2,scale_errors);
148  }
149  }
150  }
151 }
152 
153 //*********************************************************
154 void DrawingTools::Project(HistoStack* hs1, HistoStack* hs2, Experiment& exp, const std::string& groupName, const std::string& mcSampleName,
155  const std::string& var, int nx, double* xbins, int ny, double* ybins, const std::string& categ,
156  const std::string& cut, const std::string& root_opt, const std::string& opt, double norm, bool scale_errors){
157 //*********************************************************
158 
159  std::string uopt = drawUtils::ToUpper(opt);
160 
161  // Loop over SampleGroup's in the experiment
162  std::map< std::string, SampleGroup >::iterator it;
163  for (it = exp.GetSampleGroups().begin(); it != exp.GetSampleGroups().end(); it++) {
164  const std::string& groupName2 = it->first;
165  if (groupName2 != groupName && groupName!="all") continue;
166  SampleGroup& sampleGroup = it->second;
167  // Project the first sample with normalization 1 and the MC samples normalized to the first sample
168  Project(hs1, hs2, sampleGroup, mcSampleName, var,nx,xbins,ny,ybins,categ,cut,root_opt,uopt+" NOAREA",norm,scale_errors);
169  }
170 
171  // normalize by area when requested
172  if(drawUtils::CheckOption(uopt,"AREA")){
173  if (hs1) hs1->NormalizeByArea(uopt);
174  if (hs2){
175  if (hs1)
176  hs2->NormalizeByArea(uopt,hs1->GetTotal1D()->GetSumOfWeights());
177  else
178  hs2->NormalizeByArea(uopt);
179  }
180  }
181 
182 }
183 
184 //*********************************************************
185 void DrawingTools::PrintPurities(DataSample& sample, const std::string& categ, const std::string& cut, double events_ratio){
186 //*********************************************************
187 
188  DrawingToolsBase::PrintPurities(sample.GetTree(), categ, GetCombinedCut(sample,cut), events_ratio);
189 }
190 
191 //*********************************************************
192 void DrawingTools::PrintPurities(Experiment& exp, const std::string& categ, const std::string& cut, const std::string& opt){
193 //*********************************************************
194 
195  // Read the categories from the config tree
196  ReadCategories(_config_file);
197 
198  if (!cat().HasCategory(categ) || categ =="all" ) {
199  std::cout << " ------------------------------------------ " << std::endl;
200  std::cout << " Invalid category " << categ << std::endl;
201  std::cout << " ------------------------------------------ " << std::endl;
202  return;
203  }
204 
205  std::string uopt = drawUtils::ToUpper(opt);
206 
207  int i=0;
208 
209  std::vector<TrackTypeDefinition>::iterator it;
210 
211  double dummy1, dummy2, nev1, nev2;
212  // Just to get the total number of events
213  dummy1 = GetEff(exp, false, dummy1, dummy2, nev1, nev2, cut, cut,"",uopt+" PUR");
214 
215  std::cout << " --------------------------------------------------------" << std::endl;
216  std::cout << " Experiment Purities (not POT normalized): " << std::endl;
217  std::cout << " Category: " << categ << std::endl;
218  std::cout << " Cut: " << cut << std::endl;
219  std::cout << " Events: " << nev1 << std::endl;
220  std::cout << " --------------------------------------------------------" << std::endl;
221 
222  // define stuff to print % on the legend
223  std::ostringstream percstr, str_tmp;
224  const int ntypes = (const int)cat().GetCategoryTypes(categ).size();
225  std::string* cattypes = new std::string[ntypes]; // to initialize with const dimension
226  int* catcodes = new int[ntypes]; // to initialize with const dimension
227  int* catcolors = new int[ntypes]; // to initialize with const dimension
228  int itype=0;
229 
230  for (it=cat().GetCategoryTypes(categ).begin();it!=cat().GetCategoryTypes(categ).end();it++, i++){
231  std::string type = it->_name;
232  std::string code = drawUtils::GetString(it->_code);
233 
234  std::string cut2 = categ+"=="+code;
235 
236  double frac = GetEff(exp, false, dummy1, dummy2, nev1, nev2, cut2, cut,"",uopt+" PUR");
237 
238  std::cout << std::setprecision(8) << std::setw(25) << type << std::setw(12) << frac*100. << " % (" << nev1 << " events)" << std::endl;
239 
240  // create categ_temp to print % on the legend
241  percstr.str(std::string()); // to clear it
242  percstr << std::setprecision(2) << std::fixed << frac*100.; // round to 2 decimal
243  str_tmp.str(std::string()); // to clear it
244  str_tmp << it->_name << std::setw(8) << percstr.str() << " %"; // tab
245  cattypes[itype] = str_tmp.str();
246  catcodes[itype] = it->_code;
247  catcolors[itype] = it->_color;
248  itype++;
249  }
250 
251  // create categories with % in the name
252  bool multi = cat().GetCategory(categ).IsMultiType();
253  bool noWarning = true, addNOTRUTH = false, addSAND = false;
254  cat().AddCategory(categ+"_withPurities",itype,cattypes,catcodes,catcolors,multi,noWarning,addNOTRUTH,addSAND);
255 
256  std::cout << " --------------------------------------------------------" << std::endl;
257  std::cout << std::endl;
258 
259  return;
260 }
261 
262 //*********************************************************
263 void DrawingTools::Draw(DataSample& sample, const std::string& var, int nx, double xmin, double xmax,
264  const std::string& categ, const std::string& cut, const std::string& root_opt, const std::string& opt, double norm, bool scale_errors){
265 //*********************************************************
266 
267  norm = GetNormalisationFactor(NULL, &sample, norm, true, opt);
268  DrawingToolsBase::Draw(sample.GetTree(), var,nx,xmin,xmax,categ,GetCombinedCut(sample,cut),root_opt,opt,norm,scale_errors);
269 }
270 
271 //*********************************************************
272 void DrawingTools::Draw(DataSample& sample, const std::string& var, int nbins, double* xbins,
273  const std::string& categ, const std::string& cut, const std::string& root_opt, const std::string& opt, double norm, bool scale_errors){
274 //*********************************************************
275 
276  norm = GetNormalisationFactor(NULL, &sample, norm, true, opt);
277  DrawingToolsBase::Draw(sample.GetTree(), var,nbins,xbins,categ,GetCombinedCut(sample,cut),root_opt,opt,norm,scale_errors);
278 }
279 
280 //*********************************************************
281 void DrawingTools::Draw(DataSample& sample, const std::string& var, int nx, double xmin, double xmax, int ny, double ymin, double ymax,
282  const std::string& categ, const std::string& cut, const std::string& root_opt, const std::string& opt, double norm){
283 //*********************************************************
284 
285  norm = GetNormalisationFactor(NULL, &sample, norm, true, opt);
286  DrawingToolsBase::Draw(sample.GetTree(), var,nx,xmin,xmax,ny,ymin,ymax,categ,GetCombinedCut(sample,cut),root_opt,opt,norm);
287 }
288 
289 //*********************************************************
290 void DrawingTools::Draw(DataSample& sample, const std::string& var, int nx, double* xbins, int ny, double* ybins,
291  const std::string& categ, const std::string& cut, const std::string& root_opt, const std::string& opt, double norm){
292 //*********************************************************
293 
294  norm = GetNormalisationFactor(NULL, &sample, norm, true, opt);
295  DrawingToolsBase::Draw(sample.GetTree(), var,nx,xbins,ny,ybins,categ,GetCombinedCut(sample,cut),root_opt,opt,norm);
296 }
297 
298 //*********************************************************
299 void DrawingTools::DrawEff(DataSample& sample, const std::string& var, int nx, double xmin, double xmax,
300  const std::string& cut1, const std::string& cut2, const std::string& root_opt, const std::string& opt, const std::string& leg_name){
301 //*********************************************************
302 
303  DrawingToolsBase::DrawEff(sample.GetTree(), var,nx,xmin,xmax,cut1,cut2,root_opt,opt,leg_name);
304 }
305 
306 //*********************************************************
307 void DrawingTools::DrawEff(DataSample& sample, const std::string& var, int nx, double* xbins,
308  const std::string& cut1, const std::string& cut2, const std::string& root_opt, const std::string& opt, const std::string& leg_name){
309 //*********************************************************
310 
311  DrawingToolsBase::DrawEff(sample.GetTree(), var,nx,xbins,cut1,cut2,root_opt,opt,leg_name);
312 }
313 
314 //*********************************************************
315 void DrawingTools::DrawDoubleEff(DataSample& sample1, DataSample& sample2, const std::string& var, int nx, double xmin, double xmax,
316  const std::string& cut1, const std::string& cut2, const std::string& root_opt, const std::string& opt, const std::string& leg_name){
317 //*********************************************************
318 
319  DrawingToolsBase::DrawDoubleEff(sample1.GetTree(), sample2.GetTree(), var,nx,xmin,xmax,cut1,cut2,root_opt,opt,leg_name);
320 }
321 
322 //*********************************************************
323 void DrawingTools::DrawDoubleEff(DataSample& sample1, DataSample& sample2, const std::string& var, int nx, double* xbins,
324  const std::string& cut1, const std::string& cut2, const std::string& root_opt, const std::string& opt, const std::string& leg_name){
325 //*********************************************************
326 
327  DrawingToolsBase::DrawDoubleEff(sample1.GetTree(), sample2.GetTree(), var,nx,xbins,cut1,cut2,root_opt,opt,leg_name);
328 }
329 
330 //*********************************************************
331 void DrawingTools::DrawEff(Experiment& exp, bool usedata, const std::string& var, int nx, double xmin, double xmax,
332  const std::string& cut1, const std::string& cut2, const std::string& root_opt, const std::string& opt, const std::string& leg_name) {
333 //*********************************************************
334  double xbins[NMAXBINS];
335  DrawEff(exp, usedata, var, nx, GetVariableBins(nx, xmin, xmax, xbins), cut1, cut2, root_opt, opt, leg_name);
336 }
337 
338 //*********************************************************
339 void DrawingTools::DrawEff(Experiment& exp, bool usedata, const std::string& var, int nx, double* xbins,
340  const std::string& cut1, const std::string& cut2, const std::string& root_opt, const std::string& opt, const std::string& leg) {
341 //*********************************************************
342  double dummy1, dummy2;
343  std::string uopt = drawUtils::ToUpper(opt);
344  std::string uroot_opt = drawUtils::ToUpper(root_opt);
345 
346  // Check that all user options are valid
347  if (!drawUtils::ContainValidOptions(uopt)) return;
348 
349  TGraphAsymmErrors* eff = GetEff(exp, usedata, var, nx, xbins, dummy1, dummy2, cut1, cut2, uroot_opt, uopt);
350 
351  // Draw the efficiency graph
352  if (eff)
353  DrawingToolsBase::DrawGraph(eff,nx,xbins,uroot_opt,uopt,leg);
354 }
355 
356 
357 //*********************************************************
358 void DrawingTools::DrawEffNew(Experiment& exp, bool usedata, const std::string& var, int nx, double xmin, double xmax,
359  const std::string& cut1, const std::string& cut2, const std::string& root_opt, const std::string& opt1, const std::string& opt2,
360  const std::string& leg_name) {
361 //*********************************************************
362  double xbins[NMAXBINS];
363  DrawEffNew(exp, usedata, var, nx, GetVariableBins(nx, xmin, xmax, xbins), cut1, cut2, root_opt, opt1, opt2, leg_name);
364 }
365 
366 //*********************************************************
367 void DrawingTools::DrawEffNew(Experiment& exp, bool usedata, const std::string& var, int nx, double* xbins,
368  const std::string& cut1, const std::string& cut2, const std::string& root_opt, const std::string& opt1,
369  const std::string& opt2, const std::string& leg) {
370 //*********************************************************
371  double dummy1, dummy2;
372  std::string uopt1 = drawUtils::ToUpper(opt1);
373  std::string uopt2 = drawUtils::ToUpper(opt2);
374  std::string uroot_opt = drawUtils::ToUpper(root_opt);
375 
376  // Check that all user options are valid
377  if (!drawUtils::ContainValidOptions(uopt1)) return;
378 
379  // Check that all user options are valid
380  if (!drawUtils::ContainValidOptions(uopt2)) return;
381 
382  TGraphAsymmErrors* eff = GetEffNew(exp, usedata, var, nx, xbins, dummy1, dummy2, cut1, cut2, uroot_opt, uopt1, uopt2);
383 
384  // Draw the efficiency graph
385  if (eff)
386  DrawingToolsBase::DrawGraph(eff,nx,xbins,uroot_opt,uopt1,leg);
387 }
388 
389 
390 //*********************************************************
391 void DrawingTools::DrawPur(Experiment& exp, const std::string& var, int nx, double xmin, double xmax,
392  const std::string& cut1, const std::string& cut2, const std::string& root_opt, const std::string& opt, const std::string& leg_name) {
393 //*********************************************************
394  double xbins[NMAXBINS];
395  DrawPur(exp, var, nx, GetVariableBins(nx, xmin, xmax, xbins), cut1, cut2, root_opt, opt, leg_name);
396 }
397 
398 //*********************************************************
399 void DrawingTools::DrawPur(Experiment& exp, const std::string& var, int nx, double* xbins,
400  const std::string& cut1, const std::string& cut2, const std::string& root_opt, const std::string& opt, const std::string& leg) {
401 //*********************************************************
402 
403  double dummy1, dummy2;
404  std::string uopt = drawUtils::ToUpper(opt);
405  std::string uroot_opt = drawUtils::ToUpper(root_opt);
406 
407  // Check that all user options are valid
408  if (!drawUtils::ContainValidOptions(uopt)) return;
409 
410  // Check that all user options are valid
411  if (!drawUtils::ContainValidOptions(uopt)) return;
412 
413  TGraphAsymmErrors* eff = GetEff(exp, false, var, nx, xbins, dummy1, dummy2, cut1, cut2, uroot_opt, uopt+" PUR");
414 
415  // Draw the efficiency graph
416  if (eff)
417  DrawingToolsBase::DrawGraph(eff,nx,xbins,uroot_opt,uopt,leg);
418 }
419 
420 //*********************************************************
421 void DrawingTools::DrawSignificance(DataSample& sample, const std::string& var, int nx, double xmin, double xmax,
422  const std::string& cut1, const std::string& cut2, double norm, double rel_syst, const std::string& root_opt, const std::string& opt, const std::string& leg_name){
423 //*********************************************************
424 
425  DrawingToolsBase::DrawSignificance(sample.GetTree(), var,nx,xmin,xmax,cut1,cut2,norm,rel_syst,root_opt,opt,leg_name);
426 }
427 
428 //*********************************************************
429 void DrawingTools::DrawSignificance(DataSample& sample, const std::string& var, int nx, double* xbins, const std::string& cut1, const std::string& cut2,
430  double norm, double rel_syst, const std::string& root_opt, const std::string& opt, const std::string& leg_name){
431 //*********************************************************
432 
433  DrawingToolsBase::DrawSignificance(sample.GetTree(), var,nx,xbins,cut1,cut2,norm,rel_syst,root_opt,opt,leg_name);
434 }
435 
436 //*********************************************************
437 void DrawingTools::DrawRatio(DataSample& sample, const std::string& var, int nx, double xmin, double xmax,
438  const std::string& cut1, const std::string& cut2, const std::string& root_opt, const std::string& opt, const std::string& leg_name){
439 //*********************************************************
440 
441  DrawingToolsBase::DrawRatio(sample.GetTree(), var,nx,xmin,xmax,cut1,cut2,root_opt,opt,leg_name);
442 }
443 
444 //*********************************************************
445 void DrawingTools::PrintEventNumbers(DataSample& sample, const std::string& cut, const std::string& file, int toy_ref){
446 //*********************************************************
447 
448  DrawingToolsBase::PrintEventNumbers(sample.GetTree(), GetCombinedCut(sample,cut), file, toy_ref);
449 }
450 
451 //*********************************************************
452 void DrawingTools::DrawRatio(DataSample& sample, const std::string& var, int nx, double* xbins,
453  const std::string& cut1, const std::string& cut2, const std::string& root_opt, const std::string& opt, const std::string& leg_name){
454 //*********************************************************
455 
456  DrawingToolsBase::DrawRatio(sample.GetTree(), var,nx,xbins,cut1,cut2,root_opt,opt,leg_name);
457 }
458 
459 //**************************************************
460 void DrawingTools::Draw(DataSample& sample1, DataSample& sample2, const std::string& var, int nx, double xmin, double xmax,
461  const std::string& categ, const std::string& cut, const std::string& root_opt, const std::string& opt, double norm, bool scale_errors, bool pot_norm){
462 //**************************************************
463 
464  // 1D comparison between two data samples with different normalisation. Uniform binning
465  double xbins[NMAXBINS];
466  Draw(sample1,sample2,var,nx,GetVariableBins(nx,xmin,xmax,xbins),categ,cut,root_opt, opt,norm,scale_errors,pot_norm);
467 }
468 
469 //**************************************************
470 void DrawingTools::Draw(DataSample& sample1, DataSample& sample2, const std::string& var, int nx, double* xbins,
471  const std::string& categ, const std::string& cut, const std::string& root_opt, const std::string& opt, double norm, bool scale_errors, bool pot_norm){
472 //**************************************************
473 
474  // 1D comparison between two data samples with different normalisation. Variable binning
475  int ny=0;
476  double *ybins=NULL;
477  Draw(sample1,sample2,var,nx,xbins,ny,ybins,categ,cut,root_opt, opt,norm,scale_errors,pot_norm);
478 }
479 
480 //**************************************************
481 void DrawingTools::Draw(DataSample& sample1, DataSample& sample2, const std::string& var, int nx, double xmin, double xmax, int ny, double ymin, double ymax,
482  const std::string& categ, const std::string& cut, const std::string& root_opt, const std::string& opt, double norm, bool scale_errors, bool pot_norm){
483 //**************************************************
484 
485  // 2D comparison between two data samples with different normalisation. Uniform binning
486  double xbins[NMAXBINS];
487  double ybins[NMAXBINS];
488  Draw(sample1,sample2,var,nx,GetVariableBins(nx,xmin,xmax,xbins),ny,GetVariableBins(ny,ymin,ymax,ybins),categ,cut,root_opt, opt,norm,scale_errors,pot_norm);
489 }
490 
491 //**************************************************
492 void DrawingTools::Draw(DataSample& sample1, DataSample& sample2, const std::string& var, int nx, double* xbins, int ny, double* ybins,
493  const std::string& categ, const std::string& cut, const std::string& root_opt, const std::string& opt, double norm, bool scale_errors, bool pot_norm){
494 //**************************************************
495 
496  std::string uopt = drawUtils::ToUpper(opt);
497 
498  // Check that all user options are valid
499  if (!drawUtils::ContainValidOptions(uopt)) return;
500 
501  // Create empty Histo Stacks
502  HistoStack* hs1 = new HistoStack(_title,_titleX,_titleY);
503  HistoStack* hs2 = new HistoStack(_title,_titleX,_titleY);
504  _saved_histoStacks.push_back(hs1);
505  _saved_histoStacks.push_back(hs2);
506 
507  std::string slevel = GetSameLevel(root_opt);
508 
509  // Project the first sample with normalization 1 and the second sample normalized to the first one
510  Project(hs1, hs2, &sample1, &sample2, var,nx,xbins,ny,ybins,categ,cut,root_opt,opt,scale_errors,norm,pot_norm);
511 
512  // Draw the Total Stack after all samples have been projected
513  DrawingToolsBase::DrawHistoStacks(hs1,hs2,categ,root_opt,opt,1);
514 }
515 
516 //**************************************************
517 void DrawingTools::DrawRatio(DataSample& sample1, DataSample& sample2, const std::string& var, int nx, double xmin, double xmax,
518  const std::string& cut1, const std::string& cut2, double norm, const std::string& root_opt, const std::string& opt, const std::string& leg_name, bool pot_norm){
519 //**************************************************
520 
521  norm = GetNormalisationFactor(&sample1, &sample2, norm, pot_norm, opt);
522  DrawingToolsBase::DrawRatioTwoCuts(sample1.GetTree(),sample2.GetTree(),var,nx,xmin,xmax,cut1,cut2,root_opt,opt,leg_name,norm);
523 }
524 
525 //**************************************************
526 void DrawingTools::DrawRatio(DataSample& sample1, DataSample& sample2, const std::string& var, int nx, double* xbins,
527  const std::string& cut1, const std::string& cut2, double norm, const std::string& root_opt, const std::string& opt, const std::string& leg_name, bool pot_norm){
528 //**************************************************
529 
530  norm = GetNormalisationFactor(&sample1, &sample2, norm, pot_norm, opt);
531  DrawingToolsBase::DrawRatioTwoCuts(sample1.GetTree(),sample2.GetTree(),var,nx,xbins,cut1,cut2,root_opt,opt,leg_name,norm);
532 }
533 
534 //**************************************************
535 void DrawingTools::DrawRatio(DataSample& sample1, DataSample& sample2, const std::string& var, int nx, double xmin, double xmax,
536  const std::string& cut, double norm, const std::string& root_opt, const std::string& opt, const std::string& leg_name, bool pot_norm){
537 //**************************************************
538 
539  norm = GetNormalisationFactor(&sample1, &sample2, norm, pot_norm, opt);
540  DrawingToolsBase::DrawRatio(sample1.GetTree(),sample2.GetTree(),var,nx,xmin,xmax,cut,root_opt,opt,leg_name,norm);
541 }
542 
543 //**************************************************
544 void DrawingTools::DrawRatio(DataSample& sample1, DataSample& sample2, const std::string& var, int nx, double* xbins,
545  const std::string& cut, double norm, const std::string& root_opt, const std::string& opt, const std::string& leg_name, bool pot_norm){
546 //**************************************************
547 
548  norm = GetNormalisationFactor(&sample1, &sample2, norm, pot_norm, opt);
549  DrawingToolsBase::DrawRatio(sample1.GetTree(),sample2.GetTree(),var,nx,xbins,cut,root_opt,opt,leg_name,norm);
550 }
551 
552 //*********************************************************
553 void DrawingTools::DrawToys(DataSample& sample, const std::string& cut, const std::string& root_opt, const std::string& opt, const std::string& leg_name){
554 //*********************************************************
555 
556  DrawingToolsBase::DrawToys(sample.GetTree(), cut, root_opt, opt, leg_name);
557 }
558 
559 //*********************************************************
560 void DrawingTools::DrawToysRatio(DataSample& sample1, DataSample& sample2, const std::string& cut,
561  const std::string& root_opt, const std::string& opt, const std::string& leg_name, double norm, bool pot_norm){
562 //*********************************************************
563 
564  norm = GetNormalisationFactor(&sample1, &sample2, norm, pot_norm, opt);
565  DrawingToolsBase::DrawToysRatio(sample1.GetTree(), sample2.GetTree(), cut, root_opt,opt,leg_name,norm);
566 }
567 
568 //*********************************************************
569 void DrawingTools::DrawToysRatioTwoCuts(DataSample& sample1, DataSample& sample2, const std::string& cut1, const std::string& cut2,
570  const std::string& root_opt, const std::string& opt, const std::string& leg_name, double norm, bool pot_norm){
571 //*********************************************************
572 
573  norm = GetNormalisationFactor(&sample1, &sample2, norm, pot_norm);
574  DrawingToolsBase::DrawToysRatioTwoCuts(sample1.GetTree(), sample2.GetTree(), cut1, cut2, root_opt,opt,leg_name,norm);
575 }
576 
577 
578 //**************************************************
579 void DrawingTools::DrawRatioVSCut(DataSample& sample1, DataSample& sample2, const std::string& precut, int first_cut, int last_cut,
580  const std::string& root_opt, const std::string& opt, const std::string& leg, double norm, bool pot_norm){
581 //**************************************************
582 
583  DrawRatioVSCut(sample1,sample2,0,precut,first_cut,last_cut,root_opt,opt,leg,norm,pot_norm);
584 }
585 
586 //**************************************************
587 void DrawingTools::DrawRatioVSCut(DataSample& sample1, DataSample& sample2, int ibranch, const std::string& precut, int first_cut, int last_cut,
588  const std::string& root_opt, const std::string& opt, const std::string& leg, double norm, bool pot_norm){
589 //**************************************************
590 
591  // if selection exists
592  if (sel().GetSelection(ibranch,true)) {
593  int isel = ibranch;
594  std::cout << "Drawing for selection " << isel << ", branch 0" << std::endl;
595  return DrawRatioVSCut(sample1,sample2,isel,0,precut,first_cut,last_cut,root_opt,opt,leg,norm,pot_norm);
596  }
597 
598  DrawRatioVSCut(sample1,sample2,0,ibranch,precut,first_cut,last_cut,root_opt,opt,leg,norm,pot_norm);
599 }
600 
601 //**************************************************
602 void DrawingTools::DrawRatioVSCut(DataSample& sample1, DataSample& sample2, int isel, int ibranch, const std::string& precut, int first_cut, int last_cut,
603  const std::string& root_opt, const std::string& opt, const std::string& leg, double norm, bool pot_norm){
604 //**************************************************
605 
606  ReadOther(sample1.GetTree("config"));
607  norm = GetNormalisationFactor(&sample1, &sample2, norm, pot_norm, opt);
608  DrawingToolsBase::DrawRatioVSCut(sample1.GetTree(),sample2.GetTree(),isel, ibranch,precut,first_cut,last_cut,root_opt,opt,leg,norm);
609 }
610 
611 //*********************************************************
612 void DrawingTools::DrawEffPurVSCut(DataSample& sample, const std::string& signal, const std::string& precut, int first_cut, int last_cut,
613  const std::string& root_opt, const std::string& opt, const std::string& leg){
614 //*********************************************************
615 
616  DrawEffPurVSCut(sample,0,signal,precut,first_cut,last_cut, root_opt, opt, leg);
617 }
618 
619 //*********************************************************
620 void DrawingTools::DrawEffPurVSCut(DataSample& sample, int branch, const std::string& signal, const std::string& precut, int first_cut, int last_cut,
621  const std::string& root_opt, const std::string& opt, const std::string& leg){
622 //*********************************************************
623 
624  DrawEffPurVSCut(sample,0,branch,signal,precut,first_cut,last_cut, root_opt, opt, leg);
625 }
626 
627 //*********************************************************
628 void DrawingTools::DrawEffPurVSCut(DataSample& sample, int isel, int branch, const std::string& signal, const std::string& precut, int first_cut, int last_cut,
629  const std::string& root_opt, const std::string& opt, const std::string& leg){
630 //*********************************************************
631 
632  DrawEffPurVSCut(sample,isel,branch,signal,precut,first_cut,last_cut, first_cut,last_cut, root_opt, opt, leg);
633 }
634 
635 //*********************************************************
636 void DrawingTools::DrawEffPurVSCut(DataSample& sample, int isel, int branch, const std::string& signal, const std::string& precut,
637  int first_cut_pur, int last_cut_pur, int first_cut_eff, int last_cut_eff,
638  const std::string& root_opt, const std::string& opt, const std::string& leg){
639 //*********************************************************
640 
641  // Check if selection exists
642  if (!sel().GetSelection(isel,true)) return;
643 
644  std::string uopt = drawUtils::ToUpper(opt);
645 
646  // Check that all user options are valid
647  if (!drawUtils::ContainValidOptions(uopt)) return;
648 
649 
650  if (!sample.GetTree("truth")){
651  std::cout << "truth tree does not exists. Efficiency cannot be computed !!!" << std::endl;
652  return;
653  }
654 
655  // Read the min accum level to save from the config tree
656  ReadOther(sample.GetTree("config"));
657 
658  // save the current legend size
659  double sizex = _legendSize[0];
660  double sizey = _legendSize[1];
661 
662  // small legend size
663  SetLegendSize(0.1,0.1);
664 
665  // draw the efficiency
666  DrawingToolsBase::DrawEffVSCut(sample.GetTree("truth"),isel,branch,signal,precut,first_cut_eff,last_cut_eff, root_opt, opt,"eff "+leg);
667 
668  // draw the purity
669  DrawingToolsBase::DrawPurVSCut(sample.GetTree() ,isel,branch,signal,precut,first_cut_pur,last_cut_pur,(root_opt+" same").c_str(),opt,"pur "+leg);
670 
671  // go back to previous size
672  SetLegendSize(sizex,sizey);
673 }
674 
675 //*********************************************************
676 TH1_h* DrawingTools::GetHisto(DataSample& sample,const std::string& name, const std::string& var, int nx, double* xbins,
677  const std::string& cut, const std::string& root_opt, const std::string& opt, double scale, bool scale_errors){
678 //*********************************************************
679 
680  return GetHisto(sample.GetTree(), name,var,nx,xbins,cut,root_opt,opt,scale,scale_errors);
681 }
682 
683 //*********************************************************
684 TH1_h* DrawingTools::GetHisto(HistoStack* hs, TTree* tree,const std::string& name, const std::string& var, int nx, double* xbins,
685  const std::string& cut, const std::string& root_opt, const std::string& opt, double scale, bool scale_errors, int toy_ref){
686 //*********************************************************
687 
688  // This function overwrides the one of the base class.
689  // If an option (ST, SYS, DIS) is given only the reference toy experiment is plotted.
690 
691  toy_ref=-1;
692  // if (opt.find("ST")!= std::string::npos || opt.find("SYS")!= std::string::npos || opt.find("DIS")!= std::string::npos)
693  // toy_ref = GetToy_Reflysis(tree);
694 
695  // Call the base class function (the only thing it changed is the cut)
696  return DrawingToolsBase::GetHisto(hs, tree, name,var,nx,xbins,cut,root_opt,opt,scale,scale_errors,toy_ref);
697 }
698 
699 
700 //*********************************************************
701 TH1_h* DrawingTools::GetRatioHisto(TTree* tree1,TTree* tree2,const std::string& name, const std::string& var, int nx, double* xbins,
702  const std::string& cut1, const std::string& cut2, const std::string& root_opt, const std::string& opt, double norm, double scale, bool scale_errors, int toy_ref){
703 //*********************************************************
704 
705  // This function overwrides the one of the base class.
706  // If an option (ST, SYS, DIS) is given only the reference toy experiment is plotted.
707 
708  toy_ref=-1;
709  // if (opt.find("ST")!= std::string::npos || opt.find("SYS")!= std::string::npos || opt.find("DIS")!= std::string::npos)
710  // toy_ref = GetToy_Reflysis(tree1);
711 
712 
713  // Call the base class function (the only thing it changed is the cut)
714  return DrawingToolsBase::GetRatioHisto(tree1, tree2, name,var,nx,xbins,cut1,cut2,root_opt,opt,norm,scale,scale_errors,toy_ref);
715 }
716 
717 //**************************************************
718 void DrawingTools::FillGraphErrors(HistoStack* hs1, HistoStack* hs2, TGraphAsymmErrors* graph, const std::string uopt){
719 //**************************************************
720 
721  if (drawUtils::CheckInternalOption(uopt,"NOSYS")) return;
722  if (!drawUtils::CheckOption(uopt,"SYS")) return;
723 
724  Int_t nx = hs2->GetTotal1D()->GetNbinsX();
725 
726  if (hs1){
727  const TMatrixD& cov = syst_tools().GetRatioSystematicCov(hs1,hs2, uopt+" RELATIVE");
728  // Set the sqrt of the diagonal as error
729  for (int i=0;i<nx;i++){
730  double err_low = cov(i,i);
731  double err_high = err_low;
732  if (!drawUtils::CheckOption(uopt,"NOSTERROR")) {
733  err_low += graph->GetErrorYlow(i)*graph->GetErrorYlow(i);
734  err_high += graph->GetErrorYhigh(i)*graph->GetErrorYhigh(i);
735  }
736  graph->SetPointEYlow(i,sqrt(err_low));
737  graph->SetPointEYhigh(i,sqrt(err_high));
738  }
739  }
740  else{
741  const TMatrixD& cov = syst_tools().GetSystematicCov(hs2, uopt);
742  // Set the sqrt of the diagonal as error
743  for (int i=0;i<nx;i++){
744  Double_t err_low = cov(i,i);
745  Double_t err_high = err_low;
746  err_low += graph->GetErrorXlow(i+1)*graph->GetErrorXlow(i+1);
747  err_high += graph->GetErrorXhigh(i+1)*graph->GetErrorXhigh(i+1);
748  graph->SetPointEXlow(i+1,sqrt(err_low));
749  graph->SetPointEXhigh(i+1,sqrt(err_high));
750  }
751  }
752 }
753 
754 //**************************************************
755 void DrawingTools::FillHistoErrors(HistoStack* hs1, HistoStack* hs2, TH1_h* histo, const std::string uopt){
756 //**************************************************
757 
758  if (drawUtils::CheckInternalOption(uopt,"NOSYS")) return;
759  if (!drawUtils::CheckOption(uopt,"SYS")) return;
760 
761  Int_t nx = hs2->GetTotal1D()->GetNbinsX();
762 
763  if (hs1){
764  const TMatrixD& cov = syst_tools().GetRatioSystematicCov(hs1,hs2, uopt+" RELATIVE");
765  // Set the sqrt of the diagonal as error
766  for (int i=0;i<nx;i++){
767  double err = cov(i,i);
768  if (!drawUtils::CheckOption(uopt,"NOSTERROR")) {
769  err+= histo->GetBinError(i+1)*histo->GetBinError(i+1);
770  }
771  histo->SetBinError(i+1,sqrt(err));
772  }
773  }
774  else{
775  const TMatrixD& cov = syst_tools().GetSystematicCov(hs2, uopt);
776  // Set the sqrt of the diagonal as error
777  for (int i=0;i<nx;i++)
778  histo->SetBinError(i+1,sqrt(cov(i,i)));
779  }
780 
781 }
782 
783 //*********************************************************
784 void DrawingTools::FillHistoErrors(HistoStack* hs1, HistoStack* hs2, TTree* tree1, TTree* tree2, const std::string& name, const std::string& var, int nx, double* xbins,
785  const std::string& cut1, const std::string& cut2, const std::string& opt, double norm, TH1_h* hstat, TH1_h*& hsyst){
786 //*********************************************************
787 
788  (void)hstat;
789 
790  // This function overwrides the one of the base class
791  // It puts the appropriate errors into histrogram depending on the plotting options (opt)
792  // ST: plot only stat errors
793  // ST SYS: plot stat and syst errors in quadrature
794  // SYS: plot only systematic errors
795  // DIS: the error bar is the dispersion
796  // ST DIS: plot stat error and dispersion in quadrature
797  if(syst_tools().errdebug) std::cout<<"FillHistoErrors \n=============== "<<std::endl;
798 
799  std::string uopt = drawUtils::ToUpper(opt);
800  hsyst = NULL;
801  if (!drawUtils::CheckInternalOption(uopt,"NOSYS") && drawUtils::CheckOption(uopt,"SYS")){
802  // Compute the relative systematic errors
803  if(syst_tools().errdebug) std::cout<<" compute systematic errors cut1 "<<cut1<<" cut2 "<<cut2<<" name : "<<name<<std::endl;
804  hsyst = GetHistoWithSystErrors(hs1, hs2, tree1, tree2, name, var, nx, xbins, cut1, cut2, uopt+ " RELATIVE", norm);
805  }
806 }
807 
808 //*********************************************************
809 TH1_h* DrawingTools::GetHistoWithSystErrors(HistoStack* hs1, HistoStack* hs2, TTree* tree1, TTree* tree2, const std::string& name, const std::string& var, int nx, double* xbins,
810  const std::string& cut1, const std::string& cut2, const std::string& opt, double norm){
811 //*********************************************************
812  if(syst_tools().errdebug) std::cout<<"GetHistoWithSystErrors \n======================== "<<std::endl;
813 
814  (void)norm;
815 
816  // if specified (option "SYS") add systematics errors in quadrature
817  // option ST = statistics only
818  // option SYS = systematics only
819  // option SYS ST = systematics + statistical errors
820 
821  std::string uopt = drawUtils::ToUpper(opt);
822  // No systematics in those cases
823  // if (drawUtils::GetNToys(tree1)==1 || (drawUtils::CheckOption(uopt,"SYS") && drawUtils::CheckOption(uopt,"DIS"))){
824  // if (!drawUtils::CheckOption(uopt,"SYS") && !drawUtils::CheckOption(uopt,"DIS")){
825  if (!drawUtils::CheckOption(uopt,"SYS")){
826  return NULL;
827  }
828 
829  // Create histo to store systematics
830  TH1_h *hsyst = new TH1_h(GetUniqueName("hsyst_"+name).c_str(),"hsyst",nx,xbins);
831  _saved_histos.push_back(hsyst);
832 
833  TTree* tree_syst=NULL;
834  if (_treeForSystErrors)
835  tree_syst = _treeForSystErrors;
836  else
837  tree_syst = tree2;
838 
839  // compute the covariance matrix using the Systematics Tools singleton
840 
841  // const TMatrixD& cov = syst_tools().GetSystematicCov(tree_syst, var, nx, xbins, cut1, drawUtils::GetNToys(tree_syst), uopt);
842  syst_tools().UpdateSystematicCov(hs2, tree_syst, var, nx, xbins, cut2, drawUtils::GetNToys(tree_syst), uopt);
843  if (tree1){
844  syst_tools().UpdateSystematicCov(hs1, tree1, var, nx, xbins, cut1, drawUtils::GetNToys(tree1), uopt);
845  const TMatrixD& cov = syst_tools().GetRatioSystematicCov(hs1,hs2, uopt);
846  // Set the sqrt of the diagonal as error
847  for (int i=0;i<nx;i++)
848  hsyst->SetBinError(i+1,sqrt(cov(i,i)));
849  }
850  else{
851  const TMatrixD& cov = syst_tools().GetSystematicCov(hs2, uopt);
852  // Set the sqrt of the diagonal as error
853  for (int i=0;i<nx;i++)
854  hsyst->SetBinError(i+1,sqrt(cov(i,i)));
855  }
856  if(syst_tools().errdebug) std::cout<<" =>set to hall, the systematic error bars "<<std::endl;
857  return hsyst;
858 }
859 
860 //*********************************************************
861 void DrawingTools::UpdateSystInfo(HistoStack* hs1, HistoStack* hs2, TTree* tree1, TTree* tree2, const std::string& var, int nx, double* xbins,
862  const std::string& cut1, const std::string& cut2, const std::string& opt, double norm){
863 //*********************************************************
864 
865  if(syst_tools().errdebug) std::cout<<"UpdateSystInfo \n======================== "<<std::endl;
866 
867  (void)norm;
868 
869  // if specified (option "SYS") add systematics errors in quadrature
870  // option ST = statistics only
871  // option SYS = systematics only
872  // option SYS ST = systematics + statistical errors
873 
874  std::string uopt = drawUtils::ToUpper(opt);
875  // No systematics in those cases
876  // if (drawUtils::GetNToys(tree1)==1 || (drawUtils::CheckOption(uopt,"SYS") && drawUtils::CheckOption(uopt,"DIS"))){
877  // if ((!drawUtils::CheckOption(uopt,"SYS") && !drawUtils::CheckOption(uopt,"DIS"))){
878  if (!drawUtils::CheckOption(uopt,"SYS")){
879  return;
880  }
881 
882  TTree* tree_syst=NULL;
883  if (_treeForSystErrors)
884  tree_syst = _treeForSystErrors;
885  else
886  tree_syst = tree2;
887 
888  // update syst related histograms in the stacks using the Systematics Tools singleton
889 
890  // const TMatrixD& cov = syst_tools().GetSystematicCov(tree_syst, var, nx, xbins, cut1, drawUtils::GetNToys(tree_syst), uopt);
891  syst_tools().UpdateSystematicCov(hs2, tree_syst, var, nx, xbins, cut2, drawUtils::GetNToys(tree_syst), uopt);
892 
893  if(syst_tools().errdebug) std::cout<<" updated information for stack 2 "<<std::endl;
894 
895  if (tree1){
896  syst_tools().UpdateSystematicCov(hs1, tree1, var, nx, xbins, cut1, drawUtils::GetNToys(tree1), uopt);
897  if(syst_tools().errdebug) std::cout<<" updated information for stack 1 "<<std::endl;
898  }
899 
900  return;
901 
902 
903 }
904 
905 //*********************************************************
907 //*********************************************************
908 
909  sample.DumpPOT();
910 }
911 
912 //*********************************************************
914 //*********************************************************
915 
916  return sample.GetPOT();
917 }
918 
919 //*********************************************************
921 //*********************************************************
922 
923  return sample.GetNSpills();
924 }
925 
926 //*********************************************************
927 void DrawingTools::DumpPOT(Experiment& exp, const std::string& samplegroup_name) {
928 //*********************************************************
929 
930  exp.DumpPOT(samplegroup_name);
931 }
932 
933 //*********************************************************
934 double DrawingTools::GetPOTRatio(DataSample& sample1, DataSample& sample2, double POTsample1_byhand) {
935 //*********************************************************
936 
937  // so we must update it's values for the sample1 and sample2.
938 
939 
940  // Three options
941  // 1. sample1 and sample2 have standard POT values from the original files
942  // 2. either sample1 or sample2 have POT set by hand when creating the samples
943  // 3. there is no sample1 and sample2 is normalised to a POT value pass by argument to the drawing method (POTsample1p)
944 
945  double POTsample1 = POTsample1_byhand;
946  if (POTsample1<0){
947  POTsample1 = sample1.GetNorm();
948  if (POTsample1==0){
949  POTsample1 = sample1.GetPOT();
950  }
951  }
952 
953  double POTsample2 = sample2.GetNorm();
954  if (POTsample2==0 || POTsample2==1){
955 
956  // TODO: The sand muon factor. To be moved somewhere else
957  double sandFactor = 1;
958 #if !VERSION_HAS_OFFICIAL_POT
959  if (POTsample2==1)
960  sandFactor = 2.5e17;
961 #endif
962 
963  POTsample2 = sandFactor*sample2.GetPOT();
964  }
965 
966  double ratio;
967 
968  if (POTsample2 == 0) {
969  std::cout << "Warning: denominator in POT ratio is zero! Setting ratio to 1." << std::endl;
970  ratio = 1.;
971  } else if (POTsample1 == 0) {
972  std::cout << "Warning: numerator in POT ratio is zero! Setting ratio to 1." << std::endl;
973  ratio = 1.;
974  } else {
975  ratio = POTsample1 / POTsample2;
976  }
977 
978  return ratio;
979 }
980 
981 //*********************************************************
983 //*********************************************************
984  return exp.GetOverallPOTRatio();
985 }
986 
987 //*********************************************************
988 double DrawingTools::GetNormalisationFactor(DataSample* sample1,DataSample* sample2, double norm, bool pot_norm, const std::string& opt) {
989 //*********************************************************
990 
991  (void) pot_norm;
992 
993  std::string uopt = drawUtils::ToUpper(opt);
994 
995  // The option NOPOTNORM disables POT normalization
996  if (drawUtils::CheckOption(uopt,"NOPOTNORM")){
997  norm=1;
998  }
999  // By default POT normalization is used unless a valid normalization factor is given
1000  else if (norm<=0 && sample1 && sample2){
1001  norm = GetPOTRatio(*sample1, *sample2);
1002  }
1003  // When norm>0 and the POTNORM option is given, the second sample is normalized to the POT indicated by norm, regardless of the POT of sample 1
1004  else if (norm>0 && sample2 && drawUtils::CheckOption(uopt,"POTNORM")){
1005  norm = GetPOTRatio(*sample2, *sample2, norm); // sample1 may not exist, thus we give sample2 as dummy first argument
1006  }
1007  // otherwise, if the factor is still negative don't normalize
1008  else if (norm<=0)
1009  norm=1;
1010 
1011 
1012  // Otherwise the normalization factor is used to directly scale sample2 regardless of its POT
1013  return norm;
1014 }
1015 
1016 
1017 //*********************************************************
1018 void DrawingTools::DrawToys(Experiment& exp, const std::string& cut, const std::string& root_opt, const std::string& opt, const std::string& leg){
1019 //*********************************************************
1020 
1021  // Draw the distribution of entries for all toy experiments
1022  // The rms of this distribution is the systematic error
1023 
1024  std::string uopt = drawUtils::ToUpper(opt);
1025 
1026 
1027  // Check that all user options are valid
1028  if (!drawUtils::ContainValidOptions(uopt)) return;
1029 
1030  int ntoys = drawUtils::GetVarFromExperiment("NTOYS",exp);
1031  if (ntoys<=0) return;
1032 
1033  // Create temporary empty Histo Stacks
1034  HistoStack* hs2 = new HistoStack("dummy","","");
1035  HistoStack* hsw2 = new HistoStack("dummy","","");
1036 
1037  double xbins[NMAXBINS];
1038 
1039  // Project the Experiment into the HistoStack. Using 0 norm means that POT normalization is used when both samples are available
1040  // Project with no toy experiment weights
1041  Project(NULL, hs2, exp, "all","all", "toy_index",ntoys,GetVariableBins(ntoys,0,ntoys,xbins),0,NULL,"all",cut,root_opt,uopt+ " NOTOYW",0.,true);
1042 
1043  // Get the total histogram from the HistoStack
1044  TH1_h* h1 = hs2->GetTotal1D();
1045  TH1_h* hw = NULL;
1046 
1047  std::string cut2=cut;
1048  if (cut2=="") cut2="1==1";
1049 
1050  // Project the toy experiment PDF weights
1051  if (true){//(drawUtils::TreeHasVar(tree,"toy_weight")){
1052  Project(NULL, hsw2, exp, "all","all", "toy_index",ntoys,GetVariableBins(ntoys,0,ntoys,xbins),0,NULL,"all",cut,root_opt,uopt,0.,true);
1053  hw = hsw2->GetTotal1D();
1054  }
1055  else
1056  hw = h1;
1057 
1058  // compute the average toy exp weight
1059  TH1_h hwa(*hw);
1060  hwa.Divide(hw,h1);
1061 
1062  DrawToysBase(*h1,hwa,root_opt,uopt,leg);
1063 
1064  // delete the temporary HistoStacks
1065  delete hs2;
1066  delete hsw2;
1067 }
1068 
1069 //*********************************************************
1070 void DrawingTools::Draw(Experiment& exp, const std::string& var, int nx, double xmin, double xmax,
1071  const std::string& categ, const std::string& cut, const std::string& root_opt, const std::string& opt, double norm, bool scale_errors){
1072 //*********************************************************
1073 
1074  double xbins[NMAXBINS];
1075  Draw(exp,var,nx,GetVariableBins(nx,xmin,xmax,xbins),categ,cut,root_opt,opt,norm,scale_errors);
1076 }
1077 
1078 //*********************************************************
1079 void DrawingTools::Draw(Experiment& exp, const std::string& var, int nx, double xmin, double xmax, int ny, double ymin, double ymax,
1080  const std::string& categ, const std::string& cut, const std::string& root_opt, const std::string& opt, double norm, bool scale_errors){
1081 //*********************************************************
1082 
1083  double xbins[NMAXBINS];
1084  double ybins[NMAXBINS];
1085  Draw(exp,var,nx,GetVariableBins(nx,xmin,xmax,xbins),ny,GetVariableBins(ny,ymin,ymax,ybins),categ,cut,root_opt,opt,norm,scale_errors);
1086 }
1087 
1088 //*********************************************************
1089 void DrawingTools::Draw(Experiment& exp, const std::string& var, int nx, double* xbins,
1090  const std::string& categ, const std::string& cut, const std::string& root_opt, const std::string& opt, double norm, bool scale_errors){
1091 //*********************************************************
1092 
1093  double ybins[NMAXBINS];
1094  Draw(exp,var,nx,xbins,0,ybins,categ,cut,root_opt,opt,norm,scale_errors);
1095 }
1096 
1097 //*********************************************************
1098 void DrawingTools::Draw(Experiment& exp, const std::string& var, int nx, double* xbins, int ny, double* ybins,
1099  const std::string& categ, const std::string& cut, const std::string& root_opt, const std::string& opt, double norm, bool scale_errors){
1100 //*********************************************************
1101 
1102  Draw(exp,"all","all",var,nx,xbins,ny,ybins,categ,cut,root_opt,opt,norm,scale_errors);
1103 }
1104 
1105 //*********************************************************
1106 void DrawingTools::Draw(Experiment& exp, const std::string& groupName, const std::string& var, int nx, double xmin, double xmax,
1107  const std::string& categ, const std::string& cut, const std::string& root_opt, const std::string& opt, double norm, bool scale_errors){
1108 //*********************************************************
1109 
1110  double xbins[NMAXBINS];
1111  Draw(exp,groupName,var,nx,GetVariableBins(nx,xmin,xmax,xbins),categ,cut,root_opt,opt,norm,scale_errors);
1112 }
1113 
1114 //*********************************************************
1115 void DrawingTools::Draw(Experiment& exp, const std::string& groupName, const std::string& var, int nx, double xmin, double xmax, int ny, double ymin, double ymax,
1116  const std::string& categ, const std::string& cut, const std::string& root_opt, const std::string& opt, double norm, bool scale_errors){
1117 //*********************************************************
1118 
1119  double xbins[NMAXBINS];
1120  double ybins[NMAXBINS];
1121  Draw(exp,groupName,var,nx,GetVariableBins(nx,xmin,xmax,xbins),ny,GetVariableBins(ny,ymin,ymax,ybins),categ,cut,root_opt,opt,norm,scale_errors);
1122 }
1123 
1124 //*********************************************************
1125 void DrawingTools::Draw(Experiment& exp, const std::string& groupName, const std::string& var, int nx, double* xbins,
1126  const std::string& categ, const std::string& cut, const std::string& root_opt, const std::string& opt, double norm, bool scale_errors){
1127 //*********************************************************
1128 
1129  double ybins[NMAXBINS];
1130  Draw(exp,groupName,var,nx,xbins,0,ybins,categ,cut,root_opt,opt,norm,scale_errors);
1131 }
1132 
1133 //*********************************************************
1134 void DrawingTools::Draw(Experiment& exp, const std::string& groupName, const std::string& var, int nx, double* xbins, int ny, double* ybins,
1135  const std::string& categ, const std::string& cut, const std::string& root_opt, const std::string& opt, double norm, bool scale_errors){
1136 //*********************************************************
1137 
1138  Draw(exp,groupName,"all",var,nx,xbins,ny,ybins,categ,cut,root_opt,opt,norm,scale_errors);
1139 }
1140 
1141 //*********************************************************
1142 void DrawingTools::Draw(Experiment& exp, const std::string& groupName, const std::string& mcSampleName, const std::string& var, int nx, double xmin, double xmax,
1143  const std::string& categ, const std::string& cut, const std::string& root_opt, const std::string& opt, double norm, bool scale_errors){
1144 //*********************************************************
1145 
1146  double xbins[NMAXBINS];
1147  Draw(exp,groupName,mcSampleName,var,nx,GetVariableBins(nx,xmin,xmax,xbins),categ,cut,root_opt,opt,norm,scale_errors);
1148 }
1149 
1150 //*********************************************************
1151 void DrawingTools::Draw(Experiment& exp, const std::string& groupName, const std::string& mcSampleName, const std::string& var, int nx, double xmin, double xmax, int ny, double ymin, double ymax,
1152  const std::string& categ, const std::string& cut, const std::string& root_opt, const std::string& opt, double norm, bool scale_errors){
1153 //*********************************************************
1154 
1155  double xbins[NMAXBINS];
1156  double ybins[NMAXBINS];
1157  Draw(exp,groupName,mcSampleName,var,nx,GetVariableBins(nx,xmin,xmax,xbins),ny,GetVariableBins(ny,ymin,ymax,ybins),categ,cut,root_opt,opt,norm,scale_errors);
1158 }
1159 
1160 //*********************************************************
1161 void DrawingTools::Draw(Experiment& exp, const std::string& groupName, const std::string& mcSampleName, const std::string& var, int nx, double* xbins,
1162  const std::string& categ, const std::string& cut, const std::string& root_opt, const std::string& opt, double norm, bool scale_errors){
1163 //*********************************************************
1164 
1165  double ybins[NMAXBINS];
1166  Draw(exp,groupName,mcSampleName,var,nx,xbins,0,ybins,categ,cut,root_opt,opt,norm,scale_errors);
1167 }
1168 
1169 //*********************************************************
1170 void DrawingTools::Draw(Experiment& exp, const std::string& groupName, const std::string& mcSampleName, const std::string& var, int nx, double* xbins, int ny, double* ybins,
1171  const std::string& categ, const std::string& cut, const std::string& root_opt, const std::string& opt, double norm, bool scale_errors){
1172 //*********************************************************
1173 
1174  std::string uopt = drawUtils::ToUpper(opt);
1175 
1176  // Check that all user options are valid
1177  if (!drawUtils::ContainValidOptions(uopt)) return;
1178 
1179 
1180  if (groupName!="all"){
1181  if (!exp.HasSampleGroup(groupName)) return;
1182  }
1183 
1184  // Print purities when requested, and % on the legend
1185  std::string categ2 = categ;
1186  if (drawUtils::CheckOption(uopt,"PUR") && categ!="all"){
1187  std::string cut_range = AddRangeCut(var,nx,xbins,ny,ybins,cut,uopt);
1188  // Print purities when requested, and create categories with % on the name
1189  PrintPurities(exp, categ, cut_range,opt);
1190  categ2 += "_withPurities";
1191  }
1192 
1193  // Create empty Histo Stacks
1194  HistoStack* hs1 = NULL;
1195  HistoStack* hs2 = NULL;
1196  hs1 = new HistoStack(_title,_titleX,_titleY);
1197  hs2 = new HistoStack(_title,_titleX,_titleY);
1198  _saved_histoStacks.push_back(hs1);
1199  _saved_histoStacks.push_back(hs2);
1200 
1201  std::string slevel = GetSameLevel(root_opt);
1202 
1203  // Project the Experiment into the HistoStacks
1204  Project(hs1, hs2, exp, groupName, mcSampleName, var,nx,xbins,ny,ybins,categ2,cut,root_opt,uopt,norm,scale_errors);
1205 
1206  // Draw the Total Stack after all samples have been projected
1207  DrawingToolsBase::DrawHistoStacks(hs1,hs2,categ2,root_opt,opt,1);
1208 
1209 }
1210 
1211 
1212 //*********************************************************
1213 void DrawingTools::DrawRatio(Experiment& exp, const std::string& groupName, const std::string& mcSampleName, const std::string& var, int nx, double* xbins,
1214  const std::string& cut, const std::string& root_opt, const std::string& opt, const std::string& leg){
1215 //*********************************************************
1216 
1217  double ybins[NMAXBINS];
1218  DrawRatio(exp,groupName,mcSampleName,var,nx,xbins,0,ybins,cut,root_opt,opt,leg);
1219 }
1220 
1221 //*********************************************************
1222 void DrawingTools::DrawRatio(Experiment& exp, const std::string& groupName, const std::string& mcSampleName, const std::string& var, int nx, double xmin, double xmax,
1223  const std::string& cut, const std::string& root_opt, const std::string& opt, const std::string& leg){
1224 //*********************************************************
1225 
1226  double xbins[NMAXBINS];
1227  double ybins[NMAXBINS];
1228  DrawRatio(exp,groupName,mcSampleName,var,nx,GetVariableBins(nx,xmin,xmax,xbins),0,ybins,cut,root_opt,opt,leg);
1229 }
1230 
1231 //*********************************************************
1232 void DrawingTools::DrawRatio(Experiment& exp, const std::string& var, int nx, double* xbins,
1233  const std::string& cut, const std::string& root_opt, const std::string& opt, const std::string& leg){
1234 //*********************************************************
1235 
1236  DrawRatio(exp,"all","all",var,nx,xbins,cut,root_opt,opt,leg);
1237 }
1238 
1239 //*********************************************************
1240 void DrawingTools::DrawRatio(Experiment& exp, const std::string& var, int nx, double xmin, double xmax,
1241  const std::string& cut, const std::string& root_opt, const std::string& opt, const std::string& leg){
1242 //*********************************************************
1243 
1244  DrawRatio(exp,"all","all",var,nx,xmin,xmax,cut,root_opt,opt,leg);
1245 }
1246 
1247 //*********************************************************
1248 void DrawingTools::DrawRatio(Experiment& exp, const std::string& groupName, const std::string& mcSampleName, const std::string& var, int nx, double* xbins, int ny, double* ybins,
1249  const std::string& cut, const std::string& root_opt, const std::string& opt, const std::string& leg){
1250 //*********************************************************
1251 
1252  if (groupName!="all"){
1253  if (!exp.HasSampleGroup(groupName)) return;
1254  }
1255 
1256  std::string uopt = drawUtils::ToUpper(opt);
1257 
1258  // Check that all user options are valid
1259  if (!drawUtils::ContainValidOptions(uopt)) return;
1260 
1261  // Create empty Histo Stacks
1262  HistoStack* hs1 = new HistoStack(_title,_titleX,_titleY);
1263  HistoStack* hs2 = new HistoStack(_title,_titleX,_titleY);
1264  _saved_histoStacks.push_back(hs1);
1265  _saved_histoStacks.push_back(hs2);
1266 
1267  // Project the Experiment into the HistoStacks. Using 0 norm means that POT normalization is used when both samples are available
1268  Project(hs1, hs2, exp, groupName, mcSampleName, var,nx,xbins,ny,ybins,"all",cut,root_opt,uopt,0.,true);
1269 
1270  // Draw the HistoStacks
1271  DrawRatioHistoStacks(hs1,hs2,root_opt,uopt,0.,leg);
1272 
1273 
1274  // get the ratio histogram with proper errors
1275  // TH1_h* ratio = GetRatioHisto(hs1,hs2, uopt);
1276 
1277  // Draw the ratio histogram
1278  // DrawRatio(ratio,root_opt,uopt,leg);
1279 }
1280 
1281 //*********************************************************
1282 void DrawingTools::AnalysisResults(Experiment& exp, const std::string& cut, const std::string& opt, const std::string& categ){
1283 //*********************************************************
1284 
1285  AnalysisResults(exp,"all","all",cut,opt,categ);
1286 }
1287 
1288 //*********************************************************
1289 void DrawingTools::AnalysisResults(Experiment& exp, const std::string& groupName, const std::string& mcSampleName, const std::string& cut, const std::string& opt, const std::string& categ){
1290 //*********************************************************
1291 
1292  std::string uopt = drawUtils::ToUpper(opt);
1293 
1294  // Check that all user options are valid
1295  if (!drawUtils::ContainValidOptions(uopt)) return;
1296 
1297 
1298  // Create empty Histo Stacks
1299  HistoStack* hs1 = NULL;
1300  HistoStack* hs2 = NULL;
1301 
1302  if (!drawUtils::CheckOption(uopt,"NODATA")){
1303  hs1 = new HistoStack(_title,_titleX,_titleY);
1304  _saved_histoStacks.push_back(hs1);
1305  }
1306  if (!drawUtils::CheckOption(uopt,"NOMC")){
1307  hs2 = new HistoStack(_title,_titleX,_titleY);
1308  _saved_histoStacks.push_back(hs2);
1309  }
1310 
1311  double xbins[2]={0.,1.};
1312  double *ybins = NULL;
1313 
1314  // Project the Experiment into the HistoStack. Using 0 norm means that POT normalization is used when both samples are available
1315  Project(hs1, hs2, exp, groupName, mcSampleName, "0.5",1,xbins,0,ybins,"all",cut,"",opt,0.,true);
1316 
1317  double N1 = hs1->GetTotal1D()->GetBinContent(1);
1318  double N2 = hs2->GetTotal1D()->GetBinContent(1);
1319  double est1 = hs1->GetTotal1D()->GetBinError(1);
1320  double est2 = hs2->GetTotal1D()->GetBinError(1);
1321  double esys2 = 0;
1322  if (hs2->GetTotalSyst1D()){
1323  est2 = hs2->GetTotalStat1D()->GetBinError(1);
1324  esys2 = hs2->GetTotalSyst1D()->GetBinError(1);
1325  }
1326 
1327 
1328  // compute data/MC ratio and its error
1329  Double_t ratio = N1/N2;
1330  Double_t ratio_stat = sqrt(pow(est1/N2,2)+ pow(N1/(N2*N2)*est2,2));
1331  Double_t ratio_syst = N1/(N2*N2)*esys2;
1332 
1333  std::cout << " --------------------------------------------------------" << std::endl;
1334  std::cout << " Analysis results for " << cut << std::endl;
1335  std::cout << " --------------------------------------------------------" << std::endl;
1336  char out1[256];
1337  char out2[256];
1338  char out3[256];
1339  char out4[256];
1340  sprintf(out1,"%-10s: %-12s %-12s %-12s", "sample","events", "stat error", "syst error");
1341  sprintf(out2,"%-10s: %-12.2f %-12.2f %-12.2f", "data", N1, est1, 0.);
1342  sprintf(out3,"%-10s: %-12.2f %-12.2f %-12.2f", "mc", N2, est2, esys2);
1343  sprintf(out4,"%-10s: %-12.3f %-12.3f %-12.4f", "ratio",ratio, ratio_stat, ratio_syst);
1344  std::cout << out1 << std::endl;
1345  std::cout << " --------------------------------------------------------" << std::endl;
1346  std::cout << out2 << std::endl;
1347  std::cout << out3 << std::endl;
1348  std::cout << out4 << std::endl;
1349 
1350  // Print purities when requested
1351  if (drawUtils::CheckOption(uopt,"PUR") && categ!="all")
1352  PrintPurities(exp,categ,cut,uopt);
1353 }
1354 
1355 //**************************************************
1356 void DrawingTools::DrawEventsVSCut(Experiment& exp, const std::string& cut_norm, int first_cut, int last_cut,
1357  const std::string& root_opt, const std::string& opt, const std::string& leg){
1358 //**************************************************
1359 
1360  DrawEventsVSCut(exp,0,cut_norm,first_cut,last_cut,root_opt,opt,leg);
1361 }
1362 
1363 //**************************************************
1364 void DrawingTools::DrawEventsVSCut(Experiment& exp, int branch, const std::string& cut_norm, int first_cut, int last_cut,
1365  const std::string& root_opt, const std::string& opt, const std::string& leg){
1366 //**************************************************
1367 
1368  DrawEventsVSCut(exp,0,branch,cut_norm,first_cut,last_cut,root_opt,opt,leg);
1369 }
1370 
1371 //**************************************************
1372 void DrawingTools::DrawEventsVSCut(Experiment& exp, int isel, int branch, const std::string& cut_norm, int first_cut, int last_cut,
1373  const std::string& root_opt, const std::string& opt, const std::string& leg){
1374 //**************************************************
1375 
1376  // Read the steps from the config tree
1377  // ReadSteps(_config_file);
1378 
1379  // Check if selection exists
1380  if (!sel().GetSelection(isel,true)) return;
1381 
1382  std::string slevel = GetSameLevel(root_opt);
1383  std::string uopt = drawUtils::ToUpper(opt);
1384 
1385  // Check that all user options are valid
1386  if (!drawUtils::ContainValidOptions(uopt)) return;
1387 
1388 
1389  // Get the event vs cuts for both data and MC
1390  TH1_h* hdata;
1391  TH1_h* hmc ;
1392  GetEventsVSCut(exp,"events",cut_norm,isel,branch,first_cut, last_cut,root_opt,uopt,hdata,hmc);
1393 
1394 
1395  // Create the legend
1396  if (slevel=="0" && (leg!="" || (hdata && hmc))){
1397  // save the current legend size
1398  double sizex = _legendSize[0];
1399  double sizey = _legendSize[1];
1400 
1401  // small legend size
1402  SetLegendSize(0.2,0.2);
1403 
1404  CreateLegend();
1405 
1406  // go back to previous size
1407  SetLegendSize(sizex,sizey);
1408  }
1409 
1410  // Set cut names
1411  TH1_h* hall;
1412  if (hdata) hall = hdata;
1413  else hall = hmc;
1414 
1415  Int_t cut_offset = 0;
1416  // First bin corresponds to no cut
1417  if (first_cut ==-1){
1418  hall->GetXaxis()->SetBinLabel(1, "NO CUT");
1419  cut_offset = 1;
1420  }
1421 
1422  std::vector<StepBase*> cuts = sel().GetSelection(isel)->GetCutsInBranch(branch);
1423  // Start from second bin since first corresponds to no cut
1424  for (int i=cut_offset;i<hall->GetNbinsX();i++ ){
1425  int icut = first_cut+i;
1426  hall->GetXaxis()->SetBinLabel(i+1, cuts[icut]->Title().c_str());
1427  }
1428 
1429  // No error in X
1430  gStyle->SetErrorX(0.0001);
1431 
1432  hall->SetMarkerStyle(21);
1433 
1434  // Draw the data and MC histos
1435  if (hdata)
1436  DrawHisto(hdata, _auto_colors[_same_level], _line_width, _auto_colors[_same_level], _fill_style, "pl e"+root_opt, uopt+" NOSTAT NOLEG");
1437 
1438  if (hmc){
1439  if (hdata){
1440  slevel = GetSameLevel("same");
1441  DrawHisto(hmc, _auto_colors[_same_level], _line_width, _auto_colors[_same_level], _fill_style, "pl e same "+root_opt, uopt+" NOSTAT NOLEG");
1442  }
1443  else
1444  DrawHisto(hmc, _auto_colors[_same_level], _line_width, _auto_colors[_same_level], _fill_style, "pl e "+root_opt, uopt+" NOSTAT NOLEG");
1445  }
1446 
1447  hall->GetXaxis()->SetTitle("");
1448  hall->GetYaxis()->SetTitle("# events");
1449 
1450  // Add an entry to the legend if requested
1451  if (!drawUtils::CheckOption(uopt,"NOLEG")){
1452  if (leg!="" || (hdata && hmc)){
1453  if (hdata && !hmc) _legends.back()->AddEntry( hdata, leg.c_str(),"LE1P");
1454  if (!hdata && hmc) _legends.back()->AddEntry( hmc, leg.c_str(),"LE1P");
1455  if (hdata && hmc){
1456  _legends.back()->AddEntry( hdata, ("data "+leg).c_str(),"LE1P");
1457  _legends.back()->AddEntry( hmc, ("MC "+leg).c_str(),"LE1P");
1458  }
1459  _legends.back()->Draw();
1460  }
1461  }
1462  if (!drawUtils::CheckOption(uopt,"NODRAW"))
1463  gPad->Update();
1464 
1465  // reset error in X
1466  gStyle->SetErrorX();
1467 
1468 
1469 
1470  // Print numbers on the screen
1471 
1472  char out1[256];
1473  char out2[256];
1474 
1475  std::cout << " ------------- Events vs cut ---------------------------------- " << std::endl;
1476  for (int i=0;i<hall->GetNbinsX();i++ ){
1477  int icut = first_cut+i;
1478  std::string cut_name="";
1479  if (icut==-1)
1480  cut_name = "NO CUT";
1481  else
1482  cut_name = cuts[icut]->Title();
1483 
1484  if (hdata && hmc){
1485  sprintf(out1,"%3s: %-25s %-10s %-10s", "#", "cut", "data", "MC");
1486  sprintf(out2,"%3d: %-25s %-10.2f %-10.2f", icut, cut_name.c_str(), hdata->GetBinContent(i+1), hmc->GetBinContent(i+1));
1487  }
1488  else if (hdata){
1489  sprintf(out1,"%3s: %-25s %-10s", "#", "cut", "data");
1490  sprintf(out2,"%3d: %-25s %-10.2f", icut, cut_name.c_str(), hdata->GetBinContent(i+1));
1491  }
1492  else if (hmc){
1493  sprintf(out1,"%3s: %-25s %-10s", "#", "cut", "MC");
1494  sprintf(out2,"%3d: %-25s %-10.2f", icut, cut_name.c_str(), hmc->GetBinContent(i+1));
1495  }
1496 
1497  if (i==0) std::cout << out1 << std::endl;
1498  std::cout << out2 << std::endl;
1499  }
1500 }
1501 
1502 //**************************************************
1503 void DrawingTools::DrawRatioVSCut(Experiment& exp, const std::string& precut, int first_cut, int last_cut,
1504  const std::string& root_opt, const std::string& opt, const std::string& leg){
1505 //**************************************************
1506 
1507  DrawRatioVSCut(exp,0,precut,first_cut,last_cut,root_opt,opt,leg);
1508 }
1509 
1510 //**************************************************
1511 void DrawingTools::DrawRatioVSCut(Experiment& exp, int branch, const std::string& precut, int first_cut, int last_cut,
1512  const std::string& root_opt, const std::string& opt, const std::string& leg){
1513 //**************************************************
1514 
1515  DrawRatioVSCut(exp,0,branch,precut,first_cut,last_cut,root_opt,opt,leg);
1516 }
1517 
1518 //**************************************************
1519 void DrawingTools::DrawRatioVSCut(Experiment& exp, int isel, int branch, const std::string& precut, int first_cut, int last_cut,
1520  const std::string& root_opt, const std::string& opt, const std::string& leg){
1521 //**************************************************
1522 
1523  // Check if selection exists
1524  if (!sel().GetSelection(isel,true)) return;
1525 
1526  std::string uopt = drawUtils::ToUpper(opt);
1527 
1528  // Check that all user options are valid
1529  if (!drawUtils::ContainValidOptions(uopt)) return;
1530 
1531  std::string slevel = GetSameLevel(root_opt);
1532  if (slevel=="0" && leg!="")
1533  CreateLegend();
1534 
1535  TH1_h* hdata;
1536  TH1_h* hmc;
1537  Int_t first_cut2=-1;
1538  GetEventsVSCut(exp,"ratio",precut,isel,branch,first_cut2, last_cut,root_opt,uopt,hdata,hmc);
1539 
1540  if (!hdata || !hmc){
1541  std::cout << "Cannot compute ratio because either data or MC histos are empty" << std::endl;
1542  return;
1543  }
1544 
1545  std::cout << "----- Data/MC ratio values -----------" << std::endl;
1546  DrawingToolsBase::DrawRatioVSCut(hdata,hmc,isel,branch,first_cut,root_opt,uopt,leg);
1547 }
1548 
1549 //**************************************************
1550 void DrawingTools::DrawPurVSCut(Experiment& exp, const std::string& signal, const std::string& precut, int first_cut, int last_cut,
1551  const std::string& root_opt, const std::string& opt, const std::string& leg){
1552 //**************************************************
1553 
1554  DrawPurVSCut(exp,0,signal,precut,first_cut,last_cut,root_opt, opt, leg);
1555 }
1556 
1557 //**************************************************
1558 void DrawingTools::DrawPurVSCut(Experiment& exp, int branch, const std::string& signal, const std::string& precut, int first_cut, int last_cut,
1559  const std::string& root_opt, const std::string& opt, const std::string& leg){
1560 //**************************************************
1561 
1562  DrawPurVSCut(exp,0,branch,signal,precut,first_cut,last_cut,root_opt, opt, leg);
1563 }
1564 
1565 //**************************************************
1566 void DrawingTools::DrawPurVSCut(Experiment& exp, int isel, int branch, const std::string& signal, const std::string& precut, int first_cut, int last_cut,
1567  const std::string& root_opt, const std::string& opt, const std::string& leg){
1568 //**************************************************
1569 
1570  // Check if selection exists
1571  if (!sel().GetSelection(isel,true)) return;
1572 
1573  std::string uopt = drawUtils::ToUpper(opt);
1574 
1575  // Check that all user options are valid
1576  if (!drawUtils::ContainValidOptions(uopt)) return;
1577 
1578  std::string slevel = GetSameLevel(root_opt);
1579  if (slevel=="0" && leg!="")
1580  CreateLegend();
1581 
1582  std::string numer = "";
1583  if (signal == "") {
1584  numer = precut;
1585  } else if (precut == "") {
1586  numer = signal;
1587  } else {
1588  numer = signal+"&&"+precut;
1589  }
1590 
1591  // Histogram for cut1+cut2 (numerator)
1592  TH1_h* hdata;
1593  TH1_h* hmc1, *hmc2 ;
1594  Int_t first_cut2=-1;
1595  GetEventsVSCut(exp,"pur1",numer,isel,branch,first_cut2, last_cut,root_opt,uopt,hdata,hmc1);
1596 
1597  // Histogram for cut2 (denominator)
1598  GetEventsVSCut(exp,"pur2",precut,isel,branch,first_cut2, last_cut,root_opt,uopt,hdata,hmc2);
1599 
1600  if (!hmc1 || !hmc2){
1601  std::cout << "Cannot compute purity because the experiment does not have any MC sample" << std::endl;
1602  return;
1603  }
1604 
1605  std::cout << "----- Purity values -----------" << std::endl;
1606  DrawingToolsBase::DrawRatioVSCut(hmc1,hmc2,isel,branch,first_cut,root_opt,uopt+ " EFF",leg);
1607 }
1608 
1609 //**************************************************
1610 void DrawingTools::DrawEffVSCut(Experiment& exp, const std::string& signal, const std::string& precut, int first_cut, int last_cut,
1611  const std::string& root_opt, const std::string& opt, const std::string& leg){
1612 //**************************************************
1613 
1614  DrawEffVSCut(exp,0,signal,precut,first_cut,last_cut,root_opt, opt, leg);
1615 }
1616 
1617 //**************************************************
1618 void DrawingTools::DrawEffVSCut(Experiment& exp, int branch, const std::string& signal, const std::string& precut, int first_cut, int last_cut,
1619  const std::string& root_opt, const std::string& opt, const std::string& leg){
1620 //**************************************************
1621 
1622  DrawEffVSCut(exp,0,branch,signal,precut,first_cut,last_cut,root_opt, opt, leg);
1623 }
1624 
1625 //**************************************************
1626 void DrawingTools::DrawEffVSCut(Experiment& exp, int isel, int branch, const std::string& signal, const std::string& precut, int first_cut, int last_cut,
1627  const std::string& root_opt, const std::string& opt, const std::string& leg){
1628 //**************************************************
1629 
1630  // Check if selection exists
1631  if (!sel().GetSelection(isel,true)) return;
1632 
1633  std::string uopt = drawUtils::ToUpper(opt);
1634 
1635  // Check that all user options are valid
1636  if (!drawUtils::ContainValidOptions(uopt)) return;
1637 
1638  std::string slevel = GetSameLevel(root_opt);
1639  if (slevel=="0" && leg!="")
1640  CreateLegend();
1641 
1642  std::string numer = "";
1643  if (signal == "") {
1644  numer = precut;
1645  } else if (precut == "") {
1646  numer = signal;
1647  } else {
1648  numer = signal+"&&"+precut;
1649  }
1650 
1651  // Get the current tree name
1652  std::string tree_name = exp.GetCurrentTree();
1653 
1654  // use the "truth" tree for efficiencies
1655  exp.SetCurrentTree("truth");
1656 
1657  // Histogram for cut1+cut2 (numerator)
1658  TH1_h* hdata;
1659  TH1_h* hmc1;
1660  Int_t first_cut2=-1;
1661  GetEventsVSCut(exp,"eff1",numer,isel,branch,first_cut2, last_cut,root_opt,uopt,hdata,hmc1);
1662 
1663  if (!hmc1){
1664  std::cout << "Cannot compute efficiency because the experiment does not have any MC sample" << std::endl;
1665  return;
1666  }
1667 
1668  // go back to the previous tree name
1669  exp.SetCurrentTree(tree_name);
1670 
1671  // Histogram for cut2 (denominator)
1672  int nx = hmc1->GetNbinsX();
1673  double xmin = hmc1->GetXaxis()->GetXmin();
1674  double xmax = hmc1->GetXaxis()->GetXmax();
1675  double xbins[NMAXBINS];
1676  TH1_h* hmc2 = new TH1_h(GetUniqueName("eff2").c_str(),"eff2",nx,GetVariableBins(nx,xmin,xmax,xbins));
1677  _saved_histos.push_back(hmc2);
1678 
1679  for (int i=0; i<hmc2->GetNbinsX();i++){
1680  hmc2->SetBinContent(i+1,hmc1->GetBinContent(1));
1681  hmc2->SetBinError( i+1,hmc1->GetBinError(1));
1682  }
1683 
1684  std::cout << "----- Efficiency values -----------" << std::endl;
1685  DrawingToolsBase::DrawRatioVSCut(hmc1,hmc2,isel,branch,first_cut,root_opt,uopt+" EFF",leg);
1686 }
1687 
1688 //*********************************************************
1689 void DrawingTools::DrawEffPurVSCut(Experiment& exp, const std::string& signal, const std::string& precut, int first_cut, int last_cut,
1690  const std::string& root_opt, const std::string& opt, const std::string& leg){
1691 //*********************************************************
1692 
1693  DrawEffPurVSCut(exp,0,signal,precut,first_cut,last_cut, root_opt, opt, leg);
1694 }
1695 
1696 
1697 //*********************************************************
1698 void DrawingTools::DrawEffPurVSCut(Experiment& exp, int branch, const std::string& signal, const std::string& precut, int first_cut, int last_cut,
1699  const std::string& root_opt, const std::string& opt, const std::string& leg){
1700 //*********************************************************
1701 
1702  DrawEffPurVSCut(exp,0,branch,signal,precut,first_cut,last_cut, root_opt, opt, leg);
1703 }
1704 
1705 //*********************************************************
1706 void DrawingTools::DrawEffPurVSCut(Experiment& exp, int isel, int branch, const std::string& signal, const std::string& precut, int first_cut, int last_cut,
1707  const std::string& root_opt, const std::string& opt, const std::string& leg){
1708 //*********************************************************
1709 
1710  DrawEffPurVSCut(exp,isel,branch,signal,precut,first_cut,last_cut, first_cut,last_cut, root_opt, opt, leg);
1711 }
1712 
1713 //*********************************************************
1714 void DrawingTools::DrawEffPurVSCut(Experiment& exp, int isel, int branch, const std::string& signal, const std::string& precut,
1715  int first_cut_pur, int last_cut_pur, int first_cut_eff, int last_cut_eff,
1716  const std::string& root_opt, const std::string& opt, const std::string& leg){
1717 //*********************************************************
1718 
1719  // Check if selection exists
1720  if (!sel().GetSelection(isel,true)) return;
1721 
1722  std::string uopt = drawUtils::ToUpper(opt);
1723 
1724  // Check that all user options are valid
1725  if (!drawUtils::ContainValidOptions(uopt)) return;
1726 
1727  // save the current legend size
1728  double sizex = _legendSize[0];
1729  double sizey = _legendSize[1];
1730 
1731  // small legend size
1732  SetLegendSize(0.1,0.1);
1733 
1734  // draw the efficiency
1735  DrawEffVSCut(exp,isel,branch,signal,precut,first_cut_eff,last_cut_eff,root_opt, opt,"eff "+leg);
1736 
1737  // draw the purity
1738  DrawPurVSCut(exp,isel,branch,signal,precut,first_cut_pur,last_cut_pur,(root_opt+" same").c_str(),opt,"pur "+leg);
1739 
1740  // go back to previous size
1741  SetLegendSize(sizex,sizey);
1742 }
1743 
1744 //*********************************************************
1745 double DrawingTools::GetEff(Experiment& exp, bool usedata,
1746  const std::string& cut1, const std::string& cut2, const std::string& root_opt, const std::string& opt) {
1747 //*********************************************************
1748  double errhigh = 0.;
1749  double errlow = 0.;
1750  double nev1 = 0.;
1751  double nev2 = 0.;
1752  return GetEff(exp, usedata, errlow, errhigh, nev1, nev2, cut1, cut2, root_opt, opt);
1753 }
1754 
1755 //*********************************************************
1756 double DrawingTools::GetEff(Experiment& exp, bool usedata, double& errlow, double& errhigh, double& nev1, double& nev2,
1757  const std::string& cut1, const std::string& cut2, const std::string& root_opt, const std::string& opt) {
1758 //*********************************************************
1759 
1760  errlow = 0;
1761  errhigh = 0;
1762  nev1 = 0;
1763  nev2 = 0;
1764  std::string slevel = GetSameLevel(root_opt);
1765 
1766  std::string uopt = drawUtils::ToUpper(opt);
1767 
1768  // Check that all user options are valid
1769  if (!drawUtils::ContainValidOptions(uopt)) return 0;
1770 
1771 
1772  // Need to project against a variable. "NWEIGHTS" is stored in all trees.
1773  std::string var = "NWEIGHTS";
1774  int nx = 1;
1775  double xbins[2] = {-1e6, 1e6};
1776 
1777  bool scale_errors = true;
1778 
1779  TGraphAsymmErrors* eff = GetEff(exp, usedata, var, nx, xbins, nev1, nev2, cut1, cut2, root_opt, opt, scale_errors);
1780  if (!eff) return 0;
1781 
1782  if (eff->GetN() != 1) {
1783  std::cout << "Error computing efficiency" << std::endl;
1784  return 0;
1785  }
1786 
1787  errlow = eff->GetEYlow()[0];
1788  errhigh = eff->GetEYhigh()[0];
1789 
1790  return eff->GetY()[0];
1791 }
1792 
1793 //*********************************************************
1794 TGraphAsymmErrors* DrawingTools::GetEff(Experiment& exp, bool usedata, const std::string& var, int nx, double* xbins, double& nev1, double& nev2,
1795  const std::string& cut1, const std::string& cut2, const std::string& root_opt, const std::string& opt, bool scale_errors) {
1796 //*********************************************************
1797 
1798  // Create empty Histo Stacks
1799  HistoStack* hs1d = NULL;
1800  HistoStack* hs2d = NULL;
1801  HistoStack* hs1m = NULL;
1802  HistoStack* hs2m = NULL;
1803  if (!drawUtils::CheckOption(opt,"NODATA")){
1804  hs1d = new HistoStack(_title,_titleX,_titleY);
1805  hs2d = new HistoStack(_title,_titleX,_titleY);
1806  }
1807  if (!drawUtils::CheckOption(opt,"NOMC")){
1808  hs1m = new HistoStack(_title,_titleX,_titleY);
1809  hs2m = new HistoStack(_title,_titleX,_titleY);
1810  }
1811 
1812  std::string groupName = "all";
1813  std::string mcSampleName = "all";
1814  std::string categ = "all";
1815  std::string newopt = opt + " NOVARBIN";
1816 
1817  // Get the current tree name
1818  std::string tree_name = exp.GetCurrentTree();
1819 
1820  // use the "truth" tree for efficiencies and "default" for purities
1821  if (newopt.find("PUR")==std::string::npos && newopt.find("NOTRUTH")==std::string::npos)
1822  exp.SetCurrentTree("truth");
1823 
1824  int ny = 0;
1825  double ybins[1] = {0};
1826 
1827  // Project the Experiment into the HistoStacks. Using 0 norm means that POT normalization is used when both samples are available
1828  Project(hs1d, hs1m, exp, groupName, mcSampleName, var,nx,xbins,ny,ybins,categ,(cut1+" && "+cut2),root_opt,newopt,0.,scale_errors);
1829  Project(hs2d, hs2m, exp, groupName, mcSampleName, var,nx,xbins,ny,ybins,categ, cut2, root_opt,newopt,0.,scale_errors);
1830 
1831  // go back to the previous tree name
1832  if (newopt.find("PUR")==std::string::npos && newopt.find("NOTRUTH")==std::string::npos)
1833  exp.SetCurrentTree(tree_name);
1834 
1835  // h1 = Histogram for cut1+cut2 (numerator)
1836  // h2 = Histogram for cut2 (denominator)
1837  TH1_h* h1;
1838  TH1_h* h2;
1839  if (usedata) {
1840  h1 = hs1d->GetTotal1D();
1841  h2 = hs2d->GetTotal1D();
1842  } else {
1843  h1 = hs1m->GetTotal1D();
1844  h2 = hs2m->GetTotal1D();
1845  }
1846 
1847  if (!h1){
1848  std::cout << "ERROR. numerator does not exist !!!" << std::endl;
1849  return NULL;
1850  }
1851  if (!h2){
1852  std::cout << "ERROR. denominator does not exist !!!" << std::endl;
1853  return NULL;
1854  }
1855 
1856 
1857  nev1 = h1->Integral(0, h1->GetNbinsX() + 1);
1858  nev2 = h2->Integral(0, h2->GetNbinsX() + 1);
1859 
1860  if (h1->GetSumw2N()==0) h1->Sumw2();
1861  if (h2->GetSumw2N()==0) h2->Sumw2();
1862 
1863  // compute the efficiency
1864  TGraphAsymmErrors* eff = new TGraphAsymmErrors(h1);
1865  _saved_graphs.push_back(eff);
1866  eff->Divide(h1, h2, _eff_params.c_str()); //the options are explicitely provided by SetEffDivideParams(const std::string&), root_opt not used to avoid possible confusions
1867 
1868  // Put the errors into the ratio
1869  if (usedata)
1870  FillGraphErrors(hs1d, hs2d, eff, opt);
1871  else
1872  FillGraphErrors(hs1m, hs2m, eff, opt);
1873 
1874 
1875  if (hs1d) delete hs1d;
1876  if (hs2d) delete hs2d;
1877  if (hs1m) delete hs1m;
1878  if (hs2m) delete hs2m;
1879 
1880 
1881  return eff;
1882 }
1883 
1884 //*********************************************************
1885 TGraphAsymmErrors* DrawingTools::GetEffNew(Experiment& exp, bool usedata, const std::string& var, int nx, double* xbins, double& nev1, double& nev2,
1886  const std::string& cut1, const std::string& cut2, const std::string& root_opt, const std::string& opt1,
1887  const std::string& opt2, bool scale_errors) {
1888 //*********************************************************
1889 
1890  // Create empty Histo Stacks
1891  HistoStack* hs1d = NULL;
1892  HistoStack* hs2d = NULL;
1893  HistoStack* hs1m = NULL;
1894  HistoStack* hs2m = NULL;
1895 
1896  // both opt1 and opt2 must contain the option "NODATA" or "NOMC"
1897  if (!drawUtils::CheckOption(opt1,"NODATA")){
1898  hs1d = new HistoStack(_title,_titleX,_titleY);
1899  hs2d = new HistoStack(_title,_titleX,_titleY);
1900  }
1901  if (!drawUtils::CheckOption(opt2,"NOMC")){
1902  hs1m = new HistoStack(_title,_titleX,_titleY);
1903  hs2m = new HistoStack(_title,_titleX,_titleY);
1904  }
1905 
1906  std::string groupName = "all";
1907  std::string mcSampleName = "all";
1908  std::string categ = "all";
1909  std::string newopt1 = opt1 + " NOVARBIN";
1910  std::string newopt2 = opt2 + " NOVARBIN";
1911 
1912  // Get the current tree name
1913  // std::string tree_name = exp.GetCurrentTree();
1914 
1915  int ny = 0;
1916  double ybins[1] = {0};
1917 
1918  // Project the Experiment into the HistoStacks. Using 0 norm means that POT normalization is used when both samples are available
1919  Project(hs1d, hs1m, exp, groupName, mcSampleName, var,nx,xbins,ny,ybins,categ,cut1,root_opt,newopt1,0.,scale_errors);
1920  Project(hs2d, hs2m, exp, groupName, mcSampleName, var,nx,xbins,ny,ybins,categ,cut2,root_opt,newopt2,0.,scale_errors);
1921 
1922  // go back to the previous tree name
1923  // exp.SetCurrentTree(tree_name);
1924 
1925  // h1 = Histogram for cut1+cut2 (numerator)
1926  // h2 = Histogram for cut2 (denominator)
1927  TH1_h* h1;
1928  TH1_h* h2;
1929  if (usedata) {
1930  h1 = hs1d->GetTotal1D();
1931  h2 = hs2d->GetTotal1D();
1932  } else {
1933  h1 = hs1m->GetTotal1D();
1934  h2 = hs2m->GetTotal1D();
1935  }
1936 
1937  nev1 = h1->Integral(0, h1->GetNbinsX() + 1);
1938  nev2 = h2->Integral(0, h2->GetNbinsX() + 1);
1939 
1940  // compute the efficiency
1941  TGraphAsymmErrors* eff = new TGraphAsymmErrors(h1);
1942  _saved_graphs.push_back(eff);
1943  eff->Divide(h1, h2, _eff_params.c_str()); //the options are explicitely provided by SetEffDivideParams(const std::string&), root_opt not used to avoid possible confusions
1944 
1945  // Put the errors into the ratio
1946  if (usedata)
1947  FillGraphErrors(hs1d, hs2d, eff, opt1);
1948  else
1949  FillGraphErrors(hs1m, hs2m, eff, opt1);
1950 
1951 
1952  if (hs1d) delete hs1d;
1953  if (hs2d) delete hs2d;
1954  if (hs1m) delete hs1m;
1955  if (hs2m) delete hs2m;
1956 
1957 
1958  return eff;
1959 }
1960 
1961 //*********************************************************
1962 void DrawingTools::DrawRatioNew(Experiment& exp, bool usedata, const std::string& var, int nx, double xmin, double xmax,
1963  const std::string& cut1, const std::string& cut2, const std::string& root_opt, const std::string& opt1, const std::string& opt2) {
1964 //*********************************************************
1965  double xbins[NMAXBINS];
1966  DrawRatioNew(exp, usedata, var, nx, GetVariableBins(nx, xmin, xmax, xbins), cut1, cut2, root_opt, opt1, opt2);
1967 }
1968 
1969 //*********************************************************
1970 void DrawingTools::DrawRatioNew(Experiment& exp, bool usedata, const std::string& var, int nx, double* xbins,
1971  const std::string& cut1, const std::string& cut2, const std::string& root_opt, const std::string& opt1,
1972  const std::string& opt2) {
1973 //*********************************************************
1974  double dummy1, dummy2;
1975  std::string uopt1 = drawUtils::ToUpper(opt1);
1976  std::string uopt2 = drawUtils::ToUpper(opt2);
1977  std::string uroot_opt = drawUtils::ToUpper(root_opt);
1978 
1979  DrawRatioNew(exp, usedata, var, nx, xbins, dummy1, dummy2, cut1, cut2, uroot_opt, uopt1, uopt2);
1980 }
1981 
1982 //*********************************************************
1983 void DrawingTools::DrawRatioNew(Experiment& exp, bool usedata, const std::string& var, int nx, double* xbins, double& nev1, double& nev2,
1984  const std::string& cut1, const std::string& cut2, const std::string& root_opt, const std::string& opt1,
1985  const std::string& opt2, bool scale_errors) {
1986 //*********************************************************
1987 
1988 
1989  std::string uopt1 = drawUtils::ToUpper(opt1);
1990  std::string uopt2 = drawUtils::ToUpper(opt2);
1991 
1992  // Check that all user options are valid
1993  if (!drawUtils::ContainValidOptions(uopt1)) return;
1994 
1995  // Check that all user options are valid
1996  if (!drawUtils::ContainValidOptions(uopt2)) return;
1997 
1998 
1999  // Create empty Histo Stacks
2000  HistoStack* hs1d = NULL;
2001  HistoStack* hs2d = NULL;
2002  HistoStack* hs1m = NULL;
2003  HistoStack* hs2m = NULL;
2004 
2005  // both opt1 and opt2 must contain the option "NODATA" or "NOMC"
2006  if (!drawUtils::CheckOption(opt1,"NODATA")){
2007  hs1d = new HistoStack(_title,_titleX,_titleY);
2008  hs2d = new HistoStack(_title,_titleX,_titleY);
2009  }
2010  if (!drawUtils::CheckOption(opt2,"NOMC")){
2011  hs1m = new HistoStack(_title,_titleX,_titleY);
2012  hs2m = new HistoStack(_title,_titleX,_titleY);
2013  }
2014 
2015  std::string groupName = "all";
2016  std::string mcSampleName = "all";
2017  std::string categ = "all";
2018  std::string newopt1 = uopt1 + " NOVARBIN";
2019  std::string newopt2 = uopt2 + " NOVARBIN";
2020 
2021  // Get the current tree name
2022  // std::string tree_name = exp.GetCurrentTree();
2023 
2024  int ny = 0;
2025  double ybins[1] = {0};
2026 
2027  // Project the Experiment into the HistoStacks. Using 0 norm means that POT normalization is used when both samples are available
2028  Project(hs1d, hs1m, exp, groupName, mcSampleName, var,nx,xbins,ny,ybins,categ,cut1,root_opt,newopt1,0.,scale_errors);
2029  Project(hs2d, hs2m, exp, groupName, mcSampleName, var,nx,xbins,ny,ybins,categ,cut2,root_opt,newopt2,0.,scale_errors);
2030 
2031  // go back to the previous tree name
2032  // exp.SetCurrentTree(tree_name);
2033 
2034  // h1 = Histogram for cut1+cut2 (numerator)
2035  // h2 = Histogram for cut2 (denominator)
2036  TH1_h* h1;
2037  TH1_h* h2;
2038  if (usedata) {
2039  h1 = hs1d->GetTotal1D();
2040  h2 = hs2d->GetTotal1D();
2041  } else {
2042  h1 = hs1m->GetTotal1D();
2043  h2 = hs2m->GetTotal1D();
2044  }
2045 
2046  nev1 = h1->Integral(0, h1->GetNbinsX() + 1);
2047  nev2 = h2->Integral(0, h2->GetNbinsX() + 1);
2048 
2049  //Draw the HistoStacks
2050  if (usedata)
2051  DrawRatioHistoStacks(hs1d,hs2d,root_opt,newopt1,0.);
2052  else
2053  DrawRatioHistoStacks(hs1m,hs2m,root_opt,newopt1,0.);
2054 
2055  if (hs1d) delete hs1d;
2056  if (hs2d) delete hs2d;
2057  if (hs1m) delete hs1m;
2058  if (hs2m) delete hs2m;
2059 
2060 }
2061 
2062 
2063 //**************************************************
2064 void DrawingTools::GetEventsVSCut(Experiment& exp, const std::string& name, const std::string& cut_norm, int isel,int ibranch, int& first_cut, int& last_cut,
2065  const std::string& root_opt, const std::string& opt, TH1_h*& data, TH1_h*& mc){
2066 //**************************************************
2067 
2068  // Check if selection exists
2069  if (!sel().GetSelection(isel,true)) return;
2070 
2071  (void)root_opt; // root_opt not used here
2072  std::string uopt = drawUtils::ToUpper(opt);
2073 
2074  // Read the steps from the config tree
2075  // ReadSteps(_config_file);
2076 
2077 
2078  // Deal properly with first and last cuts
2079  if (last_cut>(int)(sel().GetSelection(isel)->GetNCuts(ibranch)-1) || last_cut == -1) last_cut=sel().GetSelection(isel)->GetNCuts(ibranch)-1;
2080  if (first_cut<-1 || first_cut>last_cut ) first_cut=-1;
2081 
2082  // Output Histrogram attributes
2083  double xmin=first_cut-0.5;
2084  double xmax=last_cut+0.5;
2085  int nx = (int)(xmax-xmin);
2086 
2087  std::vector<double> balldata;
2088  balldata.resize(nx);
2089  std::vector<double> ballmc;
2090  ballmc.resize(nx);
2091 
2092  // initially no data and MC are found
2093  bool found_data=false;
2094  bool found_mc=false;
2095  data = NULL;
2096  mc = NULL;
2097 
2098  std::string cut0 = cut_norm;
2099  if (cut0 == "") cut0 = "1==1";
2100 
2101  for (int i=0;i<nx;i++ ){
2102  int icut = first_cut+i;
2103 
2104  // Define the cuts
2105  std::stringstream scut;
2106  scut << icut;
2107  std::stringstream sbranch;
2108  sbranch << ibranch;
2109  std::stringstream ssel;
2110  ssel << isel;
2111 
2112  std::string cut;
2113  if (exp.GetCurrentTree() == "truth"){
2114  if (sel().GetNEnabledSelections()>1)
2115  cut= cut0 + " && accum_level["+ssel.str()+"]["+sbranch.str()+"]>"+scut.str();
2116  else
2117  cut= cut0 + " && accum_level["+sbranch.str()+"]>"+scut.str();
2118  }
2119  else{
2120  if (sel().GetNEnabledSelections()>1)
2121  cut= cut0 + " && accum_level[]["+ssel.str()+"]["+sbranch.str()+"]>"+scut.str();
2122  else
2123  cut= cut0 + " && accum_level[]["+sbranch.str()+"]>"+scut.str();
2124  }
2125 
2126  // Create temporary empty Histo Stacks
2127  HistoStack* hs1 = new HistoStack((_title+"cut"+scut.str()).c_str(),_titleX,_titleY);
2128  HistoStack* hs2 = new HistoStack((_title+"cut"+scut.str()).c_str(),_titleX,_titleY);
2129 
2130  double xbins_dummy[2]={0,1};
2131  double ybins_dummy[1];
2132 
2133  // Project the Experiment into the HistoStacks. Using 0 norm means that POT normalization is used when both samples are available
2134  Project(hs1, hs2, exp, "all", "all", "0.5",1,xbins_dummy,0,ybins_dummy,"all",cut,root_opt,opt,0.,false);
2135 
2136  if (hs2->GetTotal1D()){
2137  ballmc[i] = (double)hs2->GetTotal1D()->Integral();
2138  found_mc = true;
2139  }
2140 
2141  if (hs1->GetTotal1D()){
2142  balldata[i] = (double)hs1->GetTotal1D()->Integral();
2143  found_data = true;
2144  }
2145 
2146  // delete the temporary HistoStacks
2147  delete hs1;
2148  delete hs2;
2149  }
2150 
2151 
2152  // Fill the output histograms
2153  double xbins[NMAXBINS];
2154  if (found_data){
2155  data = new TH1_h(GetUniqueName(name+"_data").c_str(),"",nx,GetVariableBins(nx,xmin,xmax,xbins));
2156  _saved_histos.push_back(data);
2157  for (int i=0;i<nx;i++ )
2158  data->SetBinContent(i+1,balldata[i]);
2159  }
2160  if (found_mc){
2161  mc = new TH1_h(GetUniqueName(name+"_mc").c_str(),"",nx,GetVariableBins(nx,xmin,xmax,xbins));
2162  _saved_histos.push_back(mc);
2163  for (int i=0;i<nx;i++ )
2164  mc->SetBinContent(i+1,ballmc[i]);
2165  }
2166 
2167 }
2168 
2169 //*********************************************************
2170 void DrawingTools::CompareSampleGroups(Experiment& exp, const std::string& mcSampleName, const std::string& var, int nx, double xmin, double xmax,
2171  const std::string& cut, const std::string& root_opt, const std::string& opt, bool scale_errors, const std::string& normtype){
2172 //*********************************************************
2173 
2174  double xbins[NMAXBINS];
2175  CompareSampleGroups(exp,mcSampleName,var,nx,GetVariableBins(nx,xmin,xmax,xbins),cut,root_opt,opt,scale_errors,normtype);
2176 }
2177 
2178 //*********************************************************
2179 void DrawingTools::CompareSampleGroups(Experiment& exp, const std::string& mcSampleName, const std::string& var, int nx, double* xbins,
2180  const std::string& cut, const std::string& root_opt, const std::string& opt, bool scale_errors, const std::string& normtype){
2181 //*********************************************************
2182 
2183  std::vector<HistoStack*> hs;
2184  int ny = 0;
2185  double ybins[NMAXBINS];
2186  bool first = true;
2187  double norm;
2188  int lc = 1;
2189  DataSample* firstSample=NULL;
2190  std::string unormtype = drawUtils::ToUpper(normtype);
2191  std::string uroot_opt = drawUtils::ToUpper(root_opt);
2192  std::string uopt = drawUtils::ToUpper(opt);
2193  int count = 0;
2194 
2195  // Check that all user options are valid
2196  if (!drawUtils::ContainValidOptions(uopt)) return;
2197 
2198  // Create the legend
2199  if (!drawUtils::CheckInternalOption(uopt,"NOCREATELEG")) {
2200  CreateLegend();
2201  }
2202 
2203  // Loop over SampleGroup's in the experiment
2204  std::map< std::string, SampleGroup >::iterator it;
2205  for (it = exp.GetSampleGroups().begin(); it != exp.GetSampleGroups().end(); it++) {
2206  SampleGroup& sampleGroup = it->second;
2207 
2208  DataSample* data = sampleGroup.GetDataSample();
2209  std::map< std::string, DataSample*>& mcSamples = sampleGroup.GetMCSamples();
2210 
2211  if (data) {
2212  bool thisfirst = false;
2213  HistoStack* hs = new HistoStack(_title,_titleX,_titleY);
2214  _saved_histoStacks.push_back(hs);
2215 
2216  if (unormtype == "POT") {
2217  if (first) {
2218  firstSample = data;
2219  norm = 1;
2220  } else {
2221  norm = GetNormalisationFactor(firstSample, data, 1.0, true, opt);
2222  }
2223  } else {
2224  norm = 1;
2225  }
2226 
2227  if (first) {
2228  first = false;
2229  thisfirst = true;
2230  }
2231 
2232  // Project the first sample
2233  Project(hs, "sample1", *data, var, nx, xbins, ny, ybins, "all", cut, uroot_opt, uopt, norm, scale_errors);
2234 
2235  if (unormtype == "ONE") {
2236  double integral = hs->GetTotal1D()->Integral();
2237  hs->GetTotal1D()->Sumw2();
2238  hs->GetTotal1D()->Scale(1./integral);
2239  }
2240 
2241  std::string leg = it->first + " Data";
2242  hs->GetTotal1D()->SetTitle(leg.c_str());
2243  lc = _auto_colors[count];
2244  if (!drawUtils::CheckInternalOption(uopt,"NOCREATELEG")) {
2245  _drawleg = true;
2246  }
2247 
2248  SetStatPos((1-0.4*count-gStyle->GetPadRightMargin()),(1.04-gStyle->GetPadTopMargin()));
2249  DrawHisto(hs->GetTotal1D(),lc,1,lc,0, uroot_opt + " E", uopt, "lpe");
2250  if (!drawUtils::CheckOption(uopt,"NODRAW"))
2251  gPad->Update();
2252 
2253  if (thisfirst) {
2254  uroot_opt += " SAMES";
2255  }
2256  }
2257 
2258  if (mcSamples.size() > 0) {
2259  bool thisfirst = false;
2260  HistoStack* hs = new HistoStack(_title,_titleX,_titleY);
2261  _saved_histoStacks.push_back(hs);
2262 
2263  std::map<std::string, DataSample*>::iterator it2;
2264  for (it2 = mcSamples.begin(); it2 != mcSamples.end(); it2++) {
2265  const std::string& mcSampleName2 = it2->first;
2266  if (mcSampleName2 != mcSampleName && mcSampleName != "all") continue;
2267 
2268  DataSample* sample2 = it2->second;
2269  if (sample2) {
2270  if (unormtype == "POT") {
2271  if (first) {
2272  firstSample = sample2;
2273  norm = 1;
2274  } else {
2275  norm = GetNormalisationFactor(firstSample, sample2, 1.0, true, opt);
2276  }
2277  } else {
2278  norm = 1;
2279  }
2280 
2281  if (first) {
2282  first = false;
2283  thisfirst = true;
2284  }
2285 
2286  // Project the second sample normalized to the first one
2287  Project(hs, "sample2", *sample2, var, nx, xbins, ny, ybins, "all", cut, uroot_opt, uopt, norm, scale_errors);
2288  }
2289  }
2290 
2291  if (unormtype == "ONE") {
2292  double integral = hs->GetTotal1D()->Integral();
2293  hs->GetTotal1D()->Sumw2();
2294  hs->GetTotal1D()->Scale(1./integral);
2295  }
2296 
2297  std::string leg = it->first;
2298  if (mcSampleName == "all") {
2299  leg += " MC";
2300  } else {
2301  leg += " " + mcSampleName;
2302  }
2303 
2304  lc = _auto_colors[count];
2305  hs->GetTotal1D()->SetTitle(leg.c_str());
2306  if (!drawUtils::CheckInternalOption(uopt,"NOCREATELEG")) {
2307  _drawleg = true;
2308  }
2309 
2310  SetStatPos((0.8-0.4*count-gStyle->GetPadRightMargin()),(1.04-gStyle->GetPadTopMargin()));
2311  DrawHisto(hs->GetTotal1D(),lc,2,lc,3004+count, uroot_opt + " HIST", uopt, "f");
2312  if (!drawUtils::CheckOption(uopt,"NODRAW"))
2313  gPad->Update();
2314 
2315  if (thisfirst) {
2316  uroot_opt += " SAMES";
2317  }
2318  }
2319 
2320  count++;
2321  }
2322 
2323  // Create the legend
2324  if (!drawUtils::CheckOption(uopt,"NOLEG")){
2325  _legends.back()->Draw();
2326  }
2327 
2328 }
2329 
2330 
2331 //*********************************************************
2332 Double_t DrawingTools::DrawErrors(TTree* tree, const std::string& var, int nx, double xmin, double xmax,
2333  const std::string& cut, const std::string& root_opt, const std::string& opt, const std::string& leg, double norm, bool scale_errors){
2334 //*********************************************************
2335 
2336  // Draw 1D histogram errors for a given set of cuts and uniform binning
2337  double xbins[NMAXBINS];
2338  return DrawErrors(tree, var, nx, GetVariableBins(nx,xmin,xmax,xbins), cut, root_opt, opt, leg, norm, scale_errors);
2339 }
2340 
2341 //*********************************************************
2342 Double_t DrawingTools::DrawRelativeErrors(TTree* tree, const std::string& var, int nx, double xmin, double xmax,
2343  const std::string& cut, const std::string& root_opt, const std::string& opt, const std::string& leg, double norm, bool scale_errors){
2344 //*********************************************************
2345 
2346  // Draw 1D histogram relative errors for a given set of cuts and uniform binning
2347  double xbins[NMAXBINS];
2348  return DrawRelativeErrors(tree, var, nx, GetVariableBins(nx,xmin,xmax,xbins), cut, root_opt, opt, leg, norm, scale_errors);
2349 }
2350 
2351 //*********************************************************
2352 Double_t DrawingTools::DrawErrors(TTree* tree, const std::string& var, int nx, double* xbins,
2353  const std::string& cut, const std::string& root_opt, const std::string& opt, const std::string& leg, double norm, bool scale_errors){
2354 //*********************************************************
2355 
2356  // Draw 1D histogram errors for a given set of cuts and variable binning
2357  bool relative=false;
2358  return DrawErrorsBase(tree, var, nx, xbins, cut, relative, root_opt, opt, leg, norm, scale_errors);
2359 }
2360 
2361 //*********************************************************
2362 Double_t DrawingTools::DrawRelativeErrors(TTree* tree, const std::string& var, int nx, double* xbins,
2363  const std::string& cut, const std::string& root_opt, const std::string& opt, const std::string& leg, double norm, bool scale_errors){
2364 //*********************************************************
2365 
2366  // Draw 1D histogram relative errors for a given set of cuts and variable binning
2367  bool relative=true;
2368  return DrawErrorsBase(tree, var, nx, xbins, cut, relative, root_opt, opt, leg, norm, scale_errors);
2369 }
2370 
2371 //*********************************************************
2372 Double_t DrawingTools::DrawRelativeErrors(TTree* tree1, TTree* tree2, const std::string& var, int nx, double xmin, double xmax,
2373  const std::string& cut, const std::string& root_opt, const std::string& opt, const std::string& leg, double norm, bool scale_errors){
2374 //*********************************************************
2375 
2376  // Draw 1D histogram relative errors for a given set of cuts and uniform binning
2377  double xbins[NMAXBINS];
2378  return DrawRelativeErrors(tree1, tree2, var, nx, GetVariableBins(nx,xmin,xmax,xbins), cut, root_opt, opt, leg, norm, scale_errors);
2379 }
2380 
2381 //*********************************************************
2382 Double_t DrawingTools::DrawRelativeErrors(TTree* tree1, TTree* tree2, const std::string& var, int nx, double* xbins,
2383  const std::string& cut, const std::string& root_opt, const std::string& opt, const std::string& leg, double norm, bool scale_errors){
2384 //*********************************************************
2385 
2386  // Draw 1D histogram relative errors for a given set of cuts and variable binning
2387  bool relative=true;
2388  DrawErrorsBase(tree1, var, nx, xbins, cut, relative, root_opt, opt, leg, norm, scale_errors);
2389  return DrawErrorsBase(tree2, var, nx, xbins, cut, relative, root_opt+" same", opt, leg, norm, scale_errors);
2390 }
2391 
2392 //*********************************************************
2393 Double_t DrawingTools::DrawErrorsBase(TTree* tree, const std::string& var, int nx, double* xbins,
2394  const std::string& cut, bool relative, const std::string& root_opt, const std::string& opt, const std::string& leg, double norm, bool scale_errors){
2395 //*********************************************************
2396  if(syst_tools().errdebug) std::cout<<"DrawErrorBase \n=============== "<<std::endl;
2397  (void)norm;
2398  (void)scale_errors;
2399 
2400  std::string uopt = drawUtils::ToUpper(opt);
2401 
2402  // Check that all user options are valid
2403  if (!drawUtils::ContainValidOptions(uopt)) return 0;
2404 
2405  // Create the empty HistoStack
2406  HistoStack* hs = new HistoStack(_title,_titleX,_titleY);
2407  _saved_histoStacks.push_back(hs);
2408 
2409  // Project the tree
2410  double* ybins=NULL;
2411  uopt += " EXP";
2412  DrawingToolsBase::Project(hs, "", tree,var,nx,xbins,0,ybins,"all",cut,root_opt,uopt,norm,scale_errors);
2413 
2414  return DrawErrorsBase(hs,relative,root_opt,opt,leg);
2415 }
2416 
2417 //*********************************************************
2418 Double_t DrawingTools::DrawErrors(Experiment& exp, const std::string& var, int nx, double xmin, double xmax,
2419  const std::string& cut, const std::string& root_opt, const std::string& opt, const std::string& leg, bool scale_errors){
2420 //*********************************************************
2421 
2422  // Draw 1D histogram errors for a given set of cuts and uniform binning
2423  double xbins[NMAXBINS];
2424  return DrawErrors(exp, var, nx, GetVariableBins(nx,xmin,xmax,xbins), cut, root_opt, opt, leg, scale_errors);
2425 }
2426 
2427 //*********************************************************
2428 Double_t DrawingTools::DrawRelativeErrors(Experiment& exp, const std::string& var, int nx, double xmin, double xmax,
2429  const std::string& cut, const std::string& root_opt, const std::string& opt, const std::string& leg, bool scale_errors){
2430 //*********************************************************
2431 
2432  // Draw 1D histogram relative errors for a given set of cuts and uniform binning
2433  double xbins[NMAXBINS];
2434  return DrawRelativeErrors(exp, var, nx, GetVariableBins(nx,xmin,xmax,xbins), cut, root_opt, opt, leg, scale_errors);
2435 }
2436 
2437 //*********************************************************
2438 Double_t DrawingTools::DrawErrors(Experiment& exp, const std::string& var, int nx, double* xbins,
2439  const std::string& cut, const std::string& root_opt, const std::string& opt, const std::string& leg, bool scale_errors){
2440 //*********************************************************
2441 
2442  // Draw 1D histogram errors for a given set of cuts and variable binning
2443  bool relative=false;
2444  return DrawErrorsBase(exp, "all", "all", var, nx, xbins, cut, relative, root_opt, opt, leg, scale_errors);
2445 }
2446 
2447 //*********************************************************
2448 Double_t DrawingTools::DrawRelativeErrors(Experiment& exp, const std::string& var, int nx, double* xbins,
2449  const std::string& cut, const std::string& root_opt, const std::string& opt, const std::string& leg, bool scale_errors){
2450 //*********************************************************
2451 
2452  // Draw 1D histogram relative errors for a given set of cuts and variable binning
2453  bool relative=true;
2454  return DrawErrorsBase(exp, "all", "all", var, nx, xbins, cut, relative, root_opt, opt, leg, scale_errors);
2455 }
2456 
2457 //*********************************************************
2458 Double_t DrawingTools::DrawErrors(Experiment& exp, const std::string& groupName, const std::string& mcSampleName, const std::string& var, int nx, double xmin, double xmax,
2459  const std::string& cut, const std::string& root_opt, const std::string& opt, const std::string& leg, bool scale_errors){
2460 //*********************************************************
2461 
2462  // Draw 1D histogram errors for a given set of cuts and uniform binning
2463  double xbins[NMAXBINS];
2464  return DrawErrors(exp, groupName, mcSampleName, var, nx, GetVariableBins(nx,xmin,xmax,xbins), cut, root_opt, opt, leg, scale_errors);
2465 }
2466 
2467 //*********************************************************
2468 Double_t DrawingTools::DrawRelativeErrors(Experiment& exp, const std::string& groupName, const std::string& mcSampleName, const std::string& var, int nx, double xmin, double xmax,
2469  const std::string& cut, const std::string& root_opt, const std::string& opt, const std::string& leg, bool scale_errors){
2470 //*********************************************************
2471 
2472  // Draw 1D histogram relative errors for a given set of cuts and uniform binning
2473  double xbins[NMAXBINS];
2474  return DrawRelativeErrors(exp, groupName, mcSampleName, var, nx, GetVariableBins(nx,xmin,xmax,xbins), cut, root_opt, opt, leg, scale_errors);
2475 }
2476 
2477 //*********************************************************
2478 Double_t DrawingTools::DrawErrors(Experiment& exp, const std::string& groupName, const std::string& mcSampleName, const std::string& var, int nx, double* xbins,
2479  const std::string& cut, const std::string& root_opt, const std::string& opt, const std::string& leg, bool scale_errors){
2480 //*********************************************************
2481 
2482  // Draw 1D histogram errors for a given set of cuts and variable binning
2483  bool relative=false;
2484  return DrawErrorsBase(exp, groupName, mcSampleName, var, nx, xbins, cut, relative, root_opt, opt, leg, scale_errors);
2485 }
2486 
2487 //*********************************************************
2488 Double_t DrawingTools::DrawRelativeErrors(Experiment& exp, const std::string& groupName, const std::string& mcSampleName, const std::string& var, int nx, double* xbins,
2489  const std::string& cut, const std::string& root_opt, const std::string& opt, const std::string& leg, bool scale_errors){
2490 //*********************************************************
2491 
2492  // Draw 1D histogram relative errors for a given set of cuts and variable binning
2493  bool relative=true;
2494  return DrawErrorsBase(exp, groupName, mcSampleName, var, nx, xbins, cut, relative, root_opt, opt, leg, scale_errors);
2495 }
2496 
2497 //*********************************************************
2498 Double_t DrawingTools::DrawErrorsBase(Experiment& exp, const std::string& groupName, const std::string& mcSampleName, const std::string& var, int nx, double* xbins,
2499  const std::string& cut, bool relative, const std::string& root_opt, const std::string& opt, const std::string& leg, bool scale_errors){
2500 //*********************************************************
2501 
2502  std::string uopt = drawUtils::ToUpper(opt);
2503 
2504  // Check that all user options are valid
2505  if (!drawUtils::ContainValidOptions(uopt)) return 0;
2506 
2507 
2508  if (groupName!="all"){
2509  if (!exp.HasSampleGroup(groupName)) return 0;
2510  }
2511 
2512  // Create empty Histo Stacks
2513  HistoStack* hs1 = NULL;
2514  HistoStack* hs2 = NULL;
2515  if (!drawUtils::CheckOption(uopt,"NODATA")){
2516  hs1 = new HistoStack(_title,_titleX,_titleY);
2517  _saved_histoStacks.push_back(hs1);
2518  }
2519  if (!drawUtils::CheckOption(uopt,"NOMC")){
2520  hs2 = new HistoStack(_title,_titleX,_titleY);
2521  _saved_histoStacks.push_back(hs2);
2522  }
2523 
2524  // Project the Experiment into the HistoStacks. Using 0 norm means that POT normalization is used when both samples are available
2525  double* ybins=NULL;
2526  Project(hs1, hs2, exp, groupName, mcSampleName, var,nx,xbins,0,ybins,"all",cut,root_opt,opt,0.,scale_errors);
2527 
2528  if (hs2)
2529  return DrawErrorsBase(hs2,relative,root_opt,opt,leg);
2530  else if (hs1)
2531  return DrawErrorsBase(hs1,relative,root_opt,opt,leg);
2532  else return 0;
2533 }
2534 
2535 //*********************************************************
2536 Double_t DrawingTools::DrawErrorsBase(HistoStack* hs, bool relative, const std::string& root_opt, const std::string& opt, const std::string& leg){
2537 //*********************************************************
2538 
2539  std::string uopt = drawUtils::ToUpper(opt);
2540 
2541  // Check that all user options are valid
2542  if (!drawUtils::ContainValidOptions(uopt)) return 0;
2543 
2544  std::string slevel = GetSameLevel(root_opt);
2545  std::string name3 = GetUniqueName("alle");
2546 
2547  if (slevel=="0" && leg!="")
2548  CreateLegend();
2549 
2550  TH1_h* hall = hs->GetTotal1D();
2551 
2552  if (opt.find("ST")==std::string::npos && (opt.find("SYS")!=std::string::npos || opt.find("DIS")!=std::string::npos))
2553  hall = hs->GetTotalSyst1D();
2554  else if (opt.find("ST")!=std::string::npos && (opt.find("SYS")==std::string::npos && opt.find("DIS")==std::string::npos))
2555  hall = hs->GetTotalStat1D();
2556 
2557  TH1_h* herrors = new TH1_h(*hall);
2558  herrors->SetName(name3.c_str());
2559  _saved_histos.push_back(herrors);
2560 
2561  Double_t ntotal =0;
2562  Double_t avg_error =0;
2563  for (int i=0;i<hall->GetNbinsX();i++){
2564  if (relative)
2565  if (hall->GetBinContent(i+1)!=0){
2566  herrors->SetBinContent(i+1, hall->GetBinError(i+1)/hall->GetBinContent(i+1));
2567  avg_error += hall->GetBinError(i+1);
2568  }
2569  else
2570  herrors->SetBinContent(i+1, 0.);
2571  else{
2572  avg_error += hall->GetBinError(i+1)*hall->GetBinContent(i+1);
2573  herrors->SetBinContent(i+1, hall->GetBinError(i+1));
2574  }
2575 
2576  ntotal += hall->GetBinContent(i+1);
2577  herrors->SetBinError(i+1, 0);
2578  }
2579 
2580  avg_error/=ntotal;
2581  std::cout << "average differential error = " << avg_error << std::endl;
2582 
2583  std::string title_temp = _title;
2584 
2585  // Histogram attributes
2586  if (relative)
2587  SetTitleY("relative error");
2588  else
2589  SetTitleY("absolute error");
2590 
2591  herrors->SetTitle(leg.c_str());
2592 
2593  std::string varbin = "";
2594  if (relative) varbin= " NOVARBIN";
2595 
2596  // Draw the histo
2597  DrawHisto(herrors, _line_width, _line_color, _fill_style, root_opt, uopt+ " NOSTAT"+varbin,"LE1P");
2598 
2599  // reset the Y title
2600  SetTitleY(title_temp);
2601 
2602  // Draw the legend
2603  if (!drawUtils::CheckOption(uopt,"NOLEG") && leg!="")
2604  _legends.back()->Draw();
2605 
2606  if (!drawUtils::CheckOption(uopt,"NODRAW"))
2607  gPad->Update();
2608 
2609  return avg_error;
2610 }
2611 
2612 //*********************************************************
2613 void DrawingTools::DrawCovMatrix(TTree* tree, const std::string& var, int nx, double* xbins,
2614  const std::string& cut, const std::string& root_opt, const std::string& uopt){
2615 //*********************************************************
2616 
2617  const TMatrixD& mcov = GetCovMatrix(tree, var, nx, xbins, cut, uopt);
2618 
2619  // Draw the histo
2620  DrawMatrix(mcov, _auto_colors[_same_level], _line_width, _line_color, _fill_style, root_opt, uopt);
2621 
2622 }
2623 
2624 //*********************************************************
2625 void DrawingTools::DrawCovMatrix(TTree* tree, const std::string& var, int nx, double xmin, double xmax,
2626  const std::string& cut, const std::string& root_opt, const std::string& uopt){
2627 //*********************************************************
2628  double xbins[NMAXBINS];
2629 
2630  DrawCovMatrix(tree, var, nx, GetVariableBins(nx, xmin, xmax, xbins), cut, root_opt, uopt);
2631 
2632 }
2633 
2634 //*********************************************************
2635 void DrawingTools::DrawCovMatrix(Experiment& exp, const std::string& groupName, const std::string& mcSampleName, const std::string& var, int nx, double* xbins,
2636  const std::string& cut, const std::string& root_opt, const std::string& uopt){
2637 //*********************************************************
2638  const TMatrixD& mcov = GetCovMatrix(exp, groupName, mcSampleName, var, nx, xbins, cut, root_opt, uopt);
2639 
2640  // Draw the histo
2641  DrawMatrix(mcov, _auto_colors[_same_level], _line_width, _line_color, _fill_style, root_opt, uopt);
2642 }
2643 
2644 //*********************************************************
2645 void DrawingTools::DrawCovMatrix(Experiment& exp, const std::string& groupName, const std::string& mcSampleName, const std::string& var, int nx, double xmin, double xmax,
2646  const std::string& cut, const std::string& root_opt, const std::string& uopt){
2647 //*********************************************************
2648  const TMatrixD& mcov = GetCovMatrix(exp, groupName, mcSampleName, var, nx, xmin, xmax, cut, root_opt, uopt);
2649 
2650  // Draw the histo
2651  DrawMatrix(mcov, _auto_colors[_same_level], _line_width, _line_color, _fill_style, root_opt, uopt);
2652 }
2653 
2654 //*********************************************************
2655 void DrawingTools::DrawCovMatrix(Experiment& exp, const std::string& var, int nx, double* xbins,
2656  const std::string& cut, const std::string& root_opt, const std::string& uopt){
2657 //*********************************************************
2658  const TMatrixD& mcov = GetCovMatrix(exp, var, nx, xbins, cut, root_opt, uopt);
2659 
2660  // Draw the histo
2661  DrawMatrix(mcov, _auto_colors[_same_level], _line_width, _line_color, _fill_style, root_opt, uopt);
2662 }
2663 
2664 
2665 //*********************************************************
2666 void DrawingTools::DrawCovMatrix(Experiment& exp, const std::string& var, int nx, double xmin, double xmax,
2667  const std::string& cut, const std::string& root_opt, const std::string& uopt){
2668 //*********************************************************
2669  const TMatrixD& mcov = GetCovMatrix(exp, var, nx, xmin, xmax, cut, root_opt, uopt);
2670 
2671  // Draw the histo
2672  DrawMatrix(mcov, _auto_colors[_same_level], _line_width, _line_color, _fill_style, root_opt, uopt);
2673 }
2674 
2675 //*********************************************************
2676 const TMatrixD& DrawingTools::GetCovMatrix(Experiment& exp, const std::string& groupName, const std::string& mcSampleName, const std::string& var, int nx, double* xbins,
2677  const std::string& cut, const std::string& root_opt, const std::string& opt){
2678 //*********************************************************
2679  std::string uopt = drawUtils::ToUpper(opt);
2680 
2681  // Check that all user options are valid
2682  if (!drawUtils::ContainValidOptions(uopt)) return syst_tools().GetSystematicCov(NULL, "DUMMY");
2683 
2684 
2685  if (groupName!="all"){
2686  if (!exp.HasSampleGroup(groupName)) return syst_tools().GetSystematicCov(NULL, "DUMMY");
2687  }
2688 
2689  // Create empty Histo Stacks
2690  HistoStack* hs1 = NULL;
2691  if (drawUtils::CheckOption(uopt,"SCALETODATA")){
2692  hs1 = new HistoStack(_title,_titleX,_titleY);
2693  _saved_histoStacks.push_back(hs1);
2694  }
2695 
2696  // For MC information
2697  HistoStack* hs2 = new HistoStack(_title,_titleX,_titleY);
2698  _saved_histoStacks.push_back(hs2);
2699 
2700 
2701  std::string opt_tmp = uopt;
2702 
2703  opt_tmp += " CAT"; //not to fill histos with errors
2704 
2705  opt_tmp += "MATRIX"; //matrix mode, still update the histo strack histograms related to systematics
2706 
2707  // Project the Experiment into the HistoStacks. Using 0 norm means that POT normalization is used when both samples are available
2708  double* ybins=NULL;
2709  Project(hs1, hs2, exp, groupName, mcSampleName, var,nx,xbins,0,ybins,"all",cut,root_opt,opt_tmp, 0., false); // false --> do not care about stat errors
2710 
2711  // Experiment was projected so can calculate the covariance matrix
2712  // Get the covariance matrix using systematic tools
2713  const TMatrixD& mcov = syst_tools().GetSystematicCov(hs2, uopt);
2714 
2715  return mcov;
2716 }
2717 
2718 //*********************************************************
2719 const TMatrixD& DrawingTools::GetCovMatrix(Experiment& exp, const std::string& groupName, const std::string& mcSampleName, const std::string& var, int nx, double xmin, double xmax,
2720  const std::string& cut, const std::string& root_opt, const std::string& uopt){
2721 //*********************************************************
2722  double xbins[NMAXBINS];
2723 
2724  return GetCovMatrix(exp, groupName, mcSampleName, var, nx, GetVariableBins(nx, xmin, xmax, xbins), cut, root_opt, uopt);
2725 }
2726 
2727 //*********************************************************
2728 const TMatrixD& DrawingTools::GetCovMatrix(Experiment& exp, const std::string& var, int nx, double* xbins,
2729  const std::string& cut, const std::string& root_opt, const std::string& uopt){
2730 //*********************************************************
2731 
2732  return GetCovMatrix(exp, "all", "all", var, nx, xbins, cut, root_opt, uopt);
2733 }
2734 
2735 //*********************************************************
2736 const TMatrixD& DrawingTools::GetCovMatrix(Experiment& exp, const std::string& var, int nx, double xmin, double xmax,
2737  const std::string& cut, const std::string& root_opt, const std::string& uopt){
2738 //*********************************************************
2739  double xbins[NMAXBINS];
2740 
2741  return GetCovMatrix(exp, "all", "all", var, nx, GetVariableBins(nx, xmin, xmax, xbins), cut, root_opt, uopt);
2742 }
2743 
2744 //*********************************************************
2745 const TMatrixD& DrawingTools::GetCovMatrix(TTree* tree, const std::string& var, int nx, double xmin, double xmax,
2746  const std::string& cut, const std::string& uopt){
2747 //*********************************************************
2748  double xbins[NMAXBINS];
2749 
2750  //get the covariance matrix using systematic tools
2751  return GetCovMatrix(tree, var, nx, GetVariableBins(nx, xmin, xmax, xbins), cut, uopt);
2752 }
2753 
2754 //*********************************************************
2755 const TMatrixD& DrawingTools::GetCovMatrix(TTree* tree, const std::string& var, int nx, double* xbins,
2756  const std::string& cut, const std::string& uopt){
2757 //*********************************************************
2758  int NTOYS = drawUtils::GetNToys(tree);
2759 
2760 
2761 
2762 
2763  //get the covariance matrix using systematic tools
2764  const TMatrixD& mcov = syst_tools().GetSystematicCov(tree, var, nx, xbins, cut, NTOYS, uopt);
2765 
2766  return mcov;
2767 }
2768 
2769 //*********************************************************
2770 void DrawingTools::DrawMatrix(const TMatrixD& m, int lc, int lw, int fc, int fs,
2771  const std::string& root_opt, const std::string& uopt){
2772 //*********************************************************
2773 
2774  // Histogram corresponding to the matrix
2775  TH2D* h = new TH2D(m);
2776 
2777  //set unique name
2778  std::string name = h->GetName();
2779  h->SetName(GetUniqueName(name).c_str());
2780 
2781  _saved_histos.push_back(h);
2782 
2783  // Draw the histo
2784  DrawHisto(h, lc, lw, fc, fs, root_opt, uopt+ " NOSTAT NOMIN","");
2785 
2786  std::string ropt = drawUtils::ToUpper(root_opt);
2787  if (ropt.find("COLZ"))
2788  gPad->SetRightMargin(0.15); //to be able to see the palette labels
2789 
2790  h->GetXaxis()->SetTitle("Bins");
2791  h->GetYaxis()->SetTitle("Bins");
2792  gPad->Modified();
2793  gPad->Update();
2794 
2795 }
2796 
bool HasMCSample(const std::string &name)
Check whether the group has a given MC sample.
Definition: Experiment.cxx:87
double GetGoodPOT(DataSample &data)
return the Good POT used to create this DataSample object.
void DrawCovMatrix(TTree *tree, const std::string &var, int nx, double xmin, double xmax, const std::string &cut="", const std::string &root_opt="", const std::string &uopt="")
[DrawingToolsDrawErrors]
int GetGoodSpills(DataSample &data)
return the number of Good spills used to create this DataSample object.
TTree * GetTree(Int_t index)
Returns the a tree with a given index.
Definition: TreeManager.hxx:28
void PrintEventNumbers(TTree *tree, const std::string &cut, const std::string &file="", int toy_ref=-1)
Print the event number of a specific selection.
void UpdateSystInfo(HistoStack *hs1, HistoStack *hs2, TTree *tree1, TTree *tree2, const std::string &var, int nx, double *xbins, const std::string &cut1, const std::string &cut2, const std::string &opt, double norm)
fill/update systematics information (fill appopriate histograms) for the stacks
double GetNormalisationFactor(DataSample *sample1, DataSample *sample2, double norm=-1., bool pot_norm=true, const std::string &opt="")
void DrawPurVSCut(TTree *tree, const std::string &signal="", const std::string &precut="", int first_cut=-1, int last_cut=-1, const std::string &root_opt="", const std::string &opt="", const std::string &leg="")
Draw the selection purity as a function of the cut. Must use the default tree as input.
Double_t DrawErrors(TTree *tree, const std::string &var, int nx, double xmin, double xmax, const std::string &cut="", const std::string &root_opt="", const std::string &opt="", const std::string &leg="", double norm=1, bool scale_errors=false)
[DrawingToolsDrawErrors]
const TMatrixD & GetCovMatrix(TTree *tree, const std::string &var, int nx, double *xbins, const std::string &cut="", const std::string &uopt="")
Returns covariance matrix given a tree.
void DrawToysRatioTwoCuts(TTree *tree1, TTree *tree2, const std::string &cut1, const std::string &cut2, const std::string &root_opt="", const std::string &opt="", const std::string &leg="", double norm=1)
TH1 * Draw(TTree *tree, const std::string &var, int nbins, double *xbins, const std::string &categ="all", const std::string &cut="", const std::string &root_opt="", const std::string &opt="", double norm=1, bool scale_errors=true)
1D histos
TH1_h * GetTotalStat1D()
Return the total 1D histo with only stat errors.
Definition: HistoStack.hxx:70
void DrawToysRatio(TTree *tree1, TTree *tree2, const std::string &cut="", const std::string &root_opt="", const std::string &opt="", const std::string &leg="", double norm=1)
TH1_h * GetTotalSyst1D()
Return the total 1D histo with only systematic errors.
Definition: HistoStack.hxx:73
void SetCurrentSystGroup(const std::string &group)
Set the current Systematics group.
Definition: HistoStack.hxx:91
void NormalizeByArea(const std::string &uopt, double area=1)
normalize all histos in the stack by area
Definition: HistoStack.cxx:499
void DrawRatioVSCut(DataSample &sample1, DataSample &sample2, const std::string &precut="", int first_cut=-1, int last_cut=-1, const std::string &root_opt="", const std::string &opt="", const std::string &leg="", double norm=-1., bool pot_norm=true)
void DrawEffVSCut(TTree *tree, const std::string &signal="", const std::string &precut="", int first_cut=-1, int last_cut=-1, const std::string &root_opt="", const std::string &opt="", const std::string &leg="")
Draw the selection efficiency as a function of the cut. Must use the truth tree as input...
std::map< std::string, DataSample * > & GetMCSamples()
Get all MC samples in a group.
Definition: Experiment.hxx:50
void DrawMatrix(const TMatrixD &m, int lc, int lw, int fc, int fs, const std::string &root_opt="", const std::string &opt="")
[DrawingToolsDrawCovMatrix]
Double_t GetPOT()
This is the method used externaly. It corresponds to POT that passed beam and ND280 quality cuts...
Definition: Header.hxx:36
void PrintPurities(TTree *tree, const std::string &categ, const std::string &cut, double events_ratio=1)
void DrawDoubleEff(TTree *tree1, TTree *tree2, const std::string &var, int nx, double *xbins, const std::string &cut1, const std::string &cut2, const std::string &root_opt="", const std::string &opt="", const std::string &leg="")
ratio between two Efficiencies
std::string GetString(int code)
convert integer to string
void DumpPOT(const std::string &name)
Dump detailed POT information for a given sample pair.
Definition: Experiment.cxx:287
bool ContainValidOptions(const std::string &uopt)
Check if the input string contails only valid options.
double GetPOTRatio(DataSample &sample1, DataSample &sample2, double POTsample1_byhand=-1)
void DrawSignificance(TTree *tree, const std::string &var, int nbins, double *xbins, const std::string &cut1, const std::string &cut2, double norm=1, double rel_syst=0, const std::string &root_opt="", const std::string &opt="", const std::string &leg="")
1D significance
int GetVarFromExperiment(const std::string &var, Experiment &exp, const std::string &groupName="all", const std::string &mcSampleName="all")
Get the Value of an integer variable from the experiment.
void SetCurrentTree(const std::string &name)
Set the current configuration to all samples in all SampleGroups.
Definition: Experiment.cxx:275
void CompareSampleGroups(Experiment &exp, const std::string &mcSampleName, const std::string &var, int nx, double xmin, double xmax, const std::string &cut="", const std::string &root_opt="", const std::string &opt="", bool scale_errors=true, const std::string &normtype="POT")
bool HasSampleGroup(const std::string &name)
Checks if the Experiment has a SampleGroup with a given name.
Definition: Experiment.cxx:222
void DrawGraph(TGraphAsymmErrors *eff, int nbins, double *xbins, const std::string &uroot_opt, const std::string &uopt, const std::string &leg, double ymax=1.05)
[DrawingToolsBase_eff_ratio]
DataSample * GetDataSample()
Get the data sample in a group.
Definition: Experiment.hxx:38
std::string ToUpper(const std::string &str)
Definition: DrawingUtils.cxx:9
void DrawToys(TTree *tree, const std::string &cut="", const std::string &root_opt="", const std::string &opt="", const std::string &leg="")
void DrawRatioVSCut(TTree *tree1, TTree *tree2, const std::string &precut="", int first_cut=-1, int last_cut=-1, const std::string &root_opt="", const std::string &opt="", const std::string &leg="", double norm=1.)
Draw the ratio between two trees as a function of the cut.
bool CheckInternalOption(const std::string &uopt, const std::string &this_opt)
Check if specific option appears in option field (don&#39;t check if it exists: Added with AddOption) ...
int GetNToys(TTree *tree)
get the number of weights in the tree
Int_t GetNSpills()
This is the method used externaly. It corresponds to POT that passed beam and ND280 quality cuts...
Definition: Header.hxx:39
void PrintPurities(DataSample &data, const std::string &categ, const std::string &cut, double events_ratio=1)
void GetEventsVSCut(Experiment &exp, const std::string &name, const std::string &cut_norm, int isel, int ibranch, int &first_cut, int &last_cut, const std::string &root_opt, const std::string &opt, TH1_h *&data, TH1_h *&mc)
data and mc will be FILLED here
TH1_h * GetTotal1D()
Return the total 1D histo.
Definition: HistoStack.hxx:67
void DrawRatio(TTree *tree, const std::string &var, int nbins, double *xbins, const std::string &cut1, const std::string &cut2, const std::string &root_opt="", const std::string &opt="", const std::string &leg="")
const std::string & GetCurrentTree() const
Get the current configuration.
Definition: Experiment.hxx:148
std::map< std::string, SampleGroup > & GetSampleGroups()
Returns all sample groups.
Definition: Experiment.hxx:115
void DumpPOT()
Print the POT information.
Definition: Header.cxx:226
Float_t GetOverallPOTRatio()
Get the overall POT ratio.
Definition: Experiment.cxx:346
bool CheckOption(const std::string &uopt, const std::string &this_opt)
Check if specific option exists, and if so if it appears in option field.
void DumpPOT(DataSample &data)
[DrawingToolsVsCutsMethods]