FillPIDFromText Class Reference

#include <FillPIDFromText.h>

Inheritance diagram for FillPIDFromText:
JobCModule

List of all members.

Public Member Functions

 FillPIDFromText ()
 ~FillPIDFromText ()
JobCResult Reco (MomNavigator *mom)
virtual void BeginJob ()
void ReadTextFile ()
const RegistryDefaultConfig () const
void Config (const Registry &r)

Private Attributes

int counter
string fTextFile
NuePIDHeader::Decider_t fDecider
std::set< TxtEntryelist
int kSelRes
int kSelFlav

Detailed Description

Definition at line 19 of file FillPIDFromText.h.


Constructor & Destructor Documentation

FillPIDFromText::FillPIDFromText (  ) 

Definition at line 56 of file FillPIDFromText.cxx.

00056                                 :
00057    counter(0),
00058    fTextFile(),
00059    fDecider(NuePIDHeader::kUnknown),
00060    elist(),
00061    kSelRes(-1),
00062    kSelFlav(-1)
00063 
00064 {}

FillPIDFromText::~FillPIDFromText (  ) 

Definition at line 68 of file FillPIDFromText.cxx.

00069 {}


Member Function Documentation

void FillPIDFromText::BeginJob ( void   )  [virtual]

Implement for notification of begin of job

Reimplemented from JobCModule.

Definition at line 73 of file FillPIDFromText.cxx.

References ReadTextFile().

00074 {
00075    ReadTextFile();
00076 }

void FillPIDFromText::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 237 of file FillPIDFromText.cxx.

References fDecider, fTextFile, Registry::Get(), kSelFlav, and kSelRes.

00238 {
00239 //======================================================================
00240 // Configure the module given the Registry r
00241 //======================================================================
00242   const char* tmps;
00243 
00244   if (r.Get("TextFile",tmps)) { fTextFile = (string)(tmps); }
00245   int d;
00246   if (r.Get("Decider",d)) { fDecider = (NuePIDHeader::Decider_t)(d); }
00247   if (r.Get("SelRes",d)) { kSelRes = d; }
00248   if (r.Get("SelFlav",d)) { kSelFlav = d; }
00249 }

const Registry & FillPIDFromText::DefaultConfig ( void   )  const [virtual]

Get the default configuration registry. This should normally be overridden. One useful idiom is to implement it like:

const Registry& MyModule::DefaultConfig() const { static Registry cfg; // never is destroyed if (cfg.Size()) return cfg; // already filled it // set defaults: cfg.Set("TheAnswer",42); cfg.Set("Units","unknown"); return cfg; }

Reimplemented from JobCModule.

Definition at line 211 of file FillPIDFromText.cxx.

References JobCModule::GetName(), Registry::LockValues(), Registry::Set(), and Registry::UnLockValues().

00212 {
00213 //======================================================================
00214 // Supply the default configuration for the module
00215 //======================================================================
00216   static Registry r; // Default configuration for module
00217 
00218   // Set name of config
00219   std::string name = this->GetName();
00220   name += ".config.default";
00221   r.SetName(name.c_str());
00222 
00223   // Set values in configuration
00224   r.UnLockValues();
00225   r.Set("TextFile","pid.txt");
00226   r.Set("Decider",0);
00227   r.Set("SelRes",-1);
00228   r.Set("SelFlav",-1);
00229 
00230   r.LockValues();
00231 
00232   return r;
00233 }

void FillPIDFromText::ReadTextFile (  ) 

Definition at line 253 of file FillPIDFromText.cxx.

References MuELoss::a, elist, fDecider, fTextFile, Msg::kDebug, Msg::kError, MSG, and run().

Referenced by BeginJob().

00254 {
00255 
00256    int nread=0;
00257    std::ifstream in(fTextFile.c_str());
00258    if(!in){
00259       MSG("FilPIDFromText",Msg::kError)<<"Could not open "<<fTextFile<<endl;
00260       return;
00261    }
00262 
00263    int run, subrun, snarl, event, flav, res;
00264    float like;
00265    in>>run;
00266    while(!in.eof()){
00267       nread++;
00268       in>>subrun>>snarl>>event;
00269       if(fDecider==6) {in >> flav >> res; 
00270         MSG("FillPIDFromText",Msg::kDebug)<< run << " " 
00271              << subrun << " " << snarl << " " 
00272              << event << " " << flav << " " << res << endl;}
00273       if(fDecider==7) in >> like;
00274 
00275       TxtEntry *a;
00276       if (fDecider==6) {        TxtEntry t(run,subrun,snarl,event, flav,res);a=&t;}
00277       else if (fDecider==7) {   TxtEntry t(run,subrun,snarl,event, like);a=&t;}
00278       else{                     TxtEntry t(run,subrun,snarl,event);a=&t;}
00279 
00280       elist.insert(*a);
00281       in>>run;
00282    }
00283 
00284    MSG("FillPIDFromText",Msg::kDebug)<<"Read in  "<<nread<<" entries "<<endl;
00285    MSG("FillPIDFromText",Msg::kDebug)<<"elist has  "<<elist.size()<<" entries "<<endl;
00286 }

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

Implement this for read-write access to the MomNavigator

Reimplemented from JobCModule.

Definition at line 80 of file FillPIDFromText.cxx.

References MomNavigator::AdoptFragment(), counter, elist, NtpSRRecord::evthdr, fDecider, NuePIDHeader::GetEventNo(), MomNavigator::GetFragment(), RecRecordImp< T >::GetHeader(), NuePIDHeader::GetRun(), RecDataHeader::GetRun(), NuePIDHeader::GetSnarl(), RecPhysicsHeader::GetSnarl(), RecDataHeader::GetSubRun(), NuePIDHeader::GetSubRun(), RecHeader::GetVldContext(), NuePID::IsNue, Msg::kDebug, Msg::kError, JobCResult::kFailed, Msg::kInfo, JobCResult::kPassed, kSelFlav, kSelRes, NuePID::likelihood, MSG, NtpSREventSummary::nevent, NuePIDHeader::SetDecider(), NuePIDHeader::SetEventNo(), NuePIDHeader::SetEvents(), NuePIDHeader::SetRun(), NuePIDHeader::SetSnarl(), NuePIDHeader::SetSubRun(), and Munits::sr.

00081 {
00082    if(counter%1000==0){
00083       MSG("FillPIDFromText",Msg::kInfo)<<"On entry "<<counter<<endl;
00084    }
00085    counter++;
00086 
00087    //make sure the elist set was filled
00088    if(elist.size()==0){
00089       MSG("FillPIDFromText",Msg::kError)<<"No entries in elist, abort"<<endl;
00090       assert(0);
00091    }
00092 
00093    //read in a NtpSRRecord
00094    NtpSRRecord *sr = static_cast<NtpSRRecord *>(mom->GetFragment("NtpSRRecord"));
00095    if(!sr){
00096       MSG("FillPIDFromText",Msg::kError)<<"Couldn't get a NtpSRRecord from mom"<<endl;
00097       return JobCResult::kFailed;
00098    }
00099    //get vldcontext
00100    VldContext vc=sr->GetHeader().GetVldContext();
00101 
00102    Int_t dec=-1;
00103    Float_t likelihood=1;
00104 
00105    int evtn=sr->evthdr.nevent;
00106    if(evtn==0){
00107       //do something clever, 
00108       //ok, not very clever, just do it once
00109       //make a pid header
00110       NuePIDHeader h(vc);
00111       h.SetSnarl(sr->GetHeader().GetSnarl());
00112       h.SetRun(sr->GetHeader().GetRun());
00113       h.SetSubRun(sr->GetHeader().GetSubRun());
00114       h.SetEventNo(-1);
00115       h.SetEvents(evtn);
00116       h.SetDecider(fDecider);
00117 
00118       //make a pid object
00119       NuePID *pid=new NuePID(h);
00120 
00121 
00122       //is this event in the set?
00123       TxtEntry test(h.GetRun(),h.GetSubRun(),h.GetSnarl(),0);
00124       std::set<TxtEntry>::iterator t=elist.find(test);
00125       if(t==elist.end()){
00126          //not in our list
00127          pid->IsNue=-1;
00128          pid->likelihood=1;
00129       }
00130       else{
00131          //is in our list
00132 
00133         if(fDecider==6) {
00134           Int_t decflav=-1;
00135           Int_t decres=-1;
00136           if(kSelFlav==-1){decflav=1;}
00137           else if((*t).flav==kSelFlav&&kSelFlav>-1){decflav =1;}
00138           if(kSelRes==-1){decres=1;}      
00139           else if((*t).res==kSelRes&&kSelRes>-1){decres = 1;}
00140 
00141           if(decflav==-1||decres==-1){dec=-1;}
00142           else {dec=1;}
00143         }
00144         if(fDecider==7) {likelihood=(*t).like; dec=1;}
00145         MSG("FillPIDFromText",Msg::kDebug) << (*t).run 
00146                          << (*t).subrun << " " << (*t).snarl << " " 
00147                          << (*t).event << " " << (*t).flav << " " << (*t).res 
00148                          << " " << dec << endl;
00149          pid->IsNue=dec;
00150          pid->likelihood=likelihood;
00151       }
00152       MSG("FillPIDFromText",Msg::kDebug)<<"PID decision: "<<pid->IsNue<<endl;
00153       //give pid object to mom to write to file
00154       mom->AdoptFragment(pid);
00155       return JobCResult::kPassed;
00156    }
00157 
00158    //loop over events is NtpSRRecord
00159    for(int i=0;i<evtn;i++){
00160       //make a pid header
00161       NuePIDHeader h(vc);
00162       h.SetSnarl(sr->GetHeader().GetSnarl());
00163       h.SetRun(sr->GetHeader().GetRun());
00164       h.SetSubRun(sr->GetHeader().GetSubRun());
00165       h.SetEventNo(i);
00166       h.SetEvents(evtn);
00167       h.SetDecider(fDecider);
00168 
00169       //make a pid object
00170       NuePID *pid=new NuePID(h);
00171 
00172       //is this event in the set?
00173       TxtEntry test(h.GetRun(),h.GetSubRun(),h.GetSnarl(),h.GetEventNo());
00174       std::set<TxtEntry>::iterator t=elist.find(test);
00175       if(t==elist.end()){
00176          //not in our list
00177          pid->IsNue=-1;
00178          pid->likelihood=1;
00179       }
00180       else{
00181         if(fDecider==6) {
00182           Int_t decflav=-1;
00183           Int_t decres=-1;
00184           if(kSelFlav==-1){decflav=1;}
00185           else if((*t).flav==kSelFlav&&kSelFlav>-1){decflav =1;}
00186           if(kSelRes==-1){decres=1;}      
00187           else if((*t).res==kSelRes&&kSelRes>-1){decres = 1;}
00188 
00189           if(decflav==-1||decres==-1){dec=-1;}
00190           else {dec=1;}
00191         }
00192         if(fDecider==7) {likelihood=(*t).like; dec=1;}
00193         MSG("FillPIDFromText",Msg::kDebug)<< (*t).run 
00194              << (*t).subrun << " " << (*t).snarl << " " 
00195              << (*t).event << " " << (*t).flav << " " << (*t).res 
00196              << " " << dec << endl;
00197          //is in our list
00198          pid->IsNue=dec;
00199          pid->likelihood=likelihood;
00200       }
00201       MSG("FillPIDFromText",Msg::kDebug)<<"PID decision: "<<pid->IsNue<<endl;
00202       //give pid object to mom to write to file}
00203       mom->AdoptFragment(pid);
00204    }
00205 
00206   return JobCResult::kPassed; // kNoDecision, kFailed, etc.
00207 }


Member Data Documentation

int FillPIDFromText::counter [private]

Definition at line 37 of file FillPIDFromText.h.

Referenced by Reco().

std::set<TxtEntry> FillPIDFromText::elist [private]

Definition at line 40 of file FillPIDFromText.h.

Referenced by ReadTextFile(), and Reco().

Definition at line 39 of file FillPIDFromText.h.

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

string FillPIDFromText::fTextFile [private]

Definition at line 38 of file FillPIDFromText.h.

Referenced by Config(), and ReadTextFile().

Definition at line 43 of file FillPIDFromText.h.

Referenced by Config(), and Reco().

int FillPIDFromText::kSelRes [private]

Definition at line 42 of file FillPIDFromText.h.

Referenced by Config(), and Reco().


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

Generated on 2 Nov 2017 for loon by  doxygen 1.6.1