MDetector/Channel.h
Go to the documentation of this file.
1 #ifndef _mdet_Channel_h
2 #define _mdet_Channel_h
3 
4 #include <mdet/MDetectorComponent.h>
5 //
6 #include <utl/Validated.h>
7 //
8 #include <complex>
9 #include <memory>
10 
11 
12 namespace det {
13  struct ParentCreator;
14  struct ComponentUpdater;
15 }
16 
17 namespace mdet {
18 
19  class FrontEnd;
20 
21 
37  class Channel : public MDetectorComponent<Channel>::Type {
38  public:
59  class Discriminator {
60  private:
69  class Callable {
70  public:
72  virtual double operator()(double t) const = 0;
74  virtual Callable* Clone() const = 0;
76  virtual ~Callable();
77  };
99  public:
100  template<class Functor>
101  class Proxy : public Callable {
102  public:
103  Proxy(const Functor& f) : fFunctor(f) { }
104  double operator()(double t) const
105  { return fFunctor(t); /* As a good proxy, forward the call */ }
106 
108  Clone()
109  const
110  {
111  /*
112  * The function MakeDiscriminator returns by copy, tough
113  * thanks to Named-Return-Value-Optimization it's likely
114  * that no temporaries will be created. Nevertheless, one cannot
115  * just make private the copy constructor because, tough not
116  * finally used, needs to be visible.
117  *
118  * So, being it visible copying is allowed. If we don't do
119  * something the compiler generated copy constructor will
120  * inherit std::auto_ptr's behaviour and so the copies
121  * won't be equivalent (since the original auto_ptr
122  * gets its pointer zeroed).
123  *
124  * See
125  * http://www.artima.com/forums/flat.jsp?forum=226&thread=175294
126  */
128  }
129  private:
130  const Functor& fFunctor;
131  };
132 
133  private:
134  /*
135  * Types of nested members.
136  */
138  friend class Channel;
139  struct Root {
141  double fTime;
143  double fOutput;
144  };
146  typedef std::vector<Root> RootContainer;
148  typedef RootContainer::const_iterator RootIterator;
149  /*
150  * We should use list since we don't know the number in advance;
151  * but on the other hand we need to sort'em and so a random access
152  * container is needed.
153  */
154  typedef std::vector<double> RawRootsContainer;
155  public:
165  typedef RawRootsContainer::const_iterator AtThresholdConstIterator;
183  double operator()(double t) const;
200  double GetOverThresholdTimeSpan() const;
209  double operator()(double* x, double* p) const;
211  Discriminator(const Discriminator& d);
212  private:
214  template<class Functor>
215  Discriminator(const Channel& c, const Functor& f, double beginTime, double endTime) :
216  fChannel(c),
217  /*
218  * Exception Safety Note: We're initiliazing a std::auto_ptr here, with
219  * a constructor that doesn't throw exceptions.
220  * Also the constructor called by the new expression also doesn't throw
221  * exceptions, it just binds a reference.
222  * And, of course, being a auto_ptr it handles its resource.
223  * See Guru Of the Week "Constructor Failures" at
224  * http://www.gotw.ca/gotw/066.htm.
225  */
226  fInputPulse(new Proxy<Functor>(f)),
228  / c.GetSlewRate()),
229  fBeginTime(beginTime),
230  fEndTime(endTime)
231  {
232  // Define this constructor here due to being a template.
233  // Delegate initialization to the helper method.
234  Init();
235  }
237  void Init();
239  bool OverThreshold(double t) const;
241  double ApplySaturation(double v) const;
243  double ComputeOutput(double signReferenceTime, double deltaTime, double prevOutput) const;
245  template<class Iterator>
246  double ComputeBorderTime(Iterator beg, Iterator end, double time) const;
250  const std::unique_ptr<Callable> fInputPulse;
254  double fBeginTime;
256  double fEndTime;
261  };
262 
263  static const char* const kComponentName;
264 
265  static const char* const kComponentId;
269  const FrontEnd& GetFrontEnd() const { return fFrontEnd; }
297  double GetThreshold() const;
307  std::complex<double> ComputeTransfer(double freq) const;
324  double ComputeSignalShift() const;
338  double GetSignalShiftMean() const;
343  double GetSignalShiftStdDev() const;
352  template <class Functor>
353  Discriminator
354  MakeDiscriminator(const Functor& inputPulse, double beginTime, double endTime)
355  const
356  {
357  // Note that tough we're returning by-value it's likely that no copies will be made:
358  // The (good) compilers likely optimize away the unnecessary temporaries.
359  // Nevertheless, despite being not called at last, the copy constructor needs to
360  // be visible from the calling point (ie we cannot privatize it).
361  //
362  // Also note that we're using an auto_ptr to handle the proxy:
363  // if there were copies involved, remember that when copying auto_ptr s
364  // we don't get equivalent objects: the pointed-to object ownership
365  // passes to the target of the copy (and the source doesn't own it anymore:
366  // we don't get a deadly double deletion).
367  // See
368  // http://www.aristeia.com/BookErrata/auto_ptr-update.html,
369  // http://www.gotw.ca/gotw/025.htm and
370  // http://www.gotw.ca/publications/using_auto_ptr_effectively.htm (beware
371  // that this last one is outdated in some aspects).
372  return Discriminator(*this, inputPulse, beginTime, endTime);
373  }
374  private:
375  /*
376  * Properties that characterize the amplification
377  * stage (with its frequency response). The
378  * idea is that client code doesn't access
379  * to this properties.
380  * Instead the client code would provide a signal
381  * and in this class (through this, or any other
382  * mean) would give the output-response to that
383  * given signal by the channel.
384  */
388  double GetInvertingInputResistance() const;
392  double GetFeedbackResistance() const;
396  double GetDCGain() const;
400  double GetLowCutoffFrequency() const;
404  double GetHighCutoffFrequency() const;
405  /*
406  * Propeties that characterize the discrimination stage.
407  * The output signal of the discriminator is ideally a
408  * two valued continuous wave. This two values are set
409  * according to the comparisson with the threshold,
410  * the hi value level meaning that the signal was
411  * greater than the threshold and viceversa.
412  * In reality, the signal has a finite transition time
413  * between states, and finite stabilization times.
414  */
419  double GetDiscriminatorLowLevel() const;
424  double GetDiscriminatorHiLevel() const;
431  double GetSlewRate() const;
438  double GetResponseTime() const;
451  double GetAbsoluteError() const;
460  double GetInitialIntervalLength() const;
466  unsigned int GetIterationsNumber() const;
472  unsigned int GetMaxNumberOfErrors() const;
480  std::complex<double> ComputeFrequencyFactor(double freq, double freqLimit) const;
496  Channel(int cId, const det::VManager::IndexMap& parentMap, const FrontEnd& parent);
500  ~Channel() { }
504  friend struct det::ParentCreator;
510  template<class T>
511  friend void boost::checked_delete(T*) BOOST_NOEXCEPT;
513  friend struct det::ComponentUpdater;
514  /*
515  * As told by Manuel Platino, there could be a parasite capacitance
516  * in parallel with the op-amp amplification circuit.
517  */
518  mutable utl::Validated<double> fInvertingInputResistance;
519 
520  mutable utl::Validated<double> fFeedbackResistance;
521 
522  mutable utl::Validated<double> fDCGain;
523 
524  mutable utl::Validated<double> fLowCutoffFrequency;
525 
526  mutable utl::Validated<double> fHighCutoffFrequency;
527 
528  mutable utl::Validated<double> fThreshold;
529 
530  mutable utl::Validated<double> fResponseTime;
531 
532  mutable utl::Validated<double> fDiscriminatorLowLevel;
533 
534  mutable utl::Validated<double> fDiscriminatorHiLevel;
535 
536  mutable utl::Validated<double> fSlewRate;
537 
538  mutable utl::Validated<double> fAbsoluteError;
539 
540  mutable utl::Validated<double> fInitialIntervalLength;
541 
542  // Used int instead of unsigned due to lack of an specific overload for the later.
543  mutable utl::Validated<int> fIterationsNumber;
544 
545  // Idem.
546  mutable utl::Validated<int> fMaxNumberOfErrors;
547 
548  mutable utl::Validated<double> fSignalShiftMean;
549 
550  mutable utl::Validated<double> fSignalShiftStdDev;
551 
553 
554  };
555 
556 }
557 
558 
559 #endif
double ComputeOutput(double signReferenceTime, double deltaTime, double prevOutput) const
Compute final output for a give time difference.
AtThresholdConstIterator AtThresholdBegin() const
Begin iterator over times.
static const char *const kComponentName
utl::Validated< double > fSlewRate
utl::Validated< double > fResponseTime
utl::Validated< double > fSignalShiftStdDev
utl::Validated< double > fLowCutoffFrequency
utl::Validated< double > fDiscriminatorLowLevel
const FrontEnd & fFrontEnd
int freq
Definition: dump1090.h:244
const Channel & fChannel
The channel where to apply the discrimination.
bool OverThreshold(double t) const
Check input agains threshold.
Callback interface wrapping the access to the underlying functor providing the input pulse...
virtual double operator()(double t) const =0
Define the interface via which we will make the calls.
Defines within it the common (templated) type for muon detector hierarchy components.
double GetInitialIntervalLength() const
Lenght of the intervals (in time) in which divide the whole interval where roots are looked for...
void Init()
Perform initialization.
double operator()(double t) const
Define the interface via which we will make the calls.
unsigned int GetMaxNumberOfErrors() const
Maximum number of errors admited without loggin when solving the equation threshold == input...
RawRootsContainer fRawRoots
Plain root value (only times).
double ComputeSignalShift() const
Computes a signal shift value according this Channel&#39;s characteristics (and, particularly, to the distribution of these values).
double GetFeedbackResistance() const
The resistance within the feedback loop.
Helper class encapsulating the discriminator response logic.
const FrontEnd & GetFrontEnd() const
The shared common-to-all-channels electronic frontend of this channel.
Electronic front-end for the modules.
Definition: FrontEnd.h:33
Eletronic channel.
double ComputeBorderTime(Iterator beg, Iterator end, double time) const
Helper templated function to calculate the times that define the total span.
double fTransitionTime
Maximum time required to switch between states.
virtual ~Callable()
The deletion of the objects will be made through a Callable*.
RootContainer fRoots
Once and for all calculate the roots given the input pulse.
double GetResponseTime() const
Response time of the discriminator associated with the channel.
Discriminator(const Channel &c, const Functor &f, double beginTime, double endTime)
Templated constructor with the generic functor.
double GetHighCutoffFrequency() const
Hi end of frequency response.
utl::Validated< double > fThreshold
utl::Validated< double > fSignalShiftMean
double GetDCGain() const
A dimensionless quantity signaling the DC gain.
friend void boost::checked_delete(T *) BOOST_NOEXCEPT
Friendship for destruction.
double GetSlewRate() const
Voltage change per time unit.
Channel(int cId, const det::VManager::IndexMap &parentMap, const FrontEnd &parent)
Constructs the electronic channel.
double fTime
The x value (that&#39;s the root of the equation input == threshold).
std::complex< double > ComputeTransfer(double freq) const
Computes the circuit transfer function at the given frequency.
utl::Validated< int > fMaxNumberOfErrors
Discriminator const
Create a fresh discriminator.
static const char *const kComponentId
utl::Validated< int > fIterationsNumber
double fOutput
The y value (that&#39;s the output voltage while in the associated time).
Templated specialization of the mdet::Channel::Discriminator::Callable interface. ...
utl::Validated< double > fAbsoluteError
RawRootsContainer::const_iterator AtThresholdConstIterator
Iterator over the times when the input signal reaches the threshold level.
double GetDiscriminatorLowLevel() const
Target voltage when the signal is lower than the threshold.
std::vector< Root > RootContainer
Container for the roots (time + output).
virtual Callable * Clone() const =0
To allow proper copy semantics (see implemetation).
utl::Validated< double > fDCGain
double GetSignalShiftMean() const
Retrieves the mean shift.
double GetSignalShiftStdDev() const
The standard deviation of the shift.
double fBeginTime
Define the relevant interval start time.
const VManager::Status f
double GetOverThresholdTimeSpan() const
Return the total time span over the discrimination threshold.
double GetInvertingInputResistance() const
The resistance attached to the inverting input.
unsigned int GetIterationsNumber() const
Number of iterations allowed for the root finding procedures.
AtThresholdConstIterator AtThresholdEnd() const
End iterator over times.
std::map< std::string, std::string > IndexMap
Definition: VManager.h:133
std::vector< double > RawRootsContainer
const std::unique_ptr< Callable > fInputPulse
The input pulse where to apply the discrimination.
double GetLowCutoffFrequency() const
Low end of frequency response.
double GetAbsoluteError() const
Absolute error for root finding.
utl::Validated< double > fFeedbackResistance
double operator()(double t) const
Evaluate the discriminator output given the input pulse.
std::complex< double > ComputeFrequencyFactor(double freq, double freqLimit) const
Helper method to compute the factor (in the transfer function) that depends on frequency.
RootContainer::const_iterator RootIterator
Iterator over our roots struct.
double ApplySaturation(double v) const
Compute the final output for a given difference agains the threshold.
utl::Validated< double > fHighCutoffFrequency
utl::Validated< double > fInvertingInputResistance
utl::Validated< double > fInitialIntervalLength
Type
The type of file that we are acutally opening.
Definition: IoCodes.h:33
~Channel()
Destructor (!).
double GetThreshold() const
Discrimination threshold.
double fEndTime
Define the relevant interval final time.
utl::Validated< double > fDiscriminatorHiLevel
Discriminator(const Discriminator &d)
Copy.
double GetDiscriminatorHiLevel() const
Target voltage when the signal is higher than the threshold.
The child the information from the parent upon construction.

, generated on Tue Sep 26 2023.