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

Clusterer.cxx

Go to the documentation of this file.
00001 #include<cmath>
00002 #include "Clusterer/Clusterer.h"
00003 #include "Clusterer/HitCluster.h"
00004 #include "Clusterer/HitClusterFast.h"
00005 #include "RecoBase/Cluster.h"
00006 #include "RecoBase/CellHit.h"
00007 #include "JobControl/Exception.h"
00008 
00009 #include "RawData/RawDigit.h"
00010 #include "RawData/DAQHeader.h"
00011 #include "Geometry/Geometry.h"
00012 #include "Geometry/PlaneGeo.h"
00013 #include "Geometry/CellGeo.h"
00014 #include "Utilities/EDMUtils.h"
00015 
00016 using namespace recobase;
00017 using namespace cluster;
00018 
00019 MODULE_DECL(Clusterer);
00020 ClassImp(Clusterer)
00021 
00022 Clusterer::Clusterer(const char* version) : jobc::Module("Clusterer")
00023 {
00024  fGeo=0;
00025   fClusterAlgType=0;
00026   this->SetCfgVersion(version);
00027 
00028 }
00029 
00030 
00031 void Clusterer::Update(const cfg::Config& c)
00032 {
00033   c("ClusterAlgType").Get(fClusterAlgType);
00034 }
00035 
00036 Clusterer::~Clusterer()
00037 {
00038   this->RemoveAllWatches();
00039 }
00040 
00041 jobc::Result Clusterer::Reco(edm::EventHandle& evt)
00042 {
00043   //make cell hits from rawdigits
00044   /*
00045     std::vector<const rawdata::RawDigit*> rawdigits(0);
00046     evt.Raw().Get("./",rawdigits);
00047 
00048     printf("cluster-\n");
00049     for (unsigned int i =0;i<rawdigits.size();i++)
00050     {
00051     printf("%d %d \n",i,rawdigits[i]->TDC(0));
00052     CellHit c(rawdigits[i]->Channel(),rawdigits[i]->ADC(0),rawdigits[i]->TDC(0));
00053     c.SetPlane(i/100);
00054     c.SetCell(i%100);
00055     evt.Reco().Put(c,"");
00056     }
00057     printf("-cluster\n");
00058 
00059   */
00060 
00061 
00062 
00063   //get cellhits from the file
00064   std::vector<const recobase::CellHit*> cellhit(0);
00065   //assert_jobc(evt.Reco().Get("Hits",cellhit),"No CellHits found in DetSim() folder!");
00066 
00067   try{
00068     evt.Cal().Get("Hits",cellhit);
00069   }catch(...){return jobc::kFailed;}
00070   
00071 
00072   if (!fGeo) fGeo = &util::EDMUtils::GetGeometry(evt);
00073   
00074   evt.Reco().List();
00075 
00076   std::vector<recobase::Cluster> planecluster(0);
00077 
00078   if (fClusterAlgType==0)
00079     {
00080       HitCluster a;
00081       planecluster = a.MakeClusters(cellhit);
00082     }
00083   if (fClusterAlgType==1)
00084     {
00085       HitClusterFast a;
00086       planecluster = a.MakeClusters(cellhit);
00087     }
00088 
00089 
00090   for(unsigned int i=0; i<planecluster.size(); i++)
00091     {
00092       UpdateClusterStat(planecluster[i]);
00093       //                printf("cluster at %f %f w %f d %f\n",planecluster[i].Zpos(),planecluster[i].Tpos(),planecluster[i].fdt,planecluster[i].fdz);
00094         if(planecluster[i].NCell())
00095       evt.Reco().Put(planecluster[i],"");
00096     }
00097 
00098   evt.Reco().List();
00099 
00100   return jobc::kPassed;
00101 }
00102 
00103 
00104 void Clusterer::UpdateClusterStat(recobase::Cluster & p)
00105 {
00106  
00107 
00108   double fQtot=0.0;
00109   double tmax=-1.E10, tmin=1.E10;
00110   double ftpos=0.0;
00111   double fzpos=0.0;
00112 
00113   double fdt=0;
00114   double fdz=0;
00115 
00116   if(!fGeo)
00117   {printf("NO GEO!!!\n");return;}
00118 
00119 
00120 
00121   int view = fGeo->Plane(p.Plane(0)).View();
00122 
00123         
00124 
00125   int cells = (view == geo::kX) ? p.NXCell() : p.NYCell();
00126 
00127   for ( int i=0;i<cells;i++){
00128     const recobase::CellHit* ch = (view == geo::kX) ? p.XCell(i) : p.YCell(i);
00129 
00130 
00131     float mip=0.0;
00132     if(ch->PE() > 0) mip = ch->PE();else continue;
00133     fQtot +=mip;
00134 
00135     double tpos=0;
00136     double zpos=0;
00137 
00138 
00139 
00140     unsigned int cell = ch->Cell();
00141     unsigned int plane = ch->Plane();
00142     //printf("%d %d \n",plane,cell);
00143     
00144     double posit[3];
00145 
00146     fGeo->Plane(plane).Cell(cell).GetCenter(posit,0.0);
00147 
00148     //fGeo->Plane(plane).Cell(cell).LocalToWorld(posit,posit);
00149 
00150     if(i==0)
00151       { 
00152         fdt=fGeo->Plane(plane).Cell(cell).HalfD();
00153         fdz=fGeo->Plane(plane).Cell(cell).HalfW();
00154 
00155       }
00156     //  double posit[3];
00157     //  gcell.GetCenter(posit,0.0);
00158 
00159     //printf("   (%d,%d,%f,%f,%f,%f)",plane,cell,posit[0],posit[1],posit[2],mip);
00160 
00161 
00162     if(fGeo->Plane(plane).View()==geo::kY)
00163       tpos = posit[1];
00164     else
00165       tpos=posit[0];
00166 
00167     zpos = posit[2];
00168      
00169     //  tpos=zpos=1;
00170 
00171     ftpos +=tpos*mip;
00172     fzpos +=zpos*mip;
00173 
00174     if( tpos > tmax ) tmax = tpos;
00175     if( tpos < tmin ) tmin = tpos;
00176 
00177   }
00178   ftpos/=fQtot;
00179   fzpos/=fQtot;
00180   fdt = sqrt(pow(fdt,2.) + pow((tmax-tmin)/2.,2.));
00181 
00182   p.SetQ(fQtot);
00183 
00184   double pos[4];
00185   double dpos[4];
00186   for(int i=0;i<4;i++)
00187   {
00188     pos[i]=0;
00189     dpos[i]=0;
00190   }
00191 
00192   
00193   pos[2]=fzpos;
00194   dpos[2]=fdz;
00195 
00196   if(view==geo::kX)
00197   {
00198     pos[0]=ftpos;
00199     dpos[0]=fdt;
00200   }else{
00201     pos[1]=ftpos;
00202     dpos[1]=fdt;
00203   }
00204 
00205   p.SetXYZT(pos);
00206   p.SetdXYZT(dpos);
00207 
00208 
00209   //printf("\n");
00210 
00211 
00212 }

Generated on Mon Nov 23 04:45:25 2009 for NOvA Offline by  doxygen 1.3.9.1