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