LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
ems::MergeEMShower3D Class Reference
Inheritance diagram for ems::MergeEMShower3D:
art::EDProducer art::ProducerBase art::Consumer art::EngineCreator art::ProductRegistryHelper

Public Types

using ModuleType = EDProducer
 
using WorkerType = WorkerT< EDProducer >
 
template<typename UserConfig , typename KeysToIgnore = void>
using Table = ProducerBase::Table< UserConfig, KeysToIgnore >
 

Public Member Functions

 MergeEMShower3D (fhicl::ParameterSet const &p)
 
 MergeEMShower3D (MergeEMShower3D const &)=delete
 
 MergeEMShower3D (MergeEMShower3D &&)=delete
 
MergeEMShower3Doperator= (MergeEMShower3D const &)=delete
 
MergeEMShower3Doperator= (MergeEMShower3D &&)=delete
 
void beginJob () override
 
void produce (art::Event &e) override
 
void reconfigure (fhicl::ParameterSet const &p)
 
void mcinfo (art::Event &evt)
 
int getClusterBestId (const std::vector< art::Ptr< recob::Hit > > &v)
 
int getGammaId (art::Event &evt, const size_t t)
 
double getCos3D (const TVector3 &p0, const recob::Track &trk)
 
double getClusterAdcSum (const std::vector< art::Ptr< recob::Hit > > &v)
 
std::vector< ems::ShowersCollectioncollectshowers (art::Event &evt, std::vector< ems::ShowerInfo > &showers, bool refpoint)
 
TVector3 getBestPoint (const std::vector< recob::Track > &tracks, const std::vector< ShowerInfo > &showers, const TVector3 &p0, const TVector3 &p1, double step)
 
template<typename PROD , BranchType B = InEvent>
ProductID getProductID (std::string const &instanceName={}) const
 
template<typename PROD , BranchType B>
ProductID getProductID (ModuleDescription const &moduleDescription, std::string const &instanceName) const
 
bool modifiesEvent () const
 
template<typename T , BranchType = InEvent>
ProductToken< T > consumes (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ProductToken< T > consumes (InputTag const &it)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ViewToken< T > consumesView (InputTag const &it)
 
template<typename T , BranchType = InEvent>
ProductToken< T > mayConsume (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ProductToken< T > mayConsume (InputTag const &it)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ViewToken< T > mayConsumeView (InputTag const &it)
 
base_engine_tcreateEngine (seed_t seed)
 
base_engine_tcreateEngine (seed_t seed, std::string const &kind_of_engine_to_make)
 
base_engine_tcreateEngine (seed_t seed, std::string const &kind_of_engine_to_make, label_t const &engine_label)
 
seed_t get_seed_value (fhicl::ParameterSet const &pset, char const key[]="seed", seed_t const implicit_seed=-1)
 

Static Public Member Functions

static cet::exempt_ptr< Consumernon_module_context ()
 

Protected Member Functions

CurrentProcessingContext const * currentContext () const
 
void validateConsumedProduct (BranchType const bt, ProductInfo const &pi)
 
void prepareForJob (fhicl::ParameterSet const &pset)
 
void showMissingConsumes () const
 

Private Attributes

TTree * fEvTree
 
int fVtxIndex
 
int fNParts [2]
 
int fNPMA
 
int fNConv
 
int fNTot
 
int fWhat
 
int fEvWhat
 
int fNMerged
 
int fNCleanMerged
 
double fDistvtxmcreco
 
double fMcMom
 
int fEvNumber
 
TVector3 fPi0vtx
 
TVector3 fRefPoint
 
std::string fHitsModuleLabel
 
std::string fCluModuleLabel
 
std::string fTrk3DModuleLabel
 
std::string fVtxModuleLabel
 
double fNarrowConeAngle
 
double fWideConeAngle
 
shower::ShowerEnergyAlg fShowerEnergyAlg
 

Detailed Description

Definition at line 337 of file MergeEMShower3D_module.cc.

Member Typedef Documentation

using art::EDProducer::ModuleType = EDProducer
inherited

Definition at line 34 of file EDProducer.h.

template<typename UserConfig , typename KeysToIgnore = void>
using art::EDProducer::Table = ProducerBase::Table<UserConfig, KeysToIgnore>
inherited

Definition at line 43 of file EDProducer.h.

using art::EDProducer::WorkerType = WorkerT<EDProducer>
inherited

Definition at line 35 of file EDProducer.h.

Constructor & Destructor Documentation

ems::MergeEMShower3D::MergeEMShower3D ( fhicl::ParameterSet const &  p)
explicit

Definition at line 402 of file MergeEMShower3D_module.cc.

References reconfigure().

403  : fShowerEnergyAlg(p.get<fhicl::ParameterSet>("ShowerEnergyAlg"))
404 {
405  reconfigure(p);
406 
407  produces< std::vector<recob::Shower> >();
408  produces< std::vector<recob::Vertex> >();
409 
410  produces< art::Assns<recob::Shower, recob::Vertex> >();
411  produces< art::Assns<recob::Shower, recob::Cluster> >();
412  produces< art::Assns<recob::Shower, recob::Hit> >();
413 }
void reconfigure(fhicl::ParameterSet const &p)
shower::ShowerEnergyAlg fShowerEnergyAlg
ems::MergeEMShower3D::MergeEMShower3D ( MergeEMShower3D const &  )
delete
ems::MergeEMShower3D::MergeEMShower3D ( MergeEMShower3D &&  )
delete

Member Function Documentation

void ems::MergeEMShower3D::beginJob ( )
overridevirtual

Reimplemented from art::EDProducer.

Definition at line 415 of file MergeEMShower3D_module.cc.

References fDistvtxmcreco, fEvNumber, fEvTree, fEvWhat, fMcMom, fNCleanMerged, fNConv, fNMerged, fNParts, fNPMA, fNTot, and art::TFileDirectory::make().

416 {
418 
419  fEvTree = tfs->make<TTree>("ShowerTestEv", "pi0 tests");
420  fEvTree->Branch("fEvNumber", &fEvNumber, "fEvNumber/I");
421  fEvTree->Branch("fNPartsA", &fNParts[0], "fNPartsA/I");
422  fEvTree->Branch("fNPartsB", &fNParts[1], "fNPartsB/I");
423  fEvTree->Branch("fNTot", &fNTot, "fNTot/I");
424  fEvTree->Branch("fNPMA", &fNPMA, "fNPMA/I");
425  fEvTree->Branch("fNConv", &fNConv, "fNConv/I");
426  fEvTree->Branch("fEvWhat", &fEvWhat, "fEvWhat/I");
427  fEvTree->Branch("fMcMom", &fMcMom, "fMcMom/D");
428 
429  fEvTree->Branch("fDistvtxmcreco", &fDistvtxmcreco, "fDistvtxmcreco/D");
430  fEvTree->Branch("fNMerged", &fNMerged, "fNMerged/I");
431  fEvTree->Branch("fNCleanMerged", &fNCleanMerged, "fNCleanMerged/I");
432 }
T * make(ARGS...args) const
std::vector< ems::ShowersCollection > ems::MergeEMShower3D::collectshowers ( art::Event evt,
std::vector< ems::ShowerInfo > &  showers,
bool  refpoint 
)

Definition at line 629 of file MergeEMShower3D_module.cc.

References geo::GeometryCore::CryostatBoundaries(), pma::Dist2(), fNarrowConeAngle, fNConv, fRefPoint, fTrk3DModuleLabel, getBestPoint(), art::DataViewImpl::getByLabel(), pma::GetProjectionToSegment(), and pma::SolveLeastSquares3D().

Referenced by produce().

630 {
631  std::vector< ems::ShowersCollection > gammawithconv;
632 
633  const double smallcone = fNarrowConeAngle; // degree.
634  bool merge = true;
635  if (refpoint)
636  {
639  if (evt.getByLabel(fTrk3DModuleLabel, trkListHandle))
640  {
641  double dsize[6];
642  geom->CryostatBoundaries(dsize, 0);
643  TVector3 geoP0(dsize[0], dsize[2], dsize[4]), geoP1(dsize[1], dsize[3], dsize[5]);
644  TVector3 pov = getBestPoint(*trkListHandle, showers, geoP0, geoP1, 5.0);
645  fRefPoint = pov;
646 
647  for (size_t is = 0; is < showers.size(); is++)
648  showers[is].SetP0Dist(pov);
649  std::sort(showers.begin(), showers.end(), ems::bDistLess());
650 
651  for (size_t is = 0; is < showers.size(); is++)
652  {
653  size_t m_idx = 0;
654  double a, a_min = 360.0;
655  for (size_t m = 0; m < gammawithconv.size(); ++m)
656  {
657  a = gammawithconv[m].Angle(showers[is].GetFront());
658  if ((a < fNarrowConeAngle) && (a < a_min))
659  {
660  m_idx = m; a_min = a;
661  }
662 
663  std::vector< std::pair<TVector3, TVector3> > lines;
664  lines.push_back(std::pair<TVector3, TVector3>(
665  showers[is].GetFront(), showers[is].GetFront() + showers[is].GetDir()));
666  lines.push_back(std::pair<TVector3, TVector3>(
667  gammawithconv[m].Front(), gammawithconv[m].Front() + gammawithconv[m].Dir()));
668 
669  TVector3 isect, pm;
670  pma::SolveLeastSquares3D(lines, isect);
671  pm = pma::GetProjectionToSegment(isect,
672  gammawithconv[m].Front(), gammawithconv[m].Front() + gammawithconv[m].Dir());
673 
674  if (pma::Dist2(pov, gammawithconv[m].Front()) < pma::Dist2(pov, pm))
675  {
676  a = gammawithconv[m].Angle(isect);
677  if ((a < fNarrowConeAngle) && (a < a_min))
678  {
679  m_idx = m; a_min = a;
680  }
681  }
682  }
683  if (a_min < fNarrowConeAngle)
684  {
685  gammawithconv[m_idx].Merge(showers[is]);
686  }
687  else if (showers[is].HasConPoint())
688  {
689  ems::ShowersCollection sc(showers[is]);
690  gammawithconv.push_back(sc);
691  }
692 
693  }
694  }
695  }
696  else
697  {
698  for (size_t i = 0; i < showers.size(); ++i)
699  if (showers[i].HasConPoint())
700  {
701  ems::ShowersCollection sc(showers[i]);
702  gammawithconv.push_back(sc);
703  }
704 
705  fNConv = gammawithconv.size();
706  while (merge)
707  {
708  merge = false;
709  size_t i = 0;
710  while (i < gammawithconv.size())
711  {
712  size_t best = 0; double a_min = smallcone;
713  for (size_t j = 0; j < gammawithconv.size(); j++)
714  if (i != j)
715  {
716  double a = gammawithconv[i].MinAngle(gammawithconv[j]);
717  if (a < a_min)
718  {
719  a_min = a; best = j; merge = true;
720  }
721  }
722  if (merge)
723  {
724  gammawithconv[i].Merge(gammawithconv[best]);
725  gammawithconv.erase(gammawithconv.begin() + best);
726  break;
727  }
728  i++;
729  }
730  }
731  }
732  return gammawithconv;
733 }
double Dist2(const TVector2 &v1, const TVector2 &v2)
Definition: Utilities.cxx:19
void CryostatBoundaries(double *boundaries, geo::CryostatID const &cid) const
Returns the boundaries of the specified cryostat.
TVector2 GetProjectionToSegment(const TVector2 &p, const TVector2 &p0, const TVector2 &p1)
Definition: Utilities.cxx:156
double SolveLeastSquares3D(const std::vector< std::pair< TVector3, TVector3 > > &lines, TVector3 &result)
Definition: Utilities.cxx:176
TVector3 getBestPoint(const std::vector< recob::Track > &tracks, const std::vector< ShowerInfo > &showers, const TVector3 &p0, const TVector3 &p1, double step)
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
template<typename T , BranchType = InEvent>
ProductToken<T> art::Consumer::consumes ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ProductToken<T> art::Consumer::consumes ( InputTag const &  it)
inherited

Definition at line 147 of file Consumer.h.

References art::InputTag::instance(), art::InputTag::label(), and art::InputTag::process().

148 {
149  if (!moduleContext_)
150  return ProductToken<T>::invalid();
151 
152  consumables_[BT].emplace_back(ConsumableType::Product,
153  TypeID{typeid(T)},
154  it.label(),
155  it.instance(),
156  it.process());
157  return ProductToken<T>{it};
158 }
static ProductToken< T > invalid()
Definition: ProductToken.h:47
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
template<typename T , art::BranchType BT>
void art::Consumer::consumesMany ( )
inherited

Definition at line 162 of file Consumer.h.

163 {
164  if (!moduleContext_)
165  return;
166 
167  consumables_[BT].emplace_back(ConsumableType::Many, TypeID{typeid(T)});
168 }
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
template<typename Element , BranchType = InEvent>
ViewToken<Element> art::Consumer::consumesView ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ViewToken<T> art::Consumer::consumesView ( InputTag const &  it)
inherited

Definition at line 172 of file Consumer.h.

References art::InputTag::instance(), art::InputTag::label(), and art::InputTag::process().

173 {
174  if (!moduleContext_)
175  return ViewToken<T>::invalid();
176 
177  consumables_[BT].emplace_back(ConsumableType::ViewElement,
178  TypeID{typeid(T)},
179  it.label(),
180  it.instance(),
181  it.process());
182  return ViewToken<T>{it};
183 }
static ViewToken< Element > invalid()
Definition: ProductToken.h:75
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
EngineCreator::base_engine_t & EngineCreator::createEngine ( seed_t  seed,
std::string const &  kind_of_engine_to_make 
)
inherited

Definition at line 32 of file EngineCreator.cc.

References art::EngineCreator::rng().

34 {
35  return rng()->createEngine(
36  placeholder_schedule_id(), seed, kind_of_engine_to_make);
37 }
long seed
Definition: chem4.cc:68
static art::ServiceHandle< art::RandomNumberGenerator > & rng()
EngineCreator::base_engine_t & EngineCreator::createEngine ( seed_t  seed,
std::string const &  kind_of_engine_to_make,
label_t const &  engine_label 
)
inherited

Definition at line 40 of file EngineCreator.cc.

References art::EngineCreator::rng().

43 {
44  return rng()->createEngine(
45  placeholder_schedule_id(), seed, kind_of_engine_to_make, engine_label);
46 }
long seed
Definition: chem4.cc:68
static art::ServiceHandle< art::RandomNumberGenerator > & rng()
CurrentProcessingContext const * art::EDProducer::currentContext ( ) const
protectedinherited

Definition at line 120 of file EDProducer.cc.

References art::EDProducer::current_context_.

121  {
122  return current_context_.get();
123  }
CPC_exempt_ptr current_context_
Definition: EDProducer.h:116
EngineCreator::seed_t EngineCreator::get_seed_value ( fhicl::ParameterSet const &  pset,
char const  key[] = "seed",
seed_t const  implicit_seed = -1 
)
inherited

Definition at line 49 of file EngineCreator.cc.

References fhicl::ParameterSet::get().

Referenced by art::MixFilter< T >::initEngine_().

52 {
53  auto const& explicit_seeds = pset.get<std::vector<int>>(key, {});
54  return explicit_seeds.empty() ? implicit_seed : explicit_seeds.front();
55 }
TVector3 ems::MergeEMShower3D::getBestPoint ( const std::vector< recob::Track > &  tracks,
const std::vector< ShowerInfo > &  showers,
const TVector3 &  p0,
const TVector3 &  p1,
double  step 
)

Definition at line 819 of file MergeEMShower3D_module.cc.

References pma::Dist2(), f, and getCos3D().

Referenced by collectshowers().

823 {
824  TVector3 best, p;
825 
826  double f, fmin = 1.0e10;
827 
828  double dx = step;
829  double dy = step;
830  double dz = step;
831 
832  double x0 = p0.X();
833  while (x0 < p1.X())
834  {
835  double y0 = p0.Y();
836  while (y0 < p1.Y())
837  {
838  double z0 = p0.Z();
839  while (z0 < p1.Z())
840  {
841  f = 0.0;
842  //size_t nOK = 0;
843  TVector3 mid(0., 0., 0.);
844 
845  p.SetXYZ(x0, y0, z0);
846  for (size_t t = 0; t < tracks.size(); t++)
847  // if (showers[t].OK)
848  {
849  auto const & trk = tracks[t];
850 
851  double cos = -acos( getCos3D(p, trk) ) / (0.5*TMath::Pi());
852  //double cos = getCos3D(p, trk);
853 
854  if (showers[t].HasConPoint()) cos *= 3.0;
855  cos *= sqrt( showers[t].GetAdcSum() );
856 
857  mid += 0.5 * (trk.Vertex<TVector3>() + trk.End<TVector3>());
858 
859  f += cos;
860  // nOK++;
861  }
862  //if (!nOK) return best;
863 
864  // f /= nOK;
865  // mid *= 1.0 / nOK;
866 
867  f = -f + 0.0001 * sqrt(pma::Dist2(p, mid));
868  if (f < fmin)
869  {
870  fmin = f; best = p;
871  }
872 
873  z0 += dz;
874  }
875  y0 += dy;
876  }
877  x0 += dx;
878  }
879  return best;
880 }
double Dist2(const TVector2 &v1, const TVector2 &v2)
Definition: Utilities.cxx:19
double getCos3D(const TVector3 &p0, const recob::Track &trk)
TFile f
Definition: plotHisto.C:6
double ems::MergeEMShower3D::getClusterAdcSum ( const std::vector< art::Ptr< recob::Hit > > &  v)

Definition at line 903 of file MergeEMShower3D_module.cc.

References DEFINE_ART_MODULE.

Referenced by produce().

904 {
905  double sum = 0.0;
906  for (auto ptr : v)
907  {
908  sum += ptr->SummedADC();
909  }
910  return sum;
911 }
int ems::MergeEMShower3D::getClusterBestId ( const std::vector< art::Ptr< recob::Hit > > &  v)

Definition at line 736 of file MergeEMShower3D_module.cc.

References cheat::BackTrackerService::HitToTrackIDEs(), and max.

Referenced by getGammaId().

737 {
739 
740  std::map< int, size_t > ids;
741  for (auto ptr : v)
742  {
743  auto hid = bt_serv->HitToTrackIDEs(ptr);
744  if (hid.size()) ids[hid.front().trackID]++;
745  }
746 
747  int best_id = 9999;
748  size_t max = 0;
749  for (auto p : ids)
750  {
751  if ((p.second > (int)(0.8 * v.size())) && (p.second > max))
752  {
753  max = p.second; best_id = p.first;
754  }
755  }
756 
757  return best_id;
758 }
const std::vector< sim::TrackIDE > HitToTrackIDEs(recob::Hit const &hit)
Int_t max
Definition: plot.C:27
double ems::MergeEMShower3D::getCos3D ( const TVector3 &  p0,
const recob::Track trk 
)

Definition at line 882 of file MergeEMShower3D_module.cc.

References dir, pma::Dist2(), recob::Track::End(), recob::Track::Vertex(), and recob::Track::VertexDirection().

Referenced by getBestPoint().

883 {
884  TVector3 p1, dir;
885 
886  if (pma::Dist2(p0, trk.Vertex()) < pma::Dist2(p0, trk.End()))
887  p1 = trk.Vertex<TVector3>();
888  else
889  p1 = trk.End<TVector3>();
890 
891  p1 -= p0;
892  double m = p1.Mag();
893  if (m > 0.0)
894  {
895  p1 *= 1.0 / m;
896  double c = fabs(p1 * trk.VertexDirection<TVector3>());
897  if (c > 1.0) c = 1.0;
898  return c;
899  }
900  else return 0.0;
901 }
double Dist2(const TVector2 &v1, const TVector2 &v2)
Definition: Utilities.cxx:19
Vector_t VertexDirection() const
Access to track direction at different points.
Definition: Track.h:135
Point_t const & Vertex() const
Access to track position at different points.
Definition: Track.h:127
TDirectory * dir
Definition: macro.C:5
Point_t const & End() const
Access to track position at different points.
Definition: Track.h:128
int ems::MergeEMShower3D::getGammaId ( art::Event evt,
const size_t  t 
)

Definition at line 786 of file MergeEMShower3D_module.cc.

References fCluModuleLabel, fHitsModuleLabel, fTrk3DModuleLabel, fVtxModuleLabel, fWhat, art::DataViewImpl::getByLabel(), and getClusterBestId().

Referenced by produce().

787 {
788  fWhat = 0;
789  int cid = 0, gid = 0;
793  art::Handle< std::vector<recob::Hit> > hitListHandle;
794  if (evt.getByLabel(fTrk3DModuleLabel, trkListHandle) &&
795  evt.getByLabel(fVtxModuleLabel, vtxListHandle) &&
796  evt.getByLabel(fCluModuleLabel, cluListHandle) &&
797  evt.getByLabel(fHitsModuleLabel, hitListHandle))
798  {
799  art::FindManyP< recob::Cluster > cluFromTrk(trkListHandle, evt, fTrk3DModuleLabel);
800  art::FindManyP< recob::Vertex > vtxFromTrk(trkListHandle, evt, fVtxModuleLabel);
801  art::FindManyP< recob::Hit > hitFromClu(cluListHandle, evt, fCluModuleLabel);
802 
803  auto src_clu_list = cluFromTrk.at(t);
804  for (size_t c = 0; c < src_clu_list.size(); ++c)
805  {
806  std::vector< art::Ptr<recob::Hit> > v = hitFromClu.at(src_clu_list[c].key());
807  cid = getClusterBestId(v);
808 
809  if ((fWhat == 0) && (cid == 9999)) fWhat = 1; // confused 2D
810  if ((fWhat == 0) && (gid == 0)) gid = cid;
811  if ((fWhat == 0) && (cid != gid)) fWhat = 2; // confused 3D
812  }
813  }
814 
815  if (fWhat == 0) return gid;
816  else return 9999;
817 }
int getClusterBestId(const std::vector< art::Ptr< recob::Hit > > &v)
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
template<typename PROD , BranchType B>
ProductID art::EDProducer::getProductID ( std::string const &  instanceName = {}) const
inlineinherited

Definition at line 123 of file EDProducer.h.

References art::EDProducer::moduleDescription_.

124  {
125  return ProducerBase::getProductID<PROD, B>(moduleDescription_,
126  instanceName);
127  }
ModuleDescription moduleDescription_
Definition: EDProducer.h:115
template<typename PROD , BranchType B>
ProductID art::ProducerBase::getProductID ( ModuleDescription const &  moduleDescription,
std::string const &  instanceName 
) const
inherited

Definition at line 56 of file ProducerBase.h.

References B, and art::ModuleDescription::moduleLabel().

Referenced by art::ProducerBase::modifiesEvent().

58  {
59  auto const& pd =
60  get_ProductDescription<PROD>(B, md.moduleLabel(), instanceName);
61  return pd.productID();
62  }
Int_t B
Definition: plot.C:25
template<typename T , BranchType = InEvent>
ProductToken<T> art::Consumer::mayConsume ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ProductToken<T> art::Consumer::mayConsume ( InputTag const &  it)
inherited

Definition at line 190 of file Consumer.h.

References art::InputTag::instance(), art::InputTag::label(), and art::InputTag::process().

191 {
192  if (!moduleContext_)
193  return ProductToken<T>::invalid();
194 
195  consumables_[BT].emplace_back(ConsumableType::Product,
196  TypeID{typeid(T)},
197  it.label(),
198  it.instance(),
199  it.process());
200  return ProductToken<T>{it};
201 }
static ProductToken< T > invalid()
Definition: ProductToken.h:47
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
template<typename T , art::BranchType BT>
void art::Consumer::mayConsumeMany ( )
inherited

Definition at line 205 of file Consumer.h.

206 {
207  if (!moduleContext_)
208  return;
209 
210  consumables_[BT].emplace_back(ConsumableType::Many, TypeID{typeid(T)});
211 }
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
template<typename Element , BranchType = InEvent>
ViewToken<Element> art::Consumer::mayConsumeView ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ViewToken<T> art::Consumer::mayConsumeView ( InputTag const &  it)
inherited

Definition at line 215 of file Consumer.h.

References art::InputTag::instance(), art::InputTag::label(), and art::InputTag::process().

216 {
217  if (!moduleContext_)
218  return ViewToken<T>::invalid();
219 
220  consumables_[BT].emplace_back(ConsumableType::ViewElement,
221  TypeID{typeid(T)},
222  it.label(),
223  it.instance(),
224  it.process());
225  return ViewToken<T>{it};
226 }
static ViewToken< Element > invalid()
Definition: ProductToken.h:75
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
void ems::MergeEMShower3D::mcinfo ( art::Event evt)

Definition at line 760 of file MergeEMShower3D_module.cc.

References art::fill_ptr_vector(), fMcMom, fPi0vtx, art::DataViewImpl::getByLabel(), simb::MCParticle::P(), simb::MCParticle::Vx(), simb::MCParticle::Vy(), and simb::MCParticle::Vz().

Referenced by produce().

761 {
762  int pi0_idx = -1;
763 
764  art::Handle< std::vector<simb::MCTruth> > mctruthListHandle;
765  std::vector< art::Ptr<simb::MCTruth> > mclist;
766  if (evt.getByLabel("generator", mctruthListHandle))
767  {
768  art::fill_ptr_vector(mclist, mctruthListHandle);
769  if (mclist.size())
770  {
771  size_t np = mclist[0]->NParticles();
772  for (size_t i = 0; i < np; ++i)
773  if (mclist[0]->GetParticle(i).PdgCode() == 111)
774  {pi0_idx = i; break;}
775  }
776  }
777 
778  if (pi0_idx < 0) return;
779 
780  const simb::MCParticle & pi0 = mclist[0]->GetParticle(pi0_idx);
781  TVector3 pi0_vtx(pi0.Vx(), pi0.Vy(), pi0.Vz());
782  fPi0vtx = pi0_vtx;
783  fMcMom = pi0.P();
784 }
double P(const int i=0) const
Definition: MCParticle.h:238
double Vx(const int i=0) const
Definition: MCParticle.h:225
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
double Vz(const int i=0) const
Definition: MCParticle.h:227
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:464
double Vy(const int i=0) const
Definition: MCParticle.h:226
bool art::ProducerBase::modifiesEvent ( ) const
inlineinherited

Definition at line 40 of file ProducerBase.h.

References art::ProducerBase::getProductID().

41  {
42  return true;
43  }
MergeEMShower3D& ems::MergeEMShower3D::operator= ( MergeEMShower3D const &  )
delete
MergeEMShower3D& ems::MergeEMShower3D::operator= ( MergeEMShower3D &&  )
delete
void art::Consumer::prepareForJob ( fhicl::ParameterSet const &  pset)
protectedinherited

Definition at line 89 of file Consumer.cc.

References fhicl::ParameterSet::get_if_present().

Referenced by art::EDProducer::doBeginJob(), art::EDFilter::doBeginJob(), and art::EDAnalyzer::doBeginJob().

90 {
91  if (!moduleContext_)
92  return;
93 
94  pset.get_if_present("errorOnMissingConsumes", requireConsumes_);
95  for (auto& consumablesPerBranch : consumables_) {
96  cet::sort_all(consumablesPerBranch);
97  }
98 }
bool requireConsumes_
Definition: Consumer.h:137
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
void ems::MergeEMShower3D::produce ( art::Event e)
overridevirtual

Implements art::EDProducer.

Definition at line 447 of file MergeEMShower3D_module.cc.

References collectshowers(), util::CreateAssn(), dir, pma::Dist2(), art::EventID::event(), fCluModuleLabel, fDistvtxmcreco, fEvNumber, fEvTree, fHitsModuleLabel, fMcMom, fNCleanMerged, fNConv, fNMerged, fNParts, fNPMA, fNTot, fPi0vtx, fRefPoint, fShowerEnergyAlg, fTrk3DModuleLabel, fVtxIndex, fVtxModuleLabel, fWhat, fWideConeAngle, art::DataViewImpl::getByLabel(), getClusterAdcSum(), getGammaId(), hits(), art::Event::id(), geo::kU, geo::kV, geo::kZ, mcinfo(), art::Event::put(), recob::Shower::set_total_energy(), recob::Shower::set_total_energy_err(), and shower::ShowerEnergyAlg::ShowerEnergy().

448 {
449  std::unique_ptr< std::vector< recob::Shower > > cascades(new std::vector< recob::Shower >);
450  std::unique_ptr< std::vector< recob::Vertex > > vertices(new std::vector< recob::Vertex >);
451 
452  std::unique_ptr< art::Assns< recob::Shower, recob::Vertex > > shs2vtx(new art::Assns< recob::Shower, recob::Vertex >);
453  std::unique_ptr< art::Assns< recob::Shower, recob::Cluster > > shs2cl(new art::Assns< recob::Shower, recob::Cluster >);
454  std::unique_ptr< art::Assns< recob::Shower, recob::Hit > > shs2hit(new art::Assns< recob::Shower, recob::Hit >);
455 
456  std::vector< ShowersCollection > gammawithconv;
457 
461  art::Handle< std::vector<recob::Hit> > hitListHandle;
462  if (evt.getByLabel(fTrk3DModuleLabel, trkListHandle) &&
463  evt.getByLabel(fVtxModuleLabel, vtxListHandle) &&
464  evt.getByLabel(fCluModuleLabel, cluListHandle) &&
465  evt.getByLabel(fHitsModuleLabel, hitListHandle))
466  {
467 
468  fEvNumber = evt.id().event();
469  fNMerged = 0; fNCleanMerged = 0; fNParts[0] = 0; fNParts[1] = 0;
470  fNPMA = 0; fNConv = 0; fNTot = 0; fMcMom = 0; fWhat = 0;
471  fDistvtxmcreco = -10.0;
472 
473  art::FindManyP< recob::Cluster > cluFromTrk(trkListHandle, evt, fTrk3DModuleLabel);
474  art::FindManyP< recob::Vertex > vtxFromTrk(trkListHandle, evt, fVtxModuleLabel);
475  art::FindManyP< recob::Hit > hitFromClu(cluListHandle, evt, fCluModuleLabel);
476 
477  // all reconstructed shower fragments
478  std::vector< ShowerInfo > showers;
479  for (size_t t = 0; t < trkListHandle->size(); ++t)
480  {
481  const recob::Track& trk = (*trkListHandle)[t];
482 
483  auto src_clu_list = cluFromTrk.at(t);
484  double adcsum = 0.0;
485  std::vector<double> ensum(3, 0.0);
486 
487  for (size_t c = 0; c < src_clu_list.size(); ++c)
488  {
489  std::vector< art::Ptr<recob::Hit> > v = hitFromClu.at(src_clu_list[c].key());
490  adcsum += getClusterAdcSum(v);
491 
492  if (src_clu_list[c]->View() == geo::kU) { ensum[0] += adcsum; }
493  else if (src_clu_list[c]->View() == geo::kV) { ensum[1] += adcsum; }
494  else if (src_clu_list[c]->View() == geo::kZ) { ensum[2] += adcsum; }
495  }
496 
497  auto cnv = vtxFromTrk.at(t);
498  if (cnv.size())
499  {
500  int gid = getGammaId(evt, t);
501  ShowerInfo si(t, gid, true, ensum, trk);
502  showers.push_back(si);
503  }
504  else
505  {
506  int gid = getGammaId(evt, t);
507  ShowerInfo si(t, gid, false, ensum, trk);
508  showers.push_back(si);
509  }
510  }
511 
512  fNTot = showers.size();
513 
515  gammawithconv = collectshowers(evt, showers, true); // true switches on refpoint
516 
517  // with pma segments reconstructed
518  // procceed with pma segments when two conversions
519  std::vector< ShowerInfo > pmaseg;
520  for (size_t i = 0; i < showers.size(); ++i)
521  if (!showers[i].HasConPoint())
522  pmaseg.push_back(showers[i]);
523 
524  fNPMA = pmaseg.size();
525 
526  const double bigcone = fWideConeAngle; // degree.
527 
528  if (gammawithconv.size())
529  for (size_t i = 0; i < pmaseg.size(); i++)
530  {
531  double a_min = bigcone; size_t best = 0;
532  for (size_t j = 0; j < gammawithconv.size(); j++)
533  {
534  TVector3 halfpoint = (pmaseg[i].GetFront() + pmaseg[i].GetEnd()) * 0.5;
535  double a = gammawithconv[j].first.Angleto(halfpoint);
536  if (a < a_min)
537  {
538  a_min = a; best = j;
539  }
540  }
541  if (a_min < bigcone)
542  gammawithconv[best].Merge(pmaseg[i]);
543  }
544 
545  mcinfo(evt);
546 
547 
548  for (size_t i = 0; i < gammawithconv.size(); ++i)
549  if (gammawithconv[i].IsClean()) fNCleanMerged++;
550 
551  fNMerged = gammawithconv.size();
552  if (gammawithconv.size() == 2)
553  {
554  fNParts[0] = gammawithconv[0].Size();
555  fNParts[1] = gammawithconv[1].Size();
556  }
557 
558  fDistvtxmcreco = std::sqrt(pma::Dist2(fRefPoint, fPi0vtx));
559  fEvTree->Fill();
560 
561  fVtxIndex = 0;
562  for (size_t i = 0; i < gammawithconv.size(); ++i)
563  {
564  int id = i;
565  TVector3 v0(0., 0., 0.);
566  TVector3 dir = gammawithconv[i].Dir();
567  TVector3 front = gammawithconv[i].Front();
568 
569  std::vector<double> dedx = gammawithconv[i].DeDx();
570  std::vector< double > vd;
571  recob::Shower cas(
572  dir, v0, front, v0,
573  vd, vd, dedx, vd, gammawithconv[i].PlaneId(), id);
574 
575 
576  std::vector< art::Ptr<recob::Cluster> > cls;
577  std::vector< art::Ptr<recob::Hit> > hits;
578  for (size_t p = 0; p < gammawithconv[i].Size(); p++)
579  {
580  int trkKey = gammawithconv[i].GetParts()[p].GetKey();
581  auto src_clu_list = cluFromTrk.at(trkKey);
582 
583  for (size_t c = 0; c < src_clu_list.size(); c++)
584  {
585  cls.push_back(src_clu_list[c]);
586 
587  auto v = hitFromClu.at(src_clu_list[c].key());
588  for (size_t h = 0; h < v.size(); h++) hits.push_back(v[h]);
589  }
590 
591  auto ver_list = vtxFromTrk.at(trkKey);
592  }
593 
594  std::vector<double> totE;
595  std::vector<double> totEerr;
596  for (int i = 0; i<3; ++i){
597  totE.push_back(fShowerEnergyAlg.ShowerEnergy(hits,i));
598  totEerr.push_back(0);
599  }
600  cas.set_total_energy(totE);
601  cas.set_total_energy_err(totEerr);
602  cascades->push_back(cas);
603 
604  double vtx_pos[3] = {front.X(), front.Y(), front.Z()};
605  vertices->push_back(recob::Vertex(vtx_pos, fVtxIndex));
606  fVtxIndex++;
607 
608  if (vertices->size())
609  {
610  size_t vtx_idx = (size_t)(vertices->size() - 1);
611  util::CreateAssn(*this, evt, *cascades, *vertices, *shs2vtx, vtx_idx, vtx_idx + 1);
612  }
613 
614  util::CreateAssn(*this, evt, *cascades, cls, *shs2cl);
615  util::CreateAssn(*this, evt, *cascades, hits, *shs2hit);
616 
617  }
618 
619  }
620 
621  evt.put(std::move(cascades));
622  evt.put(std::move(vertices));
623 
624  evt.put(std::move(shs2vtx));
625  evt.put(std::move(shs2cl));
626  evt.put(std::move(shs2hit));
627 }
double ShowerEnergy(std::vector< art::Ptr< recob::Hit > > const &hits, int plane)
Finds the total energy deposited by the shower in this view.
unsigned int event
Definition: DataStructs.h:537
double Dist2(const TVector2 &v1, const TVector2 &v2)
Definition: Utilities.cxx:19
Planes which measure V.
Definition: geo_types.h:77
Planes which measure Z direction.
Definition: geo_types.h:79
shower::ShowerEnergyAlg fShowerEnergyAlg
Definition of vertex object for LArSoft.
Definition: Vertex.h:35
int getGammaId(art::Event &evt, const size_t t)
Planes which measure U.
Definition: geo_types.h:76
void hits()
Definition: readHits.C:15
std::vector< ems::ShowersCollection > collectshowers(art::Event &evt, std::vector< ems::ShowerInfo > &showers, bool refpoint)
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.
void mcinfo(art::Event &evt)
TDirectory * dir
Definition: macro.C:5
double getClusterAdcSum(const std::vector< art::Ptr< recob::Hit > > &v)
TCEvent evt
Definition: DataStructs.cxx:5
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
Definition: Track.h:52
void ems::MergeEMShower3D::reconfigure ( fhicl::ParameterSet const &  p)

Definition at line 434 of file MergeEMShower3D_module.cc.

References fCluModuleLabel, fHitsModuleLabel, fNarrowConeAngle, fTrk3DModuleLabel, fVtxModuleLabel, fWideConeAngle, and fhicl::ParameterSet::get().

Referenced by MergeEMShower3D().

435 {
436  fHitsModuleLabel = p.get< std::string >("HitsModuleLabel");
437  fCluModuleLabel = p.get< std::string >("ClustersModuleLabel");
438  fTrk3DModuleLabel = p.get< std::string >("Trk3DModuleLabel");
439  fVtxModuleLabel = p.get< std::string >("VtxModuleLabel");
440 
441  fNarrowConeAngle = p.get< double >("NarrowConeAngle");
442  fWideConeAngle = p.get< double >("WideConeAngle");
443 
444  return;
445 }
void art::Consumer::showMissingConsumes ( ) const
protectedinherited

Definition at line 125 of file Consumer.cc.

Referenced by art::EDProducer::doEndJob(), art::EDFilter::doEndJob(), art::EDAnalyzer::doEndJob(), and art::RootOutput::endJob().

126 {
127  if (!moduleContext_)
128  return;
129 
130  // If none of the branches have missing consumes statements, exit early.
131  if (std::all_of(cbegin(missingConsumes_),
132  cend(missingConsumes_),
133  [](auto const& perBranch) { return perBranch.empty(); }))
134  return;
135 
136  constexpr cet::HorizontalRule rule{60};
137  mf::LogPrint log{"MTdiagnostics"};
138  log << '\n'
139  << rule('=') << '\n'
140  << "The following consumes (or mayConsume) statements are missing from\n"
141  << module_context(moduleDescription_) << '\n'
142  << rule('-') << '\n';
143 
144  cet::for_all_with_index(
145  missingConsumes_, [&log](std::size_t const i, auto const& perBranch) {
146  for (auto const& pi : perBranch) {
147  log << " "
148  << assemble_consumes_statement(static_cast<BranchType>(i), pi)
149  << '\n';
150  }
151  });
152  log << rule('=');
153 }
cet::exempt_ptr< ModuleDescription const > moduleDescription_
Definition: Consumer.h:140
constexpr T pi()
Returns the constant pi (up to 35 decimal digits of precision)
bool moduleContext_
Definition: Consumer.h:136
ConsumableProductSets missingConsumes_
Definition: Consumer.h:139
void art::Consumer::validateConsumedProduct ( BranchType const  bt,
ProductInfo const &  pi 
)
protectedinherited

Definition at line 101 of file Consumer.cc.

References art::errors::ProductRegistrationFailure.

103 {
104  // Early exits if consumes tracking has been disabled or if the
105  // consumed product is an allowed consumable.
106  if (!moduleContext_)
107  return;
108 
109  if (cet::binary_search_all(consumables_[bt], pi))
110  return;
111 
112  if (requireConsumes_) {
114  "Consumer: an error occurred during validation of a "
115  "retrieved product\n\n")
116  << "The following consumes (or mayConsume) statement is missing from\n"
117  << module_context(moduleDescription_) << ":\n\n"
118  << " " << assemble_consumes_statement(bt, pi) << "\n\n";
119  }
120 
121  missingConsumes_[bt].insert(pi);
122 }
cet::exempt_ptr< ModuleDescription const > moduleDescription_
Definition: Consumer.h:140
bool requireConsumes_
Definition: Consumer.h:137
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
constexpr T pi()
Returns the constant pi (up to 35 decimal digits of precision)
ConsumableProducts consumables_
Definition: Consumer.h:138
bool moduleContext_
Definition: Consumer.h:136
ConsumableProductSets missingConsumes_
Definition: Consumer.h:139

Member Data Documentation

std::string ems::MergeEMShower3D::fCluModuleLabel
private

Definition at line 391 of file MergeEMShower3D_module.cc.

Referenced by getGammaId(), produce(), and reconfigure().

double ems::MergeEMShower3D::fDistvtxmcreco
private

Definition at line 383 of file MergeEMShower3D_module.cc.

Referenced by beginJob(), and produce().

int ems::MergeEMShower3D::fEvNumber
private

Definition at line 385 of file MergeEMShower3D_module.cc.

Referenced by beginJob(), and produce().

TTree* ems::MergeEMShower3D::fEvTree
private

Definition at line 372 of file MergeEMShower3D_module.cc.

Referenced by beginJob(), and produce().

int ems::MergeEMShower3D::fEvWhat
private

Definition at line 380 of file MergeEMShower3D_module.cc.

Referenced by beginJob().

std::string ems::MergeEMShower3D::fHitsModuleLabel
private

Definition at line 390 of file MergeEMShower3D_module.cc.

Referenced by getGammaId(), produce(), and reconfigure().

double ems::MergeEMShower3D::fMcMom
private

Definition at line 384 of file MergeEMShower3D_module.cc.

Referenced by beginJob(), mcinfo(), and produce().

double ems::MergeEMShower3D::fNarrowConeAngle
private

Definition at line 395 of file MergeEMShower3D_module.cc.

Referenced by collectshowers(), and reconfigure().

int ems::MergeEMShower3D::fNCleanMerged
private

Definition at line 381 of file MergeEMShower3D_module.cc.

Referenced by beginJob(), and produce().

int ems::MergeEMShower3D::fNConv
private

Definition at line 378 of file MergeEMShower3D_module.cc.

Referenced by beginJob(), collectshowers(), and produce().

int ems::MergeEMShower3D::fNMerged
private

Definition at line 381 of file MergeEMShower3D_module.cc.

Referenced by beginJob(), and produce().

int ems::MergeEMShower3D::fNParts[2]
private

Definition at line 377 of file MergeEMShower3D_module.cc.

Referenced by beginJob(), and produce().

int ems::MergeEMShower3D::fNPMA
private

Definition at line 378 of file MergeEMShower3D_module.cc.

Referenced by beginJob(), and produce().

int ems::MergeEMShower3D::fNTot
private

Definition at line 378 of file MergeEMShower3D_module.cc.

Referenced by beginJob(), and produce().

TVector3 ems::MergeEMShower3D::fPi0vtx
private

Definition at line 387 of file MergeEMShower3D_module.cc.

Referenced by mcinfo(), and produce().

TVector3 ems::MergeEMShower3D::fRefPoint
private

Definition at line 388 of file MergeEMShower3D_module.cc.

Referenced by collectshowers(), and produce().

shower::ShowerEnergyAlg ems::MergeEMShower3D::fShowerEnergyAlg
private

Definition at line 398 of file MergeEMShower3D_module.cc.

Referenced by produce().

std::string ems::MergeEMShower3D::fTrk3DModuleLabel
private

Definition at line 392 of file MergeEMShower3D_module.cc.

Referenced by collectshowers(), getGammaId(), produce(), and reconfigure().

int ems::MergeEMShower3D::fVtxIndex
private

Definition at line 375 of file MergeEMShower3D_module.cc.

Referenced by produce().

std::string ems::MergeEMShower3D::fVtxModuleLabel
private

Definition at line 393 of file MergeEMShower3D_module.cc.

Referenced by getGammaId(), produce(), and reconfigure().

int ems::MergeEMShower3D::fWhat
private

Definition at line 380 of file MergeEMShower3D_module.cc.

Referenced by getGammaId(), and produce().

double ems::MergeEMShower3D::fWideConeAngle
private

Definition at line 396 of file MergeEMShower3D_module.cc.

Referenced by produce(), and reconfigure().


The documentation for this class was generated from the following file: