Ignore:
Timestamp:
01/27/09 10:40:55 (16 years ago)
Author:
tbretz
Message:
*** empty log message ***
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/msimcamera/MSimCamera.cc

    r9256 r9274  
    4747
    4848#include "MSpline3.h"
     49#include "MPulseShape.h"
    4950
    5051#include "MParList.h"
     52//#include "MParameters.h"
    5153
    5254#include "MPhotonEvent.h"
     
    6769//
    6870MSimCamera::MSimCamera(const char* name, const char *title)
    69 : fEvt(0), fStat(0), fRunHeader(0), fCamera(0), fSpline(0),
    70   fFunction("exp(-(x/2)^2/2)"), fNpx(25), fXmin(-25), fXmax(25)
     71: fEvt(0), fStat(0), fRunHeader(0), fCamera(0), fSpline(0)//, fPulsePos(0)
    7172{
    7273    fName  = name  ? name  : "MSimCamera";
     
    7677// --------------------------------------------------------------------------
    7778//
    78 //  Call Clear()
    79 //
    80 MSimCamera::~MSimCamera()
    81 {
    82     Clear();
    83 }
    84 
    85 // --------------------------------------------------------------------------
    86 //
    87 //  Delete fSpline if set and set it to 0
    88 //
    89 void MSimCamera::Clear(Option_t *)
    90 {
    91     if (fSpline)
    92         delete fSpline;
    93     fSpline=0;
    94 }
    95 
    96 // --------------------------------------------------------------------------
    97 //
    98 //  Read the intended pulse shape from a file and initialize the spline
    99 // accordingly
    100 //
    101 Bool_t MSimCamera::ReadFile(const char *fname)
    102 {
    103     if (!fRunHeader)
    104         return kFALSE;
    105 
    106     if (fname)
    107         fFileName = fname;
    108 
    109     *fLog << inf << "Reading pulse shape from " << fFileName << endl;
    110 
    111     const TGraph g(fFileName);
    112     if (g.GetN()==0)
    113     {
    114         *fLog << err << "ERROR - No data points from " << fFileName << "." << endl;
    115         return kFALSE;
    116     }
    117 
    118     // option: b1/e1 b2/e2   (first second derivative?)
    119     // option: valbeg/valend (first second derivative?)
    120 
    121     Clear();
    122     fSpline = new MSpline3(g, fRunHeader->GetFreqSampling()/1000.);
    123 
    124     return kTRUE;
    125 }
    126 
    127 void MSimCamera::SetFunction(const TF1 &f)
    128 {
    129     // FIXME: Use TF1 directly? (In most cases this seems to be slower)
    130     if (!fRunHeader)
    131         return;// kFALSE;
    132 
    133     // option: b1/e1 b2/e2   (first second derivative?)
    134     // option: valbeg/valend (first second derivative?)
    135 
    136     // if (f.GetNpar()==0)
    137     // No SUPPORT
    138 
    139     Clear();
    140     fSpline = new MSpline3(f, fRunHeader->GetFreqSampling()/1000.);
    141 
    142     fFunction = f.GetTitle();
    143 }
    144 
    145 Bool_t MSimCamera::SetFunction(const char *func, Int_t n, Double_t xmin, Double_t xmax)
    146 {
    147     // FIXME: Use TF1 directly? (In most cases this seems to be slower)
    148     TF1 f("f", func, xmin, xmax);
    149     f.SetNpx(n);
    150 
    151     SetFunction(f);
    152 
    153     return kTRUE;
    154 }
    155 
    156 // --------------------------------------------------------------------------
    157 //
    158 // SetReadyToSave for fRunHeader
    159 //
    160 Bool_t MSimCamera::ReInit(MParList *pList)
    161 {
    162     // make that the run-header gets written to the file
    163     fRunHeader->SetReadyToSave();
    164 
    165     return kTRUE;
    166 }
    167 
    168 // --------------------------------------------------------------------------
    169 //
    17079// Search for the necessayr parameter containers.
    17180// Setup spline for pulse shape.
     
    197106        return kFALSE;
    198107    }
    199 
    200 
    201     // FIMXE: Move to ReInit in case fRunHeader is read form file?
    202     if (!fFileName.IsNull())
    203         return ReadFile(fFileName);
    204 
    205     if (!fFunction.IsNull())
    206         return SetFunction(fFunction, fNpx, fXmin, fXmax);
    207 
     108/*
     109    fPulsePos = (MParameterD*)pList->FindObject("IntendedPulsePos", "MParameterD");
     110    if (!fPulsePos)
     111    {
     112        *fLog << err << "IntendedPulsePos [MParameterD] not found... aborting." << endl;
     113        return kFALSE;
     114    }
     115 */
     116    MPulseShape *pulse = (MPulseShape*)pList->FindObject("MPulseShape");
     117    if (!pulse)
     118    {
     119        *fLog << err << "MPulseShape not found... aborting." << endl;
     120        return kFALSE;
     121    }
     122
     123    *fLog << warn << "FIXME - SCALE WITH THE SAMPLING FREQUENCY." << endl;
     124
     125    fSpline = pulse->GetSpline();
    208126    if (!fSpline)
    209127    {
     
    225143    const Double_t freq = fRunHeader->GetFreqSampling()/1000.;
    226144
    227     const Double_t start = fStat->GetTimeFirst()*freq + fSpline->GetXmin();
    228     const Double_t end   = fStat->GetTimeLast() *freq + fSpline->GetXmax();
     145    const Double_t start = fStat->GetTimeFirst()*freq;
     146    const Double_t end   = fStat->GetTimeLast() *freq;
    229147
    230148    const UInt_t   nlen  = TMath::CeilNint(end-start);
     
    236154    const UInt_t npix = fStat->GetMaxIndex()+1;
    237155
     156    const Double_t pl = fSpline->GetXmin()*freq;
     157    const Double_t pr = fSpline->GetXmax()*freq;
     158
    238159    // Init the arrays and set the range which will contain valid data
    239160    fCamera->Init(npix, nlen);
    240     fCamera->SetValidRange(0   -TMath::FloorNint(fSpline->GetXmin()),
    241                            nlen-TMath::CeilNint( fSpline->GetXmax()));
     161    fCamera->SetValidRange(TMath::FloorNint(pr), TMath::CeilNint(nlen+pl));
    242162
    243163    // Add electronic noise to empty channels
     
    258178
    259179        const UInt_t   idx = ph.GetTag();
    260         const Double_t t   = (ph.GetTime()-fStat->GetTimeFirst())*freq - fSpline->GetXmin();
     180        const Double_t t   = (ph.GetTime()-fStat->GetTimeFirst())*freq;// - fSpline->GetXmin();
    261181
    262182        // FIXME: Time jitter?
    263183        // FIXME: Add additional routing here?
    264184
     185        // === FIXME === FIXME === FIXME === Frequency!!!!
    265186        (*fCamera)[idx].AddPulse(*fSpline, t, ph.GetWeight());
    266187    }
    267188
    268189    return kTRUE;
    269 }
    270 
    271 // --------------------------------------------------------------------------
    272 //
    273 // FileName: pulse-shape.txt
    274 // Function.Name: gaus
    275 // Function.Npx:    50
    276 // Function.Xmin:  -5
    277 // Function.Xmax:   5
    278 //
    279 Int_t MSimCamera::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
    280 {
    281     Bool_t rc = kFALSE;
    282     if (IsEnvDefined(env, prefix, "FileName", print))
    283     {
    284         rc = kTRUE;
    285         SetFileName(GetEnvValue(env, prefix, "FileName", fFileName));
    286     }
    287 
    288     if (IsEnvDefined(env, prefix, "Function.Name", print))
    289     {
    290         rc = kTRUE;
    291         SetFunction(GetEnvValue(env, prefix, "Function.Name", fFunction));
    292 
    293         if (IsEnvDefined(env, prefix, "Function.Npx", print))
    294             fNpx = GetEnvValue(env, prefix, "Function.Npx", fNpx);
    295         if (IsEnvDefined(env, prefix, "Function.Xmin", print))
    296             fXmin = GetEnvValue(env, prefix, "Function.Xmin", fXmin);
    297         if (IsEnvDefined(env, prefix, "Function.Xmax", print))
    298             fXmax = GetEnvValue(env, prefix, "Function.Xmax", fXmax);
    299     }
    300 
    301     return rc;
    302190}
    303191
Note: See TracChangeset for help on using the changeset viewer.