Main Page | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Globals

TDSPRating.h

Go to the documentation of this file.
00001 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #ifndef TDSPRATING_H
00019 #define TDSPRATING_H
00020 
00021 #include <Rtypes.h>
00022 #include <Riostream.h>
00023 #include <TMath.h>
00024 #include <TRandom.h>
00025 #include <TError.h>
00026 
00032 class TDSPRating {
00033 
00034  protected:
00035   
00036   Double_t fRate;                          // The Rate of the Process
00037   UInt_t    fRelativeRate;                 // what was the last relative rate (input-rate/fRate)                 
00038   Double_t fRelativeRateMean;              // what is the mean relative rate
00039   Double_t fRelativeRateSigma;
00040   UInt_t   fRateIndex;                     // Counter (due to diffenent sampling rates, Representation holds)
00041 
00042   void     Next();                         // Next entry
00043   Int_t    NewRelativeRate();              // New Relative Rate
00044   
00045  public: 
00046   
00047   TDSPRating();
00048   virtual ~TDSPRating();
00049 
00050   
00051   void     SetRate(Double_t);                              // Set the Rate for the Stochastic Process
00052   Double_t GetRate() { return fRate;};                     // Get the Rate for the Stochastic Process
00053   Double_t GetRelativeRate() { return fRelativeRateMean;}; // Get mean of the relative ratings
00054   void     SetRateSigma(Double_t s) { fRelativeRateSigma = s;}; // Set the Sigma
00055   Double_t GetRateSigma() const { return fRelativeRateSigma;}; // Get the Sigma
00056   Double_t GetLastRelativeRate() { return fRelativeRate;}; // get the last relative rating
00057   void     ResetRating()  { fRateIndex=0;};  // Reset the Rating
00058   Bool_t   IsRate(); // Do we have to change the representation 
00059   virtual  void  PrepareRate(Double_t r); // Prepare the Rating to application on a signal sampled at a rate "r"
00060 
00061   ClassDef(TDSPRating,1)
00062   
00063 };
00064 
00065 inline void   TDSPRating::Next() {
00066   
00067   if (++fRateIndex>=fRelativeRate) {
00068     NewRelativeRate();
00069     fRateIndex=0;
00070   }
00071 }
00072 
00073 inline Bool_t TDSPRating::IsRate() {
00074   return fRateIndex == 0;
00075 }
00076 
00077 
00078 inline Int_t TDSPRating::NewRelativeRate() { 
00079   ResetRating();
00080   return (fRelativeRate = TMath::Max(1,TMath::Nint(gRandom->Gaus(fRelativeRateMean,fRelativeRateSigma)))); 
00081 } 
00082 
00083 
00084 
00085 inline void   TDSPRating::PrepareRate(Double_t rate){
00086   
00087 
00088 #if defined(__OPTIMIZE__)&&defined(__GNUC__)
00089   // Workaround for wrong optimization in GCC 2.95.3
00090   //
00091   volatile Double_t Relative_Rate = rate/fRate;
00092 #else
00093   Double_t Relative_Rate = rate/fRate;
00094 #endif
00095   // The Relative Rates has been changed (this can only come from manual settings)
00096   //
00097   if (fRelativeRateMean != Relative_Rate) {
00098     if (Relative_Rate<1.0) 
00099       Error("TDSPRating::PrepareRate","Can not set relative Sampling Rates (input/response) of %f < 1.0 !!",Relative_Rate);
00100     else {
00101       
00102       fRelativeRateMean  = Relative_Rate;
00103       
00104       NewRelativeRate();
00105     }
00106   }
00107   
00108 }
00109 
00110 
00111 #endif

Generated on Fri Apr 23 16:23:43 2004 by doxygen 1.3.2