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 "TTree.h"
12 #include "TRandom3.h"
13 
17 
18 
19 namespace sumdata {
20  class POTSum;
21 }
22 
23 namespace cmf {
24 
25  struct FileExtracts{
26 
28  {}
29 
31  cmf::SpillSummary const& ss,
32  std::string const& tn,
33  double ec)
34  : metadata(md)
35  , spillSummary(ss)
36  , treeName(tn)
37  , eventCap(ec)
38  {
40  if (metadata.IsNuMuSelected()) sel = cmf::kNuMuSelection;
41  else if(metadata.IsNuESelected() ) sel = cmf::kNuESelection;
42  key = metadata.MCKey() * (metadata.DetectorKey() +
43  metadata.FileKey() +
44  metadata.BeamTypeKey() +
45  metadata.PeriodKey() +
46  metadata.InteractionKey() +
48  }
49 
50  double CappedPOT() { return spillSummary.goodPOT * eventCap; }
51  double CappedLiveTime() { return spillSummary.liveTime * eventCap; }
52  long Key() { return key; }
53  double EventCap() { return eventCap; }
54 
58  double eventCap;
59  long key;
60  };
61 
63 
64  public:
65 
66  explicit EventListManipulator(fhicl::ParameterSet const& pset);
68 
69  void reconfigure(const fhicl::ParameterSet& p);
70 
71  void Deserialize(cmf::EventListColl & eventLists,
73  std::set<cmf::DetType_t> const& detectors=std::set<cmf::DetType_t>({cmf::kNEARDET,
74  cmf::kFARDET}));
75 
76  cmf::ExposureMap const& ExposureMap() const;
77 
78  void PrintPOTSummary(cmf::ExposureMap &exposureMap);
79 
80  void PrintLivetimeSummary(cmf::ExposureMap &exposureMap);
81 
82  private:
83 
84  void SetExposures(fhicl::ParameterSet const& pset);
85 
86  void ExtractFromFile(TFile* metadataFile,
87  std::string const& dirName,
88  cmf::DataMC_t const& dataMC,
89  std::set<cmf::DetType_t> const& detectors,
90  std::vector<cmf::FileExtracts> & extractVec);
91 
92  void FillTextFile(cmf::MetaData const& md,
93  cmf::EventId & ev,
94  cmf::DataVars & dv,
95  cmf::TruthVars & tv,
96  cmf::WeightVars & wv);
97 
98  void FillEventList(TFile * eventFile,
99  std::string const& treeName,
100  double const& eventCap,
101  cmf::EventList & eventList);
102 
103  double PeriodEventCap(cmf::MetaData const& md,
104  long treeEvents);
105 
106  bool UseEventsFromMetaData(cmf::MetaData const& md,
107  cmf::DataMC_t dataMC,
108  std::set<cmf::DetType_t> const& detectors);
109 
110  void PrintExposureSummary(cmf::ExposureMap& exposureMap, bool isLivetime);
111 
112  std::vector<std::string> fCMFEventLabels; ///< Labels in input files holding CovarianceMatrixFit Events
113  std::vector<std::string> fTreeDirectories; ///< directory holding the input trees
114  TRandom3 fRandom; ///< Random number generator to use creating fake data lists
115  cmf::ExposureMap fExposure; ///< POT in 1e12 to normalise to
116  std::set<cmf::DetType_t> fDetectors; ///< which detector(s) are we loading events from
117  std::map<std::string, float> fEventCaps; ///< maximum fraction of events to use from each combination
118  ///< of detector, filetype and epoch
119  bool fUseEventId; ///< use if you need access to run/subrun/event/etc
120  std::set<long> fPeriodsToUse; ///< which periods to use in the analysis
121  std::map<cmf::SelectionType_t, double> fMaxNuEnergy; ///< maximum neutrino energy to go into the lists
122  bool fLoadAllEventLists; ///< force all event lists to be loaded
123  float fMaxEventsPerTree; ///< maximum number of events to use per tree
124  float fMinEventsPerTree; ///< minimum number of events to use per tree
125  bool fFillTextFile; ///< fills text file with selection information
126  bool fDeserializeCosmics; ///< whether or not deserialize cosmic muons
127  };
128 
129  inline cmf::ExposureMap const& cmf::EventListManipulator::ExposureMap() const { return fExposure; }
130 }
131 
132 #endif /* EventListManipulator_hpp */
std::map< cmf::MetaData, cmf::SpillSummary > ExposureMap
Definition: Structs.h:215
static long SelectionTypeKey(cmf::SelectionType_t const &st)
Definition: StaticFuncs.h:19
const char * p
Definition: xmltok.h:285
bool fFillTextFile
fills text file with selection information
Float_t ss
Definition: plot.C:24
std::vector< std::string > fCMFEventLabels
Labels in input files holding CovarianceMatrixFit Events.
std::set< long > fPeriodsToUse
which periods to use in the analysis
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
cmf::ExposureMap fExposure
POT in 1e12 to normalise to.
bool fLoadAllEventLists
force all event lists to be loaded
enum cmf::dataMC_type DataMC_t
float fMinEventsPerTree
minimum number of events to use per tree
cmf::ExposureMap const & ExposureMap() const
std::map< std::string, float > fEventCaps
bool fDeserializeCosmics
whether or not deserialize cosmic muons
cmf::SpillSummary spillSummary
Module to combine a set of results into a single file currently only does one data product type at a ...
Definition: Event.cxx:24
std::vector< cmf::EventList > EventListColl
Definition: Event.h:150
std::string dirName
Definition: PlotSpectra.h:47
TRandom3 fRandom
Random number generator to use creating fake data lists.
TODO.
FileExtracts(cmf::MetaData const &md, cmf::SpillSummary const &ss, std::string const &tn, double ec)
bool fUseEventId
use if you need access to run/subrun/event/etc
std::vector< std::string > fTreeDirectories
directory holding the input trees
enum BeamMode string