14 #include "messagefacility/MessageLogger/MessageLogger.h"
15 #include "fhiclcpp/ParameterSet.h"
16 #include "canvas/Persistency/Common/Ptr.h"
17 #include "art/Framework/Core/EDAnalyzer.h"
18 #include "art/Framework/Core/ModuleMacros.h"
19 #include "canvas/Persistency/Common/FindManyP.h"
20 #include "art/Framework/Principal/Event.h"
21 #include "art/Framework/Principal/Handle.h"
22 #include "art/Framework/Services/Registry/ServiceHandle.h"
23 #include "art_root_io/TFileService.h"
31 #include "TPrincipal.h"
42 explicit ClusterPCA(fhicl::ParameterSet
const& pset);
47 void PerformClusterPCA(
const std::vector<art::Ptr<recob::Hit> >& HitsThisCluster,
double* PrincDirectionWT,
double& PrincValue,
double& TotalCharge,
bool NormPC);
77 , fClusterModuleLabel(pset.
get<
std::string>(
"ClusterModuleLabel"))
78 , fNormPC (pset.
get<
bool>(
"NormPC"))
91 art::ServiceHandle<art::TFileService const>
tfs;
92 fTree = tfs->make<TTree>(
"PCATree",
"PCATree");
105 art::Handle< std::vector<recob::Cluster> > clusterVecHandle;
108 constexpr
size_t nViews = 3;
112 std::array<std::vector<size_t>, nViews> ClsIndex;
115 for(
size_t i = 0; i < clusterVecHandle->size(); ++i){
118 art::Ptr<recob::Cluster> cl(clusterVecHandle, i);
131 mf::LogError(
"ClusterPCA")
132 <<
"Hit belongs to an unsupported view (#" << cl->View() <<
")";
136 ClsIndex[
fView].push_back(i);
142 const std::vector<size_t>& ClsIndices = ClsIndex[
fView];
144 for(
size_t c = 0; c < ClsIndices.size(); ++c){
147 const std::vector<art::Ptr<recob::Hit>>& ptrvs = fm.at(ClsIndices[c]);
149 double PrincDir[2], PrincValue=0;
150 double TotalCharge=0;
191 double Center[2] = {0,0};
194 for(
auto itHit = HitsThisCluster.begin(); itHit!=HitsThisCluster.end(); ++itHit)
196 Center[0] += (*itHit)->WireID().Wire;
197 Center[1] += (*itHit)->PeakTime();
198 TotalCharge += (*itHit)->Integral();
201 Center[0] /= float(HitsThisCluster.size());
202 Center[1] /= float(HitsThisCluster.size());
207 std::string OptionString;
214 TPrincipal pc(2, OptionString.c_str());
217 for(
auto itHit = HitsThisCluster.begin(); itHit!=HitsThisCluster.end(); ++itHit)
219 WireTime[0] = (*itHit)->WireID().Wire - Center[0];
220 WireTime[1] = (*itHit)->PeakTime() - Center[1];
228 PrincipalEigenvalue = (*pc.GetEigenValues())[0];
230 for(
size_t n=0;
n!=2; ++
n)
232 PrincipalDirection[
n]= (*pc.GetEigenVectors())[0][
n];
248 DEFINE_ART_MODULE(ClusterPCA)
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
Declaration of signal hit object.
Planes which measure Z direction.
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
void analyze(art::Event const &evt)
std::string fClusterModuleLabel
Declaration of cluster object.
Definition of data types for geometry description.
void PerformClusterPCA(const std::vector< art::Ptr< recob::Hit > > &HitsThisCluster, double *PrincDirectionWT, double &PrincValue, double &TotalCharge, bool NormPC)
ClusterPCA(fhicl::ParameterSet const &pset)
art::ServiceHandle< art::TFileService > tfs