LArSoft  v10_04_05
Liquid Argon Software toolkit - https://larsoft.org/
ShowerRecoTools::ShowerTrackFinderCheater Class Reference
Inheritance diagram for ShowerRecoTools::ShowerTrackFinderCheater:
ShowerRecoTools::IShowerTool

Public Member Functions

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

Private Member Functions

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

shower::LArPandoraShowerCheatingAlg fLArPandoraShowerCheatingAlg
 
const bool fDebugEVD
 
const art::InputTag fPFParticleLabel
 
const art::InputTag fHitModuleLabel
 
const std::string fTrueParticleIntputLabel
 
const std::string fShowerStartPositionInputTag
 
const std::string fShowerDirectionInputTag
 
const std::string fInitialTrackHitsOutputLabel
 
const std::string fInitialTrackSpacePointsOutputLabel
 

Detailed Description

Definition at line 21 of file ShowerTrackFinderCheater_tool.cc.

Constructor & Destructor Documentation

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

Definition at line 47 of file ShowerTrackFinderCheater_tool.cc.

48  : IShowerTool(pset.get<fhicl::ParameterSet>("BaseTools"))
49  , fLArPandoraShowerCheatingAlg(pset.get<fhicl::ParameterSet>("LArPandoraShowerCheatingAlg"))
50  , fDebugEVD(pset.get<bool>("DebugEVD"))
51  , fPFParticleLabel(pset.get<art::InputTag>("PFParticleLabel"))
52  , fHitModuleLabel(pset.get<art::InputTag>("HitModuleLabel"))
53  , fTrueParticleIntputLabel(pset.get<std::string>("TrueParticleIntputLabel"))
54  , fShowerStartPositionInputTag(pset.get<std::string>("ShowerStartPositionInputTag"))
55  , fShowerDirectionInputTag(pset.get<std::string>("ShowerDirectionInputTag"))
56  , fInitialTrackHitsOutputLabel(pset.get<std::string>("InitialTrackHitsOutputLabel"))
58  pset.get<std::string>("InitialTrackSpacePointsOutputLabel"))
59  {}
T get(std::string const &key) const
Definition: ParameterSet.h:314
IShowerTool(const fhicl::ParameterSet &pset)
Definition: IShowerTool.h:31
shower::LArPandoraShowerCheatingAlg fLArPandoraShowerCheatingAlg

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 150 of file IShowerTool.h.

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

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

Implements ShowerRecoTools::IShowerTool.

Definition at line 61 of file ShowerTrackFinderCheater_tool.cc.

References shower::LArPandoraShowerCheatingAlg::CheatDebugEVD(), reco::shower::ShowerElementHolder::CheckElement(), simb::MCParticle::Daughter(), DEFINE_ART_CLASS_TOOL, fDebugEVD, fHitModuleLabel, fInitialTrackHitsOutputLabel, fInitialTrackSpacePointsOutputLabel, fLArPandoraShowerCheatingAlg, fPFParticleLabel, fShowerDirectionInputTag, fShowerStartPositionInputTag, fTrueParticleIntputLabel, reco::shower::ShowerElementHolder::GetElement(), shower::LArPandoraShowerCheatingAlg::GetTrueChain(), shower::LArPandoraShowerCheatingAlg::GetTrueParticleMap(), art::ProductRetriever::getValidHandle(), hits(), art::Ptr< T >::key(), simb::MCParticle::NumberDaughters(), simb::MCParticle::PdgCode(), reco::shower::ShowerElementHolder::SetElement(), simb::MCParticle::TrackId(), shower::LArPandoraShowerCheatingAlg::TrueParticleID(), and shower::LArPandoraShowerCheatingAlg::TrueParticleIDFromTrueChain().

64  {
65  const simb::MCParticle* trueParticle = nullptr;
66 
67  //Get the hits from the shower:
68  auto const pfpHandle = Event.getValidHandle<std::vector<recob::PFParticle>>(fPFParticleLabel);
69  auto const clockData =
71 
72  //Get the clusters
73  auto const clusHandle = Event.getValidHandle<std::vector<recob::Cluster>>(fPFParticleLabel);
74  art::FindManyP<recob::Cluster> fmc(pfpHandle, Event, fPFParticleLabel);
75  std::vector<art::Ptr<recob::Cluster>> clusters = fmc.at(pfparticle.key());
76 
77  //Get the hit association
78  art::FindManyP<recob::Hit> fmhc(clusHandle, Event, fPFParticleLabel);
79 
80  std::vector<art::Ptr<recob::Hit>> showerHits;
81  for (auto const& cluster : clusters) {
82 
83  //Get the hits
84  std::vector<art::Ptr<recob::Hit>> hits = fmhc.at(cluster.key());
85  showerHits.insert(showerHits.end(), hits.begin(), hits.end());
86  }
87 
88  if (ShowerEleHolder.CheckElement(fTrueParticleIntputLabel)) {
89  ShowerEleHolder.GetElement(fTrueParticleIntputLabel, trueParticle);
90  }
91  else {
92 
93  //Could store these in the shower element holder and just calculate once?
94  std::map<int, const simb::MCParticle*> trueParticles =
96  std::map<int, std::vector<int>> showersMothers =
98 
99  //Get the true particle from the shower
100  std::pair<int, double> ShowerTrackInfo =
102  clockData, showersMothers, showerHits, 2);
103 
104  if (ShowerTrackInfo.first == -99999) {
105  mf::LogError("ShowerStartPosition") << "True Shower Not Found";
106  return 1;
107  }
108  trueParticle = trueParticles[ShowerTrackInfo.first];
109  ShowerEleHolder.SetElement(trueParticle, fTrueParticleIntputLabel);
110  }
111 
112  if (!trueParticle) {
113  mf::LogError("ShowerDirectionCheater") << "True shower not found, returning";
114  return 1;
115  }
116 
117  //This is all based on the shower vertex being known. If it is not lets not do the track
118  if (!ShowerEleHolder.CheckElement(fShowerStartPositionInputTag)) {
119  mf::LogError("ShowerTrackFinderCheater") << "Start position not set, returning " << std::endl;
120  return 1;
121  }
122  if (!ShowerEleHolder.CheckElement(fShowerDirectionInputTag)) {
123  mf::LogError("ShowerTrackFinderCheater") << "Direction not set, returning " << std::endl;
124  return 1;
125  }
126 
127  geo::Point_t ShowerStartPosition = {-999, -999, -999};
128  ShowerEleHolder.GetElement(fShowerStartPositionInputTag, ShowerStartPosition);
129 
130  geo::Vector_t ShowerDirection = {-999, -999, -999};
131  ShowerEleHolder.GetElement(fShowerDirectionInputTag, ShowerDirection);
132 
133  auto const hitHandle = Event.getValidHandle<std::vector<recob::Hit>>(fHitModuleLabel);
134 
135  // Get the hits associated with the space points
136  art::FindManyP<recob::SpacePoint> fmsph(hitHandle, Event, fPFParticleLabel);
137  if (!fmsph.isValid()) {
138  throw cet::exception("ShowerTrackFinderCheater")
139  << "Spacepoint and hit association not valid. Stopping.";
140  }
141 
142  std::vector<int> trueParticleIdVec;
143 
144  // If we have an electron, take the hits from the primary only
145  // This will also cover the cases Pandora misclassify a track as a shower
146  if (trueParticle->PdgCode() != 22) { trueParticleIdVec.push_back(trueParticle->TrackId()); }
147  else {
148  // To check if we are rolling up showers, check the number of daughters the photon has
149  const int nDaughters = trueParticle->NumberDaughters();
150  if (nDaughters == 0) {
151  // If we roll up showers, we have no choice but to take all of the hits from the photon
152  trueParticleIdVec.push_back(-trueParticle->TrackId());
153  }
154  else {
155  // If we do not roll up the showers, take all of the primary daughters
156  for (int i = 0; i < nDaughters; i++) {
157  trueParticleIdVec.push_back(trueParticle->Daughter(i));
158  }
159  }
160  }
161 
162  std::vector<art::Ptr<recob::Hit>> trackHits;
163  std::vector<art::Ptr<recob::SpacePoint>> trackSpacePoints;
164 
165  //Get the hits from the true particle
166  for (auto hit : showerHits) {
167  int trueHitId = fLArPandoraShowerCheatingAlg.TrueParticleID(clockData, hit);
168  if (std::find(trueParticleIdVec.cbegin(), trueParticleIdVec.cend(), trueHitId) !=
169  trueParticleIdVec.cend()) {
170  trackHits.push_back(hit);
171  std::vector<art::Ptr<recob::SpacePoint>> sps = fmsph.at(hit.key());
172  if (sps.size() == 1) { trackSpacePoints.push_back(sps.front()); }
173  }
174  }
175 
176  if (trackHits.empty() || trackSpacePoints.empty())
177  mf::LogWarning("ShowerTrackFinderCheater")
178  << "Creating intial track with " << trackHits.size() << " hits and "
179  << trackSpacePoints.size() << " spacepoints" << std::endl;
180 
181  ShowerEleHolder.SetElement(trackHits, fInitialTrackHitsOutputLabel);
182  ShowerEleHolder.SetElement(trackSpacePoints, fInitialTrackSpacePointsOutputLabel);
183 
184  if (fDebugEVD) {
186  clockData, trueParticle, Event, ShowerEleHolder, pfparticle);
187  }
188 
189  return 0;
190  }
int PdgCode() const
Definition: MCParticle.h:213
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
std::map< int, const simb::MCParticle * > GetTrueParticleMap() const
void SetElement(T &dataproduct, const std::string &Name, bool checktag=false)
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
Cluster finding and building.
int NumberDaughters() const
Definition: MCParticle.h:218
int TrackId() const
Definition: MCParticle.h:211
int Daughter(const int i) const
Definition: MCParticle.cxx:118
void hits()
Definition: readHits.C:15
key_type key() const noexcept
Definition: Ptr.h:166
std::map< int, std::vector< int > > GetTrueChain(std::map< int, const simb::MCParticle * > &trueParticles) const
bool CheckElement(const std::string &Name) const
void CheatDebugEVD(detinfo::DetectorClocksData const &clockData, const simb::MCParticle *trueParticle, art::Event const &Event, reco::shower::ShowerElementHolder &ShowerEleHolder, const art::Ptr< recob::PFParticle > &pfparticle) const
int GetElement(const std::string &Name, T &Element) const
int TrueParticleID(detinfo::DetectorClocksData const &clockData, const art::Ptr< recob::Hit > &hit) const
Detector simulation of raw signals on wires.
std::pair< int, double > TrueParticleIDFromTrueChain(detinfo::DetectorClocksData const &clockData, std::map< int, std::vector< int >> const &ShowersMothers, std::vector< art::Ptr< recob::Hit >> const &hits, int planeid) 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
shower::LArPandoraShowerCheatingAlg fLArPandoraShowerCheatingAlg
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
const shower::LArPandoraShowerAlg& ShowerRecoTools::IShowerTool::GetLArPandoraShowerAlg ( ) const
inlineprotectedinherited

Definition at line 80 of file IShowerTool.h.

Referenced by ShowerRecoTools::ShowerLengthPercentile::CalculateElement(), ShowerRecoTools::Shower3DCylinderTrackHitFinder::CalculateElement(), ShowerRecoTools::ShowerPCAPropergationStartPosition::CalculateElement(), ShowerRecoTools::Shower2DLinearRegressionTrackHitFinder::CalculateElement(), ShowerRecoTools::ShowerPFPVertexStartPosition::CalculateElement(), ShowerRecoTools::ShowerUnidirectiondEdx::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().

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

Definition at line 100 of file IShowerTool.h.

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

103  {
104 
105  //Check the element has been set
106  bool check_element = ShowerEleHolder.CheckElement(Name);
107  if (!check_element) {
108  throw cet::exception("IShowerTool") << "tried to get a element that does not exist. Failed "
109  "at making the art ptr for Element: "
110  << Name << std::endl;
111  }
112 
113  //Check the unique ptr has been set.
114  bool check_ptr = UniquePtrs->CheckUniqueProduerPtr(Name);
115  if (!check_ptr) {
116  throw cet::exception("IShowerTool")
117  << "tried to get a ptr that does not exist. Failed at making the art ptr for Element"
118  << Name;
119  }
120 
121  //Check if the user has defined an index if not just use the current shower index/
122  int index;
123  if (iter != -1) { index = iter; }
124  else {
125  index = ShowerEleHolder.GetShowerNumber();
126  }
127 
128  //Make the ptr
129  return UniquePtrs->GetArtPtr<T>(Name, index);
130  }
reco::shower::ShowerProducedPtrsHolder * UniquePtrs
Definition: IShowerTool.h:83
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 66 of file IShowerTool.h.

67  {
68  UniquePtrs = &uniqueproducerPtrs;
69  }
reco::shower::ShowerProducedPtrsHolder * UniquePtrs
Definition: IShowerTool.h:83
virtual void ShowerRecoTools::IShowerTool::InitialiseProducers ( )
inlinevirtualinherited
template<class T >
void ShowerRecoTools::IShowerTool::InitialiseProduct ( std::string  Name,
std::string  InstanceName = "" 
)
inlineprotectedinherited

Definition at line 135 of file IShowerTool.h.

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

136  {
137 
138  if (collectorPtr == nullptr) {
139  mf::LogWarning("IShowerTool") << "The art::ProducesCollector ptr has not been set";
140  return;
141  }
142 
143  collectorPtr->produces<T>(InstanceName);
144  UniquePtrs->SetShowerUniqueProduerPtr(type<T>(), Name, InstanceName);
145  }
reco::shower::ShowerProducedPtrsHolder * UniquePtrs
Definition: IShowerTool.h:83
art::ProducesCollector * collectorPtr
Definition: IShowerTool.h:95
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 160 of file IShowerTool.h.

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

Referenced by ShowerRecoTools::ShowerExampleTool::CalculateElement().

160 { UniquePtrs->PrintPtr(Name); }
reco::shower::ShowerProducedPtrsHolder * UniquePtrs
Definition: IShowerTool.h:83
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 44 of file IShowerTool.h.

48  {
49 
50  int calculation_status = CalculateElement(pfparticle, Event, ShowerEleHolder);
51  if (calculation_status != 0) return calculation_status;
52  if (fRunEventDisplay) {
54  pfparticle, Event, ShowerEleHolder, evd_display_name_append);
55  }
56  return calculation_status;
57  }
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:80
void ShowerRecoTools::IShowerTool::SetPtr ( art::ProducesCollector collector)
inlineinherited

Definition at line 63 of file IShowerTool.h.

63 { collectorPtr = collector; }
art::ProducesCollector * collectorPtr
Definition: IShowerTool.h:95

Member Data Documentation

const bool ShowerRecoTools::ShowerTrackFinderCheater::fDebugEVD
private

Definition at line 36 of file ShowerTrackFinderCheater_tool.cc.

Referenced by CalculateElement().

const art::InputTag ShowerRecoTools::ShowerTrackFinderCheater::fHitModuleLabel
private

Definition at line 38 of file ShowerTrackFinderCheater_tool.cc.

Referenced by CalculateElement().

const std::string ShowerRecoTools::ShowerTrackFinderCheater::fInitialTrackHitsOutputLabel
private

Definition at line 43 of file ShowerTrackFinderCheater_tool.cc.

Referenced by CalculateElement().

const std::string ShowerRecoTools::ShowerTrackFinderCheater::fInitialTrackSpacePointsOutputLabel
private

Definition at line 44 of file ShowerTrackFinderCheater_tool.cc.

Referenced by CalculateElement().

shower::LArPandoraShowerCheatingAlg ShowerRecoTools::ShowerTrackFinderCheater::fLArPandoraShowerCheatingAlg
private

Definition at line 33 of file ShowerTrackFinderCheater_tool.cc.

Referenced by CalculateElement().

const art::InputTag ShowerRecoTools::ShowerTrackFinderCheater::fPFParticleLabel
private

Definition at line 37 of file ShowerTrackFinderCheater_tool.cc.

Referenced by CalculateElement().

const std::string ShowerRecoTools::ShowerTrackFinderCheater::fShowerDirectionInputTag
private

Definition at line 42 of file ShowerTrackFinderCheater_tool.cc.

Referenced by CalculateElement().

const std::string ShowerRecoTools::ShowerTrackFinderCheater::fShowerStartPositionInputTag
private

Definition at line 41 of file ShowerTrackFinderCheater_tool.cc.

Referenced by CalculateElement().

const std::string ShowerRecoTools::ShowerTrackFinderCheater::fTrueParticleIntputLabel
private

Definition at line 40 of file ShowerTrackFinderCheater_tool.cc.

Referenced by CalculateElement().


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