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
15 
16 namespace ShowerRecoTools {
17 
19 
20  public:
22 
23  //Calculate Cheating Start Position
24  int CalculateElement(const art::Ptr<recob::PFParticle>& pfparticle,
26  reco::shower::ShowerElementHolder& ShowerEleHolder) override;
27 
28  private:
29  //Algorithm functions
31 
32  //FCL
35 
38  };
39 
41  : IShowerTool(pset.get<fhicl::ParameterSet>("BaseTools"))
42  , fLArPandoraShowerCheatingAlg(pset.get<fhicl::ParameterSet>("LArPandoraShowerCheatingAlg"))
43  , fPFParticleLabel(pset.get<art::InputTag>("PFParticleLabel"))
44  , fHitModuleLabel(pset.get<art::InputTag>("HitModuleLabel"))
45  , fShowerStartPositionOutputLabel(pset.get<std::string>("ShowerStartPositionOutputLabel"))
46  , fTrueParticleOutputLabel(pset.get<std::string>("TrueParticleOutputLabel"))
47  {}
48 
49  int
51  art::Event& Event,
52  reco::shower::ShowerElementHolder& ShowerEleHolder)
53  {
54 
55  //Could store these in the shower element holder and just calculate once?
56  std::map<int, const simb::MCParticle*> trueParticles =
58  std::map<int, std::vector<int>> showersMothers =
60 
61  //Get the hits from the shower:
62  auto const pfpHandle = Event.getValidHandle<std::vector<recob::PFParticle>>(fPFParticleLabel);
63 
64  //Get the clusters
65  auto const clusHandle = Event.getValidHandle<std::vector<recob::Cluster>>(fPFParticleLabel);
66 
67  art::FindManyP<recob::Cluster> fmc(pfpHandle, Event, fPFParticleLabel);
68  std::vector<art::Ptr<recob::Cluster>> clusters = fmc.at(pfparticle.key());
69 
70  //Get the hit association
71  art::FindManyP<recob::Hit> fmhc(clusHandle, Event, fPFParticleLabel);
72 
73  std::vector<art::Ptr<recob::Hit>> showerHits;
74  for (auto const& cluster : clusters) {
75 
76  //Get the hits
77  std::vector<art::Ptr<recob::Hit>> hits = fmhc.at(cluster.key());
78  showerHits.insert(showerHits.end(), hits.begin(), hits.end());
79  }
80 
81  //Get the true particle from the shower
82  auto const clockData =
84 
85  std::pair<int, double> ShowerTrackInfo =
87  clockData, showersMothers, showerHits, 2);
88 
89  if (ShowerTrackInfo.first == -99999) {
90  mf::LogError("ShowerStartPositionCheater") << "True Shower Not Found";
91  return 1;
92  }
93 
94  const simb::MCParticle* trueParticle = trueParticles[ShowerTrackInfo.first];
95  if (!trueParticle) {
96  mf::LogError("ShowerDirectionCheater") << "True shower not found, returning";
97  return 1;
98  }
99 
100  ShowerEleHolder.SetElement(trueParticle, fTrueParticleOutputLabel);
101 
102  TVector3 trueStartPos = {-999, -999, -999};
103  // If the true particle is a photon, we need to be smarter.
104  // Select the first traj point where tne photon loses energy
105  if (abs(trueParticle->PdgCode()) == 22) {
106  double initialEnergy = trueParticle->E();
107  unsigned int TrajPoints = trueParticle->NumberTrajectoryPoints();
108  for (unsigned int trajPoint = 0; trajPoint < TrajPoints; trajPoint++) {
109  if (trueParticle->E(trajPoint) < initialEnergy) {
110  trueStartPos = trueParticle->Position(trajPoint).Vect();
111  break;
112  }
113  }
114  }
115  else {
116  trueStartPos = trueParticle->Position().Vect();
117  }
118 
119  TVector3 trueStartPosErr = {-999, -999, -999};
120  ShowerEleHolder.SetElement(trueStartPos, trueStartPosErr, fShowerStartPositionOutputLabel);
121 
122  return 0;
123  }
124 }
125 
double E(const int i=0) const
Definition: MCParticle.h:233
unsigned int NumberTrajectoryPoints() const
Definition: MCParticle.h:218
const TLorentzVector & Position(const int i=0) const
Definition: MCParticle.h:219
int PdgCode() const
Definition: MCParticle.h:212
#define DEFINE_ART_CLASS_TOOL(tool)
Definition: ToolMacros.h:42
std::string string
Definition: nybbler.cc:12
std::map< int, const simb::MCParticle * > GetTrueParticleMap() const
void SetElement(T &dataproduct, const std::string &Name, bool checktag=false)
STL namespace.
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
Cluster finding and building.
T abs(T value)
key_type key() const noexcept
Definition: Ptr.h:216
std::map< int, std::vector< int > > GetTrueChain(std::map< int, const simb::MCParticle * > &trueParticles) const
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
shower::LArPandoraShowerCheatingAlg fLArPandoraShowerCheatingAlg
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
Definition: types.h:32
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115