Managed::ClusterManager Class Reference

#include <ClusterManager.h>

List of all members.

Public Member Functions

 ClusterManager ()
 ~ClusterManager ()
void MakeClusters (double min_cluster_e=0.4, double min_strip_e=0.4, double max_t_skip=0.025)
void Reset ()
void AddStrip (int myplane, int mystrip, double myenergy, double st, double sz, int view)
void LoadHits ()
std::vector< int > GetPlanes ()
std::vector< int > GetStrips (int plane)
Managed::ManagedClusterGetCluster (int cid)
Managed::ManagedClusterGetSavedCluster (int cid)
void SplitEnergy (Managed::ManagedCluster *cluster, double energy, int matchenergy)
int MergeClusters (int cid1, int cid2)
void FillClusterMap (std::map< double, std::map< double, std::pair< double, int > > > *cluster_map)
std::vector< int > FindClustersInZ (double z, int view)
std::map< double, std::map
< double, int > > * 
GetClusterMap (int view=0)
std::vector< int > GetViewIndex (int view)
void SetHitManager (Managed::HitManager *h)
HitManagerGetHitManager ()
void SetClusterSaver (Managed::ClusterSaver *cs)
Managed::ClusterSaverGetClusterSaver ()
void DumpClusters ()
int SaveCluster (int cluster_id, double energy_to_save=0, int status=0)
void ClearInUse ()
void MarkUsed (int id)

Public Attributes

std::map< double, std::map
< double, int > > 
cluster_map
std::map< double, std::map
< double, int > > 
cluster_map_u
std::map< double, std::map
< double, int > > 
cluster_map_v
std::vector
< Managed::ManagedCluster
clusters
double maxz
double minz
double maxu
double minu
double maxv
double minv

Private Member Functions

void EraseCluster (int cid)
void AdjustCluster (Managed::ManagedCluster *cluster)
 ClassDef (ClusterManager, 1)
void RebuildClusterMaps ()

Private Attributes

int clusters_are_made
std::map< int, std::map< int,
int > > 
loc_map
std::vector< ManagedHithits
HitManagerhitmanager
ClusterSaverclustersaver
int needMapRebuild
std::vector< int > inuse
std::vector< int > clusters_to_delete

Detailed Description

Definition at line 18 of file ClusterManager.h.


Constructor & Destructor Documentation

ClusterManager::ClusterManager (  ) 

Definition at line 13 of file ClusterManager.cxx.

00014 {
00015 
00016                 clusters_are_made=0;
00017                 
00018                 loc_map.clear();
00019                 cluster_map.clear();
00020                 cluster_map_u.clear();
00021                 cluster_map_v.clear();
00022                 hits.clear();
00023                 clusters.clear();       
00024                 
00025                 clusters_to_delete.clear();
00026                 
00027                 minu=100000;
00028                 maxu=-100000;
00029                 minv=100000;
00030                 maxv=-100000;
00031                 minz=100000;
00032                 maxz=-100000;
00033                 clustersaver=0;
00034                 
00035                 hitmanager=0;
00036                 
00037                 needMapRebuild=0;
00038 
00039 }

ClusterManager::~ClusterManager (  ) 

Definition at line 317 of file ClusterManager.cxx.

00318 {}


Member Function Documentation

void ClusterManager::AddStrip ( int  myplane,
int  mystrip,
double  myenergy,
double  st,
double  sz,
int  view 
)

Definition at line 779 of file ClusterManager.cxx.

References hits, loc_map, maxu, maxv, maxz, minu, minv, and minz.

00780 {
00781         ManagedHit h(view,myplane,mystrip,sz,st,myenergy);
00782         
00783         hits.push_back(h);
00784         loc_map[myplane][mystrip]=hits.size()-1;
00785         
00786         
00787         minz=minz < sz ? minz : sz;
00788         maxz=maxz > sz ? maxz : sz;
00789 
00790 
00791 
00792                         if(view==2)
00793                         {
00794                                 minu=minu < st ? minu : st;
00795                                 maxu=maxu > st ? maxu : st;
00796                         }else if(view==3)
00797                         {
00798                                 minv=minv < st ? minv : st;
00799                                 maxv=maxv > st ? maxv : st;                     
00800                         }
00801 
00802         
00803 }

void ClusterManager::AdjustCluster ( Managed::ManagedCluster cluster  )  [private]

Definition at line 213 of file ClusterManager.cxx.

References clusters_to_delete, Managed::ManagedCluster::e, MuELoss::e, Managed::ManagedCluster::Finalize(), Managed::HitManager::FindHit(), GetCluster(), Managed::ManagedCluster::hit_id, Managed::ManagedCluster::hite, hitmanager, Managed::ManagedCluster::id, Msg::kDebug, MSG, and Managed::ManagedHit::SetEnergy().

Referenced by SaveCluster().

00214 {
00215         if(!cluster)return;
00216         ManagedCluster * current_cluster = GetCluster(cluster->id);
00217         if(!current_cluster)return;
00218         
00219         MSG("ClusterManager",Msg::kDebug)<<"cluster e "<<cluster->e<<" curcluster "<<current_cluster->e<<"\n";
00220         
00221         //is the passed object a part of the current cluster vector, or was it copied?
00222         //if its copied, make sure it gets copied back into the version in the vector
00223 //      if(fabs(cluster->e - current_cluster->e)<1e-9)
00224 //              return;
00225         
00226         //now we need to update the hits!
00227         int modified_cluster=0;
00228         for(unsigned int i=0;i<cluster->hit_id.size();i++)
00229         {
00230                 ManagedHit * hit = hitmanager->FindHit(cluster->hit_id[i]);
00231                 
00232                 double setenergy = 0;
00233                 if(hit)setenergy = hit->SetEnergy(cluster->hite[i]);
00234                 
00235                 MSG("ClusterManager",Msg::kDebug)<<"setting energy to "<<cluster->hite[i]<<" and it set "<<setenergy<<"\n";
00236                 if(fabs(setenergy-current_cluster->hite[i])>1e-9)
00237                 {
00238                         MSG("ClusterManager",Msg::kDebug)<<"modifying cluster\n";
00239                         current_cluster->hite[i]=setenergy;
00240                         modified_cluster=1;
00241                 }
00242         }
00243                 
00244         if(modified_cluster)current_cluster->Finalize();
00245         
00246         if(current_cluster->e<0.001)clusters_to_delete.push_back(current_cluster->id);
00247 
00248 }

Managed::ClusterManager::ClassDef ( ClusterManager  ,
 
) [private]
void Managed::ClusterManager::ClearInUse (  )  [inline]

Definition at line 74 of file ClusterManager.h.

References inuse.

Referenced by PrimaryShowerFinder::MakeChains().

00074 {inuse.clear();};

void ClusterManager::DumpClusters (  ) 

Definition at line 321 of file ClusterManager.cxx.

References cluster_map, cluster_map_u, cluster_map_v, Managed::ManagedCluster::dt, Managed::ManagedCluster::dz, Managed::ManagedCluster::e, GetCluster(), Msg::kInfo, MSG, Managed::ManagedCluster::t, Managed::ManagedCluster::view, and Managed::ManagedCluster::z.

Referenced by Finder::Process().

00322 {
00323         ostringstream os;
00324 
00325         std::map<double, std::map<double, int> >::iterator p_iter;
00326         std::map<double, int>::iterator s_iter;
00327 
00328         os<<"dumping clusters (all)...\n";
00329            
00330         for(p_iter=cluster_map.begin();p_iter!=cluster_map.end(); p_iter++)
00331         {
00332                 std::map<double, int>::iterator s_iter;
00333                 for(s_iter=p_iter->second.begin();s_iter!=p_iter->second.end(); s_iter++)
00334                 {
00335                         ManagedCluster *mc = GetCluster(s_iter->second);
00336                         if(!mc){
00337                                 os<<"missing cluster id "<<s_iter->second<<"\n";
00338                                 continue;
00339                         }
00340                         os<<"id "<<s_iter->second<<"   z "<<mc->z<<" t "<<mc->t<<" e "<<mc->e<<" dz "<<mc->dz<<" dt "<<mc->dt<<" view "<<mc->view<<"\n";
00341                 
00342         
00343                 }
00344         }
00345 
00346 
00347         os<<"dumping clusters (u)...\n";
00348            
00349         for(p_iter=cluster_map_u.begin();p_iter!=cluster_map_u.end(); p_iter++)
00350         {
00351                 std::map<double, int>::iterator s_iter;
00352                 for(s_iter=p_iter->second.begin();s_iter!=p_iter->second.end(); s_iter++)
00353                 {
00354                         ManagedCluster *mc = GetCluster(s_iter->second);
00355                         if(!mc){
00356                                 os<<"missing cluster id "<<s_iter->second<<"\n";
00357                                 continue;
00358                         }
00359                         os<<"z "<<mc->z<<" t "<<mc->t<<" e "<<mc->e<<" dz "<<mc->dz<<" dt "<<mc->dt<<" view "<<mc->view<<"\n";
00360                         os<<"id "<<s_iter->second<<"\n";
00361         
00362                 }
00363         }
00364         
00365         os<<"dumping clusters (v)...\n";
00366            
00367         for(p_iter=cluster_map_v.begin();p_iter!=cluster_map_v.end(); p_iter++)
00368         {
00369                 std::map<double, int>::iterator s_iter;
00370                 for(s_iter=p_iter->second.begin();s_iter!=p_iter->second.end(); s_iter++)
00371                 {
00372                         ManagedCluster *mc = GetCluster(s_iter->second);
00373                         if(!mc){
00374                                 os<<"missing cluster id "<<s_iter->second<<"\n";
00375                                 continue;
00376                         }
00377                         os<<"z "<<mc->z<<" t "<<mc->t<<" e "<<mc->e<<" dz "<<mc->dz<<" dt "<<mc->dt<<" view "<<mc->view<<"\n";
00378                         os<<"id "<<s_iter->second<<"\n";
00379         
00380                 }
00381         }
00382         
00383         
00384         os<<"done....\n\n";
00385         
00386         
00387         MSG("ClusterManager",Msg::kInfo)<<os;
00388 }

void ClusterManager::EraseCluster ( int  cid  )  [private]

Definition at line 907 of file ClusterManager.cxx.

References cluster_map, cluster_map_u, cluster_map_v, clusters, done(), it, Msg::kDebug, and MSG.

Referenced by MergeClusters().

00908 {
00909 
00910         MSG("ClusterManager",Msg::kDebug)<<"erasing "<<cid<<"\n";
00911 
00912     std::map<double, std::map<double, int> >::iterator p_iterr;
00913     std::map<double, int >::iterator s_iterr;
00914         for(p_iterr=cluster_map.begin();p_iterr!=cluster_map.end(); p_iterr++)
00915     {   
00916         int done =0;
00917         for(s_iterr=p_iterr->second.begin();s_iterr!=p_iterr->second.end(); s_iterr++)
00918         {
00919                 if(s_iterr->second==cid)
00920                 {
00921                         p_iterr->second.erase(s_iterr);
00922                         done=1;
00923                         break;
00924                         }
00925                 }
00926                 if(done)break;
00927         }       
00928 
00929         for(p_iterr=cluster_map_u.begin();p_iterr!=cluster_map_u.end(); p_iterr++)
00930     {   
00931         int done =0;
00932         for(s_iterr=p_iterr->second.begin();s_iterr!=p_iterr->second.end(); s_iterr++)
00933         {
00934                 if(s_iterr->second==cid)
00935                 {
00936                         p_iterr->second.erase(s_iterr);
00937                         done=1;
00938                         break;
00939                         }
00940                 }
00941                 if(done)break;
00942         }       
00943         
00944         for(p_iterr=cluster_map_v.begin();p_iterr!=cluster_map_v.end(); p_iterr++)
00945     {   
00946         int done =0;
00947         for(s_iterr=p_iterr->second.begin();s_iterr!=p_iterr->second.end(); s_iterr++)
00948         {
00949                 if(s_iterr->second==cid)
00950                 {
00951                         p_iterr->second.erase(s_iterr);
00952                         done=1;
00953                         break;
00954                         }
00955                 }
00956                 if(done)break;
00957         }       
00958 
00959         
00960         std::vector<Managed::ManagedCluster>::iterator it;
00961         for(it=clusters.begin();it!=clusters.end();it++)
00962         {
00963                 if(it->id==cid)
00964                 {
00965                         clusters.erase(it);
00966                         break;
00967                 }
00968         }
00969 
00970 }

void ClusterManager::FillClusterMap ( std::map< double, std::map< double, std::pair< double, int > > > *  cluster_map  ) 

Definition at line 975 of file ClusterManager.cxx.

References clusters.

Referenced by Finder::Process().

00976 {
00977         for(unsigned int i=0;i<clusters.size();i++)
00978         {
00979                 (*cluster_map)[clusters[i].z][clusters[i].t]=std::pair<double,int>(clusters[i].e, clusters[i].view);
00980         }
00981 
00982 }

std::vector< int > ClusterManager::FindClustersInZ ( double  z,
int  view = 0 
)

Definition at line 44 of file ClusterManager.cxx.

References cluster_map, cluster_map_u, cluster_map_v, and it.

Referenced by PrimaryShowerFinder::ExpandShowerChain().

00045 {
00046         double planedist = 0.04;
00047         
00048         
00049         std::map<double, std::map<double, int>  >*cmap = 0;
00050         if(view==2)cmap=&cluster_map_u;
00051         else if(view==3)cmap=&cluster_map_v;
00052         else cmap=&cluster_map;
00053         
00054         std::map<double, std::map<double, int>  >::iterator it = cmap->lower_bound(z-planedist);
00055         
00056         std::vector<int> rec;
00057         for(;it!=cmap->end();it++)
00058         {
00059                 if(it->first > z+planedist)break;
00060                 std::map<double, int>::iterator s_iter;
00061                 for(s_iter=it->second.begin();s_iter!=it->second.end(); s_iter++)
00062                 {
00063                         rec.push_back(s_iter->second);
00064                 }       
00065         
00066         }
00067 
00068         return rec;
00069 }

Managed::ManagedCluster * ClusterManager::GetCluster ( int  cid  ) 
std::map< double, std::map< double, int > > * ClusterManager::GetClusterMap ( int  view = 0  ) 
Managed::ClusterSaver* Managed::ClusterManager::GetClusterSaver (  )  [inline]

Definition at line 68 of file ClusterManager.h.

References clustersaver.

Referenced by LongMuonFinder::MakeParticle3D().

00068 {return clustersaver;};

HitManager* Managed::ClusterManager::GetHitManager (  )  [inline]

Definition at line 65 of file ClusterManager.h.

References hitmanager.

00065 {return hitmanager;};

std::vector<int> Managed::ClusterManager::GetPlanes (  ) 
Managed::ManagedCluster * ClusterManager::GetSavedCluster ( int  cid  ) 

Definition at line 856 of file ClusterManager.cxx.

References clustersaver, and Managed::ClusterSaver::GetCluster().

Referenced by LongMuonFinder::FindLongMuon().

00857 {
00858         return clustersaver->GetCluster(cid);
00859 }

std::vector<int> Managed::ClusterManager::GetStrips ( int  plane  ) 
std::vector< int > ClusterManager::GetViewIndex ( int  view  ) 

Definition at line 306 of file ClusterManager.cxx.

References clusters.

Referenced by Finder::FindNeutrons().

00307 {
00308         std::vector<int> ret;
00309         
00310         for(unsigned int i=0;i<clusters.size();i++)
00311                 if(clusters[i].view==view)ret.push_back(i);
00312                 
00313         return ret;
00314 
00315 }

void ClusterManager::LoadHits (  ) 

Definition at line 742 of file ClusterManager.cxx.

References Managed::HitManager::GetAvailableHits(), hitmanager, hits, loc_map, maxu, maxv, maxz, minu, minv, minz, and Reset().

Referenced by MakeClusters().

00743 {
00744         if(!hitmanager)return;
00745         Reset();
00746         
00747         std::vector<ManagedHit> avail_hits = hitmanager->GetAvailableHits();
00748         
00749         for(unsigned int i=0;i<avail_hits.size();i++)
00750         {
00751                         
00752                         hits.push_back(avail_hits[i]);
00753                         loc_map[avail_hits[i].GetPlane()][avail_hits[i].GetStrip()]=hits.size()-1;
00754         
00755                         double sz = avail_hits[i].GetZ();
00756                         double st = avail_hits[i].GetT();
00757                         
00758                         minz=minz < sz ? minz : sz;
00759                         maxz=maxz > sz ? maxz : sz;
00760                         
00761                         int view=avail_hits[i].GetView();
00762                         if(view==2)
00763                         {
00764                                 minu=minu < st ? minu : st;
00765                                 maxu=maxu > st ? maxu : st;
00766                         }else if(view==3)
00767                         {
00768                                 minv=minv < st ? minv : st;
00769                                 maxv=maxv > st ? maxv : st;                     
00770                         }
00771         }
00772 
00773 }

void ClusterManager::MakeClusters ( double  min_cluster_e = 0.4,
double  min_strip_e = 0.4,
double  max_t_skip = 0.025 
)

Definition at line 393 of file ClusterManager.cxx.

References Managed::ManagedCluster::AdvanceID(), cluster_map, cluster_map_u, cluster_map_v, clusters, Managed::ManagedCluster::e, MuELoss::e, Managed::ManagedCluster::Finalize(), hitmanager, hits, Managed::ManagedCluster::hitt, Managed::ManagedCluster::id, Managed::ManagedCluster::Insert(), it, Msg::kDebug, LoadHits(), loc_map, Munits::m, MSG, Managed::ManagedCluster::Reset(), Managed::ManagedCluster::ResetIDCounter(), and Managed::ManagedCluster::view.

Referenced by Finder::Process().

00394 {
00395 
00396         //see if we have hits
00397         if(hits.size()==0 && hitmanager==0)return;
00398         
00399         LoadHits();
00400 
00401         
00402         if(hits.size()==0)return;
00403 
00406 
00407 //      double thresh=0.4; ///for a cluster
00408 //      double sthresh=0.4;//for an individual strip   0.2 mips ~ 1 pe   
00409                                                 // roughly gaussian 7.361 w/ rms 1.252 pe/mip - lowest bin is 5 pe/mip
00410         //int skip=1;   
00411 //      double skipt=0.05; //strip width is 0.025?
00412 
00413         
00414         double thresh=min_cluster_e;
00415         double sthresh=min_strip_e;
00416         double skipt=max_t_skip;
00417 
00418 
00419 
00420         std::vector<ManagedCluster> theclusters;
00421 
00422 
00423         std::map<int, std::map<int, int> >::iterator p_iter;
00424         std::map<int, int>::iterator s_iter;
00425         double loc_z=-1;
00426 
00427         //int last_strip=-1;
00428         int numstrip=0;
00429         double sum_e_t=0;
00430         double sum_e=0; 
00431         double lastt=-100000.0;
00432         int thisview=0;
00433            
00434         ManagedCluster c;  
00435         c.ResetIDCounter();
00436         c.AdvanceID();
00437          
00438          
00439         // cout <<"idcounter 1 " <<c.idcounter<< " "<<c.id<<endl;
00440            
00441            
00442         for(p_iter=loc_map.begin();p_iter!=loc_map.end(); p_iter++)
00443         {
00444                 std::map<int, int>::iterator s_iter;
00445                 for(s_iter=p_iter->second.begin();s_iter!=p_iter->second.end(); s_iter++)
00446                 {
00447                         if(hits[s_iter->second].GetERemaining()<sthresh)continue;
00448                         if(numstrip==0) lastt=hits[s_iter->second].GetT();
00449 
00450                         if((fabs(hits[s_iter->second].GetT()-lastt)>skipt|| loc_z!=hits[s_iter->second].GetZ()) && numstrip>0)
00451                         {  //we have finished with this cluster, so record it and reset info
00452                                 sum_e_t/=sum_e;  //weighted average t
00453                                 if(thresh<sum_e)
00454                                 {
00455 
00456                                         cluster_map[loc_z][sum_e_t]=c.id;
00457                                         if(thisview==2)cluster_map_u[loc_z][sum_e_t]=c.id;
00458                                         if(thisview==3)cluster_map_v[loc_z][sum_e_t]=c.id;
00459                                                                                 
00460                                         c.Finalize();
00461                                         theclusters.push_back(c);
00462 
00463                                 }
00464 
00465 
00466 
00467                                 //printf("----cluster at %f %f %f %d   id %d\n\n", loc_z, sum_e_t,sum_e, thisview,c.id);
00468 
00469                                 sum_e_t=0;
00470                                 sum_e=0;
00471                                 //   loc_z=-1;
00472                                 numstrip=0;     
00473                                 thisview=0;
00474                                 c.Reset();
00475                                 c.AdvanceID();
00476                                 
00477                                    // cout <<"idcounter 2 " <<c.idcounter<< " "<<c.id<<endl;
00478                                         
00479                                 if(loc_z!=hits[s_iter->second].GetZ())
00480                                 {
00481                                         lastt=-100000.0;
00482                                 
00483                                 }
00484                                 //last_strip=-1;
00485                         }
00486 
00487 
00488 
00489                         
00490             loc_z=hits[s_iter->second].GetZ();
00491                         lastt=hits[s_iter->second].GetT();
00492                         //last_strip=s_iter->first;
00493                         numstrip++;
00494                         sum_e+=hits[s_iter->second].GetERemaining();
00495                         sum_e_t+=hits[s_iter->second].GetERemaining()*hits[s_iter->second].GetT();
00496                         thisview=hits[s_iter->second].GetView();
00497                         c.view=hits[s_iter->second].GetView();
00498                         c.Insert(hits[s_iter->second].GetZ(),hits[s_iter->second].GetT(),hits[s_iter->second].GetERemaining(),hits[s_iter->second].GetPlane(),hits[s_iter->second].GetStrip(),hits[s_iter->second].GetID());
00499 
00500 
00501 
00502                         //printf("%d - %d %d %f %f %f %d\n",numstrip,p_iter->first, s_iter->first, hits[s_iter->second].GetERemaining(),hits[s_iter->second].GetZ(),hits[s_iter->second].GetT(),hits[s_iter->second].GetView());
00503                  }
00504         }
00505         //get the last cluster///
00506         
00507         if(numstrip>0)
00508         {
00509                 sum_e_t/=sum_e;  //weighted average t
00510         if(thresh<sum_e)
00511         {
00512                 cluster_map[loc_z][sum_e_t]=c.id;
00513                         if(thisview==2)cluster_map_u[loc_z][sum_e_t]=c.id;
00514                         if(thisview==3)cluster_map_v[loc_z][sum_e_t]=c.id;
00515                 
00516                 c.Finalize();
00517                         theclusters.push_back(c);
00518                 }
00519         
00520         }
00521         MSG("ClusterManager",Msg::kDebug)<<"----cluster at "<< loc_z<<" "<<sum_e_t<<" "<<sum_e<<" "<<thisview<<" id "<<c.id<<"\n";
00522         
00523         /*
00524         //uncomment this to bypass the sharing
00525 
00526         for(unsigned int k=0;k<theclusters.size();k++)  
00527         {
00528                 theclusters[k].Finalize();
00529                 clusters.push_back(theclusters[k]);
00530         }
00531 
00532         return;
00533         */
00535         
00536         c.Reset();
00537         c.AdvanceID();
00538                                         
00539         //cout <<"idcounter 3 " <<c.idcounter<< " "<<c.id<<endl;
00540 
00541             
00542         std::vector<ManagedCluster> tmponepeak;
00543         std::vector<ManagedCluster> tmpmultpeak;
00544         //go through clusters, looking for multiple peaks....
00545         for(unsigned int k=0;k<theclusters.size();k++)  
00546         {
00547                 std::map<double,int>::iterator it;
00548                 it=theclusters[k].tsortmap.begin();
00549         
00550                 int npeak=0;
00551 
00552                 
00553 
00554                 std::vector<int> maxidx;
00555                 std::vector<double> maxe;
00556                 
00557                 std::vector<int> sortedidx;
00558                 std::vector<double> sortede;
00559                 
00560                 MSG("ClusterManager",Msg::kDebug)<<"clu idx "<< k<<" id "<<theclusters[k].id <<" with "<<(int)theclusters[k].hite.size() <<" hits \n";
00561 
00562                 if(theclusters[k].hite.size()==1)
00563                 {
00564                         theclusters[k].Finalize();
00565         
00566                         if(theclusters[k].e>0.001)
00567                                 tmponepeak.push_back(theclusters[k]);
00568                         continue;
00569 
00570                 
00571                 }
00572 
00573 
00574 
00575                 
00577                 int plastidx=-1;
00578                 double plaste=0;
00579                 int lastidx=it->second;
00580                 double laste = theclusters[k].hite[it->second];
00581                                         
00582                 MSG("ClusterManager",Msg::kDebug)<<"\t z "<<theclusters[k].hitz[it->second]<<" t "<<theclusters[k].hitt[it->second]<<" e "<<theclusters[k].hite[it->second]<<"\n";
00583 
00584                 it++;           
00585                 for(;it!=theclusters[k].tsortmap.end();it++)
00586                 {
00587                 
00588                         double e=theclusters[k].hite[it->second];
00589                         
00590                         MSG("ClusterManager",Msg::kDebug)<<"\t z "<<theclusters[k].hitz[it->second]<<" t "<<theclusters[k].hitt[it->second]<<" e "<<theclusters[k].hite[it->second]<<"\n";
00591                         
00592                         if(  e < laste&&(laste>plaste || plastidx<0) )
00593                         {       
00594                                 maxidx.push_back(lastidx);
00595                                 maxe.push_back(laste);
00596                                 MSG("ClusterManager",Msg::kDebug)<<"\t\tpeak e "<<laste<<"\n";
00597                                 npeak++;                        
00598                         }else{
00599                                 //these hits needs to be shared!
00600                                 sortedidx.push_back(lastidx);
00601                                 sortede.push_back(laste);
00602                         }
00603                         plaste=laste;
00604                         plastidx=lastidx;
00605                         laste=e;
00606                         lastidx=it->second;
00607                                         
00608                 }               
00609                         
00610                 //last hit
00611                 if(plastidx>-1 && laste>plaste)
00612                 {
00613                         maxidx.push_back(lastidx);
00614                         maxe.push_back(laste);
00615                         MSG("ClusterManager",Msg::kDebug)<<"\t\tpeak e "<<laste<<"\n";
00616                         npeak++;
00617                 }else{
00618                         //these hits needs to be shared!
00619                         sortedidx.push_back(lastidx);
00620                         sortede.push_back(laste);               
00621                 }
00622                 
00623                 
00625                 
00626                 
00627                 
00628                 
00629                 
00630                 
00631                 
00632                 MSG("ClusterManager",Msg::kDebug)<<"cluster "<<theclusters[k].id<< " npeak "<<npeak<<"\n";
00633                 
00634                 if(npeak<2) //1 hit cluster will have 0 peaks!
00635                 {
00636                         theclusters[k].Finalize();
00637         
00638                         if(theclusters[k].e>0.001)
00639                                 tmponepeak.push_back(theclusters[k]);
00640                         continue;
00641                 }
00642                 
00643                 
00644                 
00645                 //split up the cluster!
00646                 for(unsigned int i=0;i<maxidx.size();i++)
00647                 {
00648                         c.Reset();
00649                         c.AdvanceID();
00650                 
00651                     //cout <<"idcounter 4 " <<c.idcounter<< " "<<c.id<<endl;
00652                 
00653                         double t=theclusters[k].hitt[maxidx[i]];
00654                         double z=theclusters[k].hitz[maxidx[i]];
00655                         double maxe=theclusters[k].hite[maxidx[i]];
00656                         int plane=theclusters[k].hitplane[maxidx[i]];
00657                         int strip=theclusters[k].hitstrip[maxidx[i]];
00658                         int hitid=theclusters[k].hit_id[maxidx[i]];
00659 
00660                         MSG("ClusterManager",Msg::kDebug)<<"filling m "<<z<<" "<<t<<" "<<maxe<<" "<<plane<<" "<<strip<<"\n";
00661 
00662                         c.Insert(z, t, maxe, plane, strip, hitid);
00663                 
00664                         for(unsigned int j=0;j<sortedidx.size();j++)
00665                         {
00666                 
00667                                 //calculate normalizing denominator....
00668                                 double denom=0;
00669                                 for(unsigned int m=0;m<maxidx.size();m++)
00670                                 {
00671                                         double maxt=theclusters[k].hitt[maxidx[m]];
00672                                         double sortedt=theclusters[k].hitt[sortedidx[j]];
00673                 
00674                                         denom+=theclusters[k].hite[maxidx[m]]/ ( (maxt-sortedt) * (maxt-sortedt) );
00675                                 }               
00676                 
00677                 
00678                 
00679                                 double st = theclusters[k].hitt[sortedidx[j]];
00680                                 double e= sortede[j];// / ( (st - t ) * (st -t) );
00681                                 e*=maxe/((t-theclusters[k].hitt[sortedidx[j]]) * (t-theclusters[k].hitt[sortedidx[j]]))/denom;
00682                                 
00683                                         double t=theclusters[k].hitt[sortedidx[j]];
00684                                         double z=theclusters[k].hitz[sortedidx[j]];
00685                                         int plane=theclusters[k].hitplane[sortedidx[j]];
00686                                         int strip=theclusters[k].hitstrip[sortedidx[j]];
00687                                         int hitid=theclusters[k].hit_id[sortedidx[j]];
00688                                                                         
00689                                         MSG("ClusterManager",Msg::kDebug)<<"filling s "<<z<<" "<<t<<" "<<plane<<" "<<strip<<" --- "<<st<<" --- "<<maxe/denom<<" tot "<<sortede[j]<<" used "<<e<<"\n";
00690                                 
00691                                 if(e>0.001)
00692                                 {
00693                                         c.Insert(z, t, e, plane, strip,hitid);
00694                                 }
00695                         }
00696                         
00697                         c.view = theclusters[k].view;
00698                         c.Finalize();
00699                         
00700                         if(c.hitt.size()>0 && c.e>0.001)
00701                         {
00702                                 tmponepeak.push_back(c);
00703                                 MSG("ClusterManager",Msg::kDebug)<<"new cluster stored with size "<<c.hitt.size()<<" e "<<c.e<<" in view "<<c.view<<"\n";
00704                         }
00705                 }
00706         
00707         }
00708         
00709 
00710         
00711         
00712         cluster_map.clear();
00713         cluster_map_u.clear();
00714         cluster_map_v.clear();
00715         
00716         for(unsigned int k=0;k<tmponepeak.size();k++)
00717         {
00718                 cluster_map[tmponepeak[k].z][tmponepeak[k].t]=tmponepeak[k].id;
00719                 tmponepeak[k].Finalize();
00720                 clusters.push_back(tmponepeak[k]);
00721                 if(tmponepeak[k].view==2)cluster_map_u[tmponepeak[k].z][tmponepeak[k].t]=tmponepeak[k].id;
00722                 if(tmponepeak[k].view==3)cluster_map_v[tmponepeak[k].z][tmponepeak[k].t]=tmponepeak[k].id;
00723                 MSG("ClusterManager",Msg::kDebug)<<"saving cluster id "<<tmponepeak[k].id<<"\n";
00724                 
00725                 
00726         //      minz=minz < tmponepeak[k].GetZ() ? minz : tmponepeak[k].GetZ();
00727         //      maxz=maxz > tmponepeak[k].GetZ() ? maxz : tmponepeak[k].GetZ();
00728         //      mint=mint < tmponepeak[k].GetT() ? mint : tmponepeak[k].GetT();
00729         //      maxt=maxt > tmponepeak[k].GetT() ? maxt : tmponepeak[k].GetT();
00730                 
00731                 
00732                 
00733         }
00734         
00735         //printf("ClusterManager dimensions z,t %f %f z,t %f %f\n",minz,mint, maxz,maxt);
00736         
00737 }

void Managed::ClusterManager::MarkUsed ( int  id  )  [inline]

Definition at line 76 of file ClusterManager.h.

References inuse.

Referenced by PrimaryShowerFinder::MakeChains().

00076 {inuse.push_back(id);};

int ClusterManager::MergeClusters ( int  cid1,
int  cid2 
)

Definition at line 863 of file ClusterManager.cxx.

References cluster_map, cluster_map_u, cluster_map_v, clusters, EraseCluster(), Managed::ManagedCluster::Finalize(), GetCluster(), Managed::ManagedCluster::hit_id, Managed::ManagedCluster::hite, Managed::ManagedCluster::hitplane, Managed::ManagedCluster::hitstrip, Managed::ManagedCluster::hitt, Managed::ManagedCluster::hitz, Managed::ManagedCluster::id, Managed::ManagedCluster::Insert(), Msg::kDebug, MSG, Managed::ManagedCluster::t, Managed::ManagedCluster::view, and Managed::ManagedCluster::z.

Referenced by LongMuonFinder::MergeChainClusters().

00864 {
00865         ManagedCluster *c1 = GetCluster(cid1);
00866         ManagedCluster *c2 = GetCluster(cid2);
00867         
00868         if(!c1 && c2)return cid2;
00869         if(!c2 && c1)return cid1;
00870         if(!c1 && !c2)return -1;
00871         
00872         
00873         ManagedCluster newcluster;
00874         MSG("ClusterManager",Msg::kDebug)<<"merging "<<cid1<<" "<<cid2<< " making "<<newcluster.id<<"\n";
00875         
00876         //copy over the old hits...
00877         for(unsigned int i=0;i<c1->hit_id.size();i++)
00878                 newcluster.Insert(c1->hitz[i],c1->hitt[i],c1->hite[i],c1->hitplane[i],c1->hitstrip[i],c1->hit_id[i]);
00879         for(unsigned int i=0;i<c2->hit_id.size();i++)
00880                 newcluster.Insert(c2->hitz[i],c2->hitt[i],c2->hite[i],c2->hitplane[i],c2->hitstrip[i],c2->hit_id[i]);
00881 
00882 //      printf("%d %d\n",c1->id,c2->id);
00883 
00884 
00885         //the pointers c1 and c2 seem to be disrupted by the assignment of the newcluster to the maps... why?
00886         //because the pointers are into a vector... which has its elements shifted!
00887         
00888         EraseCluster(cid1);
00889         EraseCluster(cid2);
00890                 
00891         cluster_map[newcluster.z][newcluster.t]=newcluster.id;
00892         newcluster.Finalize();
00893         clusters.push_back(newcluster);
00894         if(newcluster.view==2)cluster_map_u[newcluster.z][newcluster.t]=newcluster.id;
00895         if(newcluster.view==3)cluster_map_v[newcluster.z][newcluster.t]=newcluster.id;
00896 
00897 
00898         
00899 
00900 
00901         return newcluster.id;
00902 }

void ClusterManager::RebuildClusterMaps (  )  [private]

Definition at line 88 of file ClusterManager.cxx.

References cluster_map, cluster_map_u, cluster_map_v, clusters, clusters_to_delete, and needMapRebuild.

Referenced by GetClusterMap().

00089 {
00090 
00091 
00092         if(clusters_to_delete.size()>0)
00093         {
00094                 std::vector<Managed::ManagedCluster> cluster_temp;
00095                 for(unsigned int i=0;i<clusters.size();i++)
00096                 {
00097                         int keep=1;
00098                         for(unsigned int j=0;j<clusters_to_delete.size();j++)
00099                         {
00100                                 if(clusters_to_delete[j]==clusters[i].id)
00101                                 {
00102                                         keep=0;
00103                                         break;
00104                                 }
00105                         }
00106                         if(!keep)continue;
00107                         
00108                         cluster_temp.push_back(clusters[i]);
00109                 }
00110         
00111                 clusters=cluster_temp;
00112                 cluster_temp.clear();
00113                 clusters_to_delete.clear();
00114         }
00115 
00116         cluster_map.clear();
00117         cluster_map_u.clear();
00118         cluster_map_v.clear();
00119 
00120         for(unsigned int i=0;i<clusters.size();i++)
00121         {
00122                 cluster_map[clusters[i].z][clusters[i].t]=clusters[i].id;
00123                 if(clusters[i].view==2)cluster_map_u[clusters[i].z][clusters[i].t]=clusters[i].id;
00124                 if(clusters[i].view==3)cluster_map_v[clusters[i].z][clusters[i].t]=clusters[i].id;                                                              
00125         }
00126 
00127         needMapRebuild=0;
00128 }

void ClusterManager::Reset (  ) 

Definition at line 807 of file ClusterManager.cxx.

References cluster_map, cluster_map_u, cluster_map_v, clusters, clusters_are_made, clusters_to_delete, hits, inuse, loc_map, maxu, maxv, maxz, minu, minv, minz, and needMapRebuild.

Referenced by LoadHits().

00808 {
00809                 clusters_are_made=0;
00810                 
00811                 loc_map.clear();
00812                 cluster_map.clear();
00813                 cluster_map_u.clear();
00814                 cluster_map_v.clear();
00815                 hits.clear();
00816                 clusters.clear();
00817                 
00818                 minu=100000;
00819                 maxu=-100000;
00820                 minv=100000;
00821                 maxv=-100000;
00822                 minz=100000;
00823                 maxz=-100000;
00824                 
00825                 needMapRebuild=0;
00826                 clusters_to_delete.clear();
00827                 
00828                 inuse.clear();
00829 }

int ClusterManager::SaveCluster ( int  cluster_id,
double  energy_to_save = 0,
int  status = 0 
)

Definition at line 132 of file ClusterManager.cxx.

References AdjustCluster(), clustersaver, Managed::ManagedCluster::e, GetCluster(), hitmanager, needMapRebuild, Managed::ClusterSaver::SaveCluster(), Managed::ManagedCluster::SetStatus(), and SplitEnergy().

Referenced by LongMuonFinder::FindLongMuon(), PrimaryShowerFinder::FindPrimaryShower(), and Finder::Weave().

00133 {
00134         if(cluster_id<0)
00135         {
00136 //              printf("!!!! attempt to save an already saved cluster!\n");
00137                 return cluster_id;//its already a saved cluster!
00138         }
00139         //tell them we need a new map because we may be removing clusters....
00140         needMapRebuild=1;
00141 
00142         ManagedCluster *cluster = GetCluster(cluster_id);
00143         
00144         if(!cluster)return 0;
00145         
00147         //allow the ability to fake a save cluster for tempory work
00148         if(!clustersaver)
00149         {
00150 //              printf("SAVING WITHOUT SAVER!\n");
00151                 //can only allocation the full energy in the cluster...
00152                 if(energy_to_save-cluster->e >= 0)
00153                 {
00154 //                      printf("setting e to 0, was %f\n",cluster->e);
00155                         SplitEnergy(cluster,cluster->e,0);
00156                         if(hitmanager)AdjustCluster(cluster);
00157                         return 0;
00158                 
00159                 }       
00160                 
00161                         SplitEnergy(cluster,energy_to_save,0);
00162                         if(hitmanager)AdjustCluster(cluster);
00163         
00164                 return 0;
00165         }
00167         
00168         
00169         
00170 
00171         //can only allocation the full energy in the cluster...
00172         if(energy_to_save-cluster->e >= 0 || energy_to_save==0)
00173         {
00174                 energy_to_save=cluster->e;
00175                 int newid= clustersaver->SaveCluster(cluster);
00176                 ManagedCluster *newcluster=GetCluster(newid);
00177                 if(newcluster)
00178                 {
00179                         newcluster->SetStatus(status);
00180                         SplitEnergy(cluster,newcluster->e,0);
00181                 }else{
00182                         SplitEnergy(cluster,0,0);//throw away a cluster since the new cluster can't be made... probably because the old cluster had 0 e anyways.
00183                 }
00184                 AdjustCluster(cluster);
00185                 
00186         //      if(newcluster)printf("saving full cluster with e %f  old has %f\n",newcluster->e,cluster->e);
00187                 return newid;
00188         }
00189                         
00190                         
00191         //if we are here we want to save only part of the cluster!
00192         ManagedCluster newcluster = *cluster;
00193                         
00194         SplitEnergy(&newcluster,energy_to_save,1);
00195         SplitEnergy(cluster,energy_to_save,0);
00196                         
00197         newcluster.SetStatus(status);
00198         int newid = clustersaver->SaveCluster(&newcluster);
00199                         
00200         AdjustCluster(cluster);
00201 
00202 //      printf("saving split save has %f old has %f\n",GetCluster(newid)->e,cluster->e);
00203                         
00204         return newid;
00205 
00206 
00207 }

void Managed::ClusterManager::SetClusterSaver ( Managed::ClusterSaver cs  )  [inline]

Definition at line 67 of file ClusterManager.h.

References clustersaver.

Referenced by PrimaryShowerFinder::MakeChains(), and ParticleFinder::Reco().

00067 {clustersaver=cs;};

void Managed::ClusterManager::SetHitManager ( Managed::HitManager h  )  [inline]

Definition at line 64 of file ClusterManager.h.

References hitmanager.

Referenced by PrimaryShowerFinder::MakeChains(), and ParticleFinder::Reco().

00064 {hitmanager=h;};

void ClusterManager::SplitEnergy ( Managed::ManagedCluster cluster,
double  energy,
int  matchenergy 
)

Definition at line 252 of file ClusterManager.cxx.

References Managed::ManagedCluster::e, MuELoss::e, Managed::ManagedCluster::Finalize(), Managed::ManagedCluster::hite, Msg::kDebug, and MSG.

Referenced by SaveCluster().

00253 {
00254 
00255         MSG("ClusterManager",Msg::kDebug)<<"splitting cluster with "<<cluster->e<<" to have "<<energy <<" match "<<matchenergy<<"\n";
00256 
00257         double totale=cluster->e;
00258         if(totale<1e-9)return;
00259         for(unsigned int i=0;i<cluster->hite.size();i++)
00260         {
00261         
00262                 double newe =0;
00263                 if(matchenergy)newe=cluster->hite[i]/totale*energy;
00264                 else newe=cluster->hite[i]/totale*(totale-energy);
00265                 
00266         /*      printf("hit with %f should have %f\n",cluster->hite[i],newe);
00267                 
00268                 if(matchenergy)
00269                 {
00270                         //needs to also adjust the hit stored in the hit manager here.....
00271                         Managed::ManagedHit *hit = hitmanager->FindHit(cluster->hit_id[i]);             
00272                         double sete = hit->SetEnergy(newe);
00273                         cluster->hite[i]=sete;
00274                         printf("setting to %f\n",sete);
00275                 }else{
00276 
00277                         //add save the rest as a new hit
00278                         if(newe>0)
00279                         {
00280                                 printf("newhit energy %f\n",newe);
00281                                 Managed::ManagedHit *hit = hitmanager->FindHit(cluster->hit_id[i]);     
00282                                 int newid = hitmanager->InsertHit(hit->GetView(), hit->GetPlane(), hit->GetStrip(), hit->GetZ(), hit->GetT(), newe);
00283                                 cluster->hite[i]=newe;
00284                                 cluster->hit_id[i]=newid;
00285                                 printf("setting to %f\n",newe);
00286                         }else{
00287                                 cluster->hite[i]=0;
00288                                 cluster->hit_id[i]=-1;
00289                                 printf("setting to 0");
00290                         }
00291                 }
00292                 
00293         */
00294         cluster->hite[i]=newe;  
00295 
00296 //              if(matchenergy)hite[i]=hite[i]/totale*energy;
00297 //              else hite[i]=hite[i]/totale*(totale-energy);
00298 
00299         }
00300         cluster->Finalize();
00301 
00302 }


Member Data Documentation

std::map<double, std::map<double, int> > Managed::ClusterManager::cluster_map
std::map<double, std::map<double, int> > Managed::ClusterManager::cluster_map_u
std::map<double, std::map<double, int> > Managed::ClusterManager::cluster_map_v

Definition at line 76 of file ClusterManager.h.

Referenced by Reset().

std::vector<int> Managed::ClusterManager::clusters_to_delete [private]

Definition at line 96 of file ClusterManager.h.

Referenced by AdjustCluster(), RebuildClusterMaps(), and Reset().

std::vector<ManagedHit> Managed::ClusterManager::hits [private]

Definition at line 81 of file ClusterManager.h.

Referenced by AddStrip(), LoadHits(), MakeClusters(), and Reset().

std::vector<int> Managed::ClusterManager::inuse [private]

Definition at line 94 of file ClusterManager.h.

Referenced by ClearInUse(), GetCluster(), MarkUsed(), and Reset().

std::map<int, std::map<int,int> > Managed::ClusterManager::loc_map [private]

Definition at line 80 of file ClusterManager.h.

Referenced by AddStrip(), LoadHits(), MakeClusters(), and Reset().

Definition at line 91 of file ClusterManager.h.

Referenced by GetClusterMap(), RebuildClusterMaps(), Reset(), and SaveCluster().


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

Generated on 13 Dec 2018 for loon by  doxygen 1.6.1