51 :
IShowerTool(pset.get<fhicl::ParameterSet>(
"BaseTools"))
52 , fCalorimetryAlg(pset.get<fhicl::ParameterSet>(
"CalorimetryAlg"))
53 , fVerbose(pset.get<int>(
"Verbose"))
54 , fdEdxTrackLength(pset.get<float>(
"dEdxTrackLength"))
55 , fMaxHitPlane(pset.get<bool>(
"MaxHitPlane"))
56 , fMissFirstPoint(pset.get<bool>(
"MissFirstPoint"))
57 , fSumHitSnippets(pset.get<bool>(
"SumHitSnippets"))
58 , fShowerStartPositionInputLabel(pset.get<std::string>(
"ShowerStartPositionInputLabel"))
59 , fInitialTrackHitsInputLabel(pset.get<std::string>(
"InitialTrackHitsInputLabel"))
60 , fShowerDirectionInputLabel(pset.get<std::string>(
"ShowerDirectionInputLabel"))
61 , fShowerdEdxOutputLabel(pset.get<std::string>(
"ShowerdEdxOutputLabel"))
62 , fShowerBestPlaneOutputLabel(pset.get<std::string>(
"ShowerBestPlaneOutputLabel"))
75 mf::LogError(
"ShowerUnidirectiondEdx") <<
"Start position not set, returning " << std::endl;
80 mf::LogError(
"ShowerUnidirectiondEdx")
81 <<
"Initial Track Hits not set returning" << std::endl;
86 mf::LogError(
"ShowerUnidirectiondEdx") <<
"Shower Direction not set" << std::endl;
91 std::vector<art::Ptr<recob::Hit>> trackhits;
94 if (trackhits.empty()) {
96 mf::LogWarning(
"ShowerUnidirectiondEdx") <<
"Not Hits in the initial track" << std::endl;
100 geo::Point_t ShowerStartPosition = {-999, -999, -999};
103 geo::Vector_t showerDir = {-999, -999, -999};
106 geo::TPCID vtxTPC =
fGeom->FindTPCAtPosition(geo::vect::toPoint(ShowerStartPosition));
109 std::vector<double> dEdxVec;
110 std::vector<std::vector<art::Ptr<recob::Hit>>> trackHits;
111 unsigned int numPlanes =
fGeom->Nplanes();
112 trackHits.resize(numPlanes);
115 for (
unsigned int hitIt = 0; hitIt < trackhits.size(); ++hitIt) {
116 art::Ptr<recob::Hit> hit = trackhits.at(hitIt);
117 geo::PlaneID hitWire = hit->WireID();
118 geo::TPCID TPC = hitWire.asTPCID();
121 if (TPC == vtxTPC) { (trackHits.at(hitWire.Plane)).push_back(hit); }
124 int bestHitsPlane = 0;
125 int bestPlaneHits = 0;
126 int bestPlane = -999;
127 double minPitch = 999;
129 auto const clockData =
130 art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(Event);
132 art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(Event, clockData);
134 for (
unsigned int plane = 0; plane < numPlanes; ++plane) {
135 std::vector<art::Ptr<recob::Hit>> trackPlaneHits = trackHits.at(plane);
137 std::map<art::Ptr<recob::Hit>, std::vector<art::Ptr<recob::Hit>>> hitSnippets;
141 if (trackPlaneHits.size()) {
149 double wirepitch =
fGeom->WirePitch(trackPlaneHits.at(0)->WireID().planeID());
151 fGeom->WireAngleToVertical(
fGeom->Plane(geo::PlaneID{0, 0, plane}).View(),
152 trackPlaneHits[0]->WireID().planeID()) -
155 std::abs(std::sin(angleToVert) * showerDir.Y() + std::cos(angleToVert) * showerDir.Z());
157 pitch = wirepitch / cosgamma;
161 std::vector<float> vQ;
164 int w0 = trackPlaneHits.at(0)->WireID().Wire;
166 for (
auto const& hit : trackPlaneHits) {
171 int w1 = hit->WireID().Wire;
177 double q = hit->Integral();
179 for (
const art::Ptr<recob::Hit> secondaryHit : hitSnippets[hit])
180 q += secondaryHit->Integral();
184 totQ += hit->Integral();
185 avgT += hit->PeakTime();
192 if (pitch < minPitch) {
198 double dQdx = TMath::Median(vQ.size(), &vQ[0]) / pitch;
200 clockData, detProp, dQdx, avgT / nhits, trackPlaneHits.at(0)->WireID().Plane);
202 if (isinf(dEdx)) { dEdx = -999; };
204 if (nhits > bestPlaneHits || ((nhits == bestPlaneHits) && (pitch < minPitch))) {
205 bestHitsPlane = plane;
206 bestPlaneHits = nhits;
209 dEdxVec.push_back(dEdx);
212 throw cet::exception(
"ShowerUnidirectiondEdx")
213 <<
"pitch is 0. I can't think how it is 0? Stopping so I can tell you" << std::endl;
217 dEdxVec.push_back(-999);
219 trackPlaneHits.clear();
223 std::vector<double> dEdxVecErr = {-999, -999, -999};
230 if (bestPlane == -999) {
231 throw cet::exception(
"ShowerUnidirectiondEdx") <<
"No best plane set";
238 std::cout <<
"Best Plane: " << bestPlane << std::endl;
239 for (
unsigned int plane = 0; plane < dEdxVec.size(); plane++) {
240 std::cout <<
"Plane: " << plane <<
" with dEdx: " << dEdxVec[plane] << std::endl;