All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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
9 #include "art/Utilities/ToolMacros.h"
10 
11 //LArSoft Includes
18 
19 namespace ShowerRecoTools {
20 
22 
23  public:
24  ShowerStartPositionCheater(const fhicl::ParameterSet& pset);
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
36  const art::InputTag fPFParticleLabel;
37  const art::InputTag fHitModuleLabel;
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 
52  int
53  ShowerStartPositionCheater::CalculateElement(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 =
86  art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(Event);
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  TVector3 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 = trueParticle->Position(trajPoint).Vect();
114  break;
115  }
116  }
117  }
118  else {
119  trueStartPos = trueParticle->Position().Vect();
120  }
121 
122  TVector3 trueStartPosErr = {-999, -999, -999};
123  ShowerEleHolder.SetElement(trueStartPos, trueStartPosErr, fShowerStartPositionOutputLabel);
124 
125  return 0;
126  }
127 }
128 
129 DEFINE_ART_CLASS_TOOL(ShowerRecoTools::ShowerStartPositionCheater)
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
Definition: UtilFunc.cxx:42
process_name cluster
Definition: cheaterreco.fcl:51
std::map< int, const simb::MCParticle * > GetTrueParticleMap() const
void SetElement(T &dataproduct, const std::string &Name, bool checktag=false)
T abs(T value)
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