Changeset 18155 for trunk/Mars/mdrs


Ignore:
Timestamp:
02/19/15 10:37:24 (10 years ago)
Author:
tbretz
Message:
We now precalculate the DRS offsets. This is faster and allows to read and write them directly to a fits file.
Location:
trunk/Mars/mdrs
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Mars/mdrs/MDrsCalibrationTime.cc

    r18151 r18155  
    5959    gSystem->ExpandPathName(fname);
    6060
    61     string msg;
    6261    try
    6362    {
    64         msg = DrsCalibrateTime::ReadFitsImp(fname.Data());
     63        fits file(fname.Data());
     64        if (!file)
     65            throw runtime_error(strerror(errno));
     66
     67        if (file.GetStr("TELESCOP")!="FACT")
     68        {
     69            std::ostringstream msg;
     70            msg << "Not a valid FACT file (TELESCOP not FACT in header)";
     71            throw runtime_error(msg.str());
     72        }
     73
     74        if (file.GetNumRows()!=1)
     75            throw runtime_error("Number of rows in table is not 1.");
     76
     77        fNumSamples  = file.GetUInt("NROI");
     78        fNumChannels = file.GetUInt("NCH");
     79        fNumEntries  = file.GetUInt("NBTIME");
     80
     81        const double *d = reinterpret_cast<double*>(file.SetPtrAddress("CellOffset"));
     82        if (!file.GetNextRow())
     83            throw runtime_error("Read error.");
     84
     85        fOffsets.assign(d, d+fNumSamples*fNumChannels),
     86        fDelays.resize(0);
    6587    }
    6688    catch (const exception &e)
    6789    {
    68         msg = e.what();
     90        *fLog << err << "Error reading from " << fname << ": " << e.what() << endl;
     91        return false;
    6992    }
    7093
    71     if (msg.empty())
    72     {
    73         *fLog << inf << "Read DRS calibration file " << fname << endl;
    74         return true;
    75     }
    76 
    77     *fLog << err << "Error reading from " << fname << ": " << msg << endl;
    78     return false;
     94    *fLog << inf << "Read DRS calibration file " << fname << endl;
     95    return true;
    7996}
    8097
     
    88105    }
    89106
    90     string msg;
    91107    try
    92108    {
    93         msg = DrsCalibrateTime::WriteFitsImp(fname);
     109        ofits file(fname.c_str());
     110        if (!file)
     111            throw runtime_error(strerror(errno));
     112
     113        file.SetDefaultKeys();
     114        file.AddColumnDouble(fNumSamples*fNumChannels, "CellOffset", "samples", "Integral cell offset");
     115
     116        file.SetInt("ADCRANGE", 2000,    "Dynamic range of the ADC in mV");
     117        file.SetInt("DACRANGE", 2500,    "Dynamic range of the DAC in mV");
     118        file.SetInt("ADC",      12,      "Resolution of ADC in bits");
     119        file.SetInt("DAC",      16,      "Resolution of DAC in bits");
     120        file.SetInt("NPIX",     1440,    "Number of channels in the camera");
     121        file.SetInt("NTM",      0,       "Number of time marker channels");
     122        file.SetInt("NROI",     fNumSamples,  "Region of interest");
     123        file.SetInt("NCH",      fNumChannels, "Number of chips");
     124        file.SetInt("NBTIME",   fNumEntries,  "Num of entries for time calibration");
     125
     126        file.WriteTableHeader("DrsCellTimes");
     127        //file.SetInt("NIGHT", night, "Night as int");
     128
     129        /*
     130        file.SetStr("DATE-OBS", fDateObs, "First event of whole DRS calibration");
     131        file.SetStr("DATE-END", fDateEnd, "Last event of whole DRS calibration");
     132        file.SetStr("RUN-BEG", fDateRunBeg[0], "First event of run 0");
     133        file.SetStr("RUN-END", fDateRunEnd[0], "Last event of run 0");
     134        */
     135
     136        if (!file.WriteRow(fOffsets.data(), fOffsets.size()*sizeof(double)))
     137            throw runtime_error("Write error.");
    94138    }
    95139    catch (const exception &e)
    96140    {
    97         msg = e.what();
     141        *fLog << err << "Error writing to " << fname << ": " << e.what() << endl;
     142        return false;
    98143    }
    99144
    100     if (msg.empty())
    101     {
    102         *fLog << inf << "Wrote DRS calibration file " << fname << endl;
    103         return true;
    104     }
    105 
    106     *fLog << err << "Error writing to " << fname << ": " << msg << endl;
    107     return false;
     145    *fLog << inf << "Wrote DRS calibration file " << fname << endl;
     146    return true;
    108147}
  • trunk/Mars/mdrs/MDrsCalibrationTime.h

    r18154 r18155  
    1212class TGraph;
    1313
    14 class MDrsCalibrationTime : public MParContainer, public DrsCalibrateTime
     14class MDrsCalibrationTime : public MParContainer//, public DrsCalibrateTime
    1515{
     16    int64_t fNumEntries;
     17
     18    size_t fNumSamples;
     19    size_t fNumChannels;
     20
     21    std::vector<double> fOffsets;
    1622    std::vector<double> fDelays;
    1723
     
    1925    MDrsCalibrationTime(const char *name=0, const char *title=0)
    2026    {
    21         fName  = name ? name : "MDrsCalibrationTime";
     27        fName  = name  ? name : "MDrsCalibrationTime";
    2228        fTitle = title ? title : "";
    2329    }
     
    2531    void InitSize(uint16_t channels, uint16_t samples)
    2632    {
    27         //fDelays.clear();
    28         //fDelays.resize(channels);
    29 
    30         DrsCalibrateTime::InitSize(channels, samples);
     33        fNumSamples  = samples;
     34        fNumChannels = channels;
    3135    }
    3236
    3337    void SetCalibration(const DrsCalibrateTime &cal)
    3438    {
    35         *static_cast<DrsCalibrateTime*>(this) = cal;
     39        fNumEntries  = cal.fNumEntries,
     40        fNumSamples  = cal.fNumSamples,
     41        fNumChannels = cal.fNumChannels,
     42
     43        fOffsets.resize(fNumSamples*fNumChannels);
     44
     45        for (size_t c=0; c<fNumChannels; c++)
     46            for (size_t s=0; s<fNumSamples; s++)
     47                fOffsets[c*fNumSamples+s] = cal.Offset(c, s);
    3648    }
    3749
     
    3951    void SetDelays(const TGraph &g);
    4052
    41     double GetOffset(int hw, int spos, float tm) const
     53    double GetOffset(uint32_t hw, uint32_t spos, float tm) const
    4254    {
    43         return Offset(hw/9, fmod(tm+spos, 1024)) - Offset(hw/9, spos);
     55        const uint32_t ch = (hw/9)*fNumSamples;
     56        return fOffsets[ch + fmod(tm+spos, fNumSamples)] - fOffsets[ch + spos];
    4457    }
    4558
     
    5265    bool WriteFits(const std::string &fname) const;
    5366
    54     ClassDef(MDrsCalibrationTime, 2) // A list of histograms storing the Fadc spektrum of one pixel
     67    ClassDef(MDrsCalibrationTime, 3) // A list of histograms storing the Fadc spektrum of one pixel
    5568};
    5669
  • trunk/Mars/mdrs/MHDrsCalibrationTime.cc

    r17760 r18155  
    1616!
    1717!
    18 !   Author(s): Thomas Bretz 2013 <mailto:tbretz@phys.ethz.ch>
    19 !
    20 !   Copyright: MAGIC Software Development, 2000-2014
     18!   Author(s): Thomas Bretz 2013 <mailto:tbretz@physik.rwth-aachen.de>
     19!
     20!   Copyright: MAGIC Software Development, 2000-2015
    2121!
    2222!
     
    3737#include "MStatusDisplay.h"
    3838
     39#include "MDrsCalibrationTime.h"
    3940#include "MPedestalSubtractedEvt.h"
    4041
  • trunk/Mars/mdrs/MHDrsCalibrationTime.h

    r14922 r18155  
    22#define MARS_MHDrsCalibrationTime
    33
    4 #ifndef MARS_DrsCalibrationTime
    5 #include "MDrsCalibrationTime.h"
     4#ifndef MARS_DrsCalib
     5#include "DrsCalib.h"
    66#endif
    77
     
    2323    MDrsCalibrationTime    *fCal;     //!
    2424
    25     MDrsCalibrationTime fData; //
     25    DrsCalibrateTime fData; //
    2626
    2727    void InitHistogram();
Note: See TracChangeset for help on using the changeset viewer.