LArSoft  v09_90_00
Liquid Argon Software toolkit - https://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 
16 
18 #include "fhiclcpp/ParameterSet.h"
19 
20 #include "MCRecoEdep.h"
21 #include "MCRecoPart.h"
22 #include "MCShowerRecoAlg.h"
23 #include "MCTrackRecoAlg.h"
25 
26 #include <memory>
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  template <typename T>
35  void MakeMCEdep(art::Event& evt);
36 
37 private:
38  // Declare member data here.
45 
50 };
51 
53  : EDProducer{pset}
54  , fPart(pset.get<fhicl::ParameterSet>("MCRecoPart"))
55  , fEdep(pset.get<fhicl::ParameterSet>("MCRecoEdep"))
56  , fMCSAlg(pset.get<fhicl::ParameterSet>("MCShowerRecoAlg"))
57  , fMCTAlg(pset.get<fhicl::ParameterSet>("MCTrackRecoAlg"))
58 {
59 
60  //for backwards compatibility to using the "G4ModName" label...
61  if (!(pset.get_if_present<art::InputTag>("MCParticleLabel", fMCParticleLabel) &&
62  pset.get_if_present<art::InputTag>("SimChannelLabel", fSimChannelLabel))) {
63 
64  mf::LogWarning("MCReco_module") << "USING DEPRECATED G4ModName CONFIG IN MCRECO_MODULE"
65  << "\nUse 'MCParticleLabel' and 'SimChannelLabel' instead.";
66 
67  fMCParticleLabel = pset.get<art::InputTag>("G4ModName", "largeant");
68  fMCParticleDroppedLabel = pset.get<art::InputTag>("G4ModName", "largeant:droppedMCParticles");
69  fSimChannelLabel = pset.get<art::InputTag>("G4ModName", "largeant");
70  }
71  else {
73  pset.get<art::InputTag>("MCParticleDroppedLabel", "largeant:droppedMCParticles");
74  }
75 
76  fUseSimEnergyDeposit = pset.get<bool>("UseSimEnergyDeposit", false);
77  fUseSimEnergyDepositLite = pset.get<bool>("UseSimEnergyDepositLite", false);
78  fIncludeDroppedParticles = pset.get<bool>("IncludeDroppedParticles", false);
79 
80  if (fUseSimEnergyDepositLite && fUseSimEnergyDeposit) {
81  mf::LogWarning("MCReco_module")
82  << "Asked to use both SimEnergyDeposit and SimEnergyDepositLite - will use SimEnergyDeposit.";
83  }
84 
85  produces<std::vector<sim::MCShower>>();
86  produces<std::vector<sim::MCTrack>>();
87  // Call appropriate produces<>() functions here.
88 
89  //MCReco::~MCReco()
90  //{
91  // Clean up dynamic memory and other resources here.
92  //}
93 }
94 
96 {
97  // std::unique_ptr< std::vector<sim::MCTrack> > outTrackArray(new std::vector<sim::MCTrack>);
98 
99  // Retrieve mcparticles
101  evt.getByLabel(fMCParticleLabel, mcpHandle);
102  if (!mcpHandle.isValid())
103  throw cet::exception(__FUNCTION__) << "Failed to retrieve simb::MCParticle";
104  ;
105 
106  // Find associations
107  art::FindOneP<simb::MCTruth> ass(mcpHandle, evt, fMCParticleLabel);
108  std::vector<simb::Origin_t> orig_array;
109  orig_array.reserve(mcpHandle->size());
110  for (size_t i = 0; i < mcpHandle->size(); ++i) {
111  const art::Ptr<simb::MCTruth>& mct = ass.at(i);
112  orig_array.push_back(mct->Origin());
113  }
114 
115  const std::vector<simb::MCParticle>& mcp_array(*mcpHandle);
116 
118  auto const& mcmp_array =
119  *evt.getValidHandle<std::vector<simb::MCParticle>>(fMCParticleDroppedLabel);
120  fPart.AddParticles(mcp_array, orig_array, mcmp_array);
121  } // end if fIncludeDroppedParticles
122  else {
123  fPart.AddParticles(mcp_array, orig_array);
124  }
125 
126  // change implemented by David Caratelli to allow for MCRECO to run without SimChannels and using
127  // SimEnergyDeposits instead
128  if (fUseSimEnergyDeposit == true) { MakeMCEdep<sim::SimEnergyDeposit>(evt); }
129  // change implemented by Laura Domine to allow for MCRECO to run with SimEnergyDepositLite
130  else if (fUseSimEnergyDepositLite == true) {
131  MakeMCEdep<sim::SimEnergyDepositLite>(evt);
132  }
133  else {
134  MakeMCEdep<sim::SimChannel>(evt);
135  }
136 
137  //Add MCShowers and MCTracks to the event
140 
141  fEdep.Clear();
142  fPart.clear();
143 }
144 
145 template <typename T>
147 {
148  // Retrieve T
149  auto const& sed_array = *evt.getValidHandle<std::vector<T>>(fSimChannelLabel);
150  fEdep.MakeMCEdep(sed_array);
151 }
152 
void MakeMCEdep(const std::vector< sim::SimChannel > &schArray)
Definition: MCRecoEdep.cxx:62
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.cc:6
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 fIncludeDroppedParticles
void AddParticles(const std::vector< simb::MCParticle > &mcp_v, const std::vector< simb::Origin_t > &orig_v, const std::vector< simb::MCParticle > &mcmp_v={})
Definition: MCRecoPart.cxx:133
bool isValid() const noexcept
Definition: Handle.h:203
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: Event.h:77
::sim::MCRecoEdep fEdep
art::InputTag fMCParticleLabel
void MakeMCEdep(art::Event &evt)
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
bool fUseSimEnergyDepositLite
::sim::MCRecoPart fPart
art::InputTag fSimChannelLabel
Class def header for mctrack data container.
MCReco(fhicl::ParameterSet const &p)
bool fUseSimEnergyDeposit
::sim::MCTrackRecoAlg fMCTAlg
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
void produce(art::Event &e) override
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
art::InputTag fMCParticleDroppedLabel
std::unique_ptr< std::vector< sim::MCTrack > > Reconstruct(MCRecoPart &part_v, MCRecoEdep &edep_v)
TCEvent evt
Definition: DataStructs.cxx:8
Float_t e
Definition: plot.C:35
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33