Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
tdslicer::TDSlicer Class Reference
Inheritance diagram for tdslicer::TDSlicer:
art::EDProducer art::ProducerBase art::Consumer art::EngineCreator art::ProductRegistryHelper

Public Types

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

Public Member Functions

 TDSlicer (const Parameters &params)
 
virtual ~TDSlicer ()
 
void beginRun (art::Run &run)
 
void produce (art::Event &evt)
 
void endJob ()
 
double GetDist (double dt, double dp, double dc)
 
std::vector< PtInfoGetPtInfo (const std::vector< art::Ptr< rb::CellHit > > &hits)
 
std::vector< intGetCentroids (const std::vector< PtInfo > &info)
 
std::vector< rb::ClusterDBSCAN (std::vector< art::Ptr< rb::CellHit > > hits)
 
void SortStuff (std::vector< double > &mindist, std::vector< art::Ptr< rb::CellHit > > &hits)
 
int GetPoint (const std::vector< double > &dist, const std::vector< bool > &isUsed)
 
void FillDists (std::vector< std::vector< double > > &dists, const std::vector< art::Ptr< rb::CellHit > > &hits)
 
std::vector< double > Prims (const std::vector< art::Ptr< rb::CellHit > > &hits)
 
void TrimNoise (rb::Cluster *cNoise, std::vector< rb::Cluster > *c2D)
 
std::vector< rb::ClusterCombineViews (rb::Cluster *cNoise, std::vector< rb::Cluster > *cX, std::vector< rb::Cluster > *cY)
 
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< Tconsumes (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ProductToken< Tconsumes (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< TconsumesView (InputTag const &it)
 
template<typename T , BranchType = InEvent>
ProductToken< TmayConsume (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ProductToken< TmayConsume (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< TmayConsumeView (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
 

Protected Attributes

TDSlicerParams fParams
 
TDSlicerDetectorParams fDetectorParams
 

Detailed Description

Definition at line 145 of file TDSlicer_module.cc.

Member Typedef Documentation

using art::EDProducer::ModuleType = EDProducer
inherited

Definition at line 34 of file EDProducer.h.

Definition at line 148 of file TDSlicer_module.cc.

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

tdslicer::TDSlicer::TDSlicer ( const Parameters params)
explicit

Definition at line 191 of file TDSlicer_module.cc.

192  : fParams(params())
193  {
194  produces< std::vector<rb::Cluster> >();
195  }
TDSlicerParams fParams
tdslicer::TDSlicer::~TDSlicer ( )
virtual

Definition at line 198 of file TDSlicer_module.cc.

199  { }

Member Function Documentation

void tdslicer::TDSlicer::beginRun ( art::Run run)
virtual

Reimplemented from art::EDProducer.

Definition at line 202 of file TDSlicer_module.cc.

References ana::assert(), geo::GeometryBase::DetId(), fDetectorParams, tdslicer::TDSlicerParams::fdParams, fParams, geom(), novadaq::cnv::kFARDET, novadaq::cnv::kNEARDET, novadaq::cnv::kTESTBEAM, tdslicer::TDSlicerParams::ndParams, and tdslicer::TDSlicerParams::tbParams.

203  {
205  switch (geom->DetId()) {
208  break;
211  break;
214  break;
215  default:
216  assert(0 && "Unknown detector");
217  }
218  }
TDSlicerParams fParams
Table< TDSlicerDetectorParams > tbParams
Table< TDSlicerDetectorParams > fdParams
Far Detector at Ash River, MN.
Table< TDSlicerDetectorParams > ndParams
novadaq::cnv::DetId DetId() const
Prefer ds::DetectorService::DetId() instead.
Definition: GeometryBase.h:243
Near Detector in the NuMI cavern.
void geom(int which=0)
Definition: geom.C:163
TDSlicerDetectorParams fDetectorParams
assert(nhit_max >=nhit_nbins)
std::vector< rb::Cluster > tdslicer::TDSlicer::CombineViews ( rb::Cluster cNoise,
std::vector< rb::Cluster > *  cX,
std::vector< rb::Cluster > *  cY 
)

Definition at line 343 of file TDSlicer_module.cc.

References MECModelEnuComparisons::i, makeTrainCVSamples::int, and TrimNoise().

Referenced by produce().

346  {
347  TrimNoise(cNoise, cX);
348  TrimNoise(cNoise, cY);
349 
350  std::vector<rb::Cluster> clusts;
351  for (int i = 0; i < (int)cX->size(); i++)
352  clusts.push_back(cX->at(i));
353  for (int i = 0; i < (int)cY->size(); i++)
354  clusts.push_back(cY->at(i));
355  return clusts;
356  }
void TrimNoise(rb::Cluster *cNoise, std::vector< rb::Cluster > *c2D)
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 146 of file Consumer.h.

References art::InputTag::instance(), PandAna.reco_validation.prod5_pid_validation::invalid, art::InputTag::label(), art::InputTag::process(), and T.

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

Definition at line 161 of file Consumer.h.

References T.

162 {
163  if (!moduleContext_)
164  return;
165 
166  consumables_[BT].emplace_back(ConsumableType::Many, TypeID{typeid(T)});
167 }
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
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 171 of file Consumer.h.

References art::InputTag::instance(), PandAna.reco_validation.prod5_pid_validation::invalid, art::InputTag::label(), art::InputTag::process(), and T.

172 {
173  if (!moduleContext_)
174  return ViewToken<T>::invalid();
175 
176  consumables_[BT].emplace_back(ConsumableType::ViewElement,
177  TypeID{typeid(T)},
178  it.label(),
179  it.instance(),
180  it.process());
181  return ViewToken<T>{it};
182 }
set< int >::iterator it
static ViewToken< Element > invalid()
Definition: ProductToken.h:75
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
base_engine_t& art::EngineCreator::createEngine ( seed_t  seed)
inherited
base_engine_t& art::EngineCreator::createEngine ( seed_t  seed,
std::string const &  kind_of_engine_to_make 
)
inherited
base_engine_t& art::EngineCreator::createEngine ( seed_t  seed,
std::string const &  kind_of_engine_to_make,
label_t const &  engine_label 
)
inherited
CurrentProcessingContext const* art::EDProducer::currentContext ( ) const
protectedinherited
std::vector< rb::Cluster > tdslicer::TDSlicer::DBSCAN ( std::vector< art::Ptr< rb::CellHit > >  hits)

Definition at line 443 of file TDSlicer_module.cc.

References rb::Cluster::Add(), fDetectorParams, hits(), tdslicer::TDSlicerDetectorParams::minPrimDist, Prims(), and SortStuff().

Referenced by produce().

444  {
445  std::vector<rb::Cluster> clusts(1);
446  std::vector<double> mindist = Prims(hits);
447 
448  SortStuff(mindist, hits);
449  while (hits.size()>0){
450  if (mindist[0] > fDetectorParams.minPrimDist()){
451  //if (mindist[0] > 150){
452  mindist = Prims(hits);
453  SortStuff(mindist, hits);
454  rb::Cluster clust;
455  clusts.push_back(clust);
456  }
457  clusts.back().Add(hits[0]);
458  hits.erase(hits.begin());
459  mindist.erase(mindist.begin());
460  }
461  return clusts;
462  }
void SortStuff(std::vector< double > &mindist, std::vector< art::Ptr< rb::CellHit > > &hits)
A collection of associated CellHits.
Definition: Cluster.h:47
std::vector< double > Prims(const std::vector< art::Ptr< rb::CellHit > > &hits)
virtual void Add(const art::Ptr< rb::CellHit > &cell, double weight=1)
Definition: Cluster.cxx:84
void hits()
Definition: readHits.C:15
TDSlicerDetectorParams fDetectorParams
void tdslicer::TDSlicer::endJob ( )
virtual

Reimplemented from art::EDProducer.

Definition at line 221 of file TDSlicer_module.cc.

222  {
223  }
void tdslicer::TDSlicer::FillDists ( std::vector< std::vector< double > > &  dists,
const std::vector< art::Ptr< rb::CellHit > > &  hits 
)

Definition at line 373 of file TDSlicer_module.cc.

References tdslicer::TDSlicerDetectorParams::cellScale, lem_server::cs, fDetectorParams, hits(), MECModelEnuComparisons::i, makeTrainCVSamples::int, calib::j, tdslicer::TDSlicerDetectorParams::planeScale, nd_projection_maker::ps, util::sqr(), std::sqrt(), and tdslicer::TDSlicerDetectorParams::timeScale.

Referenced by Prims().

375  {
376  std::vector<double> ts(hits.size());
377  std::vector<double> ps(hits.size());
378  std::vector<double> cs(hits.size());
379 
380  for(unsigned int i = 0; i < hits.size(); ++i){
381  ts[i] = hits[i]->TNS()/fDetectorParams.timeScale();
382  ps[i] = hits[i]->Plane()/fDetectorParams.planeScale();
383  cs[i] = hits[i]->Cell()/fDetectorParams.cellScale();
384  }
385 
386  for (int i = 0; i < (int)hits.size(); i++){
387  for (int j = 0; j <= i; j++){
388  if(i == j){
389  dists[i][j] = 0;
390  continue;
391  }
392  double dp=util::sqr(ps[i]-ps[j]);
393  double dc=util::sqr(cs[i]-cs[j]);
394  double dt=util::sqr(ts[i]-ts[j]);
395  dists[i][j] = sqrt(dp+dc)
396  + sqrt(dt+dc)
397  + sqrt(dt+dp);
398  dists[j][i] = dists[i][j];
399  }
400  }
401  }
T sqrt(T number)
Definition: d0nt_math.hpp:156
T sqr(T x)
More efficient square function than pow(x,2)
Definition: MathUtil.h:23
Definition: Cand.cxx:23
void hits()
Definition: readHits.C:15
const double j
Definition: BetheBloch.cxx:29
TDSlicerDetectorParams fDetectorParams
seed_t art::EngineCreator::get_seed_value ( fhicl::ParameterSet const &  pset,
char const  key[] = "seed",
seed_t const  implicit_seed = -1 
)
inherited
std::vector< int > tdslicer::TDSlicer::GetCentroids ( const std::vector< PtInfo > &  info)

Definition at line 465 of file TDSlicer_module.cc.

References fDetectorParams, MECModelEnuComparisons::i, makeTrainCVSamples::int, tdslicer::TDSlicerDetectorParams::minDens, and tdslicer::TDSlicerDetectorParams::minIsol.

Referenced by produce().

466  {
467  std::vector<int> centroids;
468  for (int i = 0; i < (int)info.size(); i++){
469  if (info[i].dens >= fDetectorParams.minDens() &&
470  info[i].isol >= fDetectorParams.minIsol()){
471  centroids.push_back(i);
472  }
473  }
474  return centroids;
475  }
const XML_Char XML_Encoding * info
Definition: expat.h:530
TDSlicerDetectorParams fDetectorParams
double tdslicer::TDSlicer::GetDist ( double  dt,
double  dp,
double  dc 
)

Definition at line 225 of file TDSlicer_module.cc.

References tdslicer::TDSlicerDetectorParams::calcDT2D, tdslicer::TDSlicerParams::cellLength, stan::math::fabs(), fDetectorParams, fParams, tdslicer::TDSlicerParams::planeLength, util::pythag(), R, tdslicer::TDSlicerParams::speedOfLight, and tdslicer::TDSlicerDetectorParams::timeScale.

Referenced by GetPtInfo(), and produce().

226  {
227  if (fDetectorParams.calcDT2D()){
228  double R = util::pythag(fParams.planeLength()*dp,
229  fParams.cellLength()*dc);
231  }
232  else {
233  double R = dp*fParams.planeLength();
235  // We know in the ND, all our physics momentum is in the +z direction,
236  // Hits at higher planes, should also be at higher dt
237  }
238  }
fvar< T > fabs(const fvar< T > &x)
Definition: fabs.hpp:15
TDSlicerParams fParams
Definition: Cand.cxx:23
#define R(x)
double pythag(double x, double y)
2D Euclidean distance
Definition: MathUtil.h:29
TDSlicerDetectorParams fDetectorParams
int tdslicer::TDSlicer::GetPoint ( const std::vector< double > &  dist,
const std::vector< bool > &  isUsed 
)

Definition at line 359 of file TDSlicer_module.cc.

References MECModelEnuComparisons::i, makeTrainCVSamples::int, and min().

Referenced by Prims().

361  {
362  double min = 1e6; // Infinity
363  int minIdx = -1;
364  for (int i = 0; i < (int)dist.size(); i++){
365  if (!isUsed[i] && dist[i]<min){
366  min = dist[i];
367  minIdx = i;
368  }
369  }
370  return minIdx;
371  }
double dist
Definition: runWimpSim.h:113
static float min(const float a, const float b, const float c)
Definition: absgeo.cxx:45
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_.

Referenced by skim::NueSkimmer::CopyMichelSlice(), and skim::NueSkimmer::CopyMichelTrack().

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 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  }
std::vector< PtInfo > tdslicer::TDSlicer::GetPtInfo ( const std::vector< art::Ptr< rb::CellHit > > &  hits)

Definition at line 242 of file TDSlicer_module.cc.

References dist, stan::math::exp(), fDetectorParams, GetDist(), hits(), MECModelEnuComparisons::i, makeTrainCVSamples::int, calib::j, std::max(), min(), and tdslicer::TDSlicerDetectorParams::minIsol.

Referenced by produce().

243  {
244  std::vector<PtInfo> info(hits.size());
245 
246  double maxdist = 0;
247  for (int i = 0; i < (int)hits.size(); i++){
248  info[i].tns = hits[i]->TNS();
249  info[i].plane= hits[i]->Plane();
250  info[i].cell = hits[i]->Cell();
251  for (int j = i+1; j < (int)hits.size(); j++){
252  double dt = (hits[i]->TNS() - hits[j]->TNS());
253  double dp = (hits[i]->Plane() - hits[j]->Plane());
254  double dc = (hits[i]->Cell() - hits[j]->Cell());
255  double dist = GetDist(dt,dp,dc);
256  //double dist = fabs(sqrt(dt*dt+dp*dp/18/18));
257  if (dist > 10) break; // Tiny density contribution beyond this
258  if (dist > maxdist) maxdist = dist;
259  if (i != j){
260  const double ed2 = exp(-dist*dist);
261  info[i].dens += ed2;
262  info[j].dens += ed2;
263  }
264  }
265  for (int j = i-1; j >= 0; j--){
266  double dt = (hits[i]->TNS() - hits[j]->TNS());
267  double dp = (hits[i]->Plane() - hits[j]->Plane());
268  double dc = (hits[i]->Cell() - hits[j]->Cell());
269  double dist = GetDist(dt,dp,dc);
270  //double dist = fabs(sqrt(dt*dt+dp*dp/18/18));
271  if (dist > 10) break; // Tiny density contribution beyond this
272  if (dist > maxdist) maxdist = dist;
273  if (i != j){
274  const double ed2 = exp(-dist*dist);
275  info[i].dens += ed2;
276  info[j].dens += ed2;
277  }
278  }
279  }
280 
281  for (int i = 0; i < (int)hits.size(); i++){
282  double min = std::max(maxdist, fDetectorParams.minIsol());
283  info[i].nn = -1;
284 
285  // Need the closest point with higher density.
286  // Hits sorted by time, so start at i, find next higher dens point
287  for (int j = i+1; j < (int)hits.size(); j++){
288  if (info[j].dens > info[i].dens){
289  double dt = (info[i].tns - info[j].tns);
290  double dp = (info[i].plane - info[j].plane);
291  double dc = (hits[i]->Cell() - hits[j]->Cell());
292  double dist = GetDist(dt,dp,dc);
293  //double dist = fabs(sqrt(dt*dt+dp*dp/18/18));
294  if (dist < min){
295  info[i].nn = j;
296  min = dist;
297  }
298  // We've now found a higher density point.
299  break;
300  }
301  }
302  // Now, go backwards
303  for (int j = i-1; j >= 0; j--){
304  if (info[j].dens > info[i].dens){
305  double dt = (info[i].tns - info[j].tns);
306  double dp = (info[i].plane - info[j].plane);
307  double dc = (hits[i]->Cell() - hits[j]->Cell());
308  double dist = GetDist(dt,dp,dc);
309  //double dist = fabs(sqrt(dt*dt+dp*dp/18/18));
310  if (dist < min){
311  info[i].nn = j;
312  min = dist;
313  }
314  // We've now found a higher density point.
315  break;
316  }
317  }
318  info[i].isol = min;
319  }
320 
321 
322  return info;
323  }
T max(const caf::Proxy< T > &a, T b)
const XML_Char XML_Encoding * info
Definition: expat.h:530
double GetDist(double dt, double dp, double dc)
double dist
Definition: runWimpSim.h:113
Definition: Cand.cxx:23
void hits()
Definition: readHits.C:15
fvar< T > exp(const fvar< T > &x)
Definition: exp.hpp:10
const double j
Definition: BetheBloch.cxx:29
static float min(const float a, const float b, const float c)
Definition: absgeo.cxx:45
TDSlicerDetectorParams fDetectorParams
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 189 of file Consumer.h.

References art::InputTag::instance(), PandAna.reco_validation.prod5_pid_validation::invalid, art::InputTag::label(), art::InputTag::process(), and T.

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

Definition at line 204 of file Consumer.h.

References T.

205 {
206  if (!moduleContext_)
207  return;
208 
209  consumables_[BT].emplace_back(ConsumableType::Many, TypeID{typeid(T)});
210 }
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
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 214 of file Consumer.h.

References art::InputTag::instance(), PandAna.reco_validation.prod5_pid_validation::invalid, art::InputTag::label(), art::InputTag::process(), and T.

215 {
216  if (!moduleContext_)
217  return ViewToken<T>::invalid();
218 
219  consumables_[BT].emplace_back(ConsumableType::ViewElement,
220  TypeID{typeid(T)},
221  it.label(),
222  it.instance(),
223  it.process());
224  return ViewToken<T>{it};
225 }
set< int >::iterator it
static ViewToken< Element > invalid()
Definition: ProductToken.h:75
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
bool art::ProducerBase::modifiesEvent ( ) const
inlineinherited

Definition at line 40 of file ProducerBase.h.

References art::ProducerBase::getProductID(), and string.

41  {
42  return true;
43  }
static cet::exempt_ptr<Consumer> art::Consumer::non_module_context ( )
staticinherited
void art::Consumer::prepareForJob ( fhicl::ParameterSet const &  pset)
protectedinherited
std::vector< double > tdslicer::TDSlicer::Prims ( const std::vector< art::Ptr< rb::CellHit > > &  hits)

Definition at line 404 of file TDSlicer_module.cc.

References ana::assert(), FillDists(), GetPoint(), hits(), MECModelEnuComparisons::i, calib::j, std::max(), and submit_syst::x.

Referenced by DBSCAN().

405  {
406  int N = hits.size();
407  std::vector<double> mindist(N,1e6);
408  if (N==0) return mindist;
409  std::vector<bool> isUsed (N,false);
410 
411  std::vector< std::vector<double> > distmatrix(N, std::vector<double>(N));
412  FillDists(distmatrix,hits);
413 
414 
415  // Include the first point
416  mindist[0] = 0;
417 
418  for (int i = 0; i < N; i++){
419  int x = GetPoint(mindist,isUsed); // Get closest point
420  assert(x!=-1);//Do better than this
421  isUsed[x] = true;
422 
423  for (int j = 0; j < N; j++){
424  if (!isUsed[j] && distmatrix[x][j] < mindist[j])
425  mindist[j] = std::max(distmatrix[x][j],mindist[x]);
426  }
427  }
428  return mindist;
429  }
T max(const caf::Proxy< T > &a, T b)
void FillDists(std::vector< std::vector< double > > &dists, const std::vector< art::Ptr< rb::CellHit > > &hits)
int GetPoint(const std::vector< double > &dist, const std::vector< bool > &isUsed)
void hits()
Definition: readHits.C:15
const double j
Definition: BetheBloch.cxx:29
assert(nhit_max >=nhit_nbins)
void tdslicer::TDSlicer::produce ( art::Event evt)
virtual

Implements art::EDProducer.

Definition at line 478 of file TDSlicer_module.cc.

References rb::Cluster::Add(), plot_validation_datamc::c, tdslicer::TDSlicerParams::cellInput, close(), CombineViews(), lem_server::cs, DBSCAN(), DEFINE_ART_MODULE(), dist, fDetectorParams, fParams, art::DataViewImpl::getByLabel(), GetCentroids(), GetDist(), GetPtInfo(), MECModelEnuComparisons::i, compare_h5_caf::idx, makeTrainCVSamples::int, calib::j, geo::kX, tdslicer::TDSlicerDetectorParams::maxEventHits, nd_projection_maker::ps, art::Event::put(), rb::Cluster::SetNoise(), gen_flatrecord::size, rb::SortByTime(), and tdslicer::TDSlicerDetectorParams::timeThreshold.

479  {
480  // NOTE: There is currently no requirement that a slice have hits in
481  // both views.
482 
484 
485  // Get the cell hits
487  evt.getByLabel(fParams.cellInput(), hitcol);
488 
489  // Load the cell hits into a vector for easy use
490  std::vector<art::Ptr<rb::CellHit > > hitlist;
491  hitlist.reserve(hitcol->size());
492  for(unsigned int i = 0; i < hitcol->size(); ++i){
493  art::Ptr<rb::CellHit> hit(hitcol, i);
494  hitlist.push_back(hit);
495  }
496 
497  // Safety in case of a very large number of hits in the event, which can
498  // take a long time to slice, and the results probably won't be useful for
499  // downstream modules anyway.
500  if(fDetectorParams.maxEventHits() > 0 &&
501  int(hitlist.size()) > fDetectorParams.maxEventHits()){
502  mf::LogWarning("TDSlicer") << "Very large number of hits ("
503  << hitlist.size()
504  << ") in event. Higher than configured limit ("
506  << "). Will put all hits in the noise slice.";
507  rb::Cluster noise;
508  for(art::Ptr<rb::CellHit> c: hitlist) noise.Add(c);
509  noise.SetNoise(true);
510  evt.put(std::make_unique<std::vector<rb::Cluster>>(1, noise));
511  return;
512  }
513 
514  rb::SortByTime(hitlist);
515 
516  std::vector<PtInfo> info = GetPtInfo(hitlist);
517  std::vector<int> centroids = GetCentroids(info);
518  std::sort(centroids.begin(), centroids.end());
519 
520  std::unique_ptr< std::vector<rb::Cluster> >
521  clustercol(new std::vector<rb::Cluster>);
522 
523 
524  std::vector<double> ts(hitlist.size());
525  std::vector<int> ps(hitlist.size());
526  std::vector<int> cs(hitlist.size());
527 
528  for(unsigned int i = 0; i < hitlist.size(); ++i){
529  ts[i] = hitlist[i]->TNS();
530  ps[i] = hitlist[i]->Plane();
531  cs[i] = hitlist[i]->Cell();
532  }
533 
534  //
535  // Construct the actual slices to be put into the event.
536  //
537  std::vector< std::vector< art::Ptr<rb::CellHit> > >
538  protoclustsX(centroids.size()+1);
539  std::vector< std::vector< art::Ptr<rb::CellHit> > >
540  protoclustsY(centroids.size()+1);
541  // int loweridx = 0; // lowest index recently assigned
542  for(unsigned int i = 0; i < hitlist.size(); ++i){
543  int idx = 0;
545  int nmatch = 0;
546  for (int j = 0; j < int(centroids.size()); j++){
547  // for (int j = loweridx-1; j <= loweridx+2; j++){
548  if (j < 0 || j >= int(centroids.size())) continue;
549  double dt = ts[centroids[j]] - ts[i];
550  double dp = ps[centroids[j]] - ps[i];
551  double dc = cs[centroids[j]] - cs[i];
552  double dist = GetDist(dt,dp,dc);
553  if (dist < close){
554  nmatch++;
555  close = dist;
556  idx = j+1;
557  }
558  }
559  hitlist[i]->View() == geo::kX ? protoclustsX[idx].push_back(hitlist[i])
560  : protoclustsY[idx].push_back(hitlist[i]);
561  }
562 
563  std::vector<rb::Cluster> clusters(1);
564  for (int i = 0; i < (int)protoclustsX[0].size(); i++)
565  clusters[0].Add(protoclustsX[0][i]);
566  for (int i = 0; i < (int)protoclustsY[0].size(); i++)
567  clusters[0].Add(protoclustsY[0][i]);
568 
569  for (int i = 1; i < (int)protoclustsX.size(); i++){
570  std::vector<rb::Cluster> curclustsX = DBSCAN(protoclustsX[i]);
571  std::vector<rb::Cluster> curclustsY = DBSCAN(protoclustsY[i]);
572  // We're not merging views here, just add x / y slices to same vector
573  std::vector<rb::Cluster> curclusts =
574  CombineViews(&clusters[0], &curclustsX, &curclustsY);
575  for (int j = 0; j < (int)curclusts.size(); j++){
576  clusters.push_back(curclusts[j]);
577  }
578  }
579 
580  // Tag the noise cluster as such.
581  clusters[0].SetNoise(true);
582 
583  // Always put in the noise cluster even if it is empty.
584  for (int i = 0; i < (int)clusters.size(); i++){
585  // if (clusters[i].NXCell() < 3) continue;
586  // if (clusters[i].NYCell() < 3) continue;
587  clustercol->push_back(clusters[i]);
588  }
589 
590  //
591  // Before saving the clusters, put the hits inside them into a
592  // standard order
593  //
594  for (unsigned int i=0; i<clustercol->size(); ++i) {
595  (*clustercol)[i].StandardSort();
596  }
597 
598  // put the slices into the event
599  evt.put(std::move(clustercol));
600 
601  } // end Produce function
float TNS() const
Definition: CellHit.h:46
const XML_Char XML_Encoding * info
Definition: expat.h:530
void SetNoise(bool noise)
Declare the cluster to consist of noise hits or not.
Definition: Cluster.h:161
unsigned short Plane() const
Definition: CellHit.h:39
double GetDist(double dt, double dp, double dc)
TDSlicerParams fParams
geo::View_t View() const
Definition: CellHit.h:41
std::vector< int > GetCentroids(const std::vector< PtInfo > &info)
Vertical planes which measure X.
Definition: PlaneGeo.h:28
A collection of associated CellHits.
Definition: Cluster.h:47
void SortByTime(std::vector< art::Ptr< rb::CellHit > > &c)
Sort c in time order (earliest to latest).
Definition: CellHit.cxx:134
std::vector< PtInfo > GetPtInfo(const std::vector< art::Ptr< rb::CellHit > > &hits)
virtual void Add(const art::Ptr< rb::CellHit > &cell, double weight=1)
Definition: Cluster.cxx:84
double dist
Definition: runWimpSim.h:113
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
unsigned short Cell() const
Definition: CellHit.h:40
Definition: Cand.cxx:23
Atom< std::string > cellInput
const double j
Definition: BetheBloch.cxx:29
std::vector< rb::Cluster > DBSCAN(std::vector< art::Ptr< rb::CellHit > > hits)
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
Definition: structs.h:12
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
TDSlicerDetectorParams fDetectorParams
std::vector< rb::Cluster > CombineViews(rb::Cluster *cNoise, std::vector< rb::Cluster > *cX, std::vector< rb::Cluster > *cY)
procfile close()
void art::Consumer::showMissingConsumes ( ) const
protectedinherited

Referenced by art::RootOutput::endJob().

void tdslicer::TDSlicer::SortStuff ( std::vector< double > &  mindist,
std::vector< art::Ptr< rb::CellHit > > &  hits 
)

Definition at line 431 of file TDSlicer_module.cc.

References h2, hits(), and MECModelEnuComparisons::i.

Referenced by DBSCAN().

431  {
432  std::vector<std::pair<double, art::Ptr<rb::CellHit>>> h2;
433  h2.reserve(hits.size());
434  for(unsigned int i = 0; i < hits.size(); ++i)
435  h2.emplace_back(mindist[i], hits[i]);
436  std::sort(h2.begin(), h2.end());
437  for(unsigned int i = 0; i < hits.size(); ++i){
438  mindist[i] = h2[i].first;
439  hits[i] = h2[i].second;
440  }
441  }
void hits()
Definition: readHits.C:15
TH1F * h2
Definition: plot.C:45
void tdslicer::TDSlicer::TrimNoise ( rb::Cluster cNoise,
std::vector< rb::Cluster > *  c2D 
)

Definition at line 326 of file TDSlicer_module.cc.

References rb::Cluster::Add(), hadd_many_files::counter, fDetectorParams, MECModelEnuComparisons::i, makeTrainCVSamples::int, calib::j, and tdslicer::TDSlicerDetectorParams::minCell.

Referenced by CombineViews().

328  {
329  double counter = 0;
330  for (int i = c2D->size()-1; i >= 0; i--){
331  if (c2D->at(i).NXCell() < fDetectorParams.minCell() &&
332  c2D->at(i).NYCell() < fDetectorParams.minCell()){
333  for (int j = 0; j < (int)c2D->at(i).NCell(); j++){
334  cNoise->Add(c2D->at(i).Cell(j));
335  }
336  c2D->erase(c2D->begin()+i);
337  }
338  counter++;
339  }
340  }
virtual void Add(const art::Ptr< rb::CellHit > &cell, double weight=1)
Definition: Cluster.cxx:84
const double j
Definition: BetheBloch.cxx:29
TDSlicerDetectorParams fDetectorParams
void art::Consumer::validateConsumedProduct ( BranchType const  bt,
ProductInfo const &  pi 
)
protectedinherited

Member Data Documentation

TDSlicerDetectorParams tdslicer::TDSlicer::fDetectorParams
protected
TDSlicerParams tdslicer::TDSlicer::fParams
protected

Definition at line 178 of file TDSlicer_module.cc.

Referenced by beginRun(), GetDist(), and produce().


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