All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sbndcode/sbndcode/CRT/CRTTools/CRTT0Matching_module.cc
Go to the documentation of this file.
1 /////////////////////////////////////////////////////////////////////////////
2 /// Class: CRTT0Matching
3 /// Module Type: producer
4 /// File: CRTT0Matching_module.cc
5 ///
6 /// Author: Thomas Brooks
7 /// E-mail address: tbrooks@fnal.gov
8 ///
9 /// Modified from CRTT0Matching by Thomas Warburton.
10 /////////////////////////////////////////////////////////////////////////////
11 
12 // 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
54 
55 // ROOT
56 #include "TVector3.h"
57 
58 
59 namespace sbnd {
60 
61  class CRTT0Matching : public art::EDProducer {
62  public:
63 
64  explicit CRTT0Matching(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  CRTT0Matching(CRTT0Matching const &) = delete;
71  CRTT0Matching(CRTT0Matching &&) = delete;
72  CRTT0Matching & operator = (CRTT0Matching 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 fCrtHitModuleLabel; ///< name of crt producer
90 
92 
93  }; // class CRTT0Matching
94 
95 
96  CRTT0Matching::CRTT0Matching(fhicl::ParameterSet const & p)
97  : EDProducer(p), t0Alg(p.get<fhicl::ParameterSet>("T0Alg"))
98  // Initialize member data here, if know don't want to reconfigure on the fly
99  {
100 
101  // Call appropriate produces<>() functions here.
102  produces< std::vector<anab::T0> >();
103  produces< art::Assns<recob::Track , anab::T0> >();
104  produces< art::Assns<sbn::crt::CRTHit, anab::T0> >();
105 
106  reconfigure(p);
107 
108  } // CRTT0Matching()
109 
110 
111  void CRTT0Matching::reconfigure(fhicl::ParameterSet const & p)
112  {
113 
114  fTpcTrackModuleLabel = (p.get<art::InputTag> ("TpcTrackModuleLabel"));
115  fCrtHitModuleLabel = (p.get<art::InputTag> ("CrtHitModuleLabel"));
116 
117  } // CRTT0Matching::reconfigure()
118 
119 
121  {
122 
123  } // CRTT0Matching::beginJob()
124 
125  void CRTT0Matching::produce(art::Event & event)
126  {
127 
128  // Create anab::T0 objects and make association with recob::Track
129  std::unique_ptr< std::vector<anab::T0> > T0col( new std::vector<anab::T0>);
130  std::unique_ptr< art::Assns<recob::Track, anab::T0> > Trackassn( new art::Assns<recob::Track, anab::T0>);
131  std::unique_ptr< art::Assns <sbn::crt::CRTHit, anab::T0> > t0_crthit_assn( new art::Assns<sbn::crt::CRTHit, anab::T0> );
132 
133  // Retrieve CRT hit list
134  art::Handle<std::vector<sbn::crt::CRTHit>> crtListHandle;
135  std::vector<art::Ptr<sbn::crt::CRTHit>> crtList;
136  if(event.getByLabel(fCrtHitModuleLabel, crtListHandle))
137  art::fill_ptr_vector(crtList, crtListHandle);
138 
139  std::vector<sbn::crt::CRTHit> crtHits;
140  for (auto const& crtHit : crtList){
141  crtHits.push_back(*crtHit);
142  }
143 
144  // Retrieve track list
145  art::Handle< std::vector<recob::Track> > trackListHandle;
146  std::vector<art::Ptr<recob::Track> > trackList;
147  if (event.getByLabel(fTpcTrackModuleLabel,trackListHandle))
148  art::fill_ptr_vector(trackList, trackListHandle);
149 
150  mf::LogInfo("CRTT0Matching")
151  <<"Number of reconstructed tracks = "<<trackList.size()<<"\n"
152  <<"Number of CRT hits = "<<crtList.size();
153 
154  if (trackListHandle.isValid() && crtListHandle.isValid() ){
155 
156  auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(event);
157  // Loop over all the reconstructed tracks
158  for(size_t track_i = 0; track_i < trackList.size(); track_i++) {
159 
160  // std::pair<double, double> matchedTime = t0Alg.T0AndDCAFromCRTHits(detProp, *trackList[track_i], crtHits, event);
161  matchCand closest = t0Alg.GetClosestCRTHit(detProp, *trackList[track_i], crtHits, event);
162 
163  if(closest.dca >=0 ){
164  mf::LogInfo("CRTT0Matching")
165  <<"Matched time = "<<closest.t0<<" [us] to track "<<trackList[track_i]->ID()<<" with DCA = "<<closest.dca;
166  T0col->push_back(anab::T0(closest.t0*1e3, trackList[track_i]->ID(), closest.thishit.plane, (int)closest.extrapLen, closest.dca));
167  util::CreateAssn(*this, event, *T0col, trackList[track_i], *Trackassn);
168 
169  //find this CRThit in the collection
170  // note this does not work (both the loop and the assoc !!)
171  unsigned CRThitIndex = std::numeric_limits<unsigned>::max();
172  for (int ic=0; ic<(int)crtList.size(); ++ic){
173  if (crtList[ic]->ts0_ns==closest.thishit.ts0_ns && crtList[ic]->z_pos==closest.thishit.z_pos && crtList[ic]->peshit==closest.thishit.peshit)
174  CRThitIndex=ic;
175  }
176  if (CRThitIndex != std::numeric_limits<unsigned>::max())
177  util::CreateAssn(*this, event, *T0col, crtList[CRThitIndex], *t0_crthit_assn);
178 
179  } // DCA check
180 
181  } // Loop over tracks
182 
183  } // Validity check
184 
185  event.put(std::move(T0col));
186  event.put(std::move(Trackassn));
187  event.put(std::move(t0_crthit_assn));
188 
189  } // CRTT0Matching::produce()
190 
191 
193  {
194 
195  } // CRTT0Matching::endJob()
196 
197 
198  DEFINE_ART_MODULE(CRTT0Matching)
199 
200 } // sbnd namespace
201 
202 namespace {
203 
204 }
art::InputTag fCrtHitModuleLabel
name of crt producer
matchCand GetClosestCRTHit(detinfo::DetectorPropertiesData const &detProp, recob::Track tpcTrack, std::pair< double, double > t0MinMax, std::vector< sbn::crt::CRTHit > crtHits, int driftDirection)
art::InputTag fTpcTrackModuleLabel
name of track producer
int plane
Name of the CRT wall (in the form of numbers).
Definition: CRTHit.hh:36
float peshit
Total photo-electron (PE) in a crt hit.
Definition: CRTHit.hh:27
Declaration of signal hit object.
pdgs p
Definition: selectors.fcl:22
Definition: T0.h:16
float z_pos
position in z-direction (cm).
Definition: CRTHit.hh:42
double ts0_ns
Timestamp T0 (from White Rabbit), in UTC absolute time scale in nanoseconds from the Epoch...
Definition: CRTHit.hh:32
Access the description of detector geometry.
Provides recob::Track data product.
Encapsulate the geometry of a wire.
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.
CRTT0Matching & operator=(CRTT0Matching const &)=delete
Encapsulate the construction of a single detector plane.
do i e
stream1 can override from command line with o or output services user sbnd
Collection of Physical constants used in LArSoft.
art framework interface to geometry description
auto const detProp