Public Member Functions | Private Member Functions | Private Attributes | List of all members
cluster::ClusterPCA Class Reference
Inheritance diagram for cluster::ClusterPCA:
art::EDAnalyzer art::detail::Analyzer art::detail::LegacyModule art::Observer art::ModuleBase

Public Member Functions

 ClusterPCA (fhicl::ParameterSet const &pset)
 
 ~ClusterPCA ()
 
- Public Member Functions inherited from art::EDAnalyzer
 EDAnalyzer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 EDAnalyzer (Table< Config > const &config)
 
std::string workerType () const
 
- Public Member Functions inherited from art::detail::Analyzer
virtual ~Analyzer () noexcept
 
 Analyzer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 Analyzer (Table< Config > const &config)
 
void doBeginJob (SharedResources const &resources)
 
void doEndJob ()
 
void doRespondToOpenInputFile (FileBlock const &fb)
 
void doRespondToCloseInputFile (FileBlock const &fb)
 
void doRespondToOpenOutputFiles (FileBlock const &fb)
 
void doRespondToCloseOutputFiles (FileBlock const &fb)
 
bool doBeginRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doEndRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doBeginSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEndSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEvent (EventPrincipal &ep, ModuleContext const &mc, std::atomic< std::size_t > &counts_run, std::atomic< std::size_t > &counts_passed, std::atomic< std::size_t > &counts_failed)
 
- Public Member Functions inherited from art::Observer
 ~Observer () noexcept
 
 Observer (Observer const &)=delete
 
 Observer (Observer &&)=delete
 
Observeroperator= (Observer const &)=delete
 
Observeroperator= (Observer &&)=delete
 
void registerProducts (ProductDescriptions &, ModuleDescription const &)
 
void fillDescriptions (ModuleDescription const &)
 
fhicl::ParameterSetID selectorConfig () const
 
- Public Member Functions inherited from art::ModuleBase
virtual ~ModuleBase () noexcept
 
 ModuleBase ()
 
ModuleDescription const & moduleDescription () const
 
void setModuleDescription (ModuleDescription const &)
 
std::array< std::vector< ProductInfo >, NumBranchTypes > const & getConsumables () const
 
void sortConsumables (std::string const &current_process_name)
 
template<typename T , BranchType BT>
ViewToken< T > consumesView (InputTag const &tag)
 
template<typename T , BranchType BT>
ViewToken< T > mayConsumeView (InputTag const &tag)
 

Private Member Functions

void PerformClusterPCA (const std::vector< art::Ptr< recob::Hit > > &HitsThisCluster, double *PrincDirectionWT, double &PrincValue, double &TotalCharge, bool NormPC)
 
void analyze (art::Event const &evt)
 
void beginJob ()
 

Private Attributes

std::string fClusterModuleLabel
 
bool fNormPC
 
TTree * fTree
 
Int_t fView
 
Float_t fPrincDirW
 
Float_t fPrincDirT
 
Float_t fPrincValue
 
Float_t fTotalCharge
 
Float_t fNHits
 

Additional Inherited Members

- Public Types inherited from art::EDAnalyzer
using WorkerType = WorkerT< EDAnalyzer >
 
using ModuleType = EDAnalyzer
 
- Protected Member Functions inherited from art::Observer
std::string const & processName () const
 
bool wantAllEvents () const noexcept
 
bool wantEvent (ScheduleID id, Event const &e) const
 
Handle< TriggerResultsgetTriggerResults (Event const &e) const
 
 Observer (fhicl::ParameterSet const &config)
 
 Observer (std::vector< std::string > const &select_paths, std::vector< std::string > const &reject_paths, fhicl::ParameterSet const &config)
 
- Protected Member Functions inherited from art::ModuleBase
ConsumesCollectorconsumesCollector ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > consumes (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > mayConsume (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 

Detailed Description

Definition at line 38 of file ClusterPCA_module.cc.

Constructor & Destructor Documentation

cluster::ClusterPCA::ClusterPCA ( fhicl::ParameterSet const &  pset)
explicit

Definition at line 75 of file ClusterPCA_module.cc.

76  : EDAnalyzer(pset)
77  , fClusterModuleLabel(pset.get<std::string>("ClusterModuleLabel"))
78  , fNormPC (pset.get<bool>("NormPC"))
79  {
80  }
std::string string
Definition: nybbler.cc:12
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
std::string fClusterModuleLabel
cluster::ClusterPCA::~ClusterPCA ( )

Definition at line 83 of file ClusterPCA_module.cc.

84  {
85  }

Member Function Documentation

void cluster::ClusterPCA::analyze ( art::Event const &  evt)
privatevirtual

Implements art::EDAnalyzer.

Definition at line 102 of file ClusterPCA_module.cc.

103  {
104  // Get a Handle for the input Cluster object(s).
105  art::Handle< std::vector<recob::Cluster> > clusterVecHandle;
106  evt.getByLabel(fClusterModuleLabel,clusterVecHandle);
107 
108  constexpr size_t nViews = 3;
109 
110  // one vector of cluster index in the original collection, per view;
111  // to support all present views, replace with a dynamically growing array
112  std::array<std::vector<size_t>, nViews> ClsIndex;
113 
114  // loop over the input Clusters
115  for(size_t i = 0; i < clusterVecHandle->size(); ++i){
116 
117  //get a art::Ptr to each Cluster
118  art::Ptr<recob::Cluster> cl(clusterVecHandle, i);
119 
120  switch(cl->View()){
121  case geo::kU :
122  fView=0;
123  break;
124  case geo::kV :
125  fView=1;
126  break;
127  case geo::kZ :
128  fView=2;
129  break;
130  default :
131  mf::LogError("ClusterPCA")
132  << "Hit belongs to an unsupported view (#" << cl->View() << ")";
133  break;
134  }// end switch on view
135 
136  ClsIndex[fView].push_back(i);
137  }// end loop over input clusters
138 
139  art::FindManyP<recob::Hit> fm(clusterVecHandle, evt, fClusterModuleLabel);
140  for(fView = 0; fView < (int) nViews; ++fView){
141 
142  const std::vector<size_t>& ClsIndices = ClsIndex[fView];
143 
144  for(size_t c = 0; c < ClsIndices.size(); ++c){
145 
146  // find the hits associated with the current cluster
147  const std::vector<art::Ptr<recob::Hit>>& ptrvs = fm.at(ClsIndices[c]);
148 
149  double PrincDir[2], PrincValue=0;
150  double TotalCharge=0;
151 
152  PerformClusterPCA( ptrvs, PrincDir, PrincValue, TotalCharge, fNormPC);
153 
154  fPrincDirW = PrincDir[0];
155  fPrincDirT = PrincDir[1];
156  fPrincValue = PrincValue;
157  fTotalCharge = TotalCharge;
158  fNHits = ptrvs.size();
159 
160  fTree->Fill();
161 
162  }// end loop over first cluster iterator
163  }// end loop over planes
164 
165  return;
166 
167  } // ClusterPCA::analyze()
Planes which measure V.
Definition: geo_types.h:130
Planes which measure Z direction.
Definition: geo_types.h:132
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
QAsciiDict< Entry > cl
Planes which measure U.
Definition: geo_types.h:129
std::string fClusterModuleLabel
void PerformClusterPCA(const std::vector< art::Ptr< recob::Hit > > &HitsThisCluster, double *PrincDirectionWT, double &PrincValue, double &TotalCharge, bool NormPC)
static constexpr double fm
Definition: Units.h:75
TCEvent evt
Definition: DataStructs.cxx:7
void cluster::ClusterPCA::beginJob ( )
privatevirtual

Reimplemented from art::EDAnalyzer.

Definition at line 89 of file ClusterPCA_module.cc.

90  {
92  fTree = tfs->make<TTree>("PCATree","PCATree");
93  fTree->Branch("View", &fView, "View/I");
94  fTree->Branch("PrincDirW", &fPrincDirW, "PrincDirW/F");
95  fTree->Branch("PrincDirT", &fPrincDirT, "PrincDirT/F");
96  fTree->Branch("PrincValue",&fPrincValue, "PrincValue/F");
97  fTree->Branch("TotalCharge",&fTotalCharge, "TotalCharge/F");
98  fTree->Branch("NHits", &fNHits, "fNHits/F");
99  }
void cluster::ClusterPCA::PerformClusterPCA ( const std::vector< art::Ptr< recob::Hit > > &  HitsThisCluster,
double *  PrincDirectionWT,
double &  PrincValue,
double &  TotalCharge,
bool  NormPC 
)
private

Definition at line 188 of file ClusterPCA_module.cc.

189  {
190 
191  double Center[2] = {0,0};
192  TotalCharge = 0;
193 
194  for(auto itHit = HitsThisCluster.begin(); itHit!=HitsThisCluster.end(); ++itHit)
195  {
196  Center[0] += (*itHit)->WireID().Wire;
197  Center[1] += (*itHit)->PeakTime();
198  TotalCharge += (*itHit)->Integral();
199  }
200 
201  Center[0] /= float(HitsThisCluster.size());
202  Center[1] /= float(HitsThisCluster.size());
203 
204 
205  double WireTime[2];
206 
207  std::string OptionString;
208 
209  if(NormPC==false)
210  OptionString = "D";
211  else
212  OptionString = "ND";
213 
214  TPrincipal pc(2, OptionString.c_str());
215 
216 
217  for(auto itHit = HitsThisCluster.begin(); itHit!=HitsThisCluster.end(); ++itHit)
218  {
219  WireTime[0] = (*itHit)->WireID().Wire - Center[0];
220  WireTime[1] = (*itHit)->PeakTime() - Center[1];
221 
222  pc.AddRow(WireTime);
223 
224  }
225 
226  pc.MakePrincipals();
227 
228  PrincipalEigenvalue = (*pc.GetEigenValues())[0];
229 
230  for(size_t n=0; n!=2; ++n)
231  {
232  PrincipalDirection[n]= (*pc.GetEigenVectors())[0][n];
233  }
234 
235 
236  // Comment this out if you want to shut it up
237  pc.Print("MSEV");
238 
239  pc.Clear();
240  return;
241 }
std::string string
Definition: nybbler.cc:12
std::void_t< T > n

Member Data Documentation

std::string cluster::ClusterPCA::fClusterModuleLabel
private

Definition at line 52 of file ClusterPCA_module.cc.

Float_t cluster::ClusterPCA::fNHits
private

Definition at line 62 of file ClusterPCA_module.cc.

bool cluster::ClusterPCA::fNormPC
private

Definition at line 53 of file ClusterPCA_module.cc.

Float_t cluster::ClusterPCA::fPrincDirT
private

Definition at line 59 of file ClusterPCA_module.cc.

Float_t cluster::ClusterPCA::fPrincDirW
private

Definition at line 58 of file ClusterPCA_module.cc.

Float_t cluster::ClusterPCA::fPrincValue
private

Definition at line 60 of file ClusterPCA_module.cc.

Float_t cluster::ClusterPCA::fTotalCharge
private

Definition at line 61 of file ClusterPCA_module.cc.

TTree* cluster::ClusterPCA::fTree
private

Definition at line 55 of file ClusterPCA_module.cc.

Int_t cluster::ClusterPCA::fView
private

Definition at line 57 of file ClusterPCA_module.cc.


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