Anp::SelectSpill Class Reference

#include <SelectSpill.h>

Inheritance diagram for Anp::SelectSpill:
Anp::AlgSnarl Anp::Base

List of all members.

Public Member Functions

 SelectSpill ()
virtual ~SelectSpill ()
bool Run (Record &record)
void Config (const Registry &reg)
bool Init (const Header &header)
void End (const DataBlock &)

Private Types

typedef std::map< std::string,
std::pair< unsigned int,
double > > 
BeamMap

Private Member Functions

bool Count (const std::string &key, const Header &header)
bool PassBeam (const Header &header)
bool PassCoil (const Header &header)
bool PassList (const Header &header)
bool ReadList (const Header &header)

Private Attributes

std::string fBeam
std::string fPathBad
std::string fPathGood
std::string fPathList
std::ofstream fList
BeamMap fMap
bool fListData
bool fPrint
bool fReverse
int fTrigger
double fMinICoil
double fMaxICoil
std::vector< RunSubrunfListBad
std::vector< RunSubrunfListGood
std::vector< RunSubrunfMissGood

Detailed Description

Definition at line 27 of file SelectSpill.h.


Member Typedef Documentation

typedef std::map<std::string, std::pair<unsigned int, double> > Anp::SelectSpill::BeamMap [private]

Definition at line 53 of file SelectSpill.h.


Constructor & Destructor Documentation

Anp::SelectSpill::SelectSpill (  ) 

Definition at line 27 of file SelectSpill.cxx.

00028    :fBeam(""),
00029     fListData(false),
00030     fPrint(false),
00031     fReverse(false),
00032     fTrigger(0),
00033     fMinICoil(4600),
00034     fMaxICoil(5200)
00035 {
00036 }

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

Definition at line 39 of file SelectSpill.cxx.

00040 {
00041 }


Member Function Documentation

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

Reimplemented from Anp::AlgSnarl.

Definition at line 78 of file SelectSpill.cxx.

References bfld::AsString(), fBeam, fList, fListData, fMaxICoil, fMinICoil, fPathBad, fPathGood, fPathList, fPrint, fReverse, Registry::Get(), Registry::KeyExists(), BeamType::kUnknown, Anp::Read(), and BeamType::TagToEnum().

00079 {
00080    const char *value_beam = 0;   
00081    if(reg.Get("SelectSpillB", value_beam) && value_beam)
00082    {
00083       if(std::strcmp(value_beam, "ALLBEAM") == 0)
00084       {
00085          fBeam.clear();
00086       }
00087       else
00088       {
00089          fBeam = value_beam;
00090       }      
00091    }
00092 
00093    //
00094    // Check that beam is of known type
00095    //
00096    if(!fBeam.empty())
00097    {
00098       BeamType::BeamType_t beam = BeamType::TagToEnum(fBeam.c_str());
00099 
00100       if(beam == BeamType::kUnknown)
00101       {
00102          //
00103          // Try adding to beam string "i" and "z"
00104          //
00105          if(fBeam.size() > 6)
00106          {
00107             beam = BeamType::TagToEnum((fBeam.substr(0, 4)+"z"+fBeam.substr(4, 3)+"i").c_str());
00108          } 
00109          
00110          fBeam = BeamType::AsString(beam); 
00111       }
00112    }
00113 
00114    const char *value_bad  = 0;
00115    const char *value_good = 0;
00116    const char *value_list = 0;
00117 
00118    if(reg.Get("SelectSpillPathBad",  value_bad)  && value_bad)  fPathBad  = value_bad;
00119    if(reg.Get("SelectSpillPathGood", value_good) && value_good) fPathGood = value_good;
00120    if(reg.Get("SelectSpillPathList", value_list) && value_list) fPathList = value_list;
00121 
00122    Anp::Read(reg, "SelectSpillListData", fListData);
00123    Anp::Read(reg, "SelectSpillPrint",    fPrint);
00124    Anp::Read(reg, "SelectSpillReverse",  fReverse);
00125 
00126    reg.Get("SelecSpillMinICoil", fMinICoil);
00127    reg.Get("SelecSpillMaxICoil", fMaxICoil);
00128 
00129    if(reg.KeyExists("PrintConfig"))
00130    {
00131       cout << "SelectSpill::Config" << endl
00132            << "   Beam = " << fBeam << endl
00133            << "   PathBad = " << fPathBad << endl
00134            << "   PathGood = " << fPathGood << endl
00135            << "   PathList = " << fPathList << endl
00136            << "   ListData = " << fListData << endl
00137            << "   Print = " << fPrint << endl
00138            << "   Reverse = " << fReverse << endl
00139            << "   MinICoil = " << fMinICoil << endl
00140            << "   MaxICoil = " << fMaxICoil << endl;
00141    }
00142 
00143    fList.open(fPathList.c_str());
00144 }

bool Anp::SelectSpill::Count ( const std::string &  key,
const Header header 
) [private]

Definition at line 187 of file SelectSpill.cxx.

References fMap, Munits::second, Anp::Header::Tor101(), Anp::Header::TorTgt(), Anp::Header::Tr101D(), and Anp::Header::TrTgtD().

Referenced by PassBeam(), and Run().

00188 {
00189    //
00190    // Get (insert for a first time) pointer to current beam string
00191    //
00192    BeamMap::iterator bit = 
00193       fMap.insert(BeamMap::value_type(key, pair<unsigned int, double>(0, 0.0))).first;
00194    
00195    if     (header.TorTgt() > 0.0) (bit -> second).second += header.TorTgt();
00196    else if(header.TrTgtD() > 0.0) (bit -> second).second += header.TrTgtD();
00197    else if(header.Tr101D() > 0.0) (bit -> second).second += header.Tr101D();
00198    else if(header.Tor101() > 0.0) (bit -> second).second += header.Tor101();
00199    else
00200    {
00201       cerr << "SelectSpill::Count - invalid toroid data" << endl;
00202       return false;
00203    }
00204    ++(bit -> second).first; //count snarls
00205 
00206    return true;
00207 }

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

Reimplemented from Anp::AlgSnarl.

Definition at line 158 of file SelectSpill.cxx.

References fMap, fMissGood, run(), and Munits::second.

00159 {
00160    //
00161    // Print number of snarls and pot for each beam
00162    //
00163    
00164    int bwidth = 0, swidth = 0;
00165    for(BeamMap::const_iterator bit = fMap.begin(); bit != fMap.end(); ++bit)
00166    {
00167       bwidth = std::max<int>(bwidth, bit->first.size());
00168       swidth = std::max<int>(swidth, 1+static_cast<int>(std::log10(double(bit->second.first+1))));
00169    }
00170 
00171    for(BeamMap::const_iterator bit = fMap.begin(); bit != fMap.end(); ++bit)
00172    {
00173       cout << "   " << std::setw(bwidth) << bit -> first << " nsnarl = "
00174            << std::setw(swidth) << std::right << bit -> second.first << ", pot = "
00175            << std::setw(6) << std::setprecision(4) << std::left << std::scientific
00176            << bit -> second.second << endl;
00177    }
00178 
00179    cout << "SelectSpill::End - printing " << fMissGood.size() << " missing runs" << endl;
00180    for(vector<RunSubrun>::const_iterator rit = fMissGood.begin(); rit != fMissGood.end(); ++rit)
00181    {
00182       cout << "   " << rit -> run << " " << rit -> subrun << endl;
00183    }
00184 }

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

Reimplemented from Anp::AlgSnarl.

Definition at line 147 of file SelectSpill.cxx.

References ReadList().

00148 {
00149    //
00150    // Read good and bad run list for this detector
00151    //
00152    SelectSpill::ReadList(header);
00153 
00154    return true;
00155 }

bool Anp::SelectSpill::PassBeam ( const Header header  )  [private]

Definition at line 210 of file SelectSpill.cxx.

References Count(), fBeam, Anp::Header::GetBEAMTYPE(), Anp::Header::GoodBeam(), and Anp::Header::IsData().

Referenced by Run().

00211 {   
00212    //
00213    // Select beam type and apply "good beam" cut
00214    //
00215    if(header.IsData() && !header.GoodBeam()) return false;
00216 
00217    //
00218    // Get beam type for this snarl
00219    //
00220    const string beam = header.GetBEAMTYPE();
00221 
00222    SelectSpill::Count(beam, header);
00223 
00224    //
00225    // Select beam type, if fBeam string is filled
00226    //
00227    if(!fBeam.empty() && fBeam != "ALLBEAM" && fBeam != beam) return false;
00228 
00229    return true;
00230 }

bool Anp::SelectSpill::PassCoil ( const Header header  )  [private]

Definition at line 233 of file SelectSpill.cxx.

References Anp::Header::CoilCur(), Anp::Header::CoilRevs(), fMaxICoil, fReverse, Anp::Header::GoodCoil(), Anp::Header::IsData(), Anp::Header::IsFar(), and Anp::Header::IsNear().

Referenced by Run().

00234 {   
00235    //
00236    // Apply near and far detector coil quality cut
00237    //
00238    if(header.IsData())
00239    {
00240       if(!header.GoodCoil()) return false;
00241    }
00242    else
00243    {
00244       return true;
00245    }
00246 
00247    if(header.IsNear())
00248    {
00249       const double icur = std::fabs(header.CoilCur());
00250       if(icur < fMinICoil || icur > fMaxICoil)
00251       {
00252          return false;
00253       }
00254       
00255       if(fReverse)
00256       {
00257          if(!header.CoilRevs()) return false;
00258       }
00259       else
00260       {
00261          if(header.CoilRevs()) return false;
00262       }
00263 
00264       return true;
00265    }
00266    else if(header.IsFar())
00267    {
00268       return true;
00269    }
00270 
00271    return false;
00272 }

bool Anp::SelectSpill::PassList ( const Header header  )  [private]

Definition at line 275 of file SelectSpill.cxx.

References find(), fListBad, fListGood, fMissGood, Anp::Header::IsData(), Anp::Header::Run(), run(), Anp::Header::Snarl(), and Anp::Header::SubRun().

Referenced by Run().

00276 {
00277    //
00278    // Ignore run and subruns that are on the bad run list, also
00279    // if good run list exists then only pass runs on that list.
00280    //
00281    bool pass = true;
00282    // In Dogwood3 this doesnt work for some reason. Why check monte carlo files anyway?
00283    // just return true for all data here 
00284    if(!header.IsData()) return true;
00285    //   if(fListData && !header.IsData())
00286    //   {
00287    //      return true;
00288    //   }
00289 
00290    if(!fListBad.empty())
00291    {
00292       const RunSubrun run(header.Run(), header.SubRun());
00293       if(std::find(fListBad.begin(), fListBad.end(), run) != fListBad.end())
00294       {
00295          pass = false;
00296       }
00297    }
00298 
00299    if(!fListGood.empty())
00300    {
00301       pass = false;
00302       for(vector<RunSubrun>::const_iterator rit = fListGood.begin(); rit != fListGood.end(); ++rit)
00303       {
00304          if(rit -> run != header.Run() || rit -> subrun != header.Snarl())
00305          {
00306             continue;
00307          }
00308          
00309          vector<RunSubrun>::iterator fit = std::find(fMissGood.begin(), fMissGood.end(), *rit);
00310          if( fit==fMissGood.end()) cout<<" SelectSpill::PassList  - found no RunSubrun (run: "<<rit->run<<", subrun:"<<rit-> subrun<<")"<<endl;
00311          else cout<<" SelectSpill::PassList - found RunSubrun (run: "<<rit->run<<", subrun:"<<rit-> subrun<<")"<<endl;
00312          fMissGood.erase(fit);
00313 
00314          pass = true;
00315          break;
00316       }
00317    }
00318 
00319    return pass;
00320 }

bool Anp::SelectSpill::ReadList ( const Header header  )  [private]

Definition at line 323 of file SelectSpill.cxx.

References fListBad, fListGood, fMissGood, fPathBad, fPathGood, fPrint, Anp::Header::IsData(), Anp::Header::IsFar(), Anp::Header::IsNear(), and Anp::ReadRunList().

Referenced by Init().

00324 {
00325    //
00326    // Read good run list and bad run list
00327    //
00328    if(fPathBad.empty())
00329    {
00330       string filename;
00331       if     (header.IsNear()) filename = "PhysicsNtuple/Config/RunListNearBad.txt";
00332       else if(header.IsFar())  filename = "PhysicsNtuple/Config/RunListFarBad.txt";
00333 
00334       const char *srt_char = std::getenv("SRT_PRIVATE_CONTEXT");
00335       if(srt_char)
00336       {
00337          fPathBad = std::string(srt_char) + "/" + filename;
00338       }
00339    }
00340 
00341    if(fPathGood.empty())
00342    {
00343       string filename;
00344       if     (header.IsNear()) filename = "PhysicsNtuple/Config/RunListNearGood.txt";
00345       else if(header.IsFar())  filename = "PhysicsNtuple/Config/RunListFarGood.txt";
00346 
00347       const char *srt_char = std::getenv("SRT_PRIVATE_CONTEXT");
00348       if(srt_char)
00349       {
00350          fPathGood = std::string(srt_char) + "/" + filename;
00351       }
00352    }
00353 
00354    if(header.IsData()) fListBad  = Anp::ReadRunList(fPathBad, fPrint);
00355    fListGood = Anp::ReadRunList(fPathGood, fPrint);
00356    fMissGood = fListGood;
00357 
00358    if(!fListBad.empty())
00359    {
00360       cout << "SelectSpill::ReadList - read " << fListBad.size() << " bad run entries from" << endl
00361            << "   " << fPathBad << endl;
00362    }
00363 
00364    if(!fListGood.empty())
00365    {
00366       cout << "SelectSpill::ReadList - read " << fListGood.size() << " good run entries from" << endl
00367            << "   " << fPathGood << endl;
00368    }
00369 
00370    return true;
00371 }

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

Implements Anp::AlgSnarl.

Definition at line 44 of file SelectSpill.cxx.

References Count(), fList, Anp::Record::GetHeader(), header, PassBeam(), PassCoil(), PassList(), Anp::Header::Run(), Anp::Header::Snarl(), and Anp::Header::SubRun().

00045 {
00046    //
00047    // Select spills with a given beam type that pass "good beam" cuts
00048    //
00049    const Header &header = record.GetHeader();
00050 
00051    //
00052    // Select beam type and apply beam quality cut
00053    //
00054    if( !SelectSpill::PassBeam(header)) return false;
00055    else SelectSpill::Count("1: PassBeam", header);
00056 
00057    //
00058    // Apply detector coil cut
00059    //
00060    if( !SelectSpill::PassCoil(header)) return false;
00061    else SelectSpill::Count("2: PassCoil", header);
00062 
00063    //
00064    // Check if this snarl is on bad run list or not on good run list
00065    //
00066    if( !SelectSpill::PassList(header)) return false;
00067    else SelectSpill::Count("3: PassList", header);
00068 
00069    if(fList.is_open())
00070    {
00071       fList << header.Run() << " " << header.SubRun() << " " << header.Snarl() << endl;
00072    }
00073 
00074    return true;
00075 }


Member Data Documentation

std::string Anp::SelectSpill::fBeam [private]

Definition at line 57 of file SelectSpill.h.

Referenced by Config(), and PassBeam().

std::ofstream Anp::SelectSpill::fList [private]

Definition at line 62 of file SelectSpill.h.

Referenced by Config(), and Run().

std::vector<RunSubrun> Anp::SelectSpill::fListBad [private]

Definition at line 74 of file SelectSpill.h.

Referenced by PassList(), and ReadList().

Definition at line 66 of file SelectSpill.h.

Referenced by Config().

std::vector<RunSubrun> Anp::SelectSpill::fListGood [private]

Definition at line 75 of file SelectSpill.h.

Referenced by PassList(), and ReadList().

Definition at line 64 of file SelectSpill.h.

Referenced by Count(), and End().

double Anp::SelectSpill::fMaxICoil [private]

Definition at line 72 of file SelectSpill.h.

Referenced by Config(), and PassCoil().

double Anp::SelectSpill::fMinICoil [private]

Definition at line 71 of file SelectSpill.h.

Referenced by Config().

std::vector<RunSubrun> Anp::SelectSpill::fMissGood [private]

Definition at line 76 of file SelectSpill.h.

Referenced by End(), PassList(), and ReadList().

std::string Anp::SelectSpill::fPathBad [private]

Definition at line 58 of file SelectSpill.h.

Referenced by Config(), and ReadList().

std::string Anp::SelectSpill::fPathGood [private]

Definition at line 59 of file SelectSpill.h.

Referenced by Config(), and ReadList().

std::string Anp::SelectSpill::fPathList [private]

Definition at line 60 of file SelectSpill.h.

Referenced by Config().

bool Anp::SelectSpill::fPrint [private]

Definition at line 67 of file SelectSpill.h.

Referenced by Config(), and ReadList().

Definition at line 68 of file SelectSpill.h.

Referenced by Config(), and PassCoil().

Definition at line 70 of file SelectSpill.h.


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

Generated on 15 Jul 2018 for loon by  doxygen 1.6.1