Ignore:
Timestamp:
01/17/09 14:52:43 (16 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mextralgo
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mextralgo/ExtralgoIncl.h

    r7942 r9226  
    11#ifndef __CINT__
    22
     3#include "../mbase/MArrayF.h"
     4
    35#endif // __CINT__
  • trunk/MagicSoft/Mars/mextralgo/MExtralgoSpline.cc

    r9212 r9226  
    1818!   Author(s): Markus Gaug 09/2004 <mailto:markus@ifae.es>
    1919!
    20 !   Copyright: MAGIC Software Development, 2002-2008
     20!   Copyright: MAGIC Software Development, 2002-2009
    2121!
    2222!
     
    120120// --------------------------------------------------------------------------
    121121//
    122 // Returns the highest x value in [min;max[ at which the spline in
    123 // the bin i is equal to y
    124 //
    125 // min and max are defined to be [0;1]
    126 //
    127 // The default for min is 0, the default for max is 1
    128 // The defaule for y is 0
    129 //
    130 Double_t MExtralgoSpline::FindY(Int_t i, Bool_t downwards, Double_t y, Double_t min, Double_t max) const
     122// Solve the polynomial
     123//
     124//    y = a*x^3 + b*x^2 + c*x + d'
     125//    0 = a*x^3 + b*x^2 + c*x + d' - y
     126//
     127// to find y in the i-th bin. Return the result as x1, x2, x3 and the return
     128// code from MMath::SolvPol3.
     129//
     130Int_t MExtralgoSpline::SolvePol3(Int_t i, Double_t y, Double_t &x1, Double_t &x2, Double_t &x3) const
    131131{
    132132    // y = a*x^3 + b*x^2 + c*x + d'
     
    145145    //     return -2;
    146146
     147    return MMath::SolvePol3(a, b, c, d, x1, x2, x3);
     148}
     149
     150// --------------------------------------------------------------------------
     151//
     152// Returns the highest x value in [min;max[ at which the spline in
     153// the bin i is equal to y
     154//
     155// min and max must be in the range [0;1]
     156//
     157// The default for min is 0, the default for max is 1
     158// The default for y is 0
     159//
     160Double_t MExtralgoSpline::FindYdn(Int_t i, Double_t y, Double_t min, Double_t max) const
     161{
    147162    Double_t x1, x2, x3;
    148     const Int_t rc = MMath::SolvePol3(a, b, c, d, x1, x2, x3);
    149 
    150     if (downwards==kTRUE)
    151     {
    152         Double_t x = -1;
    153 
    154         if (rc>0 && x1>=min && x1<max && x1>x)
    155             x = x1;
    156         if (rc>1 && x2>=min && x2<max && x2>x)
    157             x = x2;
    158         if (rc>2 && x3>=min && x3<max && x3>x)
    159             x = x3;
    160 
    161         return x<0 ? -2 : x+i;
    162     }
    163     else
    164     {
    165         Double_t x = 2;
    166 
    167         if (rc>0 && x1>min && x1<=max && x1<x)
    168             x = x1;
    169         if (rc>1 && x2>min && x2<=max && x2<x)
    170             x = x2;
    171         if (rc>2 && x3>min && x3<=max && x3<x)
    172             x = x3;
    173 
    174         return x>1 ? -2 : x+i;
    175     }
    176 
    177     return -2;
     163    const Int_t rc = SolvePol3(i, y, x1, x2, x3);
     164
     165    Double_t x = -1;
     166
     167    if (rc>0 && x1>=min && x1<max && x1>x)
     168        x = x1;
     169    if (rc>1 && x2>=min && x2<max && x2>x)
     170        x = x2;
     171    if (rc>2 && x3>=min && x3<max && x3>x)
     172        x = x3;
     173
     174    return x<0 ? -2 : x+i;
     175}
     176
     177// --------------------------------------------------------------------------
     178//
     179// Returns the lowest x value in [min;max[ at which the spline in
     180// the bin i is equal to y
     181//
     182// min and max must be in the range [0;1]
     183//
     184// The default for min is 0, the default for max is 1
     185// The default for y is 0
     186//
     187Double_t MExtralgoSpline::FindYup(Int_t i, Double_t y, Double_t min, Double_t max) const
     188{
     189    Double_t x1, x2, x3;
     190    const Int_t rc = SolvePol3(i, y, x1, x2, x3);
     191
     192    Double_t x = 2;
     193
     194    if (rc>0 && x1>min && x1<=max && x1<x)
     195        x = x1;
     196    if (rc>1 && x2>min && x2<=max && x2<x)
     197        x = x2;
     198    if (rc>2 && x3>min && x3<=max && x3<x)
     199        x = x3;
     200
     201    return x>1 ? -2 : x+i;
    178202}
    179203
     
    181205//
    182206// Search analytically downward for the value y of the spline, starting
    183 // at x, until x==0. If y is not found -2 is returned.
     207// at x, until x==0. If y is not found or out of range -2 is returned.
    184208//
    185209Double_t MExtralgoSpline::SearchYdn(Float_t x, Float_t y) const
     
    192216        return -2;
    193217
    194     Double_t rc = FindY(i, kTRUE, y, 0, x-i);
     218    Double_t rc = FindYdn(i, y, 0, x-i);
    195219    while (--i>=0 && rc<0)
    196         rc = FindY(i, kTRUE, y);
     220        rc = FindYdn(i, y);
    197221
    198222    return rc;
    199223}
    200224
     225// --------------------------------------------------------------------------
     226//
     227// Search analytically upwards for the value y of the spline, starting
     228// at x, until x==fNum-1. If y is not found or out of range -2 is returned.
     229//
    201230Double_t MExtralgoSpline::SearchYup(Float_t x, Float_t y) const
    202231{
     
    208237        return -2;
    209238
    210     Double_t rc = FindY(i, kFALSE, y, x-i, 1.);
     239    Double_t rc = FindYup(i, y, x-i, 1.);
    211240    while (++i<fNum-1 && rc<0)
    212         rc = FindY(i, kFALSE, y);
     241        rc = FindYup(i, y);
    213242
    214243    return rc;
     
    222251Float_t MExtralgoSpline::CalcIntegral(Float_t pos) const
    223252{
    224     // In the future we will calculate the intgeral analytically.
    225     // It has been tested that it gives identical results within
    226     // acceptable differences.
    227 
    228253    // We allow extrapolation of 1/2 slice.
    229254    const Float_t min = fRiseTime;        //-0.5+fRiseTime;
     
    236261
    237262    return EvalInteg(pos-fRiseTime, pos+fFallTime);
     263}
     264
     265MArrayF MExtralgoSpline::GetIntegral(bool norm) const
     266{
     267    MArrayF val(fNum);
     268
     269    //val[0] = 0;
     270
     271    Double_t integ = 0;
     272    for (int i=0; i<fNum-1; i++)
     273    {
     274        integ += EvalInteg(i);
     275
     276        val[i+1] = integ;
     277    }
     278
     279    if (norm)
     280        for (int i=0; i<fNum-1; i++)
     281            val[i+1] /= val[fNum-1];
     282
     283    return val;
    238284}
    239285
  • trunk/MagicSoft/Mars/mextralgo/MExtralgoSpline.h

    r9212 r9226  
    66#endif
    77
     8class MArrayF;
    89class TComplex;
    910
     
    7576    }
    7677
    77     Double_t FindY(Int_t i, Bool_t downwards, Double_t y=0, Double_t min=0, Double_t max=1) const;
     78    Int_t SolvePol3(Int_t i, Double_t y, Double_t &x1, Double_t &x2, Double_t &x3) const;
     79    Double_t FindYdn(Int_t i, Double_t y=0, Double_t min=0, Double_t max=1) const;
     80    Double_t FindYup(Int_t i, Double_t y=0, Double_t min=0, Double_t max=1) const;
     81    //Double_t FindY(Int_t i, Bool_t downwards, Double_t y=0, Double_t min=0, Double_t max=1) const;
    7882
    7983    Int_t EvalDerivEq0(const Int_t i, Double_t &x1, Double_t &x2) const;
     
    153157    }
    154158
    155     // Identical to sum EvalInteg(i, 0, 1) for i=0 to i<b but much faster
     159    // Identical to sum of EvalInteg(i, 0, 1) for i=a to i=b-1,
     160    // but much faster
     161    // It is identical to EvalInteg(fVal[a], fVal[b])
    156162    // Be carefull: NO RANGECHECK!
    157163    inline Double_t EvalInteg(Int_t a, Int_t b) const
     
    329335    Double_t SearchYdn(Float_t y) const { return SearchYdn(fNum, y); }
    330336    Double_t SearchYup(Float_t y) const { return SearchYup(0,    y); }
     337
     338    MArrayF GetIntegral(bool norm=true) const;
    331339};
    332340
Note: See TracChangeset for help on using the changeset viewer.