LArSoft  v07_13_02
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.
40 
45 };
46 
48  : fPart (pset.get< fhicl::ParameterSet >("MCRecoPart"))
49  , fEdep (pset.get< fhicl::ParameterSet >("MCRecoEdep"))
50  , fMCSAlg (pset.get< fhicl::ParameterSet >("MCShowerRecoAlg"))
51  , fMCTAlg (pset.get< fhicl::ParameterSet >("MCTrackRecoAlg"))
52 {
53 
54  //for backwards compatibility to using the "G4ModName" label...
55  if(!(pset.get_if_present<art::InputTag>("MCParticleLabel",fMCParticleLabel) &&
56  pset.get_if_present<art::InputTag>("SimChannelLabel",fSimChannelLabel)) ){
57 
58  mf::LogWarning("MCReco_module") << "USING DEPRECATED G4ModName CONFIG IN MCRECO_MODULE"
59  << "\nUse 'MCParticleLabel' and 'SimChannelLabel' instead.";
60 
61  fMCParticleLabel = pset.get<art::InputTag>("G4ModName","largeant");
62  fSimChannelLabel = pset.get<art::InputTag>("G4ModName","largeant");
63  }
64 
65  produces< std::vector< sim::MCShower> >();
66  produces< std::vector< sim::MCTrack> >();
67  // Call appropriate produces<>() functions here.
68 
69 //MCReco::~MCReco()
70 //{
71  // Clean up dynamic memory and other resources here.
72 //}
73 }
74 
76 {
77 // std::unique_ptr< std::vector<sim::MCTrack> > outTrackArray(new std::vector<sim::MCTrack>);
78 
79  // Retrieve mcparticles
81  evt.getByLabel(fMCParticleLabel,mcpHandle);
82  if(!mcpHandle.isValid()) throw cet::exception(__FUNCTION__) << "Failed to retrieve simb::MCParticle";;
83 
84  // Find associations
86  std::vector<simb::Origin_t> orig_array;
87  orig_array.reserve(mcpHandle->size());
88  for(size_t i=0; i<mcpHandle->size(); ++i) {
89  const art::Ptr<simb::MCTruth> &mct = ass.at(i);
90  orig_array.push_back(mct->Origin());
91  }
92 
93  // Retrieve SimChannel
95  evt.getByLabel(fSimChannelLabel,schHandle);
96  if(!schHandle.isValid()) throw cet::exception(__FUNCTION__) << "Failed to retrieve sim::SimChannel";
97 
98  const std::vector<simb::MCParticle>& mcp_array(*mcpHandle);
99  fPart.AddParticles(mcp_array,orig_array);
100 
101  const std::vector<sim::SimChannel>& sch_array(*schHandle);
102  fEdep.MakeMCEdep(sch_array);
103 
104  //Add MCShowers and MCTracks to the event
107 
108  fEdep.Clear();
109  fPart.clear();
110 }
111 
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)
::sim::MCShowerRecoAlg fMCSAlg
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
bool isValid() const
Definition: Handle.h:190
::sim::MCRecoEdep fEdep
art::InputTag fMCParticleLabel
#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:124
parameter set interface
::sim::MCRecoPart fPart
T get(std::string const &key) const
Definition: ParameterSet.h:231
bool get_if_present(std::string const &key, T &value) const
Definition: ParameterSet.h:208
art::InputTag fSimChannelLabel
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
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
std::unique_ptr< std::vector< sim::MCTrack > > Reconstruct(MCRecoPart &part_v, MCRecoEdep &edep_v)
TCEvent evt
Definition: DataStructs.cxx:5
Float_t e
Definition: plot.C:34
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33