@@ -1174,232 +1174,149 @@ namespace {
11741174 /* ***********************************************
11751175 Pixel Tracker Map Comparison of coordinates
11761176 *************************************************/
1177- template <AlignmentPI::partitions myType , AlignmentPI::coordinate coord , int ntags , IOVMultiplicity nIOVs >
1178- class PixelAlignmentCompareMapsBase : public PlotImage <Alignments, nIOVs, ntags > {
1177+ template <AlignmentPI::partitions P , AlignmentPI::coordinate C , int NTAGS , IOVMultiplicity NIOVs >
1178+ class PixelAlignmentCompareMapsBase : public PlotImage <Alignments, NIOVs, NTAGS > {
11791179 public:
11801180 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- }
1181+ : PlotImage<Alignments, NIOVs, NTAGS>(" SiPixel Comparison Map of " + AlignmentPI::getStringFromCoordinate(C)),
1182+ label_ (" PixelAlignmentComparisonMap" + AlignmentPI::getStringFromCoordinate(C)),
1183+ payloadStr_(" Tracker Alignment" ) {}
11861184
11871185 bool fill () override {
11881186 gStyle ->SetPalette (1 );
11891187
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;
1188+ const auto &iovs = PlotBase::getTag<0 >().iovs ;
1189+ const auto &tag1 = PlotBase::getTag<0 >().name ;
1190+ const auto &[since1, hash1] = iovs.front ();
1191+ auto [since2, hash2] = (NTAGS == 2 ) ? PlotBase::getTag<1 >().iovs .front () : iovs.back ();
1192+ const auto &tag2 = (NTAGS == 2 ) ? PlotBase::getTag<1 >().name : tag1;
11961193
1197- // we don't support (yet) comparison with more than 2 tags
1198- assert (this ->m_plotAnnotations .ntags < 3 );
1194+ auto ref = this ->fetchPayload (hash1);
1195+ auto tgt = this ->fetchPayload (hash2);
1196+ if (!ref || !tgt)
1197+ return false ;
11991198
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 () ;
1199+ const auto &refAli = ref-> m_align , tgtAli = tgt-> m_align ;
1200+ if ( isPhase0 (refAli) || isPhase0 (tgtAli)) {
1201+ edm::LogError (label_) << " Not supported for non-Phase1 geometries. " ;
1202+ TCanvas canv ( " Canv " , " Canv " , 1200 , 1000 );
1203+ AlignmentPI::displayNotSupported (canv, 0 );
1204+ return false ;
12061205 }
12071206
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) );
1207+ Phase1PixelMaps maps ( " " );
1208+ maps. resetOption (P == AlignmentPI::INVALID ? " COLZA L " : " COLZL " );
12101209
1211- std::string lastIOVsince = std::to_string (std::get<0 >(lastiov));
1212- std::string firstIOVsince = std::to_string (std::get<0 >(firstiov));
1210+ std::string coordStr = AlignmentPI::getStringFromCoordinate (C);
1211+ std::string unit = (C <= 3 ) ? " #mum" : " mrad" ;
1212+ std::string label = fmt::sprintf (" #Delta %s [%s]" , coordStr, unit);
12131213
1214- const std::vector<AlignTransform> &ref_ali = first_payload->m_align ;
1215- const std::vector<AlignTransform> &target_ali = last_payload->m_align ;
1214+ std::string histoLabel = (P == AlignmentPI::BPix) ? " AlignmentBarrel"
1215+ : (P == AlignmentPI::FPix) ? " AlignmentForward"
1216+ : " Alignment" ;
12161217
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- }
1218+ if (P != AlignmentPI::FPix)
1219+ maps.bookBarrelHistograms (histoLabel, (payloadStr_ + " " + coordStr).c_str (), label.c_str ());
1220+ if (P != AlignmentPI::BPix)
1221+ maps.bookForwardHistograms (histoLabel, (payloadStr_ + " " + coordStr).c_str (), label.c_str ());
12251222
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- }
1223+ std::map<uint32_t , double > diff;
1224+ fillDiffs (refAli, tgtAli, diff);
12431225
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 );
1226+ for (const auto &[id, val] : diff) {
1227+ int subid = DetId (id).subdetId ();
1228+ if (subid > 2 )
1229+ continue ;
1230+ if (P == AlignmentPI::INVALID || (P == AlignmentPI::BPix && subid == 1 ))
1231+ maps.fillBarrelBin (histoLabel, id, val);
1232+ if (P == AlignmentPI::INVALID || (P == AlignmentPI::FPix && subid == 2 ))
1233+ maps.fillForwardBin (histoLabel, id, val);
1234+ }
12941235
1295- std::string textToAdd = " #color[4]{" + tagname1 + " }, IOV: #color[4]{" + firstIOVsince + " } vs #color[4]{" +
1296- tagname2 + " }, IOV: #color[4]{" + lastIOVsince + " }" ;
1236+ maps.beautifyAllHistograms ();
12971237
1298- ksPt.AddText (textToAdd.c_str ());
1299- ksPt.Draw ();
1238+ TCanvas canvas (" Canv" , " Canv" , (P == AlignmentPI::BPix ? 1200 : 1600 ), 1000 );
1239+ if (P == AlignmentPI::BPix)
1240+ maps.drawBarrelMaps (histoLabel, canvas);
1241+ else if (P == AlignmentPI::FPix)
1242+ maps.drawForwardMaps (histoLabel, canvas);
1243+ else
1244+ maps.drawSummaryMaps (histoLabel, canvas);
13001245
1301- canvas.cd ();
1302- std::string fileName (this ->m_imageFileName );
1303- canvas.SaveAs (fileName.c_str ());
1304- }
1246+ // come back to the main pad
1247+ canvas.cd ();
1248+ TPaveText text (0 , 0 , 0.88 , 0.04 , " NDC" );
1249+ text.SetBorderSize (0 );
1250+ text.SetFillColor (0 );
1251+ text.AddText (
1252+ fmt::sprintf (
1253+ " #color[4]{%s}, IOV: #color[4]{%lu} vs #color[4]{%s}, IOV: #color[4]{%lu}" , tag1, since1, tag2, since2)
1254+ .c_str ());
1255+ text.Draw ();
1256+
1257+ canvas.SaveAs (this ->m_imageFileName .c_str ());
13051258 return true ;
13061259 }
13071260
13081261 protected:
1309- std::string payloadString;
1310- std::string label_;
1262+ std::string label_, payloadStr_;
13111263
13121264 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 ();
1265+ bool isPhase0 (const std::vector<AlignTransform> &alis) const {
1266+ static const auto phase0 =
1267+ SiPixelDetInfoFileReader (edm::FileInPath (SiPixelDetInfoFileReader::kPh0DefaultFile ).fullPath ()).getAllDetIds ();
1268+ return std::any_of (alis.begin (), alis.end (), [&](const auto &a) {
1269+ return std::find (phase0.begin (), phase0.end (), a.rawId ()) != phase0.end ();
13221270 });
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 ;
13311271 }
13321272
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 ());
1273+ void fillDiffs (const std::vector<AlignTransform> &ref,
1274+ const std::vector<AlignTransform> &tgt,
1275+ std::map<uint32_t , double > &diff) const {
1276+ for (size_t i = 0 ; i < ref.size (); ++i) {
1277+ if (ref[i].rawId () != tgt[i].rawId ())
1278+ continue ;
1279+ auto id = ref[i].rawId ();
1280+ auto dt = tgt[i].translation () - ref[i].translation ();
13451281
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 ());
1282+ CLHEP::HepRotation dr = tgt[i].rotation ();
1283+ CLHEP::HepRotation rr = ref[i].rotation ();
13551284
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 ());
1285+ align::RotationType dr_align (dr.xx (), dr.xy (), dr.xz (), dr.yx (), dr.yy (), dr.yz (), dr.zx (), dr.zy (), dr.zz ());
13651286
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])};
1287+ align::RotationType rr_align (rr.xx (), rr.xy (), rr.xz (), rr.yx (), rr.yy (), rr.yz (), rr.zx (), rr.zy (), rr.zz ());
13701288
1371- const auto &deltaTrans = target_ali[i].translation () - ref_ali[i].translation ();
1289+ auto da = align::toAngles (dr_align);
1290+ auto ra = align::toAngles (rr_align);
13721291
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
1292+ switch (C) {
1293+ case AlignmentPI::t_x:
1294+ diff[id] = dt.x () * AlignmentPI::cmToUm;
1295+ break ;
1296+ case AlignmentPI::t_y:
1297+ diff[id] = dt.y () * AlignmentPI::cmToUm;
1298+ break ;
1299+ case AlignmentPI::t_z:
1300+ diff[id] = dt.z () * AlignmentPI::cmToUm;
1301+ break ;
1302+ case AlignmentPI::rot_alpha:
1303+ diff[id] = deltaPhi (da[0 ], ra[0 ]) * AlignmentPI::tomRad;
1304+ break ;
1305+ case AlignmentPI::rot_beta:
1306+ diff[id] = deltaPhi (da[1 ], ra[1 ]) * AlignmentPI::tomRad;
1307+ break ;
1308+ case AlignmentPI::rot_gamma:
1309+ diff[id] = deltaPhi (da[2 ], ra[2 ]) * AlignmentPI::tomRad;
1310+ break ;
1311+ default :
1312+ break ;
1313+ }
1314+ }
13981315 }
13991316 };
14001317
14011318 // template implementations for Barrel Pixel
1402-
1319+
14031320 template <AlignmentPI::coordinate coord>
14041321 using BPixAlignmentCompareMap = PixelAlignmentCompareMapsBase<AlignmentPI::BPix, coord, 1 , MULTI_IOV>;
14051322
@@ -1423,7 +1340,7 @@ namespace {
14231340 typedef BPixAlignmentCompareMapTwoTags<AlignmentPI::rot_gamma> BPixAlignmentCompareMapGammaTwoTags;
14241341
14251342 // template implementations for Forward Pixel
1426-
1343+
14271344 template <AlignmentPI::coordinate coord>
14281345 using FPixAlignmentCompareMap = PixelAlignmentCompareMapsBase<AlignmentPI::FPix, coord, 1 , MULTI_IOV>;
14291346
0 commit comments