00001
00002 #include "DetectorDescription/Base/interface/DDdebug.h"
00003
00004 #include "global_angular.h"
00005
00006
00007
00008 #include <cfloat>
00009 #define MAX_DOUBLE DBL_MAX
00010
00011
00012 #include "CLHEP/Units/GlobalSystemOfUnits.h"
00013 #include <Math/RotationZ.h>
00014
00015
00016
00017
00018
00019
00020 global_angular_0::global_angular_0(AlgoPos * a,std::string label)
00021 : AlgoImpl(a,label),
00022 rotate_(0), center_(3), rotateSolid_(0),
00023 alignSolid_(true), n_(1), startCopyNo_(1), incrCopyNo_(1),
00024 startAngle_(0), rangeAngle_(360.*deg)
00025 {
00026 DCOUT('A', "Creating angular label=" << label);
00027 }
00028
00029 global_angular_0::~global_angular_0()
00030 { }
00031
00032
00033 DD3Vector fUnitVector(double theta, double phi)
00034 {
00035 return DD3Vector(cos(phi)*sin(theta),
00036 sin(phi)*sin(theta),
00037 cos(theta));
00038 }
00039
00040
00041 bool global_angular_0::checkParameters()
00042 {
00043 bool result = true;
00044
00045 planeRot_ = DDRotationMatrix();
00046 solidRot_ = DDRotationMatrix();
00047
00048 radius_ = ParE_["radius"][0];
00049
00050 startAngle_ = ParE_["startAngle"][0];
00051 rangeAngle_ = ParE_["rangeAngle"][0];
00052 n_ = int(ParE_["n"][0]);
00053 startCopyNo_ = int(ParE_["startCopyNo"][0]);
00054 incrCopyNo_ = int(ParE_["incrCopyNo"][0]);
00055
00056 if (fabs(rangeAngle_-360.0*deg)<0.001*deg) {
00057 delta_ = rangeAngle_/double(n_);
00058 }
00059 else {
00060 if (n_ > 1) {
00061 delta_ = rangeAngle_/double(n_-1);
00062 }
00063 else {
00064 delta_ = 0.;
00065 }
00066 }
00067
00068 DCOUT('a', " startA=" << startAngle_/deg << " rangeA=" << rangeAngle_/deg <<
00069 " n=" << n_ << " delta=" << delta_/deg);
00070
00071
00072 typedef parE_type::mapped_type::size_type sz_type;
00073 sz_type sz = ParE_["rotateSolid"].size();
00074 rotateSolid_.clear();
00075 rotateSolid_.resize(sz);
00076 if (sz%3) {
00077 err_ += "\trotateSolid must occur 3*n times (defining n subsequent rotations)\n";
00078 err_ += "\t currently it appears " + d2s(sz) + " times!\n";
00079 result = false;
00080 }
00081 for (sz_type i=0; i<sz; ++i) {
00082 rotateSolid_[i] = ParE_["rotateSolid"][i];
00083 }
00084 for (sz_type i=0; i<sz; i += 3 ) {
00085 if ( (rotateSolid_[i] > 180.*deg) || (rotateSolid_[i] < 0.) ) {
00086 err_ += "\trotateSolid \'theta\' must be in range [0,180*deg]\n";
00087 err_ += "\t currently it is " + d2s(rotateSolid_[i]/deg)
00088 + "*deg in rotateSolid[" + d2s(double(i)) + "]!\n";
00089 result = false;
00090 }
00091 DDAxisAngle temp(fUnitVector(rotateSolid_[i],rotateSolid_[i+1]),
00092 rotateSolid_[i+2]);
00093 DCOUT('a', " rotsolid[" << i << "] axis=" << temp.Axis() << " rot.angle=" << temp.Angle()/deg);
00094 solidRot_ = temp*solidRot_;
00095 }
00096
00097
00098
00099
00100 sz = ParE_["rotate"].size();
00101 rotate_.clear();
00102 rotate_.resize(sz);
00103 if (sz%3) {
00104 err_ += "\trotate must occur 3*n times (defining n subsequent rotations)\n";
00105 err_ += "\t currently it appears " + d2s(sz) + " times!\n";
00106 result = false;
00107 }
00108 for (sz_type i=0; i<sz; ++i) {
00109 rotate_[i] = ParE_["rotate"][i];
00110 }
00111 for (sz_type i=0; i<sz; i += 3 ) {
00112 if ( (rotate_[i] > 180.*deg) || (rotate_[i] < 0) ) {
00113 err_ += "\trotate \'theta\' must be in range [0,180*deg]\n";
00114 err_ += "\t currently it is " + d2s(rotate_[i]/deg)
00115 + "*deg in rotate[" + d2s(double(i)) + "]!\n";
00116 result = false;
00117 }
00118 DDAxisAngle temp(fUnitVector(rotateSolid_[i],rotateSolid_[i+1]),
00119 rotateSolid_[i+2]);
00120 DCOUT('a', " rotsolid[" << i << "] axis=" << temp.Axis() << " rot.angle=" << temp.Angle()/deg);
00121 planeRot_ = planeRot_*temp;
00122 }
00123
00124
00125 center_[0] = ParE_["center"][0];
00126 center_[1] = ParE_["center"][1];
00127 center_[2] = ParE_["center"][2];
00128
00129 if (ParS_["alignSolid"][0] != "T") {
00130 DCOUT('a', " alignSolid = false");
00131 alignSolid_ = false;
00132 }
00133 else {
00134 alignSolid_ = true;
00135 }
00136
00137 return result;
00138 }
00139
00140
00141 DDTranslation global_angular_0::translation()
00142 {
00143 double angle = startAngle_+ double(count_-1)*delta_;
00144
00145 DD3Vector v = fUnitVector(90*deg,angle)*radius_ ;
00146
00147 if (rotate_[2]!=0) {
00148
00149 v = planeRot_*v;
00150 }
00151
00152 v += DD3Vector(center_[0], center_[1], center_[2]);
00153
00154 DCOUT('A', " angle=" << angle/deg << " translation=" << v << " count_=" << count_);
00155 return v;
00156 }
00157
00158
00159 DDRotationMatrix global_angular_0::rotation()
00160 {
00161
00162 DDRotationMatrix rot = solidRot_;
00163
00164 if (alignSolid_) {
00165 double angle = startAngle_+ double(count_-1)*delta_;
00166 ROOT::Math::RotationZ r2(angle);
00167 rot = r2*rot;
00168 }
00169
00170
00171 if (rotate_[2]!=0) {
00172 rot = planeRot_*rot;
00173
00174
00175 }
00176
00177 return rot;
00178 }
00179
00180
00181 int global_angular_0::copyno() const
00182 {
00183
00184
00185 int factor = AlgoImpl::copyno() - 1;
00186 return startCopyNo_ + factor*incrCopyNo_;
00187 }
00188
00189
00190
00191
00192 void global_angular_0::checkTermination()
00193 {
00194 if ( (n_-count_) == -1 ) terminate();
00195 }
00196
00197
00198 void global_angular_0::stream(std::ostream & os) const
00199 {
00200 os << "global_angular_0::stream(): not implemented.";
00201 }
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223 global_angular_Check::global_angular_Check()
00224 {
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235 constraintsE_["startAngle"] = ConstraintE( 1,
00236 1,
00237 0.,
00238 360.0*deg,
00239 false,
00240 true,
00241 0.0
00242 );
00243
00244 constraintsE_["rangeAngle"] = ConstraintE( 1,
00245 1,
00246 0.,
00247 360.0*deg,
00248 false,
00249 true,
00250 360.0*deg
00251 );
00252
00253 constraintsE_["n"] = ConstraintE( 1,
00254 1,
00255 1,
00256 +MAX_DOUBLE,
00257 false,
00258 true,
00259 1
00260 );
00261 constraintsE_["startCopyNo"] = ConstraintE( 1,
00262 1,
00263 -MAX_DOUBLE,
00264 +MAX_DOUBLE,
00265 false,
00266 true,
00267 1
00268 );
00269
00270 constraintsE_["incrCopyNo"] = ConstraintE( 1,
00271 1,
00272 -MAX_DOUBLE,
00273 +MAX_DOUBLE,
00274 false,
00275 true,
00276 1
00277 );
00278
00279
00280 constraintsE_["radius"] = ConstraintE( 1,
00281 1,
00282 0.,
00283 +MAX_DOUBLE,
00284 true,
00285 false,
00286 2
00287 );
00288
00289 constraintsS_["alignSolid"] = ConstraintS( 1,
00290 1,
00291
00292
00293 false,
00294 true,
00295 "T"
00296 );
00297
00298 constraintsE_["center"] = ConstraintE( 3,
00299 3,
00300 -MAX_DOUBLE,
00301 +MAX_DOUBLE,
00302 false,
00303 true,
00304 0.
00305 );
00306
00307 constraintsE_["rotate"] = ConstraintE( 3,
00308 9,
00309 -360.0*deg,
00310 360.0*deg,
00311 false,
00312 true,
00313 0.0
00314 );
00315
00316 constraintsE_["rotateSolid"] = ConstraintE( 3,
00317 9,
00318 -360.0*deg,
00319 360.0*deg,
00320 false,
00321 true,
00322 0.0
00323 );
00324
00325 }
00326
00327