Anp::SelectKinem Class Reference

#include <SelectKinem.h>

Inheritance diagram for Anp::SelectKinem:
Anp::AlgSnarl Anp::Base

List of all members.

Public Member Functions

 SelectKinem ()
virtual ~SelectKinem ()
bool Run (Record &record)
void Config (const Registry &reg)
void Set (TDirectory *dir)
bool Init (const Header &header)
void End (const DataBlock &block)

Private Types

enum  Kinematic {
  kBad, kNC, kCC, kQES,
  kRES, kDIS, kExitBack, kExitSide,
  kExitCalr, kExitSpec, kStop
}
enum  Selection {
  kUnknown, kAll, kAntiEasy, kAntiReco,
  kEasy, kReco
}

Private Member Functions

AlgSnarlPtr GetAlg (const std::string &key)
bool Select (Event &event, const Record &record, const std::string &key) const
bool Pass (const Event &event, const Record &record, const Kinematic kinem, const Selection selec) const
Kinematic GetKinematic (const std::string &key) const
Selection GetSelection (const std::string &key) const

Private Attributes

TDirectory * fDir
std::string fAlgList
std::string fAlgName
std::string fDirName
std::string fRegPath
Registry fConfig
Header fHeader
Record fRecord
int fDISKey
int fQESKey
double fDISCut
double fQESCut
double fEHCut
double fUVCut
double fW2Cut
std::vector< std::string > fKeys
std::map< std::string,
AlgSnarlPtr
fAlgMap

Detailed Description

Definition at line 23 of file SelectKinem.h.


Member Enumeration Documentation

Enumerator:
kBad 
kNC 
kCC 
kQES 
kRES 
kDIS 
kExitBack 
kExitSide 
kExitCalr 
kExitSpec 
kStop 

Definition at line 42 of file SelectKinem.h.

00043       {
00044          kBad, kNC, kCC, kQES, kRES, kDIS, kExitBack, kExitSide, kExitCalr, kExitSpec, kStop
00045       };

Enumerator:
kUnknown 
kAll 
kAntiEasy 
kAntiReco 
kEasy 
kReco 

Definition at line 47 of file SelectKinem.h.

00048       {
00049          kUnknown, kAll, kAntiEasy, kAntiReco, kEasy, kReco
00050       };


Constructor & Destructor Documentation

Anp::SelectKinem::SelectKinem (  ) 

Definition at line 31 of file SelectKinem.cxx.

00032    :fDir(0),
00033     fAlgList(""),
00034     fAlgName(""),
00035     fDirName(""),
00036     fRegPath("SelectKinem.txt"),
00037     fConfig(false),
00038     fHeader(),
00039     fRecord(),
00040     fDISKey(1523),
00041     fQESKey(1521),
00042     fDISCut(0.25),
00043     fQESCut(0.75),
00044     fEHCut(0.15),
00045     fUVCut(-1.0),
00046     fW2Cut(4.0)
00047 {
00048 }

Anp::SelectKinem::~SelectKinem (  )  [virtual]

Definition at line 51 of file SelectKinem.cxx.

00052 {
00053 }


Member Function Documentation

void Anp::SelectKinem::Config ( const Registry reg  )  [virtual]

Reimplemented from Anp::AlgSnarl.

Definition at line 109 of file SelectKinem.cxx.

References fAlgList, fAlgName, fConfig, fDirName, fDISCut, fDISKey, fEHCut, fKeys, fQESCut, fQESKey, fRegPath, fUVCut, fW2Cut, Registry::Get(), GetKinematic(), GetSelection(), infile, it, kAll, kBad, Registry::KeyExists(), kUnknown, Registry::Merge(), Anp::ReadRegistry(), reg, Registry::Set(), UtilString::StringTok(), Registry::UnLockKeys(), and Registry::UnLockValues().

00110 {
00111    //
00112    // Configure self
00113    //
00114 
00115    const char *value_path = 0;
00116    if(reg_.Get("SelectKinemRegPath", value_path) && value_path)
00117    {
00118       fRegPath = value_path;
00119    }
00120    
00121    Registry tmp(false);
00122    Registry reg(reg_);
00123 
00124    ifstream infile(fRegPath.c_str());
00125    if(infile.is_open() && Anp::ReadRegistry(fRegPath, tmp, true))
00126    {
00127       cout << "SelectKinem::Config - read registry configuration from: " << endl
00128            << "   " << fRegPath << endl;
00129 
00130       reg.UnLockKeys();
00131       reg.UnLockValues();
00132       reg.Merge(tmp);
00133    }
00134 
00135    const char *value_char = 0;
00136    if(reg.Get("SelectKinemAlgName", value_char) && value_char)
00137    {
00138       fAlgName = value_char;
00139    }
00140 
00141    value_char = 0;
00142    if(reg.Get("SelectKinemDirName", value_char) && value_char)
00143    {
00144       fDirName = value_char;
00145    }
00146 
00147    reg.Get("SelectKinemDISKey", fDISKey);
00148    reg.Get("SelectKinemQESKey", fQESKey);
00149    reg.Get("SelectKinemDISCut", fDISCut);
00150    reg.Get("SelectKinemQESCut", fQESCut);
00151 
00152    reg.Get("SelectKinemEHCut", fEHCut);
00153    reg.Get("SelectKinemUVCut", fUVCut);
00154    reg.Get("SelectKinemW2Cut", fW2Cut);
00155 
00156    //
00157    // Merge main registry and reset some keys used by RunAlgSnarl
00158    //
00159    fConfig.Merge(reg);
00160    fConfig.Set("AlgEventList", "");
00161    fConfig.Set("AlgSnarlList", "");
00162    fConfig.Set("AlgSnarlDirName", "");
00163    fConfig.Set("AlgSnarlMakeCopy", "no");
00164    fConfig.Set("AlgSnarlPrintEnd", "no");
00165 
00166    //
00167    // Read and set list of algorithms from SelectKinemList key
00168    //
00169    value_char = 0;
00170    if(reg.Get("SelectKinemList", value_char) && value_char)
00171    {
00172       const string alist = value_char;
00173       if(alist.find("SelectKinem") == string::npos)
00174       {
00175          fAlgList = alist;
00176          if     (fAlgName.find("Event") != string::npos) fConfig.Set("AlgEventList", alist.c_str());
00177          else if(fAlgName.find("Snarl") != string::npos) fConfig.Set("AlgSnarlList", alist.c_str());
00178       }
00179       else
00180       {
00181          cerr << "SelectKinem::Config - algorithm list should not include self" << endl; 
00182       }
00183    }
00184 
00185    if(reg.Get("SelectKinem", value_char) && value_char)
00186    {
00187       vector<string> svec;
00188 
00189       UtilString::StringTok(svec, string(value_char), ", ");
00190       
00191       for(vector<string>::const_iterator sit = svec.begin(); sit != svec.end(); ++sit)
00192       {
00193          const string &key = *sit;
00194          
00195          const Selection selec = SelectKinem::GetSelection(key);
00196          const Kinematic kinem = SelectKinem::GetKinematic(key);
00197 
00198          if(selec == kAll || (kinem != kBad && selec != kUnknown))
00199          {
00200             fKeys.push_back(key);
00201             continue;       
00202          }
00203          
00204          cerr << "SelectKinem::Config - ignoring unknown key: " << key << endl;
00205       }
00206       
00207       std::sort(fKeys.begin(), fKeys.end());
00208    }
00209 
00210    if(fConfig.KeyExists("PrintConfig") || fConfig.KeyExists("PrintKinem"))
00211    {
00212       cout << "SelectKinem::Config" << endl
00213            << "   AlgList = " << fAlgList << endl
00214            << "   AlgName = " << fAlgName << endl
00215            << "   DirName = " << fDirName << endl
00216            << "   RegPath = " << fRegPath << endl
00217            << "   DISKey = " << fDISKey << endl
00218            << "   QESKey = " << fQESKey << endl
00219            << "   DISCut = " << fDISCut << endl
00220            << "   QESCut = " << fQESCut << endl
00221            << "   EHCut = " << fEHCut << endl
00222            << "   UVCut = " << fUVCut << endl
00223            << "   W2Cut = " << fW2Cut << endl
00224            << "   Added " << fKeys.size() << " keys" << endl;
00225       
00226       for(vector<string>::const_iterator it = fKeys.begin(); it != fKeys.end(); ++it)
00227       {
00228          if(it == fKeys.begin())
00229          {
00230             cout << "   " << *it;
00231          }
00232          else if(it + 1 == fKeys.end())
00233          {
00234             cout << " " << *it << endl;
00235          }
00236          else
00237          {
00238             cout << " " << *it;
00239          }
00240       }
00241    }
00242 }

void Anp::SelectKinem::End ( const DataBlock block  )  [virtual]

Reimplemented from Anp::AlgSnarl.

Definition at line 269 of file SelectKinem.cxx.

References fAlgMap, Munits::second, and Anp::Handle< T >::valid().

00270 {
00271    for(map<string, AlgSnarlPtr>::iterator ialg = fAlgMap.begin(); ialg != fAlgMap.end(); ++ialg)
00272    {
00273       AlgSnarlPtr alg = ialg -> second;
00274 
00275       if(alg.valid())
00276       {
00277          alg -> End(block);
00278       }
00279    }
00280    
00281    fAlgMap.clear();
00282 }

AlgSnarlPtr Anp::SelectKinem::GetAlg ( const std::string &  key  )  [private]

Referenced by Run().

Kinematic Anp::SelectKinem::GetKinematic ( const std::string &  key  )  const [private]

Referenced by Config().

Selection Anp::SelectKinem::GetSelection ( const std::string &  key  )  const [private]

Referenced by Config().

bool Anp::SelectKinem::Init ( const Header header  )  [virtual]

Reimplemented from Anp::AlgSnarl.

Definition at line 256 of file SelectKinem.cxx.

References fHeader, and Anp::Header::IsValid().

00257 {
00258    //
00259    // Configure self and save copy of Header
00260    //
00261    assert(!fHeader.IsValid() && "SelectKinem already has valid header - logic errror");
00262 
00263    fHeader = header;
00264 
00265    return fHeader.IsValid();
00266 }

bool Anp::SelectKinem::Pass ( const Event event,
const Record record,
const Kinematic  kinem,
const Selection  selec 
) const [private]

Definition at line 342 of file SelectKinem.cxx.

References Anp::RecoNu::EHad(), Anp::RecoNu::ExitBack(), Anp::RecoNu::ExitSide(), fDISCut, fDISKey, fEHCut, fQESCut, fQESKey, fUVCut, fW2Cut, Anp::Record::GetHeader(), Anp::Event::GetNu(), Anp::GetUVAssymForQES(), Anp::Header::IsNear(), kBad, kDIS, kEasy, kExitBack, kExitCalr, kExitSide, kExitSpec, kQES, kReco, kRES, kStop, Anp::LongestTrack(), Anp::RecoNu::Stop(), Anp::Record::TrackEnd(), and Anp::RecoNu::W2().

00344 {
00345    //
00346    // Check if event passed kinematic selections
00347    //
00348 
00349    if(kinem == kBad)
00350    {
00351       cerr << "SelectKinem::Pass - unknown kinematics: " << kinem << endl;
00352       return false;
00353    }
00354 
00355    if(selec == kReco)
00356    {
00357       if     (kinem == kQES && event[fQESKey] > fQESCut) return true;
00358       else if(kinem == kDIS && event[fDISKey] > fDISCut) return true;
00359       else if(kinem == kRES && 
00360               !SelectKinem::Pass(event, record, kQES, kReco) && 
00361               !SelectKinem::Pass(event, record, kDIS, kReco))
00362       {
00363          return true;
00364       }
00365       else if(kinem == kExitBack && event.GetNu().ExitBack()) return true;
00366       else if(kinem == kExitSide && event.GetNu().ExitSide()) return true;
00367       else if(kinem == kStop     && event.GetNu().Stop())     return true;
00368       else if(kinem == kExitCalr || kinem == kExitSpec)
00369       {
00370          if(event.GetNu().ExitSide() && record.GetHeader().IsNear())
00371          {
00372             const TrackIter itrack = Anp::LongestTrack(event, record);
00373             if(itrack != record.TrackEnd())
00374             {
00375                if(kinem == kExitCalr && itrack -> GetBasic().EndPlane() < 121) return true;
00376                if(kinem == kExitSpec && itrack -> GetBasic().EndPlane() > 120) return true;
00377             }
00378          }
00379       }
00380 
00381       return false;
00382    }
00383    else if(selec == kEasy)
00384    {      
00385       if(event.GetNu().EHad() < fEHCut)
00386       {
00387          if(kinem == kQES) return true;
00388          return false;
00389       }
00390       else
00391       {
00392          if(fUVCut > 0.0 && std::fabs(Anp::GetUVAssymForQES(event, record)) > fUVCut)
00393          {
00394             if(kinem == kQES) return true;
00395             return false;
00396          }
00397 
00398          if(kinem == kQES) return false;
00399          
00400          if(event.GetNu().W2() < fW2Cut)
00401          {
00402             if(kinem == kRES) return true;
00403          }
00404          else
00405          {
00406             if(kinem == kDIS) return true;
00407          }
00408 
00409          return false;
00410       }
00411    }
00412 
00413    cerr << "SelectKinem::Pass - uknown selection key: " << selec << endl;
00414 
00415    return false;
00416 }

bool Anp::SelectKinem::Run ( Record record  )  [virtual]

Implements Anp::AlgSnarl.

Definition at line 56 of file SelectKinem.cxx.

References Anp::CleanRecord(), Anp::Record::Erase(), Anp::Record::EventBeg(), Anp::Record::EventBegIterator(), Anp::Record::EventEnd(), Anp::Record::EventEndIterator(), fKeys, fRecord, GetAlg(), Anp::Record::GetHeader(), Anp::Header::IsData(), Select(), and Anp::Handle< T >::valid().

00057 {    
00058    //
00059    // Create empty Record class, code runs faster when this is outside loop.   
00060    //
00061    for(vector<string>::const_iterator kit = fKeys.begin(); kit != fKeys.end(); ++kit)
00062    {
00063       const string &key = *kit;
00064 
00065       AlgSnarlPtr alg = SelectKinem::GetAlg(key);
00066       if(!alg.valid())
00067       {
00068          continue;
00069       }
00070 
00071       if(key.find("true") != string::npos && record.GetHeader().IsData())
00072       {
00073          continue;
00074       }
00075       
00076       //
00077       // Fill copy with Record content
00078       //
00079       fRecord = record;
00080 
00081       //
00082       // Remove events that do not pass current selection
00083       //
00084       EventIterator ievent = fRecord.EventBegIterator();
00085       while(ievent != fRecord.EventEndIterator())
00086       {
00087          if(SelectKinem::Select(*ievent, fRecord, key))
00088          {
00089             ++ievent;
00090          }
00091          else
00092          {
00093             ievent = fRecord.Erase(ievent);
00094          }
00095       }
00096       
00097       //
00098       // Remove tracks and showers that do not match selected events
00099       //
00100       Anp::CleanRecord(fRecord.EventBeg(), fRecord.EventEnd(), fRecord);
00101       
00102       alg -> Run(fRecord);      
00103    }
00104 
00105    return true;
00106 }

bool Anp::SelectKinem::Select ( Event event,
const Record record,
const std::string &  key 
) const [private]

Referenced by Run().

void Anp::SelectKinem::Set ( TDirectory *  dir  )  [virtual]

Reimplemented from Anp::AlgSnarl.

Definition at line 245 of file SelectKinem.cxx.

References fDir, fDirName, and Anp::GetDir().

00246 {
00247    if(!dir)
00248    {
00249       return;
00250    }
00251    
00252    fDir = Anp::GetDir(fDirName, dir);
00253 }


Member Data Documentation

std::string Anp::SelectKinem::fAlgList [private]

Definition at line 68 of file SelectKinem.h.

Referenced by Config().

std::map<std::string, AlgSnarlPtr> Anp::SelectKinem::fAlgMap [private]

Definition at line 87 of file SelectKinem.h.

Referenced by End().

std::string Anp::SelectKinem::fAlgName [private]

Definition at line 69 of file SelectKinem.h.

Referenced by Config().

Definition at line 73 of file SelectKinem.h.

Referenced by Config().

TDirectory* Anp::SelectKinem::fDir [private]

Definition at line 66 of file SelectKinem.h.

Referenced by Set().

std::string Anp::SelectKinem::fDirName [private]

Definition at line 70 of file SelectKinem.h.

Referenced by Config(), and Set().

double Anp::SelectKinem::fDISCut [private]

Definition at line 79 of file SelectKinem.h.

Referenced by Config(), and Pass().

Definition at line 77 of file SelectKinem.h.

Referenced by Config(), and Pass().

double Anp::SelectKinem::fEHCut [private]

Definition at line 81 of file SelectKinem.h.

Referenced by Config(), and Pass().

Definition at line 74 of file SelectKinem.h.

Referenced by Init().

std::vector<std::string> Anp::SelectKinem::fKeys [private]

Definition at line 85 of file SelectKinem.h.

Referenced by Config(), and Run().

double Anp::SelectKinem::fQESCut [private]

Definition at line 80 of file SelectKinem.h.

Referenced by Config(), and Pass().

Definition at line 78 of file SelectKinem.h.

Referenced by Config(), and Pass().

Definition at line 75 of file SelectKinem.h.

Referenced by Run().

std::string Anp::SelectKinem::fRegPath [private]

Definition at line 71 of file SelectKinem.h.

Referenced by Config().

double Anp::SelectKinem::fUVCut [private]

Definition at line 82 of file SelectKinem.h.

Referenced by Config(), and Pass().

double Anp::SelectKinem::fW2Cut [private]

Definition at line 83 of file SelectKinem.h.

Referenced by Config(), and Pass().


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

Generated on 16 Apr 2018 for loon by  doxygen 1.6.1