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
#include "Geometry/VeryForwardGeometryBuilder/interface/CTPPSGeometryESCommon.h"
#include "Geometry/VeryForwardGeometryBuilder/interface/CTPPSDDDNames.h"

namespace CTPPSGeometryESCommon {

  std::unique_ptr<DetGeomDesc> applyAlignments(const DetGeomDesc& idealDetRoot,
                                               const CTPPSRPAlignmentCorrectionsData* alignments) {
    std::deque<const DetGeomDesc*> bufferIdealGeo;
    bufferIdealGeo.emplace_back(&idealDetRoot);

    std::deque<DetGeomDesc*> bufferAlignedGeo;
    DetGeomDesc* alignedDetRoot = new DetGeomDesc(idealDetRoot, DetGeomDesc::cmWithoutChildren);
    bufferAlignedGeo.emplace_back(alignedDetRoot);

    while (!bufferIdealGeo.empty()) {
      const DetGeomDesc* idealDet = bufferIdealGeo.front();
      DetGeomDesc* alignedDet = bufferAlignedGeo.front();
      bufferIdealGeo.pop_front();
      bufferAlignedGeo.pop_front();

      const std::string name = alignedDet->name();

      // Is it sensor? If yes, apply full sensor alignments
      if (name == DDD_TOTEM_RP_SENSOR_NAME || name == DDD_CTPPS_DIAMONDS_SEGMENT_NAME ||
          name == DDD_CTPPS_UFSD_SEGMENT_NAME || name == DDD_CTPPS_PIXELS_SENSOR_NAME ||
          name == DDD_CTPPS_PIXELS_SENSOR_NAME_2x2 ||
          std::regex_match(name, std::regex(DDD_TOTEM_TIMING_SENSOR_TMPL))) {
        unsigned int plId = alignedDet->geographicalID();

        if (alignments) {
          const auto& ac = alignments->getFullSensorCorrection(plId);
          alignedDet->applyAlignment(ac);
        }
      }

      // Is it RP box? If yes, apply RP alignments
      if (name == DDD_TOTEM_RP_RP_NAME || name == DDD_CTPPS_DIAMONDS_RP_NAME || name == DDD_CTPPS_PIXELS_RP_NAME ||
          name == DDD_TOTEM_TIMING_RP_NAME) {
        unsigned int rpId = alignedDet->geographicalID();

        if (alignments) {
          const auto& ac = alignments->getRPCorrection(rpId);
          alignedDet->applyAlignment(ac);
        }
      }

      // create and add children
      const auto& idealDetChildren = idealDet->components();
      for (unsigned int i = 0; i < idealDetChildren.size(); i++) {
        const DetGeomDesc* idealDetChild = idealDetChildren[i];
        bufferIdealGeo.emplace_back(idealDetChild);

        // create new node with the same information as in idealDetChild and add it as a child of alignedDet
        DetGeomDesc* alignedDetChild = new DetGeomDesc(*idealDetChild, DetGeomDesc::cmWithoutChildren);
        alignedDet->addComponent(alignedDetChild);

        bufferAlignedGeo.emplace_back(alignedDetChild);
      }
    }
    return std::unique_ptr<DetGeomDesc>(alignedDetRoot);
  }

}  // namespace CTPPSGeometryESCommon