00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <iostream>
00016 #include <cmath>
00017 #include <map>
00018 #include <TMath.h>
00019 #include <TCanvas.h>
00020 #include <TStyle.h>
00021 #include <TGraph.h>
00022 #include <TFile.h>
00023 #include <TH1.h>
00024 #include "TUnfoldDensity.h"
00025
00026 using namespace std;
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 #define TEST_INPUT_COVARIANCE
00083
00084 void testUnfold5d()
00085 {
00086
00087 TH1::SetDefaultSumw2();
00088
00089
00090
00091 TFile *outputFile=new TFile("testUnfold5_results.root","recreate");
00092
00093
00094
00095 TFile *inputFile=new TFile("testUnfold5_histograms.root");
00096
00097 outputFile->cd();
00098
00099 TUnfoldBinning *detectorBinning,*generatorBinning;
00100
00101 inputFile->GetObject("detector",detectorBinning);
00102 inputFile->GetObject("generator",generatorBinning);
00103
00104 if((!detectorBinning)||(!generatorBinning)) {
00105 cout<<"problem to read binning schemes\n";
00106 }
00107
00108
00109 detectorBinning->Write();
00110 generatorBinning->Write();
00111
00112
00113 TH1 *histDataReco,*histDataTruth;
00114 TH2 *histMCGenRec;
00115
00116 inputFile->GetObject("histDataReco",histDataReco);
00117 inputFile->GetObject("histDataTruth",histDataTruth);
00118 inputFile->GetObject("histMCGenRec",histMCGenRec);
00119
00120 #ifdef TEST_ZERO_UNCORR_ERROR
00121
00122
00123
00124 for(int i=0;i<=histMCGenRec->GetNbinsX()+1;i++) {
00125 for(int j=0;j<=histMCGenRec->GetNbinsY()+1;j++) {
00126 histMCGenRec->SetBinError(i,j,0.0);
00127 }
00128 }
00129 #endif
00130
00131 histDataReco->Write();
00132 histDataTruth->Write();
00133 histMCGenRec->Write();
00134
00135 if((!histDataReco)||(!histDataTruth)||(!histMCGenRec)) {
00136 cout<<"problem to read input histograms\n";
00137 }
00138
00139
00140
00141
00142
00143 TUnfold::EConstraint constraintMode= TUnfold::kEConstraintArea;
00144
00145
00146
00147 TUnfold::ERegMode regMode = TUnfold::kRegModeCurvature;
00148
00149
00150 TUnfoldDensity::EDensityMode densityFlags=
00151 TUnfoldDensity::kDensityModeBinWidth;
00152
00153
00154 const char *REGULARISATION_DISTRIBUTION=0;
00155 const char *REGULARISATION_AXISSTEERING="*[B]";
00156
00157
00158 TUnfoldDensity unfold(histMCGenRec,TUnfold::kHistMapOutputHoriz,
00159 regMode,constraintMode,densityFlags,
00160 generatorBinning,detectorBinning,
00161 REGULARISATION_DISTRIBUTION,
00162 REGULARISATION_AXISSTEERING);
00163
00164
00165
00166 #ifdef TEST_INPUT_COVARIANCE
00167
00168 TH2D *inputEmatrix=
00169 detectorBinning->CreateErrorMatrixHistogram("input_covar",true);
00170 for(int i=1;i<=inputEmatrix->GetNbinsX();i++) {
00171 Double_t e=histDataReco->GetBinError(i);
00172 inputEmatrix->SetBinContent(i,i,e*e);
00173
00174
00175 }
00176 unfold.SetInput(histDataReco,0.0,0.0,inputEmatrix);
00177 #else
00178 unfold.SetInput(histDataReco );
00179 #endif
00180
00181 #ifdef PRINT_MATRIX_L
00182 TH2 *histL= unfold.GetL("L");
00183 for(Int_t j=1;j<=histL->GetNbinsY();j++) {
00184 cout<<"L["<<unfold.GetLBinning()->GetBinName(j)<<"]";
00185 for(Int_t i=1;i<=histL->GetNbinsX();i++) {
00186 Double_t c=histL->GetBinContent(i,j);
00187 if(c!=0.0) cout<<" ["<<i<<"]="<<c;
00188 }
00189 cout<<"\n";
00190 }
00191 #endif
00192
00193
00194
00195
00196 Int_t nScan=30;
00197 TSpline *rhoLogTau=0;
00198 TGraph *lCurve=0;
00199
00200
00201
00202
00203
00204
00205 const char *SCAN_DISTRIBUTION="signal";
00206 const char *SCAN_AXISSTEERING=0;
00207
00208 Int_t iBest=unfold.ScanTau(nScan,0.,0.,&rhoLogTau,
00209 TUnfoldDensity::kEScanTauRhoMax,
00210 SCAN_DISTRIBUTION,SCAN_AXISSTEERING,
00211 &lCurve);
00212
00213
00214 Double_t t[1],rho[1],x[1],y[1];
00215 rhoLogTau->GetKnot(iBest,t[0],rho[0]);
00216 lCurve->GetPoint(iBest,x[0],y[0]);
00217 TGraph *bestRhoLogTau=new TGraph(1,t,rho);
00218 TGraph *bestLCurve=new TGraph(1,x,y);
00219 Double_t *tAll=new Double_t[nScan],*rhoAll=new Double_t[nScan];
00220 for(Int_t i=0;i<nScan;i++) {
00221 rhoLogTau->GetKnot(i,tAll[i],rhoAll[i]);
00222 }
00223 TGraph *knots=new TGraph(nScan,tAll,rhoAll);
00224
00225 cout<<"chi**2="<<unfold.GetChi2A()<<"+"<<unfold.GetChi2L()
00226 <<" / "<<unfold.GetNdf()<<"\n";
00227
00228
00229
00230
00231
00232
00233 TH1 *histDataUnfold=unfold.GetOutput("unfolded signal",0,0,0,kFALSE);
00234
00235 TH1 *histMCReco=histMCGenRec->ProjectionY("histMCReco",0,-1,"e");
00236 TH1 *histMCTruth=histMCGenRec->ProjectionX("histMCTruth",0,-1,"e");
00237 Double_t scaleFactor=histDataTruth->GetSumOfWeights()/
00238 histMCTruth->GetSumOfWeights();
00239 histMCReco->Scale(scaleFactor);
00240 histMCTruth->Scale(scaleFactor);
00241
00242 TH2 *histProbability=unfold.GetProbabilityMatrix("histProbability");
00243
00244 TH1 *histGlobalCorr=unfold.GetRhoItotal("histGlobalCorr",0,0,0,kFALSE);
00245 TH1 *histGlobalCorrScan=unfold.GetRhoItotal
00246 ("histGlobalCorrScan",0,SCAN_DISTRIBUTION,SCAN_AXISSTEERING,kFALSE);
00247 TH2 *histCorrCoeff=unfold.GetRhoIJtotal("histCorrCoeff",0,0,0,kFALSE);
00248
00249 TCanvas canvas;
00250 canvas.Print("testUnfold5.ps[");
00251
00252
00253
00254
00255
00256 canvas.Clear();
00257 canvas.Divide(3,2);
00258
00259
00260 canvas.cd(1);
00261 histDataReco->SetMinimum(0.0);
00262 histDataReco->Draw("E");
00263 histMCReco->SetLineColor(kBlue);
00264 histMCReco->Draw("SAME HIST");
00265
00266 canvas.cd(2);
00267 histProbability->Draw("BOX");
00268
00269 canvas.cd(3);
00270 gPad->SetLogy();
00271 histDataUnfold->Draw("E");
00272 histDataTruth->SetLineColor(kBlue);
00273 histDataTruth->Draw("SAME HIST");
00274 histMCTruth->SetLineColor(kRed);
00275 histMCTruth->Draw("SAME HIST");
00276
00277 canvas.cd(4);
00278 rhoLogTau->Draw();
00279 knots->Draw("*");
00280 bestRhoLogTau->SetMarkerColor(kRed);
00281 bestRhoLogTau->Draw("*");
00282
00283
00284 canvas.cd(5);
00285
00286 histGlobalCorrScan->Draw("HIST");
00287
00288 canvas.cd(6);
00289 lCurve->Draw("AL");
00290 bestLCurve->SetMarkerColor(kRed);
00291 bestLCurve->Draw("*");
00292
00293
00294 canvas.Print("testUnfold5.ps");
00295
00296 canvas.Print("testUnfold5.ps]");
00297
00298 }