74 mf::LogError(
"ShowerUnidirectiondEdx") <<
"Start position not set, returning " << std::endl;
79 mf::LogError(
"ShowerUnidirectiondEdx")
80 <<
"Initial Track Hits not set returning" << std::endl;
85 mf::LogError(
"ShowerUnidirectiondEdx") <<
"Shower Direction not set" << std::endl;
90 std::vector<art::Ptr<recob::Hit>> trackhits;
93 if (trackhits.empty()) {
95 mf::LogWarning(
"ShowerUnidirectiondEdx") <<
"Not Hits in the initial track" << std::endl;
99 TVector3 ShowerStartPosition = {-999, -999, -999};
102 TVector3 showerDir = {-999, -999, -999};
108 std::vector<double> dEdxVec;
109 std::vector<std::vector<art::Ptr<recob::Hit>>> trackHits;
110 unsigned int numPlanes =
fGeom->Nplanes();
111 trackHits.resize(numPlanes);
114 for (
unsigned int hitIt = 0; hitIt < trackhits.size(); ++hitIt) {
115 art::Ptr<recob::Hit>
hit = trackhits.at(hitIt);
120 if (TPC == vtxTPC) { (trackHits.at(hitWire.
Plane)).push_back(hit); }
123 int bestHitsPlane = 0;
124 int bestPlaneHits = 0;
125 int bestPlane = -999;
126 double minPitch = 999;
128 auto const clockData =
129 art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(Event);
131 art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(Event, clockData);
133 for (
unsigned int plane = 0; plane < numPlanes; ++plane) {
134 std::vector<art::Ptr<recob::Hit>> trackPlaneHits = trackHits.at(plane);
136 if (trackPlaneHits.size()) {
144 double wirepitch =
fGeom->WirePitch(trackPlaneHits.at(0)->WireID().planeID());
145 double angleToVert =
fGeom->WireAngleToVertical(
fGeom->Plane(plane).View(),
146 trackPlaneHits[0]->WireID().planeID()) -
149 std::abs(std::sin(angleToVert) * showerDir.Y() + std::cos(angleToVert) * showerDir.Z());
151 pitch = wirepitch / cosgamma;
155 std::vector<float> vQ;
158 int w0 = trackPlaneHits.at(0)->WireID().Wire;
160 for (
auto const& hit : trackPlaneHits) {
163 int w1 = hit->WireID().Wire;
168 vQ.push_back(hit->Integral());
169 totQ += hit->Integral();
170 avgT += hit->PeakTime();
177 if (pitch < minPitch) {
183 double dQdx = TMath::Median(vQ.size(), &vQ[0]) / pitch;
185 clockData,
detProp, dQdx, avgT / nhits, trackPlaneHits.at(0)->WireID().Plane);
187 if (isinf(dEdx)) { dEdx = -999; };
189 if (nhits > bestPlaneHits || ((nhits == bestPlaneHits) && (pitch < minPitch))) {
190 bestHitsPlane = plane;
191 bestPlaneHits = nhits;
194 dEdxVec.push_back(dEdx);
197 throw cet::exception(
"ShowerUnidirectiondEdx")
198 <<
"pitch is 0. I can't think how it is 0? Stopping so I can tell you" << std::endl;
202 dEdxVec.push_back(-999);
204 trackPlaneHits.clear();
208 std::vector<double> dEdxVecErr = {-999, -999, -999};
215 if (bestPlane == -999) {
216 throw cet::exception(
"ShowerUnidirectiondEdx") <<
"No best plane set";
223 std::cout <<
"Best Plane: " << bestPlane << std::endl;
224 for (
unsigned int plane = 0; plane < dEdxVec.size(); plane++) {
225 std::cout <<
"Plane: " << plane <<
" with dEdx: " << dEdxVec[plane] << std::endl;
The data type to uniquely identify a Plane.
void SetElement(T &dataproduct, const std::string &Name, bool checktag=false)
bool CheckElement(const std::string &Name) const
The data type to uniquely identify a TPC.
PlaneID_t Plane
Index of the plane within its TPC.
int GetElement(const std::string &Name, T &Element) const
float dEdx(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, const TCSlice &slc, TP3D &tp3d)
constexpr TPCID const & asTPCID() const
Conversion to TPCID (for convenience of notation).
double dEdx_AREA(detinfo::DetectorClocksData const &clock_data, detinfo::DetectorPropertiesData const &det_prop, recob::Hit const &hit, double pitch, double T0=0) const
BEGIN_PROLOG could also be cout