JHUGen MELA  JHUGen v7.5.6, MELA v2.4.2
Matrix element calculations as used in JHUGen.
MELANCSplineCore.cc
Go to the documentation of this file.
1 #include "MELANCSplineCore.h"
2 #include <cmath>
3 #include "TMath.h"
4 #include "TIterator.h"
5 #include "Riostream.h"
6 
7 using namespace TMath;
8 using namespace RooFit;
9 using namespace std;
10 using namespace TNumericUtil;
11 
12 
14 
16 RooAbsReal(),
17 verbosity(MELANCSplineCore::kSilent),
18 useFloor(true), floorEval(0), floorInt(0),
19 rangeXmin(1), rangeXmax(-1),
20 theXVar("theXVar", "theXVar", this),
21 leafDepsList("leafDepsList", "leafDepsList", this)
22 {}
23 
25  const char* name,
26  const char* title
27  ) :
28  RooAbsReal(name, title),
29  verbosity(MELANCSplineCore::kSilent),
30  useFloor(true), floorEval(0), floorInt(0),
31  rangeXmin(1), rangeXmax(-1),
32  theXVar("theXVar", "theXVar", this),
33  leafDepsList("leafDepsList", "leafDepsList", this)
34 {}
35 
37  const char* name,
38  const char* title,
39  RooAbsReal& inXVar,
40  const std::vector<T>& inXList,
41  Bool_t inUseFloor,
42  T inFloorEval,
43  T inFloorInt
44  ) :
45  RooAbsReal(name, title),
46  verbosity(MELANCSplineCore::kSilent),
47  useFloor(inUseFloor), floorEval(inFloorEval), floorInt(inFloorInt),
48  rangeXmin(1), rangeXmax(-1),
49  theXVar("theXVar", "theXVar", this, inXVar),
50  leafDepsList("leafDepsList", "leafDepsList", this),
51  XList(inXList)
52 {}
53 
55  const MELANCSplineCore& other,
56  const char* name
57  ) :
58  RooAbsReal(other, name),
59  verbosity(other.verbosity),
60  useFloor(other.useFloor), floorEval(other.floorEval), floorInt(other.floorInt),
61  rangeXmin(other.rangeXmin), rangeXmax(other.rangeXmax),
62  theXVar("theXVar", this, other.theXVar),
63  leafDepsList("leafDepsList", this, other.leafDepsList),
64  XList(other.XList)
65 {}
66 
70 void MELANCSplineCore::doFloor(Bool_t flag){ useFloor = flag; }
71 
72 void MELANCSplineCore::getBArray(const std::vector<MELANCSplineCore::T>& kappas, const vector<MELANCSplineCore::T>& fcnList, std::vector<MELANCSplineCore::T>& BArray, BoundaryCondition const& bcBegin, BoundaryCondition const& bcEnd)const{
73  BArray.clear();
74  int npoints=kappas.size();
75  if (npoints!=(int)fcnList.size()){
76  coutE(InputArguments) << "MELANCSplineCore::getBArray: Dim(kappas)=" << npoints << " != Dim(fcnList)=" << fcnList.size() << endl;
77  assert(0);
78  }
79  if (
81  ||
82  bcBegin==bcQuadratic || bcEnd==bcQuadratic
83  ){
84  int nthr=1+(bcBegin==bcQuadraticWithNullSlope || bcBegin==bcQuadratic ? 1 : 0) + (bcEnd==bcQuadraticWithNullSlope || bcEnd==bcQuadratic ? 1 : 0);
85  if (npoints<=nthr){
86  cerr << "Npoints " << npoints << " <= " << nthr << endl;
87  assert(0);
88  }
89  }
90  if (npoints>1){
91  MELANCSplineCore::T bcval=0, ecval=0;
92  // First point constraint
93  switch (bcBegin){
95  bcval=(npoints<3 ? 0 : ((fcnList.at(2)-fcnList.at(1))*kappas.at(1)-(fcnList.at(1)-fcnList.at(0))*kappas.at(0))/(0.5/kappas.at(0)+0.5/kappas.at(1)));
96  case bcNaturalSpline:
97  BArray.push_back(3.*(fcnList.at(1)-fcnList.at(0)) - bcval/2./pow(kappas.at(0), 2));
98  break;
100  bcval=(fcnList.at(1)-fcnList.at(0))*kappas.at(0);
101  case bcClamped:
102  BArray.push_back(bcval/kappas.at(0));
103  break;
104  case bcQuadratic:
105  bcval=2.*(fcnList.at(1)-fcnList.at(0));
106  BArray.push_back(bcval);
107  break;
109  bcval=2.*(fcnList.at(1)-fcnList.at(0));
110  BArray.push_back(0);
111  BArray.push_back(bcval*kappas.at(0)/kappas.at(1));
112  break;
113  default:
114  cerr << "MELANCSplineCore::getBArray: bcBegin " << bcBegin << " is not implemented!" << endl;
115  assert(0);
116  }
117  // Intermediate point constraint is always D0, D1 and D2 continuous
118  for (int j=1; j<npoints-1; j++){
119  if (j==1 && bcBegin==bcQuadraticWithNullSlope) continue;
120  if (j==npoints-2 && bcEnd==bcQuadraticWithNullSlope) continue;
121  MELANCSplineCore::T val_j = fcnList.at(j);
122  MELANCSplineCore::T val_jpo = fcnList.at(j+1);
123  MELANCSplineCore::T val_jmo = fcnList.at(j-1);
124  MELANCSplineCore::T kappa_j = kappas.at(j);
125  MELANCSplineCore::T kappa_jmo = kappas.at(j-1);
126  MELANCSplineCore::T rsq = pow(kappa_j/kappa_jmo, 2);
127  MELANCSplineCore::T Bval = val_jpo*rsq + val_j*(1.-rsq) - val_jmo;
128  Bval *= 3.;
129  BArray.push_back(Bval);
130  }
131  // Last point constraint
132  switch (bcEnd){
134  ecval=(npoints<3 ? 0 : ((fcnList.at(npoints-1)-fcnList.at(npoints-2))*kappas.at(npoints-2)-(fcnList.at(npoints-2)-fcnList.at(npoints-3))*kappas.at(npoints-3))/(0.5/kappas.at(npoints-3)+0.5/kappas.at(npoints-2)));
135  case bcNaturalSpline:
136  BArray.push_back(3.*(fcnList.at(npoints-1)-fcnList.at(npoints-2)) + ecval/2./pow(kappas.at(npoints-1), 2));
137  break;
138  case bcApproximatedSlope:
139  ecval=(fcnList.at(npoints-1)-fcnList.at(npoints-2))*kappas.at(npoints-2);
140  case bcClamped:
141  BArray.push_back(ecval/kappas.at(npoints-1));
142  break;
143  case bcQuadratic:
144  ecval=2.*(fcnList.at(npoints-1)-fcnList.at(npoints-2));
145  BArray.push_back(ecval);
146  break;
148  ecval=2.*(fcnList.at(npoints-1)-fcnList.at(npoints-2));
149  BArray.push_back(ecval);
150  BArray.push_back(0);
151  break;
152  default:
153  cerr << "MELANCSplineCore::getAArray: bcEnd " << bcEnd << " is not implemented!" << endl;
154  assert(0);
155  }
156  }
157  else if (npoints==1) BArray.push_back(0);
158 }
159 void MELANCSplineCore::getAArray(const vector<MELANCSplineCore::T>& kappas, vector<vector<MELANCSplineCore::T>>& AArray, BoundaryCondition const& bcBegin, BoundaryCondition const& bcEnd)const{
160  AArray.clear();
161  Int_t npoints = kappas.size();
162  for (int i=0; i<npoints; i++){
163  vector<MELANCSplineCore::T> Ai(npoints, 0.);
164  if (npoints==1) Ai[0]=1;
165  else if (i==0){
166  switch(bcBegin){
167  case bcNaturalSpline:
169  Ai[0]=2; Ai[1]=kappas.at(1)/kappas.at(0);
170  break;
171  case bcClamped:
172  case bcApproximatedSlope:
174  Ai[0]=1;
175  break;
176  case bcQuadratic:
177  Ai[0]=1; Ai[1]=kappas.at(1)/kappas.at(0);
178  break;
179  default:
180  cerr << "MELANCSplineCore::getAArray: bcBegin " << bcBegin << " is not implemented!" << endl;
181  assert(0);
182  }
183  }
184  else if (i==npoints-1){
185  switch(bcEnd){
186  case bcNaturalSpline:
188  Ai[npoints-2]=1; Ai[npoints-1]=2.*kappas.at(npoints-1)/kappas.at(npoints-2);
189  break;
190  case bcClamped:
191  case bcApproximatedSlope:
193  Ai[npoints-1]=1;
194  break;
195  case bcQuadratic:
196  Ai[npoints-2]=1; Ai[npoints-1]=kappas.at(npoints-1)/kappas.at(npoints-2);
197  break;
198  default:
199  cerr << "MELANCSplineCore::getAArray: bcEnd " << bcEnd << " is not implemented!" << endl;
200  assert(0);
201  }
202  }
203  else{
204  if ((i==1 && bcBegin==bcQuadraticWithNullSlope) || (i==npoints-2 && bcEnd==bcQuadraticWithNullSlope)) Ai[i]=1;
205  else{
206  MELANCSplineCore::T kappa_j = kappas.at(i);
207  MELANCSplineCore::T kappa_jmo = kappas.at(i-1);
208  MELANCSplineCore::T kappa_jpo = kappas.at(i+1);
209 
210  Ai[i-1]=1;
211  Ai[i]=2.*kappa_j/kappa_jmo*(1.+kappa_j/kappa_jmo);
212  Ai[i+1]=kappa_j*kappa_jpo/pow(kappa_jmo, 2);
213  }
214  }
215  AArray.push_back(Ai);
216  }
217 }
218 
219 vector<MELANCSplineCore::T> MELANCSplineCore::getCoefficients(const TVector_t& S, const vector<MELANCSplineCore::T>& kappas, const vector<MELANCSplineCore::T>& fcnList, const Int_t& bin)const{
221  vector<MELANCSplineCore::T> res;
222 
223  const int fcnsize = fcnList.size();
224  if (fcnsize>bin){
225  A=fcnList.at(bin);
226  B=S[bin];
227  if (fcnsize>(bin+1)){
228  DefaultAccumulator<MELANCSplineCore::T> dFcn = fcnList.at(bin+1);
229  dFcn -= A;
230 
231  C += MELANCSplineCore::T(3.)*dFcn;
232  C -= 2.*B;
233  C -= S[bin+1]*kappas.at(bin+1)/kappas.at(bin);
234 
235  D += MELANCSplineCore::T(-2.)*dFcn;
236  D += B;
237  D += S[bin+1]*kappas.at(bin+1)/kappas.at(bin);
238  }
239  }
240 
241  res.push_back(A);
242  res.push_back(B);
243  res.push_back(C);
244  res.push_back(D);
245  return res;
246 }
247 vector<vector<MELANCSplineCore::T>> MELANCSplineCore::getCoefficientsAlongDirection(const std::vector<MELANCSplineCore::T>& kappas, const TMatrix_t& Ainv, const vector<MELANCSplineCore::T>& fcnList, BoundaryCondition const& bcBegin, BoundaryCondition const& bcEnd, const Int_t pickBin)const{
248  vector<MELANCSplineCore::T> BArray;
249  getBArray(kappas, fcnList, BArray, bcBegin, bcEnd);
250 
251  Int_t npoints = BArray.size();
252  TVector_t Btrans(npoints);
253  for (int i=0; i<npoints; i++) Btrans[i]=BArray.at(i);
254  TVector_t Strans = Ainv*Btrans;
255 
256  vector<vector<MELANCSplineCore::T>> coefs;
257  for (Int_t bin=0; bin<(npoints>1 ? npoints-1 : 1); bin++){
258  if (pickBin>=0 && bin!=pickBin) continue;
259  vector<MELANCSplineCore::T> coef = getCoefficients(Strans, kappas, fcnList, bin);
260  coefs.push_back(coef);
261  }
262  return coefs;
263 }
264 
265 MELANCSplineCore::T MELANCSplineCore::evalSplineSegment(const std::vector<MELANCSplineCore::T>& coefs, const MELANCSplineCore::T& kappa, const MELANCSplineCore::T& tup, const MELANCSplineCore::T& tdn, Bool_t doIntegrate)const{
267  for (unsigned int ic=0; ic<coefs.size(); ic++){
268  if (doIntegrate) res += coefs.at(ic)*(pow(tup, (int)(ic+1))-pow(tdn, (int)(ic+1)))/((MELANCSplineCore::T)(ic+1));
269  else res += coefs.at(ic)*pow(tup, (int)ic);
270  }
271  if (doIntegrate) res /= kappa;
272  return res;
273 }
274 
275 void MELANCSplineCore::getLeafDependents(RooRealProxy& proxy, RooArgSet& set){
276  RooArgSet deps;
277  proxy.absArg()->leafNodeServerList(&deps, 0, true);
278  set.add(deps);
279 }
281  TIterator* iter = set.createIterator();
282  RooAbsArg* absarg;
283  while ((absarg = (RooAbsArg*)iter->Next())){ if (dynamic_cast<RooRealVar*>(absarg)) leafDepsList.add(*absarg); }
284  delete iter;
285 }
MELANCSplineCore::T
Float_t T
Definition: MELANCSplineCore.h:18
MELANCSplineCore::VerbosityLevel
VerbosityLevel
Definition: MELANCSplineCore.h:22
MELANCSplineCore::setIntFloor
void setIntFloor(T val)
Definition: MELANCSplineCore.cc:69
TNumericUtil::KahanAccumulator
Definition: MELAAccumulators.h:27
MELANCSplineCore::setEvalFloor
void setEvalFloor(T val)
Definition: MELANCSplineCore.cc:68
ClassImp
ClassImp(MELANCSplineCore) MELANCSplineCore
Definition: MELANCSplineCore.cc:13
MELANCSplineCore::getLeafDependents
void getLeafDependents(RooRealProxy &proxy, RooArgSet &set)
Definition: MELANCSplineCore.cc:275
MELANCSplineCore::BoundaryCondition
BoundaryCondition
Definition: MELANCSplineCore.h:28
MELANCSplineCore::bcQuadraticWithNullSlope
@ bcQuadraticWithNullSlope
Definition: MELANCSplineCore.h:34
MELANCSplineCore::setVerbosity
virtual void setVerbosity(VerbosityLevel flag)
Definition: MELANCSplineCore.cc:67
set
set(CMAKE_MACOSX_RPATH 1) set(CMAKE_CACHEFILE_DIR CMakeFiles/) cmake_minimum_required(VERSION 2.8) project(collier) enable_language(Fortran) get_filename_component(Fortran_COMPILER_NAME $
Definition: CMakeLists.txt:65
modparameters::kappa
complex(8), public kappa
Definition: mod_Parameters.F90:882
TNumericUtil
Definition: MELAAccumulators.h:6
MELANCSplineCore::evalSplineSegment
virtual T evalSplineSegment(const std::vector< T > &coefs, const T &kappa, const T &tup, const T &tdn, Bool_t doIntegrate=false) const
Definition: MELANCSplineCore.cc:265
MELANCSplineCore::getCoefficientsAlongDirection
virtual std::vector< std::vector< T > > getCoefficientsAlongDirection(const std::vector< T > &kappas, const TMatrix_t &Ainv, const std::vector< T > &fcnList, BoundaryCondition const &bcBegin, BoundaryCondition const &bcEnd, const Int_t pickBin) const
Definition: MELANCSplineCore.cc:247
MELANCSplineCore::bcQuadratic
@ bcQuadratic
Definition: MELANCSplineCore.h:33
MELANCSplineCore::TMatrix_t
TMatrixT< T > TMatrix_t
Definition: MELANCSplineCore.h:19
MELANCSplineCore::MELANCSplineCore
MELANCSplineCore()
MELANCSplineCore
Definition: MELANCSplineCore.h:16
MELANCSplineCore::bcApproximatedSlope
@ bcApproximatedSlope
Definition: MELANCSplineCore.h:29
MELANCSplineCore::bcClamped
@ bcClamped
Definition: MELANCSplineCore.h:30
MELANCSplineCore::useFloor
Bool_t useFloor
Definition: MELANCSplineCore.h:68
MELANCSplineCore.h
MELANCSplineCore::bcNaturalSpline
@ bcNaturalSpline
Definition: MELANCSplineCore.h:32
MELANCSplineCore::floorInt
T floorInt
Definition: MELANCSplineCore.h:70
MELANCSplineCore::floorEval
T floorEval
Definition: MELANCSplineCore.h:69
MELANCSplineCore::doFloor
void doFloor(Bool_t flag)
Definition: MELANCSplineCore.cc:70
MELANCSplineCore::addLeafDependents
void addLeafDependents(RooArgSet &set)
Definition: MELANCSplineCore.cc:280
MELANCSplineCore::verbosity
VerbosityLevel verbosity
Definition: MELANCSplineCore.h:67
MELANCSplineCore::TVector_t
TVectorT< T > TVector_t
Definition: MELANCSplineCore.h:20
MELANCSplineCore::getBArray
virtual void getBArray(const std::vector< T > &kappas, const std::vector< T > &fcnList, std::vector< T > &BArray, BoundaryCondition const &bcBegin, BoundaryCondition const &bcEnd) const
Definition: MELANCSplineCore.cc:72
MELANCSplineCore::getAArray
virtual void getAArray(const std::vector< T > &kappas, std::vector< std::vector< T >> &AArray, BoundaryCondition const &bcBegin, BoundaryCondition const &bcEnd) const
Definition: MELANCSplineCore.cc:159
MELANCSplineCore::bcApproximatedSecondDerivative
@ bcApproximatedSecondDerivative
Definition: MELANCSplineCore.h:31
MELANCSplineCore::getCoefficients
virtual std::vector< T > getCoefficients(const TVector_t &S, const std::vector< T > &kappas, const std::vector< T > &fcnList, const Int_t &bin) const
Definition: MELANCSplineCore.cc:219
MELANCSplineCore::leafDepsList
RooListProxy leafDepsList
Definition: MELANCSplineCore.h:76