Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

HoughLine.cxx

Go to the documentation of this file.
00001 #include "NueAna/ParticlePID/ParticleFinder/HoughLine.h"
00002 #include <math.h>
00003 
00004 ClassImp(HoughLine)
00005 
00006 bool operator < (const HoughLine & left, const HoughLine & right)
00007 {
00008         if(left.ncluster < right.ncluster)return true;
00009         return false;
00010 }
00011 
00012 
00013 HoughLine::HoughLine()
00014 {
00015         Reset();
00016 }
00017 
00018 HoughLine::~HoughLine()
00019 {}
00020 
00021 HoughLine::HoughLine(double theta, double r, double offset_t, double offset_z)
00022 {
00023         SetHoughParams(theta, r, offset_t, offset_z);
00024 }
00025 
00026 
00027 void HoughLine::AddCluster(Managed::ManagedCluster *cl)
00028 {
00029 
00030         //printf("z %f t %f\n",cl->z,cl->t);
00031 
00032         if(!cl)return;
00033         cluster_id.push_back(cl->id);
00034         
00035 //      printf("adding cluster %d to hl %f %f  %f %f  ",cl->id,start_z,start_t,end_z,end_t);
00036 
00037         sum_e+=cl->e;
00038         if(ncluster==0 && start_z==0) //need to check start_z in case we did a resethits(1)
00039         {
00040                 start_z=end_z=cl->z;
00041                 start_t=end_t=cl->t;
00042         }
00043 
00044         if(start_z > cl->z)
00045         {
00046                 start_z = cl->z;
00047                 start_t = cl->t;
00048         }
00049         
00050         if(end_z < cl->z)
00051         {
00052                 end_z = cl->z;
00053                 end_t = cl->t;
00054         }
00055         
00056 //      printf(" now at %f %f  %f %f\n",start_z,start_t,end_z,end_t);
00057 
00058         ncluster++;
00059         
00060         double exp_t = GetExpectedT(cl->z);
00061         chi2+=(cl->t-exp_t)*(cl->t-exp_t);
00062 }
00063 
00064 
00065 void HoughLine::SetHoughParams(double theta, double r, double offset_t, double offset_z)
00066 {
00067         Reset();
00068         this->theta=theta;
00069         this->r=r;
00070         this->offset_t=offset_t;
00071         this->offset_z=offset_z;
00072         
00073         
00074         //determine the angle off of z "phi
00075         double d=1;
00076         double zpos1 = offset_z + (offset_t + r/sin(theta)-d)*sin(theta)/cos(theta);
00077         double zpos2 = offset_z + (offset_t + r/sin(theta)+d)*sin(theta)/cos(theta);
00078         
00079         phi = atan(2*d/(zpos2-zpos1));
00080         
00081 }
00082 
00083 
00084 void HoughLine::Reset()
00085 {
00086 
00087                 
00088         theta=0;
00089         r=0;
00090         offset_t=0;
00091         offset_z=0;
00092         chi2=0;
00093         phi=0;
00094         
00095         ResetHits(0);
00096 
00097 }
00098 
00099 void HoughLine::ResetHits(int keep_bounds)
00100 {
00101 
00102         cluster_id.clear();
00103         
00104         if(!keep_bounds)
00105         {
00106                 start_z=0;
00107                 start_t=0;
00108                 end_z=0;
00109                 end_t=0;
00110         }
00111         
00112         
00113         ncluster=0;
00114         
00115         sum_e=0;
00116         primary=0;      
00117 }
00118 
00119                 
00120 double HoughLine::GetExpectedT(double z)
00121 {
00122 
00123 
00124         return (- cos(theta)/sin(theta))*(z-offset_z)+r/sin(theta) + offset_t;
00125 
00126 }
00127 
00128 
00129 
00130 extern bool CompareChi2(const HoughLine & l,const HoughLine &r)
00131 {
00132         return l.chi2/l.ncluster > r.chi2/r.ncluster;
00133 }       
00134 
00135 
00136 extern bool CompareT(const HoughLine & l,const HoughLine &r)
00137 {
00138         if(fabs(l.start_t-r.start_t)<0.0001)
00139         {
00140                 if(fabs(l.end_t-r.end_t)<0.0001)
00141                 {
00142                         return CompareChi2(l,r);
00143                 }
00144                 return l.end_t<r.end_t;
00145         }
00146 
00147         return l.start_t<r.start_t;
00148 
00149 }
00150 
00151 extern bool CompareLength(const HoughLine & l,const HoughLine &r)
00152 {
00153         if(fabs(l.start_z-r.start_z)<0.0001)
00154         {
00155                 if(fabs(l.end_z-r.end_z)<0.0001)
00156                 {
00157                         return CompareT(l,r);
00158                 }
00159 
00160                 return l.end_z<r.end_z;
00161         }
00162 
00163         return l.start_z<r.start_z;
00164 
00165 }
00166 
00167 extern bool CompareTotalEnergy(const HoughLine & l,const HoughLine &r)
00168 {
00169         return l.sum_e > r.sum_e;
00170 }
00171 
00172 extern bool CompareForwardAndClusters(const HoughLine & l,const HoughLine &r)
00173 {
00174         if(l.ncluster == r.ncluster)
00175         {
00176                 //are they the same number of planes?
00177                 if(fabs(l.end_z-l.start_z + r.start_z -r.end_z)/0.06 < 1)
00178                 {
00179                         //return the most forward one
00180                         return l.start_z>r.start_z;
00181                 }
00182                 //select the shortest one
00183                 return l.end_z-l.start_z > r.end_z-r.start_z;
00184 
00185         }
00186 
00187         return l.ncluster < r.ncluster;
00188 
00189 }
00190 
00191 
00192 
00193 
00194 
00195 
00196 

Generated on Mon Feb 15 11:06:47 2010 for loon by  doxygen 1.3.9.1