Ignore:
Timestamp:
04/16/09 12:04:29 (16 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/msim
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/msim/MSimAbsorption.cc

    r9348 r9425  
    3030//
    3131//  Input Containers:
     32//   fParName [MParSpline]
    3233//   MPhotonEvent
    3334//   MCorsikaEvtHeader
     
    4344
    4445#include <TRandom.h>
    45 #include <TSpline.h>
    4646
    4747#include "MLog.h"
     
    5050#include "MParList.h"
    5151
    52 #include "MBinning.h"
    53 #include "MArrayD.h"
    54 
    55 #include "MSpline3.h"
     52#include "MParSpline.h"
    5653
    5754#include "MCorsikaEvtHeader.h"
     
    6966//
    7067MSimAbsorption::MSimAbsorption(const char* name, const char *title)
    71     : fEvt(0), fHeader(0), fSpline(0), fUseTheta(kFALSE)
     68    : fEvt(0), fHeader(0), fSpline(0), fParName("MParSpline"), fUseTheta(kFALSE)
    7269{
    7370    fName  = name  ? name  : "MSimAbsorption";
    7471    fTitle = title ? title : "Task to calculate wavelength dependent absorption";
    75 }
    76 
    77 // --------------------------------------------------------------------------
    78 //
    79 //  Calls Clear()
    80 //
    81 MSimAbsorption::~MSimAbsorption()
    82 {
    83     Clear();
    84 }
    85 
    86 // --------------------------------------------------------------------------
    87 //
    88 // Delete fSpline and set to 0.
    89 //
    90 void MSimAbsorption::Clear(Option_t *)
    91 {
    92     if (fSpline)
    93         delete fSpline;
    94     fSpline=0;
    95 }
    96 
    97 // --------------------------------------------------------------------------
    98 //
    99 // Read a TGraph from a file and return a newly allocated MSpline3.
    100 //
    101 MSpline3 *MSimAbsorption::ReadSpline(const char *fname)
    102 {
    103     *fLog << inf << "Reading spline from " << fname << endl;
    104 
    105     TGraph g(fname);
    106     if (g.GetN()==0)
    107     {
    108         *fLog << err << "ERROR - No data points from " << fname << "." << endl;
    109         return 0;
    110     }
    111 
    112     // option: b1/e1 b2/e2   (first second derivative?)
    113     // option: valbeg/valend (first second derivative?)
    114 
    115     return new MSpline3(g);
    116 }
    117 
    118 // --------------------------------------------------------------------------
    119 //
    120 // Initializes a spline from min to max with n points with 1.
    121 //
    122 void MSimAbsorption::InitUnity(UInt_t n, Float_t min, Float_t max)
    123 {
    124     // Delete the existing spline
    125     Clear();
    126 
    127     // We need at least two points (the edges)
    128     if (n<2)
    129         return;
    130 
    131     // Initialize an array with the x-values
    132     const MBinning bins(n-1, min, max);
    133 
    134     // Initialize an array with all one
    135     MArrayD y(n);
    136     y.Reset(1);
    137 
    138     // Set the spline
    139     fSpline = new MSpline3(bins.GetEdges(), y.GetArray(), n);
    140 }
    141 
    142 // --------------------------------------------------------------------------
    143 //
    144 // Takes the existing fSpline and multiplies it with the given spline.
    145 // As x-points the values from fSpline are used.
    146 //
    147 void MSimAbsorption::Multiply(const TSpline3 &spline)
    148 {
    149     if (!fSpline)
    150     {
    151         Clear();
    152         // WARNING WARNING WARNING: This is a very dangerous cast!
    153         fSpline = (MSpline3*)spline.Clone();
    154         return;
    155     }
    156 
    157     // Initialize a TGraph with the number of knots from a TSpline
    158     TGraph g(fSpline->GetNp());
    159 
    160     // Loop over all knots
    161     for (int i=0; i<fSpline->GetNp(); i++)
    162     {
    163         // Get th i-th knot
    164         Double_t x, y;
    165         fSpline->GetKnot(i, x, y);
    166 
    167         // Multiply y by the value from the given spline
    168         y *= spline.Eval(x);
    169 
    170         // push the point "back"
    171         g.SetPoint(i, x, y);
    172     }
    173 
    174     // Clear the spline and initialize a new one from the updated TGraph
    175     Clear();
    176     fSpline = new MSpline3(g);
    177 }
    178 
    179 // --------------------------------------------------------------------------
    180 //
    181 // Initializes a TSpline3 with n knots x and y. Call Multiply for it.
    182 //
    183 void MSimAbsorption::Multiply(UInt_t n, const Double_t *x, const Double_t *y)
    184 {
    185     const TSpline3 spline("Spline", const_cast<Double_t*>(x), const_cast<Double_t*>(y), n);
    186     Multiply(spline);
    187 }
    188 
    189 // --------------------------------------------------------------------------
    190 //
    191 // Read a Spline from a file using ReadSpline.
    192 // Call Multiply for it.
    193 //
    194 void MSimAbsorption::Multiply(const char *fname)
    195 {
    196     const MSpline3 *spline = ReadSpline(fname);
    197     if (!spline)
    198         return;
    199 
    200     fFileName = "";
    201 
    202     Multiply(*spline);
    203 
    204     delete spline;
    205 }
    206 
    207 // --------------------------------------------------------------------------
    208 //
    209 // Read a spline from a file and set fSpline accfordingly.
    210 //
    211 Bool_t MSimAbsorption::ReadFile(const char *fname)
    212 {
    213     if (fname)
    214         fFileName = fname;
    215 
    216     MSpline3 *spline = ReadSpline(fFileName);
    217     if (!spline)
    218         return kFALSE;
    219 
    220 
    221     // option: b1/e1 b2/e2   (first second derivative?)
    222     // option: valbeg/valend (first second derivative?)
    223 
    224     Clear();
    225     fSpline = spline;
    226 
    227     return kTRUE;
    22872}
    22973
     
    23579Int_t MSimAbsorption::PreProcess(MParList *pList)
    23680{
    237     if (fFileName.IsNull())
    238     {
    239         *fLog << inf << "No file given... skipping." << endl;
    240         return kSKIP;
    241     }
    242 
    24381    fEvt = (MPhotonEvent*)pList->FindObject("MPhotonEvent");
    24482    if (!fEvt)
    24583    {
    24684        *fLog << err << "MPhotonEvent not found... aborting." << endl;
     85        return kFALSE;
     86    }
     87
     88    fSpline = (MParSpline*)pList->FindObject(fParName, "MParSpline");
     89    if (!fSpline)
     90    {
     91        *fLog << err << fParName << " [MParSpline] not found... aborting." << endl;
     92        return kFALSE;
     93    }
     94
     95    if (!fSpline->IsValid())
     96    {
     97        *fLog << err << "Spline in " << fParName << " is inavlid... aborting." << endl;
    24798        return kFALSE;
    24899    }
     
    257108    *fLog << inf << "Using " << (fUseTheta?"Theta":"Wavelength") << " for absorption." << endl;
    258109
    259     return ReadFile();
     110    return kTRUE;
    260111}
    261112
     
    331182{
    332183    Bool_t rc = kFALSE;
    333     if (IsEnvDefined(env, prefix, "FileName", print))
     184    if (IsEnvDefined(env, prefix, "ParName", print))
    334185    {
    335186        rc = kTRUE;
    336         SetFileName(GetEnvValue(env, prefix, "FileName", fFileName));
     187        SetParName(GetEnvValue(env, prefix, "ParName", fParName));
    337188    }
    338189
  • trunk/MagicSoft/Mars/msim/MSimAbsorption.h

    r9232 r9425  
    66#endif
    77
    8 class TSpline3;
    9 
    108class MParList;
    11 class MSpline3;
     9class MParSpline;
    1210class MPhotonEvent;
    1311class MCorsikaEvtHeader;
     
    1917    MCorsikaEvtHeader *fHeader;  //! Header storing event information
    2018
    21     MSpline3          *fSpline;  //! Spline to interpolate wavelength or incident angle
     19    MParSpline        *fSpline;  //! Spline to interpolate wavelength or incident angle
    2220
    23     TString fFileName;           // FileName of the file containing the curve
     21    TString fParName;            // Container name of the spline containing the curve
    2422    Bool_t  fUseTheta;           // Switches between using wavelength or incident angle
    2523
     
    3230    Int_t  Process();
    3331
    34     // MSimAbsorption
    35     MSpline3 *ReadSpline(const char *fname);
    36 
    3732public:
    3833    MSimAbsorption(const char *name=NULL, const char *title=NULL);
    39     ~MSimAbsorption();
    4034
    4135    // MSimAbsorption
    42     Bool_t ReadFile(const char *fname=0);
    43     void SetFileName(const char *fname) { fFileName=fname; }
     36    void SetParName(const char *name) { fParName=name; }
    4437
    4538    void SetUseTheta(Bool_t b=kTRUE) { fUseTheta = b; }
    46 
    47     void InitUnity(UInt_t n, Float_t min, Float_t max);
    48 
    49     void Multiply(const char *fname);
    50     void Multiply(const TSpline3 &spline);
    51     void Multiply(UInt_t n, const Double_t *x, const Double_t *y);
    52 
    53     // TObject
    54     void Clear(Option_t *o="");
    5539
    5640    ClassDef(MSimAbsorption, 0) // Task to calculate wavelength or incident angle dependent absorption
Note: See TracChangeset for help on using the changeset viewer.