Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:15:25

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // File: DDTOBRodAlgo.cc
0003 // Description: Positioning constituents of a TOB rod
0004 ///////////////////////////////////////////////////////////////////////////////
0005 
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 #include "DetectorDescription/Core/interface/DDCurrentNamespace.h"
0008 #include "DetectorDescription/Core/interface/DDSplit.h"
0009 #include "DetectorDescription/Core/interface/DDTypes.h"
0010 #include "DetectorDescription/Core/interface/DDAlgorithm.h"
0011 #include "DetectorDescription/Core/interface/DDAlgorithmFactory.h"
0012 
0013 #include <string>
0014 #include <vector>
0015 
0016 using namespace std;
0017 
0018 class DDTOBRodAlgo : public DDAlgorithm {
0019 public:
0020   //Constructor and Destructor
0021   DDTOBRodAlgo();
0022   ~DDTOBRodAlgo() override;
0023 
0024   void initialize(const DDNumericArguments& nArgs,
0025                   const DDVectorArguments& vArgs,
0026                   const DDMapArguments& mArgs,
0027                   const DDStringArguments& sArgs,
0028                   const DDStringVectorArguments& vsArgs) override;
0029 
0030   void execute(DDCompactView& cpv) override;
0031 
0032 private:
0033   string central;      // Name of the central piece
0034   string idNameSpace;  // Namespace of this and ALL sub-parts
0035 
0036   double shift;             // Shift in z
0037   vector<string> sideRod;   // Name of the Side Rod
0038   vector<double> sideRodX;  // x-positions
0039   vector<double> sideRodY;  // y-positions
0040   vector<double> sideRodZ;  // z-positions
0041   string endRod1;           // Name of the End Rod of type 1
0042   vector<double> endRod1Y;  // y-positions
0043   vector<double> endRod1Z;  // z-positions
0044   string endRod2;           // Name of the End Rod of type 2
0045   double endRod2Y;          // y-position
0046   double endRod2Z;          // z-position
0047 
0048   string cable;   // Name of the Mother cable
0049   double cableZ;  // z-position
0050 
0051   string clamp;              // Name of the clamp
0052   vector<double> clampX;     // x-positions
0053   vector<double> clampZ;     // z-positions
0054   string sideCool;           // Name of the Side Cooling Tube
0055   vector<double> sideCoolX;  // x-positions
0056   vector<double> sideCoolY;  // y-positions to avoid overlap with the module (be at the same level of EndCool)
0057   vector<double> sideCoolZ;  // z-positions
0058   string endCool;            // Name of the End Cooling Tube
0059   string endCoolRot;         // Rotation matrix name for end cool
0060   double endCoolY;           // y-position to avoid overlap with the module
0061   double endCoolZ;           // z-position
0062 
0063   string optFibre;           // Name of the Optical Fibre
0064   vector<double> optFibreX;  // x-positions
0065   vector<double> optFibreZ;  // z-positions
0066 
0067   string sideClamp1;            // Name of the side clamp of type 1
0068   vector<double> sideClampX;    // x-positions
0069   vector<double> sideClamp1DZ;  // Delta(z)-positions
0070   string sideClamp2;            // Name of the side clamp of type 2
0071   vector<double> sideClamp2DZ;  // Delta(z)-positions
0072 
0073   string module;             // Name of the detector modules
0074   vector<string> moduleRot;  // Rotation matrix name for module
0075   vector<double> moduleY;    // y-positions
0076   vector<double> moduleZ;    // z-positions
0077   vector<string> connect;    // Name of the connectors
0078   vector<double> connectY;   // y-positions
0079   vector<double> connectZ;   // z-positions
0080 
0081   string aohName;            // AOH name
0082   vector<double> aohCopies;  // AOH copies to be positioned on each ICC
0083   vector<double> aohX;       // AOH translation with respect small-ICC center (X)
0084   vector<double> aohY;       // AOH translation with respect small-ICC center (Y)
0085   vector<double> aohZ;       // AOH translation with respect small-ICC center (Z)
0086 };
0087 
0088 DDTOBRodAlgo::DDTOBRodAlgo()
0089     : sideRod(0),
0090       sideRodX(0),
0091       sideRodY(0),
0092       sideRodZ(0),
0093       endRod1Y(0),
0094       endRod1Z(0),
0095       clampX(0),
0096       clampZ(0),
0097       sideCoolX(0),
0098       sideCoolY(0),
0099       sideCoolZ(0),
0100       endCoolY(0),
0101       endCoolZ(0),
0102       optFibreX(0),
0103       optFibreZ(0),
0104       sideClampX(0),
0105       sideClamp1DZ(0),
0106       sideClamp2DZ(0),
0107       moduleRot(0),
0108       moduleY(0),
0109       moduleZ(0),
0110       connect(0),
0111       connectY(0),
0112       connectZ(0),
0113       aohCopies(0),
0114       aohX(0),
0115       aohY(0),
0116       aohZ(0) {
0117   LogDebug("TOBGeom") << "DDTOBRodAlgo info: Creating an instance";
0118 }
0119 
0120 DDTOBRodAlgo::~DDTOBRodAlgo() {}
0121 
0122 void DDTOBRodAlgo::initialize(const DDNumericArguments& nArgs,
0123                               const DDVectorArguments& vArgs,
0124                               const DDMapArguments&,
0125                               const DDStringArguments& sArgs,
0126                               const DDStringVectorArguments& vsArgs) {
0127   central = sArgs["CentralName"];
0128   shift = nArgs["Shift"];
0129   idNameSpace = DDCurrentNamespace::ns();
0130   DDName parentName = parent().name();
0131   LogDebug("TOBGeom") << "DDTOBRodAlgo debug: Parent " << parentName << " Central " << central << " NameSpace "
0132                       << idNameSpace << "\tShift " << shift;
0133 
0134   sideRod = vsArgs["SideRodName"];
0135   sideRodX = vArgs["SideRodX"];
0136   sideRodY = vArgs["SideRodY"];
0137   sideRodZ = vArgs["SideRodZ"];
0138   for (int i = 0; i < (int)(sideRod.size()); i++) {
0139     LogDebug("TOBGeom") << "DDTOBRodAlgo debug: " << sideRod[i] << " to be positioned " << sideRodX.size()
0140                         << " times at y = " << sideRodY[i] << " z = " << sideRodZ[i] << " and x";
0141     for (double j : sideRodX)
0142       LogDebug("TOBGeom") << "\tsideRodX[" << i << "] = " << j;
0143   }
0144 
0145   endRod1 = sArgs["EndRod1Name"];
0146   endRod1Y = vArgs["EndRod1Y"];
0147   endRod1Z = vArgs["EndRod1Z"];
0148   LogDebug("TOBGeom") << "DDTOBRodAlgo debug: " << endRod1 << " to be "
0149                       << "positioned " << endRod1Y.size() << " times at";
0150   for (int i = 0; i < (int)(endRod1Y.size()); i++)
0151     LogDebug("TOBGeom") << "\t[" << i << "]\ty = " << endRod1Y[i] << "\tz = " << endRod1Z[i];
0152 
0153   endRod2 = sArgs["EndRod2Name"];
0154   endRod2Y = nArgs["EndRod2Y"];
0155   endRod2Z = nArgs["EndRod2Z"];
0156   LogDebug("TOBGeom") << "DDTOBRodAlgo debug: " << endRod2 << " to be "
0157                       << "positioned at y = " << endRod2Y << " z = " << endRod2Z;
0158 
0159   cable = sArgs["CableName"];
0160   cableZ = nArgs["CableZ"];
0161   LogDebug("TOBGeom") << "DDTOBRodAlgo debug: " << cable << " to be "
0162                       << "positioned at z = " << cableZ;
0163 
0164   clamp = sArgs["ClampName"];
0165   clampX = vArgs["ClampX"];
0166   clampZ = vArgs["ClampZ"];
0167   LogDebug("TOBGeom") << "DDTOBRodAlgo debug: " << clamp << " to be "
0168                       << "positioned " << clampX.size() << " times at";
0169   for (int i = 0; i < (int)(clampX.size()); i++)
0170     LogDebug("TOBGeom") << "\t[" << i << "]\tx = " << clampX[i] << "\tz = " << clampZ[i];
0171 
0172   sideCool = sArgs["SideCoolName"];
0173   sideCoolX = vArgs["SideCoolX"];
0174   sideCoolY = vArgs["SideCoolY"];
0175   sideCoolZ = vArgs["SideCoolZ"];
0176   LogDebug("TOBGeom") << "DDTOBRodAlgo debug: " << sideCool << " to be "
0177                       << "positioned " << sideCoolX.size() << " times at";
0178   for (int i = 0; i < (int)(sideCoolX.size()); i++)
0179     LogDebug("TOBGeom") << "\t[" << i << "]\tx = " << sideCoolX[i] << "\ty = " << sideCoolY[i]
0180                         << "\tz = " << sideCoolZ[i];
0181 
0182   endCool = sArgs["EndCoolName"];
0183   endCoolY = nArgs["EndCoolY"];
0184   endCoolZ = nArgs["EndCoolZ"];
0185   endCoolRot = sArgs["EndCoolRot"];
0186   LogDebug("TOBGeom") << "DDTOBRodAlgo debug: " << endCool << " to be "
0187                       << "positioned with " << endCoolRot << " rotation at"
0188                       << " y = " << endCoolY << " z = " << endCoolZ;
0189 
0190   optFibre = sArgs["OptFibreName"];
0191   optFibreX = vArgs["optFibreX"];
0192   optFibreZ = vArgs["optFibreZ"];
0193   LogDebug("TOBGeom") << "DDTOBRodAlgo debug: " << optFibre << " to be "
0194                       << "positioned " << optFibreX.size() << " times at";
0195   for (int i = 0; i < (int)(optFibreX.size()); i++)
0196     LogDebug("TOBGeom") << "\t[" << i << "]\tx = " << optFibreX[i] << "\tz = " << optFibreZ[i];
0197 
0198   sideClamp1 = sArgs["SideClamp1Name"];
0199   sideClampX = vArgs["SideClampX"];
0200   sideClamp1DZ = vArgs["SideClamp1DZ"];
0201   LogDebug("TOBGeom") << "DDTOBRodAlgo debug: " << sideClamp1 << " to be "
0202                       << "positioned " << sideClampX.size() << " times at";
0203   for (int i = 0; i < (int)(sideClampX.size()); i++)
0204     LogDebug("TOBGeom") << "\t[" << i << "]\tx = " << sideClampX[i] << "\tdz = " << sideClamp1DZ[i];
0205 
0206   sideClamp2 = sArgs["SideClamp2Name"];
0207   sideClamp2DZ = vArgs["SideClamp2DZ"];
0208   LogDebug("TOBGeom") << "DDTOBRodAlgo debug: " << sideClamp2 << " to be "
0209                       << "positioned " << sideClampX.size() << " times at";
0210   for (int i = 0; i < (int)(sideClampX.size()); i++)
0211     LogDebug("TOBGeom") << "\t[" << i << "]\tx = " << sideClampX[i] << "\tdz = " << sideClamp2DZ[i];
0212 
0213   moduleRot = vsArgs["ModuleRot"];
0214   module = sArgs["ModuleName"];
0215   moduleY = vArgs["ModuleY"];
0216   moduleZ = vArgs["ModuleZ"];
0217   LogDebug("TOBGeom") << "DDTOBRodAlgo debug:\t" << module << " positioned " << moduleRot.size() << " times";
0218   for (int i = 0; i < (int)(moduleRot.size()); i++)
0219     LogDebug("TOBGeom") << "\tRotation " << moduleRot[i] << "\ty = " << moduleY[i] << "\tz = " << moduleZ[i];
0220 
0221   connect = vsArgs["ICCName"];
0222   connectY = vArgs["ICCY"];
0223   connectZ = vArgs["ICCZ"];
0224   LogDebug("TOBGeom") << "DDTOBRodAlgo debug:\t" << connect.size() << " ICC positioned with no rotation";
0225   for (int i = 0; i < (int)(connect.size()); i++)
0226     LogDebug("TOBGeom") << "\t" << connect[i] << "\ty = " << connectY[i] << "\tz = " << connectZ[i];
0227 
0228   aohName = sArgs["AOHName"];
0229   aohCopies = vArgs["AOHCopies"];
0230   aohX = vArgs["AOHx"];
0231   aohY = vArgs["AOHy"];
0232   aohZ = vArgs["AOHz"];
0233   LogDebug("TOBGeom") << "DDTOBRodAlgo debug:\t" << aohName << " AOH will be positioned on ICC's";
0234   for (int i = 0; i < (int)(aohCopies.size()); i++)
0235     LogDebug("TOBGeom") << " copies " << aohCopies[i] << "\tx = " << aohX[i] << "\ty = " << aohY[i]
0236                         << "\tz = " << aohZ[i];
0237 }
0238 
0239 void DDTOBRodAlgo::execute(DDCompactView& cpv) {
0240   LogDebug("TOBGeom") << "==>> Constructing DDTOBRodAlgo...";
0241   DDName rodName = parent().name();
0242   DDName centName(DDSplit(central).first, DDSplit(central).second);
0243 
0244   // Side Rods
0245   for (int i = 0; i < (int)(sideRod.size()); i++) {
0246     for (int j = 0; j < (int)(sideRodX.size()); j++) {
0247       DDTranslation r(sideRodX[j], sideRodY[i], sideRodZ[i]);
0248       DDName child(DDSplit(sideRod[i]).first, DDSplit(sideRod[i]).second);
0249       cpv.position(child, rodName, j + 1, r, DDRotation());
0250       LogDebug("TOBGeom") << "DDTOBRodAlgo test: " << child << " number " << j + 1 << " positioned in " << rodName
0251                           << " at " << r << " with no rotation";
0252     }
0253   }
0254 
0255   // Clamps
0256   for (int i = 0; i < (int)(clampX.size()); i++) {
0257     DDTranslation r(clampX[i], 0, shift + clampZ[i]);
0258     DDName child(DDSplit(clamp).first, DDSplit(clamp).second);
0259     cpv.position(child, rodName, i + 1, r, DDRotation());
0260     LogDebug("TOBGeom") << "DDTOBRodAlgo test: " << child << " number " << i + 1 << " positioned in " << rodName
0261                         << " at " << r << " with no rotation";
0262   }
0263 
0264   // Side Cooling tubes
0265   for (int i = 0; i < (int)(sideCoolX.size()); i++) {
0266     DDTranslation r(sideCoolX[i], sideCoolY[i], shift + sideCoolZ[i]);
0267     DDName child(DDSplit(sideCool).first, DDSplit(sideCool).second);
0268     cpv.position(child, rodName, i + 1, r, DDRotation());
0269     LogDebug("TOBGeom") << "DDTOBRodAlgo test: " << child << " number " << i + 1 << " positioned in " << rodName
0270                         << " at " << r << " with no rotation";
0271   }
0272 
0273   // Optical Fibres
0274   for (int i = 0; i < (int)(optFibreX.size()); i++) {
0275     DDTranslation r(optFibreX[i], 0, shift + optFibreZ[i]);
0276     DDName child(DDSplit(optFibre).first, DDSplit(optFibre).second);
0277     cpv.position(child, rodName, i + 1, r, DDRotation());
0278     LogDebug("TOBGeom") << "DDTOBRodAlgo test: " << child << " number " << i + 1 << " positioned in " << rodName
0279                         << " at " << r << " with no rotation";
0280   }
0281 
0282   // Side Clamps
0283   for (int i = 0; i < (int)(sideClamp1DZ.size()); i++) {
0284     int j = i / 2;
0285     DDTranslation r(sideClampX[i], moduleY[j], shift + moduleZ[j] + sideClamp1DZ[i]);
0286     DDName child(DDSplit(sideClamp1).first, DDSplit(sideClamp1).second);
0287     cpv.position(child, rodName, i + 1, r, DDRotation());
0288     LogDebug("TOBGeom") << "DDTOBRodAlgo test: " << child << " number " << i + 1 << " positioned in " << rodName
0289                         << " at " << r << " with no rotation";
0290   }
0291   for (int i = 0; i < (int)(sideClamp2DZ.size()); i++) {
0292     int j = i / 2;
0293     DDTranslation r(sideClampX[i], moduleY[j], shift + moduleZ[j] + sideClamp2DZ[i]);
0294     DDName child(DDSplit(sideClamp2).first, DDSplit(sideClamp2).second);
0295     cpv.position(child, rodName, i + 1, r, DDRotation());
0296     LogDebug("TOBGeom") << "DDTOBRodAlgo test: " << child << " number " << i + 1 << " positioned in " << rodName
0297                         << " at " << r << " with no rotation";
0298   }
0299 
0300   // End Rods
0301   for (int i = 0; i < (int)(endRod1Y.size()); i++) {
0302     DDTranslation r(0, endRod1Y[i], shift + endRod1Z[i]);
0303     DDName child(DDSplit(endRod1).first, DDSplit(endRod1).second);
0304     cpv.position(child, centName, i + 1, r, DDRotation());
0305     LogDebug("TOBGeom") << "DDTOBRodAlgo test: " << child << " number " << i + 1 << " positioned in " << centName
0306                         << " at " << r << " with no rotation";
0307   }
0308   DDTranslation r1(0, endRod2Y, shift + endRod2Z);
0309   DDName child1(DDSplit(endRod2).first, DDSplit(endRod2).second);
0310   cpv.position(child1, centName, 1, r1, DDRotation());
0311   LogDebug("TOBGeom") << "DDTOBRodAlgo test: " << child1 << " number 1 "
0312                       << "positioned in " << centName << " at " << r1 << " with no rotation";
0313 
0314   // End cooling tubes
0315   DDTranslation r2(0, endCoolY, shift + endCoolZ);
0316   string rotstr = DDSplit(endCoolRot).first;
0317   string rotns = DDSplit(endCoolRot).second;
0318   DDRotation rot2(DDName(rotstr, rotns));
0319   DDName child2(DDSplit(endCool).first, DDSplit(endCool).second);
0320   cpv.position(child2, centName, 1, r2, rot2);
0321   LogDebug("TOBGeom") << "DDTOBRodAlgo test: " << child2 << " number 1 "
0322                       << "positioned in " << centName << " at " << r2 << " with " << rot2;
0323 
0324   //Mother cable
0325   DDTranslation r3(0, 0, shift + cableZ);
0326   DDName child3(DDSplit(cable).first, DDSplit(cable).second);
0327   cpv.position(child3, centName, 1, r3, DDRotation());
0328   LogDebug("TOBGeom") << "DDTOBRodAlgo test: " << child3 << " number 1 "
0329                       << "positioned in " << centName << " at " << r3 << " with no rotation";
0330 
0331   //Modules
0332   for (int i = 0; i < (int)(moduleRot.size()); i++) {
0333     DDTranslation r(0, moduleY[i], shift + moduleZ[i]);
0334     rotstr = DDSplit(moduleRot[i]).first;
0335     DDRotation rot;
0336     if (rotstr != "NULL") {
0337       rotns = DDSplit(moduleRot[i]).second;
0338       rot = DDRotation(DDName(rotstr, rotns));
0339     }
0340     DDName child(DDSplit(module).first, DDSplit(module).second);
0341     cpv.position(child, centName, i + 1, r, rot);
0342     LogDebug("TOBGeom") << "DDTOBRodAlgo test: " << child << " number " << i + 1 << " positioned in " << centName
0343                         << " at " << r << " with " << rot;
0344   }
0345 
0346   //Connectors (ICC, CCUM, ...)
0347   for (int i = 0; i < (int)(connect.size()); i++) {
0348     DDTranslation r(0, connectY[i], shift + connectZ[i]);
0349     DDName child(DDSplit(connect[i]).first, DDSplit(connect[i]).second);
0350     cpv.position(child, centName, i + 1, r, DDRotation());
0351     LogDebug("TOBGeom") << "DDTOBRodAlgo test: " << child << " number " << i + 1 << " positioned in " << centName
0352                         << " at " << r << " with no rotation";
0353   }
0354 
0355   //AOH (only on ICCs)
0356   int copyNumber = 0;
0357   for (int i = 0; i < (int)(aohCopies.size()); i++) {
0358     if (aohCopies[i] != 0) {
0359       // first copy with (+aohX,+aohZ) translation
0360       copyNumber++;
0361       DDTranslation r(aohX[i] + 0, aohY[i] + connectY[i], aohZ[i] + shift + connectZ[i]);
0362       DDName child(DDSplit(aohName).first, DDSplit(aohName).second);
0363       cpv.position(child, centName, copyNumber, r, DDRotation());
0364       LogDebug("TOBGeom") << "DDTOBRodAlgo test: " << child << " number " << copyNumber << " positioned in " << centName
0365                           << " at " << r << " with no rotation";
0366       // if two copies add a copy with (-aohX,-aohZ) translation
0367       if (aohCopies[i] == 2) {
0368         copyNumber++;
0369         DDTranslation r(-aohX[i] + 0, aohY[i] + connectY[i], -aohZ[i] + shift + connectZ[i]);
0370         DDName child(DDSplit(aohName).first, DDSplit(aohName).second);
0371         cpv.position(child, centName, copyNumber, r, DDRotation());
0372         LogDebug("TOBGeom") << "DDTOBRodAlgo test: " << child << " number " << copyNumber << " positioned in "
0373                             << centName << " at " << r << " with no rotation";
0374       }
0375       // if four copies add 3 copies with (-aohX,+aohZ) (-aohX,-aohZ) (+aohX,+aohZ) and translations
0376       if (aohCopies[i] == 4) {
0377         for (unsigned int j = 1; j < 4; j++) {
0378           copyNumber++;
0379           switch (j) {
0380             case 1: {
0381               DDTranslation r(-aohX[i] + 0, aohY[i] + connectY[i], +aohZ[i] + shift + connectZ[i]);
0382               DDName child(DDSplit(aohName).first, DDSplit(aohName).second);
0383               cpv.position(child, centName, copyNumber, r, DDRotation());
0384               break;
0385             }
0386             case 2: {
0387               DDTranslation r(-aohX[i] + 0, aohY[i] + connectY[i], -aohZ[i] + shift + connectZ[i]);
0388               DDName child(DDSplit(aohName).first, DDSplit(aohName).second);
0389               cpv.position(child, centName, copyNumber, r, DDRotation());
0390               break;
0391             }
0392             case 3: {
0393               DDTranslation r(+aohX[i] + 0, aohY[i] + connectY[i], -aohZ[i] + shift + connectZ[i]);
0394               DDName child(DDSplit(aohName).first, DDSplit(aohName).second);
0395               cpv.position(child, centName, copyNumber, r, DDRotation());
0396               break;
0397             }
0398           }
0399           LogDebug("TOBGeom") << "DDTOBRodAlgo test: " << child << " number " << copyNumber << " positioned in "
0400                               << centName << " at " << r << " with no rotation";
0401         }
0402       }
0403     }
0404   }
0405 
0406   LogDebug("TOBGeom") << "<<== End of DDTOBRodAlgo construction ...";
0407 }
0408 
0409 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDTOBRodAlgo, "track:DDTOBRodAlgo");