DDTIDModuleAlgo

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 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635
///////////////////////////////////////////////////////////////////////////////
// File: DDTIDModuleAlgo.cc
// Description: Creation of a TID Module
///////////////////////////////////////////////////////////////////////////////

#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "DetectorDescription/Core/interface/DDLogicalPart.h"
#include "DetectorDescription/Core/interface/DDSolid.h"
#include "DetectorDescription/Core/interface/DDMaterial.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 DDTIDModuleAlgo : public DDAlgorithm {
public:
  //Constructor and Destructor
  DDTIDModuleAlgo();
  ~DDTIDModuleAlgo() 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:
  string genMat;       //General material name
  int detectorN;       //Detector planes
  double moduleThick;  //Module thickness
  double detTilt;      //Tilt of stereo detector
  double fullHeight;   //Height
  double dlTop;        //Width at top of wafer
  double dlBottom;     //Width at bottom of wafer
  double dlHybrid;     //Width at the hybrid end
  bool doComponents;   //Components to be made

  string boxFrameName;           //Top frame     name
  string boxFrameMat;            //              material
  double boxFrameHeight;         //              height
  double boxFrameThick;          //              thickness
  double boxFrameWidth;          //              extra width
  double bottomFrameHeight;      //Bottom of the frame
  double bottomFrameOver;        //              overlap
  double topFrameHeight;         //Top    of the frame
  double topFrameOver;           //              overlap
  vector<string> sideFrameName;  //Side frame    name
  string sideFrameMat;           //              material
  double sideFrameWidth;         //              width
  double sideFrameThick;         //              thickness
  double sideFrameOver;          //              overlap (wrt wafer)
  vector<string> holeFrameName;  //Hole in the frame   name
  vector<string> holeFrameRot;   //              Rotation matrix

  vector<string> kaptonName;  //Kapton circuit name
  string kaptonMat;           //               material
  //  double                   kaptonWidth;   //               width -> computed internally from sideFrameWidth and kaptonOver
  double kaptonThick;             //               thickness
  double kaptonOver;              //               overlap (wrt Wafer)
  vector<string> holeKaptonName;  //Hole in the kapton circuit name
  vector<string> holeKaptonRot;   //              Rotation matrix

  vector<string> waferName;       //Wafer         name
  string waferMat;                //              material
  double sideWidthTop;            //              width on the side Top
  double sideWidthBottom;         //                                Bottom
  vector<string> activeName;      //Sensitive     name
  string activeMat;               //              material
  double activeHeight;            //              height
  vector<double> waferThick;      //              wafer thickness (active = wafer - backplane)
  string activeRot;               //              Rotation matrix
  vector<double> backplaneThick;  //              thickness
  string hybridName;              //Hybrid        name
  string hybridMat;               //              material
  double hybridHeight;            //              height
  double hybridWidth;             //              width
  double hybridThick;             //              thickness
  vector<string> pitchName;       //Pitch adapter name
  string pitchMat;                //              material
  double pitchHeight;             //              height
  double pitchThick;              //              thickness
  double pitchStereoTol;          //              tolerance in dimensions of the stereo
  string coolName;                // Cool insert name
  string coolMat;                 //              material
  double coolHeight;              //              height
  double coolThick;               //              thickness
  double coolWidth;               //              width
};

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

DDTIDModuleAlgo::~DDTIDModuleAlgo() {}

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

  LogDebug("TIDGeom") << "DDTIDModuleAlgo debug: Parent " << parentName << " General Material " << genMat
                      << " Detector Planes " << detectorN;

  moduleThick = nArgs["ModuleThick"];
  detTilt = nArgs["DetTilt"];
  fullHeight = nArgs["FullHeight"];
  dlTop = nArgs["DlTop"];
  dlBottom = nArgs["DlBottom"];
  dlHybrid = nArgs["DlHybrid"];
  string comp = sArgs["DoComponents"];
  if (comp == "No" || comp == "NO" || comp == "no")
    doComponents = false;
  else
    doComponents = true;

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

  boxFrameName = sArgs["BoxFrameName"];
  boxFrameMat = sArgs["BoxFrameMaterial"];
  boxFrameThick = nArgs["BoxFrameThick"];
  boxFrameHeight = nArgs["BoxFrameHeight"];
  boxFrameWidth = nArgs["BoxFrameWidth"];
  bottomFrameHeight = nArgs["BottomFrameHeight"];
  bottomFrameOver = nArgs["BottomFrameOver"];
  LogDebug("TIDGeom") << "DDTIDModuleAlgo debug: " << boxFrameName << " Material " << boxFrameMat << " Thickness "
                      << boxFrameThick << " width " << boxFrameWidth << " height " << boxFrameHeight
                      << " Extra Height at Bottom " << bottomFrameHeight << " Overlap " << bottomFrameOver;

  topFrameHeight = nArgs["TopFrameHeight"];
  topFrameOver = nArgs["TopFrameOver"];
  sideFrameName = vsArgs["SideFrameName"];
  sideFrameMat = sArgs["SideFrameMaterial"];
  sideFrameWidth = nArgs["SideFrameWidth"];
  sideFrameThick = nArgs["SideFrameThick"];
  sideFrameOver = nArgs["SideFrameOver"];
  holeFrameName = vsArgs["HoleFrameName"];
  holeFrameRot = vsArgs["HoleFrameRotation"];
  for (i = 0; i < detectorN; i++)
    LogDebug("TIDGeom") << "DDTIDModuleAlgo debug : " << sideFrameName[i] << " Material " << sideFrameMat << " Width "
                        << sideFrameWidth << " Thickness " << sideFrameThick << " Overlap " << sideFrameOver
                        << " Hole  " << holeFrameName[i];

  kaptonName = vsArgs["KaptonName"];
  kaptonMat = sArgs["KaptonMaterial"];
  kaptonThick = nArgs["KaptonThick"];
  kaptonOver = nArgs["KaptonOver"];
  holeKaptonName = vsArgs["HoleKaptonName"];
  holeKaptonRot = vsArgs["HoleKaptonRotation"];
  for (i = 0; i < detectorN; i++)
    LogDebug("TIDGeom") << "DDTIDModuleAlgo debug : " << kaptonName[i] << " Material " << kaptonMat << " Thickness "
                        << kaptonThick << " Overlap " << kaptonOver << " Hole  " << holeKaptonName[i];

  waferName = vsArgs["WaferName"];
  waferMat = sArgs["WaferMaterial"];
  sideWidthTop = nArgs["SideWidthTop"];
  sideWidthBottom = nArgs["SideWidthBottom"];

  LogDebug("TIDGeom") << "DDTIDModuleAlgo debug: Wafer Material " << waferMat << " Side Width Top " << sideWidthTop
                      << " Side Width Bottom " << sideWidthBottom;
  for (i = 0; i < detectorN; i++)
    LogDebug("TIDGeom") << "\twaferName[" << i << "] = " << waferName[i];

  activeName = vsArgs["ActiveName"];
  activeMat = sArgs["ActiveMaterial"];
  activeHeight = nArgs["ActiveHeight"];
  waferThick = vArgs["WaferThick"];
  activeRot = sArgs["ActiveRotation"];
  backplaneThick = vArgs["BackPlaneThick"];
  LogDebug("TIDGeom") << "DDTIDModuleAlgo debug: Active Material " << activeMat << " Height " << activeHeight
                      << " rotated by " << activeRot;
  for (i = 0; i < detectorN; i++)
    LogDebug("TIDGeom") << " translated by (0," << -0.5 * backplaneThick[i] << ",0)\tactiveName[" << i
                        << "] = " << activeName[i] << " of thickness " << waferThick[i] - backplaneThick[i];

  hybridName = sArgs["HybridName"];
  hybridMat = sArgs["HybridMaterial"];
  hybridHeight = nArgs["HybridHeight"];
  hybridWidth = nArgs["HybridWidth"];
  hybridThick = nArgs["HybridThick"];
  LogDebug("TIDGeom") << "DDTIDModuleAlgo debug: " << hybridName << " Material " << hybridMat << " Height "
                      << hybridHeight << " Width " << hybridWidth << " Thickness " << hybridThick;

  pitchName = vsArgs["PitchName"];
  pitchMat = sArgs["PitchMaterial"];
  pitchHeight = nArgs["PitchHeight"];
  pitchThick = nArgs["PitchThick"];
  pitchStereoTol = nArgs["PitchStereoTolerance"];

  LogDebug("TIDGeom") << "DDTIDModuleAlgo debug: Pitch Adapter Material " << pitchMat << " Height " << pitchHeight
                      << " Thickness " << pitchThick;
  for (i = 0; i < detectorN; i++)
    LogDebug("TIDGeom") << "\tpitchName[" << i << "] = " << pitchName[i];

  coolName = sArgs["CoolInsertName"];
  coolMat = sArgs["CoolInsertMaterial"];
  coolHeight = nArgs["CoolInsertHeight"];
  coolThick = nArgs["CoolInsertThick"];
  coolWidth = nArgs["CoolInsertWidth"];
  LogDebug("TIDGeom") << "DDTIDModuleAlgo debug: Cool Element Material " << coolMat << " Height " << coolHeight
                      << " Thickness " << coolThick << " Width " << coolWidth;
}

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

  DDName parentName(parent().name());

  double sidfr = sideFrameWidth - sideFrameOver;  // width of side frame on the sides of module
  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 kaptonWidth = sidfr + kaptonOver;

  double dxbot = 0.5 * dlBottom + sidfr;
  double dxtop = 0.5 * dlTop + sidfr;
  double dxtopenv, dxbotenv;  // top/bot width of the module envelope trap

  // Envelope
  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 bl1 = dxbotenv;
  double bl2 = dxtopenv;
  double h1 = 0.5 * moduleThick;
  double dz = 0.5 * (boxFrameHeight + sideFrameHeight);

  DDSolid solidUncut, solidCut;
  DDSolid solid = DDSolidFactory::trap(parentName, dz, 0, 0, h1, bl1, bl1, 0, h1, bl2, bl2, 0);
  DDMaterial matter = DDMaterial(DDName(DDSplit(genMat).first, DDSplit(genMat).second));
  DDLogicalPart module(solid.ddname(), matter, solid);
  LogDebug("TIDGeom") << "DDTIDModuleAlgo test:\t" << solid.name() << " Trap made of " << genMat << " of dimensions "
                      << dz << ", 0, 0, " << h1 << ", " << bl1 << ", " << bl1 << ", 0, " << h1 << ", " << bl2 << ", "
                      << bl2 << ", 0";

  if (doComponents) {
    //Box frame
    matter = DDMaterial(DDName(DDSplit(boxFrameMat).first, DDSplit(boxFrameMat).second));
    double dx = 0.5 * boxFrameWidth;
    double dy = 0.5 * boxFrameThick;
    double dz = 0.5 * boxFrameHeight;
    solid = DDSolidFactory::box(DDName(DDSplit(boxFrameName).first, DDSplit(boxFrameName).second), dx, dy, dz);
    LogDebug("TIDGeom") << "DDTIDModuleAlgo test:\t" << solid.name() << " Box made of " << matter.ddname()
                        << " of dimensions " << dx << ", " << dy << ", " << dz;
    DDLogicalPart boxFrame(solid.ddname(), matter, solid);

    // Hybrid
    matter = DDMaterial(DDName(DDSplit(hybridMat).first, DDSplit(hybridMat).second));
    dx = 0.5 * hybridWidth;
    dy = 0.5 * hybridThick;
    dz = 0.5 * hybridHeight;
    solid = DDSolidFactory::box(DDName(DDSplit(hybridName).first, DDSplit(hybridName).second), dx, dy, dz);
    LogDebug("TIDGeom") << "DDTIDModuleAlgo test:\t" << solid.name() << " Box made of " << matter.ddname()
                        << " of dimensions " << dx << ", " << dy << ", " << dz;
    DDLogicalPart hybrid(solid.ddname(), matter, solid);

    // Cool Insert
    matter = DDMaterial(DDName(DDSplit(coolMat).first, DDSplit(coolMat).second));
    dx = 0.5 * coolWidth;
    dy = 0.5 * coolThick;
    dz = 0.5 * coolHeight;
    solid = DDSolidFactory::box(DDName(DDSplit(coolName).first, DDSplit(coolName).second), dx, dy, dz);
    LogDebug("TIDGeom") << "DDTIDModuleAlgo test:\t" << solid.name() << " Box made of " << matter.ddname()
                        << " of dimensions " << dx << ", " << dy << ", " << dz;
    DDLogicalPart cool(solid.ddname(), matter, solid);

    // Loop over detectors to be placed
    for (int k = 0; k < detectorN; k++) {
      double bbl1, bbl2;  // perhaps useless (bl1 enough)

      // Frame Sides
      matter = DDMaterial(DDName(DDSplit(sideFrameMat).first, DDSplit(sideFrameMat).second));
      if (dlHybrid > dlTop) {
        // ring 1, ring 2
        bbl1 = dxtop - (dxtop - dxbot) * (fullHeight + botfr) / fullHeight;
        bbl2 = dxbot + (dxtop - dxbot) * (fullHeight + pitchHeight + topfr) / fullHeight;
      } else {
        // ring 3
        bbl1 = dxtop - (dxtop - dxbot) * (fullHeight + pitchHeight + botfr) / fullHeight;
        bbl2 = dxbot + (dxtop - dxbot) * (fullHeight + topfr) / fullHeight;
      }
      h1 = 0.5 * sideFrameThick;
      dz = 0.5 * sideFrameHeight;
      solid = DDSolidFactory::trap(DDName(DDSplit(sideFrameName[k]).first, DDSplit(sideFrameName[k]).second),
                                   dz,
                                   0,
                                   0,
                                   h1,
                                   bbl1,
                                   bbl1,
                                   0,
                                   h1,
                                   bbl2,
                                   bbl2,
                                   0);
      LogDebug("TIDGeom") << "DDTIDModuleAlgo test:\t" << solid.name() << " Trap made of " << matter.ddname()
                          << " of dimensions " << dz << ", 0, 0, " << h1 << ", " << bbl1 << ", " << bbl1 << ", 0, "
                          << h1 << ", " << bbl2 << ", " << bbl2 << ", 0";
      DDLogicalPart sideFrame(solid.ddname(), matter, solid);

      string rotstr, rotns;
      DDRotation rot;

      // Hole in the frame below the wafer
      matter = DDMaterial(DDName(DDSplit(genMat).first, DDSplit(genMat).second));
      double xpos, zpos;
      dz = fullHeight - bottomFrameOver - topFrameOver;
      bbl1 = dxbot - sideFrameWidth + bottomFrameOver * (dxtop - dxbot) / fullHeight;
      bbl2 = dxtop - sideFrameWidth - topFrameOver * (dxtop - dxbot) / fullHeight;
      if (dlHybrid > dlTop) {
        // ring 1, ring 2
        zpos = -(topFrameHeight + 0.5 * dz - 0.5 * sideFrameHeight);
      } else {
        // ring 3
        zpos = bottomFrameHeight + 0.5 * dz - 0.5 * sideFrameHeight;
      }
      dz /= 2.;
      solid = DDSolidFactory::trap(DDName(DDSplit(holeFrameName[k]).first, DDSplit(holeFrameName[k]).second),
                                   dz,
                                   0,
                                   0,
                                   h1,
                                   bbl1,
                                   bbl1,
                                   0,
                                   h1,
                                   bbl2,
                                   bbl2,
                                   0);
      LogDebug("TIDGeom") << "DDTIDModuleAlgo test:\t" << solid.name() << " Trap made of " << matter.ddname()
                          << " of dimensions " << dz << ", 0, 0, " << h1 << ", " << bbl1 << ", " << bbl1 << ", 0, "
                          << h1 << ", " << bbl2 << ", " << bbl2 << ", 0";
      DDLogicalPart holeFrame(solid.ddname(), matter, solid);

      rotstr = DDSplit(holeFrameRot[k]).first;
      if (rotstr != "NULL") {
        rotns = DDSplit(holeFrameRot[k]).second;
        rot = DDRotation(DDName(rotstr, rotns));
      } else {
        rot = DDRotation();
      }
      cpv.position(holeFrame, sideFrame, 1, DDTranslation(0.0, 0.0, zpos), rot);
      LogDebug("TIDGeom") << "DDTIDModuleAlgo test: " << holeFrame.name() << " number 1 positioned in "
                          << sideFrame.name() << " at (0,0," << zpos << ") with no rotation";

      // Kapton circuit
      matter = DDMaterial(DDName(DDSplit(kaptonMat).first, DDSplit(kaptonMat).second));
      double kaptonExtraHeight = 0;  // kapton extra height in the stereo
      if (dlHybrid > dlTop) {
        // ring 1, ring 2
        bbl1 = dxtop - (dxtop - dxbot) * (fullHeight + botfr) / fullHeight;
        if (k == 1) {
          kaptonExtraHeight = dlTop * sin(detTilt) - fullHeight * (1 - cos(detTilt));
          kaptonExtraHeight = 0.5 * fabs(kaptonExtraHeight);
          bbl2 = dxbot + (dxtop - dxbot) * (fullHeight + kaptonExtraHeight) / fullHeight;
        } else {
          bbl2 = dxtop;
        }
      } else {
        // ring 3
        bbl2 = dxbot + (dxtop - dxbot) * (fullHeight + topfr) / fullHeight;
        if (k == 1) {
          kaptonExtraHeight = dlBottom * sin(detTilt) - fullHeight * (1 - cos(detTilt));
          kaptonExtraHeight = 0.5 * fabs(kaptonExtraHeight);
          bbl1 = dxtop - (dxtop - dxbot) * (fullHeight + kaptonExtraHeight) / fullHeight;
        } else {
          bbl1 = dxbot;
        }
      }
      h1 = 0.5 * kaptonThick;
      dz = 0.5 * (kaptonHeight + kaptonExtraHeight);

      // For the stereo create the uncut solid, the solid to be removed and then the subtraction solid
      if (k == 1) {
        // Uncut solid
        string kaptonUncutName = kaptonName[k] + "Uncut";
        solidUncut = DDSolidFactory::trap(DDName(DDSplit(kaptonUncutName).first, DDSplit(kaptonUncutName).second),
                                          dz,
                                          0,
                                          0,
                                          h1,
                                          bbl1,
                                          bbl1,
                                          0,
                                          h1,
                                          bbl2,
                                          bbl2,
                                          0);

        // Piece to be cut
        string kaptonCutName = kaptonName[k] + "Cut";

        if (dlHybrid > dlTop) {
          dz = 0.5 * dlTop;
        } else {
          dz = 0.5 * dlBottom;
        }
        h1 = 0.5 * kaptonThick;
        bbl1 = fabs(dz * sin(detTilt));
        bbl2 = bbl1 * 0.000001;
        double thet = atan((bbl1 - bbl2) / (2 * dz));
        solidCut = DDSolidFactory::trap(DDName(DDSplit(kaptonCutName).first, DDSplit(kaptonCutName).second),
                                        dz,
                                        thet,
                                        0,
                                        h1,
                                        bbl1,
                                        bbl1,
                                        0,
                                        h1,
                                        bbl2,
                                        bbl2,
                                        0);

        string aRot("tidmodpar:9PYX");
        rotstr = DDSplit(aRot).first;
        rotns = DDSplit(aRot).second;
        rot = DDRotation(DDName(rotstr, rotns));

        xpos = -0.5 * fullHeight * sin(detTilt);
        zpos = 0.5 * kaptonHeight - bbl2;

        // Subtraction Solid
        solid = DDSolidFactory::subtraction(DDName(DDSplit(kaptonName[k]).first, DDSplit(kaptonName[k]).second),
                                            solidUncut,
                                            solidCut,
                                            DDTranslation(xpos, 0.0, zpos),
                                            rot);
      } else {
        solid = DDSolidFactory::trap(DDName(DDSplit(kaptonName[k]).first, DDSplit(kaptonName[k]).second),
                                     dz,
                                     0,
                                     0,
                                     h1,
                                     bbl1,
                                     bbl1,
                                     0,
                                     h1,
                                     bbl2,
                                     bbl2,
                                     0);
      }

      DDLogicalPart kapton(solid.ddname(), matter, solid);
      LogDebug("TIDGeom") << "DDTIDModuleAlgo test:\t" << solid.name() << " SUBTRACTION SOLID Trap made of "
                          << matter.ddname() << " of dimensions " << dz << ", 0, 0, " << h1 << ", " << bbl1 << ", "
                          << bbl1 << ", 0, " << h1 << ", " << bbl2 << ", " << bbl2 << ", 0";

      // Hole in the kapton below the wafer
      matter = DDMaterial(DDName(DDSplit(genMat).first, DDSplit(genMat).second));
      dz = fullHeight - kaptonOver;
      xpos = 0;
      if (dlHybrid > dlTop) {
        // ring 1, ring 2
        bbl1 = dxbot - kaptonWidth + kaptonOver * (dxtop - dxbot) / fullHeight;
        bbl2 = dxtop - kaptonWidth;
        zpos = 0.5 * (kaptonHeight - kaptonExtraHeight - dz);
        if (k == 1) {
          zpos -= 0.5 * kaptonOver * (1 - cos(detTilt));
          xpos = -0.5 * kaptonOver * sin(detTilt);
        }
      } else {
        // ring 3
        bbl1 = dxbot - kaptonWidth;
        bbl2 = dxtop - kaptonWidth - kaptonOver * (dxtop - dxbot) / fullHeight;
        zpos = -0.5 * (kaptonHeight - kaptonExtraHeight - dz);
      }
      dz /= 2.;
      solid = DDSolidFactory::trap(DDName(DDSplit(holeKaptonName[k]).first, DDSplit(holeKaptonName[k]).second),
                                   dz,
                                   0,
                                   0,
                                   h1,
                                   bbl1,
                                   bbl1,
                                   0,
                                   h1,
                                   bbl2,
                                   bbl2,
                                   0);
      LogDebug("TIDGeom") << "DDTIDModuleAlgo test:\t" << solid.name() << " Trap made of " << matter.ddname()
                          << " of dimensions " << dz << ", 0, 0, " << h1 << ", " << bbl1 << ", " << bbl1 << ", 0, "
                          << h1 << ", " << bbl2 << ", " << bbl2 << ", 0";
      DDLogicalPart holeKapton(solid.ddname(), matter, solid);

      rotstr = DDSplit(holeKaptonRot[k]).first;
      if (rotstr != "NULL") {
        rotns = DDSplit(holeKaptonRot[k]).second;
        rot = DDRotation(DDName(rotstr, rotns));
      } else {
        rot = DDRotation();
      }
      cpv.position(holeKapton, kapton, 1, DDTranslation(xpos, 0.0, zpos), rot);
      LogDebug("TIDGeom") << "DDTIDModuleAlgo test: " << holeKapton.name() << " number 1 positioned in "
                          << kapton.name() << " at (0,0," << zpos << ") with no rotation";

      // Wafer
      matter = DDMaterial(DDName(DDSplit(waferMat).first, DDSplit(waferMat).second));
      if (k == 0 && dlHybrid < dlTop) {
        bl1 = 0.5 * dlTop;
        bl2 = 0.5 * dlBottom;
      } else {
        bl1 = 0.5 * dlBottom;
        bl2 = 0.5 * dlTop;
      }
      h1 = 0.5 * waferThick[k];
      dz = 0.5 * fullHeight;
      solid = DDSolidFactory::trap(
          DDName(DDSplit(waferName[k]).first, DDSplit(waferName[k]).second), dz, 0, 0, h1, bl1, bl1, 0, h1, bl2, bl2, 0);
      LogDebug("TIDGeom") << "DDTIDModuleAlgo test:\t" << solid.name() << " Trap made of " << matter.ddname()
                          << " of dimensions " << dz << ", 0, 0, " << h1 << ", " << bl1 << ", " << bl1 << ", 0, " << h1
                          << ", " << bl2 << ", " << bl2 << ", 0";
      DDLogicalPart wafer(solid.ddname(), matter, solid);

      // Active
      matter = DDMaterial(DDName(DDSplit(activeMat).first, DDSplit(activeMat).second));
      if (k == 0 && dlHybrid < dlTop) {
        bl1 -= sideWidthTop;
        bl2 -= sideWidthBottom;
      } else {
        bl1 -= sideWidthBottom;
        bl2 -= sideWidthTop;
      }
      dz = 0.5 * (waferThick[k] - backplaneThick[k]);  // inactive backplane
      h1 = 0.5 * activeHeight;
      solid = DDSolidFactory::trap(DDName(DDSplit(activeName[k]).first, DDSplit(activeName[k]).second),
                                   dz,
                                   0,
                                   0,
                                   h1,
                                   bl2,
                                   bl1,
                                   0,
                                   h1,
                                   bl2,
                                   bl1,
                                   0);
      LogDebug("TIDGeom") << "DDTIDModuleAlgo test:\t" << solid.name() << " Trap made of " << matter.ddname()
                          << " of dimensions " << dz << ", 0, 0, " << h1 << ", " << bl2 << ", " << bl1 << ", 0, " << h1
                          << ", " << bl2 << ", " << bl1 << ", 0";
      DDLogicalPart active(solid.ddname(), matter, solid);
      rotstr = DDSplit(activeRot).first;
      if (rotstr != "NULL") {
        rotns = DDSplit(activeRot).second;
        rot = DDRotation(DDName(rotstr, rotns));
      } else {
        rot = DDRotation();
      }
      DDTranslation tran(0.0, -0.5 * backplaneThick[k], 0.0);  // from the definition of the wafer local axes
      cpv.position(active, wafer, 1, tran, rot);               // inactive backplane
      LogDebug("TIDGeom") << "DDTIDModuleAlgo test: " << active.name() << " number 1 positioned in " << wafer.name()
                          << " at " << tran << " with " << rot;

      //Pitch Adapter
      matter = DDMaterial(DDName(DDSplit(pitchMat).first, DDSplit(pitchMat).second));
      if (dlHybrid > dlTop) {
        dz = 0.5 * dlTop;
      } else {
        dz = 0.5 * dlBottom;
      }
      if (k == 0) {
        dx = dz;
        dy = 0.5 * pitchThick;
        dz = 0.5 * pitchHeight;
        solid = DDSolidFactory::box(DDName(DDSplit(pitchName[k]).first, DDSplit(pitchName[k]).second), dx, dy, dz);
        LogDebug("TIDGeom") << "DDTIDModuleAlgo test:\t" << solid.name() << " Box made of " << matter.ddname()
                            << " of dimensions"
                            << " " << dx << ", " << dy << ", " << dz;
      } else {
        h1 = 0.5 * pitchThick;
        bl1 = 0.5 * pitchHeight + 0.5 * dz * sin(detTilt);
        bl2 = 0.5 * pitchHeight - 0.5 * dz * sin(detTilt);

        dz -= 0.5 * pitchStereoTol;
        bl1 -= pitchStereoTol;
        bl2 -= pitchStereoTol;

        double thet = atan((bl1 - bl2) / (2. * dz));
        solid = DDSolidFactory::trap(DDName(DDSplit(pitchName[k]).first, DDSplit(pitchName[k]).second),
                                     dz,
                                     thet,
                                     0,
                                     h1,
                                     bl1,
                                     bl1,
                                     0,
                                     h1,
                                     bl2,
                                     bl2,
                                     0);
        LogDebug("TIDGeom") << "DDTIDModuleAlgo test:\t" << solid.name() << " Trap made of " << matter.ddname()
                            << " of "
                            << "dimensions " << dz << ", " << thet / CLHEP::deg << ", 0, " << h1 << ", " << bl1 << ", "
                            << bl1 << ", 0, " << h1 << ", " << bl2 << ", " << bl2 << ", 0";
      }
      DDLogicalPart pa(solid.ddname(), matter, solid);
    }
  }
  LogDebug("TIDGeom") << "<<== End of DDTIDModuleAlgo construction ...";
}

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