ATTPCROOT  0.3.0-alpha
A ROOT-based framework for analyzing data from active target detectors
AtY.cxx
Go to the documentation of this file.
1 #include "AtY.h"
2 
3 #include "AtHit.h"
4 #include "AtSample.h" // for RandomSample
5 
6 #include <FairLogger.h> // for Logger, LOG
7 
8 #include <algorithm> // for max
9 #include <memory> // for allocator_traits<>::value_type
10 
11 using namespace RandomSample;
12 
13 std::vector<AtHit> AtY::SampleHits(int N)
14 {
15  std::vector<AtHit> ret;
16  LOG(debug) << "Vetoing " << fBeam.size() << " from beam region";
17 
18  // If every hit is outside of the beam region, then skip the vetoed beam region
19  if (fBeam.size() + N - 2 > fHits->size() || fNotBeam.size() + 2 > fHits->size()) {
20  LOG(debug) << "Defaulting to normal sampling (fBeam is size: " << fBeam.size() << ")";
21  for (auto ind : sampleIndicesFromCDF(N))
22  ret.push_back(*fHits->at(ind));
23  return ret;
24  }
25 
26  double maxZ = std::max(ret[0].GetPosition().Z(), ret[1].GetPosition().Z());
27 
28  // Try to sample 10 times respecting all of the conditions.
29  // If they're not met just return the final attempt
30  for (int iter = 0; iter < 10; iter++) {
31  ret.clear();
32 
33  // Sample the beam region
34  for (auto ind : sampleIndicesFromCDF(2, fNotBeam))
35  ret.push_back(*fHits->at(ind));
36 
37  // try 10 times to find fragment hits that are closer to the pad plane
38  for (int iterFF = 0; iterFF < 10; ++iterFF) {
39  auto indices = sampleIndicesFromCDF(N - 2, fBeam);
40  bool isGood = true;
41  for (auto ind : indices)
42  isGood |= fHits->at(ind)->GetPosition().Z() > maxZ;
43 
44  if (isGood) {
45  for (auto ind : indices)
46  ret.push_back(*fHits->at(ind));
47  return ret;
48  }
49  }
50  }
51 
52  // Failed to find hits that meat our contition but we should have beam sampled already
53  // so just sample the non-beam region.
54  for (auto ind : sampleIndicesFromCDF(N - 2, fBeam))
55  ret.push_back(*fHits->at(ind));
56 
57  return ret;
58 }
59 
60 void AtY::SetHitsToSample(const std::vector<const AtHit *> &hits)
61 {
62  fHits = &hits;
63  fBeam.clear();
64  fNotBeam.clear();
65  FillCDF();
66  for (int i = 0; i < fHits->size(); i++) {
67  if (fHits->at(i)->GetPosition().Rho() < fBeamRadius) {
68  fBeam.push_back(i);
69  } else {
70  fNotBeam.push_back(i);
71  }
72  }
73 }
RandomSample::AtY::SampleHits
virtual std::vector< AtHit > SampleHits(int N) override
Sample hits (AtHit) from fHits.
Definition: AtY.cxx:13
RandomSample
Definition: AtSampleConsensus.h:26
AtY.h
RandomSample::AtSample::sampleIndicesFromCDF
std::vector< int > sampleIndicesFromCDF(int N, std::vector< int > vetoed={})
Definition: AtSample.cxx:77
RandomSample::AtY::fBeam
std::vector< int > fBeam
Definition: AtY.h:22
RandomSample::AtY::fBeamRadius
double fBeamRadius
Definition: AtY.h:24
RandomSample::AtSample::fHits
const std::vector< const AtHit * > * fHits
Definition: AtSample.h:38
AtHit.h
RandomSample::AtY::fNotBeam
std::vector< int > fNotBeam
Definition: AtY.h:21
RandomSample::AtSample::FillCDF
void FillCDF()
Definition: AtSample.cxx:115
RandomSample::AtY::SetHitsToSample
virtual void SetHitsToSample(const std::vector< const AtHit * > &hits) override
Definition: AtY.cxx:60
AtSample.h