All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Member Functions | Private Attributes | List of all members
cluster::ClusterPCA Class Reference
Inheritance diagram for cluster::ClusterPCA:

Public Member Functions

 ClusterPCA (fhicl::ParameterSet const &pset)
 
 ~ClusterPCA ()
 

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
 

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 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)
private

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
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)
TCEvent evt
Definition: DataStructs.cxx:8
void cluster::ClusterPCA::beginJob ( )
private

Definition at line 89 of file ClusterPCA_module.cc.

90  {
91  art::ServiceHandle<art::TFileService const> tfs;
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  }
art::ServiceHandle< art::TFileService > tfs
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 }

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: