test_PSF.C

Deil Christoph, 10/10/2012 11:46 AM

Download (26.1 KB)

 
1
#include <iostream>
2

    
3
#include <TH1.h>
4
#include <TH2.h>
5
#include <TF1.h>
6
#include <TCanvas.h>
7
#include <TStyle.h>
8
#include <TFile.h>
9
#include <TLegend.h>
10

    
11
#include <sash/DataSet.hh>
12
#include <sash/HESSArray.hh>
13
#include <crash/EquatorSystem.hh>
14
#include <plotters/SkyHist.hh>
15
#include <plotters/FITSTools.hh>
16
#include <response/EffectiveAreaLookupIR.hh>
17
#include <background/BgStats.hh>
18
#include <background/BgMaps.hh>
19
#include <background/Utils.hh>
20
#include <background/AcceptanceLookupIR.hh>
21
#include <flux/PSFLookupIR.hh>
22
#include <flux/PSFInfo.hh>
23

    
24

    
25
//
26
// reads a PSF file created by the ExtractPSF tool and
27
// fits a parameterization to the PSF
28
//
29
int testfit( const char* filename = "psf.root" ){
30

    
31
  Flux::PSFInfo* psfinfo = Flux::PSFInfo::ReadFromFile(filename);
32
  if( !psfinfo ) return 1;
33

    
34
  TH1F* dist = psfinfo->CreateNormalizedDistribution();
35
  TF1* fit   = psfinfo->CreatePSFFunction("TRIPLEEXP");
36
  double radius = psfinfo->GetContainmentRadius();
37
  std::cout << "Containment radius: " << radius << std::endl;
38

    
39
  std::cout << "Integral: " << fit->Integral(0.0,0.45) << std::endl;
40

    
41
  TCanvas* psfCanvas = new TCanvas( "psfCanvas", "PSF (read)", 1000, 700 );
42
  psfCanvas->Divide(2,1);
43

    
44
  std::cout << *psfinfo << std::endl;
45

    
46
  psfCanvas->cd(1);
47
  dist->Draw();
48
  fit->Draw("L SAME");
49
  gPad->SetLogy();
50

    
51
  psfCanvas->cd(2);
52
  psfinfo->GetWeights().Draw();
53

    
54
  return 0;
55
}
56

    
57

    
58

    
59
//
60
// shows simple Fill functions of PSF class
61
//
62
int test_PSFInfo() {
63

    
64
  int muonRun    = 101;
65
  int telPattern = 30;
66
  double azimuth = 180.;
67
  double zenith  = 13.;
68
  double offset  = 0.5;
69
  double energy  = 1.0;
70

    
71
  double index = -2.0;
72

    
73
  // it's important to use the fullEnclosure config for effective areas! we don't want any theta cuts
74
  // since we also don't do them when filling the PSF lookup!
75
  Flux::PSFLookupIR* psfLookup = new Flux::PSFLookupIR( "std" );
76
  Response::EffectiveAreaLookupIR* effAreaLookup = 
77
    new Response::EffectiveAreaLookupIR( "std_fullEnclosure", true, true );
78

    
79
  Flux::PSFInfo* psfinfo_fixedE = new Flux::PSFInfo( Sash::HESSArray::GetHESSArray(), "test_fixedE", index );
80
  std::cout << *psfinfo_fixedE << std::endl;
81

    
82
  // fill PSF object for a single fixed energy
83
  psfinfo_fixedE->FillYourself(energy,muonRun,telPattern,azimuth,zenith,offset,1.0,psfLookup);
84

    
85

    
86
  // fill PSF object for an assumed E^(index) spectrum
87
  Flux::PSFInfo* psfinfo_spectrum = new Flux::PSFInfo( Sash::HESSArray::GetHESSArray(), "test_spectrum", index );
88
  std::cout << psfinfo_spectrum << std::endl;
89

    
90
  psfinfo_spectrum->FillYourself(muonRun,telPattern,azimuth,zenith,offset,1.0,true,psfLookup,effAreaLookup);
91

    
92

    
93

    
94
  TH1F& histo_fixedE = psfinfo_fixedE->GetPsf();
95
  TH1F& histo_spectrum = psfinfo_spectrum->GetPsf();
96

    
97
  TCanvas* testCanvas = new TCanvas("testCanvas", "test", 1100, 800 );
98
  testCanvas->Divide(2,2);
99

    
100
  testCanvas->cd(1);
101
  histo_fixedE.Draw();
102

    
103
  testCanvas->cd(3);
104
  psfinfo_fixedE->GetWeights().Draw();
105

    
106
  testCanvas->cd(2);
107
  histo_spectrum.Draw();
108

    
109
  testCanvas->cd(4);
110
  psfinfo_spectrum->GetWeights().Draw();
111

    
112

    
113
  // test fit
114
  TCanvas* psfCanvas = new TCanvas( "psfCanvas", "PSF fit", 1000, 700 );
115
  psfCanvas->cd();
116
  TH1F* dist = psfinfo_spectrum->CreateNormalizedDistribution();
117
  TF1* fit = psfinfo_spectrum->CreatePSFFunction("TRIPLEEXP");
118
  dist->Draw();
119
  fit->Draw("L SAME");
120

    
121

    
122
  // compare PSF for different optical efficiency
123
  Flux::PSFInfo* psfinfo_fixedE_mu1 = 
124
    new Flux::PSFInfo( Sash::HESSArray::GetHESSArray(), "test_fixedE_mu1", index );
125
  psfinfo_fixedE_mu1->FillYourself(energy,100,telPattern,azimuth,zenith,offset,1.0,psfLookup);
126
  std::cout << *psfinfo_fixedE_mu1 << std::endl;
127
  std::cout << psfinfo_fixedE_mu1->GetContainmentRadius() << std::endl;
128

    
129
  Flux::PSFInfo* psfinfo_fixedE_mu2 = 
130
    new Flux::PSFInfo( Sash::HESSArray::GetHESSArray(), "test_fixedE_mu2", index );
131
  psfinfo_fixedE_mu2->FillYourself(energy,102,telPattern,azimuth,zenith,offset,1.0,psfLookup);
132
  std::cout << *psfinfo_fixedE_mu2 << std::endl;
133
  std::cout << psfinfo_fixedE_mu2->GetContainmentRadius() << std::endl;
134

    
135
  TH1F* dist_mu1 = psfinfo_fixedE_mu1->CreateNormalizedDistribution();
136
  dist_mu1->SetLineColor(4);
137
  TH1F* dist_mu2 = psfinfo_fixedE_mu2->CreateNormalizedDistribution();
138
  dist_mu2->SetLineColor(2);
139

    
140
  dist_mu1->Scale(1.0/dist_mu1->GetMaximum());
141
  dist_mu2->Scale(1.0/dist_mu2->GetMaximum());
142

    
143
  TCanvas* optCanv = new TCanvas( "optCanv", "compare opt eff", 1000, 700 );
144
  optCanv->cd();
145
  dist_mu1->Draw();
146
  dist_mu2->Draw("same");
147
  gPad->SetLogy();
148

    
149
  return 0;
150
}
151

    
152

    
153

    
154
//
155
// open a hap result file and compare the PSF to data
156
//
157
// needs a hap result file and the psf file created by the ExtractPSF task
158
//
159
// arguments:
160
//    hap_result_file:    hap result file containing a BgMaps object
161
//    psf_file:           PSF as produced by the ExtractPSF task
162
//    run:                only use specified run (0=all runs) from result file
163
//    thetaSqrBins:       number of bins for the final theta^2 comparison plot
164
//    integrationRange:   theta^2 value up to which data and PSF model are integrated
165
//                        in the calculation of the overall normalization
166
//    cor_radius:         correlation radius to be used in the calculation of the correlated excess map
167
//    minPhi, maxPhi:     phi range used for the extraction of the theta^2 plot, in case of nearby sources
168
//
169
int compare_to_data( const char* hap_result_file, const char* psf_file, int run = 0,
170
                     int thetaSqrBins = 100, double integrationRange = 0.05,
171
                     double cor_radius = 0.08, double minPhi = 0., double maxPhi = 360. ){
172

    
173
  double thetaSqrMax = 0.3;
174

    
175
  Flux::PSFInfo* psfinfo = Flux::PSFInfo::ReadFromFile(psf_file);
176
  if( !psfinfo ) return 10;
177

    
178
  TFile* file = new TFile( hap_result_file );
179
  if( !file->IsOpen() ) return 1;
180

    
181
  Sash::HESSArray* hess = &(Sash::HESSArray::GetHESSArray());
182
  Background::BgStats *stats = 0;
183
  Sash::DataSet* ds = 0;
184
  if( run == 0 ) ds = Background::FindTotalDataSet();
185
  else ds = Background::FindRunDataSet();
186
  if( !ds ) return 2;
187
  if( run == 0 ){
188
    ds->GetEntry(0);
189
    std::vector<const Background::BgStats*> statsvec = 
190
      hess->GetAll<Background::BgStats>();
191
    for( unsigned int j=0 ; j<statsvec.size() ; ++j )
192
      std::cout << "BgStats " << j << ": " << statsvec[j]->GetName() << std::endl;
193
  
194
    stats = statsvec.size() > 0 ? const_cast<Background::BgStats*>(statsvec.front()) : 0;
195
  }
196
  else{
197
    for( int i=0 ; i<ds->GetEntries() ; ++i ){
198
      ds->GetEntry(i);
199

    
200
      std::vector<const Background::BgStats*> statsvec = 
201
        hess->GetAll<Background::BgStats>();
202
      for( unsigned int j=0 ; j<statsvec.size() ; ++j )
203
        std::cout << "BgStats " << j << ": " << statsvec[j]->GetName() << std::endl;
204
      stats = statsvec.size() > 0 ? const_cast<Background::BgStats*>(statsvec.front()) : 0;
205
      if( stats->GetIdNumber() == run ) break;
206
      else stats = 0;
207
    }
208
  }
209

    
210

    
211
  if( !stats ) return 3;
212

    
213
  std::cout << *stats << std::endl;
214

    
215
  std::vector<const Background::BgMaps*> mapsvec = 
216
    hess->GetAll<Background::BgMaps>();
217
  for( unsigned int j=0 ; j<mapsvec.size() ; ++j ){
218
    std::cout << "BgMaps  " << j << ": " << mapsvec[j]->GetName() << std::endl;
219
  }
220
  Background::BgMaps *maps = mapsvec.size() > 0 ? const_cast<Background::BgMaps*>(mapsvec.front()) : 0;
221
  if( !maps ) return 4;
222

    
223

    
224
  TH1F* psfdist = psfinfo->CreateNormalizedDistribution();
225
  TF1* psffit   = psfinfo->CreatePSFFunction("TRIPLEEXP");
226
  double radius = psfinfo->GetContainmentRadius();
227
  std::cout << "Containment radius: " << radius << std::endl;
228

    
229
  TCanvas* psfCanvas = new TCanvas( "psfCanvas", "PSF", 800, 600 );
230
  psfCanvas->Divide(2,1);
231

    
232
  std::cout << *psfinfo << std::endl;
233

    
234
  psfCanvas->cd(1);
235
  psfdist->Draw();
236
  psffit->Draw("L SAME");
237
  gPad->SetLogy();
238

    
239
  psfCanvas->cd(2);
240
  psfinfo->GetWeights().Draw();
241

    
242

    
243
  TCanvas* excessCanvas = new TCanvas( "excessCanvas", "excess map", 800, 800 );
244
  excessCanvas->cd();
245

    
246
  std::cout << "Making the Excess map..." << std::endl;
247
  Plotters::SkyHist *excess = maps->MakeExcessMap();
248
  std::cout << "Smoothing the Excess map..." << std::endl;
249
  Plotters::SkyHist *smooth = excess->GetCorrelatedSkyMap( cor_radius );
250
  smooth->SetVisFov(1.0); //2.0
251
  smooth->Draw("colz");
252
  smooth->DrawPSFFunction(psffit,cor_radius,false);
253

    
254
  // add a wedge showing the range of the theta^2 plot if that differs from the full circle
255
  if( minPhi > 0.0 || maxPhi < 360. ) {
256

    
257
    Plotters::SkyHist* sh = smooth;
258
    Tools::CircleSegment* wedge = new Tools::CircleSegment( sh->GetPosition(),
259
                                                            0., sqrt(thetaSqrMax),
260
                                                            minPhi, maxPhi, "wedge" );
261
    wedge->SetLineWidth(1);
262
    wedge->SetLineColor(kWhite);
263
    sh->DrawRegion(wedge);
264
  }
265

    
266
  gPad->Modified();
267

    
268
  TCanvas* azmCanvas = new TCanvas( "azmCanvas", "azimuth-related plots", 800, 600 );
269
  azmCanvas->cd();
270

    
271
  std::cout << "Making azimuth profile..." << std::endl;
272
  TH1F* azmProfile = excess->MakeAzimuthProfile(excess->GetPosition(), 0., sqrt(thetaSqrMax), 12, false );
273
  azmProfile->SetStats(0);
274
  azmProfile->Draw();
275
  if( azmProfile->GetMinimum() > 0.0 )
276
    azmProfile->SetMinimum(0);
277
  gPad->SetGridy();
278

    
279

    
280
  TCanvas* thetaCanvas = new TCanvas( "thetaCanvas", "theta plots", 800, 600 );
281
  thetaCanvas->cd();
282

    
283
  std::cout << "Making th2 for ON..." << std::endl;
284
  TH1F* thon = maps->GetOnMap().MakeThetaSq(thetaSqrMax,thetaSqrBins,minPhi,maxPhi,true);
285
  thon->Draw("hist");
286
  Plotters::SkyHist *alphaoff = (Plotters::SkyHist*) maps->GetOffMap().Clone("AlphaOff");
287

    
288
  std::cout << "Making alpha map..." << std::endl;
289
  Plotters::SkyHist *alpha = maps->MakeAlphaMap( );
290
  alphaoff->Multiply( alpha );
291

    
292
  std::cout << "Making th2 for alpha*OFF..." << std::endl;
293
  TH1F *thoff = alphaoff->MakeThetaSq(thetaSqrMax,thetaSqrBins,minPhi,maxPhi,true);
294
  thoff->SetLineColor(kRed);
295
  thoff->Draw("hist same");
296
  gPad->Modified();
297

    
298
  TF1* bgLevel = new TF1( "bgLevel", "pol0", 0., thetaSqrMax );
299
  thoff->Fit( bgLevel, "RW0" );
300
  bgLevel->Draw("L SAME");
301

    
302

    
303
  TCanvas* compCanvas = new TCanvas( "compCanvas", "comparison of data and PSF", 800, 800 );
304
  compCanvas->cd();
305

    
306
  TH1F* excessThetaSq = excess->MakeThetaSq(thetaSqrMax,thetaSqrBins,minPhi,maxPhi,true);
307
  excessThetaSq->SetTitle("comparison of PSF to data");
308
  excessThetaSq->Draw();
309
  excessThetaSq->GetYaxis()->SetTickLength(-0.01);
310

    
311
  TH1F* psf_rescaled = (TH1F*)psfinfo->GetPsf().Clone("psf_rescaled");
312
  psf_rescaled->SetLineColor(2);
313
  psf_rescaled->SetMarkerColor(2);
314

    
315
  // calculate scale factor from integral over first few bins
316
  // start with coarse histogram
317
  int dataBin = excessThetaSq->FindBin(integrationRange);
318
  double exactIntegrationRange = excessThetaSq->GetXaxis()->GetBinUpEdge(dataBin);
319
  double dataIntegral = excessThetaSq->Integral(1,dataBin,"width");
320
  int psfBin = psf_rescaled->FindBin(exactIntegrationRange-0.0001);
321
  double psfIntegral = psf_rescaled->Integral(1,psfBin,"width");
322
  double scaleFactor = dataIntegral/psfIntegral;
323

    
324
  std::cout << "dataBin: " << dataBin << " psfBin: " << psfBin 
325
            << " exact range: " << exactIntegrationRange << std::endl;
326

    
327
  psf_rescaled->Scale(scaleFactor);
328

    
329
  psf_rescaled->Draw("same");
330

    
331

    
332
  TLegend* leg = new TLegend( 0.6,0.6,0.89,0.89 );
333
  leg->AddEntry(excessThetaSq, "data", "L");
334
  leg->AddEntry(psf_rescaled, "PSF model", "L" );
335
  leg->SetFillColor(kWhite);
336
  leg->SetLineColor(kWhite);
337
  leg->Draw();
338

    
339

    
340
  // Crab fit (similar fit as in Crab paper, for comparison)
341
  TF1* func = new TF1( "psf_function",
342
                       "[0]*(exp(-((x)/(2*[1]*[1])))+[2]*exp(-((x)/(2*[3]*[3]))))",
343
                        0.0005, 0.2 );
344
  func->SetParameter(0,excessThetaSq->GetMaximum());
345
  func->SetParameter(1,0.046);
346
  func->SetParameter(2,0.15);
347
  func->SetParameter(3,0.12);
348
  excessThetaSq->Fit(func,"RI0");
349
  func->SetLineColor(kGreen);
350
  func->SetLineWidth(1);
351
  // func->Draw("L SAME");
352
  std::cout << "Simple fit: Chi2 / ndf = " << func->GetChisquare() << " / " << func->GetNDF() 
353
            << " prob: " << func->GetProb() << std::endl;
354

    
355
  excessThetaSq->GetXaxis()->SetRangeUser(0.,0.1);
356

    
357
  // create histograms with identical binning for Kolmogorov test
358
  // we assume that the PSF model has a finer binning than the data histogram
359
  // with the number of bins in a given range being an integer multiple of the data bins
360
  double maxK = 0.1;
361
  int nbinsK = excessThetaSq->FindBin(maxK);
362
  double xmaxK = excessThetaSq->GetXaxis()->GetBinUpEdge(nbinsK);
363
  double ratiod = psf_rescaled->FindBin(xmaxK-0.0001)/nbinsK;
364
  int ratio = int(round(ratiod));
365
  std::cout << "Ratio: " << ratiod << " -> " << ratio << std::endl;
366
  TH1F* dataHistoK = new TH1F( "dataHistoK", "comparison of data and PSF model;#theta^{2} / deg^{2}", 
367
                               nbinsK, 0., xmaxK );
368
  TH1F* modelHistoK = new TH1F( "modelHistoK", "modelHistoK", nbinsK, 0., xmaxK );
369
  for( int i=1 ; i<=nbinsK ; ++i ){
370
    dataHistoK->SetBinContent(i,excessThetaSq->GetBinContent(i));
371
    dataHistoK->SetBinError(i,excessThetaSq->GetBinError(i));
372
    double contentSum = 0.0;
373
    double varSum = 0.0;
374
    for( int j=1+(i-1)*ratio ; j<=i*ratio ; ++j ){
375
      double binc = psf_rescaled->GetBinContent(j);
376
      double bine = psf_rescaled->GetBinError(j);
377
      contentSum += binc;
378
      varSum += bine*bine;
379
    }
380
    modelHistoK->SetBinContent(i,contentSum/ratiod);
381
    modelHistoK->SetBinError(i,sqrt(varSum)/ratiod);
382
  }
383

    
384
  TCanvas* kolmoCanv = new TCanvas("kolmoCanv","Kolmogorov test", 900, 900 );
385
  kolmoCanv->cd(1);
386
  dataHistoK->Draw();
387
  dataHistoK->GetYaxis()->SetTickLength(-0.01);
388
  modelHistoK->SetLineColor(psf_rescaled->GetLineColor());
389
  modelHistoK->Draw("SAME");
390
  dataHistoK->SetMaximum(1.05*max(dataHistoK->GetMaximum(),modelHistoK->GetMaximum()));
391

    
392
//   quickPsf->Draw("hist same");
393

    
394
  dataHistoK->GetXaxis()->SetRangeUser(0.,0.036);
395

    
396
  TLegend* leg2 = new TLegend( 0.6,0.6,0.89,0.89 );
397
  leg2->AddEntry(dataHistoK, "data", "L");
398
  leg2->AddEntry(modelHistoK, "PSF model", "L" );
399
  leg2->SetFillColor(kWhite);
400
  leg2->SetLineColor(kWhite);
401
  leg2->Draw();
402

    
403
  double prob = dataHistoK->KolmogorovTest(modelHistoK);
404
  std::cout << " Kolmogorov prob: " << prob << std::endl;
405

    
406
  return 0;
407
}
408

    
409

    
410
int psf_to_fits( const char* psffile, const char* fitsfile ){
411

    
412
  Flux::PSFInfo* psfinfo = Flux::PSFInfo::ReadFromFile(psffile);
413
  if( !psfinfo ) return 1;
414

    
415
  TF1* psffunc = psfinfo->CreatePSFFunction( "TRIPLEEXP" );
416

    
417
  Stash::Coordinate pos( Stash::Lambda( "18h0m0s" ),
418
                         Stash::Beta( "0d0'0.0" ),
419
                         Crash::GetRADecJ2000System() );
420
  Stash::Beta fov(0.5,Stash::Angle::Degrees);
421
  Stash::SmallAngle binsize(0.002,Stash::Angle::Degrees);
422
  Plotters::SkyHist* sh = new Plotters::SkyHist("sh","PSF",pos,fov,binsize);
423

    
424
  Background::AcceptanceLookupIR::FillAcceptanceMap( *sh, pos, 1.0, psffunc );
425

    
426
  std::cout << "Writing map \"" << sh->GetName() << "\" to file " << fitsfile << std::endl;
427
  Plotters::SkyHistToFITS(sh, fitsfile, sh->GetName() );
428

    
429
  return 0;
430
}
431

    
432

    
433

    
434
//
435
//
436
//
437
//   THE FOLLOWING FUNCTIONS ARE FOR EXPERT TESTS ONLY!!!
438
//
439
//
440

    
441

    
442
//
443
// test the --fast option of ExtractPSF
444
//
445
int test_fast( const char* file1 = "psf.root", const char* file2 = "psf_fast.root" ) {
446

    
447
  Flux::PSFInfo* psfinfo1 = Flux::PSFInfo::ReadFromFile(file1);
448
  if( !psfinfo1 ) return 1;
449

    
450
  Flux::PSFInfo* psfinfo2 = Flux::PSFInfo::ReadFromFile(file2);
451
  if( !psfinfo2 ) return 2;
452

    
453
  std::cout << "1:\n" << *psfinfo1 << std::endl;
454
  std::cout << "2:\n" << *psfinfo2 << std::endl;
455

    
456
  TH1F* dist1 = psfinfo1->CreateNormalizedDistribution();
457
  TH1F* dist2 = psfinfo2->CreateNormalizedDistribution();
458
  dist2->SetLineColor(2);
459

    
460
  TCanvas* psfCanvas = new TCanvas( "psfFastCanvas", "PSF test", 1000, 700 );
461
  psfCanvas->cd();
462

    
463
  dist1->Draw();
464
  dist2->Draw("SAME");
465

    
466
  gPad->SetLogy();
467

    
468
  return 0;
469
}
470

    
471

    
472
//
473
// test uncertainty handling
474
//
475
int test_uncertainty( const char* filename = "psf.root" ) {
476

    
477
  Flux::PSFInfo* psfinfo = Flux::PSFInfo::ReadFromFile(filename);
478
  if( !psfinfo ) return 1;
479
  std::cout << *psfinfo << std::endl;
480

    
481
  std::cout << "Fitting psf with DOUBLEEXP" << std::endl;
482
  TF1* fit21 = psfinfo->CreatePSFFunction("DOUBLEEXP");
483
  std::cout << "Fitting psf with TRIPLEEXP" << std::endl;
484
  TF1* fit22 = psfinfo->CreatePSFFunction("TRIPLEEXP");
485

    
486
  TH1F*  dist  = psfinfo->CreateNormalizedDistributionOldStyle();
487
  TH1F*  dist2 = psfinfo->CreateNormalizedDistribution();
488

    
489
  std::cout << "name: " << dist2->GetName() << std::endl;
490

    
491
  TCanvas* testCanvas = new TCanvas("uncertaintyCanvas", "test uncertainties", 1100, 800 );
492
  testCanvas->Divide(2,2);
493

    
494
  testCanvas->cd(1);
495
  dist->SetTitle("old-style");
496
  dist->Draw();
497

    
498
  gPad->SetLogy();
499

    
500
  testCanvas->cd(2);
501

    
502
  dist2->SetTitle("new style, double exp");
503
  dist2->Draw();
504

    
505
  fit21->Draw("L SAME");
506

    
507
  gPad->SetLogy();
508

    
509
  testCanvas->cd(4);
510
  TH1D* dist2c = (TH1D*)dist2->Clone("dist2c");
511
  dist2c->SetTitle("new style, triple exp");
512
  dist2c->Draw();
513
  
514
  fit22->Draw("L SAME");
515

    
516
  gPad->SetLogy();
517

    
518
  return(0);
519
}
520

    
521

    
522

    
523
//
524
// access the PSF lookup file directly
525
//
526
int draw_fixed_PSF() {
527

    
528
  gStyle->SetOptFit(1111);
529

    
530
  TFile* f = new TFile( "$HESSCONFIG/std/PSF.root" , "READ" );
531
  TH2F* psf = (TH2F*)f->Get("ThetaSq_muon101_30telp_180azm_20deg_0.5off");
532

    
533
  double logE = log10(1.0);
534

    
535
  int bin = psf->GetXaxis()->FindBin(logE);
536

    
537
  TH1D* proj = psf->ProjectionY("_py",bin,bin);
538
  proj->SetStats(0);
539

    
540
  TCanvas* canvas = new TCanvas("canvas", "PSF", 1100, 800 );
541
  canvas->cd();
542
  proj->Draw("hist");
543
  gPad->SetLogy();
544

    
545
  Stash::Coordinate pos( Stash::Lambda( "18h55m52.63s" ),
546
                         Stash::Beta( "-10d0'52.5" ),
547
                         Crash::GetRADecJ2000System() );
548
  Stash::Beta fov(0.3,Stash::Angle::Degrees);
549
  Stash::SmallAngle binsize(0.002,Stash::Angle::Degrees);
550
  Plotters::SkyHist* sh = new Plotters::SkyHist("sh","PSF",pos,fov,binsize);
551
  Plotters::SkyHist* shf = new Plotters::SkyHist("shf","PSF func",pos,fov,binsize);
552

    
553
  Background::AcceptanceLookupIR::FillAcceptanceMap( *sh, pos, 1.0, proj );
554
  sh->SetContour(50);
555

    
556
  TCanvas* psfCanvas = new TCanvas("psfCanvas", "PSF", 1100, 800 );
557
  psfCanvas->Divide(2,2);
558

    
559
  psfCanvas->cd(1);
560
  psf->Draw("colz");
561
  psf->SetStats(0);
562
  psf->SetMaximum(100.);
563

    
564
  psfCanvas->cd(2);
565
  proj->Draw();
566
  gPad->SetLogy();
567

    
568
  TF1* func = new TF1( "psf_function",
569
                       "[0]*exp(-((x)/(2*[1]*[1])))+[2]*exp(-((x)/(2*[3]*[3])))",
570
                       0.0005, 0.2 );
571

    
572
  double s = proj->GetMaximum();
573
  func->SetParameters( s*0.3, 0.2, s, 0.05 );
574
  func->SetParLimits(0,0.001,1000000.);
575
  func->SetParLimits(1,0.05,0.8);
576
  func->SetParLimits(2,0.001,1000000.);
577
  func->SetParLimits(3,0.01,0.2);
578

    
579
  proj->Fit( func, "", "", 0.000, 0.04 );
580
  proj->SetStats(1);
581

    
582
  Background::AcceptanceLookupIR::FillAcceptanceMap( *shf, pos, 1.0, func );
583
  shf->SetContour(50);
584

    
585
  psfCanvas->cd(3);
586
  sh->Draw("colz");
587
  gPad->Modified();
588
  
589
  psfCanvas->cd(4);
590
  shf->Draw("colz");
591
  gPad->Modified();
592
  
593
  return 0;
594
}
595

    
596

    
597
//
598
// compare azimuth dependence of PSF
599
//
600
int azimuth_dependence() {
601

    
602
  double spectralIndex = 3.5;
603

    
604
  Flux::PSFLookupIR* psfLookup = new Flux::PSFLookupIR( "std" );
605
  Response::EffectiveAreaLookupIR* effAreaLookup = 
606
    new Response::EffectiveAreaLookupIR( "std_fullEnclosure", true, true );
607

    
608
  Flux::PSFInfo* psfinfo_north = 
609
    new Flux::PSFInfo( Sash::HESSArray::GetHESSArray(), "psf_north", spectralIndex );
610
  std::cout << *psfinfo_north << std::endl;
611
  Flux::PSFInfo* psfinfo_south = 
612
    new Flux::PSFInfo( Sash::HESSArray::GetHESSArray(), "psf_south", spectralIndex );
613
  std::cout << *psfinfo_south << std::endl;
614
  Flux::PSFInfo* psfinfo_ipol = 
615
    new Flux::PSFInfo( Sash::HESSArray::GetHESSArray(), "psf_ipol", spectralIndex );
616
  std::cout << *psfinfo_ipol << std::endl;
617

    
618

    
619
  psfinfo_north->FillYourself(101,30,0.,30.,0.5,1.0,true,psfLookup,effAreaLookup);
620
  psfinfo_south->FillYourself(101,30,180.,30.,0.5,1.0,true,psfLookup,effAreaLookup);
621
  psfinfo_ipol->FillYourself( 101,30,90.,30.,0.5,1.0,true,psfLookup,effAreaLookup);
622

    
623
  TH1F* psfdist_north = psfinfo_north->CreateNormalizedDistribution();
624
  TH1F* psfdist_south = psfinfo_south->CreateNormalizedDistribution();
625
  TH1F* psfdist_ipol  = psfinfo_ipol->CreateNormalizedDistribution();
626

    
627
  psfdist_north->Rebin(6);
628
  psfdist_north->Scale(1./6.);
629
  psfdist_south->Rebin(6);
630
  psfdist_south->Scale(1./6.);
631
  psfdist_ipol->Rebin(6);
632
  psfdist_ipol->Scale(1./6.);
633

    
634
  TCanvas* azmCanv = new TCanvas("azmCanv","azimuth dependence of PSF", 900, 900 );
635
  azmCanv->cd();
636

    
637
  psfdist_south->SetStats(0);
638
  psfdist_south->SetLineColor(4);
639
  psfdist_south->Draw();
640
  psfdist_south->GetYaxis()->SetTickLength(-0.01);
641
  psfdist_south->GetXaxis()->SetRangeUser(0.,0.1);
642

    
643
  psfdist_north->SetLineColor(1);
644
  psfdist_north->Draw("same");
645

    
646
  psfdist_ipol->SetLineColor(2);
647
  psfdist_ipol->Draw("same");
648

    
649
  return 0;
650
}
651

    
652

    
653

    
654
//
655
// compare zenith dependence of PSF
656
//
657
int zenith_dependence() {
658

    
659
  double spectralIndex = 3.5;
660

    
661
  Flux::PSFLookupIR* psfLookup = new Flux::PSFLookupIR( "std" );
662
  Response::EffectiveAreaLookupIR* effAreaLookup = 
663
    new Response::EffectiveAreaLookupIR( "std_fullEnclosure", true, true );
664

    
665
  Flux::PSFInfo* psfinfo_20 = 
666
    new Flux::PSFInfo( Sash::HESSArray::GetHESSArray(), "psf_20", spectralIndex );
667
  std::cout << *psfinfo_20 << std::endl;
668
  Flux::PSFInfo* psfinfo_30 = 
669
    new Flux::PSFInfo( Sash::HESSArray::GetHESSArray(), "psf_30", spectralIndex );
670
  std::cout << *psfinfo_30 << std::endl;
671
  Flux::PSFInfo* psfinfo_ipol = 
672
    new Flux::PSFInfo( Sash::HESSArray::GetHESSArray(), "psf_ipol", spectralIndex );
673
  std::cout << *psfinfo_ipol << std::endl;
674

    
675

    
676

    
677
  psfinfo_20->FillYourself(101,30,180.,20.,0.5,1.0,true,psfLookup,effAreaLookup);
678
  psfinfo_30->FillYourself(101,30,180.,30.,0.5,1.0,true,psfLookup,effAreaLookup);
679
  psfinfo_ipol->FillYourself(101,30,180.,25.,0.5,1.0,true,psfLookup,effAreaLookup);
680

    
681

    
682
  TH1F* psfdist_20 = psfinfo_20->CreateNormalizedDistribution();
683
  TH1F* psfdist_30 = psfinfo_30->CreateNormalizedDistribution();
684
  TH1F* psfdist_ipol  = psfinfo_ipol->CreateNormalizedDistribution();
685

    
686
  psfdist_20->Rebin(6);
687
  psfdist_20->Scale(1./6.);
688
  psfdist_30->Rebin(6);
689
  psfdist_30->Scale(1./6.);
690
  psfdist_ipol->Rebin(6);
691
  psfdist_ipol->Scale(1./6.);
692

    
693
  TCanvas* zenCanv = new TCanvas("zenCanv","zenith dependence of PSF", 900, 900 );
694
  zenCanv->cd();
695

    
696
  psfdist_30->SetStats(0);
697
  psfdist_30->SetLineColor(4);
698
  psfdist_30->Draw();
699
  psfdist_30->GetYaxis()->SetTickLength(-0.01);
700
  psfdist_30->GetXaxis()->SetRangeUser(0.,0.1);
701

    
702
  psfdist_20->SetLineColor(1);
703
  psfdist_20->Draw("same");
704

    
705
  psfdist_ipol->SetLineColor(2);
706
  psfdist_ipol->Draw("same");
707

    
708
  return 0;
709
}
710

    
711

    
712
//
713
// compare dependence of PSF on spectral index
714
//
715
int spectral_dependence() {
716

    
717
  Flux::PSFLookupIR* psfLookup = new Flux::PSFLookupIR( "std" );
718
  Response::EffectiveAreaLookupIR* effAreaLookup = 
719
    new Response::EffectiveAreaLookupIR( "std_fullEnclosure", true, true );
720

    
721
  Flux::PSFInfo* psfinfo_20 = new Flux::PSFInfo( Sash::HESSArray::GetHESSArray(), "psf_20", 2.0 );
722
  std::cout << *psfinfo_20 << std::endl;
723
  Flux::PSFInfo* psfinfo_25 = new Flux::PSFInfo( Sash::HESSArray::GetHESSArray(), "psf_25", 2.5 );
724
  std::cout << *psfinfo_25 << std::endl;
725
  Flux::PSFInfo* psfinfo_30 = new Flux::PSFInfo( Sash::HESSArray::GetHESSArray(), "psf_30", 3.0 );
726
  std::cout << *psfinfo_30 << std::endl;
727

    
728

    
729
  psfinfo_20->FillYourself(101,30,180.,20.,0.5,1.0,true,psfLookup,effAreaLookup);
730
  psfinfo_25->FillYourself(101,30,180.,20.,0.5,1.0,true,psfLookup,effAreaLookup);
731
  psfinfo_30->FillYourself(101,30,180.,20.,0.5,1.0,true,psfLookup,effAreaLookup);
732

    
733

    
734
  TH1F* psfdist_20 = psfinfo_20->CreateNormalizedDistribution();
735
  TH1F* psfdist_25 = psfinfo_25->CreateNormalizedDistribution();
736
  TH1F* psfdist_30 = psfinfo_30->CreateNormalizedDistribution();
737

    
738
  psfdist_20->Rebin(6);
739
  psfdist_20->Scale(1./6.);
740
  psfdist_30->Rebin(6);
741
  psfdist_30->Scale(1./6.);
742
  psfdist_25->Rebin(6);
743
  psfdist_25->Scale(1./6.);
744

    
745
  TCanvas* specCanv = new TCanvas("specCanv","dependence of PSF on spectral index", 900, 900 );
746
  specCanv->cd();
747

    
748
  psfdist_30->SetStats(0);
749
  psfdist_30->SetLineColor(4);
750
  psfdist_30->Draw();
751
  psfdist_30->GetYaxis()->SetTickLength(-0.01);
752
  psfdist_30->GetXaxis()->SetRangeUser(0.,0.1);
753

    
754
  psfdist_20->SetLineColor(1);
755
  psfdist_20->Draw("same");
756

    
757
  psfdist_25->SetLineColor(2);
758
  psfdist_25->Draw("same");
759

    
760
  return 0;
761
}
762

    
763
//
764
// compare zenith interpolation of PSF
765
// set HESSCONFIG to right directory !!!
766
// ~/scratch/lookups/std_10deg_fullEnclosure/result
767
//
768
int fancy_zenith_dependence() {
769

    
770
  double spectralIndex = 3.5;
771

    
772
  Flux::PSFLookupIR* psfLookup = new Flux::PSFLookupIR( "std_fullEnclosure" );
773
  Response::EffectiveAreaLookupIR* effAreaLookup = 
774
    new Response::EffectiveAreaLookupIR( "std_fullEnclosure", true, true );
775
  Flux::PSFLookupIR* psfLookup2 = new Flux::PSFLookupIR( "std_10deg_fullEnclosure" );
776
  Response::EffectiveAreaLookupIR* effAreaLookup2 = 
777
    new Response::EffectiveAreaLookupIR( "std_10deg_fullEnclosure", true, true );
778

    
779
  Flux::PSFInfo* psfinfo_0 = 
780
    new Flux::PSFInfo( Sash::HESSArray::GetHESSArray(), "psf_0", spectralIndex );
781
  std::cout << *psfinfo_0 << std::endl;
782
  Flux::PSFInfo* psfinfo_10_corr = 
783
    new Flux::PSFInfo( Sash::HESSArray::GetHESSArray(), "psf_10_corr", spectralIndex );
784
  std::cout << *psfinfo_10_corr << std::endl;
785
  Flux::PSFInfo* psfinfo_10_ipol = 
786
    new Flux::PSFInfo( Sash::HESSArray::GetHESSArray(), "psf_10_ipol", spectralIndex );
787
  std::cout << *psfinfo_10_ipol << std::endl;
788
  Flux::PSFInfo* psfinfo_20 = 
789
    new Flux::PSFInfo( Sash::HESSArray::GetHESSArray(), "psf_20", spectralIndex );
790
  std::cout << *psfinfo_20 << std::endl;
791

    
792

    
793
  psfinfo_0->FillYourself(101,30,180.,0.,0.5,1.0,true,psfLookup,effAreaLookup);
794
  psfinfo_10_corr->FillYourself(101,30,180.,10.,0.5,1.0,true,psfLookup2,effAreaLookup2);
795
  psfinfo_10_ipol->FillYourself( 101,30,180.,10.,0.5,1.0,true,psfLookup,effAreaLookup);
796
  psfinfo_20->FillYourself(101,30,180.,20.,0.5,1.0,true,psfLookup,effAreaLookup);
797

    
798

    
799
  TH1F* psfdist_0 = psfinfo_0->CreateNormalizedDistribution();
800
  TH1F* psfdist_10_corr = psfinfo_10_corr->CreateNormalizedDistribution();
801
  TH1F* psfdist_10_ipol = psfinfo_10_ipol->CreateNormalizedDistribution();
802
  TH1F* psfdist_20 = psfinfo_20->CreateNormalizedDistribution();
803

    
804
  psfdist_0->Rebin(6);
805
  psfdist_0->Scale(1./6.);
806
  psfdist_10_corr->Rebin(6);
807
  psfdist_10_corr->Scale(1./6.);
808
  psfdist_10_ipol->Rebin(6);
809
  psfdist_10_ipol->Scale(1./6.);
810
  psfdist_20->Rebin(6);
811
  psfdist_20->Scale(1./6.);
812

    
813
  TCanvas* zenCanv = new TCanvas("zenCanv","zenith dependence of PSF", 900, 900 );
814
  zenCanv->cd();
815

    
816
  psfdist_0->SetStats(0);
817
  psfdist_0->SetLineColor(4);
818
  psfdist_0->Draw();
819
  psfdist_0->GetYaxis()->SetTickLength(-0.01);
820
  psfdist_0->GetXaxis()->SetRangeUser(0.,0.1);
821

    
822
  psfdist_20->SetLineColor(1);
823
  psfdist_20->Draw("same");
824

    
825
  psfdist_10_ipol->SetLineColor(2);
826
  psfdist_10_ipol->Draw("same");
827
  psfdist_10_corr->SetLineColor(3);
828
  psfdist_10_corr->Draw("same");
829

    
830
  return 0;
831
}
832

    
833