Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:09:03

0001 #ifndef DQM_TRACKERREMAPPER_PHASE1PIXELROCMAPS_H
0002 #define DQM_TRACKERREMAPPER_PHASE1PIXELROCMAPS_H
0003 
0004 #include "TH1.h"
0005 #include "TH2.h"
0006 #include "TStyle.h"
0007 #include "TCanvas.h"
0008 #include "TLine.h"
0009 #include "TLatex.h"
0010 
0011 #include <array>
0012 #include <bitset>
0013 #include <fmt/printf.h>
0014 #include <fstream>
0015 #include <boost/tokenizer.hpp>
0016 #include <boost/range/adaptor/indexed.hpp>
0017 
0018 #include "FWCore/ParameterSet/interface/FileInPath.h"
0019 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0020 #include "CalibTracker/StandaloneTrackerTopology/interface/StandaloneTrackerTopology.h"
0021 #include "DataFormats/TrackerCommon/interface/PixelBarrelName.h"
0022 #include "DataFormats/TrackerCommon/interface/PixelEndcapName.h"
0023 
0024 #ifndef PHASE1PIXELMAP_STANDALONE
0025 #define LOGDEBUG(x) LogDebug(x)
0026 #else
0027 #define LOGDEBUG(x) std::cout << x << ": "
0028 #endif
0029 
0030 /*--------------------------------------------------------------------
0031 / helper functions to dress plots
0032 /--------------------------------------------------------------------*/
0033 namespace PixelROCMapHelper {
0034   void draw_line(double x1, double x2, double y1, double y2, int width, int style, int color);
0035   void dress_plot(
0036       TPad*& canv, TH2* h, int lay, int ring, int phase, bool half_shift, bool mark_zero, bool standard_palette);
0037 }  // namespace PixelROCMapHelper
0038 
0039 /*--------------------------------------------------------------------
0040 / Ancillary struct to contain detector topology coordinates
0041 /--------------------------------------------------------------------*/
0042 struct DetCoordinates {
0043   int m_layer;
0044   int m_s_ladder;
0045   int m_s_module;
0046   int m_ring;
0047   int m_s_blade;
0048   int m_s_disk;
0049   int m_panel;
0050   bool m_isFlipped;
0051 
0052 public:
0053   DetCoordinates() {
0054     m_layer = -1;
0055     m_s_ladder = -1;
0056     m_s_module = -1;
0057     m_ring = -1;
0058     m_s_blade = -1;
0059     m_s_disk = -1;
0060     m_panel = -1;
0061     m_isFlipped = false;
0062   }
0063 
0064   void printCoordinates() {
0065     if (this->isBarrel()) {
0066       edm::LogPrint("DetCoordinates") << "layer: " << m_layer << " ladder: " << m_s_ladder << " module: " << m_s_module
0067                                       << std::endl;
0068     } else {
0069       edm::LogPrint("DetCoordinates") << "ring: " << m_ring << " blade: " << m_s_blade << " panel: " << m_panel
0070                                       << " disk: " << m_s_disk << std::endl;
0071     }
0072   }
0073 
0074   bool isBarrel() { return (m_layer > 0); }
0075   bool isEndcap() { return (m_ring > 0); }
0076   bool isFlipped() { return m_isFlipped; }
0077 };
0078 
0079 /*--------------------------------------------------------------------
0080 / Ancillary class to build pixel phase-1 tracker maps
0081 /--------------------------------------------------------------------*/
0082 class Phase1PixelROCMaps {
0083 public:
0084   Phase1PixelROCMaps(const char* option, const std::string& zAxisTitle = "")
0085       : m_option{option},
0086         m_zAxisTitle{zAxisTitle},
0087         m_trackerTopo{StandaloneTrackerTopology::fromTrackerParametersXMLFile(
0088             edm::FileInPath("Geometry/TrackerCommonData/data/PhaseI/trackerParameters.xml").fullPath())} {
0089     // ---------------------    BOOK HISTOGRAMS
0090     // barrel
0091     for (unsigned int lay = 1; lay <= n_layers; lay++) {
0092       int nlad = nlad_list[lay - 1];
0093       std::string name = "occ_Layer_" + std::to_string(lay);
0094       std::string title = "; Module # ; Ladder #";
0095 
0096       // if a z-axis title is specified, add the z-axis title
0097       if (!m_zAxisTitle.empty()) {
0098         title += fmt::sprintf(" ;%s", m_zAxisTitle.c_str());
0099       }
0100 
0101       h_bpix_maps[lay - 1] = std::make_shared<TH2D>(
0102           name.c_str(), title.c_str(), 72, -n_layers - 0.5, n_layers + 0.5, (nlad * 4 + 2), -nlad - 0.5, nlad + 0.5);
0103     }
0104 
0105     // endcaps
0106     for (unsigned int ring = 1; ring <= n_rings; ring++) {
0107       int n = nybins_list[ring - 1];
0108       float y = nxbins_list[ring - 1] + 0.5;
0109       std::string name = "occ_ring_" + std::to_string(ring);
0110       std::string title = "; Disk # ; Blade/Panel #";
0111 
0112       // if a z-axis title is specified, add the z-axis title
0113       if (!m_zAxisTitle.empty()) {
0114         title += fmt::sprintf(" ;%s", m_zAxisTitle.c_str());
0115       }
0116 
0117       h_fpix_maps[ring - 1] =
0118           std::make_shared<TH2D>(name.c_str(), title.c_str(), 56, -n_rings - 1.5, n_rings + 1.5, n, -y, y);
0119     }
0120   }
0121 
0122   ~Phase1PixelROCMaps() {}
0123 
0124   // Forward declarations
0125   DetCoordinates findDetCoordinates(const uint32_t& t_detid);
0126   void fillWholeModule(const uint32_t& detid, double value);
0127   void fillSelectedRocs(const uint32_t& detid, const std::bitset<16>& theROCs, double value);
0128   void drawBarrelMaps(TCanvas& canvas, const std::string& text = "");
0129   void drawForwardMaps(TCanvas& canvas, const std::string& text = "");
0130   void drawMaps(TCanvas& canvas, const std::string& text = "");
0131 
0132   inline std::array<std::shared_ptr<TH2D>, 4> getLayerMaps() { return h_bpix_maps; }
0133   inline std::array<std::shared_ptr<TH2D>, 2> getRingMaps() { return h_fpix_maps; }
0134 
0135 private:
0136   Option_t* m_option;
0137   std::string m_zAxisTitle;
0138   TrackerTopology m_trackerTopo;
0139 
0140   // tough luck, we can only do phase-1...
0141   static constexpr int numColumns = 416;
0142   static constexpr int numRows = 160;
0143   static constexpr int n_rings = 2;
0144   static constexpr int n_layers = 4;
0145 
0146   const int nlad_list[n_layers] = {6, 14, 22, 32};
0147   const int nybins_list[n_rings] = {92, 140};
0148   const int nxbins_list[n_rings] = {11, 17};
0149 
0150   // maps
0151   std::array<std::shared_ptr<TH2D>, n_layers> h_bpix_maps;
0152   std::array<std::shared_ptr<TH2D>, n_rings> h_fpix_maps;
0153 
0154   // options
0155   static constexpr const char* kVerbose = "verbose";
0156 
0157   // Forward declarations of private methods
0158   std::vector<std::pair<int, int> > maskedBarrelRocsToBins(DetCoordinates coord);
0159   std::vector<std::tuple<int, int, int> > maskedBarrelRocsToBins(DetCoordinates coord, std::bitset<16> myRocs);
0160   std::vector<std::pair<int, int> > maskedForwardRocsToBins(DetCoordinates coord);
0161   std::vector<std::tuple<int, int, int> > maskedForwardRocsToBins(DetCoordinates coord, std::bitset<16> myRocs);
0162 
0163 protected:
0164   //============================================================================
0165   // Taken from pixel naming classes
0166   // BmO (-z-x) = 1, BmI (-z+x) = 2 , BpO (+z-x) = 3 , BpI (+z+x) = 4
0167   inline int quadrant(const DetId& detid, bool phase_) {
0168     if (detid.subdetId() == PixelSubdetector::PixelBarrel) {
0169       return PixelBarrelName(detid, &m_trackerTopo, phase_).shell();
0170     } else {
0171       return PixelEndcapName(detid, &m_trackerTopo, phase_).halfCylinder();
0172     }
0173   }
0174 
0175   //============================================================================
0176   // Online ladder convention taken from pixel naming class for barrel
0177   // Apply sign convention (- sign for BmO and BpO)
0178   inline int signed_ladder(const DetId& detid, bool phase_) {
0179     if (detid.subdetId() != PixelSubdetector::PixelBarrel)
0180       return -9999;
0181     int signed_ladder = PixelBarrelName(detid, &m_trackerTopo, phase_).ladderName();
0182     if (quadrant(detid, phase_) % 2)
0183       signed_ladder *= -1;
0184     return signed_ladder;
0185   }
0186 
0187   //============================================================================
0188   // Online mdoule convention taken from pixel naming class for barrel
0189   // Apply sign convention (- sign for BmO and BmI)
0190   inline int signed_module(const DetId& detid, bool phase_) {
0191     if (detid.subdetId() != PixelSubdetector::PixelBarrel)
0192       return -9999;
0193     int signed_module = PixelBarrelName(detid, &m_trackerTopo, phase_).moduleName();
0194     if (quadrant(detid, phase_) < 3)
0195       signed_module *= -1;
0196     return signed_module;
0197   }
0198 
0199   //============================================================================
0200   // Phase 0: Ring was not an existing convention
0201   //   but the 7 plaquettes were split by HV group
0202   //   --> Derive Ring 1/2 for them
0203   //   Panel 1 plq 1-2, Panel 2, plq 1   = Ring 1
0204   //   Panel 1 plq 3-4, Panel 2, plq 2-3 = Ring 2
0205   // Phase 1: Using pixel naming class for endcap
0206   inline int ring(const DetId& detid, bool phase_) {
0207     if (detid.subdetId() != PixelSubdetector::PixelEndcap)
0208       return -9999;
0209     int ring = -9999;
0210     if (phase_ == 0) {
0211       ring = 1 + (m_trackerTopo.pxfPanel(detid) + m_trackerTopo.pxfModule(detid) > 3);
0212     } else if (phase_ == 1) {
0213       ring = PixelEndcapName(detid, &m_trackerTopo, phase_).ringName();
0214     }
0215     return ring;
0216   }
0217 
0218   //============================================================================
0219   // Online blade convention taken from pixel naming class for endcap
0220   // Apply sign convention (- sign for BmO and BpO)
0221   inline int signed_blade(const DetId& detid, bool phase_) {
0222     if (detid.subdetId() != PixelSubdetector::PixelEndcap)
0223       return -9999;
0224     int signed_blade = PixelEndcapName(detid, &m_trackerTopo, phase_).bladeName();
0225     if (quadrant(detid, phase_) % 2)
0226       signed_blade *= -1;
0227     return signed_blade;
0228   }
0229 
0230   //============================================================================
0231   inline int signed_blade_panel(const DetId& detid, bool phase_) {
0232     if (detid.subdetId() != PixelSubdetector::PixelEndcap)
0233       return -9999;
0234     int signed_blade_panel = signed_blade(detid, phase_) + (m_trackerTopo.pxfPanel(detid) - 1);
0235     return signed_blade_panel;
0236   }
0237 
0238   //============================================================================
0239   // Online disk convention
0240   // Apply sign convention (- sign for BmO and BmI)
0241   inline int signed_disk(const DetId& detid, bool phase_) {
0242     if (detid.subdetId() != PixelSubdetector::PixelEndcap)
0243       return -9999;
0244     int signed_disk = m_trackerTopo.pxfDisk(DetId(detid));
0245     if (quadrant(detid, phase_) < 3)
0246       signed_disk *= -1;
0247     return signed_disk;
0248   }
0249 
0250   //============================================================================
0251   // Determines if the BPix ldder is inner or outer
0252   inline bool isBPixOuterLadder(const DetId& detid, bool isPhase0) {
0253     bool isOuter = false;
0254     int layer = m_trackerTopo.pxbLayer(detid.rawId());
0255     bool odd_ladder = m_trackerTopo.pxbLadder(detid.rawId()) % 2;
0256     if (isPhase0) {
0257       if (layer == 2)
0258         isOuter = !odd_ladder;
0259       else
0260         isOuter = odd_ladder;
0261     } else {
0262       if (layer == 4)
0263         isOuter = odd_ladder;
0264       else
0265         isOuter = !odd_ladder;
0266     }
0267     return isOuter;
0268   }
0269 };
0270 
0271 #endif