CMS 3D CMS Logo

Phase1PixelROCMaps.h
Go to the documentation of this file.
1 #ifndef DQM_TRACKERREMAPPER_PHASE1PIXELROCMAPS_H
2 #define DQM_TRACKERREMAPPER_PHASE1PIXELROCMAPS_H
3 
4 #include "TH1.h"
5 #include "TH2.h"
6 #include "TStyle.h"
7 #include "TCanvas.h"
8 #include "TLine.h"
9 #include "TLatex.h"
10 
11 #include <bitset>
12 #include <fmt/printf.h>
13 #include <fstream>
14 #include <boost/tokenizer.hpp>
15 #include <boost/range/adaptor/indexed.hpp>
16 
22 
23 #ifndef PHASE1PIXELMAP_STANDALONE
24 #define LOGDEBUG(x) LogDebug(x)
25 #else
26 #define LOGDEBUG(x) std::cout << x << ": "
27 #endif
28 
29 /*--------------------------------------------------------------------
30 / helper functions to dress plots
31 /--------------------------------------------------------------------*/
32 namespace PixelROCMapHelper {
33  void draw_line(double x1, double x2, double y1, double y2, int width, int style, int color);
34  void dress_plot(
35  TCanvas& canv, TH2* h, int lay, int ring, int phase, bool half_shift, bool mark_zero, bool standard_palette);
36 } // namespace PixelROCMapHelper
37 
38 /*--------------------------------------------------------------------
39 / Ancillary struct to contain detector topology coordinates
40 /--------------------------------------------------------------------*/
42  int m_layer;
45  int m_ring;
46  int m_s_blade;
47  int m_s_disk;
48  int m_panel;
50 
51 public:
53  m_layer = -1;
54  m_s_ladder = -1;
55  m_s_module = -1;
56  m_ring = -1;
57  m_s_blade = -1;
58  m_s_disk = -1;
59  m_panel = -1;
60  m_isFlipped = false;
61  }
62 
64  if (this->isBarrel()) {
65  edm::LogPrint("DetCoordinates") << "layer: " << m_layer << " ladder: " << m_s_ladder << " module: " << m_s_module
66  << std::endl;
67  } else {
68  edm::LogPrint("DetCoordinates") << "ring: " << m_ring << " blade: " << m_s_blade << " panel: " << m_panel
69  << " disk: " << m_s_disk << std::endl;
70  }
71  }
72 
73  bool isBarrel() { return (m_layer > 0); }
74  bool isEndcap() { return (m_ring > 0); }
75 };
76 
77 /*--------------------------------------------------------------------
78 / Ancillary class to build pixel phase-1 tracker maps
79 /--------------------------------------------------------------------*/
81 public:
83  : m_option{option},
85  edm::FileInPath("Geometry/TrackerCommonData/data/PhaseI/trackerParameters.xml").fullPath())} {
86  // --------------------- BOOK HISTOGRAMS
87  // barrel
88  for (unsigned int lay = 1; lay <= n_layers; lay++) {
89  int nlad = nlad_list[lay - 1];
90  std::string name = "occ_Layer_" + std::to_string(lay);
91  std::string title = "; Module # ; Ladder #";
92 
93  h_bpix_maps[lay - 1] = std::make_shared<TH2D>(
94  name.c_str(), title.c_str(), 72, -n_layers - 0.5, n_layers + 0.5, (nlad * 4 + 2), -nlad - 0.5, nlad + 0.5);
95  }
96 
97  // endcaps
98  for (unsigned int ring = 1; ring <= n_rings; ring++) {
99  int n = nybins_list[ring - 1];
100  float y = nxbins_list[ring - 1] + 0.5;
101  std::string name = "occ_ring_" + std::to_string(ring);
102  std::string title = "; Disk # ; Blade/Panel #";
103 
104  h_fpix_maps[ring - 1] =
105  std::make_shared<TH2D>(name.c_str(), title.c_str(), 56, -n_rings - 1.5, n_rings + 1.5, n, -y, y);
106  }
107  }
108 
110 
111  // Forward declarations
112  void fillWholeModule(const uint32_t& detid, double value);
113  void fillSelectedRocs(const uint32_t& detid, const std::bitset<16>& theROCs, double value);
114  void drawBarrelMaps(TCanvas& canvas);
115  void drawForwardMaps(TCanvas& canvas);
116  void drawMaps(TCanvas& canvas);
117 
118  inline std::array<std::shared_ptr<TH2D>, 4> getLayerMaps() { return h_bpix_maps; }
119  inline std::array<std::shared_ptr<TH2D>, 2> getRingMaps() { return h_fpix_maps; }
120 
121 private:
122  Option_t* m_option;
124 
125  // tough luck, we can only do phase-1...
126  static constexpr int numColumns = 416;
127  static constexpr int numRows = 160;
128  static constexpr int n_rings = 2;
129  static constexpr int n_layers = 4;
130 
131  const int nlad_list[n_layers] = {6, 14, 22, 32};
132  const int nybins_list[n_rings] = {92, 140};
133  const int nxbins_list[n_rings] = {11, 17};
134 
135  // maps
136  std::array<std::shared_ptr<TH2D>, n_layers> h_bpix_maps;
137  std::array<std::shared_ptr<TH2D>, n_rings> h_fpix_maps;
138 
139  // options
140  static constexpr const char* kVerbose = "verbose";
141 
142  // Forward declarations of private methods
143 
144  DetCoordinates findDetCoordinates(const uint32_t& t_detid);
145  std::vector<std::pair<int, int> > maskedBarrelRocsToBins(DetCoordinates coord);
146  std::vector<std::tuple<int, int, int> > maskedBarrelRocsToBins(DetCoordinates coord, std::bitset<16> myRocs);
147  std::vector<std::pair<int, int> > maskedForwardRocsToBins(DetCoordinates coord);
148  std::vector<std::tuple<int, int, int> > maskedForwardRocsToBins(DetCoordinates coord, std::bitset<16> myRocs);
149 
150 protected:
151  //============================================================================
152  // Taken from pixel naming classes
153  // BmO (-z-x) = 1, BmI (-z+x) = 2 , BpO (+z-x) = 3 , BpI (+z+x) = 4
154  int quadrant(const DetId& detid, bool phase_) {
155  if (detid.subdetId() == PixelSubdetector::PixelBarrel) {
156  return PixelBarrelName(detid, &m_trackerTopo, phase_).shell();
157  } else {
158  return PixelEndcapName(detid, &m_trackerTopo, phase_).halfCylinder();
159  }
160  }
161 
162  //============================================================================
163  // Online ladder convention taken from pixel naming class for barrel
164  // Apply sign convention (- sign for BmO and BpO)
165  int signed_ladder(const DetId& detid, bool phase_) {
167  return -9999;
168  int signed_ladder = PixelBarrelName(detid, &m_trackerTopo, phase_).ladderName();
169  if (quadrant(detid, phase_) % 2)
170  signed_ladder *= -1;
171  return signed_ladder;
172  }
173 
174  //============================================================================
175  // Online mdoule convention taken from pixel naming class for barrel
176  // Apply sign convention (- sign for BmO and BmI)
177  int signed_module(const DetId& detid, bool phase_) {
179  return -9999;
180  int signed_module = PixelBarrelName(detid, &m_trackerTopo, phase_).moduleName();
181  if (quadrant(detid, phase_) < 3)
182  signed_module *= -1;
183  return signed_module;
184  }
185 
186  //============================================================================
187  // Phase 0: Ring was not an existing convention
188  // but the 7 plaquettes were split by HV group
189  // --> Derive Ring 1/2 for them
190  // Panel 1 plq 1-2, Panel 2, plq 1 = Ring 1
191  // Panel 1 plq 3-4, Panel 2, plq 2-3 = Ring 2
192  // Phase 1: Using pixel naming class for endcap
193  int ring(const DetId& detid, bool phase_) {
195  return -9999;
196  int ring = -9999;
197  if (phase_ == 0) {
198  ring = 1 + (m_trackerTopo.pxfPanel(detid) + m_trackerTopo.pxfModule(detid) > 3);
199  } else if (phase_ == 1) {
200  ring = PixelEndcapName(detid, &m_trackerTopo, phase_).ringName();
201  }
202  return ring;
203  }
204 
205  //============================================================================
206  // Online blade convention taken from pixel naming class for endcap
207  // Apply sign convention (- sign for BmO and BpO)
208  int signed_blade(const DetId& detid, bool phase_) {
210  return -9999;
211  int signed_blade = PixelEndcapName(detid, &m_trackerTopo, phase_).bladeName();
212  if (quadrant(detid, phase_) % 2)
213  signed_blade *= -1;
214  return signed_blade;
215  }
216 
217  //============================================================================
218  int signed_blade_panel(const DetId& detid, bool phase_) {
220  return -9999;
221  int signed_blade_panel = signed_blade(detid, phase_) + (m_trackerTopo.pxfPanel(detid) - 1);
222  return signed_blade_panel;
223  }
224 
225  //============================================================================
226  // Online disk convention
227  // Apply sign convention (- sign for BmO and BmI)
228  int signed_disk(const DetId& detid, bool phase_) {
230  return -9999;
231  int signed_disk = m_trackerTopo.pxfDisk(DetId(detid));
232  if (quadrant(detid, phase_) < 3)
233  signed_disk *= -1;
234  return signed_disk;
235  }
236 
237  //============================================================================
238  // Determines if the BPix ldder is inner or outer
239  bool isBPixOuterLadder(const DetId& detid, bool isPhase0) {
240  bool isOuter = false;
241  int layer = m_trackerTopo.pxbLayer(detid.rawId());
242  bool odd_ladder = m_trackerTopo.pxbLadder(detid.rawId()) % 2;
243  if (isPhase0) {
244  if (layer == 2)
245  isOuter = !odd_ladder;
246  else
247  isOuter = odd_ladder;
248  } else {
249  if (layer == 4)
250  isOuter = odd_ladder;
251  else
252  isOuter = !odd_ladder;
253  }
254  return isOuter;
255  }
256 };
257 
258 #endif
DetCoordinates::m_s_disk
int m_s_disk
Definition: Phase1PixelROCMaps.h:47
Phase1PixelROCMaps
Definition: Phase1PixelROCMaps.h:80
svgfig.canvas
def canvas(*sub, **attr)
Definition: svgfig.py:482
DDAxes::y
ApeEstimator_cff.width
width
Definition: ApeEstimator_cff.py:24
PixelROCMapHelper::dress_plot
void dress_plot(TCanvas &canv, TH2 *h, int lay, int ring, int phase, bool half_shift, bool mark_zero, bool standard_palette)
Definition: Phase1PixelROCMaps.cc:293
Phase1PixelROCMaps::h_fpix_maps
std::array< std::shared_ptr< TH2D >, n_rings > h_fpix_maps
Definition: Phase1PixelROCMaps.h:137
runGCPTkAlMap.title
string title
Definition: runGCPTkAlMap.py:94
PixelBarrelName.h
MessageLogger.h
Phase1PixelROCMaps::ring
int ring(const DetId &detid, bool phase_)
Definition: Phase1PixelROCMaps.h:193
PixelSubdetector::PixelEndcap
Definition: PixelSubdetector.h:11
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
PixelSubdetector::PixelBarrel
Definition: PixelSubdetector.h:11
Phase1PixelROCMaps::getLayerMaps
std::array< std::shared_ptr< TH2D >, 4 > getLayerMaps()
Definition: Phase1PixelROCMaps.h:118
Phase1PixelROCMaps::numColumns
static constexpr int numColumns
Definition: Phase1PixelROCMaps.h:126
DetCoordinates::isBarrel
bool isBarrel()
Definition: Phase1PixelROCMaps.h:73
Phase1PixelROCMaps::fillWholeModule
void fillWholeModule(const uint32_t &detid, double value)
Definition: Phase1PixelROCMaps.cc:232
contentValuesFiles.fullPath
fullPath
Definition: contentValuesFiles.py:64
testProducerWithPsetDescEmpty_cfi.x2
x2
Definition: testProducerWithPsetDescEmpty_cfi.py:28
TrackerTopology
Definition: TrackerTopology.h:16
TrackerTopology::pxbLadder
unsigned int pxbLadder(const DetId &id) const
Definition: TrackerTopology.h:155
edm::LogPrint
Log< level::Warning, true > LogPrint
Definition: MessageLogger.h:130
PixelROCMapHelper::draw_line
void draw_line(double x1, double x2, double y1, double y2, int width, int style, int color)
Definition: Phase1PixelROCMaps.cc:280
PixelBarrelName
Definition: PixelBarrelName.h:16
PixelROCMapHelper
Definition: Phase1PixelROCMaps.h:32
Phase1PixelROCMaps::drawMaps
void drawMaps(TCanvas &canvas)
Definition: Phase1PixelROCMaps.cc:612
DetCoordinates::m_panel
int m_panel
Definition: Phase1PixelROCMaps.h:48
PixelEndcapName::halfCylinder
HalfCylinder halfCylinder() const
Definition: PixelEndcapName.h:42
Phase1PixelROCMaps::signed_blade
int signed_blade(const DetId &detid, bool phase_)
Definition: Phase1PixelROCMaps.h:208
fileinputsource_cfi.option
option
Definition: fileinputsource_cfi.py:87
PixelEndcapName::bladeName
int bladeName() const
blade id
Definition: PixelEndcapName.h:48
FileInPath.h
TrackerTopology::pxbLayer
unsigned int pxbLayer(const DetId &id) const
Definition: TrackerTopology.h:144
TrackerTopology::pxfPanel
unsigned int pxfPanel(const DetId &id) const
Definition: TrackerTopology.h:450
Phase1PixelROCMaps::nybins_list
const int nybins_list[n_rings]
Definition: Phase1PixelROCMaps.h:132
DetId
Definition: DetId.h:17
edm::FileInPath
Definition: FileInPath.h:64
DetCoordinates::m_isFlipped
bool m_isFlipped
Definition: Phase1PixelROCMaps.h:49
testProducerWithPsetDescEmpty_cfi.x1
x1
Definition: testProducerWithPsetDescEmpty_cfi.py:33
testProducerWithPsetDescEmpty_cfi.y1
y1
Definition: testProducerWithPsetDescEmpty_cfi.py:29
Phase1PixelROCMaps::getRingMaps
std::array< std::shared_ptr< TH2D >, 2 > getRingMaps()
Definition: Phase1PixelROCMaps.h:119
PixelEndcapName
Definition: PixelEndcapName.h:16
StandaloneTrackerTopology.h
Phase1PixelROCMaps::m_trackerTopo
TrackerTopology m_trackerTopo
Definition: Phase1PixelROCMaps.h:123
DetCoordinates::m_s_blade
int m_s_blade
Definition: Phase1PixelROCMaps.h:46
DetCoordinates::DetCoordinates
DetCoordinates()
Definition: Phase1PixelROCMaps.h:52
Phase1PixelROCMaps::quadrant
int quadrant(const DetId &detid, bool phase_)
Definition: Phase1PixelROCMaps.h:154
h
Phase1PixelROCMaps::maskedForwardRocsToBins
std::vector< std::pair< int, int > > maskedForwardRocsToBins(DetCoordinates coord)
Definition: Phase1PixelROCMaps.cc:140
DetCoordinates::m_s_ladder
int m_s_ladder
Definition: Phase1PixelROCMaps.h:43
PixelBarrelName::ladderName
int ladderName() const
ladder id (index in phi)
Definition: PixelBarrelName.h:49
DetId::subdetId
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum)
Definition: DetId.h:48
style
Definition: style.py:1
phase1PixelTopology::layer
constexpr std::array< uint8_t, layerIndexSize > layer
Definition: phase1PixelTopology.h:99
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
SiPixelPI::phase
phase
Definition: SiPixelPayloadInspectorHelper.h:39
testProducerWithPsetDescEmpty_cfi.y2
y2
Definition: testProducerWithPsetDescEmpty_cfi.py:30
Phase1PixelROCMaps::signed_ladder
int signed_ladder(const DetId &detid, bool phase_)
Definition: Phase1PixelROCMaps.h:165
Phase1PixelROCMaps::h_bpix_maps
std::array< std::shared_ptr< TH2D >, n_layers > h_bpix_maps
Definition: Phase1PixelROCMaps.h:136
Phase1PixelROCMaps::Phase1PixelROCMaps
Phase1PixelROCMaps(const char *option)
Definition: Phase1PixelROCMaps.h:82
PixelBarrelName::shell
Shell shell() const
Definition: PixelBarrelName.h:40
Phase1PixelROCMaps::nxbins_list
const int nxbins_list[n_rings]
Definition: Phase1PixelROCMaps.h:133
Phase1PixelROCMaps::fillSelectedRocs
void fillSelectedRocs(const uint32_t &detid, const std::bitset< 16 > &theROCs, double value)
Definition: Phase1PixelROCMaps.cc:255
TrackerTopology::pxfModule
unsigned int pxfModule(const DetId &id) const
Definition: TrackerTopology.h:163
value
Definition: value.py:1
TrackerTopology::pxfDisk
unsigned int pxfDisk(const DetId &id) const
Definition: TrackerTopology.h:446
Phase1PixelROCMaps::signed_module
int signed_module(const DetId &detid, bool phase_)
Definition: Phase1PixelROCMaps.h:177
DetCoordinates::printCoordinates
void printCoordinates()
Definition: Phase1PixelROCMaps.h:63
DetCoordinates::isEndcap
bool isEndcap()
Definition: Phase1PixelROCMaps.h:74
Phase1PixelROCMaps::n_layers
static constexpr int n_layers
Definition: Phase1PixelROCMaps.h:129
PixelBarrelName::moduleName
int moduleName() const
module id (index in z)
Definition: PixelBarrelName.h:46
Phase1PixelROCMaps::signed_disk
int signed_disk(const DetId &detid, bool phase_)
Definition: Phase1PixelROCMaps.h:228
Phase1PixelROCMaps::maskedBarrelRocsToBins
std::vector< std::pair< int, int > > maskedBarrelRocsToBins(DetCoordinates coord)
Definition: Phase1PixelROCMaps.cc:48
DetCoordinates::m_s_module
int m_s_module
Definition: Phase1PixelROCMaps.h:44
Phase1PixelROCMaps::drawForwardMaps
void drawForwardMaps(TCanvas &canvas)
Definition: Phase1PixelROCMaps.cc:598
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
Phase1PixelROCMaps::drawBarrelMaps
void drawBarrelMaps(TCanvas &canvas)
Definition: Phase1PixelROCMaps.cc:584
relativeConstraints.ring
ring
Definition: relativeConstraints.py:68
Phase1PixelROCMaps::kVerbose
static constexpr const char * kVerbose
Definition: Phase1PixelROCMaps.h:140
Phase1PixelROCMaps::findDetCoordinates
DetCoordinates findDetCoordinates(const uint32_t &t_detid)
Definition: Phase1PixelROCMaps.cc:8
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
DetCoordinates::m_ring
int m_ring
Definition: Phase1PixelROCMaps.h:45
Phase1PixelROCMaps::isBPixOuterLadder
bool isBPixOuterLadder(const DetId &detid, bool isPhase0)
Definition: Phase1PixelROCMaps.h:239
Phase1PixelROCMaps::m_option
Option_t * m_option
Definition: Phase1PixelROCMaps.h:122
DetCoordinates
Definition: Phase1PixelROCMaps.h:41
Phase1PixelROCMaps::~Phase1PixelROCMaps
~Phase1PixelROCMaps()
Definition: Phase1PixelROCMaps.h:109
DetCoordinates::m_layer
int m_layer
Definition: Phase1PixelROCMaps.h:42
StandaloneTrackerTopology::fromTrackerParametersXMLFile
TrackerTopology fromTrackerParametersXMLFile(const std::string &xmlFileName)
Definition: StandaloneTrackerTopology.cc:168
Phase1PixelROCMaps::numRows
static constexpr int numRows
Definition: Phase1PixelROCMaps.h:127
Phase1PixelROCMaps::nlad_list
const int nlad_list[n_layers]
Definition: Phase1PixelROCMaps.h:131
Phase1PixelROCMaps::signed_blade_panel
int signed_blade_panel(const DetId &detid, bool phase_)
Definition: Phase1PixelROCMaps.h:218
PixelEndcapName::ringName
int ringName() const
ring Id
Definition: PixelEndcapName.h:57
Phase1PixelROCMaps::n_rings
static constexpr int n_rings
Definition: Phase1PixelROCMaps.h:128
PixelEndcapName.h