CMFCappedEventList_module.cc
Go to the documentation of this file.
1 //
2 // Created by Brian Rebel on 12/17/20.
3 //
4 // module to create a root file with a capped event list
5 // for faster grid jobs
6 //
7 // Spectra making module
8 
9 // Framework includes
13 #include "art_root_io/TFileService.h"
14 #include "art_root_io/TFileDirectory.h"
15 #include "fhiclcpp/ParameterSet.h"
17 
18 // CMF includes
24 
25 namespace cmf {
27  public:
28  explicit CMFCappedEventList(fhicl::ParameterSet const& pset);
29  ~CMFCappedEventList() = default;
30 
31  // Required fucntions
32  void analyze(art::Event const& evt) override;
33  void endJob() override;
34 
35  void reconfigure(fhicl::ParameterSet const& pset);
36 
37  private:
38 
39  void Serialize(art::TFileDirectory & dir,
40  cmf::EventListColl const& lists,
41  TTree* mdTree,
42  cmf::MetaData & md,
44 
45  // Member data
46  std::map<cmf::DetType_t, fhicl::ParameterSet> fManipulatorParameters; ///< event list manipulator parameters
48  };
49 
50  //----------------------------------------------------------------//
52  : EDAnalyzer(pset)
53  {
54  this->reconfigure(pset);
55  }
56 
57  //----------------------------------------------------------------//
59  {
62 
63  for(auto const& det : cmf::SelectionUtility::Instance()->DetectorsToUse())
64  fManipulatorParameters.emplace(det, pset.get< fhicl::ParameterSet >(cmf::cDetType_Strings[det] + "EventListManipulator"));
65  }
66 
67  //----------------------------------------------------------------//
69  {
70  }
71 
72  //----------------------------------------------------------------//
74  {
75  // make a directory in the output file, and the act of making it puts us
76  // into that directory of the file
78  auto dir = tfs->mkdir("capped");
79 
80  // first the metadata tree
81  // leave this pointer dangling because the fileService created & manages it
84 
85  TTree *metadataTree = dir.make<TTree>( "metadata", "Event list metadata" );
86  metadataTree->Branch("metadata", &md);
87  metadataTree->Branch("spillsummary", &ss);
88 
89  // TODO: we may want to have a different max events per tree for data
90  // than 1.75e5
91  std::vector<cmf::DataMC_t> dataType({cmf::kMC, cmf::kData});
92  for(auto const& manipPars : fManipulatorParameters){
93  for(auto const& dt : dataType){
94  // get the lists of events from the TTree and put them into a map
95  // of event lists
96  cmf::EventListManipulator manipulator(manipPars.second);
97  cmf::EventListColl eventLists;
98 
99  manipulator.Deserialize(eventLists, dt, std::set<cmf::DetType_t>({manipPars.first}));
100 
101  this->Serialize(dir, eventLists, metadataTree, md, ss);
102  }
103  }
104  }
105 
106  //----------------------------------------------------------------//
107  void CMFCappedEventList::Serialize(art::TFileDirectory & dir,
108  cmf::EventListColl const& lists,
109  TTree* mdTree,
110  cmf::MetaData & md,
112  {
113  for(auto const& itr : lists){
114 
115  md = itr.ListMetaData();
116  ss = itr.ListSpillSummary();
117 
118  mdTree->Fill();
119 
120  // same principle as above for the event tree
121  TTree *eventTree = dir.make<TTree>(md.ToString().c_str(), "CovarianceMatrixFit event records");
122 
123  cmf::SerializeEvents(eventTree,
124  md,
125  itr);
126  }
127  }
128 
129 }
130 
132 
void reconfigure(fhicl::ParameterSet const &pset)
const std::vector< std::string > cDetType_Strings({"UnknownDet","NearDet","FarDet","MINOSNear","MINOSFar","AllDetectors"})
Float_t ss
Definition: plot.C:24
static SelectionUtility * Instance()
void Serialize(art::TFileDirectory &dir, cmf::EventListColl const &lists, TTree *mdTree, cmf::MetaData &md, cmf::SpillSummary &ss)
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:27
DEFINE_ART_MODULE(TestTMapFile)
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}))
void analyze(art::Event const &evt) override
Definition: Cand.cxx:23
void SerializeEvents(TTree *eventTree, cmf::MetaData const &md, cmf::EventList const &events)
Definition: Event.cxx:55
std::map< cmf::DetType_t, fhicl::ParameterSet > fManipulatorParameters
event list manipulator parameters
art::ServiceHandle< art::TFileService > fTFS
T get(std::string const &key) const
Definition: ParameterSet.h:231
int evt
void Initialize(fhicl::ParameterSet const &pset)
std::string ToString() const
Definition: Structs.cxx:135
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
TDirectory * dir
Definition: macro.C:5
void Initialize(fhicl::ParameterSet const &pset)
CMFCappedEventList(fhicl::ParameterSet const &pset)
static CovarianceBinUtility * Instance()