CMS 3D CMS Logo

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