DDTIDModulePosAlgo

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466
///////////////////////////////////////////////////////////////////////////////
// File: DDTIDModulePosAlgo.cc
// Description: Position various components inside a TID Module
///////////////////////////////////////////////////////////////////////////////

#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "DetectorDescription/Core/interface/DDCurrentNamespace.h"
#include "DetectorDescription/Core/interface/DDSplit.h"
#include "DetectorDescription/Core/interface/DDTypes.h"
#include "DetectorDescription/Core/interface/DDAlgorithm.h"
#include "DetectorDescription/Core/interface/DDAlgorithmFactory.h"
#include <CLHEP/Units/GlobalPhysicalConstants.h>
#include <CLHEP/Units/SystemOfUnits.h>

#include <string>
#include <vector>

using namespace std;

class DDTIDModulePosAlgo : public DDAlgorithm {
public:
  //Constructor and Destructor
  DDTIDModulePosAlgo();
  ~DDTIDModulePosAlgo() override;

  void initialize(const DDNumericArguments& nArgs,
                  const DDVectorArguments& vArgs,
                  const DDMapArguments& mArgs,
                  const DDStringArguments& sArgs,
                  const DDStringVectorArguments& vsArgs) override;
  void execute(DDCompactView& cpv) override;

private:
  int detectorN;             //Number of detectors
  double detTilt;            //Tilt of stereo detector
  double fullHeight;         //Height
  string boxFrameName;       //Top frame Name
  double boxFrameHeight;     //          height
  double boxFrameWidth;      //          width
  double dlTop;              //Width at top of wafer
  double dlBottom;           //Width at bottom of wafer
  double dlHybrid;           //Width at the hybrid end
  vector<double> boxFrameZ;  //              z-positions
  double bottomFrameHeight;  //Bottom of the frame
  double bottomFrameOver;    //              overlap
  double topFrameHeight;     //Top    of the frame
  double topFrameOver;       //              overlap

  vector<string> sideFrameName;  //Side Frame    name
  vector<double> sideFrameZ;     //              z-positions
  vector<string>
      sideFrameRot;       //              rotation matrix (required for correct positiong of the hole in the StereoR)
  double sideFrameWidth;  //              width
  double sideFrameOver;   //              overlap (wrt wafer)

  vector<string> kaptonName;  //Kapton Circuit    name
  vector<double> kaptonZ;     //              z-positions
  vector<string> kaptonRot;  //              rotation matrix (required for correct positiong of the hole in the StereoR)
  vector<string> waferName;  //Wafer         name
  vector<double> waferZ;     //              z-positions
  vector<string> waferRot;   //              rotation matrix
  string hybridName;         //Hybrid        name
  double hybridHeight;       //              height
  vector<double> hybridZ;    //              z-positions
  vector<string> pitchName;  //Pitch adapter rotation matrix
  double pitchHeight;        //              height
  vector<double> pitchZ;     //              z-positions
  vector<string> pitchRot;   //              rotation matrix
  string coolName;           //Cool Insert   name
  double coolHeight;         //              height
  double coolZ;              //              z-position
  double coolWidth;          //              width
  vector<double> coolRadShift;  //

  bool doSpacers;           //Spacers (alumina) to be made (Should be "Yes" for DS modules only)
  string botSpacersName;    // Spacers at the "bottom" of the module
  double botSpacersHeight;  //
  double botSpacersZ;       //              z-position
  string sidSpacersName;    //Spacers at the "sides" of the module
  double sidSpacersHeight;
  double sidSpacersZ;         //              z-position
  double sidSpacersWidth;     //              width
  double sidSpacersRadShift;  //
};

DDTIDModulePosAlgo::DDTIDModulePosAlgo() { LogDebug("TIDGeom") << "DDTIDModulePosAlgo info: Creating an instance"; }

DDTIDModulePosAlgo::~DDTIDModulePosAlgo() {}

void DDTIDModulePosAlgo::initialize(const DDNumericArguments& nArgs,
                                    const DDVectorArguments& vArgs,
                                    const DDMapArguments&,
                                    const DDStringArguments& sArgs,
                                    const DDStringVectorArguments& vsArgs) {
  int i;
  DDName parentName = parent().name();
  detectorN = (int)(nArgs["DetectorNumber"]);

  LogDebug("TIDGeom") << "DDTIDModulePosAlgo debug: Parent " << parentName << " Detector Planes " << detectorN;

  detTilt = nArgs["DetTilt"];
  fullHeight = nArgs["FullHeight"];
  dlTop = nArgs["DlTop"];
  dlBottom = nArgs["DlBottom"];
  dlHybrid = nArgs["DlHybrid"];

  LogDebug("TIDGeom") << "DDTIDModulePosAlgo debug: Detector Tilt " << detTilt / CLHEP::deg << " Height " << fullHeight
                      << " dl(Top) " << dlTop << " dl(Bottom) " << dlBottom << " dl(Hybrid) " << dlHybrid;

  boxFrameName = sArgs["BoxFrameName"];
  boxFrameHeight = nArgs["BoxFrameHeight"];
  boxFrameWidth = nArgs["BoxFrameWidth"];
  boxFrameZ = vArgs["BoxFrameZ"];
  bottomFrameHeight = nArgs["BottomFrameHeight"];
  bottomFrameOver = nArgs["BottomFrameOver"];
  topFrameHeight = nArgs["TopFrameHeight"];
  topFrameOver = nArgs["TopFrameOver"];
  LogDebug("TIDGeom") << "DDTIDModulePosAlgo debug: " << boxFrameName << " positioned at Z";
  for (i = 0; i < detectorN; i++)
    LogDebug("TIDGeom") << "\tboxFrameZ[" << i << "] = " << boxFrameZ[i];
  LogDebug("TIDGeom") << "\t Extra Height at Bottom " << bottomFrameHeight << " Overlap " << bottomFrameOver;

  sideFrameName = vsArgs["SideFrameName"];
  sideFrameZ = vArgs["SideFrameZ"];
  sideFrameRot = vsArgs["SideFrameRotation"];
  sideFrameWidth = nArgs["SideFrameWidth"];
  sideFrameOver = nArgs["SideFrameOver"];
  for (i = 0; i < detectorN; i++)
    LogDebug("TIDGeom") << "\tsideFrame[" << i << "] = " << sideFrameName[i] << " positioned at Z " << sideFrameZ[i]
                        << " with rotation " << sideFrameRot[i];

  kaptonName = vsArgs["KaptonName"];
  kaptonZ = vArgs["KaptonZ"];
  kaptonRot = vsArgs["KaptonRotation"];
  for (i = 0; i < detectorN; i++)
    LogDebug("TIDGeom") << "\tkapton[" << i << "] = " << kaptonName[i] << " positioned at Z " << kaptonZ[i]
                        << " with rotation " << kaptonRot[i];

  waferName = vsArgs["WaferName"];
  waferZ = vArgs["WaferZ"];
  waferRot = vsArgs["WaferRotation"];
  for (i = 0; i < detectorN; i++)
    LogDebug("TIDGeom") << "DDTIDModulePosAlgo debug: " << waferName[i] << " positioned at Z " << waferZ[i]
                        << " with rotation " << waferRot[i];

  hybridName = sArgs["HybridName"];
  hybridHeight = nArgs["HybridHeight"];
  hybridZ = vArgs["HybridZ"];
  LogDebug("TIDGeom") << "DDTIDModulePosAlgo debug: " << hybridName << " Height " << hybridHeight << " Z";
  for (i = 0; i < detectorN; i++)
    LogDebug("TIDGeom") << "\thybridZ[" << i << "] = " << hybridZ[i];

  pitchName = vsArgs["PitchName"];
  pitchHeight = nArgs["PitchHeight"];
  pitchZ = vArgs["PitchZ"];
  pitchRot = vsArgs["PitchRotation"];
  LogDebug("TIDGeom") << "DDTIDModulePosAlgo debug: Pitch Adapter Height " << pitchHeight;
  for (i = 0; i < detectorN; i++)
    LogDebug("TIDGeom") << "DDTIDModulePosAlgo debug: " << pitchName[i] << " position at Z " << pitchZ[i]
                        << " with rotation " << pitchRot[i];

  coolName = sArgs["CoolInsertName"];
  coolHeight = nArgs["CoolInsertHeight"];
  coolZ = nArgs["CoolInsertZ"];
  coolWidth = nArgs["CoolInsertWidth"];
  coolRadShift = vArgs["CoolInsertShift"];

  string comp = sArgs["DoSpacers"];
  if (comp == "No" || comp == "NO" || comp == "no")
    doSpacers = false;
  else
    doSpacers = true;

  botSpacersName = sArgs["BottomSpacersName"];
  botSpacersHeight = nArgs["BottomSpacersHeight"];
  botSpacersZ = nArgs["BottomSpacersZ"];
  sidSpacersName = sArgs["SideSpacersName"];
  sidSpacersHeight = nArgs["SideSpacersHeight"];
  sidSpacersZ = nArgs["SideSpacersZ"];
  sidSpacersWidth = nArgs["SideSpacersWidth"];
  sidSpacersRadShift = nArgs["SideSpacersShift"];
}

void DDTIDModulePosAlgo::execute(DDCompactView& cpv) {
  LogDebug("TIDGeom") << "==>> Constructing DDTIDModulePosAlgo...";

  DDName parentName = parent().name();

  double botfr;  // width of side frame at the the bottom of the modules
  double topfr;  // width of side frame at the the top of the modules
  double kaptonHeight;
  if (dlHybrid > dlTop) {
    // ring 1, ring 2
    topfr = topFrameHeight - pitchHeight - topFrameOver;
    botfr = bottomFrameHeight - bottomFrameOver;
    kaptonHeight = fullHeight + botfr;
  } else {
    // ring 3
    topfr = topFrameHeight - topFrameOver;
    botfr = bottomFrameHeight - bottomFrameOver - pitchHeight;
    kaptonHeight = fullHeight + topfr;
  }

  double sideFrameHeight = fullHeight + pitchHeight + botfr + topfr;
  double zCenter = 0.5 * (sideFrameHeight + boxFrameHeight);

  // (Re) Compute the envelope for positioning Cool Inserts and Side Spacers (Alumina).
  double sidfr = sideFrameWidth - sideFrameOver;  // width of side frame on the sides of module
  double dxbot = 0.5 * dlBottom + sidfr;
  double dxtop = 0.5 * dlTop + sidfr;
  double dxtopenv, dxbotenv;  // top/bot width of the module envelope trap

  double tanWafer = (dxtop - dxbot) / fullHeight;  //
  double thetaWafer = atan(tanWafer);              // 1/2 of the wafer wedge angle

  if (dlHybrid > dlTop) {
    // ring 1, ring 2
    dxtopenv = dxbot + (dxtop - dxbot) * (fullHeight + pitchHeight + topfr + hybridHeight) / fullHeight;
    dxbotenv = dxtop - (dxtop - dxbot) * (fullHeight + botfr) / fullHeight;
  } else {
    // ring 3
    dxtopenv = dxbot + (dxtop - dxbot) * (fullHeight + topfr) / fullHeight;
    dxbotenv = dxbot;
  }

  double tanEnv = (dxtopenv - dxbotenv) / (sideFrameHeight + boxFrameHeight);  // 1/2 of the envelope wedge angle

  double xpos = 0;
  double ypos = 0;
  double zpos = 0;

  // Cool Inserts
  DDName name = DDName(DDSplit(coolName).first, DDSplit(coolName).second);
  ypos = coolZ;

  double zCool;
  int copy = 0;
  DDRotation rot = DDRotation();  // should be different for different elements

  for (int j1 = 0; j1 < 2; j1++) {  // j1: 0 inserts below the hybrid
                                    //     1 inserts below the wafer
    if (dlHybrid > dlTop) {
      zCool = sideFrameHeight + boxFrameHeight - coolRadShift[j1];
      if (j1 == 0)
        zCool -= 0.5 * coolHeight;
    } else {
      zCool = coolRadShift[j1];
      if (j1 == 0)
        zCool += 0.5 * coolHeight;
    }

    if (j1 == 0) {
      xpos = -0.5 * (boxFrameWidth - coolWidth);
    } else {
      xpos = -(dxbotenv + (zCool - 0.5 * coolHeight) * tanEnv - 0.5 * coolWidth);
    }

    zpos = zCool - zCenter;
    for (int j2 = 0; j2 < 2; j2++) {
      copy++;
      cpv.position(name, parentName, copy, DDTranslation(xpos, ypos, zpos), rot);
      LogDebug("TIDGeom") << "DDTIDModulePosAlgo test: " << name << " number " << copy << " positioned in "
                          << parentName << " at " << DDTranslation(xpos, ypos, zpos) << " with " << rot;
      xpos = -xpos;
    }
  }

  if (doSpacers) {
    // Bottom Spacers (Alumina)
    DDName name = DDName(DDSplit(botSpacersName).first, DDSplit(botSpacersName).second);
    ypos = botSpacersZ;

    double zBotSpacers;
    if (dlHybrid > dlTop) {
      zBotSpacers = sideFrameHeight + boxFrameHeight - 0.5 * botSpacersHeight;
    } else {
      zBotSpacers = 0.5 * botSpacersHeight;
    }
    zpos = zBotSpacers - zCenter;
    rot = DDRotation();
    cpv.position(name, parentName, 1, DDTranslation(0.0, ypos, zpos), rot);
    LogDebug("TIDGeom") << "DDTIDModulePosAlgo test: " << name << " number " << 1 << " positioned in " << parentName
                        << " at " << DDTranslation(0.0, ypos, zpos) << " with no rotation";

    // Side Spacers (Alumina)
    name = DDName(DDSplit(sidSpacersName).first, DDSplit(sidSpacersName).second);
    ypos = sidSpacersZ;

    double zSideSpacers;
    if (dlHybrid > dlTop) {
      zSideSpacers = sideFrameHeight + boxFrameHeight - sidSpacersRadShift;
    } else {
      zSideSpacers = sidSpacersRadShift;
    }
    zpos = zSideSpacers - zCenter;

    copy = 0;
    xpos = dxbotenv + (zSideSpacers - 0.5 * sidSpacersHeight) * tanEnv - 0.5 * sidSpacersWidth + sideFrameOver;

    double phix, phiy, phiz;
    phix = 0. * CLHEP::deg;
    phiy = 90. * CLHEP::deg;
    phiz = 0. * CLHEP::deg;

    double thetay, thetax;
    thetay = 90. * CLHEP::deg;
    double thetaz = thetaWafer;

    for (int j1 = 0; j1 < 2; j1++) {
      copy++;

      // tilt Side Spacers (parallel to Side Frame)
      thetax = 90. * CLHEP::deg + thetaz;
      double thetadeg = thetax / CLHEP::deg;
      if (thetadeg != 0) {
        string arotstr = DDSplit(sidSpacersName).first + to_string(thetadeg * 10.);
        rot = DDrot(DDName(arotstr, DDSplit(sidSpacersName).second), thetax, phix, thetay, phiy, thetaz, phiz);
      }

      cpv.position(name, parentName, copy, DDTranslation(xpos, ypos, zpos), rot);
      LogDebug("TIDGeom") << "DDTIDModulePosAlgo test: " << name << " number " << copy << " positioned in "
                          << parentName << " at " << DDTranslation(xpos, ypos, zpos) << " with " << rot;
      xpos = -xpos;
      thetaz = -thetaz;
    }
  }

  // Loop over detectors to be placed
  for (int k = 0; k < detectorN; k++) {
    // Wafer
    name = DDName(DDSplit(waferName[k]).first, DDSplit(waferName[k]).second);
    xpos = 0;
    ypos = waferZ[k];
    double zWafer;
    if (dlHybrid > dlTop) {
      zWafer = botfr + 0.5 * fullHeight;
    } else {
      zWafer = boxFrameHeight + botfr + pitchHeight + 0.5 * fullHeight;
    }
    zpos = zWafer - zCenter;
    DDTranslation tran(xpos, ypos, zpos);
    string rotstr = DDSplit(waferRot[k]).first;
    string rotns;
    if (rotstr != "NULL") {
      rotns = DDSplit(waferRot[k]).second;
      rot = DDRotation(DDName(rotstr, rotns));
    }
    cpv.position(name, parentName, k + 1, tran, rot);
    LogDebug("TIDGeom") << "DDTIDModulePosAlgo test: " << name << " number " << k + 1 << " positioned in " << parentName
                        << " at " << tran << " with " << rot;

    //Pitch Adapter
    name = DDName(DDSplit(pitchName[k]).first, DDSplit(pitchName[k]).second);
    if (k == 0) {
      xpos = 0;
    } else {
      xpos = 0.5 * fullHeight * sin(detTilt);
    }
    ypos = pitchZ[k];
    double zPitch;
    if (dlHybrid > dlTop) {
      zPitch = botfr + fullHeight + 0.5 * pitchHeight;
    } else {
      zPitch = boxFrameHeight + botfr + 0.5 * pitchHeight;
    }
    zpos = zPitch - zCenter;
    rotstr = DDSplit(pitchRot[k]).first;
    if (rotstr != "NULL") {
      rotns = DDSplit(pitchRot[k]).second;
      rot = DDRotation(DDName(rotstr, rotns));
    } else {
      rot = DDRotation();
    }
    tran = DDTranslation(xpos, ypos, zpos);
    cpv.position(name, parentName, k + 1, tran, rot);
    LogDebug("TIDGeom") << "DDTIDModulePosAlgo test: " << name << " number " << k + 1 << " positioned in " << parentName
                        << " at " << tran << " with " << rot;

    // Hybrid
    name = DDName(DDSplit(hybridName).first, DDSplit(hybridName).second);
    ypos = hybridZ[k];
    double zHybrid;
    if (dlHybrid > dlTop) {
      zHybrid = botfr + fullHeight + pitchHeight + 0.5 * hybridHeight;
    } else {
      zHybrid = 0.5 * hybridHeight;
    }
    zpos = zHybrid - zCenter;
    tran = DDTranslation(0, ypos, zpos);
    rot = DDRotation();
    cpv.position(name, parentName, k + 1, tran, rot);
    LogDebug("TIDGeom") << "DDTIDModulePosAlgo test: " << name << " number " << k + 1 << " positioned in " << parentName
                        << " at " << tran << " with " << rot;

    // Box frame
    name = DDName(DDSplit(boxFrameName).first, DDSplit(boxFrameName).second);
    ypos = boxFrameZ[k];
    double zBoxFrame;
    if (dlHybrid > dlTop) {
      zBoxFrame = sideFrameHeight + 0.5 * boxFrameHeight;
    } else {
      zBoxFrame = 0.5 * boxFrameHeight;
    }
    zpos = zBoxFrame - zCenter;
    tran = DDTranslation(0, ypos, zpos);
    rot = DDRotation();
    cpv.position(name, parentName, k + 1, tran, rot);
    LogDebug("TIDGeom") << "DDTIDModulePosAlgo test: " << name << " number " << k + 1 << " positioned in " << parentName
                        << " at " << tran << " with " << rot;

    // Side frame
    name = DDName(DDSplit(sideFrameName[k]).first, DDSplit(sideFrameName[k]).second);
    ypos = sideFrameZ[k];
    double zSideFrame;
    if (dlHybrid > dlTop) {
      zSideFrame = 0.5 * sideFrameHeight;
    } else {
      zSideFrame = boxFrameHeight + 0.5 * sideFrameHeight;
    }
    zpos = zSideFrame - zCenter;
    rotstr = DDSplit(sideFrameRot[k]).first;
    if (rotstr != "NULL") {
      rotns = DDSplit(sideFrameRot[k]).second;
      rot = DDRotation(DDName(rotstr, rotns));
    } else {
      rot = DDRotation();
    }
    tran = DDTranslation(0, ypos, zpos);
    cpv.position(name, parentName, k + 1, tran, rot);
    LogDebug("TIDGeom") << "DDTIDModulePosAlgo test: " << name << " number " << k + 1 << " positioned in " << parentName
                        << " at " << tran << " with " << rot;

    // Kapton circuit
    name = DDName(DDSplit(kaptonName[k]).first, DDSplit(kaptonName[k]).second);
    ypos = kaptonZ[k];
    double zKapton;
    double kaptonExtraHeight = 0;
    if (dlHybrid > dlTop) {
      if (k == 1)
        kaptonExtraHeight = dlTop * sin(detTilt) - fullHeight * (1 - cos(detTilt));
      kaptonExtraHeight = 0.5 * fabs(kaptonExtraHeight);
      zKapton = 0.5 * (kaptonHeight + kaptonExtraHeight);
    } else {
      if (k == 1)
        kaptonExtraHeight = dlBottom * sin(detTilt) - fullHeight * (1 - cos(detTilt));
      kaptonExtraHeight = 0.5 * fabs(kaptonExtraHeight);
      zKapton = boxFrameHeight + sideFrameHeight - 0.5 * (kaptonHeight + kaptonExtraHeight);
    }
    zpos = zKapton - zCenter;
    rotstr = DDSplit(kaptonRot[k]).first;
    if (rotstr != "NULL") {
      rotns = DDSplit(kaptonRot[k]).second;
      rot = DDRotation(DDName(rotstr, rotns));
    } else {
      rot = DDRotation();
    }
    tran = DDTranslation(0, ypos, zpos);
    cpv.position(name, parentName, k + 1, tran, rot);
    LogDebug("TIDGeom") << "DDTIDModulePosAlgo test: " << name << " number " << k + 1 << " positioned in " << parentName
                        << " at " << tran << " with " << rot;
  }

  LogDebug("TIDGeom") << "<<== End of DDTIDModulePosAlgo positioning ...";
}

DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDTIDModulePosAlgo, "track:DDTIDModulePosAlgo");