All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
10 #include "art/Framework/Core/EDProducer.h"
11 #include "art/Framework/Core/ModuleMacros.h"
12 #include "canvas/Persistency/Common/FindOneP.h"
13 #include "art/Framework/Principal/Event.h"
14 #include "art/Framework/Principal/Handle.h"
15 #include "messagefacility/MessageLogger/MessageLogger.h"
16 
17 #include "canvas/Utilities/InputTag.h"
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> void MakeMCEdep(art::Event& evt);
35 
36 private:
37 
38  // Declare member data here.
39  art::InputTag fMCParticleLabel;
40  art::InputTag fMCParticleLiteLabel;
41  art::InputTag fSimChannelLabel;
45 
50 };
51 
52 MCReco::MCReco(fhicl::ParameterSet const & pset)
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  fMCParticleLiteLabel = pset.get<art::InputTag>("G4ModName","largeant");
69  fSimChannelLabel = pset.get<art::InputTag>("G4ModName","largeant");
70  }
71  else {
72  fMCParticleLiteLabel = pset.get<art::InputTag>("MCParticleLiteLabel", "largeant");
73  }
74 
75  fUseSimEnergyDeposit = pset.get<bool>("UseSimEnergyDeposit",false);
76  fUseSimEnergyDepositLite = pset.get<bool>("UseSimEnergyDepositLite",false);
77  fIncludeDroppedParticles = pset.get<bool>("IncludeDroppedParticles",false);
78 
79  if (fUseSimEnergyDepositLite && fUseSimEnergyDeposit) {
80  mf::LogWarning("MCReco_module") << "Asked to use both SimEnergyDeposit and SimEnergyDepositLite - will use SimEnergyDeposit.";
81  }
82 
83  produces< std::vector< sim::MCShower> >();
84  produces< std::vector< sim::MCTrack> >();
85  // Call appropriate produces<>() functions here.
86 
87 //MCReco::~MCReco()
88 //{
89  // Clean up dynamic memory and other resources here.
90 //}
91 }
92 
93 void MCReco::produce(art::Event & evt)
94 {
95 // std::unique_ptr< std::vector<sim::MCTrack> > outTrackArray(new std::vector<sim::MCTrack>);
96 
97  // Retrieve mcparticles
98  art::Handle<std::vector<simb::MCParticle> > mcpHandle;
99  evt.getByLabel(fMCParticleLabel,mcpHandle);
100  if(!mcpHandle.isValid()) throw cet::exception(__FUNCTION__) << "Failed to retrieve simb::MCParticle";;
101 
102  // Find associations
103  art::FindOneP<simb::MCTruth> ass(mcpHandle, evt, fMCParticleLabel);
104  std::vector<simb::Origin_t> orig_array;
105  orig_array.reserve(mcpHandle->size());
106  for(size_t i=0; i<mcpHandle->size(); ++i) {
107  const art::Ptr<simb::MCTruth> &mct = ass.at(i);
108  orig_array.push_back(mct->Origin());
109  }
110 
111  const std::vector<simb::MCParticle>& mcp_array(*mcpHandle);
112 
113  if (fIncludeDroppedParticles) {
114  auto const& mcmp_array = *evt.getValidHandle<std::vector<sim::MCParticleLite>>(fMCParticleLiteLabel);
115  fPart.AddParticles(mcp_array, orig_array, mcmp_array);
116  } // end if fIncludeDroppedParticles
117  else {
118  fPart.AddParticles(mcp_array,orig_array);
119  }
120 
121  // change implemented by David Caratelli to allow for MCRECO to run without SimChannels and using
122  // SimEnergyDeposits instead
123  if (fUseSimEnergyDeposit == true) {
124  MakeMCEdep<sim::SimEnergyDeposit>(evt);
125  }
126  // change implemented by Laura Domine to allow for MCRECO to run with SimEnergyDepositLite
127  else if (fUseSimEnergyDepositLite == true) {
128  MakeMCEdep<sim::SimEnergyDepositLite>(evt);
129  }
130  else {
131  MakeMCEdep<sim::SimChannel>(evt);
132  }
133 
134  //Add MCShowers and MCTracks to the event
135  evt.put(fMCSAlg.Reconstruct(fPart,fEdep));
136  evt.put(fMCTAlg.Reconstruct(fPart,fEdep));
137 
138  fEdep.Clear();
139  fPart.clear();
140 }
141 
142 template <typename T> void MCReco::MakeMCEdep(art::Event& evt) {
143  // Retrieve T
144  auto const& sed_array = *evt.getValidHandle<std::vector<T>>(fSimChannelLabel);
145  fEdep.MakeMCEdep(sed_array);
146 }
147 
148 DEFINE_ART_MODULE(MCReco)
void MakeMCEdep(const std::vector< sim::SimChannel > &schArray)
Definition: MCRecoEdep.cxx:64
void AddParticles(const std::vector< simb::MCParticle > &mcp_v, const std::vector< simb::Origin_t > &orig_v, const std::vector< sim::MCParticleLite > &mcmp_v={})
Definition: MCRecoPart.cxx:128
pdgs p
Definition: selectors.fcl:22
std::unique_ptr< std::vector< sim::MCShower > > Reconstruct(MCRecoPart &part_v, MCRecoEdep &edep_v)
::sim::MCShowerRecoAlg fMCSAlg
bool fIncludeDroppedParticles
::sim::MCRecoEdep fEdep
art::InputTag fMCParticleLabel
void MakeMCEdep(art::Event &evt)
bool fUseSimEnergyDepositLite
::sim::MCRecoPart fPart
art::InputTag fMCParticleLiteLabel
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
do i e
std::unique_ptr< std::vector< sim::MCTrack > > Reconstruct(MCRecoPart &part_v, MCRecoEdep &edep_v)
TCEvent evt
Definition: DataStructs.cxx:8