11 #include "art/Utilities/ToolMacros.h"
22 namespace ShowerRecoTools {
64 const fhicl::ParameterSet& pset)
66 , fNfitpass(pset.
get<unsigned int>(
"Nfitpass"))
67 , fNfithits(pset.
get<
std::
vector<unsigned int>>(
"Nfithits"))
69 , fApplyChargeWeight(pset.
get<
bool>(
"ApplyChargeWeight"))
70 , fPFParticleLabel(pset.
get<art::InputTag>(
"PFParticleLabel"))
71 , fVerbose(pset.
get<int>(
"Verbose"))
72 , fHitLabel(pset.
get<art::InputTag>(
"HitsModuleLabel"))
73 , fShowerStartPositionInputLabel(pset.
get<
std::string>(
"ShowerStartPositionInputLabel"))
74 , fShowerDirectionInputLabel(pset.
get<
std::string>(
"ShowerDirectionInputLabel"))
75 , fInitialTrackHitsOutputLabel(pset.
get<
std::string>(
"InitialTrackHitsOutputLabel"))
76 , fInitialTrackSpacePointsOutputLabel(
77 pset.
get<
std::string>(
"InitialTrackSpacePointsOutputLabel"))
80 throw art::Exception(art::errors::Configuration)
81 <<
"Shower2DLinearRegressionTrackHitFinderEMShower: fNfithits and fToler need to have size "
88 const art::Ptr<recob::PFParticle>& pfparticle,
96 mf::LogError(
"Shower2DLinearRegressionTrackHitFinder")
97 <<
"Start position not set, returning " << std::endl;
102 mf::LogError(
"Shower2DLinearRegressionTrackHitFinder")
103 <<
"Direction not set, returning " << std::endl;
107 TVector3 ShowerStartPosition = {-999, -999, -999};
110 TVector3 ShowerDirection = {-999, -999, -999};
114 auto const pfpHandle = Event.getValidHandle<std::vector<recob::PFParticle>>(
fPFParticleLabel);
117 auto const clusHandle = Event.getValidHandle<std::vector<recob::Cluster>>(
fPFParticleLabel);
119 const art::FindManyP<recob::Cluster>& fmc =
121 std::vector<art::Ptr<recob::Cluster>> clusters = fmc.at(pfparticle.key());
123 if (clusters.size() < 2) {
125 mf::LogError(
"Shower2DLinearRegressionTrackHitFinder")
126 <<
"Not enough clusters: " << clusters.size() << std::endl;
131 const art::FindManyP<recob::Hit>& fmhc =
133 std::map<geo::PlaneID, std::vector<art::Ptr<recob::Hit>>> plane_clusters;
135 for (
auto const&
cluster : clusters) {
138 std::vector<art::Ptr<recob::Hit>> hits = fmhc.at(
cluster.key());
140 for (
auto hit : hits) {
143 plane_clusters[plane].push_back(
hit);
151 auto const clockData =
152 art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(Event);
154 art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(Event, clockData);
156 std::vector<art::Ptr<recob::Hit>> InitialTrackHits;
158 for (
auto const&
cluster : plane_clusters) {
161 std::vector<art::Ptr<recob::Hit>> hits =
cluster.second;
165 detProp, hits, ShowerStartPosition, ShowerDirection);
170 InitialTrackHits.insert(InitialTrackHits.end(), trackhits.begin(), trackhits.end());
178 auto const hitHandle = Event.getValidHandle<std::vector<recob::Hit>>(
fHitLabel);
181 const art::FindManyP<recob::SpacePoint>& fmsp =
185 std::vector<art::Ptr<recob::SpacePoint>> intitaltrack_sp;
186 for (
auto const&
hit : InitialTrackHits) {
187 std::vector<art::Ptr<recob::SpacePoint>> sps = fmsp.at(
hit.key());
188 for (
auto const sp : sps) {
189 intitaltrack_sp.push_back(sp);
197 std::vector<art::Ptr<recob::Hit>>
203 std::vector<art::Ptr<recob::Hit>> trackHits;
207 std::vector<double> wfit;
208 std::vector<double> tfit;
209 std::vector<double> cfit;
214 unsigned int nhits = 0;
215 for (
auto&
hit : hits) {
222 (
std::abs((coord.Y() - (parm[0] + coord.X() * parm[1])) *
223 std::cos(std::atan(parm[1]))) <
fToler[i - 1]) ||
227 wfit.push_back(coord.X());
228 tfit.push_back(coord.Y());
234 if (i == fNfitpass - 1) { trackHits.push_back(
hit); }
238 if (i < fNfitpass - 1 && wfit.size()) {
239 fitok =
WeightedFit(wfit.size(), &wfit[0], &tfit[0], &cfit[0], &parm[0]);
271 for (Int_t i = 0; i <
n; i++) {
273 sumx2 += x[i] * x[i] * w[i];
275 sumy2 += y[i] * y[i] * w[i];
276 sumxy += x[i] * y[i] * w[i];
280 if (sumx2 * sumw - sumx * sumx == 0.)
return 1;
281 if (sumx2 - sumx * sumx / sumw == 0.)
return 1;
283 parm[0] = (sumy * sumx2 - sumx * sumxy) / (sumx2 * sumw - sumx * sumx);
284 parm[1] = (sumxy - sumx * sumy / sumw) / (sumx2 - sumx * sumx / sumw);
286 eparm[0] = sumx2 * (sumx2 * sumw - sumx * sumx);
287 eparm[1] = (sumx2 - sumx * sumx / sumw);
289 if (eparm[0] < 0. || eparm[1] < 0.)
return 1;
291 eparm[0] = sqrt(eparm[0]) / (sumx2 * sumw - sumx * sumx);
292 eparm[1] = sqrt(eparm[1]) / (sumx2 - sumx * sumx / sumw);
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
process_name opflash particleana ie x
auto coord(Vector &v, unsigned int n) noexcept
Returns an object to manage the coordinate n of a vector.
Declaration of signal hit object.
The data type to uniquely identify a Plane.
void SetElement(T &dataproduct, const std::string &Name, bool checktag=false)
Set of hits with a 2D structure.
const art::FindManyP< T1 > & GetFindManyP(const art::ValidHandle< std::vector< T2 > > &handle, const art::Event &evt, const art::InputTag &moduleTag)
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
process_name opflash particleana ie ie y
bool CheckElement(const std::string &Name) const
constexpr PlaneID const & asPlaneID() const
Conversion to PlaneID (for convenience of notation).
int GetElement(const std::string &Name, T &Element) const
Declaration of cluster object.
TVector2 HitCoordinates(detinfo::DetectorPropertiesData const &detProp, art::Ptr< recob::Hit > const &hit) const
2D representation of charge deposited in the TDC/wire plane
void OrderShowerHits(detinfo::DetectorPropertiesData const &detProp, std::vector< art::Ptr< recob::Hit >> &hits, TVector3 const &ShowerDirection, TVector3 const &ShowerPosition) const