SetKNNModule Class Reference

#include <SetKNNModule.h>

Inheritance diagram for SetKNNModule:
JobCModule

List of all members.

Public Member Functions

 SetKNNModule ()
virtual ~SetKNNModule ()
JobCResult Reco (MomNavigator *mom)
void Config (const Registry &reg)
void BeginJob ()

Private Member Functions

void Analyze (int i, TObject *object, bool print=false)
bool AnalyzeRecord (NtpStRecord *ntprec)

Private Attributes

Anp::InterfacefInterface
unsigned int fNPass
unsigned int fNFail
bool fFastMode
bool fPrintEvent
bool fPrintTrack
bool fStrip
std::string fPath
bool fIsMRCC
Registry fConfig

Detailed Description

Definition at line 37 of file SetKNNModule.h.


Constructor & Destructor Documentation

SetKNNModule::SetKNNModule (  ) 

Definition at line 100 of file SetKNNModule.cxx.

References fFastMode, and fPath.

00101    :fInterface(new Anp::Interface()),
00102     fNPass(0),
00103     fNFail(0),
00104     fPrintEvent(false),
00105     fPrintTrack(false),
00106     fStrip(false),
00107     fIsMRCC(false),
00108     fConfig(false)
00109 {
00110 
00111 //   fPath = "junk/afs/fnal.gov/files/home/room1/rustem/data/muon-knn/";
00112    fPath = "/minos/app/nue/Releases/Griffin/Data/kNN_cedar/";
00113    fFastMode = false;
00114 
00115    Anp::Factory<StorekNNData>::
00116       Instance().Hold("kNNData", Anp::Handle<StorekNNData>(new StorekNNData));
00117 }

SetKNNModule::~SetKNNModule (  )  [virtual]

Definition at line 120 of file SetKNNModule.cxx.

References fInterface, fNFail, fNPass, Msg::kDebug, and MSG.

00121 {
00122    //
00123    // Delete interface object
00124    //
00125    delete fInterface;
00126    fInterface = 0;
00127 
00128    //
00129    // Destroy StorekNNData if it exists
00130    //
00131    Anp::Factory<StorekNNData>::Instance().Remove("kNNData");
00132 
00133    MSG("SetKNNModule", Msg::kDebug) 
00134       << endl
00135       << "**************************************************" << std::endl
00136       << "    SetKNNModule" << std::endl
00137       << "      Number of passed records " << fNPass << std::endl
00138       << "      Number of failed records " << fNFail << std::endl
00139       << "**************************************************" << std::endl;
00140 }


Member Function Documentation

void SetKNNModule::Analyze ( int  i,
TObject *  object,
bool  print = false 
) [private]

Definition at line 330 of file SetKNNModule.cxx.

References fInterface, and Anp::Handle< T >::valid().

Referenced by AnalyzeRecord().

00331 {
00332    //
00333    // Extract variables from PhysicsNtuple interface
00334    //
00335    const float numubar = fInterface -> GetVar("numubar", object);
00336    const float rel_ang = fInterface -> GetVar("rel_ang", object);
00337    const float knn_pid = fInterface -> GetVar("knn_pid", object);
00338    const float knn_01  = fInterface -> GetVar("knn_01",  object);
00339    const float knn_10  = fInterface -> GetVar("knn_10",  object);
00340    const float knn_20  = fInterface -> GetVar("knn_20",  object);
00341    const float knn_40  = fInterface -> GetVar("knn_40",  object);
00342 
00343    if(print)
00344    {
00345       cout << " For event: "<<i
00346            << "   anti neutrino selection = " << numubar << endl
00347            << "   relative angle = " << rel_ang << endl
00348            << "   knn muon pid = " << knn_pid << endl
00349            << "   number of scintillator planes = " << knn_01 << endl
00350            << "   mean track signal = " << knn_10 << endl
00351            << "   low mean signal over high mean signal = " << knn_20 << endl
00352            << "   track mean signal over track window mean signal = " << knn_40 << endl;
00353    }
00354    
00355    Anp::Handle<StorekNNData> data = Anp::Factory<StorekNNData>::Instance().Get("kNNData");
00356 
00357    if(!data.valid())
00358    {
00359       cerr << " SetKNNModule::Analyze - Handle<StorekNNData> is invalid" << endl;
00360       return;
00361    }
00362 
00363    data -> Add(i, "numubar", numubar);
00364    data -> Add(i, "rel_ang", rel_ang);
00365    data -> Add(i, "knn_pid", knn_pid);
00366    data -> Add(i, "knn_01", knn_01);
00367    data -> Add(i, "knn_10", knn_10);
00368    data -> Add(i, "knn_20", knn_20);
00369    data -> Add(i, "knn_40", knn_40);
00370 }

bool SetKNNModule::AnalyzeRecord ( NtpStRecord ntprec  )  [private]

Definition at line 228 of file SetKNNModule.cxx.

References Analyze(), fInterface, fIsMRCC, fNFail, fNPass, fPrintEvent, RecRecordImp< T >::GetHeader(), RecHeader::GetVldContext(), Msg::kError, Msg::kWarning, MSG, and Anp::Handle< T >::valid().

Referenced by Reco().

00229 {
00230    Anp::Handle<StorekNNData> data = Anp::Factory<StorekNNData>::Instance().Get("kNNData");
00231    if(!data.valid())
00232    {
00233       cerr << " SetKNNModule::Analyze - Handle<StorekNNData> is invalid" << endl;
00234       return false;
00235    }
00236 
00237    std::string name = ntprec->GetName();
00238    data->SetPrefix("SNTP");
00239    if(fIsMRCC && name == "Primary") data->SetPrefix("OldSNTP");
00240 
00241    VldContext vld = ntprec->GetHeader().GetVldContext();
00242    data->SetValidity(vld);
00243 
00244    // Fill interface with data for a new snarl
00245    if(fInterface -> FillSnarl(ntprec))
00246    {
00247       ++fNPass;
00248    }
00249    else
00250    {
00251       ++fNFail;
00252       return false; 
00253    } 
00254 
00255    TClonesArray *event_array = ntprec -> evt;
00256    TClonesArray *track_array = ntprec -> trk;
00257    if(!event_array || !track_array)
00258    {           
00259       MSG("SetKNNModule", Msg::kWarning) << "Invalid TClonesArray object(s)" << endl;
00260       return false;
00261    }
00262 
00263    // Iterate over all events and access analysis variables
00264    for(int ievent = 0; ievent < event_array -> GetEntries(); ++ievent)
00265    {
00266       NtpSREvent *event = dynamic_cast<NtpSREvent *>(event_array -> At(ievent));
00267       if(!event)
00268       {
00269          MSG("SetKNNModule", Msg::kError) << "NtpSREvent dynamic_cast failed" << endl;
00270          continue;
00271       }
00272 
00273       SetKNNModule::Analyze(ievent, event, fPrintEvent);
00274       assert(event -> index == ievent && "mismatched index");
00275    }
00276 
00277    return true;
00278 }

void SetKNNModule::BeginJob ( void   )  [virtual]

Implement for notification of begin of job

Reimplemented from JobCModule.

Definition at line 319 of file SetKNNModule.cxx.

References Msg::kVerbose, and MSG.

00320 {
00321    MSG("SetKNNModule", Msg::kVerbose) << "SetKNNModule::BeginJob()..." << std::endl;
00322 
00323    //
00324    // Configure interface object at the beginning of analysis job
00325    //
00326 //   fInterface -> Config(fConfig);
00327 }

void SetKNNModule::Config ( const Registry r  )  [virtual]

Return the actual configuration. If your module directly pulls its configuration from the fConfig Registry, you don't need to override this. Override if you have local config variables.

Reimplemented from JobCModule.

Definition at line 281 of file SetKNNModule.cxx.

References fConfig, fFastMode, fIsMRCC, fPath, fPrintEvent, fPrintTrack, fStrip, Registry::Get(), Msg::kInfo, Msg::kVerbose, Registry::LockKeys(), Registry::LockValues(), Registry::Merge(), MSG, Anp::Read(), Registry::UnLockKeys(), and Registry::UnLockValues().

00282 {
00283    MSG("SetKNNModule", Msg::kVerbose) << "SetKNNModule::Config()..." << std::endl;
00284 
00285    //
00286    // Store Registry copy
00287    //
00288    fConfig.UnLockValues();
00289    fConfig.UnLockKeys();
00290    fConfig.Merge(reg);
00291    fConfig.LockKeys();
00292    fConfig.LockValues();
00293 
00294    const char* tmps;
00295    if(reg.Get("kNNPath", tmps)) fPath = tmps;
00296    
00297    int itmp;
00298    if(reg.Get("ForceMRCC", itmp)){
00299      if(itmp == 1){
00300         fIsMRCC = true;
00301          MSG("SetKNNModule", Msg::kInfo)<<"Forced to Shift to MRCC Mode"<<endl;
00302      }
00303    }
00304 
00305    if(reg.Get("RunFast", itmp)){
00306      if(itmp == 1){
00307         fFastMode = true;
00308          MSG("SetKNNModule", Msg::kInfo)<<"Shifting to Fast Mode"<<endl;
00309      }
00310    }
00311 
00312 
00313    Anp::Read(reg, "SetKNNModulePrintEvent", fPrintEvent);
00314    Anp::Read(reg, "SetKNNModulePrintTrack", fPrintTrack);
00315    Anp::Read(reg, "SetKNNModuleStrip", fStrip);
00316 }

JobCResult SetKNNModule::Reco ( MomNavigator mom  )  [virtual]

Implement this for read-write access to the MomNavigator

Reimplemented from JobCModule.

Definition at line 143 of file SetKNNModule.cxx.

References AnalyzeRecord(), Anp::Interface::Config(), fFastMode, fInterface, fIsMRCC, fPath, VldContext::GetDetector(), MomNavigator::GetFragmentList(), RecRecordImp< T >::GetHeader(), ReleaseType::GetMCSubVersion(), NtpStRecord::GetRelease(), RecHeader::GetVldContext(), ReleaseType::IsDaikon(), JobCResult::kAOK, JobCResult::kFailed, Detector::kFar, Msg::kInfo, Detector::kNear, MSG, reg, Registry::Set(), and Anp::Handle< T >::valid().

00144 {  
00145   bool foundST=false;
00146   std::vector<TObject*> records = mom->GetFragmentList("NtpStRecord");
00147 
00148   if(fFastMode){
00149     std::vector<TObject*> nrRecord =  mom->GetFragmentList("NueRecord");
00150     if(nrRecord.size() == 0) return  JobCResult::kFailed;
00151   }
00152 
00153   bool pass = true;
00154 
00155   static bool first = true;
00156 
00157   Anp::Handle<StorekNNData> data = Anp::Factory<StorekNNData>::Instance().Get("kNNData");
00158 
00159   if(!data.valid())
00160   {
00161       cerr << " SetKNNModule::Analyze - Handle<StorekNNData> is invalid" << endl;
00162       return JobCResult::kFailed;
00163   }
00164   data->Clear();
00165 
00166   for(unsigned int i=0;i<records.size() && pass; i++)
00167   {
00168       NtpStRecord *str=dynamic_cast<NtpStRecord *>(records[i]);
00169       if(str){  foundST=true;  }
00170       else continue;
00171    
00172       if(first){
00173           Registry reg(false);
00174           string pub = getenv("SRT_PUBLIC_CONTEXT");
00175           string config = pub + "/PhysicsNtuple/Config/Config2008Real.txt";
00176           reg.Set("InterfaceConfigPath", config.c_str());
00177  
00178           string file = fPath;
00179 
00180 
00181           int release = str->GetRelease();
00182           bool diakon00 = ( ReleaseType::IsDaikon(release) && 0==ReleaseType::GetMCSubVersion(release) );
00183 
00184           if(str->GetHeader().GetVldContext().GetDetector() == Detector::kNear)
00185           {
00186            if(diakon00)
00187            {
00188              file += "knn.physics.near.daikon_00.cedar_phy.L010z185i.root";
00189            }
00190            else
00191            {
00192              file += "knn.physics.near.daikon_04.cedar_phy_bhcurv.L010z185i.root";
00193            }
00194           }
00195 
00196 
00197           if(str->GetHeader().GetVldContext().GetDetector() == Detector::kFar)
00198           {
00199            if(diakon00)
00200            {
00201              file += "knn.physics.far.daikon_00.cedar_phy.L010z185i.root";
00202            }
00203            else
00204            {
00205              file += "knn.physics.far.daikon_04.cedar_phy_bhcurv.L010z185i.root";
00206            }
00207           }
00208  
00209             reg.Set("FillkNNFilePath", file.c_str());
00210 
00211           fInterface->Config(reg);
00212           first = false;
00213        }    
00214 
00215 
00216       if(records.size() > 1 && !fIsMRCC){
00217          fIsMRCC = true;
00218          MSG("SetKNNModule", Msg::kInfo)<<"Multiple NtpStRecords Detected - Shifting to MRCC Mode"<<endl;
00219       }
00220 
00221       pass = pass && AnalyzeRecord(str);
00222   }
00223 
00224   if(!pass) return JobCResult::kFailed;
00225   return JobCResult::kAOK;
00226 }


Member Data Documentation

Reimplemented from JobCModule.

Definition at line 69 of file SetKNNModule.h.

Referenced by Config().

bool SetKNNModule::fFastMode [private]

Definition at line 61 of file SetKNNModule.h.

Referenced by Config(), Reco(), and SetKNNModule().

Definition at line 56 of file SetKNNModule.h.

Referenced by Analyze(), AnalyzeRecord(), Reco(), and ~SetKNNModule().

bool SetKNNModule::fIsMRCC [private]

Definition at line 67 of file SetKNNModule.h.

Referenced by AnalyzeRecord(), Config(), and Reco().

unsigned int SetKNNModule::fNFail [private]

Definition at line 59 of file SetKNNModule.h.

Referenced by AnalyzeRecord(), and ~SetKNNModule().

unsigned int SetKNNModule::fNPass [private]

Definition at line 58 of file SetKNNModule.h.

Referenced by AnalyzeRecord(), and ~SetKNNModule().

std::string SetKNNModule::fPath [private]

Reimplemented from JobCModule.

Definition at line 65 of file SetKNNModule.h.

Referenced by Config(), Reco(), and SetKNNModule().

bool SetKNNModule::fPrintEvent [private]

Definition at line 62 of file SetKNNModule.h.

Referenced by AnalyzeRecord(), and Config().

bool SetKNNModule::fPrintTrack [private]

Definition at line 63 of file SetKNNModule.h.

Referenced by Config().

bool SetKNNModule::fStrip [private]

Definition at line 64 of file SetKNNModule.h.

Referenced by Config().


The documentation for this class was generated from the following files:

Generated on 22 Nov 2017 for loon by  doxygen 1.6.1