MINT2
FitAmplitude.cpp
Go to the documentation of this file.
1 // author: Jonas Rademacker (Jonas.Rademacker@bristol.ac.uk)
2 // status: Mon 9 Feb 2009 19:18:03 GMT
3 #include <iostream>
4 #include <fstream>
5 #include <algorithm>
6 #include <vector>
7 
8 #include "Mint/FitAmplitude.h"
10 
11 #include "Mint/DecayTree.h"
12 
13 using namespace std;
14 using namespace MINT;
15 
16 typedef std::pair<std::string, AmpInitialiser> AmpInitPair;
17 typedef std::vector<AmpInitPair> AmpInitPairList;
18 
20  public:
21  bool operator()(const AmpInitPair& a1, const AmpInitPair& a2){
22  DalitzEventPattern p1 = a1.second.getEventPattern();
23  DalitzEventPattern p2 = a2.second.getEventPattern();
24 
25  // cout << "compare: got event pattern p1 " << p1 << endl;
26  if(p1 == p2){
27  return a1.first < a2.first;
28  }else{
29  return p1 < p2;
30  }
31  /* this sorts the list such that
32  the same final states are grouped
33  together - good for printing
34  */
35 
36  }
37 };
38 
39 
42  std::string longestName = ndl->getLongestName();
43 
44  std::string longA = FitComplexPolar::makeAmpName(longestName);
45  std::string longP = FitComplexPolar::makePhaseName(longestName);
46 
47  return (longA.size() > longP.size() ? longA : longP);
48 }
49 
50 void FitAmplitude::AutogenerateFitFile(const std::string& fname, const DalitzEventPattern& compatiblePattern){
51 
52  ofstream os(fname.c_str());
53  if(! os) return;
54 
56  int nameFieldWidth = longestNameInList().size() +3;
57 
58  FitParameter::printFormat(os, nameFieldWidth);
59 
60  AmpInitPairList printList;
61  for(AmpInitMap::const_iterator it= ndl->trees().begin();
62  it != ndl->trees().end();
63  it++){
64  if(compatiblePattern == DalitzEventPattern::NoPattern ||
65  compatiblePattern.compatibleWithFinalState(it->second))
66  printList.push_back(*it);
67  }
68  AmpInitPairLessThan printSorter;
69  sort(printList.begin(), printList.end(), printSorter);
70 
71  for(AmpInitPairList::const_iterator it= printList.begin();
72  it != printList.end();
73  it++){
74  std::string s;
75  os << "*" <<endl;
76 
77  s = "\"" + FitComplexPolar::makeAmpName(it->first) + "\"";
78  s.resize(nameFieldWidth, ' ');
79  os << s << "\t" << FitParameter::getInitString() << endl;
80 
81  s = "\"" + FitComplexPolar::makePhaseName(it->first) + "\"";
82  s.resize(nameFieldWidth, ' ');
83  os << s << "\t" << FitParameter::getInitString() << endl;
84  }
85  os << "*" << endl;
86  os.close();
87 }
88 
89 FitAmplitude::FitAmplitude(const std::string& yourOwnNameWithoutPrefix
90  , const AmpInitialiser& treeWithOpts
91  , const char* fname
92  , MinuitParameterSet* pset
93  // , STRING_USAGE useStringAs
94  )
95  : _amp(treeWithOpts, this)
96  , _FitAmpPhase(FitComplexMaker(treeWithOpts.prefix() + yourOwnNameWithoutPrefix, fname, pset, this
97  , FitParameter::HIDE
98  , NamedParameterBase::QUIET
99  ))
100  , _fitFraction(treeWithOpts.prefix() + yourOwnNameWithoutPrefix + "_Frac", (double) 0, fname
101  , NamedParameterBase::QUIET)
102  , _preFactors(1)
103  , _name(treeWithOpts.prefix() + yourOwnNameWithoutPrefix)
104  , _tag(0)
105 {
106  // if(useStringAs == FitAmplitude::PREFIX){
107  // _name += treeWithOpts.uniqueName();
108  // }
109  //cout << "pset pointer in FitAmplitude " << pset << endl;
110 }
111 
112 FitAmplitude::FitAmplitude(const std::string& yourOwnNameWithoutPrefix
113  , const AmpInitialiser& treeWithOpts
114  , MinuitParameterSet* pset
115  // , STRING_USAGE useStringAs
116  )
117  : _amp(treeWithOpts, this)
118  , _FitAmpPhase(FitComplexMaker(treeWithOpts.prefix() + yourOwnNameWithoutPrefix, (char*) 0, pset, this
119  , FitParameter::HIDE
120  , NamedParameterBase::QUIET
121  ))
122  , _fitFraction(treeWithOpts.prefix() + yourOwnNameWithoutPrefix + "_Frac", (double) 0, (char*) 0
123  , NamedParameterBase::QUIET)
124  , _preFactors(1)
125  , _name(treeWithOpts.prefix() + yourOwnNameWithoutPrefix)
126  , _tag(0)
127 {
128  // if(useStringAs == FitAmplitude::PREFIX){
129  // _name += treeWithOpts.uniqueName();
130  //}
131 }
132 
134  , const char* fname
135  , MinuitParameterSet* pset
136  )
137  : _amp(treeWithOpts, this)
138  , _FitAmpPhase(FitComplexMaker(treeWithOpts.uniqueName(), fname, pset, this
139  , FitParameter::HIDE
140  , NamedParameterBase::QUIET
141  ))
142  , _fitFraction(treeWithOpts.uniqueName() + "_Frac", (double) 0, fname
143  , NamedParameterBase::QUIET)
144  , _preFactors(1)
145  , _name(treeWithOpts.uniqueName())
146  , _tag(0)
147 {
148 }
149 
151  , MinuitParameterSet* pset
152  )
153  : _amp(treeWithOpts, this)
154  ,_FitAmpPhase(FitComplexMaker(treeWithOpts.uniqueName(), (char*) 0, pset, this
155  , FitParameter::HIDE
156  , NamedParameterBase::QUIET
157  ))
158  , _fitFraction(treeWithOpts.uniqueName() + "_Frac", (double) 0
159  , NamedParameterBase::QUIET)
160  , _preFactors(1)
161  , _name(treeWithOpts.uniqueName())
162  , _tag(0)
163 {
164 }
165 
166 FitAmplitude::FitAmplitude(const std::string& StandardisedDecayTreeName
167  , const std::string& prefix
168  , const std::string& lineshapePrefix
169  , const char* fname
170  , MinuitParameterSet* pset
171  )
172  : _amp(AmpInitialiser(StandardisedDecayTreeName, prefix, lineshapePrefix), this)
173  , _FitAmpPhase(FitComplexMaker(prefix+StandardisedDecayTreeName, fname, pset, this
174  , FitParameter::HIDE
175  , NamedParameterBase::QUIET
176  ))
177  , _fitFraction(prefix+StandardisedDecayTreeName + "_Frac", (double) 0
178  , NamedParameterBase::QUIET)
179  , _preFactors(1)
180  , _name(prefix+StandardisedDecayTreeName)
181  , _tag(0)
182 {
183 
184 }
185 
186 FitAmplitude::FitAmplitude(const std::string& StandardisedDecayTreeName
187  , const std::string& prefix
188  , const std::string& lineshapePrefix
189  , MinuitParameterSet* pset
190  )
191  : _amp(AmpInitialiser(StandardisedDecayTreeName, prefix, lineshapePrefix), this)
192  , _FitAmpPhase(FitComplexMaker(prefix+StandardisedDecayTreeName, (char*) 0, pset, this
193  , FitParameter::HIDE
194  , NamedParameterBase::QUIET
195  ))
196  , _fitFraction(prefix+StandardisedDecayTreeName + "_Frac", (double) 0
197  , NamedParameterBase::QUIET)
198  , _preFactors(1)
199  , _name(prefix+StandardisedDecayTreeName)
200  , _tag(0)
201 {
202 
203 }
207  , FitParDependent(other, newDaddy)
208  , _amp(other._amp, this)
209  , _FitAmpPhase(other._FitAmpPhase)
210  , _fitFraction(other._fitFraction)
211  , _preFactors(other._preFactors)
212  , _name(other._name)
213  , _tag(other._tag)
214 {
215  /* this creates a copy of the amplitude, but
216  it will depend on the SAME fit parameter
217  (it just copies the (smart) pointer).
218 
219  Name will not change since FitParameterName doesn't
220  change.
221 
222  Since all this might not be 100% intuitive, leave it
223  private/protected for now. Use the "Get" methods instead.
224  */
225 }
226 
228 
229 }
230 
231 /* now inline
232 bool FitAmplitude::isZero() const{
233  if(0 == _FitAmpPhase) return true;
234  return _FitAmpPhase->isZero();
235 }
236 */
237 
239  if(0 == _FitAmpPhase) return false;
240  return _FitAmpPhase->isConstant();
241 }
243  return isZero() && isConstant();
244 }
246  _name += "_CPcon";
247  return amp().CPConjugate();
248 }
249 
251  FitAmplitude cp(*this);
253  return cp;
254 }
255 
257  _name += "_CconFs";
258  MINT::NamedParameter<double> fitFrac(_name + "_Frac", (double) 0, NamedParameterBase::QUIET);
259  _fitFraction = fitFrac;
260  return amp().CConjugateFinalState();
261 }
262 
264  FitAmplitude cp(*this);
266  return cp;
267 }
268 
270  _name += "_CconIs";
271  MINT::NamedParameter<double> fitFrac(_name + "_Frac", (double) 0, NamedParameterBase::QUIET);
272  _fitFraction = fitFrac;
273  return amp().CConjugateInitialState();
274 }
275 
277  FitAmplitude cp(*this);
279  return cp;
280 }
281 
283  _name += ("_L_"+anythingToString(L)).c_str();
284  MINT::NamedParameter<double> fitFrac(_name + "_Frac", (double) 0, NamedParameterBase::QUIET);
285  _fitFraction = fitFrac;
286  return amp().setL(L);
287 }
288 
290  FitAmplitude cp(*this);
291  cp.setLSameFitParameters(L);
292  return cp;
293 }
294 
295 std::complex<double> FitAmplitude::getVal(IDalitzEvent* evt){
296  if(0 == evt) return 0;
297  return getVal(*evt);
298 }
299 
300 std::complex<double> FitAmplitude::getVal(IDalitzEvent& evt){
301  //bool dbThis=false;
302  //if(isZero()) return 0;
303  complex<double> ap(AmpPhase());
304  /*
305  if(0.0 == ap) return 0;
306  if(dbThis){
307  cout << "FitAmplitude::getVal(evt) with name:\n"
308  << this->name()
309  << "\n and evt = \n"
310  << evt
311  << endl;
312  cout << " returning " << ap << " * "
313  << endl;
314  cout << " " << getValWithoutFitParameters(evt)
315  << "\n ----------------- "
316  << endl;
317  }
318  */
319  return ap * getValWithoutFitParameters(evt);
320 }
321 
322 /*
323 std::complex<double> FitAmplitude::getNewVal(IDalitzEvent& evt){
324  complex<double> ap(AmpPhase());
325  return ap * amp().getNewVal(evt);
326 }
327 */
328 
330  complex<double> ap(AmpPhase());
331  return ap * amp().getOnePermutationsVal(evt);
332 }
333 
334 
335 void FitAmplitude::multiply(double r){ // by value
336  _preFactors.addTerm(r);
337 }
338 void FitAmplitude::multiply(const std::complex<double>& z){ // by value
339  _preFactors.addTerm(z);
340 }
342  _preFactors.addTerm(irc);
343 }
345  _preFactors.addTerm(irc);
346 }
349 }
352 }
353 
354 void FitAmplitude::print(std::ostream& os) const{
355  // os << "**FitAmlitude: " << name()
356  os << _fitFraction << "\n"
357  << FitAmpPhase();
358 }
359 
361  multiply(r);
362  return *this;
363 }
364 FitAmplitude& FitAmplitude::operator*=(const complex<double>& z){
365  multiply(z);
366  return *this;
367 }
369  multiply(irc);
370  return *this;
371 }
373  multiply(irc);
374  return *this;
375 }
377  multiply(irce);
378  return *this;
379 }
381  multiply(irce);
382  return *this;
383 }
384 
385 std::ostream& operator<<(std::ostream& os, const FitAmplitude& fa){
386  fa.print(os);
387  return os;
388 }
389 
390 //
std::complex< double > AmpPhase() const
Definition: FitAmplitude.h:153
bool isConstant() const
Definition: FitComplex.cpp:68
std::complex< double > getOnePermutationsVal(IDalitzEvent &evt)
Definition: Amplitude.cpp:366
bool isConstant() const
bool isZero() const
Definition: FitAmplitude.h:98
static void AutogenerateFitFile(const std::string &fname="protoFitAmplitudeFile.txt", const DalitzEventPattern &pat=DalitzEventPattern::NoPattern)
bool operator()(const AmpInitPair &a1, const AmpInitPair &a2)
FitAmplitude GetCConjugateFinalStateSameFitParameters() const
bool compatibleWithFinalState(const AmpInitialiser &ampInitContainsTree) const
FitAmplitude GetDifferentLSameFitParameters(int L) const
bool canBeIgnored() const
virtual std::complex< double > getVal(IDalitzEvent &evt)
bool CPConjugateSameFitParameters()
static const double s
FitAmplitude(const FitAmplitude &other, IFitParRegister *newDaddy=0)
FitAmplitude & operator *=(double r)
MINT::counted_ptr< MINT::FitComplex > _FitAmpPhase
Definition: FitAmplitude.h:39
bool CConjugateInitialStateSameFitParameters()
virtual std::complex< double > getValWithoutFitParameters(IDalitzEvent &evt)
Definition: FitAmplitude.h:196
std::pair< std::string, AmpInitialiser > AmpInitPair
bool CConjugateFinalState()
Definition: Amplitude.cpp:129
MINT::ComplexProduct _preFactors
Definition: FitAmplitude.h:41
std::vector< AmpInitPair > AmpInitPairList
MINT::FitComplex & FitAmpPhase()
Definition: FitAmplitude.h:147
bool CConjugateFinalStateSameFitParameters()
bool CPConjugate()
Definition: Amplitude.cpp:123
bool setL(int L)
Definition: Amplitude.cpp:142
bool setLSameFitParameters(int L)
std::string _name
Definition: FitAmplitude.h:44
MINT::NamedParameter< double > _fitFraction
Definition: FitAmplitude.h:40
MINT::ComplexProductForEvent< IDalitzEvent > _evt_dep_preFactors
Definition: FitAmplitude.h:42
static const DalitzEventPattern NoPattern
void addTerm(double val)
static NamedDecayTreeList * getMe(const std::string &printopt="printNever")
static std::string longestNameInList()
counted_ptr< FitComplex > FitComplexMaker(const std::string &name, const char *fname=0, MinuitParameterSet *pset=0, MINT::IFitParRegister *daddy=0, FitParameter::FIX_OR_WHAT fow=FitParameter::FIX, NamedParameterBase::VERBOSITY vb=NamedParameterBase::VERBOSE)
Definition: FitComplex.cpp:17
Amplitude & amp()
Definition: FitAmplitude.h:163
virtual std::complex< double > getNewOnePermutationsVal(IDalitzEvent &evt)
std::string anythingToString(const T &anything)
Definition: Utils.h:62
const AmpInitMap & trees(const std::string &opt="ALL") const
std::string getLongestName() const
std::ostream & operator<<(std::ostream &os, const FitAmplitude &fa)
FitAmplitude GetCPConjugateSameFitParameters() const
bool CConjugateInitialState()
Definition: Amplitude.cpp:136
FitAmplitude GetCConjugateInitialStateSameFitParameters() const
std::string uniqueName(const DecayTree &dt_in)
Definition: DecayTree.cpp:27
void print(std::ostream &os=std::cout) const
void multiply(double r)