ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/auterman/Analysis/FinalPlots/bin/handleHists.cc
Revision: 1.1
Committed: Fri Mar 26 17:01:13 2010 UTC (15 years, 1 month ago) by auterman
Content type: text/plain
Branch point for: FinalPlots, MAIN
Log Message:
Initial revision

File Contents

# User Rev Content
1 auterman 1.1 #include "handleHists.h"
2     #include "ConfigFile.h"
3     #include "TPostScript.h"
4     #include "TCanvas.h"
5     #include "THStack.h"
6     #include "TLegend.h"
7     #include "TStyle.h"
8     #include "TFile.h"
9     #include "TH1.h"
10     #include "TGraph.h"
11    
12     #include <iostream>
13     #include <iomanip>
14     #include <sstream>
15     #include <cstdlib>
16     #include <cmath>
17    
18     using namespace std;
19    
20    
21    
22     TH1 * handleHists::GetHist(const string file, const string hist, const string treename, const string uncert, const string dir)
23     {
24     TH1F * result;
25    
26     stringstream ss;
27     ss << hist<< "_"<<_plotindex++;
28     string name = ss.str(); //root can't handle two hists with same names
29    
30     //open root file
31     if (file=="") return 0;
32     TFile f( file.c_str() );
33     if (f.IsZombie()) {
34     //cout << "Error opening file '" << file << "'"<< endl;
35     return 0;
36     }
37    
38     //construct tree-name for uncertainty histograms:
39     string unc = (uncert=="" ? "" : "_"+uncert+"_"+dir);
40    
41     cout << "opening file '" << file << "' histogram '"<< treename+unc << "/" << hist << "'."<<endl;
42    
43     //open requested histogram 'hist', in directory 'treename'
44     string dummy_name = hist;
45     if (treename!="") dummy_name = treename+unc+"/"+hist;
46     if (uncert.find("Stat")!=string::npos) {
47     //There is no separate histogram for statistical uncertainties; calculate these from the errors of the normal histogram:
48     dummy_name = treename+"/"+hist;
49     }
50     result = (TH1F*)f.Get( dummy_name.c_str() );
51     if (!result) {
52     cerr << "ERROR:Unable to read histogram '" <<dummy_name<< "' from file '"<<file<< "'!"<<endl;
53     exit(1);
54     }
55     result->SetDirectory(0);
56     if (uncert=="") result->SetTitle( hist.c_str() );
57     else result->SetTitle( uncert.c_str() );
58     if (uncert=="Stat") {
59     bool up = (dir=="UP"||dir=="up"||dir=="PLUS"||dir=="plus");
60     //There is no separate histogram for statistical uncertainties; calculate these from the errors of the normal histogram:
61     for (int i=0; i<=result->GetNbinsX(); ++i)
62     if (up) result->SetBinContent(i,result->GetBinContent(i)+result->GetBinError(i));
63     else result->SetBinContent(i,result->GetBinContent(i)-result->GetBinError(i));
64     }
65    
66     return result;
67     }
68    
69     handleHists::handleHists( ConfigFile* config)
70     {
71     _plotindex=0;
72     _SumOfDiffs=0.;
73     string qcdfile = config->read<string>("qcd-rootfile","");
74     string qcdtree = config->read<string>("qcd-treename","");
75     nqcd = config->read<string>("qcd-leg-name","QCD");
76     string ttbarfile = config->read<string>("ttbar-rootfile","");
77     string ttbartree = config->read<string>("ttbar-treename","");
78     nttbar = config->read<string>("ttbar-leg-name","t#bar{t}");
79     string znunufile = config->read<string>("znunu-rootfile","");
80     string znunutree = config->read<string>("znunu-treename","");
81     nznunu = config->read<string>("znunu-leg-name","Z#rightarrow#nu#bar{#nu}");
82     string signalfile = config->read<string>("signal-rootfile","");
83     string signaltree = config->read<string>("signal-treename","");
84     nsignal = config->read<string>("signal-leg-name","Signal");
85     string datafile = config->read<string>("data-rootfile","");
86     string datatree = config->read<string>("data-treename","");
87     ndata = config->read<string>("data-leg-name","Data");
88    
89     vars = bag_of_string(config->read<string>("final variables","HT"));
90     corr_unc = bag_of_string(config->read<string>("correlated uncertainties","JEC"));
91     uncorr_unc = bag_of_string(config->read<string>("uncorrelated uncertainties","method"));
92    
93     _plotSystematics = config->read<bool>("plot systematics",false);
94     _showSignalBand = config->read<bool>("show signal uncertainty",false);
95     _showDiff = config->read<bool>("show difference",false);
96    
97     //read in all histograms and store them in the private vectors of this class
98     for (vector<string>::const_iterator var=vars.begin(); var!=vars.end(); ++var) {
99    
100     //read 'normal' histograms (without syst. uncertainties)
101     _data_hists.push_back( GetHist(datafile, (*var), datatree ) );
102     TH1 * sig = GetHist(signalfile, (*var), signaltree );
103     TH1 * qcd = GetHist(qcdfile, (*var), qcdtree );
104     TH1 * top = GetHist(ttbarfile, (*var), ttbartree);
105     TH1 * z = GetHist(znunufile, (*var), znunutree);
106     _signal_hists.push_back( sig );
107     _qcd_hists. push_back( qcd );
108     _ttbar_hists. push_back( top );
109     _znunu_hists. push_back( z );
110    
111     //read background histogram correlated uncertainties:
112     for (vector<string>::const_iterator cor=corr_unc.begin(); cor!=corr_unc.end(); ++cor) {
113     _syst_up_corr[qcd].push_back( GetHist(qcdfile, (*var),qcdtree, (*cor),"UP" ) );
114     _syst_dn_corr[qcd].push_back( GetHist(qcdfile, (*var),qcdtree, (*cor),"DN" ) );
115     _syst_up_corr[top].push_back( GetHist(ttbarfile,(*var),ttbartree, (*cor),"UP" ) );
116     _syst_dn_corr[top].push_back( GetHist(ttbarfile,(*var),ttbartree, (*cor),"DN" ) );
117     _syst_up_corr[ z ].push_back( GetHist(znunufile,(*var),znunutree, (*cor),"UP" ) );
118     _syst_dn_corr[ z ].push_back( GetHist(znunufile,(*var),znunutree, (*cor),"DN" ) );
119     _syst_up_corr[sig].push_back( GetHist(signalfile,(*var),signaltree, (*cor),"UP" ) );
120     _syst_dn_corr[sig].push_back( GetHist(signalfile,(*var),signaltree, (*cor),"DN" ) );
121     }
122     //read background histogram un-correlated uncertainties:
123     for (vector<string>::const_iterator uco=uncorr_unc.begin(); uco!=uncorr_unc.end(); ++uco) {
124     _syst_up_uncorr[qcd].push_back( GetHist(qcdfile, (*var),qcdtree, (*uco),"UP" ) );
125     _syst_dn_uncorr[qcd].push_back( GetHist(qcdfile, (*var),qcdtree, (*uco),"DN" ) );
126     _syst_up_uncorr[top].push_back( GetHist(ttbarfile,(*var),ttbartree, (*uco),"UP" ) );
127     _syst_dn_uncorr[top].push_back( GetHist(ttbarfile,(*var),ttbartree, (*uco),"DN" ) );
128     _syst_up_uncorr[ z ].push_back( GetHist(znunufile,(*var),znunutree, (*uco),"UP" ) );
129     _syst_dn_uncorr[ z ].push_back( GetHist(znunufile,(*var),znunutree, (*uco),"DN" ) );
130     _syst_up_uncorr[sig].push_back( GetHist(signalfile,(*var),signaltree, (*uco),"UP" ) );
131     _syst_dn_uncorr[sig].push_back( GetHist(signalfile,(*var),signaltree, (*uco),"DN" ) );
132     }
133     }//loop over all 'final variables'
134    
135     if ((_data_hists.size()==_signal_hists.size())*(_data_hists.size()==_qcd_hists.size())*
136     (_data_hists.size()==_ttbar_hists.size())*(_znunu_hists.size()==_qcd_hists.size())!=1){
137     cerr<<"ERROR: Read in different number of data, signal, and background histograms!"<<endl;
138     exit(1);
139     }
140     }
141    
142     TH1 * handleHists::GetSyst(const std::string dir, const TH1*h1, const TH1*h2, const TH1*h3)
143     {
144     if (!h1&&!h2&&!h3) return 0;
145     if (!h1) return GetSyst(dir, h2, h3);
146    
147     int bins = h1->GetNbinsX();
148     stringstream ss; ss << _plotindex++;
149     string unique; unique = ss.str();
150     string name = "syssum_"+unique+(string)h1->GetTitle()+dir;
151     TH1 * sum = new TH1F(name.c_str(),h1->GetTitle(),bins,h1->GetXaxis()->GetXmin(),h1->GetXaxis()->GetXmax());
152     name = "relquad_"+unique+(string)h1->GetTitle()+dir;
153     TH1 * relquadsum = new TH1F(name.c_str(),"",bins,h1->GetXaxis()->GetXmin(),h1->GetXaxis()->GetXmax());
154    
155     //Store all samples for which the syst. uncertainties shall be combined in one
156     //vector 'samples'. Consider only histograms with at least one entry.
157     vector<const TH1*> samples;
158     if (h1) samples.push_back(h1);
159     if (h2) samples.push_back(h2);
160     if (h3) samples.push_back(h3);
161    
162     //Calculate the total systematic uncertainty for 'samples':
163     for (vector<const TH1*>::const_iterator s=samples.begin(); s!=samples.end(); ++s) {
164    
165     //simply add all correlated uncertainties for 's' (assume 100% correlation),
166     //the uncertainties are *relative* to the unchanged hists 's'
167     vector<TH1*>::const_iterator corr_begin =
168     (dir=="UP" ? _syst_up_corr[(*s)].begin() : _syst_dn_corr[(*s)].begin());
169     vector<TH1*>::const_iterator corr_end =
170     (dir=="UP" ? _syst_up_corr[(*s)].end() : _syst_dn_corr[(*s)].end());
171    
172     for (vector<TH1*>::const_iterator c=corr_begin; c!=corr_end; ++c) {
173     sum->Add( *c );
174     sum->Add( *s, -1.0 ); //sum up (c-s)
175     }
176    
177     //now add quadratically all uncorrelated uncertainties for 's';
178     //this is done bin-by-bin, and for *relative* uncertainties
179     vector<TH1*>::const_iterator uncorr_begin =
180     (dir=="UP" ? _syst_up_uncorr[*s].begin() : _syst_dn_uncorr[*s].begin());
181     vector<TH1*>::const_iterator uncorr_end =
182     (dir=="UP" ? _syst_up_uncorr[*s].end() : _syst_dn_uncorr[*s].end());
183     for (vector<TH1*>::const_iterator u=uncorr_begin; u!=uncorr_end; ++u) {
184     for (int bin=0; bin<=bins; ++bin) {
185     double cont = (*u)->GetBinContent(bin) - (*s)->GetBinContent(bin);
186     relquadsum->SetBinContent(bin, relquadsum->GetBinContent(bin)+cont*cont);
187     }
188     }
189     }
190    
191     //add total correlated and total uncorrelated uncertainties quadratically:
192     for (int bin=0; bin<=bins; ++bin) {
193     double cont = sum->GetBinContent(bin);
194     relquadsum->SetBinContent(bin, relquadsum->GetBinContent(bin)+cont*cont);
195     //sqrt(relquadsum):
196     cont=0;
197     for (vector<const TH1*>::const_iterator s=samples.begin(); s!=samples.end(); ++s)
198     cont+=(*s)->GetBinContent(bin);
199     cont += (dir=="UP" ? sqrt(relquadsum->GetBinContent(bin)) : -sqrt(relquadsum->GetBinContent(bin)));
200     sum->SetBinContent(bin, cont );
201     }
202     sum->SetLineStyle( 9 ); //dashed
203    
204     delete relquadsum;
205     return sum; //abolute syst. uncertainty, i.e. *not* relative
206     }
207    
208     TGraph * handleHists::MakeBand(const TH1*h1, const TH1*h2)
209     {
210     if (!h1 || !h2) return 0;
211     TGraph * result = new TGraph(h1->GetNbinsX()+h1->GetNbinsX()+2);
212     unsigned p = 0;
213     for (int i=0; i<=h1->GetNbinsX(); ++i )
214     result->SetPoint(p++, h1->GetBinCenter(i), h1->GetBinContent(i) );
215     for (int i=h2->GetNbinsX(); i>=0; --i )
216     result->SetPoint(p++, h2->GetBinCenter(i), h2->GetBinContent(i) );
217    
218     return result;
219     }
220    
221     void handleHists::PlotStackedBackground(const string out)
222     {
223     gStyle->SetFrameBorderMode(0);
224     gStyle->SetFrameFillColor(0);
225     gStyle->SetTitleFillColor(0);
226     gStyle->SetOptStat(0);
227     gStyle->SetCanvasColor(0);
228     gStyle->SetHistFillColor(0);
229     gStyle->SetStatBorderSize(0);
230     TPostScript ps(out.c_str(), 111);
231     TCanvas * c1;
232     if (_showDiff) {
233     c1 = new TCanvas("c1","",1200,600);
234     c1->Divide(2,1);
235     }
236     else
237     c1 = new TCanvas("c1","",600,600);
238    
239     std::vector<TH1*>::const_iterator d=_data_hists.begin(),
240     s=_signal_hists.begin(),
241     q=_qcd_hists.begin(),
242     t=_ttbar_hists.begin(),
243     z=_znunu_hists.begin();
244    
245     for (;d!=_data_hists.end();++d,++s,++q,++t,++z) {//loop over all variables (HT, MHT, MET, ...)
246     c1->cd(1);
247     TH1 * axis = 0;
248     if (*q) {(*q)->SetFillColor( kYellow ); axis = *q; }
249     if (*t) {(*t)->SetFillColor( kBlue ); axis = *t; }
250     if (*z) {(*z)->SetFillColor( kGreen ); axis = *z; }
251     if (*s) {(*s)->SetLineColor( kRed ); axis = *s; }
252     if (*s) (*s)->SetLineWidth( 4 );
253     if (*d) {(*d)->SetMarkerStyle( 8 ); axis = *d; }
254     if (!axis) return; //nothing to plot.
255     TH1 * ax = (TH1*)axis->Clone();
256    
257     stringstream ss;
258     ss << "hs_"<<_plotindex++;
259     string name = ss.str();
260     THStack st(name.c_str(),"");
261     if (*z) st.Add( *z );
262     if (*t) st.Add( *t );
263     if (*q) st.Add( *q );
264    
265     //background uncertainties
266     TH1 * syst_up = GetSyst( "UP", *q, *t, *z);
267     TH1 * syst_dn = GetSyst( "DN", *q, *t, *z);
268    
269     //signal uncertainties
270     TH1 * sig_syst_up = GetSyst( "UP", *s);
271     TH1 * sig_syst_dn = GetSyst( "DN", *s);
272     TGraph * signalUncert = MakeBand( sig_syst_up, sig_syst_dn );
273     if (signalUncert) signalUncert->SetFillColor( 6 );
274     //if (signalUncert) signalUncert->SetFillStyle( 3004 );
275    
276     string var = ax->GetTitle();
277     string titel = ";"+var+" [GeV]; events";
278     int bins = ax->GetNbinsX();
279     double min = ax->GetXaxis()->GetXmin();
280     double max = ax->GetXaxis()->GetXmax();
281     cout << "...plotting "<< var << " with bins="<<bins<<", min="<<min<<", max="<<max<<endl;
282    
283     double maximum = 0;
284     if (*d) if ((*d)->GetMaximum()+sqrt((*d)->GetMaximum()) > maximum) maximum = (*d)->GetMaximum()+sqrt((*d)->GetMaximum());
285     if (*s) if ((*s)->GetMaximum()>maximum) maximum = (*s)->GetMaximum();
286     if (*z||*t||*q) if (st.GetMaximum()>maximum) maximum = st.GetMaximum();
287     if (syst_up) if (syst_up->GetMaximum()>maximum) maximum = syst_up->GetMaximum();
288     ax->SetMinimum(0);
289     ax->SetMaximum(maximum);
290     ax->SetTitle(titel.c_str());
291     ax->GetYaxis()->SetTitleOffset(1.4);
292    
293     TLegend leg(0.5,0.7,0.9,0.9);
294     leg.SetFillColor(0);leg.SetBorderSize(1);
295     if ( (*d) ) leg.AddEntry( (*d), ndata.c_str(),"pe");
296     if ( (*s) ) leg.AddEntry( (*s), nsignal.c_str(),"l");
297     if ( signalUncert && _showSignalBand ) leg.AddEntry( signalUncert, "signal uncert.","f");
298     if ( (*q) ) leg.AddEntry( (*q), nqcd.c_str(),"f");
299     if ( (*t) ) leg.AddEntry( (*t), nttbar.c_str(),"f");
300     if ( (*z) ) leg.AddEntry( (*z), nznunu.c_str(),"f");
301     if ( syst_up) leg.AddEntry( syst_up, "total sys. uncert.","l");
302    
303     ax->Draw("h");
304     if (syst_up) syst_up->Draw("h,same"); //syst.uncertainty band upper border
305     st.Draw("h,same"); //stacked backgrounds
306    
307     if (syst_dn) syst_dn->Draw("h,same"); //syst.uncertainty band lower border
308     if (_showSignalBand && signalUncert) signalUncert->Draw("f");
309     if (*s) (*s)->Draw("h,same"); //signal
310     if (*d) (*d)->Draw("pe,same"); //data with stat. errors
311     leg.Draw(); //legend
312     //c1->Update();
313    
314     if (_showDiff) {
315     c1->cd(2);
316     TH1 * diff = (TH1*)axis->Clone();
317     for (int i=0; i<=(*d)->GetNbinsX(); ++i ) {
318     diff->SetBinContent(i, (*d)->GetBinContent(i) - (*s)->GetBinContent(i));
319     //diff->SetBinError(i, sqrt((*d)->GetBinError(i)*(*d)->GetBinError(i) + (*s)->GetBinError(i)*(*s)->GetBinError(i)) );
320     _SumOfDiffs += (*d)->GetBinContent(i) - (*s)->GetBinContent(i);
321     }
322     diff->SetTitle("difference: PAT - RECO");
323     diff->SetLineColor( kRed );
324     //diff->SetLineWidth( 4 );
325     //diff->SetMarkerStyle( 8 );
326     diff->Draw("h");
327     }
328     c1->Update();
329     ps.NewPage();
330    
331     }//loop over all histograms (HT, MHT, MET, ...)
332     cout << "Wrote result plots to file '"<<out<<"'"<<endl;
333    
334     }
335    
336     void handleHists::PlotAllSystematics(const string out)
337     {
338     TPostScript ps(out.c_str(), 111);
339     TCanvas c1("c1","",600,600);
340     std::vector<TH1*>::const_iterator q=_qcd_hists.begin(),
341     t=_ttbar_hists.begin(),
342     z=_znunu_hists.begin();
343     //construct for each background plot a full list of uncertainties (merge un- and correlated ones)
344     std::map<const TH1*, std::vector<TH1*> > syst_up(_syst_up_corr);
345     std::map<const TH1*, std::vector<TH1*> > syst_dn(_syst_dn_corr);
346     for (std::map<const TH1*, std::vector<TH1*> >::const_iterator up=_syst_up_uncorr.begin();up!=_syst_up_uncorr.end();++up)
347     for (std::vector<TH1*>::const_iterator val=up->second.begin();val!=up->second.end();++val)
348     syst_up[up->first].push_back( *val );
349     for (std::map<const TH1*, std::vector<TH1*> >::const_iterator dn=_syst_dn_uncorr.begin();dn!=_syst_dn_uncorr.end();++dn)
350     for (std::vector<TH1*>::const_iterator val=dn->second.begin();val!=dn->second.end();++val)
351     syst_dn[dn->first].push_back( *val );
352    
353     //loop over all variables (HT, MHT, MET, ...)
354     for (;q!=_qcd_hists.end();++q,++t,++z) {
355    
356     //loop over all syst. uncertainties
357     for (unsigned uncert=0; uncert<corr_unc.size()+uncorr_unc.size(); ++uncert){
358     TH1 * n; //A not-empty background histogram
359     if (*q) {(*q)->SetFillColor( kYellow ); n = (*q);}
360     if (*t) {(*t)->SetFillColor( kBlue ); n = (*t);}
361     if (*z) {(*z)->SetFillColor( kGreen ); n = (*z);}
362    
363     stringstream ss;
364     ss << "hs_"<<_plotindex++;
365     string name = ss.str();
366     THStack st(name.c_str(),"");
367     if (*z) st.Add( *z );
368     if (*t) st.Add( *t );
369     if (*q) st.Add( *q );
370    
371     //Match to-be plotted backgrounds with their uncertainty
372     ss << "hsysUP_"<<_plotindex++;
373     TH1 * h_syst_up = new TH1F(ss.str().c_str(),"",n->GetNbinsX(),n->GetXaxis()->GetXmin(),n->GetXaxis()->GetXmax());
374     ss << "hsysDN_"<<_plotindex++;
375     TH1 * h_syst_dn = new TH1F(ss.str().c_str(),"",n->GetNbinsX(),n->GetXaxis()->GetXmin(),n->GetXaxis()->GetXmax());
376     if (*z) h_syst_up->Add( syst_up[*z][uncert] );
377     if (*t) h_syst_up->Add( syst_up[*t][uncert] );
378     if (*q) h_syst_up->Add( syst_up[*q][uncert] );
379     if (*z) h_syst_dn->Add( syst_dn[*z][uncert] );
380     if (*t) h_syst_dn->Add( syst_dn[*t][uncert] );
381     if (*q) h_syst_dn->Add( syst_dn[*q][uncert] );
382    
383     //Get names etc from "n" a non-empty background histogram
384     string uncertName = syst_up[n][uncert]->GetTitle();
385     string var = n->GetTitle();
386     string titel = ";"+var+" [GeV]; events";
387     int bins = n->GetNbinsX();
388     double min = n->GetXaxis()->GetXmin();
389     double max = n->GetXaxis()->GetXmax();
390     cout << "...plotting "<< var << " with bins="<<bins<<", min="<<min<<", max="<<max<<endl;
391    
392     h_syst_up->SetMinimum(0);
393     h_syst_up->SetTitle(titel.c_str());
394     h_syst_up->GetYaxis()->SetTitleOffset(1.4);
395    
396     TLegend leg(0.5,0.7,0.9,0.9);
397     leg.SetFillColor(0);leg.SetBorderSize(1);
398     if ( (*q) ) leg.AddEntry( (*q), nqcd.c_str(),"f");
399     if ( (*t) ) leg.AddEntry( (*t), nttbar.c_str(),"f");
400     if ( (*z) ) leg.AddEntry( (*z), nznunu.c_str(),"f");
401     if ( h_syst_up->Integral()>0. ) leg.AddEntry( h_syst_up, uncertName.c_str(),"l");
402    
403     h_syst_up->Draw("h"); //syst.uncertainty band upper border
404     st.Draw("h,same"); //stacked backgrounds
405     h_syst_dn->Draw("h,same"); //syst.uncertainty band lower border
406     leg.Draw(); //legend
407     c1.Update();
408     ps.NewPage();
409    
410     }//loop over syst. uncertainties
411     }//loop over all histograms (HT, MHT, MET, ...)
412     cout << "Wrote result plots to file '"<<out<<"'"<<endl;
413    
414     }
415    
416     void handleHists::PlotHistograms(const string out)
417     {
418     PlotStackedBackground( out );
419     if (_plotSystematics) PlotAllSystematics( "systematics.ps" );
420     }
421    
422     void handleHists::Print()
423     {
424     std::vector<TH1*>::const_iterator d=_data_hists.begin(),
425     s=_signal_hists.begin(),
426     q=_qcd_hists.begin(),
427     t=_ttbar_hists.begin(),
428     z=_znunu_hists.begin();
429    
430     for (;d!=_data_hists.end();++d,++s,++q,++t,++z) {
431     stringstream ss;
432     ss << "hps_"<<_plotindex++;
433     string name = ss.str();
434     THStack st(name.c_str(),"");
435     st.Add( *z );
436     st.Add( *t );
437     st.Add( *q );
438    
439     TH1 * syst_up = GetSyst( "UP", *q, *t, *z);
440     TH1 * syst_dn = GetSyst( "DN", *q, *t, *z);
441     double b = 0.0;
442     if (*q) b+=(*q)->Integral();
443     if (*t) b+=(*t)->Integral();
444     if (*z) b+=(*z)->Integral();
445     double data=0.0;
446     if (*d) data=(*d)->Integral();
447     double signal=0.0;
448     if (*s) signal=(*s)->Integral();
449    
450     if (syst_up) cout << setw(10) << syst_up->GetTitle();
451     else if (*s) cout << setw(10) << (*s)->GetTitle();
452     else if (*d) cout << setw(10) << (*d)->GetTitle();
453     cout << " d: " << data
454     << ", s: " << signal
455     << ", b: " << b;
456     if (syst_up && syst_dn)
457     cout << " " << showpos << syst_up->Integral()-b
458     << " " << showpos << syst_dn->Integral()-b << noshowpos
459     << "(syst.) ";
460     cout << "+-"<< sqrt(data) << "(stat)"
461     << endl;
462     }
463     cout << "Sum of all differences: " << _SumOfDiffs << endl;
464    
465     }
466    
467     handleHists::~handleHists()
468     {
469     //delete all histograms
470     /*
471     for (map<const TH1*, vector<TH1*> >::iterator it=_syst_up_corr.begin();it!=_syst_up_corr.end(); ++it)
472     for (vector<TH1*>::iterator i=it->second.begin(); i!=it->second.end();++i) delete *i;
473     for (map<const TH1*, vector<TH1*> >::iterator it=_syst_dn_corr.begin();it!=_syst_up_corr.end(); ++it)
474     for (vector<TH1*>::iterator i=it->second.begin(); i!=it->second.end();++i) delete *i;
475     for (map<const TH1*, vector<TH1*> >::iterator it=_syst_up_uncorr.begin();it!=_syst_up_corr.end(); ++it)
476     for (vector<TH1*>::iterator i=it->second.begin(); i!=it->second.end();++i) delete *i;
477     for (map<const TH1*, vector<TH1*> >::iterator it=_syst_dn_uncorr.begin();it!=_syst_up_corr.end(); ++it)
478     for (vector<TH1*>::iterator i=it->second.begin(); i!=it->second.end();++i) delete *i;
479     for (vector<TH1*>::iterator it=_qcd_hists.begin(); it!=_qcd_hists.end();++it) delete *it;
480     for (vector<TH1*>::iterator it=_ttbar_hists.begin(); it!=_ttbar_hists.end();++it) delete *it;
481     for (vector<TH1*>::iterator it=_znunu_hists.begin(); it!=_znunu_hists.end();++it) delete *it;
482     for (vector<TH1*>::iterator it=_signal_hists.begin(); it!=_signal_hists.end();++it) delete *it;
483     for (vector<TH1*>::iterator it=_data_hists.begin(); it!=_data_hists.end();++it) delete *it;
484     */
485     _syst_up_corr.clear();
486     _syst_dn_corr.clear();
487     _syst_up_uncorr.clear();
488     _syst_dn_uncorr.clear();
489     _qcd_hists.clear();
490     _ttbar_hists.clear();
491     _znunu_hists.clear();
492     _signal_hists.clear();
493     _data_hists.clear();
494     }