LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
MCReco_module.cc
Go to the documentation of this file.
1 // Class: MCReco
3 // Module Type: producer
4 // File: MCReco_module.cc
5 //
6 // Generated at Mon Aug 11 05:40:00 2014 by Kazuhiro Terao using artmod
7 // from cetpkgsupport v1_05_04.
9 
17 
19 #include "fhiclcpp/ParameterSet.h"
20 
21 #include "MCShowerRecoAlg.h"
22 #include "MCTrackRecoAlg.h"
23 
24 #include <memory>
25 
26 class MCReco;
27 
28 class MCReco : public art::EDProducer {
29 public:
30  explicit MCReco(fhicl::ParameterSet const & p);
31 // virtual ~MCReco();
32 
33  void produce(art::Event & e) override;
34 
35 private:
36 
37  // Declare member data here.
38  std::string fG4Module;
43 };
44 
46  : fPart (pset.get< fhicl::ParameterSet >("MCRecoPart"))
47  , fEdep (pset.get< fhicl::ParameterSet >("MCRecoEdep"))
48  , fMCSAlg (pset.get< fhicl::ParameterSet >("MCShowerRecoAlg"))
49  , fMCTAlg (pset.get< fhicl::ParameterSet >("MCTrackRecoAlg"))
50 {
51  fG4Module = pset.get<std::string>("G4ModName","largeant");
52  produces< std::vector< sim::MCShower> >();
53  produces< std::vector< sim::MCTrack> >();
54  // Call appropriate produces<>() functions here.
55 
56 //MCReco::~MCReco()
57 //{
58  // Clean up dynamic memory and other resources here.
59 //}
60 }
61 
63 {
64 // std::unique_ptr< std::vector<sim::MCTrack> > outTrackArray(new std::vector<sim::MCTrack>);
65 
66  // Retrieve mcparticles
68  evt.getByLabel(fG4Module.c_str(),mcpHandle);
69  if(!mcpHandle.isValid()) throw cet::exception(__FUNCTION__) << "Failed to retrieve simb::MCParticle";;
70 
71  // Find associations
72  art::FindOneP<simb::MCTruth> ass(mcpHandle, evt, fG4Module.c_str());
73  std::vector<simb::Origin_t> orig_array;
74  orig_array.reserve(mcpHandle->size());
75  for(size_t i=0; i<mcpHandle->size(); ++i) {
76  const art::Ptr<simb::MCTruth> &mct = ass.at(i);
77  orig_array.push_back(mct->Origin());
78  }
79 
80  // Retrieve SimChannel
82  evt.getByLabel(fG4Module.c_str(),schHandle);
83  if(!schHandle.isValid()) throw cet::exception(__FUNCTION__) << "Failed to retrieve sim::SimChannel";
84 
85  const std::vector<simb::MCParticle>& mcp_array(*mcpHandle);
86  fPart.AddParticles(mcp_array,orig_array);
87 
88  const std::vector<sim::SimChannel>& sch_array(*schHandle);
89  fEdep.MakeMCEdep(sch_array);
90 
91  //Add MCShowers and MCTracks to the event
94 
95  fEdep.Clear();
96  fPart.clear();
97 }
98 
void MakeMCEdep(const std::vector< sim::SimChannel > &schArray)
Definition: MCRecoEdep.cxx:55
simb::Origin_t Origin() const
Definition: MCTruth.h:71
std::unique_ptr< std::vector< sim::MCShower > > Reconstruct(MCRecoPart &part_v, MCRecoEdep &edep_v)
std::string fG4Module
::sim::MCShowerRecoAlg fMCSAlg
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
bool isValid() const
Definition: Handle.h:190
::sim::MCRecoEdep fEdep
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
void AddParticles(const std::vector< simb::MCParticle > &mcp_v, const std::vector< simb::Origin_t > &orig_v)
Definition: MCRecoPart.cxx:122
parameter set interface
::sim::MCRecoPart fPart
T get(std::string const &key) const
Definition: ParameterSet.h:231
MCReco(fhicl::ParameterSet const &p)
::sim::MCTrackRecoAlg fMCTAlg
void produce(art::Event &e) override
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
std::unique_ptr< std::vector< sim::MCTrack > > Reconstruct(MCRecoPart &part_v, MCRecoEdep &edep_v)
Float_t e
Definition: plot.C:34
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33