FlyoDoc_2011 Pisa 2011 by GmP --- 011

flyopunta/src/src_uti/gcomplx.cpp

00001 /***************************************************************************
00002                           gcomplx.cpp  -  description
00003                              -------------------
00004     begin                : Wed Aug 15 2001
00005     copyright            : (C) 2001 by Giuseppe Pierazzini
00006     email                : peppe@unipi.it
00007   ***************************************************************************
00008   *                                                                         *
00009   *   NA48  simulation program.                                             *
00010   *                                                                         *
00011 
00012 ***************************************************************************/
00013 #define GCOMPLX
00014 #include "parm.h"
00015 #include "gcomplx.h"
00016 
00017    Gcomplx Rgc[100];
00018    Gcomplx *Prgc;
00019    int Ireg=0;
00020 
00021 
00022 // -------
00023 
00024 
00025  Gcomplx::Gcomplx(double parm)
00026   { real=parm;
00027     imm=parm;
00028     norma=normaq=0.0;
00029   }
00030 
00031  Gcomplx::Gcomplx(double a, double b)
00032   {
00033      real=a;
00034      imm=b;
00035      Norma();
00036   }
00037 
00038  Gcomplx::~Gcomplx(){}
00039 //-----------------------------------
00040 
00041 
00042  double  Gcomplx::Norma()
00043  { normaq=real*real + imm*imm;
00044    norma=sqrt(normaq);
00045 
00046    return norma;
00047  }
00048 
00049   double& Gcomplx::operator[](int i) {
00050           if(i==0)return real; else return imm;}
00051 
00052 // asssegnamento
00053   Gcomplx & Gcomplx::operator=(Gcomplx& a)                //  ritorna il vettore a..
00054     { real=a.real;imm=a.imm;     //   si puo' scrivere A=B=C..
00055       normaq=a.normaq;norma=a.norma; return a;
00056     }
00057 
00058   Gcomplx & Gcomplx::operator=(Gcomplx * a)
00059     {   *this=*a;  return *a; }
00060 
00061   Gcomplx &  Gcomplx::operator=(double *a)
00062     {real=a[0];imm=a[1];
00063      normaq=real*real + imm*imm;
00064      norma=sqrt(normaq);
00065      return *this;
00066     }
00067   Gcomplx &  Gcomplx::operator=(double a)
00068     {real=a;imm=0.;
00069      normaq=a*a;
00070      norma=fabs(a);
00071      return *this;
00072     }
00073 
00074 
00075 
00076 
00077 // incrementi
00078 
00079   Gcomplx & Gcomplx::operator+=(Gcomplx& a)  // attenzione non calcola
00080     { real+=a.real;imm+=a.imm; return *this;}
00081 
00082   Gcomplx & Gcomplx::operator+=(Gcomplx * a)  // attenzione non calcol
00083     {  *this+=*a; return *this;}
00084 
00085   Gcomplx & Gcomplx::operator+=(double a)  // attenzione non calcol
00086     {  real+=a; return *this;}
00087 
00088 
00089   Gcomplx & Gcomplx::operator-=(Gcomplx * a) // attenzione non calcol
00090     {  *this-=*a; return *this;}
00091 
00092   Gcomplx & Gcomplx::operator-=(Gcomplx& a)                 // attenzione non calcola no
00093     { real-=a.real;imm-=a.imm; return *this;}
00094 
00095   Gcomplx & Gcomplx::operator-=(double a)  // attenzione non calcol
00096     {  real-=a; return *this;}
00097 
00098 
00099 
00100  // operatore unario di cambio segno
00101 
00102   Gcomplx & Gcomplx::operator-()
00103      { real=-real;imm=-imm;return *this;}
00104 
00105 
00106 
00107 // prodotto di due complessi
00108 
00109  Gcomplx & Gcomplx::operator*(Gcomplx &A)
00110    { Ireg++; if(Ireg>99)Ireg=0; Prgc=(Rgc+Ireg);
00111 
00112      Prgc->real=real*A.real-imm*A.imm;
00113      Prgc->imm=imm*A.real+real*A.imm;
00114      Prgc->Norma();
00115      return *Prgc;
00116     }
00117 
00118  Gcomplx & Gcomplx::operator*(Gcomplx *A)
00119   { return *this*(*A);}
00120 
00121 
00122  // prodotto per uno scalare
00123 
00124  Gcomplx & Gcomplx::operator*(double b)
00125    { Ireg++; if(Ireg>99)Ireg=0; Prgc=(Rgc+Ireg);
00126      Prgc->real=real*b;
00127      Prgc->imm=imm*b;
00128      Prgc->norma=norma*fabs(b);
00129      Prgc->normaq=normaq*b*b;
00130      return *Prgc;
00131     }
00132 
00133  Gcomplx & operator*(double c,Gcomplx & A)  // friend function for symmetry
00134     { return A*c;}
00135 
00136  Gcomplx & Gcomplx::operator*=(Gcomplx &A)
00137    {
00138      double re=real*A.real-imm*A.imm;
00139      double im =imm*A.real+real*A.imm;
00140      real=re; imm=im;
00141      Norma();
00142      return *this;
00143    }
00144 
00145 
00146 
00147 
00148 
00149 
00150 //rapporto
00151  Gcomplx & Gcomplx::operator/(Gcomplx &A)
00152    {
00153      return *this * A.Inverso();
00154     }
00155  Gcomplx & Gcomplx::operator/(Gcomplx *A)
00156    { return *this / *A;     }
00157 
00158  Gcomplx & Gcomplx::operator/(double a)
00159    {
00160     a=1./a;
00161     return   *this*a;
00162    }
00163  Gcomplx & operator/(double c,Gcomplx & A)  //friend
00164     { return A.Inverso()*c;}
00165 
00166  Gcomplx & Gcomplx::operator/=(Gcomplx &A)
00167    {
00168      *this= *this * A.Inverso();
00169      Norma();
00170      return *this ;
00171     }
00172 
00173 
00174  // prodotto scalare
00175  double Gcomplx::operator%(Gcomplx & A)
00176    {  return(real*A.real-imm*A.imm);}
00177 
00178  double Gcomplx::operator%(Gcomplx * A)          // attenzione..funziona...........
00179    { return this[0]%A[0];}
00180 
00181  //somma
00182 
00183   Gcomplx&  Gcomplx::operator+(Gcomplx& A)
00184     {
00185       Ireg++; if(Ireg>99)Ireg=0; Prgc=(Rgc+Ireg);
00186       Prgc->real=real+A.real;
00187       Prgc->imm=imm  +A.imm;
00188       return *Prgc;}
00189 
00190   Gcomplx&  Gcomplx::operator+(Gcomplx* a)
00191      {  return *this + *a;}
00192 
00193   Gcomplx&  Gcomplx::operator+(double r)
00194      {Ireg++; if(Ireg>99)Ireg=0; Prgc=(Rgc+Ireg);
00195       Prgc->real=r+real;
00196       Prgc->imm=imm;
00197       return *Prgc;}
00198   Gcomplx&  operator+(double r,Gcomplx& A)
00199      {Ireg++; if(Ireg>99)Ireg=0; Prgc=(Rgc+Ireg);
00200       Prgc->real=r+A.real;
00201       Prgc->imm=A.imm;
00202       return *Prgc;}
00203 
00204 
00205 // sottrazione
00206 
00207    Gcomplx&  Gcomplx::operator-(Gcomplx& A)
00208      {
00209        Ireg++; if(Ireg>99)Ireg=0; Prgc=(Rgc+Ireg);
00210        Prgc->real=real-A.real;
00211        Prgc->imm=imm  -A.imm;
00212        return *Prgc;}
00213 
00214    Gcomplx&  Gcomplx::operator-(Gcomplx* a)
00215       {  return *this - *a;}
00216 
00217    Gcomplx&  Gcomplx::operator-(double r)
00218       {Ireg++; if(Ireg>99)Ireg=0; Prgc=(Rgc+Ireg);
00219        Prgc->real=real-r;
00220        Prgc->imm=imm;
00221        return *Prgc;}
00222    Gcomplx&  operator-(double r,Gcomplx& A)
00223       {Ireg++; if(Ireg>99)Ireg=0; Prgc=(Rgc+Ireg);
00224        Prgc->real=r-A.real;
00225        Prgc->imm=A.imm;
00226        return *Prgc;}
00227 
00228 
00229 
00230  // coniugata
00231 
00232  Gcomplx & Gcomplx::operator&()
00233      {Ireg++; if(Ireg>99)Ireg=0; Prgc=(Rgc+Ireg);
00234       Prgc->real=real;
00235       Prgc->imm=-imm;
00236       return  *Prgc;}
00237 
00238 
00239 
00240 // inverso
00241 Gcomplx & Gcomplx::Inverso()
00242   { Ireg++; if(Ireg>99) Ireg=0; Prgc=(Rgc+Ireg);
00243    Prgc->real=real/normaq;
00244    Prgc->imm=-imm/normaq;
00245    Prgc->norma=1./norma;
00246    Prgc->normaq=1./normaq;
00247    return  *Prgc;
00248 
00249 /*    Rgc[Ireg].real=real/normaq;
00250    Rgc[Ireg].imm=-imm/normaq;
00251    Rgc[Ireg].norma=1./norma;
00252    Rgc[Ireg].normaq=1./normaq;
00253    return  Rgc[Ireg];
00254 */
00255 
00256   }
00257 
00258  // ritorna il vettore normalizzato
00259  Gcomplx & Gcomplx::Verso()
00260    { Ireg++; if(Ireg>99) Ireg=0; Prgc=(Rgc+Ireg);
00261      Prgc->real=real/norma;
00262      Prgc->imm=imm/norma;
00263      Prgc->norma=Prgc->normaq=1.0;
00264      return *Prgc;
00265    }
00266 
00267  Gcomplx & Gcomplx::Set(double a,double b)
00268    { real=a;
00269      imm=b;
00270      normaq=real*real + imm*imm;
00271      norma=sqrt(normaq);
00272      return *this;
00273    }
00274 
00275 
00276   // output per debug...............
00277   void   Gcomplx::print(char *t)
00278     {
00279     
00280      using namespace std;                 
00281      Gout.precision(5);
00282      Gout<<std::setfill(' ')<<std::fixed;      
00283      Gout<<"\n"<<setw(10)<<t<<"=[r: "<<setw(12)<<real<<"  i:=["
00284      <<setw(12)<<imm<<"] |"<<setw(12)<<norma<<"| "<<endl;       
00285     }       
00286 
 All Classes Namespaces Files Functions Variables