LArSoft  v06_85_00
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 324 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 389 of file MergeEMShower3D_module.cc.

References reconfigure().

390  : fShowerEnergyAlg(p.get<fhicl::ParameterSet>("ShowerEnergyAlg"))
391 {
392  reconfigure(p);
393 
394  produces< std::vector<recob::Shower> >();
395  produces< std::vector<recob::Vertex> >();
396 
397  produces< art::Assns<recob::Shower, recob::Vertex> >();
398  produces< art::Assns<recob::Shower, recob::Cluster> >();
399  produces< art::Assns<recob::Shower, recob::Hit> >();
400 }
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 402 of file MergeEMShower3D_module.cc.

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

403 {
405 
406  fEvTree = tfs->make<TTree>("ShowerTestEv", "pi0 tests");
407  fEvTree->Branch("fEvNumber", &fEvNumber, "fEvNumber/I");
408  fEvTree->Branch("fNPartsA", &fNParts[0], "fNPartsA/I");
409  fEvTree->Branch("fNPartsB", &fNParts[1], "fNPartsB/I");
410  fEvTree->Branch("fNTot", &fNTot, "fNTot/I");
411  fEvTree->Branch("fNPMA", &fNPMA, "fNPMA/I");
412  fEvTree->Branch("fNConv", &fNConv, "fNConv/I");
413  fEvTree->Branch("fEvWhat", &fEvWhat, "fEvWhat/I");
414  fEvTree->Branch("fMcMom", &fMcMom, "fMcMom/D");
415 
416  fEvTree->Branch("fDistvtxmcreco", &fDistvtxmcreco, "fDistvtxmcreco/D");
417  fEvTree->Branch("fNMerged", &fNMerged, "fNMerged/I");
418  fEvTree->Branch("fNCleanMerged", &fNCleanMerged, "fNCleanMerged/I");
419 }
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 616 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().

617 {
618  std::vector< ems::ShowersCollection > gammawithconv;
619 
620  const double smallcone = fNarrowConeAngle; // degree.
621  bool merge = true;
622  if (refpoint)
623  {
626  if (evt.getByLabel(fTrk3DModuleLabel, trkListHandle))
627  {
628  double dsize[6];
629  geom->CryostatBoundaries(dsize, 0);
630  TVector3 geoP0(dsize[0], dsize[2], dsize[4]), geoP1(dsize[1], dsize[3], dsize[5]);
631  TVector3 pov = getBestPoint(*trkListHandle, showers, geoP0, geoP1, 5.0);
632  fRefPoint = pov;
633 
634  for (size_t is = 0; is < showers.size(); is++)
635  showers[is].SetP0Dist(pov);
636  std::sort(showers.begin(), showers.end(), ems::bDistLess());
637 
638  for (size_t is = 0; is < showers.size(); is++)
639  {
640  size_t m_idx = 0;
641  double a, a_min = 360.0;
642  for (size_t m = 0; m < gammawithconv.size(); ++m)
643  {
644  a = gammawithconv[m].Angle(showers[is].GetFront());
645  if ((a < fNarrowConeAngle) && (a < a_min))
646  {
647  m_idx = m; a_min = a;
648  }
649 
650  std::vector< std::pair<TVector3, TVector3> > lines;
651  lines.push_back(std::pair<TVector3, TVector3>(
652  showers[is].GetFront(), showers[is].GetFront() + showers[is].GetDir()));
653  lines.push_back(std::pair<TVector3, TVector3>(
654  gammawithconv[m].Front(), gammawithconv[m].Front() + gammawithconv[m].Dir()));
655 
656  TVector3 isect, pm;
657  pma::SolveLeastSquares3D(lines, isect);
658  pm = pma::GetProjectionToSegment(isect,
659  gammawithconv[m].Front(), gammawithconv[m].Front() + gammawithconv[m].Dir());
660 
661  if (pma::Dist2(pov, gammawithconv[m].Front()) < pma::Dist2(pov, pm))
662  {
663  a = gammawithconv[m].Angle(isect);
664  if ((a < fNarrowConeAngle) && (a < a_min))
665  {
666  m_idx = m; a_min = a;
667  }
668  }
669  }
670  if (a_min < fNarrowConeAngle)
671  {
672  gammawithconv[m_idx].Merge(showers[is]);
673  }
674  else if (showers[is].HasConPoint())
675  {
676  ems::ShowersCollection sc(showers[is]);
677  gammawithconv.push_back(sc);
678  }
679 
680  }
681  }
682  }
683  else
684  {
685  for (size_t i = 0; i < showers.size(); ++i)
686  if (showers[i].HasConPoint())
687  {
688  ems::ShowersCollection sc(showers[i]);
689  gammawithconv.push_back(sc);
690  }
691 
692  fNConv = gammawithconv.size();
693  while (merge)
694  {
695  merge = false;
696  size_t i = 0;
697  while (i < gammawithconv.size())
698  {
699  size_t best = 0; double a_min = smallcone;
700  for (size_t j = 0; j < gammawithconv.size(); j++)
701  if (i != j)
702  {
703  double a = gammawithconv[i].MinAngle(gammawithconv[j]);
704  if (a < a_min)
705  {
706  a_min = a; best = j; merge = true;
707  }
708  }
709  if (merge)
710  {
711  gammawithconv[i].Merge(gammawithconv[best]);
712  gammawithconv.erase(gammawithconv.begin() + best);
713  break;
714  }
715  i++;
716  }
717  }
718  }
719  return gammawithconv;
720 }
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:167
double SolveLeastSquares3D(const std::vector< std::pair< TVector3, TVector3 > > &lines, TVector3 &result)
Definition: Utilities.cxx:187
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 806 of file MergeEMShower3D_module.cc.

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

Referenced by collectshowers().

810 {
811  TVector3 best, p;
812 
813  double f, fmin = 1.0e10;
814 
815  double dx = step;
816  double dy = step;
817  double dz = step;
818 
819  double x0 = p0.X();
820  while (x0 < p1.X())
821  {
822  double y0 = p0.Y();
823  while (y0 < p1.Y())
824  {
825  double z0 = p0.Z();
826  while (z0 < p1.Z())
827  {
828  f = 0.0;
829  //size_t nOK = 0;
830  TVector3 mid(0., 0., 0.);
831 
832  p.SetXYZ(x0, y0, z0);
833  for (size_t t = 0; t < tracks.size(); t++)
834  // if (showers[t].OK)
835  {
836  auto const & trk = tracks[t];
837 
838  double cos = -acos( getCos3D(p, trk) ) / (0.5*TMath::Pi());
839  //double cos = getCos3D(p, trk);
840 
841  if (showers[t].HasConPoint()) cos *= 3.0;
842  cos *= sqrt( showers[t].GetAdcSum() );
843 
844  mid += 0.5 * (trk.Vertex() + trk.End());
845 
846  f += cos;
847  // nOK++;
848  }
849  //if (!nOK) return best;
850 
851  // f /= nOK;
852  // mid *= 1.0 / nOK;
853 
854  f = -f + 0.0001 * sqrt(pma::Dist2(p, mid));
855  if (f < fmin)
856  {
857  fmin = f; best = p;
858  }
859 
860  z0 += dz;
861  }
862  y0 += dy;
863  }
864  x0 += dx;
865  }
866  return best;
867 }
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 890 of file MergeEMShower3D_module.cc.

References DEFINE_ART_MODULE.

Referenced by produce().

891 {
892  double sum = 0.0;
893  for (auto ptr : v)
894  {
895  sum += ptr->SummedADC();
896  }
897  return sum;
898 }
int ems::MergeEMShower3D::getClusterBestId ( const std::vector< art::Ptr< recob::Hit > > &  v)

Definition at line 723 of file MergeEMShower3D_module.cc.

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

Referenced by getGammaId().

724 {
726 
727  std::map< int, size_t > ids;
728  for (auto ptr : v)
729  {
730  auto hid = bt_serv->HitToTrackIDEs(ptr);
731  if (hid.size()) ids[hid.front().trackID]++;
732  }
733 
734  int best_id = 9999;
735  size_t max = 0;
736  for (auto p : ids)
737  {
738  if ((p.second > (int)(0.8 * v.size())) && (p.second > max))
739  {
740  max = p.second; best_id = p.first;
741  }
742  }
743 
744  return best_id;
745 }
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 869 of file MergeEMShower3D_module.cc.

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

Referenced by getBestPoint().

870 {
871  TVector3 p1, dir;
872 
873  if (pma::Dist2(p0, trk.Vertex()) < pma::Dist2(p0, trk.End()))
874  p1 = trk.Vertex();
875  else
876  p1 = trk.End();
877 
878  p1 -= p0;
879  double m = p1.Mag();
880  if (m > 0.0)
881  {
882  p1 *= 1.0 / m;
883  double c = fabs(p1 * trk.VertexDirection());
884  if (c > 1.0) c = 1.0;
885  return c;
886  }
887  else return 0.0;
888 }
double Dist2(const TVector2 &v1, const TVector2 &v2)
Definition: Utilities.cxx:19
TVector3 VertexDirection() const
Covariance matrices are either set or not.
Definition: Track.h:247
TDirectory * dir
Definition: macro.C:5
TVector3 Vertex() const
Covariance matrices are either set or not.
Definition: Track.h:245
TVector3 End() const
Covariance matrices are either set or not.
Definition: Track.h:246
int ems::MergeEMShower3D::getGammaId ( art::Event evt,
const size_t  t 
)

Definition at line 773 of file MergeEMShower3D_module.cc.

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

Referenced by produce().

774 {
775  fWhat = 0;
776  int cid = 0, gid = 0;
780  art::Handle< std::vector<recob::Hit> > hitListHandle;
781  if (evt.getByLabel(fTrk3DModuleLabel, trkListHandle) &&
782  evt.getByLabel(fVtxModuleLabel, vtxListHandle) &&
783  evt.getByLabel(fCluModuleLabel, cluListHandle) &&
784  evt.getByLabel(fHitsModuleLabel, hitListHandle))
785  {
786  art::FindManyP< recob::Cluster > cluFromTrk(trkListHandle, evt, fTrk3DModuleLabel);
787  art::FindManyP< recob::Vertex > vtxFromTrk(trkListHandle, evt, fVtxModuleLabel);
788  art::FindManyP< recob::Hit > hitFromClu(cluListHandle, evt, fCluModuleLabel);
789 
790  auto src_clu_list = cluFromTrk.at(t);
791  for (size_t c = 0; c < src_clu_list.size(); ++c)
792  {
793  std::vector< art::Ptr<recob::Hit> > v = hitFromClu.at(src_clu_list[c].key());
794  cid = getClusterBestId(v);
795 
796  if ((fWhat == 0) && (cid == 9999)) fWhat = 1; // confused 2D
797  if ((fWhat == 0) && (gid == 0)) gid = cid;
798  if ((fWhat == 0) && (cid != gid)) fWhat = 2; // confused 3D
799  }
800  }
801 
802  if (fWhat == 0) return gid;
803  else return 9999;
804 }
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 747 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().

748 {
749  int pi0_idx = -1;
750 
751  art::Handle< std::vector<simb::MCTruth> > mctruthListHandle;
752  std::vector< art::Ptr<simb::MCTruth> > mclist;
753  if (evt.getByLabel("generator", mctruthListHandle))
754  {
755  art::fill_ptr_vector(mclist, mctruthListHandle);
756  if (mclist.size())
757  {
758  size_t np = mclist[0]->NParticles();
759  for (size_t i = 0; i < np; ++i)
760  if (mclist[0]->GetParticle(i).PdgCode() == 111)
761  {pi0_idx = i; break;}
762  }
763  }
764 
765  if (pi0_idx < 0) return;
766 
767  const simb::MCParticle & pi0 = mclist[0]->GetParticle(pi0_idx);
768  TVector3 pi0_vtx(pi0.Vx(), pi0.Vy(), pi0.Vz());
769  fPi0vtx = pi0_vtx;
770  fMcMom = pi0.P();
771 }
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 434 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().

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

Definition at line 421 of file MergeEMShower3D_module.cc.

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

Referenced by MergeEMShower3D().

422 {
423  fHitsModuleLabel = p.get< std::string >("HitsModuleLabel");
424  fCluModuleLabel = p.get< std::string >("ClustersModuleLabel");
425  fTrk3DModuleLabel = p.get< std::string >("Trk3DModuleLabel");
426  fVtxModuleLabel = p.get< std::string >("VtxModuleLabel");
427 
428  fNarrowConeAngle = p.get< double >("NarrowConeAngle");
429  fWideConeAngle = p.get< double >("WideConeAngle");
430 
431  return;
432 }
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 378 of file MergeEMShower3D_module.cc.

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

double ems::MergeEMShower3D::fDistvtxmcreco
private

Definition at line 370 of file MergeEMShower3D_module.cc.

Referenced by beginJob(), and produce().

int ems::MergeEMShower3D::fEvNumber
private

Definition at line 372 of file MergeEMShower3D_module.cc.

Referenced by beginJob(), and produce().

TTree* ems::MergeEMShower3D::fEvTree
private

Definition at line 359 of file MergeEMShower3D_module.cc.

Referenced by beginJob(), and produce().

int ems::MergeEMShower3D::fEvWhat
private

Definition at line 367 of file MergeEMShower3D_module.cc.

Referenced by beginJob().

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

Definition at line 377 of file MergeEMShower3D_module.cc.

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

double ems::MergeEMShower3D::fMcMom
private

Definition at line 371 of file MergeEMShower3D_module.cc.

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

double ems::MergeEMShower3D::fNarrowConeAngle
private

Definition at line 382 of file MergeEMShower3D_module.cc.

Referenced by collectshowers(), and reconfigure().

int ems::MergeEMShower3D::fNCleanMerged
private

Definition at line 368 of file MergeEMShower3D_module.cc.

Referenced by beginJob(), and produce().

int ems::MergeEMShower3D::fNConv
private

Definition at line 365 of file MergeEMShower3D_module.cc.

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

int ems::MergeEMShower3D::fNMerged
private

Definition at line 368 of file MergeEMShower3D_module.cc.

Referenced by beginJob(), and produce().

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

Definition at line 364 of file MergeEMShower3D_module.cc.

Referenced by beginJob(), and produce().

int ems::MergeEMShower3D::fNPMA
private

Definition at line 365 of file MergeEMShower3D_module.cc.

Referenced by beginJob(), and produce().

int ems::MergeEMShower3D::fNTot
private

Definition at line 365 of file MergeEMShower3D_module.cc.

Referenced by beginJob(), and produce().

TVector3 ems::MergeEMShower3D::fPi0vtx
private

Definition at line 374 of file MergeEMShower3D_module.cc.

Referenced by mcinfo(), and produce().

TVector3 ems::MergeEMShower3D::fRefPoint
private

Definition at line 375 of file MergeEMShower3D_module.cc.

Referenced by collectshowers(), and produce().

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

Definition at line 385 of file MergeEMShower3D_module.cc.

Referenced by produce().

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

Definition at line 379 of file MergeEMShower3D_module.cc.

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

int ems::MergeEMShower3D::fVtxIndex
private

Definition at line 362 of file MergeEMShower3D_module.cc.

Referenced by produce().

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

Definition at line 380 of file MergeEMShower3D_module.cc.

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

int ems::MergeEMShower3D::fWhat
private

Definition at line 367 of file MergeEMShower3D_module.cc.

Referenced by getGammaId(), and produce().

double ems::MergeEMShower3D::fWideConeAngle
private

Definition at line 383 of file MergeEMShower3D_module.cc.

Referenced by produce(), and reconfigure().


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