LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
IShowerTool.h
Go to the documentation of this file.
1 //############################################################################
2 //### Name: IShowerTool ###
3 //### Author: Dominic Barker ###
4 //### Date: 13.05.19 ###
5 //### Description: Generic Tool for finding the shower energy. Used in ###
6 //### LArPandoraModularShowerCreation_module.cc ###
7 //############################################################################
8 
9 #ifndef IShowerTool_H
10 #define IShowerTool_H
11 
12 //LArSoft Includes
16 
17 namespace recob {
18  class PFParticle;
19 }
20 
21 //Framwork Includes
23 namespace art {
24  class Event;
25 }
27 #include "fhiclcpp/ParameterSet.h"
28 
29 namespace ShowerRecoTools {
30  class IShowerTool {
31 
32  public:
34  : fLArPandoraShowerAlg(pset.get<fhicl::ParameterSet>("LArPandoraShowerAlg"))
35  , fRunEventDisplay(pset.get<bool>("EnableEventDisplay")){};
36 
37  virtual ~IShowerTool() noexcept = default;
38 
39  //Generic Elemnt Finder. Used to calculate thing about the shower.
40  virtual int CalculateElement(const art::Ptr<recob::PFParticle>& pfparticle,
41  art::Event& Event,
42  reco::shower::ShowerElementHolder& ShowerEleHolder) = 0;
43 
44  //Main function that runs the shower tool. This includes running the derived function
45  //that calculates the shower element and also runs the event display if requested
47  art::Event& Event,
48  reco::shower::ShowerElementHolder& ShowerEleHolder,
49  std::string evd_display_name_append = "")
50  {
51 
52  int calculation_status = CalculateElement(pfparticle, Event, ShowerEleHolder);
53  if (calculation_status != 0) return calculation_status;
54  if (fRunEventDisplay) {
55  IShowerTool::GetLArPandoraShowerAlg().DebugEVD(
56  pfparticle, Event, ShowerEleHolder, evd_display_name_append);
57  }
58  return calculation_status;
59  }
60 
61  //Function to initialise the producer i.e produces<std::vector<recob::Vertex> >(); commands go here.
62  virtual void InitialiseProducers() {}
63 
64  //Set the point looking back at the producer module show we can make things in the module
65  void SetPtr(art::ProducesCollector* collector) { collectorPtr = collector; }
66 
67  //Initialises the unique ptr holder so that the tool can access it behind the scenes.
69  {
70  UniquePtrs = &uniqueproducerPtrs;
71  }
72 
73  //End function so the user can add associations
74  virtual int AddAssociations(const art::Ptr<recob::PFParticle>& pfpPtr,
75  art::Event& Event,
76  reco::shower::ShowerElementHolder& ShowerEleHolder)
77  {
78  return 0;
79  }
80 
81  protected:
83  {
84  return fLArPandoraShowerAlg;
85  };
86 
87  private:
88  //ptr to the holder of all the unique ptrs.
90 
91  //Algorithm functions
93 
94  //Flags
96 
98 
99  protected:
100  //Function to return the art:ptr for the corrsponding index iter. This allows the user the make associations
101  template <class T>
103  reco::shower::ShowerElementHolder& ShowerEleHolder,
104  int iter = -1)
105  {
106 
107  //Check the element has been set
108  bool check_element = ShowerEleHolder.CheckElement(Name);
109  if (!check_element) {
110  throw cet::exception("IShowerTool") << "tried to get a element that does not exist. Failed "
111  "at making the art ptr for Element: "
112  << Name << std::endl;
113  }
114 
115  //Check the unique ptr has been set.
116  bool check_ptr = UniquePtrs->CheckUniqueProduerPtr(Name);
117  if (!check_ptr) {
118  throw cet::exception("IShowerTool")
119  << "tried to get a ptr that does not exist. Failed at making the art ptr for Element"
120  << Name;
121  }
122 
123  //Check if the user has defined an index if not just use the current shower index/
124  int index;
125  if (iter != -1) { index = iter; }
126  else {
127  index = ShowerEleHolder.GetShowerNumber();
128  }
129 
130  //Make the ptr
131  return UniquePtrs->GetArtPtr<T>(Name, index);
132  }
133 
134  //Function so that the user can add products to the art event. This will set up the unique ptrs and the ptr makers required.
135  //Example: InitialiseProduct<std::vector<recob<vertex>>("MyVertex")
136  template <class T>
137  void InitialiseProduct(std::string Name, std::string InstanceName = "")
138  {
139 
140  if (collectorPtr == nullptr) {
141  mf::LogWarning("IShowerTool") << "The art::ProducesCollector ptr has not been set";
142  return;
143  }
144 
145  collectorPtr->produces<T>(InstanceName);
146  UniquePtrs->SetShowerUniqueProduerPtr(type<T>(), Name, InstanceName);
147  }
148 
149  //Function so that the user can add assocations to the event.
150  //Example: AddSingle<art::Assn<recob::Vertex,recob::shower>((art::Ptr<recob::Vertex>) Vertex, (art::Prt<recob::shower>) Shower), "myassn")
151  template <class T, class A, class B>
152  void AddSingle(A& a, B& b, std::string Name)
153  {
154  UniquePtrs->AddSingle<T>(a, b, Name);
155  }
156 
157  //Function to get the size of the vector, for the event, that is held in the unique producer ptr that will be put in the event.
158  int GetVectorPtrSize(std::string Name) { return UniquePtrs->GetVectorPtrSize(Name); }
159 
160  void PrintPtrs() { UniquePtrs->PrintPtrs(); }
161 
162  void PrintPtr(std::string Name) { UniquePtrs->PrintPtr(Name); }
163  };
164 }
165 
166 #endif
virtual int AddAssociations(const art::Ptr< recob::PFParticle > &pfpPtr, art::Event &Event, reco::shower::ShowerElementHolder &ShowerEleHolder)
Definition: IShowerTool.h:74
void AddSingle(A &a, B &b, std::string Name)
Definition: IShowerTool.h:152
virtual void InitialiseProducers()
Definition: IShowerTool.h:62
Reconstruction base classes.
int GetVectorPtrSize(std::string Name)
Definition: IShowerTool.h:158
reco::shower::ShowerProducedPtrsHolder * UniquePtrs
Definition: IShowerTool.h:85
art::ProducesCollector * collectorPtr
Definition: IShowerTool.h:97
int RunShowerTool(const art::Ptr< recob::PFParticle > &pfparticle, art::Event &Event, reco::shower::ShowerElementHolder &ShowerEleHolder, std::string evd_display_name_append="")
Definition: IShowerTool.h:46
void PrintPtr(const std::string &Name) const
bool CheckUniqueProduerPtr(const std::string &Name) const
void InitaliseProducerPtr(reco::shower::ShowerProducedPtrsHolder &uniqueproducerPtrs)
Definition: IShowerTool.h:68
void PrintPtr(std::string Name)
Definition: IShowerTool.h:162
void produces(std::string const &instanceName={}, Persistable const persistable=Persistable::Yes)
void AddSingle(A &a, B &b, const std::string &Name)
parameter set interface
art::Ptr< T > GetProducedElementPtr(std::string Name, reco::shower::ShowerElementHolder &ShowerEleHolder, int iter=-1)
Definition: IShowerTool.h:102
bool CheckElement(const std::string &Name) const
const shower::LArPandoraShowerAlg & GetLArPandoraShowerAlg() const
Definition: IShowerTool.h:82
void InitialiseProduct(std::string Name, std::string InstanceName="")
Definition: IShowerTool.h:137
decltype(auto) get(T &&obj)
ADL-aware version of std::to_string.
Definition: StdUtils.h:120
IShowerTool(const fhicl::ParameterSet &pset)
Definition: IShowerTool.h:33
shower::LArPandoraShowerAlg fLArPandoraShowerAlg
Definition: IShowerTool.h:92
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
void SetPtr(art::ProducesCollector *collector)
Definition: IShowerTool.h:65
Definition: MVAAlg.h:12
art::Ptr< T > GetArtPtr(const std::string &Name, const int &iter) const
int SetShowerUniqueProduerPtr(type< T >, const std::string &Name, const std::string &Instance="")
int GetVectorPtrSize(const std::string &Name) const
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33