unfolding of energy spectra: combunfold · daniel mazin magic software school, july 2016, kochel am...
TRANSCRIPT
Unfolding of energy spectra: CombUnfold.C
Daniel MazinICRR, U-Tokyo and Max-Planck-Institute for Physics, Munich
6th MAGIC Software School, July 2016, Kochel am See
Sabrina EineckeTU Dortmund
Unfolding of energy spectra: CombUnfold.C
Daniel MazinICRR, U-Tokyo and Max-Planck-Institute for Physics, Munich
6th MAGIC Software School, July 2016, Kochel am See
Sabrina EineckeTU Dortmund
7th MAGIC Software School, June 2018, La Palma
Daniel Mazin MAGIC software school, July 2016, Kochel am See !3
Acceptance
Resolution Background Indirect
Measurement
Etrue
Etrue
Eest Eest
Eest
Unfolding
Measurement process suffers from following properties • Indirect measurement • Limited resolution • Limited acceptance • Threshold effects • Background
Motivation
Daniel Mazin MAGIC software school, July 2016, Kochel am See !4
Finite energy resolution
• Variance within the air shower• Depth of Gammas follows certain probability• Interactions between particles follow certain probabilities• ...
• Detector not perfect• Reflection at mirrors• Detection efficiency• Limited measurement resolution of
electronics• ...
• Binning of observables• Systematic distortions like threshold effects
2 gammas with same energy:
2 gammas with different energy:
energy migration matrix
Motivation
Daniel Mazin MAGIC software school, July 2016, Kochel am See
Inverting of migration matrix
• Unfolding uses the migration matrix to convert excess events in Eest to excess events in Etrue
• We need to work with distributions, cannot access true energy of individual events
5
Estimated energy is not true energy!
Daniel Mazin MAGIC software school, July 2016, Kochel am See
Mathematical description
!6
Measured distribution of observable
Unknown distribution of the
sought
Migration matrix: response of detector, geometry, atmosphere, magnetic field, Zd,
Az, ...
Measured background distribution of observable
~A = M · ~B +~b
Daniel Mazin MAGIC software school, July 2016, Kochel am See
Mathematical description
!7
Measured distribution of observable
Unknown distribution of the
sought
Migration matrix: response of detector, geometry, atmosphere, magnetic field, Zd,
Az, ...
~A = M · ~B +~b
Eest
Daniel Mazin MAGIC software school, July 2016, Kochel am See
Mathematical description
!8
§ Simplification: (Solution methods for are the same as for )
§ System of equations:
§ nA = nB : one solution § nA < nB : underconstrained case, infinite solutions § nA > nB : overconstrained case, no exact solutions
~b = 0~A�~b = M · ~B ~A = M · ~B
0
B@A1...
AnA
1
CA =
0
B@M11 · · · M1nB
.... . .
...MnA1 · · · MnAnB
1
CA ·
0
B@B1...
BnB
1
CA
note: b=0 in CombUnfold because we work with excess distribution
Daniel Mazin MAGIC software school, July 2016, Kochel am See
Unfolding solutions
!9
§ In principle: § Exact solutions § Minimizing specific expressions
Least Squares expression
à only valid for observables following a gaussian distribution à not fulfilled for bins with low event numbers
Likelihood expression à takes also Poisson statistics in account
L0(~a) =X
i
(gi(~a)� gi,m · ln gi(~a))!= min
with p(gi,m; gi): Poisson distr., gi,m: number of measured events in bin ~a: minimization parameter
�20 =
⇣~A�M · ~B
⌘T· V [ ~A]�1 ·
⇣~A�M · ~B
⌘!= min.
Daniel Mazin MAGIC software school, July 2016, Kochel am See
Forward (un)folding
!10
§ Assumption of parametric function for with parameters § e.g. for power-law distribution:
§ Find best match between observed data and folded with § Minimize (deviation between and with current )
§ Continous provides smooth solution § No regularization needed
§ Not independent from model § Not sensitive for distinct features
§ No real unfolding, use as cross-check!
f(x,~a)
f(x, a1, a2) = a1 · xa2
~a = (a1, a2, ..., an)
f(x) MM · f(x) ~a
~B
Daniel Mazin MAGIC software school, July 2016, Kochel am See
Example of where it will fail
!11
if you don’t know there is a line you will not find it in the forward folding method
Daniel Mazin MAGIC software school, July 2016, Kochel am See
Regularization
!12
§ Unfolding is ill-posed problem § Strong fluctuations in solution § Large deviations from true distribution
§ Reasons for fluctuations: § Small and insignificant entries in matrix § Amplification during unfolding § Measurement inaccuracy § Solution is dominated by noise
§ How to suppress these fluctuations? à Regularization!
§ Regularization = Requirement to
solution § e.g. smoothness
§ Too strong: Loss of important
information § Too weak: Too many unphysical
fluctuations
BUT: Regularization is unavoidable and has to be controlled!!!
Motivation: Explanation:
Daniel Mazin MAGIC software school, July 2016, Kochel am See
Regularization
!13
Too small
Too strong
Balanced
Fluctuations are suppressed
Daniel Mazin MAGIC software school, July 2016, Kochel am See
Regularization• Two additional terms:
• w is the weight of the regularization
• Reg is a measure of smoothness of B (true distribution)• Solution for B is obtained by minimizing:
• w is regularization parameter:
• Large w: no regularization; strong fluctuations
• Small w: strong regularization; smooth result
14
Daniel Mazin MAGIC software school, July 2016, Kochel am See
Regularization
!15
~p~B
~B
~BReg( ~B)
Reg( ~B) =X
j
pj · ln✓pj✏j
◆
Different choices of regularization applied to :
§ Tikhonov: Regularization term as square of an operator applied to à by using second derivative the curvature of is constrained
§ Schmelling: Regularizaiton term as minimum cross entropy à representing the deviation from normalized denoted as to normalized prior knowledge about ~✏
Reg( ~B) =X
j
✓d2B
dx2
◆2
j
=X
j
✓2 ·
✓Bj+1 �Bj
Bj+1 +Bj� Bj �Bj�1
Bj +Bj�1
◆◆2
Daniel Mazin MAGIC software school, July 2016, Kochel am See
Regularization
!16
Daniel Mazin MAGIC software school, July 2016, Kochel am See
Regularization in CombUnfold
!17
Daniel Mazin MAGIC software school, July 2016, Kochel am See
Regularization
18
Too small
Too strong
Balanced
(Fluctuations are suppressed à uncertainties become smaller) V [ ~B] =
✓I+
�2
w
◆�2
too strong regularization results in too small error bars
Daniel Mazin MAGIC software school, July 2016, Kochel am See
Regularization
19
real
exam
ple
from
Com
bUnf
old
Daniel Mazin MAGIC software school, July 2016, Kochel am See 20
HANDS-ON
CombUnfold.C
Daniel Mazin MAGIC software school, July 2016, Kochel am See
Combining spectra
• CombUnfold.C was designed to join several spectra and unfold them at once. Even if you have just a single flute output file, use this macro!
• Combining is done by proper averaging of collection areas and observation time
• Energy binnings have to be the same in different samples (rerun flute if needed)
21
Daniel Mazin MAGIC software school, July 2016, Kochel am See
Correlated fit• Due to unfolding, bins in true energy are
correlated
• Chi2 fit is more complicated: the correlations have to be taken into account using the covariance (error) matrix of the unfolding result
• Once the energy spectrum is unfolded, a correlated fit is performed inside CombUnfold.
• The results of the correlated fit should be quoted, not the simple fits to the unfolded spectra
22
Daniel Mazin MAGIC software school, July 2016, Kochel am See
program
• combunfold.rc (adjust to your data!, can rename it)
• Output of flute (Output_flute.root) is the input file for the unfolding
• CombUnfold.C (no changes needed)
• Enter root and execute:
• .x CombUnfold.C(“./combunfold.rc”)
23
Daniel Mazin MAGIC software school, July 2016, Kochel am See
Cookbook for CombUnfold
1. Adjust input file (output from flute, typically Output_flute.root) to MCombineDataForUnfolding.InputFiles
2. Run forward folding with
1.Automatic ranges in Eest and in Etrue
2.Power law function
3. Change Eest and Etrue to manual ranges and adjust the Eest and Etrue ranges (bin numbers)
4. Run forward folding with power law, check histograms
5. Eventually change the function to log parabola or broken power law
6. Run all 6 unfolding algorithms with the same setting as by step 5:check histograms for sanity, compare χ2 results and fit parameters
7. Eventually you need to adjust the regularization weight by hand
8. Optionally you can adjust the fitting range in energy 24
important slide!steps:
Daniel Mazin MAGIC software school, July 2016, Kochel am See
combunfold.rc
25
MCombineDataForUnfolding.NumFiles: 1
Number of files to be combined and unfolded:
Names of files to be combined and unfolded. These are flute output files:
MCombineDataForUnfolding.InputFiles[0]: /nfs/mydir/Output_flute.root
Number of iterations:# ------------------------------------------------------------------------- # Use this to set the number of spectrum iterations # ------------------------------------------------------------------------- MCombineDataForUnfolding.NSpectrumIterations: 1
step 1
keep here 1. it means initial unfolding to determine the tentative spectrum and 1 iteration using the tentative spectrum
Daniel Mazin MAGIC software school, July 2016, Kochel am See
combunfold.rc
# ----------------------- # FlagUnfold = 1 Schmelling (minimization by Gauss-Newton
method) # 2 Tikhonov (minimization by MINUIT) # 3 Bertero (appropriate for under-constrained case) # 4 Forward unfolding # 5 Schmelling (minimization by MINUIT) # 6 BerteroW (approproate for over-constrained case) MCallUnfold.FlagUnfold: 4
26
Choose the unfolding method!step 2
Daniel Mazin MAGIC software school, July 2016, Kochel am See
combunfold.rc
# If bin range for Eest should be selected automatically # set RangeAutoSelectA to 1 MCallUnfold.RangeAutoSelectA: 1
# If bin range for Etrue should be selected automatically # set RangeAutoSelectB to 1 MCallUnfold.RangeAutoSelectB: 1
27
Run first with forward folding and automatic range selectionstep 2
Daniel Mazin MAGIC software school, July 2016, Kochel am See
Adjust the function you fit the unfolded spectrum with
28
# Type of function to be fitted to the fluxes # or to be used in the Forward unfolding # F1Type = 1 power law (Npar = 3) # 2 for power law with cutoff (Npar = 4) # 3 for power law with VARIABLE POWER INDEX (Npar = 5) # 4 for power law with VARIABLE POWER INDEX and cutoff # (Npar = 5) # 5 for broken power law (Npar = 6) # 6 for broken power law # with variable alpha1 (Npar = 7) # 7 for broken power law # with a cutoff (Npar = 7) # 8 for broken power law with variable # alpha1 and cutoff (Npar = 8) MCallUnfold.F1Type: 1
step 2 (and 5)
Daniel Mazin MAGIC software school, July 2016, Kochel am See 29
remove comment markers at the function of your choice and check the comment markers for the other functions
MCallUnfold.F1Type: 3
# Optional : for the parameters of the function, # give starting values, initial step sizes, lower and upper limits # and indicate by fix=1 whether a parameter should be fixed # these are values for Type 1 # f0 alpha r MCallUnfold.Npar: 3 MCallUnfold.ParamVinit: 0.4e-10 -2.0 0.25 MCallUnfold.ParamStep: 1.e-12 0.2 0.0 MCallUnfold.ParamLimlo: 1.e-15 -10.0 0.0 MCallUnfold.ParamLimup: 1.e-7 10.0 0.0 MCallUnfold.ParamFix: 0 0 1
Adjust the function you fit the unfolded spectrum withstep 2 (and 5)
Daniel Mazin MAGIC software school, July 2016, Kochel am See
combunfold.rc
# If bin range for Eest should be selected automatically # set RangeAutoSelectA to 1 MCallUnfold.RangeAutoSelectA: 0
# If bin range for Etrue should be selected automatically # set RangeAutoSelectB to 1 MCallUnfold.RangeAutoSelectB: 0
30
change the energy range to manualstep 3
Daniel Mazin MAGIC software school, July 2016, Kochel am See
combunfold.rc
# ----------------------- # Bin range of Eest to be used in the unfolding # (unless selected automatically) MCallUnfold.nminAnmaxA: 7 25
# Bin range of Etrue to be used in the unfolding # (unless selected automatically) MCallUnfold.nminBnmaxB: 7 17
31
• Choose the ranges of Eest and Etrue • Needs to be adjusted!
Select bin ranges from the migration matrix plot in the OrigPlot tab:
step 3
Daniel Mazin MAGIC software school, July 2016, Kochel am See
Select bins in Eest and Etrue
32
step 3
• Eest: only bins containing more than ~10 events, no gaps
• Etrue: bins with acceptance of > 70%
• Etrue: bins with Aeff > 1000m2
Daniel Mazin MAGIC software school, July 2016, Kochel am See
combunfold.rc
33
1. place curser over the bin
2. read the bin numbers in the status display
step 3
Daniel Mazin MAGIC software school, July 2016, Kochel am See
Output Tabs• There 5 tabs for 2 iterations each (0th and 1st iterations). The sequence of
the plots is almost random
• Tab 1: Iter plots (goodness results as a function of the regularization weight)
• Tab 2: Input plots (input distribution, migration matrix etc in chosen Eest and Etrue ranges)
• Tab 3: Result Plots (distribution before and after unfolding, chi2 contributions of individual bins)
• Tab 4: Orig Plots (measured distribution, entire migration matrix, acceptance)
• Tab 5: Correlated Fit (fit with chosen function to the unfolded distribution, or the best spectral form for the forward folding)
34
step 4
Daniel Mazin MAGIC software school, July 2016, Kochel am See
Tab Iter plots
35
more regularization less regularization
step 4
• check smoothness • don’t select singularities • don’t select extremes
Daniel Mazin MAGIC software school, July 2016, Kochel am See
Tab Input plots
36
step 4
• check smoothness • check agreement
Daniel Mazin MAGIC software school, July 2016, Kochel am See
Tab result plots
37
step 4
• check agreement is reasonable • check chi2 contributions
open symbols: excess in Eest green markers: unfolded excess in Etrue you expect them to be different because of unfolding!
Daniel Mazin MAGIC software school, July 2016, Kochel am See
Tab Orig plots
38
step 4
Daniel Mazin MAGIC software school, July 2016, Kochel am See
Tab Orig plots
39
step 4
• choose the range • choose the range • check the effective area • check the acceptance of
Etrue bins
Daniel Mazin MAGIC software school, July 2016, Kochel am See
Tab Correlated fit
40
step 4
• resulting fit parameters • check chi2 contributions
(not for forward folding)
here the result is not so good!
Daniel Mazin MAGIC software school, July 2016, Kochel am See
Proper choice of w• Variety of choices for regularization
terms (Reg)
• Following criteria are used to choose w:
• χ02 is not too high
• Noise component of the unfolded distribution (Trace (T)) should not be much higher that the noise component of the measurements (Trace (K))
• User can actually choose his own preferred weight w
41
step 7
Daniel Mazin MAGIC software school, July 2016, Kochel am See
combunfold.rc
42
# Criterion for choosing the best weight # FlagCriterion = 1 biggest increase of trace(Sigma), # 2 LSQ solution (very large weight, many iterations) # 3 chi2 = # of sign. measurements, # 4 chi2 = rank of G, # 5 Trace(Sigma)/Trace(C) = 1, # 6 D2bar minimal (only MC) # 7 # 8 choose the weight given by the bin IterBin MCallUnfold.FlagCriterion: 5
Default condition: noise in data equal to noise after unfolding
step 7
Daniel Mazin MAGIC software school, July 2016, Kochel am See
combunfold.rc
43
# Criterion for choosing the best weight # FlagCriterion = 1 biggest increase of trace(Sigma), # 2 LSQ solution (very large weight, many iterations) # 3 chi2 = # of sign. measurements, # 4 chi2 = rank of G, # 5 Trace(Sigma)/Trace(C) = 1, # 6 D2bar minimal (only MC) # 7 # 8 choose the weight given by the bin IterBin MCallUnfold.FlagCriterion: 8
# if FlagCriterion = 8 the weight is taken corresponding to bin IterBin MCallUnfold.IterBin: 9
In case there are reasons to change these conditions
step 7
Daniel Mazin MAGIC software school, July 2016, Kochel am See
Range of the fit
• # ----------------------- • # In MCorrelatedFit perform the correlated fit only in the range • # specified here by the user (GeV) • MCallUnfold.FitMinUser: 70 • MCallUnfold.FitMaxUser: 10000
44
step 8• Typically you don’t need to do that, the entire Etrue
range from the unfolding range is used for the fit. • However, you might want to exclude some bins from
the fit manually. • In the latter case, at the very end of combunfold.rc you
can specify the range where the fit should be performed
Daniel Mazin MAGIC software school, July 2016, Kochel am See
Output fileroot [0] TFile *f = new TFile("Unfolding_Output_combunfold.root")root [1] f->ls()
TFile** Unfolding_Output_combunfold.root TFile* Unfolding_Output_combunfold.root
KEY: TH1D CorrelFitResult;1 dN/dE for correlated fit KEY: TGraphAsymmErrors fGraph1;1 Gamma-ray flux after correlated fit (take these points for publication)
KEY: TGraphAsymmErrors fGraph2;1 Unused flux points after correlated fit KEY: TH1D CorrelFitResultE2;1 E2 * dN/dE
KEY: TGraphAsymmErrors fGraph1E2;1 SED (E2*dN/dE) after correlated fit KEY: TGraphAsymmErrors fGraph2E2;1 Unused Energy flux points (E2*dN/dE) after correlated fit
KEY: TF1 Func;1 KEY: TF1 FuncE2;1
KEY: TH1D ExcessEnergy;1 Original Measured Distributionroot [2]
45
Daniel Mazin MAGIC software school, July 2016, Kochel am See
Output file
• In the ROOT output file (e.g. Unfolding_Output_combunfold.root) you can find:
• TGraphAsymmErrors *fGraph1 differential spectrum
• TGraphAsymmErrors *fGraph1E2 SED
• TF1 *Func fit to diff spectrum
• TF1 *FuncE2 fit to SED
46
Daniel Mazin MAGIC software school, July 2016, Kochel am See
For publications
• Spectral parameters are typically taken from Forward Folding
• For spectral points we typically take Bertero (method #3) or Tikhonov (method #2)
47
AGN
e+e-
UV/O/IR Photons
Stars and Dustin Galaxies
HE/VHE ϒ-Rays
Nikishov (1962), Jelley (1966), Gould & Schreder (1966)
dN/d
E
Energy
intrinsic
dN/d
E
Energy
measured
E�EEBL ⇡ 4(mec2)2 ⇡ 1MeV2
EEBL ⇠ eV ! E� ⇠ TeV
slide from M Raue
TeV constraints
from M. Meyer
attenuation
EBL correction
0.1 1 10 100 1000� [µm]
1
10
100
�I �
[nW
m�
2sr
�1 ]
this work - Dominguez+ 10Kneiske+ 04 - best fitFranceschini+ 08Kneiske & Dole 10Gilmore+ 10Aharonian+ 06Mazin & Raue 07 - realisticMazin & Raue 07 - extremeAlbert+ 08Schlegel+ 98Hauser+ 98Finkbeiner+ 00Lagache+ 00Gardner+ 00Gorjian+ 00Cambresy+ 01Madau & Pozzetti 01Metcalfe+ 03Chary+ 04Fazio+ 04; Franceschini+ 08Xu+ 05Matsumoto+ 05Frayer+ 06Bernstein+ 07Levenson & Wright 08Matsuura+ 10Hopwood+ 10Bethermin+ 10Berta+ 10Keenan+ 10
Dominguez et al, MNRAS, 410, 2556 (2010)
Daniel Mazin MAGIC software school, July 2016, Kochel am See
EBL correction# -------------------------------------------------------------------------
# Use this to define the file containing the attenuation factors for the
# absorption due to the extragalactic photon background
# if no file is specified no absorption correction will be applied
# -------------------------------------------------------------------------
MCallUnfold.AttFactorFile: exptau_z0.212_modelFranceschini.dat
51
Memo: 1. no file (commented out) means no EBL correction! 2. make sure the file has 50 entries 3. make sure your attend file covers the needed energy range! 4. make sure you use a correct attend file (ask me or Abelardo)
Daniel Mazin MAGIC software school, July 2016, Kochel am See
EBL correction
52
Daniel Mazin MAGIC software school, July 2016, Kochel am See
Tips• Run with all unfolding methods
• Check if the result is robust (means the resulting fit parameters are stable) by including / excluding few bins in estimated / true energy (each side), but keep the bin validity criteria in mind
• WIKI: http://magic.pic.es/priv/wiki/index.php/MAGIC_software:Unfolding
• WIKI: http://magic.pic.es/priv/wiki/index.php/CombUnfold
• Don’t hesitate to ask questions: [email protected] [email protected]
53
Daniel Mazin MAGIC software school, July 2016, Kochel am See
Cookbook for CombUnfold
1. Adjust input file (output from flute, typically Output_flute.root) to MCombineDataForUnfolding.InputFiles
2. Run forward folding with
1.Automatic ranges in Eest and in Etrue
2.Power law function
3. Change Eest and Etrue to manual ranges and adjust the Eest and Etrue ranges (bin numbers)
4. Run forward folding with power law, check histograms
5. Eventually change the function to log parabola or broken power law
6. Run all 6 unfolding algorithms with the same setting as by step 5:check histograms for sanity, compare χ2 results and fit parameters
7. Eventually you need to adjust the regularization weight by hand
8. Optionally you can adjust the fitting range in energy 54
important slide!steps:
Daniel Mazin MAGIC software school, July 2016, Kochel am See
References
• MAGIC-TDAS 06-01, Wittek and Aliu: “The Unfolding Program in the Standard Analysis Chain”
• “Unfolding of differential energy spectra in the MAGIC experiment” J.Albert et al., NIM A 583 (2007) 494-506
• “Solving inverse problems with the unfolding program TRUEE: example in astroparticle physics”, Milke et al., NIM A 697 (2013) 133-147
55