NPtGainDisplayer.cpp

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

Generated on Mon Feb 6 14:01:24 2006 for SCT DAQ/DCS Software - C++ by  doxygen 1.4.6