All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MCSFitProducerICARUS_module.cc
Go to the documentation of this file.
1 #include "art/Framework/Core/EDProducer.h"
2 #include "art/Framework/Core/ModuleMacros.h"
3 #include "art/Framework/Principal/Event.h"
4 #include "art/Framework/Principal/Handle.h"
5 #include "art/Framework/Principal/Run.h"
6 #include "art/Framework/Principal/SubRun.h"
7 
8 #include "messagefacility/MessageLogger/MessageLogger.h"
9 
10 #include "fhiclcpp/ParameterSet.h"
11 #include "fhiclcpp/types/Atom.h"
12 #include "fhiclcpp/types/Table.h"
13 #include "canvas/Utilities/InputTag.h"
14 #include "canvas/Persistency/Common/FindManyP.h"
15 
19 
20 //#include "larreco/RecoAlg/TrajectoryMCSFitter.h"
22 #include "lardata/RecoBaseProxy/Track.h" //needed only if you do use the proxies
23 #include <memory>
24 
25 namespace trkf {
26  /**
27  * @file MCSFitProducerICARUS_module.cc
28  * @class trkf::MCSFitProducerICARUS
29  *
30  * @brief Producer for TrajectoryMCSFitterICARUS.
31  *
32  * Producer for TrajectoryMCSFitterICARUS, which performs a Maximum Likelihood fit of Multiple Coulomb Scattering angles between segments within a Track or Trajectory.
33  * It reads a recob::Track collection and produces a collection of recob::MCSFitResult where the elements are in the same order as the input collection (no explicit association is written).
34  *
35  * For configuration options see MCSFitProducer#Inputs and MCSFsitProducer#Config
36  *
37  * @author F. Varanini (Padova, ICARUS)
38  * @date 2018
39  * @version 1.0
40  */
41  class MCSFitProducerICARUS : public art::EDProducer {
42  public:
43 
44  struct Inputs {
45  using Name = fhicl::Name;
46  using Comment = fhicl::Comment;
47  fhicl::Atom<art::InputTag> inputLabel {
48  Name("inputLabel"),
49  Comment("Label of recob::TrackTrajectory Collection to be fit")
50  };
51  };
52 
53  struct Config {
54  using Name = fhicl::Name;
55  fhicl::Table<MCSFitProducerICARUS::Inputs> inputs {
56  Name("inputs"),
57  };
58  fhicl::Table<TrajectoryMCSFitterICARUS::Config> fitter {
59  Name("fitter")
60  };
61  };
62  using Parameters = art::EDProducer::Table<Config>;
63 
64  explicit MCSFitProducerICARUS(Parameters const & p);
66 
67  // Plugins should not be copied or assigned.
72 
73  void produce(art::Event & e) override;
74 std::vector<recob::Hit> projectHitsOnPlane(art::Event & e,const recob::Track& traj,unsigned int p) const;
75 
76  private:
78  art::InputTag inputTag;
80  };
81 }
82 
84  : EDProducer{p}, p_(p), mcsfitter(p_().fitter)
85 {
86  inputTag = art::InputTag(p_().inputs().inputLabel());
87  produces<std::vector<recob::MCSFitResult> >();
88 }
89 
91 
93 {
94  //std::cout << " MCSFitProducerICARUS produce " << std::endl;
95  //
96  auto output = std::make_unique<std::vector<recob::MCSFitResult> >();
97  //
98  art::Handle<std::vector<recob::Track> > inputH;
99  bool ok = e.getByLabel(inputTag,inputH);
100  if (!ok) throw cet::exception("MCSFitProducerICARUS") << "Cannot find input art::Handle with inputTag " << inputTag;
101  const auto& inputVec = *(inputH.product());
102 
103 //std::cout << " inputh size " << inputVec.size() << std::endl;
104 
105 for (const auto& element : inputVec) {
106  //fit
107  std::vector<recob::Hit> hits2d=projectHitsOnPlane(e,element,2);
108  mcsfitter.set2DHits(hits2d);
109  mcsfitter.ComputeD3P();
110  try{
111  recob::MCSFitResult result = mcsfitter.fitMcs(element);
112  output->emplace_back(std::move(result));
113  } catch(...)
114  {
115  continue;
116  }
117  }
118 
119  e.put(std::move(output));
120 }
121 
122 std::vector<recob::Hit> trkf::MCSFitProducerICARUS::projectHitsOnPlane(art::Event & e,const recob::Track& traj,unsigned int p) const
123 {
124 std::vector<recob::Hit> v;
125  // Get track collection proxy and parallel mcs fit data (associated hits loaded by default)
126  // Note: if tracks were produced from a TrackTrajectory collection you could access the original trajectories adding ',proxy::withOriginalTrajectory()' to the list of arguments
127 //std::cout << " before calling proxy " << std::endl;
128 auto const& tracks = proxy::getCollection<proxy::Tracks>(e,inputTag);
129 //std::cout << " after calling proxy " << std::endl;
130 const auto& track = tracks[0];
131 //std::cout << " proxy nhits " << track.nHits() << std::endl;
132 
133  for (const art::Ptr<recob::Hit>& h : track.hits())
134  if(h->WireID().Plane == p) {
135  //std::cout << "collection hit wire=" << h->WireID() << " peak time=" << h->PeakTime() << std::endl;
136  v.emplace_back(*h);
137  }
138 return v;
139 }
140 
141 
142 DEFINE_ART_MODULE(trkf::MCSFitProducerICARUS)
MCSFitProducerICARUS & operator=(MCSFitProducerICARUS const &)=delete
ClusterModuleLabel join with tracks
pdgs p
Definition: selectors.fcl:22
process_name use argoneut_mc_hitfinder track
TrajectoryMCSFitterICARUS mcsfitter
Offers proxy::Tracks and proxy::Track class for recob::Track access.
fhicl::Table< MCSFitProducerICARUS::Inputs > inputs
while getopts h
art::EDProducer::Table< Config > Parameters
BEGIN_PROLOG vertical distance to the surface Name
Declaration of cluster object.
std::vector< recob::Hit > projectHitsOnPlane(art::Event &e, const recob::Track &traj, unsigned int p) const
Provides recob::Track data product.
void produce(art::Event &e) override
Class storing the result of the Maximum Likelihood fit of Multiple Coulomb Scattering angles between ...
Definition: MCSFitResult.h:19
BEGIN_PROLOG sequence::SlidingWindowTriggerPatternsOppositeWindows END_PROLOG simSlidingORM6O6 effSlidingORW output
Class for Maximum Likelihood fit of Multiple Coulomb Scattering angles between segments within a Trac...
Producer for TrajectoryMCSFitterICARUS.
do i e
fhicl::Table< TrajectoryMCSFitterICARUS::Config > fitter
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a &quot;fitted&quot; track: