All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TrackStoppingChi2Fitter_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: TrackStoppingChi2Fitter
3 // Plugin Type: producer (art v3_06_03)
4 // File: TrackStoppingChi2Fitter_module.cc
5 //
6 // Generated at Mon Mar 1 10:30:45 2021 by Edward Tyley using cetskelgen
7 // from cetlib version v3_11_01.
8 //
9 // Producer to identify Bragg peaks from stopping tracks
10 // Based on the StoppingParticleCosmicIDAlg by Tom Brooks in sbndcode
11 ////////////////////////////////////////////////////////////////////////
12 
13 #include "art/Framework/Core/EDProducer.h"
14 #include "art/Framework/Core/ModuleMacros.h"
15 #include "art/Framework/Principal/Event.h"
16 #include "art/Framework/Principal/Handle.h"
17 #include "art/Framework/Principal/Run.h"
18 #include "art/Framework/Principal/SubRun.h"
19 #include "canvas/Utilities/InputTag.h"
20 #include "fhiclcpp/ParameterSet.h"
22 #include "messagefacility/MessageLogger/MessageLogger.h"
23 
26 
27 #include <memory>
28 
29 namespace sbn {
30 class TrackStoppingChi2Fitter : public art::EDProducer {
31  public:
32  explicit TrackStoppingChi2Fitter(fhicl::ParameterSet const& p);
33  // The compiler-generated destructor is fine for non-base
34  // classes without bare pointers or other resource use.
35 
36  // Plugins should not be copied or assigned.
41 
42  // Required functions.
43  void produce(art::Event& e) override;
44 
45  private:
46  // Declare member data here.
47  const art::InputTag fTrackLabel, fCaloLabel;
48  const float fMinTrackLength;
49 
51 };
52 
54  : EDProducer { p }
55  , fTrackLabel(p.get<std::string>("TrackLabel"))
56  , fCaloLabel(p.get<std::string>("CaloLabel"))
57  , fMinTrackLength(p.get<float>("MinTrackLength"))
58  , fTrackStoppingChi2Alg(p)
59 {
60  produces<std::vector<StoppingChi2Fit>>();
61  produces<art::Assns<recob::Track, StoppingChi2Fit>>();
62  produces<art::Assns<anab::Calorimetry, StoppingChi2Fit>>();
63 }
64 
66 {
67  // Implementation of required member function here.
68  auto const trackHandle(e.getValidHandle<std::vector<recob::Track>>(fTrackLabel));
69 
70  std::vector<art::Ptr<recob::Track>> tracks;
71  art::fill_ptr_vector(tracks, trackHandle);
72 
73  art::FindManyP<anab::Calorimetry> fmTrackCalo(trackHandle, e, fCaloLabel);
74 
75  auto fitVec = std::make_unique<std::vector<StoppingChi2Fit>>();
76  auto trackAssns = std::make_unique<art::Assns<recob::Track, StoppingChi2Fit>>();
77  auto caloAssns = std::make_unique<art::Assns<anab::Calorimetry, StoppingChi2Fit>>();
78 
79  for (auto const& track : tracks) {
80 
81  if (track->Length() < fMinTrackLength)
82  continue;
83 
84  const std::vector<art::Ptr<anab::Calorimetry>> caloVec(fmTrackCalo.at(track.key()));
85 
86  if (caloVec.size() != 3)
87  continue;
88 
89  // Find the plane with the most hits: prefer collection > 1st induction > 2nd induction if multiple planes have the same number
90  const unsigned int maxHits(std::max({ caloVec[0]->dEdx().size(), caloVec[1]->dEdx().size(), caloVec[2]->dEdx().size() }));
91  const int bestPlane((caloVec[2]->dEdx().size() == maxHits) ? 2 : (caloVec[0]->dEdx().size() == maxHits) ? 0 : (caloVec[1]->dEdx().size() == maxHits) ? 1 : -1);
92 
93  if (bestPlane == -1)
94  continue;
95 
96  StoppingChi2Fit thisFit(fTrackStoppingChi2Alg.RunFit(*caloVec.at(bestPlane)));
97 
98  if (thisFit.pol0Chi2 < 0.f || thisFit.expChi2 < 0.f)
99  continue;
100 
101  fitVec->push_back(thisFit);
102  util::CreateAssn(*this, e, *fitVec, track, *trackAssns);
103  util::CreateAssn(*this, e, *fitVec, caloVec[bestPlane], *caloAssns);
104  }
105 
106  e.put(std::move(fitVec));
107  e.put(std::move(trackAssns));
108  e.put(std::move(caloAssns));
109 }
110 }
111 
112 DEFINE_ART_MODULE(sbn::TrackStoppingChi2Fitter)
ClusterModuleLabel join with tracks
pdgs p
Definition: selectors.fcl:22
std::size_t size(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:561
process_name use argoneut_mc_hitfinder track
sbn::TrackStoppingChi2Alg fTrackStoppingChi2Alg
TrackStoppingChi2Fitter(fhicl::ParameterSet const &p)
float dEdx(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, const TCSlice &slc, TP3D &tp3d)
Definition: PFPUtils.cxx:2687
Provides recob::Track data product.
TrackStoppingChi2Fitter & operator=(TrackStoppingChi2Fitter const &)=delete
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
StoppingChi2Fit RunFit(const std::vector< float > &dEdxVec, const std::vector< float > &resRangeVec) const