All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RangePAllPID_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: RangePAllPID
3 // Plugin Type: producer (art v3_02_06)
4 // File: RangePAllPID_module.cc
5 //
6 // Generated at Wed Feb 19 17:38:21 2020 by Gray Putnam using cetskelgen
7 // from cetlib version v3_07_02.
8 ////////////////////////////////////////////////////////////////////////
9 
10 #include "art/Framework/Core/EDProducer.h"
11 #include "art/Framework/Core/ModuleMacros.h"
12 #include "art/Framework/Principal/Event.h"
13 #include "art/Framework/Principal/Handle.h"
14 #include "art/Framework/Principal/Run.h"
15 #include "art/Framework/Principal/SubRun.h"
16 #include "canvas/Utilities/InputTag.h"
17 #include "fhiclcpp/ParameterSet.h"
18 #include "messagefacility/MessageLogger/MessageLogger.h"
20 
21 #include "TDatabasePDG.h"
22 
23 #include "LArReco/TrackMomentumCalculator.h"
25 
26 #include <memory>
27 
28 namespace sbn {
29  class RangePAllPID;
30 }
31 
32 
33 class sbn::RangePAllPID : public art::EDProducer {
34 public:
35  explicit RangePAllPID(fhicl::ParameterSet const& p);
36  // The compiler-generated destructor is fine for non-base
37  // classes without bare pointers or other resource use.
38 
39  // Plugins should not be copied or assigned.
40  RangePAllPID(RangePAllPID const&) = delete;
41  RangePAllPID(RangePAllPID&&) = delete;
42  RangePAllPID& operator=(RangePAllPID const&) = delete;
43  RangePAllPID& operator=(RangePAllPID&&) = delete;
44 
45  // Required functions.
46  void produce(art::Event& e) override;
47 
48 private:
49 
51  art::InputTag fTrackLabel;
52  double fMuonMass;
53  double fPionMass;
54 
55 };
56 
57 const static std::vector<int> PIDs {13, 211, 2212};
58 const static std::vector<std::string> names {"muon", "pion", "proton"};
59 
60 sbn::RangePAllPID::RangePAllPID(fhicl::ParameterSet const& p)
61  : EDProducer{p},
62  fRangeCalculator(p.get<float>("MinTrackLength", 10.)),
63  fTrackLabel(p.get<art::InputTag>("TrackLabel", "pandoraTrack"))
64 {
65  for (unsigned i = 0; i < names.size(); i++) {
66  produces<std::vector<sbn::RangeP>>(names[i]);
67  produces<art::Assns<recob::Track, sbn::RangeP>>(names[i]);
68  }
69 
70  const TDatabasePDG *PDGTable = TDatabasePDG::Instance();
71  fMuonMass = PDGTable->GetParticle(13)->Mass();
72  fPionMass = PDGTable->GetParticle(211)->Mass();
73 }
74 
75 void sbn::RangePAllPID::produce(art::Event& e)
76 {
77  art::Handle<std::vector<recob::Track>> track_handle;
78  e.getByLabel(fTrackLabel, track_handle);
79 
80  std::vector<art::Ptr<recob::Track>> tracks;
81  art::fill_ptr_vector(tracks, track_handle);
82 
83  for (unsigned i = 0; i < PIDs.size(); i++) {
84  std::unique_ptr<std::vector<sbn::RangeP>> rangecol(new std::vector<sbn::RangeP>);
85  std::unique_ptr<art::Assns<recob::Track, sbn::RangeP>> assn(new art::Assns<recob::Track, sbn::RangeP>);
86 
87  for (const art::Ptr<recob::Track> track: tracks) {
88  sbn::RangeP rangep;
89  // Rescale the input and output as described by https://inspirehep.net/literature/1766384 (eq. 6.2)
90  if (PIDs[i] == 211) {
91  rangep.range_p = fRangeCalculator.GetTrackMomentum(track->Length() * (fMuonMass / fPionMass), 13) * (fPionMass / fMuonMass);
92  }
93  else {
94  rangep.range_p = fRangeCalculator.GetTrackMomentum(track->Length(), PIDs[i]);
95  }
96  rangep.trackID = track->ID();
97  rangecol->push_back(rangep);
98  util::CreateAssn(*this, e, *rangecol, track, *assn, names[i]);
99  }
100 
101  e.put(std::move(rangecol), names[i]);
102  e.put(std::move(assn), names[i]);
103  }
104 
105 }
106 
107 DEFINE_ART_MODULE(sbn::RangePAllPID)
ClusterModuleLabel join with tracks
static const std::vector< int > PIDs
pdgs p
Definition: selectors.fcl:22
process_name use argoneut_mc_hitfinder track
fRangeCalculator(p.get< float >("MinTrackLength", 0.1))
int trackID
Definition: RangeP.h:8
trkf::TrackMomentumCalculator fRangeCalculator
static const std::vector< std::string > names
art::InputTag fTrackLabel
float range_p
Definition: RangeP.h:7
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.
static const TDatabasePDG * PDGTable(new TDatabasePDG)
RangePAllPID & operator=(RangePAllPID const &)=delete
do i e
RangePAllPID(fhicl::ParameterSet const &p)
void produce(art::Event &e) override