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

Public Member Functions

 ShowerTrackPCADirection (const fhicl::ParameterSet &pset)
 
int CalculateElement (const art::Ptr< recob::PFParticle > &pfparticle, art::Event &Event, reco::shower::ShowerElementHolder &ShowerEleHolder) override
 

Private Member Functions

TVector3 ShowerPCAVector (const detinfo::DetectorClocksData &clockData, const detinfo::DetectorPropertiesData &detProp, std::vector< art::Ptr< recob::SpacePoint >> &spacePoints_pfp, const art::FindManyP< recob::Hit > &fmh, TVector3 &ShowerCentre)
 
- Private 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="")
 
virtual void InitialiseProducers ()
 
void SetPtr (art::ProducesCollector *collector)
 
void InitaliseProducerPtr (reco::shower::ShowerProducedPtrsHolder &uniqueproducerPtrs)
 
virtual int AddAssociations (const art::Ptr< recob::PFParticle > &pfpPtr, art::Event &Event, reco::shower::ShowerElementHolder &ShowerEleHolder)
 
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 Attributes

art::InputTag fPFParticleLabel
 
art::InputTag fHitModuleLabel
 
int fVerbose
 
bool fChargeWeighted
 
unsigned int fMinPCAPoints
 
std::string fShowerStartPositionInputLabel
 
std::string fInitialTrackSpacePointsInputLabel
 
std::string fShowerDirectionOutputLabel
 

Detailed Description

Definition at line 20 of file ShowerTrackPCADirection_tool.cc.

Constructor & Destructor Documentation

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

Definition at line 49 of file ShowerTrackPCADirection_tool.cc.

50  : IShowerTool(pset.get<fhicl::ParameterSet>("BaseTools"))
51  , fPFParticleLabel(pset.get<art::InputTag>("PFParticleLabel"))
52  , fHitModuleLabel(pset.get<art::InputTag>("HitModuleLabel"))
53  , fVerbose(pset.get<int>("Verbose"))
54  , fChargeWeighted(pset.get<bool>("ChargeWeighted"))
55  , fMinPCAPoints(pset.get<unsigned int>("MinPCAPoints"))
56  , fShowerStartPositionInputLabel(pset.get<std::string>("ShowerStartPositionInputLabel"))
57  , fInitialTrackSpacePointsInputLabel(pset.get<std::string>("InitialTrackSpacePointsInputLabel"))
58  , fShowerDirectionOutputLabel(pset.get<std::string>("ShowerDirectionOutputLabel"))
59  {}
std::string string
Definition: nybbler.cc:12
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::ShowerTrackPCADirection::CalculateElement ( const art::Ptr< recob::PFParticle > &  pfparticle,
art::Event Event,
reco::shower::ShowerElementHolder ShowerEleHolder 
)
overridevirtual

Implements ShowerRecoTools::IShowerTool.

Definition at line 62 of file ShowerTrackPCADirection_tool.cc.

65  {
66 
67  if (!ShowerEleHolder.CheckElement(fShowerStartPositionInputLabel)) {
68  if (fVerbose)
69  mf::LogError("ShowerTrackPCA") << "Start Position not set. Stopping" << std::endl;
70  ;
71  return 1;
72  }
73  if (!ShowerEleHolder.CheckElement(fInitialTrackSpacePointsInputLabel)) {
74  if (fVerbose)
75  mf::LogError("ShowerTrackPCA") << "TrackSpacePoints not set, returning " << std::endl;
76  return 1;
77  }
78 
79  //Get the spacepoints handle and the hit assoication
80  auto const spHandle = Event.getValidHandle<std::vector<recob::SpacePoint>>(fPFParticleLabel);
81 
82  const art::FindManyP<recob::Hit>& fmh =
83  ShowerEleHolder.GetFindManyP<recob::Hit>(spHandle, Event, fPFParticleLabel);
84 
85  std::vector<art::Ptr<recob::SpacePoint>> trackSpacePoints;
86  ShowerEleHolder.GetElement(fInitialTrackSpacePointsInputLabel, trackSpacePoints);
87 
88  //We cannot progress with no spacepoints.
89  if (trackSpacePoints.size() < fMinPCAPoints) {
90  if (fVerbose)
91  mf::LogError("ShowerTrackPCA") << "Not enough spacepoints for PCA, returning " << std::endl;
92  return 1;
93  }
94 
95  auto const clockData =
97  auto const detProp =
99 
100  //Find the PCA vector
101  TVector3 trackCentre;
102  TVector3 Eigenvector = ShowerPCAVector(clockData, detProp, trackSpacePoints, fmh, trackCentre);
103 
104  //Get the General direction as the vector between the start position and the centre
105  TVector3 StartPositionVec = {-999, -999, -999};
106  ShowerEleHolder.GetElement(fShowerStartPositionInputLabel, StartPositionVec);
107  TVector3 GeneralDir = (trackCentre - StartPositionVec).Unit();
108 
109  //Dot product
110  double DotProduct = Eigenvector.Dot(GeneralDir);
111 
112  //If the dotproduct is negative the Direction needs Flipping
113  if (DotProduct < 0) {
114  Eigenvector[0] = -Eigenvector[0];
115  Eigenvector[1] = -Eigenvector[1];
116  Eigenvector[2] = -Eigenvector[2];
117  }
118 
119  TVector3 EigenvectorErr = {-999, -999, -999};
120 
121  ShowerEleHolder.SetElement(Eigenvector, EigenvectorErr, fShowerDirectionOutputLabel);
122 
123  return 0;
124  }
void SetElement(T &dataproduct, const std::string &Name, bool checktag=false)
const art::FindManyP< T1 > & GetFindManyP(const art::ValidHandle< std::vector< T2 > > &handle, const art::Event &evt, const art::InputTag &moduleTag)
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
bool CheckElement(const std::string &Name) const
int GetElement(const std::string &Name, T &Element) const
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:48
TVector3 ShowerPCAVector(const detinfo::DetectorClocksData &clockData, const detinfo::DetectorPropertiesData &detProp, std::vector< art::Ptr< recob::SpacePoint >> &spacePoints_pfp, const art::FindManyP< recob::Hit > &fmh, TVector3 &ShowerCentre)
QTextStream & endl(QTextStream &s)
TVector3 ShowerRecoTools::ShowerTrackPCADirection::ShowerPCAVector ( const detinfo::DetectorClocksData clockData,
const detinfo::DetectorPropertiesData detProp,
std::vector< art::Ptr< recob::SpacePoint >> &  spacePoints_pfp,
const art::FindManyP< recob::Hit > &  fmh,
TVector3 &  ShowerCentre 
)
private

Definition at line 128 of file ShowerTrackPCADirection_tool.cc.

133  {
134 
135  //Initialise the the PCA.
136  TPrincipal* pca = new TPrincipal(3, "");
137 
138  float TotalCharge = 0;
139 
140  //Get the Shower Centre
141  ShowerCentre =
142  IShowerTool::GetLArPandoraShowerAlg().ShowerCentre(clockData, detProp, sps, fmh, TotalCharge);
143 
144  //Normalise the spacepoints, charge weight and add to the PCA.
145  for (auto& sp : sps) {
146 
147  TVector3 sp_position = IShowerTool::GetLArPandoraShowerAlg().SpacePointPosition(sp);
148 
149  float wht = 1;
150 
151  //Normalise the spacepoint position.
152  sp_position = sp_position - ShowerCentre;
153 
154  if (fChargeWeighted) {
155 
156  //Get the charge.
157  float Charge = IShowerTool::GetLArPandoraShowerAlg().SpacePointCharge(sp, fmh);
158 
159  //Get the time of the spacepoint
160  float Time = IShowerTool::GetLArPandoraShowerAlg().SpacePointTime(sp, fmh);
161 
162  //Correct for the lifetime at the moment.
163  Charge *= std::exp((sampling_rate(clockData) * Time) / (detProp.ElectronLifetime() * 1e3));
164 
165  //Charge Weight
166  wht *= std::sqrt(Charge / TotalCharge);
167  }
168 
169  double sp_coord[3];
170  sp_coord[0] = sp_position.X() * wht;
171  sp_coord[1] = sp_position.Y() * wht;
172  sp_coord[2] = sp_position.Z() * wht;
173 
174  //Add to the PCA
175  pca->AddRow(sp_coord);
176  }
177 
178  //Evaluate the PCA
179  pca->MakePrincipals();
180 
181  //Get the Eigenvectors.
182  const TMatrixD* Eigenvectors = pca->GetEigenVectors();
183 
184  TVector3 Eigenvector = {(*Eigenvectors)[0][0], (*Eigenvectors)[1][0], (*Eigenvectors)[2][0]};
185 
186  delete pca;
187 
188  return Eigenvector;
189  }
double SpacePointTime(art::Ptr< recob::SpacePoint > const &sp, art::FindManyP< recob::Hit > const &fmh) const
const shower::LArPandoraShowerAlg & GetLArPandoraShowerAlg() const
Definition: IShowerTool.h:87
double SpacePointCharge(art::Ptr< recob::SpacePoint > const &sp, art::FindManyP< recob::Hit > const &fmh) const
TVector3 ShowerCentre(std::vector< art::Ptr< recob::SpacePoint >> const &showersps) const
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock.
TVector3 SpacePointPosition(art::Ptr< recob::SpacePoint > const &sp) const

Member Data Documentation

bool ShowerRecoTools::ShowerTrackPCADirection::fChargeWeighted
private

Definition at line 41 of file ShowerTrackPCADirection_tool.cc.

art::InputTag ShowerRecoTools::ShowerTrackPCADirection::fHitModuleLabel
private

Definition at line 39 of file ShowerTrackPCADirection_tool.cc.

std::string ShowerRecoTools::ShowerTrackPCADirection::fInitialTrackSpacePointsInputLabel
private

Definition at line 45 of file ShowerTrackPCADirection_tool.cc.

unsigned int ShowerRecoTools::ShowerTrackPCADirection::fMinPCAPoints
private

Definition at line 42 of file ShowerTrackPCADirection_tool.cc.

art::InputTag ShowerRecoTools::ShowerTrackPCADirection::fPFParticleLabel
private

Definition at line 38 of file ShowerTrackPCADirection_tool.cc.

std::string ShowerRecoTools::ShowerTrackPCADirection::fShowerDirectionOutputLabel
private

Definition at line 46 of file ShowerTrackPCADirection_tool.cc.

std::string ShowerRecoTools::ShowerTrackPCADirection::fShowerStartPositionInputLabel
private

Definition at line 44 of file ShowerTrackPCADirection_tool.cc.

int ShowerRecoTools::ShowerTrackPCADirection::fVerbose
private

Definition at line 40 of file ShowerTrackPCADirection_tool.cc.


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