00001 #include "MarkSpaceRatioDisplayer.h" 00002 #include "DisplayManager.h" 00003 #include "DisplayInfo.h" 00004 00005 #include "SctData/MarkSpaceRatioTestResult.h" 00006 #include "SctData/DefectList.h" 00007 00008 #include "TH2.h" 00009 #include "TGraph.h" 00010 #include "TCanvas.h" 00011 #include "TLatex.h" 00012 #include "TLine.h" 00013 #include "TLegend.h" 00014 #include "TStyle.h" 00015 #include <string> 00016 #include <boost/shared_ptr.hpp> 00017 00018 using namespace std; 00019 using namespace SctData; 00020 using namespace Sct; 00021 using namespace boost; 00022 00023 namespace SctDataDisplay { 00024 00025 00026 class MarkSpaceRatioDisplayData : public DisplayData { 00027 public: 00028 vector<shared_ptr<TObject> > obs; 00029 }; 00030 00031 bool MarkSpaceRatioDisplayer::inMap = DisplayManager::addToMap("SctData::MarkSpaceRatioTestResult", shared_ptr<Displayer>(new MarkSpaceRatioDisplayer())); 00032 00033 00034 shared_ptr<DisplayData> MarkSpaceRatioDisplayer::display(shared_ptr<const Sct::Serializable> serial, const DisplayInfo& info, std::ostream& os) { 00035 shared_ptr<MarkSpaceRatioDisplayData> data (new MarkSpaceRatioDisplayData()); 00036 shared_ptr<const MarkSpaceRatioTestResult> test 00037 = dynamic_pointer_cast<const MarkSpaceRatioTestResult>(serial); 00038 00039 shared_ptr<TCanvas> canvas (createCanvas(test->getUniqueID(),test->getUniqueID())); 00040 data->obs.push_back(canvas); 00041 canvas->Divide(1,2); 00042 00043 shared_ptr<TGraph> g0 (new TGraph()); 00044 shared_ptr<TGraph> g1 (new TGraph()); 00045 shared_ptr<TGraph> g0flip (new TGraph()); 00046 shared_ptr<TGraph> g1flip (new TGraph()); 00047 00048 shared_ptr<TGraph> g0diff (new TGraph()); 00049 shared_ptr<TGraph> g1diff (new TGraph()); 00050 00051 data->obs.push_back(g0); 00052 data->obs.push_back(g1); 00053 00054 data->obs.push_back(g0flip); 00055 data->obs.push_back(g1flip); 00056 00057 data->obs.push_back(g0diff); 00058 data->obs.push_back(g1diff); 00059 00060 const unsigned & n=test->getNPoints(); 00061 g0->Set(n); 00062 g1->Set(n); 00063 g0flip->Set(n); 00064 g1flip->Set(n); 00065 00066 g0diff->Set(n); 00067 g1diff->Set(n); 00068 00069 double ymin=1.E12; 00070 double ymax=0.; 00071 00072 double xmin=0.; 00073 double xmax=0.; 00074 00075 double diffmin=0.; 00076 double diffmax=0.; 00077 00078 for (unsigned i=0 ; i<n; ++i){ 00079 const MarkSpaceRatioTestResult::MsrPoint& p = test->getPoint(i); 00080 g0->SetPoint(i, p.msr, p.occ0); 00081 g1->SetPoint(i, p.msr, p.occ1); 00082 00083 g0flip->SetPoint(i, p.msr, p.occ0flip); 00084 g1flip->SetPoint(i, p.msr, p.occ1flip); 00085 00086 double diff0=p.occ0-p.occ0flip; 00087 double diff1=p.occ1-p.occ1flip; 00088 00089 g0diff->SetPoint(i, p.msr, diff0); 00090 g1diff->SetPoint(i, p.msr, diff1); 00091 00092 if (p.occ0>ymax) ymax=p.occ0; 00093 if (p.occ1>ymax) ymax=p.occ1; 00094 if (p.occ0flip>ymax) ymax=p.occ0flip; 00095 if (p.occ1flip>ymax) ymax=p.occ1flip; 00096 00097 if (p.occ0<ymin) ymin=p.occ0; 00098 if (p.occ1<ymin) ymin=p.occ1; 00099 if (p.occ0flip<ymin) ymin=p.occ0flip; 00100 if (p.occ1flip<ymin) ymin=p.occ1flip; 00101 00102 if (p.msr>xmax) xmax=p.msr; 00103 if (p.msr<xmin) xmin=p.msr; 00104 00105 if (diff0>diffmax) diffmax=diff0; 00106 if (diff1>diffmax) diffmax=diff1; 00107 00108 if (diff0<diffmin) diffmin=diff0; 00109 if (diff1<diffmin) diffmin=diff1; 00110 } 00111 00112 canvas->cd(1); 00113 00114 gStyle->SetTitleX(0.7); 00115 00116 string name=test->getUniqueID(); 00117 shared_ptr<TH2> hist1(new TH2D(name.c_str(),"Mark:Space ratio",2,xmin,xmax,2,ymin,ymax)); 00118 hist1->SetXTitle("MSR register"); 00119 hist1->SetYTitle("Duty Cycle"); 00120 hist1->GetXaxis()->SetLabelSize(0.05); 00121 hist1->GetXaxis()->SetTitleSize(0.05); 00122 hist1->GetYaxis()->SetLabelSize(0.05); 00123 hist1->GetYaxis()->SetTitleSize(0.05); 00124 hist1->Draw(); 00125 00126 data->obs.push_back(hist1); 00127 00128 g0->SetLineColor(2); 00129 g0->SetMarkerColor(2); 00130 g0->SetMarkerStyle(21); 00131 g0->Draw("LP"); 00132 00133 g0flip->SetLineColor(2); 00134 g0flip->SetLineStyle(2); 00135 g0flip->SetMarkerColor(2); 00136 g0flip->SetMarkerStyle(21); 00137 g0flip->Draw("LP"); 00138 00139 g1->SetLineColor(4); 00140 g1->SetMarkerColor(4); 00141 g1->SetMarkerStyle(20); 00142 g1->Draw("LP"); 00143 00144 g1flip->SetLineColor(4); 00145 g1flip->SetLineStyle(2); 00146 g1flip->SetMarkerColor(4); 00147 g1flip->SetMarkerStyle(20); 00148 g1flip->Draw("LP"); 00149 00150 shared_ptr<TLegend> legend0 (new TLegend(0.4, 0.75, 0.6, 0.99)); 00151 legend0->SetBorderSize(1); 00152 legend0->AddEntry(g0.get(),"Link 0","lp"); 00153 legend0->AddEntry(g1.get(),"Link 1","lp"); 00154 legend0->AddEntry(g0flip.get(),"Link 0 (flipped)","lp"); 00155 legend0->AddEntry(g1flip.get(),"Link 1 (flipped)","lp"); 00156 legend0->Draw(); 00157 data->obs.push_back(legend0); 00158 00159 canvas->cd(2); 00160 00161 name += "_2"; 00162 shared_ptr<TH2> hist2(new TH2D(name.c_str(),"Mark:Space ratio",2,xmin,xmax,2,diffmin,diffmax)); 00163 hist2->SetXTitle("MSR register"); 00164 hist2->SetYTitle("Change in DutyCycle"); 00165 hist2->GetXaxis()->SetLabelSize(0.05); 00166 hist2->GetXaxis()->SetTitleSize(0.05); 00167 hist2->GetYaxis()->SetLabelSize(0.05); 00168 hist2->GetYaxis()->SetTitleSize(0.05); 00169 hist2->Draw(); 00170 00171 data->obs.push_back(hist2); 00172 00173 g0diff->SetLineColor(2); 00174 g0diff->SetMarkerStyle(21); 00175 g0diff->Draw("LP"); 00176 00177 g1diff->SetLineColor(4); 00178 g1diff->SetMarkerStyle(20); 00179 g1diff->Draw("LP"); 00180 00181 char label[30]; 00182 sprintf(label,"Optimum = %5.1f", test->getOptimum()); 00183 00184 shared_ptr<TLatex> lat (new TLatex(test->getOptimum(), diffmin*0.8, label)); 00185 lat->Draw(); 00186 data->obs.push_back(lat); 00187 00188 shared_ptr<TLine> line (new TLine(xmin, 0, xmax, 0)); 00189 line->SetLineStyle(2); 00190 line->Draw(); 00191 data->obs.push_back(line); 00192 00193 shared_ptr<TLine> line2 (new TLine(test->getOptimum(), diffmin*0.68, test->getOptimum(), diffmax*0.68)); 00194 line2->SetLineColor(13); 00195 line2->Draw(); 00196 data->obs.push_back(line2); 00197 00198 shared_ptr<TLegend> legend1 (new TLegend(0.4, 0.85, 0.6, 0.99)); 00199 legend1->SetBorderSize(1); 00200 legend1->AddEntry(g0diff.get(),"Link 0","lp"); 00201 legend1->AddEntry(g1diff.get(),"Link 1","lp"); 00202 legend1->Draw(); 00203 data->obs.push_back(legend1); 00204 00205 return data; 00206 } 00207 00208 }