MakeMatches_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // \file MakeMatches_module.cc
3 // \brief Get the main info from the list of matches
4 // \author Bruno Zamorano - B.Zamorano@sussex.ac.uk
5 ////////////////////////////////////////////////////////////////////////
6 
7 #include "LEM/PIDInput.h"
8 
9 #include "LEM/LEMInput.h"
10 #include "LEM/func/FindMatches.h" // For num matches constant
12 #include "LEM/func/MatchList.h"
13 
14 #include "RecoBase/CellHit.h"
15 #include "RecoBase/Cluster.h"
16 #include "nusimdata/SimulationBase/MCTruth.h" // mode enum
17 #include "Utilities/AssociationUtil.h"
19 #include "Utilities/func/MathUtil.h"
20 
21 // Framework includes
30 #include "fhiclcpp/ParameterSet.h"
32 
33 namespace lem
34 {
35  /// Calculate final %PID variables from match details
37  {
38  public:
39  explicit MakeMatches(const fhicl::ParameterSet& pset);
40  ~MakeMatches();
41 
42  virtual void beginJob();
43  virtual void beginRun(art::Run& run);
44  virtual void produce(art::Event& evt);
45  virtual void reconfigure(const fhicl::ParameterSet& pset);
46 
47  protected:
51  };
52 
53  //.......................................................................
55  {
56  reconfigure(pset);
57 
58  produces<std::vector<lem::PIDInput>>();
59  produces<art::Assns<lem::PIDInput, rb::Cluster>>();
60  }
61 
62  //......................................................................
64  {
65  }
66 
67  //......................................................................
69  {
70  fTrimMatchLists = pset.get<bool>("TrimMatchLists");
71  fMatchesLabel = pset.get<std::string>("MatchesLabel");
72  fSummarizeLabel = pset.get<std::string>("SummarizeLabel");
73  }
74 
75  //......................................................................
77  {
78  }
79 
80  //......................................................................
82  {
84  run.getByLabel(fMatchesLabel, libsum);
85 
86  assert(!libsum.failedToGet());
87  }
88 
89  //......................................................................
91  {
92  std::unique_ptr<std::vector<lem::PIDInput> > pidinputcol(new std::vector<lem::PIDInput>);
93  std::unique_ptr<art::Assns<lem::PIDInput, rb::Cluster>> assns(new art::Assns<lem::PIDInput, rb::Cluster>);
94 
96  evt.getByLabel(fMatchesLabel, matchlists);
97 
99  evt.getByLabel(fSummarizeLabel, inputs);
100 
101  assert(inputs->size() == matchlists->size());
102 
104 
105  const unsigned int matchMax = matchlists->size();
106  for(unsigned int matchIdx = 0; matchIdx < matchMax; ++matchIdx){
107  MatchList matchlist = (*matchlists)[matchIdx];
108 
109  // Get all the slices associated with this match list
110  std::vector<art::Ptr<rb::Cluster> > slices = fmt.at(matchIdx);
111  // Associated slices can be empty when we're running over lemsum files,
112  // where the slices have been stripped out. In that case, don't make
113  // associations, LEMAssociator will sort it out later.
114  assert(slices.empty() || slices.size() == 1);
115 
116  std::vector<MatchSummary> matches, enrichedMatches;
117  for(unsigned int i = 0; i < matchlist.matches.size(); ++i){
118  if(matchlist.matches[i].enrich){
119  enrichedMatches.push_back(matchlist.matches[i]);
120  }
121  else{
122  matches.push_back(matchlist.matches[i]);
123  }
124  }
125 
126  if(matches.empty()){
127  lem::PIDInput pidinput;
128  pidinputcol ->push_back(pidinput);
129  if(!slices.empty())
130  util::CreateAssn(*this, evt, *pidinputcol, slices[0], *assns);
131  continue;
132  }
133 
134  lem::PIDInput pidinput;
135  pidinput.matchList = matchlist;
136  pidinput.matches = matches;
137  pidinput.enrichedMatches = enrichedMatches;
138 
139  pidinputcol->push_back(pidinput);
140 
141  if(!slices.empty()){
142  util::CreateAssn(*this, evt, *pidinputcol, slices[0], *assns);
143  }
144  } // end for matchIdx
145 
146  evt.put(std::move(pidinputcol));
147  evt.put(std::move(assns));
148  }
149 
151 
152 } // end namespace lem
153 ////////////////////////////////////////////////////////////////////////
MakeMatches(const fhicl::ParameterSet &pset)
static bool CreateAssn(art::EDProducer const &prod, art::Event &evt, std::vector< T > &a, art::Ptr< U > b, art::Assns< T, U > &assn, size_t indx=UINT_MAX, std::string const &instance=std::string())
Create a 1 to 1 association between a new product and one already in the event.
std::vector< MatchSummary > matches
Definition: MatchList.h:24
lem::MatchList matchList
Definition: PIDInput.h:26
std::vector< lem::MatchSummary > enrichedMatches
Definition: PIDInput.h:28
Calculate final PID variables from match details.
Attach MatchList and other useful stuff.
Definition: PIDInput.h:20
virtual void beginJob()
DEFINE_ART_MODULE(TestTMapFile)
std::string fSummarizeLabel
Definition: Run.h:31
Collection of MatchSummary objects.
PID
Definition: FillPIDs.h:13
Core of the LEM match-finding algorithm.
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
Details of the library LEM matches were made against.
virtual void produce(art::Event &evt)
Collection of MatchSummary objects.
Definition: MatchList.h:17
T get(std::string const &key) const
Definition: ParameterSet.h:231
virtual void beginRun(art::Run &run)
Definition: run.py:1
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
std::vector< lem::MatchSummary > matches
Definition: PIDInput.h:27
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
assert(nhit_max >=nhit_nbins)
bool failedToGet() const
Definition: Handle.h:196
virtual void reconfigure(const fhicl::ParameterSet &pset)
std::string fMatchesLabel