ROOTPWA
testPWAConstraint.cc
Go to the documentation of this file.
1 
2 //
3 // Copyright 2009 Sebastian Neubert
4 //
5 // This file is part of rootpwa
6 //
7 // rootpwa is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // rootpwa is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with rootpwa. If not, see <http://www.gnu.org/licenses/>.
19 //
21 //test program for rootpwa
22 //#include <fitlog.h>
23 //#include <integral.h>
24 #include <iostream>
25 #include <list>
26 #include <vector>
27 #include <string>
28 #include <map>
29 #include <complex>
30 #include "TBranch.h"
31 #include "TTree.h"
32 #include "TFile.h"
33 #include "TString.h"
34 #include "TComplex.h"
35 #include "TRandom.h"
36 #include "TPWALikelihood.h"
37 #include "TFitBin.h"
38 #include "TPWALikelihoodC.h"
39 
40 using namespace std;
41 
42 
43 int lineno = 1; // global variables needed for lex (not understood)
44 char *progname;
45 
46 int main(int argc, char** argv){
47 
48  TPWALikelihoodC LC;
50  unsigned int rank=1;
51  // There is one phase constraint in phase.constr!
52  LC.Init("wavelist2",rank,"norm.int","norm.int",20000,"phase.constr");
53  L.Init("wavelist2",rank,"norm.int","norm.int",20000);
54  LC.LoadAmplitudes();
55  L.LoadAmplitudes();
56  // There is one phase constraint in phase.constr!
57  cout << "LC.NDim()=" << LC.NDim() << " L.NDim()=" << L.NDim() << endl;
58  if(LC.NDim()!=L.NDim()-1)return 1;
59 
60  // 12 parameters + flat
61  // wavelist2 has 4 waves:
62  // 1-0-+0+rho770_11_pi-.amp
63  // 1-0-+0+sigma_00_pi-.amp
64  // 1-1++1-rho770_01_pi-.amp
65  // 1-1++0+sigma_10_pi-.amp
66 
67  // Re0 Re1 Im1 Re2 Im2 Re3 Im3
68  double xL[13]={0.52707,0.21068,-0.604365,0.17596,-0.216668,-0.0990815,-0.348459,0.208961,0,0,0,0,0};
69  // flat
70 
71  // now we contrain second and third wave:
72  // Phase {
73  // 1-0-+0+sigma_00_pi-.amp
74  // 1-1++1-rho770_01_pi-.amp
75  // 0.3
76  // }
77 
78  // Re0 Mag1 Re2 Im2 Re3 Im3 Flat
79  double x[13]={0.52707,0.21068,0.17596,-0.216668,-0.0990815,-0.348459,0.208961,0,0,0,0,0};
80  //double x[13]; for(int i=0;i<13;++i)x[i]=0.001;
81  //string a[13]={"a","b","c","d","e","f","g","h","i","j","k","l","flat"};
82  double LLC=LC(x);
83  double LL=L(xL);
84  std::cout<<"L(xL)="<<LL<<std::endl;
85  std::cout<<"LC(x)="<<LLC<<std::endl;
86 
87  LC.Print();
88 
89  // check derivatives:
90  // first numerical:
91  double LC1=LC(x);
92  double h=1E-8;
93  double dxNumC[13];
94  double dxAnaC[13];
95  bool problem=false;
96  for(unsigned int i=0; i<LC.NDim();++i){
97  x[i]+=h;
98  double LC2=LC(x);
99  dxNumC[i]=(LC2-LC1)/h;
100  x[i]-=h;
101  }
102  // Then analytic
103  double FC;
104  LC.FdF(x,FC,dxAnaC);
105  for(unsigned int i=0; i<LC.NDim();++i){
106  if(2*fabs(dxNumC[i]-dxAnaC[i])/(fabs(dxNumC[i])+fabs(dxAnaC[i]))>0.0001){
107  problem=true;
108  cout << "ERR>>>" << endl;
109  }
110  cout<< "dLC/d"<<i<<"(num)="<<dxNumC[i]<<endl;
111  cout<< "dLC/d"<<i<<"(ana)="<<dxAnaC[i]<<endl;
112 
113  }
114  if(problem)return 12;
115 
116 
117  // check if the contraint works
118  vector<complex<double> > V;
119  vector<pair<int,int> > indices;
120  vector<string> names;
121  TMatrixD cov(LC.NDim(),LC.NDim());
122  for(unsigned int i=0;i<LC.NDim();++i){
123  cov[i][i]=1.2;
124  if(i<LC.NDim()-1){
125  cov[i][i+1]=0.5;
126  cov[i+1][i]=0.5;
127  }
128  }
129  cout << "Assume Covariance Matrix:" << endl;
130  cov.Print();
131  TMatrixD cova(2,2);
132  LC.buildCAmps(x,V,indices,names,cov,cova,true);
133  cout << "Returned Covariance Matrix from TPWALikelihoodC" << endl;
134  cova.Print();
135 
136  // compare the two constraint amps:
137  double phasediff=std::arg(V[1])-std::arg(V[2]);
138  cout << "PhaseDiff= " << phasediff << endl;
139  if(phasediff!=0.3)return 2;
140 
141  return 0;
142 
143 }
144 
145 // dummy function needed since we link to but do not use minuit.o
146 int mnparm(int, string, double, double, double, double) {
147  cerr << "this is impossible" << endl;
148  throw "aFit";
149  return 0;
150 }