All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CRTTrackMatching_module.cc
Go to the documentation of this file.
1 /////////////////////////////////////////////////////////////////////////////
2 /// Class: CRTTrackMatching
3 /// Module Type: producer
4 /// File: CRTTrackMatching_module.cc
5 ///
6 /// Author: Thomas Brooks
7 /// E-mail address: tbrooks@fnal.gov
8 ///
9 /////////////////////////////////////////////////////////////////////////////
10 
11 // sbndcode includes
15 
16 // Framework includes
17 #include "art/Framework/Core/EDProducer.h"
18 #include "art/Framework/Core/ModuleMacros.h"
19 #include "canvas/Persistency/Common/FindManyP.h"
20 #include "art/Framework/Principal/Handle.h"
21 #include "art/Framework/Principal/Event.h"
22 #include "canvas/Persistency/Common/Ptr.h"
23 #include "canvas/Persistency/Common/PtrVector.h"
24 #include "art/Framework/Principal/Run.h"
25 #include "art/Framework/Principal/SubRun.h"
26 #include "art_root_io/TFileService.h"
27 #include "art_root_io/TFileDirectory.h"
28 
29 #include "canvas/Utilities/InputTag.h"
30 #include "fhiclcpp/ParameterSet.h"
31 #include "messagefacility/MessageLogger/MessageLogger.h"
32 
33 #include <memory>
34 #include <iostream>
35 #include <map>
36 #include <iterator>
37 #include <algorithm>
38 
39 // LArSoft
50 
51 // ROOT
52 #include "TVector3.h"
53 
54 namespace {
55  // Local namespace for local functions
56 
57 }
58 
59 namespace sbnd {
60 
61  class CRTTrackMatching : public art::EDProducer {
62  public:
63 
64  explicit CRTTrackMatching(fhicl::ParameterSet const & p);
65 
66  // The destructor generated by the compiler is fine for classes
67  // without bare pointers or other resource use.
68 
69  // Plugins should not be copied or assigned.
70  CRTTrackMatching(CRTTrackMatching const &) = delete;
72  CRTTrackMatching & operator = (CRTTrackMatching const &) = delete;
74 
75  // Required functions.
76  void produce(art::Event & e) override;
77 
78  // Selected optional functions.
79  void beginJob() override;
80 
81  void endJob() override;
82 
83  void reconfigure(fhicl::ParameterSet const & p);
84 
85  private:
86 
87  // Params got from fcl file.......
88  art::InputTag fTpcTrackModuleLabel; ///< name of track producer
89  art::InputTag fCrtTrackModuleLabel; ///< name of crt producer
90 
93 
94  }; // class CRTTrackMatching
95 
96 
97  CRTTrackMatching::CRTTrackMatching(fhicl::ParameterSet const & p)
98  : EDProducer(p), trackAlg(p.get<fhicl::ParameterSet>("CrtTrackAlg"))
99  // Initialize member data here, if know don't want to reconfigure on the fly
100  {
101 
102  // Call appropriate produces<>() functions here.
103  produces< std::vector<anab::T0> >();
104  produces< art::Assns<recob::Track , anab::T0> >();
105  //produces< art::Assns<recob::Track , sbn::crt::CRTTrack> >();
106 
107  reconfigure(p);
108 
109  } // CRTTrackMatching()
110 
111 
112  void CRTTrackMatching::reconfigure(fhicl::ParameterSet const & p)
113  {
114 
115  fTpcTrackModuleLabel = (p.get<art::InputTag> ("TpcTrackModuleLabel"));
116  fCrtTrackModuleLabel = (p.get<art::InputTag> ("CrtTrackModuleLabel"));
117 
118  } // CRTTrackMatching::reconfigure()
119 
120 
122  {
123  // Implementation of optional member function here.
124  art::ServiceHandle<art::TFileService> tfs;
125 
126  } // CRTTrackMatching::beginJob()
127 
128 
129  void CRTTrackMatching::produce(art::Event & event)
130  {
131 
132  // Create anab::T0 objects and make association with recob::Track
133  std::unique_ptr< std::vector<anab::T0> > T0col( new std::vector<anab::T0>);
134  std::unique_ptr< art::Assns<recob::Track, anab::T0> > Trackassn( new art::Assns<recob::Track, anab::T0>);
135  //std::unique_ptr< art::Assns<recob::Track, sbn::crt::CRTTrack> > Crtassn( new art::Assns<recob::Track, sbn::crt::CRTTrack>);
136 
137  // Get TPC tracks
138  art::Handle< std::vector<recob::Track> > tpcTrackListHandle;
139  std::vector<art::Ptr<recob::Track> > tpcTrackList;
140  if (event.getByLabel(fTpcTrackModuleLabel, tpcTrackListHandle))
141  art::fill_ptr_vector(tpcTrackList, tpcTrackListHandle);
142 
143  // Get track to hit associations
144  //art::FindManyP<recob::Hit> findManyHits(tpcTrackListHandle, event, fTpcTrackModuleLabel);
145 
146  // Get CRT tracks
147  art::Handle< std::vector<sbn::crt::CRTTrack> > crtTrackListHandle;
148  std::vector<art::Ptr<sbn::crt::CRTTrack> > crtTrackList;
149  if (event.getByLabel(fCrtTrackModuleLabel, crtTrackListHandle))
150  art::fill_ptr_vector(crtTrackList, crtTrackListHandle);
151 
152  std::vector<sbn::crt::CRTTrack> crtTracks;
153  for(auto const& crtTrack : crtTrackList){
154  crtTracks.push_back(*crtTrack);
155  }
156 
157  auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(event);
158 
159  // Validity check
160  if (tpcTrackListHandle.isValid() && crtTrackListHandle.isValid() ){
161 
162  mf::LogInfo("CRTTrackMatching")
163  <<"Number of TPC tracks = "<<tpcTrackList.size()<<"\n"
164  <<"Number of CRT tracks = "<<crtTrackList.size();
165  for (size_t tpc_i = 0; tpc_i < tpcTrackList.size(); tpc_i++){
166 
167  std::pair<int,double> matchedResult = trackAlg.GetMatchedCRTTrackIdAndScore(detProp,
168  *tpcTrackList[tpc_i], crtTracks, event);
169  int matchedID = matchedResult.first;
170  double matchedScore = matchedResult.second;
171 
172  if(matchedID != -99999){
173  double crtTime = ((double)(int)crtTracks.at(matchedID).ts1_ns); // [ns]
174  T0col->push_back(anab::T0(crtTime, 0, tpcTrackList[tpc_i]->ID(), (*T0col).size(), matchedScore));
175  util::CreateAssn(*this, event, *T0col, tpcTrackList[tpc_i], *Trackassn);
176  //util::CreateAssn(*this, event, crtTrackList[matchedID], tpcTrackList[tpc_i], *Crtassn);
177  }
178  }
179 
180  } // Validity check
181 
182  event.put(std::move(T0col));
183  event.put(std::move(Trackassn));
184  //event.put(std::move(Crtassn));
185 
186  } // CRTTrackMatching::produce()
187 
188 
190  {
191 
192  } // CRTTrackMatching::endJob()
193 
194 
195  DEFINE_ART_MODULE(CRTTrackMatching)
196 
197 } // sbnd namespace
198 
199 namespace {
200 
201 }
art::InputTag fCrtTrackModuleLabel
name of crt producer
CRTTrackMatching & operator=(CRTTrackMatching const &)=delete
Declaration of signal hit object.
pdgs p
Definition: selectors.fcl:22
void produce(art::Event &e) override
Definition: T0.h:16
Access the description of detector geometry.
void reconfigure(fhicl::ParameterSet const &p)
CRTTrackMatching(fhicl::ParameterSet const &p)
art::InputTag fTpcTrackModuleLabel
name of track producer
Provides recob::Track data product.
bool CreateAssn(art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t index=UINT_MAX)
Creates a single one-to-one association.
do i e
stream1 can override from command line with o or output services user sbnd
art::ServiceHandle< art::TFileService > tfs
Collection of Physical constants used in LArSoft.
std::pair< int, double > GetMatchedCRTTrackIdAndScore(detinfo::DetectorPropertiesData const &detProp, recob::Track tpcTrack, std::vector< sbn::crt::CRTTrack > crtTracks, const art::Event &event)
art framework interface to geometry description
auto const detProp