test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Ellipsoid.cc
Go to the documentation of this file.
2 #include "CLHEP/Units/GlobalSystemOfUnits.h"
3 #include <iostream>
4 #include <cmath>
5 
6 void DDI::Ellipsoid::stream(std::ostream & os) const
7 {
8  os << " xSemiAxis[cm]=" << p_[0]/cm
9  << " ySemiAxis[cm]=" << p_[1]/cm
10  << " zSemiAxis" << p_[2]/cm
11  << " zBottomCut" << p_[3]/cm
12  << " zTopCut" << p_[4]/cm;
13 }
14 
15 double DDI::Ellipsoid::halfVol(double dz, double maxz) const {
16  double volume(0.);
17  double z(0.);
18  double x;
19  double y;
20  double c2 = p_[2] * p_[2];
21  for (;z <= maxz; z=z+dz) {
22  // what is x here? what is y? This assumes a TRIANGLE approximation
23  // This assumes that I can estimate the decrease in x and y at current z
24  // at current z, x is the projection down to the x axis.
25  // x = a * sqrt(1-z^2 / c^2 )
26  // unneccesary paranoia?
27  if ( z*z / c2 > 1.0 ) {
28  std::cout << "error!" << std::endl;
29  exit(0);
30  }
31  x = p_[0] * sqrt( 1 - z*z/c2);
32  y = p_[1] * sqrt( 1 - z*z/c2);
33 // if (dispcount < 100)
34 // std::cout << "x = " << x << " y = " << y << " z = " << z << std::endl;
35 // ++dispcount;
36  volume = volume + Geom::pi() * dz * x * y;
37  }
38 // std::cout << " x = " << x;
39 // std::cout << " y = " << y;
40 // std::cout << " z = " << z;
41 // std::cout << " vol = " << volume << std::endl;
42  return volume;
43 }
44 
45 double DDI::Ellipsoid::volume() const {
46  double volume(0.);
47  // default if both p_[3] and p_[4] are 0
48  volume = 4./3. * Geom::pi() * p_[0] * p_[1] * p_[2];
49  if ( p_[3] > 0.0 ) {
50  //fail
51  std::cout << "FAIL: p_[3] > 0.0" <<std::endl;
52  } else if ( p_[4] < 0.0 ) {
53  //fail
54  std::cout << "FAIL: p_[4] < 0.0" <<std::endl;
55  } else if ( p_[3] < 0. && p_[4] > 0. ) {
56  volume = halfVol (p_[4]/100000., p_[4]) + halfVol (std::fabs(p_[3]/100000.), std::fabs(p_[3]));
57  } else if ( p_[3] < 0. ) {
58  volume = volume / 2 + halfVol(std::fabs(p_[3]/100000.), std::fabs(p_[3]));
59  } else if ( p_[4] > 0. ) {
60  volume = volume / 2 + halfVol (p_[4]/100000., p_[4]);
61  }
62  return volume;
63 
64 }
double volume() const
Not as flexible and possibly less accurate than G4 volume.
Definition: Ellipsoid.cc:45
double halfVol(double dz, double maxz) const
Definition: Ellipsoid.cc:15
T x() const
Cartesian x coordinate.
void stream(std::ostream &os) const
Definition: Ellipsoid.cc:6
T sqrt(T t)
Definition: SSEVec.h:48
double pi()
Definition: Pi.h:31
std::vector< double > p_
Definition: Solid.h:32
tuple cout
Definition: gather_cfg.py:121