00001 #include <BeamDataUtil/test/TestCalibModule.h>
00002 #include <BeamDataUtil/BDSwicCalibrator.h>
00003 #include <BeamDataUtil/BDHadMuMon.h>
00004 #include <BeamDataUtil/BDDevices.h>
00005
00006 #include <Conventions/Munits.h>
00007 #include <DataUtil/GetRawBlock.h>
00008
00009 #include <RawData/RawRecord.h>
00010 #include <RawData/RawBeamMonHeaderBlock.h>
00011 #include <RawData/RawBeamMonBlock.h>
00012
00013
00014 #include <JobControl/JobCModuleRegistry.h>
00015 #include <JobControl/JobCResult.h>
00016 #include <MessageService/MsgService.h>
00017 CVSID("$Id: TestCalibModule.cxx,v 1.1 2005/05/09 22:12:26 minoscvs Exp $");
00018 JOBMODULE(TestCalibModule,
00019 "BeamMonTestCalib", "Test calibrating the SWIC data.");
00020
00021 #include <vector>
00022 #include <string>
00023
00024 using namespace std;
00025 using namespace DataUtil;
00026
00027 TestCalibModule::TestCalibModule()
00028 {
00029 for (int ind=0; ind<4; ++ind) {
00030 fHadMu[ind] = new BDHadMuMon;
00031 }
00032 }
00033 TestCalibModule::~TestCalibModule()
00034 {
00035 }
00036
00037 static void dump_hadmus(BDHadMuMon* hm[])
00038 {
00039 for (int ind=0; ind<4; ++ind) {
00040 double x,y,w,h;
00041 BDHadMuMon* hmm = hm[ind];
00042
00043 hmm->GetStats(x,y,w,h);
00044
00045 cerr << "\t" << ind << ": "
00046 << hmm->GetTotalCharge()
00047 << " (" << x<<", " << y << "),["<< w<<", "<<h<<"]\n";
00048 continue;
00049 int nrowcol = hmm->GetNrowcol();
00050 cerr << "pC:";
00051 for (int xind=0; xind<nrowcol; ++xind) {
00052 cerr << "\t\t";
00053 for (int yind=0; yind<nrowcol; ++yind) {
00054 double q = hmm->GetCharge(hmm->Index(hmm->Channel(xind+1,yind+1)));
00055 cerr << Form("%7.4e ",q/Munits::picocoloumb);
00056 }
00057 cerr << endl;
00058 }
00059
00060 }
00061 }
00062
00063 JobCResult TestCalibModule::Ana(const MomNavigator *mom)
00064 {
00065 vector<const RawBeamMonBlock*> rbmbs = GetRawBlocks<RawBeamMonBlock>(mom);
00066 vector<const RawBeamMonHeaderBlock*> rbmhbs = GetRawBlocks<RawBeamMonHeaderBlock>(mom);
00067
00068 if (rbmhbs.size() != 1 && rbmbs.size() != 1) {
00069 MSG("BD",Msg::kWarning)
00070 << "No beam monitoring data in mom\n";
00071 return JobCResult::kFailed;
00072 }
00073
00074 const RawBeamMonHeaderBlock& rbmhb = *rbmhbs[0];
00075 const RawBeamMonBlock& rbmb = *rbmbs[0];
00076
00077 vector<string> hadmu_name = BDDevices::HadMuMonitors();
00078 for (int ind=0; ind<4; ++ind) {
00079 const RawBeamData* d = rbmb[hadmu_name[ind].c_str()];
00080 if (!d) {
00081 MSG("BD",Msg::kDebug)
00082 << "No device data for " << hadmu_name[ind] << ", skipping\n";
00083 continue;
00084 }
00085 fHadMu[ind]->SetData(*d);
00086 }
00087 cerr << "Before calibration\n";
00088 dump_hadmus(fHadMu);
00089
00090 BDSwicCalibrator::Get().Calibrate(rbmhb,rbmb);
00091
00092 cerr << "After calibration\n";
00093 dump_hadmus(fHadMu);
00094
00095 cerr << endl;
00096
00097 return JobCResult::kAOK;
00098 }
00099 void TestCalibModule::BeginJob()
00100 {
00101 }
00102 void TestCalibModule::EndJob()
00103 {
00104 }