All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 { class PFParticle; }
18 
19 //Framwork Includes
20 #include "art/Framework/Core/ProducesCollector.h"
21 namespace art { class Event; }
22 #include "canvas/Persistency/Common/Ptr.h"
23 #include "fhiclcpp/ParameterSet.h"
24 
25 namespace ShowerRecoTools {
26  class IShowerTool {
27 
28  public:
29  IShowerTool(const fhicl::ParameterSet& pset)
30  : fLArPandoraShowerAlg(pset.get<fhicl::ParameterSet>("LArPandoraShowerAlg"))
31  , fRunEventDisplay(pset.get<bool>("EnableEventDisplay")){};
32 
33  virtual ~IShowerTool() noexcept = default;
34 
35  //Generic Elemnt Finder. Used to calculate thing about the shower.
36  virtual int CalculateElement(const art::Ptr<recob::PFParticle>& pfparticle,
37  art::Event& Event,
38  reco::shower::ShowerElementHolder& ShowerEleHolder) = 0;
39 
40  //Main function that runs the shower tool. This includes running the derived function
41  //that calculates the shower element and also runs the event display if requested
42  int
43  RunShowerTool(const art::Ptr<recob::PFParticle>& pfparticle,
44  art::Event& Event,
45  reco::shower::ShowerElementHolder& ShowerEleHolder,
46  std::string evd_display_name_append = "")
47  {
48 
49  int calculation_status = CalculateElement(pfparticle, Event, ShowerEleHolder);
50  if (calculation_status != 0) return calculation_status;
51  if (fRunEventDisplay) {
53  pfparticle, Event, ShowerEleHolder, evd_display_name_append);
54  }
55  return calculation_status;
56  }
57 
58  //Function to initialise the producer i.e produces<std::vector<recob::Vertex> >(); commands go here.
59  virtual void
61  {}
62 
63  //Set the point looking back at the producer module show we can make things in the module
64  void
65  SetPtr(art::ProducesCollector* collector)
66  {
67  collectorPtr = collector;
68  }
69 
70  //Initialises the unique ptr holder so that the tool can access it behind the scenes.
71  void
73  {
74  UniquePtrs = &uniqueproducerPtrs;
75  }
76 
77  //End function so the user can add associations
78  virtual int
79  AddAssociations(const art::Ptr<recob::PFParticle>& pfpPtr,
80  art::Event& Event,
81  reco::shower::ShowerElementHolder& ShowerEleHolder)
82  {
83  return 0;
84  }
85 
86  protected:
89  {
90  return fLArPandoraShowerAlg;
91  };
92 
93  private:
94  //ptr to the holder of all the unique ptrs.
96 
97  //Algorithm functions
99 
100  //Flags
102 
103  art::ProducesCollector* collectorPtr;
104 
105  protected:
106  //Function to return the art:ptr for the corrsponding index iter. This allows the user the make associations
107  template <class T>
108  art::Ptr<T>
110  reco::shower::ShowerElementHolder& ShowerEleHolder,
111  int iter = -1)
112  {
113 
114  //Check the element has been set
115  bool check_element = ShowerEleHolder.CheckElement(Name);
116  if (!check_element) {
117  throw cet::exception("IShowerTool") << "tried to get a element that does not exist. Failed "
118  "at making the art ptr for Element: "
119  << Name << std::endl;
120  }
121 
122  //Check the unique ptr has been set.
123  bool check_ptr = UniquePtrs->CheckUniqueProduerPtr(Name);
124  if (!check_ptr) {
125  throw cet::exception("IShowerTool")
126  << "tried to get a ptr that does not exist. Failed at making the art ptr for Element"
127  << Name;
128  }
129 
130  //Check if the user has defined an index if not just use the current shower index/
131  int index;
132  if (iter != -1) { index = iter; }
133  else {
134  index = ShowerEleHolder.GetShowerNumber();
135  }
136 
137  //Make the ptr
138  return UniquePtrs->GetArtPtr<T>(Name, index);
139  }
140 
141  //Function so that the user can add products to the art event. This will set up the unique ptrs and the ptr makers required.
142  //Example: InitialiseProduct<std::vector<recob<vertex>>("MyVertex")
143  template <class T>
144  void
145  InitialiseProduct(std::string Name, std::string InstanceName = "")
146  {
147 
148  if (collectorPtr == nullptr) {
149  mf::LogWarning("IShowerTool") << "The art::ProducesCollector ptr has not been set";
150  return;
151  }
152 
153  collectorPtr->produces<T>(InstanceName);
154  UniquePtrs->SetShowerUniqueProduerPtr(type<T>(), Name, InstanceName);
155  }
156 
157  //Function so that the user can add assocations to the event.
158  //Example: AddSingle<art::Assn<recob::Vertex,recob::shower>((art::Ptr<recob::Vertex>) Vertex, (art::Prt<recob::shower>) Shower), "myassn")
159  template <class T, class A, class B>
160  void
161  AddSingle(A& a, B& b, std::string Name)
162  {
163  UniquePtrs->AddSingle<T>(a, b, Name);
164  }
165 
166  //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.
167  int
168  GetVectorPtrSize(std::string Name)
169  {
170  return UniquePtrs->GetVectorPtrSize(Name);
171  }
172 
173  void
175  {
177  }
178 
179  void
180  PrintPtr(std::string Name)
181  {
182  UniquePtrs->PrintPtr(Name);
183  }
184  };
185 }
186 
187 #endif
virtual int AddAssociations(const art::Ptr< recob::PFParticle > &pfpPtr, art::Event &Event, reco::shower::ShowerElementHolder &ShowerEleHolder)
Definition: IShowerTool.h:79
void AddSingle(A &a, B &b, std::string Name)
Definition: IShowerTool.h:161
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
Definition: UtilFunc.cxx:42
virtual void InitialiseProducers()
Definition: IShowerTool.h:60
void DebugEVD(art::Ptr< recob::PFParticle > const &pfparticle, art::Event const &Event, const reco::shower::ShowerElementHolder &ShowerEleHolder, std::string const &evd_disp_name_append="") const
int GetVectorPtrSize(std::string Name)
Definition: IShowerTool.h:168
reco::shower::ShowerProducedPtrsHolder * UniquePtrs
Definition: IShowerTool.h:91
art::ProducesCollector * collectorPtr
Definition: IShowerTool.h:103
static constexpr bool
int RunShowerTool(const art::Ptr< recob::PFParticle > &pfparticle, art::Event &Event, reco::shower::ShowerElementHolder &ShowerEleHolder, std::string evd_display_name_append="")
Definition: IShowerTool.h:43
void PrintPtr(const std::string &Name) const
process_name shower
Definition: cheaterreco.fcl:51
bool CheckUniqueProduerPtr(const std::string &Name) const
process_name gaushit a
virtual int CalculateElement(const art::Ptr< recob::PFParticle > &pfparticle, art::Event &Event, reco::shower::ShowerElementHolder &ShowerEleHolder)=0
void InitaliseProducerPtr(reco::shower::ShowerProducedPtrsHolder &uniqueproducerPtrs)
Definition: IShowerTool.h:72
void PrintPtr(std::string Name)
Definition: IShowerTool.h:180
process_name standard_reco_uboone reco
void AddSingle(A &a, B &b, const std::string &Name)
BEGIN_PROLOG default
art::Ptr< T > GetProducedElementPtr(std::string Name, reco::shower::ShowerElementHolder &ShowerEleHolder, int iter=-1)
Definition: IShowerTool.h:109
bool CheckElement(const std::string &Name) const
BEGIN_PROLOG vertical distance to the surface Name
virtual ~IShowerTool() noexcept=default
const shower::LArPandoraShowerAlg & GetLArPandoraShowerAlg() const
Definition: IShowerTool.h:88
void InitialiseProduct(std::string Name, std::string InstanceName="")
Definition: IShowerTool.h:145
IShowerTool(const fhicl::ParameterSet &pset)
Definition: IShowerTool.h:29
shower::LArPandoraShowerAlg fLArPandoraShowerAlg
Definition: IShowerTool.h:98
void SetPtr(art::ProducesCollector *collector)
Definition: IShowerTool.h:65
art::Ptr< T > GetArtPtr(const std::string &Name, const int &iter) const
float A
Definition: dedx.py:137
int SetShowerUniqueProduerPtr(type< T >, const std::string &Name, const std::string &Instance="")
int GetVectorPtrSize(const std::string &Name) const