Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Related Pages

RetrieveAndCompare.cpp

00001 #include "SctData/NPtGainTestResult.h"
00002 #include "SctData/ResponseCurve.h"
00003 #include "../../AnalysisTestFramework.h"
00004 #include "../../CutUtils.h"
00005 #include "../../TestFileUtil.h"
00006 
00007 struct ChannelInfo {
00008     unsigned int runNumber;
00009     unsigned int scanNumber;
00010     unsigned int channel;
00011     unsigned int nScans;
00012     float SCTDAQVersion;
00013     char serial[15];    
00014 };
00015 string ChannelInfoStr = "Run/i:Scan:Channel:NScans:SCTDAQVersion/F:Serial/C";
00016 
00017 struct ChannelRCData {
00018     double gain;
00019     double noise;
00020     double offset;
00021     int code;
00022 };
00023 string ChannelDataStr = "Gain/D:Noise:Offset:Code/I";
00024 
00025 struct ChipInfo {
00026     unsigned int runNumber;
00027     unsigned int scanNumber;
00028     unsigned int chip;
00029     unsigned int nScans;
00030     float SCTDAQVersion;
00031     char serial[15];    
00032 };
00033 string ChipInfoStr = "Run/i:Scan:Chip:NScans:SCTDAQVersion/F:Serial/C";
00034 
00035 struct ChipRCData {
00036     double gain;
00037     double noise;
00038     double offset;
00039     double p0;
00040     double p1;
00041     double p2;
00042     int func;
00043     int pass;
00044 };
00045 string ChipDataStr = "Gain/D:Noise:Offset:P0:P1:P2:Func/I:Pass";
00046 
00047 //Response curve stuff
00048 string RCExt = "_rc.dat";
00049 string RCExt2 = "_ResponseCurve.dat";
00050 string RCOutput = "${SCT_DAQ_ROOT}/SystemTests/logs/ResponseCurve.root";
00051 string RCArg = "-RC";
00052 string RCArg2 = "-7";
00053 
00054 //Three-point gain stuff
00055 string GainExt = "_rc3.dat";
00056 string GainExt2 = "_3PtGain.dat";
00057 string GainOutput = "${SCT_DAQ_ROOT}/SystemTests/logs/ThreePointGain.root";
00058 string GainArg = "-3ptgain";
00059 string GainArg2 = "-5";
00060 
00061 //Globals variables:
00062 ChipRCData RodDaq;                    //Our data
00063 ChipRCData SctDaq;                    //SCTDAQ data
00064 ChipInfo info;                          //Some info
00065 
00066 ChannelRCData chRodDaq; 
00067 ChannelRCData chSctDaq; 
00068 ChannelInfo chInfo;
00069 
00070 
00071 class NPtGainCompare : public AnalysisTestFramework<NPtGainTestResult> {
00072 public:
00073     NPtGainCompare();
00074     virtual void publishData(SctTestApiStatus* status);
00075     virtual void downloadData(string serialNumber);
00076     virtual void compare(const NPtGainTestResult& t);   
00077     virtual float compareChip(const NPtGainTestResult& t);      
00078     virtual void compareChannel(const NPtGainTestResult& t, float version);     
00079     virtual void setup();
00080     virtual void printAdditionalArgs();
00081     virtual int handleArg(int argc, int i, char** argv);
00082     virtual void summaryOutput();
00083     string getFileName(string serial);
00084     string getRCFileName(string serial);
00085     
00086     bool rc;
00087     TTree* channelTree;
00088 };
00089 
00090 void NPtGainCompare::summaryOutput() {
00091     //Chip data tests
00092     if (cut(*tree, "pass", "(RodDaq.Pass-SctDaq.Pass)", 0.01, 0.01, 0.01, true) > 0) {
00093         ++exitCode;
00094         cout << "Failed pass tail check" << endl;
00095     }    
00096     if (cut(*tree, "gain", "(RodDaq.Gain-SctDaq.Gain)/SctDaq.Gain", 0.01, 0.01, 0.15, true) > 0) {
00097         ++exitCode;
00098         cout << "Failed gain tail check" << endl;
00099     }    
00100     if (cut(*tree, "noise", "(RodDaq.Noise-SctDaq.Noise)/SctDaq.Noise", 0.02, 0.02, 0.25, true) > 0) {
00101         ++exitCode;
00102         cout << "Failed noise tail check" << endl;
00103     }    
00104     if (cut(*tree, "offset", "(RodDaq.Offset-SctDaq.Offset)", 1, 10, 80, true) > 0) {
00105         ++exitCode;
00106         cout << "Failed offset tail check" << endl;
00107     }
00108     /*
00109       No checks on the output params - they are too correlated for it to mean anything
00110       Hopefully the aggregate/summary tests above and below will suffice
00111       
00112     if (cut(*tree, "p0", "(RodDaq.P0-SctDaq.P0)", 0.01, 0.01, 0.01, true) > 0) {
00113         ++exitCode;
00114         cout << "Failed p0 tail check" << endl;
00115     }    
00116     if (cut(*tree, "p1", "(RodDaq.P1-SctDaq.P1)", 0.01, 0.01, 0.01, true) > 0) {
00117         ++exitCode;
00118         cout << "Failed p1 tail check" << endl;
00119     }    
00120     if (cut(*tree, "p2", "(RodDaq.P2-SctDaq.P2)", 0.01, 0.01, 0.01, true) > 0) {
00121         ++exitCode;
00122         cout << "Failed p2 tail check" << endl;
00123     }    
00124     */
00125     
00126     //Channel data tests
00127     if (cut(*channelTree, "gain", "(RodDaq.Gain-SctDaq.Gain)/SctDaq.Gain", 0.01, 0.01, 0.01, true) > 0) {
00128         ++exitCode;
00129         cout << "Failed gain tail check" << endl;
00130     }
00131     if (cut(*channelTree, "noise", "(RodDaq.Noise-SctDaq.Noise)/SctDaq.Noise", 0.01, 0.01, 0.01, true) > 0) {
00132         ++exitCode;
00133         cout << "Failed noise tail check" << endl;
00134     }
00135     if (cut(*channelTree, "offset", "(RodDaq.Offset-SctDaq.Offset)", 0.01, 0.01, 0.01, true) > 0) {
00136         ++exitCode;
00137         cout << "Failed offset tail check" << endl;
00138     }
00139     if (cut(*channelTree, "code", "(RodDaq.Code-SctDaq.Code)", 0.01, 0.01, 0.01, true) > 0) {
00140         ++exitCode;
00141         cout << "Failed code tail check" << endl;
00142     }
00143 
00144     exitCode += errorCode;
00145 }
00146 
00147 
00148 void NPtGainCompare::compare(const NPtGainTestResult& sd) {
00149     float version = compareChip(sd);
00150     compareChannel(sd, version);
00151 }
00152 
00153 int getCode(const NPtGainTestResult& rc, unsigned int channel) {
00154     list<Defect> defects = rc.getDefects().getDefectsAffectingElement(ModuleElement::Channel(channel))->getAllDefects();
00155     
00156     int code = 0;
00157     if (defects.size() > 0) cout << "Channel: " << channel << endl;
00158     for (list<Defect>::const_iterator i=defects.begin(); i!=defects.end(); ++i) {
00159     cout << i->getPrototype().getName() << endl;
00160     if (i->getPrototype() == StandardDefects::DEAD) code += 0x1;
00161     else if (i->getPrototype() == StandardDefects::STUCKON) code += 0x2;
00162     else if (i->getPrototype() == StandardDefects::PARTBONDED) code += 0x8000;
00163     else if (i->getPrototype() == StandardDefects::UNBONDED) code += 0x1000;
00164     else if (i->getPrototype() == StandardDefects::NOISY) code += 0x4000;
00165     else if (i->getPrototype() == StandardDefects::LO_GAIN) code += 0x100;  
00166     else if (i->getPrototype() == StandardDefects::HI_GAIN) code += 0x200;
00167     else if (i->getPrototype() == StandardDefects::LO_OFFSET) code += 0x400;
00168     else if (i->getPrototype() == StandardDefects::HI_OFFSET) code += 0x800;    
00169     else code += 100000;
00170     }
00171     return code;
00172 }
00173 
00174 string NPtGainCompare::getRCFileName(string serial) {
00175     ostringstream oss;
00176     oss << serial;
00177     if (rc) oss << RCExt;
00178     else oss << GainExt;
00179     
00180     return oss.str();
00181 }
00182 
00183 void NPtGainCompare::compareChannel(const NPtGainTestResult& rc, float version) {
00184     strncpy(chInfo.serial, rc.getModuleName().c_str(), 14);
00185     chInfo.runNumber = rc.getRunNumber();
00186     chInfo.scanNumber = rc.getScanNumberAt(0);
00187     chInfo.nScans = rc.getNScans();
00188     chInfo.SCTDAQVersion = version;
00189     
00190     string fileName = getRCFileName(rc.getModuleName());
00191     ifstream file (fileName.c_str());
00192     if (!file.good())
00193         throw IllegalStateError("Failed to open comparison file: " + fileName, __FILE__, __LINE__);
00194     //Dump first line
00195     file.ignore(256, '\n');
00196 
00197     for (unsigned int channel = 0; channel<nChannelModule; ++channel) {
00198     string comment;
00199     file >> dec >> chInfo.channel >> hex >> chSctDaq.code >> chSctDaq.gain >> chSctDaq.offset >> chSctDaq.noise >> comment;
00200     //Ignore rest of line
00201     file.ignore(256, '\n');
00202     
00203     if (channel != chInfo.channel) 
00204         throw IllegalStateError("Read incorrect channel", __FILE__, __LINE__);
00205     
00206     const NPtGainTestResultData& data = rc.getChannelData(channel);
00207 
00208     chRodDaq.code = getCode(rc, channel);
00209     chRodDaq.gain = data.gain;
00210     chRodDaq.noise = data.noise;
00211     chRodDaq.offset = data.offset;
00212 
00213         channelTree->Fill();
00214     }
00215 }
00216 
00217 string NPtGainCompare::getFileName(string serial) {
00218     ostringstream oss;
00219     oss << serial << (rc ? RCExt2 : GainExt2);
00220     
00221     return oss.str();
00222 }
00223 
00224 //Returns the version
00225 float NPtGainCompare::compareChip(const NPtGainTestResult& sd) {
00226     strncpy(info.serial, sd.getModuleName().c_str(), 14);
00227     info.runNumber = sd.getRunNumber();
00228     info.scanNumber = sd.getScanNumberAt(0);
00229     info.nScans = sd.getNScans();
00230     
00231     string fileName = getFileName(sd.getModuleName());
00232     ifstream file (fileName.c_str());
00233     if (!file.good())
00234         throw IllegalStateError("Failed to open comparison file: " + fileName, __FILE__, __LINE__);
00235     
00236     SctDaq.pass = TestFileUtil::getPass(file);
00237     info.SCTDAQVersion = TestFileUtil::skipHeader(file);
00238 
00239     for (unsigned int chip = 0; chip<nChipModule; ++chip) {
00240     info.chip = chip;
00241     double temp;
00242     string chipStr;
00243     file >> chipStr >> temp >> temp >> SctDaq.gain >> temp >> SctDaq.offset >> temp >> temp >> SctDaq.noise >> temp >> SctDaq.func
00244          >> SctDaq.p0 >> SctDaq.p1 >> SctDaq.p2;
00245     //Ignore rest of line
00246     file.ignore(256, '\n');
00247     
00248     RodDaq.pass = sd.getPassed();
00249     const NPtGainTestResultData& data = sd.getChipData(chip);   
00250     RodDaq.gain = data.gain;
00251     RodDaq.noise = data.noise;
00252     RodDaq.offset = data.offset;
00253     RodDaq.func = data.rc->getIndex();
00254     TF1& f = *data.rc->getFunction();
00255     RodDaq.p0 = f.GetParameter(0);
00256     RodDaq.p1 = f.GetParameter(1);
00257     RodDaq.p2 = f.GetParameter(2);
00258 
00259         tree->Fill();
00260     }
00261     return info.SCTDAQVersion;
00262 }
00263 
00264 
00268 void NPtGainCompare::setup() {
00269     string name = Env::substituteVariables(rc ? RCOutput : GainOutput);
00270     file = new TFile(name.c_str(), "RECREATE");
00271     tree = new TTree("NPtChip", "NPtGain Chip Comparison Data");
00272     channelTree = new TTree("NPtChannel", "NPtGain Channel Comparison Data");
00273     tree->Branch("RodDaq", &RodDaq, ChipDataStr.c_str());
00274     tree->Branch("SctDaq", &SctDaq, ChipDataStr.c_str());
00275     tree->Branch("Info", &info, ChipInfoStr.c_str());
00276     
00277     channelTree->Branch("RodDaq", &chRodDaq, ChannelDataStr.c_str());
00278     channelTree->Branch("SctDaq", &chSctDaq, ChannelDataStr.c_str());
00279     channelTree->Branch("Info", &chInfo, ChannelInfoStr.c_str());    
00280     
00281     info.serial[14] = '\0';
00282     chInfo.serial[14] = '\0';
00283 }
00284 
00288 void NPtGainCompare::downloadData(string serialNumber) {
00289     ostringstream oss;
00290     ostringstream oss1;
00291     TestInfo info = rc ? moduleData.getResponseCurveInfo(serialNumber) : moduleData.get3PtGainInfo(serialNumber);
00292     oss << "java ProdDatabase/getDBfiles " << (rc ? RCArg : GainArg) << " -d -r " << info.runNumber << " -s " << info.scanNumber << "  " << serialNumber;
00293     oss1 << "java ProdDatabase/getDBfiles " << (rc ? RCArg2 : GainArg2) << " -d -r " << info.runNumber << " -s " << info.scanNumber << "  " << serialNumber;
00294     system(oss.str().c_str());
00295     system(oss1.str().c_str());
00296 }
00297 
00298 void NPtGainCompare::publishData(SctTestApiStatus* status) {
00299     if (rc) highLevelApi->responseCurve(status);
00300     else highLevelApi->threePointGain(status);
00301 }
00302 
00303 NPtGainCompare::NPtGainCompare() {
00304     channelTree = 0;
00305     rc = true;
00306 }
00307 
00308 void NPtGainCompare::printAdditionalArgs() {
00309     cout << "-3:           3pt-gain rather than response curve" << endl;
00310 }
00311 
00312 int NPtGainCompare::handleArg(int argc, int i, char** argv) {
00313     if (string(argv[i]) == "-3") {
00314     rc = false;    
00315     } else {
00316     printHelp();
00317     }
00318     return i;
00319 }
00320 
00321 int main(int argc, char** argv) {
00322     NPtGainCompare sdc;
00323     sdc.analyzeAll(argc, argv);
00324     return sdc.getExitCode();
00325 }
00326 
00327 

Generated on Thu Jul 8 11:41:13 2004 for SCT DAQ/DCS Software - C++ by doxygen 1.3.5