Ignore:
Timestamp:
07/15/05 13:25:57 (19 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/msignal
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeDigitalFilter.cc

    r7134 r7194  
    7070#include "MRawRunHeader.h"
    7171#include "MCalibrationPattern.h"
     72#include "MExtractedSignalCam.h"
    7273
    7374#include "MPedestalPix.h"
     
    142143  if (fWindowSizeHiGain > availhirange)
    143144  {
    144       // Please simplify this!
    145       *fLog << warn << GetDescriptor()
    146             << Form("%s%2i%s%2i%s%2i%s",": Hi Gain window size: ",fWindowSizeHiGain,
    147                     " is bigger than available range: [",(int)fHiGainFirst,",",(int)fHiGainLast,"]") << endl;
     145      *fLog << warn << GetDescriptor() << ": Hi Gain window size: " << Form("%2i",fWindowSizeHiGain);
     146      *fLog << " is bigger than available range: [" << Form("%2i", (int)fHiGainFirst);
     147      *fLog << "," << Form("%21", (int)fHiGainLast) << "]" << endl;
     148
    148149      fHiGainLast = fHiGainFirst + fWindowSizeHiGain;
    149       *fLog << warn << GetDescriptor()
    150             << ": Will set the upper range to: " << (int)fHiGainLast << endl;
     150
     151      *fLog << warn << GetDescriptor() << ": Will set the upper range to: " << (int)fHiGainLast << endl;
    151152    }
    152153 
     
    163164      if (fWindowSizeLoGain > availlorange)
    164165        {
    165       // Please simplify this!
    166           *fLog << warn << GetDescriptor()
    167                 << Form("%s%2i%s%2i%s%2i%s",": Lo Gain window size: ",fWindowSizeLoGain,
    168                         " is bigger than available range: [",(int)fLoGainFirst,",",(int)fLoGainLast,"]") << endl;
    169           fLoGainLast = fLoGainFirst + fWindowSizeLoGain;
    170           *fLog << warn << GetDescriptor()
    171             << ": Will set the upper range to: " << (int)fLoGainLast << endl;
     166            *fLog << warn << GetDescriptor() << ": Lo Gain window size: " << Form("%2i",fWindowSizeLoGain);
     167            *fLog << " is bigger than available range: [" << Form("%2i", (int)fLoGainFirst);
     168            *fLog << "," << Form("%21", (int)fLoGainLast) << "]" << endl;
     169
     170            fLoGainLast = fLoGainFirst + fWindowSizeLoGain;
     171
     172            *fLog << warn << GetDescriptor() << ": Will set the upper range to: " << (int)fLoGainLast << endl;
    172173        }
    173174     
     
    205206// --------------------------------------------------------------------------
    206207//
    207 // InitArrays
    208 //
    209 // Gets called in the ReInit() and initialized the arrays
    210 //
    211 Bool_t MExtractTimeAndChargeDigitalFilter::InitArrays()
    212 {
    213     if (!fRunHeader)
     208// The weights are determined using GetAutimaticWeights().
     209//
     210// kFALSE is returned if it returned an error.
     211// kTRUE  is returned if no new weights were set.
     212//
     213// If new weights are set
     214//  fTimeShiftHiGain
     215//  fTimeShiftLoGain
     216//  fNumHiGainSamples
     217//  fNumLoGainSamples
     218//  fSqrtHiGainSamples
     219//  fSqrtLoGainSamples
     220// and
     221//  fSignals->SetUsedFADCSlices(...)
     222// is updated accordingly.
     223//
     224Bool_t MExtractTimeAndChargeDigitalFilter::GetWeights()
     225{
     226    switch (GetAutomaticWeights())
     227    {
     228    case kERROR: // An error occured
    214229        return kFALSE;
    215 
    216     const Int_t rangehi = (Int_t)(fHiGainLast - fHiGainFirst + 1 + fHiLoLast);
    217     const Int_t rangelo = (Int_t)(fLoGainLast - fLoGainFirst + 1);
    218 
    219     fHiGainSignal.Set(rangehi);
    220     fLoGainSignal.Set(rangelo);
    221 
    222     // Try to get automatic weights
    223     if (!ReadAutomaticWeightsFile())
    224         return kFALSE;
    225 
    226     // If still no weights set try conservative way
    227     if (fNameWeightsFileSet.IsNull())
    228         if (!ReadWeightsFile(fNameWeightsFile))
    229             return kFALSE;
    230 
    231     fTimeShiftHiGain = (Float_t)fHiGainFirst + 0.5 + 1./fBinningResolutionHiGain;
     230    case kFALSE: // No new weights set
     231        return kTRUE;
     232    }
     233
     234    // New weights set
     235    fTimeShiftHiGain = 0.5 + 1./fBinningResolutionHiGain + fHiGainFirst;
    232236    fTimeShiftLoGain = 0.5 + 1./fBinningResolutionLoGain;
     237
    233238    //
    234239    // We need here the effective number of samples which is about 2.5 in the case of a window
     
    240245    fSqrtLoGainSamples = TMath::Sqrt(fNumLoGainSamples);
    241246
     247    // From MExtractTimeAndCharge::ReInit
     248    if (fSignals)
     249        fSignals->SetUsedFADCSlices(fHiGainFirst, fHiGainLast+fHiLoLast, fNumHiGainSamples,
     250                                    fLoGainFirst, fLoGainLast, fNumLoGainSamples);
    242251    return kTRUE;
     252}
     253
     254// --------------------------------------------------------------------------
     255//
     256// InitArrays
     257//
     258// Gets called in the ReInit() and initialized the arrays
     259//
     260Bool_t MExtractTimeAndChargeDigitalFilter::InitArrays()
     261{
     262    if (!fRunHeader)
     263        return kFALSE;
     264
     265    const Int_t rangehi = (Int_t)(fHiGainLast - fHiGainFirst + 1 + fHiLoLast);
     266    const Int_t rangelo = (Int_t)(fLoGainLast - fLoGainFirst + 1);
     267
     268    fHiGainSignal.Set(rangehi);
     269    fLoGainSignal.Set(rangelo);
     270
     271    return GetWeights();
     272}
     273
     274// --------------------------------------------------------------------------
     275//
     276// Check if reading a new weights file is necessary because the calibration
     277// pattern has changed. (Cannot be done in ReInit, because at this time
     278// the calibration pattern is not available.
     279// Then process the event.
     280//
     281Int_t MExtractTimeAndChargeDigitalFilter::Process()
     282{
     283    // Change Weights if the calibration patter changes
     284    if (!GetWeights())
     285        return kERROR;
     286
     287    // Process event
     288    return MExtractTimeAndCharge::Process();
    243289}
    244290
     
    643689//----------------------------------------------------------------------------
    644690//
     691// If automatic weights are requested, no default weights (name.IsNull())
     692// are requested, fRunHeader is available and fRunHeader->IsMonteCarloRun()
     693// is true prepend "MC_" in from of the name.
     694//
     695// return poth+name;
     696//
     697TString MExtractTimeAndChargeDigitalFilter::CompileWeightFileName(TString path, const TString &name) const
     698{
     699    if (fAutomaticWeights && !name.IsNull() && fRunHeader && fRunHeader->IsMonteCarloRun())
     700        path += "MC_";
     701
     702    path += name;
     703
     704    return path;
     705}
     706
     707//----------------------------------------------------------------------------
     708//
    645709// Read a pre-defined weights file into the class.
    646710// This is mandatory for the extraction
     
    648712// If filenname is empty, then all weights will be set to 1.
    649713//
    650 Bool_t MExtractTimeAndChargeDigitalFilter::ReadWeightsFile(TString filename)
    651 {
    652  
    653     // This is a fix for TEnv files edited with windows editors
    654     filename.ReplaceAll("\015", "");
    655 
    656     fAmpWeightsHiGain .Set(fBinningResolutionHiGain*fWindowSizeHiGain);
    657     fAmpWeightsLoGain .Set(fBinningResolutionLoGain*fWindowSizeLoGain);
    658     fTimeWeightsHiGain.Set(fBinningResolutionHiGain*fWindowSizeHiGain);
    659     fTimeWeightsLoGain.Set(fBinningResolutionLoGain*fWindowSizeLoGain);
    660 
    661     if (fNameWeightsFile.IsNull() || fNameWeightsFile=="-")
    662     {
     714// Returns:
     715//  kTRUE:  new weights set
     716//  kFALSE: no  weights set
     717//  kERROR: error
     718//
     719Int_t MExtractTimeAndChargeDigitalFilter::ReadWeightsFile(TString filename, TString path)
     720{
     721    if (filename.IsNull())
     722    {
     723        fAmpWeightsHiGain .Set(fBinningResolutionHiGain*fWindowSizeHiGain);
     724        fAmpWeightsLoGain .Set(fBinningResolutionLoGain*fWindowSizeLoGain);
     725        fTimeWeightsHiGain.Set(fBinningResolutionHiGain*fWindowSizeHiGain);
     726        fTimeWeightsLoGain.Set(fBinningResolutionLoGain*fWindowSizeLoGain);
     727
    663728        fAmpWeightsHiGain.Reset(1);
    664729        fTimeWeightsHiGain.Reset(1);
    665730        fAmpWeightsLoGain.Reset(1);
    666731        fTimeWeightsLoGain.Reset(1);
    667         fNameWeightsFileSet = "-";
    668732        return kTRUE;
    669733    }
    670734
     735    // Add "MC_" in front of the filename if necessary
     736    filename = CompileWeightFileName(path, filename);
     737
    671738    //filename = MJob::ExpandPath(filename);
    672739
    673740    if (fNameWeightsFileSet==filename)
    674         return kTRUE;
     741        return kFALSE; // No file read
    675742
    676743    ifstream fin(filename.Data());
     
    679746        *fLog << err << GetDescriptor() << ": ERROR - Cannot open file " << filename << ": ";
    680747        *fLog << strerror(errno) << endl;
    681         return kFALSE;
    682     }
    683 
    684     *fLog << all << "DigitalFilter: Reading weights in " << filename << "..." << flush;
     748        return kERROR;
     749    }
     750
     751    *fLog << all << GetDescriptor() << ": Reading weights in " << filename << "..." << flush;
    685752
    686753    Int_t len = 0;
     
    705772            {
    706773                *fLog << err << "ERROR - 'High Gain Weights' found twice in line #" << line << "." << endl;
    707                 return kFALSE;
     774                return kERROR;
    708775            }
    709776
     
    712779                *fLog << err << "ERROR - Wrong number of arguments in line #" << line << ":" << endl;
    713780                *fLog << str << endl;
    714                 return kFALSE;
     781                return kERROR;
    715782            }
    716783
     
    727794            {
    728795                *fLog << err << "ERROR - 'Lo Gain Weights' found twice in line #" << line << "." << endl;
    729                 return kFALSE;
     796                return kERROR;
    730797            }
    731798
     
    734801                *fLog << err << "ERROR - Wrong number of arguments in line #" << line << ":" << endl;
    735802                *fLog << str << endl;
    736                 return kFALSE;
     803                return kERROR;
    737804            }
    738805
     
    758825            *fLog << err << "ERROR - Wrong number of arguments in line #" << line << ":" << endl;
    759826            *fLog << str << endl;
    760             return kFALSE;
     827            return kERROR;
    761828        }
    762829
     
    770837    if (cnt != len)
    771838    {
    772         *fLog << err << "Size mismatch in weights file " << filename << endl;
    773         return kFALSE;
     839        *fLog << err << "ERROR - Size mismatch in weights file " << filename << endl;
     840        return kERROR;
    774841    }
    775842
    776843    if (!hi)
    777844    {
    778         *fLog << err << "No correct header found in weights file " << filename << endl;
    779         return kFALSE;
     845        *fLog << err << "ERROR - No correct header found in weights file " << filename << endl;
     846        return kERROR;
    780847    }
    781848
     
    824891//----------------------------------------------------------------------------
    825892//
    826 // If automatic weight disabled or run type is pedestal no action is taken
    827 // and kTRUE is returned.
    828 //
    829 // Otherwise:
    830 //  - If runtype is kRTData and filename starts with "MC_weights" "MC" is
    831 //    replaced by "cosmics"
    832 //  - If runtype is kRTMonteCarlo and filename starts with "cosmics_weights"
    833 //    "cosmics" is replaced by "MC"
    834 //  - If name filename begins with "calibration_weights_" for blue and green
    835 //    "UV" is replaced by "blue"
    836 //  - If name filename begins with "calibration_weights_" for UV and CT1
    837 //    "blue" is replaced by "UV"
    838 //
    839 // The replacements are done in this order. If no match is found no
    840 // replacement is done. Afterwards ReadWeightsFile for the resulting
    841 // path-/filename is called.
    842 //
    843 Bool_t MExtractTimeAndChargeDigitalFilter::ReadAutomaticWeightsFile()
    844 {
    845     if (!fAutomaticWeights || fRunHeader->GetRunType()==MRawRunHeader::kRTPedestal)
    846         return kTRUE;
    847 
    848     if (fNameWeightsFile.IsNull())
    849     {
    850         *fLog << err << "ERROR - Cannot get automatic weights without default filename." << endl;
    851         return kFALSE;
    852     }
    853 
    854     *fLog << dbg << endl;
    855     *fLog << underline << GetDescriptor() << endl;
    856     *fLog << " Trying to get automatic weight for " << fNameWeightsFile << endl;
    857 
     893// The default (+ prepending possible "MC_") is read for:
     894//
     895//   - RunType: Pedestal (independant of fAutomaticWeights)
     896//   - fAutomaticWeights disabled
     897//
     898//  if fAutomaticWeights enabled:
     899//   - fNameWeightsFile.IsNull()
     900//   - !fCalibPattern
     901//   - fCalibPattern->GetPulserColor()==MCalibrationCam::kNONE
     902//
     903// If automatic weights are enabled, the case above didn't take place and
     904// fNameWeightsFile starts with "calibration_weights_"
     905//   - the color (blue, UV) is replaced by the appropriate one
     906//     taken from the calibration pattern
     907//
     908// In most cases a debug output is printed. Further output about the color
     909// determination can be switched on with debug level > 5;
     910//
     911// Returns:
     912//  kFALSE: No new weights set
     913//  kTRUE:  New weights set
     914//  kERROR: Error
     915//
     916Int_t MExtractTimeAndChargeDigitalFilter::GetAutomaticWeights()
     917{
    858918    const Ssiz_t pos = fNameWeightsFile.Last('/')+1;
    859919    const Ssiz_t len = fNameWeightsFile.Length();
    860920
     921    // Split file name in path and name
    861922    TString path = fNameWeightsFile(0, pos>=0?pos:len);
    862923    TString name = fNameWeightsFile(pos>=0?pos:0, len);
    863924
    864     if (name.BeginsWith("cosmics_weights") && fRunHeader->GetRunType()==MRawRunHeader::kRTMonteCarlo)
    865     {
    866         name.Remove(0, 7);
    867         name.Prepend("MC");
    868         *fLog << "Run type: Monte Carlo data" << endl;
    869     }
    870     if (name.BeginsWith("MC_weights") && fRunHeader->GetRunType()==MRawRunHeader::kRTData)
    871     {
    872         name.Remove(0, 2);
    873         name.Prepend("cosmics");
    874         *fLog << "Run type: Cosmics data" << endl;
     925    // Remove trailing "MC_" for automatic weights
     926    if (fAutomaticWeights && name.BeginsWith("MC_"))
     927        name.Remove(0, 3);
     928
     929    // In case of a pedetsal run no calibration pattern can be available
     930    // the default weights are always used.
     931    if (fRunHeader->GetRunType()==MRawRunHeader::kRTPedestal)
     932    {
     933        *fLog << dbg << "Pedestal file... using default weights: " << fNameWeightsFile << endl;
     934        return ReadWeightsFile(name, path);
     935    }
     936
     937    // If automatic weights are switched off use default weights
     938    if (!fAutomaticWeights)
     939    {
     940        *fLog << dbg << "Automatic weights switched off... using default weights: " << fNameWeightsFile << endl;
     941        return ReadWeightsFile(name, path);
     942    }
     943
     944    // If automatic weights are switched on but no filename is given raise error
     945    if (fNameWeightsFile.IsNull())
     946    {
     947        *fLog << err << "ERROR - Cannot get automatic weights without default filename." << endl;
     948        return kERROR;
     949    }
     950
     951    // If this is no pedestal run, automatic weights are requested and a
     952    // filename for the weights file is given pedestal-extraction from
     953    // cosmics data is assumed.
     954    if (!fCalibPattern)
     955    {
     956        *fLog << dbg << "No decoded calibration pattern available... using default weights: " << fNameWeightsFile << endl;
     957        return ReadWeightsFile(name, path);
     958    }
     959
     960    const Bool_t debug = gLog.GetDebugLevel()>5;
     961
     962    // If no calibration pattern is available do not change the
     963    // current weighs or current weights file name.
     964    if (fCalibPattern->GetPulserColor()==MCalibrationCam::kNONE)
     965    {
     966        // If we are extracting data and the calibration pattern is kNONE
     967        // we assume that it is a data file without interleaved events
     968        // and calibration pattern information available.
     969        if ((fRunHeader->GetRunType()!=MRawRunHeader::kRTData && !fRunHeader->IsMonteCarloRun()) || debug)
     970            *fLog << dbg << "No calibration color set so far... guessing default: " << fNameWeightsFile << endl;
     971
     972        return ReadWeightsFile(name, path);
     973    }
     974
     975    if (debug)
     976    {
     977        *fLog << dbg << endl;
     978        *fLog << underline << GetDescriptor() << endl;
     979        *fLog << " Trying to get automatic weight for " << fNameWeightsFile << endl;
     980        *fLog << " Run type: ";
    875981    }
    876982
    877983    if (name.BeginsWith("calibration_weights_") && fCalibPattern)
    878984    {
    879         *fLog << " Run type: Calibration with color " << (int)fCalibPattern->GetPulserColor() << ", setting ";
     985        if (debug)
     986            *fLog << " Calibration with color " << fCalibPattern->GetPulserColorStr() << ", setting ";
    880987        switch (fCalibPattern->GetPulserColor())
    881988        {
    882989        case MCalibrationCam::kBLUE:  // 2
    883990        case MCalibrationCam::kGREEN: // 1
    884             *fLog << "blue/green" << endl;
     991            if (debug)
     992                *fLog << "blue/green, ";
    885993            name.ReplaceAll("UV", "blue");
    886994            break;
     
    888996        case MCalibrationCam::kUV:    // 3
    889997        case MCalibrationCam::kCT1:   // 0
    890             *fLog << "UV/CT1" << endl;
     998            if (debug)
     999                *fLog << "UV/CT1, ";
    8911000            name.ReplaceAll("blue", "UV");
    8921001            break;
    8931002        case MCalibrationCam::kNONE:
    894             *fLog << "None" << endl;
    8951003            break;
    896         default: // kNONE=4
    897             *fLog << "???" << endl;
    898         }
    899     }
    900 
    901     path += name;
    902 
    903     return ReadWeightsFile(path);
     1004        default: // kNone + etc
     1005            *fLog << err << "ERROR - Cannot get automatic weights for " << fCalibPattern->GetPulserColorStr() << endl;
     1006            return kERROR;
     1007        }
     1008    }
     1009
     1010    return ReadWeightsFile(name, path);
    9041011}
    9051012
  • trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeDigitalFilter.h

    r7099 r7194  
    6969  // MExtractTimeAndChargeDigitalFilter
    7070  void    CalcBinningResArrays();
    71   Bool_t  ReadAutomaticWeightsFile();
     71  Int_t   GetAutomaticWeights();
     72  Bool_t  GetWeights();
     73  Int_t   ReadWeightsFile(TString filename, TString path="");
     74  TString CompileWeightFileName(TString path, const TString &name) const;
    7275
    7376  // MExtractTimeAndCharge
     
    7679  // MTask
    7780  Int_t PreProcess(MParList *pList);
     81  Int_t Process();
    7882
    7983protected:
     
    8589  ~MExtractTimeAndChargeDigitalFilter() { }
    8690
    87   Bool_t ReadWeightsFile(TString filename);
    88  
    8991  Bool_t WriteWeightsFile(TString filename,
    9092                          TH1F *shapehi, TH2F *autocorrhi,
     
    9294
    9395
    94   void SetNameWeightsFile(TString s="") { fNameWeightsFile = s; fNameWeightsFileSet=""; }
     96  void SetNameWeightsFile(TString s="") { s.ReplaceAll("\015", ""); // This is a fix for TEnv files edited with windows editors
     97      fNameWeightsFile = s; fNameWeightsFileSet=""; }
    9598  void EnableAutomaticWeights(Bool_t b=kTRUE) { fAutomaticWeights = b; }
    9699
Note: See TracChangeset for help on using the changeset viewer.