THistogram Class Reference

A class for a histogram used in tracking. More...

#include <THistogram.h>

List of all members.

Public Member Functions

 THistogram (unsigned nBins)
 Constructor.
virtual ~THistogram ()
 Destructor.
void dump (const std::string &message=std::string(""), const std::string &prefix=std::string("")) const
 dumps debug information.
const AList< TMLink > *const bin (unsigned i) const
 returns a pointer to i'th AList<TMLink>.
const AList< TMLink > *const bin (int i) const
 returns a pointer to i'th AList<TMLink>.
unsigned nBin (unsigned i) const
 returns number in i'th bin.
unsigned nBins (void) const
 returns # of bins.
AList< TMLinkcontents (unsigned center, unsigned width) const
 returns an AList of TMLinks within 'center' bin +- 'width' bin region.
AList< TMLinkcontents (int start, int end) const
 returns an AList of TMLinks from 'start' bin to 'end' bin region.
const AList< TMLink > & contents (void) const
 returns an AList<TMLink> of all contents.
AList< TSegment0clusters0 (void) const
 returns an AList<TSegment0> of clusters.
AList< TSegmentclusters (void) const
 returns an AList<TSegment0> of clusters.
AList< TSegment0segments0 (void) const
 returns an AList<TSegment0> using clusters() function.
AList< TSegmentsegments (void) const
 returns an AList<TSegment0> using clusters() function.
void fillX (const AList< TMLink > &links)
 fills with hits.
void fillY (const AList< TMLink > &links)
 fills with hits.
void fillPhi (const AList< TMLink > &links)
 fills with hits.
void remove (const AList< TMLink > &links)
 removes links.
void mask (unsigned binN)
 masks a bin. Masked bin will not be returned by findPeak.
void unmask (void)
 remove masks.

Private Attributes

unsigned _nBins
unsigned * _bins
bool_masks
AList< TMLink > ** _links
AList< TMLink_all
float _binSize


Detailed Description

A class for a histogram used in tracking.

Definition at line 34 of file THistogram.h.


Constructor & Destructor Documentation

THistogram::THistogram ( unsigned  nBins  ) 

Constructor.

Definition at line 19 of file THistogram.cxx.

References _bins, _binSize, _links, _masks, _nBins, genRecEmupikp::i, and M_PI.

00019                                      : _nBins(nBins) {
00020     _binSize = 2. * M_PI / (float) _nBins;
00021     _bins = (unsigned *) malloc(_nBins * sizeof(unsigned));
00022     _masks = (bool *) malloc(_nBins * sizeof(bool));
00023     _links = (AList<TMLink> **) malloc(_nBins * sizeof(AList<TMLink> *));
00024     for (unsigned i = 0; i < _nBins; i++) {
00025         _bins[i] = 0;
00026         _masks[i] = false;
00027         _links[i] = new AList<TMLink>;
00028     }
00029 }

THistogram::~THistogram (  )  [virtual]

Destructor.

Definition at line 31 of file THistogram.cxx.

References _bins, _links, _masks, _nBins, and genRecEmupikp::i.

00031                         {
00032     free(_bins);
00033     free(_masks);
00034     for (unsigned i = 0; i < _nBins; i++)
00035         delete _links[i];
00036     free(_links);
00037 }


Member Function Documentation

const AList< TMLink > *const THistogram::bin ( int  i  )  const [inline]

returns a pointer to i'th AList<TMLink>.

Definition at line 129 of file THistogram.h.

References _links, and _nBins.

00129                            {
00130     while (i < 0) i += _nBins;
00131     return _links[i % _nBins];
00132 }

const AList< TMLink > *const THistogram::bin ( unsigned  i  )  const [inline]

returns a pointer to i'th AList<TMLink>.

Definition at line 122 of file THistogram.h.

References _links, and _nBins.

Referenced by contents().

00122                                 {
00123     if (i < _nBins) return _links[i];
00124     return 0;
00125 }

AList< TSegment > THistogram::clusters ( void   )  const

returns an AList<TSegment0> of clusters.

Definition at line 229 of file THistogram.cxx.

References _bins, _links, _nBins, TTrackBase::append(), and delete_small_size::size.

Referenced by segments().

00229                                {
00230     AList<TSegment> list;
00231 //    std::cout<<"enter clusters"<<std::endl;
00232     //...Serach for empty bin...
00233     unsigned begin = 0;
00234     while (_bins[begin] > 0)begin++;
00235     if (begin == _nBins) return list;
00236 
00237     //...Start searching...
00238     unsigned loop = 0;
00239     while (loop < _nBins) {
00240         ++loop;
00241         unsigned id = (begin + loop) % _nBins;
00242         if (_bins[id]) {
00243             unsigned size = 0;
00244             TSegment * c = new TSegment();
00245             while (_bins[id]) {
00246                 if (_bins[id]) ++size;
00247                 c->append(* _links[id]);
00248                 ++loop;
00249                 id = (begin + loop) % _nBins;
00250                 if (loop == _nBins) break;
00251             }
00252             list.append(c);
00253         }
00254     }
00255     return list;
00256 }

AList< TSegment0 > THistogram::clusters0 ( void   )  const

returns an AList<TSegment0> of clusters.

Definition at line 162 of file THistogram.cxx.

References _bins, _links, _nBins, TTrackBase::append(), and delete_small_size::size.

Referenced by TFastFinder::doit(), TConformalFinder0::findClusters(), TConformalFinder0::findClusters2(), and segments0().

00162                                 {
00163     AList<TSegment0> list;
00164 
00165     //...Serach for empty bin...
00166     unsigned begin = 0;
00167     while (_bins[begin] > 0) begin++;
00168     if (begin == _nBins) return list;
00169 
00170     //...Start searching...
00171     unsigned loop = 0;
00172     while (loop < _nBins) {
00173         ++loop;
00174         unsigned id = (begin + loop) % _nBins;
00175         if (_bins[id]) {
00176             unsigned size = 0;
00177             TSegment0 * c = new TSegment0();
00178             while (_bins[id]) {
00179                 if (_bins[id]) ++size;
00180                 c->append(* _links[id]);
00181                 ++loop;
00182                 id = (begin + loop) % _nBins;
00183                 if (loop == _nBins) break;
00184             }
00185             list.append(c);
00186         }
00187     }
00188     return list;
00189 }

const AList< TMLink > & THistogram::contents ( void   )  const [inline]

returns an AList<TMLink> of all contents.

Definition at line 154 of file THistogram.h.

References _all.

00154                                {
00155     return _all;
00156 }

AList< TMLink > THistogram::contents ( int  start,
int  end 
) const

returns an AList of TMLinks from 'start' bin to 'end' bin region.

Definition at line 154 of file THistogram.cxx.

References bin(), and genRecEmupikp::i.

00154                                              {
00155     AList<TMLink> links;
00156     for (int i = start; i <= end; i++)
00157         links.append(* bin(i));
00158     return links;
00159 }

AList< TMLink > THistogram::contents ( unsigned  center,
unsigned  width 
) const

returns an AList of TMLinks within 'center' bin +- 'width' bin region.

Definition at line 143 of file THistogram.cxx.

References bin(), and genRecEmupikp::i.

00143                                                           {
00144     AList<TMLink> links;
00145     for (int i = - (int) width;
00146          i <= (int) width;
00147          i++) {
00148         links.append(* bin((int) center + i));
00149     }
00150     return links;
00151 }

void THistogram::dump ( const std::string message = std::string(""),
const std::string prefix = std::string("") 
) const

dumps debug information.

Definition at line 40 of file THistogram.cxx.

References _bins, _links, _masks, _nBins, genRecEmupikp::i, ganga-rec::j, n1, and RealDBUtil::npos.

00040                                                                    {
00041     std::cout << pre;
00042     std::cout << "THistogram dump:#bins=" << _nBins << std::endl;
00043     unsigned nLoops = _nBins / 15 + 1;
00044     unsigned n0 = 0;
00045     unsigned n1 = 0;
00046     for (unsigned i = 0; i < nLoops; i++) {
00047         for (unsigned j = 0; j < 15; j++) {
00048             if (n0 == _nBins) break;
00049             printf("%4d", n0);
00050             ++n0;
00051         }
00052         std::cout << std::endl;
00053         for (unsigned j = 0; j < 15; j++) {
00054             if (n1 == _nBins) break;
00055             if (! _masks[n1]) printf("%4d", _bins[n1]);
00056             else              printf("-%3d", _bins[n1]);
00057             ++n1;
00058         }       
00059         std::cout << std::endl;
00060     }
00061 
00062     if (msg.find("detail") != std::string::npos) {
00063         for (unsigned i = 0; i < _nBins; i++) {
00064             std::cout << "bin " << i << " : ";
00065             for (unsigned j = 0; j < _links[i]->length(); j++) {
00066                 std::cout << (* _links[i])[j]->wire()->name() << ",";
00067             }
00068             std::cout << std::endl;
00069         }
00070     }
00071 
00072     return;
00073 }

void THistogram::fillPhi ( const AList< TMLink > &  links  ) 

fills with hits.

Definition at line 111 of file THistogram.cxx.

References _all, _bins, _binSize, _links, _nBins, genRecEmupikp::i, M_PI, and boss::pos.

Referenced by TConformalFinder::findSegments().

00111                                                {
00112     _all = (AList<TMLink> &) links;
00113     unsigned nLinks = links.length();
00114     double offset = _binSize / 4.;
00115     for (unsigned i = 0; i < nLinks; i++) {
00116         TMLink * l = links[i];
00117         const HepPoint3D & p = l->position();
00118         float phi = atan2(p.y(), p.x()) + M_PI;
00119 //      std::cout<<"atan "<<atan2(-1., -1.)<<std::endl;
00120         unsigned pos = (unsigned) floor((phi + offset) / _binSize);
00121 
00122 //      std::cout <<"layer "<<l->wire()->layerId()<<" cell "<<l->wire()->localId()
00123 //                <<" x "<<p.x()<<" y "<<p.y()<<" pos "<<pos<<" xypos hit "<<l->hit()->xyPosition()<<" xypos wire "<<l->wire()->xyPosition()<<" drift "<<l->hit()->drift(0)<< "+-" <<l->hit()->dDrift(0)<<std::endl;
00124 //      std::cout<<"binsize "<<_binSize<<" offset "<<offset<<" phi "<<phi<<std::endl;
00125         //...Why is this needed?...
00126         pos %= _nBins;
00127 
00128         ++_bins[pos];
00129         _links[pos]->append(l);
00130     }
00131 }

void THistogram::fillX ( const AList< TMLink > &  links  ) 

fills with hits.

Definition at line 76 of file THistogram.cxx.

References _all, _bins, _binSize, _links, _nBins, genRecEmupikp::i, and boss::pos.

Referenced by TFastFinder::doit().

00076                                              {
00077     _all = (AList<TMLink> &) links;
00078     unsigned nLinks = links.length();
00079     double offset = _binSize / 4.;
00080     for (unsigned i = 0; i < nLinks; i++) {
00081         TMLink * l = links[i];
00082         const HepPoint3D & p = l->position();
00083         unsigned pos = (unsigned) floor((p.x() + offset) / _binSize);
00084 
00085         //...Why is this needed?...
00086         pos %= _nBins;
00087 
00088         ++_bins[pos];
00089         _links[pos]->append(l);
00090     }
00091 }

void THistogram::fillY ( const AList< TMLink > &  links  ) 

fills with hits.

Definition at line 94 of file THistogram.cxx.

References _all, _bins, _binSize, _links, _nBins, genRecEmupikp::i, and boss::pos.

00094                                              {
00095     _all = (AList<TMLink> &) links;
00096     unsigned nLinks = links.length();
00097     for (unsigned i = 0; i < nLinks; i++) {
00098         TMLink * l = links[i];
00099         const HepPoint3D & p = l->position();
00100         unsigned pos = (unsigned) floor(p.y() / _binSize);
00101 
00102         //...Why is this needed?...
00103         pos %= _nBins;
00104 
00105         ++_bins[pos];
00106         _links[pos]->append(l);
00107     }
00108 }

void THistogram::mask ( unsigned  binN  )  [inline]

masks a bin. Masked bin will not be returned by findPeak.

Definition at line 142 of file THistogram.h.

References _masks.

00142                            {
00143     _masks[a] = true;
00144 }

unsigned THistogram::nBin ( unsigned  i  )  const [inline]

returns number in i'th bin.

Definition at line 160 of file THistogram.h.

References _bins, and _nBins.

00160                                  {
00161     if (i < _nBins) return _bins[i];
00162     return 0;
00163 }

unsigned THistogram::nBins ( void   )  const [inline]

returns # of bins.

Definition at line 136 of file THistogram.h.

References _nBins.

00136                             {
00137     return _nBins;
00138 }

void THistogram::remove ( const AList< TMLink > &  links  ) 

removes links.

Definition at line 134 of file THistogram.cxx.

References _all, _bins, _links, _nBins, and genRecEmupikp::i.

00134                                               {
00135     for (unsigned i = 0; i < _nBins; i++) {
00136         _links[i]->remove(links);
00137         _bins[i] = _links[i]->length();
00138     }
00139     _all.remove(links);
00140 }

AList< TSegment > THistogram::segments ( void   )  const

returns an AList<TSegment0> using clusters() function.

Definition at line 259 of file THistogram.cxx.

References clusters(), genRecEmupikp::i, and ganga-rec::j.

Referenced by TConformalFinder::findSegments().

00259                                {
00260   //yuany
00261   /*
00262   for (unsigned i = 0; i < _nBins; i++) {
00263       std::cout<<"i "<<i<<" bins[i] "<<_bins[i]<<std::endl;
00264     }
00265   */
00266     //...Obtain raw clusters...
00267     AList<TSegment> list = clusters();
00268     unsigned n = list.length();
00269     if (n == 0) return list;
00270 
00271     //...Examine each cluster...
00272     AList<TSegment> splitted;
00273     for (unsigned i = 0; i < n; i++) {
00274         TSegment * c = list[i];
00275 
00276 #ifdef TRKRECO_DEBUG_DETAIL
00277         std::cout << "    base segment : ";
00278         c->dump("hits");
00279 #endif
00280 
00281         AList<TSegment> newClusters = c->split();
00282         if (newClusters.length() == 0) {
00283 #ifdef TRKRECO_DEBUG_DETAIL
00284             std::cout << "    ... Solving dual hits" << std::endl;
00285 #endif
00286             c->solveDualHits();
00287             continue;
00288         }
00289 
00290         list.append(newClusters);
00291         splitted.append(c);
00292 #ifdef TRKRECO_DEBUG_DETAIL
00293         c->dump("hits", "    ");
00294         std::cout << "    ... splitted as" << std::endl;
00295         for (unsigned j = 0; j < newClusters.length(); j++) {
00296             std::cout << "    " << j << " : ";
00297             newClusters[j]->dump("hits");
00298         }
00299 #endif
00300     }
00301     list.remove(splitted);
00302     HepAListDeleteAll(splitted);
00303     
00304     //yuany
00305 //    n = list.length();
00306 //    for (unsigned i = 0; i < n; i++) {
00307 //      TSegment * c = list[i];
00308 //      std::cout << "    base segment : ";
00309 //      c->dump("hits");
00310 //    }
00311 
00312     return list;
00313 }

AList< TSegment0 > THistogram::segments0 ( void   )  const

returns an AList<TSegment0> using clusters() function.

Definition at line 192 of file THistogram.cxx.

References clusters0(), genRecEmupikp::i, and ganga-rec::j.

00192                                 {
00193 
00194     //...Obtain raw clusters...
00195     AList<TSegment0> list = clusters0();
00196     unsigned n = list.length();
00197     if (n == 0) return list;
00198 
00199     //...Examine each cluster...
00200     AList<TSegment0> splitted;
00201     for (unsigned i = 0; i < n; i++) {
00202         TSegment0 * c = list[i];
00203 
00204         AList<TSegment0> newClusters = c->split();
00205         if (newClusters.length() == 0) {
00206             c->solveDualHits();
00207             continue;
00208         }
00209 
00210         list.append(newClusters);
00211         splitted.append(c);
00212 #ifdef TRKRECO_DEBUG_DETAIL
00213         c->dump("hits", "    ");
00214         std::cout << "    ... splitted as" << std::endl;
00215         for (unsigned j = 0; j < newClusters.length(); j++) {
00216             std::cout << "    " << j << " : ";
00217             newClusters[j]->dump("hits");
00218         }
00219 #endif
00220     }
00221     list.remove(splitted);
00222     HepAListDeleteAll(splitted);
00223 
00224     return list;
00225 
00226 }

void THistogram::unmask ( void   )  [inline]

remove masks.

Definition at line 148 of file THistogram.h.

References _masks, _nBins, and genRecEmupikp::i.

00148                        {
00149     for (unsigned i = 0; i < _nBins; i++) _masks[i] = false;
00150 }


Member Data Documentation

AList<TMLink> THistogram::_all [private]

Definition at line 105 of file THistogram.h.

Referenced by contents(), fillPhi(), fillX(), fillY(), and remove().

unsigned* THistogram::_bins [private]

Definition at line 102 of file THistogram.h.

Referenced by clusters(), clusters0(), dump(), fillPhi(), fillX(), fillY(), nBin(), remove(), THistogram(), and ~THistogram().

float THistogram::_binSize [private]

Definition at line 106 of file THistogram.h.

Referenced by fillPhi(), fillX(), fillY(), and THistogram().

AList<TMLink>** THistogram::_links [private]

Definition at line 104 of file THistogram.h.

Referenced by bin(), clusters(), clusters0(), dump(), fillPhi(), fillX(), fillY(), remove(), THistogram(), and ~THistogram().

bool* THistogram::_masks [private]

Definition at line 103 of file THistogram.h.

Referenced by dump(), mask(), THistogram(), unmask(), and ~THistogram().

unsigned THistogram::_nBins [private]

Definition at line 101 of file THistogram.h.

Referenced by bin(), clusters(), clusters0(), dump(), fillPhi(), fillX(), fillY(), nBin(), nBins(), remove(), THistogram(), unmask(), and ~THistogram().


Generated on Tue Nov 29 23:36:00 2016 for BOSS_7.0.2 by  doxygen 1.4.7