Skip to content

Commit

Permalink
Merge pull request #44537 from mmusich/mm_dev_tkal_improv
Browse files Browse the repository at this point in the history
Improvements for `TrackerAlignment_PayloadInspector`: support OT-only comparisons and re-ordered TF{E}PX detid schemas
  • Loading branch information
cmsbuild authored Mar 27, 2024
2 parents 625d0bd + ce441bf commit b657a45
Show file tree
Hide file tree
Showing 2 changed files with 151 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1184,6 +1184,79 @@ namespace AlignmentPI {
} // loop on detids
}

/*--------------------------------------------------------------------*/
inline bool isReorderedTFPXTEPX(const std::vector<AlignTransform>& transforms)
/*--------------------------------------------------------------------*/
{
// Lambda function to extract the disk, blade panel and numbers from rawId
auto extractBladePanel = [](const AlignTransform& transform) {
// Extract blade and panel numbers using bitwise operations
uint32_t rawId = transform.rawId();
int subid = DetId(transform.rawId()).subdetId();
if (subid == 2) {
// Tracker with subdisk hierarchy level (additional hierarchy level wrt original)
// see for parameters: Geometry/TrackerCommonData/data/PhaseII/TFPXTEPXReordered/trackerParameters.xml
//
//<Vector name="Subdetector2" type="numeric" nEntries="12">
// 23, 19, 18, 12, 10, 2, 0x3, 0xF, 0x1, 0x3F, 0x3, 0xFF
//</Vector>

//unsigned int sideStartBit_ = 23;
//unsigned int diskStartBit_ = 19;
//unsigned int subDiskStartBit_ = 18;
//unsigned int bladeStartBit_ = 12;
//unsigned int panelStartBit_ = 10;
//unsigned int moduleStartBit_ = 2;
//unsigned int sideMask_ = 0x3;
//unsigned int diskMask_ = 0xF;
//unsigned int subDiskMask_ = 0x1;
//unsigned int bladeMask_ = 0x3F;
//unsigned int panelMask_ = 0x3;
//unsigned int moduleMask_ = 0xFF;

// Original Tracker
// see for parameters: Geometry/TrackerCommonData/data/PhaseII/trackerParameters.xml
//
//<Vector name="Subdetector2" type="numeric" nEntries="10">
// 23, 18, 12, 10, 2, 0x3, 0xF, 0x3F, 0x3, 0xFF
//</Vector>

//unsigned int sideStartBit_ = 23;
unsigned int diskStartBit_ = 18;
unsigned int bladeStartBit_ = 12;
unsigned int panelStartBit_ = 10;
//unsigned int moduleStartBit_ = 2;
//unsigned int sideMask_ = 0x3;
unsigned int diskMask_ = 0xF;
unsigned int bladeMask_ = 0x3F;
unsigned int panelMask_ = 0x3;
//unsigned int moduleMask_ = 0xFF;

int disk = (rawId >> diskStartBit_) & diskMask_; // Assuming regular trackerParameters.xml
int blade = (rawId >> bladeStartBit_) & bladeMask_; // Assuming regular trackerParameters.xml
int panel = (rawId >> panelStartBit_) & panelMask_; // Assuming regular trackerParameters.xml
return std::make_tuple(disk, blade, panel);
}
return std::make_tuple(-1, -1, -1); // Return (-1, -1, -1) if subdetId is not 2
};

bool foundZeroDisk = false; // Flag to track if a disk with value 0 is found
std::for_each(
transforms.begin(), transforms.end(), [&extractBladePanel, &foundZeroDisk](const AlignTransform& transform) {
auto [disk, blade, panel] = extractBladePanel(transform);
int subid = DetId(transform.rawId()).subdetId();
if (subid == 2) {
if (disk == 0) {
edm::LogInfo("isReorderedTFPXTEPX") << "subid: " << subid << " detid: " << transform.rawId()
<< " disk: " << disk << " blade: " << blade << " panel: " << panel;
foundZeroDisk = true; // Set flag to true if disk value is 0
}
}
});

return foundZeroDisk; // Return true if at least one disk with value 0 is found
}

} // namespace AlignmentPI

#endif
102 changes: 78 additions & 24 deletions CondCore/AlignmentPlugins/plugins/TrackerAlignment_PayloadInspector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ namespace {
// one at a time
//******************************************//

template <int ntags, IOVMultiplicity nIOVs, bool doOnlyPixel>
enum RegionCategory { ALL = 0, INNER = 1, OUTER = 2 };

template <int ntags, IOVMultiplicity nIOVs, RegionCategory cat>
class TrackerAlignmentCompareAll : public PlotImage<Alignments, nIOVs, ntags> {
public:
TrackerAlignmentCompareAll()
Expand Down Expand Up @@ -105,21 +107,54 @@ namespace {
std::vector<AlignTransform> ref_ali = first_payload->m_align;
std::vector<AlignTransform> target_ali = last_payload->m_align;

const bool ph2 = (ref_ali.size() > AlignmentPI::phase1size);

// check that the geomtery is a tracker one
const char *path_toTopologyXML = nullptr;
if (ph2) {
if (AlignmentPI::isReorderedTFPXTEPX(ref_ali) && AlignmentPI::isReorderedTFPXTEPX(target_ali)) {
edm::LogPrint("TrackerAlignment_PayloadInspector")
<< "Both reference and target alignments are reordered. Using the trackerParameters for the Reordered "
"TFPX,TEPX.";
path_toTopologyXML = "Geometry/TrackerCommonData/data/PhaseII/TFPXTEPXReordered/trackerParameters.xml";
} else if (!AlignmentPI::isReorderedTFPXTEPX(ref_ali) && !AlignmentPI::isReorderedTFPXTEPX(target_ali)) {
edm::LogPrint("TrackerAlignment_PayloadInspector")
<< "Neither reference nor target alignments are reordered. Using the standard trackerParameters.";
path_toTopologyXML = "Geometry/TrackerCommonData/data/PhaseII/trackerParameters.xml";
} else {
if (cat == RegionCategory::ALL || cat == RegionCategory::INNER) {
// Emit warning and exit false if alignments are mismatched
edm::LogWarning("TrackerAlignment_PayloadInspector")
<< "Mismatched alignments detected. One is reordered while the other is not. Unable to proceed.";
return false;
} else {
edm::LogWarning("TrackerAlignment_PayloadInspector")
<< "Mismatched inner tracks alignments detected. One is reordered while the other is not. Ignoring as "
"OT only comparison requested.";
path_toTopologyXML = "Geometry/TrackerCommonData/data/PhaseII/trackerParameters.xml";
}
}
} else {
path_toTopologyXML = (ref_ali.size() == AlignmentPI::phase0size)
? "Geometry/TrackerCommonData/data/trackerParameters.xml"
: "Geometry/TrackerCommonData/data/PhaseI/trackerParameters.xml";
}

// Use remove_if along with a lambda expression to remove elements based on the condition (subid > 2)
if (doOnlyPixel) {
if (cat != RegionCategory::ALL) {
ref_ali.erase(std::remove_if(ref_ali.begin(),
ref_ali.end(),
[](const AlignTransform &transform) {
int subid = DetId(transform.rawId()).subdetId();
return subid > 2;
return (cat == RegionCategory::INNER) ? (subid > 2) : (subid <= 2);
}),
ref_ali.end());

target_ali.erase(std::remove_if(target_ali.begin(),
target_ali.end(),
[](const AlignTransform &transform) {
int subid = DetId(transform.rawId()).subdetId();
return subid > 2;
return (cat == RegionCategory::INNER) ? (subid > 2) : (subid <= 2);
}),
target_ali.end());
}
Expand All @@ -134,18 +169,6 @@ namespace {
return false;
}

const bool ph2 = (ref_ali.size() > AlignmentPI::phase1size);

// check that the geomtery is a tracker one
const char *path_toTopologyXML = nullptr;
if (ph2) {
path_toTopologyXML = "Geometry/TrackerCommonData/data/PhaseII/trackerParameters.xml";
} else {
path_toTopologyXML = (ref_ali.size() == AlignmentPI::phase0size)
? "Geometry/TrackerCommonData/data/trackerParameters.xml"
: "Geometry/TrackerCommonData/data/PhaseI/trackerParameters.xml";
}

TrackerTopology tTopo =
StandaloneTrackerTopology::fromTrackerParametersXMLFile(edm::FileInPath(path_toTopologyXML).fullPath());

Expand Down Expand Up @@ -184,7 +207,9 @@ namespace {

// fill all the histograms together
std::map<int, AlignmentPI::partitions> boundaries;
boundaries.insert({0, AlignmentPI::BPix}); // always start with BPix, not filled in the loop
if (cat < RegionCategory::OUTER) {
boundaries.insert({0, AlignmentPI::BPix}); // always start with BPix, not filled in the loop
}
AlignmentPI::fillComparisonHistograms(boundaries, ref_ali, target_ali, diffs);

unsigned int subpad{1};
Expand Down Expand Up @@ -232,6 +257,8 @@ namespace {
canvas.cd();
canvas.Modified();

bool doOnlyPixel = (cat == RegionCategory::INNER);

TLine l[6][boundaries.size()];
TLatex tSubdet[6];
for (unsigned int i = 0; i < 6; i++) {
Expand Down Expand Up @@ -292,11 +319,14 @@ namespace {
}
};

typedef TrackerAlignmentCompareAll<1, MULTI_IOV, false> TrackerAlignmentComparatorSingleTag;
typedef TrackerAlignmentCompareAll<2, SINGLE_IOV, false> TrackerAlignmentComparatorTwoTags;
typedef TrackerAlignmentCompareAll<1, MULTI_IOV, RegionCategory::ALL> TrackerAlignmentComparatorSingleTag;
typedef TrackerAlignmentCompareAll<2, SINGLE_IOV, RegionCategory::ALL> TrackerAlignmentComparatorTwoTags;

typedef TrackerAlignmentCompareAll<1, MULTI_IOV, true> PixelAlignmentComparatorSingleTag;
typedef TrackerAlignmentCompareAll<2, SINGLE_IOV, true> PixelAlignmentComparatorTwoTags;
typedef TrackerAlignmentCompareAll<1, MULTI_IOV, RegionCategory::INNER> PixelAlignmentComparatorSingleTag;
typedef TrackerAlignmentCompareAll<2, SINGLE_IOV, RegionCategory::INNER> PixelAlignmentComparatorTwoTags;

typedef TrackerAlignmentCompareAll<1, MULTI_IOV, RegionCategory::OUTER> OTAlignmentComparatorSingleTag;
typedef TrackerAlignmentCompareAll<2, SINGLE_IOV, RegionCategory::OUTER> OTAlignmentComparatorTwoTags;

//*******************************************//
// Size of the movement over all partitions,
Expand Down Expand Up @@ -350,10 +380,32 @@ namespace {
return false;
}

const bool ph2 = (ref_ali.size() > AlignmentPI::phase1size);

// check that the geomtery is a tracker one
const char *path_toTopologyXML = (ref_ali.size() == AlignmentPI::phase0size)
? "Geometry/TrackerCommonData/data/trackerParameters.xml"
: "Geometry/TrackerCommonData/data/PhaseI/trackerParameters.xml";
const char *path_toTopologyXML = nullptr;
if (ph2) {
if (AlignmentPI::isReorderedTFPXTEPX(ref_ali) && AlignmentPI::isReorderedTFPXTEPX(target_ali)) {
edm::LogPrint("TrackerAlignment_PayloadInspector")
<< "Both reference and target alignments are reordered. Using the trackerParameters for the Reordered "
"TFPX,TEPX.";
path_toTopologyXML = "Geometry/TrackerCommonData/data/PhaseII/TFPXTEPXReordered/trackerParameters.xml";
} else if (!AlignmentPI::isReorderedTFPXTEPX(ref_ali) && !AlignmentPI::isReorderedTFPXTEPX(target_ali)) {
edm::LogPrint("TrackerAlignment_PayloadInspector")
<< "Neither reference nor target alignments are reordered. Using the standard trackerParameters.";
path_toTopologyXML = "Geometry/TrackerCommonData/data/PhaseII/trackerParameters.xml";
} else {
// Emit warning and exit false if alignments are mismatched
edm::LogWarning("TrackerAlignment_PayloadInspector")
<< "Mismatched alignments detected. One is reordered while the other is not. Unable to proceed.";
return false;
}
} else {
path_toTopologyXML = (ref_ali.size() == AlignmentPI::phase0size)
? "Geometry/TrackerCommonData/data/trackerParameters.xml"
: "Geometry/TrackerCommonData/data/PhaseI/trackerParameters.xml";
}

TrackerTopology tTopo =
StandaloneTrackerTopology::fromTrackerParametersXMLFile(edm::FileInPath(path_toTopologyXML).fullPath());

Expand Down Expand Up @@ -1422,6 +1474,8 @@ namespace {
PAYLOAD_INSPECTOR_MODULE(TrackerAlignment) {
PAYLOAD_INSPECTOR_CLASS(PixelAlignmentComparatorSingleTag);
PAYLOAD_INSPECTOR_CLASS(PixelAlignmentComparatorTwoTags);
PAYLOAD_INSPECTOR_CLASS(OTAlignmentComparatorSingleTag);
PAYLOAD_INSPECTOR_CLASS(OTAlignmentComparatorTwoTags);
PAYLOAD_INSPECTOR_CLASS(TrackerAlignmentComparatorSingleTag);
PAYLOAD_INSPECTOR_CLASS(TrackerAlignmentComparatorTwoTags);
PAYLOAD_INSPECTOR_CLASS(TrackerAlignmentCompareX);
Expand Down

0 comments on commit b657a45

Please sign in to comment.