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