46 #include "TPrincipal.h" 90 produces<std::vector<recob::Shower> >();
91 produces<std::vector<recob::SpacePoint> >();
92 produces<art::Assns<recob::Shower, recob::Hit> >();
93 produces<art::Assns<recob::Shower, recob::Cluster> >();
94 produces<art::Assns<recob::Shower, recob::Track> >();
95 produces<art::Assns<recob::Shower, recob::SpacePoint> >();
96 produces<art::Assns<recob::SpacePoint, recob::Hit> >();
121 std::unique_ptr<std::vector<recob::Shower> > showers(
new std::vector<recob::Shower>);
122 std::unique_ptr<std::vector<recob::SpacePoint> > spacePoints(
new std::vector<recob::SpacePoint>);
133 std::vector<art::Ptr<recob::Hit> >
hits;
139 std::vector<art::Ptr<recob::Track> > tracks;
145 std::vector<art::Ptr<recob::Cluster> > clusters;
151 std::vector<art::Ptr<recob::PFParticle> > pfps;
157 std::vector<art::Ptr<recob::Vertex> > vertices;
168 std::vector<std::vector<int> > newShowers;
169 std::vector<unsigned int> pfParticles;
171 std::map<int,std::vector<int> > clusterToTracks;
172 std::map<int,std::vector<int> > trackToClusters;
183 std::vector<int> clustersToIgnore;
186 if (clustersToIgnore.size() > 0) {
187 clusterToTracks.clear();
188 trackToClusters.clear();
193 newShowers = initialShowers;
201 for (
size_t ipfp = 0; ipfp<pfps.size(); ++ipfp){
208 int trkLikeIdx = hitResults->getIndex(
"track");
209 int emLikeIdx = hitResults->getIndex(
"em");
210 if ((trkLikeIdx < 0) || (emLikeIdx < 0)){
211 throw cet::exception(
"EMShower") <<
"No em/track labeled columns in MVA data products.";
214 std::vector<art::Ptr<recob::Hit>> pfphits;
215 std::vector<art::Ptr<recob::Cluster> > clus = fmcp.at(ipfp);
216 for (
size_t iclu = 0; iclu<clus.size(); ++iclu){
217 std::vector<art::Ptr<recob::Hit> > ClusterHits = fmh.at(clus[iclu].key());
218 pfphits.insert(pfphits.end(), ClusterHits.begin(), ClusterHits.end());
221 auto vout = hitResults->getOutput(pfphits);
222 double trk_like = -1, trk_or_em = vout[trkLikeIdx] + vout[emLikeIdx];
224 trk_like = vout[trkLikeIdx] / trk_or_em;
226 std::vector<int> clusters;
227 for (
size_t iclu = 0; iclu<clus.size(); ++iclu){
228 clusters.push_back(clus[iclu].key());
230 if (clusters.size()){
231 newShowers.push_back(clusters);
232 pfParticles.push_back(ipfp);
244 std::vector<int> clusters;
245 std::vector<art::Ptr<recob::Cluster> > clus = fmcp.at(ipfp);
246 for (
size_t iclu = 0; iclu<clus.size(); ++iclu){
247 clusters.push_back(clus[iclu].key());
249 if (clusters.size()){
250 newShowers.push_back(clusters);
251 pfParticles.push_back(ipfp);
260 for (
std::vector<std::vector<int> >::
iterator newShower = newShowers.begin(); newShower != newShowers.end(); ++newShower, ++showerNum) {
266 std::cout << std::endl << std::endl <<
"Start shower " << showerNum << std::endl;
274 std::vector<int> associatedTracks;
284 std::vector<art::Ptr<recob::Hit> > showerClusterHits = fmh.at(cluster.
key());
290 int trkLikeIdx = hitResults->getIndex(
"track");
291 int emLikeIdx = hitResults->getIndex(
"em");
292 if ((trkLikeIdx < 0) || (emLikeIdx < 0)){
293 throw cet::exception(
"EMShower") <<
"No em/track labeled columns in MVA data products.";
295 for (
auto & showerHit : showerClusterHits){
296 auto vout = hitResults->getOutput(showerHit);
297 double trk_like = -1, trk_or_em = vout[trkLikeIdx] + vout[emLikeIdx];
299 trk_like = vout[trkLikeIdx] / trk_or_em;
312 std::vector<int> clusterTracks = clusterToTracks.at(*showerCluster);
313 for (
std::vector<int>::iterator clusterTracksIt = clusterTracks.begin(); clusterTracksIt != clusterTracks.end(); ++clusterTracksIt)
314 if (std::find(associatedTracks.begin(), associatedTracks.end(), *clusterTracksIt) == associatedTracks.end())
315 associatedTracks.push_back(*clusterTracksIt);
321 for (
std::vector<int>::iterator associatedTracksIt = associatedTracks.begin(); associatedTracksIt != associatedTracks.end(); ++associatedTracksIt) {
329 for (
size_t ihit = 0; ihit<showerHits.
size(); ++ihit){
330 if (fmspp.isValid()){
331 std::vector<art::Ptr<recob::SpacePoint> > spacePoints_pfp = fmspp.at(ihit);
333 showerSpacePoints_p.
push_back(*spacePointsIt);
342 std::cout <<
" ------------------ Ordering shower hits -------------------- " << std::endl;
345 std::cout <<
" ------------------ End ordering shower hits -------------------- " << std::endl;
348 std::unique_ptr<recob::Track> initialTrack;
349 std::map<int,std::vector<art::Ptr<recob::Hit> > > initialTrackHits;
353 std::vector<std::vector<art::Ptr<recob::Hit> > > hitAssns;
354 std::vector<recob::SpacePoint> showerSpacePoints;
359 const std::vector<art::Ptr<recob::SpacePoint> > trackSpacePoints = fmsp.at(trackIt->key());
361 showerSpacePoints.push_back(*(*trackSpIt));
368 int firstSpacePoint = spacePoints->size(), nSpacePoint = 0;
370 spacePoints->emplace_back(sspIt->XYZ(), sspIt->ErrXYZ(), sspIt->Chisq(), spacePoints->size());
371 util::CreateAssn(*
this, evt, *(spacePoints.get()), hitAssns.at(nSpacePoint), *(hitSpAssociations.get()));
373 int lastSpacePoint = spacePoints->size();
379 showers->push_back(shower);
380 util::CreateAssn(*
this, evt, *(showers.get()), showerHits, *(hitShowerAssociations.get()));
381 util::CreateAssn(*
this, evt, *(showers.get()), showerClusters, *(clusterAssociations.get()));
382 util::CreateAssn(*
this, evt, *(showers.get()), showerTracks, *(trackAssociations.get()));
383 util::CreateAssn(*
this, evt, *(showers.get()), *(spacePoints.get()), *(spShowerAssociations.get()), firstSpacePoint, lastSpacePoint);
386 mf::LogInfo(
"EMShower") <<
"Discarding shower " << showerNum <<
" due to incompleteness (SaveNonCompleteShowers == false)";
391 if (vertices.size()) {
393 TVector3 nuvtx(0,0,DBL_MAX);
394 for (
auto & vtx: vertices){
397 if (xyz[2]<nuvtx.Z()){
398 nuvtx.SetXYZ(xyz[0], xyz[1], xyz[2]);
402 TVector3 shwvtx(0,0,0);
403 double mindis = DBL_MAX;
404 for (
auto &sp : showerSpacePoints_p){
405 double dis = sqrt(pow(nuvtx.X()-sp->XYZ()[0],2)+pow(nuvtx.X()-sp->XYZ()[1],2)+pow(nuvtx.X()-sp->XYZ()[2],2));
408 shwvtx.SetXYZ(sp->XYZ()[0], sp->XYZ()[1], sp->XYZ()[2]);
414 for (
auto & vtx: vertices){
417 double dis = sqrt(pow(xyz[0]-shwvtx.X(),2)+pow(xyz[1]-shwvtx.Y(),2)+pow(xyz[2]-shwvtx.Z(),2));
429 showers->push_back(shower);
430 showers->back().set_id(showers->size()-1);
431 util::CreateAssn(*
this, evt, *(showers.get()), showerHits, *(hitShowerAssociations.get()));
432 util::CreateAssn(*
this, evt, *(showers.get()), showerClusters, *(clusterAssociations.get()));
433 util::CreateAssn(*
this, evt, *(showers.get()), showerTracks, *(trackAssociations.get()));
434 util::CreateAssn(*
this, evt, *(showers.get()), showerSpacePoints_p, *(spShowerAssociations.get()));
443 evt.
put(std::move(showers));
444 evt.
put(std::move(spacePoints));
445 evt.
put(std::move(hitShowerAssociations));
446 evt.
put(std::move(clusterAssociations));
447 evt.
put(std::move(trackAssociations));
448 evt.
put(std::move(spShowerAssociations));
449 evt.
put(std::move(hitSpAssociations));
void XYZ(double *xyz) const
Legacy method to access vertex position, preserved to avoid breaking code. Please try to use Vertex::...
const TVector3 & ShowerStart() const
Encapsulate the construction of a single cyostat.
art::InputTag fClusterModuleLabel
std::vector< recob::SpacePoint > MakeSpacePoints(std::map< int, std::vector< art::Ptr< recob::Hit > > > hits, std::vector< std::vector< art::Ptr< recob::Hit > > > &hitAssns)
Makes space points from the shower hits in each plane.
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
Declaration of signal hit object.
bool fSaveNonCompleteShowers
EMShower(fhicl::ParameterSet const &pset)
art::InputTag fVertexModuleLabel
std::map< int, std::vector< art::Ptr< recob::Hit > > > OrderShowerHits(const art::PtrVector< recob::Hit > &shower, int plane)
Takes the hits associated with a shower and orders them so they follow the direction of the shower...
int PdgCode() const
Return the type of particle as a PDG ID.
Cluster finding and building.
art::InputTag fTrackModuleLabel
ProductID put(std::unique_ptr< PROD > &&product)
void set_id(const int id)
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
std::vector< std::vector< int > > FindShowers(std::map< int, std::vector< int > > const &trackToClusters)
Makes showers given a map between tracks and all clusters associated with them.
#define DEFINE_ART_MODULE(klass)
Provides recob::Track data product.
void push_back(Ptr< U > const &p)
T get(std::string const &key) const
void AssociateClustersAndTracks(std::vector< art::Ptr< recob::Cluster > > const &clusters, art::FindManyP< recob::Hit > const &fmh, art::FindManyP< recob::Track > const &fmt, std::map< int, std::vector< int > > &clusterToTracks, std::map< int, std::vector< int > > &trackToClusters)
Map associated tracks and clusters together given their associated hits.
art::ServiceHandle< geo::Geometry > fGeom
art::InputTag fHitsModuleLabel
art::InputTag fCNNEMModuleLabel
bool CreateAssn(PRODUCER const &prod, art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t indx=UINT_MAX)
Creates a single one-to-one association.
Declaration of cluster object.
art::InputTag fPFParticleModuleLabel
void produce(art::Event &evt)
void FindInitialTrack(const std::map< int, std::vector< art::Ptr< recob::Hit > > > &hits, std::unique_ptr< recob::Track > &initialTrack, std::map< int, std::vector< art::Ptr< recob::Hit > > > &initialTrackHits, int plane)
Finds the initial track-like part of the shower and the hits in all views associated with it...
data_t::const_iterator const_iterator
void reconfigure(fhicl::ParameterSet const &p)
double fMinTrackLikeScore
Utility object to perform functions of association.
Encapsulate the construction of a single detector plane.
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
recob::Shower MakeShower(art::PtrVector< recob::Hit > const &hits, std::unique_ptr< recob::Track > const &initialTrack, std::map< int, std::vector< art::Ptr< recob::Hit > > > const &initialTrackHits)
Makes a recob::Shower object given the hits in the shower and the initial track-like part...
std::vector< int > CheckShowerPlanes(std::vector< std::vector< int > > const &initialShowers, std::vector< art::Ptr< recob::Cluster > > const &clusters, art::FindManyP< recob::Hit > const &fmh)
Takes the initial showers found and tries to resolve issues where one bad view ruins the event...
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
detinfo::DetectorProperties const * fDetProp
static std::unique_ptr< MVAReader > create(const art::Event &evt, const art::InputTag &tag)
art framework interface to geometry description
cet::coded_exception< error, detail::translate > exception
Encapsulate the construction of a single detector plane.