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