22 #include "art/Framework/Core/EDProducer.h"
23 #include "art/Framework/Core/ModuleMacros.h"
24 #include "art/Framework/Principal/Event.h"
25 #include "art/Framework/Principal/Handle.h"
26 #include "art/Framework/Services/Registry/ServiceHandle.h"
27 #include "art_root_io/TFileService.h"
28 #include "canvas/Persistency/Common/FindManyP.h"
29 #include "canvas/Persistency/Common/Ptr.h"
30 #include "canvas/Persistency/Common/PtrVector.h"
31 #include "fhiclcpp/ParameterSet.h"
32 #include "messagefacility/MessageLogger/MessageLogger.h"
54 #include "range/v3/view.hpp"
60 explicit ShowerReco(fhicl::ParameterSet
const& pset);
109 std::vector<std::vector<double>>
112 std::vector<std::vector<double>>
130 std::vector<std::vector<double>>
164 fClusterModuleLabel = pset.get<std::string>(
"ClusterModuleLabel");
165 fCaloPSet = pset.get<fhicl::ParameterSet>(
"CaloAlg");
168 pset.get<
double>(
"dEdxlength");
170 pset.get<
double>(
"calodEdxlength");
171 fUseArea = pset.get<
bool>(
"UseArea");
173 produces<std::vector<recob::Shower>>();
174 produces<art::Assns<recob::Shower, recob::Cluster>>();
175 produces<art::Assns<recob::Shower, recob::Hit>>();
176 produces<std::vector<anab::Calorimetry>>();
177 produces<art::Assns<recob::Shower, anab::Calorimetry>>();
184 art::ServiceHandle<geo::Geometry const> geo;
192 auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataForJob();
196 art::ServiceHandle<art::TFileService const>
tfs;
222 "ChargedistributionADC",
"std::vector<std::vector<double>>", &
fDistribChargeADC);
224 "ChargedistributionMeV",
"std::vector<std::vector<double>>", &
fDistribChargeMeV);
235 auto const* geom = lar::providerFrom<geo::Geometry>();
236 auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataForJob();
238 art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataForJob();
247 ShowerReco::ShowerReco::ClearandResizeVectors(
unsigned int )
251 for (
unsigned int i = 1; i <= fNPlanes; ++i)
256 fDistribChargeADC.clear();
257 fDistribChargeMeV.clear();
258 fDistribChargeposition.clear();
260 fDistribChargeADC.resize(fNPlanes);
261 fDistribChargeMeV.resize(fNPlanes);
262 fDistribChargeposition.resize(fNPlanes);
265 fDistribChargeADC.clear();
266 fDistribChargeMeV.clear();
267 fDistribHalfChargeMeV.clear();
268 fDistribChargeposition.clear();
270 fNPitch.resize(fNAngles);
271 fDistribChargeADC.resize(fNPlanes);
272 fDistribChargeMeV.resize(fNPlanes);
273 fDistribHalfChargeMeV.resize(fNPlanes);
274 fDistribChargeposition.resize(fNPlanes);
276 for (
unsigned int ii = 0; ii < fNAngles; ii++) {
277 fNPitch[ii].resize(fNPlanes, -1);
280 fNpoints_corr_ADC_2cm.clear();
281 fNpoints_corr_MeV_2cm.clear();
283 fNpoints_corr_ADC_2cm.resize(fNAngles, -1);
284 fNpoints_corr_MeV_2cm.resize(fNAngles, -1);
286 for (
unsigned int ii = 0; ii < fNPlanes; ii++) {
287 fDistribChargeADC[ii].resize(0);
288 fDistribChargeMeV[ii].resize(0);
289 fDistribHalfChargeMeV[ii].resize(0);
290 fDistribChargeposition[ii].resize(0);
293 fWire_vertex.clear();
294 fTime_vertex.clear();
295 fWire_vertexError.clear();
296 fTime_vertexError.clear();
299 fTotChargeADC.clear();
300 fTotChargeMeV.clear();
301 fTotChargeMeV_MIPs.clear();
303 fNpoints_2cm.clear();
305 fNhitsperplane.clear();
306 fTotADCperplane.clear();
308 fWire_vertex.resize(fNAngles, -1);
309 fTime_vertex.resize(fNAngles, -1);
310 fWire_vertexError.resize(fNPlanes, -1);
311 fTime_vertexError.resize(fNPlanes, -1);
312 fWire_last.resize(fNAngles, -1);
313 fTime_last.resize(fNAngles, -1);
314 fTotChargeADC.resize(fNAngles, 0);
315 fTotChargeMeV.resize(fNAngles, 0);
316 fTotChargeMeV_MIPs.resize(fNAngles, 0);
317 fRMS_2cm.resize(fNAngles, 0);
318 fNpoints_2cm.resize(fNAngles, 0);
320 fCorr_MeV_2cm.clear();
321 fCorr_Charge_2cm.clear();
322 xyz_vertex_fit.clear();
324 fChargeADC_2cm.clear();
325 fChargeMeV_2cm.clear();
326 fChargeMeV_2cm_refined.clear();
327 fChargeMeV_2cm_refined.clear();
328 fChargeMeV_2cm_axsum.clear();
330 fCorr_MeV_2cm.resize(fNAngles, 0);
331 fCorr_Charge_2cm.resize(fNAngles, 0);
332 xyz_vertex_fit.resize(3);
334 fChargeADC_2cm.resize(fNAngles,
336 fChargeMeV_2cm.resize(fNAngles,
338 fChargeMeV_2cm_refined.resize(0);
339 fChargeMeV_2cm_refined.resize(fNAngles, 0);
340 fChargeMeV_2cm_axsum.resize(fNAngles, 0);
342 fNhitsperplane.resize(fNPlanes, -1);
343 fTotADCperplane.resize(fNPlanes, -1);
354 auto const* geom = lar::providerFrom<geo::Geometry>();
355 auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
357 art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(evt, clockData);
360 fNPlanes = geom->Nplanes();
361 auto Shower3DVector = std::make_unique<std::vector<recob::Shower>>();
362 auto cassn = std::make_unique<art::Assns<recob::Shower, recob::Cluster>>();
363 auto hassn = std::make_unique<art::Assns<recob::Shower, recob::Hit>>();
364 auto calorimetrycol = std::make_unique<std::vector<anab::Calorimetry>>();
365 auto calassn = std::make_unique<art::Assns<anab::Calorimetry, recob::Shower>>();
369 art::Handle<std::vector<recob::Cluster>> clusterListHandle;
372 art::Handle<std::vector<art::PtrVector<recob::Cluster>>> clusterAssociationHandle;
377 fRun = evt.id().run();
379 fEvent = evt.id().event();
386 std::vector<art::PtrVector<recob::Cluster>>::const_iterator clusterSet =
387 clusterAssociationHandle->begin();
389 for (
size_t iClustSet = 0; iClustSet < clusterAssociationHandle->size(); iClustSet++) {
391 const art::PtrVector<recob::Cluster> CurrentClusters = (*(clusterSet++));
394 if (clusterListHandle->size() < 2 || CurrentClusters.size() < 2) {
401 std::vector<std::vector<art::Ptr<recob::Hit>>> hitlist_all;
402 hitlist_all.resize(fNPlanes);
404 for (
size_t iClust = 0; iClust < CurrentClusters.size(); iClust++) {
405 art::Ptr<recob::Cluster>
const& pclust = CurrentClusters[iClust];
411 std::vector<art::Ptr<recob::Hit>>
const& hitlist = ClusterHits.at(pclust.key());
415 if (hitlist.size() == 0)
continue;
417 p = (*hitlist.begin())->
WireID().Plane;
422 double ADCcharge = 0;
424 for (art::Ptr<recob::Hit>
const&
hit : hitlist) {
425 p =
hit->WireID().Plane;
426 hitlist_all[
p].push_back(
hit);
427 ADCcharge +=
hit->PeakAmplitude();
435 unsigned int bp1 = 0, bp2 = 0;
436 double minerror1 = 99999999, minerror2 = 9999999;
437 for (
unsigned int ii = 0; ii <
fNPlanes; ++ii) {
442 if (minerror1 >= locerror)
444 minerror1 = locerror;
448 for (
unsigned int ij = 0; ij <
fNPlanes; ++ij) {
453 if (minerror2 >= locerror && ij != bp1) {
454 minerror2 = locerror;
462 const double origin[3] = {0.};
463 std::vector<std::vector<double>> position;
467 for (
unsigned int xx = 0; xx <
fNPlanes; xx++) {
469 geom->Plane(xx).LocalToWorld(origin, pos1);
470 std::vector<double> pos2;
471 pos2.push_back(pos1[0]);
472 pos2.push_back(pos1[1]);
473 pos2.push_back(pos1[2]);
474 position.push_back(pos2);
480 int chan1 = geom->PlaneWireToChannel(bp1,
fWire_vertex[bp1], 0);
481 int chan2 = geom->PlaneWireToChannel(bp2,
fWire_vertex[bp2], 0);
484 geom->ChannelsIntersect(chan1, chan2, y, z);
492 catch (cet::exception
const&
e) {
493 mf::LogWarning(
"ShowerReco") <<
"caught exception \n" <<
e;
500 if (bp1 != fNPlanes - 1 && bp2 != fNPlanes - 1) {
502 unsigned int wirevertex;
504 geom->Plane(fNPlanes - 1).LocalToWorld(origin, pos);
508 wirevertex = geom->NearestWire(pos, fNPlanes - 1);
521 if (fabs(
xphi) < 5.) {
522 xtheta = gser.Get3DSpecialCaseTheta(
527 for (
unsigned int i = 0; i <
fNAngles; ++i) {
545 if (!(fabs(
xphi) > 89 && fabs(
xphi) < 91))
550 hitlist_all[fNPlanes - 1]);
555 art::PtrVector<recob::Cluster> prodvec;
556 for (
unsigned int i = 0; i < clusterListHandle->size(); ++i) {
557 art::Ptr<recob::Cluster> prod(clusterListHandle, i);
558 prodvec.push_back(prod);
562 std::vector<recob::SpacePoint> spcpts;
570 TMath::Cos(fPhi * TMath::Pi() / 180) * TMath::Sin(fTheta * TMath::Pi() / 180),
571 TMath::Cos(fTheta * TMath::Pi() / 180),
572 TMath::Sin(fPhi * TMath::Pi() / 180) * TMath::Sin(fTheta * TMath::Pi() / 180));
581 Shower3DVector->push_back(singShower);
586 for (
size_t p = 0;
p < prodvec.size(); ++
p) {
587 std::vector<art::Ptr<recob::Hit>> hits = fmh.at(
p);
592 calorimetrycol->emplace_back(
595 art::PtrVector<recob::Shower> ssvec;
597 art::ProductID aid = evt.getProductID<std::vector<recob::Shower>>();
598 art::Ptr<recob::Shower> aptr(aid, 0, evt.productGetter(aid));
599 ssvec.push_back(aptr);
605 evt.put(std::move(Shower3DVector));
606 evt.put(std::move(cassn));
607 evt.put(std::move(hassn));
608 evt.put(std::move(calorimetrycol));
609 evt.put(std::move(calassn));
629 unsigned int wire = 0, plane = fNPlanes - 1;
631 double mevav2cm = 0.;
633 double npoints_calo = 0;
638 if (fabs(
xphi) < 90) direction = 1;
641 double ortdist, linedist;
642 double wire_on_line, time_on_line;
646 double newpitch = gser.PitchInView(plane,
xphi,
xtheta);
651 time =
hit.PeakTime();
652 wire =
hit.WireID().Wire;
653 plane =
hit.WireID().Plane;
661 dEdx_new = calalg.
dEdx_AMP(clockData, detProp,
hit, newpitch);
665 totCnrg_corr += dEdx_new;
677 ortdist = gser.Get2DDistance(wire_on_line, time_on_line, wire, time);
680 double wdist = (((double)wire - (
double)
fWire_vertex[plane]) * newpitch) *
685 vdEdx.push_back(dEdx_new);
687 vdQdx.push_back(
hit.PeakAmplitude() / newpitch);
690 Kin_En += dEdx_new * newpitch;
713 auto const signalType =
726 time =
hit.PeakTime();
727 wire =
hit.WireID().Wire;
728 plane =
hit.WireID().Plane;
735 dEdx = calalg.
dEdx_AMP(clockData, detProp,
hit, newpitch);
747 ortdist = gser.Get2DDistance(wire_on_line, time_on_line, wire, time);
749 double wdist = (((double)wire - (
double)
fWire_vertex[plane]) * newpitch) * direction;
756 fRMS_2cm[set] += (dEdx - mevav2cm) * (dEdx - mevav2cm);
767 time =
hit.PeakTime();
768 wire =
hit.WireID().Wire;
769 plane =
hit.WireID().Plane;
776 dEdx = calalg.
dEdx_AMP(clockData, detProp,
hit, newpitch);
788 ortdist = gser.Get2DDistance(wire_on_line, time_on_line, wire, time);
790 double wdist = (((double)wire - (
double)
fWire_vertex[plane]) * newpitch) * direction;
797 if (((dEdx > (mevav2cm -
fRMS_2cm[set])) && (dEdx < (mevav2cm +
fRMS_2cm[set]))) ||
819 angle[plane] = clust->StartAngle();
820 slope[plane] = std::tan(clust->StartAngle());
std::vector< double > fTime_last
process_name opflash particleana ie ie ie z
fhicl::ParameterSet fCaloPSet
std::vector< double > fWire_vertexError
ShowerReco(fhicl::ParameterSet const &pset)
std::vector< double > fTotChargeADC
std::vector< double > fCorr_Charge_2cm
void set_direction_err(const TVector3 &dir_e)
Utilities related to art service access.
constexpr to_element_t to_element
std::vector< int > fNhitsperplane
std::vector< std::vector< double > > fNPitch
Declaration of signal hit object.
The data type to uniquely identify a Plane.
std::vector< std::vector< double > > fDistribChargeMeV
std::vector< int > fNpoints_corr_MeV_2cm
std::vector< std::vector< double > > fSingleEvtAngle
std::vector< double > fTime_vertex
std::vector< double > fTotADCperplane
std::vector< unsigned int > fWire_last
SigType_t SignalType(geo::PlaneID const &pid) const
Returns the type of signal on the channels of specified TPC plane.
std::vector< std::vector< double > > fDistribHalfChargeMeV
std::vector< double > fChargeMeV_2cm_refined
std::vector< float > vdEdx
void GetVertexAndAnglesFromCluster(art::Ptr< recob::Cluster > clust, unsigned int plane)
std::vector< float > vdQdx
std::vector< int > fNpoints_2cm
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
std::vector< double > fTime_vertexError
std::vector< std::vector< double > > fSingleEvtAngleVal
void set_direction(const TVector3 &dir)
process_name opflash particleana ie ie y
double dEdx_AMP(detinfo::DetectorClocksData const &clock_data, detinfo::DetectorPropertiesData const &det_prop, recob::Hit const &hit, double pitch, double T0=0) const
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
std::vector< float > vresRange
std::vector< double > fRMS_2cm
void produce(art::Event &evt)
Description of geometry of one entire detector.
Declaration of cluster object.
float dEdx(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, const TCSlice &slc, TP3D &tp3d)
std::vector< double > fCorr_MeV_2cm
std::string fClusterModuleLabel
bool CreateAssn(art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t index=UINT_MAX)
Creates a single one-to-one association.
std::vector< double > xyz_vertex_fit
void beginRun(art::Run &run)
Encapsulate the construction of a single detector plane.
Contains all timing reference information for the detector.
std::vector< double > fChargeMeV_2cm
Var Sqrt(const Var &v)
Use to take sqrt of a var.
std::vector< double > fTotChargeMeV_MIPs
std::vector< double > fChargeADC_2cm
double dEdx_AREA(detinfo::DetectorClocksData const &clock_data, detinfo::DetectorPropertiesData const &det_prop, recob::Hit const &hit, double pitch, double T0=0) const
std::vector< float > deadwire
int trigger_offset(DetectorClocksData const &data)
std::vector< std::vector< double > > fDistribChargeADC
void LongTransEnergy(geo::GeometryCore const *geom, detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, unsigned int set, std::vector< art::Ptr< recob::Hit >> hitlist)
constexpr double kBogusD
obviously bogus double value
art::ServiceHandle< art::TFileService > tfs
std::vector< double > fChargeMeV_2cm_axsum
void ClearandResizeVectors(unsigned int nPlanes)
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock.
std::vector< int > fNpoints_corr_ADC_2cm
std::vector< std::vector< double > > fDistribChargeposition
std::vector< unsigned int > fWire_vertex
art framework interface to geometry description
constexpr Point origin()
Returns a origin position with a point of the specified type.
std::vector< double > fTotChargeMeV
Signal from collection planes.