83 const simb::MCParticle* trueParticle;
86 auto const pfpHandle = Event.getValidHandle<std::vector<recob::PFParticle>>(
fPFParticleLabel);
88 auto const clockData =
89 art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(Event);
91 art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(Event, clockData);
99 std::map<int, const simb::MCParticle*> trueParticles =
101 std::map<int, std::vector<int>> showersMothers =
105 auto const clusHandle = Event.getValidHandle<std::vector<recob::Cluster>>(
fPFParticleLabel);
107 std::vector<art::Ptr<recob::Cluster>> clusters = fmc.at(pfparticle.key());
112 std::vector<art::Ptr<recob::Hit>> showerHits;
113 for (
auto const&
cluster : clusters) {
115 std::vector<art::Ptr<recob::Hit>> hits = fmhc.at(
cluster.key());
116 showerHits.insert(showerHits.end(), hits.begin(), hits.end());
120 std::pair<int, double> ShowerTrackInfo =
122 clockData, showersMothers, showerHits, 2);
124 if (ShowerTrackInfo.first == -99999) {
125 mf::LogError(
"ShowerDirectionCheater") <<
"True shower not found, returning";
128 trueParticle = trueParticles[ShowerTrackInfo.first];
133 mf::LogError(
"ShowerDirectionCheater") <<
"True shower not found, returning";
137 TVector3 trueDir = TVector3{trueParticle->Px(), trueParticle->Py(), trueParticle->Pz()}.Unit();
139 TVector3 trueDirErr = {-999, -999, -999};
145 rmsGradient = std::numeric_limits<float>::lowest();
149 art::FindManyP<recob::SpacePoint> fmspp(pfpHandle, Event,
fPFParticleLabel);
151 if (!fmspp.isValid()) {
152 throw cet::exception(
"ShowerDirectionCheater")
153 <<
"Trying to get the spacepoint and failed. Something is not configured correctly. "
157 auto const spHandle = Event.getValidHandle<std::vector<recob::SpacePoint>>(
fPFParticleLabel);
159 if (!fmh.isValid()) {
160 throw cet::exception(
"ShowerDirectionCheater")
161 <<
"Spacepoint and hit association not valid. Stopping.";
163 std::vector<art::Ptr<recob::SpacePoint>> spacePoints = fmspp.at(pfparticle.key());
165 if (spacePoints.size() < 3) {
166 mf::LogWarning(
"ShowerDirectionCheater")
167 << spacePoints.size() <<
" spacepoints in shower, not calculating direction" << std::endl;
175 clockData,
detProp, spacePoints, fmh, TotalCharge);
181 TVector3 StartPositionVec = {-999, -999, -999};
184 TVector3 GeneralDir = (ShowerCentre - StartPositionVec).Unit();
193 spacePoints, ShowerCentre, trueDir,
fNSegments);
std::map< int, const simb::MCParticle * > GetTrueParticleMap() const
void SetElement(T &dataproduct, const std::string &Name, bool checktag=false)
double RMSShowerGradient(std::vector< art::Ptr< recob::SpacePoint >> &sps, const TVector3 &ShowerCentre, const TVector3 &Direction, const unsigned int nSegments) const
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
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
TVector3 ShowerCentre(std::vector< art::Ptr< recob::SpacePoint >> const &showersps) const