MCReco_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // 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.
8 ////////////////////////////////////////////////////////////////////////
9 
12 #include "canvas/Persistency/Common/FindOneP.h"
16 
18 #include "fhiclcpp/ParameterSet.h"
19 
20 #include "MCRecoEdep.h"
21 #include "MCShowerRecoAlg.h"
22 #include "MCTrackRecoAlg.h"
24 
25 #include <memory>
26 
27 class MCReco : public art::EDProducer {
28 public:
29  explicit MCReco(fhicl::ParameterSet const & p);
30 // virtual ~MCReco();
31 
32  void produce(art::Event & e) override;
33 
34 private:
35 
36  // Declare member data here.
40 
45 };
46 
48  : EDProducer{pset}
49  , fPart (pset.get< fhicl::ParameterSet >("MCRecoPart"))
50  , fEdep (pset.get< fhicl::ParameterSet >("MCRecoEdep"))
51  , fMCSAlg (pset.get< fhicl::ParameterSet >("MCShowerRecoAlg"))
52  , fMCTAlg (pset.get< fhicl::ParameterSet >("MCTrackRecoAlg"))
53 {
54 
55  //for backwards compatibility to using the "G4ModName" label...
56  if(!(pset.get_if_present<art::InputTag>("MCParticleLabel",fMCParticleLabel) &&
57  pset.get_if_present<art::InputTag>("SimChannelLabel",fSimChannelLabel)) ){
58 
59  mf::LogWarning("MCReco_module") << "USING DEPRECATED G4ModName CONFIG IN MCRECO_MODULE"
60  << "\nUse 'MCParticleLabel' and 'SimChannelLabel' instead.";
61 
62  fMCParticleLabel = pset.get<art::InputTag>("G4ModName","largeant");
63  fSimChannelLabel = pset.get<art::InputTag>("G4ModName","largeant");
64  }
65 
66  fUseSimEnergyDeposit = pset.get<bool>("UseSimEnergyDeposit",false);
67 
68  produces< std::vector< sim::MCShower> >();
69  produces< std::vector< sim::MCTrack> >();
70  // Call appropriate produces<>() functions here.
71 
72 //MCReco::~MCReco()
73 //{
74  // Clean up dynamic memory and other resources here.
75 //}
76 }
77 
79 {
80 // std::unique_ptr< std::vector<sim::MCTrack> > outTrackArray(new std::vector<sim::MCTrack>);
81 
82  // Retrieve mcparticles
84  evt.getByLabel(fMCParticleLabel,mcpHandle);
85  if(!mcpHandle.isValid()) throw cet::exception(__FUNCTION__) << "Failed to retrieve simb::MCParticle";;
86 
87  // Find associations
88  art::FindOneP<simb::MCTruth> ass(mcpHandle, evt, fMCParticleLabel);
89  std::vector<simb::Origin_t> orig_array;
90  orig_array.reserve(mcpHandle->size());
91  for(size_t i=0; i<mcpHandle->size(); ++i) {
92  const art::Ptr<simb::MCTruth> &mct = ass.at(i);
93  orig_array.push_back(mct->Origin());
94  }
95 
96  const std::vector<simb::MCParticle>& mcp_array(*mcpHandle);
97  fPart.AddParticles(mcp_array,orig_array);
98 
99 
100  // change implemented by David Caratelli to allow for MCRECO to run without SimChannels and using
101  // SimEnergyDeposits instead
102  if (fUseSimEnergyDeposit == true) {
103  // Retrieve SimEnergyDeposit
105  evt.getByLabel(fSimChannelLabel,sedHandle);
106  if(!sedHandle.isValid()) throw cet::exception(__FUNCTION__) << "Failed to retrieve sim::SimEnergyDeposit";
107 
108  const std::vector<sim::SimEnergyDeposit>& sed_array(*sedHandle);
109  fEdep.MakeMCEdep(sed_array);
110  }
111  else {
112  // Retrieve SimChannel
114  evt.getByLabel(fSimChannelLabel,schHandle);
115  if(!schHandle.isValid()) throw cet::exception(__FUNCTION__) << "Failed to retrieve sim::SimChannel";
116 
117  const std::vector<sim::SimChannel>& sch_array(*schHandle);
118  fEdep.MakeMCEdep(sch_array);
119  }
120 
121  //Add MCShowers and MCTracks to the event
124 
125  fEdep.Clear();
126  fPart.clear();
127 }
128 
void MakeMCEdep(const std::vector< sim::SimChannel > &schArray)
Definition: MCRecoEdep.cxx:60
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
simb::Origin_t Origin() const
Definition: MCTruth.h:74
std::unique_ptr< std::vector< sim::MCShower > > Reconstruct(MCRecoPart &part_v, MCRecoEdep &edep_v)
::sim::MCShowerRecoAlg fMCSAlg
bool isValid() const noexcept
Definition: Handle.h:191
::sim::MCRecoEdep fEdep
art::InputTag fMCParticleLabel
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:633
const double e
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
void AddParticles(const std::vector< simb::MCParticle > &mcp_v, const std::vector< simb::Origin_t > &orig_v)
Definition: MCRecoPart.cxx:128
::sim::MCRecoPart fPart
p
Definition: test.py:223
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: DataViewImpl.h:686
art::InputTag fSimChannelLabel
Class def header for mctrack data container.
MCReco(fhicl::ParameterSet const &p)
bool fUseSimEnergyDeposit
::sim::MCTrackRecoAlg fMCTAlg
void produce(art::Event &e) override
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:7
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33