LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
ShowerStartPositionCheater_tool.cc
Go to the documentation of this file.
1 //############################################################################
2 //### Name: ShowerStartPositionCheater ###
3 //### Author: Ed Tyley ###
4 //### Date: 16.07.19 ###
5 //### Description: Cheating tool using truth for shower direction ###
6 //############################################################################
7 
8 //Framework Includes
10 
11 //LArSoft Includes
18 
19 namespace ShowerRecoTools {
20 
22 
23  public:
25 
26  //Calculate Cheating Start Position
27  int CalculateElement(const art::Ptr<recob::PFParticle>& pfparticle,
28  art::Event& Event,
29  reco::shower::ShowerElementHolder& ShowerEleHolder) override;
30 
31  private:
32  //Algorithm functions
34 
35  //FCL
38 
40  const std::string fTrueParticleOutputLabel;
41  };
42 
44  : IShowerTool(pset.get<fhicl::ParameterSet>("BaseTools"))
45  , fLArPandoraShowerCheatingAlg(pset.get<fhicl::ParameterSet>("LArPandoraShowerCheatingAlg"))
46  , fPFParticleLabel(pset.get<art::InputTag>("PFParticleLabel"))
47  , fHitModuleLabel(pset.get<art::InputTag>("HitModuleLabel"))
48  , fShowerStartPositionOutputLabel(pset.get<std::string>("ShowerStartPositionOutputLabel"))
49  , fTrueParticleOutputLabel(pset.get<std::string>("TrueParticleOutputLabel"))
50  {}
51 
53  const art::Ptr<recob::PFParticle>& pfparticle,
54  art::Event& Event,
55  reco::shower::ShowerElementHolder& ShowerEleHolder)
56  {
57 
58  //Could store these in the shower element holder and just calculate once?
59  std::map<int, const simb::MCParticle*> trueParticles =
61  std::map<int, std::vector<int>> showersMothers =
63 
64  //Get the hits from the shower:
65  auto const pfpHandle = Event.getValidHandle<std::vector<recob::PFParticle>>(fPFParticleLabel);
66 
67  //Get the clusters
68  auto const clusHandle = Event.getValidHandle<std::vector<recob::Cluster>>(fPFParticleLabel);
69 
70  art::FindManyP<recob::Cluster> fmc(pfpHandle, Event, fPFParticleLabel);
71  std::vector<art::Ptr<recob::Cluster>> clusters = fmc.at(pfparticle.key());
72 
73  //Get the hit association
74  art::FindManyP<recob::Hit> fmhc(clusHandle, Event, fPFParticleLabel);
75 
76  std::vector<art::Ptr<recob::Hit>> showerHits;
77  for (auto const& cluster : clusters) {
78 
79  //Get the hits
80  std::vector<art::Ptr<recob::Hit>> hits = fmhc.at(cluster.key());
81  showerHits.insert(showerHits.end(), hits.begin(), hits.end());
82  }
83 
84  //Get the true particle from the shower
85  auto const clockData =
87 
88  std::pair<int, double> ShowerTrackInfo =
90  clockData, showersMothers, showerHits, 2);
91 
92  if (ShowerTrackInfo.first == -99999) {
93  mf::LogError("ShowerStartPositionCheater") << "True Shower Not Found";
94  return 1;
95  }
96 
97  const simb::MCParticle* trueParticle = trueParticles[ShowerTrackInfo.first];
98  if (!trueParticle) {
99  mf::LogError("ShowerDirectionCheater") << "True shower not found, returning";
100  return 1;
101  }
102 
103  ShowerEleHolder.SetElement(trueParticle, fTrueParticleOutputLabel);
104 
105  geo::Point_t trueStartPos{-999, -999, -999};
106  // If the true particle is a photon, we need to be smarter.
107  // Select the first traj point where tne photon loses energy
108  if (abs(trueParticle->PdgCode()) == 22) {
109  double initialEnergy = trueParticle->E();
110  unsigned int TrajPoints = trueParticle->NumberTrajectoryPoints();
111  for (unsigned int trajPoint = 0; trajPoint < TrajPoints; trajPoint++) {
112  if (trueParticle->E(trajPoint) < initialEnergy) {
113  trueStartPos = geo::vect::toPoint(trueParticle->Position(trajPoint).Vect());
114  break;
115  }
116  }
117  }
118  else {
119  trueStartPos = geo::vect::toPoint(trueParticle->Position().Vect());
120  }
121 
122  geo::Point_t trueStartPosErr = {-999, -999, -999};
123  ShowerEleHolder.SetElement(trueStartPos, trueStartPosErr, fShowerStartPositionOutputLabel);
124 
125  return 0;
126  }
127 }
128 
double E(const int i=0) const
Definition: MCParticle.h:234
unsigned int NumberTrajectoryPoints() const
Definition: MCParticle.h:219
const TLorentzVector & Position(const int i=0) const
Definition: MCParticle.h:220
int PdgCode() const
Definition: MCParticle.h:213
#define DEFINE_ART_CLASS_TOOL(tool)
Definition: ToolMacros.h:42
std::map< int, const simb::MCParticle * > GetTrueParticleMap() const
void SetElement(T &dataproduct, const std::string &Name, bool checktag=false)
::geo::Point_t toPoint(Point const &p)
Convert the specified point into a geo::Point_t.
constexpr auto abs(T v)
Returns the absolute value of the argument.
STL namespace.
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
Cluster finding and building.
void hits()
Definition: readHits.C:15
parameter set interface
key_type key() const noexcept
Definition: Ptr.h:166
std::map< int, std::vector< int > > GetTrueChain(std::map< int, const simb::MCParticle * > &trueParticles) const
shower::LArPandoraShowerCheatingAlg fLArPandoraShowerCheatingAlg
Declaration of cluster object.
int CalculateElement(const art::Ptr< recob::PFParticle > &pfparticle, art::Event &Event, reco::shower::ShowerElementHolder &ShowerEleHolder) override
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
decltype(auto) get(T &&obj)
ADL-aware version of std::to_string.
Definition: StdUtils.h:120
Definition: MVAAlg.h:12