Anp::SelectFiducial Class Reference

#include <SelectFiducial.h>

Inheritance diagram for Anp::SelectFiducial:
Anp::AlgSnarl Anp::Base

List of all members.

Public Member Functions

 SelectFiducial ()
virtual ~SelectFiducial ()
bool Run (Record &record)
void Config (const Registry &reg)
void End (const DataBlock &)

Private Types

typedef std::pair< double, double > PassFail

Private Member Functions

bool Pass (const Record &record, const Vertex &vtx, const std::string &base) const
bool PassTrack (const Record &record, const Vertex &vtx) const
bool PassTruth (const Record &record, const Truth &truth) const
void Count (const std::string &key, bool pass, double weight)

Private Attributes

FiducialCut fCut
std::map< std::string, PassFailfCountMap

Detailed Description

Definition at line 26 of file SelectFiducial.h.


Member Typedef Documentation

typedef std::pair<double,double> Anp::SelectFiducial::PassFail [private]

Definition at line 41 of file SelectFiducial.h.


Constructor & Destructor Documentation

Anp::SelectFiducial::SelectFiducial (  ) 

Definition at line 21 of file SelectFiducial.cxx.

00022    :fCut(),
00023     fCountMap()
00024 {
00025 }

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

Definition at line 28 of file SelectFiducial.cxx.

00029 {
00030 }


Member Function Documentation

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

Reimplemented from Anp::AlgSnarl.

Definition at line 257 of file SelectFiducial.cxx.

References fCut, Registry::Get(), Anp::FiducialCut::Init(), Registry::KeyExists(), and Anp::FiducialCut::Print().

00258 {
00259    //
00260    // Configure Registry values
00261    //
00262 
00263    string path = "";
00264 
00265    const char *value_char = 0;
00266    if(reg.Get("FiducialCutPath", value_char) && value_char)
00267    {
00268       path = value_char;
00269    }
00270 
00271    //
00272    // Read Registry file with fiducial volume definition
00273    //
00274    fCut.Init(path);
00275 
00276    if(reg.KeyExists("PrintConfig"))
00277    {
00278       cout << "SelectFiducial::Config" << endl;
00279       fCut.Print();
00280    }
00281 }

void Anp::SelectFiducial::Count ( const std::string &  key,
bool  pass,
double  weight 
) [private]

Referenced by Run().

void Anp::SelectFiducial::End ( const DataBlock  )  [virtual]

Reimplemented from Anp::AlgSnarl.

Definition at line 284 of file SelectFiducial.cxx.

References fCountMap, Munits::second, and size.

00285 {
00286    //
00287    // Print count for all used keys
00288    //
00289 
00290    //
00291    // Compute widths of three fields: string size and two integers
00292    //
00293    unsigned widthS = 0, widthN1 = 0, widthN2 = 0;
00294 
00295    for(map<string, PassFail>::const_iterator cit = fCountMap.begin(); cit != fCountMap.end(); ++cit)
00296    {
00297       const double d1 = (cit -> second).first;
00298       const double d2 = (cit -> second).second;
00299     
00300       unsigned w1 = 1;
00301       unsigned w2 = 1;
00302 
00303       if(d1 > 1.0)
00304       {
00305          w1 += static_cast<unsigned int>(std::log10(d1));
00306       }
00307       if(d2 > 1.0)
00308       {
00309          w2 += static_cast<unsigned int>(std::log10(d2));
00310       }
00311       
00312       if(cit == fCountMap.begin())
00313       {
00314          widthS  = (cit -> first).size();
00315          widthN1 = w1;
00316          widthN2 = w2;
00317       }
00318       else
00319       {
00320          widthS  = std::max<unsigned int>(widthS, (cit -> first).size());
00321          widthN1 = std::max<unsigned int>(widthN1, w1);
00322          widthN2 = std::max<unsigned int>(widthN2, w2);
00323       }
00324    }
00325 
00326    if(widthS < 1)
00327    {
00328       return;
00329    }
00330 
00331    //
00332    // Actually print keys and values
00333    //
00334    for(map<string, PassFail>::const_iterator cit = fCountMap.begin(); cit != fCountMap.end(); ++cit)
00335    {
00336       const double d1 = (cit -> second).first;
00337       const double d2 = (cit -> second).second;
00338 
00339       const unsigned int n1 = static_cast<unsigned int>(d1);
00340       const unsigned int n2 = static_cast<unsigned int>(d2);
00341       
00342       cout << "   " << setw(widthS) << left << cit -> first << ": (pass, fail, frac) = ("
00343            << setw(widthN1) << std::right << n1 << ", "
00344            << setw(widthN2) << std::right << n2 << ", ";
00345       
00346       double ratio = 0.0;
00347       if(d1+d2 > 0.0)
00348       {
00349          ratio = d1/(d1+d2);
00350       }
00351 
00352       cout << setw(6) << setprecision(4) << ratio << ")" << endl;
00353    }
00354 }

bool Anp::SelectFiducial::Pass ( const Record record,
const Vertex vtx,
const std::string &  base 
) const [private]

Referenced by PassTrack(), and Run().

bool Anp::SelectFiducial::PassTrack ( const Record record,
const Vertex vtx 
) const [private]

Definition at line 435 of file SelectFiducial.cxx.

References Anp::Vertex::CosU(), Anp::Vertex::CosV(), Anp::Vertex::CosZ(), fCut, Anp::Vertex::IsFiducial(), Pass(), Anp::FiducialCut::TrackZOffset(), Anp::Vertex::U(), Anp::Vertex::V(), and Anp::Vertex::Z().

Referenced by Run().

00436 {
00437    return Pass(record, Anp::Vertex(vtx.U(),
00438                                    vtx.V(),
00439                                    vtx.Z() - fCut.TrackZOffset(),
00440                                    vtx.CosU(),
00441                                    vtx.CosV(),
00442                                    vtx.CosZ(),
00443                                    vtx.IsFiducial()), "Track");
00444 }

bool Anp::SelectFiducial::PassTruth ( const Record record,
const Truth truth 
) const [private]

Definition at line 447 of file SelectFiducial.cxx.

References Anp::Record::EventBeg(), Anp::Record::EventEnd(), find(), Anp::Record::ShowerBeg(), Anp::Record::ShowerEnd(), Anp::Record::TrackBeg(), and Anp::Record::TrackEnd().

Referenced by Run().

00448 {
00449    //
00450    // Select truth info objects that reconstructed event or track
00451    //
00452    if(std::find(record.EventBeg(),  record.EventEnd(),  truth) != record.EventEnd()  ||
00453       std::find(record.TrackBeg(),  record.TrackEnd(),  truth) != record.TrackEnd()  ||
00454       std::find(record.ShowerBeg(), record.ShowerEnd(), truth) != record.ShowerEnd())
00455    {
00456       return true;
00457    }
00458 
00459    return false;
00460 }

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

Implements Anp::AlgSnarl.

Definition at line 33 of file SelectFiducial.cxx.

References Count(), Anp::Record::Erase(), Anp::FiducialCut::Erase(), Anp::Record::EventBeg(), Anp::Record::EventBegIterator(), Anp::Record::EventEnd(), Anp::Record::EventEndIterator(), fCut, Anp::FiducialCut::FiducialKey(), find(), Anp::Record::FindEvent(), Anp::Record::GetNStdHeps(), Anp::LongestTrack(), Pass(), PassTrack(), PassTruth(), Anp::FiducialCut::SelectStdHep(), Anp::Record::ShowerBeg(), Anp::Record::ShowerBegIterator(), Anp::Record::ShowerEnd(), Anp::Record::ShowerEndIterator(), Anp::Record::StdHepBegIterator(), Anp::Record::StdHepEndIterator(), Anp::Record::TrackBeg(), Anp::Record::TrackBegIterator(), Anp::Record::TrackEnd(), Anp::Record::TrackEndIterator(), Anp::Record::TruthBeg(), Anp::Record::TruthBegIterator(), Anp::Record::TruthEnd(), Anp::Record::TruthEndIterator(), Anp::FiducialCut::UseTrackVtx(), and Anp::FiducialCut::Valid().

00034 {
00035    //
00036    // 1) Pass reconstructed events with vertex in the fiducal volume
00037    //
00038    // 2) Pass a true event if either the true vertex is in the fiducial volume
00039    //    or true event matches a reconstructed event with the vertex the fiducial volume
00040    //
00041    // 3) Remove TruthReco objects from Truth that do not match selected
00042    //    reconstructed events and tracks
00043    //
00044    // 4) Pass StdHep record if it matches a passed MCTruth record
00045    //    or it matches a recostructed object that passed fiducial cuts.
00046    //
00047 
00048    if(!fCut.Valid()) return false;
00049 
00050    //
00051    // Select reconstructed events with fiducial vertex OR matching fiducial track
00052    //
00053    EventIterator ievent = record.EventBegIterator();
00054    while(ievent != record.EventEndIterator())
00055    {
00056       bool pass_fiducial = false;
00057 
00058       const TrackIter itrack = Anp::LongestTrack(*ievent, record);
00059       if(fCut.UseTrackVtx() && itrack != record.TrackEnd())
00060       {
00061          pass_fiducial = SelectFiducial::PassTrack(record, itrack -> GetBegVtx());
00062       }
00063       else
00064       {
00065          pass_fiducial = SelectFiducial::Pass(record, ievent -> GetVtx(), "Event");
00066       }
00067 
00068       //
00069       // Add FiducialKey value to signal that this is fiducial event
00070       //
00071       if(fCut.FiducialKey() > 0 && pass_fiducial)
00072       {
00073          ievent -> Add(fCut.FiducialKey(), 1.0);
00074       }
00075 
00076       SelectFiducial::Count("EventW", pass_fiducial, ievent -> Weight());
00077 
00078       if(pass_fiducial || !fCut.Erase())
00079       {
00080          ++ievent;
00081       }
00082       else
00083       {
00084          ievent = record.Erase(ievent);
00085       }
00086    }
00087 
00088    //
00089    // Select reconstructed tracks with fiducial vertex OR matching fiducial event
00090    //
00091    TrackIterator itrack = record.TrackBegIterator();
00092    while(itrack != record.TrackEndIterator())
00093    {      
00094       bool pass_fiducial = false;
00095       
00096       if(record.FindEvent(*itrack) != record.EventEnd())
00097       {
00098          pass_fiducial = true;
00099       }
00100       else if(SelectFiducial::PassTrack(record, itrack -> GetBegVtx()))
00101       {
00102          pass_fiducial = true;
00103       }
00104       
00105       SelectFiducial::Count("TrackW", pass_fiducial, itrack -> Weight());
00106       
00107       if(pass_fiducial || !fCut.Erase())
00108       {
00109          ++itrack;
00110       }
00111       else
00112       {
00113          itrack = record.Erase(itrack);
00114       }
00115    }
00116 
00117    //
00118    // Select reconstructed showers matching fiducial event
00119    //
00120    ShowerIterator ishower = record.ShowerBegIterator();
00121    while(ishower != record.ShowerEndIterator())
00122    {      
00123       bool pass_fiducial = false;
00124       if(record.FindEvent(*ishower) != record.EventEnd())
00125       {
00126          pass_fiducial = true;
00127       }
00128 
00129       SelectFiducial::Count("ShowerW", pass_fiducial, ishower -> Weight());
00130 
00131       if(pass_fiducial || !fCut.Erase())
00132       {
00133          ++ishower;
00134       }
00135       else
00136       {
00137          ishower = record.Erase(ishower);
00138       }
00139    }
00140 
00141    //
00142    // Select true record if 
00143    //    a) truth record matches reconstructed event, track or shower
00144    //    b) OR true vertex is within fiducial volume
00145    //
00146    TruthIterator itruth = record.TruthBegIterator();
00147    while(itruth != record.TruthEndIterator())
00148    {
00149       bool pass_fiducial = false;
00150       if(SelectFiducial::PassTruth(record, *itruth))
00151       {
00152          pass_fiducial = true;
00153       }
00154       if(SelectFiducial::Pass(record, itruth -> GetVtx(), "Truth"))
00155       {
00156          // set fiducial status
00157          pass_fiducial = true;
00158          itruth -> SetFiducial(true);
00159 
00160          //
00161          // Add FiducialKey value to signal that this is true fiducial interaction
00162          //
00163          if(fCut.FiducialKey() > 0)
00164          {
00165             itruth -> Add(fCut.FiducialKey(), 1.0);
00166          }
00167       } else {
00168         itruth -> SetFiducial(false);
00169       }
00170       
00171       string key;
00172       if     (itruth -> IsNC()) key = "TruthNCW";
00173       else if(itruth -> IsCC()) key = "TruthCCW";
00174 
00175       SelectFiducial::Count(key,        pass_fiducial, itruth -> Weight());
00176       SelectFiducial::Count("TruthAll", pass_fiducial, itruth -> Weight());     
00177 
00178       if(pass_fiducial || !fCut.Erase())
00179       {
00180          ++itruth;
00181       }
00182       else
00183       {
00184          itruth = record.Erase(itruth);
00185       }
00186    }
00187 
00188    for(TruthIterator itruth = record.TruthBegIterator(); itruth != record.TruthEndIterator(); ++itruth)
00189    {
00190       TruthRecoIterator ireco = itruth -> RecoBegIterator(); 
00191       while(ireco != itruth -> RecoEndIterator())
00192       {
00193          if(!fCut.Erase() ||
00194             std::find(record.EventBeg(),  record.EventEnd(),  *ireco) != record.EventEnd()  ||
00195             std::find(record.TrackBeg(),  record.TrackEnd(),  *ireco) != record.TrackEnd()  ||
00196             std::find(record.ShowerBeg(), record.ShowerEnd(), *ireco) != record.ShowerEnd())
00197          {
00198             ++ireco;
00199          }
00200          else
00201          {
00202             ireco = itruth -> Erase(ireco);
00203          }
00204       }
00205    }
00206 
00207    //
00208    // Select StdHep objects that match selected true interactions
00209    //
00210    if(fCut.SelectStdHep())
00211    {
00212       StdHepIterator ihep = record.StdHepBegIterator();
00213       while(ihep != record.StdHepEndIterator())
00214       {
00215          bool matched = false;
00216          for(TruthIter itruth = record.TruthBeg(); itruth != record.TruthEnd(); ++itruth)
00217          {
00218             if(itruth -> Match(*ihep))
00219             {
00220                matched = true;
00221                break;
00222             }
00223             
00224             for(TruthRecoIter reco = itruth -> RecoBeg(); reco != itruth -> RecoEnd(); ++reco)
00225             {
00226                if(ihep -> StdHepIndex() == reco -> StdHepIndex())
00227                {
00228                   matched = true;
00229                   break;
00230                }
00231             }
00232             
00233             if(matched) break;
00234          }
00235 
00236          SelectFiducial::Count("StdHepN", matched, 1.0);
00237          
00238          if(matched)
00239          {
00240             ++ihep;
00241          }
00242          else
00243          {
00244             ihep = record.Erase(ihep);
00245          }
00246       }
00247    }
00248    else
00249    {
00250       Count("StdHepN", true, record.GetNStdHeps());
00251    }
00252 
00253    return true;
00254 }


Member Data Documentation

std::map<std::string, PassFail> Anp::SelectFiducial::fCountMap [private]

Definition at line 56 of file SelectFiducial.h.

Referenced by End().

Definition at line 54 of file SelectFiducial.h.

Referenced by Config(), PassTrack(), and Run().


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

Generated on 19 Jan 2018 for loon by  doxygen 1.6.1