CosmicTrack_module.cc
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////
2 /// \brief Track finder for cosmic rays
3 /// \author brebel@fnal.gov, gsdavies@iastate.edu
4 /// \date
5 ///////////////////////////////////////////////////////////////////////
6 #include <cmath>
7 #include <string>
8 #include <vector>
9 
10 // ROOT includes
11 #include "TVector3.h"
12 
13 // NOvA includes
16 #include "Calibrator/Calibrator.h"
17 #include "RecoBase/CellHit.h"
18 #include "RecoBase/Cluster.h"
19 #include "RecoBase/FilterList.h"
20 #include "RecoBase/Track.h"
21 #include "Utilities/AssociationUtil.h"
22 #include "Utilities/func/MathUtil.h"
23 
24 // Framework includes
34 #include "fhiclcpp/ParameterSet.h"
36 
37 
38 namespace trk {
39  class CosmicTrack : public art::EDProducer {
40  public:
41  explicit CosmicTrack(fhicl::ParameterSet const& pset);
42  virtual ~CosmicTrack();
43 
44  void produce(art::Event& evt);
45  void reconfigure(const fhicl::ParameterSet& p);
46 
47  private:
48  std::string fClusterInput; ///< Input folder from cluster reco
49  int fTrackAlgEnum; ///< which algorithm to use 0: CosmicTrackAlg
50  ///< 1: WindowTrackingAlg
51  trk::TrackAlg *fTrkAlg; ///< Algorithm to carry out track fitting
52 
53  };
54 
55  //......................................................................
57  : fTrkAlg(nullptr)
58  {
59  reconfigure(pset);
60 
61  produces< std::vector<rb::Track> >();
62  // Associate Tracks with the Slice they came from
63  produces< art::Assns<rb::Track, rb::Cluster> >();
64 
65  switch(fTrackAlgEnum){
66  case 0:
67  fTrkAlg = new trk::CosmicTrackAlg(pset.get<fhicl::ParameterSet>("TrackAlgPSet"));
68  break;
69  case 1:
70  fTrkAlg = new trk::WindowTrackingAlg(pset.get<fhicl::ParameterSet>("TrackAlgPSet"));
71  break;
72  default:
73  fTrkAlg = new trk::WindowTrackingAlg(pset.get<fhicl::ParameterSet>("TrackAlgPSet"));
74  break;
75  }
76 
77  }
78 
79  //......................................................................
81  {
82  if (fTrkAlg) delete fTrkAlg;
83  }
84 
85  //......................................................................
87  {
88  fClusterInput = pset.get< std::string >("ClusterInput" );
89  fTrackAlgEnum = pset.get< int >("TrackingAlgEnumeration", 1);
90  }
91 
92  //......................................................................
93  ///
94  /// Reconstruction method for this module. Provides read-write access
95  /// to the event data.
96  ///
97  /// \param evt - Read-write access to the event data
98  ///
100  {
101  // Declare a container for Track objects to be stored in the art::event
102  std::unique_ptr< std::vector<rb::Track> > trackcol(new std::vector<rb::Track>);
103  // Associate Tracks with the Slice they came from
104  std::unique_ptr< art::Assns<rb::Track, rb::Cluster> > assns(new art::Assns<rb::Track, rb::Cluster>);
105 
106  // define vector holding the clusters
108  evt.getByLabel(fClusterInput, hSlices);
109 
110  std::vector< art::Ptr<rb::Cluster> > slices;
111  art::fill_ptr_vector(slices, hSlices);
112 
113  // now we have time slices of cellhits in clusters from Slicer- fit each
114  // one and make the tracks
115  const int sliceMax = slices.size();
116 
117  for(int sliceIdx = 0; sliceIdx < sliceMax; ++sliceIdx){
118 
119  // ignore clusters that are tagged as noise
120  if(slices[sliceIdx]->IsNoise() ) continue;
121 
122  LOG_DEBUG("CosmicTrack") << "On slice " << sliceIdx << " of " << sliceMax;
123 
124  // Use the cosmic track algorithm to build a track from the slice
125  std::vector<rb::Track> tracks = fTrkAlg->MakeTrack(slices[sliceIdx].get());
126  for(auto track : tracks){
127  if ( track.NCell() == 0 ) continue; // failed to make a track
128  trackcol->push_back(track);
129  //for(auto const tp : track.Trajectory()) tp.Print();
130  util::CreateAssn(*this, evt, *trackcol, slices[sliceIdx], *assns);
131  }
132  }// end loop over slices
133 
134  evt.put(std::move(trackcol));
135  evt.put(std::move(assns));
136  } // end produce
137 
138 } // end trk namespace
139 
140 namespace trk{
141 
143 
144 }
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
An algorithm to perform cosmic ray track fitting.
Definition: TrackAlg.h:25
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.
const char * p
Definition: xmltok.h:285
std::string fClusterInput
Input folder from cluster reco.
void produce(art::Event &evt)
Definition: event.h:19
DEFINE_ART_MODULE(TestTMapFile)
Track finder for cosmic rays.
An algorithm to perform cosmic ray track fitting.
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
Track finder for cosmic rays.
T get(std::string const &key) const
Definition: ParameterSet.h:231
void reconfigure(const fhicl::ParameterSet &p)
An algorithm to perform cosmic ray track fitting.
trk::TrackAlg * fTrkAlg
Algorithm to carry out track fitting.
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
CosmicTrack(fhicl::ParameterSet const &pset)
virtual std::vector< rb::Track > MakeTrack(const rb::Cluster *slice)=0
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:464
Track finder for cosmic rays.