NPtGainSummaryWriter.cpp

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         default : out << "%ResponseCurve" << endl; break;
00022 //      case (10) : out << "%ResponseCurve" << endl; break;
00023 //      default : out <<"%NPtGain"<<endl; break;
00024         }
00025 
00026         out << "#\n#LoopA - Fit"<<endl;
00027         out << "#      func    p0     p1       p2" << endl;
00028         for (short unsigned ichip=0; ichip<nChipModule; ++ichip){
00029         out << "#"<<getChipName(ichip) << endl;
00030         if (result.getChipData(ichip).rc.get()==0){
00031           throw Sct::IllegalStateError("No Response Curve with chip!", __FILE__, __LINE__);
00032         }
00033         shared_ptr<TF1> fit = result.getChipData(ichip).rc->getFunction();
00034         if (!fit.get()) {
00035           throw Sct::IllegalStateError("No Fit with Response Curve!", __FILE__, __LINE__);
00036         }
00037         out << setfill(' ');
00038         out << setw(6) << result.getChipData(ichip).rc->getIndex();
00039         for (short ipar=0; ipar<fit->GetNpar(); ++ipar){
00040             out << "  " << setfill(' ') << setw(6) << fit->GetParameter(ipar);
00041         }
00042         out << endl;
00043         }
00044 
00045         out << "#\n#LoopB - Gain, Offset, Noise at 2.00fC"<<endl;
00046         out << "#     vt50    rms     gain    rms   offset   rms   outnse   innse   rms" << endl;
00047 
00048         for (short unsigned ichip=0; ichip<nChipModule; ++ichip){
00049         Stats<float> vt50(nChannelChip);
00050         Stats<float> gain(nChannelChip);
00051         Stats<float> offset(nChannelChip);
00052         Stats<float> outnse(nChannelChip);
00053         Stats<float> innse(nChannelChip);
00054         
00055         for (unsigned ichan=0; ichan<nChannelChip; ++ichan){
00056             unsigned ichannel = ichan + ichip*nChannelChip;
00057             bool valid=result.getDefects().defectSeverityEncompassingElement(ModuleElement::Channel(ichannel)) < SERIOUS;           
00058 
00059             vt50.modifyAt(ichan).valid = valid;
00060             gain.modifyAt(ichan).valid = valid;
00061             offset.modifyAt(ichan).valid = valid;
00062             outnse.modifyAt(ichan).valid = valid;
00063             innse.modifyAt(ichan).valid = valid;
00064             
00065             vt50.modifyAt(ichan).value = result.getChannelData(ichannel).rc->getFunction()->Eval(result.getSpecialScanPointValue());
00066             gain.modifyAt(ichan).value = result.getChannelData(ichannel).gain;
00067             innse.modifyAt(ichan).value = result.getChannelData(ichannel).noise;
00068             offset.modifyAt(ichan).value = result.getChannelData(ichannel).offset;
00069         }
00070         
00071         out << "#"<<getChipName(ichip) << endl;
00072         out << setfill(' ')  << setw(6) << vt50.mean() << "  " << sqrt(vt50.var()) << "  " 
00073             << setw(6) << gain.mean() << "  " <<  setw(6) << sqrt(gain.var()) << "  " 
00074             << setw(6) << offset.mean() << "  " << setw(6) << sqrt(offset.var()) << "  "
00075             << setw(6) << innse.mean()*gain.mean()/6250. << "  "
00076             << setw(6) << innse.mean() << "  " << setw(6) << sqrt(innse.var()) << endl;
00077         }
00078         
00079 
00080         out << "#\n#LoopC - comment"<<endl;
00081         out << "#";
00082         for (short unsigned ichip=0; ichip<nChipModule/2; ++ichip){
00083         out << getChipName(ichip) << " ";
00084         }
00085         out << endl;
00086 
00087         for (short unsigned ichip=0; ichip<nChipModule/2; ++ichip){
00088         outputDefectOnChip(ichip, result, out);
00089         }
00090         out << endl << "#";
00091         
00092         for (short unsigned ichip=nChipModule/2; ichip<nChipModule; ++ichip){
00093         out << getChipName(ichip) << " ";
00094         }
00095         out << endl;
00096         for (short unsigned ichip=nChipModule/2; ichip<nChipModule; ++ichip){
00097         outputDefectOnChip(ichip, result, out);
00098         }
00099         out << endl << "#"<<endl;
00100 
00101         out << "#ChipSlope:\tNoise\tOffset\tGain" << endl; 
00102         for (short unsigned ichip=0; ichip<nChipModule; ++ichip){
00103           out << "#"<< getChipName(ichip)<<endl<<"#SLOPE\t";
00104           if (ichip<result.noiseSlope.size()){out << result.noiseSlope[ichip]<<"\t";}else{out << ".\t";}
00105           if (ichip<result.offsetSlope.size()){out << result.offsetSlope[ichip]<<"\t";}else{out << ".\t";}
00106           if (ichip<result.gainSlope.size()){out << result.gainSlope[ichip];}else{out << ".";}
00107           out << endl;
00108         }
00109         SummaryWriter::write(t.getDefects(), out);      
00110     }
00111 
00112     void NPtGainSummaryWriter::outputDefectOnChip(unsigned ichip, const NPtGainTestResult& result, ostream& out) throw() {
00113         auto_ptr<DefectList> defects = result.getDefects().getDefectsEncompassingElement(ModuleElement::Chip(ichip) );
00114         
00115         short unsigned ndefect=0;
00116         for (list<Defect>::const_iterator i = defects->getAllDefects().begin() ;
00117          i != defects->getAllDefects().end(); ++i ) {
00118 
00119           if ( (*i).getModuleElement().isChip() ) {
00120         if (ndefect!=0) out << ",";
00121         ++ndefect;
00122         out << "\""<< (*i).getPrototype().getName() << "\"";
00123         }
00124         }
00125         if (ndefect==0) {
00126            out <<  "\"OK\"  " ;
00127         }else{
00128                out << " ";
00129         }
00130     }
00131       
00132       //------------------------------------------------------
00133 
00134     bool NPtGainSummaryWriter::inMap = SummaryManager::instance().addWriter("SctData::NPtGainTestResult", shared_ptr<SummaryWriter>(new NPtGainSummaryWriter()));
00135     }
00136 }

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