00001 #include "SummaryManager.h"
00002 #include "NPtGainSummaryWriter.h"
00003
00004 #include "SctData/NPtGainTestResult.h"
00005 #include "SctData/ResponseCurve.h"
00006 #include "SctData/Stat.h"
00007
00008 #include <iomanip>
00009 #include <TF1.h>
00010
00011 namespace SctData {
00012 namespace TestSummary{
00013 using namespace std;
00014
00015 void NPtGainSummaryWriter::write(const TestResult& t, ostream& out) const throw(Sct::IoError, Sct::LogicError)
00016 {
00017 t.getNScans();
00018 const NPtGainTestResult& result = dynamic_cast<const NPtGainTestResult&>(t);
00019 switch ( result.getNScans() ){
00020 case (3) : out << "%ThreePointGain" << endl; break;
00021 case (10) : out << "%ResponseCurve" << endl; break;
00022 default : out <<"%NPtGain"<<endl; break;
00023 }
00024
00025 out << "#\n#LoopA - Fit"<<endl;
00026 out << "# func p0 p1 p2" << endl;
00027 for (short unsigned ichip=0; ichip<nChipModule; ++ichip){
00028 out << "#"<<getChipName(ichip) << endl;
00029 shared_ptr<TF1> fit = result.getChipData(ichip).rc->getFunction();
00030 out << setfill(' ');
00031 out << setw(6) << result.getChipData(ichip).rc->getIndex();
00032 for (short ipar=0; ipar<fit->GetNpar(); ++ipar){
00033 out << " " << setfill(' ') << setw(6) << fit->GetParameter(ipar);
00034 }
00035 out << endl;
00036 }
00037
00049 out << "#\n#LoopB - Gain, Offset, Noise at 2.00fC"<<endl;
00050 out << "# vt50 rms gain rms offset rms outnse innse rms" << endl;
00051
00052 for (short unsigned ichip=0; ichip<nChipModule; ++ichip){
00053 Stats<float> vt50(nChannelChip);
00054 Stats<float> gain(nChannelChip);
00055 Stats<float> offset(nChannelChip);
00056 Stats<float> outnse(nChannelChip);
00057 Stats<float> innse(nChannelChip);
00058
00059 for (unsigned ichan=0; ichan<nChannelChip; ++ichan){
00060 unsigned ichannel = ichan + ichip*nChannelChip;
00061 bool valid=result.getDefects().defectSeverityEncompassingElement(ModuleElement::Channel(ichannel)) == NONE;
00062
00063 vt50.modifyAt(ichan).valid = valid;
00064 gain.modifyAt(ichan).valid = valid;
00065 offset.modifyAt(ichan).valid = valid;
00066 outnse.modifyAt(ichan).valid = valid;
00067 innse.modifyAt(ichan).valid = valid;
00068
00069 vt50.modifyAt(ichan).value = result.getChannelData(ichannel).rc->getFunction()->Eval(result.getSpecialScanPointValue());
00070 gain.modifyAt(ichan).value = result.getChannelData(ichannel).gain;
00071 innse.modifyAt(ichan).value = result.getChannelData(ichannel).noise;
00072 offset.modifyAt(ichan).value = result.getChannelData(ichannel).offset;
00073 }
00074
00075 out << "#"<<getChipName(ichip) << endl;
00076 out << setfill(' ') << setw(6) << vt50.mean() << " " << sqrt(vt50.var()) << " "
00077 << setw(6) << gain.mean() << " " << setw(6) << sqrt(gain.var()) << " "
00078 << setw(6) << offset.mean() << " " << setw(6) << sqrt(offset.var()) << " "
00079 << setw(6) << innse.mean()*gain.mean()/6250. << " "
00080 << setw(6) << innse.mean() << " " << setw(6) << sqrt(innse.var()) << endl;
00081 }
00082
00083
00084 out << "#\n#LoopC - comment"<<endl;
00085 out << "#";
00086 for (short unsigned ichip=0; ichip<nChipModule/2; ++ichip){
00087 out << getChipName(ichip) << " ";
00088 }
00089 out << endl;
00090
00091 for (short unsigned ichip=0; ichip<nChipModule/2; ++ichip){
00092 outputDefectOnChip(ichip, result, out);
00093 }
00094 out << endl << "#";
00095
00096 for (short unsigned ichip=nChipModule/2; ichip<nChipModule; ++ichip){
00097 out << getChipName(ichip) << " ";
00098 }
00099 out << endl;
00100 for (short unsigned ichip=nChipModule/2; ichip<nChipModule; ++ichip){
00101 outputDefectOnChip(ichip, result, out);
00102 }
00103 out << endl << "#";
00104
00105 SummaryWriter::write(t.getDefects(), out);
00106
00107 }
00108
00109 void NPtGainSummaryWriter::outputDefectOnChip(unsigned ichip, const NPtGainTestResult& result, ostream& out) throw() {
00110 auto_ptr<DefectList> defects = result.getDefects().getDefectsEncompassingElement(ModuleElement::Chip(ichip) );
00111
00112 short unsigned ndefect=0;
00113 for (list<Defect>::const_iterator i = defects->getAllDefects().begin() ;
00114 i != defects->getAllDefects().end(); ++i ) {
00115
00116 if ( (*i).getModuleElement().isChip() ) {
00117 if (ndefect!=0) out << ",";
00118 ++ndefect;
00119 out << (*i).getPrototype().getName() ;
00120 }
00121 }
00122 if (ndefect==0) out << "\"OK\" " ;
00123 }
00124
00125
00126
00127 bool NPtGainSummaryWriter::inMap = SummaryManager::instance().addWriter("SctData::NPtGainTestResult", shared_ptr<SummaryWriter>(new NPtGainSummaryWriter()));
00128 }
00129 }