Public Member Functions | Private Member Functions | Private Attributes | List of all members
ShowerRecoTools::ShowerExampleTool Class Reference
Inheritance diagram for ShowerRecoTools::ShowerExampleTool:
ShowerRecoTools::IShowerTool

Public Member Functions

 ShowerExampleTool (const fhicl::ParameterSet &pset)
 
int CalculateElement (const art::Ptr< recob::PFParticle > &pfparticle, art::Event &Event, reco::shower::ShowerElementHolder &ShowerEleHolder) override
 
- Public Member Functions inherited from ShowerRecoTools::IShowerTool
 IShowerTool (const fhicl::ParameterSet &pset)
 
virtual ~IShowerTool () noexcept=default
 
int RunShowerTool (const art::Ptr< recob::PFParticle > &pfparticle, art::Event &Event, reco::shower::ShowerElementHolder &ShowerEleHolder, std::string evd_display_name_append="")
 
void SetPtr (art::ProducesCollector *collector)
 
void InitaliseProducerPtr (reco::shower::ShowerProducedPtrsHolder &uniqueproducerPtrs)
 

Private Member Functions

void InitialiseProducers () override
 
int AddAssociations (const art::Ptr< recob::PFParticle > &pfpPtr, art::Event &Event, reco::shower::ShowerElementHolder &ShowerEleHolder) override
 

Private Attributes

art::InputTag fPFParticleLabel
 
int fVerbose
 

Additional Inherited Members

- Protected Member Functions inherited from ShowerRecoTools::IShowerTool
const shower::LArPandoraShowerAlgGetLArPandoraShowerAlg () const
 
template<class T >
art::Ptr< T > GetProducedElementPtr (std::string Name, reco::shower::ShowerElementHolder &ShowerEleHolder, int iter=-1)
 
template<class T >
void InitialiseProduct (std::string Name, std::string InstanceName="")
 
template<class T , class A , class B >
void AddSingle (A &a, B &b, std::string Name)
 
int GetVectorPtrSize (std::string Name)
 
void PrintPtrs ()
 
void PrintPtr (std::string Name)
 

Detailed Description

Definition at line 18 of file ShowerExampleTool_tool.cc.

Constructor & Destructor Documentation

ShowerRecoTools::ShowerExampleTool::ShowerExampleTool ( const fhicl::ParameterSet pset)

Definition at line 42 of file ShowerExampleTool_tool.cc.

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  {}
T get(std::string const &key) const
Definition: ParameterSet.h:271
IShowerTool(const fhicl::ParameterSet &pset)
Definition: IShowerTool.h:28

Member Function Documentation

int ShowerRecoTools::ShowerExampleTool::AddAssociations ( const art::Ptr< recob::PFParticle > &  pfpPtr,
art::Event Event,
reco::shower::ShowerElementHolder ShowerEleHolder 
)
overrideprivatevirtual

Reimplemented from ShowerRecoTools::IShowerTool.

Definition at line 137 of file ShowerExampleTool_tool.cc.

140  {
141  //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.
142 
143  //First check the element has been set
144  if (!ShowerEleHolder.CheckElement("myvertex")) {
145  if (fVerbose) mf::LogError("ShowerExampleTooAddAssn") << "vertex not set." << std::endl;
146  return 1;
147  }
148 
149  //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.
150  int ptrsize = GetVectorPtrSize("myvertex");
151 
152  const art::Ptr<recob::Vertex> vertexptr =
153  GetProducedElementPtr<recob::Vertex>("myvertex", ShowerEleHolder, ptrsize);
154  const art::Ptr<recob::Shower> showerptr =
155  GetProducedElementPtr<recob::Shower>("shower", ShowerEleHolder);
156  AddSingle<art::Assns<recob::Shower, recob::Vertex>>(showerptr, vertexptr, "myvertexassan");
157 
158  return 0;
159  }
int GetVectorPtrSize(std::string Name)
Definition: IShowerTool.h:167
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
bool CheckElement(const std::string &Name) const
QTextStream & endl(QTextStream &s)
int ShowerRecoTools::ShowerExampleTool::CalculateElement ( const art::Ptr< recob::PFParticle > &  pfparticle,
art::Event Event,
reco::shower::ShowerElementHolder ShowerEleHolder 
)
overridevirtual

Implements ShowerRecoTools::IShowerTool.

Definition at line 60 of file ShowerExampleTool_tool.cc.

63  {
64 
65  //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
66 
67  //Now we are calculating the property of the shower like pfparticle. You have access to everything in the event. Maybe you want the vertex.
68 
69  auto const vtxHandle = Event.getValidHandle<std::vector<recob::Vertex>>(fPFParticleLabel);
70  std::vector<art::Ptr<recob::Vertex>> vertices;
71  art::fill_ptr_vector(vertices, vtxHandle);
72 
73  //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:
74  bool shower_direction_set = ShowerEleHolder.CheckElement("ShowerDirection");
75 
76  TVector3 ShowerDirection = {-999, -999, -999};
77 
78  //Then you can go and get that element if you want to use it and fill it in for you.
79  if (shower_direction_set) { ShowerEleHolder.GetElement("ShowerDirection", ShowerDirection); }
80 
81  //Do some crazy physics - Some legacy code in here for ease.
82  art::Ptr<recob::Vertex> proposed_vertex = vertices[0];
83  double xyz[3] = {-999, -999, -999};
84  proposed_vertex->XYZ(xyz);
85 
86  if (ShowerDirection.X() < 0) {
87  xyz[0] = -xyz[0];
88  xyz[1] = -xyz[1];
89  xyz[2] = -xyz[2];
90  }
91  recob::Vertex new_vertex = recob::Vertex(xyz);
92  TVector3 recobshower_vertex = {xyz[0], xyz[1], xyz[2]};
93  TVector3 recobshower_err = {xyz[0] * 0.1, xyz[1] * 0.1, xyz[2] * 0.1};
94  //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.
95  ShowerEleHolder.SetElement(recobshower_vertex, recobshower_err, "ShowerStartPosition");
96 
97  //You can also set the same element with a different name so that you can compare downstream two tools.
98  //The standard is to actually define the name in fcl.
99  ShowerEleHolder.SetElement(
100  recobshower_vertex, recobshower_err, "ShowerExampleTool_ShowerStartPosition");
101 
102  //Or you can set one of the save elements
103  ShowerEleHolder.SetElement(new_vertex, "myvertex");
104 
105  //Or a new unsave one.
106  std::vector<double> xyz_vec = {xyz[0], xyz[1], xyz[2]};
107  ShowerEleHolder.SetElement(xyz_vec, "xyz");
108 
109  //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.
110  ShowerEleHolder.SetElement(xyz_vec, "xyz", true);
111 
112  //You can see if an element will be checked before the shower is save with
113  bool will_be_checked = ShowerEleHolder.CheckElementTag("xyz");
114 
115  if (will_be_checked) { std::cout << "Element checked at save time" << std::endl; }
116 
117  //You can also changed the tag.
118  ShowerEleHolder.SetElementTag("xyz", false);
119 
120  //Note: Elements that are actually saved because you defined them in InitialiseProducers will be checked regardless. We don't want you saving nothign now.
121 
122  //You can also get the shower number that you are current one (the first shower number is 0).
123  int showernum = ShowerEleHolder.GetShowerNumber();
124  if (fVerbose > 1) std::cout << "You on are shower: " << showernum << std::endl;
125 
126  //You can also read out what ptr are set and what elements are set:.
127  PrintPtrs();
128  PrintPtr("myvertex");
129  ShowerEleHolder.PrintElements();
130 
131  //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.
132 
133  return 0;
134  }
void XYZ(double *xyz) const
Legacy method to access vertex position, preserved to avoid breaking code. Please try to use Vertex::...
Definition: Vertex.cxx:36
void SetElement(T &dataproduct, const std::string &Name, bool checktag=false)
void SetElementTag(const std::string &Name, bool checkelement)
Definition of vertex object for LArSoft.
Definition: Vertex.h:35
void PrintPtr(std::string Name)
Definition: IShowerTool.h:179
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
bool CheckElement(const std::string &Name) const
bool CheckElementTag(const std::string &Name) const
int GetElement(const std::string &Name, T &Element) const
boost::graph_traits< ModuleGraph >::vertex_descriptor Vertex
Definition: ModuleGraph.h:25
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:297
QTextStream & endl(QTextStream &s)
void ShowerRecoTools::ShowerExampleTool::InitialiseProducers ( )
overrideprivatevirtual

Reimplemented from ShowerRecoTools::IShowerTool.

Definition at line 50 of file ShowerExampleTool_tool.cc.

51  {
52  //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.
53  InitialiseProduct<std::vector<recob::Vertex>>("myvertex");
54 
55  //We can also do associations
56  InitialiseProduct<art::Assns<recob::Shower, recob::Vertex>>("myvertexassan");
57  }

Member Data Documentation

art::InputTag ShowerRecoTools::ShowerExampleTool::fPFParticleLabel
private

Definition at line 38 of file ShowerExampleTool_tool.cc.

int ShowerRecoTools::ShowerExampleTool::fVerbose
private

Definition at line 39 of file ShowerExampleTool_tool.cc.


The documentation for this class was generated from the following file: