CVNMapperProtoDUNE_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // \file CVNMapperProtoDUNE_module.cc
3 // \brief Producer module for creating CVN PixelMaps for individual
4 // particles in ProtoDUNE
5 // \author Leigh Whitehead - leigh.howard.whitehead@cern.ch
6 ////////////////////////////////////////////////////////////////////////
7 
8 // C/C++ includes
9 #include <iostream>
10 #include <sstream>
11 
12 // Framework includes
16 #include "art_root_io/TFileDirectory.h"
17 #include "art_root_io/TFileService.h"
19 #include "fhiclcpp/ParameterSet.h"
23 #include "canvas/Persistency/Common/FindManyP.h"
24 
25 // LArSoft includes
29 
33 
35 
36 namespace cvn {
37 
39  public:
40  explicit CVNMapperProtoDUNE(fhicl::ParameterSet const& pset);
42 
43  void produce(art::Event& evt);
44  void beginJob();
45  void endJob();
46 
47 
48 
49  private:
50  /// Module label for input hits
52 
53  /// Module label for input particles
55 
56  /// Module label for input tracks
58 
59  /// Module label for input showers
61 
62  /// Instance lablel for cluster pixelmaps
64 
65  /// Minimum number of hits for cluster to be converted to pixel map
66  unsigned short fMinClusterHits;
67 
68  /// Width of pixel map in tdcs
69  unsigned short fTdcWidth;
70 
71  /// Length of pixel map in wires
72  unsigned short fWireLength;
73 
74  /// Length of pixel map in wires
76 
77  /// Maximum gap in wires at front of cluster to prevent pruning of upstream
78  /// hits
79  //unsigned int fMaxWireGap;
80 
81  /// Use unwrapped pixel maps?
82  // 0 means no unwrap, 1 means unwrap in wire, 2 means unwrap in wire and time
83  unsigned short fUnwrappedPixelMap;
84 
85  /// Track length cut
87 
88  /// Use the whole event instead of each track and shower
90 
91  /// For protoDUNE vertex finding, we only want the beam slice
93 
94  /// PixelMapProducer does the work for us
96 
97  };
98 
99 
100 
101  //.......................................................................
103  fHitsModuleLabel (pset.get<std::string> ("HitsModuleLabel")),
104  fParticleModuleLabel (pset.get<std::string> ("ParticleModuleLabel")),
105  fTrackLabel (pset.get<std::string> ("TrackLabel")),
106  fShowerLabel (pset.get<std::string> ("ShowerLabel")),
107  fClusterPMLabel(pset.get<std::string> ("ClusterPMLabel")),
108  fMinClusterHits(pset.get<unsigned short> ("MinClusterHits")),
109  fTdcWidth (pset.get<unsigned short> ("TdcWidth")),
110  fWireLength (pset.get<unsigned short> ("WireLength")),
111  fTimeResolution (pset.get<unsigned short> ("TimeResolution")),
112  fUnwrappedPixelMap(pset.get<unsigned short> ("UnwrappedPixelMap")),
113  fTrackLengthCut(pset.get<unsigned short> ("TrackLengthCut")),
114  fUseWholeEvent(pset.get<bool> ("UseWholeEvent")),
115  fUseBeamSliceOnly(pset.get<bool> ("UseBeamSliceOnly")),
117  {
118 
119  produces< std::vector<cvn::PixelMap> >(fClusterPMLabel);
120 
121  }
122 
123  //......................................................................
125  {
126  //======================================================================
127  // Clean up any memory allocated by your module
128  //======================================================================
129  }
130 
131  //......................................................................
133  { }
134 
135  //......................................................................
137  {
138  }
139 
140  //......................................................................
142  {
143 
144  //Declaring containers for things to be stored in event
145  std::unique_ptr< std::vector<cvn::PixelMap> > pmCol(new std::vector<cvn::PixelMap>);
146 
147  // Use unwrapped pixel maps if requested
148  // For protoDUNE unwrapped if > 0
151 
152  // Use the whole event just like we would for the FD
153  auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(evt);
154  if(fUseWholeEvent){
155  std::vector< art::Ptr< recob::Hit > > hitlist;
156  auto hitListHandle = evt.getHandle< std::vector< recob::Hit > >(fHitsModuleLabel);
157  if (hitListHandle)
158  art::fill_ptr_vector(hitlist, hitListHandle);
159  unsigned short nhits = hitlist.size();
160 
161  std::cout << "nhits: " << nhits << std::endl; // REMOVE
162 
163  if(nhits>fMinClusterHits){
164  PixelMap pm = fProducer.CreateMap(detProp, hitlist);
165  pmCol->push_back(pm);
166  }
167  }
168  else if(fUseBeamSliceOnly){
169  // We want to make a pixel map for just APA3. We can pad out to 500 pixels in the wire number
170  // The best way to do this is to get the Pandora beam slice
171  cvn::CVNProtoDUNEUtils pfpUtil;
172  const unsigned int beamSlice = pfpUtil.GetBeamSlice(evt,fParticleModuleLabel);
173  if(beamSlice < 500){
174  const std::vector<const recob::Hit*> sliceHits = pfpUtil.GetRecoSliceHits(beamSlice,evt,fParticleModuleLabel);
175 
176  PixelMap pm = fProducer.CreateMap(detProp, sliceHits);
177  pmCol->push_back(pm);
178  }
179  }
180  else{
181  // Get the list of tracks and showers and their associated hits
182  auto allTracks=evt.getValidHandle<std::vector<recob::Track> >(fTrackLabel);
183  const art::FindManyP<recob::Hit> findTrackHits(allTracks,evt,fTrackLabel);
184 
185  auto allShowers=evt.getValidHandle<std::vector<recob::Shower> >(fShowerLabel);
186  const art::FindManyP<recob::Hit> findShowerHits(allShowers,evt,fShowerLabel);
187 
188  std::cout << "Event contains " << allTracks->size() << " tracks and " << allShowers->size() << " showers" << std::endl;
189 
190  // Iterate over the tracks and showers making a PixelMap for each
191  for(unsigned int t = 0; t < allTracks->size(); ++t){
192 
193  std::vector<art::Ptr<recob::Hit> > trackHits = findTrackHits.at(t);
194  if(trackHits.size()>fMinClusterHits && (*allTracks)[t].Length() > fTrackLengthCut){
195  // std::cout << "Making PixelMap number " << pmCol->size() + 1 << " with " << trackHits.size() << " hits" << std::endl;
196 
197  PixelMap pm = fProducer.CreateMap(detProp, trackHits);
198  pmCol->push_back(pm);
199  }
200 
201  }
202 
203  for(unsigned int s = 0; s < allShowers->size(); ++s){
204 
205  std::vector<art::Ptr<recob::Hit> > showerHits = findShowerHits.at(s);
206  if(showerHits.size()>fMinClusterHits){
207  PixelMap pm = fProducer.CreateMap(detProp, showerHits);
208  pmCol->push_back(pm);
209  }
210  }
211  }
212 
213  std::cout << "Made " << pmCol->size() << " pixel maps for this event" << std::endl;
214 
215  evt.put(std::move(pmCol), fClusterPMLabel);
216 
217  }
218 
219  //----------------------------------------------------------------------
220 
221 
222 
224 } // end namespace cvn
225 ////////////////////////////////////////////////////////////////////////
std::string fTrackLabel
Module label for input tracks.
unsigned short fTdcWidth
Width of pixel map in tdcs.
PixelMapProducer fProducer
PixelMapProducer does the work for us.
Handle< PROD > getHandle(SelectorBase const &) const
Definition: DataViewImpl.h:382
std::string string
Definition: nybbler.cc:12
bool fUseWholeEvent
Use the whole event instead of each track and shower.
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
unsigned short fMinClusterHits
Minimum number of hits for cluster to be converted to pixel map.
uint size() const
Definition: qcstring.h:201
PixelMap for CVN.
Utility class for truth labels.
double fTimeResolution
Length of pixel map in wires.
CVNMapperProtoDUNE(fhicl::ParameterSet const &pset)
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
std::string fClusterPMLabel
Instance lablel for cluster pixelmaps.
void SetUnwrapped(unsigned short unwrap)
def move(depos, offset)
Definition: depos.py:107
const std::vector< const recob::Hit * > GetRecoSliceHits(const recob::Slice &slice, art::Event const &evt, const std::string sliceModule) const
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
float fTrackLengthCut
Track length cut.
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: DataViewImpl.h:686
bool fUseBeamSliceOnly
For protoDUNE vertex finding, we only want the beam slice.
std::string fParticleModuleLabel
Module label for input particles.
unsigned short fUnwrappedPixelMap
Use unwrapped pixel maps?
Declaration of signal hit object.
std::string fShowerLabel
Module label for input showers.
unsigned short GetBeamSlice(art::Event const &evt, const std::string particleLabel) const
Try to get the slice tagged as beam. Returns 9999 if no beam slice was found.
PixelMap, basic input to CVN neural net.
Definition: PixelMap.h:22
PixelMapProducer for CVN.
Provides recob::Track data product.
unsigned short fWireLength
Length of pixel map in wires.
TCEvent evt
Definition: DataStructs.cxx:7
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:297
Producer algorithm for PixelMap, input to CVN neural net.
static QCString * s
Definition: config.cpp:1042
QTextStream & endl(QTextStream &s)
PixelMap CreateMap(detinfo::DetectorPropertiesData const &detProp, const std::vector< art::Ptr< recob::Hit > > &slice)
std::string fHitsModuleLabel
Module label for input hits.