CMS 3D CMS Logo

DD4hep_TrackingMaterialPlotter.cc
Go to the documentation of this file.
1 #include <iostream>
2 
3 #include <TROOT.h>
4 #include <TObjArray.h>
5 #include <TColor.h>
6 #include <TStyle.h>
7 #include <TCanvas.h>
8 #include <TFrame.h>
9 #include "DD4hep_XHistogram.h"
11 
13 
15  m_color.emplace_back(kBlack); // unassigned
16  m_color.emplace_back(kAzure); // PixelBarrel
17  m_color.emplace_back(kAzure + 1); //
18  m_color.emplace_back(kAzure + 1); //
19  m_color.emplace_back(kAzure + 3); //
20  m_color.emplace_back(kAzure + 3); //
21  m_color.emplace_back(kGreen); // TIB
22  m_color.emplace_back(kGreen); //
23  m_color.emplace_back(kGreen + 2); //
24  m_color.emplace_back(kGreen + 2); //
25  m_color.emplace_back(kGreen - 3); //
26  m_color.emplace_back(kGreen - 3); //
27  m_color.emplace_back(kGreen - 1); //
28  m_color.emplace_back(kGreen - 1); //
29  m_color.emplace_back(kRed); // TOB
30  m_color.emplace_back(kRed); //
31  m_color.emplace_back(kRed); //
32  m_color.emplace_back(kRed + 3); //
33  m_color.emplace_back(kRed + 3); //
34  m_color.emplace_back(kRed + 3); //
35  m_color.emplace_back(kRed - 3); //
36  m_color.emplace_back(kRed - 3); //
37  m_color.emplace_back(kRed - 3); //
38  m_color.emplace_back(kOrange + 9); //
39  m_color.emplace_back(kOrange + 9); //
40  m_color.emplace_back(kOrange + 9); //
41  m_color.emplace_back(kOrange + 7); //
42  m_color.emplace_back(kOrange + 7); //
43  m_color.emplace_back(kOrange + 7); //
44  m_color.emplace_back(kOrange + 5); //
45  m_color.emplace_back(kOrange + 5); //
46  m_color.emplace_back(kOrange + 5); //
47  m_color.emplace_back(kOrange + 8); // PixelEndcap Z-
48  m_color.emplace_back(kOrange + 10); //
49  m_color.emplace_back(kOrange - 3); //
50  m_color.emplace_back(kOrange - 1); // PixelEndcap Z+
51  m_color.emplace_back(kOrange - 8); //
52  m_color.emplace_back(kYellow); // TID Z-
53  m_color.emplace_back(kYellow); //
54  m_color.emplace_back(kYellow + 2); //
55  m_color.emplace_back(kYellow + 2); //
56  m_color.emplace_back(kYellow + 2); //
57  m_color.emplace_back(kYellow + 3); //
58  m_color.emplace_back(kMagenta); //
59  m_color.emplace_back(kMagenta); //
60  m_color.emplace_back(kMagenta); //
61  m_color.emplace_back(kMagenta); //
62  m_color.emplace_back(kMagenta); //
63  m_color.emplace_back(kMagenta + 1); //
64  m_color.emplace_back(kMagenta + 2); //
65  m_color.emplace_back(kMagenta + 3); //
66  m_color.emplace_back(kMagenta + 4); //
67  m_color.emplace_back(kMagenta + 5); //
68  m_color.emplace_back(kMagenta + 6); //
69  m_color.emplace_back(kMagenta + 7); //
70  m_color.emplace_back(kMagenta + 8); //
71 }
72 
74  const TColor& last,
75  unsigned int steps /*= 100*/,
76  unsigned int index /* = 0*/) {
77  if (index == 0) {
78  // if no index was given, find the highest used one and start from that plus one
79  index = ((TObjArray*)gROOT->GetListOfColors())->GetLast() + 1;
80  }
81 
82  float r1, g1, b1, r2, g2, b2;
83  first.GetRGB(r1, g1, b1);
84  last.GetRGB(r2, g2, b2);
85  float delta_r = (r2 - r1) / (steps - 1);
86  float delta_g = (g2 - g1) / (steps - 1);
87  float delta_b = (b2 - b1) / (steps - 1);
88 
89  m_gradient.resize(steps);
90  for (unsigned int i = 0; i < steps; ++i) {
91  new TColor(static_cast<Int_t>(index + i), r1 + delta_r * i, g1 + delta_g * i, b1 + delta_b * i);
92  m_gradient[i] = index + i;
93  }
94 
95  return index;
96 }
97 
98 unsigned int DD4hep_TrackingMaterialPlotter::fill_gradient(const unsigned int& first,
99  const unsigned int& last,
100  const unsigned int& steps,
101  const unsigned int& index) {
102  return fill_gradient(
103  *(TColor*)gROOT->GetListOfColors()->At(first), *(TColor*)gROOT->GetListOfColors()->At(last), steps, index);
104 }
105 
107  const float rzMinZ = -maxZ;
108  const float rzMaxZ = maxZ;
109  const float rzMinR = 0.;
110  const float rzMaxR = maxR;
111  const int rzBinsZ = (int)(2. * maxZ * resolution);
112  const int rzBinsR = (int)(maxR * resolution);
113 
114  std::vector<double> max;
115  max.emplace_back(0.08);
116  max.emplace_back(0.00016);
118  2, rzBinsZ, rzBinsR, std::make_pair(rzMinZ, rzMaxZ), std::make_pair(rzMinR, rzMaxR), m_color.size(), max);
119 
120  TColor::InitializeColors();
121  fill_color();
122  fill_gradient(kWhite, kBlack, 100); // 100-steps gradient from white to black
123 }
124 
126  std::vector<double> w(2);
127  w[0] = step.radiationLengths();
128  w[1] = step.energyLoss();
129  m_tracker.fill(std::make_pair(step.in().z(), step.out().z()),
130  std::make_pair(step.in().perp(), step.out().perp()),
131  w,
132  step.length(),
133  1); // 0 is empty, 1 is unassigned
134 }
135 
137  std::vector<double> w(2);
138  w[0] = step.radiationLengths();
139  w[1] = step.energyLoss();
140  m_tracker.fill(std::make_pair(step.in().z(), step.out().z()),
141  std::make_pair(step.in().perp(), step.out().perp()),
142  w,
143  step.length(),
144  layer + 1); // layer is 1-based, but plot uses: 0 is empty, 1 is unassigned
145 }
146 
148  const double scale = 10.;
149  std::unique_ptr<TCanvas> canvas;
150 
152  canvas = std::make_unique<TCanvas>(
153  "radlen_rz", "RadiationLengths - RZ view", (int)(600 * scale * 1.25), (int)(120 * scale * 1.50));
154  gStyle->SetOptStat(0);
155  gStyle->SetPalette(m_gradient.size(), &m_gradient.front());
156  gStyle->SetNumberContours(m_gradient.size());
157  canvas->GetFrame()->SetFillColor(kWhite);
158  radlen->Draw("colz");
159  radlen->Draw("same axis y+");
160  radlen->SaveAs("radlen.root");
161  canvas->SaveAs("radlen.png");
162  // Replicate RainBow palette, with White in the first white_slots
163  // positions
164  int white_slots = 1;
165  int MyPalette[100];
166  double stops[9] = {0.0000, 0.1250, 0.2500, 0.3750, 0.5000, 0.6250, 0.7500, 0.8750, 1.0000};
167  double red[9] = {
168  0. / 255., 5. / 255., 15. / 255., 35. / 255., 102. / 255., 196. / 255., 208. / 255., 199. / 255., 110. / 255.};
169  double green[9] = {
170  0. / 255., 48. / 255., 124. / 255., 192. / 255., 206. / 255., 226. / 255., 97. / 255., 16. / 255., 0. / 255.};
171  double blue[9] = {
172  99. / 255., 142. / 255., 198. / 255., 201. / 255., 90. / 255., 22. / 255., 13. / 255., 8. / 255., 2. / 255.};
173  int palette_index = TColor::CreateGradientColorTable(9, stops, red, green, blue, 100 - white_slots);
174  for (int i = 0; i < white_slots; i++)
175  MyPalette[i] = kWhite;
176  for (int i = 0; i < 100 - white_slots; i++)
177  MyPalette[i + white_slots] = palette_index + i;
178  canvas->Clear();
179  gStyle->SetNumberContours(100);
180  gStyle->SetPalette(100, MyPalette); // ROOT Rainbow color palette
181  radlen->Draw("colz");
182  radlen->Draw("same axis y+");
183  canvas->SaveAs("radlenColor.png");
184 
186  canvas->SetName("dedx_rz");
187  canvas->SetTitle("-dE/dx term - RZ view");
188  canvas->GetFrame()->SetFillColor(kWhite);
189  dedx->Draw("colz");
190  dedx->Draw("same axis y+");
191  dedx->SaveAs("dedx.root");
192  canvas->SaveAs("dedx.png");
193  canvas->Clear();
194  gStyle->SetNumberContours(100);
195  gStyle->SetPalette(100, MyPalette); // ROOT Rainbow color palette
196  dedx->Draw("colz");
197  dedx->Draw("same axis y+");
198  canvas->SaveAs("dedxColor.png");
199 
201  canvas->SetName("layer_rz");
202  canvas->SetTitle("Layers - RZ view");
203  canvas->GetFrame()->SetFillColor(kWhite);
204  gStyle->SetOptStat(0);
205  gStyle->SetPalette(m_color.size(), &m_color.front());
206  gStyle->SetNumberContours(m_color.size());
207  colormap->SetMinimum(1);
208  colormap->SetMaximum(m_color.size());
209  colormap->Draw("col");
210  colormap->Draw("same axis y+");
211  colormap->SaveAs("layers.root");
212  canvas->SaveAs("layers.png");
213 }
svgfig.canvas
def canvas(*sub, **attr)
Definition: svgfig.py:482
mps_fire.i
i
Definition: mps_fire.py:428
DD4hep_XHistogram::Histogram
TH2F Histogram
Definition: DD4hep_XHistogram.h:16
DD4hep_TrackingMaterialPlotter::DD4hep_TrackingMaterialPlotter
DD4hep_TrackingMaterialPlotter(float maxZ, float maxR, float resolution)
Definition: DD4hep_TrackingMaterialPlotter.cc:106
L1EGammaCrystalsEmulatorProducer_cfi.scale
scale
Definition: L1EGammaCrystalsEmulatorProducer_cfi.py:10
MaterialAccountingStep.h
DD4hep_TrackingMaterialPlotter::fill_gradient
unsigned int fill_gradient(const TColor &first, const TColor &last, unsigned int steps=100, unsigned int index=0)
Definition: DD4hep_TrackingMaterialPlotter.cc:73
step
step
Definition: StallMonitor.cc:94
DD4hep_XHistogram::ColorMap
TH2I ColorMap
Definition: DD4hep_XHistogram.h:15
DD4hep_TrackingMaterialPlotter::m_color
std::vector< int > m_color
Definition: DD4hep_TrackingMaterialPlotter.h:31
DD4hep_XHistogram.h
hitfit::delta_r
double delta_r(const Fourvec &a, const Fourvec &b)
Find the distance between two four-vectors in the two-dimensional space .
Definition: fourvec.cc:238
diffTwoXMLs.g1
g1
Definition: diffTwoXMLs.py:52
b2
static constexpr float b2
Definition: L1EGammaCrystalsEmulatorProducer.cc:82
DD4hep_XHistogram::get
Histogram * get(size_t h=0) const
access one of the histograms
Definition: DD4hep_XHistogram.h:87
DD4hep_TrackingMaterialPlotter::fill_color
void fill_color()
Definition: DD4hep_TrackingMaterialPlotter.cc:14
dqmdumpme.first
first
Definition: dqmdumpme.py:55
DD4hep_TrackingMaterialPlotter::plotSegmentInLayer
void plotSegmentInLayer(const MaterialAccountingStep &step, int layer)
Definition: DD4hep_TrackingMaterialPlotter.cc:136
DivergingColor.red
list red
Definition: DivergingColor.py:172
CosmicsPD_Skims.maxZ
maxZ
Definition: CosmicsPD_Skims.py:136
b1
static constexpr float b1
Definition: L1EGammaCrystalsEmulatorProducer.cc:82
dqmdumpme.last
last
Definition: dqmdumpme.py:56
DD4hep_TrackingMaterialPlotter.h
w
const double w
Definition: UKUtility.cc:23
DD4hep_XHistogram
Definition: DD4hep_XHistogram.h:13
L1TObjectsTimingClient_cff.resolution
resolution
Definition: L1TObjectsTimingClient_cff.py:52
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
DD4hep_TrackingMaterialPlotter::m_gradient
std::vector< int > m_gradient
Definition: DD4hep_TrackingMaterialPlotter.h:32
diffTwoXMLs.r2
r2
Definition: diffTwoXMLs.py:73
createfilelist.int
int
Definition: createfilelist.py:10
DivergingColor.blue
list blue
Definition: DivergingColor.py:173
DD4hep_TrackingMaterialPlotter::plotSegmentUnassigned
void plotSegmentUnassigned(const MaterialAccountingStep &step)
Definition: DD4hep_TrackingMaterialPlotter.cc:125
DD4hep_XHistogram::fill
void fill(double x, double y, const std::vector< double > &weight, double norm)
fill one point
Definition: DD4hep_XHistogram.cc:70
diffTwoXMLs.g2
g2
Definition: diffTwoXMLs.py:71
DD4hep_TrackingMaterialPlotter::m_tracker
DD4hep_XHistogram m_tracker
Definition: DD4hep_TrackingMaterialPlotter.h:29
DD4hep_XHistogram::colormap
ColorMap * colormap(void) const
access the colormap
Definition: DD4hep_XHistogram.h:98
MaterialAccountingStep
Definition: MaterialAccountingStep.h:9
diffTwoXMLs.r1
r1
Definition: diffTwoXMLs.py:53
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
customisers.steps
steps
Definition: customisers.py:40
DD4hep_TrackingMaterialPlotter::draw
void draw(void)
Definition: DD4hep_TrackingMaterialPlotter.cc:147