Pandora
Pandora source code navigator
Loading...
Searching...
No Matches
ShowerPCAEigenvalueLength_tool.cc
Go to the documentation of this file.
1//############################################################################
2//### Name: ShowerPCAEigenvalueLength ###
3//### Author: Ed Tyley ###
4//### Date: 07.01.20 ###
5//### Description: Simple code to calculate the lenght from the PCA ###
6//### eigenvalues ###
7//############################################################################
8
9//Framework Includes
10#include "art/Utilities/ToolMacros.h"
11
12//LArSoft Includes
13#include "lardataobj/RecoBase/PCAxis.h"
15
16namespace ShowerRecoTools {
17
19
20 public:
21 ShowerPCAEigenvalueLength(const fhicl::ParameterSet& pset);
22
23 //Generic 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 art::InputTag fPFParticleLabel;
34 float fNSigma;
35 };
36
38 : IShowerTool(pset.get<fhicl::ParameterSet>("BaseTools"))
39 , fPFParticleLabel(pset.get<art::InputTag>("PFParticleLabel"))
40 , fVerbose(pset.get<int>("Verbose"))
41 , fShowerPCAInputLabel(pset.get<std::string>("ShowerPCAInputLabel"))
42 , fShowerLengthOutputLabel(pset.get<std::string>("ShowerLengthOutputLabel"))
43 , fShowerOpeningAngleOutputLabel(pset.get<std::string>("ShowerOpeningAngleOutputLabel"))
44 , fNSigma(pset.get<float>("NSigma"))
45 {}
46
48 const art::Ptr<recob::PFParticle>& pfparticle,
49 art::Event& Event,
50 reco::shower::ShowerElementHolder& ShowerEleHolder)
51 {
52
53 if (!ShowerEleHolder.CheckElement(fShowerPCAInputLabel)) {
54 if (fVerbose)
55 mf::LogError("ShowerPCAEigenvalueLength") << "PCA not set, returning " << std::endl;
56 return 1;
57 }
58
59 recob::PCAxis PCA = recob::PCAxis();
60 ShowerEleHolder.GetElement(fShowerPCAInputLabel, PCA);
61
62 const double* eigenValues = PCA.getEigenValues();
63
64 // The PCA eigenvalues give the deviance of space points around the center
65 // Take the sqrt to get std. dev and take fNSigma in each direction:
66 // Call the length fNSigma x 2 x std. dev. along primary eigenvalues
67 // Call the width fNSigma x 2 x std. dev. along secondary eigenvalues
68
69 //TODO: Actually calculate the erros (Maybe fNSigma+-1Sigma?)
70
71 //Find the length
72 double primaryEigenValue = (eigenValues)[0];
73 double ShowerLength = std::sqrt(primaryEigenValue) * 2 * fNSigma;
74 double ShowerLengthError = -999;
75
76 //Find the width of the shower
77 double secondaryEigenValue = (eigenValues)[1];
78 double ShowerWidth = std::sqrt(secondaryEigenValue) * 2 * fNSigma;
79
80 double ShowerAngle = std::atan(ShowerWidth / ShowerLength);
81 double ShowerAngleError = -999;
82
83 // Fill the shower element holder
84 ShowerEleHolder.SetElement(ShowerLength, ShowerLengthError, fShowerLengthOutputLabel);
85 ShowerEleHolder.SetElement(ShowerAngle, ShowerAngleError, fShowerOpeningAngleOutputLabel);
86
87 return 0;
88 }
89}
90
int CalculateElement(const art::Ptr< recob::PFParticle > &pfparticle, art::Event &Event, reco::shower::ShowerElementHolder &ShowerEleHolder) override
int GetElement(const std::string &Name, T &Element) const
void SetElement(T &dataproduct, const std::string &Name, bool checktag=false)
bool CheckElement(const std::string &Name) const