LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
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
 
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)
 

Protected Member Functions

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)
 

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
 

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:314
IShowerTool(const fhicl::ParameterSet &pset)
Definition: IShowerTool.h:33

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 127 of file ShowerExampleTool_tool.cc.

References reco::shower::ShowerElementHolder::CheckElement(), DEFINE_ART_CLASS_TOOL, fVerbose, and ShowerRecoTools::IShowerTool::GetVectorPtrSize().

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  }
int GetVectorPtrSize(std::string Name)
Definition: IShowerTool.h:158
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
bool CheckElement(const std::string &Name) const
Definition: fwd.h:26
template<class T , class A , class B >
void ShowerRecoTools::IShowerTool::AddSingle ( A &  a,
B &  b,
std::string  Name 
)
inlineprotectedinherited

Definition at line 152 of file IShowerTool.h.

References reco::shower::ShowerProducedPtrsHolder::AddSingle().

153  {
154  UniquePtrs->AddSingle<T>(a, b, Name);
155  }
reco::shower::ShowerProducedPtrsHolder * UniquePtrs
Definition: IShowerTool.h:85
void AddSingle(A &a, B &b, const std::string &Name)
int ShowerRecoTools::ShowerExampleTool::CalculateElement ( const art::Ptr< recob::PFParticle > &  pfparticle,
art::Event Event,
reco::shower::ShowerElementHolder ShowerEleHolder 
)
overridevirtual

Implements ShowerRecoTools::IShowerTool.

Definition at line 58 of file ShowerExampleTool_tool.cc.

References reco::shower::ShowerElementHolder::CheckElement(), reco::shower::ShowerElementHolder::CheckElementTag(), art::fill_ptr_vector(), fPFParticleLabel, fVerbose, reco::shower::ShowerElementHolder::GetElement(), reco::shower::ShowerElementHolder::GetShowerNumber(), art::ProductRetriever::getValidHandle(), util::kBogusD, util::kBogusI, recob::Vertex::position(), reco::shower::ShowerElementHolder::PrintElements(), ShowerRecoTools::IShowerTool::PrintPtr(), ShowerRecoTools::IShowerTool::PrintPtrs(), reco::shower::ShowerElementHolder::SetElement(), and reco::shower::ShowerElementHolder::SetElementTag().

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  }
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space.
Definition: geo_vectors.h:160
void SetElement(T &dataproduct, const std::string &Name, bool checktag=false)
void SetElementTag(const std::string &Name, bool checkelement)
constexpr int kBogusI
obviously bogus integer value
Definition of vertex object for LArSoft.
Definition: Vertex.h:35
void PrintPtr(std::string Name)
Definition: IShowerTool.h:162
bool CheckElement(const std::string &Name) const
bool CheckElementTag(const std::string &Name) const
int GetElement(const std::string &Name, T &Element) const
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
Definition: geo_vectors.h:180
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
constexpr double kBogusD
obviously bogus double value
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:306
const Point_t & position() const
Return vertex 3D position.
Definition: Vertex.h:64
const shower::LArPandoraShowerAlg& ShowerRecoTools::IShowerTool::GetLArPandoraShowerAlg ( ) const
inlineprotectedinherited

Definition at line 82 of file IShowerTool.h.

Referenced by ShowerRecoTools::ShowerLengthPercentile::CalculateElement(), ShowerRecoTools::ShowerUnidirectiondEdx::CalculateElement(), ShowerRecoTools::Shower3DCylinderTrackHitFinder::CalculateElement(), ShowerRecoTools::ShowerPCAPropergationStartPosition::CalculateElement(), ShowerRecoTools::Shower2DLinearRegressionTrackHitFinder::CalculateElement(), ShowerRecoTools::ShowerPFPVertexStartPosition::CalculateElement(), ShowerRecoTools::ShowerDirectionCheater::CalculateElement(), ShowerRecoTools::ShowerPCADirection::CalculateElement(), ShowerRecoTools::ShowerIncrementalTrackHitFinder::CalculateElement(), ShowerRecoTools::ShowerTrajPointdEdx::CalculateElement(), ShowerRecoTools::ShowerPCADirection::CalculateShowerPCA(), ShowerRecoTools::Shower2DLinearRegressionTrackHitFinder::FindInitialTrackHits(), ShowerRecoTools::Shower3DCylinderTrackHitFinder::FindTrackSpacePoints(), ShowerRecoTools::ShowerIncrementalTrackHitFinder::FitSegmentAndCalculateResidual(), ShowerRecoTools::ShowerIncrementalTrackHitFinder::PruneFrontOfSPSPool(), ShowerRecoTools::ShowerIncrementalTrackHitFinder::PruneTrack(), ShowerRecoTools::ShowerIncrementalTrackHitFinder::RunTestOfIncrementalSpacePointFinder(), ShowerRecoTools::ShowerTrackPCADirection::ShowerPCAVector(), and ShowerRecoTools::ShowerIncrementalTrackHitFinder::ShowerPCAVector().

83  {
84  return fLArPandoraShowerAlg;
85  };
shower::LArPandoraShowerAlg fLArPandoraShowerAlg
Definition: IShowerTool.h:92
template<class T >
art::Ptr<T> ShowerRecoTools::IShowerTool::GetProducedElementPtr ( std::string  Name,
reco::shower::ShowerElementHolder ShowerEleHolder,
int  iter = -1 
)
inlineprotectedinherited

Definition at line 102 of file IShowerTool.h.

References reco::shower::ShowerElementHolder::CheckElement(), reco::shower::ShowerProducedPtrsHolder::CheckUniqueProduerPtr(), reco::shower::ShowerProducedPtrsHolder::GetArtPtr(), and reco::shower::ShowerElementHolder::GetShowerNumber().

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  }
reco::shower::ShowerProducedPtrsHolder * UniquePtrs
Definition: IShowerTool.h:85
bool CheckUniqueProduerPtr(const std::string &Name) const
bool CheckElement(const std::string &Name) const
art::Ptr< T > GetArtPtr(const std::string &Name, const int &iter) const
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
int ShowerRecoTools::IShowerTool::GetVectorPtrSize ( std::string  Name)
inlineprotectedinherited
void ShowerRecoTools::IShowerTool::InitaliseProducerPtr ( reco::shower::ShowerProducedPtrsHolder uniqueproducerPtrs)
inlineinherited

Definition at line 68 of file IShowerTool.h.

69  {
70  UniquePtrs = &uniqueproducerPtrs;
71  }
reco::shower::ShowerProducedPtrsHolder * UniquePtrs
Definition: IShowerTool.h:85
void ShowerRecoTools::ShowerExampleTool::InitialiseProducers ( )
overrideprivatevirtual

Reimplemented from ShowerRecoTools::IShowerTool.

Definition at line 49 of file ShowerExampleTool_tool.cc.

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  }
template<class T >
void ShowerRecoTools::IShowerTool::InitialiseProduct ( std::string  Name,
std::string  InstanceName = "" 
)
inlineprotectedinherited

Definition at line 137 of file IShowerTool.h.

References art::ProducesCollector::produces(), and reco::shower::ShowerProducedPtrsHolder::SetShowerUniqueProduerPtr().

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  }
reco::shower::ShowerProducedPtrsHolder * UniquePtrs
Definition: IShowerTool.h:85
art::ProducesCollector * collectorPtr
Definition: IShowerTool.h:97
void produces(std::string const &instanceName={}, Persistable const persistable=Persistable::Yes)
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
int SetShowerUniqueProduerPtr(type< T >, const std::string &Name, const std::string &Instance="")
void ShowerRecoTools::IShowerTool::PrintPtr ( std::string  Name)
inlineprotectedinherited

Definition at line 162 of file IShowerTool.h.

References reco::shower::ShowerProducedPtrsHolder::PrintPtr().

Referenced by CalculateElement().

162 { UniquePtrs->PrintPtr(Name); }
reco::shower::ShowerProducedPtrsHolder * UniquePtrs
Definition: IShowerTool.h:85
void PrintPtr(const std::string &Name) const
void ShowerRecoTools::IShowerTool::PrintPtrs ( )
inlineprotectedinherited

Definition at line 160 of file IShowerTool.h.

References reco::shower::ShowerProducedPtrsHolder::PrintPtrs().

Referenced by CalculateElement().

160 { UniquePtrs->PrintPtrs(); }
reco::shower::ShowerProducedPtrsHolder * UniquePtrs
Definition: IShowerTool.h:85
int ShowerRecoTools::IShowerTool::RunShowerTool ( const art::Ptr< recob::PFParticle > &  pfparticle,
art::Event Event,
reco::shower::ShowerElementHolder ShowerEleHolder,
std::string  evd_display_name_append = "" 
)
inlineinherited

Definition at line 46 of file IShowerTool.h.

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  }
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
virtual int CalculateElement(const art::Ptr< recob::PFParticle > &pfparticle, art::Event &Event, reco::shower::ShowerElementHolder &ShowerEleHolder)=0
const shower::LArPandoraShowerAlg & GetLArPandoraShowerAlg() const
Definition: IShowerTool.h:82
void ShowerRecoTools::IShowerTool::SetPtr ( art::ProducesCollector collector)
inlineinherited

Definition at line 65 of file IShowerTool.h.

65 { collectorPtr = collector; }
art::ProducesCollector * collectorPtr
Definition: IShowerTool.h:97

Member Data Documentation

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

Definition at line 38 of file ShowerExampleTool_tool.cc.

Referenced by CalculateElement().

int ShowerRecoTools::ShowerExampleTool::fVerbose
private

Definition at line 39 of file ShowerExampleTool_tool.cc.

Referenced by AddAssociations(), and CalculateElement().


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