53 m_pIntenManager(
NULL ),
54 m_accMCReader(
NULL ),
55 m_genMCReader(
NULL ),
56 m_emptyNormIntCache( true ),
57 m_emptyAmpIntCache( true )
61 m_pIntenManager(
NULL ),
62 m_accMCReader(
NULL ),
63 m_genMCReader(
NULL ),
64 m_emptyNormIntCache( true ),
65 m_emptyAmpIntCache( true )
68 cout <<
"Reading cached normalization integral calculation from: " 69 << normIntFile << endl;
71 ifstream inFile( normIntFile.c_str() );
74 cout <<
"NormIntInterface WARNING: Could not find file " 75 << normIntFile << endl;
86 m_pIntenManager( &intenManager ),
87 m_accMCReader( accMCData ),
88 m_genMCReader( genMCData ),
89 m_emptyNormIntCache( true ),
90 m_emptyAmpIntCache( true ),
91 m_termNames( intenManager.getTermNames() )
93 assert( ( m_accMCReader !=
NULL ) && ( m_genMCReader !=
NULL ) );
97 m_nGenEvents = m_genMCReader->
numEvents();
98 m_nAccEvents = m_accMCReader->
numEvents();
107 input >> m_nGenEvents >> m_nAccEvents;
115 for(
int i = 0; i < numTerms; ++i ){
119 m_termNames.push_back( name );
120 m_termIndex[name] = i;
125 for(
int i = 0; i < numTerms; ++i ){
126 for(
int j = 0; j < numTerms; ++j ){
128 complex< double > integral;
131 m_ampIntCache[2*i*numTerms+2*j] = real( integral );
132 m_ampIntCache[2*i*numTerms+2*j+1] = imag( integral );
136 for(
int i = 0; i < numTerms; ++i ){
137 for(
int j = 0; j < numTerms; ++j ){
139 complex< double > integral;
142 m_normIntCache[2*i*numTerms+2*j] = real( integral );
143 m_normIntCache[2*i*numTerms+2*j+1] = imag( integral );
147 m_emptyNormIntCache =
false;
148 m_emptyAmpIntCache =
false;
160 double totalAccEvts = nAccEvts + m_nAccEvents;
161 double totalGenEvts = nGenEvts + m_nGenEvents;
163 string ampName, conjAmpName;
165 int n = m_termNames.size();
167 for(
int i = 0; i < n; ++i ){
168 for(
int j = 0; j < n; ++j ){
170 m_ampIntCache[2*i*n+j] *= m_nAccEvents;
171 m_ampIntCache[2*i*n+j+1] *= m_nAccEvents;
173 complex< double > ai = nii.
ampInt( m_termNames[i], m_termNames[j] );
175 m_ampIntCache[2*i*n+j] += nAccEvts * real( ai );
176 m_ampIntCache[2*i*n+j+1] += nAccEvts * imag( ai );
178 m_ampIntCache[2*i*n+j] /= totalAccEvts;
179 m_ampIntCache[2*i*n+j+1] /= totalAccEvts;
182 m_ampIntCache[2*i*n+j] *= m_nGenEvents;
183 m_ampIntCache[2*i*n+j+1] *= m_nGenEvents;
185 complex< double > ni = nii.
normInt( m_termNames[i], m_termNames[j] );
187 m_ampIntCache[2*i*n+j] += nGenEvts * real( ni );
188 m_ampIntCache[2*i*n+j+1] += nGenEvts * imag( ni );
190 m_ampIntCache[2*i*n+j] /= totalGenEvts;
191 m_ampIntCache[2*i*n+j+1] /= totalGenEvts;
197 m_nAccEvents = totalAccEvts;
198 m_nGenEvents = totalGenEvts;
200 m_emptyNormIntCache =
false;
201 m_emptyAmpIntCache =
false;
208 return( ( m_accMCReader !=
NULL ) &&
209 ( m_genMCReader !=
NULL ) &&
210 ( m_pIntenManager !=
NULL ) );
217 return( ( m_termIndex.find( amp ) != m_termIndex.end() ) &&
218 ( m_termIndex.find( conjAmp ) != m_termIndex.end() ) );
228 cout <<
"ERROR: normalization integral does not exist for " 229 << amp <<
", " << conjAmp <<
"*" << endl;
241 cout <<
"ERROR: the AmplitudeManager has amplitudes that contain free\n" 242 <<
" parameters, but no MC has been provided to recalculate\n" 243 <<
" the normalization integrals. Check that config file\n" 244 <<
" lists appropriate data and MC sources." << endl;
256 int n = m_termNames.size();
257 int i = m_termIndex.find( amp )->second;
258 int j = m_termIndex.find( conjAmp )->second;
260 return complex< double >( m_normIntCache[2*i*n+2*j],
261 m_normIntCache[2*i*n+2*j+1] );
281 if( !forceUseCache && ( m_pIntenManager !=
NULL ) &&
284 cout <<
"WARNING: request of for numerical integral of amplitude\n" 285 <<
" that has floating parameters using *generated* MC.\n" 286 <<
" (This is not typically used in a fit -- check for bugs!)\n" 287 <<
" Providing original cached value which may be incorrect if\n" 288 <<
" the parameter has changed since initialization." 302 cout <<
"ERROR: amplitude integral does not exist for " 303 << amp <<
", " << conjAmp <<
"*" << endl;
307 int n = m_termNames.size();
308 int i = m_termIndex.find( amp )->second;
309 int j = m_termIndex.find( conjAmp )->second;
311 return complex< double >( m_ampIntCache[2*i*n+2*j],
312 m_ampIntCache[2*i*n+2*j+1] );
322 assert( m_accMCReader !=
NULL );
324 if( !m_emptyNormIntCache && normIntOnly ){
332 m_emptyNormIntCache =
false;
343 assert( m_genMCReader !=
NULL );
348 cout <<
"Loading generated Monte Carlo..." << endl;
351 cout <<
"\tDone.\n" << flush;
353 cout <<
"Calculating integrals..." << endl;
356 cout <<
"\tDone." << endl;
358 m_emptyAmpIntCache =
false;
361 if( ( m_accMCReader == m_genMCReader ) && !m_emptyAmpIntCache )
364 cout <<
"Perfect acceptance -- using integrals from generated MC" << endl;
373 cout <<
"Loading acccepted Monte Carlo..." << endl;
376 cout <<
"\tDone." << endl;
381 cout <<
"Calculating integrals..." << endl;
385 cout <<
"\tDone." << endl;
388 m_emptyNormIntCache =
false;
396 ofstream out( fileName.c_str() );
406 out << m_nGenEvents <<
"\t" << m_nAccEvents << endl;
408 out << m_termNames.size() << endl;
410 for( vector< string >::const_iterator name = m_termNames.begin();
411 name != m_termNames.end();
414 out << *name << endl;
417 int n = m_termNames.size();
420 for(
int i = 0; i < n ; ++i ){
421 for(
int j = 0; j < n; ++j ) {
423 complex< double > value( m_ampIntCache[2*i*n+2*j],
424 m_ampIntCache[2*i*n+2*j+1] );
431 value /=
sqrt( m_ampIntCache[2*i*n+2*i] *
432 m_ampIntCache[2*j*n+2*j] );
436 out << value <<
"\t";
443 for(
int i = 0; i < n ; ++i ){
444 for(
int j = 0; j < n; ++j ) {
446 complex< double > value( m_normIntCache[2*i*n+2*j],
447 m_normIntCache[2*i*n+2*j+1] );
456 value /=
sqrt( m_ampIntCache[2*i*n+2*i] *
457 m_ampIntCache[2*j*n+2*j] );
461 out << value <<
"\t";
469 NormIntInterface::initializeCache() {
471 int n = m_termNames.size();
473 for(
int i = 0; i < n; ++i )
474 m_termIndex[m_termNames[i]] = i;
481 m_normIntCache =
new GDouble[m_cacheSize];
482 m_ampIntCache =
new GDouble[m_cacheSize];
484 memset( m_normIntCache, 0, m_cacheSize *
sizeof(
GDouble ) );
485 memset( m_ampIntCache, 0, m_cacheSize *
sizeof(
GDouble ) );
491 memcpy( m_ampIntCache, input, m_cacheSize *
sizeof(
GDouble ) );
492 m_emptyAmpIntCache =
false;
498 memcpy( m_normIntCache, input, m_cacheSize *
sizeof(
GDouble ) );
499 m_emptyNormIntCache =
false;
void exportNormIntCache(const string &fileName, bool renormalize=false) const
void allocateTerms(const IntensityManager &intenMan, bool bAllocIntensity=false)
virtual complex< double > normInt(string amp, string conjAmp, bool forceUseCache=false) const
const IntensityManager * intenManager() const
bool hasNormInt(string amp, string conjAmp) const
void operator+=(const NormIntInterface &nii)
virtual complex< double > ampInt(string amp, string conjAmp, bool forceUseCache=false) const
virtual void forceCacheUpdate(bool normIntOnly=false) const
bool hasAmpInt(string amp, string conjAmp) const
virtual bool hasTermWithFreeParam() const =0
const vector< string > & getTermNames() const
bool hasAccessToMC() const
virtual unsigned int numEvents() const =0
void loadData(DataReader *pDataReader, bool bForceNegativeWeight=false)
void setAmpIntMatrix(const double *input) const
istream & loadNormIntCache(istream &in)
virtual void calcIntegrals(AmpVecs &Vecs, int iNGenEvents) const =0
GDouble * m_pdIntegralMatrix
void setNormIntMatrix(const double *input) const