00001 #include "NPtGainDisplayer.h"
00002 #include "DisplayManager.h"
00003 #include "DisplayInfo.h"
00004
00005 #include "SctData/NPtGainTestResult.h"
00006 #include "SctData/FitScanResult.h"
00007 #include "SctData/ResponseCurve.h"
00008 #include "Sct/SctParameters.h"
00009
00010 #include <TGraph.h>
00011 #include <TCanvas.h>
00012 #include <TF1.h>
00013 #include <TPolyLine.h>
00014
00015 #include <algorithm>
00016
00017 using namespace Sct;
00018 using namespace SctData;
00019 using namespace std;
00020 using namespace boost;
00021
00022 namespace SctDataDisplay {
00023
00024 class NPtGainDisplayData : public DisplayData {
00025 public:
00026 vector<shared_ptr<TCanvas> > canvas;
00027 shared_ptr<const NPtGainTestResult> test;
00028 vector<shared_ptr<TF1> > funcs;
00029 vector<shared_ptr<TGraph> > graphs;
00030 vector<shared_ptr<TPolyLine> > lines;
00031 };
00032
00033 bool NPtGainDisplayer::inMap = DisplayManager::addToMap("SctData::NPtGainTestResult", shared_ptr<Displayer>(new NPtGainDisplayer()));
00034
00035
00036 shared_ptr<DisplayData> NPtGainDisplayer::display(shared_ptr<const Sct::Serializable> serial, const DisplayInfo& info, std::ostream& os) {
00037 shared_ptr<NPtGainDisplayData> data (new NPtGainDisplayData());
00038 data->test = dynamic_pointer_cast<const NPtGainTestResult>(serial);
00039
00040
00041 shared_ptr<TGraph> noise = data->test->getNoiseGraph();
00042 shared_ptr<TGraph> gain = data->test->getGainGraph();
00043 shared_ptr<TGraph> offset = data->test->getOffsetGraph();
00044
00045 data->graphs.push_back(noise);
00046 data->graphs.push_back(gain);
00047 data->graphs.push_back(offset);
00048
00049 plotData("Gain", 0, 80, *data, *gain);
00050 plotData("Noise", 0, 2500, *data, *noise);
00051 plotData("Offset", 0, 200, *data, *offset);
00052
00053 if (info.displayChips.size() > 0)
00054 displayChips(*data, info, os);
00055
00056 if (info.displayChannels.size() > 0)
00057 displayChannels(*data, info, os);
00058
00059 os << "Defects:" << std::endl;
00060 printDefectList(data->test->getDefects(), os);
00061
00062 return data;
00063 }
00064
00065 void NPtGainDisplayer::plotData(string name, double min, double max, NPtGainDisplayData& data, TGraph& graph) {
00066 std::string canvasname=(string)data.test->getHeader().getUniqueID() + "_" + name;
00067 if (DisplayManager::rootMode()){
00068 shared_ptr<TDirectory> file=DisplayManager::getTDirectory();
00069 if (file) {
00070 file->cd();
00071 graph.Write(canvasname.c_str());
00072 }
00073 }else{
00074 std::string canvasname=(string)data.test->getHeader().getUniqueID() + "_" + name;
00075 shared_ptr<TCanvas> c = createCanvas(canvasname, canvasname);
00076 data.canvas.push_back(c);
00077 graph.SetMaximum(max);
00078 graph.SetMinimum(min);
00079 graph.SetTitle(name.c_str());
00080 graph.GetXaxis()->SetLimits(0, nChannelModule);
00081 graph.GetXaxis()->SetTitle("Channel Number");
00082 graph.Draw("alp");
00083 for (unsigned int i=0; i<nChipModule; ++i) {
00084 shared_ptr<TPolyLine> p (new TPolyLine(2));
00085 data.lines.push_back(p);
00086 p->SetLineStyle(2);
00087 p->SetPoint(0, nChannelChip*i-0.5, min);
00088 p->SetPoint(1, nChannelChip*i-0.5, max);
00089 p->Draw();
00090 }
00091 }
00092 }
00093
00094 void NPtGainDisplayer::displayChips(NPtGainDisplayData& data, const DisplayInfo& info, std::ostream& os) {
00095 shared_ptr<TCanvas> c = createCanvas((string)data.test->getHeader().getUniqueID() + "_chipRC", data.test->getModuleName() + " Chip Fits");
00096 data.canvas.push_back(c);
00097 divideCanvas(info.displayChips.size(), *c);
00098 for (unsigned int i = 0; i < info.displayChips.size(); ++i) {
00099 c->cd(i + 1);
00100 displayData(data, data.test->getChipData(info.displayChips[i]));
00101 }
00102
00103
00104 os << "Chip parameters" << endl;
00105 for (unsigned int i = 0; i < 12; ++i) {
00106 shared_ptr<TF1> f = data.test->getChipData(i).rc->getFunction();
00107 os << f->GetParameter(0) << " " << f->GetParameter(1) << " " << f->GetParameter(2) << endl;
00108 }
00109 }
00110
00111 void NPtGainDisplayer::displayChannels(NPtGainDisplayData& data, const DisplayInfo& info, std::ostream& os) {
00112 shared_ptr<TCanvas> c;
00113 unsigned int nMax = min((unsigned int)25, info.displayChannels.size());
00114 int j=0;
00115
00116 for (unsigned int i=0; i<info.displayChannels.size(); ++i, ++j) {
00117 if (j%nMax == 0) {
00118 c = createCanvas((string)data.test->getUniqueID() + "_channelRC", "Channel Response Curves for module " + data.test->getModuleName());
00119 data.canvas.push_back(c);
00120 divideCanvas(nMax, *c);
00121 j=0;
00122 }
00123 c->cd(i%nMax + 1);
00124 displayData(data, data.test->getChannelData(info.displayChannels[i]));
00125 }
00126 }
00127
00128 void NPtGainDisplayer::displayData(NPtGainDisplayData& data, const NPtGainTestResultData& testData) {
00129 gPad->SetLeftMargin(0.17);
00130 gPad->SetBottomMargin(0.15);
00131 gPad->SetTopMargin(0.03);
00132 gPad->SetRightMargin(0.03);
00133 TGraph & g = *testData.graph;
00134 g.SetMarkerStyle(20);
00135 g.Draw("ap");
00136 g.GetHistogram()->SetXTitle("Q_th / fC");
00137 g.GetHistogram()->SetYTitle("V_th / mV");
00138 g.GetHistogram()->GetYaxis()->SetTitleOffset(1.2);
00139 g.GetHistogram()->GetXaxis()->SetLabelSize(0.06);
00140 g.GetHistogram()->GetYaxis()->SetLabelSize(0.06);
00141 g.GetHistogram()->GetXaxis()->SetTitleSize(0.06);
00142 g.GetHistogram()->GetYaxis()->SetTitleSize(0.06);
00143 shared_ptr<TF1> f = testData.rc->getFunction();
00144 f->SetRange(0, 8);
00145 f->SetFillStyle(0);
00146 f->Draw("same");
00147 data.funcs.push_back(f);
00148 }
00149
00150
00151 }