47 <<
"\n-------------------------------------------------------" 48 <<
"\nConfiguring production 5 event lists" 49 <<
"\n-------------------------------------------------------";
51 fRandom.SetSeed(pset.
get<
unsigned int>(
"RandomSeed", 0));
53 auto detectors = pset.
get<std::vector<std::string>>(
"DetectorsToUse", std::vector<std::string>({
"Near",
"Far"}));
56 fCMFEventLabels = pset.
get< std::vector<std::string> >(
"CMFEventLabels" , std::vector<std::string>() );
57 fTreeDirectories = pset.
get< std::vector<std::string> >(
"TreeDirectories" , std::vector<std::string>() );
70 fMaxEventsPerTree = 1.e6;
98 for(
auto const&
name : caps.get_names()){
105 if(
name.find(
"Near") != std::string::npos &&
106 name.find(
"Beam") == std::string::npos &&
107 name.find(
"Data") == std::string::npos )
continue;
129 auto psetExposure = pset.
get< std::vector<fhicl::ParameterSet> >(
"ExposureToUse", std::vector<fhicl::ParameterSet>() );
132 << psetExposure.size()
133 <<
" exposures from fhicl";
135 auto fhcExposureMultiplier = pset.
get<
double>(
"FHCExposureMultiplier", 1.);
136 auto rhcExposureMultiplier = pset.
get<
double>(
"RHCExposureMultiplier", 1.);
138 for(
auto const& exposure : psetExposure){
140 auto psetDet = exposure.get<
std::string>(
"Detector" );
141 auto psetPeriod = exposure.get<
int >(
"Period" );
142 auto psetExposure = exposure.get<
float >(
"Exposure" );
143 auto psetLivetime = exposure.get<
float >(
"Livetime" );
159 psetExposure *= (beam ==
cmf::kFHC) ? fhcExposureMultiplier : rhcExposureMultiplier;
202 std::map<int, double> NDFHC;
203 std::map<int, double> FDFHC;
204 std::map<int, double> NDRHC;
205 std::map<int, double> FDRHC;
208 for (
auto const& itr : exposureMap)
212 if (isLiveTime) value = itr.second.liveTime;
213 else value = itr.second.goodPOT;
217 if (NDFHC.find(itr.first.period) == NDFHC.end())
218 NDFHC[itr.first.period] = value;
219 if (std::find(ps.begin(), ps.end(), itr.first.period) == ps.end()) ps.push_back(itr.first.period);
223 if (FDFHC.find(itr.first.period) == FDFHC.end())
224 FDFHC[itr.first.period] = value;
225 if (std::find(ps.begin(), ps.end(), itr.first.period) == ps.end()) ps.push_back(itr.first.period);
230 if (NDRHC.find(itr.first.period) == NDRHC.end())
231 NDRHC[itr.first.period] = value;
232 if (std::find(ps.begin(), ps.end(), itr.first.period) == ps.end()) ps.push_back(itr.first.period);
237 if (FDRHC.find(itr.first.period) == FDRHC.end())
238 FDRHC[itr.first.period] = value;
239 if (std::find(ps.begin(), ps.end(), itr.first.period) == ps.end()) ps.push_back(itr.first.period);
245 <<
"\n-------------------------------------------------------" 246 <<
"\nLIVETIME SUMMARY" 247 <<
"\n-------------------------------------------------------";
251 <<
"\n-------------------------------------------------------" 253 <<
"\n-------------------------------------------------------";
256 std::sort(ps.begin(), ps.end());
268 for (
size_t i = 0;
i < ps.size(); ++
i){
299 std::set<cmf::DetType_t>
const&
detectors)
314 <<
" failed cmf::kMC and !md.isMC";
320 <<
" failed cmf::kData and md.isMC";
326 <<
" failed cmf::kFakeData and !md.isMC";
334 <<
" failed count of periods to use " 343 <<
" failed interaction type check to use " 363 <<
" failed to find " 369 <<
" in selections to use";
428 <<
"Check event cap for " 449 std::set<cmf::DetType_t>
const&
detectors,
450 std::vector<cmf::FileExtracts> & extractVec)
453 <<
"extracting metadata from file";
458 TTree *metadataTree =
dynamic_cast<TTree *
>(metadataFile->Get((dirName +
"/metadata").c_str()));
462 <<
"cannot find metadata tree: " 463 << dirName +
"/metadata";
475 metadataTree->SetBranchAddress(
"metadata", &md);
476 metadataTree->SetBranchAddress(
"spillsummary", &ss);
481 for(
int ctr = 0; ctr < metadataTree->GetEntries(); ++ctr){
482 metadataTree->GetEntry(ctr);
489 if(exposureMap.count(*md) < 1) exposureMap[*md] = *ss;
490 else exposureMap[*
md] += *
ss;
494 for(
auto const& itr : exposureMap){
497 mdString = itr.first.ToString();
499 treeName = dirName +
"/" + mdString;
501 if(itr.second.goodPOT > 0 ||
503 extractVec.emplace_back(itr.first,
506 this->PeriodEventCap(itr.first, dynamic_cast<TTree*>(metadataFile->Get(treeName.c_str()))->GetEntriesFast()));
511 << itr.first.ToString()
513 << itr.second.goodPOT
515 << itr.second.liveTime
517 << exposureMap.size();
539 std::set<cmf::DetType_t>
const&
detectors)
543 std::vector<cmf::FileExtracts> extractVec;
544 size_t totalEvents = 0;
548 double normalization = 1.;
553 TFile *
f = TFile::Open(
fileName.c_str());
557 <<
"successfully opened " 561 <<
"Cannot open file " 571 <<
" metadata categories";
576 std::map<long, double> keyToMinExposure;
578 double cappedExposure;
580 for(
auto & itr : extractVec){
582 cappedExposure = (itr.metadata.IsCosmicMuon()) ? itr.CappedLiveTime() : itr.CappedPOT();
584 if(keyToMinExposure.count(key) < 1)
585 keyToMinExposure[key] = cappedExposure;
587 keyToMinExposure[
key] =
std::min(keyToMinExposure.find(key)->second, cappedExposure);
595 << itr.spillSummary.goodPOT
597 << keyToMinExposure[
key]
599 << itr.spillSummary.liveTime
601 << keyToMinExposure[
key];
608 for(
auto & itr : extractVec){
614 ss = itr.spillSummary;
640 normalization = keyToMinExposure[itr.Key()] / exposure;
651 normalization = keyToMinExposure[itr.Key()] / exposure;
659 << itr.metadata.ToString()
665 << exposure / itr.eventCap
668 <<
" cap POT/livetime " 674 <<
" with normalization of " 678 if(listItr == eventLists.end()){
682 this->
FillEventList(f, itr.treeName, itr.eventCap, normalization, *listItr);
684 totalEvents += listItr->size();
693 <<
" event lists and " 697 for(
auto const& itr : eventLists){
699 md = itr.ListMetaData();
700 ss = itr.ListSpillSummary();
750 ifile.open(fileName);
843 double const& eventCap,
844 double const& normalization,
854 std::vector<unsigned char>* systVarKeys =
nullptr;
855 std::vector<float>* systVarMinus2Wgts =
nullptr;
856 std::vector<float>* systVarMinus1Wgts =
nullptr;
857 std::vector<float>* systVarPlus1Wgts =
nullptr;
858 std::vector<float>* systVarPlus2Wgts =
nullptr;
867 TTree *eventTree =
dynamic_cast<TTree*
>(eventFile->Get(treeName.c_str()));
868 eventTree->SetBranchAddress(
"dataVars", &dataVars);
870 eventTree->SetBranchAddress(
"eventId", &eventId);
873 eventTree->SetBranchAddress(
"truthVars" , &truthVars );
874 eventTree->SetBranchAddress(
"weightVars", &weightVars);
876 eventTree->SetBranchAddress(
"systVarKeys", &systVarKeys);
877 eventTree->SetBranchAddress(
"systVarMinus2Wgts", &systVarMinus2Wgts);
878 eventTree->SetBranchAddress(
"systVarMinus1Wgts", &systVarMinus1Wgts);
879 eventTree->SetBranchAddress(
"systVarPlus1Wgts", &systVarPlus1Wgts);
880 eventTree->SetBranchAddress(
"systVarPlus2Wgts", &systVarPlus2Wgts);
904 <<
" < 10^9 POT. That cannot be right, bail";
906 auto systs = std::make_unique<cmf::SystVarColl>();
910 long maxEvents = eventTree->GetEntries();
911 for(
long evNum = 0; evNum < maxEvents; ++evNum){
921 if(
fRandom.Rndm() > eventCap)
continue;
923 eventTree->GetEntry(evNum);
947 for(
size_t v = 0;
v < systVarKeys->size(); ++
v){
948 loc = (*systVarKeys)[
v];
957 if(std::find(sysKeys.begin(), sysKeys.end(),
loc) == sysKeys.end())
continue;
961 if((*systVarMinus2Wgts)[
v] == 1 &&
962 (*systVarMinus1Wgts)[
v] == 1 &&
963 (*systVarPlus1Wgts )[
v] == 1 &&
964 (*systVarPlus2Wgts )[
v] == 1 )
continue;
966 systs->emplace_back(loc,
967 (*systVarMinus2Wgts)[
v],
968 (*systVarMinus1Wgts)[v],
969 (*systVarPlus1Wgts )[v],
970 (*systVarPlus2Wgts )[v]);
973 <<
"check systematic vector sizes for event " 976 << systVarKeys->size()
978 << systVarMinus2Wgts->size()
980 << systVarMinus1Wgts->size()
982 << systVarPlus1Wgts->size()
984 << systVarPlus2Wgts->size()
1005 if (
md.IsNuESelected()) selectionStr =
"nue";
1006 else if(
md.IsNCSelected() ) selectionStr =
"nc";
1035 eventTree =
nullptr;
#define LOG_DEBUG(stream)
std::map< cmf::MetaData, cmf::SpillSummary > ExposureMap
cmf::SpillSummary const & ListSpillSummary() const
float fFake_Weight
Weight for fake data events.
const std::string cSelectionType_Strings[12]
float PeriodEventCap(cmf::MetaData const &md, long treeEvents)
float fTrueCCNC
true cc vs nc
void FillEventList(TFile *eventFile, std::string const &treeName, double const &eventCap, double const &normalization, cmf::EventList &eventList)
bool fFillTextFile
fills text file with selection information
static SelectionUtility * Instance()
std::vector< std::string > fCMFEventLabels
Labels in input files holding CovarianceMatrixFit Events.
std::set< long > fPeriodsToUse
which periods to use in the analysis
cmf::EventListColl::iterator FindEventList(cmf::MetaData const &md, cmf::EventListColl &eventListColl)
enum cmf::det_type DetType_t
::xsd::cxx::tree::exception< char > exception
enum cmf::sel_type SelectionType_t
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
static bool IsNuESelected(cmf::SelectionType_t const &sel)
static bool IsNuMuQuantiles(cmf::SelectionType_t const &sel)
float fTrueE
True nu energy.
EventListManipulator(fhicl::ParameterSet const &pset)
cmf::ExposureMap fExposure
POT in 1e12 to normalise to.
bool fLoadAllEventLists
force all event lists to be loaded
Base container for the MC related Vars that constitute an event.
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}))
static ParameterUtility * Instance()
void SetEventCaps(fhicl::ParameterSet const &pset)
void PrintLivetimeSummary(cmf::ExposureMap &exposureMap)
const XML_Char int const XML_Char * value
enum cmf::dataMC_type DataMC_t
T get(std::string const &key) const
cmf::MetaData const & ListMetaData() const
static cmf::DetType_t StringToDetectorType(std::string const &str)
bool UsesSelection(cmf::SelectionType_t const &s) const
float fMinEventsPerTree
minimum number of events to use per tree
static cmf::BeamType_t PeriodToBeamType(std::string const &str)
void FillTextFile(cmf::MetaData const &md, cmf::EventId &ev, cmf::DataVars &dv, cmf::TruthVars &tv, cmf::WeightVars &wv)
std::map< std::string, float > fEventCaps
float val_at(uint8_t const &varkey, cmf::MetaData const &md) const
Base container for the MC related Vars that constitute an event.
bool fDeserializeCosmics
whether or not deserialize cosmic muons
float fXSecCVPPFX_Weight
Deprecated, Was Tufts weight for SA.
associates each detector-beam pair to a set of selections
std::vector< uint8_t > SysParKeys() const
Module to combine a set of results into a single file currently only does one data product type at a ...
std::vector< cmf::EventList > EventListColl
void PrintExposureSummary(cmf::ExposureMap &exposureMap, bool isLivetime)
static float RecoEnergy(float leptonicEnergy, float hadronicEnergy, cmf::MetaData const &md)
TRandom3 fRandom
Random number generator to use creating fake data lists.
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)
enum cmf::beam_type BeamType_t
bool UseEventsFromMetaData(cmf::MetaData const &md, cmf::DataMC_t dataMC, std::set< cmf::DetType_t > const &detectors)
void AddEvent(EventPtr const &ev)
const DetBeamSelSet & SelectionsToUse()
void reconfigure(const fhicl::ParameterSet &p)
void SetExposures(fhicl::ParameterSet const &pset)
void PrintPOTSummary(cmf::ExposureMap &exposureMap)
#define LOG_VERBATIM(category)
std::string to_string(ModuleType mt)
T min(const caf::Proxy< T > &a, T b)
bool fUseEventId
use if you need access to run/subrun/event/etc
const std::string cBeamType_Strings[4]
std::vector< std::string > fTreeDirectories
directory holding the input trees
static std::string KeyToString(long const &key)
bool UsesDetBeamAndSel(cmf::MetaData const &md) const