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

NagRootComp.cpp

00001 #include "SctData/FitScanResult.h"
00002 #include "SctData/FitObject.h"
00003 
00004 #include "../../AnalysisTests/AnalysisTestFramework.h"
00005 #include "../../AnalysisTests/CutUtils.h"
00006 
00007 using namespace Sct;
00008 using namespace Sct::IS;
00009 using namespace boost;
00010 using namespace SctData;
00011 using namespace SctTest;
00012 using namespace std;
00013 
00014 struct Info {
00015     unsigned int runNumber;
00016     unsigned int scanNumber;
00017     unsigned int channel;
00018     char serial[15];    
00019 };
00020 string InfoStr = "Run/i:Scan:Channel:Serial/C";
00021 
00022 struct ThresholdData {
00023     double Mean;
00024     double Sigma;
00025     double ChiSq;
00026 };
00027 string ThresholdDataStr = "Mean/D:Sigma:ChiSq";
00028 
00029 ThresholdData root;
00030 ThresholdData nag;
00031 Info info;
00032 
00033 class NagRootCompare : public AnalysisTestFramework<FitScanResult> {
00034 public:
00035     NagRootCompare();
00036     virtual void doModule(string serialNumber);
00037     virtual void publishData(SctTestApiStatus* status);    
00038     virtual void setup();
00039     virtual void summaryOutput();
00040     
00041 private:
00042     void setFitStrategy(string strategy);
00043     void compareFits(FitScanResult& nagFit, FitScanResult& rootFit);
00044     void fillData(FitObject& fitOb, ThresholdData& data);
00045     void removeAll();
00046 };
00047 
00048 NagRootCompare::NagRootCompare() : AnalysisTestFramework<FitScanResult>(".*FitScanResult", "FittedData") {
00049     nData = 10;
00050 }
00051 
00052 void NagRootCompare::removeAll() {
00053     ISInfoIterator it( SctNames::getPartition(), "FittedData", ".*" );
00054     ISInfoDictionary dict(SctNames::getPartition());
00055     while (it()) {
00056     dict.remove(it.name());
00057     }
00058     ISInfoIterator it2( SctNames::getPartition(), "EventData", ".*" );
00059     while (it2()) {
00060     dict.remove(it2.name());
00061     }
00062     system("is_ls -p SCT");
00063 }
00064 
00065 void NagRootCompare::doModule(string serialNumber) {
00066     SctTestApiStatus status; 
00067     status.returnCode = 0;
00068     
00069     highLevelApi->setModuleSerial(&status, copyStringToILU(serialNumber));
00070     
00071     try {
00072     setFitStrategy("NagFitStrategy");
00073     publishData(&status);
00074     if (status.returnCode != 0) {
00075         cerr << "Error publishing data: " << status.returnCode << endl;
00076         return;
00077     }   
00078     vector<shared_ptr<FitScanResult> > nagFits = readData(serialNumber);
00079     
00080     removeAll();
00081     setFitStrategy("RootFitStrategy");
00082     
00083     publishData(&status);
00084     if (status.returnCode != 0) {
00085         cerr << "Error publishing data: " << status.returnCode << endl;
00086         return;
00087     }   
00088     vector<shared_ptr<FitScanResult> > rootFits = readData(serialNumber);
00089     
00090     if (nagFits.size() != rootFits.size()) {
00091         cout << "Numbers of fits different!!  Nag: " << nagFits.size() << " Root: " << rootFits.size() << endl;
00092         ++exitCode;
00093         return;
00094     }
00095     
00096     for (unsigned int i=0; i<nagFits.size(); ++i) {
00097         compareFits(*nagFits[i], *rootFits[i]);
00098     }
00099     } catch(Throwable& e) {
00100     e.sendToMrs(MRS_ERROR);
00101     }
00102 }
00103 
00104 
00105 
00106 void NagRootCompare::fillData(FitObject& fitOb, ThresholdData& data) {
00107     data.Mean = fitOb.getParameter("Mean");
00108     data.Sigma = fitOb.getParameter("Sigma");
00109     data.ChiSq = fitOb.getChiSquared() / (fitOb.getNDF() + fitOb.getNPar());
00110 }
00111 
00112 
00113 void NagRootCompare::compareFits(FitScanResult& nagFit, FitScanResult& rootFit) {
00114     info.runNumber = nagFit.getHeader().getRunNumber();
00115     info.scanNumber = nagFit.getHeader().getScanNumber();
00116     strncpy(info.serial, nagFit.getHeader().getModuleName().c_str(), 14);
00117                       
00118     
00119     for (unsigned int channel = 0; channel<nChannelModule; ++channel) { 
00120     info.channel = channel;
00121     fillData(nagFit.getChannelFit(channel), nag);    
00122     fillData(rootFit.getChannelFit(channel), root);
00123     
00124     tree->Fill();   
00125     }
00126 }
00127 
00128 
00132 void NagRootCompare::setup() {
00133     string name = Env::substituteVariables("${SCT_DAQ_ROOT}/SystemTests/logs/NagRootComp.root");
00134     file = new TFile(name.c_str(), "RECREATE");
00135     tree = new TTree("Data", "Threshold Scan Comparison Data");
00136     tree->Branch("Info", &info, InfoStr.c_str());
00137     tree->Branch("Nag", &nag, ThresholdDataStr.c_str());
00138     tree->Branch("Root", &root, ThresholdDataStr.c_str());
00139     info.serial[14] = '\0';
00140 }
00141 
00142 void NagRootCompare::publishData(SctTestApiStatus* status) {
00143     highLevelApi->responseCurve(status);
00144 }
00145 
00149 void NagRootCompare::summaryOutput() {
00150     if (cut(*tree, "mean", "(Nag.Mean-Root.Mean)/Nag.Mean*100", 0.1, 0.5, 5) > 0) {
00151     ++exitCode;
00152     cout << "Failed mean tail check" << endl;
00153     }
00154     if (cut(*tree, "sigma", "(Nag.Sigma-Root.Sigma)/Nag.Sigma*100", 1, 2, 10) > 0) {
00155     ++exitCode;
00156     cout << "Failed sigma tail check" << endl;
00157     }
00158     if (cut(*tree, "chi", "(Nag.ChiSq-Root.ChiSq)", 0.3, 0.5, 2, false) > 0) {
00159     ++exitCode;
00160     cout << "Failed ChiSq tail check" << endl;
00161     }
00162 }
00163 
00164 void NagRootCompare::setFitStrategy(string strategy) {
00165     string command = "java -Dipc.ref.file=$IPC_REF_FILE bsh.Interpreter $SCT_DAQ_ROOT/SystemTests/scripts/SetFitStrategy.bsh " + strategy;
00166     system(command.c_str());
00167 }
00168         
00169 int main(int argc, char** argv) {
00170     TH1::AddDirectory(true);
00171     NagRootCompare sdc;
00172     sdc.analyzeAll(argc, argv);
00173     return sdc.getExitCode();
00174 }

Generated on Thu Jul 15 09:50:48 2004 for SCT DAQ/DCS Software - C++ by doxygen 1.3.5