00001 #include "NueAna/ParticlePID/ParticleFinder/Managed/ClusterSaver.h"
00002
00003 #include <math.h>
00004 using namespace Managed;
00005 ClassImp(ClusterSaver)
00006
00007 ClusterSaver::ClusterSaver()
00008 {
00009 Reset();
00010
00011 }
00012
00013
00014 ClusterSaver::~ClusterSaver()
00015 {
00016
00017 cluster_map.clear();
00018 clusters.clear();
00019 cluster_map_u.clear();
00020 cluster_map_v.clear();
00021
00022 clusters_to_delete.clear();
00023 }
00024
00025
00026 int ClusterSaver::SaveCluster(Managed::ManagedCluster *cluster)
00027 {
00028
00029 if(cluster->e<0.0001)return 0;
00030
00031 Managed::ManagedCluster c = *cluster;
00032 c.id = --save_id;
00033 cluster_map[c.z][c.t]=c.id;
00034 c.Finalize();
00035 clusters.push_back(c);
00036
00037 cluster_map[c.z][c.t]=c.id;
00038
00039 if(c.view==2)cluster_map_u[c.z][c.t]=c.id;
00040 if(c.view==3)cluster_map_v[c.z][c.t]=c.id;
00041
00042
00043 if(c.z<minz)minz=c.z;
00044 if(c.z>maxz)maxz=c.z;
00045 if(c.view==2)
00046 {
00047 if(c.t<minu)minu=c.t;
00048 if(c.t>maxu)maxu=c.t;
00049 }
00050 if(c.view==3)
00051 {
00052 if(c.t<minv)minv=c.t;
00053 if(c.t>maxv)maxv=c.t;
00054 }
00055
00056 if(c.t<mint)mint=c.t;
00057 if(c.t>maxt)maxt=c.t;
00058
00059 return c.id;
00060 }
00061
00062
00063 std::map<double, std::map<double, int> > * ClusterSaver::GetClusterMap(int view)
00064 {
00065
00066
00067
00068 if(needMapRebuild)RebuildClusterMaps();
00069
00070
00071
00072 if(view==2)return &cluster_map_u;
00073 if(view==3)return &cluster_map_v;
00074 return &cluster_map;
00075 }
00076
00077
00078
00079 void ClusterSaver::RebuildClusterMaps()
00080 {
00081
00082
00083 if(clusters_to_delete.size()>0)
00084 {
00085 std::vector<Managed::ManagedCluster> cluster_temp;
00086 for(unsigned int i=0;i<clusters.size();i++)
00087 {
00088 int keep=1;
00089 for(unsigned int j=0;j<clusters_to_delete.size();j++)
00090 {
00091 if(clusters_to_delete[j]==clusters[i].id)
00092 {
00093 keep=0;
00094 break;
00095 }
00096 }
00097 if(!keep)continue;
00098
00099 cluster_temp.push_back(clusters[i]);
00100 }
00101
00102 clusters=cluster_temp;
00103 cluster_temp.clear();
00104 clusters_to_delete.clear();
00105 }
00106
00107 cluster_map.clear();
00108 cluster_map_u.clear();
00109 cluster_map_v.clear();
00110
00111 for(unsigned int i=0;i<clusters.size();i++)
00112 {
00113 cluster_map[clusters[i].z][clusters[i].t]=clusters[i].id;
00114 if(clusters[i].view==2)cluster_map_u[clusters[i].z][clusters[i].t]=clusters[i].id;
00115 if(clusters[i].view==3)cluster_map_v[clusters[i].z][clusters[i].t]=clusters[i].id;
00116 }
00117
00118 needMapRebuild=0;
00119 }
00120
00121
00122
00123
00124 void ClusterSaver::DumpClusters()
00125 {
00126
00127 RebuildClusterMaps();
00128
00129
00130
00131
00132
00133
00134
00135
00136 std::map<double, std::map<double, int> >::iterator p_iter;
00137 std::map<double, int>::iterator s_iter;
00138
00139 printf("dumping clusters... %d found in array\n",(int)clusters.size());
00140
00141 for(p_iter=cluster_map.begin();p_iter!=cluster_map.end(); p_iter++)
00142 {
00143 std::map<double, int>::iterator s_iter;
00144 for(s_iter=p_iter->second.begin();s_iter!=p_iter->second.end(); s_iter++)
00145 {
00146 ManagedCluster *mc = GetCluster(s_iter->second);
00147 if(!mc){printf("missing cluster id %d\n",s_iter->second);continue;}
00148 printf("z %f t %f e %f dz %f dt %f view %d \n",mc->z,mc->t,mc->e,mc->dz,mc->dt,mc->view);
00149 printf("id %d\n",s_iter->second);
00150
00151 }
00152 }
00153
00154 printf("done....\n\n");
00155 }
00156
00157
00158
00159 void ClusterSaver::Reset()
00160 {
00161
00162
00163 cluster_map.clear();
00164 clusters.clear();
00165 cluster_map_u.clear();
00166 cluster_map_v.clear();
00167 mint=100000;
00168 maxt=-100000;
00169 minz=100000;
00170 maxz=-100000;
00171 minu=100000;
00172 maxu=-100000;
00173 minv=100000;
00174 maxv=-100000;
00175 nClusters=0;
00176
00177 save_id=-1;
00178 needMapRebuild=0;
00179 clusters_to_delete.clear();
00180 }
00181
00182
00183
00184 Managed::ManagedCluster* ClusterSaver::GetCluster(int cid)
00185 {
00186 ManagedCluster * c =0;
00187 for(unsigned int i=0;i<clusters.size();i++)
00188 {
00189 if(clusters[i].id==cid)c=&clusters[i];
00190 }
00191
00192 return c;
00193 }
00194
00195
00196
00197 void ClusterSaver::FillClusterMap(std::map<double, std::map<double, std::pair<double, int> > > * cluster_map )
00198 {
00199 for(unsigned int i=0;i<clusters.size();i++)
00200 {
00201 (*cluster_map)[clusters[i].z][clusters[i].t]=std::pair<double,int>(clusters[i].e, clusters[i].view);
00202 }
00203
00204 }
00205
00206
00207 std::map<std::pair<int,int>, double> ClusterSaver::GetStripEnergy()
00208 {
00209 std::map<std::pair<int,int>, double> ret;
00210
00211 for(unsigned int i=0;i<clusters.size();i++)
00212 {
00213 for(unsigned int j=0;j<clusters[i].hitplane.size();j++)
00214 {
00215 if(clusters[i].GetStatus()<=-10)continue;
00216
00217
00218
00219 ret[std::pair<int,int>(clusters[i].hitplane[j],clusters[i].hitstrip[j])]+=clusters[i].hite[j];
00220
00221 }
00222 }
00223 return ret;
00224 }
00225
00226
00227 void ClusterSaver::recomputeBounds()
00228 {
00229
00230 mint=100000;
00231 maxt=-100000;
00232 minz=100000;
00233 maxz=-100000;
00234 minu=100000;
00235 maxu=-100000;
00236 minv=100000;
00237 maxv=-100000;
00238 nClusters=0;
00239
00240 for(unsigned int i=0;i<clusters.size();i++)
00241 {
00242 for(unsigned int j=0;j<clusters[i].hitplane.size();j++)
00243 {
00244 if(clusters[i].GetStatus()<=-10)continue;
00245
00246 ManagedCluster c = clusters[i];
00247 if(c.e<1e-6)continue;
00248
00249 nClusters++;
00250
00251 if(c.z<minz)minz=c.z;
00252 if(c.z>maxz)maxz=c.z;
00253 if(c.view==2)
00254 {
00255 if(c.t<minu)minu=c.t;
00256 if(c.t>maxu)maxu=c.t;
00257 }
00258 if(c.view==3)
00259 {
00260 if(c.t<minv)minv=c.t;
00261 if(c.t>maxv)maxv=c.t;
00262 }
00263
00264 if(c.t<mint)mint=c.t;
00265 if(c.t>maxt)maxt=c.t;
00266
00267
00268
00269 }
00270 }
00271
00272 }
00273
00274
00275