Ignore:
Timestamp:
08/18/15 10:28:44 (9 years ago)
Author:
Jens Buss
Message:
merged Trunk into Branch
Location:
branches/MarsGapdTimeJitter
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/MarsGapdTimeJitter

  • branches/MarsGapdTimeJitter/mdrs/MCalibrateDrsTimes.cc

    r17759 r18282  
    152152            continue;
    153153
    154         const Float_t signal = (*fSignals)[sw].GetArrivalTime();
     154        const Float_t signal = (*fSignals)[sw].GetArrivalTimeHiGain();
     155        const Float_t slope  = (*fSignals)[sw].GetArrivalTimeHiGainError();
    155156        const Float_t offset = fCalib ? fCalib->GetOffset(hw, start[hw], signal) : 0;
    156         const Float_t delay  = fCalib ? fCalib->GetDelay(sw) : 0;
     157        const Float_t offset2 = (fCalib && (signal-slope)>=0) ? fCalib->GetOffset(hw, start[hw], signal-slope) : 0;
     158        const Float_t delay  = fCalib ? fCalib->GetDelay(hw) : 0;
    157159
    158160        //if (fIsTimeMarker)
     
    160162
    161163        // convert from slices to ns
    162         const Float_t utime = 1000*(signal       )/fFreq-delay; // [ns]
    163         const Float_t time  = 1000*(signal-offset)/fFreq-delay; // [ns]
     164        const Float_t utime      = 1000*(signal       )/fFreq-delay;  // [ns]
     165        const Float_t time       = 1000*(signal-offset)/fFreq-delay;  // [ns]
     166        const Float_t slopecal   = (slope-offset+offset2)<0 ? -1 : 1000*(slope-offset+offset2)/fFreq; // [ns]
     167        const Float_t uslope     = slope<0 ? -1 : 1000*(slope)/fFreq;                // [ns]
    164168
    165169        /*
     
    172176        {
    173177            (*fArrivalTime)[idx[j]].SetArrivalTime(time);
     178            (*fArrivalTime)[idx[j]].SetTimeSlope(slopecal);
    174179            if (fArrivalTimeU)
     180            {
    175181                (*fArrivalTimeU)[idx[j]].SetArrivalTime(utime);
     182                (*fArrivalTimeU)[idx[j]].SetTimeSlope(uslope);
     183            }
    176184        }
    177185    }
  • branches/MarsGapdTimeJitter/mdrs/MDrsCalibration.h

    r17758 r18282  
    3030    }
    3131
    32     bool ReadFits(TString str)
     32    bool ReadFits(TString fname)
    3333    {
    34         gSystem->ExpandPathName(str);
     34        gSystem->ExpandPathName(fname);
    3535
    36         const std::string msg = ReadFitsImp(str.Data());
     36        std::string msg;
     37        try
     38        {
     39            msg = ReadFitsImp(fname.Data());
     40        }
     41        catch (const std::exception &e)
     42        {
     43            msg = e.what();
     44        }
     45
    3746        if (msg.empty())
     47        {
     48            *fLog << inf << "Read DRS calibration file " << fname << std::endl;
    3849            return true;
     50        }
    3951
    40         *fLog << err << msg << std::endl;
     52        *fLog << err << "Error reading from " << fname << ": " << msg << std::endl;
    4153        return false;
    4254    }
  • branches/MarsGapdTimeJitter/mdrs/MDrsCalibrationTime.cc

    r14922 r18282  
    1616!
    1717!
    18 !   Author(s): Thomas Bretz  2013 <mailto:thomas.bretz@epfl.ch>
     18!   Author(s): Thomas Bretz  2013 <mailto:tbretz@physik.rwth-aachen.de>
    1919!
    20 !   Copyright: MAGIC Software Development, 2000-2013
     20!   Copyright: MAGIC Software Development, 2000-2015
    2121!
    2222!
     
    3131
    3232#include <TH1.h>
     33#include <TGraph.h>
    3334
    3435ClassImp(MDrsCalibrationTime);
     
    4849    return true;
    4950}
     51
     52void MDrsCalibrationTime::SetDelays(const TGraph &g)
     53{
     54    fDelays.assign(g.GetY(), g.GetY()+g.GetN());
     55}
     56
     57bool MDrsCalibrationTime::ReadFits(TString fname)
     58{
     59    gSystem->ExpandPathName(fname);
     60
     61    try
     62    {
     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);
     87    }
     88    catch (const exception &e)
     89    {
     90        *fLog << err << "Error reading from " << fname << ": " << e.what() << endl;
     91        return false;
     92    }
     93
     94    *fLog << inf << "Read DRS calibration file " << fname << endl;
     95    return true;
     96}
     97
     98bool MDrsCalibrationTime::WriteFits(const string &fname) const
     99{
     100    const Bool_t exists = !gSystem->AccessPathName(fname.c_str(), kFileExists);
     101    if (exists)
     102    {
     103        *fLog << err << "File '" << fname << "' already exists." << endl;
     104        return false;
     105    }
     106
     107    try
     108    {
     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.");
     138    }
     139    catch (const exception &e)
     140    {
     141        *fLog << err << "Error writing to " << fname << ": " << e.what() << endl;
     142        return false;
     143    }
     144
     145    *fLog << inf << "Wrote DRS calibration file " << fname << endl;
     146    return true;
     147}
  • branches/MarsGapdTimeJitter/mdrs/MDrsCalibrationTime.h

    r17697 r18282  
    1010
    1111class TH1;
     12class TGraph;
    1213
    13 class MDrsCalibrationTime : public MParContainer, public DrsCalibrateTime
     14class MDrsCalibrationTime : public MParContainer//, public DrsCalibrateTime
    1415{
     16    int64_t fNumEntries;
     17
     18    size_t fNumSamples;
     19    size_t fNumChannels;
     20
     21    std::vector<double> fOffsets;
    1522    std::vector<double> fDelays;
    1623
     
    1825    MDrsCalibrationTime(const char *name=0, const char *title=0)
    1926    {
    20         fName  = name ? name : "MDrsCalibrationTime";
     27        fName  = name  ? name : "MDrsCalibrationTime";
    2128        fTitle = title ? title : "";
    2229    }
     
    2431    void InitSize(uint16_t channels, uint16_t samples)
    2532    {
    26         //fDelays.clear();
    27         //fDelays.resize(channels);
    28 
    29         DrsCalibrateTime::InitSize(channels, samples);
     33        fNumSamples  = samples;
     34        fNumChannels = channels;
    3035    }
    3136
    3237    void SetCalibration(const DrsCalibrateTime &cal)
    3338    {
    34         *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);
    3548    }
    3649
    3750    bool SetDelays(const TH1 &cam);
     51    void SetDelays(const TGraph &g);
    3852
    39     double GetOffset(int hw, int spos, float tm) const
     53    double GetOffset(uint32_t hw, uint32_t spos, float tm) const
    4054    {
    41         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];
    4257    }
    4358
    44     double GetDelay(int sw) const
     59    double GetDelay(int hw) const
    4560    {
    46         return fDelays.size()==0 ? 0 : fDelays[sw];
     61        return fDelays.size()==0 ? 0 : fDelays[hw];
    4762    }
    4863
    49     ClassDef(MDrsCalibrationTime, 2) // A list of histograms storing the Fadc spektrum of one pixel
     64    bool ReadFits(TString fname);
     65    bool WriteFits(const std::string &fname) const;
     66
     67    ClassDef(MDrsCalibrationTime, 3) // A list of histograms storing the Fadc spektrum of one pixel
    5068};
    5169
  • branches/MarsGapdTimeJitter/mdrs/MHDrsCalibrationTime.cc

    r17760 r18282  
    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
  • branches/MarsGapdTimeJitter/mdrs/MHDrsCalibrationTime.h

    r14922 r18282  
    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.