LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
CFAlgoTimeOverlap.cxx
Go to the documentation of this file.
2 
3 namespace cmtool {
4 
5  //-------------------------------------------------------
7  //-------------------------------------------------------
8  {
9  SetRatioCut(0.001); //(0.095) ;
10  SetStartTimeCut(10);
11  SetDebug(false);
12  SetVerbose(false);
13  RequireThreePlanes(true);
14  }
15 
16  //-----------------------------
18  //-----------------------------
19  {}
20 
21  //----------------------------------------------------------------------------------------------
23  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 (_require_3planes && clusters.size() == 2) return -1;
31  // Code-block by Kazu ends
32 
33  double ratio = 1;
34  double time_difference = 0;
35  double max_time_difference = 0;
36  double max_charge = 0;
37  double charge_ratio = 1;
38 
39  //Preserve location in time space. Cut clusters that have similar time differences,
40  // but hit wires at very different times.
41  double start_t = 0;
42  double end_t = 0;
43  double prev_start_t = 0;
44  double prev_end_t = 0;
45 
46  double max_hits_1 = 0;
47  double max_hits_2 = 0;
48 
49  for (auto const& c : clusters) {
50 
51  auto charge = c->GetParams().sum_charge;
52 
53  time_difference = c->GetParams().start_point.t - c->GetParams().end_point.t;
54 
55  if (time_difference < 0) time_difference *= -1;
56 
57  if (max_time_difference < time_difference) max_time_difference = time_difference;
58 
59  if (max_charge < charge) max_charge = charge;
60 
61  if (c->GetParams().N_Hits > max_hits_1) {
62  max_hits_2 = max_hits_1;
63  max_hits_1 = c->GetParams().N_Hits;
64  }
65  else if (c->GetParams().N_Hits > max_hits_2)
66  max_hits_2 = c->GetParams().N_Hits;
67  }
68 
69  ratio = 1;
70  charge_ratio = 1;
71  for (size_t c_index = 0; c_index < clusters.size(); ++c_index) {
72  auto const& c = clusters[c_index];
73 
74  double length = c->GetParams().length;
75  //auto charge = c->GetParams().sum_charge ;
76  //Order hits from most to least
77  //SetMaxMiddleMin(hits_0,hits_1,hits_2,max_hits,middle_hits,min_hits);
78 
79  //Make start_t always smaller
80  if (c->GetParams().start_point.t > c->GetParams().end_point.t) {
81  start_t = c->GetParams().end_point.t;
82  end_t = c->GetParams().start_point.t;
83  }
84  else {
85  start_t = c->GetParams().start_point.t;
86  end_t = c->GetParams().end_point.t;
87  }
88 
89  if (prev_start_t == 0) prev_start_t = start_t;
90  if (prev_end_t == 0) prev_end_t = end_t;
91 
92  time_difference = end_t - start_t;
93 
94  ratio *= time_difference / max_time_difference;
95 
96  charge_ratio = max_hits_2 / max_hits_1; // charge/max_charge ;
97 
98  if (c_index == (clusters.size() - 1)) ratio *= charge_ratio;
99 
100  //If current cluster's start time is not within some range of the previous cluster's start time,
101  //modify ratio to disallow matching
102 
103  if ((start_t > (prev_start_t - _start_time_cut) &&
104  start_t < (prev_start_t + _start_time_cut)) ||
105  (end_t > (prev_end_t - _start_time_cut) && end_t < (prev_end_t + _start_time_cut)) ||
106  (length > 25 && start_t > (prev_start_t - 2 * _start_time_cut) &&
107  start_t < (prev_start_t + 2 * _start_time_cut)))
108  ratio *= 1;
109  else
110  ratio *= 0.001;
111 
112  prev_start_t = start_t;
113  prev_end_t = end_t;
114 
115  if (_debug && c_index == (clusters.size() - 1) && ratio > _time_ratio_cut) {
116  std::cout << "\nPLANE: " << c->Plane();
117  std::cout << "\nStart point: " << start_t << std::endl;
118  std::cout << "End Point: " << end_t << std::endl;
119  // std::cout<<"Previous start time: "<<prev_start_t<<std::endl;
120  std::cout << "Time diff: " << time_difference << std::endl;
121  std::cout << "Max time diff: " << max_time_difference << std::endl;
122  std::cout << "Ratio for each cluster: " << ratio << std::endl;
123  // std::cout<<"Charge: "<<charge<<std::endl;
124  std::cout << "Charge Ratio: " << charge_ratio << std::endl;
125  //std::cout<<"Hits are: "<<min_hits<<", "<<middle_hits<<", "<<max_hits<<std::endl;
126  // std::cout<<"Adjusted Charge Ratio: "<<adjusted_charge_ratio<<std::endl;
127  std::cout << "Length and Width: " << c->GetParams().length << ", " << c->GetParams().width
128  << std::endl;
129  }
130  }
131 
132  if (_verbose && ratio > _time_ratio_cut)
133  std::cout << "**************************FOUND A MATCH . ratio is: " << ratio << "\n\n\n"
134  << std::endl;
135 
136  return (ratio > _time_ratio_cut ? ratio : -1);
137  }
138 
139  //------------------------------
140  /*
141  void CFAlgoTimeOverlap::SetMaxMiddleMin(const double first,
142  const double second,
143  const double third,
144  double &max,
145  double &middle,
146  double &min)
147  //------------------------------
148  {
149 
150  if(first > second && first > third){
151  max = first;
152  }
153  else if (first > second && first < third){
154  max = third ;
155  middle = first ;
156  min = second ;
157  }
158  else if (first > third && first < second){
159  max = second ;
160  middle = first ;
161  min = third ;
162  }
163  else if(first <second && first <third)
164  min = first ;
165 
166 
167  if (max == first && second > third){
168  middle = second ;
169  min = third ;
170  }
171  else if (max ==first && third > second){
172  middle = third ;
173  min = second ;
174  }
175 
176  if(min ==first && second > third){
177  middle = third ;
178  max = second;
179  }
180  else if(min ==first && third > second){
181  middle = second ;
182  max = third ;
183  }
184 
185 
186  //Very rarely, the angles(or hits) may be equal
187  if( first == second && first > third ){
188  max = first;
189  middle = second ;
190  min = third ;
191  }
192  else if( first == second && first < third){
193  max = third;
194  middle = first ;
195  min = second ;
196  }
197 
198  else if( first ==third && first > second){
199  max = first;
200  middle = third;
201  min = second;
202  }
203 
204  else if( first == third && first < second){
205  max = second ;
206  middle = first;
207  min = third ;
208  }
209 
210  else if( second ==third && second < first){
211  max = first;
212  middle = third;
213  min = second;
214  }
215 
216  else if( second == third && second > first){
217  max = second;
218  middle = third;
219  min = first ;
220  }
221  }
222  */
223 
224  //------------------------------
226  //------------------------------
227  {}
228 
229 }
void SetStartTimeCut(float start_time)
void SetVerbose(bool verbose) override
Setter function for verbosity.
void RequireThreePlanes(bool doit)
void SetRatioCut(float ratio)
Class def header for a class CFAlgoTimeOverlap.
CFAlgoTimeOverlap()
Default constructor.
void Reset() override
Function to reset the algorithm instance called within CMergeManager/CMatchManager&#39;s Reset() ...
float Float(util::GeometryUtilities const &, const std::vector< const cluster::ClusterParamsAlg * > &clusters) override