00001
00002
00003
00005
00006 #include <cmath>
00007 #include <algorithm>
00008
00009 namespace std{} using namespace std;
00010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00011 #include "DetectorDescription/Base/interface/DDutils.h"
00012 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
00013 #include "DetectorDescription/Core/interface/DDSolid.h"
00014 #include "DetectorDescription/Core/interface/DDMaterial.h"
00015 #include "DetectorDescription/Core/interface/DDCurrentNamespace.h"
00016 #include "DetectorDescription/Core/interface/DDSplit.h"
00017 #include "Geometry/HcalAlgo/plugins/DDHCalTBCableAlgo.h"
00018 #include "CLHEP/Units/GlobalPhysicalConstants.h"
00019 #include "CLHEP/Units/GlobalSystemOfUnits.h"
00020
00021 DDHCalTBCableAlgo::DDHCalTBCableAlgo(): theta(0),rmax(0),zoff(0) {
00022 LogDebug("HCalGeom") << "DDHCalTBCableAlgo info: Creating an instance";
00023 }
00024
00025 DDHCalTBCableAlgo::~DDHCalTBCableAlgo() {}
00026
00027
00028 void DDHCalTBCableAlgo::initialize(const DDNumericArguments & nArgs,
00029 const DDVectorArguments & vArgs,
00030 const DDMapArguments & ,
00031 const DDStringArguments & sArgs,
00032 const DDStringVectorArguments & ) {
00033
00034 genMat = sArgs["MaterialName"];
00035 nsectors = int (nArgs["NSector"]);
00036 nsectortot = int (nArgs["NSectorTot"]);
00037 nhalf = int (nArgs["NHalf"]);
00038 rin = nArgs["RIn"];
00039 theta = vArgs["Theta"];
00040 rmax = vArgs["RMax"];
00041 zoff = vArgs["ZOff"];
00042
00043 absMat = sArgs["AbsMatName"];
00044 thick = nArgs["Thickness"];
00045 width1 = nArgs["Width1"];
00046 length1 = nArgs["Length1"];
00047 width2 = nArgs["Width2"];
00048 length2 = nArgs["Length2"];
00049 gap2 = nArgs["Gap2"];
00050
00051 LogDebug("HCalGeom") << "DDHCalTBCableAlgo debug: General material "
00052 << genMat << "\tSectors " << nsectors << ", "
00053 << nsectortot << "\tHalves " << nhalf << "\tRin " <<rin;
00054 for (unsigned int i = 0; i < theta.size(); i++)
00055 LogDebug("HCalGeom") << "\t" << i << " Theta " << theta[i] << " rmax "
00056 << rmax[i] << " zoff " << zoff[i];
00057 LogDebug("HCalGeom") << "\tCable mockup made of " << absMat << "\tThick "
00058 << thick << "\tLength and width " << length1 << ", "
00059 << width1 <<" and " << length2 << ", " << width2
00060 << " Gap " << gap2;
00061
00062 idName = sArgs["MotherName"];
00063 idNameSpace = DDCurrentNamespace::ns();
00064 rotns = sArgs["RotNameSpace"];
00065 DDName parentName = parent().name();
00066 LogDebug("HCalGeom") << "DDHCalTBCableAlgo debug: Parent " << parentName
00067 << " idName " << idName << " NameSpace " << idNameSpace
00068 << " for solids etc. and " << rotns << " for rotations";
00069 }
00070
00071 void DDHCalTBCableAlgo::execute(DDCompactView& cpv) {
00072
00073 LogDebug("HCalGeom") << "==>> Constructing DDHCalTBCableAlgo...";
00074 unsigned int i=0;
00075
00076 double alpha = CLHEP::pi/nsectors;
00077 double dphi = nsectortot*CLHEP::twopi/nsectors;
00078
00079 double zstep0 = zoff[1]+rmax[1]*tan(theta[1])+(rin-rmax[1])*tan(theta[2]);
00080 double zstep1 = zstep0+thick/cos(theta[2]);
00081 double zstep2 = zoff[3];
00082
00083 double rstep0 = rin + (zstep2-zstep1)/tan(theta[2]);
00084 double rstep1 = rin + (zstep1-zstep0)/tan(theta[2]);
00085
00086 vector<double> pgonZ;
00087 pgonZ.push_back(zstep0);
00088 pgonZ.push_back(zstep1);
00089 pgonZ.push_back(zstep2);
00090 pgonZ.push_back(zstep2+thick/cos(theta[2]));
00091
00092 vector<double> pgonRmin;
00093 pgonRmin.push_back(rin);
00094 pgonRmin.push_back(rin);
00095 pgonRmin.push_back(rstep0);
00096 pgonRmin.push_back(rmax[2]);
00097
00098 vector<double> pgonRmax;
00099 pgonRmax.push_back(rin);
00100 pgonRmax.push_back(rstep1);
00101 pgonRmax.push_back(rmax[2]);
00102 pgonRmax.push_back(rmax[2]);
00103
00104 string name("Null");
00105 DDSolid solid;
00106 solid = DDSolidFactory::polyhedra(DDName(idName, idNameSpace),
00107 nsectortot, -alpha, dphi, pgonZ,
00108 pgonRmin, pgonRmax);
00109 LogDebug("HCalGeom") << "DDHCalTBCableAlgo test: "
00110 << DDName(idName,idNameSpace) << " Polyhedra made of "
00111 << genMat << " with " << nsectortot << " sectors from "
00112 << -alpha/CLHEP::deg << " to "
00113 << (-alpha+dphi)/CLHEP::deg << " and with "
00114 << pgonZ.size() << " sections";
00115 for (i = 0; i <pgonZ.size(); i++)
00116 LogDebug("HCalGeom") << "\t\tZ = " << pgonZ[i] << "\tRmin = "
00117 << pgonRmin[i] << "\tRmax = " << pgonRmax[i];
00118
00119 DDName matname(DDSplit(genMat).first, DDSplit(genMat).second);
00120 DDMaterial matter(matname);
00121 DDLogicalPart genlogic(solid.ddname(), matter, solid);
00122
00123 DDName parentName = parent().name();
00124 DDTranslation r0(0.0, 0.0, 0.0);
00125 DDRotation rot;
00126 cpv.position(DDName(idName, idNameSpace), parentName, 1, r0, rot);
00127 LogDebug("HCalGeom") << "DDHCalTBCableAlgo test: "
00128 << DDName(idName,idNameSpace) << " number 1 positioned "
00129 << "in " << parentName << " at " << r0 << " with "<<rot;
00130
00131 if (nhalf != 1) {
00132 rot = DDRotation(DDName("180D", rotns));
00133 cpv.position(DDName(idName, idNameSpace), parentName, 2, r0, rot);
00134 LogDebug("HCalGeom") << "DDHCalTBCableAlgo test: "
00135 << DDName(idName,idNameSpace) <<" number 2 positioned"
00136 << "in " << parentName << " at " << r0 << " with "
00137 << rot;
00138 }
00139
00140
00141 name = idName + "Module";
00142 LogDebug("HCalGeom") << "DDHCalTBCableAlgo test: "
00143 << DDName(name,idNameSpace) << " Polyhedra made of "
00144 << genMat << " with 1 sector from " <<-alpha/CLHEP::deg
00145 << " to " << alpha/CLHEP::deg << " and with "
00146 << pgonZ.size() << " sections";
00147 for (i = 0; i < pgonZ.size(); i++)
00148 LogDebug("HCalGeom") << "\t\tZ = " << pgonZ[i] << "\tRmin = "
00149 << pgonRmin[i] << "\tRmax = " << pgonRmax[i];
00150 solid = DDSolidFactory::polyhedra(DDName(name, idNameSpace),
00151 1, -alpha, 2*alpha, pgonZ,
00152 pgonRmin, pgonRmax);
00153 DDLogicalPart seclogic(solid.ddname(), matter, solid);
00154
00155 for (int ii=0; ii<nsectortot; ii++) {
00156 double phi = ii*2*alpha;
00157 double phideg = phi/CLHEP::deg;
00158
00159 DDRotation rotation;
00160 string rotstr("NULL");
00161 if (phideg != 0) {
00162 rotstr = "R";
00163 if (phideg < 100) rotstr = "R0";
00164 rotstr = rotstr + dbl_to_string(phideg);
00165 rotation = DDRotation(DDName(rotstr, rotns));
00166 if (!rotation) {
00167 LogDebug("HCalGeom") << "DDHCalTBCableAlgo test: Creating a new "
00168 << "rotation " << rotstr << "\t90," << phideg
00169 << ", 90, " << (phideg+90) << ", 0, 0";
00170 rotation = DDrot(DDName(rotstr, idNameSpace), 90*CLHEP::deg,
00171 phideg*CLHEP::deg, 90*CLHEP::deg,
00172 (90+phideg)*CLHEP::deg, 0*CLHEP::deg, 0*CLHEP::deg);
00173 }
00174 }
00175
00176 cpv.position(seclogic, genlogic, ii+1, DDTranslation(0.0, 0.0, 0.0), rotation);
00177 LogDebug("HCalGeom") << "DDHCalTBCableAlgo test: " << seclogic.name()
00178 << " number " << ii+1 << " positioned in "
00179 << genlogic.name() << " at (0,0,0) with " << rotation;
00180 }
00181
00182
00183 double rinl = pgonRmin[0] + thick * sin(theta[2]);
00184 double routl = pgonRmax[2] - thick * sin(theta[2]);
00185 double dx1 = rinl * tan(alpha);
00186 double dx2 = 0.90 * routl * tan(alpha);
00187 double dy = 0.50 * thick;
00188 double dz = 0.50 * (routl -rinl);
00189 name = idName + "Trap";
00190 solid = DDSolidFactory::trap(DDName(name, idNameSpace), dz, 0, 0, dy, dx1,
00191 dx1, 0, dy, dx2, dx2, 0);
00192 LogDebug("HCalGeom") << "DDHCalTBCableAlgo test: " << solid.name()
00193 <<" Trap made of " << genMat << " of dimensions " << dz
00194 << ", 0, 0, " << dy << ", " << dx1 << ", " << dx1
00195 << ", 0, " << dy << ", " << dx2 << ", " << dx2 <<", 0";
00196 DDLogicalPart glog(solid.ddname(), matter, solid);
00197
00198 string rotstr = name;
00199 LogDebug("HCalGeom") << "DDHCalTBCableAlgo test: Creating a new rotation: "
00200 << rotstr << "\t90, 270, " << (180-theta[2]/CLHEP::deg)
00201 << ", 0, " << (90-theta[2]/CLHEP::deg) << ", 0";
00202 rot = DDrot(DDName(rotstr, idNameSpace), 90*CLHEP::deg, 270*CLHEP::deg,
00203 180*CLHEP::deg-theta[2], 0, 90*CLHEP::deg-theta[2], 0);
00204 DDTranslation r1(0.5*(rinl+routl), 0, 0.5*(pgonZ[1]+pgonZ[2]));
00205 cpv.position(glog, seclogic, 1, r1, rot);
00206 LogDebug("HCalGeom") << "DDHCalTBCableAlgo test: " << glog.name()
00207 << " number 1 positioned in " << seclogic.name()
00208 << " at " << r1 << " with " << rot;
00209
00210
00211 name = idName + "Cable1";
00212 double phi = atan((dx2-dx1)/(2*dz));
00213 double xmid = 0.5*(dx1+dx2)-1.0;
00214 solid = DDSolidFactory::box(DDName(name, idNameSpace), 0.5*width1,
00215 0.5*thick, 0.5*length1);
00216 LogDebug("HCalGeom") << "DDHCalTBCableAlgo test: " << solid.name()
00217 << " Box made of " << absMat << " of dimension "
00218 << 0.5*width1 << ", " << 0.5*thick << ", "
00219 << 0.5*length1;
00220 DDName absname(DDSplit(absMat).first, DDSplit(absMat).second);
00221 DDMaterial absmatter(absname);
00222 DDLogicalPart cablog1(solid.ddname(), absmatter, solid);
00223
00224 rotstr = idName + "Left";
00225 LogDebug("HCalGeom") << "DDHCalTBCableAlgo test: Creating a new rotation "
00226 << rotstr << "\t" << (90+phi/CLHEP::deg) << "," << 0
00227 << "," << 90 << "," << 90 << "," << phi/CLHEP::deg
00228 << "," << 0;
00229 DDRotation rot2 = DDrot(DDName(rotstr, idNameSpace), 90*CLHEP::deg+phi, 0.0,
00230 90*CLHEP::deg, 90*CLHEP::deg, phi, 0.0);
00231 DDTranslation r2((xmid-0.5*width1*cos(phi)), 0, 0);
00232 cpv.position(cablog1, glog, 1, r2, rot2);
00233 LogDebug("HCalGeom") << "DDHCalTBCableAlgo test: " << cablog1.name()
00234 << " number 1 positioned in " << glog.name() << " at "
00235 << r2 << " with " << rot2;
00236
00237 rotstr = idName + "Right";
00238 LogDebug("HCalGeom") << "DDHCalTBCableAlgo test: Creating a new rotation "
00239 << rotstr << "\t" << (90-phi/CLHEP::deg)
00240 << ", 0, 90, 90, " << -phi/CLHEP::deg << ", 0";
00241 DDRotation rot3 = DDrot(DDName(rotstr, idNameSpace), 90*CLHEP::deg-phi,
00242 0*CLHEP::deg, 90*CLHEP::deg, 90*CLHEP::deg,
00243 -phi, 0*CLHEP::deg);
00244 DDTranslation r3(-(xmid-0.5*width1*cos(phi)), 0, 0);
00245 cpv.position(cablog1, glog, 2, r3, rot3);
00246 LogDebug("HCalGeom") << "DDHCalTBCableAlgo test: " << cablog1.name()
00247 << " number 2 positioned in " << glog.name() << " at "
00248 << r3 << " with " << rot3;
00249
00250
00251 name = idName + "Cable2";
00252 solid = DDSolidFactory::box(DDName(name, idNameSpace), 0.5*width2,
00253 0.5*thick, 0.5*length2);
00254 LogDebug("HCalGeom") << "DDHCalTBCableAlgo test: " << solid.name()
00255 << " Box made of " << absMat << " of dimension "
00256 << 0.5*width2 << ", " << 0.5*thick << ", "<<0.5*length2;
00257 DDLogicalPart cablog2(solid.ddname(), absmatter, solid);
00258
00259 double xpos = 0.5*(width2+gap2);
00260 cpv.position(cablog2, glog, 1, DDTranslation(xpos, 0.0, 0.0), DDRotation());
00261 LogDebug("HCalGeom") << "DDHCalTBCableAlgo test: " << cablog2.name()
00262 << " number 1 positioned in " << glog.name() << " at ("
00263 << xpos << ", 0, 0) with no rotation";
00264 cpv.position(cablog2, glog, 2, DDTranslation(-xpos, 0.0, 0.0), DDRotation());
00265 LogDebug("HCalGeom") << "DDHCalTBCableAlgo test: " << cablog2.name()
00266 << " number 2 positioned in " << glog.name() << " at ("
00267 <<-xpos << ", 0, 0) with no rotation";
00268
00269 LogDebug("HCalGeom") << "<<== End of DDHCalTBCableAlgo construction ...";
00270 }