CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 "XHistogram.h"
11 
13 
15 {
16  m_color.push_back(kBlack); // unassigned
17  m_color.push_back(kBlue); // PixelBarrel
18  m_color.push_back(kBlue + 100); //
19  m_color.push_back(kBlue); //
20  m_color.push_back(kGreen); // TIB
21  m_color.push_back(kGreen + 100); //
22  m_color.push_back(kGreen); //
23  m_color.push_back(kGreen + 100); //
24  m_color.push_back(kRed); // TOB
25  m_color.push_back(kRed + 100); //
26  m_color.push_back(kRed); //
27  m_color.push_back(kRed + 100); //
28  m_color.push_back(kRed); //
29  m_color.push_back(kRed + 100); //
30  m_color.push_back(kBlue); // PixelEndcap Z-
31  m_color.push_back(kBlue + 100); //
32  m_color.push_back(kGreen); // TID Z-
33  m_color.push_back(kGreen + 100); //
34  m_color.push_back(kGreen); //
35  m_color.push_back(kRed); // TEC Z-
36  m_color.push_back(kRed + 100); //
37  m_color.push_back(kRed); //
38  m_color.push_back(kRed + 100); //
39  m_color.push_back(kRed); //
40  m_color.push_back(kRed + 100); //
41  m_color.push_back(kRed); //
42  m_color.push_back(kRed + 100); //
43  m_color.push_back(kRed); //
44  m_color.push_back(kBlue); // PixelEndcap Z+
45  m_color.push_back(kBlue + 100); //
46  m_color.push_back(kGreen); // TID Z+
47  m_color.push_back(kGreen + 100); //
48  m_color.push_back(kGreen); //
49  m_color.push_back(kRed); // TEC Z+
50  m_color.push_back(kRed + 100); //
51  m_color.push_back(kRed); //
52  m_color.push_back(kRed + 100); //
53  m_color.push_back(kRed); //
54  m_color.push_back(kRed + 100); //
55  m_color.push_back(kRed); //
56  m_color.push_back(kRed + 100); //
57  m_color.push_back(kRed); //
58 }
59 
60 
61 unsigned int TrackingMaterialPlotter::fill_gradient(const TColor & first, const TColor & last, unsigned int steps /*= 100*/, unsigned int index /* = 0*/)
62 {
63  if (index == 0) {
64  // if no index was given, find the highest used one and start from that plus one
65  index = ((TObjArray*) gROOT->GetListOfColors())->GetLast() + 1;
66  }
67 
68  float r1, g1, b1, r2, g2, b2;
69  first.GetRGB(r1, g1, b1);
70  last.GetRGB(r2, g2, b2);
71  float delta_r = (r2 - r1) / (steps - 1);
72  float delta_g = (g2 - g1) / (steps - 1);
73  float delta_b = (b2 - b1) / (steps - 1);
74 
75  m_gradient.resize(steps);
76  for (unsigned int i = 0; i < steps; ++i) {
77  new TColor(index + i, r1 + delta_r * i, g1 + delta_g * i, b1 + delta_b * i);
78  m_gradient[i] = index + i;
79  }
80 
81  return index;
82 }
83 
84 unsigned int TrackingMaterialPlotter::fill_gradient(unsigned int first, unsigned int last, unsigned int steps /*= 100*/, unsigned int index /* = 0*/)
85 {
86  return fill_gradient(* (TColor *) gROOT->GetListOfColors()->At(first), * (TColor *) gROOT->GetListOfColors()->At(last), steps, index);
87 }
88 
90 {
91  const float rzMinZ = -maxZ;
92  const float rzMaxZ = maxZ;
93  const float rzMinR = 0.;
94  const float rzMaxR = maxR;
95  const int rzBinsZ = (int) (2. * maxZ * resolution);
96  const int rzBinsR = (int) ( maxR * resolution);
97 
98  std::vector<double> max;
99  max.push_back( 0.02 );
100  max.push_back( 0.04 );
101  m_tracker = XHistogram( 2, rzBinsZ, rzBinsR, std::make_pair(rzMinZ, rzMaxZ), std::make_pair(rzMinR, rzMaxR), m_color.size(), max);
102 
103  TColor::InitializeColors();
104  fill_color();
105  fill_gradient( kWhite, kBlack, 100); // 100-steps gradient from white to black
106 }
107 
109 {
110  std::vector<double> w(2);
111  w[0] = step.radiationLengths();
112  w[1] = step.energyLoss();
113  m_tracker.fill( std::make_pair(step.in().z(), step.out().z()),
114  std::make_pair(step.in().perp(), step.out().perp()),
115  w, step.length(), 1 ); // 0 is empty, 1 is unassigned
116 }
117 
119 {
120  std::vector<double> w(2);
121  w[0] = step.radiationLengths();
122  w[1] = step.energyLoss();
123  m_tracker.fill( std::make_pair(step.in().z(), step.out().z()),
124  std::make_pair(step.in().perp(), step.out().perp()),
125  w, step.length(), layer+1 ); // layer is 1-based, but plot uses: 0 is empty, 1 is unassigned
126 }
127 
128 
130 {
131  const double scale = 10.;
132  TCanvas* canvas;
133 
134  XHistogram::Histogram* radlen = m_tracker.get(0);
135  canvas = new TCanvas("radlen_rz", "RadiationLengths - RZ view", (int) (600 * scale * 1.25), (int) (120 * scale * 1.50));
136  gStyle->SetOptStat(0);
137  gStyle->SetPalette( m_gradient.size(), & m_gradient.front() );
138  gStyle->SetNumberContours( m_gradient.size() );
139  canvas->GetFrame()->SetFillColor(kWhite);
140  radlen->Draw("colz");
141  radlen->Draw("same axis y+");
142  canvas->SaveAs("radlen.png");
143  delete canvas;
144 
146  canvas = new TCanvas("dedx_rz", "-dE/dx term - RZ view", (int) (600 * scale * 1.25), (int) (120 * scale * 1.50));
147  canvas->GetFrame()->SetFillColor(kWhite);
148  gStyle->SetOptStat(0);
149  gStyle->SetPalette( m_gradient.size(), & m_gradient.front() );
150  gStyle->SetNumberContours( m_gradient.size() );
151  dedx->Draw("colz");
152  dedx->Draw("same axis y+");
153  canvas->SaveAs("dedx.png");
154  delete canvas;
155 
157  canvas = new TCanvas("layer_rz", "Layers - RZ view", (int) (600 * scale * 1.25), (int) (120 * scale * 1.50));
158  canvas->GetFrame()->SetFillColor(kWhite);
159  gStyle->SetOptStat(0);
160  gStyle->SetPalette( m_color.size(), & m_color.front() );
161  gStyle->SetNumberContours( m_color.size() );
162  colormap->SetMinimum( 1 );
163  colormap->SetMaximum( m_color.size() );
164  colormap->Draw("col");
165  colormap->Draw("same axis y+");
166  canvas->SaveAs("layers.png");
167  delete canvas;
168 }
169 
void plotSegmentUnassigned(const MaterialAccountingStep &step)
int i
Definition: DBlmapReader.cc:9
ColorMap * colormap(void) const
access the colormap
Definition: XHistogram.h:104
T perp() const
Definition: PV3DBase.h:72
const double w
Definition: UKUtility.cc:23
TH2F Histogram
Definition: XHistogram.h:17
double length(void) const
double radiationLengths(void) const
Histogram * get(size_t h=0) const
access one of the histograms
Definition: XHistogram.h:89
double energyLoss(void) const
def canvas
Definition: svgfig.py:481
TrackingMaterialPlotter(float maxZ, float maxR, float resolution)
T z() const
Definition: PV3DBase.h:64
double delta_r(const Fourvec &a, const Fourvec &b)
Find the distance between two four-vectors in the two-dimensional space .
Definition: fourvec.cc:249
bool first
Definition: L1TdeRCT.cc:75
unsigned int fill_gradient(const TColor &first, const TColor &last, unsigned int steps=100, unsigned int index=0)
const GlobalPoint & out(void) const
TH2I ColorMap
Definition: XHistogram.h:16
void plotSegmentInLayer(const MaterialAccountingStep &step, int layer)
void fill(double x, double y, const std::vector< double > &weight, double norm)
fill one point
Definition: XHistogram.cc:71
const GlobalPoint & in(void) const