80 #define TEST_INPUT_COVARIANCE
85 TH1::SetDefaultSumw2();
89 TFile *outputFile=
new TFile(
"testUnfold5_results.root",
"recreate");
93 TFile *inputFile=
new TFile(
"testUnfold5_histograms.root");
97 TUnfoldBinning *detectorBinning,*generatorBinning;
99 inputFile->GetObject(
"detector",detectorBinning);
100 inputFile->GetObject(
"generator",generatorBinning);
102 if((!detectorBinning)||(!generatorBinning)) {
103 cout<<
"problem to read binning schemes\n";
107 detectorBinning->Write();
108 generatorBinning->Write();
111 TH1 *histDataReco,*histDataTruth;
114 inputFile->GetObject(
"histDataReco",histDataReco);
115 inputFile->GetObject(
"histDataTruth",histDataTruth);
116 inputFile->GetObject(
"histMCGenRec",histMCGenRec);
118 #ifdef TEST_ZERO_UNCORR_ERROR
122 for(
int i=0;i<=histMCGenRec->GetNbinsX()+1;i++) {
123 for(
int j=0;j<=histMCGenRec->GetNbinsY()+1;j++) {
124 histMCGenRec->SetBinError(i,j,0.0);
129 histDataReco->Write();
130 histDataTruth->Write();
131 histMCGenRec->Write();
133 if((!histDataReco)||(!histDataTruth)||(!histMCGenRec)) {
134 cout<<
"problem to read input histograms\n";
141 TUnfold::EConstraint constraintMode= TUnfold::kEConstraintArea;
145 TUnfold::ERegMode regMode = TUnfold::kRegModeCurvature;
148 TUnfoldDensity::EDensityMode densityFlags=
149 TUnfoldDensity::kDensityModeBinWidth;
152 const char *REGULARISATION_DISTRIBUTION=0;
153 const char *REGULARISATION_AXISSTEERING=
"*[B]";
156 TUnfoldDensity unfold(histMCGenRec,TUnfold::kHistMapOutputHoriz,
157 regMode,constraintMode,densityFlags,
158 generatorBinning,detectorBinning,
159 REGULARISATION_DISTRIBUTION,
160 REGULARISATION_AXISSTEERING);
164 #ifdef TEST_INPUT_COVARIANCE
167 detectorBinning->CreateErrorMatrixHistogram(
"input_covar",
true);
168 for(
int i=1;i<=inputEmatrix->GetNbinsX();i++) {
169 Double_t e=histDataReco->GetBinError(i);
170 inputEmatrix->SetBinContent(i,i,e*e);
174 unfold.SetInput(histDataReco,0.0,0.0,inputEmatrix);
176 unfold.SetInput(histDataReco );
179 #ifdef PRINT_MATRIX_L
180 TH2 *histL= unfold.GetL(
"L");
181 for(Int_t j=1;j<=histL->GetNbinsY();j++) {
182 cout<<
"L["<<unfold.GetLBinning()->GetBinName(j)<<
"]";
183 for(Int_t i=1;i<=histL->GetNbinsX();i++) {
184 Double_t c=histL->GetBinContent(i,j);
185 if(c!=0.0) cout<<
" ["<<i<<
"]="<<c;
195 TSpline *rhoLogTau=0;
203 const char *SCAN_DISTRIBUTION=
"signal";
204 const char *SCAN_AXISSTEERING=0;
206 Int_t iBest=unfold.ScanTau(nScan,0.,0.,&rhoLogTau,
207 TUnfoldDensity::kEScanTauRhoMax,
208 SCAN_DISTRIBUTION,SCAN_AXISSTEERING,
212 Double_t t[1],rho[1],x[1],y[1];
213 rhoLogTau->GetKnot(iBest,t[0],rho[0]);
214 lCurve->GetPoint(iBest,x[0],y[0]);
215 TGraph *bestRhoLogTau=
new TGraph(1,t,rho);
216 TGraph *bestLCurve=
new TGraph(1,x,y);
217 Double_t *tAll=
new Double_t[nScan],*rhoAll=
new Double_t[nScan];
218 for(Int_t i=0;i<nScan;i++) {
219 rhoLogTau->GetKnot(i,tAll[i],rhoAll[i]);
221 TGraph *knots=
new TGraph(nScan,tAll,rhoAll);
223 cout<<
"chi**2="<<unfold.GetChi2A()<<
"+"<<unfold.GetChi2L()
224 <<
" / "<<unfold.GetNdf()<<
"\n";
231 TH1 *histDataUnfold=unfold.GetOutput(
"unfolded signal",0,0,0,kFALSE);
233 TH1 *histMCReco=histMCGenRec->ProjectionY(
"histMCReco",0,-1,
"e");
234 TH1 *histMCTruth=histMCGenRec->ProjectionX(
"histMCTruth",0,-1,
"e");
235 Double_t scaleFactor=histDataTruth->GetSumOfWeights()/
236 histMCTruth->GetSumOfWeights();
237 histMCReco->Scale(scaleFactor);
238 histMCTruth->Scale(scaleFactor);
240 TH2 *histProbability=unfold.GetProbabilityMatrix(
"histProbability");
242 unfold.GetRhoItotal(
"histGlobalCorr",0,0,0,kFALSE);
243 TH1 *histGlobalCorrScan=unfold.GetRhoItotal
244 (
"histGlobalCorrScan",0,SCAN_DISTRIBUTION,SCAN_AXISSTEERING,kFALSE);
245 unfold.GetRhoIJtotal(
"histCorrCoeff",0,0,0,kFALSE);
248 canvas.Print(
"testUnfold5.ps[");
259 histDataReco->SetMinimum(0.0);
260 histDataReco->Draw(
"E");
261 histMCReco->SetLineColor(kBlue);
262 histMCReco->Draw(
"SAME HIST");
265 histProbability->Draw(
"BOX");
269 histDataUnfold->Draw(
"E");
270 histDataTruth->SetLineColor(kBlue);
271 histDataTruth->Draw(
"SAME HIST");
272 histMCTruth->SetLineColor(kRed);
273 histMCTruth->Draw(
"SAME HIST");
278 bestRhoLogTau->SetMarkerColor(kRed);
279 bestRhoLogTau->Draw(
"*");
284 histGlobalCorrScan->Draw(
"HIST");
288 bestLCurve->SetMarkerColor(kRed);
289 bestLCurve->Draw(
"*");
292 canvas.Print(
"testUnfold5.ps");
294 canvas.Print(
"testUnfold5.ps]");