Pandora
Pandora source code navigator
Loading...
Searching...
No Matches
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
17namespace recob {
18 class PFParticle;
19}
20
21//Framwork Includes
22#include "art/Framework/Core/ProducesCollector.h"
23namespace art {
24 class Event;
25}
26#include "canvas/Persistency/Common/Ptr.h"
27#include "fhiclcpp/ParameterSet.h"
28
29namespace ShowerRecoTools {
31
32 public:
33 IShowerTool(const fhicl::ParameterSet& pset)
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
46 int RunShowerTool(const art::Ptr<recob::PFParticle>& pfparticle,
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) {
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:
86
87 private:
88 //ptr to the holder of all the unique ptrs.
90
91 //Algorithm functions
93
94 //Flags
96
97 art::ProducesCollector* collectorPtr;
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>
102 art::Ptr<T> GetProducedElementPtr(std::string Name,
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
161
162 void PrintPtr(std::string Name) { UniquePtrs->PrintPtr(Name); }
163 };
164}
165
166#endif
int GetVectorPtrSize(std::string Name)
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
art::Ptr< T > GetProducedElementPtr(std::string Name, reco::shower::ShowerElementHolder &ShowerEleHolder, int iter=-1)
reco::shower::ShowerProducedPtrsHolder * UniquePtrs
Definition IShowerTool.h:89
virtual void InitialiseProducers()
Definition IShowerTool.h:62
void PrintPtr(std::string Name)
IShowerTool(const fhicl::ParameterSet &pset)
Definition IShowerTool.h:33
void SetPtr(art::ProducesCollector *collector)
Definition IShowerTool.h:65
void InitialiseProduct(std::string Name, std::string InstanceName="")
void InitaliseProducerPtr(reco::shower::ShowerProducedPtrsHolder &uniqueproducerPtrs)
Definition IShowerTool.h:68
virtual ~IShowerTool() noexcept=default
shower::LArPandoraShowerAlg fLArPandoraShowerAlg
Definition IShowerTool.h:92
void AddSingle(A &a, B &b, std::string Name)
virtual int CalculateElement(const art::Ptr< recob::PFParticle > &pfparticle, art::Event &Event, reco::shower::ShowerElementHolder &ShowerEleHolder)=0
virtual int AddAssociations(const art::Ptr< recob::PFParticle > &pfpPtr, art::Event &Event, reco::shower::ShowerElementHolder &ShowerEleHolder)
Definition IShowerTool.h:74
art::ProducesCollector * collectorPtr
Definition IShowerTool.h:97
const shower::LArPandoraShowerAlg & GetLArPandoraShowerAlg() const
Definition IShowerTool.h:82
bool CheckElement(const std::string &Name) const
void PrintPtr(const std::string &Name) const
int GetVectorPtrSize(const std::string &Name) const
void AddSingle(A &a, B &b, const std::string &Name)
art::Ptr< T > GetArtPtr(const std::string &Name, const int &iter) const
int SetShowerUniqueProduerPtr(type< T >, const std::string &Name, const std::string &Instance="")
bool CheckUniqueProduerPtr(const std::string &Name) const
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