ROOTPWA
partialWaveWeight.cc
Go to the documentation of this file.
1 #include "partialWaveWeight.h"
2 
3 #include <list>
4 #include <fstream>
5 #include <string>
6 
7 #include "TString.h"
8 
9 #include "reportingUtils.hpp"
10 #include "particle.h"
11 
12 
13 using namespace std;
14 using namespace rpwa;
15 
16 void
17 partialWaveWeight::addWave(const std::string& keyfilename,
18  productionAmp* amp,
19  const std::complex<double>& branching,
20  unsigned int vectori)
21 {
22 
23  if(vectori <= m_waves.size()) {
24  m_waves.resize(vectori+1);
25  m_amps.resize(vectori+1);
26  m_branchings.resize(vectori+1);
27  m_gamp.resize(vectori+1);
28  }
29 
30  // check if this is a double amplitude (by isospin symmetry)
31  if(keyfilename.find("+-",7) != string::npos) {
32  cerr << "Decomposing " << keyfilename << endl;
33  cerr << "What is the relative phase (0 or pi)?:";
34  //string select;
35  //cin >> select;
36  if(keyfilename.find("f11285",7) != string::npos) {
37  m_relphase[keyfilename] = -1;
38  } else {
39  m_relphase[keyfilename] = 1;
40  }
41 
42  // deccompose into components:
43  TString name(keyfilename.c_str());
44  int pos = name.Last('/');
45  TString w1a = name(pos+8, name.Length()-pos-8);
46 
47  w1a.ReplaceAll("+-", "+");
48  w1a.ReplaceAll("-+", "-");
49  w1a.Prepend(name(0, pos+8));
50 
51  TString w1b = name(pos+8, name.Length()-pos-8);
52  w1b.ReplaceAll("+-", "-");
53  w1b.ReplaceAll("-+", "+");
54  w1b.Prepend(name(0, pos+8));
55 
56  cerr << w1a << endl;
57  cerr << m_relphase[keyfilename] << endl;
58  cerr << w1b << endl;
59 
60  m_gamp[vectori].addWave(w1a.Data());
61  m_waves[vectori].push_back(keyfilename);
62  m_branchings[vectori].push_back(branching);
63  m_amps[vectori].push_back(amp);
64  m_gamp[vectori].addWave(w1b.Data());
65  m_waves[vectori].push_back(keyfilename);
66  m_branchings[vectori].push_back(branching);
67  m_amps[vectori].push_back(amp);
68 
69  } else {
70  m_gamp[vectori].addWave(keyfilename);
71  m_waves[vectori].push_back(keyfilename);
72  m_branchings[vectori].push_back(branching);
73  m_amps[vectori].push_back(amp);
74  }
75 
76 }
77 
78 
79 void
80 partialWaveWeight::loadIntegrals(const std::string& normIntFileName, double mass) {
81  //printInfo << "Loading normalization integral from '"
82  // << normIntFileName << "'." << endl;
83  ifstream intFile(normIntFileName.c_str());
84  if (!intFile) {
85  printErr << "Cannot open file '"
86  << normIntFileName << "'. Exiting." << endl;
87  throw;
88  }
89  // !!! integral.scan() performs no error checks!
90  // check units:
91  if(mass > 10) {
92  mass/=1000; //(MeV/GeV)
93  }
94  m_normInt[mass].scan(intFile);
95  intFile.close();
96  // renomalize
97  // list<string> waves=m_normInt.files();
98  // list<string>::iterator it1=waves.begin();
99  // list<string>::iterator it2=waves.begin();
100  // while(it1!=waves.end()){
101  // string w1=*it1;
102  // it2=it1;
103  // ++it2;
104  // while(it2!=waves.end()){
105  // string w2=*it2;
106  // double nrm=sqrt(m_normInt.el(w1,w1).real()*m_normInt.el(w2,w2).real())/m_normInt.nevents();
107  // //cout << w1 << " " << w2 << " " <<nrm << endl;
108  // m_normInt.el(w1,w2)=m_normInt.el(w1,w2)/nrm;
109  // m_normInt.el(w2,w1)=m_normInt.el(w2,w1)/nrm;
110  // ++it2;
111  // }
112  // m_normInt.el(w1,w1)=m_normInt.nevents();
113  // ++it1;
114  // }
115  m_hasInt = true;
116 }
117 
118 
119 
120 std::complex<double>
121 partialWaveWeight::prodAmp(unsigned int iv,
122  unsigned int iw,
123  event& e)
124 {
125  // get mass
126  std::list<particle> part = e.f_particles();
127  fourVec p;
128  std::list<particle>::iterator it = part.begin();
129  while(it != part.end()) {
130  p += (it++)->get4P();
131  }
132  double m = p.len();
133  return m_amps[iv][iw]->amp(m) * m_branchings[iv][iv];
134 }
135 
136 
137 
138 
139 
140 double
141 partialWaveWeight::weight(event& e) {
142  unsigned int nvec = m_waves.size();
143  double w = 0;
144  integral* close_int = 0;
145  if(m_hasInt) {
146  // get closest mass bin
147  double mass = e.f_mass();
148  // loop through available integrals;
149  std::map<double,integral>::iterator it = m_normInt.begin();
150  //cerr << m_normInt.size() << " Integrals available" << endl;
151  double closemass = 0;
152  while(it != m_normInt.end()) {
153  double m = it->first;
154  if(fabs(m - mass) < fabs(m - closemass)) {
155  closemass=m;
156  };
157  ++it;
158  }
159  //cerr << mass << " -> closemass=" << closemass << endl;
160  close_int = &(m_normInt[closemass]);
161  } // endif has int
162 
163  for(unsigned int ivec = 0; ivec < nvec; ++ivec) { // loop over production vectors
164  std::complex<double> amp(0,0);
165  unsigned int nwaves = m_waves[ivec].size();
166  for(unsigned int iwaves = 0; iwaves < nwaves; ++iwaves){
167  string w1 = m_waves[ivec][iwaves];
168 
169  // std::cerr << w1 << std::endl;
170  //std::cerr.flush();
171  w1.erase(0, w1.find_last_of("/")+1);
172  w1.replace(w1.find(".key"), 4, ".amp");
173  std::complex<double> decayamp;
174  decayamp = m_gamp[ivec].Amp(iwaves, e);
175  //std::cerr << "..first component ..." << std::endl;
176  if(w1.find("+-", 7) != string::npos) { // brute force treatment of composed amplitudes!
177 
178  // see addWave to understand bookkeeping!
179  // Here an isospin clebsch factor is missing
180  ++iwaves;
181  decayamp += m_relphase[m_waves[ivec][iwaves]] * m_gamp[ivec].Amp(iwaves, e);
182  }
183  // std::cerr << "..done" << std::endl;
184  double nrm = 1;
185  if(m_hasInt) {
186  nrm = sqrt(close_int->val(w1, w1).real());
187  }
188  amp += (decayamp / nrm) * prodAmp(ivec, iwaves, e);
189  }
190  w += std::norm(amp);
191  } // end loop over production vectors
192  if(w == 0) {
193  w = 1;
194  }
195  return w;
196 
197 }
198