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