46 :
IShowerTool(pset.get<fhicl::ParameterSet>(
"BaseTools"))
47 , fVerbose(pset.get<int>(
"Verbose"))
48 , fUsePandoraVertex(pset.get<bool>(
"UsePandoraVertex"))
49 , fHitModuleLabel(pset.get<
art::InputTag>(
"HitModuleLabel"))
50 , fPFParticleLabel(pset.get<
art::InputTag>(
"PFParticleLabel"))
51 , fInitialTrackHitsInputLabel(pset.get<std::string>(
"InitialTrackHitsInputLabel"))
52 , fShowerStartPositionInputLabel(pset.get<std::string>(
"ShowerStartPositionInputLabel"))
53 , fInitialTrackInputLabel(pset.get<std::string>(
"InitialTrackInputLabel"))
54 , fShowerDirectionOutputLabel(pset.get<std::string>(
"ShowerDirectionOutputLabel"))
65 mf::LogError(
"ShowerTrackHitDirection") <<
"Initial track hits not set" << std::endl;
72 mf::LogError(
"ShowerTrackHitDirection")
73 <<
"Start position not set, returning " << std::endl;
78 geo::Point_t StartPosition = {-999, -999, -99};
86 mf::LogError(
"ShowerTrackHitDirection") <<
"Initial track not set" << std::endl;
89 recob::Track InitialTrack;
91 geo::Point_t Start_point = InitialTrack.Start();
92 StartPosition = {Start_point.X(), Start_point.Y(), Start_point.Z()};
96 auto const hitHandle = Event.getValidHandle<std::vector<recob::Hit>>(
fHitModuleLabel);
99 const art::FindManyP<recob::SpacePoint>& fmsp =
103 std::vector<art::Ptr<recob::Hit>> InitialTrackHits;
107 float sumX = 0, sumX2 = 0;
108 float sumY = 0, sumY2 = 0;
109 float sumZ = 0, sumZ2 = 0;
112 std::vector<art::Ptr<recob::SpacePoint>> intitaltrack_sp;
113 for (
auto const hit : InitialTrackHits) {
114 std::vector<art::Ptr<recob::SpacePoint>> sps = fmsp.at(hit.key());
115 for (
auto const sp : sps) {
116 intitaltrack_sp.push_back(sp);
119 auto const pos = sp->position() - StartPosition;
120 if (pos.R() == 0) {
continue; }
123 sumX2 += pos.X() * pos.X();
125 sumY2 += pos.Y() * pos.Y();
127 sumZ2 += pos.Z() * pos.Z();
131 float NumSps = intitaltrack_sp.size();
132 auto const Mean = geo::Vector_t{sumX / NumSps, sumY / NumSps, sumZ / NumSps}.Unit();
137 if (sumX2 / NumSps - ((sumX / NumSps) * ((sumX / NumSps))) > 0) {
138 RMSX = std::sqrt(sumX2 / NumSps - ((sumX / NumSps) * ((sumX / NumSps))));
140 if (sumY2 / NumSps - ((sumY / NumSps) * ((sumY / NumSps))) > 0) {
141 RMSY = std::sqrt(sumY2 / NumSps - ((sumY / NumSps) * ((sumY / NumSps))));
143 if (sumZ2 / NumSps - ((sumZ / NumSps) * ((sumZ / NumSps))) > 0) {
144 RMSZ = std::sqrt(sumZ2 / NumSps - ((sumZ / NumSps) * ((sumZ / NumSps))));
148 geo::Vector_t Direction_Mean{0, 0, 0};
150 for (
auto const sp : intitaltrack_sp) {
151 auto const Direction = sp->position() - StartPosition;
152 if ((std::abs((Direction - Mean).X()) < 1 * RMSX) &&
153 (std::abs((Direction - Mean).Y()) < 1 * RMSY) &&
154 (std::abs((Direction - Mean).Z()) < 1 * RMSZ)) {
155 if (Direction.R() == 0) {
continue; }
157 Direction_Mean += Direction;
163 Direction_Mean = Direction_Mean.Unit();
168 mf::LogError(
"ShowerTrackHitDirection")
169 <<
"None of the points are within 1 sigma" << std::endl;