CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/Geometry/HcalAlgo/plugins/DDHCalFibreBundle.cc

Go to the documentation of this file.
00001 
00002 // File: DDHCalFibreBundle.cc
00003 // Description: Create & Position fibre bundles in mother
00005 
00006 #include <cmath>
00007 #include <algorithm>
00008 
00009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00010 #include "DetectorDescription/Base/interface/DDutils.h"
00011 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
00012 #include "DetectorDescription/Core/interface/DDSolid.h"
00013 #include "DetectorDescription/Core/interface/DDMaterial.h"
00014 #include "DetectorDescription/Core/interface/DDCurrentNamespace.h"
00015 #include "DetectorDescription/Core/interface/DDSplit.h"
00016 #include "Geometry/HcalAlgo/plugins/DDHCalFibreBundle.h"
00017 #include "CLHEP/Units/GlobalSystemOfUnits.h"
00018 
00019 DDHCalFibreBundle::DDHCalFibreBundle() {
00020   LogDebug("HCalGeom") <<"DDHCalFibreBundle info: Creating an instance";
00021 }
00022 
00023 DDHCalFibreBundle::~DDHCalFibreBundle() {}
00024 
00025 void DDHCalFibreBundle::initialize(const DDNumericArguments & nArgs,
00026                                    const DDVectorArguments & vArgs,
00027                                    const DDMapArguments & ,
00028                                    const DDStringArguments & sArgs,
00029                                    const DDStringVectorArguments & ) {
00030 
00031   deltaPhi    = nArgs["DeltaPhi"];
00032   deltaZ      = nArgs["DeltaZ"];
00033   numberPhi   = int(nArgs["NumberPhi"]);
00034   material    = sArgs["Material"];
00035   areaSection = vArgs["AreaSection"];
00036   rStart      = vArgs["RadiusStart"];
00037   rEnd        = vArgs["RadiusEnd"];
00038   bundle      = dbl_to_int(vArgs["Bundles"]);
00039   tilt        = nArgs["TiltAngle"];
00040   
00041   idNameSpace = DDCurrentNamespace::ns();
00042   childPrefix = sArgs["Child"]; 
00043   DDName parentName = parent().name();
00044   edm::LogInfo("HCalGeom") << "DDHCalFibreBundle debug: Parent " << parentName
00045                        << " with " << bundle.size() << " children with prefix "
00046                        << childPrefix << ", material " << material << " with "
00047                        << numberPhi << " bundles along phi; width of mother "
00048                        << deltaZ << " along Z, " << deltaPhi/CLHEP::deg 
00049                        << " along phi and with " << rStart.size()
00050                        << " different bundle types";
00051   for (unsigned int i=0; i<areaSection.size(); ++i) 
00052     edm::LogInfo("HCalGeom") << "DDHCalFibreBundle debug: Child[" << i << "] Area "
00053                          << areaSection[i] << " R at Start " << rStart[i]
00054                          << " R at End " << rEnd[i];
00055   edm::LogInfo("HCalGeom") << "DDHCalFibreBundle debug: NameSpace " 
00056                            << idNameSpace << " Tilt Angle " << tilt/CLHEP::deg
00057                            << " Bundle type at different positions";
00058   for (unsigned int i=0; i<bundle.size(); ++i) {
00059     edm::LogInfo("HCalGeom") << "DDHCalFibreBundle debug: Position[" << i << "] "
00060                          << " with Type " << bundle[i];
00061   }
00062 }
00063 
00064 void DDHCalFibreBundle::execute(DDCompactView& cpv) {
00065 
00066   DDName mother = parent().name();
00067   DDName matname(DDSplit(material).first, DDSplit(material).second);
00068   DDMaterial matter(matname);
00069 
00070   // Create the rotation matrices
00071   double dPhi = deltaPhi/numberPhi;
00072   std::vector<DDRotation> rotation;
00073   for (int i=0; i<numberPhi; ++i) {
00074     double phi    = -0.5*deltaPhi+(i+0.5)*dPhi;
00075     double phideg = phi/CLHEP::deg;
00076     std::string rotstr = "R0"+ dbl_to_string(phideg);
00077     DDRotation  rot = DDRotation(DDName(rotstr, idNameSpace));
00078     if (!rot) {
00079       edm::LogInfo("HCalGeom") << "DDHCalFibreBundle test: Creating a new "
00080                            << "rotation " << rotstr << "\t" << 90 << ","
00081                            << phideg << ","  << 90 << "," << (phideg+90)
00082                            << ", 0, 0";
00083       rot = DDrot(DDName(rotstr, idNameSpace), 90*CLHEP::deg, phi, 
00084                   90*CLHEP::deg, (90*CLHEP::deg+phi), 0,  0);
00085     }
00086     rotation.push_back(rot);
00087   }
00088 
00089   // Create the solids and logical parts
00090   std::vector<DDLogicalPart> logs;
00091   for (unsigned int i=0; i<areaSection.size(); ++i) {
00092     double r0     = rEnd[i]/std::cos(tilt);
00093     double dStart = areaSection[i]/(2*dPhi*rStart[i]);
00094     double dEnd   = areaSection[i]/(2*dPhi*r0);
00095     std::string name = childPrefix + dbl_to_string(i);
00096     DDSolid solid = DDSolidFactory::cons(DDName(name, idNameSpace), 0.5*deltaZ,
00097                                          rStart[i]-dStart, rStart[i]+dStart,
00098                                          r0-dEnd, r0+dEnd, -0.5*dPhi, dPhi);
00099     edm::LogInfo("HCalGeom") << "DDHCalFibreBundle test: Creating a new solid "
00100                          << name << " a cons with dZ " << deltaZ << " rStart "
00101                          << rStart[i]-dStart << ":"  << rStart[i]+dStart
00102                          << " rEnd " << r0-dEnd << ":" << r0+dEnd << " Phi " 
00103                          << -0.5*dPhi/CLHEP::deg << ":" << 0.5*dPhi/CLHEP::deg;
00104     DDLogicalPart log(DDName(name, idNameSpace), matter, solid);
00105     logs.push_back(log);
00106   }
00107 
00108   // Now posiiton them
00109   int    copy = 0;
00110   int    nY   = (int)(bundle.size())/numberPhi;
00111   for (unsigned int i=0; i<bundle.size(); i++) {
00112     DDTranslation tran(0,0,0);
00113     int ir = (int)(i)/nY;
00114     if (ir >= numberPhi) ir = numberPhi-1;
00115     int ib = bundle[i];
00116     copy++;
00117     if (ib>=0 && ib<(int)(logs.size())) {
00118       cpv.position(logs[ib], mother, copy, tran, rotation[ir]);
00119       edm::LogInfo("HCalGeom") << "DDHCalFibreBundle test: " << logs[ib].name() 
00120                            << " number " << copy << " positioned in "
00121                            << mother << " at " << tran << " with " 
00122                            << rotation[ir];
00123     }
00124   }
00125 }