4 : fUseCollectionOnly(pset.
get<
bool>(
"UseCollectionOnly"))
5 , fPFParticleLabel(pset.
get<
art::InputTag>(
"PFParticleLabel"))
6 , fSCEXFlip(pset.
get<
bool>(
"SCEXFlip"))
8 , fInitialTrackInputLabel(pset.
get<
std::
string>(
"InitialTrackInputLabel"))
9 , fShowerStartPositionInputLabel(pset.
get<
std::
string>(
"ShowerStartPositionInputLabel"))
10 , fShowerDirectionInputLabel(pset.
get<
std::
string>(
"ShowerDirectionInputLabel"))
11 , fInitialTrackSpacePointsInputLabel(pset.
get<
std::
string>(
"InitialTrackSpacePointsInputLabel"))
20 TVector3
const& ShowerStartPosition,
21 TVector3
const& ShowerDirection)
const 24 std::map<double, art::Ptr<recob::Hit>> OrderedHits;
36 TVector2 Shower2DStartPosition = {
38 ShowerStartPosition.X()};
44 TVector2 Shower2DDirection = {ShowerDirection.Dot(PlaneDirection), ShowerDirection.X()};
46 Shower2DDirection = Shower2DDirection.Unit();
48 for (
auto const&
hit : hits) {
59 TVector2
pos = hitcoord - Shower2DStartPosition;
60 OrderedHits[pos * Shower2DDirection] =
hit;
64 std::vector<art::Ptr<recob::Hit>> showerHits;
65 std::transform(OrderedHits.begin(),
67 std::back_inserter(showerHits),
68 [](std::pair<double, art::Ptr<recob::Hit>>
const&
hit) {
return hit.second; });
76 TVector2 frontpos = fronthitcoord - Shower2DStartPosition;
80 TVector2 backpos = backhitcoord - Shower2DStartPosition;
82 double frontproj = frontpos * Shower2DDirection;
83 double backproj = backpos * Shower2DDirection;
101 std::map<double, art::Ptr<recob::SpacePoint>> OrderedSpacePoints;
104 for (
auto const& sp : showersps) {
110 OrderedSpacePoints[perp] = sp;
115 for (
auto const& sp : OrderedSpacePoints) {
116 showersps.push_back(sp.second);
129 std::map<double, art::Ptr<recob::SpacePoint>> OrderedSpacePoints;
132 for (
auto const& sp : showersps) {
138 OrderedSpacePoints[len] = sp;
143 for (
auto const& sp : OrderedSpacePoints) {
144 showersps.push_back(sp.second);
151 TVector3
const&
vertex)
const 154 std::map<double, art::Ptr<recob::SpacePoint>> OrderedSpacePoints;
157 for (
auto const& sp : showersps) {
163 OrderedSpacePoints[mag] = sp;
168 for (
auto const& sp : OrderedSpacePoints) {
169 showersps.push_back(sp.second);
178 if (showersps.empty())
return TVector3{};
180 TVector3 centre_position;
181 for (
auto const& sp : showersps) {
183 centre_position +=
pos;
185 centre_position *= (1. / showersps.size());
187 return centre_position;
195 art::FindManyP<recob::Hit>
const& fmh)
const 198 float totalCharge = 0;
200 clockData, detProp, showerspcs, fmh, totalCharge);
208 art::FindManyP<recob::Hit>
const& fmh,
209 float& totalCharge)
const 212 TVector3
pos, chargePoint = TVector3(0, 0, 0);
215 for (
auto const& sp : showersps) {
221 std::vector<art::Ptr<recob::Hit>>
const& hits = fmh.at(sp.key());
226 for (
auto const&
hit : hits) {
230 charge =
hit->Integral();
250 float mean = charge / ((
float)hits.size());
254 if (hits.size() > 1) {
255 rms = std::sqrt((charge2 - charge * charge) / ((
float)(hits.size() - 1)));
260 for (
auto const&
hit : hits) {
261 double lifetimecorrection = std::exp((
sampling_rate(clockData) *
hit->PeakTime()) /
263 if (
hit->Integral() * lifetimecorrection > (mean - 2 *
rms) &&
264 hit->Integral() * lifetimecorrection < (mean + 2 *
rms)) {
265 charge +=
hit->Integral() * lifetimecorrection;
271 mf::LogWarning(
"LArPandoraShowerAlg") <<
"no points used to make the charge value. \n";
277 chargePoint += charge *
pos;
278 totalCharge += charge;
281 mf::LogWarning(
"LArPandoraShowerAlg") <<
"Averaged charge, within 2 sigma, for a spacepoint " 282 "is zero, Maybe this not a good method. \n";
286 double intotalcharge = 1 / totalCharge;
287 TVector3 centre = chargePoint * intotalcharge;
296 const Double32_t* sp_xyz = sp->
XYZ();
297 return TVector3{sp_xyz[0], sp_xyz[1], sp_xyz[2]};
307 return (position_a - position_b).Mag();
313 art::FindManyP<recob::Hit>
const& fmh)
const 319 std::vector<art::Ptr<recob::Hit>>
const& hits = fmh.at(sp.
key());
320 for (
auto const&
hit : hits) {
321 Charge +=
hit->Integral();
324 Charge /= (
float)hits.size();
332 art::FindManyP<recob::Hit>
const& fmh)
const 338 std::vector<art::Ptr<recob::Hit>>
const& hits = fmh.at(sp.
key());
339 for (
auto const&
hit : hits) {
340 Time +=
hit->PeakTime();
343 Time /= (
float)hits.size();
371 return pos.Dot(direction);
408 const unsigned int nSegments)
const 413 <<
"Unable to calculate RMS Shower Gradient with 0 segments" <<
std::endl;
415 if (sps.size() < 3)
return 0;
424 const double length = (maxProj - minProj);
425 const double segmentsize = length / nSegments;
427 if (segmentsize < std::numeric_limits<double>::epsilon())
return 0;
429 std::map<int, std::vector<float>> len_segment_map;
432 for (
auto const& sp : sps) {
440 int sg_len = std::round(len / segmentsize);
441 len_segment_map[sg_len].push_back(len_perp);
451 for (
auto const& segment : len_segment_map) {
452 if (segment.second.size() < 2)
continue;
456 if (RMS < 0)
continue;
459 sumx += segment.first;
461 sumx2 += segment.first * segment.first;
462 sumxy += RMS * segment.first;
466 const float denom = counter * sumx2 - sumx * sumx;
468 return std::abs(denom) < std::numeric_limits<float>::epsilon() ?
470 (counter * sumxy - sumx * sumy) / denom;
477 if (perps.size() < 2)
return std::numeric_limits<double>::lowest();
480 for (
const auto& perp : perps) {
484 return std::sqrt(sum / (perps.size() - 1));
491 unsigned int const&
TPC)
const 501 unsigned int const&
TPC)
const 506 <<
"Trying to correct SCE pitch when service is not configured" <<
std::endl;
520 geo::Vector_t pitchVec{pitch * dir.X() + xFlip * (nextPosOffset.X() - posOffset.X()),
521 pitch * dir.Y() + (nextPosOffset.Y() - posOffset.Y()),
522 pitch * dir.Z() + (nextPosOffset.Z() - posOffset.Z())};
540 <<
"Trying to correct SCE EField when service is not configured" <<
std::endl;
547 EFieldOffsets *= EField;
549 return EFieldOffsets.r();
559 std::cout <<
"Making Debug Event Display" <<
std::endl;
565 int subRun = Event.
subRun();
566 int event = Event.
event();
567 int PFPID = pfparticle->
Self();
570 TString canvasName = Form(
"canvas_%i_%i_%i_%i", run, subRun,
event, PFPID);
571 if (evd_disp_name_append.length() > 0) canvasName +=
"_" + evd_disp_name_append;
572 TCanvas* canvas =
tfs->make<TCanvas>(canvasName, canvasName);
590 art::FindManyP<recob::SpacePoint> fmspp(pfpHandle, Event,
fPFParticleLabel);
591 if (!fmspp.isValid()) {
592 throw cet::exception(
"LArPandoraShowerAlg") <<
"Trying to get the spacepoint and failed. Somet\ 593 hing is not configured correctly. Stopping ";
597 std::vector<art::Ptr<recob::SpacePoint>>
const& spacePoints = fmspp.at(pfparticle.
key());
600 if (spacePoints.empty()) {
return; }
603 TVector3 showerStartPosition = {-999, -999, -999};
604 TVector3 showerDirection = {-999, -999, -999};
605 std::vector<art::Ptr<recob::SpacePoint>> trackSpacePoints;
610 double startXYZ[3] = {-999, -999, -999};
618 startXYZ[0] = showerStartPosition.X();
619 startXYZ[1] = showerStartPosition.Y();
620 startXYZ[2] = showerStartPosition.Z();
622 auto startPoly = std::make_unique<TPolyMarker3D>(1, startXYZ);
628 double xDirPoints[2] = {-999, -999};
629 double yDirPoints[2] = {-999, -999};
630 double zDirPoints[2] = {-999, -999};
636 auto allPoly = std::make_unique<TPolyMarker3D>(spacePoints.size());
654 for (
auto spacePoint : spacePoints) {
660 allPoly->SetPoint(point, x, y, z);
672 spacePoint, showerStartPosition, showerDirection);
677 xDirPoints[0] = (showerStartPosition.X() + minProj * showerDirection.X());
678 xDirPoints[1] = (showerStartPosition.X() + maxProj * showerDirection.X());
680 yDirPoints[0] = (showerStartPosition.Y() + minProj * showerDirection.Y());
681 yDirPoints[1] = (showerStartPosition.Y() + maxProj * showerDirection.Y());
683 zDirPoints[0] = (showerStartPosition.Z() + minProj * showerDirection.Z());
684 zDirPoints[1] = (showerStartPosition.Z() + maxProj * showerDirection.Z());
687 auto dirPoly = std::make_unique<TPolyLine3D>(2, xDirPoints, yDirPoints, zDirPoints);
693 auto trackPoly = std::make_unique<TPolyMarker3D>(trackSpacePoints.size());
701 for (
auto spacePoint : trackSpacePoints) {
707 trackPoly->SetPoint(point, x, y, z);
724 std::vector<art::Ptr<recob::PFParticle>> pfps;
729 int pfpTrackCounter = 0;
730 int pfpShowerCounter = 0;
733 for (
auto const& pfp : pfps) {
734 std::vector<art::Ptr<recob::SpacePoint>>
const& sps = fmspp.at(pfp.key());
736 int pdg =
abs(pfp->PdgCode());
737 if (pdg == 11 || pdg == 22) { pfpShowerCounter += sps.size(); }
739 pfpTrackCounter += sps.size();
743 auto pfpPolyTrack = std::make_unique<TPolyMarker3D>(pfpTrackCounter);
744 auto pfpPolyShower = std::make_unique<TPolyMarker3D>(pfpShowerCounter);
748 int showerPoints = 0;
750 for (
auto const& pfp : pfps) {
751 std::vector<art::Ptr<recob::SpacePoint>>
const& sps = fmspp.at(pfp.key());
752 int pdg =
abs(pfp->PdgCode());
753 for (
auto sp : sps) {
768 if (pdg == 11 || pdg == 22) {
769 pfpPolyShower->SetPoint(showerPoints, x, y, z);
773 pfpPolyTrack->SetPoint(trackPoints, x, y, z);
786 auto TrackTrajPoly = std::make_unique<TPolyMarker3D>(TPolyMarker3D(1));
787 auto TrackInitTrajPoly = std::make_unique<TPolyMarker3D>(TPolyMarker3D(1));
806 TVector3 TrajPosition = {
807 TrajPositionPoint.X(), TrajPositionPoint.Y(), TrajPositionPoint.Z()};
809 TVector3
pos = TrajPosition;
814 TrackTrajPoly->SetPoint(point, x, y, z);
819 TVector3 TrajPosition = {
820 TrajInitPositionPoint.X(), TrajInitPositionPoint.Y(), TrajInitPositionPoint.Z()};
821 TVector3
pos = TrajPosition;
825 TrackInitTrajPoly->SetPoint(TrackInitTrajPoly->GetN(),
x,
y,
z);
829 gStyle->SetOptStat(0);
830 TH3F axes(
"axes",
"", 1, x_min, x_max, 1, y_min, y_max, 1, z_min, z_max);
831 axes.SetDirectory(0);
832 axes.GetXaxis()->SetTitle(
"X");
833 axes.GetYaxis()->SetTitle(
"Y");
834 axes.GetZaxis()->SetTitle(
"Z");
838 pfpPolyShower->SetMarkerStyle(20);
839 pfpPolyShower->SetMarkerColor(4);
840 pfpPolyShower->Draw();
841 pfpPolyTrack->SetMarkerStyle(20);
842 pfpPolyTrack->SetMarkerColor(6);
843 pfpPolyTrack->Draw();
844 allPoly->SetMarkerStyle(20);
846 trackPoly->SetMarkerStyle(20);
847 trackPoly->SetMarkerColor(2);
849 startPoly->SetMarkerStyle(21);
850 startPoly->SetMarkerSize(0.5);
851 startPoly->SetMarkerColor(3);
853 dirPoly->SetLineWidth(1);
854 dirPoly->SetLineColor(6);
856 TrackTrajPoly->SetMarkerStyle(22);
857 TrackTrajPoly->SetMarkerColor(7);
858 TrackTrajPoly->Draw();
859 TrackInitTrajPoly->SetMarkerStyle(22);
860 TrackInitTrajPoly->SetMarkerColor(4);
861 TrackInitTrajPoly->Draw();
void OrderShowerSpacePointsPerpendicular(std::vector< art::Ptr< recob::SpacePoint >> &showersps, TVector3 const &vertex, TVector3 const &direction) const
geo::Length_t WireCoordinate(double YPos, double ZPos, geo::PlaneID const &planeid) const
Returns the index of the nearest wire to the specified position.
virtual bool EnableSimEfieldSCE() const =0
double SCECorrectPitch(double const &pitch, TVector3 const &pos, TVector3 const &dir, unsigned int const &TPC) const
double DistanceBetweenSpacePoints(art::Ptr< recob::SpacePoint > const &sp_a, art::Ptr< recob::SpacePoint > const &sp_b) const
EventNumber_t event() const
PlaneGeo const & Plane(unsigned int const p, unsigned int const tpc=0, unsigned int const cstat=0) const
Returns the specified wire.
size_t Self() const
Returns the index of this particle.
double rms(sqlite3 *db, std::string const &table_name, std::string const &column_name)
void DebugEVD(art::Ptr< recob::PFParticle > const &pfparticle, art::Event const &Event, const reco::shower::ShowerElementHolder &ShowerEleHolder, std::string const &evd_disp_name_append="") const
static constexpr Flag_t NoPoint
The trajectory point is not defined.
double CalculateRMS(const std::vector< float > &perps) const
virtual geo::Vector_t GetCalPosOffsets(geo::Point_t const &point, int const &TPCid) const =0
void OrderShowerSpacePoints(std::vector< art::Ptr< recob::SpacePoint >> &showersps, TVector3 const &vertex, TVector3 const &direction) const
geo::WireID WireID() const
art::InputTag fPFParticleLabel
art::ServiceHandle< geo::Geometry const > fGeom
Point_t const & LocationAtPoint(size_t i) const
The data type to uniquely identify a Plane.
const std::string fInitialTrackInputLabel
size_t NumberTrajectoryPoints() const
Various functions related to the presence and the number of (valid) points.
double ElectronLifetime() const
WireID_t Wire
Index of the wire within its plane.
double RMSShowerGradient(std::vector< art::Ptr< recob::SpacePoint >> &sps, const TVector3 &ShowerCentre, const TVector3 &Direction, const unsigned int nSegments) const
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space.
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
double SpacePointTime(art::Ptr< recob::SpacePoint > const &sp, art::FindManyP< recob::Hit > const &fmh) const
Vector GetIncreasingWireDirection() const
Returns the direction of increasing wires.
double SCECorrectEField(double const &EField, TVector3 const &pos) const
geo::Length_t WirePitch(geo::PlaneID const &planeid) const
Returns the distance between two consecutive wires.
LArPandoraShowerAlg(const fhicl::ParameterSet &pset)
virtual geo::Vector_t GetPosOffsets(geo::Point_t const &point) const =0
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
const std::string fInitialTrackSpacePointsInputLabel
key_type key() const noexcept
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
bool CheckElement(const std::string &Name) const
const std::string fShowerDirectionInputLabel
SubRunNumber_t subRun() const
constexpr PlaneID const & asPlaneID() const
Conversion to PlaneID (for convenience of notation).
double SpacePointProjection(art::Ptr< recob::SpacePoint > const &sp, TVector3 const &vertex, TVector3 const &direction) const
static int max(int a, int b)
int GetElement(const std::string &Name, T &Element) const
const std::string fShowerStartPositionInputLabel
Detector simulation of raw signals on wires.
double ConvertTicksToX(double ticks, int p, int t, int c) const
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
double SpacePointCharge(art::Ptr< recob::SpacePoint > const &sp, art::FindManyP< recob::Hit > const &fmh) const
art::ServiceHandle< art::TFileService > tfs
virtual geo::Vector_t GetEfieldOffsets(geo::Point_t const &point) const =0
float PeakTime() const
Time of the signal peak, in tick units.
virtual bool EnableCalSpatialSCE() const =0
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
LArSoft-specific namespace.
Contains all timing reference information for the detector.
static unsigned int reverse(QString &chars, unsigned char *level, unsigned int a, unsigned int b)
TVector2 HitCoordinates(detinfo::DetectorPropertiesData const &detProp, art::Ptr< recob::Hit > const &hit) const
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
const Double32_t * XYZ() const
PointFlags_t const & FlagsAtPoint(size_t i) const
TVector3 ShowerCentre(std::vector< art::Ptr< recob::SpacePoint >> const &showersps) const
T::provider_type const * providerFrom()
Returns a constant pointer to the provider of specified service.
double SpacePointPerpendicular(art::Ptr< recob::SpacePoint > const &sp, TVector3 const &vertex, TVector3 const &direction) const
constexpr PlaneID const & planeID() const
auto const & get(AssnsNode< L, R, D > const &r)
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock.
spacecharge::SpaceCharge const * fSCE
double mean(sqlite3 *db, std::string const &table_name, std::string const &column_name)
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
cet::coded_exception< error, detail::translate > exception
QTextStream & endl(QTextStream &s)
Event finding and building.
TVector3 SpacePointPosition(art::Ptr< recob::SpacePoint > const &sp) const
Signal from collection planes.
void OrderShowerHits(detinfo::DetectorPropertiesData const &detProp, std::vector< art::Ptr< recob::Hit >> &hits, TVector3 const &ShowerDirection, TVector3 const &ShowerPosition) const