All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Chi2ParticleID_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////
2 //
3 // \brief A chisq-test based particle identification method using calorimetry information
4 //
5 // \author tjyang@fnal.gov
6 //
7 ////////////////////////////////////////////////////////////////////////////
8 
13 
14 // Framework includes
15 #include "art/Framework/Core/EDProducer.h"
16 #include "art/Framework/Core/ModuleMacros.h"
17 #include "art/Framework/Principal/Event.h"
18 #include "art/Framework/Principal/Handle.h"
19 #include "canvas/Persistency/Common/Assns.h"
20 #include "canvas/Persistency/Common/FindManyP.h"
21 #include "canvas/Persistency/Common/Ptr.h"
22 #include "fhiclcpp/ParameterSet.h"
23 
24 namespace pid {
25  class Chi2ParticleID;
26 }
27 
28 class pid::Chi2ParticleID : public art::EDProducer {
29 public:
30  explicit Chi2ParticleID(fhicl::ParameterSet const & p);
31 
32  virtual void produce(art::Event & e);
33 
34 private:
35 
36  std::string fTrackModuleLabel;
38 
40 
41 };
42 
43 pid::Chi2ParticleID::Chi2ParticleID(fhicl::ParameterSet const & p)
44  : EDProducer{p}
45  , fChiAlg(p.get< fhicl::ParameterSet >("Chi2PIDAlg"))
46 {
47  fTrackModuleLabel = p.get< std::string >("TrackModuleLabel");
48  fCalorimetryModuleLabel = p.get< std::string >("CalorimetryModuleLabel");
49 
50  produces< std::vector<anab::ParticleID> >();
51  produces< art::Assns<recob::Track, anab::ParticleID> >();
52 }
53 
55 {
56  art::Handle< std::vector<recob::Track> > trackListHandle;
57  evt.getByLabel(fTrackModuleLabel,trackListHandle);
58 
59  std::vector<art::Ptr<recob::Track> > tracklist;
60  art::fill_ptr_vector(tracklist, trackListHandle);
61 
62  art::FindManyP<anab::Calorimetry> fmcal(trackListHandle, evt, fCalorimetryModuleLabel);
63 
64  //if (!fmcal.isValid()) return;
65 
66  std::unique_ptr< std::vector<anab::ParticleID> > particleidcol(new std::vector<anab::ParticleID>);
67  std::unique_ptr< art::Assns<recob::Track, anab::ParticleID> > assn(new art::Assns<recob::Track, anab::ParticleID>);
68 
69  if (fmcal.isValid()) {
70  std::vector<art::Ptr<anab::Calorimetry>> calovec(1, art::Ptr<anab::Calorimetry>());
71  for (size_t trkIter = 0; trkIter < tracklist.size(); ++trkIter){
72  for (size_t i = 0; i<fmcal.at(trkIter).size(); ++i){
73  calovec[0] = fmcal.at(trkIter)[i];
74  anab::ParticleID pidout = fChiAlg.DoParticleID(calovec);
75  particleidcol->push_back(pidout);
76  util::CreateAssn(*this, evt, *particleidcol, tracklist[trkIter], *assn);
77  }
78  }
79  }
80  evt.put(std::move(particleidcol));
81  evt.put(std::move(assn));
82 
83  return;
84 
85 }
86 
87 ////////////////////////////////////////////////////////////////////////
88 // Class: Chi2ParticleID
89 // Module Type: producer
90 // File: Chi2ParticleID_module.cc
91 //
92 // Generated at Fri Jul 13 16:06:02 2012 by Tingjun Yang using artmod
93 // from art v1_00_11.
94 ////////////////////////////////////////////////////////////////////////
95 
96 
97 DEFINE_ART_MODULE(pid::Chi2ParticleID)
Chi2ParticleID(fhicl::ParameterSet const &p)
pdgs p
Definition: selectors.fcl:22
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
TCEvent evt
Definition: DataStructs.cxx:8
virtual void produce(art::Event &e)