AmpTools
ConfigurationInfo.cc
Go to the documentation of this file.
1 //******************************************************************************
2 // This file is part of AmpTools, a package for performing Amplitude Analysis
3 //
4 // Copyright Trustees of Indiana University 2010, all rights reserved
5 //
6 // This software written by Matthew Shepherd, Ryan Mitchell, and
7 // Hrayr Matevosyan at Indiana University, Bloomington
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions
11 // are met:
12 // 1. Redistributions of source code must retain the above copyright
13 // notice and author attribution, this list of conditions and the
14 // following disclaimer.
15 // 2. Redistributions in binary form must reproduce the above copyright
16 // notice and author attribution, this list of conditions and the
17 // following disclaimer in the documentation and/or other materials
18 // provided with the distribution.
19 // 3. Neither the name of the University nor the names of its contributors
20 // may be used to endorse or promote products derived from this software
21 // without specific prior written permission.
22 //
23 // Creation of derivative forms of this software for commercial
24 // utilization may be subject to restriction; written permission may be
25 // obtained from the Trustees of Indiana University.
26 //
27 // INDIANA UNIVERSITY AND THE AUTHORS MAKE NO REPRESENTATIONS OR WARRANTIES,
28 // EXPRESS OR IMPLIED. By way of example, but not limitation, INDIANA
29 // UNIVERSITY MAKES NO REPRESENTATIONS OR WARRANTIES OF MERCANTABILITY OR
30 // FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THIS SOFTWARE OR
31 // DOCUMENTATION WILL NOT INFRINGE ANY PATENTS, COPYRIGHTS, TRADEMARKS,
32 // OR OTHER RIGHTS. Neither Indiana University nor the authors shall be
33 // held liable for any liability with respect to any claim by the user or
34 // any other party arising from use of the program.
35 //******************************************************************************
36 
37 #include <iostream>
38 #include <utility>
39 #include <string>
40 #include <vector>
41 #include <map>
42 #include <complex>
43 #include <cstdlib>
44 
46 
47 
51 }
52 
53 
54 vector< string >
56 
57  vector<string> keywords;
58  for (map<string, vector< vector<string> > >::const_iterator
59  mapItr = m_userKeywordMap.begin();
60  mapItr != m_userKeywordMap.end(); mapItr++){
61  keywords.push_back(mapItr->first);
62  }
63  return keywords;
64 }
65 
66 
67 vector< vector<string> >
68 ConfigurationInfo::userKeywordArguments(const string& userKeyword) const{
69 
70  if (m_userKeywordMap.find(userKeyword) != m_userKeywordMap.end())
71  return m_userKeywordMap.find(userKeyword)->second;
72  return vector< vector<string> >();
73 }
74 
75 
76 vector<ReactionInfo*>
77 ConfigurationInfo::reactionList (const string& reactionName) const {
78 
79  vector<ReactionInfo*> reactions;
80  for (unsigned int i = 0; i < m_reactions.size(); i++){
81  if ((reactionName == "") || (m_reactions[i]->reactionName() == reactionName)){
82  reactions.push_back(m_reactions[i]);
83  }
84  }
85 
86  return reactions;
87 }
88 
89 
90 vector<CoherentSumInfo*>
91 ConfigurationInfo::coherentSumList (const string& reactionName,
92  const string& sumName) const {
93  vector<CoherentSumInfo*> sums;
94  for (unsigned int i = 0; i < m_sums.size(); i++){
95  if (((reactionName == "") || (m_sums[i]->reactionName() == reactionName)) &&
96  ((sumName == "") || (m_sums[i]->sumName() == sumName))){
97  sums.push_back(m_sums[i]);
98  }
99  }
100  return sums;
101 }
102 
103 
104 vector<AmplitudeInfo*>
105 ConfigurationInfo::amplitudeList (const string& reactionName,
106  const string& sumName,
107  const string& ampName) const {
108  vector<AmplitudeInfo*> amplitudes;
109  for (unsigned int i = 0; i < m_amplitudes.size(); i++){
110  if (((reactionName == "") || (m_amplitudes[i]->reactionName() == reactionName)) &&
111  ((sumName == "") || (m_amplitudes[i]->sumName() == sumName)) &&
112  ((ampName == "") || (m_amplitudes[i]->ampName() == ampName))){
113  amplitudes.push_back(m_amplitudes[i]);
114  }
115  }
116  return amplitudes;
117 }
118 
119 vector<ParameterInfo*>
120 ConfigurationInfo::parameterList (const string& reactionName,
121  const string& sumName,
122  const string& ampName,
123  const string& parName) const {
124  if ((reactionName == "") &&
125  (sumName == "") &&
126  (ampName == "") &&
127  (parName == "")) return m_parameters;
128  vector<ParameterInfo*> parameters;
129  for (unsigned int i = 0; i < m_amplitudes.size(); i++){
130  if (((reactionName == "") || (m_amplitudes[i]->reactionName() == reactionName)) &&
131  ((sumName == "") || (m_amplitudes[i]->sumName() == sumName)) &&
132  ((ampName == "") || (m_amplitudes[i]->ampName() == ampName))){
133  vector<ParameterInfo*> ampParameters = m_amplitudes[i]->parameters();
134  for (unsigned int j = 0; j < ampParameters.size(); j++){
135  bool foundParameter = false;
136  for (unsigned int k = 0; k < parameters.size(); k++){
137  if (parameters[k]->parName() == ampParameters[j]->parName()) foundParameter = true;
138  }
139  if (!foundParameter){
140  if ((parName == "") || (ampParameters[j]->parName() == parName)){
141  parameters.push_back(ampParameters[j]);
142  }
143  }
144  }
145  }
146  }
147  return parameters;
148 }
149 
150 
151 
153 ConfigurationInfo::reaction (const string& reactionName) const {
154  for (unsigned int i = 0; i < m_reactions.size(); i++){
155  if (m_reactions[i]->reactionName() == reactionName){
156  return m_reactions[i];
157  }
158  }
160  return reaction;
161 }
162 
163 
165 ConfigurationInfo::coherentSum (const string& reactionName,
166  const string& sumName) const {
167  for (unsigned int i = 0; i < m_sums.size(); i++){
168  if ((m_sums[i]->reactionName() == reactionName) &&
169  (m_sums[i]->sumName() == sumName)){
170  return m_sums[i];
171  }
172  }
173  CoherentSumInfo* sum = NULL;
174  return sum;
175 }
176 
177 
179 ConfigurationInfo::amplitude (const string& reactionName,
180  const string& sumName,
181  const string& ampName) const {
182  for (unsigned int i = 0; i < m_amplitudes.size(); i++){
183  if ((m_amplitudes[i]->reactionName() == reactionName) &&
184  (m_amplitudes[i]->sumName() == sumName) &&
185  (m_amplitudes[i]->ampName() == ampName)){
186  return m_amplitudes[i];
187  }
188  }
190  return amplitude;
191 }
192 
193 
195 ConfigurationInfo::parameter (const string& parName) const {
196  for (unsigned int i = 0; i < m_parameters.size(); i++){
197  if (m_parameters[i]->parName() == parName){
198  return m_parameters[i];
199  }
200  }
202  return parameter;
203 }
204 
205 
206 
207 void
208 ConfigurationInfo::addUserKeyword(const string& userKeyword, const vector<string>& arguments){
209 
210  vector< vector<string> > argList = m_userKeywordMap[userKeyword];
211  argList.push_back(arguments);
212  m_userKeywordMap[userKeyword] = argList;
213 }
214 
215 
217 ConfigurationInfo::createReaction (const string& reactionName,
218  const vector<string>& particleList){
219  ReactionInfo* rctn = reaction(reactionName);
220  if (rctn == NULL){
221  rctn = new ReactionInfo(reactionName,particleList);
222  m_reactions.push_back(rctn);
223  }
224  else{
225  rctn->setParticleList(particleList);
226  rctn->clear();
227  }
228  return rctn;
229 }
230 
231 
233 ConfigurationInfo::createCoherentSum (const string& reactionName,
234  const string& sumName){
235  CoherentSumInfo* sum = coherentSum(reactionName,sumName);
236  if (sum == NULL){
237  ReactionInfo* rctn = reaction(reactionName);
238  if (rctn == NULL){
239  cout << "ConfigurationInfo: Trying to create coherentSum for unknown reaction" << endl;
240  cout << "\tcreateCoherentSum(" << reactionName << "," << sumName << ")" << endl;
241  exit(0);
242  }
243  sum = new CoherentSumInfo(reactionName,sumName);
244  m_sums.push_back(sum);
245  }
246  else{
247  sum->clear();
248  }
249  return sum;
250 }
251 
252 
253 
255 ConfigurationInfo::createAmplitude (const string& reactionName,
256  const string& sumName,
257  const string& ampName){
258  AmplitudeInfo* amp = amplitude(reactionName,sumName,ampName);
259  if (amp == NULL){
260  ReactionInfo* rctn = reaction(reactionName);
261  if (rctn == NULL){
262  cout << "ConfigurationInfo: Trying to create amplitude for unknown reaction" << endl;
263  cout << "\tcreateAmplitude(" << reactionName << "," << sumName << "," << ampName << ")" << endl;
264  exit(0);
265  }
266  CoherentSumInfo* sum = coherentSum(reactionName,sumName);
267  if (sum == NULL){
268  cout << "ConfigurationInfo: Trying to create amplitude for unknown coherent sum" << endl;
269  cout << "\tcreateAmplitude(" << reactionName << "," << sumName << "," << ampName << ")" << endl;
270  exit(0);
271  }
272  amp = new AmplitudeInfo(reactionName,sumName,ampName);
273  m_amplitudes.push_back(amp);
274  }
275  else{
276  amp->clear();
277  }
278  return amp;
279 }
280 
281 
282 
284 ConfigurationInfo::createParameter (const string& parName,
285  double value){
286  ParameterInfo* par = parameter(parName);
287  if (par == NULL){
288  par = new ParameterInfo(parName,value);
289  m_parameters.push_back(par);
290  }
291  else{
292  par->setValue(value);
293  par->clear();
294  }
295  return par;
296 }
297 
298 
299 
300 void
301 ConfigurationInfo::removeUserKeyword(const string& userKeyword){
302 
303  if (userKeyword == "") m_userKeywordMap.clear();
304  m_userKeywordMap.erase(userKeyword);
305 }
306 
307 
308 void
309 ConfigurationInfo::removeReaction (const string& reactionName){
310  removeCoherentSum(reactionName);
311  vector<ReactionInfo*> removeList = reactionList(reactionName);
312  unsigned int removeListSize = removeList.size();
313  for (unsigned int i = 0; i < removeListSize; i++){
314  for (unsigned int j = 0; j < m_reactions.size(); j++){
315  if (removeList[i]->reactionName() == m_reactions[j]->reactionName()){
316  m_reactions[j]->clear();
317  delete m_reactions[j];
318  m_reactions.erase(m_reactions.begin()+j,m_reactions.begin()+j+1);
319  j = m_reactions.size();
320  }
321  }
322  }
323 }
324 
325 void
326 ConfigurationInfo::removeCoherentSum (const string& reactionName,
327  const string& sumName){
328  removeAmplitude(reactionName,sumName);
329  vector<CoherentSumInfo*> removeList = coherentSumList(reactionName, sumName);
330  unsigned int removeListSize = removeList.size();
331  for (unsigned int i = 0; i < removeListSize; i++){
332  for (unsigned int j = 0; j < m_sums.size(); j++){
333  if ((removeList[i]->reactionName() == m_sums[j]->reactionName()) &&
334  (removeList[i]->sumName() == m_sums[j]->sumName())){
335  m_sums[j]->clear();
336  delete m_sums[j];
337  m_sums.erase(m_sums.begin()+j,m_sums.begin()+j+1);
338  j = m_sums.size();
339  }
340  }
341  }
342 }
343 
344 void
345 ConfigurationInfo::removeAmplitude (const string& reactionName,
346  const string& sumName,
347  const string& ampName){
348  vector<AmplitudeInfo*> removeList = amplitudeList(reactionName, sumName, ampName);
349  unsigned int removeListSize = removeList.size();
350  for (unsigned int i = 0; i < removeListSize; i++){
351  for (unsigned int j = 0; j < m_amplitudes.size(); j++){
352  m_amplitudes[j]->removeConstraint(removeList[i]);
353  }
354  }
355  for (unsigned int i = 0; i < removeListSize; i++){
356  for (unsigned int j = 0; j < m_amplitudes.size(); j++){
357  if ((removeList[i]->reactionName() == m_amplitudes[j]->reactionName()) &&
358  (removeList[i]->sumName() == m_amplitudes[j]->sumName()) &&
359  (removeList[i]->ampName() == m_amplitudes[j]->ampName())){
360  m_amplitudes[j]->clear();
361  delete m_amplitudes[j];
362  m_amplitudes.erase(m_amplitudes.begin()+j,m_amplitudes.begin()+j+1);
363  j = m_amplitudes.size();
364  }
365  }
366  }
367 }
368 
369 
370 void
371 ConfigurationInfo::removeParameter (const string& parName){
372  vector<ParameterInfo*> removeList;
373  if (parName == ""){
374  removeList = m_parameters;
375  }
376  else{
377  ParameterInfo* parinfo = parameter(parName);
378  if (parinfo) removeList.push_back(parinfo);
379  }
380  unsigned int removeListSize = removeList.size();
381  for (unsigned int i = 0; i < removeListSize; i++){
382  for (unsigned int j = 0; j < m_amplitudes.size(); j++){
383  m_amplitudes[j]->removeParameter(removeList[i]);
384  }
385  }
386  for (unsigned int i = 0; i < removeListSize; i++){
387  for (unsigned int j = 0; j < m_parameters.size(); j++){
388  if (removeList[i]->parName() == m_parameters[j]->parName()){
389  m_parameters[j]->clear();
390  delete m_parameters[j];
391  m_parameters.erase(m_parameters.begin()+j,m_parameters.begin()+j+1);
392  j = m_parameters.size();
393  }
394  }
395  }
396 }
397 
398 map< string, vector< string > >
400 
401  map< string, vector< string > > cMap;
402 
403  for( vector< AmplitudeInfo* >::const_iterator aItr = m_amplitudes.begin();
404  aItr != m_amplitudes.end();
405  ++aItr ){
406 
407  cMap[(**aItr).fullName()] = vector< string >( 0 );
408 
409  vector< AmplitudeInfo* > constraints = (**aItr).constraints();
410 
411  for( vector< AmplitudeInfo* >::const_iterator bItr = constraints.begin();
412  bItr != constraints.end();
413  ++bItr ){
414 
415  cMap[(**aItr).fullName()].push_back( (**bItr).fullName() );
416  }
417  }
418 
419  return cMap;
420 }
421 
422 
423 void
424 ConfigurationInfo::write( const string& fileName ) const {
425 
426  ofstream ff(fileName.c_str());
427  write( ff );
428  ff.close();
429 }
430 
431 ostream&
432 ConfigurationInfo::write( ostream& ff ) const {
433 
434  vector<ReactionInfo*> Rs = reactionList();
435  vector<CoherentSumInfo*> Ss = coherentSumList();
436  vector<AmplitudeInfo*> As = amplitudeList();
437  vector<ParameterInfo*> Ps = parameterList();
438 
439  ff << "### FIT CONFIGURATION ###" << endl;
440 
441 
442  // fit
443 
444  ff << "fit " << fitName() << endl;
445 
446 
447  // user keywords
448 
449  vector<string> keywords = userKeywords();
450  for (unsigned int i = 0; i < keywords.size(); i++){
451  vector< vector<string> > argslist = userKeywordArguments(keywords[i]);
452  int min = 0; int max = 0;
453  for (unsigned int j = 0; j < argslist.size(); j++){
454  if (argslist[j].size() < min) min = argslist[j].size();
455  if (argslist[j].size() > max) max = argslist[j].size();
456  }
457  ff << "keyword " << keywords[i] << " " << min << " " << max << endl;
458  for (unsigned int j = 0; j < argslist.size(); j++){
459  vector<string> args = argslist[j];
460  ff << keywords[i] << " ";
461  for (unsigned int k = 0; k < args.size(); k++){
462  ff << args[k] << " ";
463  }
464  ff << endl;
465  }
466  }
467 
468 
469  // reaction
470 
471  for (unsigned int i = 0; i < Rs.size(); i++){
472  ReactionInfo* R = Rs[i];
473  ff << "reaction " << R->reactionName();
474  vector<string> particles = R->particleList();
475  for (unsigned int j = 0; j < particles.size(); j++){ ff << " " << particles[j];}
476  ff << endl;}
477 
478 
479  // sum
480 
481  for (unsigned int i = 0; i < Ss.size(); i++){
482  CoherentSumInfo* S = Ss[i];
483  ff << "sum " << S->fullName() << endl;}
484 
485 
486  // amplitude
487 
488  for (unsigned int i = 0; i < As.size(); i++){
489  AmplitudeInfo* A = As[i];
490  vector< vector<string> > Fs = A->factors();
491  for (unsigned int j = 0; j < Fs.size(); j++){
492  ff << "amplitude " << A->fullName();
493  vector<string> args = Fs[j];
494  for (unsigned int k = 0; k < args.size(); k++){
495  ff << " " << args[k];}
496  ff << endl;}}
497 
498 
499  // parameter
500 
501  for (unsigned int i = 0; i < Ps.size(); i++){
502  ParameterInfo* P = Ps[i];
503  ff << "parameter " << P->parName() << " " << P->value();
504  if (P->fixed()){ ff << " fixed"; }
505  else if (P->bounded()){ ff << " bounded " << P->lowerBound()
506  << " " << P->upperBound(); }
507  else if (P->gaussianBounded()) { ff << " gaussian " << P->centralValue()
508  << " " << P->gaussianError(); }
509  ff << endl;}
510 
511 
512  // scale
513 
514  for (unsigned int i = 0; i < As.size(); i++){
515  AmplitudeInfo* A = As[i];
516  ff << "scale " << A->fullName() << " " << A->scale() << endl;}
517 
518 
519  // constrain
520 
521  for (unsigned int i = 0; i < As.size(); i++){
522  AmplitudeInfo* A = As[i];
523  vector<AmplitudeInfo*> constr = A->constraints();
524  for (unsigned int j = 0; j < constr.size(); j++){
525  ff << "constrain " << A->fullName() << " " << constr[j]->fullName() << endl;}}
526 
527 
528  // initialize
529 
530  for (unsigned int i = 0; i < As.size(); i++){
531  AmplitudeInfo* A = As[i];
532  ff << "initialize " << A->fullName() << " cartesian "
533  << A->value().real() << " "
534  << A->value().imag();
535  if (!A->real() && A->fixed()) {ff << " fixed";}
536  else if ( A->real() && !A->fixed()) {ff << " real";}
537  else if ( A->real() && A->fixed()) {ff << " fixed real";}
538  ff << endl;}
539 
540 
541  // permute
542 
543  for (unsigned int i = 0; i < As.size(); i++){
544  AmplitudeInfo* A = As[i];
545  vector< vector<int> > perms = A->permutations();
546  for (unsigned int j = 0; j < perms.size(); j++){
547  ff << "permute " << A->fullName();
548  vector<int> perm = perms[j];
549  for (unsigned int k = 0; k < perm.size(); k++){
550  ff << " " << perm[k];}
551  ff << endl;}}
552 
553 
554  // data
555 
556  for (unsigned int i = 0; i < Rs.size(); i++){
557  ReactionInfo* R = Rs[i];
558  string cls = R->data().first;
559  vector<string> args = R->data().second;
560  if (cls != ""){
561  ff << "data " << R->reactionName() << " " << cls;
562  for (unsigned int j = 0; j < args.size(); j++){ ff << " " << args[j];}
563  ff << endl;}}
564 
565 
566  // genmc
567 
568  for (unsigned int i = 0; i < Rs.size(); i++){
569  ReactionInfo* R = Rs[i];
570  string cls = R->genMC().first;
571  vector<string> args = R->genMC().second;
572  if (cls != ""){
573  ff << "genmc " << R->reactionName() << " " << cls;
574  for (unsigned int j = 0; j < args.size(); j++){ ff << " " << args[j];}
575  ff << endl;}}
576 
577 
578  // accmc
579 
580  for (unsigned int i = 0; i < Rs.size(); i++){
581  ReactionInfo* R = Rs[i];
582  string cls = R->accMC().first;
583  vector<string> args = R->accMC().second;
584  if (cls != ""){
585  ff << "accmc " << R->reactionName() << " " << cls;
586  for (unsigned int j = 0; j < args.size(); j++){ ff << " " << args[j];}
587  ff << endl;}}
588 
589 
590  // normintfile
591 
592  for (unsigned int i = 0; i < Rs.size(); i++){
593  ReactionInfo* R = Rs[i];
594  string ni = R->normIntFile();
595  if ((ni != "") && !(R->normIntFileInput())){
596  ff << "normintfile " << R->reactionName() << " " << ni << endl;}
597  if ((ni != "") && (R->normIntFileInput())){
598  ff << "normintfile " << R->reactionName() << " " << ni << " input" << endl;}}
599 
600  return ff;
601 }
602 
603 void
604 ConfigurationInfo::display(string fileName, bool append) const {
605 
606  // this is a display function - it should not modify ConfiguraitonInfo
607  // but all of the accessor functions are non-const to allow
608  // flexibility in manipulating the configuration info so we will
609  // cast away the constness and call the private non-const diplsay
610  // function
611 
612  ConfigurationInfo* ci = const_cast< ConfigurationInfo* >( this );
613 
614  ci->display( fileName, append );
615 }
616 
617 void
618 ConfigurationInfo::display(string fileName, bool append){
619 
620 
621  ofstream outfile;
622  streambuf* cout_sbuf = cout.rdbuf();
623  if (fileName != ""){
624  if (append){
625  outfile.open(fileName.c_str(), ios::out | ios::app);
626  }
627  else{
628  outfile.open(fileName.c_str());
629  }
630  cout.rdbuf(outfile.rdbuf());
631  }
632 
633  cout << endl;
634  cout << "## CONFIGURATION INFO DISPLAY ##" << endl;
635  cout << endl;
636 
637  if (fileName != ""){
638  outfile.close();
639  cout.rdbuf(cout_sbuf);
640  }
641 
642  for (unsigned int i = 0; i < m_reactions.size(); i++){
643  m_reactions[i]->display(fileName,true);
644  vector<CoherentSumInfo*> sums = coherentSumList(m_reactions[i]->reactionName());
645  for (unsigned int j = 0; j < sums.size(); j++){
646  sums[j]->display(fileName,true);
647  vector<AmplitudeInfo*> amps = amplitudeList(m_reactions[i]->reactionName(),sums[j]->sumName());
648  for (unsigned int k = 0; k < amps.size(); k++){
649  amps[k]->display(fileName,true);
650  }
651  }
652  }
653  for (unsigned int l = 0; l < m_parameters.size(); l++){
654  m_parameters[l]->display(fileName,true);
655  }
656 }
657 
658 
659 
660 void
661 ReactionInfo::display(string fileName, bool append){
662 
663  ofstream outfile;
664  streambuf* cout_sbuf = cout.rdbuf();
665  if (fileName != ""){
666  if (append){
667  outfile.open(fileName.c_str(), ios::out | ios::app);
668  }
669  else{
670  outfile.open(fileName.c_str());
671  }
672  cout.rdbuf(outfile.rdbuf());
673  }
674 
675  cout << "############################################" << endl;
676  cout << "############# REACTION INFO #############" << endl;
677  cout << "############################################" << endl;
678  cout << " REACTION NAME: " << m_reactionName << endl;
679  cout << " PARTICLE LIST: " << m_particleList.size() << endl;
680  for (unsigned int i = 0; i < m_particleList.size(); i++){
681  cout << "\t\t" << i+1 << ". " << m_particleList[i] << endl;
682  }
683  cout << " DATA READER: " << m_data.first << endl;
684  for (unsigned int i = 0; i < m_data.second.size(); i++){
685  cout << "\t\t\t\t" << m_data.second[i] << endl;
686  }
687  if( m_bkgnd.first != "" ){
688  cout << " BACKGROUND READER: " << m_bkgnd.first << endl;
689  for (unsigned int i = 0; i < m_bkgnd.second.size(); i++){
690  cout << "\t\t\t\t" << m_bkgnd.second[i] << endl;
691  }
692  }
693  cout << " ACC MC READER: " << m_accMC.first << endl;
694  for (unsigned int i = 0; i < m_accMC.second.size(); i++){
695  cout << "\t\t\t\t" << m_accMC.second[i] << endl;
696  }
697  cout << " GEN MC READER: " << m_genMC.first << endl;
698  for (unsigned int i = 0; i < m_genMC.second.size(); i++){
699  cout << "\t\t\t\t" << m_genMC.second[i] << endl;
700  }
701  cout << " NORMALIZATION INTEGRAL FILE: " << endl;
702  if (m_normIntFile != "") cout << "\t\t " << m_normIntFile << endl;
703  if (m_normIntFileInput) cout << "\t\t (use as input)" << endl;
704 
705  if (fileName != ""){
706  outfile.close();
707  cout.rdbuf(cout_sbuf);
708  }
709 
710 }
711 
712 
713 void
714 CoherentSumInfo::display(string fileName, bool append){
715 
716  ofstream outfile;
717  streambuf* cout_sbuf = cout.rdbuf();
718  if (fileName != ""){
719  if (append){
720  outfile.open(fileName.c_str(), ios::out | ios::app);
721  }
722  else{
723  outfile.open(fileName.c_str());
724  }
725  cout.rdbuf(outfile.rdbuf());
726  }
727 
728  cout << "********************************************" << endl;
729  cout << "*********** COHERENT SUM INFO ************" << endl;
730  cout << "********************************************" << endl;
731  cout << " REACTION NAME: " << m_reactionName << endl;
732  cout << " COHERENT SUM NAME: " << m_sumName << endl;
733 
734  if (fileName != ""){
735  outfile.close();
736  cout.rdbuf(cout_sbuf);
737  }
738 
739 }
740 
741 
742 void
743 AmplitudeInfo::display(string fileName, bool append){
744 
745  ofstream outfile;
746  streambuf* cout_sbuf = cout.rdbuf();
747  if (fileName != ""){
748  if (append){
749  outfile.open(fileName.c_str(), ios::out | ios::app);
750  }
751  else{
752  outfile.open(fileName.c_str());
753  }
754  cout.rdbuf(outfile.rdbuf());
755  }
756 
757  cout << "++++++++++++++++++++++++++++++++++++++++++++" << endl;
758  cout << "+++++++++++++ AMPLITUDE INFO +++++++++++++" << endl;
759  cout << "++++++++++++++++++++++++++++++++++++++++++++" << endl;
760  cout << " REACTION NAME: " << m_reactionName << endl;
761  cout << " COHERENT SUM NAME: " << m_sumName << endl;
762  cout << " AMPLITUDE NAME: " << m_ampName << endl;
763  cout << " FACTORS: " << m_factors.size() << endl;
764  for (unsigned int i = 0; i < m_factors.size(); i++){
765  vector<string> factor = m_factors[i];
766  cout << "\t\t" << i+1 << ". ";
767  for (unsigned int j = 0; j < factor.size(); j++){
768  cout << " " << factor[j];
769  }
770  cout << endl;
771  }
772  cout << " PERMUTATIONS: " << m_permutations.size() << endl;
773  for (unsigned int i = 0; i < m_permutations.size(); i++){
774  vector<int> permutation = m_permutations[i];
775  cout << "\t\t" << i+1 << ". ";
776  for (unsigned int j = 0; j < permutation.size(); j++){
777  cout << " " << permutation[j];
778  }
779  cout << endl;
780  }
781  cout << " CONSTRAINTS: " << m_constraints.size() << endl;
782  for (unsigned int i = 0; i < m_constraints.size(); i++){
783  cout << "\t\t" << i+1 << ". " << m_constraints[i]->reactionName()
784  << " " << m_constraints[i]->sumName()
785  << " " << m_constraints[i]->ampName() << endl;
786  }
787  cout << " PARAMETERS: " << m_parameters.size() << endl;
788  for (unsigned int i = 0; i < m_parameters.size(); i++){
789  cout << "\t\t" << i+1 << ". " << m_parameters[i]->parName() << endl;
790  }
791  cout << " INITIAL VALUE: " << m_value << endl;
792  cout << " REAL? " << m_real << endl;
793  cout << " FIXED? " << m_fixed << endl;
794  cout << " SCALE: " << m_scale << endl;
795 
796  if (fileName != ""){
797  outfile.close();
798  cout.rdbuf(cout_sbuf);
799  }
800 
801 }
802 
803 
804 void
805 ParameterInfo::display(string fileName, bool append){
806 
807  ofstream outfile;
808  streambuf* cout_sbuf = cout.rdbuf();
809  if (fileName != ""){
810  if (append){
811  outfile.open(fileName.c_str(), ios::out | ios::app);
812  }
813  else{
814  outfile.open(fileName.c_str());
815  }
816  cout.rdbuf(outfile.rdbuf());
817  }
818 
819  cout << "--------------------------------------------" << endl;
820  cout << "------------- PARAMETER INFO -------------" << endl;
821  cout << "--------------------------------------------" << endl;
822  cout << " PARAMETER NAME: " << m_parName << endl;
823  cout << " INITIAL VALUE: " << m_value << endl;
824  cout << " FIXED? " << m_fixed << endl;
825  cout << " BOUNDED? " << m_bounded << endl;
826  cout << " LOWER BOUND: " << m_lowerBound << endl;
827  cout << " UPPER BOUND: " << m_upperBound << endl;
828  cout << " GAUSSIAN BOUNDED? " << m_gaussianBounded << endl;
829  cout << " CENTRAL VALUE: " << m_centralValue << endl;
830  cout << " GAUSSIAN ERROR: " << m_gaussianError << endl;
831 
832  if (fileName != ""){
833  outfile.close();
834  cout.rdbuf(cout_sbuf);
835  }
836 
837 }
838 
839 
840 void
842  // don't constrain an amplitude to itself
843  if ((this->reactionName() == constraint->reactionName()) &&
844  (this->sumName() == constraint->sumName()) &&
845  (this->ampName() == constraint->ampName())) return;
846  // add "constraint" as a constraint
847  if (!hasConstraint(constraint)) m_constraints.push_back(constraint);
848  // also add all of "constraint"'s constraints as constraints
849  vector<AmplitudeInfo*> constraints = constraint->constraints();
850  for (unsigned int i = 0; i < constraints.size(); i++){
851  if (!hasConstraint(constraints[i])) addConstraint(constraints[i]);
852  }
853  // also reciprocate
854  if (!(constraint->hasConstraint(this))) constraint->addConstraint(this);
855 }
856 
857 
858 bool
860  bool foundConstraint = false;
861  for (unsigned int i = 0; i < m_constraints.size(); i++){
862  if ((m_constraints[i]->reactionName() == constraint->reactionName()) &&
863  (m_constraints[i]->sumName() == constraint->sumName()) &&
864  (m_constraints[i]->ampName() == constraint->ampName())) foundConstraint = true;
865  }
866  return foundConstraint;
867 }
868 
869 
870 void
872  // remove "constraint" as a constraint
873  if (hasConstraint(constraint)){
874  for (unsigned int i = 0; i < m_constraints.size(); i++){
875  if ((m_constraints[i]->reactionName() == constraint->reactionName()) &&
876  (m_constraints[i]->sumName() == constraint->sumName()) &&
877  (m_constraints[i]->ampName() == constraint->ampName())){
878  m_constraints.erase(m_constraints.begin()+i,m_constraints.begin()+i+1);
879  i = m_constraints.size();
880  }
881  }
882  }
883  // remove "constraint"'s constraints as constraints
884  vector<AmplitudeInfo*> constraints = constraint->constraints();
885  for (unsigned int i = 0; i < constraints.size(); i++){
886  if (hasConstraint(constraints[i])) removeConstraint(constraints[i]);
887  }
888  // reciprocate
889  if (constraint->hasConstraint(this)) constraint->removeConstraint(this);
890 }
891 
892 
893 void
895  bool foundParameter = false;
896  for (unsigned int i = 0; i < m_parameters.size(); i++){
897  if (m_parameters[i]->parName() == parameter->parName()) foundParameter = true;
898  }
899  if (!foundParameter) m_parameters.push_back(parameter);
900 }
901 
902 void
904  for (unsigned int i = 0; i < m_parameters.size(); i++){
905  if (m_parameters[i]->parName() == parameter->parName()){
906  m_parameters.erase(m_parameters.begin()+i,m_parameters.begin()+i+1);
907  i = m_parameters.size();
908  }
909  }
910 }
911 
912 
913 void
915  vector<string> empty;
916  m_data = pair<string, vector<string> >("",empty);
917  m_bkgnd = pair<string, vector<string> >("",empty);
918  m_genMC = pair<string, vector<string> >("",empty);
919  m_accMC = pair<string, vector<string> >("",empty);
920  m_normIntFile = "";
921  m_normIntFileInput = false;
922 }
923 
924 void
926  m_factors.clear();
927  m_permutations.clear();
928  m_constraints.clear();
929  m_value = complex<double>(0.0,0.0);
930  m_real = false;
931  m_fixed = false;
932  m_scale = "1.0";
933  m_parameters.clear();
934 }
935 
936 void
938  m_fixed = false;
939  m_bounded = false;
940  m_lowerBound = 0.0;
941  m_upperBound = 0.0;
942  m_gaussianBounded = false;
943  m_centralValue = 0.0;
944  m_gaussianError = 0.0;
945 }
946 
947 
948 
949 
950 
ReactionInfo * reaction(const string &reactionName) const
void removeAmplitude(const string &reactionName="", const string &sumName="", const string &ampName="")
bool fixed() const
void removeConstraint(AmplitudeInfo *constraint)
void removeReaction(const string &reactionName="")
vector< CoherentSumInfo * > coherentSumList(const string &reactionName="", const string &sumName="") const
double gaussianError() const
const pair< string, vector< string > > & accMC() const
bool gaussianBounded() const
complex< double > value() const
bool real() const
void display(string fileName="", bool append=true)
void addUserKeyword(const string &uesrKeyword, const vector< string > &arguments)
ParameterInfo * parameter(const string &parName) const
const vector< string > & particleList() const
const vector< vector< int > > & permutations() const
bool bounded() const
map< string, vector< string > > constraintMap() const
vector< vector< string > > userKeywordArguments(const string &userKeyword) const
double upperBound() const
double value() const
string scale() const
void setValue(double value)
void write(const string &fileName) const
const vector< AmplitudeInfo *> & constraints() const
void display(string fileName="", bool append=true)
vector< string > userKeywords() const
#define NULL
Definition: URtypes.h:72
const pair< string, vector< string > > & genMC() const
string reactionName() const
void display(string fileName="", bool append=true)
AmplitudeInfo * amplitude(const string &reactionName, const string &sumName, const string &ampName) const
const pair< string, vector< string > > & data() const
void display(string fileName="", bool append=false) const
ReactionInfo * createReaction(const string &reactionName, const vector< string > &particleList)
void addParameter(ParameterInfo *parameter)
const vector< vector< string > > & factors() const
double lowerBound() const
ParameterInfo * createParameter(const string &parName, double value)
void display(string fileName="", bool append=true)
vector< ParameterInfo * > parameterList(const string &reactionName="", const string &sumName="", const string &ampName="", const string &parName="") const
string fitName() const
void setParticleList(const vector< string > &particleList)
string fullName() const
bool normIntFileInput() const
string parName() const
bool fixed() const
void removeCoherentSum(const string &reactionName="", const string &sumName="")
vector< AmplitudeInfo * > amplitudeList(const string &reactionName="", const string &sumName="", const string &ampName="") const
string sumName() const
CoherentSumInfo * createCoherentSum(const string &reactionName, const string &sumName)
void removeParameter(const string &parName="")
double centralValue() const
string fullName() const
AmplitudeInfo * createAmplitude(const string &reactionName, const string &sumName, const string &ampName)
void addConstraint(AmplitudeInfo *constraint)
void removeUserKeyword(const string &userKeyword="")
bool hasConstraint(AmplitudeInfo *constraint) const
void removeParameter(ParameterInfo *parameter)
CoherentSumInfo * coherentSum(const string &reactionName, const string &sumName) const
vector< ReactionInfo * > reactionList(const string &reactionName="") const
string reactionName() const
string ampName() const
string normIntFile() const