AmpTools
IntensityManager.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 <sstream>
39 #include <fstream>
40 
41 #include <sys/time.h>
42 
43 #include <vector>
44 #include <string>
45 #include <map>
46 #include <list>
47 #include <complex>
48 #include <string.h>
49 #include <algorithm>
50 #include <cassert>
51 
54 #include "IUAmpTools/Kinematics.h"
55 
56 IntensityManager::IntensityManager( const vector< string >& reaction,
57  const string& reactionName) :
58 m_reactionName(reactionName),
59 m_renormalizeTerms( false ),
60 m_normInt( NULL )
61 {
62 
63 }
64 
65 double
66 IntensityManager::calcIntensity( const Kinematics* kinematics ) const
67 {
68 
69  // Create and fill an AmpVecs object with a single event
70  AmpVecs aVecs;
71  aVecs.loadEvent(kinematics);
72  aVecs.allocateTerms(*this,true);
73 
74  // Calculate the intensity based on this one event
75  calcIntensities(aVecs);
76  GDouble intensity = aVecs.m_pdIntensity[0];
77 
78  // Deallocate memory and return
79  aVecs.deallocAmpVecs();
80 
81  return intensity;
82 
83 }
84 
85 int
86 IntensityManager::addTerm( const string& name,
87  const string& scale ){
88 
89  // track the name and sum based on index
90  m_termNames.push_back( name );
91 
92  // record the index
93  m_termIndex[name] = m_termNames.size() - 1;
94 
95  m_prodFactorVec.push_back( static_cast< complex< double >* >( 0 ) );
96  m_termScaleVec.push_back( AmpParameter( scale ) );
97 
98  setDefaultProductionFactor( name, complex< double >( 1, 0 ) );
99 
100  return m_termIndex[name];
101 }
102 
103 
104 const vector< string >&
106 
107  return m_termNames;
108 }
109 
110 const AmpParameter&
111 IntensityManager::getScale( const string& name ) const {
112 
113  return m_termScaleVec[termIndex(name)];
114 }
115 
116 int
117 IntensityManager::termIndex( const string& termName ) const {
118 
119  map< string, int >::const_iterator mapItr = m_termIndex.find( termName );
120  assert( mapItr != m_termIndex.end() );
121 
122  return mapItr->second;
123 }
124 
125 bool
126 IntensityManager::hasTerm(const string& name) const {
127 
128  map< string, const complex< double >* >::const_iterator prodItr = m_prodFactor.find( name );
129  return (prodItr != m_prodFactor.end()) ? true : false;
130 }
131 
132 
133 complex< double >
134 IntensityManager::productionFactor( const string& name ) const {
135 
136  if( m_prodFactor.find( name ) == m_prodFactor.end() ){
137 
138  cout << "ERROR: cannot provide production amplitude for " << name << endl;
139  assert( false );
140  }
141 
142  return productionFactor( m_termIndex.at( name ) );
143 }
144 
145 complex< double >
146 IntensityManager::productionFactor( int ampIndex ) const {
147 
148  return *m_prodFactorVec.at( ampIndex ) *
149  static_cast< double >( m_termScaleVec.at( ampIndex ) );
150 }
151 
152 void
153 IntensityManager::prodFactorArray( double* array ) const {
154 
155  complex< double > value;
156 
157  for( int i = 0; i < m_prodFactorVec.size(); ++i ){
158 
159  value = *m_prodFactorVec[i] *
160  static_cast< double >( m_termScaleVec[i] );
161 
162  array[2*i] = real( value );
163  array[2*i+1] = imag( value );
164  }
165 }
166 
167 void
169  complex< double > prodFactor )
170 {
171  m_defaultProdFactor[name] = prodFactor;
172  m_prodFactor[name] = &(m_defaultProdFactor[name]);
173  m_prodFactorVec[m_termIndex[name]] = &(m_defaultProdFactor[name]);
174 }
175 
176 void
178  const complex< double >* prodAmpPtr )
179 {
180  map< string, const complex< double >* >::iterator prodItr = m_prodFactor.find( name );
181 
182  if( prodItr == m_prodFactor.end() ){
183 
184  cout << "ERROR: amplitude " << name << " has no factors!" << endl;
185  assert( false );
186  }
187 
188  m_prodFactor[name] = prodAmpPtr;
189  m_prodFactorVec[m_termIndex[name]] = prodAmpPtr;
190 }
191 
192 void
194 {
195  for( map< string, complex< double > >::iterator
196  prodItr = m_defaultProdFactor.begin();
197  prodItr != m_defaultProdFactor.end(); ++prodItr ){
198 
199  m_prodFactor[prodItr->first] = &(m_defaultProdFactor[prodItr->first]);
200  m_prodFactorVec[m_termIndex[prodItr->first]] = &(m_defaultProdFactor[prodItr->first]);
201  }
202 }
203 
204 void
205 IntensityManager::setParPtr( const string& name, const string& parName,
206  const double* ampParPtr ){
207 
208  if( m_termScaleVec[m_termIndex[name]].name() == parName ){
209 
210  m_termScaleVec[m_termIndex[name]].setExternalValue( ampParPtr );
211  }
212 }
213 
214 void
215 IntensityManager::setParValue( const string& name, const string& parName,
216  double val ){
217 
218  if( m_termScaleVec[m_termIndex[name]].name() == parName ){
219 
220  m_termScaleVec[m_termIndex[name]].setValue( val );
221  }
222 }
223 
224 /*
225  * disable these for now until a fix is made to the NormIntInterface to prevent
226  * problems with free parameters in amplitudes
227 
228  void
229  IntensityManager::renormalizeAmps( const NormIntInterface* normInt ){
230 
231  m_normInt = normInt;
232  m_renormalizeAmps = true;
233  }
234 
235  void
236  IntensityManager::disableRenormalization(){
237 
238  m_renormalizeAmps = false;
239  }
240  */
241 
void setExternalProductionFactor(const string &ampName, const complex< double > *prodAmpPtr)
void allocateTerms(const IntensityManager &intenMan, bool bAllocIntensity=false)
Definition: AmpVecs.cc:235
void prodFactorArray(double *array) const
double calcIntensity(const Kinematics *kinematics) const
virtual void setParValue(const string &termName, const string &parName, double ampParValue)
bool hasTerm(const string &termName) const
double GDouble
IntensityManager(const vector< string > &reaction, const string &reactionName)
void deallocAmpVecs()
Definition: AmpVecs.cc:73
virtual double calcIntensities(AmpVecs &ampVecs) const =0
int termIndex(const string &termName) const
virtual void setParPtr(const string &termName, const string &parName, const double *ampParPtr)
const vector< string > & getTermNames() const
#define NULL
Definition: URtypes.h:72
void setDefaultProductionFactor(const string &termName, complex< double > prodAmp)
const AmpParameter & getScale(const string &name) const
int addTerm(const string &termName, const string &scale="1.0")
GDouble * m_pdIntensity
Definition: AmpVecs.h:137
complex< double > productionFactor(const string &termName) const
void loadEvent(const Kinematics *pKinematics, unsigned long long iEvent=0, unsigned long long iNTrueEvents=1, bool bForceNegativeWeight=false)
Definition: AmpVecs.cc:128