From 96503690de562b4a009ddcea91adf1808f362167 Mon Sep 17 00:00:00 2001
From: Bertram Kopf <bertram@ep1.rub.de>
Date: Fri, 12 Jan 2024 22:45:34 +0100
Subject: [PATCH] improved performance for tensor amp calculations III

---
 PwaUtils/EvtDataBaseList.hh   | 3 ++-
 PwaUtils/IsobarTensorDecay.cc | 3 ++-
 PwaUtils/TensorDecAmps.cc     | 7 +++++--
 3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/PwaUtils/EvtDataBaseList.hh b/PwaUtils/EvtDataBaseList.hh
index eb5b560a..804975d2 100644
--- a/PwaUtils/EvtDataBaseList.hh
+++ b/PwaUtils/EvtDataBaseList.hh
@@ -44,7 +44,7 @@ typedef std::map<unsigned short, double> mapShortDouble;
 typedef std::map<unsigned short, Vector4<double> > mapShort4Vec;
 typedef std::map<unsigned short, map<Id2StringType, complex<double> > > mapShortInt2Complex;
 typedef std::map<unsigned short, map<unsigned short, map<Id3StringType, complex<double> > > > mapShortShortInt3Complex;
-
+typedef std::map<unsigned short, map<Id3StringType, map<unsigned short, complex<double> > > > mapShortInt3ShortComplex;
 
 struct EvtData {
   mapShortInt3Complex WignerDIdId3;
@@ -55,6 +55,7 @@ struct EvtData {
   mapShortInt2Complex Complex2Spin;
   mapShortShortInt3Complex ComplexLS3Spin;
   mapShortShortInt3Complex ComplexN3Spin;
+  mapShortInt3ShortComplex Complex3SpinLS;
   double evtWeight;
   int evtNo;
 };
diff --git a/PwaUtils/IsobarTensorDecay.cc b/PwaUtils/IsobarTensorDecay.cc
index f5266221..1a1692cf 100644
--- a/PwaUtils/IsobarTensorDecay.cc
+++ b/PwaUtils/IsobarTensorDecay.cc
@@ -295,7 +295,8 @@ void IsobarTensorDecay::fillWignerDs(std::map<std::string, Vector4<double> >& fs
 	  }
 	  Id3StringType IdLamXLam1Lam2=FunctionUtils::spin3Index(lamMother, lamDaughter1, lamDaughter2);
 	  unsigned short currentLSId=(*itJPCLS)->idnumberLS;
-	  evtData->ComplexLS3Spin[_nameId][currentLSId][IdLamXLam1Lam2]=result(0);	  
+	  // evtData->ComplexLS3Spin[_nameId][currentLSId][IdLamXLam1Lam2]=result(0);
+          evtData->Complex3SpinLS[_nameId][IdLamXLam1Lam2][currentLSId]=result(0);
 	}
       }
     }
diff --git a/PwaUtils/TensorDecAmps.cc b/PwaUtils/TensorDecAmps.cc
index ee59d983..2931e096 100644
--- a/PwaUtils/TensorDecAmps.cc
+++ b/PwaUtils/TensorDecAmps.cc
@@ -119,7 +119,8 @@ complex<double> TensorDecAmps::lsLoop(AbsXdecAmp* grandmaAmp, Spin lamX, EvtData
 				      Spin lam1Max, Spin lam2Min, Spin lam2Max, bool withDecs) {
   complex<double> result(0.,0.);
 
-  map<unsigned short, map<Id3StringType, complex<double> > >& currentLS3SpinMap=theData->ComplexLS3Spin.at(_decay->nameId());
+  // map<unsigned short, map<Id3StringType, complex<double> > >& currentLS3SpinMap=theData->ComplexLS3Spin.at(_decay->nameId());
+  map<Id3StringType, map<unsigned short, complex<double> > >& current3SpinLSMap=theData->Complex3SpinLS.at(_decay->nameId());
   std::vector< std::shared_ptr<const LScomb> >::const_iterator itLS;
 
   for(Spin lambda1=-_Jdaughter1; lambda1<=_Jdaughter1; ++lambda1){
@@ -127,9 +128,11 @@ complex<double> TensorDecAmps::lsLoop(AbsXdecAmp* grandmaAmp, Spin lamX, EvtData
       for(Spin lambda2=-_Jdaughter2; lambda2<=_Jdaughter2; ++lambda2){ 
       if(lambda2<lam2Min || lambda2>lam2Max) continue;
       Id3StringType IdLamXLam1Lam2=FunctionUtils::spin3Index(lamX, lambda1, lambda2);
+      map<unsigned short, complex<double> >& currentLSMap = current3SpinLSMap.at(IdLamXLam1Lam2);
       complex<double> amp(0.,0.);
       for(itLS=_LSs.begin(); itLS!=_LSs.end(); ++itLS){
-	complex<double> tmpamp=_currentParamMagExpi.at(*itLS)*currentLS3SpinMap.at((*itLS)->idnumberLS).at(IdLamXLam1Lam2);
+	//complex<double> tmpamp=_currentParamMagExpi.at(*itLS)*currentLS3SpinMap.at((*itLS)->idnumberLS).at(IdLamXLam1Lam2);
+	complex<double> tmpamp=_currentParamMagExpi.at(*itLS)*currentLSMap.at((*itLS)->idnumberLS);
 	if (_absDyn->isLdependent()){
           tmpamp *=_cachedDynIdLSMap.at((*itLS)->L).at(_absDyn->grandMaId(grandmaAmp));
         }
-- 
GitLab