CFAlgoChargeDistrib.cxx
Go to the documentation of this file.
1 #include "CFAlgoChargeDistrib.h"
4 
5 namespace cmtool {
6 
7  //-------------------------------------------------------
9  //-------------------------------------------------------
10  {
11  SetVerbose(false);
12  SetDebug(false);
13  }
14 
15  //-----------------------------
17  //-----------------------------
18  {
19 
20  }
21 
22  //----------------------------------------------------------------------------------------------
23  float CFAlgoChargeDistrib::Float(const std::vector<const cluster::ClusterParamsAlg*> &clusters)
24  //----------------------------------------------------------------------------------------------
25  {
26 
27  // Code-block by Kazu starts
28  // This ensures the algorithm works only if # clusters is > 2 (and not =2)
29  // You may take out this block if you want to allow matching using clusters from only 2 planes.
30  //if(clusters.size()==2) return -1;
31  // Code-block by Kazu ends
32 
33  //This algorithm now works for 3 planes: find 3Dstart point from first 2 planes and find
34  //How well that agrees with 3rd plane's start point location.
35 
36  //So first, make sure clusters vector has more than 1 element.
37  //If not, return -1. Algorithm does not make sense
38  if ( clusters.size() == 1 )
39  return -1;
40 
41  if (_verbose) { std::cout << "Number of clusters taken into account: " << clusters.size() << std::endl; }
42 
43  //MicroBooNE Nomenclature:
44  //Planes: U == 0; V == 1; Y == 2.
45 
46  //Get hits for all 3 clusters
47  std::vector<std::vector<util::PxHit> > Hits;//(clusters.size(), std::vector<util::PxHit>());
48 
49  for (size_t c=0; c < clusters.size(); c++)
50  Hits.push_back( clusters.at(c)->GetHitVector() );
51 
52  // return parameter is the product of
53  // "convolutions" of each pair of clusters
54  // return conv(a,b)*conv(b,c)*conv(c,a)
55  // in the case of 3 planes with clusters
56  // a, b and c.
57  // The functions being convolved are the
58  // charge-distribution in time of each clusters
59  // The "convolution" is the common area of the
60  // two distributions: the larger the charge-
61  // -overlap the better the match
62  // No normalization is performed.
63 
64  float totOverlap = 1;
65  for (size_t c1=0; c1 < (Hits.size()-1); c1++){
66  for (size_t c2=c1+1; c2 < Hits.size(); c2++){
67  if (_verbose) { std::cout << "Considering Clusters: " << c1 << ", " << c2 << std::endl; }
68  totOverlap *= TProfConvol(Hits.at(c1), Hits.at(c2) );
69  }
70  }
71 
72  if (_verbose) { std::cout << "Tot Overlap is: " << totOverlap << std::endl << std::endl; }
73 
74  return totOverlap;
75 
76  }
77 
78  //------------------------------
80  //------------------------------
81  {
82 
83  }
84 
85 
86  // Function to calculate the "convolution"
87  float CFAlgoChargeDistrib::TProfConvol(std::vector<util::PxHit> hA ,std::vector<util::PxHit> hB)
88  {
90  const detinfo::DetectorProperties* detp = lar::providerFrom<detinfo::DetectorPropertiesService>();
91  int NumTimeSamples = detp->NumberTimeSamples() * geou.TimeToCm();
92 
93  double Tmin = NumTimeSamples;
94  double Tmax = 0;
95 
96  // Make two vectors to hold the Time-Profile of the Q-distribution
97  // of the two clusters
98  std::vector<float> QprofA(100,0.);
99  std::vector<float> QprofB(100,0.);
100  float QB = 0;
101  float QA = 0;
102 
103  //First find min and max times
104  for(auto const& hitA : hA) {
105  if(hitA.t > Tmax) Tmax = hitA.t;
106  if(hitA.t < Tmin) Tmin = hitA.t;
107  }
108  for(auto const& hitB : hB) {
109  if(hitB.t > Tmax) Tmax = hitB.t;
110  if(hitB.t < Tmin) Tmin = hitB.t;
111  }
112 
113  //Now Fill Q-profile vectors
114  for(auto const& hitA : hA){
115  QprofA.at( int(99*(hitA.t-Tmin)/(Tmax-Tmin)) ) += hitA.charge;
116  QA += hitA.charge;
117  }
118  for(auto const& hitB : hB){
119  QprofB.at( int(99*(hitB.t-Tmin)/(Tmax-Tmin)) ) += hitB.charge;
120  QB += hitB.charge;
121  }
122 
123  /*//Normalize distributions
124  for (size_t b=0; b < QprofA.size(); b++)
125  QprofA.at(b) /= QA;
126  for (size_t b=0; b < QprofB.size(); b++)
127  QprofB.at(b) /= QB;
128  */
129 
130  //print out distribution if verbose
131  if (_debug){
132  std::cout << "Q distribution for Cluster A:" << std::endl;
133  for (size_t b=0; b < QprofA.size(); b++)
134  if ( QprofA.at(b) != 0 ) { std::cout << b << "\t" << QprofA.at(b) << std::endl; }
135  std::cout << "Q distribution for Cluster B:" << std::endl;
136  for (size_t b=0; b < QprofB.size(); b++)
137  if ( QprofB.at(b) != 0 ) { std::cout << b << "\t" << QprofB.at(b) << std::endl; }
138  }
139 
140  // Now find convolution between the two distributions
141  // Scan two vectors and always take smallest quantity
142  // Add this smallest quantity as vector is scanned to
143  // obtain the common Q-distribution for the clusters
144  float conv= 0;
145  for (size_t b=0; b < QprofA.size(); b++){
146  if ( QprofA.at(b) < QprofB.at(b) ) { conv += QprofA.at(b); }
147  else { conv += QprofB.at(b); }
148  }
149  if (_verbose) { std::cout << "Convolution is: " << conv << std::endl; }
150 
151  return conv;
152  }
153 
154 
155 }
float TProfConvol(std::vector< util::PxHit > hita, std::vector< util::PxHit > hitb)
Class def header for a class CFAlgoChargeDistrib.
Double_t TimeToCm() const
void SetVerbose(bool on)
Setter function for verbosity.
CFAlgoChargeDistrib()
Default constructor.
virtual unsigned int NumberTimeSamples() const =0
virtual float Float(const std::vector< const cluster::ClusterParamsAlg * > &clusters)
art::PtrVector< recob::Hit > Hits
static bool * b
Definition: config.cpp:1043
Definition: cfalgo.cc:3
virtual void Reset()
Function to reset the algorithm instance, called together with manager&#39;s Reset()
QTextStream & endl(QTextStream &s)