Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Private Member Functions | List of all members
util::HoughCalc Class Reference

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N20-09-17/Utilities/HoughCalc.h"

Classes

struct  hitnode
 
struct  node
 
struct  Params
 

Public Types

using Parameters = art::ServiceTable< Params >
 

Public Member Functions

 HoughCalc (const Parameters &params, art::ActivityRegistry &reg)
 
virtual ~HoughCalc ()
 
void Reset ()
 
void AddPoint (double x1, double sigx1, double x2, double sigx2, double y1, double sigy1, double y2, double sigy2, double w, int ih1)
 
void FindLines (double *theta, double *rho, double *score)
 
void FindLineErrs (double *etheta, double *erho)
 
bool TestHit (double x, double y, double thmx, double rhomx, double sigth, double sigr)
 
bool TestHit (double x, double y, double thmx, double rhomx, double sigr)
 
double DistHit (double x, double y, double thmx, double rhomx)
 
int GetHit ()
 

Static Public Member Functions

static void MakeTree (double thresh)
 
static int UpdateTree ()
 
static void SetThresh (double thresh)
 

Static Private Member Functions

static void InsertSort (node *head, node *item)
 
static void DeleteChain (node *head)
 
static void DeleteChain (hitnode *head)
 
static nodenewNode (int t, int r)
 
static void nodeUpdate (node *head, double ww, int ih1)
 
static void AddPoint (double theta, double rho, double ww, int ih1)
 
static void RemovePoint (double theta, double rho, double ww, int ih1)
 

Detailed Description

Definition at line 60 of file HoughCalc.h.

Member Typedef Documentation

Definition at line 69 of file HoughCalc.h.

Constructor & Destructor Documentation

util::HoughCalc::HoughCalc ( const Parameters params,
art::ActivityRegistry reg 
)

Definition at line 45 of file HoughCalc_service.cc.

References MECModelEnuComparisons::i, and calib::j.

46  {
47  for(int i=0;i<gsNtheta;i++){
48  for(int j=0;j<gsNrho;j++){
49  nodearray[i][j]=NULL;
50  }
51  thetaarray[i]=NULL;
52  thetacount[i]=0;
53  }
54  }
const double j
Definition: BetheBloch.cxx:29
util::HoughCalc::~HoughCalc ( )
virtual

Definition at line 56 of file HoughCalc_service.cc.

References DeleteChain(), and MECModelEnuComparisons::i.

57  {
58  //Free up all linked list nodes....
59  for(int i=0;i<gsNtheta;i++){
60  if(thetacount[i]>0)DeleteChain(thetaarray[i]);
61  }
62 
63  delete treehead;treehead=NULL;
64  }
static void DeleteChain(node *head)

Member Function Documentation

void util::HoughCalc::AddPoint ( double  x1,
double  sigx1,
double  x2,
double  sigx2,
double  y1,
double  sigy1,
double  y2,
double  sigy2,
double  w,
int  ih1 
)

Definition at line 307 of file HoughCalc_service.cc.

References std::atan(), std::cos(), Gaus(), M_PI, r(), RemovePoint(), std::sin(), chisquared::theta, w, x1, submit_syst::x2, y1, and submit_syst::y2.

311  {
312  int itheta;
313  int ir;
314  double theta;
315  double r;
316  double yy1, yy2;
317  double ww;
318 
319  double theta_segment = (y2!=y1)?
320  -1.*atan((x2-x1)/(y2-y1)):
321  M_PI/2.;
322  if (theta_segment<0.) theta_segment += M_PI;
323  double r_segment = cos(theta_segment)*x1 + sin(theta_segment)*y1;
324 
325  for (itheta=-3; itheta<=3; ++itheta) {
326  theta = theta_segment + M_PI*(double)(itheta)/(double)(gsNtheta);
327  if(theta<0.) theta = M_PI - theta;
328  if(theta>M_PI) theta = theta - M_PI;
329  for (ir=-3; ir<=3; ++ir) {
330  r = r_segment + (maxrho-minrho)*(double)(ir)/(double)(gsNrho); //mod by steve, must multiply by (maxrho-minrho)....
331  yy1 = (sin(theta)!=0.)?
332  (r - cos(theta)*x1)/sin(theta):
333  y1;
334  yy2 = (sin(theta)!=0.)?
335  (r - cos(theta)*x2)/sin(theta):
336  y2;
337  ww = TMath::Gaus(yy1,y1,sigy1)*TMath::Gaus(yy2,y2,sigy2)*w;
338 
339  if(ww > 0.01) AddPoint(theta,r,ww,ih1);
340  if(ww < 0) RemovePoint(theta,r,ww,ih1);
341  }
342  }
343  }
Float_t y1[n_points_granero]
Definition: compare.C:5
Float_t x1[n_points_granero]
Definition: compare.C:5
void AddPoint(double x1, double sigx1, double x2, double sigx2, double y1, double sigy1, double y2, double sigy2, double w, int ih1)
static void RemovePoint(double theta, double rho, double ww, int ih1)
#define M_PI
Definition: SbMath.h:34
T atan(T number)
Definition: d0nt_math.hpp:66
double Gaus(TH1D *h, double &err, bool isTruth)
Definition: absCal.cxx:489
T sin(T number)
Definition: d0nt_math.hpp:132
T cos(T number)
Definition: d0nt_math.hpp:78
TRandom3 r(0)
Float_t w
Definition: plot.C:20
void util::HoughCalc::AddPoint ( double  theta,
double  rho,
double  ww,
int  ih1 
)
staticprivate

Definition at line 175 of file HoughCalc_service.cc.

References makeTrainCVSamples::int, newNode(), nodeUpdate(), r(), and confusionMatrixTree::t.

176  {
177  int t = (int)TMath::Floor((theta-mintheta)/(maxtheta-mintheta)*(gsNtheta));
178  int r = (int)TMath::Floor((rho-minrho)/(maxrho-minrho)*(gsNrho));
179 
180  if(r<0||t<0||r>=gsNrho||t>=gsNtheta) return;
181 
182  if (nodearray[t][r]==NULL){
183  nodearray[t][r]=newNode(t,r);
184  thetacount[t]++;
185  nodearray[t][r]->c0=thetaarray[t];
186  thetaarray[t]=nodearray[t][r];
187  }
188 
189  nodeUpdate(nodearray[t][r],ww,ih1);
190  }
static void nodeUpdate(node *head, double ww, int ih1)
TRandom3 r(0)
static node * newNode(int t, int r)
void util::HoughCalc::DeleteChain ( node head)
staticprivate

Definition at line 283 of file HoughCalc_service.cc.

References util::HoughCalc::node::c0, stan::math::head(), util::HoughCalc::node::hitlist, and APDHVSetting::temp.

Referenced by Reset(), and ~HoughCalc().

284  {
285  while(head != NULL){
286  node *temp = head->c0;
287  DeleteChain(head->hitlist);
288  delete head;
289  head=temp;
290  }
291 
292  }
Eigen::Matrix< T, Eigen::Dynamic, 1 > head(const Eigen::Matrix< T, Eigen::Dynamic, 1 > &v, size_t n)
Definition: head.hpp:24
static void DeleteChain(node *head)
void util::HoughCalc::DeleteChain ( hitnode head)
staticprivate

Definition at line 296 of file HoughCalc_service.cc.

References util::HoughCalc::hitnode::c0, stan::math::head(), and APDHVSetting::temp.

297  {
298  while(head!=NULL){
299  hitnode *temp=head;
300  head=head->c0;
301  delete temp;
302  }
303  }
Eigen::Matrix< T, Eigen::Dynamic, 1 > head(const Eigen::Matrix< T, Eigen::Dynamic, 1 > &v, size_t n)
Definition: head.hpp:24
double util::HoughCalc::DistHit ( double  x,
double  y,
double  thmx,
double  rhomx 
)

Definition at line 448 of file HoughCalc_service.cc.

References std::cos(), DEFINE_ART_SERVICE, stan::math::fabs(), r(), std::sin(), and submit_syst::y.

450  {
451  double r;
452  r = cos(thmx)*x + sin(thmx)*y;
453  return fabs(r-rhomx);
454  }
fvar< T > fabs(const fvar< T > &x)
Definition: fabs.hpp:15
T sin(T number)
Definition: d0nt_math.hpp:132
T cos(T number)
Definition: d0nt_math.hpp:78
TRandom3 r(0)
void util::HoughCalc::FindLineErrs ( double *  etheta,
double *  erho 
)

Definition at line 372 of file HoughCalc_service.cc.

References util::HoughCalc::node::c1, stan::math::fabs(), util::HoughCalc::node::rho, std::sqrt(), APDHVSetting::temp, util::HoughCalc::node::theta, UpdateTree(), and util::HoughCalc::node::weight.

373  {
374  //this was a trial function, but it doesn't work very well. I wouldn't use it.--TV
375 
376  if (treehead->c1==NULL){peaklist=NULL;return;}
377 
378  if(treehead->c1->goodsort==0)UpdateTree();
379  //update the tree if we failed to do so
380  //so long as treehead->c1 has not been touched
381  //it is still the max, so don't bother resorting rest of tree
382 
383  if (treehead->c1==NULL){peaklist=NULL;return;}
384 
385  double sigr=0.;
386  double sigt=0.;
387  double totw=0.;
388 
389  double thetamx=(double)(treehead->c1->theta);
390  double rmx=(double)(treehead->c1->rho);
391  // std::cout<<"thetamx "<<thetamx<<" rho "<<rmx<<std::endl;
392  node *temp = treehead->c1;
393  while(temp!=NULL){
394  // std::cout<<"temp weight is "<<temp->weight<<" my thres "<<myThresh<<std::endl;
395  if(temp->weight>=myThresh){
396  sigr+=(temp->rho-rmx)*(temp->rho-rmx)*fabs(temp->weight);
397  sigt+=(temp->theta-thetamx)*(temp->theta-thetamx)*fabs(temp->weight);
398  totw+=fabs(temp->weight);
399  // std::cout<<" rho "<<temp->rho<<" theta "<<temp->theta<<std::endl;
400  // std::cout<<"sigr "<<sigr<<" sigt "<<sigt<<" totw "<<totw<<std::endl;
401  }
402  temp = temp->c1;
403  }
404  // std::cout<<"after loop sigr "<<sigr<<" sigt "<<sigt<<" totw "<<totw<<std::endl;
405  *ethetamx=0.;
406  *ermx=0.;
407  if(fabs(totw)>0.001){
408  *ethetamx = sqrt(sigt/totw)/(double)(gsNtheta)*(maxtheta-mintheta);
409  *ermx = sqrt(sigr/totw)/(double)(gsNrho)*(maxrho-minrho);
410  }
411  // std::cout<<"theta "<<thetamx<<" rmx "<<rmx<<std::endl;
412  // std::cout<<"all done err theta "<<*ethetamx<<" ermx "<<*ermx<<std::endl;
413  return;
414  }
fvar< T > fabs(const fvar< T > &x)
Definition: fabs.hpp:15
T sqrt(T number)
Definition: d0nt_math.hpp:156
static int UpdateTree()
void util::HoughCalc::FindLines ( double *  theta,
double *  rho,
double *  score 
)

Definition at line 347 of file HoughCalc_service.cc.

References UpdateTree().

348  {
349  if (treehead->c1==NULL){*score=0;peaklist=NULL;return;}
350 
351  if(treehead->c1->goodsort==0)UpdateTree();
352  //update the tree if we failed to do so
353  //so long as treehead->c1 has not been touched
354  //it is still the max, so don't bother resorting rest of tree
355 
356  if (treehead->c1==NULL){*score=0;peaklist=NULL;return;}
357 
358 
359  *thetamx=(double)(treehead->c1->theta+0.5)/(double)(gsNtheta)
360  *(maxtheta-mintheta)+mintheta;
361  *rmx=(double)(treehead->c1->rho+0.5)/(double)(gsNrho)
362  *(maxrho-minrho)+minrho;
363  *score=treehead->c1->weight;
364 
365  peaklist=treehead->c1->hitlist;
366 
367  return;
368  }
static int UpdateTree()
int util::HoughCalc::GetHit ( )

Definition at line 221 of file HoughCalc_service.cc.

222  {
223  int hit=-1;
224 
225  if(peaklist!=NULL)
226  {
227  hit=peaklist->hit;
228  peaklist=peaklist->c0;
229  }
230  return hit;
231  }
Definition: event.h:1
void util::HoughCalc::InsertSort ( node head,
node item 
)
staticprivate

Definition at line 272 of file HoughCalc_service.cc.

References util::HoughCalc::node::c1, and util::HoughCalc::node::weight.

Referenced by MakeTree(), and UpdateTree().

273  {
274  while(head->c1 != NULL &&
275  item->weight < head->c1->weight )
276  {head=head->c1;}
277  item->c1=head->c1;
278  head->c1=item;
279  }
Eigen::Matrix< T, Eigen::Dynamic, 1 > head(const Eigen::Matrix< T, Eigen::Dynamic, 1 > &v, size_t n)
Definition: head.hpp:24
void util::HoughCalc::MakeTree ( double  thresh)
static

Definition at line 89 of file HoughCalc_service.cc.

References util::HoughCalc::node::c0, util::HoughCalc::node::c1, util::HoughCalc::node::goodsort, MECModelEnuComparisons::i, InsertSort(), newNode(), and util::HoughCalc::node::weight.

89  {
90 
91  peaklist=NULL;
92 
93  myThresh=thresh;
94 
95  //need a infinite weight node for insertion sort
96  if (treehead==NULL)
97  {
98  treehead=newNode(-1,-1);
99  treehead->weight=INFINITY;
100  }
101  else treehead->c1=NULL;
102 
103  node *toadd=NULL;
104 
105  for(int i=0;i<gsNtheta;i++){
106  toadd=thetaarray[i];
107  while(toadd!=NULL){
108  toadd->c1=NULL;
109  if(toadd->weight>=thresh)
110  {
111  if(treehead->c1==NULL)treehead->c1=toadd;
112  else InsertSort(treehead,toadd);
113  toadd->goodsort=1;
114  }
115  toadd=toadd->c0;
116  }
117  }
118  }
static void InsertSort(node *head, node *item)
static node * newNode(int t, int r)
HoughCalc::node * util::HoughCalc::newNode ( int  t,
int  r 
)
staticprivate

Definition at line 255 of file HoughCalc_service.cc.

References util::HoughCalc::node::c0, util::HoughCalc::node::c1, util::HoughCalc::node::goodsort, util::HoughCalc::node::hitcount, util::HoughCalc::node::hitlist, file_size_ana::node, r(), util::HoughCalc::node::rho, confusionMatrixTree::t, APDHVSetting::temp, util::HoughCalc::node::theta, util::HoughCalc::node::treeready, and util::HoughCalc::node::weight.

Referenced by AddPoint(), and MakeTree().

256  {
257  node *temp=new node;
258  temp->rho=r;
259  temp->theta=t;
260  temp->hitcount=0;
261  temp->weight=0.0;
262  temp->hitlist=NULL;
263  temp->c0=NULL;
264  temp->c1=NULL;
265  temp->goodsort=0;
266  temp->treeready=0;
267  return temp;
268  }
TRandom3 r(0)
void util::HoughCalc::nodeUpdate ( node head,
double  ww,
int  ih1 
)
staticprivate

Definition at line 235 of file HoughCalc_service.cc.

References util::HoughCalc::hitnode::c0, util::HoughCalc::hitnode::hit, util::HoughCalc::node::hitcount, util::HoughCalc::node::hitlist, getGoodRuns4SAM::n, APDHVSetting::temp, util::HoughCalc::hitnode::weight, and util::HoughCalc::node::weight.

Referenced by AddPoint().

236  {
237 
238  head->weight+=ww;
239 
240  //use code below to see which hits made up this bin
241  return;
242  hitnode *temp = head->hitlist;
243  while(temp!=NULL){if(temp->hit==ih1){temp->weight+=ww;return;}temp=temp->c0;}
244 
245  hitnode *n = new hitnode;
246  n->hit=ih1;
247  n->weight=ww;
248  n->c0=head->hitlist;
249  head->hitlist=n;
250  head->hitcount++;
251  }
Eigen::Matrix< T, Eigen::Dynamic, 1 > head(const Eigen::Matrix< T, Eigen::Dynamic, 1 > &v, size_t n)
Definition: head.hpp:24
void util::HoughCalc::RemovePoint ( double  theta,
double  rho,
double  ww,
int  ih1 
)
staticprivate

Definition at line 194 of file HoughCalc_service.cc.

References makeTrainCVSamples::int, r(), and confusionMatrixTree::t.

Referenced by AddPoint().

195  {
196  int t = (int)TMath::Floor((theta-mintheta)/(maxtheta-mintheta)*(gsNtheta));
197  int r = (int)TMath::Floor((rho-minrho)/(maxrho-minrho)*(gsNrho));
198 
199  if(r<0||t<0||r>=gsNrho||t>=gsNtheta) return;
200  if(nodearray[t][r]==NULL)return;
201 
202  //use this code if keeping list of hits which made up bin
203  /*
204  int foundhit=0;
205 
206  hitnode * hit = nodearray[t][r]->hitlist;
207  while(hit!=NULL&&hit->hit==ih1){nodearray[t][r]->hitlist=hit->c0;delete hit;hit=nodearray[t][r]->hitlist;foundhit=1;}
208  while(hit!=NULL){if(hit->c0==NULL)break;if(hit->c0->hit==ih1){hitnode* t=hit->c0;hit->c0=hit->c0->c0;delete t;foundhit=1;}else hit=hit->c0;}
209 
210  if(foundhit==1){
211  nodearray[t][r]->hitcount--;
212  }
213  */
214 
215  nodearray[t][r]->goodsort=0;
216  nodearray[t][r]->weight+=ww; //ww is <0 here...
217  }
TRandom3 r(0)
void util::HoughCalc::Reset ( )

Definition at line 68 of file HoughCalc_service.cc.

References DeleteChain(), MECModelEnuComparisons::i, and calib::j.

68  {
69  if(treehead!=NULL){
70  for(int i=0;i<gsNtheta;i++){
71  if(thetacount[i]>0)DeleteChain(thetaarray[i]);
72  thetaarray[i]=NULL;
73  thetacount[i]=0;
74  for(int j=0;j<gsNrho;j++){
75  nodearray[i][j]=NULL;
76  }
77  }
78  treehead=NULL;
79  }
80  }
const double j
Definition: BetheBloch.cxx:29
static void DeleteChain(node *head)
void util::HoughCalc::SetThresh ( double  thresh)
static

Definition at line 85 of file HoughCalc_service.cc.

85 {myThresh=thresh;}
bool util::HoughCalc::TestHit ( double  x,
double  y,
double  thmx,
double  rhomx,
double  sigth,
double  sigr 
)

Definition at line 418 of file HoughCalc_service.cc.

References std::cos(), stan::math::fabs(), M_PI, r(), std::sin(), chisquared::theta, and submit_syst::y.

421  {
422  int itheta;
423  double theta;
424  double r;
425  for (itheta=0; itheta<5*gsNtheta; ++itheta) {
426  theta = M_PI*(double)itheta/(double)(5*gsNtheta);
427  if (fabs(theta-thmx)>sigth) continue;
428  r = cos(theta)*x + sin(theta)*y;
429  if (fabs(r-rhomx)<sigr) return true;
430  }
431  return false;
432  }
fvar< T > fabs(const fvar< T > &x)
Definition: fabs.hpp:15
#define M_PI
Definition: SbMath.h:34
T sin(T number)
Definition: d0nt_math.hpp:132
T cos(T number)
Definition: d0nt_math.hpp:78
TRandom3 r(0)
bool util::HoughCalc::TestHit ( double  x,
double  y,
double  thmx,
double  rhomx,
double  sigr 
)

Definition at line 436 of file HoughCalc_service.cc.

References std::cos(), stan::math::fabs(), r(), std::sin(), and submit_syst::y.

439  {
440  double r;
441  r = cos(thmx)*x + sin(thmx)*y;
442  if (fabs(r-rhomx)<sigr) return true;
443  return false;
444  }
fvar< T > fabs(const fvar< T > &x)
Definition: fabs.hpp:15
T sin(T number)
Definition: d0nt_math.hpp:132
T cos(T number)
Definition: d0nt_math.hpp:78
TRandom3 r(0)
int util::HoughCalc::UpdateTree ( )
static

Definition at line 124 of file HoughCalc_service.cc.

References util::HoughCalc::node::c1, util::HoughCalc::node::goodsort, InsertSort(), APDHVSetting::temp, and util::HoughCalc::node::weight.

Referenced by FindLineErrs(), and FindLines().

125  {
126 
127  //MsgDebug("Util","Updating Tree\n");
128 
129  node * toadd=NULL;
130  node * temp = treehead->c1;
131  node * pretemp = treehead;
132 
133  while(temp!=NULL){
134 
135  if(temp->weight<myThresh){pretemp->c1=temp->c1;temp->c1=NULL;temp=pretemp->c1;continue;}
136 
137  if (temp->goodsort==0){
138  pretemp->c1=temp->c1;
139 
140  if(toadd==NULL)
141  {
142  toadd=temp;
143  toadd->c1=NULL;
144  }
145  else
146  {
147  temp->c1=toadd;
148  toadd=temp;
149  }
150 
151  //leave pretemp in place
152  temp=pretemp->c1;
153 
154  }else{
155  pretemp=pretemp->c1;
156  temp=pretemp->c1;
157  }
158  }
159 
160  while(toadd!=NULL){
161  node * toaddtemp = toadd;
162  toadd=toadd->c1;
163  toaddtemp->c1=NULL;
164 
165  toaddtemp->goodsort=1;
166  if(toaddtemp->weight>=myThresh) InsertSort(treehead,toaddtemp);
167  }
168 
169  if(treehead->c1!=NULL)return 1;
170  return 0;
171  }
static void InsertSort(node *head, node *item)

The documentation for this class was generated from the following files: