CVNCosmicMapper_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // \file CVNCosmicMapper_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 // Framework includes
18 #include "fhiclcpp/ParameterSet.h"
23 
24 // NOvASoft includes
25 #include "RecoBase/CellHit.h"
26 #include "RecoBase/Cluster.h"
27 
28 #include "Utilities/AssociationUtil.h"
29 
31 #include "CVN/func/PixelMap.h"
32 #include "CVN/func/TrainingData.h"
33 
34 
35 
36 namespace cvn {
37 
39  public:
40  explicit CVNCosmicMapper(fhicl::ParameterSet const& pset);
42 
43  void produce(art::Event& evt);
44  void beginJob();
45  void endJob();
46 
47 
48 
49  private:
50 
51  /// Read CellHits from this input
53 
54 
55 
56  /// Ratio of Cosmic pixel maps to Nu pixel maps to create
57  //unsigned short fCosmicToNuRatio;
58 
59  /// Width of pixel map in cells
60  unsigned short fCellWidth;
61 
62  /// Length of pixel map in planes
63  unsigned short fPlaneLength;
64 
65  /// Maximum gap in planes at front of cluster to prevent pruning of upstream
66  /// hits
67  unsigned int fMaxPlaneGap;
68 
69  /// Size of time window used in map
71 
72  /// Where to start first time window
74 
75  /// amount of overlap between windows
77 
78  /// number of time windows to make
79  unsigned int fNumClusters;
80 
81  /// write clusters to file
83  };
84 
85 
86 
87  //.......................................................................
89  fCellHitToken(consumes<std::vector<rb::CellHit>>(pset.get<std::string>("CellHitInput"))),
90  fCellWidth (pset.get<unsigned short> ("CellWidth")),
91  fPlaneLength (pset.get<unsigned short> ("PlaneLength")),
92  fMaxPlaneGap (pset.get<unsigned int> ("MaxPlaneGap")),
93  fTimeWinSize (pset.get<int> ("TimeWinSize")),
94  fTimeWinOffset (pset.get<int> ("TimeWinOffset")),
95  fTimeWinOverlap(pset.get<int> ("TimeWinOverlap")),
96  fNumClusters (pset.get<unsigned int> ("NumClusters")),
97  fWriteClusters (pset.get<bool> ("WriteClusters"))
98  {
99 
100  produces< std::vector<cvn::PixelMap> > ();
101  if (fWriteClusters) produces< std::vector<rb::Cluster> > ();
102  if (fWriteClusters) produces< art::Assns<cvn::PixelMap, rb::Cluster> >();
103  }
104 
105  //......................................................................
107  {
108  }
109 
110  //......................................................................
112  {
113  }
114 
115  //......................................................................
117  {
118  }
119 
120  //......................................................................
122  {
123 
124  std::unique_ptr< std::vector<rb::Cluster>> clustercol(new std::vector<rb::Cluster>);
125  std::unique_ptr< art::Assns<PixelMap, rb::Cluster> >
127 
128  //Declaring containers for things to be stored in event
129  auto pmCol = std::make_unique<std::vector<PixelMap>>();
130  pmCol->reserve(fNumClusters+1);
131 
132  // Get the cell hits
134  evt.getByToken(fCellHitToken, hitcol);
135 
136  std::vector<art::Ptr<rb::CellHit > > hits;
137  if (fWriteClusters){
138  for(unsigned int i = 0; i < hitcol->size(); ++i){
139  art::Ptr<rb::CellHit> hit(hitcol, i);
140  hits.push_back(hit);
141  }
142  std::sort(hits.begin(), hits.end(),
144  {return a->TNS() < b->TNS();});
145  }
146 
147  // Extract all the hits as concrete objects
148  std::vector<rb::CellHit> hitlist = *hitcol;
149 
150  // Sort the hits by time to improve the speed.
151  // WARNING: The rest of the code assumes that the hits are
152  // time sorted!
153  std::sort(hitlist.begin(), hitlist.end(),
154  [](const rb::CellHit& a, const rb::CellHit& b)
155  {return a.TNS() < b.TNS();});
156 
157  // Sort hits into time chunks now and make clusters from them.
158  // Also need to associate the hits with an label.
159 
160  //boundary is always the full detector size so just fix that
162 
163 
164  rb::Cluster cluster;
165 
166  // Step through the event and group clusters of hits over 15uSec centered on 217-232 (spill window)
167  // We add a 1uSec overlap on the beginning as well
168  for(unsigned int i = 0; i < fNumClusters; ++i) {
169  pmCol->emplace_back(fPlaneLength, fCellWidth, bound, true); // PEOnly
170  PixelMap& pm = pmCol->back();
171  unsigned int iCount=0;
172  if (fWriteClusters) cluster.Clear();
175  for(unsigned int j = 0; j < hitlist.size(); ++j) {
176  const rb::CellHit& hj = hitlist[j];
177 
178  if ((i*(fTimeWinSize-fTimeWinOverlap)+fTimeWinOffset) > (hj.TNS())) continue;
180  if (fWriteClusters){
181  clustercol->push_back(cluster);
182  util::CreateAssn(*this, evt, *(assoc.get()), *(pmCol.get()), *(clustercol), i, i);
183  }
184  break;
185  }
186  unsigned int view = (unsigned int)hj.View();
187  pm.Add(hj.Plane(),
188  hj.Cell(),
189  1.0,
190  view,
191  iCount,
192  hj.TNS(),
193  kEmptyHit,
194  0.0,
195  0,
196  0 );
197  iCount++;
198  if (fWriteClusters) cluster.Add(hits[j]);
199  }
200  }
201 
202 
203 
204  // Drop the cluster collections, pixelmap collections and associations into the event
205  evt.put(std::move(pmCol));
206  if (fWriteClusters){
207  evt.put(std::move(clustercol));
208  evt.put(std::move(assoc));
209  }
210  }
211 
212  //----------------------------------------------------------------------
213 
214 
215 
217 } // end namespace cvn
218 ////////////////////////////////////////////////////////////////////////
float TNS() const
Definition: CellHit.h:46
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.
unsigned int fNumClusters
number of time windows to make
const art::ProductToken< std::vector< rb::CellHit > > fCellHitToken
Read CellHits from this input.
unsigned short Plane() const
Definition: CellHit.h:39
geo::View_t View() const
Definition: CellHit.h:41
A collection of associated CellHits.
Definition: Cluster.h:47
int fTimeWinSize
Size of time window used in map.
void Add(const unsigned int &plane, const unsigned int &cell, const float &pe, unsigned int &view, unsigned int &hitID, const float &time, const HitType label, const double purity, const int object, const int nuIdx)
Definition: PixelMap.cxx:65
int fTimeWinOverlap
amount of overlap between windows
DEFINE_ART_MODULE(TestTMapFile)
PixelMap for CVN.
Defines an enumeration for prong classification.
bool fWriteClusters
write clusters to file
virtual void Add(const art::Ptr< rb::CellHit > &cell, double weight=1)
Definition: Cluster.cxx:84
void SetMinTime(float minTime)
Definition: PixelMap.h:42
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
unsigned short Cell() const
Definition: CellHit.h:40
void hits()
Definition: readHits.C:15
const double a
const double j
Definition: BetheBloch.cxx:29
unsigned short fPlaneLength
Length of pixel map in planes.
Perform a "2 point" Hough transform on a collection of hits.
unsigned short fCellWidth
Ratio of Cosmic pixel maps to Nu pixel maps to create.
CVNCosmicMapper(fhicl::ParameterSet const &pset)
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
A rawdata::RawDigit with channel information decoded.
Definition: CellHit.h:27
Definition: event.h:1
int fTimeWinOffset
Where to start first time window.
PixelMap, basic input to CVN neural net.
Definition: PixelMap.h:23
PixelMapProducer for CVN.
const hit & b
Definition: hits.cxx:21
void produce(art::Event &evt)
bool getByToken(ProductToken< PROD > const &token, Handle< PROD > &result) const
Definition: DataViewImpl.h:387
virtual void Clear()
Forget about all owned cell hits.
Definition: Cluster.cxx:279
ProductToken< T > consumes(InputTag const &)
void SetMaxTime(float maxTime)
Definition: PixelMap.h:44