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

Legend:

Unmodified
Added
Removed
  • 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.