Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:58:04

0001 #ifndef CalibCalorimetry_HcalAlgos_AbsElectronicODERHS_h_
0002 #define CalibCalorimetry_HcalAlgos_AbsElectronicODERHS_h_
0003 
0004 #include <vector>
0005 #include <climits>
0006 #include <algorithm>
0007 
0008 #include "CalibCalorimetry/HcalAlgos/interface/AbsODERHS.h"
0009 #include "CondFormats/HcalObjects/interface/HcalInterpolatedPulse.h"
0010 
0011 //
0012 // Modeling of electronic circuits always involves an input pulse that
0013 // determines the circuit output. This class adds an input pulse to
0014 // AbsODERHS and establishes a uniform interface to circuit parameters.
0015 //
0016 class AbsElectronicODERHS : public AbsODERHS {
0017 public:
0018   static const unsigned invalidNode = UINT_MAX - 1U;
0019 
0020   inline AbsElectronicODERHS() : initialized_(false), allSet_(false) {}
0021 
0022   inline explicit AbsElectronicODERHS(const HcalInterpolatedPulse& pulse) : inputPulse_(pulse) {}
0023 
0024   inline ~AbsElectronicODERHS() override {}
0025 
0026   inline const HcalInterpolatedPulse& inputPulse() const { return inputPulse_; }
0027 
0028   inline HcalInterpolatedPulse& inputPulse() { return inputPulse_; }
0029 
0030   template <class Pulse>
0031   inline void setInputPulse(const Pulse& pulse) {
0032     inputPulse_ = pulse;
0033   }
0034 
0035   // The following methods must be overriden by derived classes.
0036   // Total number of nodes included in the simulation:
0037   virtual unsigned numberOfNodes() const = 0;
0038 
0039   // The node which counts as "output" (preamp output in case
0040   // of QIE8, which is not necessarily the node which accumulates
0041   // the charge):
0042   virtual unsigned outputNode() const = 0;
0043 
0044   // The node which counts as "control". If this method returns
0045   // "invalidNode" then there is no such node in the circuit.
0046   virtual unsigned controlNode() const { return invalidNode; }
0047 
0048   // The number of simulation parameters:
0049   virtual unsigned nParameters() const = 0;
0050 
0051   // Check if all parameters have been set
0052   inline bool allParametersSet() const {
0053     // Raise "allSet_" flag if all parameters have been set
0054     if (!allSet_) {
0055       const unsigned nExpected = this->nParameters();
0056       if (nExpected) {
0057         if (paramMask_.size() != nExpected)
0058           return false;
0059         unsigned count = 0;
0060         const unsigned char* mask = &paramMask_[0];
0061         for (unsigned i = 0; i < nExpected; ++i)
0062           count += mask[i];
0063         allSet_ = count == nExpected;
0064       } else
0065         allSet_ = true;
0066     }
0067     return allSet_;
0068   }
0069 
0070   inline void setParameter(const unsigned which, const double value) {
0071     if (!initialized_)
0072       initialize();
0073     paramMask_.at(which) = 1;
0074     params_[which] = value;
0075   }
0076 
0077   inline double getParameter(const unsigned which) const {
0078     if (!paramMask_.at(which))
0079       throw cms::Exception(
0080           "In AbsElectronicODERHS::getParameter: no such parameter or "
0081           "parameter value is not established yet");
0082     return params_[which];
0083   }
0084 
0085   inline const std::vector<double>& getAllParameters() const {
0086     if (!allParametersSet())
0087       throw cms::Exception(
0088           "In AbsElectronicODERHS::getAllParameters: "
0089           "some parameter values were not established yet");
0090     return params_;
0091   }
0092 
0093   inline void setLeadingParameters(const double* values, const unsigned len) {
0094     if (len) {
0095       assert(values);
0096       if (!initialized_)
0097         initialize();
0098       const unsigned sz = params_.size();
0099       const unsigned imax = std::min(sz, len);
0100       for (unsigned i = 0; i < imax; ++i) {
0101         params_[i] = values[i];
0102         paramMask_[i] = 1;
0103       }
0104     }
0105   }
0106 
0107   inline void setLeadingParameters(const std::vector<double>& values) {
0108     if (!values.empty())
0109       setLeadingParameters(&values[0], values.size());
0110   }
0111 
0112 protected:
0113   HcalInterpolatedPulse inputPulse_;
0114   std::vector<double> params_;
0115 
0116 private:
0117   std::vector<unsigned char> paramMask_;
0118   bool initialized_;
0119   mutable bool allSet_;
0120 
0121   inline void initialize() {
0122     const unsigned nExpected = this->nParameters();
0123     if (nExpected) {
0124       params_.resize(nExpected);
0125       paramMask_.resize(nExpected);
0126       for (unsigned i = 0; i < nExpected; ++i)
0127         paramMask_[i] = 0;
0128     }
0129     initialized_ = true;
0130   }
0131 };
0132 
0133 #endif  // CalibCalorimetry_HcalAlgos_AbsElectronicODERHS_h_