Ignore:
Timestamp:
01/27/09 10:40:55 (16 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/melectronics
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/melectronics/ElectronicsLinkDef.h

    r9242 r9274  
    66
    77#pragma link C++ class APD+;
     8#pragma link C++ class MPulseShape+;
    89#pragma link C++ class MAnalogSignal+;
    910#pragma link C++ class MDigitalSignal+;
  • trunk/MagicSoft/Mars/melectronics/MAnalogSignal.cc

    r9252 r9274  
    3333#include "MAnalogSignal.h"
    3434
     35#include <TF1.h>
    3536#include <TRandom.h>
    3637#include <TObjArray.h>
     
    6970// and multiplied by f.
    7071//
    71 void MAnalogSignal::AddPulse(const MSpline3 &spline, Float_t t, Float_t f)
     72// Return kTRUE if the full range of the spline could be added to the
     73// analog signal, kFALSE otherwise.
     74//
     75Bool_t MAnalogSignal::AddPulse(const MSpline3 &spline, Float_t t, Float_t f)
    7276{
    7377    // FIXME: This could be improved using a MExtralgoSpline with
     
    7983    const Float_t end   = t+spline.GetXmax();
    8084
    81     /*const*/ Int_t  first = TMath::CeilNint(start);
    82     /*const*/ UInt_t last  = TMath::CeilNint(end); // Ceil:< Floor:<=
    83 
    84     if (first<0 || last>GetSize())
    85     {
    86         gLog << err << "ERROR - AddPulse: Out of bounds, ";
    87         gLog << "Win=[" << first << "," << last << "] N=" << GetSize() << " t=" << t;
    88         gLog << " Spline=[" << spline.GetXmin() << "," << spline.GetXmax() << "]" << endl;
    89 
    90         if (first<0)
    91             first=0;
    92         if (last>GetSize())
    93             last=GetSize();
    94     }
     85    Int_t  first = TMath::CeilNint(start);
     86    UInt_t last  = TMath::CeilNint(end); // Ceil:< Floor:<=
     87
     88    Bool_t rc = kTRUE;
     89    if (first<0)
     90    {
     91        first=0;
     92        rc = kFALSE;
     93    }
     94    if (last>GetSize())
     95    {
     96        last=GetSize();
     97        rc = kFALSE;
     98    }
     99
     100    // FIXME: As soon as we have access to TSpline3::fPoly we can
     101    //        gain a lot in execution speed here.
    95102
    96103    Float_t *arr = GetArray();
    97104    for (UInt_t i=first; i<last; i++)
    98105        arr[i] += spline.Eval(i-t)*f;
     106
     107    return rc;
     108}
     109
     110// ------------------------------------------------------------------------
     111//
     112// Evaluate the spline an add the result between t+xmin and t+xmax
     113// (xmin and xmax are the limits of the TF1) to the signal.
     114// The spline is evaluated at the bin-center of the analog signal
     115// and multiplied by f.
     116//
     117// Return kTRUE if the full range of the function could be added to the
     118// analog signal, kFALSE otherwise.
     119//
     120Bool_t MAnalogSignal::AddPulse(const TF1 &func, Float_t t, Float_t f)
     121{
     122    // Both in units of the sampling frequency
     123    const Float_t start = t+func.GetXmin();
     124    const Float_t end   = t+func.GetXmax();
     125
     126    Int_t  first = TMath::CeilNint(start);
     127    UInt_t last  = TMath::CeilNint(end); // Ceil:< Floor:<=
     128
     129    Bool_t rc = kTRUE;
     130    if (first<0)
     131    {
     132        first=0;
     133        rc = kFALSE;
     134    }
     135    if (last>GetSize())
     136    {
     137        last=GetSize();
     138        rc = kFALSE;
     139    }
     140
     141    // FIXME: As soon as we have access to TSpline3::fPoly we can
     142    //        gain a lot in execution speed here.
     143
     144    Float_t *arr = GetArray();
     145    for (UInt_t i=first; i<last; i++)
     146        arr[i] += func.Eval(i-t)*f;
     147
     148    return rc;
    99149}
    100150
     
    156206// The user is responsible of deleting the TObjArray.
    157207//
    158 TObjArray *MAnalogSignal::Discriminate(Float_t threshold, Float_t len) const
     208TObjArray *MAnalogSignal::Discriminate(Float_t threshold, Double_t start, Double_t end, Float_t len) const
    159209{
    160210    TObjArray *ttl = new TObjArray;
     
    175225
    176226    Double_t x1 = 0;
    177     Double_t x2 = 0;
     227    Double_t x2 = start;  // Start searching at x2
    178228
    179229    while (1)
    180230    {
    181         x1 = sp.SearchYup(x2+deadtime, threshold);
    182         if (x1<0)
    183             break;
    184 
    185         const Bool_t rising = sp.Deriv1(x1)>0;
    186         if (!rising)
     231        // Search for the next rising edge (starting at x2)
     232        while (1)
    187233        {
    188             // The last value might just have been a local max/min
    189             // or its period was short than 1e-4
     234            x1 = sp.SearchYup(x2+deadtime, threshold);
     235            if (x1<0 || x1>=end)
     236                return ttl;
     237
     238            const Bool_t rising = sp.Deriv1(x1)>0;
     239            if (rising)
     240                break;
     241
    190242            x2 = x1;
    191             //gLog << warn << "Rising edge expected at " << x1 << " (after " << x2 << ", N=" << fN << ")" << endl;
    192             continue;
    193243        }
    194244
    195         x2 = sp.SearchYup(x1+deadtime, threshold);
    196         if (x2<0)
    197             break;
    198 
    199         const Bool_t falling = sp.Deriv1(x2)<=0;
    200         if (!falling)
     245        // Search for the next falling edge (starting at x1)
     246        while (1)
    201247        {
    202             // The last value might just have been a local max/min
    203             // or its period was short than 1e-4
     248            x2 = sp.SearchYup(x1+deadtime, threshold);
     249            if (x2<0)
     250                x2 = end;
     251            if (x2>=end)
     252                break;
     253
     254            const Bool_t falling = sp.Deriv1(x2)<0;
     255            if (falling)
     256                break;
     257
    204258            x1 = x2;
    205             //gLog << warn << "Falling edge expected at " << x2 << " (after " << x1 << " N=" << fN << ")" << endl;
    206             continue;
    207259        }
    208260
     261        // We found a rising and a falling edge
    209262        MDigitalSignal *sig = new MDigitalSignal(x1, len>0?len:x2-x1);
    210263
     
    228281    }
    229282
    230     if (x1>=0)
    231         gLog << warn << "Falling edge expected before end at N=" << fN << "!" << endl;
    232 
    233283    return ttl;
    234284}
  • trunk/MagicSoft/Mars/melectronics/MAnalogSignal.h

    r9242 r9274  
    66#endif
    77
     8class TF1;
    89class MSpline3;
    910
     
    1718    MAnalogSignal(UInt_t n) { Set(n); }
    1819
    19     void Set(UInt_t n);
    20     void AddPulse(const MSpline3 &spline, Float_t t, Float_t f=1);
    21     void AddSignal(const MAnalogSignal &s);
     20    void   Set(UInt_t n);
     21    Bool_t AddPulse(const MSpline3 &spline, Float_t t, Float_t f=1);
     22    Bool_t AddPulse(const TF1 &f1, Float_t t, Float_t f=1);
     23    void   AddSignal(const MAnalogSignal &s);
    2224
    2325    // Deprecated. Use MSimRandomPhotons instead
     
    2628    void AddGaussianNoise(Float_t amplitude=1, Float_t offset=0);
    2729
    28     TObjArray *Discriminate(Float_t threshold, Float_t len=-1) const;
     30    TObjArray *Discriminate(Float_t threshold, Double_t start, Double_t end, Float_t len=-1) const;
     31    TObjArray *Discriminate(Float_t threshold, Float_t len=-1) const { return Discriminate(threshold, 0, fN-1, len); }
    2932
    3033    ClassDef(MAnalogSignal, 1) // Storage class for an analog signal
  • trunk/MagicSoft/Mars/melectronics/Makefile

    r9242 r9274  
    2424           MAnalogSignal.cc \
    2525           MAnalogChannels.cc \
    26            MDigitalSignal.cc
     26           MDigitalSignal.cc  \
     27           MPulseShape.cc
    2728
    2829############################################################
Note: See TracChangeset for help on using the changeset viewer.