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

Public Member Functions

 ShowerDirectionCheater (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
 
art::ServiceHandle< art::TFileService > tfs
 
const art::InputTag fPFParticleLabel
 
const unsigned int fNSegments
 
const bool fRMSFlip
 
const bool fVertexFlip
 
TTree * Tree
 
float vertexDotProduct
 
float rmsGradient
 
const std::string fShowerStartPositionInputLabel
 
const std::string fTrueParticleInputLabel
 
const std::string fShowerDirectionOutputLabel
 

Detailed Description

Definition at line 24 of file ShowerDirectionCheater_tool.cc.

Constructor & Destructor Documentation

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

Definition at line 59 of file ShowerDirectionCheater_tool.cc.

References fRMSFlip, fVertexFlip, rmsGradient, tfs, Tree, and vertexDotProduct.

60  : IShowerTool(pset.get<fhicl::ParameterSet>("BaseTools"))
61  , fLArPandoraShowerCheatingAlg(pset.get<fhicl::ParameterSet>("LArPandoraShowerCheatingAlg"))
62  , fPFParticleLabel(pset.get<art::InputTag>("PFParticleLabel"))
63  , fNSegments(pset.get<unsigned int>("NSegments"))
64  , fRMSFlip(pset.get<bool>("RMSFlip"))
65  , fVertexFlip(pset.get<bool>("VertexFlip"))
66  , fShowerStartPositionInputLabel(pset.get<std::string>("ShowerStartPositionInputLabel"))
67  , fTrueParticleInputLabel(pset.get<std::string>("TrueParticleInputLabel"))
68  , fShowerDirectionOutputLabel(pset.get<std::string>("ShowerDirectionOutputLabel"))
69  {
70  if (fVertexFlip || fRMSFlip) {
71  Tree = tfs->make<TTree>("DebugTreeDirCheater", "DebugTree from shower direction cheater");
72  if (fVertexFlip) Tree->Branch("vertexDotProduct", &vertexDotProduct);
73  if (fRMSFlip) Tree->Branch("rmsGradient", &rmsGradient);
74  }
75  }
art::ServiceHandle< art::TFileService > tfs
T get(std::string const &key) const
Definition: ParameterSet.h:314
shower::LArPandoraShowerCheatingAlg fLArPandoraShowerCheatingAlg
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::ShowerDirectionCheater::CalculateElement ( const art::Ptr< recob::PFParticle > &  pfparticle,
art::Event Event,
reco::shower::ShowerElementHolder ShowerEleHolder 
)
overridevirtual

Implements ShowerRecoTools::IShowerTool.

Definition at line 77 of file ShowerDirectionCheater_tool.cc.

References reco::shower::ShowerElementHolder::CheckElement(), DEFINE_ART_CLASS_TOOL, fLArPandoraShowerCheatingAlg, fNSegments, fPFParticleLabel, fRMSFlip, fShowerDirectionOutputLabel, fShowerStartPositionInputLabel, fTrueParticleInputLabel, fVertexFlip, reco::shower::ShowerElementHolder::GetElement(), ShowerRecoTools::IShowerTool::GetLArPandoraShowerAlg(), shower::LArPandoraShowerCheatingAlg::GetTrueChain(), shower::LArPandoraShowerCheatingAlg::GetTrueParticleMap(), art::ProductRetriever::getValidHandle(), hits(), art::Ptr< T >::key(), simb::MCParticle::Px(), simb::MCParticle::Py(), simb::MCParticle::Pz(), rmsGradient, shower::LArPandoraShowerAlg::RMSShowerGradient(), reco::shower::ShowerElementHolder::SetElement(), shower::LArPandoraShowerAlg::ShowerCentre(), Tree, shower::LArPandoraShowerCheatingAlg::TrueParticleIDFromTrueChain(), and vertexDotProduct.

80  {
81 
82  const simb::MCParticle* trueParticle;
83 
84  //Get the hits from the shower:
85  auto const pfpHandle = Event.getValidHandle<std::vector<recob::PFParticle>>(fPFParticleLabel);
86 
87  auto const clockData =
89  auto const detProp =
91 
92  if (ShowerEleHolder.CheckElement(fTrueParticleInputLabel)) {
93  ShowerEleHolder.GetElement(fTrueParticleInputLabel, trueParticle);
94  }
95  else {
96 
97  //Could store these in the shower element holder and just calculate once?
98  std::map<int, const simb::MCParticle*> trueParticles =
100  std::map<int, std::vector<int>> showersMothers =
102 
103  //Get the clusters
104  auto const clusHandle = Event.getValidHandle<std::vector<recob::Cluster>>(fPFParticleLabel);
105  art::FindManyP<recob::Cluster> fmc(pfpHandle, Event, fPFParticleLabel);
106  std::vector<art::Ptr<recob::Cluster>> clusters = fmc.at(pfparticle.key());
107 
108  //Get the hit association
109  art::FindManyP<recob::Hit> fmhc(clusHandle, Event, fPFParticleLabel);
110 
111  std::vector<art::Ptr<recob::Hit>> showerHits;
112  for (auto const& cluster : clusters) {
113  //Get the hits
114  std::vector<art::Ptr<recob::Hit>> hits = fmhc.at(cluster.key());
115  showerHits.insert(showerHits.end(), hits.begin(), hits.end());
116  }
117 
118  //Get the true particle from the shower
119  std::pair<int, double> ShowerTrackInfo =
121  clockData, showersMothers, showerHits, 2);
122 
123  if (ShowerTrackInfo.first == -99999) {
124  mf::LogError("ShowerDirectionCheater") << "True shower not found, returning";
125  return 1;
126  }
127  trueParticle = trueParticles[ShowerTrackInfo.first];
128  ShowerEleHolder.SetElement(trueParticle, fTrueParticleInputLabel);
129  }
130 
131  if (!trueParticle) {
132  mf::LogError("ShowerDirectionCheater") << "True shower not found, returning";
133  return 1;
134  }
135 
136  auto trueDir = geo::Vector_t{trueParticle->Px(), trueParticle->Py(), trueParticle->Pz()}.Unit();
137 
138  geo::Vector_t trueDirErr = {-999, -999, -999};
139  ShowerEleHolder.SetElement(trueDir, trueDirErr, fShowerDirectionOutputLabel);
140 
141  if (fRMSFlip || fVertexFlip) {
142 
143  // Reset the tree values to defaults
144  rmsGradient = std::numeric_limits<float>::lowest();
145  vertexDotProduct = std::numeric_limits<float>::lowest();
146 
147  //Get the SpacePoints and hits
148  art::FindManyP<recob::SpacePoint> fmspp(pfpHandle, Event, fPFParticleLabel);
149 
150  if (!fmspp.isValid()) {
151  throw cet::exception("ShowerDirectionCheater")
152  << "Trying to get the spacepoint and failed. Something is not configured correctly. "
153  "Stopping ";
154  }
155 
156  auto const spHandle = Event.getValidHandle<std::vector<recob::SpacePoint>>(fPFParticleLabel);
157  art::FindManyP<recob::Hit> fmh(spHandle, Event, fPFParticleLabel);
158  if (!fmh.isValid()) {
159  throw cet::exception("ShowerDirectionCheater")
160  << "Spacepoint and hit association not valid. Stopping.";
161  }
162  std::vector<art::Ptr<recob::SpacePoint>> spacePoints = fmspp.at(pfparticle.key());
163 
164  if (spacePoints.size() < 3) {
165  mf::LogWarning("ShowerDirectionCheater")
166  << spacePoints.size() << " spacepoints in shower, not calculating direction" << std::endl;
167  return 1;
168  }
169 
170  //Get Shower Centre
171  float TotalCharge;
172 
173  auto const ShowerCentre = IShowerTool::GetLArPandoraShowerAlg().ShowerCentre(
174  clockData, detProp, spacePoints, fmh, TotalCharge);
175 
176  //Check if we are pointing the correct direction or not, First try the start position
177  if (ShowerEleHolder.CheckElement(fShowerStartPositionInputLabel) && fVertexFlip) {
178 
179  //Get the General direction as the vector between the start position and the centre
180  geo::Point_t StartPositionVec = {-999, -999, -999};
181  ShowerEleHolder.GetElement(fShowerStartPositionInputLabel, StartPositionVec);
182 
183  auto const GeneralDir = (ShowerCentre - StartPositionVec).Unit();
184 
185  //Dot product
186  vertexDotProduct = trueDir.Dot(GeneralDir);
187  }
188 
189  if (fRMSFlip) {
190  //Otherwise Check against the RMS of the shower. Method adapated from EMShower Thanks Mike.
192  spacePoints, ShowerCentre, trueDir, fNSegments);
193  }
194  Tree->Fill();
195  }
196 
197  return 0;
198  }
double Py(const int i=0) const
Definition: MCParticle.h:232
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
double Px(const int i=0) const
Definition: MCParticle.h:231
void SetElement(T &dataproduct, const std::string &Name, bool checktag=false)
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
Cluster finding and building.
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
int GetElement(const std::string &Name, T &Element) const
shower::LArPandoraShowerCheatingAlg fLArPandoraShowerCheatingAlg
const shower::LArPandoraShowerAlg & GetLArPandoraShowerAlg() const
Definition: IShowerTool.h:82
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
geo::Point_t ShowerCentre(std::vector< art::Ptr< recob::SpacePoint >> const &showersps) const
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
double Pz(const int i=0) const
Definition: MCParticle.h:233
double RMSShowerGradient(std::vector< art::Ptr< recob::SpacePoint >> &sps, const geo::Point_t &ShowerCentre, const geo::Vector_t &Direction, const unsigned int nSegments) const
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
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(), 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().

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

Member Data Documentation

shower::LArPandoraShowerCheatingAlg ShowerRecoTools::ShowerDirectionCheater::fLArPandoraShowerCheatingAlg
private

Definition at line 36 of file ShowerDirectionCheater_tool.cc.

Referenced by CalculateElement().

const unsigned int ShowerRecoTools::ShowerDirectionCheater::fNSegments
private

Definition at line 44 of file ShowerDirectionCheater_tool.cc.

Referenced by CalculateElement().

const art::InputTag ShowerRecoTools::ShowerDirectionCheater::fPFParticleLabel
private

Definition at line 42 of file ShowerDirectionCheater_tool.cc.

Referenced by CalculateElement().

const bool ShowerRecoTools::ShowerDirectionCheater::fRMSFlip
private

Definition at line 45 of file ShowerDirectionCheater_tool.cc.

Referenced by CalculateElement(), and ShowerDirectionCheater().

const std::string ShowerRecoTools::ShowerDirectionCheater::fShowerDirectionOutputLabel
private

Definition at line 56 of file ShowerDirectionCheater_tool.cc.

Referenced by CalculateElement().

const std::string ShowerRecoTools::ShowerDirectionCheater::fShowerStartPositionInputLabel
private

Definition at line 54 of file ShowerDirectionCheater_tool.cc.

Referenced by CalculateElement().

const std::string ShowerRecoTools::ShowerDirectionCheater::fTrueParticleInputLabel
private

Definition at line 55 of file ShowerDirectionCheater_tool.cc.

Referenced by CalculateElement().

const bool ShowerRecoTools::ShowerDirectionCheater::fVertexFlip
private

Definition at line 47 of file ShowerDirectionCheater_tool.cc.

Referenced by CalculateElement(), and ShowerDirectionCheater().

float ShowerRecoTools::ShowerDirectionCheater::rmsGradient
private

Definition at line 52 of file ShowerDirectionCheater_tool.cc.

Referenced by CalculateElement(), and ShowerDirectionCheater().

art::ServiceHandle<art::TFileService> ShowerRecoTools::ShowerDirectionCheater::tfs
private

Definition at line 39 of file ShowerDirectionCheater_tool.cc.

Referenced by ShowerDirectionCheater().

TTree* ShowerRecoTools::ShowerDirectionCheater::Tree
private

Definition at line 50 of file ShowerDirectionCheater_tool.cc.

Referenced by CalculateElement(), and ShowerDirectionCheater().

float ShowerRecoTools::ShowerDirectionCheater::vertexDotProduct
private

Definition at line 51 of file ShowerDirectionCheater_tool.cc.

Referenced by CalculateElement(), and ShowerDirectionCheater().


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