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 struct Info info;
00032 
00033 class NagRootCompare : public AnalysisTestFramework<FitScanResult> {
00034 public:
00035     NagRootCompare();
00036     virtual void doModule(string serialNumber);
00037     virtual void publishData();    
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(copyStringToCorba(serialNumber));
00070     
00071     try {
00072     setFitStrategy("NagFitStrategy");
00073     try {
00074       publishData();
00075     } catch (...) {
00076       cerr << "Error publishing data: " << /*status.returnCode << */endl;
00077       return;
00078     }   
00079     vector<shared_ptr<FitScanResult> > nagFits = readData(serialNumber);
00080     
00081     removeAll();
00082     setFitStrategy("RootFitStrategy");
00083     try{ 
00084       publishData();
00085     } catch (...) {
00086       cerr << "Error publishing data: " << /*status.returnCode << */endl;
00087       return;
00088     }   
00089     vector<shared_ptr<FitScanResult> > rootFits = readData(serialNumber);
00090     
00091     if (nagFits.size() != rootFits.size()) {
00092         cout << "Numbers of fits different!!  Nag: " << nagFits.size() << " Root: " << rootFits.size() << endl;
00093         ++exitCode;
00094         return;
00095     }
00096     
00097     for (unsigned int i=0; i<nagFits.size(); ++i) {
00098         compareFits(*nagFits[i], *rootFits[i]);
00099     }
00100     } catch(Throwable& e) {
00101     e.sendToMrs(MRS_ERROR);
00102     }
00103 }
00104 
00105 
00106 
00107 void NagRootCompare::fillData(FitObject& fitOb, ThresholdData& data) {
00108     data.Mean = fitOb.getParameter("Mean");
00109     data.Sigma = fitOb.getParameter("Sigma");
00110     data.ChiSq = fitOb.getChiSquared() / (fitOb.getNDF() + fitOb.getNPar());
00111 }
00112 
00113 
00114 void NagRootCompare::compareFits(FitScanResult& nagFit, FitScanResult& rootFit) {
00115     info.runNumber = nagFit.getHeader().getRunNumber();
00116     info.scanNumber = nagFit.getHeader().getScanNumber();
00117     strncpy(info.serial, nagFit.getHeader().getModuleName().c_str(), 14);
00118                       
00119     
00120     for (unsigned int channel = 0; channel<nChannelModule; ++channel) { 
00121     info.channel = channel;
00122     fillData(nagFit.getChannelFit(channel), nag);    
00123     fillData(rootFit.getChannelFit(channel), root);
00124     
00125     tree->Fill();   
00126     }
00127 }
00128 
00129 
00133 void NagRootCompare::setup() {
00134     string name = Env::substituteVariables("${SCT_DAQ_ROOT}/SystemTests/logs/NagRootComp.root");
00135     file = new TFile(name.c_str(), "RECREATE");
00136     tree = new TTree("Data", "Threshold Scan Comparison Data");
00137     tree->Branch("Info", &info, InfoStr.c_str());
00138     tree->Branch("Nag", &nag, ThresholdDataStr.c_str());
00139     tree->Branch("Root", &root, ThresholdDataStr.c_str());
00140     info.serial[14] = '\0';
00141 }
00142 
00143 void NagRootCompare::publishData() {
00144     highLevelApi->responseCurve();
00145 }
00146 
00150 void NagRootCompare::summaryOutput() {
00151     if (cut(*tree, "mean", "(Nag.Mean-Root.Mean)/Nag.Mean*100", 0.1, 0.5, 5) > 0) {
00152     ++exitCode;
00153     cout << "Failed mean tail check" << endl;
00154     }
00155     if (cut(*tree, "sigma", "(Nag.Sigma-Root.Sigma)/Nag.Sigma*100", 1, 2, 10) > 0) {
00156     ++exitCode;
00157     cout << "Failed sigma tail check" << endl;
00158     }
00159     if (cut(*tree, "chi", "(Nag.ChiSq-Root.ChiSq)", 0.3, 0.5, 2, false) > 0) {
00160     ++exitCode;
00161     cout << "Failed ChiSq tail check" << endl;
00162     }
00163 }
00164 
00165 void NagRootCompare::setFitStrategy(string strategy) {
00166     string command = "java -Dtdaq.ipc.init.ref=$TDAQ_IPC_INIT_REF bsh.Interpreter $SCT_DAQ_ROOT/SystemTests/scripts/SetFitStrategy.bsh " + strategy;
00167     system(command.c_str());
00168 }
00169         
00170 int main(int argc, char** argv) {
00171     TH1::AddDirectory(true);
00172     NagRootCompare sdc;
00173     sdc.analyzeAll(argc, argv);
00174     return sdc.getExitCode();
00175 }

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