Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:08:27

0001 #ifndef DQM_SiPixelPhase1Summary_SiPixelBarycenterHelper_h
0002 #define DQM_SiPixelPhase1Summary_SiPixelBarycenterHelper_h
0003 
0004 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 #include "CondFormats/Alignment/interface/Alignments.h"
0007 #include "Alignment/TrackerAlignment/interface/TrackerNameSpace.h"
0008 #include "DataFormats/TrackerCommon/interface/PixelBarrelName.h"
0009 #include "DataFormats/TrackerCommon/interface/PixelEndcapName.h"
0010 
0011 // Helper mainly based on https://github.com/cms-sw/cmssw/blob/master/CondCore/AlignmentPlugins/interface/AlignmentPayloadInspectorHelper.h
0012 
0013 namespace DQMBarycenter {
0014 
0015   enum coordinate {
0016     t_x = 1,
0017     t_y = 2,
0018     t_z = 3,
0019     rot_alpha = 4,
0020     rot_beta = 5,
0021     rot_gamma = 6,
0022   };
0023 
0024   enum partitions {
0025     BPix = 1,
0026     FPix_zp = 2,
0027     FPix_zm = 3,
0028     BPix_xp = 4,
0029     BPix_xm = 5,
0030     FPix_zp_xp = 6,
0031     FPix_zm_xp = 7,
0032     FPix_zp_xm = 8,
0033     FPix_zm_xm = 9,
0034   };
0035 
0036   enum class PARTITION {
0037     BPIX,        // 0 Barrel Pixel
0038     FPIX_zp,     // 1 Forward Pixel Z-Plus
0039     FPIX_zm,     // 2 Forward Pixel Z-Minus
0040     BPIX_xp,     // 3 Barrel Pixel X-Plus
0041     BPIX_xm,     // 4 Barrel Pixel X-Minus
0042     FPIX_zp_xp,  // 5 Forward Pixel Z-Plus X-Plus
0043     FPIX_zm_xp,  // 6 Forward Pixel Z-Minus X-Plus
0044     FPIX_zp_xm,  // 7 Forward Pixel Z-Plus X-Minus
0045     FPIX_zm_xm,  // 8 Forward Pixel Z-Minus X-Minus
0046     LAST = FPIX_zm_xm
0047   };
0048 
0049   extern const PARTITION PARTITIONS[(int)PARTITION::LAST + 1];
0050   const PARTITION PARTITIONS[] = {
0051       PARTITION::BPIX,
0052       PARTITION::FPIX_zp,
0053       PARTITION::FPIX_zm,
0054       PARTITION::BPIX_xp,
0055       PARTITION::BPIX_xm,
0056       PARTITION::FPIX_zp_xp,
0057       PARTITION::FPIX_zm_xp,
0058       PARTITION::FPIX_zp_xm,
0059       PARTITION::FPIX_zm_xm,
0060   };
0061 
0062   class TkAlBarycenters {
0063     std::map<DQMBarycenter::PARTITION, double> Xbarycenters;
0064     std::map<DQMBarycenter::PARTITION, double> Ybarycenters;
0065     std::map<DQMBarycenter::PARTITION, double> Zbarycenters;
0066     std::map<DQMBarycenter::PARTITION, double> nmodules;
0067 
0068   public:
0069     inline void init();
0070 
0071     /*--------------------------------------------------------------------*/
0072     inline const std::array<double, 9> getX()
0073     /*--------------------------------------------------------------------*/
0074     {
0075       return {{Xbarycenters[PARTITION::BPIX],
0076                Xbarycenters[PARTITION::FPIX_zm],
0077                Xbarycenters[PARTITION::FPIX_zp],
0078                Xbarycenters[PARTITION::BPIX_xp],
0079                Xbarycenters[PARTITION::BPIX_xm],
0080                Xbarycenters[PARTITION::FPIX_zp_xp],
0081                Xbarycenters[PARTITION::FPIX_zm_xp],
0082                Xbarycenters[PARTITION::FPIX_zp_xm],
0083                Xbarycenters[PARTITION::FPIX_zm_xm]}};
0084     };
0085 
0086     /*--------------------------------------------------------------------*/
0087     inline const std::array<double, 9> getY()
0088     /*--------------------------------------------------------------------*/
0089     {
0090       return {{Ybarycenters[PARTITION::BPIX],
0091                Ybarycenters[PARTITION::FPIX_zm],
0092                Ybarycenters[PARTITION::FPIX_zp],
0093                Ybarycenters[PARTITION::BPIX_xp],
0094                Ybarycenters[PARTITION::BPIX_xm],
0095                Ybarycenters[PARTITION::FPIX_zp_xp],
0096                Ybarycenters[PARTITION::FPIX_zm_xp],
0097                Ybarycenters[PARTITION::FPIX_zp_xm],
0098                Ybarycenters[PARTITION::FPIX_zm_xm]}};
0099     };
0100 
0101     /*--------------------------------------------------------------------*/
0102     inline const std::array<double, 9> getZ()
0103     /*--------------------------------------------------------------------*/
0104     {
0105       return {{Zbarycenters[PARTITION::BPIX],
0106                Zbarycenters[PARTITION::FPIX_zm],
0107                Zbarycenters[PARTITION::FPIX_zp],
0108                Zbarycenters[PARTITION::BPIX_xp],
0109                Zbarycenters[PARTITION::BPIX_xm],
0110                Zbarycenters[PARTITION::FPIX_zp_xp],
0111                Zbarycenters[PARTITION::FPIX_zm_xp],
0112                Zbarycenters[PARTITION::FPIX_zp_xm],
0113                Zbarycenters[PARTITION::FPIX_zm_xm]}};
0114     };
0115     inline virtual ~TkAlBarycenters() {}
0116 
0117     /*--------------------------------------------------------------------*/
0118     inline void computeBarycenters(const std::vector<AlignTransform>& input,
0119                                    const TrackerTopology& tTopo,
0120                                    const std::map<DQMBarycenter::coordinate, float>& GPR)
0121     /*--------------------------------------------------------------------*/
0122     {
0123       for (const auto& ali : input) {
0124         if (DetId(ali.rawId()).det() != DetId::Tracker) {
0125           edm::LogWarning("SiPixelBarycenters::computeBarycenters")
0126               << "Encountered invalid Tracker DetId:" << ali.rawId() << " " << DetId(ali.rawId()).det()
0127               << " is different from " << DetId::Tracker << "  - terminating ";
0128           assert(DetId(ali.rawId()).det() != DetId::Tracker);
0129         }
0130 
0131         const auto& tns = align::TrackerNameSpace(&tTopo);
0132         int subid = DetId(ali.rawId()).subdetId();
0133         if (subid == PixelSubdetector::PixelBarrel || subid == PixelSubdetector::PixelEndcap) {  // use only pixel
0134           switch (subid) {  // Separate BPIX, FPIX_zp and FPIX_zm
0135             case PixelSubdetector::PixelBarrel:
0136               Xbarycenters[PARTITION::BPIX] += (ali.translation().x());
0137               Ybarycenters[PARTITION::BPIX] += (ali.translation().y());
0138               Zbarycenters[PARTITION::BPIX] += (ali.translation().z());
0139               nmodules[PARTITION::BPIX]++;
0140               break;
0141             case PixelSubdetector::PixelEndcap:
0142               // minus side
0143               if (tns.tpe().endcapNumber(ali.rawId()) == 1) {
0144                 Xbarycenters[PARTITION::FPIX_zm] += (ali.translation().x());
0145                 Ybarycenters[PARTITION::FPIX_zm] += (ali.translation().y());
0146                 Zbarycenters[PARTITION::FPIX_zm] += (ali.translation().z());
0147                 nmodules[PARTITION::FPIX_zm]++;
0148               }  // plus side
0149               else {
0150                 Xbarycenters[PARTITION::FPIX_zp] += (ali.translation().x());
0151                 Ybarycenters[PARTITION::FPIX_zp] += (ali.translation().y());
0152                 Zbarycenters[PARTITION::FPIX_zp] += (ali.translation().z());
0153                 nmodules[PARTITION::FPIX_zp]++;
0154               }
0155               break;
0156             default:
0157               edm::LogError("PixelDQM") << "Unrecognized partition for barycenter computation " << subid << std::endl;
0158               break;
0159           }
0160 
0161           switch (subid) {  // Separate following the PCL HLS
0162             case PixelSubdetector::PixelBarrel:
0163               if ((PixelBarrelName(DetId(ali.rawId()), true).shell() == PixelBarrelName::mO) ||
0164                   (PixelBarrelName(DetId(ali.rawId()), true).shell() == PixelBarrelName::pO)) {  // BPIX x-
0165                 Xbarycenters[PARTITION::BPIX_xm] += (ali.translation().x());
0166                 Ybarycenters[PARTITION::BPIX_xm] += (ali.translation().y());
0167                 Zbarycenters[PARTITION::BPIX_xm] += (ali.translation().z());
0168                 nmodules[PARTITION::BPIX_xm]++;
0169               } else {  // BPIX x+
0170                 Xbarycenters[PARTITION::BPIX_xp] += (ali.translation().x());
0171                 Ybarycenters[PARTITION::BPIX_xp] += (ali.translation().y());
0172                 Zbarycenters[PARTITION::BPIX_xp] += (ali.translation().z());
0173                 nmodules[PARTITION::BPIX_xp]++;
0174               }
0175               break;
0176             case PixelSubdetector::PixelEndcap:
0177               if (PixelEndcapName(DetId(ali.rawId()), true).halfCylinder() == PixelEndcapName::mO) {  //FPIX z- x-
0178                 Xbarycenters[PARTITION::FPIX_zm_xm] += (ali.translation().x());
0179                 Ybarycenters[PARTITION::FPIX_zm_xm] += (ali.translation().y());
0180                 Zbarycenters[PARTITION::FPIX_zm_xm] += (ali.translation().z());
0181                 nmodules[PARTITION::FPIX_zm_xm]++;
0182               } else if (PixelEndcapName(DetId(ali.rawId()), true).halfCylinder() ==
0183                          PixelEndcapName::mI) {  //FPIX z- x+
0184                 Xbarycenters[PARTITION::FPIX_zm_xp] += (ali.translation().x());
0185                 Ybarycenters[PARTITION::FPIX_zm_xp] += (ali.translation().y());
0186                 Zbarycenters[PARTITION::FPIX_zm_xp] += (ali.translation().z());
0187                 nmodules[PARTITION::FPIX_zm_xp]++;
0188               } else if (PixelEndcapName(DetId(ali.rawId()), true).halfCylinder() ==
0189                          PixelEndcapName::pO) {  //FPIX z+ x-
0190                 Xbarycenters[PARTITION::FPIX_zp_xm] += (ali.translation().x());
0191                 Ybarycenters[PARTITION::FPIX_zp_xm] += (ali.translation().y());
0192                 Zbarycenters[PARTITION::FPIX_zp_xm] += (ali.translation().z());
0193                 nmodules[PARTITION::FPIX_zp_xm]++;
0194               } else if (PixelEndcapName(DetId(ali.rawId()), true).halfCylinder() ==
0195                          PixelEndcapName::pI) {  //FPIX z+ x+
0196                 Xbarycenters[PARTITION::FPIX_zp_xp] += (ali.translation().x());
0197                 Ybarycenters[PARTITION::FPIX_zp_xp] += (ali.translation().y());
0198                 Zbarycenters[PARTITION::FPIX_zp_xp] += (ali.translation().z());
0199                 nmodules[PARTITION::FPIX_zp_xp]++;
0200               } else {
0201                 edm::LogError("PixelDQM") << "Unrecognized partition for barycenter computation " << subid << std::endl;
0202               }
0203               break;
0204             default:
0205               edm::LogError("PixelDQM") << "Unrecognized partition for barycenter computation " << subid << std::endl;
0206               break;
0207           }
0208         }
0209       }
0210 
0211       for (const auto& p : PARTITIONS) {
0212         Xbarycenters[p] /= nmodules[p];
0213         Ybarycenters[p] /= nmodules[p];
0214         Zbarycenters[p] /= nmodules[p];
0215 
0216         Xbarycenters[p] += GPR.at(DQMBarycenter::t_x);
0217         Ybarycenters[p] += GPR.at(DQMBarycenter::t_y);
0218         Zbarycenters[p] += GPR.at(DQMBarycenter::t_z);
0219       }
0220     }
0221   };
0222 }  // namespace DQMBarycenter
0223 
0224 #endif