Commit 9d1b51eabe1efad4414d97e448abe55ac1a80b73

Authored by Jürgen Knödlseder
1 parent 8ae9a2af

Add checks for legacy model parameters (#1820)

doc/source/users/user_manual/modules/model.rst
... ... @@ -123,6 +123,22 @@ Point source
123 123 </spectrum>
124 124 </source>
125 125  
  126 +An alternative XML format is supported for compatibility with the Fermi/LAT XML
  127 +format:
  128 +
  129 +.. code-block:: xml
  130 +
  131 + <source name="Crab" type="PointSource">
  132 + <spatialModel type="SkyDirFunction">
  133 + <parameter name="RA" scale="1.0" value="83.6331" min="-360" max="360" free="1"/>
  134 + <parameter name="DEC" scale="1.0" value="22.0145" min="-90" max="90" free="1"/>
  135 + </spatialModel>
  136 + <spectrum type="...">
  137 + ...
  138 + </spectrum>
  139 + </source>
  140 +
  141 +
126 142 Radial disk
127 143 ===========
128 144  
... ... @@ -139,6 +155,7 @@ Radial disk
139 155 </spectrum>
140 156 </source>
141 157  
  158 +
142 159 Radial Gaussian
143 160 ===============
144 161  
... ... @@ -155,6 +172,7 @@ Radial Gaussian
155 172 </spectrum>
156 173 </source>
157 174  
  175 +
158 176 Radial shell
159 177 ============
160 178  
... ... @@ -172,6 +190,7 @@ Radial shell
172 190 </spectrum>
173 191 </source>
174 192  
  193 +
175 194 Elliptical disk
176 195 ===============
177 196  
... ... @@ -190,6 +209,7 @@ Elliptical disk
190 209 </spectrum>
191 210 </source>
192 211  
  212 +
193 213 Elliptical Gaussian
194 214 ===================
195 215  
... ... @@ -208,6 +228,7 @@ Elliptical Gaussian
208 228 </spectrum>
209 229 </source>
210 230  
  231 +
211 232 Isotropic source
212 233 ================
213 234  
... ... @@ -222,6 +243,21 @@ Isotropic source
222 243 </spectrum>
223 244 </source>
224 245  
  246 +An alternative XML format is supported for compatibility with the Fermi/LAT XML
  247 +format:
  248 +
  249 +.. code-block:: xml
  250 +
  251 + <source name="Crab" type="DiffuseSource">
  252 + <spatialModel type="ConstantValue">
  253 + <parameter name="Value" scale="1" value="1" min="1" max="1" free="0"/>
  254 + </spatialModel>
  255 + <spectrum type="...">
  256 + ...
  257 + </spectrum>
  258 + </source>
  259 +
  260 +
225 261 Diffuse map
226 262 ===========
227 263  
... ... @@ -229,6 +265,20 @@ Diffuse map
229 265  
230 266 <source name="Crab" type="DiffuseSource">
231 267 <spatialModel type="DiffuseMap" file="map.fits">
  268 + <parameter name="Normalization" scale="1" value="1" min="0.001" max="1000.0" free="0"/>
  269 + </spatialModel>
  270 + <spectrum type="...">
  271 + ...
  272 + </spectrum>
  273 + </source>
  274 +
  275 +An alternative XML format is supported for compatibility with the Fermi/LAT XML
  276 +format:
  277 +
  278 +.. code-block:: xml
  279 +
  280 + <source name="Crab" type="DiffuseSource">
  281 + <spatialModel type="SpatialMap" file="map.fits">
232 282 <parameter name="Prefactor" scale="1" value="1" min="0.001" max="1000.0" free="0"/>
233 283 </spatialModel>
234 284 <spectrum type="...">
... ... @@ -236,6 +286,7 @@ Diffuse map
236 286 </spectrum>
237 287 </source>
238 288  
  289 +
239 290 Diffuse map cube
240 291 ================
241 292  
... ... @@ -250,6 +301,20 @@ Diffuse map cube
250 301 </spectrum>
251 302 </source>
252 303  
  304 +An alternative XML format is supported for compatibility with the Fermi/LAT XML
  305 +format:
  306 +
  307 +.. code-block:: xml
  308 +
  309 + <source name="Crab" type="DiffuseSource">
  310 + <spatialModel type="MapCubeFunction" file="map_cube.fits">
  311 + <parameter name="Value" scale="1" value="1" min="0.001" max="1000.0" free="0"/>
  312 + </spatialModel>
  313 + <spectrum type="...">
  314 + ...
  315 + </spectrum>
  316 + </source>
  317 +
253 318  
254 319 Spectral components
255 320 ^^^^^^^^^^^^^^^^^^^
... ... @@ -274,6 +339,15 @@ The XML format for specifying a constant is:
274 339 <parameter name="Normalization" scale="1e-16" value="5.7" min="1e-07" max="1000.0" free="1"/>
275 340 </spectrum>
276 341  
  342 +An alternative XML format is supported for compatibility with the Fermi/LAT XML
  343 +format:
  344 +
  345 +.. code-block:: xml
  346 +
  347 + <spectrum type="ConstantValue">
  348 + <parameter name="Value" scale="1e-16" value="5.7" min="1e-07" max="1000.0" free="1"/>
  349 + </spectrum>
  350 +
277 351  
278 352 Node function
279 353 =============
... ... @@ -348,20 +422,32 @@ where the parameters in the XML definition have the following mappings:
348 422  
349 423 * :math:`k_0` = ``Prefactor``
350 424 * :math:`\gamma` = ``Index``
351   -* :math:`E_0` = ``Scale``
  425 +* :math:`E_0` = ``PivotEnergy``
352 426  
353 427 The XML format for specifying a power law is:
354 428  
355 429 .. code-block:: xml
356 430  
357 431 <spectrum type="PowerLaw">
  432 + <parameter name="Prefactor" scale="1e-16" value="5.7" min="1e-07" max="1000.0" free="1"/>
  433 + <parameter name="Index" scale="-1" value="2.48" min="0.0" max="+5.0" free="1"/>
  434 + <parameter name="PivotEnergy" scale="1e6" value="0.3" min="0.01" max="1000.0" free="0"/>
  435 + </spectrum>
  436 +
  437 +An alternative XML format is supported for compatibility with the Fermi/LAT XML
  438 +format:
  439 +
  440 +.. code-block:: xml
  441 +
  442 + <spectrum type="PowerLaw">
358 443 <parameter name="Prefactor" scale="1e-16" value="5.7" min="1e-07" max="1000.0" free="1"/>
359 444 <parameter name="Index" scale="-1" value="2.48" min="0.0" max="+5.0" free="1"/>
360 445 <parameter name="Scale" scale="1e6" value="0.3" min="0.01" max="1000.0" free="0"/>
361 446 </spectrum>
362 447  
363 448 An alternative power law function is defined by the :doxy:`GModelSpectralPlaw2`
364   -class that uses the integral flux as parameter rather than the Prefactor:
  449 +class that uses the integral photon flux as parameter rather than the
  450 +Prefactor:
365 451  
366 452 .. math::
367 453 \frac{dN}{dE} = \frac{N(\gamma+1)E^{\gamma}}
... ... @@ -369,17 +455,30 @@ class that uses the integral flux as parameter rather than the Prefactor:
369 455  
370 456 where the parameters in the XML definition have the following mappings:
371 457  
372   -* :math:`N` = ``Integral``
  458 +* :math:`N` = ``PhotonFlux``
373 459 * :math:`\gamma` = ``Index``
374 460 * :math:`E_{\rm min}` = ``LowerLimit``
375 461 * :math:`E_{\rm max}` = ``UpperLimit``
376 462  
377   -The XML format for specifying a power law defined by the integral flux is:
  463 +The XML format for specifying a power law defined by the integral photon flux
  464 +is:
  465 +
  466 +.. code-block:: xml
  467 +
  468 + <spectrum type="PowerLawPhotonFlux">
  469 + <parameter scale="1e-07" name="PhotonFlux" min="1e-07" max="1000.0" value="1.0" free="1"/>
  470 + <parameter scale="1.0" name="Index" min="-5.0" max="+5.0" value="-2.0" free="1"/>
  471 + <parameter scale="1.0" name="LowerLimit" min="10.0" max="1000000.0" value="100.0" free="0"/>
  472 + <parameter scale="1.0" name="UpperLimit" min="10.0" max="1000000.0" value="500000.0" free="0"/>
  473 + </spectrum>
  474 +
  475 +An alternative XML format is supported for compatibility with the Fermi/LAT XML
  476 +format:
378 477  
379 478 .. code-block:: xml
380 479  
381 480 <spectrum type="PowerLaw2">
382   - <parameter scale="1e-07" name="Integral" min="1e-07" max="1000.0" value="1.0" free="1"/>
  481 + <parameter scale="1e-07" name="Intergal" min="1e-07" max="1000.0" value="1.0" free="1"/>
383 482 <parameter scale="1.0" name="Index" min="-5.0" max="+5.0" value="-2.0" free="1"/>
384 483 <parameter scale="1.0" name="LowerLimit" min="10.0" max="1000000.0" value="100.0" free="0"/>
385 484 <parameter scale="1.0" name="UpperLimit" min="10.0" max="1000000.0" value="500000.0" free="0"/>
... ... @@ -409,7 +508,7 @@ where the parameters in the XML definition have the following mappings:
409 508  
410 509 * :math:`k_0` = ``Prefactor``
411 510 * :math:`\gamma` = ``Index``
412   -* :math:`E_0` = ``Scale``
  511 +* :math:`E_0` = ``PivotEnergy``
413 512 * :math:`E_{\rm cut}` = ``Cutoff``
414 513  
415 514 The XML format for specifying an exponentially cut-off power law is:
... ... @@ -417,6 +516,18 @@ The XML format for specifying an exponentially cut-off power law is:
417 516 .. code-block:: xml
418 517  
419 518 <spectrum type="ExpCutoff">
  519 + <parameter name="Prefactor" scale="1e-16" value="5.7" min="1e-07" max="1000.0" free="1"/>
  520 + <parameter name="Index" scale="-1" value="2.48" min="0.0" max="+5.0" free="1"/>
  521 + <parameter name="Cutoff" scale="1e6" value="1.0" min="0.01" max="1000.0" free="1"/>
  522 + <parameter name="PivotEnergy" scale="1e6" value="0.3" min="0.01" max="1000.0" free="0"/>
  523 + </spectrum>
  524 +
  525 +An alternative XML format is supported for compatibility with the Fermi/LAT XML
  526 +format:
  527 +
  528 +.. code-block:: xml
  529 +
  530 + <spectrum type="ExpCutoff">
420 531 <parameter name="Prefactor" scale="1e-16" value="5.7" min="1e-07" max="1000.0" free="1"/>
421 532 <parameter name="Index" scale="-1" value="2.48" min="0.0" max="+5.0" free="1"/>
422 533 <parameter name="Cutoff" scale="1e6" value="1.0" min="0.01" max="1000.0" free="1"/>
... ... @@ -441,17 +552,30 @@ where the parameters in the XML definition have the following mappings:
441 552 * :math:`k_0` = ``Prefactor``
442 553 * :math:`\gamma` = ``Index1``
443 554 * :math:`\alpha` = ``Index2``
444   -* :math:`E_0` = ``Scale``
  555 +* :math:`E_0` = ``PivotEnergy``
445 556 * :math:`E_{\rm cut}` = ``Cutoff``
446 557  
447 558 .. code-block:: xml
448 559  
449 560 <spectrum type="PLSuperExpCutoff">
450   - <parameter name="Prefactor" scale="1e-16" value="1.0" min="1e-07" max="1000.0" free="1"/>
451   - <parameter name="Index1" scale="-1" value="2.0" min="0.0" max="+5.0" free="1"/>
452   - <parameter name="Cutoff" scale="1e6" value="1.0" min="0.01" max="1000.0" free="1"/>
453   - <parameter name="Scale" scale="1e6" value="1.0" min="0.01" max="1000.0" free="0"/>
454   - <parameter name="Index2" scale="1.0" value="1.5" min="0.1" max="5.0" free="1"/>
  561 + <parameter name="Prefactor" scale="1e-16" value="1.0" min="1e-07" max="1000.0" free="1"/>
  562 + <parameter name="Index1" scale="-1" value="2.0" min="0.0" max="+5.0" free="1"/>
  563 + <parameter name="Cutoff" scale="1e6" value="1.0" min="0.01" max="1000.0" free="1"/>
  564 + <parameter name="Index2" scale="1.0" value="1.5" min="0.1" max="5.0" free="1"/>
  565 + <parameter name="PivotEnergy" scale="1e6" value="1.0" min="0.01" max="1000.0" free="0"/>
  566 + </spectrum>
  567 +
  568 +An alternative XML format is supported for compatibility with the Fermi/LAT XML
  569 +format:
  570 +
  571 +.. code-block:: xml
  572 +
  573 + <spectrum type="PLSuperExpCutoff">
  574 + <parameter name="Prefactor" scale="1e-16" value="1.0" min="1e-07" max="1000.0" free="1"/>
  575 + <parameter name="Index1" scale="-1" value="2.0" min="0.0" max="+5.0" free="1"/>
  576 + <parameter name="Cutoff" scale="1e6" value="1.0" min="0.01" max="1000.0" free="1"/>
  577 + <parameter name="Index2" scale="1.0" value="1.5" min="0.1" max="5.0" free="1"/>
  578 + <parameter name="Scale" scale="1e6" value="1.0" min="0.01" max="1000.0" free="0"/>
455 579 </spectrum>
456 580  
457 581  
... ... @@ -527,7 +651,7 @@ where the parameters in the XML definition have the following mappings:
527 651 * :math:`k_0` = ``Prefactor``
528 652 * :math:`\gamma` = ``Index``
529 653 * :math:`\eta` = ``Curvature``
530   -* :math:`E_0` = ``Scale``
  654 +* :math:`E_0` = ``PivotEnergy``
531 655  
532 656  
533 657 The XML format for specifying a log parabola spectrum is:
... ... @@ -535,21 +659,22 @@ The XML format for specifying a log parabola spectrum is:
535 659 .. code-block:: xml
536 660  
537 661 <spectrum type="LogParabola">
538   - <parameter name="Prefactor" scale="1e-17" value="5.878" min="1e-07" max="1000.0" free="1"/>
539   - <parameter name="Index" scale="-1" value="2.32473" min="0.0" max="+5.0" free="1"/>
540   - <parameter name="Curvature" scale="-1" value="0.074" min="-5.0" max="+5.0" free="1"/>
541   - <parameter name="Scale" scale="1e6" value="1.0" min="0.01" max="1000.0" free="0"/>
  662 + <parameter name="Prefactor" scale="1e-17" value="5.878" min="1e-07" max="1000.0" free="1"/>
  663 + <parameter name="Index" scale="-1" value="2.32473" min="0.0" max="+5.0" free="1"/>
  664 + <parameter name="Curvature" scale="-1" value="0.074" min="-5.0" max="+5.0" free="1"/>
  665 + <parameter name="PivotEnergy" scale="1e6" value="1.0" min="0.01" max="1000.0" free="0"/>
542 666 </spectrum>
543 667  
544   -An alternative XML format is supported for compatibility with the Fermi/LAT XML format:
  668 +An alternative XML format is supported for compatibility with the Fermi/LAT XML
  669 +format:
545 670  
546 671 .. code-block:: xml
547 672  
548 673 <spectrum type="LogParabola">
549   - <parameter name="Prefactor" scale="1e-17" value="5.878" min="1e-07" max="1000.0" free="1"/>
550   - <parameter name="alpha" scale="1" value="2.32473" min="0.0" max="+5.0" free="1"/>
551   - <parameter name="beta" scale="1" value="0.074" min="-5.0" max="+5.0" free="1"/>
552   - <parameter name="Scale" scale="1e6" value="1.0" min="0.01" max="1000.0" free="0"/>
  674 + <parameter name="norm" scale="1e-17" value="5.878" min="1e-07" max="1000.0" free="1"/>
  675 + <parameter name="alpha" scale="1" value="2.32473" min="0.0" max="+5.0" free="1"/>
  676 + <parameter name="beta" scale="1" value="0.074" min="-5.0" max="+5.0" free="1"/>
  677 + <parameter name="Eb" scale="1e6" value="1.0" min="0.01" max="1000.0" free="0"/>
553 678 </spectrum>
554 679  
555 680 where
... ...
examples/cpp/readmodel.cpp
... ... @@ -53,7 +53,7 @@ void create_xml_file(void)
53 53 file << " min=\"1e-07\" max=\"1000.0\" value=\"1.73\" free=\"1\"/>\n";
54 54 file << " <parameter scale=\"1.0\" name=\"Index\" min=\"-5.0\"";
55 55 file << " max=\"+5.0\" value=\"-2.1\" free=\"1\"/>\n";
56   - file << " <parameter scale=\"1.0\" name=\"Scale\" min=\"10.0\"";
  56 + file << " <parameter scale=\"1.0\" name=\"PivotEnergy\" min=\"10.0\"";
57 57 file << " max=\"1000000.0\" value=\"100.0\" free=\"0\"/>\n";
58 58 file << " </spectrum>\n";
59 59 file << " <spatialModel type=\"PointSource\">\n";
... ...
inst/cta/test/data/radio.xml
... ... @@ -7,7 +7,7 @@
7 7 <parameter name="PivotEnergy" scale="1e6" value="0.3" min="0.01" max="1000.0" free="0"/>
8 8 </spectrum>
9 9 <spatialModel type="DiffuseMap" file="radio_map.fits">
10   - <parameter scale="1" name="Prefactor" min="0.001" max="1000.0" value="1" free="0"/>
  10 + <parameter scale="1" name="Normalization" min="0.001" max="1000.0" value="1" free="0"/>
11 11 </spatialModel>
12 12 </source>
13 13 <source name="Background" type="RadialAcceptance" instrument="CTA">
... ...
inst/cta/test/data/rsp_models.xml
... ... @@ -7,7 +7,7 @@
7 7 <parameter scale="1.0" name="PivotEnergy" min="10.0" max="1000000.0" value="100.0" free="0"/>
8 8 </spectrum>
9 9 <spatialModel type="DiffuseMap" file="cena_lobes_parkes.fits">
10   - <parameter scale="1" name="Prefactor" min="0.001" max="1000.0" value="1" free="0"/>
  10 + <parameter scale="1" name="Normalization" min="0.001" max="1000.0" value="1" free="0"/>
11 11 </spatialModel>
12 12 </source>
13 13 </source_library>
... ...
inst/lat/test/data/p6v3/source_model.xml
... ... @@ -9,7 +9,7 @@
9 9 </source>
10 10 <source type="DiffuseSource" name="Galactic_diffuse">
11 11 <spectrum type="ConstantValue">
12   - <parameter scale="1.0" name="Value" min="0.0" max="1000.0" value="1.0" free="1"/>
  12 + <parameter scale="1.0" name="Normalization" min="0.0" max="1000.0" value="1.0" free="1"/>
13 13 </spectrum>
14 14 <spatialModel type="DiffuseMapCube" file="test_cube.fits">
15 15 <parameter scale="1" name="Normalization" min="0.001" max="1000.0" value="1" free="0"/>
... ...
inst/lat/test/data/p7v6/source_model.xml
... ... @@ -9,7 +9,7 @@
9 9 </source>
10 10 <source type="DiffuseSource" name="Galactic_diffuse">
11 11 <spectrum type="ConstantValue">
12   - <parameter scale="1.0" name="Value" min="0.0" max="1000.0" value="1.0" free="1"/>
  12 + <parameter scale="1.0" name="Normalization" min="0.0" max="1000.0" value="1.0" free="1"/>
13 13 </spectrum>
14 14 <spatialModel type="DiffuseMapCube" file="test_cube.fits">
15 15 <parameter scale="1" name="Normalization" min="0.001" max="1000.0" value="1" free="0"/>
... ...
inst/lat/test/data/p8v2/source_model.xml
... ... @@ -9,7 +9,7 @@
9 9 </source>
10 10 <source type="DiffuseSource" name="Galactic_diffuse">
11 11 <spectrum type="ConstantValue">
12   - <parameter scale="1.0" name="Value" min="0.0" max="1000.0" value="1.0" free="1"/>
  12 + <parameter scale="1.0" name="Normalization" min="0.0" max="1000.0" value="1.0" free="1"/>
13 13 </spectrum>
14 14 <spatialModel type="DiffuseMapCube" file="test_cube.fits">
15 15 <parameter scale="1" name="Normalization" min="0.001" max="1000.0" value="1" free="0"/>
... ...
inst/lat/test/test_LAT.cpp
... ... @@ -105,9 +105,12 @@ void TestGLATLtCube::set(void)
105 105 name("GLATLtCube");
106 106  
107 107 // Append tests to test suite
108   - append(static_cast<pfunction>(&TestGLATLtCube::test_ltcube_p6), "Test P6 livetime cube");
109   - append(static_cast<pfunction>(&TestGLATLtCube::test_ltcube_p7), "Test P7 livetime cube");
110   - append(static_cast<pfunction>(&TestGLATLtCube::test_ltcube_p8), "Test P8 livetime cube");
  108 + append(static_cast<pfunction>(&TestGLATLtCube::test_ltcube_p6),
  109 + "Test P6 livetime cube");
  110 + append(static_cast<pfunction>(&TestGLATLtCube::test_ltcube_p7),
  111 + "Test P7 livetime cube");
  112 + append(static_cast<pfunction>(&TestGLATLtCube::test_ltcube_p8),
  113 + "Test P8 livetime cube");
111 114  
112 115 // Return
113 116 return;
... ... @@ -135,12 +138,18 @@ void TestGLATObservation::set(void)
135 138 name("GLATObservation");
136 139  
137 140 // Append tests to test suite
138   - append(static_cast<pfunction>(&TestGLATObservation::test_unbinned_obs_p6), "Test P6 unbinned observation");
139   - append(static_cast<pfunction>(&TestGLATObservation::test_unbinned_obs_p7), "Test P7 unbinned observation");
140   - append(static_cast<pfunction>(&TestGLATObservation::test_unbinned_obs_p8), "Test P8 unbinned observation");
141   - append(static_cast<pfunction>(&TestGLATObservation::test_binned_obs_p6), "Test P6 binned observation");
142   - append(static_cast<pfunction>(&TestGLATObservation::test_binned_obs_p7), "Test P7 binned observation");
143   - append(static_cast<pfunction>(&TestGLATObservation::test_binned_obs_p8), "Test P8 binned observation");
  141 + append(static_cast<pfunction>(&TestGLATObservation::test_unbinned_obs_p6),
  142 + "Test P6 unbinned observation");
  143 + append(static_cast<pfunction>(&TestGLATObservation::test_unbinned_obs_p7),
  144 + "Test P7 unbinned observation");
  145 + append(static_cast<pfunction>(&TestGLATObservation::test_unbinned_obs_p8),
  146 + "Test P8 unbinned observation");
  147 + append(static_cast<pfunction>(&TestGLATObservation::test_binned_obs_p6),
  148 + "Test P6 binned observation");
  149 + append(static_cast<pfunction>(&TestGLATObservation::test_binned_obs_p7),
  150 + "Test P7 binned observation");
  151 + append(static_cast<pfunction>(&TestGLATObservation::test_binned_obs_p8),
  152 + "Test P8 binned observation");
144 153  
145 154 // Return
146 155 return;
... ... @@ -168,9 +177,12 @@ void TestGLATOptimize::set(void)
168 177 name("LAT optimizers");
169 178  
170 179 // Append tests to test suite
171   - append(static_cast<pfunction>(&TestGLATOptimize::test_binned_optimizer_p6), "Test P6 binned optimizer");
172   - append(static_cast<pfunction>(&TestGLATOptimize::test_binned_optimizer_p7), "Test P7 binned optimizer");
173   - append(static_cast<pfunction>(&TestGLATOptimize::test_binned_optimizer_p8), "Test P8 binned optimizer");
  180 + append(static_cast<pfunction>(&TestGLATOptimize::test_binned_optimizer_p6),
  181 + "Test P6 binned optimizer");
  182 + append(static_cast<pfunction>(&TestGLATOptimize::test_binned_optimizer_p7),
  183 + "Test P7 binned optimizer");
  184 + append(static_cast<pfunction>(&TestGLATOptimize::test_binned_optimizer_p8),
  185 + "Test P8 binned optimizer");
174 186  
175 187 // Return
176 188 return;
... ...
src/model/GModelSpatialDiffuseCube.cpp
... ... @@ -527,52 +527,49 @@ bool GModelSpatialDiffuseCube::contains(const GSkyDir&amp; dir,
527 527 *
528 528 * @param[in] xml XML element.
529 529 *
530   - * @exception GException::model_invalid_parnum
531   - * Invalid number of model parameters found in XML element.
532   - * @exception GException::model_invalid_parnames
533   - * Invalid model parameter names found in XML element.
  530 + * @exception GException::invalid_value
  531 + * Model parameters not found in XML element.
534 532 *
535 533 * Read the map cube information from an XML element. The XML element should
536   - * have either the format
  534 + * have the format
537 535 *
538 536 * <spatialModel type="DiffuseMapCube" file="test_file.fits">
539   - * <parameter name="Normalization" scale="1" value="1" min="0.1" max="10" free="0"/>
540   - * </spatialModel>
541   - *
542   - * or alternatively
543   - *
544   - * <spatialModel type="DiffuseMapCube" file="test_file.fits">
545   - * <parameter name="Value" scale="1" value="1" min="0.1" max="10" free="0"/>
  537 + * <parameter name="Normalization" ../>
546 538 * </spatialModel>
547   - *
548 539 ***************************************************************************/
549 540 void GModelSpatialDiffuseCube::read(const GXmlElement& xml)
550 541 {
551 542 // Clear model
552 543 clear();
553 544  
554   - // Verify that XML element has exactly 1 parameters
555   - if (xml.elements() != 1 || xml.elements("parameter") != 1) {
556   - throw GException::model_invalid_parnum(G_READ, xml,
557   - "Map cube spatial model requires exactly 1 parameter.");
  545 + // If "Normalization" parameter exists then read parameter from this
  546 + // XML element
  547 + if (gammalib::xml_has_par(xml, "Normalization")) {
  548 + const GXmlElement* par = gammalib::xml_get_par(G_READ, xml, "Normalization");
  549 + m_value.read(*par);
558 550 }
559 551  
560   - // Get pointer on model parameter
561   - const GXmlElement* par = xml.element("parameter", 0);
562   -
563   - // Get value
564   - if (par->attribute("name") == "Normalization" ||
565   - par->attribute("name") == "Value") {
  552 + // ... otherwise try reading parameter from "Value" parameter
  553 + #if defined(G_LEGACY_XML_FORMAT)
  554 + else if (gammalib::xml_has_par(xml, "Value")) {
  555 + const GXmlElement* par = gammalib::xml_get_par(G_READ, xml, "Value");
566 556 m_value.read(*par);
567 557 }
  558 + #endif
  559 +
  560 + // ... otherwise throw an exception
568 561 else {
569   - throw GException::model_invalid_parnames(G_READ, xml,
570   - "Map cube spatial model requires either \"Value\" or"
571   - " \"Normalization\" parameter.");
  562 + #if defined(G_LEGACY_XML_FORMAT)
  563 + std::string msg = "Diffuse map cube model requires either "
  564 + "\"Normalization\" or \"Value\" parameter.";
  565 + #else
  566 + std::string msg = "Diffuse map cube model requires \"Normalization\" "
  567 + "parameter.";
  568 + #endif
  569 + throw GException::invalid_value(G_READ, msg);
572 570 }
573 571  
574 572 // Save filename
575   - //m_filename = xml.attribute("file");
576 573 m_filename = gammalib::xml_file_expand(xml, xml.attribute("file"));
577 574  
578 575 // Return
... ...
src/model/GModelSpatialDiffuseMap.cpp
... ... @@ -506,22 +506,14 @@ bool GModelSpatialDiffuseMap::contains(const GSkyDir&amp; dir,
506 506 *
507 507 * @param[in] xml XML element.
508 508 *
509   - * @exception GException::model_invalid_parnum
510   - * Invalid number of model parameters found in XML element.
511   - * @exception GException::model_invalid_parnames
512   - * Invalid model parameter names found in XML element.
  509 + * @exception GException::invalid_value
  510 + * Model parameters not found in XML element.
513 511 *
514 512 * Reads the spatial information for a diffuse map from an XML element. The
515 513 * expected format of the XML element is
516 514 *
517 515 * <spatialModel type="DiffuseMap" file="myfile.fits" normalize="1">
518   - * <parameter name="Prefactor" value="1" min="0.1" max="10" scale="1" free="0"/>
519   - * </spatialModel>
520   - *
521   - * or
522   - *
523   - * <spatialModel type="DiffuseMap" file="myfile.fits" normalize="1">
524   - * <parameter name="Normalization" value="1" min="0.1" max="10" scale="1" free="0"/>
  516 + * <parameter name="Normalization" ../>
525 517 * </spatialModel>
526 518 *
527 519 * The @p file attribute provides the filename of the diffuse map FITS file.
... ... @@ -536,24 +528,31 @@ bool GModelSpatialDiffuseMap::contains(const GSkyDir&amp; dir,
536 528 ***************************************************************************/
537 529 void GModelSpatialDiffuseMap::read(const GXmlElement& xml)
538 530 {
539   - // Verify that XML element has exactly 1 parameters
540   - if (xml.elements() != 1 || xml.elements("parameter") != 1) {
541   - throw GException::model_invalid_parnum(G_READ, xml,
542   - "Spatial map model requires exactly 1 parameter.");
  531 + // If "Normalization" parameter exists then read parameter from this
  532 + // XML element
  533 + if (gammalib::xml_has_par(xml, "Normalization")) {
  534 + const GXmlElement* par = gammalib::xml_get_par(G_READ, xml, "Normalization");
  535 + m_value.read(*par);
543 536 }
544 537  
545   - // Get pointer on model parameter
546   - const GXmlElement* par = xml.element("parameter", 0);
547   -
548   - // Get value
549   - if (par->attribute("name") == "Normalization" ||
550   - par->attribute("name") == "Prefactor") {
  538 + // ... otherwise try reading parameter from "Prefactor" parameter
  539 + #if defined(G_LEGACY_XML_FORMAT)
  540 + else if (gammalib::xml_has_par(xml, "Prefactor")) {
  541 + const GXmlElement* par = gammalib::xml_get_par(G_READ, xml, "Prefactor");
551 542 m_value.read(*par);
552 543 }
  544 + #endif
  545 +
  546 + // ... otherwise throw an exception
553 547 else {
554   - throw GException::model_invalid_parnames(G_READ, xml,
555   - "Spatial map model requires either \"Prefactor\" or"
556   - " \"Normalization\" parameter.");
  548 + #if defined(G_LEGACY_XML_FORMAT)
  549 + std::string msg = "Diffuse map model requires either "
  550 + "\"Normalization\" or \"Prefactor\" parameter.";
  551 + #else
  552 + std::string msg = "Diffuse map model requires \"Normalization\" "
  553 + "parameter.";
  554 + #endif
  555 + throw GException::invalid_value(G_READ, msg);
557 556 }
558 557  
559 558 // Get optional normalization attribute
... ... @@ -846,7 +845,7 @@ void GModelSpatialDiffuseMap::init_members(void)
846 845  
847 846 // Initialise Value
848 847 m_value.clear();
849   - m_value.name("Prefactor");
  848 + m_value.name("Normalization");
850 849 m_value.value(1.0);
851 850 m_value.scale(1.0);
852 851 m_value.range(0.001, 1000.0);
... ...
src/model/GModelSpectralConst.cpp
... ... @@ -414,44 +414,42 @@ GEnergy GModelSpectralConst::mc(const GEnergy&amp; emin,
414 414 *
415 415 * @param[in] xml XML element containing power law model information.
416 416 *
417   - * @exception GException::model_invalid_parnum
418   - * Invalid number of model parameters found in XML element.
419   - * @exception GException::model_invalid_parnames
420   - * Invalid model parameter name found in XML element.
  417 + * @exception GException::invalid_value
  418 + * Model parameters not found in XML element.
421 419 *
422   - * Reads the spectral information from an XML element having either the
423   - * format
  420 + * Reads the spectral information from an XML element having the format
424 421 *
425 422 * <spectrum type="ConstantValue">
426   - * <parameter name="Value" scale="1" min="0" max="1000" value="1" free="1"/>
427   - * </spectrum>
428   - *
429   - * or the format
430   - *
431   - * <spectrum type="ConstantValue">
432   - * <parameter name="Normalization" scale="1" min="0" max="1000" value="1" free="1"/>
  423 + * <parameter name="Normalization" ../>
433 424 * </spectrum>
434 425 ***************************************************************************/
435 426 void GModelSpectralConst::read(const GXmlElement& xml)
436 427 {
437   - // Verify that XML element has exactly 1 parameter
438   - if (xml.elements() != 1 || xml.elements("parameter") != 1) {
439   - throw GException::model_invalid_parnum(G_READ, xml,
440   - "Spectral constant requires exactly 1 parameter.");
  428 + // If "Normalization" parameter exists then read parameter from this
  429 + // XML element
  430 + if (gammalib::xml_has_par(xml, "Normalization")) {
  431 + const GXmlElement* par = gammalib::xml_get_par(G_READ, xml, "Normalization");
  432 + m_norm.read(*par);
441 433 }
442 434  
443   - // Get parameter element
444   - const GXmlElement* par = xml.element("parameter", 0);
445   -
446   - // Get value
447   - if (par->attribute("name") == "Normalization" ||
448   - par->attribute("name") == "Value") {
  435 + // ... otherwise try reading parameter from "Value" parameter
  436 + #if defined(G_LEGACY_XML_FORMAT)
  437 + else if (gammalib::xml_has_par(xml, "Value")) {
  438 + const GXmlElement* par = gammalib::xml_get_par(G_READ, xml, "Value");
449 439 m_norm.read(*par);
450 440 }
  441 + #endif
  442 +
  443 + // ... otherwise throw an exception
451 444 else {
452   - throw GException::model_invalid_parnames(G_READ, xml,
453   - "Spectral constant requires either"
454   - " \"Normalization\" or \"Value\" parameter.");
  445 + #if defined(G_LEGACY_XML_FORMAT)
  446 + std::string msg = "Spectral constant model requires either "
  447 + "\"Normalization\" or \"Value\" parameter.";
  448 + #else
  449 + std::string msg = "Spectral constant model requires \"Normalization\" "
  450 + "parameter.";
  451 + #endif
  452 + throw GException::invalid_value(G_READ, msg);
455 453 }
456 454  
457 455 // Return
... ... @@ -541,7 +539,7 @@ void GModelSpectralConst::init_members(void)
541 539 {
542 540 // Initialise constant normalisation
543 541 m_norm.clear();
544   - m_norm.name("Value");
  542 + m_norm.name("Normalization");
545 543 m_norm.scale(1.0);
546 544 m_norm.value(1.0); // default: 1.0
547 545 m_norm.range(0.0, 1000.0); // range: [0, 1000]
... ...
src/model/GModelSpectralExpPlaw.cpp
... ... @@ -566,10 +566,8 @@ GEnergy GModelSpectralExpPlaw::mc(const GEnergy&amp; emin,
566 566 *
567 567 * @param[in] xml XML element containing power law model information.
568 568 *
569   - * @exception GException::model_invalid_parnum
570   - * Invalid number of model parameters found in XML element.
571   - * @exception GException::model_invalid_parnames
572   - * Invalid model parameter names found in XML element.
  569 + * @exception GException::invalid_value
  570 + * Model parameters not found in XML element.
573 571 *
574 572 * Reads the spectral information from an XML element. The format of the XML
575 573 * elements is
... ... @@ -583,52 +581,42 @@ GEnergy GModelSpectralExpPlaw::mc(const GEnergy&amp; emin,
583 581 ***************************************************************************/
584 582 void GModelSpectralExpPlaw::read(const GXmlElement& xml)
585 583 {
586   - // Verify that XML element has exactly 4 parameters
587   - if (xml.elements() != 4 || xml.elements("parameter") != 4) {
588   - throw GException::model_invalid_parnum(G_READ, xml,
589   - "Power law model requires exactly 4 parameters.");
  584 + // If "PivotEnergy" parameter exists then read parameter from this
  585 + // XML element
  586 + if (gammalib::xml_has_par(xml, "PivotEnergy")) {
  587 + const GXmlElement* par = gammalib::xml_get_par(G_READ, xml, "PivotEnergy");
  588 + m_pivot.read(*par);
590 589 }
591 590  
592   - // Extract model parameters
593   - int npar[] = {0, 0, 0, 0};
594   - for (int i = 0; i < 4; ++i) {
595   -
596   - // Get parameter element
597   - const GXmlElement* par = xml.element("parameter", i);
598   -
599   - // Handle prefactor
600   - if (par->attribute("name") == "Prefactor") {
601   - m_norm.read(*par);
602   - npar[0]++;
603   - }
604   -
605   - // Handle index
606   - else if (par->attribute("name") == "Index") {
607   - m_index.read(*par);
608   - npar[1]++;
609   - }
610   -
611   - // Handle cutoff
612   - else if (par->attribute("name") == "Cutoff") {
613   - m_ecut.read(*par);
614   - npar[2]++;
615   - }
  591 + // ... otherwise try reading parameter from "Scale" parameter
  592 + #if defined(G_LEGACY_XML_FORMAT)
  593 + else if (gammalib::xml_has_par(xml, "Scale")) {
  594 + const GXmlElement* par = gammalib::xml_get_par(G_READ, xml, "Scale");
  595 + m_pivot.read(*par);
  596 + }
  597 + #endif
616 598  
617   - // Handle pivot energy
618   - else if ((par->attribute("name") == "Scale") ||
619   - (par->attribute("name") == "PivotEnergy")) {
620   - m_pivot.read(*par);
621   - npar[3]++;
622   - }
  599 + // ... otherwise throw an exception
  600 + else {
  601 + #if defined(G_LEGACY_XML_FORMAT)
  602 + std::string msg = "Exponentially cutoff power law model requires either "
  603 + "\"PivotEnergy\" or \"Scale\" parameter.";
  604 + #else
  605 + std::string msg = "Exponentially cutoff power law model requires "
  606 + "\"PivotEnergy\" parameter.";
  607 + #endif
  608 + throw GException::invalid_value(G_READ, msg);
  609 + }
623 610  
624   - } // endfor: looped over all parameters
  611 + // Get remaining XML parameters
  612 + const GXmlElement* prefactor = gammalib::xml_get_par(G_READ, xml, "Prefactor");
  613 + const GXmlElement* index = gammalib::xml_get_par(G_READ, xml, "Index");
  614 + const GXmlElement* cutoff = gammalib::xml_get_par(G_READ, xml, "Cutoff");
625 615  
626   - // Verify that all parameters were found
627   - if (npar[0] != 1 || npar[1] != 1 || npar[2] != 1 || npar[3] != 1) {
628   - throw GException::model_invalid_parnames(G_READ, xml,
629   - "Require \"Prefactor\", \"Index\", \"Cutoff\" and \"Scale\""
630   - " or \"PivotEnergy\" parameters.");
631   - }
  616 + // Read parameters
  617 + m_norm.read(*prefactor);
  618 + m_index.read(*index);
  619 + m_ecut.read(*cutoff);
632 620  
633 621 // Return
634 622 return;
... ...
src/model/GModelSpectralLogParabola.cpp
... ... @@ -580,91 +580,82 @@ GEnergy GModelSpectralLogParabola::mc(const GEnergy&amp; emin,
580 580 * of the XML elements is
581 581 *
582 582 * <spectrum type="LogParabola">
583   - * <parameter name="Prefactor" scale=".." value=".." min=".." max=".." free=".."/>
584   - * <parameter name="Index" scale=".." value=".." min=".." max=".." free=".."/>
585   - * <parameter name="Curvature" scale=".." value=".." min=".." max=".." free=".."/>
586   - * <parameter name="Scale" scale=".." value=".." min=".." max=".." free=".."/>
587   - * </spectrum>
588   - *
589   - * or for compliance with Fermi-LAT
590   - *
591   - * <spectrum type="LogParabola">
592   - * <parameter name="norm" scale=".." value=".." min=".." max=".." free=".."/>
593   - * <parameter name="alpha" scale=".." value=".." min=".." max=".." free=".."/>
594   - * <parameter name="beta" scale=".." value=".." min=".." max=".." free=".."/>
595   - * <parameter name="Eb" scale=".." value=".." min=".." max=".." free=".."/>
  583 + * <parameter name="Prefactor" ../>
  584 + * <parameter name="Index" ../>
  585 + * <parameter name="Curvature" ../>
  586 + * <parameter name="PivotEnergy" ../>
596 587 * </spectrum>
597   - *
598   - * @todo Add parameter validity check
599 588 ***************************************************************************/
600 589 void GModelSpectralLogParabola::read(const GXmlElement& xml)
601 590 {
602   - // Verify that XML element has exactly 3 parameters
603   - if (xml.elements() != 4 || xml.elements("parameter") != 4) {
604   - throw GException::model_invalid_parnum(G_READ, xml,
605   - "LogParabola model requires exactly 4 parameters.");
  591 + // If standard parameters exists then read these parameters from the XML
  592 + // element
  593 + if (gammalib::xml_has_par(xml, "Prefactor") &&
  594 + gammalib::xml_has_par(xml, "Index") &&
  595 + gammalib::xml_has_par(xml, "Curvature") &&
  596 + gammalib::xml_has_par(xml, "PivotEnergy")) {
  597 + const GXmlElement* prefactor = gammalib::xml_get_par(G_READ, xml, "Prefactor");
  598 + const GXmlElement* index = gammalib::xml_get_par(G_READ, xml, "Index");
  599 + const GXmlElement* curvature = gammalib::xml_get_par(G_READ, xml, "Curvature");
  600 + const GXmlElement* pivot = gammalib::xml_get_par(G_READ, xml, "PivotEnergy");
  601 + m_norm.read(*prefactor);
  602 + m_index.read(*index);
  603 + m_curvature.read(*curvature);
  604 + m_pivot.read(*pivot);
  605 + }
  606 + else if (gammalib::xml_has_par(xml, "Prefactor") &&
  607 + gammalib::xml_has_par(xml, "Index") &&
  608 + gammalib::xml_has_par(xml, "Curvature") &&
  609 + gammalib::xml_has_par(xml, "Scale")) {
  610 + const GXmlElement* prefactor = gammalib::xml_get_par(G_READ, xml, "Prefactor");
  611 + const GXmlElement* index = gammalib::xml_get_par(G_READ, xml, "Index");
  612 + const GXmlElement* curvature = gammalib::xml_get_par(G_READ, xml, "Curvature");
  613 + const GXmlElement* pivot = gammalib::xml_get_par(G_READ, xml, "Scale");
  614 + m_norm.read(*prefactor);
  615 + m_index.read(*index);
  616 + m_curvature.read(*curvature);
  617 + m_pivot.read(*pivot);
606 618 }
607 619  
608   - // Extract model parameters
609   - int npar[] = {0, 0, 0,0};
610   - for (int i = 0; i < 4; ++i) {
611   -
612   - // Get parameter element
613   - const GXmlElement* par = xml.element("parameter", i);
614   -
615   - // Handle prefactor
616   - if (par->attribute("name") == "Prefactor" ||
617   - par->attribute("name") == "norm") {
618   - m_norm.read(*par);
619   - npar[0]++;
620   - }
621   -
622   - // Handle index
623   - else if (par->attribute("name") == "Index"){
624   - m_index.read(*par);
625   - npar[1]++;
626   - }
627   -
628   - // Change sign if index is defined Fermi-like
629   - else if(par->attribute("name") == "alpha") {
630   - m_index.read(*par);
631   - m_index.min(-m_index.max());
632   - m_index.max(-m_index.min());
633   - m_index.value(-m_index.value());
634   - npar[1]++;
635   - }
636   -
637   - // Handle curvature
638   - else if (par->attribute("name") == "Curvature") {
639   - m_curvature.read(*par);
640   - npar[2]++;
641   - }
642   -
643   - // Change sign if curvature is defined Fermi-like
644   - else if(par->attribute("name") == "beta") {
645   - m_curvature.read(*par);
646   - m_curvature.min(-m_curvature.max());
647   - m_curvature.max(-m_curvature.min());
648   - m_curvature.value(-m_curvature.value());
649   - npar[2]++;
650   - }
651   -
652   - // Handle pivot energy
653   - else if ((par->attribute("name") == "Scale") ||
654   - (par->attribute("name") == "Eb") ||
655   - (par->attribute("name") == "PivotEnergy")) {
656   - m_pivot.read(*par);
657   - npar[3]++;
658   - }
659   -
660   - } // endfor: looped over all parameters
  620 + // ... otherwise try reading parameter from legacy parameters. Note that
  621 + // "alpha" and "beta" are negated, hence we negate the parameters and
  622 + // boundaries after reading
  623 + #if defined(G_LEGACY_XML_FORMAT)
  624 + else if (gammalib::xml_has_par(xml, "norm") &&
  625 + gammalib::xml_has_par(xml, "alpha") &&
  626 + gammalib::xml_has_par(xml, "beta") &&
  627 + gammalib::xml_has_par(xml, "Eb")) {
  628 + const GXmlElement* prefactor = gammalib::xml_get_par(G_READ, xml, "norm");
  629 + const GXmlElement* index = gammalib::xml_get_par(G_READ, xml, "alpha");
  630 + const GXmlElement* curvature = gammalib::xml_get_par(G_READ, xml, "beta");
  631 + const GXmlElement* pivot = gammalib::xml_get_par(G_READ, xml, "Eb");
  632 + m_norm.read(*prefactor);
  633 + m_index.read(*index);
  634 + m_index.min(-m_index.max());
  635 + m_index.max(-m_index.min());
  636 + m_index.value(-m_index.value());
  637 + m_curvature.read(*curvature);
  638 + m_curvature.min(-m_curvature.max());
  639 + m_curvature.max(-m_curvature.min());
  640 + m_curvature.value(-m_curvature.value());
  641 + m_pivot.read(*pivot);
  642 + }
  643 + #endif
661 644  
662   - // Verify that all parameters were found
663   - if (npar[0] != 1 || npar[1] != 1 || npar[2] != 1 || npar[3] != 1) {
664   - throw GException::model_invalid_parnames(G_READ, xml,
665   - "LogParabola requires \"Prefactor\" or \"norm\","
666   - " \"Index\" or \"alpha\", \"Curvature\" or \"beta\""
667   - " and \"Scale\", \"Eb\" or \"PivotEnergy\" parameters.");
  645 + // ... otherwise throw an exception
  646 + else {
  647 + #if defined(G_LEGACY_XML_FORMAT)
  648 + std::string msg = "Log parabola model requires either "
  649 + "\"Prefactor\", \"Index\", \"Curvature\" and "
  650 + "\"PivotEnergy\" parameters or ";
  651 + "\"norm\", \"alpha\", \"beta\" and "
  652 + "\"Eb\" parameters.";
  653 + #else
  654 + std::string msg = "Log parabola model requires "
  655 + "\"Prefactor\", \"Index\", \"Curvature\" and "
  656 + "\"PivotEnergy\" parameters.";
  657 + #endif
  658 + throw GException::invalid_value(G_READ, msg);
668 659 }
669 660  
670 661 // Return
... ... @@ -707,16 +698,30 @@ void GModelSpectralLogParabola::write(GXmlElement&amp; xml) const
707 698 "Spectral model is not of type \""+type()+"\".");
708 699 }
709 700  
  701 + // Check if parameters are Fermi/LAT style and need to be negated
  702 + GModelPar inx = m_index;
  703 + GModelPar crv = m_curvature;
  704 + if (inx.name() == "alpha") {
  705 + inx.min(-inx.max());
  706 + inx.max(-inx.min());
  707 + inx.value(-inx.value());
  708 + }
  709 + if (crv.name() == "beta") {
  710 + crv.min(-crv.max());
  711 + crv.max(-crv.min());
  712 + crv.value(-crv.value());
  713 + }
  714 +
710 715 // Get XML parameters
711 716 GXmlElement* norm = gammalib::xml_need_par(G_WRITE, xml, m_norm.name());
712   - GXmlElement* index = gammalib::xml_need_par(G_WRITE, xml, m_index.name());
713   - GXmlElement* curvature = gammalib::xml_need_par(G_WRITE, xml, m_curvature.name());
  717 + GXmlElement* index = gammalib::xml_need_par(G_WRITE, xml, inx.name());
  718 + GXmlElement* curvature = gammalib::xml_need_par(G_WRITE, xml, crv.name());
714 719 GXmlElement* pivot = gammalib::xml_need_par(G_WRITE, xml, m_pivot.name());
715 720  
716 721 // Write parameters
717 722 m_norm.write(*norm);
718   - m_index.write(*index);
719   - m_curvature.write(*curvature);
  723 + inx.write(*index);
  724 + crv.write(*curvature);
720 725 m_pivot.write(*pivot);
721 726  
722 727 // Return
... ...
src/model/GModelSpectralPlaw.cpp
... ... @@ -515,10 +515,8 @@ GEnergy GModelSpectralPlaw::mc(const GEnergy&amp; emin,
515 515 *
516 516 * @param[in] xml XML element containing power law model information.
517 517 *
518   - * @exception GException::model_invalid_parnum
519   - * Invalid number of model parameters found in XML element.
520   - * @exception GException::model_invalid_parnames
521   - * Invalid model parameter names found in XML element.
  518 + * @exception GException::invalid_value
  519 + * Model parameters not found in XML element.
522 520 *
523 521 * Reads the spectral information from an XML element. The format of the XML
524 522 * elements is
... ... @@ -533,46 +531,40 @@ GEnergy GModelSpectralPlaw::mc(const GEnergy&amp; emin,
533 531 ***************************************************************************/
534 532 void GModelSpectralPlaw::read(const GXmlElement& xml)
535 533 {
536   - // Verify that XML element has exactly 3 parameters
537   - if (xml.elements() != 3 || xml.elements("parameter") != 3) {
538   - throw GException::model_invalid_parnum(G_READ, xml,
539   - "Power law model requires exactly 3 parameters.");
  534 + // If "PivotEnergy" parameter exists then read parameter from this
  535 + // XML element
  536 + if (gammalib::xml_has_par(xml, "PivotEnergy")) {
  537 + const GXmlElement* par = gammalib::xml_get_par(G_READ, xml, "PivotEnergy");
  538 + m_pivot.read(*par);
540 539 }
541 540  
542   - // Extract model parameters
543   - int npar[] = {0, 0, 0};
544   - for (int i = 0; i < 3; ++i) {
545   -
546   - // Get parameter element
547   - const GXmlElement* par = xml.element("parameter", i);
548   -
549   - // Handle prefactor
550   - if (par->attribute("name") == "Prefactor") {
551   - m_norm.read(*par);
552   - npar[0]++;
553   - }
554   -
555   - // Handle index
556   - else if (par->attribute("name") == "Index") {
557   - m_index.read(*par);
558   - npar[1]++;
559   - }
  541 + // ... otherwise try reading parameter from "Scale" parameter
  542 + #if defined(G_LEGACY_XML_FORMAT)
  543 + else if (gammalib::xml_has_par(xml, "Scale")) {
  544 + const GXmlElement* par = gammalib::xml_get_par(G_READ, xml, "Scale");
  545 + m_pivot.read(*par);
  546 + }
  547 + #endif
560 548  
561   - // Handle pivot energy
562   - else if ((par->attribute("name") == "Scale") ||
563   - (par->attribute("name") == "PivotEnergy")) {
564   - m_pivot.read(*par);
565   - npar[2]++;
566   - }
  549 + // ... otherwise throw an exception
  550 + else {
  551 + #if defined(G_LEGACY_XML_FORMAT)
  552 + std::string msg = "Power law model requires either "
  553 + "\"PivotEnergy\" or \"Scale\" parameter.";
  554 + #else
  555 + std::string msg = "Power law model requires "
  556 + "\"PivotEnergy\" parameter.";
  557 + #endif
  558 + throw GException::invalid_value(G_READ, msg);
  559 + }
567 560  
568   - } // endfor: looped over all parameters
  561 + // Get remaining XML parameters
  562 + const GXmlElement* prefactor = gammalib::xml_get_par(G_READ, xml, "Prefactor");
  563 + const GXmlElement* index = gammalib::xml_get_par(G_READ, xml, "Index");
569 564  
570   - // Verify that all parameters were found
571   - if (npar[0] != 1 || npar[1] != 1 || npar[2] != 1) {
572   - throw GException::model_invalid_parnames(G_READ, xml,
573   - "Require \"Prefactor\", \"Index\" and \"Scale\" or "
574   - "\"PivotEnergy\" parameters.");
575   - }
  565 + // Read parameters
  566 + m_norm.read(*prefactor);
  567 + m_index.read(*index);
576 568  
577 569 // Return
578 570 return;
... ...
src/model/GModelSpectralPlaw2.cpp
... ... @@ -620,85 +620,59 @@ GEnergy GModelSpectralPlaw2::mc(const GEnergy&amp; emin,
620 620 *
621 621 * @param[in] xml XML element.
622 622 *
623   - * @exception GException::model_invalid_parnum
624   - * Invalid number of model parameters found in XML element.
625   - * @exception GException::model_invalid_parnames
626   - * Invalid model parameter names found in XML element.
  623 + * @exception GException::invalid_value
  624 + * Model parameters not found in XML element.
627 625 *
628 626 * Reads the spectral information from an XML element. The format of the XML
629 627 * elements is
630 628 *
631 629 * <spectrum type="PowerLawPhotonFlux">
632   - * <parameter name="PhotonFlux" scale=".." value=".." min=".." max=".." free=".."/>
633   - * <parameter name="Index" scale=".." value=".." min=".." max=".." free=".."/>
634   - * <parameter name="LowerLimit" scale=".." value=".." min=".." max=".." free=".."/>
635   - * <parameter name="UpperLimit" scale=".." value=".." min=".." max=".." free=".."/>
  630 + * <parameter name="PhotonFlux" ../>
  631 + * <parameter name="Index" ../>
  632 + * <parameter name="LowerLimit" ../>
  633 + * <parameter name="UpperLimit" ../>
636 634 * </spectrum>
637 635 *
638 636 * @todo Add parameter validity check
639 637 ***************************************************************************/
640 638 void GModelSpectralPlaw2::read(const GXmlElement& xml)
641 639 {
642   - // Verify that XML element has exactly 4 parameters
643   - if (xml.elements() != 4 || xml.elements("parameter") != 4) {
644   - throw GException::model_invalid_parnum(G_READ, xml,
645   - "Power law 2 spectral model requires exactly 4 parameters.");
  640 + // If "PhotonFlux" parameter exists then read parameter from this
  641 + // XML element
  642 + if (gammalib::xml_has_par(xml, "PhotonFlux")) {
  643 + const GXmlElement* par = gammalib::xml_get_par(G_READ, xml, "PhotonFlux");
  644 + m_integral.read(*par);
646 645 }
647 646  
648   - // Extract model parameters
649   - int npar[] = {0, 0, 0, 0};
650   - for (int i = 0; i < 4; ++i) {
651   -
652   - // Get parameter element
653   - const GXmlElement* par = xml.element("parameter", i);
  647 + // ... otherwise try reading parameter from "Integral" parameter
  648 + #if defined(G_LEGACY_XML_FORMAT)
  649 + else if (gammalib::xml_has_par(xml, "Integral")) {
  650 + const GXmlElement* par = gammalib::xml_get_par(G_READ, xml, "Integral");
  651 + m_integral.read(*par);
  652 + }
  653 + #endif
654 654  
655   - // Handle prefactor
  655 + // ... otherwise throw an exception
  656 + else {
656 657 #if defined(G_LEGACY_XML_FORMAT)
657   - if (par->attribute("name") == "Integral") {
658   - m_integral.read(*par);
659   - npar[0]++;
660   - }
  658 + std::string msg = "Power law photon flux model requires either "
  659 + "\"PhotonFlux\" or \"Integral\" parameter.";
  660 + #else
  661 + std::string msg = "Power law photon flux model requires "
  662 + "\"PhotonFlux\" parameter.";
661 663 #endif
662   - if (par->attribute("name") == "PhotonFlux") {
663   - m_integral.read(*par);
664   - npar[0]++;
665   - }
666   -
667   - // Handle index
668   - else if (par->attribute("name") == "Index") {
669   - m_index.read(*par);
670   - npar[1]++;
671   - }
672   -
673   - // Handle lower limit
674   - else if (par->attribute("name") == "LowerLimit") {
675   - m_emin.read(*par);
676   - npar[2]++;
677   - }
678   -
679   - // Handle upper limit
680   - else if (par->attribute("name") == "UpperLimit") {
681   - m_emax.read(*par);
682   - npar[3]++;
683   - }
  664 + throw GException::invalid_value(G_READ, msg);
  665 + }
684 666  
685   - } // endfor: looped over all parameters
  667 + // Get remaining XML parameters
  668 + const GXmlElement* index = gammalib::xml_get_par(G_READ, xml, "Index");
  669 + const GXmlElement* emin = gammalib::xml_get_par(G_READ, xml, "LowerLimit");
  670 + const GXmlElement* emax = gammalib::xml_get_par(G_READ, xml, "UpperLimit");
686 671  
687   - // Verify that all parameters were found
688   - #if defined(G_LEGACY_XML_FORMAT)
689   - if (npar[0] != 1 || npar[1] != 1 || npar[2] != 1 || npar[3] != 1) {
690   - throw GException::model_invalid_parnames(G_READ, xml,
691   - "Power law 2 spectral model requires \"Integral\" or "
692   - "\"PhotonFlux\", \"Index\", \"LowerLimit\" and \"UpperLimit\" "
693   - "parameters.");
694   - }
695   - #else
696   - if (npar[0] != 1 || npar[1] != 1 || npar[2] != 1 || npar[3] != 1) {
697   - throw GException::model_invalid_parnames(G_READ, xml,
698   - "Power law 2 spectral model requires \"PhotonFlux\", \"Index\","
699   - " \"LowerLimit\" and \"UpperLimit\" parameters.");
700   - }
701   - #endif
  672 + // Read parameters
  673 + m_index.read(*index);
  674 + m_emin.read(*emin);
  675 + m_emax.read(*emax);
702 676  
703 677 // Return
704 678 return;
... ...
src/model/GModelSpectralSuperExpPlaw.cpp
... ... @@ -590,10 +590,8 @@ GEnergy GModelSpectralSuperExpPlaw::mc(const GEnergy&amp; emin,
590 590 *
591 591 * @param[in] xml XML element containing power law model information.
592 592 *
593   - * @exception GException::model_invalid_parnum
594   - * Invalid number of model parameters found in XML element.
595   - * @exception GException::model_invalid_parnames
596   - * Invalid model parameter names found in XML element.
  593 + * @exception GException::invalid_value
  594 + * Model parameters not found in XML element.
597 595 *
598 596 * Reads the spectral information from an XML element. The format of the XML
599 597 * elements is
... ... @@ -608,59 +606,45 @@ GEnergy GModelSpectralSuperExpPlaw::mc(const GEnergy&amp; emin,
608 606 ***************************************************************************/
609 607 void GModelSpectralSuperExpPlaw::read(const GXmlElement& xml)
610 608 {
611   - // Verify that XML element has exactly 5 parameters
612   - if (xml.elements() != 5 || xml.elements("parameter") != 5) {
613   - throw GException::model_invalid_parnum(G_READ, xml,
614   - "Super Exponential Power law model requires exactly 5 parameters.");
  609 + // If "PivotEnergy" parameter exists then read parameter from this
  610 + // XML element
  611 + if (gammalib::xml_has_par(xml, "PivotEnergy")) {
  612 + const GXmlElement* par = gammalib::xml_get_par(G_READ, xml, "PivotEnergy");
  613 + m_pivot.read(*par);
615 614 }
616 615  
617   - // Extract model parameters
618   - int npar[] = {0, 0, 0, 0, 0};
619   - for (int i = 0; i < 5; ++i) {
620   -
621   - // Get parameter element
622   - const GXmlElement* par = xml.element("parameter", i);
623   -
624   - // Handle prefactor
625   - if (par->attribute("name") == "Prefactor") {
626   - m_norm.read(*par);
627   - npar[0]++;
628   - }
629   -
630   - // Handle index1
631   - else if (par->attribute("name") == "Index1") {
632   - m_index1.read(*par);
633   - npar[1]++;
634   - }
635   -
636   - // Handle cutoff
637   - else if (par->attribute("name") == "Cutoff") {
638   - m_ecut.read(*par);
639   - npar[2]++;
640   - }
641   -
642   - // Handle pivot energy
643   - else if ((par->attribute("name") == "Scale") ||
644   - (par->attribute("name") == "PivotEnergy")) {
645   - m_pivot.read(*par);
646   - npar[3]++;
647   - }
648   -
649   - // Handle index2
650   - else if (par->attribute("name") == "Index2") {
651   - m_index2.read(*par);
652   - npar[4]++;
653   - }
654   -
655   - } // endfor: looped over all parameters
  616 + // ... otherwise try reading parameter from "Scale" parameter
  617 + #if defined(G_LEGACY_XML_FORMAT)
  618 + else if (gammalib::xml_has_par(xml, "Scale")) {
  619 + const GXmlElement* par = gammalib::xml_get_par(G_READ, xml, "Scale");
  620 + m_pivot.read(*par);
  621 + }
  622 + #endif
656 623  
657   - // Verify that all parameters were found
658   - if (npar[0] != 1 || npar[1] != 1 || npar[2] != 1 || npar[3] != 1 || npar[4] != 1) {
659   - throw GException::model_invalid_parnames(G_READ, xml,
660   - "Require \"Prefactor\", \"Index1\", \"Cutoff\", \"Scale\" or "
661   - "\"PivotEnergy\" and \"Index2\" parameters.");
  624 + // ... otherwise throw an exception
  625 + else {
  626 + #if defined(G_LEGACY_XML_FORMAT)
  627 + std::string msg = "Super exponentially cutoff power law model requires "
  628 + "either \"PivotEnergy\" or \"Scale\" parameter.";
  629 + #else
  630 + std::string msg = "Super exponentially cutoff power law model requires "
  631 + "\"PivotEnergy\" parameter.";
  632 + #endif
  633 + throw GException::invalid_value(G_READ, msg);
662 634 }
663 635  
  636 + // Get remaining XML parameters
  637 + const GXmlElement* prefactor = gammalib::xml_get_par(G_READ, xml, "Prefactor");
  638 + const GXmlElement* index1 = gammalib::xml_get_par(G_READ, xml, "Index1");
  639 + const GXmlElement* cutoff = gammalib::xml_get_par(G_READ, xml, "Cutoff");
  640 + const GXmlElement* index2 = gammalib::xml_get_par(G_READ, xml, "Index2");
  641 +
  642 + // Read parameters
  643 + m_norm.read(*prefactor);
  644 + m_index1.read(*index1);
  645 + m_ecut.read(*cutoff);
  646 + m_index2.read(*index2);
  647 +
664 648 // Return
665 649 return;
666 650 }
... ...
test/data/model_diffuse_cube.xml
... ... @@ -2,7 +2,7 @@
2 2 <source_library title="source library">
3 3 <source name="Test cube" type="DiffuseSource">
4 4 <spectrum type="ConstantValue">
5   - <parameter name="Value" scale="1" value="1" min="0" max="1000" free="1"/>
  5 + <parameter name="Normalization" scale="1" value="1" min="0" max="1000" free="1"/>
6 6 </spectrum>
7 7 <spatialModel type="DiffuseMapCube" file="test_cube.fits">
8 8 <parameter name="Normalization" scale="1" value="1" min="0.1" max="10" free="0"/>
... ...
test/data/model_diffuse_map.xml
... ... @@ -7,7 +7,7 @@
7 7 <parameter scale="1.0" name="PivotEnergy" min="10.0" max="1000000.0" value="100.0" free="0"/>
8 8 </spectrum>
9 9 <spatialModel type="DiffuseMap" file="cena_lobes_parkes.fits">
10   - <parameter scale="1" name="Prefactor" min="0.001" max="1000.0" value="1" free="0"/>
  10 + <parameter scale="1" name="Normalization" min="0.001" max="1000.0" value="1" free="0"/>
11 11 </spatialModel>
12 12 </source>
13 13 </source_library>
... ...
test/test_GModel.cpp
... ... @@ -833,15 +833,15 @@ void TestGModel::test_diffuse_map(void)
833 833 test_value(model.map().npix(), 3072);
834 834  
835 835 // Test operator access
836   - test_value(model["Prefactor"].value(), 3.9);
837   - test_value(model["Prefactor"].error(), 0.0);
838   - test_value(model["Prefactor"].gradient(), 0.0);
839   - model["Prefactor"].value(2.1);
840   - model["Prefactor"].error(1.9);
841   - model["Prefactor"].gradient(0.8);
842   - test_value(model["Prefactor"].value(), 2.1);
843   - test_value(model["Prefactor"].error(), 1.9);
844   - test_value(model["Prefactor"].gradient(), 0.8);
  836 + test_value(model["Normalization"].value(), 3.9);
  837 + test_value(model["Normalization"].error(), 0.0);
  838 + test_value(model["Normalization"].gradient(), 0.0);
  839 + model["Normalization"].value(2.1);
  840 + model["Normalization"].error(1.9);
  841 + model["Normalization"].gradient(0.8);
  842 + test_value(model["Normalization"].value(), 2.1);
  843 + test_value(model["Normalization"].error(), 1.9);
  844 + test_value(model["Normalization"].gradient(), 0.8);
845 845  
846 846 // Initialize photon direction for testing
847 847 GSkyDir dir;
... ...