Changeset 5298


Ignore:
Timestamp:
10/20/04 16:21:23 (20 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/Changelog

    r5296 r5298  
    2020                                                 -*-*- END OF LINE -*-*-
    2121
    22  2004/10/20: Markus Gaug
     22 2004/10/20: Thomas Bretz
    2323
    2424   * msignal/MExtractTimeFastSpline.cc:
    2525     - fixed a compiler warning: Unused variable
     26
     27   * mjob/MJPedestal.cc:
     28     - added "DisableOutput" as a resource option
     29
     30   * mbase/MArrayF.h:
     31     - added a new Reset(Float_t) member function
     32
     33   * msignal/MExtractTimeAndChargeDigitalFilter.[h,cc]:
     34     - enrolled some if-else blocks
     35     - fixed includes
     36     - enhanced error handling when a file is read
     37     - moved output from PostProcess to PreProcess
     38     - fixed and enhanced ReadEnv
     39
     40   * mjob/MJCalibrateSignal.cc:
     41     - enabled variance display for tabs showing signal
     42
     43   * mhist/MHCamera.cc:
     44     - fixed returning GetBinError for kProfile mode switched on
    2645
    2746
     
    130149 2004/10/08: R. DelosReyes
    131150
    132   * mbase/MrunIter.h
     151  * mbase/MRunIter.h
    133152    - changed the name of the Sort() function name by SortRuns()
    134153      to avoid conflicts with the Sort() function in the MDirIter class.
  • trunk/MagicSoft/Mars/mbase/MArrayF.h

    r5088 r5298  
    9696    }
    9797
     98    void Reset(Float_t f)
     99    {
     100        for (UInt_t i=0; i<fN; i++)
     101            fArray[i] = f;
     102    }
     103
    98104    void Set(UInt_t n)
    99105    {
  • trunk/MagicSoft/Mars/mhist/MHCamera.cc

    r5156 r5298  
    11621162    }
    11631163    else
    1164       {
     1164    {
    11651165        rc = TH1D::GetBinError(bin);
    1166         rc = Profile(rc);
    1167       }
    1168 
    1169     return rc;
     1166    }
     1167
     1168    return Profile(rc);
    11701169}
    11711170
  • trunk/MagicSoft/Mars/mjobs/MJCalibrateSignal.cc

    r5167 r5298  
    332332    MHCamEvent evt6(0, "Times",       "Arrival Time;;T [slice]");
    333333    evt0.EnableVariance();
     334    evt1.EnableVariance();
    334335    evt2.EnableVariance();
    335336    evt3.EnableVariance();
     337    evt4.EnableVariance();
    336338    evt6.EnableVariance();
    337339
  • trunk/MagicSoft/Mars/mjobs/MJPedestal.cc

    r5234 r5298  
    1717!
    1818!   Author(s): Thomas Bretz, 1/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
    19 !              Markus Gaug ,04/2004 <mailto:markus@ifae.es>
     19!   Author(s): Markus Gaug, 4/2004 <mailto:markus@ifae.es>
    2020!
    2121!   Copyright: MAGIC Software Development, 2000-2004
     
    8484const Float_t  MJPedestal::fgRefPedRmsExtraGalacticOuter = 3.35;
    8585const Float_t  MJPedestal::fgRefPedRmsGalacticOuter      = 4.2;
     86
    8687// --------------------------------------------------------------------------
    8788//
     
    99100      fDataCheck(kFALSE), fUseData(kFALSE)
    100101{
    101 
    102   fName  = name  ? name  : "MJPedestal";
    103   fTitle = title ? title : "Tool to create a pedestal file (MPedestalCam)";
    104  
    105   SetNormalStorage();
    106 
     102    fName  = name  ? name  : "MJPedestal";
     103    fTitle = title ? title : "Tool to create a pedestal file (MPedestalCam)";
     104
     105    SetNormalStorage();
    107106}
    108107
     
    128127Bool_t MJPedestal::ReadPedestalCam()
    129128{
    130 
    131   if (IsNoStorage())
    132     return kFALSE;
    133  
    134   const TString fname = GetOutputFile();
    135  
    136   if (gSystem->AccessPathName(fname, kFileExists))
    137     {
    138       *fLog << warn << "Input file " << fname << " doesn't exist, will create it." << endl;
    139       return kFALSE;
    140     }
    141  
    142   *fLog << inf << "Reading from file: " << fname << endl;
    143  
    144   TFile file(fname, "READ");
    145   if (fPedestalCam.Read()<=0)
    146     {
    147       *fLog << err << "Unable to read MPedestalCam from " << fname << endl;
    148       return kFALSE;
    149     }
    150  
    151   if (file.FindKey("MBadPixelsCam"))
    152     {
    153       MBadPixelsCam bad;
     129    if (IsNoStorage())
     130        return kFALSE;
     131
     132    const TString fname = GetOutputFile();
     133
     134    if (gSystem->AccessPathName(fname, kFileExists))
     135    {
     136        *fLog << warn << "Input file " << fname << " doesn't exist, will create it." << endl;
     137        return kFALSE;
     138    }
     139
     140    *fLog << inf << "Reading from file: " << fname << endl;
     141
     142    TFile file(fname, "READ");
     143    if (fPedestalCam.Read()<=0)
     144    {
     145        *fLog << err << "Unable to read MPedestalCam from " << fname << endl;
     146        return kFALSE;
     147    }
     148
     149    if (file.FindKey("MBadPixelsCam"))
     150    {
     151        MBadPixelsCam bad;
    154152        if (bad.Read()<=0)
    155           {
     153        {
    156154            *fLog << err << "Unable to read MBadPixelsCam from " << fname << endl;
    157155            return kFALSE;
    158           }
     156        }
    159157        fBadPixels.Merge(bad);
    160158    }
    161159
    162   if (fDisplay && !fDisplay->GetCanvas("Pedestals"))
    163     fDisplay->Read();
    164  
    165   return kTRUE;
     160    if (fDisplay && !fDisplay->GetCanvas("Pedestals"))
     161        fDisplay->Read();
     162
     163    return kTRUE;
    166164}
    167165
     
    371369void  MJPedestal::DisplayReferenceLines(MHCamera *cam, const Int_t what) const
    372370{
    373 
    374371  Double_t x = cam->GetNbinsX();
    375372 
     
    441438void MJPedestal::FixDataCheckHist(TH1D *hist) const
    442439{
    443 
    444440    hist->SetDirectory(NULL);
    445441    hist->SetStats(0);
     
    459455    xaxe->SetLabelSize(0.05);
    460456    yaxe->SetLabelSize(0.05);   
    461 
    462 }
     457}
     458
    463459/*
    464460Bool_t MJPedestal::WriteEventloop(MEvtLoop &evtloop) const
     
    494490//   Prefix.DataCheck:        Yes, No
    495491//   Prefix.UseData:          Yes, No
     492//   Prefix.DisableOutput:    Yes, No
    496493//
    497494Bool_t MJPedestal::CheckEnvLocal()
     
    502499    SetDataCheck(GetEnv("DataCheck", fDataCheck));
    503500    SetUseData(GetEnv("UseData", fUseData));
     501    SetNoStorage(GetEnv("DisableOutput", IsNoStorage()));
    504502
    505503    return kTRUE;
     
    516514Bool_t MJPedestal::WriteResult()
    517515{
    518  
    519   if (IsNoStorage())
     516    if (IsNoStorage())
     517        return kTRUE;
     518
     519    if (fPathOut.IsNull())
     520        return kTRUE;
     521
     522    const TString oname(GetOutputFile());
     523
     524    *fLog << inf << "Writing to file: " << oname << endl;
     525
     526    TFile file(oname, "UPDATE", "File created by MJPedestal", 9);
     527    if (!file.IsOpen())
     528    {
     529        *fLog << err << "ERROR - Couldn't open file " << oname << " for writing..." << endl;
     530        return kFALSE;
     531    }
     532
     533    if (fDisplay && fDisplay->Write()<=0)
     534    {
     535        *fLog << err << "Unable to write MStatusDisplay to " << oname << endl;
     536        return kFALSE;
     537    }
     538
     539    if (fPedestalCam.Write()<=0)
     540    {
     541        *fLog << err << "Unable to write MPedestalCam to " << oname << endl;
     542        return kFALSE;
     543    }
     544
     545    if (fBadPixels.Write()<=0)
     546    {
     547        *fLog << err << "Unable to write MBadPixelsCam to " << oname << endl;
     548        return kFALSE;
     549    }
     550
    520551    return kTRUE;
    521 
    522   if (fPathOut.IsNull())
    523     return kTRUE;
    524  
    525   const TString oname(GetOutputFile());
    526  
    527   *fLog << inf << "Writing to file: " << oname << endl;
    528 
    529   TFile file(oname, "UPDATE", "File created by MJPedestal", 9);
    530   if (!file.IsOpen())
    531     {
    532       *fLog << err << "ERROR - Couldn't open file " << oname << " for writing..." << endl;
    533       return kFALSE;
    534     }
    535  
    536   if (fDisplay && fDisplay->Write()<=0)
    537     {
    538       *fLog << err << "Unable to write MStatusDisplay to " << oname << endl;
    539       return kFALSE;
    540     }
    541 
    542   if (fPedestalCam.Write()<=0)
    543     {
    544       *fLog << err << "Unable to write MPedestalCam to " << oname << endl;
    545       return kFALSE;
    546     }
    547 
    548   if (fBadPixels.Write()<=0)
    549     {
    550       *fLog << err << "Unable to write MBadPixelsCam to " << oname << endl;
    551       return kFALSE;
    552     }
    553 
    554   return kTRUE;
    555552}
    556553
  • trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeDigitalFilter.cc

    r5203 r5298  
    5151#include "MExtractTimeAndChargeDigitalFilter.h"
    5252
     53#include <errno.h>
     54#include <fstream>
     55
     56#include <TFile.h>
     57#include <TH1F.h>
     58#include <TH2F.h>
     59#include <TString.h>
     60#include <TMatrix.h>
     61
    5362#include "MLog.h"
    5463#include "MLogManip.h"
    5564
    5665#include "MPedestalPix.h"
    57 
    58 #include "TFile.h"
    59 #include "TH1F.h"
    60 #include "TH2F.h"
    61 #include "TString.h"
    62 #include "TMatrix.h"
    63 
    64 #include <fstream>
    6566
    6667ClassImp(MExtractTimeAndChargeDigitalFilter);
     
    7879const Int_t  MExtractTimeAndChargeDigitalFilter::fgSignalStartBinHiGain = 4;
    7980const Int_t  MExtractTimeAndChargeDigitalFilter::fgSignalStartBinLoGain = 4;
     81
    8082// --------------------------------------------------------------------------
    8183//
     
    9193MExtractTimeAndChargeDigitalFilter::MExtractTimeAndChargeDigitalFilter(const char *name, const char *title)
    9294{
    93 
    94   fName  = name  ? name  : "MExtractTimeAndChargeDigitalFilter";
    95   fTitle = title ? title : "Digital Filter";
    96 
    97   SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast);
    98   SetWindowSize();
    99   SetBinningResolution();
    100   SetSignalStartBin();
    101 
    102   ReadWeightsFile("");
     95    fName  = name  ? name  : "MExtractTimeAndChargeDigitalFilter";
     96    fTitle = title ? title : "Digital Filter";
     97
     98    SetRange(fgHiGainFirst, fgHiGainLast, fgLoGainFirst, fgLoGainLast);
     99    SetWindowSize();
     100    SetBinningResolution();
     101    SetSignalStartBin();
     102
     103    ReadWeightsFile("");
    103104}
    104 
    105105
    106106// ---------------------------------------------------------------------------------------
     
    129129
    130130  if (fWindowSizeHiGain > availhirange)
    131     {
     131  {
     132      // Please simplify this!
    132133      *fLog << warn << GetDescriptor()
    133134            << Form("%s%2i%s%2i%s%2i%s",": Hi Gain window size: ",fWindowSizeHiGain,
     
    150151      if (fWindowSizeLoGain > availlorange)
    151152        {
     153      // Please simplify this!
    152154          *fLog << warn << GetDescriptor()
    153155                << Form("%s%2i%s%2i%s%2i%s",": Lo Gain window size: ",fWindowSizeLoGain,
     
    182184Bool_t MExtractTimeAndChargeDigitalFilter::ReInit(MParList *pList)
    183185{
    184 
    185   if (!MExtractTimeAndCharge::ReInit(pList))
    186     return kFALSE;
    187 
    188   Int_t range = fHiGainLast - fHiGainFirst + 1 + fHiLoLast;
    189 
    190   fHiGainSignal.Set(range);
    191 
    192   range = fLoGainLast - fLoGainFirst + 1;
    193 
    194   fLoGainSignal.Set(range);
    195 
    196   fTimeShiftHiGain = (Float_t)fHiGainFirst + 0.5 + 1./fBinningResolutionHiGain;
    197   fTimeShiftLoGain = (Float_t)fLoGainFirst + 0.5 + 1./fBinningResolutionLoGain;
    198 
    199   return kTRUE;
     186    if (!MExtractTimeAndCharge::ReInit(pList))
     187        return kFALSE;
     188
     189    fHiGainSignal.Set(fHiGainLast - fHiGainFirst + 1 + fHiLoLast);
     190    fLoGainSignal.Set(fLoGainLast - fLoGainFirst + 1);
     191
     192    fTimeShiftHiGain = (Float_t)fHiGainFirst + 0.5 + 1./fBinningResolutionHiGain;
     193    fTimeShiftLoGain = (Float_t)fLoGainFirst + 0.5 + 1./fBinningResolutionLoGain;
     194
     195    return kTRUE;
    200196}
    201197
     198Int_t MExtractTimeAndChargeDigitalFilter::PreProcess(MParList *pList)
     199{
     200    *fLog << endl;
     201    *fLog << inf << "Using the following weights: " << endl;
     202    *fLog << "Hi-Gain:" << endl;
     203
     204    for (Int_t i=0; i<fBinningResolutionHiGain*fWindowSizeHiGain; i++)
     205        *fLog << " " << fAmpWeightsHiGain[i] << " \t " << fTimeWeightsHiGain[i] << endl;
     206
     207    *fLog << "Lo-Gain:" << endl;
     208
     209    for (Int_t i=0; i<fBinningResolutionLoGain*fWindowSizeLoGain; i++)
     210        *fLog << " " << fAmpWeightsLoGain[i] << " \t " << fTimeWeightsLoGain[i] << endl;
     211
     212    return MExtractTimeAndCharge::PreProcess(pList);
     213}
    202214
    203215void MExtractTimeAndChargeDigitalFilter::FindTimeAndChargeHiGain(Byte_t *ptr, Byte_t *logain, Float_t &sum, Float_t &dsum,
     
    267279  const Float_t ABoffs = ped.GetPedestalABoffset();
    268280       
    269   Float_t PedMean[2];
    270   PedMean[0] = pedes + ABoffs;
    271   PedMean[1] = pedes - ABoffs;
     281  Float_t pedmean[2];
     282  pedmean[0] = pedes + ABoffs;
     283  pedmean[1] = pedes - ABoffs;
    272284
    273285  //
     
    286298      {
    287299        const Int_t   idx = fBinningResolutionHiGain*sample+fBinningResolutionHalfHiGain;
    288         const Float_t pex = fHiGainSignal[sample+i]-PedMean[(sample+i+abflag) & 0x1];
     300        const Float_t pex = fHiGainSignal[sample+i]-pedmean[(sample+i+abflag) & 0x1];
    289301        sum              += fAmpWeightsHiGain [idx]*pex;
    290302        time_sum         += fTimeWeightsHiGain[idx]*pex;
     
    298310      }
    299311    } /*   for (Int_t i=0;i<range-fWindowSizeHiGain;i++) */
    300  
    301   if (fmax!=0)
    302     {
    303       ftime_max        /= fmax;
    304       Int_t t_iter      = Int_t(ftime_max*fBinningResolutionHiGain);
    305       Int_t sample_iter = 0;
    306 
    307       while ( t_iter > fBinningResolutionHalfHiGain-1 || t_iter < -fBinningResolutionHalfHiGain )
    308         {
    309           if (t_iter > fBinningResolutionHalfHiGain-1)
    310             {
    311               t_iter -= fBinningResolutionHiGain;
    312               max_p--;
    313               sample_iter--;
    314             }
    315           if (t_iter < -fBinningResolutionHalfHiGain)
    316             {
    317               t_iter += fBinningResolutionHiGain;
    318               max_p++;
    319               sample_iter++;
    320             }
    321         }
    322      
    323       sum = 0.;
    324       //
    325       // Slide with a window of size fWindowSizeHiGain over the sample
    326       // and multiply the entries with the corresponding weights
    327       //
    328       for (Int_t sample=0; sample < fWindowSizeHiGain; sample++)
    329       {
    330         const Int_t   idx = fBinningResolutionHiGain*sample + fBinningResolutionHalfHiGain + t_iter;
    331         const Int_t   ids = max_p + sample;
    332         const Float_t pex = ids < 0 ? 0. :
    333           ( ids > range ? 0. : fHiGainSignal[ids]-PedMean[(ids+abflag) & 0x1]);
    334         sum              += fAmpWeightsHiGain [idx]*pex;
    335         time_sum         += fTimeWeightsHiGain[idx]*pex;
    336       }
    337 
    338       if (sum != 0.)
    339         time = max_p + fTimeShiftHiGain /* this shifts the time to the start of the rising edge */
    340              - ((Float_t)t_iter)/fBinningResolutionHiGain - time_sum/sum;
    341       else
    342         time = 0.;
    343     } /* if (max!=0) */
    344     else
    345       time=0.;
    346    
    347   return;
     312
     313  time = 0;
     314  if (fmax==0)
     315      return;
     316
     317  ftime_max        /= fmax;
     318  Int_t t_iter      = Int_t(ftime_max*fBinningResolutionHiGain);
     319  Int_t sample_iter = 0;
     320
     321  while ( t_iter > fBinningResolutionHalfHiGain-1 || t_iter < -fBinningResolutionHalfHiGain )
     322    {
     323      if (t_iter > fBinningResolutionHalfHiGain-1)
     324        {
     325          t_iter -= fBinningResolutionHiGain;
     326          max_p--;
     327          sample_iter--;
     328        }
     329      if (t_iter < -fBinningResolutionHalfHiGain)
     330        {
     331          t_iter += fBinningResolutionHiGain;
     332          max_p++;
     333          sample_iter++;
     334        }
     335    }
     336 
     337  sum = 0.;
     338  //
     339  // Slide with a window of size fWindowSizeHiGain over the sample
     340  // and multiply the entries with the corresponding weights
     341  //
     342  for (Int_t sample=0; sample < fWindowSizeHiGain; sample++)
     343  {
     344    const Int_t   idx = fBinningResolutionHiGain*sample + fBinningResolutionHalfHiGain + t_iter;
     345    const Int_t   ids = max_p + sample;
     346    const Float_t pex = ids < 0 ? 0. :
     347      ( ids > range ? 0. : fHiGainSignal[ids]-pedmean[(ids+abflag) & 0x1]);
     348    sum              += fAmpWeightsHiGain [idx]*pex;
     349    time_sum         += fTimeWeightsHiGain[idx]*pex;
     350  }
     351
     352  if (sum == 0)
     353      return;
     354
     355  time = max_p + fTimeShiftHiGain /* this shifts the time to the start of the rising edge */
     356      - ((Float_t)t_iter)/fBinningResolutionHiGain - time_sum/sum;
    348357}
    349358
     
    386395  const Float_t ABoffs = ped.GetPedestalABoffset();
    387396       
    388   Float_t PedMean[2];
    389   PedMean[0] = pedes + ABoffs;
    390   PedMean[1] = pedes - ABoffs;
     397  Float_t pedmean[2];
     398  pedmean[0] = pedes + ABoffs;
     399  pedmean[1] = pedes - ABoffs;
    391400
    392401  //
     
    405414      {
    406415        const Int_t   idx = fBinningResolutionLoGain*sample+fBinningResolutionHalfLoGain;
    407         const Float_t pex = fLoGainSignal[sample+i]-PedMean[(sample+i+abflag) & 0x1];
     416        const Float_t pex = fLoGainSignal[sample+i]-pedmean[(sample+i+abflag) & 0x1];
    408417        sum              += fAmpWeightsLoGain [idx]*pex;
    409418        time_sum         += fTimeWeightsLoGain[idx]*pex;
     
    417426      }
    418427    } /*   for (Int_t i=0;i<range-fWindowSizeLoGain;i++) */
    419  
    420   if (fmax!=0)
    421     {
    422       ftime_max        /= fmax;
    423       Int_t t_iter      = Int_t(ftime_max*fBinningResolutionLoGain);
    424       Int_t sample_iter = 0;
    425 
    426       while ( t_iter > fBinningResolutionHalfLoGain-1 || t_iter < -fBinningResolutionHalfLoGain )
    427         {
    428           if (t_iter > fBinningResolutionHalfLoGain-1)
    429             {
    430               t_iter -= fBinningResolutionLoGain;
    431               max_p--;
    432               sample_iter--;
    433             }
    434           if (t_iter < -fBinningResolutionHalfLoGain)
    435             {
    436               t_iter += fBinningResolutionLoGain;
    437               max_p++;
    438               sample_iter++;
    439             }
    440         }
    441      
    442       sum = 0.;
    443       //
    444       // Slide with a window of size fWindowSizeLoGain over the sample
    445       // and multiply the entries with the corresponding weights
    446       //
    447       for (Int_t sample=0; sample < fWindowSizeLoGain; sample++)
    448       {
    449         const Int_t   idx = fBinningResolutionLoGain*sample + fBinningResolutionHalfLoGain + t_iter;
    450         const Int_t   ids = max_p + sample;
    451         const Float_t pex = ids < 0 ? 0. :
    452           ( ids > range ? 0. : fLoGainSignal[ids]-PedMean[(ids+abflag) & 0x1]);
    453         sum              += fAmpWeightsLoGain [idx]*pex;
    454         time_sum         += fTimeWeightsLoGain[idx]*pex;
    455       }
    456 
    457       if (sum != 0.)
    458         time = max_p + fTimeShiftLoGain /* this shifts the time to the start of the rising edge */
    459              - ((Float_t)t_iter)/fBinningResolutionLoGain - time_sum/sum;
    460       else
    461         time = 0.;
    462     } /* if (max!=0) */
    463     else
    464       time=0.;
    465    
    466   return;
     428
     429  time = 0;
     430  if (fmax==0)
     431      return;
     432
     433  ftime_max        /= fmax;
     434  Int_t t_iter      = Int_t(ftime_max*fBinningResolutionLoGain);
     435  Int_t sample_iter = 0;
     436
     437  while ( t_iter > fBinningResolutionHalfLoGain-1 || t_iter < -fBinningResolutionHalfLoGain )
     438    {
     439      if (t_iter > fBinningResolutionHalfLoGain-1)
     440        {
     441          t_iter -= fBinningResolutionLoGain;
     442          max_p--;
     443          sample_iter--;
     444        }
     445      if (t_iter < -fBinningResolutionHalfLoGain)
     446        {
     447          t_iter += fBinningResolutionLoGain;
     448          max_p++;
     449          sample_iter++;
     450        }
     451    }
     452 
     453  sum = 0.;
     454
     455  //
     456  // Slide with a window of size fWindowSizeLoGain over the sample
     457  // and multiply the entries with the corresponding weights
     458  //
     459  for (Int_t sample=0; sample < fWindowSizeLoGain; sample++)
     460  {
     461    const Int_t   idx = fBinningResolutionLoGain*sample + fBinningResolutionHalfLoGain + t_iter;
     462    const Int_t   ids = max_p + sample;
     463    const Float_t pex = ids < 0 ? 0. :
     464      ( ids > range ? 0. : fLoGainSignal[ids]-pedmean[(ids+abflag) & 0x1]);
     465    sum              += fAmpWeightsLoGain [idx]*pex;
     466    time_sum         += fTimeWeightsLoGain[idx]*pex;
     467  }
     468
     469  if (sum == 0)
     470      return;
     471
     472  time = max_p + fTimeShiftLoGain /* this shifts the time to the start of the rising edge */
     473      - ((Float_t)t_iter)/fBinningResolutionLoGain - time_sum/sum;
    467474}
    468475
     476// --------------------------------------------------------------------------
     477//
     478// Read the setup from a TEnv, eg:
     479//   MJPedestal.MExtractor.WindowSizeHiGain: 6
     480//   MJPedestal.MExtractor.WindowSizeLoGain: 6
     481//   MJPedestal.MExtractor.BinningResolutionHiGain: 10
     482//   MJPedestal.MExtractor.BinningResolutionLoGain: 10
     483//   MJPedestal.MExtractor.WeightsFile: filename
     484//
    469485Int_t MExtractTimeAndChargeDigitalFilter::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
    470486{
    471  
    472   Byte_t hw = fWindowSizeHiGain;
    473   Byte_t lw = fWindowSizeLoGain;
    474   Bool_t rc = kFALSE;
    475  
    476   if (IsEnvDefined(env, prefix, "WindowSizeHiGain", print))
    477     {
    478       hw = GetEnvValue(env, prefix, "WindowSizeHiGain", hw);
    479       rc = kTRUE;
    480     }
    481   if (IsEnvDefined(env, prefix, "WindowSizeLoGain", print))
    482     {
    483       lw = GetEnvValue(env, prefix, "WindowSizeLoGain", lw);
    484       rc = kTRUE;
    485     }
    486  
    487   if (rc)
    488     SetWindowSize(hw, lw);
    489    
    490   if (IsEnvDefined(env, prefix, "BinningResolution", print))
    491     {
    492       SetBinningResolution(GetEnvValue(env, prefix, "BinningResolutionHiGain", fBinningResolutionHiGain),
    493                            GetEnvValue(env, prefix, "BinningResolutionLoGain", fBinningResolutionLoGain));
    494       rc = kTRUE;
    495     }
    496  
    497   rc = MExtractor::ReadEnv(env, prefix, print) ? kTRUE : rc;
    498  
    499   return rc;
    500 }
    501 
    502 Int_t  MExtractTimeAndChargeDigitalFilter::PostProcess()
    503 {
    504  
    505   *fLog << endl;
    506   *fLog << inf << "Used High Gain weights in the extractor: " << endl;
    507  
    508   for (Int_t i=0;i<fBinningResolutionHiGain*fWindowSizeHiGain; i++)
    509     *fLog << inf << fAmpWeightsHiGain[i] << "   " << fTimeWeightsHiGain[i] << endl;
    510 
    511   *fLog << endl;
    512   *fLog << inf << "Used Low Gain weights in the extractor: " << endl;
    513   for (Int_t i=0;i<fBinningResolutionLoGain*fWindowSizeLoGain; i++)
    514     *fLog << inf << fAmpWeightsLoGain[i] << "   " << fTimeWeightsLoGain[i] << endl;
    515  
    516   return kTRUE;
     487    Byte_t hw = fWindowSizeHiGain;
     488    Byte_t lw = fWindowSizeLoGain;
     489    Bool_t rc = kFALSE;
     490
     491    if (IsEnvDefined(env, prefix, "WindowSizeHiGain", print))
     492    {
     493        hw = GetEnvValue(env, prefix, "WindowSizeHiGain", hw);
     494        rc = kTRUE;
     495    }
     496    if (IsEnvDefined(env, prefix, "WindowSizeLoGain", print))
     497    {
     498        lw = GetEnvValue(env, prefix, "WindowSizeLoGain", lw);
     499        rc = kTRUE;
     500    }
     501
     502    if (rc)
     503        SetWindowSize(hw, lw);
     504
     505    Bool_t rc2 = kFALSE;
     506    Int_t brh = fBinningResolutionHiGain;
     507    Int_t brl = fBinningResolutionLoGain;
     508
     509    if (IsEnvDefined(env, prefix, "BinningResolutionHiGain", print))
     510    {
     511        brh = GetEnvValue(env, prefix, brh);
     512        rc2 = kTRUE;
     513    }
     514    if (IsEnvDefined(env, prefix, "BinningResolutionLoGain", print))
     515    {
     516        brl = GetEnvValue(env, prefix, brl);
     517        rc2 = kTRUE;
     518    }
     519
     520    if (rc2)
     521    {
     522        SetBinningResolution(brh, brl);
     523        rc = kTRUE;
     524    }
     525
     526    if (IsEnvDefined(env, prefix, "WeightsFile", print))
     527    {
     528        if (!ReadWeightsFile(GetEnvValue(env, prefix, "WeightsFile", "")))
     529            return kERROR;
     530        rc = kTRUE;
     531    }
     532
     533    return MExtractTimeAndCharge::ReadEnv(env, prefix, print) ? kTRUE : rc;
    517534}
    518535
     
    526543Bool_t MExtractTimeAndChargeDigitalFilter::ReadWeightsFile(TString filename)
    527544{
    528 
    529   fAmpWeightsHiGain .Set(fBinningResolutionHiGain*fWindowSizeHiGain);
    530   fAmpWeightsLoGain .Set(fBinningResolutionLoGain*fWindowSizeLoGain);
    531   fTimeWeightsHiGain.Set(fBinningResolutionHiGain*fWindowSizeHiGain);
    532   fTimeWeightsLoGain.Set(fBinningResolutionLoGain*fWindowSizeLoGain);
    533  
    534   if (filename.IsNull())
    535     {
    536       for (UInt_t i=0; i<fAmpWeightsHiGain.GetSize(); i++)
    537         {
    538           fAmpWeightsHiGain [i] = 1.;
    539           fTimeWeightsHiGain[i] = 1.;
    540         }
    541       for (UInt_t i=0; i<fAmpWeightsLoGain.GetSize(); i++)
    542         {
    543           fAmpWeightsLoGain [i] = 1.;
    544           fTimeWeightsLoGain[i] = 1.;
    545         }
    546       return kTRUE;
    547     }
    548 
    549   ifstream fin(filename.Data());
    550  
    551   if (!fin)
    552     {
    553       *fLog << err << GetDescriptor()
    554             << ": No weights file found: " << filename << endl;
    555       return kFALSE;
    556     }
    557 
    558   Int_t len = 0;
    559   Int_t cnt = 0;
    560   Bool_t hi = kFALSE;
    561   Bool_t lo = kFALSE;
    562  
    563   TString str;
    564 
    565   while (1)
    566     {
    567 
    568       str.ReadLine(fin);
    569       if (!fin)
    570         break;
    571      
    572 
    573       if (str.Contains("# High Gain Weights:"))
    574         {
    575           str.ReplaceAll("# High Gain Weights:","");
    576           sscanf(str.Data(),"%2i%2i",&fWindowSizeHiGain,&fBinningResolutionHiGain);
    577           *fLog << inf << "Found number of High Gain slices: " << fWindowSizeHiGain
    578                        << " and High Gain resolution: " << fBinningResolutionHiGain << endl;
    579           len = fBinningResolutionHiGain*fWindowSizeHiGain;
    580           fAmpWeightsHiGain .Set(len);
    581           fTimeWeightsHiGain.Set(len);
    582           hi = kTRUE;
    583           continue;
    584         }
    585      
    586       if (str.Contains("# Low Gain Weights:"))
    587         {
    588           str.ReplaceAll("# Low Gain Weights:","");
    589           sscanf(str.Data(),"%2i%2i",&fWindowSizeLoGain,&fBinningResolutionLoGain);
    590           *fLog << inf << "Found number of Low Gain slices: " << fWindowSizeLoGain
    591                        << " and Low Gain resolution: " << fBinningResolutionLoGain << endl;
    592           len = fBinningResolutionLoGain*fWindowSizeHiGain;
    593           fAmpWeightsLoGain .Set(len);
    594           fTimeWeightsLoGain.Set(len);
    595           lo = kTRUE;
    596           continue;
    597         }
    598      
    599       if (str.Contains("#"))
    600         continue;
    601 
    602       if (len == 0)
    603         continue;
    604 
    605       sscanf(str.Data(),"\t%f\t%f",lo ? &fAmpWeightsLoGain [cnt] : &fAmpWeightsHiGain [cnt],
    606                                          lo ? &fTimeWeightsLoGain[cnt] : &fTimeWeightsHiGain[cnt]);
    607 
    608       if (++cnt == len)
    609         {
    610           len = 0;
    611           cnt = 0;
    612         }
    613     }
    614 
    615   if (cnt != len)
    616     {
    617       *fLog << err << GetDescriptor()
    618             << ": Size mismatch in weights file " << filename << endl;
    619       return kFALSE;
    620     }
    621 
    622   if (!hi)
    623     {
    624       *fLog << err << GetDescriptor()
    625             << ": No correct header found in weights file " << filename << endl;
    626       return kFALSE;
    627     }
    628 
    629   return kTRUE;
     545    fAmpWeightsHiGain .Set(fBinningResolutionHiGain*fWindowSizeHiGain);
     546    fAmpWeightsLoGain .Set(fBinningResolutionLoGain*fWindowSizeLoGain);
     547    fTimeWeightsHiGain.Set(fBinningResolutionHiGain*fWindowSizeHiGain);
     548    fTimeWeightsLoGain.Set(fBinningResolutionLoGain*fWindowSizeLoGain);
     549
     550    if (filename.IsNull())
     551    {
     552        fAmpWeightsHiGain.Reset(1);
     553        fTimeWeightsHiGain.Reset(1);
     554        fAmpWeightsLoGain.Reset(1);
     555        fTimeWeightsLoGain.Reset(1);
     556        return kTRUE;
     557    }
     558
     559    ifstream fin(filename.Data());
     560    if (!fin)
     561    {
     562        *fLog << err << GetDescriptor() << ": ERROR - Cannot open file " << filename << ": ";
     563        *fLog << strerror(errno) << endl;
     564        return kFALSE;
     565    }
     566
     567    *fLog << inf << "Reading weights file " << filename << "..." << flush;
     568
     569    Int_t len = 0;
     570    Int_t cnt = 0;
     571    Int_t line = 0;
     572    Bool_t hi = kFALSE;
     573    Bool_t lo = kFALSE;
     574
     575    TString str;
     576
     577    while (1)
     578    {
     579        str.ReadLine(fin);
     580        if (!fin)
     581            break;
     582
     583        line++;
     584
     585        if (str.Contains("# High Gain Weights:"))
     586        {
     587            if (hi)
     588            {
     589                *fLog << err << "ERROR - 'High Gain Weights' found twice in line #" << line << "." << endl;
     590                return kFALSE;
     591            }
     592
     593            if (2!=sscanf(str.Data(), "# High Gain Weights:%2i %2i", &fWindowSizeHiGain, &fBinningResolutionHiGain))
     594            {
     595                *fLog << err << "ERROR - Wrong number of arguments in line #" << line << ":" << endl;
     596                *fLog << str << endl;
     597                return kFALSE;
     598            }
     599
     600            len = fBinningResolutionHiGain*fWindowSizeHiGain;
     601            fAmpWeightsHiGain .Set(len);
     602            fTimeWeightsHiGain.Set(len);
     603            hi = kTRUE;
     604            continue;
     605        }
     606
     607        if (str.Contains("# Low Gain Weights:"))
     608        {
     609            if (lo)
     610            {
     611                *fLog << err << "ERROR - 'Lo Gain Weights' found twice in line #" << line << "." << endl;
     612                return kFALSE;
     613            }
     614
     615            if (2!=sscanf(str.Data(),"# Low Gain Weights:%2i %2i", &fWindowSizeLoGain, &fBinningResolutionLoGain))
     616            {
     617                *fLog << err << "ERROR - Wrong number of arguments in line #" << line << ":" << endl;
     618                *fLog << str << endl;
     619                return kFALSE;
     620            }
     621
     622            len = fBinningResolutionLoGain*fWindowSizeHiGain;
     623            fAmpWeightsLoGain .Set(len);
     624            fTimeWeightsLoGain.Set(len);
     625            lo = kTRUE;
     626            continue;
     627        }
     628
     629        // Handle lines with comments
     630        if (str.Contains("#"))
     631            continue;
     632
     633        // Nothing found so far
     634        if (len == 0)
     635            continue;
     636
     637        if (2!=sscanf(str.Data(), "%f %f",
     638                      lo ? &fAmpWeightsLoGain [cnt] : &fAmpWeightsHiGain [cnt],
     639                      lo ? &fTimeWeightsLoGain[cnt] : &fTimeWeightsHiGain[cnt]))
     640        {
     641            *fLog << err << "ERROR - Wrong number of arguments in line #" << line << ":" << endl;
     642            *fLog << str << endl;
     643            return kFALSE;
     644        }
     645
     646        if (++cnt == len)
     647        {
     648            len = 0;
     649            cnt = 0;
     650        }
     651    }
     652
     653    if (cnt != len)
     654    {
     655        *fLog << err << "Size mismatch in weights file " << filename << endl;
     656        return kFALSE;
     657    }
     658
     659    if (!hi)
     660    {
     661        *fLog << err << "No correct header found in weights file " << filename << endl;
     662        return kFALSE;
     663    }
     664
     665    *fLog << "done." << endl;
     666
     667    *fLog << inf << " File contains " << fWindowSizeHiGain << " hi-gain slices ";
     668    *fLog << "and with a resolution of " << fBinningResolutionHiGain << endl;
     669
     670    *fLog << inf << " File contains " << fWindowSizeLoGain << " lo-gain slices ";
     671    *fLog << "and with a resolution of " << fBinningResolutionLoGain << endl;
     672
     673    return kTRUE;
    630674}
    631675
  • trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeDigitalFilter.h

    r5162 r5298  
    1616{
    1717private:
    18 
    1918  static const Byte_t fgHiGainFirst;
    2019  static const Byte_t fgHiGainLast;
     
    3433  Float_t fTimeShiftLoGain;
    3534 
    36   Int_t   fSignalStartBinHiGain;
    37   Int_t   fSignalStartBinLoGain;
     35  Int_t   fSignalStartBinHiGain; //!
     36  Int_t   fSignalStartBinLoGain; //!
    3837
    39   Int_t   fWindowSizeHiGain;           
    40   Int_t   fWindowSizeLoGain;           
     38  Int_t   fWindowSizeHiGain;
     39  Int_t   fWindowSizeLoGain;
    4140
    4241  Int_t   fBinningResolutionHiGain;
     
    4544  Int_t   fBinningResolutionHalfLoGain;
    4645 
    47   MArrayF fAmpWeightsHiGain;
    48   MArrayF fTimeWeightsHiGain;
    49   MArrayF fAmpWeightsLoGain;
    50   MArrayF fTimeWeightsLoGain;
     46  MArrayF fAmpWeightsHiGain;     //!
     47  MArrayF fTimeWeightsHiGain;    //!
     48  MArrayF fAmpWeightsLoGain;     //!
     49  MArrayF fTimeWeightsLoGain;    //!
    5150
    52   Bool_t ReInit( MParList *pList );
    53   Int_t PostProcess(); 
    54  
     51  Bool_t ReInit(MParList *pList);
     52  Int_t PreProcess(MParList *pList);
     53
    5554  Int_t  ReadEnv(const TEnv &env, TString prefix, Bool_t print);
    56  
     55
    5756protected:
    58 
    5957  virtual void FindTimeAndChargeHiGain(Byte_t *firstused, Byte_t *logain, Float_t &sum, Float_t &dsum,
    6058                                       Float_t &time, Float_t &dtime,
     
    8987  }
    9088 
    91   ClassDef(MExtractTimeAndChargeDigitalFilter, 0)   // Hendrik's digital filter
     89  ClassDef(MExtractTimeAndChargeDigitalFilter, 1)   // Hendrik's digital filter
    9290};
    9391
    9492#endif
    95 
    96 
    97 
Note: See TracChangeset for help on using the changeset viewer.