EventListManipulator.h
Go to the documentation of this file.
1 //
2 // EventListManipulator.h
3 // Helper object to handle creating EventLists from TTrees
4 //
5 // Created by Brian Rebel on 3/21/16.
6 //
7 
8 #ifndef EventListManipulator_h
9 #define EventListManipulator_h
10 
11 #include <stdio.h>
12 
13 #include "TF1.h"
14 #include "TRandom3.h"
15 #include "TH1.h"
16 #include "TTree.h"
17 
22 
23 #include "FNEX/core/Event.h"
24 #include "FNEX/core/Correlations.h"
26 
27 
28 namespace sumdata {
29  class POTSum;
30 }
31 
32 namespace fnex {
33 
34  typedef enum dataMC_type{
35  kData = 0,
36  kMC,
38  kBoth
39  } DataMC_t;
40 
41  typedef std::unordered_map<fnex::MetaData,
42  double,
44  typedef std::unordered_map<fnex::MetaData,
45  std::vector<TH1F*>,
47 
49 
50  public:
51 
53  fnex::InputPoint const& initialGuess);
54  virtual ~EventListManipulator();
55 
56  void reconfigure(const fhicl::ParameterSet& p);
57 
58  fnex::EventListMap Deserialize (fnex::DataMC_t dataMC=fnex::kBoth);
59  fnex::EventListMap DeserializeData();
60  fnex::EventListMap DeserializeMC () { return this->Deserialize(fnex::kMC); }
61 
62  private:
63 
64  void ExtractMetaDataFromFile(TFile* metadataFile,
65  std::string const& dirName,
66  fnex::DataMC_t const& dataMC,
67  std::map<fnex::MetaData, fnex::SpillSummary> & mdToSS);
68  void ExtractEventsFromFile(TFile* eventFile,
69  std::string const& dirName,
70  fnex::DataMC_t const& dataMC,
71  std::pair<fnex::MetaData, fnex::SpillSummary> const& mdToSS,
72  fnex::EventListMap & eventLists);
73  void CheckDataMCListConsistency(std::set<fnex::MetaDataLite> const& dataSets,
74  std::set<fnex::MetaDataLite> const& mcSets,
75  fnex::DataMC_t const& dataMC,
76  fnex::EventListMap & eventLists);
77  void CreateFarDetCosmicBackgrounds(fnex::EventListMap & eventLists);
78 
79  void LoadVarVals(fnex::Event & fnexEvent,
80  bool isMC,
81  std::vector<std::string> const& indepVarNames,
82  std::vector<float> const& indepVarVals);
83 
84  fnex::EventList FillEventList(TTree * eventTree,
85  fnex::MetaData const& md,
87  void CheckMCListsForFakeDataEpochs(fnex::EventListMap & lists,
88  novadaq::cnv::DetId const& det);
89  void FillFakeDataLists(fnex::EventListMap & lists);
90  void FillFakeDataListsForDetector(fnex::EventListMap & lists,
91  novadaq::cnv::DetId const& det,
92  std::map<int, double> const& detEpochToMinPOT);
93  fnex::EventList AddFakeDataToEventList(fnex::MetaData const& md,
94  fnex::SpillSummary const& ss,
95  fnex::EventList const& mcList);
96  fnex::EventList CreateFarDetCosmicBackgroundsFromEventList(fnex::MetaData const& md,
97  fnex::SpillSummary const& ss,
98  fnex::EventListMap const& listmap);
99  fnex::EventList CreateFarDetCosmicBackgroundsFromHist(fnex::MetaData const& md,
100  fnex::SpillSummary const& ss);
101  fnex::EventList CreatePoissonFakeData(fnex::MetaData const& md,
102  fnex::SpillSummary const& ss,
103  fnex::EventList const& origList);
104 
105  //double CountListEvents(fnex::EventList const& evList);
106  void MakeHistograms(fnex::EventListMap const& lists,
107  std::string const& dirName);
108  void FillHistograms(fnex::EventListMap const& evLists,
109  std::string const& dirName);
110  void FillHistogram(art::TFileDirectory & tfdir,
111  fnex::EventList const& evList,
112  std::string const& listType,
113  double const& normalization);
114  void ConcatenateLists(fnex::EventListMap const& lists,
115  std::string const& dirName,
116  bool const& byEpoch,
117  bool const& byInteraction,
118  bool const& byFile);
119 
120  double RescalePOTForEventCap(size_t & totalEvents,
121  size_t const& eventCap);
122  double RescalePOTForEventCap(double & totalEvents,
123  size_t const& eventCap);
124 
125  void FixNearDetMCExposures(fnex::EventListMap & lists);
126 
127  std::unique_ptr<TH1F> FarDetCosmicBackgroundHistAndScale(fnex::MetaData const& md,
128  float & scale,
129  fnex::SpillSummary const& ss);
130  float EpochEventCap(fnex::MetaData const& md,
131  int treeEvents);
132 
133  void WriteCappedListsAsTrees(fnex::EventListMap const& list);
134 
135  void DetermineSelections(std::vector<fhicl::ParameterSet> const& selections);
136  bool UseEventsFromMetaData(fnex::MetaData const& md,
137  fnex::DataMC_t const dataMC);
138 
139  void CreateNDPeripheralLists(fnex::EventListMap & listmap);
140  std::unique_ptr<TH1F> Cosmics2017(fnex::MetaData const & md);
141  std::unique_ptr<TH1F> Cosmics2018(fnex::MetaData const& md,
142  TFile & tf); ///< Get the nue 2018 CAFAna cosmic histogram
143 
145  std::vector<std::string> fFNEXEventLabels; ///< Labels in input files holding FNEX Events
146  std::vector<std::string> fTreeDirectories; ///< directory holding the input trees
147  TRandom3 fRandom; ///< Random number generator to use creating fake data lists
148  EnergyHistMap fNeutrinoEnergy; ///< neutrino energy
149  ExposureMap fFakeExposure; ///< POT in 1e12 of an exposure to fake up
150  fnex::InputPoint fFakeDataPoint; ///< the fake data input point
151  fnex::InputPoint fInitialGuess; ///< the fake data input point
152  std::map<long, float> fEventCaps; ///< maximum fraction of events to use from each combination
153  ///< of detector, filetype and epoch
154  bool fPoissonFakeData; ///< make the fake data Poisson distributed
155  bool fUseCosmicHists; ///< if true, use histograms to make cosmic background
156  ///< if false, use eventlisttrees of cosmic data
157  bool fUseEventId; ///< use if you need access to run/subrun/event/etc
158  bool fSumSubEpochs; ///< do we want to sum all sub epochs into a single one
159  std::unique_ptr<Correlations> fCorrelations; ///< For correlating shifts in fake data. Uses a single
160  ///< set of correlations here, will have to be a bit
161  ///< fancier for the joint fit
162  std::string fNuMuCosmicHistFile; ///< file containing the cosmic background histograms
163  std::string fNuECosmicHistFile; ///< file containing the cosmic background histograms
164  std::string fNuEDataHistFile; ///< file containing the data live time for cosmic normalization
165  /* std::string fCalibFHCHistFile; ///< file containing calibration systematic histograms for FHC */
166  /* std::string fCalibRHCHistFile; ///< file containing calibration systematic histograms for RHC */
167  std::string fCalibHistFile; ///< file containing calibration systematic histograms
168  double fTotalFDDataPOTFHC; ///< total FD data POT FHC
169  double fTotalFDDataPOTRHC; ///< total FD data POT RHC
170  double fTotalNDDataPOTFHC; ///< total ND data POT FHC
171  double fTotalNDDataPOTRHC; ///< total ND data POT RHC
172  std::map<std::string, fnex::SpillSummary> fFDPOTSum; ///< data POT per epoch in the FD
173  std::set<int> fPeriodsToUse; ///< which periods to use in the analysis
174  std::map<novadaq::cnv::DetId, std::set<fnex::SelectionType_t>> fSelectionsToUse; ///< which selection types to use?
175  std::map<fnex::SelectionType_t, double> fMaxNuEnergy; ///< maximum neutrino energy to go into the lists
176  std::string fAnalysisYear; ///< analysis year, "2016" for SA and "2017" for TA
177  bool fMakeNDPeripheral; ///< configuration to decide if we should make the
178  ///< ND peripheral eventlist or not
179  bool fLoadAllEventLists; ///< force all event lists to be loaded
180  float fMaxEventsPerTree; ///< maximum number of events to use per tree
181  bool fUseExtrapolation; ///< are we extrapolating or using covariance matrices
182  };
183 
184 }
185 
186 #endif /* EventListManipulator_hpp */
float fMaxEventsPerTree
maximum number of events to use per tree
std::string fCalibHistFile
file containing calibration systematic histograms
std::string fNuECosmicHistFile
file containing the cosmic background histograms
std::string fNuMuCosmicHistFile
file containing the cosmic background histograms
EnergyHistMap fNeutrinoEnergy
neutrino energy
double fTotalNDDataPOTFHC
total ND data POT FHC
const char * p
Definition: xmltok.h:285
const Color_t kMC
std::string fAnalysisYear
analysis year, "2016" for SA and "2017" for TA
Float_t ss
Definition: plot.C:24
bool fSumSubEpochs
do we want to sum all sub epochs into a single one
std::map< fnex::MetaData, fnex::EventList > EventListMap
Definition: Event.h:186
Create a list of fnex::Events to be used in fits.
Timing fit.
TRandom3 fRandom
Random number generator to use creating fake data lists.
std::map< fnex::SelectionType_t, double > fMaxNuEnergy
maximum neutrino energy to go into the lists
double fTotalFDDataPOTRHC
total FD data POT RHC
Double_t scale
Definition: plot.C:25
std::unordered_map< fnex::MetaData, std::vector< TH1F * >, fnex::MetaDataHasher > EnergyHistMap
art::ServiceHandle< art::TFileService > fTFS
TFileService.
double fTotalFDDataPOTFHC
total FD data POT FHC
std::map< long, float > fEventCaps
bool fPoissonFakeData
make the fake data Poisson distributed
enum fnex::dataMC_type DataMC_t
fnex::InputPoint fFakeDataPoint
the fake data input point
fnex::InputPoint fInitialGuess
the fake data input point
std::set< int > fPeriodsToUse
which periods to use in the analysis
bool fUseEventId
use if you need access to run/subrun/event/etc
std::string fNuEDataHistFile
file containing the data live time for cosmic normalization
ExposureMap fFakeExposure
POT in 1e12 of an exposure to fake up.
double fTotalNDDataPOTRHC
total ND data POT RHC
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
std::unique_ptr< Correlations > fCorrelations
std::string dirName
Definition: PlotSpectra.h:47
std::unordered_map< fnex::MetaData, double, fnex::MetaDataHasher > ExposureMap
std::map< std::string, fnex::SpillSummary > fFDPOTSum
data POT per epoch in the FD
std::vector< std::string > fFNEXEventLabels
Labels in input files holding FNEX Events.
bool fLoadAllEventLists
force all event lists to be loaded
std::vector< std::string > fTreeDirectories
directory holding the input trees
bool fUseExtrapolation
are we extrapolating or using covariance matrices
TODO.
std::map< novadaq::cnv::DetId, std::set< fnex::SelectionType_t > > fSelectionsToUse
which selection types to use?
fnex::EventListMap DeserializeMC()