CVNMapper_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // \file CVNMapper_module.cc
3 // \brief Producer module for creating CVN PixelMap objects
4 // \author Dominick Rocco - rocco@physics.umn.edu
5 ////////////////////////////////////////////////////////////////////////
6 
7 // C/C++ includes
8 #include <iostream>
9 #include <sstream>
10 
11 // ROOT includes
12 #include "TTree.h"
13 #include "TH2F.h"
14 
15 // Framework includes
22 #include "fhiclcpp/ParameterSet.h"
27 
28 // NOvASoft includes
29 #include "RecoBase/CellHit.h"
30 #include "RecoBase/Cluster.h"
31 #include "RecoBase/FilterList.h"
32 
33 #include "Utilities/AssociationUtil.h"
37 
38 #include "Calibrator/Calibrator.h"
39 #include "MCCheater/BackTracker.h"
40 
42 #include "CVN/func/PixelMap.h"
43 #include "CVN/func/TrainingData.h"
44 
45 
46 
47 
48 namespace cvn {
49 
50  class CVNMapper : public art::EDProducer {
51  public:
52  explicit CVNMapper(fhicl::ParameterSet const& pset);
53  ~CVNMapper();
54 
55  void produce(art::Event& evt);
56  void beginJob();
57  void endJob();
58 
59 
60 
61  private:
62  /// Module lablel for input clusters
64 
65  /// Module lablel for hits
67 
68  /// Module lablel for input prongs
70 
71  /// Instance lablel for input 3D prongs
73 
74  /// Instance lablel for input 2D prongs
76 
77  /// Instance lablel for event pixelmaps
79 
80  /// Instance lablel for cluster pixelmaps
82 
83  /// Instance lablel for prong pixelmaps
85 
86  /// Option to save maps for prongs
87  bool fMapProngs;
88 
89  /// Option to save maps for events
90  bool fMapEvents;
91 
92  /// Check rb::IsFiltered?
94  std::vector<std::string> fPreselectionLabels;
95 
96  /// Minimum number of hits for cluster to be converted to pixel map
97  unsigned short fMinClusterHits;
98 
99  /// Width of pixel map in cells
100  unsigned short fCellWidth;
101 
102  /// Length of pixel map in planes
103  unsigned short fPlaneLength;
104 
105  /// Maximum gap in planes at front of cluster to prevent pruning of upstream
106  /// hits
107  unsigned int fMaxPlaneGap;
108 
109  /// true=GeV, false=PECorr
110  bool fUseGeV;
111 
112  /// Use hits (1/0) instead of energy in map
113  bool fHits;
114 
115  /// Use time instead of energy in map
116  bool fTime;
117 
118  /// Check if you want to use the full-ND
120 
121  /// Use FullSlice mode in PixelMapProducer
123 
124  /// Skip filling neutrino hit truth information
126 
127  /// Only create PE pixel maps, no other types (less time/memory)
128  bool fPEOnly;
129 
130  /// PixelMapProducer does the work for us
132 
133  };
134 
135 
136 
137  //.......................................................................
139  fClusterToken(consumes<std::vector<rb::Cluster>>(pset.get<std::string>("ClusterLabel"))),
140  fHitLabel (pset.get<std::string> ("HitLabel")),
141  fProngModLabel (pset.get<std::string> ("ProngModLabel")),
142  fProng3DLabel (pset.get<std::string> ("Prong3DLabel")),
143  fProng2DLabel (pset.get<std::string> ("Prong2DLabel")),
144  fEventPMLabel (pset.get<std::string> ("EventPMLabel")),
145  fClusterPMLabel(pset.get<std::string> ("ClusterPMLabel")),
146  fProngPMLabel (pset.get<std::string> ("ProngPMLabel")),
147  fMapProngs (pset.get<bool> ("MapProngs")),
148  fMapEvents (pset.get<bool> ("MapEvents")),
149  fObeyPreselection(pset.get<bool> ("ObeyPreselection")),
150  fPreselectionLabels (pset.get<std::vector<std::string>>
151  ("PreselectionLabels")),
152  fMinClusterHits(pset.get<unsigned short> ("MinClusterHits")),
153  fCellWidth (pset.get<unsigned short> ("CellWidth")),
154  fPlaneLength (pset.get<unsigned short> ("PlaneLength")),
155  fMaxPlaneGap (pset.get<unsigned int> ("MaxPlaneGap")),
156  fUseGeV (pset.get<bool> ("UseGeV")),
157  fHits (pset.get<bool> ("Hits")),
158  fTime (pset.get<bool> ("Time")),
159  fUseFullND (pset.get<bool> ("UseFullND")),
160  fFullSlice (pset.get<bool> ("FullSlice")),
161  fFillHitNu (pset.get<bool> ("FillHitNu")),
162  fPEOnly (pset.get<bool> ("PEOnly")),
164  {
165 
166  produces< std::vector<cvn::PixelMap> >(fEventPMLabel);
167  produces< std::vector<cvn::PixelMap> >(fClusterPMLabel);
168  produces< std::vector<cvn::PixelMap> >(fProngPMLabel);
169  produces< art::Assns<cvn::PixelMap, rb::Cluster> >();
170  produces< art::Assns<cvn::PixelMap, rb::Prong> >();
171  }
172 
173  //......................................................................
175  {
176  //======================================================================
177  // Clean up any memory allocated by your module
178  //======================================================================
179  }
180 
181  //......................................................................
183  { }
184 
185  //......................................................................
187  {
188  }
189 
190  //......................................................................
192  {
193 
194  //Declaring containers for things to be stored in event
195  std::unique_ptr< std::vector<PixelMap> >
196  evt_pmCol(new std::vector<PixelMap>);
197  std::unique_ptr< std::vector<PixelMap> >
198  pmCol(new std::vector<PixelMap>);
199  std::unique_ptr< std::vector<PixelMap> >
200  prong_pmCol(new std::vector<PixelMap>);
201  std::unique_ptr< art::Assns<PixelMap, rb::Cluster> >
203  std::unique_ptr< art::Assns<PixelMap, rb::Prong> >
204  prong_assoc(new art::Assns<PixelMap,
205  rb::Prong>);
206 
207  if ( fMapEvents ){
208 
210 
211  // Get cellhits
213  evt.getByLabel(fHitLabel, hitcol);
214 
215 
216  std::vector<art::Ptr<rb::CellHit > > hitlist;
217  hitlist.reserve(hitcol->size());
218  for(unsigned int i = 0; i < hitcol->size(); ++i){
219  art::Ptr<rb::CellHit> hit(hitcol, i);
220  hitlist.push_back(hit);
221  }
222 
223  rb::SortByTime(hitlist);
224 
225  // Make evt cluster
226  rb::Cluster evtcluster;
227  for(unsigned int i = 0; i < hitlist.size(); ++i)
228  evtcluster.Add(hitlist[i]);
229 
230  PixelMap evtpm = fProducer.CreateMap(evtcluster);
231  //Boundary evtbound = evtpm.Bound();
232 
233  evt_pmCol->push_back(evtpm);
234 
235  } // end map events
236 
237 
239  evt.getByToken(fClusterToken, sliceHandle);
240 
241  if(sliceHandle->empty()){
242  mf::LogWarning ("No Slices")<<"No Slices in the input file";
243  return;
244  }
245 
247  for(unsigned int i = 0; i<sliceHandle->size();++i){
248  art::Ptr<rb::Cluster> clust(sliceHandle,i);
249  sliceCol.push_back(clust);
250  }
251 
252 
253 
254  for(unsigned int iSlice = 0; iSlice < sliceCol.size(); ++iSlice)
255  {
256 
257  if (sliceCol[iSlice]->IsNoise() ||
258  sliceCol[iSlice]->NCell() < fMinClusterHits)
259  continue;
260  // Skip if we're obeying preselection
261  if(fObeyPreselection && rb::IsFiltered(evt, sliceHandle,iSlice,
263  continue;
264  PixelMap pm = fProducer.CreateMap(*sliceCol[iSlice]);
265  Boundary bound = pm.Bound();
266 
267  pmCol->push_back(pm);
268  util::CreateAssn(*this, evt, *(pmCol.get()),
269  sliceCol[iSlice], *(assoc.get()), UINT_MAX,
271 
272  // Option to save prong level pixel maps
273  if ( fMapProngs ){
274 
275  art::FindManyP<rb::Prong> fmProng3D(sliceHandle, evt,
277  art::FindManyP<rb::Prong> fmProng2D(sliceHandle, evt,
279 
280  std::vector<art::Ptr<rb::Prong>> prongs3D;
281  std::vector<art::Ptr<rb::Prong>> prongs2D;
282 
283  if( fmProng2D.isValid() ) prongs2D = fmProng2D.at(iSlice);
284  if( fmProng3D.isValid() ) prongs3D = fmProng3D.at(iSlice);
285  else continue;
286 
287  for( unsigned int iProng = 0; iProng < prongs3D.size(); ++iProng ){
288 
289  // make prong maps with the same boundary as the slice maps
290  PixelMap new_pm = fProducer.CreateMapGivenBoundary(*prongs3D[iProng],
291  bound);
292 
293  prong_pmCol->push_back(new_pm);
294  util::CreateAssn(*this, evt, *(prong_pmCol.get()),
295  prongs3D[iProng], *(prong_assoc.get()), UINT_MAX, fProngPMLabel);
296  }// 3D prongs
297 
298  for( unsigned int iProng2 = 0; iProng2 < prongs2D.size(); ++iProng2 ){
299 
300  // make prong maps with the same boundary as the slice maps
301  PixelMap new_pm = fProducer.CreateMapGivenBoundary(*prongs2D[iProng2],
302  bound);
303 
304  prong_pmCol->push_back(new_pm);
305  util::CreateAssn(*this, evt, *(prong_pmCol.get()),
306  prongs2D[iProng2], *(prong_assoc.get()), UINT_MAX, fProngPMLabel);
307  }// 2D prongs
308 
309  }// MapProngs
310 
311  }
312  evt.put(std::move(evt_pmCol), fEventPMLabel);
313  evt.put(std::move(pmCol), fClusterPMLabel);
314  evt.put(std::move(prong_pmCol), fProngPMLabel);
315  evt.put(std::move(assoc));
316  evt.put(std::move(prong_assoc));
317  // evt.put(std::move(prong_assoc),fProng3DLabel);
318 
319  }
320 
321  //----------------------------------------------------------------------
322 
323 
324 
326 } // end namespace cvn
327 ////////////////////////////////////////////////////////////////////////
bool fPEOnly
Only create PE pixel maps, no other types (less time/memory)
bool fUseFullND
Check if you want to use the full-ND.
bool fFullSlice
Use FullSlice mode in PixelMapProducer.
bool fUseGeV
true=GeV, false=PECorr
unsigned short fCellWidth
Width of pixel map in cells.
back track the reconstruction to the simulation
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< std::string > fPreselectionLabels
unsigned int fMaxPlaneGap
const art::ProductToken< std::vector< rb::Cluster > > fClusterToken
Module lablel for input clusters.
bool fMapProngs
Option to save maps for prongs.
PixelMapProducer fProducer
PixelMapProducer does the work for us.
A collection of associated CellHits.
Definition: Cluster.h:47
bool fFillHitNu
Skip filling neutrino hit truth information.
void SortByTime(std::vector< art::Ptr< rb::CellHit > > &c)
Sort c in time order (earliest to latest).
Definition: CellHit.cxx:134
DEFINE_ART_MODULE(TestTMapFile)
PixelMap for CVN.
Defines an enumeration for prong classification.
Particle class.
CVNMapper(fhicl::ParameterSet const &pset)
virtual void Add(const art::Ptr< rb::CellHit > &cell, double weight=1)
Definition: Cluster.cxx:84
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
std::string fProng3DLabel
Instance lablel for input 3D prongs.
unsigned short fMinClusterHits
Minimum number of hits for cluster to be converted to pixel map.
void push_back(Ptr< U > const &p)
Definition: PtrVector.h:441
int evt
bool IsFiltered(const art::Event &evt, art::Ptr< T > x, const std::vector< std::string > &labels)
Is this Ptr marked "filtered out"?
Definition: FilterList.h:96
std::string fProngModLabel
Module lablel for input prongs.
bool fObeyPreselection
Check rb::IsFiltered?
Boundary Bound() const
Map boundary.
Definition: PixelMap.h:51
PixelMap CreateMapGivenBoundary(const rb::Cluster &cluster, const Boundary &bound)
Perform a "2 point" Hough transform on a collection of hits.
bool fTime
Use time instead of energy in map.
size_type size() const
Definition: PtrVector.h:308
std::string fClusterPMLabel
Instance lablel for cluster pixelmaps.
A Cluster with defined start position and direction.
Definition: Prong.h:19
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
bool fHits
Use hits (1/0) instead of energy in map.
Definition: structs.h:12
PixelMap, basic input to CVN neural net.
Definition: PixelMap.h:23
std::string fEventPMLabel
Instance lablel for event pixelmaps.
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
PixelMapProducer for CVN.
bool fMapEvents
Option to save maps for events.
std::string fProng2DLabel
Instance lablel for input 2D prongs.
PixelMap CreateMap(const rb::Cluster &slice)
bool getByToken(ProductToken< PROD > const &token, Handle< PROD > &result) const
Definition: DataViewImpl.h:387
std::string fHitLabel
Module lablel for hits.
Producer algorithm for PixelMap, input to CVN neural net.
unsigned short fPlaneLength
Length of pixel map in planes.
ProductToken< T > consumes(InputTag const &)
std::string fProngPMLabel
Instance lablel for prong pixelmaps.
void produce(art::Event &evt)
enum BeamMode string