Pandora
Pandora source code navigator
Loading...
Searching...
No Matches
ShowerExampleTool_tool.cc
Go to the documentation of this file.
1//############################################################################
2//### Name: ShowerExampleTool ###
3//### Author: Dominic Barker (dominic.barker@sheffield.ac.uk ###
4//### Date: 26.06.19 ###
5//### Description: Example form of the shower tools ###
6//############################################################################
7
8//Framework Includes
9#include "art/Utilities/ToolMacros.h"
10
11//LArSoft Includes
12#include "lardataobj/RecoBase/Shower.h"
13#include "lardataobj/RecoBase/Vertex.h"
15
16namespace ShowerRecoTools {
17
19
20 public:
21 ShowerExampleTool(const fhicl::ParameterSet& pset);
22
23 //Example Direction Finder
24 int CalculateElement(const art::Ptr<recob::PFParticle>& pfparticle,
25 art::Event& Event,
26 reco::shower::ShowerElementHolder& ShowerEleHolder) override;
27
28 private:
29 //Function to initialise the producer i.e produces<std::vector<recob::Vertex> >(); commands go here.
30 void InitialiseProducers() override;
31
32 //Function to add the assoctions
33 int AddAssociations(const art::Ptr<recob::PFParticle>& pfpPtr,
34 art::Event& Event,
35 reco::shower::ShowerElementHolder& ShowerEleHolder) override;
36
37 //prehaps you want a fcl parameter.
38 art::InputTag fPFParticleLabel;
40 };
41
42 ShowerExampleTool::ShowerExampleTool(const fhicl::ParameterSet& pset)
43 : //Setup the algs and others here
44 IShowerTool(pset.get<fhicl::ParameterSet>("BaseTools"))
45 , fPFParticleLabel(pset.get<art::InputTag>("PFParticleLabel"))
46 , fVerbose(pset.get<int>("Verbose"))
47 {}
48
50 {
51 //Do you create something and you want to save it the event. Initialsie here. For every event with have a vector of showers so each one has a vertex. This is what we are saving. Make sure to use the name "myvertex" later down the line.
52 InitialiseProduct<std::vector<recob::Vertex>>("myvertex");
53
54 //We can also do associations
55 InitialiseProduct<art::Assns<recob::Shower, recob::Vertex>>("myvertexassan");
56 }
57
58 int ShowerExampleTool::CalculateElement(const art::Ptr<recob::PFParticle>& pfparticle,
59 art::Event& Event,
60 reco::shower::ShowerElementHolder& ShowerEleHolder)
61 {
62
63 //In here calculate a shower or element (or multiple). It can be something used to create the recob::shower i.e. the direction. These have specific names so be careful to make these correctly. Alternative you can create something completely new e.g. recob::Vertex and add it the shower element holder
64
65 //Now we are calculating the property of the shower like pfparticle. You have access to everything in the event. Maybe you want the vertex.
66
67 auto const vtxHandle = Event.getValidHandle<std::vector<recob::Vertex>>(fPFParticleLabel);
68 std::vector<art::Ptr<recob::Vertex>> vertices;
69 art::fill_ptr_vector(vertices, vtxHandle);
70
71 //Remember the module goes through the tools and if you want to (fcl param) it will loop over them twice. You can check to see if a element has been set with a specific name:
72 bool shower_direction_set = ShowerEleHolder.CheckElement("ShowerDirection");
73
74 geo::Vector_t ShowerDirection = {-999, -999, -999};
75
76 //Then you can go and get that element if you want to use it and fill it in for you.
77 if (shower_direction_set) { ShowerEleHolder.GetElement("ShowerDirection", ShowerDirection); }
78
79 //Do some crazy physics - Some legacy code in here for ease.
80 recob::Vertex const& proposed_vertex = *vertices[0];
81 auto pos = proposed_vertex.position();
82
83 if (ShowerDirection.X() < 0) { pos *= -1.; }
84 recob::Vertex new_vertex{pos, {}, util::kBogusD, util::kBogusI};
85 geo::Point_t recobshower_err = pos * 0.1;
86 //You can set elements of the recob::shower just choose the right name (you can acess them later). You can give the property an error anf this must be done the for standard recob::shower properties; The standard is to access the name via a fcl file.
87 ShowerEleHolder.SetElement(pos, recobshower_err, "ShowerStartPosition");
88
89 //You can also set the same element with a different name so that you can compare downstream two tools.
90 //The standard is to actually define the name in fcl.
91 ShowerEleHolder.SetElement(pos, recobshower_err, "ShowerExampleTool_ShowerStartPosition");
92
93 //Or you can set one of the save elements
94 ShowerEleHolder.SetElement(new_vertex, "myvertex");
95
96 //Or a new unsave one.
97 std::vector<double> xyz_vec = {pos.X(), pos.Y(), pos.Z()};
98 ShowerEleHolder.SetElement(xyz_vec, "xyz");
99
100 //If you want to check if your element was actually made before the shower is made you can set a bool. If partial showers is turned off then the shower will not be made if this element is not filled. Properties i.e. elements with errors i.e. ShowerStartPosition will not be checked. There is no way to store properties in the Event, only products are stored. You can make your own class which holds the error. The defualt is not to check the element. The recob::shower properties are checked however.
101 ShowerEleHolder.SetElement(xyz_vec, "xyz", true);
102
103 //You can see if an element will be checked before the shower is save with
104 bool will_be_checked = ShowerEleHolder.CheckElementTag("xyz");
105
106 if (will_be_checked) { std::cout << "Element checked at save time" << std::endl; }
107
108 //You can also changed the tag.
109 ShowerEleHolder.SetElementTag("xyz", false);
110
111 //Note: Elements that are actually saved because you defined them in InitialiseProducers will be checked regardless. We don't want you saving nothign now.
112
113 //You can also get the shower number that you are current one (the first shower number is 0).
114 int showernum = ShowerEleHolder.GetShowerNumber();
115 if (fVerbose > 1) std::cout << "You on are shower: " << showernum << std::endl;
116
117 //You can also read out what ptr are set and what elements are set:.
118 PrintPtrs();
119 PrintPtr("myvertex");
120 ShowerEleHolder.PrintElements();
121
122 //Remember to add make a new fcl parmas list for your new tool. For examles see showertools.fcl. And remember to add it the the list in the module fcl params list.
123
124 return 0;
125 }
126
127 int ShowerExampleTool::AddAssociations(const art::Ptr<recob::PFParticle>& pfpPtr,
128 art::Event& Event,
129 reco::shower::ShowerElementHolder& ShowerEleHolder)
130 {
131 //Here you add elements to associations defined. You can get the art::Ptrs by GetProducedElementPtr<T>. Then you can add single like a usally association using AddSingle<assn<T>. Assn below.
132
133 //First check the element has been set
134 if (!ShowerEleHolder.CheckElement("myvertex")) {
135 if (fVerbose) mf::LogError("ShowerExampleTooAddAssn") << "vertex not set." << std::endl;
136 return 1;
137 }
138
139 //Then you can get the size of the vector which the unique ptr hold so that you can do associations. If you are comfortable in the fact that your element will always be made when a shower is made you don't need to to do this you can just get the art ptr as: const art::Ptr<recob::Vertex> vertexptr = GetProducedElementPtr<recob::Vertex>("myvertex", ShowerEleHolder);. Note doing this when you allow partial showers to be set can screw up the assocation for the partial shower.
140 int ptrsize = GetVectorPtrSize("myvertex");
141
142 const art::Ptr<recob::Vertex> vertexptr =
143 GetProducedElementPtr<recob::Vertex>("myvertex", ShowerEleHolder, ptrsize);
144 const art::Ptr<recob::Shower> showerptr =
145 GetProducedElementPtr<recob::Shower>("shower", ShowerEleHolder);
146 AddSingle<art::Assns<recob::Shower, recob::Vertex>>(showerptr, vertexptr, "myvertexassan");
147
148 return 0;
149 }
150}
151
152DEFINE_ART_CLASS_TOOL(ShowerRecoTools::ShowerExampleTool)
int GetVectorPtrSize(std::string Name)
void PrintPtr(std::string Name)
int CalculateElement(const art::Ptr< recob::PFParticle > &pfparticle, art::Event &Event, reco::shower::ShowerElementHolder &ShowerEleHolder) override
int AddAssociations(const art::Ptr< recob::PFParticle > &pfpPtr, art::Event &Event, reco::shower::ShowerElementHolder &ShowerEleHolder) override
ShowerExampleTool(const fhicl::ParameterSet &pset)
int GetElement(const std::string &Name, T &Element) const
void SetElementTag(const std::string &Name, bool checkelement)
bool CheckElementTag(const std::string &Name) const
void SetElement(T &dataproduct, const std::string &Name, bool checktag=false)
bool CheckElement(const std::string &Name) const