Skip to content

Commit 5ceaea1

Browse files
committed
add Pixel Alignment Map of BPix, FPix coordinate differences
1 parent 639c551 commit 5ceaea1

File tree

1 file changed

+300
-0
lines changed

1 file changed

+300
-0
lines changed

CondCore/AlignmentPlugins/plugins/TrackerAlignment_PayloadInspector.cc

Lines changed: 300 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "CalibTracker/StandaloneTrackerTopology/interface/StandaloneTrackerTopology.h"
3030
#include "CalibTracker/SiPixelESProducers/interface/SiPixelDetInfoFileReader.h"
3131
#include "DQM/TrackerRemapper/interface/Phase1PixelSummaryMap.h"
32+
#include "DQM/TrackerRemapper/interface/Phase1PixelMaps.h"
3233

3334
#include <boost/range/adaptor/indexed.hpp>
3435
#include <iomanip> // std::setprecision
@@ -1170,6 +1171,281 @@ namespace {
11701171
typedef PixelAlignmentCompareMapTwoTags<AlignmentPI::rot_beta> PixelAlignmentCompareMapBetaTwoTags;
11711172
typedef PixelAlignmentCompareMapTwoTags<AlignmentPI::rot_gamma> PixelAlignmentCompareMapGammaTwoTags;
11721173

1174+
/************************************************
1175+
Pixel Tracker Map Comparison of coordinates
1176+
*************************************************/
1177+
template <AlignmentPI::partitions myType, AlignmentPI::coordinate coord, int ntags, IOVMultiplicity nIOVs>
1178+
class PixelAlignmentCompareMapsBase : public PlotImage<Alignments, nIOVs, ntags> {
1179+
public:
1180+
PixelAlignmentCompareMapsBase()
1181+
: PlotImage<Alignments, nIOVs, ntags>("SiPixel Comparison Map of " +
1182+
AlignmentPI::getStringFromCoordinate(coord)) {
1183+
label_ = "PixelAlignmentComparisonMap" + AlignmentPI::getStringFromCoordinate(coord);
1184+
payloadString = "Tracker Alignment";
1185+
}
1186+
1187+
bool fill() override {
1188+
gStyle->SetPalette(1);
1189+
1190+
// trick to deal with the multi-ioved tag and two tag case at the same time
1191+
auto theIOVs = PlotBase::getTag<0>().iovs;
1192+
auto tagname1 = PlotBase::getTag<0>().name;
1193+
std::string tagname2 = "";
1194+
auto firstiov = theIOVs.front();
1195+
std::tuple<cond::Time_t, cond::Hash> lastiov;
1196+
1197+
// we don't support (yet) comparison with more than 2 tags
1198+
assert(this->m_plotAnnotations.ntags < 3);
1199+
1200+
if (this->m_plotAnnotations.ntags == 2) {
1201+
auto tag2iovs = PlotBase::getTag<1>().iovs;
1202+
tagname2 = PlotBase::getTag<1>().name;
1203+
lastiov = tag2iovs.front();
1204+
} else {
1205+
lastiov = theIOVs.back();
1206+
}
1207+
1208+
std::shared_ptr<Alignments> last_payload = this->fetchPayload(std::get<1>(lastiov));
1209+
std::shared_ptr<Alignments> first_payload = this->fetchPayload(std::get<1>(firstiov));
1210+
1211+
std::string lastIOVsince = std::to_string(std::get<0>(lastiov));
1212+
std::string firstIOVsince = std::to_string(std::get<0>(firstiov));
1213+
1214+
const std::vector<AlignTransform> &ref_ali = first_payload->m_align;
1215+
const std::vector<AlignTransform> &target_ali = last_payload->m_align;
1216+
1217+
if (last_payload.get() && first_payload.get()) {
1218+
// Book the TH2Poly
1219+
Phase1PixelMaps theMaps("");
1220+
if (myType == AlignmentPI::INVALID) {
1221+
theMaps.resetOption("COLZA L");
1222+
} else {
1223+
theMaps.resetOption("COLZL");
1224+
}
1225+
1226+
std::string coordinateStr = AlignmentPI::getStringFromCoordinate(coord);
1227+
std::string unit = (coord <= 3) ? "#mum" : "mrad";
1228+
std::string what = fmt::sprintf("%s %s", payloadString, coordinateStr);
1229+
std::string zaxis = fmt::sprintf("#Delta %s [%s]", coordinateStr, unit);
1230+
1231+
if (myType == AlignmentPI::BPix) {
1232+
theMaps.bookBarrelHistograms("AlignmentBarrel", what.c_str(), zaxis.c_str());
1233+
} else if (myType == AlignmentPI::FPix) {
1234+
theMaps.bookForwardHistograms("AlignmentForward", what.c_str(), zaxis.c_str());
1235+
} else if (myType == AlignmentPI::INVALID) {
1236+
theMaps.bookBarrelHistograms("Alignment", what.c_str(), zaxis.c_str());
1237+
theMaps.bookForwardHistograms("Alignment", what.c_str(), zaxis.c_str());
1238+
} else {
1239+
edm::LogError("SiPixelTemplateDBObject_PayloadInspector")
1240+
<< " un-recognized detector type " << myType << std::endl;
1241+
return false;
1242+
}
1243+
1244+
if (this->isPhase0(ref_ali) || this->isPhase0(target_ali)) {
1245+
edm::LogError(label_) << "Pixel Tracker Alignment maps are not supported for non-Phase1 Pixel geometries !";
1246+
TCanvas canvas("Canv", "Canv", 1200, 1000);
1247+
AlignmentPI::displayNotSupported(canvas, 0);
1248+
std::string fileName(this->m_imageFileName);
1249+
canvas.SaveAs(fileName.c_str());
1250+
return false;
1251+
}
1252+
1253+
// fill the map of differences
1254+
std::map<uint32_t, double> diffPerDetid;
1255+
this->fillPerDetIdDiff(coord, ref_ali, target_ali, diffPerDetid);
1256+
1257+
// now fill the tracker map
1258+
for (const auto &elem : diffPerDetid) {
1259+
// reject Strips
1260+
int subid = DetId(elem.first).subdetId();
1261+
if (subid > 2) {
1262+
continue;
1263+
}
1264+
1265+
if (myType == AlignmentPI::INVALID) {
1266+
if ((subid == PixelSubdetector::PixelBarrel)) {
1267+
theMaps.fillBarrelBin("Alignment", elem.first, elem.second);
1268+
}
1269+
if ((subid == PixelSubdetector::PixelEndcap)) {
1270+
theMaps.fillForwardBin("Alignment", elem.first, elem.second);
1271+
}
1272+
} else if ((subid == PixelSubdetector::PixelBarrel) && (myType == AlignmentPI::BPix)) {
1273+
theMaps.fillBarrelBin("AlignmentBarrel", elem.first, elem.second);
1274+
} else if ((subid == PixelSubdetector::PixelEndcap) && (myType == AlignmentPI::FPix)) {
1275+
theMaps.fillForwardBin("AlignmentForward", elem.first, elem.second);
1276+
}
1277+
}
1278+
1279+
theMaps.beautifyAllHistograms();
1280+
1281+
TCanvas canvas("Canv", "Canv", (myType == AlignmentPI::BPix) ? 1200 : 1600, 1000);
1282+
if (myType == AlignmentPI::BPix) {
1283+
theMaps.drawBarrelMaps("AlignmentBarrel", canvas);
1284+
} else if (myType == AlignmentPI::FPix) {
1285+
theMaps.drawForwardMaps("AlignmentForward", canvas);
1286+
} else if (myType == AlignmentPI::INVALID) {
1287+
theMaps.drawSummaryMaps("Alignment", canvas);
1288+
}
1289+
1290+
canvas.cd();
1291+
TPaveText ksPt(0, 0, 0.88, 0.04, "NDC");
1292+
ksPt.SetBorderSize(0);
1293+
ksPt.SetFillColor(0);
1294+
1295+
std::string textToAdd = "#color[4]{" + tagname1 + "}, IOV: #color[4]{" + firstIOVsince + "} vs #color[4]{" +
1296+
tagname2 + "}, IOV: #color[4]{" + lastIOVsince + "}";
1297+
1298+
ksPt.AddText(textToAdd.c_str());
1299+
ksPt.Draw();
1300+
1301+
canvas.cd();
1302+
std::string fileName(this->m_imageFileName);
1303+
canvas.SaveAs(fileName.c_str());
1304+
}
1305+
return true;
1306+
}
1307+
1308+
protected:
1309+
std::string payloadString;
1310+
std::string label_;
1311+
1312+
private:
1313+
//_________________________________________________
1314+
bool isPhase0(std::vector<AlignTransform> theAlis) {
1315+
SiPixelDetInfoFileReader reader =
1316+
SiPixelDetInfoFileReader(edm::FileInPath(SiPixelDetInfoFileReader::kPh0DefaultFile).fullPath());
1317+
const auto &p0detIds = reader.getAllDetIds();
1318+
1319+
std::vector<uint32_t> ownDetIds;
1320+
std::transform(theAlis.begin(), theAlis.end(), std::back_inserter(ownDetIds), [](AlignTransform ali) -> uint32_t {
1321+
return ali.rawId();
1322+
});
1323+
1324+
for (const auto &det : ownDetIds) {
1325+
// if found at least one phase-0 detId early return
1326+
if (std::find(p0detIds.begin(), p0detIds.end(), det) != p0detIds.end()) {
1327+
return true;
1328+
}
1329+
}
1330+
return false;
1331+
}
1332+
1333+
/*--------------------------------------------------------------------*/
1334+
void fillPerDetIdDiff(const AlignmentPI::coordinate &myCoord,
1335+
const std::vector<AlignTransform> &ref_ali,
1336+
const std::vector<AlignTransform> &target_ali,
1337+
std::map<uint32_t, double> &diff)
1338+
/*--------------------------------------------------------------------*/
1339+
{
1340+
for (unsigned int i = 0; i < ref_ali.size(); i++) {
1341+
uint32_t detid = ref_ali[i].rawId();
1342+
if (ref_ali[i].rawId() == target_ali[i].rawId()) {
1343+
CLHEP::HepRotation target_rot(target_ali[i].rotation());
1344+
CLHEP::HepRotation ref_rot(ref_ali[i].rotation());
1345+
1346+
align::RotationType target_ROT(target_rot.xx(),
1347+
target_rot.xy(),
1348+
target_rot.xz(),
1349+
target_rot.yx(),
1350+
target_rot.yy(),
1351+
target_rot.yz(),
1352+
target_rot.zx(),
1353+
target_rot.zy(),
1354+
target_rot.zz());
1355+
1356+
align::RotationType ref_ROT(ref_rot.xx(),
1357+
ref_rot.xy(),
1358+
ref_rot.xz(),
1359+
ref_rot.yx(),
1360+
ref_rot.yy(),
1361+
ref_rot.yz(),
1362+
ref_rot.zx(),
1363+
ref_rot.zy(),
1364+
ref_rot.zz());
1365+
1366+
const std::vector<double> deltaRot = {
1367+
::deltaPhi(align::toAngles(target_ROT)[0], align::toAngles(ref_ROT)[0]),
1368+
::deltaPhi(align::toAngles(target_ROT)[1], align::toAngles(ref_ROT)[1]),
1369+
::deltaPhi(align::toAngles(target_ROT)[2], align::toAngles(ref_ROT)[2])};
1370+
1371+
const auto &deltaTrans = target_ali[i].translation() - ref_ali[i].translation();
1372+
1373+
switch (myCoord) {
1374+
case AlignmentPI::t_x:
1375+
diff.insert({detid, deltaTrans.x() * AlignmentPI::cmToUm});
1376+
break;
1377+
case AlignmentPI::t_y:
1378+
diff.insert({detid, deltaTrans.y() * AlignmentPI::cmToUm});
1379+
break;
1380+
case AlignmentPI::t_z:
1381+
diff.insert({detid, deltaTrans.z() * AlignmentPI::cmToUm});
1382+
break;
1383+
case AlignmentPI::rot_alpha:
1384+
diff.insert({detid, deltaRot[0] * AlignmentPI::tomRad});
1385+
break;
1386+
case AlignmentPI::rot_beta:
1387+
diff.insert({detid, deltaRot[1] * AlignmentPI::tomRad});
1388+
break;
1389+
case AlignmentPI::rot_gamma:
1390+
diff.insert({detid, deltaRot[2] * AlignmentPI::tomRad});
1391+
break;
1392+
default:
1393+
edm::LogError("TrackerAlignment_PayloadInspector") << "Unrecognized coordinate " << myCoord << std::endl;
1394+
break;
1395+
} // switch on the coordinate
1396+
} // check on the same detID
1397+
} // loop on the components
1398+
}
1399+
};
1400+
1401+
// template implementations for Barrel Pixel
1402+
1403+
template <AlignmentPI::coordinate coord>
1404+
using BPixAlignmentCompareMap = PixelAlignmentCompareMapsBase<AlignmentPI::BPix, coord, 1, MULTI_IOV>;
1405+
1406+
template <AlignmentPI::coordinate coord>
1407+
using BPixAlignmentCompareMapTwoTags = PixelAlignmentCompareMapsBase<AlignmentPI::BPix, coord, 2, SINGLE_IOV>;
1408+
1409+
typedef BPixAlignmentCompareMap<AlignmentPI::t_x> BPixAlignmentCompareMapX;
1410+
typedef BPixAlignmentCompareMap<AlignmentPI::t_y> BPixAlignmentCompareMapY;
1411+
typedef BPixAlignmentCompareMap<AlignmentPI::t_z> BPixAlignmentCompareMapZ;
1412+
1413+
typedef BPixAlignmentCompareMap<AlignmentPI::rot_alpha> BPixAlignmentCompareMapAlpha;
1414+
typedef BPixAlignmentCompareMap<AlignmentPI::rot_beta> BPixAlignmentCompareMapBeta;
1415+
typedef BPixAlignmentCompareMap<AlignmentPI::rot_gamma> BPixAlignmentCompareMapGamma;
1416+
1417+
typedef BPixAlignmentCompareMapTwoTags<AlignmentPI::t_x> BPixAlignmentCompareMapXTwoTags;
1418+
typedef BPixAlignmentCompareMapTwoTags<AlignmentPI::t_y> BPixAlignmentCompareMapYTwoTags;
1419+
typedef BPixAlignmentCompareMapTwoTags<AlignmentPI::t_z> BPixAlignmentCompareMapZTwoTags;
1420+
1421+
typedef BPixAlignmentCompareMapTwoTags<AlignmentPI::rot_alpha> BPixAlignmentCompareMapAlphaTwoTags;
1422+
typedef BPixAlignmentCompareMapTwoTags<AlignmentPI::rot_beta> BPixAlignmentCompareMapBetaTwoTags;
1423+
typedef BPixAlignmentCompareMapTwoTags<AlignmentPI::rot_gamma> BPixAlignmentCompareMapGammaTwoTags;
1424+
1425+
// template implementations for Forward Pixel
1426+
1427+
template <AlignmentPI::coordinate coord>
1428+
using FPixAlignmentCompareMap = PixelAlignmentCompareMapsBase<AlignmentPI::FPix, coord, 1, MULTI_IOV>;
1429+
1430+
template <AlignmentPI::coordinate coord>
1431+
using FPixAlignmentCompareMapTwoTags = PixelAlignmentCompareMapsBase<AlignmentPI::FPix, coord, 2, SINGLE_IOV>;
1432+
1433+
typedef FPixAlignmentCompareMap<AlignmentPI::t_x> FPixAlignmentCompareMapX;
1434+
typedef FPixAlignmentCompareMap<AlignmentPI::t_y> FPixAlignmentCompareMapY;
1435+
typedef FPixAlignmentCompareMap<AlignmentPI::t_z> FPixAlignmentCompareMapZ;
1436+
1437+
typedef FPixAlignmentCompareMap<AlignmentPI::rot_alpha> FPixAlignmentCompareMapAlpha;
1438+
typedef FPixAlignmentCompareMap<AlignmentPI::rot_beta> FPixAlignmentCompareMapBeta;
1439+
typedef FPixAlignmentCompareMap<AlignmentPI::rot_gamma> FPixAlignmentCompareMapGamma;
1440+
1441+
typedef FPixAlignmentCompareMapTwoTags<AlignmentPI::t_x> FPixAlignmentCompareMapXTwoTags;
1442+
typedef FPixAlignmentCompareMapTwoTags<AlignmentPI::t_y> FPixAlignmentCompareMapYTwoTags;
1443+
typedef FPixAlignmentCompareMapTwoTags<AlignmentPI::t_z> FPixAlignmentCompareMapZTwoTags;
1444+
1445+
typedef FPixAlignmentCompareMapTwoTags<AlignmentPI::rot_alpha> FPixAlignmentCompareMapAlphaTwoTags;
1446+
typedef FPixAlignmentCompareMapTwoTags<AlignmentPI::rot_beta> FPixAlignmentCompareMapBetaTwoTags;
1447+
typedef FPixAlignmentCompareMapTwoTags<AlignmentPI::rot_gamma> FPixAlignmentCompareMapGammaTwoTags;
1448+
11731449
//*******************************************//
11741450
// History of the position of the BPix Barycenter
11751451
//******************************************//
@@ -1766,6 +2042,30 @@ PAYLOAD_INSPECTOR_MODULE(TrackerAlignment) {
17662042
PAYLOAD_INSPECTOR_CLASS(PixelAlignmentCompareMapAlphaTwoTags);
17672043
PAYLOAD_INSPECTOR_CLASS(PixelAlignmentCompareMapBetaTwoTags);
17682044
PAYLOAD_INSPECTOR_CLASS(PixelAlignmentCompareMapGammaTwoTags);
2045+
PAYLOAD_INSPECTOR_CLASS(BPixAlignmentCompareMapX);
2046+
PAYLOAD_INSPECTOR_CLASS(BPixAlignmentCompareMapY);
2047+
PAYLOAD_INSPECTOR_CLASS(BPixAlignmentCompareMapZ);
2048+
PAYLOAD_INSPECTOR_CLASS(BPixAlignmentCompareMapAlpha);
2049+
PAYLOAD_INSPECTOR_CLASS(BPixAlignmentCompareMapBeta);
2050+
PAYLOAD_INSPECTOR_CLASS(BPixAlignmentCompareMapGamma);
2051+
PAYLOAD_INSPECTOR_CLASS(BPixAlignmentCompareMapXTwoTags);
2052+
PAYLOAD_INSPECTOR_CLASS(BPixAlignmentCompareMapYTwoTags);
2053+
PAYLOAD_INSPECTOR_CLASS(BPixAlignmentCompareMapZTwoTags);
2054+
PAYLOAD_INSPECTOR_CLASS(BPixAlignmentCompareMapAlphaTwoTags);
2055+
PAYLOAD_INSPECTOR_CLASS(BPixAlignmentCompareMapBetaTwoTags);
2056+
PAYLOAD_INSPECTOR_CLASS(BPixAlignmentCompareMapGammaTwoTags);
2057+
PAYLOAD_INSPECTOR_CLASS(FPixAlignmentCompareMapX);
2058+
PAYLOAD_INSPECTOR_CLASS(FPixAlignmentCompareMapY);
2059+
PAYLOAD_INSPECTOR_CLASS(FPixAlignmentCompareMapZ);
2060+
PAYLOAD_INSPECTOR_CLASS(FPixAlignmentCompareMapAlpha);
2061+
PAYLOAD_INSPECTOR_CLASS(FPixAlignmentCompareMapBeta);
2062+
PAYLOAD_INSPECTOR_CLASS(FPixAlignmentCompareMapGamma);
2063+
PAYLOAD_INSPECTOR_CLASS(FPixAlignmentCompareMapXTwoTags);
2064+
PAYLOAD_INSPECTOR_CLASS(FPixAlignmentCompareMapYTwoTags);
2065+
PAYLOAD_INSPECTOR_CLASS(FPixAlignmentCompareMapZTwoTags);
2066+
PAYLOAD_INSPECTOR_CLASS(FPixAlignmentCompareMapAlphaTwoTags);
2067+
PAYLOAD_INSPECTOR_CLASS(FPixAlignmentCompareMapBetaTwoTags);
2068+
PAYLOAD_INSPECTOR_CLASS(FPixAlignmentCompareMapGammaTwoTags);
17692069
PAYLOAD_INSPECTOR_CLASS(TrackerAlignmentSummaryBPix);
17702070
PAYLOAD_INSPECTOR_CLASS(TrackerAlignmentSummaryFPix);
17712071
PAYLOAD_INSPECTOR_CLASS(TrackerAlignmentSummaryTIB);

0 commit comments

Comments
 (0)