CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/DetectorDescription/Algorithm/src/global_angular.cc

Go to the documentation of this file.
00001 
00002 #include "DetectorDescription/Base/interface/DDdebug.h"
00003 // GENERATED FILE. DO NOT MODIFY!
00004 #include "global_angular.h"
00005 // I tried the following on CERN lxplus and still no MAX_DOUBLE was defined.
00006 // so I tried DBL_MAX which does exist, but I do not know the source of this.
00007 // So, in keeping with everything else I saw:
00008 #include <cfloat>
00009 #define MAX_DOUBLE DBL_MAX
00010 //#include <climits>
00011 
00012 #include "CLHEP/Units/GlobalSystemOfUnits.h"
00013 #include <Math/RotationZ.h>
00014 
00015 
00016  //your code here 
00017 
00018 
00019 // always the same ctor
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) { // a full 360deg range
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   //======= collect data concerning the rotation of the solid 
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   //  DCOUT('a', "  rotsolid axis=" << solidRot_.getAxis() << " rot.angle=" << solidRot_.delta()/deg);                      
00097   
00098   
00099   //======== collect data concerning the rotation of the x-y plane
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   //  DCOUT('a', "  rotplane axis=" << planeRot_.getAxis() << " rot.angle=" << planeRot_.delta()/deg);
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     //v = planeRot_.inverse()*v;
00149     v = planeRot_*v;
00150   }
00151   
00152   v += DD3Vector(center_[0], center_[1], center_[2]); // offset
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   //your code here
00162   DDRotationMatrix rot = solidRot_;
00163 
00164   if (alignSolid_) { // rotate the solid as well
00165     double angle = startAngle_+ double(count_-1)*delta_;
00166     ROOT::Math::RotationZ r2(angle);
00167     rot = r2*rot;
00168   }
00169   // DCOUT('A', "  rot.axis=" << rot.getAxis() << " rot.angle=" << rot.delta()/deg);
00170 
00171   if (rotate_[2]!=0) {
00172     rot = planeRot_*rot;
00173     //rot = rot*planeRot_.inverse();
00174     //rot = planeRot_.inverse()*rot;
00175   }
00176 
00177   return rot;
00178 }
00179 
00180 // optional, not in the XML, omitted.
00181 int global_angular_0::copyno() const
00182 {
00183   // for the moment rely on the automatic copy-number generation
00184   //  ( copy-no == invocation count count_ )
00185   int factor = AlgoImpl::copyno() - 1;
00186   return startCopyNo_ + factor*incrCopyNo_;
00187 }
00188 
00189 
00190 
00191 // optional, not in the XML, omitted.
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  The following Code gets only generated IF the code-generator
00209  has the capability of generating evaluation/checking code for
00210  the specification of the parameters in the algorithm XML.
00211  
00212  If the following is not generated, there will be not automatic
00213  checking of the basic properties of the user-supplied parameters
00214  (bounds, occurences, default values, ...)
00215  
00216 ***************************************************************************/
00217 
00218 // IT IS ADVISABLE TO HAVE SCHEMA VALIDATION DURING PARSING THE ALGORITHM-XML
00219 // IN ORDER TO GET DEFAULT VALUES & CONTRAINTS FOR THE PARAMTERS OF THE ALGORITHM
00220 // The code-generator has to fill data-structures containing the parameter names
00221 // and their constraints. This information is only completely available during
00222 // parsing of an algorithm-defintion-xml when schema validation is turned on.
00223 global_angular_Check::global_angular_Check()
00224 {
00225   // for the time being only expression-valued parameters can be automatically checked
00226   // against their specified constraints
00227   
00228   // schema default values will be shown if necessary in the following XML comments 
00229   // on the second line. The fist shows the values as given in the instance document
00230 
00231   // expressions have to be converted into doubles. No variables [bla] shall be allowed
00232   // inside the expressions; SystemOfUnits-symbols are the only supported ones.
00233   
00234 
00235   constraintsE_["startAngle"] = ConstraintE( 1,      // minOccurs
00236                                         1,      // maxOccurs
00237                                         0.,  // min
00238                                         360.0*deg,  // max 
00239                                         false,    // use, true=required, false=optional
00240                                         true,    // use, true=use default, false=no default
00241                                         0.0
00242                                        );
00243 
00244   constraintsE_["rangeAngle"] = ConstraintE( 1,      // minOccurs
00245                                         1,      // maxOccurs
00246                                         0.,  // min
00247                                         360.0*deg,  // max 
00248                                         false,    // use, true=required, false=optional
00249                                         true,    // use, true=use default, false=no default
00250                                         360.0*deg
00251                                        );
00252 
00253   constraintsE_["n"] = ConstraintE( 1,      // minOccurs
00254                                         1,      // maxOccurs
00255                                         1,  // min
00256                                         +MAX_DOUBLE,  // max 
00257                                         false,    // use, true=required, false=optional
00258                                         true,    // use, true=use default, false=no default
00259                                         1
00260                                        );
00261   constraintsE_["startCopyNo"] = ConstraintE( 1,      // minOccurs
00262                                         1,      // maxOccurs
00263                                         -MAX_DOUBLE,  // min
00264                                         +MAX_DOUBLE,  // max 
00265                                         false,    // use, true=required, false=optional
00266                                         true,    // use, true=use default, false=no default
00267                                         1
00268                                        );
00269 
00270   constraintsE_["incrCopyNo"] = ConstraintE( 1,      // minOccurs
00271                                         1,      // maxOccurs
00272                                         -MAX_DOUBLE,  // min
00273                                         +MAX_DOUBLE,  // max 
00274                                         false,    // use, true=required, false=optional
00275                                         true,    // use, true=use default, false=no default
00276                                         1
00277                                        );
00278                                        
00279 
00280   constraintsE_["radius"] = ConstraintE( 1,      // minOccurs
00281                                         1,      // maxOccurs
00282                                         0.,  // min
00283                                         +MAX_DOUBLE,  // max 
00284                                         true,    // use, true=required, false=optional
00285                                         false,    // use, true=use default, false=no default
00286                                         2
00287                                        );
00288 
00289   constraintsS_["alignSolid"] = ConstraintS( 1,      // minOccurs
00290                                         1,      // maxOccurs
00291                                         
00292                                          
00293                                         false,    // use, true=required, false=optional
00294                                         true,    // use, true=use default, false=no default
00295                                         "T"
00296                                        );
00297 
00298   constraintsE_["center"] = ConstraintE( 3,      // minOccurs
00299                                         3,      // maxOccurs
00300                                         -MAX_DOUBLE,  // min
00301                                         +MAX_DOUBLE,  // max 
00302                                         false,    // use, true=required, false=optional
00303                                         true,    // use, true=use default, false=no default
00304                                         0.
00305                                        );
00306 
00307   constraintsE_["rotate"] = ConstraintE( 3,      // minOccurs
00308                                         9,      // maxOccurs
00309                                         -360.0*deg,  // min
00310                                         360.0*deg,  // max 
00311                                         false,    // use, true=required, false=optional
00312                                         true,    // use, true=use default, false=no default
00313                                         0.0
00314                                        );
00315 
00316   constraintsE_["rotateSolid"] = ConstraintE( 3,      // minOccurs
00317                                         9,      // maxOccurs
00318                                         -360.0*deg,  // min
00319                                         360.0*deg,  // max 
00320                                         false,    // use, true=required, false=optional
00321                                         true,    // use, true=use default, false=no default
00322                                         0.0
00323                                        );
00324 
00325 }
00326 
00327