// @(#)root/hist:$Id$
// Author: L. Moneta May 2015

/**********************************************************************
 *                                                                    *
 * Copyright (c) 2015  ROOT  Team, CERN/PH-SFT                        *
 *                                                                    *
 *                                                                    *
 **********************************************************************/
//
//  TF1NormSum.h
//  
//
//  Created by Aurélie Flandi on 27.08.14.
//
//

#ifndef ROOT_TF1NormSum__
#define ROOT_TF1NormSum__

#include <iostream>
#include "TF1.h"
#include <memory>

//class adding two functions: c1*f1+c2*f2
class TF1NormSum {
   
protected:

   // vector market as temp data member could probably be removed 
   
   unsigned int fNOfFunctions;               //! Number of functions to add
   //int> p1(new int(5));
   Double_t     fScale;                      // Fixed Scale parameter to normalize function (e.g. bin width)
   std::vector < std::shared_ptr < TF1 > > fFunctions;     // Vector of size fNOfFunctions containing TF1 functions
   std::vector < Double_t  > fCoeffs;        // Vector of size afNOfFunctions containing coefficients in front of each function
//   std::vector < Int_t     > fNOfParams;     //! Vector of size fNOfFunctions containing number of parameters for each function (does not contain the coefficients!)
//   std::vector < Int_t     > fNOfNonCstParams;  // Vector of  size fNOfFunctions containing the indices of the non-const parameter of each function
//   std::vector < Double_t *  > fParams;     //! Vector of size [fNOfFunctions][Function_p] containing an array of all function parameters
                                             // (non including coefficients) for each function
   std::vector < Int_t     > fCstIndexes;    // vector with size of fNOfFunctions containing the index of the constant parameter/ function (the removed ones) 
   std::vector< TString >    fParNames;      // parameter names 
   
   void InitializeDataMembers(const std::vector <std::shared_ptr < TF1 >> &functions, const std::vector <Double_t> &coeffs, Double_t scale); // acts as a constrcutor
   
   //smart pointer
public:
   
   TF1NormSum();
   TF1NormSum(const std::vector <TF1*>&functions, const std::vector <Double_t> &coeffs, Double_t scale = 1.);
   TF1NormSum(TF1* function1, TF1* function2, Double_t coeff1 = 1., Double_t coeff2 = 1., Double_t scale = 1.);
   TF1NormSum(TF1* function1, TF1* function2, TF1*function3, Double_t coeff1 = 1., Double_t coeff2 = 1., Double_t coeff3 = 1., Double_t scale = 1.);
   TF1NormSum(const TString &formula, Double_t xmin, Double_t xmax);
   
   double  operator()(double* x, double* p);

   std::vector<double> GetParameters() const;

   void      SetScale(Double_t scale) { fScale = scale; };
   
   void      SetParameters(const double* params);
   
   void      SetParameters(Double_t p0, Double_t p1, Double_t p2=0., Double_t p3=0., Double_t p4=0.,
                                   Double_t p5=0., Double_t p6=0., Double_t p7=0., Double_t p8=0., Double_t p9=0., Double_t p10=0.);
   
   Int_t             GetNpar() const;
   
   Double_t             GetScale() const { return fScale; }

   const char *      GetParName(Int_t ipar) const { return fParNames.at(ipar).Data(); }
   
   //ClassDef(TF1NormSum,1)
   
};
#endif /* defined(ROOT_TF1NormSum__) */
 TF1NormSum.h:1
 TF1NormSum.h:2
 TF1NormSum.h:3
 TF1NormSum.h:4
 TF1NormSum.h:5
 TF1NormSum.h:6
 TF1NormSum.h:7
 TF1NormSum.h:8
 TF1NormSum.h:9
 TF1NormSum.h:10
 TF1NormSum.h:11
 TF1NormSum.h:12
 TF1NormSum.h:13
 TF1NormSum.h:14
 TF1NormSum.h:15
 TF1NormSum.h:16
 TF1NormSum.h:17
 TF1NormSum.h:18
 TF1NormSum.h:19
 TF1NormSum.h:20
 TF1NormSum.h:21
 TF1NormSum.h:22
 TF1NormSum.h:23
 TF1NormSum.h:24
 TF1NormSum.h:25
 TF1NormSum.h:26
 TF1NormSum.h:27
 TF1NormSum.h:28
 TF1NormSum.h:29
 TF1NormSum.h:30
 TF1NormSum.h:31
 TF1NormSum.h:32
 TF1NormSum.h:33
 TF1NormSum.h:34
 TF1NormSum.h:35
 TF1NormSum.h:36
 TF1NormSum.h:37
 TF1NormSum.h:38
 TF1NormSum.h:39
 TF1NormSum.h:40
 TF1NormSum.h:41
 TF1NormSum.h:42
 TF1NormSum.h:43
 TF1NormSum.h:44
 TF1NormSum.h:45
 TF1NormSum.h:46
 TF1NormSum.h:47
 TF1NormSum.h:48
 TF1NormSum.h:49
 TF1NormSum.h:50
 TF1NormSum.h:51
 TF1NormSum.h:52
 TF1NormSum.h:53
 TF1NormSum.h:54
 TF1NormSum.h:55
 TF1NormSum.h:56
 TF1NormSum.h:57
 TF1NormSum.h:58
 TF1NormSum.h:59
 TF1NormSum.h:60
 TF1NormSum.h:61
 TF1NormSum.h:62
 TF1NormSum.h:63
 TF1NormSum.h:64
 TF1NormSum.h:65
 TF1NormSum.h:66
 TF1NormSum.h:67
 TF1NormSum.h:68
 TF1NormSum.h:69
 TF1NormSum.h:70
 TF1NormSum.h:71
 TF1NormSum.h:72
 TF1NormSum.h:73
 TF1NormSum.h:74
 TF1NormSum.h:75