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

geo::Vector_t ShowerPCAVector (const detinfo::DetectorClocksData &clockData, const detinfo::DetectorPropertiesData &detProp, std::vector< art::Ptr< recob::SpacePoint >> &spacePoints_pfp, const art::FindManyP< recob::Hit > &fmh, geo::Point_t &ShowerCentre)
 
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 25 of file ShowerTrackPCADirection_tool.cc.

Constructor & Destructor Documentation

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

Definition at line 54 of file ShowerTrackPCADirection_tool.cc.

55  : IShowerTool(pset.get<fhicl::ParameterSet>("BaseTools"))
56  , fPFParticleLabel(pset.get<art::InputTag>("PFParticleLabel"))
57  , fHitModuleLabel(pset.get<art::InputTag>("HitModuleLabel"))
58  , fVerbose(pset.get<int>("Verbose"))
59  , fChargeWeighted(pset.get<bool>("ChargeWeighted"))
60  , fMinPCAPoints(pset.get<unsigned int>("MinPCAPoints"))
61  , fShowerStartPositionInputLabel(pset.get<std::string>("ShowerStartPositionInputLabel"))
62  , fInitialTrackSpacePointsInputLabel(pset.get<std::string>("InitialTrackSpacePointsInputLabel"))
63  , fShowerDirectionOutputLabel(pset.get<std::string>("ShowerDirectionOutputLabel"))
64  {}
T get(std::string const &key) const
Definition: ParameterSet.h:314
IShowerTool(const fhicl::ParameterSet &pset)
Definition: IShowerTool.h:33

Member Function Documentation

virtual int ShowerRecoTools::IShowerTool::AddAssociations ( const art::Ptr< recob::PFParticle > &  pfpPtr,
art::Event Event,
reco::shower::ShowerElementHolder ShowerEleHolder 
)
inlinevirtualinherited
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::ShowerTrackPCADirection::CalculateElement ( const art::Ptr< recob::PFParticle > &  pfparticle,
art::Event Event,
reco::shower::ShowerElementHolder ShowerEleHolder 
)
overridevirtual

Implements ShowerRecoTools::IShowerTool.

Definition at line 66 of file ShowerTrackPCADirection_tool.cc.

References reco::shower::ShowerElementHolder::CheckElement(), fInitialTrackSpacePointsInputLabel, fMinPCAPoints, fPFParticleLabel, fShowerDirectionOutputLabel, fShowerStartPositionInputLabel, fVerbose, reco::shower::ShowerElementHolder::GetElement(), reco::shower::ShowerElementHolder::GetFindManyP(), art::ProductRetriever::getValidHandle(), reco::shower::ShowerElementHolder::SetElement(), and ShowerPCAVector().

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

Definition at line 126 of file ShowerTrackPCADirection_tool.cc.

References DEFINE_ART_CLASS_TOOL, detinfo::DetectorPropertiesData::ElectronLifetime(), fChargeWeighted, ShowerRecoTools::IShowerTool::GetLArPandoraShowerAlg(), detinfo::sampling_rate(), shower::LArPandoraShowerAlg::ShowerCentre(), shower::LArPandoraShowerAlg::SpacePointCharge(), and shower::LArPandoraShowerAlg::SpacePointTime().

Referenced by CalculateElement().

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

Member Data Documentation

bool ShowerRecoTools::ShowerTrackPCADirection::fChargeWeighted
private

Definition at line 46 of file ShowerTrackPCADirection_tool.cc.

Referenced by ShowerPCAVector().

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

Definition at line 44 of file ShowerTrackPCADirection_tool.cc.

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

Definition at line 50 of file ShowerTrackPCADirection_tool.cc.

Referenced by CalculateElement().

unsigned int ShowerRecoTools::ShowerTrackPCADirection::fMinPCAPoints
private

Definition at line 47 of file ShowerTrackPCADirection_tool.cc.

Referenced by CalculateElement().

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

Definition at line 43 of file ShowerTrackPCADirection_tool.cc.

Referenced by CalculateElement().

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

Definition at line 51 of file ShowerTrackPCADirection_tool.cc.

Referenced by CalculateElement().

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

Definition at line 49 of file ShowerTrackPCADirection_tool.cc.

Referenced by CalculateElement().

int ShowerRecoTools::ShowerTrackPCADirection::fVerbose
private

Definition at line 45 of file ShowerTrackPCADirection_tool.cc.

Referenced by CalculateElement().


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