00001
00002
00003
00004 #include <cassert>
00005 #include <iomanip>
00006
00007
00008 #include "TClonesArray.h"
00009
00010
00011 #include "CandNtupleSR/NtpSREvent.h"
00012 #include "CandNtupleSR/NtpSRTrack.h"
00013 #include "JobControl/JobCModuleRegistry.h"
00014 #include "JobControl/JobCommand.h"
00015 #include "MessageService/MsgService.h"
00016 #include "MinosObjectMap/MomNavigator.h"
00017 #include "StandardNtuple/NtpStRecord.h"
00018
00019
00020 #include "PhysicsNtuple/Default.h"
00021 #include "PhysicsNtuple/Factory.h"
00022 #include "FillBasic.h"
00023 #include "Interface.h"
00024
00025
00026 #include "TestDataModule.h"
00027
00028 CVSID("$Id: TestDataModule.cxx,v 1.4 2008/09/05 15:42:33 rustem Exp $");
00029
00030 JOBMODULE(TestDataModule, "TestDataModule", "TestDataModule");
00031
00032
00033 Anp::StorekNNData::StorekNNData()
00034 {
00035 }
00036
00037
00038 Anp::StorekNNData::~StorekNNData()
00039 {
00040 }
00041
00042
00043 bool Anp::StorekNNData::Add(const std::string &key, const float data)
00044 {
00045 return fData.insert(map<string, float>::value_type(key, data)).second;
00046 }
00047
00048
00049 bool Anp::StorekNNData::Get(const std::string &key, float &data)
00050 {
00051 map<string, float>::const_iterator fit = fData.find(key);
00052 if(fit != fData.end())
00053 {
00054 data = fit -> second;
00055 return true;
00056 }
00057
00058 return false;
00059 }
00060
00061
00062 TestDataModule::TestDataModule()
00063 :fInterface(new Anp::Interface()),
00064 fNPass(0),
00065 fNFail(0),
00066 fPrintEvent(false),
00067 fPrintTrack(false),
00068 fStrip(false),
00069 fConfig(false)
00070 {
00071 Anp::Factory<Anp::StorekNNData>::
00072 Instance().Hold("kNNData", Anp::Handle<Anp::StorekNNData>(new Anp::StorekNNData));
00073 }
00074
00075
00076 TestDataModule::~TestDataModule()
00077 {
00078
00079
00080
00081 delete fInterface;
00082 fInterface = 0;
00083
00084
00085
00086
00087 Anp::Factory<Anp::StorekNNData>::Instance().Remove("kNNData");
00088
00089 MSG("TestData", Msg::kDebug)
00090 << endl
00091 << "**************************************************" << std::endl
00092 << " TestDataModule" << std::endl
00093 << " Number of passed records " << fNPass << std::endl
00094 << " Number of failed records " << fNFail << std::endl
00095 << "**************************************************" << std::endl;
00096 }
00097
00098
00099 JobCResult TestDataModule::Reco(MomNavigator *mom)
00100 {
00101 NtpStRecord *ntprec = dynamic_cast<NtpStRecord *>(mom -> GetFragment("NtpStRecord"));
00102 if(!ntprec)
00103 {
00104 MSG("TestData", Msg::kError) << "Failed to get NtpStRecord pointer" << endl;
00105 return JobCResult::kAOK;
00106 }
00107
00108
00109
00110
00111 if(fInterface -> FillSnarl(ntprec))
00112 {
00113 ++fNPass;
00114 }
00115 else
00116 {
00117 ++fNFail;
00118 return JobCResult::kAOK;
00119 }
00120
00121 TClonesArray *event_array = ntprec -> evt;
00122 TClonesArray *track_array = ntprec -> trk;
00123 if(!event_array || !track_array)
00124 {
00125 MSG("TestData", Msg::kWarning) << "Invalid TClonesArray object(s)" << endl;
00126 return JobCResult::kAOK;
00127 }
00128
00129
00130
00131
00132 for(int ievent = 0; ievent < event_array -> GetEntries(); ++ievent)
00133 {
00134 NtpSREvent *event = dynamic_cast<NtpSREvent *>(event_array -> At(ievent));
00135 if(!event)
00136 {
00137 MSG("TestData", Msg::kError) << "NtpSREvent dynamic_cast failed" << endl;
00138 continue;
00139 }
00140
00141 if(fPrintEvent)
00142 {
00143 cout << "NtpSREvent - index "<< event -> index << endl << " ";
00144 (event -> plane).Print(cout);
00145 }
00146
00147 TestDataModule::Analyze(event, fPrintEvent);
00148 assert(event -> index == ievent && "mismatched index");
00149 }
00150
00151
00152
00153
00154 for(int itrack = 0; itrack < track_array -> GetEntries(); ++itrack)
00155 {
00156 NtpSRTrack *track = dynamic_cast<NtpSRTrack *>(track_array -> At(itrack));
00157 if(!track)
00158 {
00159 MSG("TestData", Msg::kError) << "NtpSRTrack dynamic_cast failed" << endl;
00160 continue;
00161 }
00162
00163 if(fPrintTrack)
00164 {
00165 cout << "NtpSRTrack - index "<< track -> index << endl << " ";
00166 (track -> plane).Print(cout);
00167 }
00168
00169 TestDataModule::Analyze(track, fPrintTrack);
00170 assert(track -> index == itrack && "mismatched index");
00171
00172 if(fPrintTrack && fStrip)
00173 {
00174 Anp::PrintStrips(*ntprec, track -> stp, track -> nstrip);
00175 }
00176 }
00177
00178 return JobCResult::kAOK;
00179 }
00180
00181
00182 void TestDataModule::Config(const Registry& reg)
00183 {
00184 MSG("TestData", Msg::kVerbose) << "TestDataModule::Config()..." << std::endl;
00185
00186
00187
00188
00189 fConfig.UnLockValues();
00190 fConfig.Merge(reg);
00191 fConfig.LockValues();
00192
00193 Anp::Read(reg, "TestDataModulePrintEvent", fPrintEvent);
00194 Anp::Read(reg, "TestDataModulePrintTrack", fPrintTrack);
00195 Anp::Read(reg, "TestDataModuleStrip", fStrip);
00196 }
00197
00198
00199 void TestDataModule::BeginJob()
00200 {
00201 MSG("TestData", Msg::kVerbose) << "TestDataModule::BeginJob()..." << std::endl;
00202
00203
00204
00205
00206 fInterface -> Config(fConfig);
00207 }
00208
00209
00210 void TestDataModule::Analyze(TObject *object, const bool print)
00211 {
00212
00213
00214
00215 const float numubar = fInterface -> GetVar("numubar", object);
00216 const float rel_ang = fInterface -> GetVar("rel_ang", object);
00217 const float knn_pid = fInterface -> GetVar("knn_pid", object);
00218 const float knn_01 = fInterface -> GetVar("knn_01", object);
00219 const float knn_10 = fInterface -> GetVar("knn_10", object);
00220 const float knn_20 = fInterface -> GetVar("knn_20", object);
00221 const float knn_40 = fInterface -> GetVar("knn_40", object);
00222
00223 if(print)
00224 {
00225 cout << " anti neutrino selection = " << numubar << endl
00226 << " relative angle = " << rel_ang << endl
00227 << " knn muon pid = " << knn_pid << endl
00228 << " number of scintillator planes = " << knn_01 << endl
00229 << " mean track signal = " << knn_10 << endl
00230 << " low mean signal over high mean signal = " << knn_20 << endl
00231 << " track mean signal over track window mean signal = " << knn_40 << endl;
00232 }
00233
00234 Anp::Handle<Anp::StorekNNData> data = Anp::Factory<Anp::StorekNNData>::Instance().Get("kNNData");
00235
00236 if(!data.valid())
00237 {
00238 cerr << " TestDataModule::Analyze - Handle<StorekNNData> is invalid" << endl;
00239 return;
00240 }
00241
00242 data -> Add("numubar", numubar);
00243 data -> Add("rel_ang", rel_ang);
00244
00245 float numubar_ = -1.0e6, rel_ang_ = -1.0e6;
00246
00247 data -> Get("numubar", numubar_);
00248 data -> Get("rel_ang", rel_ang_);
00249 }