Changeset 9318 for trunk/MagicSoft/Mars


Ignore:
Timestamp:
02/11/09 17:35:54 (16 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/Changelog

    r9317 r9318  
    129129     - corrected the emitted trigger positon
    130130     - (re)set calibration pattern
     131
     132   * mbase/MLut.[h,cc]:
     133     - added overload of Delete() function
     134     - added IsDefault
     135     - added SetDefault
     136
     137   * mfileio/MWriteRootFile.cc:
     138     - fixed output in OpenFile
     139
     140   * mjobs/MSequence.cc:
     141     - allow the "Night" resource to be empty
     142
     143   * msimcamera/MSimBundlePhotons.cc:
     144     - some small improvements in case of empty maps
     145
     146   * msimcamera/MSimReadout.[h,cc]:
     147     - reset gain. Use the new fConversionFactor instead
     148     - removed some setting of fRunHeader
     149
     150   * msimcamera/MSimTrigger.[h,cc]:
     151     - on useer request now offset and gain can be used to
     152       convert the signal back into units of phe
     153     - added possibility to use empty lookup tables
     154     - added debug output
     155
    131156
    132157
  • trunk/MagicSoft/Mars/mbase/MLut.cc

    r9257 r9318  
    5757}
    5858
     59void MLut::Delete(Option_t *option)
     60{
     61    TObjArray::Delete(option);
     62
     63    fMaxEntries = 0;
     64    fMinEntries = 0;
     65
     66    fMaxIndex = -1;
     67}
     68
     69// --------------------------------------------------------------------------
     70//
     71// Check if it is a default lut which would just map every entry to itself
     72// An empty Lut is a default lut
     73//
     74Bool_t MLut::IsDefault() const
     75{
     76    if (IsEmpty())
     77        return kTRUE;
     78
     79    if (!HasConstantLength() || fMaxEntries!=1)
     80        return kFALSE;
     81
     82    // Loop over all rows
     83    for (Int_t y=0; y<GetEntriesFast(); y++)
     84        if (GetRow(y)[0]!=y)
     85            return kFALSE;
     86
     87    return kTRUE;
     88}
     89
     90// --------------------------------------------------------------------------
     91//
     92// Setup a default lut which just maps n-entris to themself
     93//
     94void MLut::SetDefault(UInt_t n)
     95{
     96    Delete();
     97
     98    for (UInt_t y=0; y<n; y++)
     99    {
     100
     101        MArrayI &idx = *new MArrayI(1);
     102        idx[0] = y;
     103        Add(&idx);
     104    }
     105
     106    fMinEntries = 1;
     107    fMaxEntries = 1;
     108
     109    fMaxIndex = n;
     110}
     111
    59112// --------------------------------------------------------------------------
    60113//
     
    165218    MLut *lut = GetInverse(uniq);
    166219
    167     Delete();
     220    // Keep fMaxIndex
     221    TObjArray::Delete();
    168222
    169223    for (Int_t i=0; i<=fMaxIndex; i++)
     
    188242{
    189243    Delete();
    190 
    191     fMaxIndex   = -1;
    192     fMaxEntries =  0;
    193     fMinEntries =  0;
    194244
    195245    while (1)
  • trunk/MagicSoft/Mars/mbase/MLut.h

    r9255 r9318  
    1313{
    1414private:
    15     UInt_t fMinEntries;
    16     UInt_t fMaxEntries;
     15    UInt_t fMinEntries;   // The minimum entries per row
     16    UInt_t fMaxEntries;   // The maximum entries per row
    1717
    18     Int_t  fMaxIndex;
     18    Int_t  fMaxIndex;     // The maximum index fount in the lut
    1919
    2020    MLut *GetInverse(Bool_t uniq=kTRUE) const;
    2121
    2222public:
    23     MLut() : fMinEntries(0), fMaxEntries(0) { SetOwner(); }
     23    MLut() : fMinEntries(0), fMaxEntries(0), fMaxIndex(0) { SetOwner(); }
     24
     25    // TObjArry
     26    void Delete(Option_t *option="");
    2427
    2528    // MLut Getter
    2629    const MArrayI &GetRow(UInt_t i) const;
     30
     31     Int_t GetNumRows() const { return GetEntriesFast(); }
    2732
    2833    UInt_t GetMaxEntries() const { return fMaxEntries; }
     
    3136    Bool_t HasConstantLength() const { return fMinEntries==fMaxEntries; }
    3237    Bool_t IsEmpty() const { return fMaxEntries==0; }
     38    Bool_t IsDefault() const;
    3339
    34     // MLut convertions
     40    // MLut conversions
    3541    void SetInverse(const MLut &lut, Bool_t uniq=kTRUE);
    3642    void Invert(Bool_t uniq=kTRUE);
     43
     44    // Setter
     45    void SetDefault(UInt_t n);
    3746
    3847    // MLut I/O
  • trunk/MagicSoft/Mars/mfileio/MWriteRootFile.cc

    r9315 r9318  
    123123            if (TString(obj->GetName())=="/dev/null" && TString(obj->GetTitle())==title)
    124124            {
    125                 *fLog << inf3 << "Found file '/dev/null' <Title=" << title << ">" << endl;
     125                *fLog << inf2 << "Found open file '/dev/null' <Title=" << title << ">... re-using." << endl;
    126126                file = dynamic_cast<TFile*>(obj);
    127127                break;
     
    138138            gSystem->ExpandPathName(fqp);
    139139            file = dynamic_cast<TFile*>(gROOT->GetListOfFiles()->FindObject(fqp));
     140        }
     141
     142        if (file)
     143        {
     144            *fLog << inf2;
     145            *fLog << "Found open file '" << name << "'... re-using." << endl;
     146            *fLog << inf3;
     147            *fLog << "Make sure that you do NOT write to trees which are" << endl;
     148            *fLog << "scheduled already by a different MWriteRootFile..." << endl;
    140149        }
    141150    }
     
    162171    SetBit(kIsNotOwner);
    163172
    164     *fLog << inf;
    165     *fLog << "File '" << name << "' already open... using." << endl;
    166     *fLog << inf3;
    167     *fLog << "Make sure that you do NOT write to trees which are" << endl;
    168     *fLog << "scheduled already by a different MWriteRootFile..." << endl;
    169173    return fOut;
    170174}
  • trunk/MagicSoft/Mars/mjobs/MSequence.cc

    r9186 r9318  
    890890
    891891    str = GetEnvValue2(env, prefix, "Night", "");
    892     str += " 00:00:00";
    893     fNight.SetSqlDateTime(str);
     892    if (str.IsNull())
     893        fNight = MTime();
     894    else
     895    {
     896        str += " 00:00:00";
     897        fNight.SetSqlDateTime(str);
     898    }
    894899
    895900    fPeriod = fNight.GetMagicPeriod();
  • trunk/MagicSoft/Mars/msimcamera/MSimBundlePhotons.cc

    r9243 r9318  
    8989
    9090    // Read the look-up table
    91     if (fLut.ReadFile(fFileName)<0)
     91    fLut.Delete();
     92    if (!fFileName.IsNull() && fLut.ReadFile(fFileName)<0)
    9293        return kFALSE;
    9394
    9495    // If the table is empty remove this task from the tasklist
    9596    if (fLut.IsEmpty())
     97    {
     98        *fLog << inf << "Look-up table to bundle photons empty... skipping." << endl;
    9699        return kSKIP;
     100    }
    97101
    98102    // Now invert the tablee. Otherwise we have to do a lot of
     
    103107    if (!fLut.HasConstantLength() && fLut.GetMaxEntries()!=1)
    104108        return kFALSE;
     109
     110    *fLog << inf << "Using look-up table from " << fFileName << endl;
    105111
    106112    return kTRUE;
  • trunk/MagicSoft/Mars/msimcamera/MSimReadout.cc

    r9308 r9318  
    3131// system.
    3232//
     33// You can give a conversion factor from the unitx of your analog signal
     34// to the units of your adc. This is a fixed factor because it is just
     35// a matter of what the meaning of an adc count is, nothing which could
     36// jitter or is a real part of the electronics. Such effects should
     37// be simulated somewhere else.
     38//
    3339//
    3440//  Input Containers:
     
    7379//
    7480MSimReadout::MSimReadout(const char* name, const char *title)
    75 : fRunHeader(0), fEvtHeader(0), fCamera(0), fPulsePos(0), fTrigger(0), fData(0)
     81    : fRunHeader(0), fEvtHeader(0), fCamera(0), fPulsePos(0), fTrigger(0), fData(0),
     82    fConversionFactor(1)
    7683{
    7784    fName  = name  ? name  : "MSimReadout";
     
    135142
    136143    fRunHeader->InitPixels(cam->GetNumPixels());
    137     fRunHeader->SetValidMagicNumber();
    138     fRunHeader->SetSourceInfo("MonteCarlo");  // "Muon" from first event??
    139     fRunHeader->SetReadyToSave();
    140144
    141145    fData->InitRead(fRunHeader);
     
    209213    }
    210214
    211     const Float_t gain      = 64./1;
    212     const Float_t offset    = 128;
     215    const Float_t offset    = 0;//128;
    213216    const UInt_t  max       = fData->GetMax();
    214217
     
    230233        {
    231234            Float_t slice = j+trig>=(Int_t)sig.GetSize() ? offset :
    232                 sig[j+trig] * gain + offset;
     235                sig[j+trig] * fConversionFactor + offset;
    233236
    234237            // FIXME: Handle/Implement saturation!
     
    257260    return kTRUE;
    258261}
     262
     263// --------------------------------------------------------------------------
     264//
     265// Read the parameters from the resource file.
     266//
     267//  ConversionFactor: 1
     268//
     269Int_t MSimReadout::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
     270{
     271    Bool_t rc = kFALSE;
     272    if (IsEnvDefined(env, prefix, "ConversionFactor", print))
     273    {
     274        rc = kTRUE;
     275        fConversionFactor = GetEnvValue(env, prefix, "ConversionFactor", fConversionFactor);
     276    }
     277
     278    return rc;
     279}
  • trunk/MagicSoft/Mars/msimcamera/MSimReadout.h

    r9308 r9318  
    2424    MRawEvtData      *fData;       //! Digitized FADC signal
    2525
     26    Double_t fConversionFactor;    // Conversion factor (arbitrary) from analog signal to FADC counts
     27
    2628    // MTask
    2729    Int_t  PreProcess(MParList *pList);
    2830    Int_t  Process();
    2931    Bool_t ReInit(MParList *pList);
     32
     33    // MParContainer
     34    Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print=kFALSE);
    3035
    3136public:
  • trunk/MagicSoft/Mars/msimcamera/MSimTrigger.cc

    r9308 r9318  
    8282#include "MTriggerPattern.h"
    8383
     84#include "MPedestalCam.h"
     85#include "MPedestalPix.h"
     86
    8487ClassImp(MSimTrigger);
    8588
     
    9194//
    9295MSimTrigger::MSimTrigger(const char *name, const char *title)
    93     : fCamera(0), fPulsePos(0), fTrigger(0), fRunHeader(0), fEvtHeader(0),
    94     fDiscriminatorThreshold(-1), fDigitalSignalLength(8), fCoincidenceTime(0.5)
     96    : fCamera(0), fPulsePos(0), fTrigger(0), fRunHeader(0),
     97    fEvtHeader(0), fElectronicNoise(0), fGain(0),
     98    fDiscriminatorThreshold(-1), fDigitalSignalLength(8), fCoincidenceTime(0.5),
     99    fShiftBaseline(kTRUE), fUngainSignal(kTRUE)
    95100{
    96101    fName  = name  ? name  : "MSimTrigger";
     
    166171    }
    167172
     173    fElectronicNoise = 0;
     174    if (fShiftBaseline)
     175    {
     176        fElectronicNoise = (MPedestalCam*)pList->FindObject("ElectronicNoise", "MPedestalCam");
     177        if (!fElectronicNoise)
     178        {
     179            *fLog << err << "ElectronicNoise [MPedestalCam] not found... aborting." << endl;
     180            return kFALSE;
     181        }
     182        *fLog << inf << "Baseline will be shifted back to 0 for discriminator." << endl;
     183    }
     184
     185    fGain = 0;
     186    if (fUngainSignal)
     187    {
     188        fGain = (MPedestalCam*)pList->FindObject("Gain", "MPedestalCam");
     189        if (!fGain)
     190        {
     191            *fLog << err << "Gain [MPedestalCam] not found... aborting." << endl;
     192            return kFALSE;
     193        }
     194        *fLog << inf << "Discriminator will be multiplied by applied gain." << endl;
     195    }
     196
    168197    fRunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
    169198    if (!fRunHeader)
     
    177206        return kFALSE;
    178207
    179 
    180     if (fRouteAC.ReadFile(fNameRouteAC)<0)
    181         return kFALSE;
    182 
    183     if (fCoincidenceMap.ReadFile(fNameCoincidenceMap)<0)
    184         return kFALSE;
     208    fRouteAC.Delete();
     209    if (!fNameRouteAC.IsNull() && fRouteAC.ReadFile(fNameRouteAC)<0)
     210        return kFALSE;
     211
     212    fCoincidenceMap.Delete();
     213    if (!fNameCoincidenceMap.IsNull() && fCoincidenceMap.ReadFile(fNameCoincidenceMap)<0)
     214        return kFALSE;
     215
     216    // ---------------- Consistency checks ----------------------
     217
     218    if (!fRouteAC.IsEmpty() && !fCoincidenceMap.IsEmpty() &&
     219        fCoincidenceMap.GetMaxIndex()>fRouteAC.GetNumRows()-1)
     220    {
     221        *fLog << err;
     222        *fLog << "ERROR - AC routing produces " << fRouteAC.GetNumRows() << " analog channels," << endl;
     223        *fLog << "        but the coincidence map expects at least " << fCoincidenceMap.GetMaxIndex()+1 << " channels." << endl;
     224        return kERROR;
     225    }
    185226
    186227    if (fDiscriminatorThreshold<=0)
     
    190231    }
    191232
    192     *fLog << inf << "Using discriminator threshold of " << fDiscriminatorThreshold << endl;
     233    if (fElectronicNoise && !fRouteAC.IsEmpty() && !fRouteAC.IsDefault())
     234    {
     235        // FIXME: Apply to analog channels when summing
     236        *fLog << warn << "WARNING - A baseline shift doesn't make sense for sum-channels... reset." << endl;
     237        fElectronicNoise = 0;
     238    }
     239
     240    if (fGain && !fRouteAC.IsEmpty() && !fRouteAC.IsDefault())
     241    {
     242        // FIXME: Apply to analog channels when summing
     243        *fLog << warn << "WARNING - Ungain doesn't make sense for sum-channels... reset." << endl;
     244        fGain = 0;
     245    }
     246
     247
     248    // ---------------- Information output ----------------------
     249
     250    *fLog << inf;
     251
     252    if (fRouteAC.IsEmpty())
     253        *fLog << "Re-routing/summing of analog channels before discriminator switched off." << endl;
     254    else
     255        *fLog << "Using " << fNameRouteAC << " for re-routing/summing of analog channels before discriminator." << endl;
     256
     257    if (fCoincidenceMap.IsEmpty())
     258        *fLog << "No coincidences of digital channels will be checked. Signal-above-threshold trigger applied." << endl;
     259    else
     260        *fLog << "Using " << fNameCoincidenceMap << " to check for coincidences of the digital channels." << endl;
     261
     262    *fLog << "Using discriminator threshold of " << fDiscriminatorThreshold << endl;
    193263
    194264    return kTRUE;
     
    204274    // ================== Simulate channel bundling ====================
    205275
    206     const UInt_t npatch = fRouteAC.GetEntriesFast();
    207 
    208     MAnalogChannels patches(npatch, fCamera->GetNumSamples());
    209 
    210     for (UInt_t i=0; i<npatch; i++)
    211     {
    212         const MArrayI &row = fRouteAC.GetRow(i);
    213         for (UInt_t j=0; j<row.GetSize(); j++)
    214         {
    215             // FIXME: Simulate clipping
    216             const UInt_t idx = row[j];
    217             patches[i].AddSignal((*fCamera)[idx]);
     276    // FIXME: Before we can bundle the channels we have to make a copy
     277    //        and simulate clipping
     278
     279    // Check if routing should be done
     280    const Bool_t empty = fRouteAC.IsEmpty();
     281
     282    // If no channels are summed the number of patches stays the same
     283    const UInt_t npatch = empty ? fCamera->GetNumChannels() : fRouteAC.GetEntriesFast();
     284
     285    // Use the given analog channels as default out. If channels are
     286    // summed overwrite with a newly allocated set of analog channels
     287    MAnalogChannels *patches = fCamera;
     288    if (!empty)
     289    {
     290        // FIXME: Can we add gain and offset here into a new container?
     291
     292        patches = new MAnalogChannels(npatch, fCamera->GetNumSamples());
     293        for (UInt_t i=0; i<npatch; i++)
     294        {
     295            const MArrayI &row = fRouteAC.GetRow(i);
     296            for (UInt_t j=0; j<row.GetSize(); j++)
     297            {
     298                const UInt_t idx = row[j];
     299                (*patches)[i].AddSignal((*fCamera)[idx]);
     300            }
    218301        }
    219302    }
     
    227310
    228311    for (UInt_t i=0; i<npatch; i++)
    229         ttls.AddAt(patches[i].Discriminate(fDiscriminatorThreshold, fDigitalSignalLength), i);
     312    {
     313        // FIXME: What if the gain was also allpied to the baseline?
     314        const Double_t offset = fElectronicNoise ? (*fElectronicNoise)[i].GetPedestal() : 0;
     315        const Double_t gain   = fGain            ? (*fGain)[i].GetPedestal()            : 1;
     316        ttls.AddAt((*patches)[i].Discriminate(fDiscriminatorThreshold*gain+offset, fDigitalSignalLength), i);
     317    }
    230318
    231319    // FIXME: Write TTLs!
    232320
     321    // If analog channels had been newly allocated free memmory
     322    if (patches!=fCamera)
     323        delete patches;
     324
    233325    // =================== Simulate coincidences ======================
     326
     327    // If the map is empty we create a one-pixel-coincidence map
     328    // FIMXE: This could maybe be accelerated if the Clone can be
     329    //        omitted in the loop
     330    if (fCoincidenceMap.IsEmpty())
     331        fCoincidenceMap.SetDefault(npatch);
    234332
    235333    // Calculate the minimum and maximum time for a valid trigger
  • trunk/MagicSoft/Mars/msimcamera/MSimTrigger.h

    r9308 r9318  
    1515class MRawEvtHeader;
    1616class MRawRunHeader;
     17class MPedestalCam;
    1718
    1819class MSimTrigger : public MTask
    1920{
    2021private:
    21     MAnalogChannels *fCamera;         //! The analog input channels
    22     MParameterD     *fPulsePos;       //! The intended pulse positon
    23     MParameterD     *fTrigger;        //! The trigger position w.r.t. the analog channels
    24     MRawRunHeader   *fRunHeader;      //! The run header storing infos about the digitization
    25     MRawEvtHeader   *fEvtHeader;      //! The event header storing the trigger information
     22    MAnalogChannels *fCamera;           //! The analog input channels
     23    MParameterD     *fPulsePos;         //! The intended pulse positon
     24    MParameterD     *fTrigger;          //! The trigger position w.r.t. the analog channels
     25    MRawRunHeader   *fRunHeader;        //! The run header storing infos about the digitization
     26    MRawEvtHeader   *fEvtHeader;        //! The event header storing the trigger information
     27    MPedestalCam    *fElectronicNoise;  //! Electronic noise (for baseline correction)
     28    MPedestalCam    *fGain;             //! Gain of the pulses
    2629
    27     MLut fRouteAC;                    // Combinination map for the AC channels
    28     MLut fCoincidenceMap;             // channels for which digital coincidence is checked
     30    MLut fRouteAC;                      // Combinination map for the AC channels
     31    MLut fCoincidenceMap;               // channels for which digital coincidence is checked
    2932
    30     TString fNameRouteAC;             // Name for the AC routing
    31     TString fNameCoincidenceMap;      // Name for the coincidence mape
     33    TString fNameRouteAC;               // Name for the AC routing
     34    TString fNameCoincidenceMap;        // Name for the coincidence mape
    3235
    33     Float_t fDiscriminatorThreshold;  // Discriminator threshold
    34     Float_t fDigitalSignalLength;     // Length of the output of the discriminator
    35     Float_t fCoincidenceTime;         // Minimum coincidence time (gate)
     36    Float_t fDiscriminatorThreshold;    // Discriminator threshold
     37    Float_t fDigitalSignalLength;       // Length of the output of the discriminator
     38    Float_t fCoincidenceTime;           // Minimum coincidence time (gate)
     39
     40    Bool_t  fShiftBaseline;             // Shift the baseline back to 0 for the threshold (needs ElectronicNoise [MPedestalCam])
     41    Bool_t  fUngainSignal;              // "Remove" the gain from the signal (needs Gain [MPedestalCam])
    3642
    3743    // MSimTrigger
Note: See TracChangeset for help on using the changeset viewer.