Public Member Functions | Private Member Functions | Private Attributes | List of all members
cmf::EventListManipulator Class Reference

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N20-11-25/CovarianceMatrixFit/modules/EventListManipulator.h"

Public Member Functions

 EventListManipulator (fhicl::ParameterSet const &pset)
 
 ~EventListManipulator ()
 
void reconfigure (const fhicl::ParameterSet &p)
 
void Deserialize (cmf::EventListColl &eventLists, cmf::DataMC_t dataMC=cmf::kBoth, std::set< cmf::DetType_t > const &detectors=std::set< cmf::DetType_t >({cmf::kNEARDET, cmf::kFARDET}))
 
cmf::ExposureMap const & ExposureMap () const
 
void PrintPOTSummary (cmf::ExposureMap &exposureMap)
 
void PrintLivetimeSummary (cmf::ExposureMap &exposureMap)
 

Private Member Functions

void SetEventCaps (fhicl::ParameterSet const &pset)
 
void SetExposures (fhicl::ParameterSet const &pset)
 
void ExtractFromFile (TFile *metadataFile, std::string const &dirName, cmf::DataMC_t const &dataMC, std::set< cmf::DetType_t > const &detectors, std::vector< cmf::FileExtracts > &extractVec)
 
void FillTextFile (cmf::MetaData const &md, cmf::EventId &ev, cmf::DataVars &dv, cmf::TruthVars &tv, cmf::WeightVars &wv)
 
void FillEventList (TFile *eventFile, std::string const &treeName, double const &eventCap, double const &normalization, cmf::EventList &eventList)
 
float PeriodEventCap (cmf::MetaData const &md, long treeEvents)
 
bool UseEventsFromMetaData (cmf::MetaData const &md, cmf::DataMC_t dataMC, std::set< cmf::DetType_t > const &detectors)
 
void PrintExposureSummary (cmf::ExposureMap &exposureMap, bool isLivetime)
 

Private Attributes

std::vector< std::stringfCMFEventLabels
 Labels in input files holding CovarianceMatrixFit Events. More...
 
std::vector< std::stringfTreeDirectories
 directory holding the input trees More...
 
TRandom3 fRandom
 Random number generator to use creating fake data lists. More...
 
cmf::ExposureMap fExposure
 POT in 1e12 to normalise to. More...
 
std::set< cmf::DetType_tfDetectors
 which detector(s) are we loading events from More...
 
std::map< std::string, float > fEventCaps
 
bool fUseEventId
 use if you need access to run/subrun/event/etc More...
 
std::set< long > fPeriodsToUse
 which periods to use in the analysis More...
 
std::map< cmf::SelectionType_t, double > fMaxNuEnergy
 maximum neutrino energy to go into the lists More...
 
bool fLoadAllEventLists
 force all event lists to be loaded More...
 
float fMaxEventsPerTree
 maximum number of events to use per tree More...
 
float fMinEventsPerTree
 minimum number of events to use per tree More...
 
bool fFillTextFile
 fills text file with selection information More...
 

Detailed Description

Definition at line 61 of file EventListManipulator.h.

Constructor & Destructor Documentation

cmf::EventListManipulator::EventListManipulator ( fhicl::ParameterSet const &  pset)
explicit

Definition at line 33 of file EventListManipulator.cxx.

References fEventCaps, and reconfigure().

34  {
35  fEventCaps.clear();
36 
37  this->reconfigure(p);
38  }
const char * p
Definition: xmltok.h:285
std::map< std::string, float > fEventCaps
void reconfigure(const fhicl::ParameterSet &p)
cmf::EventListManipulator::~EventListManipulator ( )

Definition at line 41 of file EventListManipulator.cxx.

References fExposure.

42  {
43  fExposure.clear();
44  }
cmf::ExposureMap fExposure
POT in 1e12 to normalise to.

Member Function Documentation

void cmf::EventListManipulator::Deserialize ( cmf::EventListColl eventLists,
cmf::DataMC_t  dataMC = cmf::kBoth,
std::set< cmf::DetType_t > const &  detectors = std::set<cmf::DetType_t>({cmf::kNEARDET,                                                                                         cmf::kFARDET}) 
)

Definition at line 587 of file EventListManipulator.cxx.

References cmf::MetaData::detector, dirName, ExtractFromFile(), MakeMiniprodValidationCuts::f, fCMFEventLabels, plotROC::fileName, cmf::MetaData::fileType, FillEventList(), cmf::FindEventList(), fTreeDirectories, cmf::SpillSummary::goodPOT, cmf::SelectionUtility::Instance(), cmf::MetaData::interactionType, cmf::MetaData::IsCosmicMuon(), cmf::MetaData::isMC, cmf::IsNuESelected(), cmf::IsNuMuQuantiles(), cmf::kCosmicBackgroundFile, cmf::kData, findDuplicateFiles::key, cmf::KeyToString(), cmf::kMC, cmf::kNuESelection, cmf::kNuMuSelection, cmf::SpillSummary::liveTime, LOG_DEBUG, LOG_VERBATIM, fetch_tb_beamline_files::md, std::min(), cmf::MetaData::Period(), cmf::MetaData::selectionType, ss, cmf::MetaData::ToString(), cmf::SpillSummary::totalPOT, and cmf::SelectionUtility::UsesSelection().

Referenced by cmf::CMFSpectraMaker::endJob(), cmf::CovarianceMatrixFitter::FillDataSpectrum(), cmf::CovarianceFitHelper::InitializeEventLists(), cmf::SpectrumPredictionMaker::MakePredictions(), cmf::CovarianceMatrixMaker::writeResults(), cmf::CMFDecorrelator::writeResults(), and cmf::RandomUniverses::writeResults().

590  {
591  cmf::DataMC_t dataType = (dataMC == cmf::kData) ? dataMC : cmf::kMC;
592 
593  std::vector<cmf::FileExtracts> extractVec;
594  size_t totalEvents = 0;
595 
598  double normalization = 1.;
599 
600  // each input file is assumed to have a metadata tree and a cmfEvent tree
601  for(auto & fileName : fCMFEventLabels){
602 
603  TFile *f = TFile::Open(fileName.c_str());
604 
605  if(f->IsOpen())
606  LOG_VERBATIM("EventListManipulator")
607  << "successfully opened "
608  << fileName;
609  else
610  throw cet::exception("EventListManipulator")
611  << "Cannot open file "
612  << fileName;
613 
614  for(auto const& dirName : fTreeDirectories){
615 
616  this->ExtractFromFile(f, dirName, dataType, detectors, extractVec);
617 
618  LOG_DEBUG("EventListManipulator")
619  << "There are "
620  << extractVec.size()
621  << " metadata categories";
622  } // end loop over directories
623 
624  // map the detector/file/beam + general selection type to the minimum POT for that
625  // combination to do the POT accounting for concatenation
626  std::map<long, double> keyToMinExposure;
627  long key;
628  double cappedExposure;
629 
630  for(auto & itr : extractVec){
631  key = itr.Key();
632  cappedExposure = (itr.metadata.IsCosmicMuon()) ? itr.CappedLiveTime() : itr.CappedPOT();
633 
634  if(keyToMinExposure.count(key) < 1)
635  keyToMinExposure[key] = cappedExposure;
636  else
637  keyToMinExposure[key] = std::min(keyToMinExposure.find(key)->second, cappedExposure);
638 
639  LOG_DEBUG("EventListManipulator")
640  << "input key: "
641  << cmf::KeyToString(itr.metadata.Key())
642  << " concat key: "
643  << cmf::KeyToString(key)
644  << " POT: "
645  << itr.spillSummary.goodPOT
646  << " / "
647  << keyToMinExposure[key]
648  << " LiveTime: "
649  << itr.spillSummary.liveTime
650  << " / "
651  << keyToMinExposure[key];
652  }
653 
654  // now loop over the extracted information again to fill the event lists
655  // cosmic ray background livetime normalization is done when the spectra are
656  // filled
657  double exposure;
658  for(auto & itr : extractVec){
659 
660  normalization = 1.;
661 
662  // need a non-const spill summary for filling the event list in case we have to
663  // apply a cap
664  ss = itr.spillSummary;
665 
666  // Rescale POT based on the event cap, which is a fraction of the total
667  // events available
668  ss.goodPOT *= itr.eventCap;
669  ss.totalPOT *= itr.eventCap;
670  ss.liveTime *= itr.eventCap;
671 
672  // check if we are concatenating either the numu or nue selections
673  // and make the appropriate metadata for that case. We need to also
674  // adjust the event cap for this particular tree and change the
675  // total POT for this selection to account for normalization differences
676  // between the selections to be concatenated
677  md = itr.metadata;
678 
679  exposure = (md.IsCosmicMuon()) ? ss.liveTime : ss.goodPOT;
680 
683  md = cmf::MetaData(md.isMC,
684  md.detector,
685  md.fileType,
687  md.interactionType,
688  md.Period());
689 
690  normalization = keyToMinExposure[itr.Key()] / exposure;
691  }
692  else if(cmf::SelectionUtility::Instance()->UsesSelection(cmf::kNuESelection) &&
694  md = cmf::MetaData(md.isMC,
695  md.detector,
696  md.fileType,
698  md.interactionType,
699  md.Period());
700 
701  normalization = keyToMinExposure[itr.Key()] / exposure;
702  }
703  //if (itr.metadata.fileType == kCosmicBackgroundFile)
704  // normalization = fPOTSum[md.Period()].liveTime / ss.liveTime;
705 
706  //if(md.IsNuMuSelected())
707  LOG_DEBUG("EventListManipulator")
708  << "Filling "
709  << itr.metadata.ToString()
710  << " / "
711  << md.ToString()
712  << " with cap "
713  << itr.eventCap
714  << " Exposure "
715  << exposure / itr.eventCap
716  //<< " : Events "
717  //<< itr.eventTree->GetEntries()
718  << " cap POT/livetime "
719  << ss.goodPOT
720  << " / "
721  << ss.liveTime
722  //<< " : Events "
723  //<< itr.eventTree->GetEntries() * itr.eventCap
724  << " with normalization of "
725  << normalization;
726 
727  auto listItr = cmf::FindEventList(md, eventLists);
728  if(listItr == eventLists.end()){
729  eventLists.emplace_back(cmf::EventList(md, ss));
730  listItr = cmf::FindEventList(md, eventLists);
731  }
732  this->FillEventList(f, itr.treeName, itr.eventCap, normalization, *listItr);
733 
734  totalEvents += listItr->size();
735  } // end loop over extracted trees
736 
737  f->Close();
738  }// end loop over files
739 
740  LOG_VERBATIM("EventListManipulator")
741  << "There are "
742  << eventLists.size()
743  << " event lists and "
744  << totalEvents
745  << " events";
746 
747  for(auto const& itr : eventLists){
748 
749  md = itr.ListMetaData();
750  ss = itr.ListSpillSummary();
751 
752  if (md.fileType == kCosmicBackgroundFile){
753  LOG_VERBATIM("EventListManipulator")
754  << std::setw(55)
755  << md.ToString()
756  << " of period "
757  << md.Period()
758  << " "
759  << std::setw(15)
760  << " represents "
761  << ss.liveTime
762  << " livetime and "
763  << itr.size()
764  << " events "
765  << itr.size() / ss.liveTime;
766  }
767  else{
768  LOG_VERBATIM("EventListManipulator")
769  << std::setw(55)
770  << md.ToString()
771  << " of period "
772  << md.Period()
773  << " "
774  << std::setw(15)
775  << " represents "
776  << ss.goodPOT
777  << " POT and "
778  << itr.size()
779  << " events "
780  << itr.size() / ss.goodPOT;
781  }
782  }
783  }
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
fileName
Definition: plotROC.py:78
long Period() const
Definition: Structs.h:128
cmf::DetType_t detector
Definition: Structs.h:114
void FillEventList(TFile *eventFile, std::string const &treeName, double const &eventCap, double const &normalization, cmf::EventList &eventList)
double liveTime
Definition: Structs.h:187
Float_t ss
Definition: plot.C:24
static SelectionUtility * Instance()
std::vector< std::string > fCMFEventLabels
Labels in input files holding CovarianceMatrixFit Events.
cmf::EventListColl::iterator FindEventList(cmf::MetaData const &md, cmf::EventListColl &eventListColl)
Definition: Event.cxx:44
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
static bool IsNuESelected(cmf::SelectionType_t const &sel)
Definition: StaticFuncs.h:376
static bool IsNuMuQuantiles(cmf::SelectionType_t const &sel)
Definition: StaticFuncs.h:369
cmf::SelectionType_t selectionType
Definition: Structs.h:116
enum cmf::dataMC_type DataMC_t
bool UsesSelection(cmf::SelectionType_t const &s) const
std::string ToString() const
Definition: Structs.cxx:133
cmf::FileType_t fileType
Definition: Structs.h:115
double goodPOT
Definition: Structs.h:186
std::string dirName
Definition: PlotSpectra.h:47
void ExtractFromFile(TFile *metadataFile, std::string const &dirName, cmf::DataMC_t const &dataMC, std::set< cmf::DetType_t > const &detectors, std::vector< cmf::FileExtracts > &extractVec)
#define LOG_VERBATIM(category)
T min(const caf::Proxy< T > &a, T b)
cmf::InteractionType_t interactionType
Definition: Structs.h:117
std::vector< std::string > fTreeDirectories
directory holding the input trees
double totalPOT
Definition: Structs.h:185
bool IsCosmicMuon() const
Definition: Structs.h:139
static std::string KeyToString(long const &key)
Definition: StaticFuncs.h:228
cmf::ExposureMap const & cmf::EventListManipulator::ExposureMap ( ) const
inline
void cmf::EventListManipulator::ExtractFromFile ( TFile *  metadataFile,
std::string const &  dirName,
cmf::DataMC_t const &  dataMC,
std::set< cmf::DetType_t > const &  detectors,
std::vector< cmf::FileExtracts > &  extractVec 
)
private

Definition at line 459 of file EventListManipulator.cxx.

References cmf::kCosmicBackgroundFile, cmf::kNuESelection, cmf::kNuESelectionHighPID, cmf::kNuESelectionLowPID, cmf::kNuESelectionMidPID, cmf::kNuESelectionPeripheral, cmf::kNuMuSelection, LOG_DEBUG, fetch_tb_beamline_files::md, cmf::MetaData::selectionType, ss, submit_syst::str, string, cmf::MetaData::ToString(), and UseEventsFromMetaData().

Referenced by Deserialize().

464  {
465  LOG_DEBUG("EventListManipulator")
466  << "extracting metadata from file";
467 
468  std::string mdString;
469  std::string treeName;
470 
471  TTree *metadataTree = dynamic_cast<TTree *>(metadataFile->Get((dirName + "/metadata").c_str()));
472 
473  if(!metadataTree){
474  throw cet::exception("EventListManipulator")
475  << "cannot find metadata tree: "
476  << dirName + "/metadata";
477  }
478 
479  // The metadata tree may have the same metadata information in it over and over again
480  // because we hadd'ed a bunch of files together. We don't want to read in the event
481  // trees multiple times, so we will make a map of the metadata and spill summary
482  // information so that we only have one entry for each metadata
483  cmf::ExposureMap exposureMap;
484 
485  // loop over the entries in the metadataTree
486  cmf::MetaData *md = nullptr;
487  cmf::SpillSummary *ss = nullptr;
488  metadataTree->SetBranchAddress("metadata", &md);
489  metadataTree->SetBranchAddress("spillsummary", &ss);
490 
491  // We have potentially hadd'ed several files together to get the
492  // eventlisttree, so first loop over the entries in the metadata
493  // tree and sum all the POT values for each metadata type
494  for(int ctr = 0; ctr < metadataTree->GetEntries(); ++ctr){
495  metadataTree->GetEntry(ctr);
496 
497  #ifdef PRODUCTION4
498  // map the stored SelectionType values to the reordered values
499  // with all NuMu together and all NuE together. We just have to
500  // subtract one from each of the enumerations less than kNuMuSelectionQ1
501  // but we can't do a -= 1 operation because enumerations are not ints
502  LOG_DEBUG("EventListManipulator")
503  << "read in metadata "
504  << md->ToString();
505 
511 
512  LOG_DEBUG("EventListManipulator")
513  << "metadata after selection type adjustment "
514  << md->ToString();
515 #endif
516 
517  // now check if we want this metadata for our analysis
518  // and find the minimum POT for all metadata having the same
519  // beam/detector/file/interaction types for concatenated numu or nue
520  // selections
521  if(this->UseEventsFromMetaData(*md, dataMC, detectors)){
522  if(exposureMap.count(*md) < 1) exposureMap[*md] = *ss;
523  else exposureMap[*md] += *ss;
524  }
525  } // end loop over the metadata tree
526 
527  for(auto const& itr : exposureMap){
528 
529  // get the pointer to the event TTree
530  mdString = itr.first.ToString();
531 
532  treeName = dirName + "/" + mdString;
533 
534 #ifdef PRODUCTION4
535  if( !(dynamic_cast<TDirectory*>(metadataFile->Get(dirName.c_str()))->GetListOfKeys()->Contains(mdString.c_str())) ){
536  // check if the trees in the file are using Epoch in their names rather
537  // Period
538  std::string str(mdString);
539  auto perPos = str.find("Period");
540  str.replace(perPos, 6, "Epoch");
541 
542  treeName = dirName + "/" + str;
543 
544  if( !(dynamic_cast<TDirectory*>(metadataFile->Get(dirName.c_str()))->GetListOfKeys()->Contains(str.c_str())) )
545  throw cet::exception("EventListManipulator")
546  << "cannot find event tree: "
547  << str;
548  } // end if we didn't get a tree
549 #endif
550 
551  if(itr.second.goodPOT > 0 ||
552  (itr.first.fileType == kCosmicBackgroundFile && itr.second.liveTime > 0)){
553  extractVec.emplace_back(itr.first,
554  itr.second,
555  treeName,
556  this->PeriodEventCap(itr.first, dynamic_cast<TTree*>(metadataFile->Get(treeName.c_str()))->GetEntriesFast()));
557  }
558 
559  LOG_DEBUG("EventListManipulator")
560  << "deserializing: "
561  << itr.first.ToString()
562  << " "
563  << itr.second.goodPOT
564  << " "
565  << itr.second.liveTime
566  << " "
567  << exposureMap.size();
568  } // end loop over the metadata to spill summary map
569 
570 
571  // loop over the exposureMap map one more time to check which
572  // selections are being used
573  // for(auto const& itr : exposureMap){
574  // LOG_VERBATIM("EventListManipulator")
575  // << "Using "
576  // << itr.first.ToString()
577  // << " in the analysis";
578  // }
579 
580  }
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
std::map< cmf::MetaData, cmf::SpillSummary > ExposureMap
Definition: Structs.h:215
Float_t ss
Definition: plot.C:24
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
cmf::SelectionType_t selectionType
Definition: Structs.h:116
std::string ToString() const
Definition: Structs.cxx:133
std::string dirName
Definition: PlotSpectra.h:47
bool UseEventsFromMetaData(cmf::MetaData const &md, cmf::DataMC_t dataMC, std::set< cmf::DetType_t > const &detectors)
enum BeamMode string
void cmf::EventListManipulator::FillEventList ( TFile *  eventFile,
std::string const &  treeName,
double const &  eventCap,
double const &  normalization,
cmf::EventList eventList 
)
private

Definition at line 891 of file EventListManipulator.cxx.

References cmf::EventList::AddEvent(), cmf::DataVars::fFake_Weight, fFillTextFile, FillTextFile(), fMaxNuEnergy, fRandom, fUseEventId, cmf::SpillSummary::goodPOT, cmf::ParameterUtility::Instance(), cmf::kCosmicBackgroundFile, cmf::kFARDET, cmf::kFirstSigmaVar, cmf::kLastSigmaVar, fnex::kMaCCQE, cmf::kNCSelection, cmf::kNu_RecoE, cmf::kNuESelection, cmf::kNuMuSelection, cmf::EventList::ListMetaData(), cmf::EventList::ListSpillSummary(), PandAna.Demos.demo0::loc, LOG_DEBUG, LOG_WARNING, fetch_tb_beamline_files::md, string, cmf::ParameterUtility::SysParameters(), cmf::ParameterUtility::SysParKeys(), systs, cmf::MetaData::ToString(), registry_explorer::v, and cmf::DataVarVals::val_at().

Referenced by Deserialize().

896  {
897  cmf::EventId eventId;
898  cmf::DataVars dataVars;
899  cmf::TruthVars truthVars;
900  cmf::WeightVars weightVars;
901 
902  auto const& md = eventList.ListMetaData();
903 
904  cmf::GENIEVar genieVars[12]; // PROD4
905 #ifdef PRODUCTION5
906  std::vector<unsigned char>* systVarKeys = nullptr; // PROD5
907  std::vector<float>* systVarMinus2Wgts = nullptr; // PROD5
908  std::vector<float>* systVarMinus1Wgts = nullptr; // PROD5
909  std::vector<float>* systVarPlus1Wgts = nullptr; // PROD5
910  std::vector<float>* systVarPlus2Wgts = nullptr; // PROD5
911 #endif
912 
913  auto const& sysPars = cmf::ParameterUtility::Instance()->SysParameters();
914  auto const sysKeys = cmf::ParameterUtility::Instance()->SysParKeys();
915 
916  TTree *eventTree = dynamic_cast<TTree*>(eventFile->Get(treeName.c_str()));
917  eventTree->SetBranchAddress("dataVars", &dataVars);
918  if(fUseEventId)
919  eventTree->SetBranchAddress("eventId", &eventId);
920 
921  if(md.isMC){
922  eventTree->SetBranchAddress("truthVars" , &truthVars );
923  eventTree->SetBranchAddress("weightVars", &weightVars);
924 
925 #ifdef PRODUCTION5
926  eventTree->SetBranchAddress("systVarKeys", &systVarKeys);
927  eventTree->SetBranchAddress("systVarMinus2Wgts", &systVarMinus2Wgts);
928  eventTree->SetBranchAddress("systVarMinus1Wgts", &systVarMinus1Wgts);
929  eventTree->SetBranchAddress("systVarPlus1Wgts", &systVarPlus1Wgts);
930  eventTree->SetBranchAddress("systVarPlus2Wgts", &systVarPlus2Wgts);
931 #else
932  //The choice of which GENIE vars to keep changed for A2017 and again for A2018:
933  //check that the branch is there before setting its address
934 
936  for(auto const& itr : sysPars){
937  if(itr.second.Key() < cmf::kFirstSigmaVar ||
938  itr.second.Key() > cmf::kLastSigmaVar) continue;
939 
940  name = itr.first.c_str();
941 
942  // in PROD4 the branch containing the information for MaCCQE was called
943  // "MaCCQE", not "MaCCQEReduced"
944  if(itr.second.Key() == cmf::kMaCCQE) name = "MaCCQE";
945  if(eventTree->FindBranch(name.c_str())){
946  eventTree->SetBranchAddress(name.c_str(),
947  &genieVars[itr.second.Key() - cmf::kFirstSigmaVar]);
948  }
949  else{
950  // maybe the branch name doesn't have Wgt in it, but the stored in
951  // the parameter utility does
952  std::string nowgt = name.substr(0, name.find_first_of("Wgt"));
953  if(eventTree->FindBranch(nowgt.c_str()))
954  eventTree->SetBranchAddress(nowgt.c_str(),
955  &genieVars[itr.second.Key() - cmf::kFirstSigmaVar]);
956  else
957  LOG_WARNING("ELMProd4Systematics")
958  << "Could not find branch "
959  << itr.first
960  << " or "
961  << nowgt
962  << " in the eventlisttree. If you want to use that "
963  << " as a systematic, you're going to have a bad time.";
964  }
965  }
966 #endif
967  } // end if MC
968 
969  // get the generic identifier for numu or nue selection so
970  // we can then determine the maximum energy of the neutrino
971  // events to use
973  if ( md.IsNuESelected() ) selection = cmf::kNuESelection;
974  else if( md.IsNCSelected() ) selection = cmf::kNCSelection;
975 
976  LOG_DEBUG("EventListManipulator")
977  << md.ToString()
978  << " selection is "
979  << selection
980  << " max energy: "
981  << fMaxNuEnergy.find(selection)->second;
982 
983  // check that our event list corresponds to a reasonable exposure
984  if(eventList.ListSpillSummary().goodPOT < 1.e17 && md.fileType != kCosmicBackgroundFile)
985  throw cet::exception("EventListManipulator")
986  << "exposure for "
987  << eventList.ListMetaData().ToString()
988  << " is "
989  << eventList.ListSpillSummary().goodPOT
990  << " < 10^9 POT. That cannot be right, bail";
991 
992  auto systs = std::make_unique<cmf::SystVarColl>();
993  uint8_t loc;
994  for(long evNum = 0; evNum < eventTree->GetEntries(); ++evNum){
995 
996  // If the uniformly distributed random number is greater than the
997  // cap forget the current event. This has the correct boundry
998  // conditions - if the cap is 1, then all events are used; if it is
999  // 0 then none are.
1000 
1001  // At some point we may need to worry about keeping more events in the
1002  // tails of the spectrum, but for now it looks like we can keep at least
1003  // 80% of all MetaData options, so we should not be biasing the tails
1004  if(fRandom.Rndm() > eventCap) continue;
1005 
1006  eventTree->GetEntry(evNum);
1007 
1008  if (fFillTextFile)
1009  this->FillTextFile(md, eventId, dataVars, truthVars, weightVars);
1010 
1011  // we have to fill the data vals first to check the
1012  // the energy of this event
1013  dataVars.fFake_Weight = normalization;
1014  cmf::DataVarVals dataVals(dataVars);
1015 
1016  // don't bother filling events with greater than the maximum
1017  // energy for the analysis in the trees - it just wastes time
1018  // in the fitting
1019  if(dataVals.val_at(cmf::kNu_RecoE, md) > fMaxNuEnergy.find(selection)->second) continue;
1020 
1021  // now we can fill the rest of the event info because we are
1022  // keeping this event
1023  if(md.isMC){
1024  systs->clear();
1025 #ifdef PRODUCTION5
1026  for(size_t v = 0; v < systVarKeys->size(); ++v){
1027  loc = (uint8_t)(*systVarKeys)[v];
1028  if(std::find(sysKeys.begin(), sysKeys.end(), loc) == sysKeys.end()) continue;
1029 
1030  // don't bother saving a bunch of 1s in the SystVarColl, instead just
1031  // return all 1s if that systematic is desired for this event from MCVars.
1032  if((*systVarMinus2Wgts)[v] == 1 &&
1033  (*systVarMinus1Wgts)[v] == 1 &&
1034  (*systVarPlus1Wgts )[v] == 1 &&
1035  (*systVarPlus2Wgts )[v] == 1 ) continue;
1036 
1037  systs->emplace_back(loc,
1038  (*systVarMinus2Wgts)[v],
1039  (*systVarMinus1Wgts)[v],
1040  (*systVarPlus1Wgts )[v],
1041  (*systVarPlus2Wgts )[v]);
1042 
1043  LOG_DEBUG("ELMVarCheck")
1044  << "check systematic vector sizes for event "
1045  << evNum
1046  << ": "
1047  << systVarKeys->size()
1048  << " "
1049  << systVarMinus2Wgts->size()
1050  << " "
1051  << systVarMinus1Wgts->size()
1052  << " "
1053  << systVarPlus1Wgts->size()
1054  << " "
1055  << systVarPlus2Wgts->size()
1056  << " "
1057  << systs->size()
1058  << " "
1059  << systs->back();
1060  }
1061 #else
1062  for(auto const& itr : sysKeys){
1063  loc = itr;
1064  if(loc < cmf::kFirstSigmaVar || loc > cmf::kLastSigmaVar) continue;
1065  systs->emplace_back(loc,
1066  genieVars[loc - cmf::kFirstSigmaVar].fMinus2Sigma,
1067  genieVars[loc - cmf::kFirstSigmaVar].fMinus1Sigma,
1068  genieVars[loc - cmf::kFirstSigmaVar].fPlus1Sigma,
1069  genieVars[loc - cmf::kFirstSigmaVar].fPlus2Sigma);
1070  }
1071 #endif
1072 
1073  if(fUseEventId)
1074  eventList.AddEvent(eventId,
1075  dataVals,
1076  cmf::MCVarVals(truthVars, weightVars, *systs));
1077  else
1078  eventList.AddEvent(dataVals,
1079  cmf::MCVarVals(truthVars, weightVars, *systs));
1080  } // end if md.isMC
1081  else{
1082 
1083  // Print out the event id information for each data event in the FD
1084  if(md.detector == cmf::kFARDET){
1085 
1086  std::string selectionStr("numu");
1087  if (md.IsNuESelected()) selectionStr = "nue";
1088  else if(md.IsNCSelected() ) selectionStr = "nc";
1089  LOG_DEBUG("EventListManipulator")
1090  << selectionStr
1091  << " "
1092  << eventId;
1093 
1094  } // end if FD to print the event information
1095 
1096  if(fUseEventId)
1097  eventList.AddEvent(eventId,
1098  dataVals);
1099  else
1100  eventList.AddEvent(dataVals);
1101  }
1102 
1103  } // end loop over events
1104 
1105  systs.reset();
1106  eventTree = nullptr;
1107  } // done
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
const XML_Char * name
Definition: expat.h:151
cmf::SpillSummary const & ListSpillSummary() const
Definition: Event.h:131
float fFake_Weight
Weight for fake data events.
Definition: VarVals.h:131
std::vector< SystGroupDef > systs
Definition: syst_header.h:385
bool fFillTextFile
fills text file with selection information
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
enum cmf::sel_type SelectionType_t
std::map< cmf::SelectionType_t, double > fMaxNuEnergy
maximum neutrino energy to go into the lists
cmf::ParameterSpaceLoc const & SysParameters() const
Base container for the MC related Vars that constitute an event.
Definition: VarVals.h:342
static ParameterUtility * Instance()
std::vector< long > SysParKeys() const
static const unsigned char kMaCCQE
Definition: VarVals.h:70
cmf::MetaData const & ListMetaData() const
Definition: Event.h:135
void FillTextFile(cmf::MetaData const &md, cmf::EventId &ev, cmf::DataVars &dv, cmf::TruthVars &tv, cmf::WeightVars &wv)
Base container for the MC related Vars that constitute an event.
Definition: VarVals.h:383
#define LOG_WARNING(category)
std::string ToString() const
Definition: Structs.cxx:133
double goodPOT
Definition: Structs.h:186
TRandom3 fRandom
Random number generator to use creating fake data lists.
void AddEvent(EventPtr const &ev)
Definition: Event.h:162
bool fUseEventId
use if you need access to run/subrun/event/etc
enum BeamMode string
void cmf::EventListManipulator::FillTextFile ( cmf::MetaData const &  md,
cmf::EventId ev,
cmf::DataVars dv,
cmf::TruthVars tv,
cmf::WeightVars wv 
)
private

Definition at line 786 of file EventListManipulator.cxx.

References demo::app, cmf::MetaData::BeamType(), cmf::cBeamType_Strings, cmf::cSelectionType_Strings, cmf::EventId::cycle, cmf::MetaData::DetectorString(), cmf::EventId::event, cmf::DataVars::fHad_RecoE, plotROC::fileName, cmf::DataVars::fLep_RecoE, cmf::TruthVars::fTrueCCNC, cmf::TruthVars::fTrueE, cmf::TruthVars::fTruePDG, cmf::WeightVars::fXSecCVPPFX_Weight, cmf::MetaData::isMC, confusionMatrixTree::out, cmf::RecoEnergy(), cmf::EventId::run, cmf::MetaData::selectionType, cmf::EventId::slice, string, and cmf::EventId::subrun.

Referenced by FillEventList().

791  {
792 
793  std::string fileName = md.DetectorString();
794  fileName += cBeamType_Strings[md.BeamType()];
795  fileName += cSelectionType_Strings[md.selectionType];
796  fileName += ".txt";
797 
798  std::ifstream ifile;
799  std::ofstream ofile;
800  ifile.open(fileName);
801  if(!ifile) {
802  ofile.open(fileName, std::ofstream::out);
803  ofile
804  << "\n"
805  //<< md.ToString()
806  //<< " "
807  << ev.run
808  << " "
809  << ev.subrun
810  << " "
811  << ev.event
812  << " "
813  << ev.cycle
814  << " "
815  << ev.slice
816  << " "
817  << dv.fLep_RecoE
818  << " "
819  << dv.fHad_RecoE
820  << " "
821  << dv.fHad_RecoE + dv.fLep_RecoE
822  << " "
824  << " ";
825  if (md.isMC){
826  ofile
827  << tv.fTrueE
828  << " "
829  << tv.fTruePDG
830  << " "
831  << tv.fTrueCCNC
832  << " "
833  << wv.fXSecCVPPFX_Weight;
834  }
835 
836 
837  //ofile
838  // << "run"
839  // << " subrun"
840  // << " ev"
841  // << " cyc"
842  // << " slc"
843  // << " Ereco";
844  // if (md.isMC){
845  // ofile
846  // << " Etrue"
847  // << " pdg"
848  // << " ccnc"
849  // << " cvwgt";
850  // }
851  }
852  ofile.open(fileName, std::ofstream::out | std::ofstream::app);
853 
854  ofile
855  << "\n"
856  //<< md.ToString()
857  //<< " "
858  << ev.run
859  << " "
860  << ev.subrun
861  << " "
862  << ev.event
863  << " "
864  << ev.cycle
865  << " "
866  << ev.slice
867  << " "
868  << dv.fLep_RecoE
869  << " "
870  << dv.fHad_RecoE
871  << " "
872  << dv.fHad_RecoE + dv.fLep_RecoE
873  << " "
875  << " ";
876  if (md.isMC){
877  ofile
878  << tv.fTrueE
879  << " "
880  << tv.fTruePDG
881  << " "
882  << tv.fTrueCCNC
883  << " "
884  << wv.fXSecCVPPFX_Weight;
885  }
886 
887  ofile.close();
888  }
fileName
Definition: plotROC.py:78
const std::string cSelectionType_Strings[12]
Definition: Constants.h:79
float fTrueCCNC
true cc vs nc
Definition: VarVals.h:48
float fTruePDG
true PDG
Definition: VarVals.h:47
float fTrueE
True nu energy.
Definition: VarVals.h:46
int subrun
Definition: VarVals.h:84
int cycle
Definition: VarVals.h:86
int slice
Definition: VarVals.h:87
float fXSecCVPPFX_Weight
Was Tufts weight for SA.
Definition: VarVals.h:150
static float RecoEnergy(float leptonicEnergy, float hadronicEnergy, cmf::MetaData const &md)
Definition: VarVals.h:453
app
Definition: demo.py:189
float fHad_RecoE
Definition: VarVals.h:127
const std::string cBeamType_Strings[4]
Definition: Constants.h:35
int event
Definition: VarVals.h:85
float fLep_RecoE
Definition: VarVals.h:128
enum BeamMode string
float cmf::EventListManipulator::PeriodEventCap ( cmf::MetaData const &  md,
long  treeEvents 
)
private

Definition at line 399 of file EventListManipulator.cxx.

References fMaxEventsPerTree, fMinEventsPerTree, LOG_DEBUG, and cmf::MetaData::ToString().

401  {
402  //auto key = md.DetectorFilePeriodString();
403 
404  float cap = (treeEvents > fMaxEventsPerTree - 1) ? fMaxEventsPerTree / (1. * treeEvents) : 1.;
405 
406  // If we are going to have more than fMaxEventsPerTree in a tree,
407  // we want to cap it at that value to keep the memory footprint down
408 
409  // Capping events from trees with fewer events than fMinEventsPerTree
410  // doesn't make a lot of sense, so return 1 in that case
411 
412  // if(treeEvents < fMinEventsPerTree + 1){
413  // cap = 1.;
414  // }
415  // else if(treeEvents > fMaxEventsPerTree - 1){
416  // cap = fMaxEventsPerTree / (1. * treeEvents);
417  // }
418  // else if(treeEvents > fMinEventsPerTree &&
419  // treeEvents < fMaxEventsPerTree){
420 
421  // // now we are in the in between situation - fewer than fMaxEventsPerTree
422  // // but more than fMinEventsPerTree.
423 
424  // if(fEventCaps.count(key) > 0){
425  // float testNum = fEventCaps[key] * treeEvents;
426 
427  // // If the capped number would be smaller than the
428  // // minimum number of events we want, set the cap to
429  // // be equivalent to the minimum events to keep.
430  // // Otherwise just return the found cap
431  // if(testNum < fMinEventsPerTree){
432  // cap = (1. * fMinEventsPerTree) / (1. * treeEvents);
433  // }
434  // else{
435  // cap = fEventCaps[key];
436  // }
437  // } // end if there is a defined cap for this key
438  // } // end if there are more than the minimum number of events to apply a cap
439 
440  LOG_DEBUG("EVentListManipulator")
441  << "Check event cap for "
442  << md.ToString()
443  << ": "
444  << treeEvents
445  << " / "
447  << " / "
449  //<< " cap fraction: "
450  //<< fEventCaps[key]
451  << " final cap: "
452  << cap;
453 
454  // if no cap is specified, use all the events
455  return cap;
456  }
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
float fMaxEventsPerTree
maximum number of events to use per tree
float fMinEventsPerTree
minimum number of events to use per tree
void cmf::EventListManipulator::PrintExposureSummary ( cmf::ExposureMap exposureMap,
bool  isLivetime 
)
private

Definition at line 210 of file EventListManipulator.cxx.

References MECModelEnuComparisons::i, if(), cmf::kFARDET, kFHC, cmf::kNEARDET, kRHC, LOG_VERBATIM, nd_projection_maker::ps, and art::to_string().

Referenced by PrintLivetimeSummary(), and PrintPOTSummary().

211  {
212 
213  std::map<int, double> NDFHC;
214  std::map<int, double> FDFHC;
215  std::map<int, double> NDRHC;
216  std::map<int, double> FDRHC;
217  std::vector<int> ps;
218 
219  for (auto const& itr : exposureMap)
220  {
221 
222  double value;
223  if (isLiveTime) value = itr.second.liveTime;
224  else value = itr.second.goodPOT;
225 
226  // ND FHC
227  if (itr.first.detector == cmf::kNEARDET && itr.first.BeamType() == cmf::BeamType_t::kFHC){
228  if (NDFHC.find(itr.first.period) == NDFHC.end())
229  NDFHC[itr.first.period] = value;
230  if (std::find(ps.begin(), ps.end(), itr.first.period) == ps.end()) ps.push_back(itr.first.period);
231  }
232  // FD FHC
233  if (itr.first.detector == cmf::kFARDET && itr.first.BeamType() == cmf::BeamType_t::kFHC){
234  if (FDFHC.find(itr.first.period) == FDFHC.end())
235  FDFHC[itr.first.period] = value;
236  if (std::find(ps.begin(), ps.end(), itr.first.period) == ps.end()) ps.push_back(itr.first.period);
237  }
238 
239  // ND RHC
240  if (itr.first.detector == cmf::kNEARDET && itr.first.BeamType() == cmf::BeamType_t::kRHC){
241  if (NDRHC.find(itr.first.period) == NDRHC.end())
242  NDRHC[itr.first.period] = value;
243  if (std::find(ps.begin(), ps.end(), itr.first.period) == ps.end()) ps.push_back(itr.first.period);
244  }
245 
246  // FD RHC
247  if (itr.first.detector == cmf::kFARDET && itr.first.BeamType() == cmf::BeamType_t::kRHC){
248  if (FDRHC.find(itr.first.period) == FDRHC.end())
249  FDRHC[itr.first.period] = value;
250  if (std::find(ps.begin(), ps.end(), itr.first.period) == ps.end()) ps.push_back(itr.first.period);
251  }
252  }
253 
254  if (isLiveTime){
255  LOG_VERBATIM("EventListManipulator")
256  << "\n-------------------------------------------------------"
257  << "\nLIVETIME SUMMARY"
258  << "\n-------------------------------------------------------";
259  }
260  else{
261  LOG_VERBATIM("EventListManipulator")
262  << "\n-------------------------------------------------------"
263  << "\nPOT SUMMARY"
264  << "\n-------------------------------------------------------";
265  }
266 
267  std::sort(ps.begin(), ps.end());
268  LOG_VERBATIM("EventListManipulator")
269  << std::setw(20)
270  << ""
271  << std::setw(20)
272  << "ND FHC"
273  << std::setw(20)
274  << "FD FHC"
275  << std::setw(20)
276  << "ND RHC"
277  << std::setw(20)
278  << "FD RHC";
279  for (size_t i = 0; i < ps.size(); ++i){
280  LOG_VERBATIM("EventListManipulator")
281  << std::setw(20)
282  << "Period "+std::to_string(ps[i])
283  << std::setw(20)
284  << NDFHC[ps[i]]
285  << std::setw(20)
286  << FDFHC[ps[i]]
287  << std::setw(20)
288  << NDRHC[ps[i]]
289  << std::setw(20)
290  << FDRHC[ps[i]];
291  }
292 
293  }
if(dump)
const XML_Char int const XML_Char * value
Definition: expat.h:331
#define LOG_VERBATIM(category)
std::string to_string(ModuleType mt)
Definition: ModuleType.h:32
void cmf::EventListManipulator::PrintLivetimeSummary ( cmf::ExposureMap exposureMap)

Definition at line 301 of file EventListManipulator.cxx.

References PrintExposureSummary().

Referenced by SetExposures().

301  {
302  this->PrintExposureSummary(exposureMap, true);
303  }
void PrintExposureSummary(cmf::ExposureMap &exposureMap, bool isLivetime)
void cmf::EventListManipulator::PrintPOTSummary ( cmf::ExposureMap exposureMap)

Definition at line 296 of file EventListManipulator.cxx.

References PrintExposureSummary().

Referenced by SetExposures().

296  {
297  this->PrintExposureSummary(exposureMap, false);
298  }
void PrintExposureSummary(cmf::ExposureMap &exposureMap, bool isLivetime)
void cmf::EventListManipulator::reconfigure ( const fhicl::ParameterSet p)

Definition at line 47 of file EventListManipulator.cxx.

References runNovaSAM::detectors, dir, fCMFEventLabels, fDetectors, fFillTextFile, fLoadAllEventLists, fMaxEventsPerTree, fMaxNuEnergy, fMinEventsPerTree, fRandom, fTreeDirectories, fUseEventId, fhicl::ParameterSet::get(), cmf::kNCSelection, cmf::kNuESelection, cmf::kNuMuSelection, LOG_VERBATIM, SetExposures(), and cmf::StringToDetectorType().

Referenced by EventListManipulator().

48  {
49 
50 #ifdef PRODUCTION4
51  LOG_VERBATIM("EventListManipulator")
52  << "\n-------------------------------------------------------"
53  << "\nConfiguring production 4 event lists"
54  << "\n-------------------------------------------------------";
55 #endif
56 #ifdef PRODUCTION5
57  LOG_VERBATIM("EventListManipulator")
58  << "\n-------------------------------------------------------"
59  << "\nConfiguring production 5 event lists"
60  << "\n-------------------------------------------------------";
61 #endif
62 
63  fRandom.SetSeed(pset.get<unsigned int>("RandomSeed", 0));
64 
65  auto detectors = pset.get<std::vector<std::string>>("DetectorsToUse", std::vector<std::string>({"Near", "Far"}));
66  for(auto const& itr : detectors) fDetectors.insert(cmf::StringToDetectorType(itr));
67 
68  fCMFEventLabels = pset.get< std::vector<std::string> >("CMFEventLabels" , std::vector<std::string>() );
69  fTreeDirectories = pset.get< std::vector<std::string> >("TreeDirectories" , std::vector<std::string>() );
70  fUseEventId = pset.get< bool >("UseEventId" , false );
71  fMaxNuEnergy[cmf::kNuESelection ] = pset.get< double >("MaxNuEEnergyForAnalysis" , 5.0 );
72  fMaxNuEnergy[cmf::kNuMuSelection] = pset.get< double >("MaxNuMuEnergyForAnalysis" , 10.0 );
73  fMaxNuEnergy[cmf::kNCSelection ] = pset.get< double >("MaxNCEnergyForAnalysis" , 20.0 );
74  fMaxEventsPerTree = pset.get< float >("MaxEventsPerTree" , 1.e6 );
75  fMinEventsPerTree = pset.get< float >("MinEventsPerTree" , 2.e4 );
76  fFillTextFile = pset.get< bool >("FillTextFile" , false );
77 
78  // if we're printing the event lists we want the event ID information!
79  if (fFillTextFile){
80  fUseEventId = true;
81  fMaxEventsPerTree = 1.e6;
82  }
83 
84  for(auto & dir : fTreeDirectories) dir.append("/full");
85 
86  // determine which general experiments we have, ie nue or numu or both
87  // allow users to force the use of all event lists if they choose
88  fLoadAllEventLists = pset.get<bool>("LoadAllEventLists", false);
89 
90  this->SetExposures(pset);
91 
92  // Comment out using event caps for now
93  //this->SetEventCaps(pset);
94 
95  }
bool fFillTextFile
fills text file with selection information
std::vector< std::string > fCMFEventLabels
Labels in input files holding CovarianceMatrixFit Events.
std::map< cmf::SelectionType_t, double > fMaxNuEnergy
maximum neutrino energy to go into the lists
float fMaxEventsPerTree
maximum number of events to use per tree
std::set< cmf::DetType_t > fDetectors
which detector(s) are we loading events from
bool fLoadAllEventLists
force all event lists to be loaded
static cmf::DetType_t StringToDetectorType(std::string const &str)
Definition: StaticFuncs.h:275
float fMinEventsPerTree
minimum number of events to use per tree
TDirectory * dir
Definition: macro.C:5
TRandom3 fRandom
Random number generator to use creating fake data lists.
void SetExposures(fhicl::ParameterSet const &pset)
#define LOG_VERBATIM(category)
bool fUseEventId
use if you need access to run/subrun/event/etc
std::vector< std::string > fTreeDirectories
directory holding the input trees
void cmf::EventListManipulator::SetEventCaps ( fhicl::ParameterSet const &  pset)
private

Definition at line 102 of file EventListManipulator.cxx.

References fEventCaps, fPeriodsToUse, fhicl::ParameterSet::get(), LOG_DEBUG, string, and art::to_string().

103  {
104  auto caps = pset.get<fhicl::ParameterSet>("EventCap", fhicl::ParameterSet());
105  std::string keyStr;
106 
107  // the event caps are parameter sets named by the detector and file type, the
108  // periods are stored in the parameters for each detector/file type combo
109  for(auto const& name : caps.get_names()){
110 
111  LOG_DEBUG("ELMEventCap")
112  << "cap parameter: "
113  << name;
114 
115  // no flux or tau files for the ND
116  if(name.find("Near") != std::string::npos &&
117  name.find("Beam") == std::string::npos &&
118  name.find("Data") == std::string::npos ) continue;
119 
120  for(auto const& per : fPeriodsToUse){
121  keyStr = name + "P" + std::to_string(per);
122 
123  fEventCaps[keyStr] = caps.get<fhicl::ParameterSet>(name).get<float>("P" + std::to_string(per), 1.);
124 
125  LOG_DEBUG("ELMEventCap")
126  << keyStr
127  << " "
128  << caps.get<fhicl::ParameterSet>(name).get<float>("P" + std::to_string(per), 1.);
129 
130  } // end loop over periods
131  } // end loop over caps
132 
133  }
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
const XML_Char * name
Definition: expat.h:151
std::set< long > fPeriodsToUse
which periods to use in the analysis
std::map< std::string, float > fEventCaps
std::string to_string(ModuleType mt)
Definition: ModuleType.h:32
enum BeamMode string
void cmf::EventListManipulator::SetExposures ( fhicl::ParameterSet const &  pset)
private

Definition at line 137 of file EventListManipulator.cxx.

References POTSpillRate::beam, fillBadChanDBTables::det, fExposure, fPeriodsToUse, fhicl::ParameterSet::get(), cmf::SelectionUtility::Instance(), cmf::kDataFile, cmf::kFARDET, cmf::kFHC, cmf::kNEARDET, cmf::kUnknownInteraction, LOG_DEBUG, fetch_tb_beamline_files::md, cmf::PeriodToBeamType(), PrintLivetimeSummary(), PrintPOTSummary(), cmf::SelectionUtility::SelectionsToUse(), ana::sels, string, and art::to_string().

Referenced by reconfigure().

138  {
139 
140  auto psetExposure = pset.get< std::vector<fhicl::ParameterSet> >("ExposureToUse", std::vector<fhicl::ParameterSet>() );
141  LOG_DEBUG("EventListManipulator")
142  << "There are "
143  << psetExposure.size()
144  << " exposures from fhicl";
145 
146  auto fhcExposureMultiplier = pset.get<double>("FHCExposureMultiplier", 1.);
147  auto rhcExposureMultiplier = pset.get<double>("RHCExposureMultiplier", 1.);
148  fExposure.clear();
149  for(auto const& exposure : psetExposure){
150 
151  auto psetDet = exposure.get<std::string>("Detector" );
152  auto psetPeriod = exposure.get<int >("Period" );
153  auto psetExposure = exposure.get<float >("Exposure" );
154  auto psetLivetime = exposure.get<float >("Livetime" );
155 
156  fPeriodsToUse.insert(psetPeriod);
157 
158  cmf::SpillSummary spillSummary(psetExposure,
159  psetExposure,
160  psetLivetime,
161  0,
162  0);
163 
164  cmf::DetType_t det = (psetDet == "NearDet") ? cmf::kNEARDET : cmf::kFARDET;
166 
167  // if we want high stats fakes, multiply the exposure by exposure
168  // multiplier - only ever applied to FD
169  if(det == cmf::kFARDET)
170  psetExposure *= (beam == cmf::kFHC) ? fhcExposureMultiplier : rhcExposureMultiplier;
171 
172  auto const& dbsSet = cmf::SelectionUtility::Instance()->SelectionsToUse();
173  for(auto const& sel : (*dbsSet.find(cmf::SelectionUtility::DetBeamSels(det, beam))).sels){
174  cmf::MetaData md(false,
175  det,
177  sel,
179  psetPeriod);
180 
181  if(fExposure.count(md) < 1){
182  fExposure.emplace(md, spillSummary);
183  }
184  else {
185  fExposure[md].totalPOT += psetExposure;
186  fExposure[md].goodPOT += psetExposure;
187  fExposure[md].liveTime += psetLivetime;
188  }
189 
190  } // end loop over selections
191 
192  } // end if we have detectors and selections to make
193 
194  this->PrintPOTSummary (fExposure);
196 
197  //for(auto const& itr : fExposure)
198  // LOG_VERBATIM("EventListManipulator")
199  // << "configuring exposure from fhicl"
200  // << std::setw(30)
201  // << itr.first.ToString()
202  // << " to have "
203  // << itr.second
204  // << " POT and this event list will not be deserialized";
205 
206  }
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
static SelectionUtility * Instance()
std::set< long > fPeriodsToUse
which periods to use in the analysis
enum cmf::det_type DetType_t
cmf::ExposureMap fExposure
POT in 1e12 to normalise to.
void PrintLivetimeSummary(cmf::ExposureMap &exposureMap)
const Cut sels[kNumSels]
Definition: vars.h:44
static cmf::BeamType_t PeriodToBeamType(std::string const &str)
associates each detector-beam pair to a set of selections
enum cmf::beam_type BeamType_t
const DetBeamSelSet & SelectionsToUse()
void PrintPOTSummary(cmf::ExposureMap &exposureMap)
std::string to_string(ModuleType mt)
Definition: ModuleType.h:32
enum BeamMode string
bool cmf::EventListManipulator::UseEventsFromMetaData ( cmf::MetaData const &  md,
cmf::DataMC_t  dataMC,
std::set< cmf::DetType_t > const &  detectors 
)
private

Definition at line 308 of file EventListManipulator.cxx.

References cmf::cSelectionType_Strings, cmf::MetaData::detector, cmf::MetaData::DetectorString(), fDetectors, cmf::MetaData::fileType, fLoadAllEventLists, fPeriodsToUse, cmf::SelectionUtility::Instance(), cmf::MetaData::interactionType, cmf::MetaData::isMC, cmf::kCosmicBackgroundFile, cmf::kData, cmf::kFakeData, cmf::kMC, cmf::kRockFluxSwap, cmf::kRockNonSwap, cmf::kUncategorised, LOG_DEBUG, cmf::MetaData::Period(), cmf::MetaData::PeriodString(), cmf::MetaData::selectionType, cmf::MetaData::ToString(), and cmf::SelectionUtility::UsesDetBeamAndSel().

Referenced by ExtractFromFile().

311  {
312  if(fLoadAllEventLists) return true;
313 
314 #ifdef PRODUCTION4
315  if(md.fileType == cmf::kCosmicBackgroundFile ||
316  md.fileType == cmf::kRockFluxSwap ||
317  md.fileType == cmf::kRockNonSwap) return false;
318 #endif
319 
320  //if(md.fileType == cmf::kCosmicBackgroundFile) return false;
321 
322  // check if this is data and we only want MC events
323  // or vice versa
324  if(dataMC == cmf::kMC && !md.isMC){
325  LOG_DEBUG("ELMUEFMMC")
326  << md.ToString()
327  << " failed cmf::kMC and !md.isMC";
328  return false;
329  }
330  else if(dataMC == cmf::kData && md.isMC){
331  LOG_DEBUG("ELMUEFMRealData")
332  << md.ToString()
333  << " failed cmf::kData and md.isMC";
334  return false;
335  }
336  else if(dataMC == cmf::kFakeData && !md.isMC){
337  LOG_DEBUG("ELMUEFMFakeData")
338  << md.ToString()
339  << " failed cmf::kFakeData and !md.isMC";
340  return false;
341  }
342 
343  //Skip unless the epoch is in the fPeriodsToUse set
344  if(fPeriodsToUse.count(md.Period()) < 1){
345  LOG_DEBUG("ELMUEFMPeriod")
346  << md.ToString()
347  << " failed count of periods to use "
348  << md.Period();
349  return false;
350  }
351 
352  // Skip if uncategorized interactions
353  if(md.interactionType == cmf::kUncategorised){
354  LOG_DEBUG("ELMUEFMInteraction")
355  << md.ToString()
356  << " failed interaction type check to use "
357  << md.interactionType;
358  return false;
359  }
360 
361  // check if the detector for this metadata is desired, return false if it
362  // isn't in the fDetectors set. We have to check detector separately from
363  // the SelectionUtility because the selection utility is set for the entire
364  // job, not just the EventListManipulator which may only want to use
365  // event from a subset of detectors for the job.
366  // Moreover, even though ultimately we want to use both detectors, a job
367  // may want to load one at a time for memory management, so we use the
368  // detectors set to check on that
369  if(fDetectors.count(md.detector) < 1 || detectors.count(md.detector) < 1) return false;
370 
371  // now check that the selection is desired for the detector, beam and
372  // selection of this metadata
374  LOG_DEBUG("ELMUEFMDetector")
375  << md.ToString()
376  << " failed to find "
377  << md.DetectorString()
378  << " "
379  << md.PeriodString()
380  << " "
381  << cmf::cSelectionType_Strings[md.selectionType]
382  << " in selections to use";
383  return false;
384  }
385 
386  // Metadata types we are going to skip
387  // - ND flux swap for now
388  //if(md->fileType == cmf::kSwap &&
389  // md->detector == cmf::kNEARDET ) return false;
390 
391  return true;
392  }
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
const std::string cSelectionType_Strings[12]
Definition: Constants.h:79
static SelectionUtility * Instance()
std::set< long > fPeriodsToUse
which periods to use in the analysis
std::set< cmf::DetType_t > fDetectors
which detector(s) are we loading events from
bool fLoadAllEventLists
force all event lists to be loaded
bool UsesDetBeamAndSel(cmf::MetaData const &md) const

Member Data Documentation

std::vector<std::string> cmf::EventListManipulator::fCMFEventLabels
private

Labels in input files holding CovarianceMatrixFit Events.

Definition at line 114 of file EventListManipulator.h.

Referenced by Deserialize(), and reconfigure().

std::set<cmf::DetType_t> cmf::EventListManipulator::fDetectors
private

which detector(s) are we loading events from

Definition at line 118 of file EventListManipulator.h.

Referenced by reconfigure(), and UseEventsFromMetaData().

std::map<std::string, float> cmf::EventListManipulator::fEventCaps
private

maximum fraction of events to use from each combination of detector, filetype and epoch

Definition at line 119 of file EventListManipulator.h.

Referenced by EventListManipulator(), and SetEventCaps().

cmf::ExposureMap cmf::EventListManipulator::fExposure
private

POT in 1e12 to normalise to.

Definition at line 117 of file EventListManipulator.h.

Referenced by SetExposures(), and ~EventListManipulator().

bool cmf::EventListManipulator::fFillTextFile
private

fills text file with selection information

Definition at line 127 of file EventListManipulator.h.

Referenced by FillEventList(), and reconfigure().

bool cmf::EventListManipulator::fLoadAllEventLists
private

force all event lists to be loaded

Definition at line 124 of file EventListManipulator.h.

Referenced by reconfigure(), and UseEventsFromMetaData().

float cmf::EventListManipulator::fMaxEventsPerTree
private

maximum number of events to use per tree

Definition at line 125 of file EventListManipulator.h.

Referenced by PeriodEventCap(), and reconfigure().

std::map<cmf::SelectionType_t, double> cmf::EventListManipulator::fMaxNuEnergy
private

maximum neutrino energy to go into the lists

Definition at line 123 of file EventListManipulator.h.

Referenced by FillEventList(), and reconfigure().

float cmf::EventListManipulator::fMinEventsPerTree
private

minimum number of events to use per tree

Definition at line 126 of file EventListManipulator.h.

Referenced by PeriodEventCap(), and reconfigure().

std::set<long> cmf::EventListManipulator::fPeriodsToUse
private

which periods to use in the analysis

Definition at line 122 of file EventListManipulator.h.

Referenced by SetEventCaps(), SetExposures(), and UseEventsFromMetaData().

TRandom3 cmf::EventListManipulator::fRandom
private

Random number generator to use creating fake data lists.

Definition at line 116 of file EventListManipulator.h.

Referenced by FillEventList(), and reconfigure().

std::vector<std::string> cmf::EventListManipulator::fTreeDirectories
private

directory holding the input trees

Definition at line 115 of file EventListManipulator.h.

Referenced by Deserialize(), and reconfigure().

bool cmf::EventListManipulator::fUseEventId
private

use if you need access to run/subrun/event/etc

Definition at line 121 of file EventListManipulator.h.

Referenced by FillEventList(), and reconfigure().


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