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
11 
12 //LArSoft Includes
15 
16 namespace ShowerRecoTools {
17 
19 
20  public:
22 
23  //Generic Direction Finder
24  int CalculateElement(const art::Ptr<recob::PFParticle>& pfparticle,
26  reco::shower::ShowerElementHolder& ShowerEleHolder) override;
27 
28  private:
30  int fVerbose;
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 
47  int
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 
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
const double * getEigenValues() const
Definition: PCAxis.h:65
ShowerPCAEigenvalueLength(const fhicl::ParameterSet &pset)
#define DEFINE_ART_CLASS_TOOL(tool)
Definition: ToolMacros.h:42
std::string string
Definition: nybbler.cc:12
void SetElement(T &dataproduct, const std::string &Name, bool checktag=false)
STL namespace.
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
bool CheckElement(const std::string &Name) const
int GetElement(const std::string &Name, T &Element) const
Definition: types.h:32
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
QTextStream & endl(QTextStream &s)