CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_4/src/SimTracker/TrackerMaterialAnalysis/plugins/TrackingMaterialPlotter.cc

Go to the documentation of this file.
00001 #include <iostream>
00002 
00003 #include <TROOT.h>
00004 #include <TObjArray.h>
00005 #include <TColor.h>
00006 #include <TStyle.h>
00007 #include <TCanvas.h>
00008 #include <TFrame.h>
00009 #include "XHistogram.h"
00010 #include "TrackingMaterialPlotter.h"
00011 
00012 #include "SimDataFormats/ValidationFormats/interface/MaterialAccountingStep.h"
00013 
00014 void TrackingMaterialPlotter::fill_color(void)
00015 {
00016   m_color.push_back(kBlack);          // unassigned
00017   m_color.push_back(kBlue);           // PixelBarrel
00018   m_color.push_back(kBlue  + 100);    //
00019   m_color.push_back(kBlue);           //
00020   m_color.push_back(kGreen);          // TIB
00021   m_color.push_back(kGreen + 100);    //
00022   m_color.push_back(kGreen);          //
00023   m_color.push_back(kGreen + 100);    //
00024   m_color.push_back(kRed);            // TOB
00025   m_color.push_back(kRed   + 100);    //
00026   m_color.push_back(kRed);            //
00027   m_color.push_back(kRed   + 100);    //
00028   m_color.push_back(kRed);            //
00029   m_color.push_back(kRed   + 100);    //
00030   m_color.push_back(kBlue);           // PixelEndcap Z-
00031   m_color.push_back(kBlue  + 100);    //
00032   m_color.push_back(kGreen);          // TID Z-
00033   m_color.push_back(kGreen + 100);    //
00034   m_color.push_back(kGreen);          //
00035   m_color.push_back(kRed);            // TEC Z-
00036   m_color.push_back(kRed   + 100);    //
00037   m_color.push_back(kRed);            //
00038   m_color.push_back(kRed   + 100);    //
00039   m_color.push_back(kRed);            //
00040   m_color.push_back(kRed   + 100);    //
00041   m_color.push_back(kRed);            //
00042   m_color.push_back(kRed   + 100);    //
00043   m_color.push_back(kRed);            //
00044   m_color.push_back(kBlue);           // PixelEndcap Z+
00045   m_color.push_back(kBlue  + 100);    //
00046   m_color.push_back(kGreen);          // TID Z+
00047   m_color.push_back(kGreen + 100);    //
00048   m_color.push_back(kGreen);          //
00049   m_color.push_back(kRed);            // TEC Z+
00050   m_color.push_back(kRed   + 100);    //
00051   m_color.push_back(kRed);            //
00052   m_color.push_back(kRed   + 100);    //
00053   m_color.push_back(kRed);            //
00054   m_color.push_back(kRed   + 100);    //
00055   m_color.push_back(kRed);            //
00056   m_color.push_back(kRed   + 100);    //
00057   m_color.push_back(kRed);            //
00058 }
00059 
00060 
00061 unsigned int TrackingMaterialPlotter::fill_gradient(const TColor & first, const TColor & last, unsigned int steps /*= 100*/, unsigned int index /* = 0*/)
00062 {
00063   if (index == 0) {
00064     // if no index was given, find the highest used one and start from that plus one
00065     index = ((TObjArray*) gROOT->GetListOfColors())->GetLast() + 1;
00066   }
00067 
00068   float r1, g1, b1, r2, g2, b2;
00069   first.GetRGB(r1, g1, b1);
00070   last.GetRGB(r2, g2, b2);
00071   float delta_r = (r2 - r1) / (steps - 1);
00072   float delta_g = (g2 - g1) / (steps - 1);
00073   float delta_b = (b2 - b1) / (steps - 1);
00074 
00075   m_gradient.resize(steps);
00076   for (unsigned int i = 0; i < steps; ++i) {
00077     new TColor(index + i, r1 + delta_r * i, g1 + delta_g * i, b1 + delta_b * i);
00078     m_gradient[i] = index + i;
00079   }
00080 
00081   return index;
00082 }
00083 
00084 unsigned int TrackingMaterialPlotter::fill_gradient(unsigned int first, unsigned int last, unsigned int steps /*= 100*/, unsigned int index /* = 0*/)
00085 {
00086   return fill_gradient(* (TColor *) gROOT->GetListOfColors()->At(first), * (TColor *) gROOT->GetListOfColors()->At(last), steps, index);
00087 }
00088 
00089 TrackingMaterialPlotter::TrackingMaterialPlotter( float maxZ, float maxR, float resolution )
00090 {
00091   const float rzMinZ  = -maxZ;
00092   const float rzMaxZ  =  maxZ;
00093   const float rzMinR  =    0.;
00094   const float rzMaxR  =  maxR;
00095   const int   rzBinsZ = (int) (2. * maxZ * resolution);
00096   const int   rzBinsR = (int) (     maxR * resolution);
00097 
00098   std::vector<double> max;
00099   max.push_back( 0.02 );
00100   max.push_back( 0.04 );
00101   m_tracker = XHistogram( 2, rzBinsZ, rzBinsR, std::make_pair(rzMinZ, rzMaxZ), std::make_pair(rzMinR, rzMaxR), m_color.size(), max);
00102 
00103   TColor::InitializeColors();
00104   fill_color();
00105   fill_gradient( kWhite, kBlack, 100);              // 100-steps gradient from white to black
00106 }
00107 
00108 void TrackingMaterialPlotter::plotSegmentUnassigned( const MaterialAccountingStep & step )
00109 {
00110   std::vector<double> w(2);
00111   w[0] = step.radiationLengths();
00112   w[1] = step.energyLoss();
00113   m_tracker.fill( std::make_pair(step.in().z(), step.out().z()),
00114                   std::make_pair(step.in().perp(), step.out().perp()),
00115                   w, step.length(), 1 );             // 0 is empty, 1 is unassigned
00116 }
00117 
00118 void TrackingMaterialPlotter::plotSegmentInLayer( const MaterialAccountingStep & step, int layer )
00119 {
00120   std::vector<double> w(2);
00121   w[0] = step.radiationLengths();
00122   w[1] = step.energyLoss();
00123   m_tracker.fill( std::make_pair(step.in().z(), step.out().z()),
00124                   std::make_pair(step.in().perp(), step.out().perp()),
00125                   w, step.length(), layer+1 );       // layer is 1-based, but plot uses: 0 is empty, 1 is unassigned
00126 }
00127 
00128 
00129 void TrackingMaterialPlotter::draw( void )
00130 {
00131   const double scale = 10.;
00132   TCanvas* canvas;
00133 
00134   XHistogram::Histogram* radlen = m_tracker.get(0);
00135   canvas = new TCanvas("radlen_rz", "RadiationLengths - RZ view", (int) (600 * scale * 1.25),  (int) (120 * scale * 1.50));
00136   gStyle->SetOptStat(0);
00137   gStyle->SetPalette( m_gradient.size(), & m_gradient.front() );
00138   gStyle->SetNumberContours( m_gradient.size() );
00139   canvas->GetFrame()->SetFillColor(kWhite);
00140   radlen->Draw("colz");
00141   radlen->Draw("same axis y+");
00142   canvas->SaveAs("radlen.png");
00143   delete canvas;
00144 
00145   XHistogram::Histogram* dedx = m_tracker.get(1);
00146   canvas = new TCanvas("dedx_rz", "-dE/dx term - RZ view", (int) (600 * scale * 1.25),  (int) (120 * scale * 1.50));
00147   canvas->GetFrame()->SetFillColor(kWhite);
00148   gStyle->SetOptStat(0);
00149   gStyle->SetPalette( m_gradient.size(), & m_gradient.front() );
00150   gStyle->SetNumberContours( m_gradient.size() );
00151   dedx->Draw("colz");
00152   dedx->Draw("same axis y+");
00153   canvas->SaveAs("dedx.png");
00154   delete canvas;
00155 
00156   XHistogram::ColorMap* colormap = m_tracker.colormap();
00157   canvas = new TCanvas("layer_rz", "Layers - RZ view", (int) (600 * scale * 1.25),  (int) (120 * scale * 1.50));
00158   canvas->GetFrame()->SetFillColor(kWhite);
00159   gStyle->SetOptStat(0);
00160   gStyle->SetPalette( m_color.size(), & m_color.front() );
00161   gStyle->SetNumberContours( m_color.size() );
00162   colormap->SetMinimum( 1 );
00163   colormap->SetMaximum( m_color.size() );
00164   colormap->Draw("col");
00165   colormap->Draw("same axis y+");
00166   canvas->SaveAs("layers.png");
00167   delete canvas;
00168 }
00169