TDSPVector* TDSPBlockOperation::MeanPower(Int_t       bl,
					  TDSPVector *in, 
					  TDSPVector *result) {
  
  if (!result) result = new TDSPVector();

  result->SetLen(bl);

  
  Int_t     len = in->GetLen();
  TComplex  *iv = in->GetVec();
  TComplex  *ov = result->GetVec();

  Int_t     num = len/bl;
  
  if (len%bl) {
    Error("MeanPower","length of input vector (%d) is not a multiple of the block len (%d)!",len,bl);
  }

  result->Zeros();

  for(register Int_t i=0;i<len;++i) {
    ov[i%bl] += Abs2(iv[i]);
  }
  for(register Int_t j=0;j<bl;++j) ov[j] /= num;

  return result;
}
TDSPVector* TDSPBlockOperation::Sum2Diff(Int_t       bl,
					 TDSPVector *in1, 
					 TDSPVector *in2, 
					 TDSPVector *result,
					 TComplex    scaler) {
  
  
  Int_t     len1  = in1->GetLen();
  TComplex  *iv1  = in1->GetVec();


  Int_t     len2  = in1->GetLen();
  TComplex  *iv2  = in2->GetVec();

  if (len1!=len2) {
    Warning("Diff","input length differ (%d<>%d)",len1,len2);
  }

  if (len1%bl) {
    Warning("Diff","length of input vector1 (%d) is not a multiple of the block len (%d)!",len1,bl);
  }

  if (len2%bl) {
    Warning("Diff","length of input vector2 (%d) is not a multiple of the block len (%d)!",len2,bl);
  }

  Int_t len=TMath::Min(len1,len2);

  if (!result) result = new TDSPVector();
  result->SetLen(bl);
  TComplex  *ov = result->GetVec();

  result->Zeros();
  
  if (scaler==1.) {
    for(register Int_t i=0;i<len;++i) {
      ov[i%bl] += Abs2(iv1[i]-iv2[i]);
    }
  } else {
    for(register Int_t i=0;i<len;++i) {
      ov[i%bl] += Abs2(iv1[i]-scaler*iv2[i]);
    }
  }

  return result;
}
Exemplo n.º 3
0
void Surface :: Project (Point<3> & p) const
{
  Vec<3> n;
  double val;

  for (int i = 1; i <= 10; i++)
    {
      val = CalcFunctionValue (p);
      if (fabs (val) < 1e-12) return;
	
      CalcGradient (p, n);
      p -= (val / Abs2 (n)) * n;
    }
}
Exemplo n.º 4
0
void ProjectToEdge (const Surface * f1, const Surface * f2, Point<3> & hp)
{
  Vec<2> rs, lam;
  Vec<3> a1, a2;
  Mat<2> a;

  int i = 10;
  while (i > 0)
    {
      i--;
      rs(0) = f1 -> CalcFunctionValue (hp);
      rs(1) = f2 -> CalcFunctionValue (hp);
      f1->CalcGradient (hp, a1);
      f2->CalcGradient (hp, a2);

      double alpha = fabs(a1*a2)/sqrt(a1.Length2()*a2.Length2());
      if(fabs(1.-alpha) < 1e-6)
	{
	  if(fabs(rs(0)) >= fabs(rs(1)))
	    f1 -> Project(hp);
	  else
	    f2 -> Project(hp);
	}
      else
	{

	  a(0,0) = a1 * a1;
	  a(0,1) = a(1,0) = a1 * a2;
	  a(1,1) = a2 * a2;
	  
	  a.Solve (rs, lam);

	  hp -= lam(0) * a1 + lam(1) * a2;
	}

      if (Abs2 (rs) < 1e-24 && i > 1) i = 1;
    }
}
Exemplo n.º 5
0
 inline double Dist2 (const Point<D> & a, const Point<D> & b)
 {
   return Abs2 (a-b);
 }