Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:30:44

0001 #include <iostream>
0002 
0003 #include <TROOT.h>
0004 #include <TObjArray.h>
0005 #include <TColor.h>
0006 #include <TStyle.h>
0007 #include <TCanvas.h>
0008 #include <TFrame.h>
0009 #include "XHistogram.h"
0010 #include "TrackingMaterialPlotter.h"
0011 
0012 #include "SimDataFormats/ValidationFormats/interface/MaterialAccountingStep.h"
0013 
0014 void TrackingMaterialPlotter::fill_color(void) {
0015   m_color.push_back(kBlack);        // unassigned
0016   m_color.push_back(kAzure);        // PixelBarrel
0017   m_color.push_back(kAzure + 1);    //
0018   m_color.push_back(kAzure + 1);    //
0019   m_color.push_back(kAzure + 3);    //
0020   m_color.push_back(kAzure + 3);    //
0021   m_color.push_back(kGreen);        // TIB
0022   m_color.push_back(kGreen);        //
0023   m_color.push_back(kGreen + 2);    //
0024   m_color.push_back(kGreen + 2);    //
0025   m_color.push_back(kGreen - 3);    //
0026   m_color.push_back(kGreen - 3);    //
0027   m_color.push_back(kGreen - 1);    //
0028   m_color.push_back(kGreen - 1);    //
0029   m_color.push_back(kRed);          // TOB
0030   m_color.push_back(kRed);          //
0031   m_color.push_back(kRed);          //
0032   m_color.push_back(kRed + 3);      //
0033   m_color.push_back(kRed + 3);      //
0034   m_color.push_back(kRed + 3);      //
0035   m_color.push_back(kRed - 3);      //
0036   m_color.push_back(kRed - 3);      //
0037   m_color.push_back(kRed - 3);      //
0038   m_color.push_back(kOrange + 9);   //
0039   m_color.push_back(kOrange + 9);   //
0040   m_color.push_back(kOrange + 9);   //
0041   m_color.push_back(kOrange + 7);   //
0042   m_color.push_back(kOrange + 7);   //
0043   m_color.push_back(kOrange + 7);   //
0044   m_color.push_back(kOrange + 5);   //
0045   m_color.push_back(kOrange + 5);   //
0046   m_color.push_back(kOrange + 5);   //
0047   m_color.push_back(kOrange + 8);   // PixelEndcap Z-
0048   m_color.push_back(kOrange + 10);  //
0049   m_color.push_back(kOrange - 3);   //
0050   m_color.push_back(kOrange - 1);   // PixelEndcap Z+
0051   m_color.push_back(kOrange - 8);   //
0052   m_color.push_back(kYellow);       // TID Z-
0053   m_color.push_back(kYellow);       //
0054   m_color.push_back(kYellow + 2);   //
0055   m_color.push_back(kYellow + 2);   //
0056   m_color.push_back(kYellow + 2);   //
0057   m_color.push_back(kYellow + 3);   //
0058   m_color.push_back(kMagenta);      //
0059   m_color.push_back(kMagenta);      //
0060   m_color.push_back(kMagenta);      //
0061   m_color.push_back(kMagenta);      //
0062   m_color.push_back(kMagenta);      //
0063   m_color.push_back(kMagenta + 1);  //
0064   m_color.push_back(kMagenta + 2);  //
0065   m_color.push_back(kMagenta + 3);  //
0066   m_color.push_back(kMagenta + 4);  //
0067   m_color.push_back(kMagenta + 5);  //
0068   m_color.push_back(kMagenta + 6);  //
0069   m_color.push_back(kMagenta + 7);  //
0070   m_color.push_back(kMagenta + 8);  //
0071 }
0072 
0073 unsigned int TrackingMaterialPlotter::fill_gradient(const TColor& first,
0074                                                     const TColor& last,
0075                                                     unsigned int steps /*= 100*/,
0076                                                     unsigned int index /* = 0*/) {
0077   if (index == 0) {
0078     // if no index was given, find the highest used one and start from that plus one
0079     index = ((TObjArray*)gROOT->GetListOfColors())->GetLast() + 1;
0080   }
0081 
0082   float r1, g1, b1, r2, g2, b2;
0083   first.GetRGB(r1, g1, b1);
0084   last.GetRGB(r2, g2, b2);
0085   float delta_r = (r2 - r1) / (steps - 1);
0086   float delta_g = (g2 - g1) / (steps - 1);
0087   float delta_b = (b2 - b1) / (steps - 1);
0088 
0089   m_gradient.resize(steps);
0090   for (unsigned int i = 0; i < steps; ++i) {
0091     new TColor(static_cast<Int_t>(index + i), r1 + delta_r * i, g1 + delta_g * i, b1 + delta_b * i);
0092     m_gradient[i] = index + i;
0093   }
0094 
0095   return index;
0096 }
0097 
0098 unsigned int TrackingMaterialPlotter::fill_gradient(unsigned int first,
0099                                                     unsigned int last,
0100                                                     unsigned int steps /*= 100*/,
0101                                                     unsigned int index /* = 0*/) {
0102   return fill_gradient(
0103       *(TColor*)gROOT->GetListOfColors()->At(first), *(TColor*)gROOT->GetListOfColors()->At(last), steps, index);
0104 }
0105 
0106 TrackingMaterialPlotter::TrackingMaterialPlotter(float maxZ, float maxR, float resolution) {
0107   const float rzMinZ = -maxZ;
0108   const float rzMaxZ = maxZ;
0109   const float rzMinR = 0.;
0110   const float rzMaxR = maxR;
0111   const int rzBinsZ = (int)(2. * maxZ * resolution);
0112   const int rzBinsR = (int)(maxR * resolution);
0113 
0114   std::vector<double> max;
0115   max.push_back(0.08);
0116   max.push_back(0.00016);
0117   m_tracker = XHistogram(
0118       2, rzBinsZ, rzBinsR, std::make_pair(rzMinZ, rzMaxZ), std::make_pair(rzMinR, rzMaxR), m_color.size(), max);
0119 
0120   TColor::InitializeColors();
0121   fill_color();
0122   fill_gradient(kWhite, kBlack, 100);  // 100-steps gradient from white to black
0123 }
0124 
0125 void TrackingMaterialPlotter::plotSegmentUnassigned(const MaterialAccountingStep& step) {
0126   std::vector<double> w(2);
0127   w[0] = step.radiationLengths();
0128   w[1] = step.energyLoss();
0129   m_tracker.fill(std::make_pair(step.in().z(), step.out().z()),
0130                  std::make_pair(step.in().perp(), step.out().perp()),
0131                  w,
0132                  step.length(),
0133                  1);  // 0 is empty, 1 is unassigned
0134 }
0135 
0136 void TrackingMaterialPlotter::plotSegmentInLayer(const MaterialAccountingStep& step, int layer) {
0137   std::vector<double> w(2);
0138   w[0] = step.radiationLengths();
0139   w[1] = step.energyLoss();
0140   m_tracker.fill(std::make_pair(step.in().z(), step.out().z()),
0141                  std::make_pair(step.in().perp(), step.out().perp()),
0142                  w,
0143                  step.length(),
0144                  layer + 1);  // layer is 1-based, but plot uses: 0 is empty, 1 is unassigned
0145 }
0146 
0147 void TrackingMaterialPlotter::draw(void) {
0148   const double scale = 10.;
0149   TCanvas* canvas;
0150 
0151   XHistogram::Histogram* radlen = m_tracker.get(0);
0152   canvas = new TCanvas("radlen_rz", "RadiationLengths - RZ view", (int)(600 * scale * 1.25), (int)(120 * scale * 1.50));
0153   gStyle->SetOptStat(0);
0154   gStyle->SetPalette(m_gradient.size(), &m_gradient.front());
0155   gStyle->SetNumberContours(m_gradient.size());
0156   canvas->GetFrame()->SetFillColor(kWhite);
0157   radlen->Draw("colz");
0158   radlen->Draw("same axis y+");
0159   radlen->SaveAs("radlen.root");
0160   canvas->SaveAs("radlen.png");
0161   // Replicate RainBow palette, with White in the first white_slots
0162   // positions
0163   int white_slots = 1;
0164   int MyPalette[100];
0165   double stops[9] = {0.0000, 0.1250, 0.2500, 0.3750, 0.5000, 0.6250, 0.7500, 0.8750, 1.0000};
0166   double red[9] = {
0167       0. / 255., 5. / 255., 15. / 255., 35. / 255., 102. / 255., 196. / 255., 208. / 255., 199. / 255., 110. / 255.};
0168   double green[9] = {
0169       0. / 255., 48. / 255., 124. / 255., 192. / 255., 206. / 255., 226. / 255., 97. / 255., 16. / 255., 0. / 255.};
0170   double blue[9] = {
0171       99. / 255., 142. / 255., 198. / 255., 201. / 255., 90. / 255., 22. / 255., 13. / 255., 8. / 255., 2. / 255.};
0172   int palette_index = TColor::CreateGradientColorTable(9, stops, red, green, blue, 100 - white_slots);
0173   for (int i = 0; i < white_slots; i++)
0174     MyPalette[i] = kWhite;
0175   for (int i = 0; i < 100 - white_slots; i++)
0176     MyPalette[i + white_slots] = palette_index + i;
0177   canvas->Clear();
0178   gStyle->SetNumberContours(100);
0179   gStyle->SetPalette(100, MyPalette);  // ROOT Rainbow color palette
0180   radlen->Draw("colz");
0181   radlen->Draw("same axis y+");
0182   canvas->SaveAs("radlenColor.png");
0183 
0184   delete canvas;
0185 
0186   XHistogram::Histogram* dedx = m_tracker.get(1);
0187   canvas = new TCanvas("dedx_rz", "-dE/dx term - RZ view", (int)(600 * scale * 1.25), (int)(120 * scale * 1.50));
0188   canvas->GetFrame()->SetFillColor(kWhite);
0189   gStyle->SetOptStat(0);
0190   gStyle->SetPalette(m_gradient.size(), &m_gradient.front());
0191   gStyle->SetNumberContours(m_gradient.size());
0192   dedx->Draw("colz");
0193   dedx->Draw("same axis y+");
0194   dedx->SaveAs("dedx.root");
0195   canvas->SaveAs("dedx.png");
0196   canvas->Clear();
0197   gStyle->SetNumberContours(100);
0198   gStyle->SetPalette(100, MyPalette);  // ROOT Rainbow color palette
0199   dedx->Draw("colz");
0200   dedx->Draw("same axis y+");
0201   canvas->SaveAs("dedxColor.png");
0202   delete canvas;
0203 
0204   XHistogram::ColorMap* colormap = m_tracker.colormap();
0205   canvas = new TCanvas("layer_rz", "Layers - RZ view", (int)(600 * scale * 1.25), (int)(120 * scale * 1.50));
0206   canvas->GetFrame()->SetFillColor(kWhite);
0207   gStyle->SetOptStat(0);
0208   gStyle->SetPalette(m_color.size(), &m_color.front());
0209   gStyle->SetNumberContours(m_color.size());
0210   colormap->SetMinimum(1);
0211   colormap->SetMaximum(m_color.size());
0212   colormap->Draw("col");
0213   colormap->Draw("same axis y+");
0214   colormap->SaveAs("layers.root");
0215   canvas->SaveAs("layers.png");
0216   delete canvas;
0217 }