ATTPCROOT  0.3.0-alpha
A ROOT-based framework for analyzing data from active target detectors
AtRansacTask.cxx
Go to the documentation of this file.
1 #include "AtRansacTask.h"
2 
3 #include "AtEstimatorMethods.h"
4 #include "AtEvent.h" // for AtEvent
5 #include "AtPatternEvent.h"
6 #include "AtPatternTypes.h"
7 #include "AtSampleConsensus.h"
8 #include "AtSampleMethods.h"
9 
10 #include <FairLogger.h> // for LOG, Logger
11 #include <FairRootManager.h> // for FairRootManager
12 
13 #include <TClonesArray.h> // for TClonesArray
14 #include <TObject.h> // for TObject
15 
16 #include <memory> // for allocator
17 
19 
21  : fInputBranchName("AtEventH"), fOutputBranchName("AtPatternEvent"), kIsPersistence(kFALSE), kIsReprocess(kFALSE),
22  fPatternEventArray("AtPatternEvent", 1)
23 {
24 }
25 
26 AtRansacTask::~AtRansacTask() = default;
27 
28 void AtRansacTask::SetPersistence(Bool_t value)
29 {
30  kIsPersistence = value;
31 }
32 void AtRansacTask::SetInputBranch(TString branchName)
33 {
34  fInputBranchName = branchName;
35 }
36 
37 void AtRansacTask::SetOutputBranch(TString branchName)
38 {
39  fOutputBranchName = branchName;
40 }
41 
43 {
44  fRANSACModel = model;
45 }
46 void AtRansacTask::SetDistanceThreshold(Float_t threshold)
47 {
48  fRANSACThreshold = threshold;
49 }
51 {
52  fMinHitsLine = nhits;
53 }
54 void AtRansacTask::SetNumItera(Int_t niterations)
55 {
56  fNumItera = niterations;
57 }
59 {
60  fRANSACAlg = val;
61 }
63 {
64  fRandSamplMode = mode;
65 };
66 void AtRansacTask::SetIsReprocess(Bool_t value)
67 {
68  kIsReprocess = value;
69 }
70 void AtRansacTask::SetInputBranchName(TString inputName)
71 {
72  fInputBranchName = inputName;
73 }
74 void AtRansacTask::SetOutputBranchName(TString outputName)
75 {
76  fOutputBranchName = outputName;
77 }
78 
79 InitStatus AtRansacTask::Init()
80 {
81 
82  FairRootManager *ioMan = FairRootManager::Instance();
83  if (ioMan == nullptr) {
84  LOG(error) << "Cannot find RootManager!";
85  return kERROR;
86  }
87 
88  fEventArray = dynamic_cast<TClonesArray *>(ioMan->GetObject(fInputBranchName));
89  if (fEventArray == nullptr) {
90 
91  LOG(error) << "Cannot find AtEvent array!";
92  return kERROR;
93  }
94 
95  ioMan->Register(fOutputBranchName, "AtTPC", &fPatternEventArray, kIsPersistence);
96 
97  if (kIsReprocess) {
98 
99  ioMan->Register("AtEventH", "AtTPC", fEventArray, kIsPersistence);
100  }
101 
102  return kSUCCESS;
103 }
104 
105 void AtRansacTask::Exec(Option_t *opt)
106 {
107 
108  if (fEventArray->GetEntriesFast() == 0)
109  return;
110 
111  fEvent = dynamic_cast<AtEvent *>(fEventArray->At(0));
112 
113  LOG(debug) << "Running RANSAC with " << fEvent->GetNumHits() << " hits.";
114  LOG(debug) << "Running Unified RANSAC";
115 
116  auto sampleMethod = static_cast<RandomSample::SampleMethod>(fRandSamplMode);
117  auto patternType = AtPatterns::PatternType::kLine;
118  auto estimator = SampleConsensus::Estimators::kChi2;
119  if (fRANSACAlg == 2)
121  if (fRANSACAlg == 3)
123  if (fRANSACAlg == 4)
125  SampleConsensus::AtSampleConsensus ransac(estimator, patternType, sampleMethod);
126 
127  ransac.SetDistanceThreshold(fRANSACThreshold);
128  ransac.SetMinHitsPattern(fMinHitsLine);
129  ransac.SetNumIterations(fNumItera);
130  ransac.SetChargeThreshold(fChargeThres);
131  fPatternEventArray.Delete();
132  auto patternEvent = ransac.Solve(fEvent);
133  new (fPatternEventArray[0]) AtPatternEvent(patternEvent);
134 }
SampleConsensus::AtSampleConsensus::SetDistanceThreshold
void SetDistanceThreshold(Float_t threshold)
Definition: AtSampleConsensus.h:87
AtEvent::GetNumHits
Int_t GetNumHits() const
Definition: AtEvent.h:108
AtPatternEvent
Definition: AtPatternEvent.h:19
SampleConsensus::AtSampleConsensus::Solve
AtPatternEvent Solve(AtEvent *event)
See Solve(const std::vector<const AtHit *> &hitArray)
Definition: AtSampleConsensus.cxx:60
AtEvent.h
RandomSample::SampleMethod
SampleMethod
. Methods of random sampling.
Definition: AtSampleMethods.h:22
SampleConsensus::AtSampleConsensus
Perform a sample consensus on a cloud of AtHits.
Definition: AtSampleConsensus.h:46
AtRansacTask::SetDistanceThreshold
void SetDistanceThreshold(Float_t threshold)
Definition: AtRansacTask.cxx:46
AtRansacTask::SetInputBranch
void SetInputBranch(TString branchName)
Definition: AtRansacTask.cxx:32
SampleConsensus::AtSampleConsensus::SetNumIterations
void SetNumIterations(Int_t niterations)
Definition: AtSampleConsensus.h:85
AtRansacTask::Exec
virtual void Exec(Option_t *opt) override
Definition: AtRansacTask.cxx:105
AtRansacTask::SetInputBranchName
void SetInputBranchName(TString inputName)
Definition: AtRansacTask.cxx:70
AtRansacTask::AtRansacTask
AtRansacTask()
Definition: AtRansacTask.cxx:20
AtEvent
Definition: AtEvent.h:22
AtRansacTask::SetIsReprocess
void SetIsReprocess(Bool_t value=kFALSE)
Definition: AtRansacTask.cxx:66
SampleConsensus::Estimators::kChi2
@ kChi2
AtEstimatorMethods.h
AtRansacTask::SetPersistence
void SetPersistence(Bool_t value=kTRUE)
Definition: AtRansacTask.cxx:28
AtSampleConsensus.h
AtRansacTask::~AtRansacTask
~AtRansacTask()
SampleConsensus::Estimators::kLMedS
@ kLMedS
AtSampleMethods.h
AtPatternEvent.h
AtRansacTask.h
SampleConsensus::AtSampleConsensus::SetChargeThreshold
void SetChargeThreshold(double value)
Definition: AtSampleConsensus.h:88
AtRansacTask::SetMinHitsLine
void SetMinHitsLine(Int_t nhits)
Definition: AtRansacTask.cxx:50
AtRansacTask::Init
virtual InitStatus Init() override
Definition: AtRansacTask.cxx:79
SampleConsensus::Estimators::kMLESAC
@ kMLESAC
AtPatternTypes.h
AtRansacTask::SetNumItera
void SetNumItera(Int_t niterations)
Definition: AtRansacTask.cxx:54
AtPatterns::PatternType::kLine
@ kLine
AtRansacTask::SetModelType
void SetModelType(int model)
Definition: AtRansacTask.cxx:42
AtRansacTask::SetOutputBranch
void SetOutputBranch(TString branchName)
Definition: AtRansacTask.cxx:37
SampleConsensus::AtSampleConsensus::SetMinHitsPattern
void SetMinHitsPattern(Int_t nhits)
Definition: AtSampleConsensus.h:86
SampleConsensus::Estimators::kWRANSAC
@ kWRANSAC
AtRansacTask::SetOutputBranchName
void SetOutputBranchName(TString outputName)
Definition: AtRansacTask.cxx:74
ClassImp
ClassImp(AtRansacTask)
AtRansacTask::SetAlgorithm
void SetAlgorithm(Int_t val)
Definition: AtRansacTask.cxx:58
AtRansacTask
Definition: AtRansacTask.h:16
AtRansacTask::SetRanSamMode
void SetRanSamMode(Int_t mode)
Definition: AtRansacTask.cxx:62