Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:31:29

0001 #ifndef GSUtilities_h
0002 #define GSUtilities_h
0003 
0004 /** Some utilities for analysing 1D Gaussian mixtures.
0005  * Copied from ORCA's EgammaGSUtilities.
0006  */
0007 
0008 class GSUtilities {
0009 public:
0010   /// constructor from arrays of weights, parameters and standard deviations
0011   GSUtilities(const unsigned nComp, const float* weights, const float* parameters, const float* errors)
0012       : theNComp(nComp), theWeights(nullptr), theParameters(nullptr), theErrors(nullptr) {
0013     if (theNComp) {
0014       theWeights = new float[theNComp];
0015       theParameters = new float[theNComp];
0016       theErrors = new float[theNComp];
0017     }
0018     const float* wPtr1(weights);
0019     const float* pPtr1(parameters);
0020     const float* ePtr1(errors);
0021     float* wPtr2(theWeights);
0022     float* pPtr2(theParameters);
0023     float* ePtr2(theErrors);
0024     for (unsigned i = 0; i < theNComp; i++) {
0025       *(wPtr2++) = weights ? *(wPtr1++) : 1.;
0026       *(pPtr2++) = *(pPtr1++);
0027       *(ePtr2++) = *(ePtr1++);
0028     }
0029   }
0030   ~GSUtilities() {
0031     delete[] theWeights;
0032     delete[] theParameters;
0033     delete[] theErrors;
0034   }
0035   /** normalised integral from -inf to x
0036    *  (taking into account under- & overflows) 
0037    */
0038   float quantile(const float) const;
0039   /// mode
0040   float mode() const;
0041   /// value of the pdf
0042   double pdf(const double&) const;
0043   /// value of integral(pdf)
0044   double cdf(const double&) const;
0045   /// first derivative of pdf
0046   double dpdf1(const double&) const;
0047   /// second derivative of pdf
0048   double dpdf2(const double&) const;
0049 
0050   /// mean value of combined state
0051   double combinedMean() const;
0052   //  mean value of errors
0053   double errorCombinedMean() const;
0054   //  error for the highest weight
0055   float errorHighestWeight() const;
0056   // max weight component - chiara
0057   float maxWeight() const;
0058   // mode error + some utilities functions
0059   float errorMode();
0060   float getMax(float);
0061   float getMin(float);
0062 
0063 private:
0064   /// value of gaussian distribution
0065   double gauss(const double&, const double&, const double&) const;
0066   /// integrated value of gaussian distribution
0067   double gaussInt(const double&, const double&, const double&) const;
0068   /// mean value of combined state
0069   /// double combinedMean() const;
0070   /// mode from starting value
0071   double findMode(const double) const;
0072 
0073 private:
0074   unsigned theNComp;
0075   float* theWeights;
0076   float* theParameters;
0077   float* theErrors;
0078 };
0079 #endif