Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <iostream>
00011
00012 #include <TCanvas.h>
00013 #include <TH1D.h>
00014
00015 #include "BCMTFTemplate.h"
00016 #include "BCMTFSystematicVariation.h"
00017
00018 #include "BCMTFChannel.h"
00019
00020
00021 BCMTFChannel::BCMTFChannel(const char * name)
00022 : fData(0)
00023 , fFlagChannelActive(true)
00024 {
00025 fName = name;
00026 }
00027
00028
00029 BCMTFChannel::~BCMTFChannel()
00030 {
00031 if (fData)
00032 delete fData;
00033
00034 for (unsigned int i = 0; i < fTemplateContainer.size(); ++i)
00035 delete (fTemplateContainer.at(i));
00036
00037 for (unsigned int i = 0; i < fSystematicVariationContainer.size(); ++i)
00038 delete (fSystematicVariationContainer.at(i));
00039 }
00040
00041
00042 void BCMTFChannel::PrintTemplates(const char * filename)
00043 {
00044
00045 TCanvas * c1 = new TCanvas();
00046 c1->Divide(2, 2);
00047
00048 std::string f(filename);
00049
00050
00051 unsigned int ntemplates = fTemplateContainer.size();
00052
00053
00054 unsigned int npages = ntemplates / 4;
00055 if (ntemplates % 4 > 0)
00056 npages++;
00057
00058
00059 for (unsigned int i = 0; i < npages; ++i) {
00060
00061 for (unsigned int j = 0; j < 4; ++j) {
00062
00063 unsigned int templateindex = 4 * i + j;
00064
00065 if (templateindex < ntemplates && GetTemplate(templateindex)->GetHistogram()) {
00066
00067 c1->cd(j+1);
00068
00069
00070 TH1D * hist = new TH1D( *( (TH1D *) GetTemplate(templateindex)->GetHistogram()->Clone() ) );
00071
00072
00073 double efficiency = GetTemplate(templateindex)->GetEfficiency();
00074
00075
00076 hist->Scale(efficiency/hist->Integral());
00077
00078
00079 hist->Draw("HIST");
00080 }
00081 else {
00082
00083 c1->cd(j+1)->Clear();
00084 }
00085 }
00086
00087 if (npages == 1)
00088 c1->Print(f.c_str());
00089 else if (i == 0) {
00090 c1->Print( (f+std::string("[")).c_str() );
00091 c1->Print(f.c_str());
00092 }
00093 else if (i < npages-1) {
00094 c1->Print(f.c_str());
00095 }
00096 else {
00097 c1->Print(f.c_str());
00098 c1->Print( (f+std::string("]")).c_str() );
00099 }
00100 }
00101
00102
00103 delete c1;
00104 }
00105
00106
00107 void BCMTFChannel::PrintTemplate(int index, const char * filename)
00108 {
00109
00110 TCanvas * c1 = new TCanvas();
00111 c1->cd();
00112
00113
00114 unsigned int nsystematics = fSystematicVariationContainer.size();
00115
00116
00117 GetTemplate(index)->GetHistogram()->Draw();
00118
00119
00120 if (nsystematics == 0)
00121 c1->Print(filename);
00122 else
00123 c1->Print( (std::string(filename)+std::string("(")).c_str() );
00124
00125
00126 for (unsigned int isystematic = 0; isystematic < nsystematics; ++isystematic) {
00127 c1->cd();
00128
00129
00130 if (!GetSystematicVariation(isystematic)->GetHistogramUp(index) ||
00131 !GetSystematicVariation(isystematic)->GetHistogramDown(index))
00132 continue;
00133
00134
00135 TH1D hist = TH1D(*GetTemplate(index)->GetHistogram());
00136 TH1D hist_up(hist);
00137 TH1D hist_down(hist);
00138
00139
00140 hist.SetFillStyle(0);
00141 hist_up.SetFillStyle(0);
00142 hist_up.SetLineStyle(2);
00143 hist_down.SetFillStyle(0);
00144 hist_down.SetLineStyle(3);
00145
00146
00147 double efficiency = GetTemplate(index)->GetEfficiency();
00148
00149
00150 hist.Scale(efficiency/ hist.Integral());
00151
00152
00153 for (int i = 1; i <= hist.GetNbinsX(); ++i) {
00154 hist.SetBinContent(i, GetTemplate(index)->GetHistogram()->GetBinContent(i));
00155 hist_up.SetBinContent(i, hist.GetBinContent(i) * (1.0 + GetSystematicVariation(isystematic)->GetHistogramUp(index)->GetBinContent(i)));
00156 hist_down.SetBinContent(i, hist.GetBinContent(i) * (1.0 - GetSystematicVariation(isystematic)->GetHistogramDown(index)->GetBinContent(i)));
00157 }
00158
00159
00160 hist_up.Draw("HIST");
00161 hist.Draw("HISTSAME");
00162 hist_down.Draw("HISTSAME");
00163
00164 if (isystematic < nsystematics-1)
00165 c1->Print(filename);
00166 else
00167 c1->Print( (std::string(filename)+std::string(")")).c_str() );
00168 }
00169
00170
00171 delete c1;
00172 }
00173
00174