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/PlaneCluster.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 using namespace recobase;
00015 using namespace cluster;
00016 
00017 MODULE_DECL(Clusterer);
00018 ClassImp(Clusterer)
00019 
00020 Clusterer::Clusterer(const char* version) : jobc::Module("Clusterer")
00021 {
00022   fClusterAlgType=0;
00023   this->SetWatch("ClustererConfig","default");
00024 }
00025 
00026 
00027 void Clusterer::Update(const cfg::Config& c)
00028 {
00029   c("ClusterAlgType").Get(fClusterAlgType);
00030 }
00031 
00032 Clusterer::~Clusterer()
00033 {
00034   this->RemoveAllWatches();
00035 }
00036 
00037 jobc::Result Clusterer::Reco(edm::EventHandle& evt)
00038 {
00039   //make cell hits from rawdigits
00040   /*
00041     std::vector<const rawdata::RawDigit*> rawdigits(0);
00042     evt.Raw().Get("./",rawdigits);
00043 
00044     printf("cluster-\n");
00045     for (unsigned int i =0;i<rawdigits.size();i++)
00046     {
00047     printf("%d %d \n",i,rawdigits[i]->TDC(0));
00048     CellHit c(rawdigits[i]->Channel(),rawdigits[i]->ADC(0),rawdigits[i]->TDC(0));
00049     c.SetPlane(i/100);
00050     c.SetCell(i%100);
00051     evt.Reco().Put(c,"");
00052     }
00053     printf("-cluster\n");
00054 
00055   */
00056 
00057 
00058 
00059   //get cellhits from the file
00060   std::vector<const recobase::CellHit*> cellhit(0);
00061   //assert_jobc(evt.Reco().Get("Hits",cellhit),"No CellHits found in DetSim() folder!");
00062 
00063   try{
00064     evt.Reco().Get("Hits",cellhit);
00065   }catch(...){return jobc::kFailed;}
00066   
00067 
00068   std::vector<const rawdata::DAQHeader*> header;
00069   short int det = rawdata::kFar;
00070   try{ evt.DAQ().Get("./",header); }
00071   catch(edm::Exception e){
00072     std::cerr << "Error retrieving daq header, while looking "<<
00073       "in TrackReco::Reco(), using default fardet geometry" << std::endl;
00074   }
00075   if(header.size() > 0) det = header[0]->DetId();
00076   //  if (!fGeo) // ideally we would use DAQHeader instead of fDetGeom...
00077   fGeo = &geo::Geometry::Instance(evt.Header().Run(), det);
00078   
00079   evt.Reco().List();
00080 
00081   std::vector<recobase::PlaneCluster> planecluster(0);
00082 
00083   if (fClusterAlgType==0)
00084     {
00085       HitCluster a;
00086       planecluster = a.MakeClusters(cellhit);
00087     }
00088   if (fClusterAlgType==1)
00089     {
00090       HitClusterFast a;
00091       planecluster = a.MakeClusters(cellhit);
00092     }
00093 
00094 
00095   for(unsigned int i=0; i<planecluster.size(); i++)
00096     {
00097       UpdatePlaneClusterStat(planecluster[i]);
00098       //                printf("cluster at %f %f w %f d %f\n",planecluster[i].Zpos(),planecluster[i].Tpos(),planecluster[i].fdt,planecluster[i].fdz);
00099 
00100       evt.Reco().Put(planecluster[i],"");
00101     }
00102 
00103   evt.Reco().List();
00104 
00105   return jobc::kPassed;
00106 }
00107 
00108 
00109 void Clusterer::UpdatePlaneClusterStat(recobase::PlaneCluster & p)
00110 {
00111   //printf("\n");
00112 
00113   float fQtot=0.0;
00114   float tmax=-1.E10, tmin=1.E10;
00115   p.ftpos=0.0;
00116   p.fzpos=0.0;
00117   for (unsigned int i=0;i<p.fCellHit.size();i++){
00118     float mip;
00119     float f;
00120     if(p.fCellHit[i]->PE(f))mip=f;else continue;
00121     fQtot +=mip;
00122 
00123     double tpos=0;
00124     double zpos=0;
00125 
00126     unsigned int cell = p.fCellHit[i]->Cell();
00127     unsigned int plane = p.fCellHit[i]->Plane();
00128     //printf("%d %d \n",plane,cell);
00129     //const geo::CellGeo& gcell= fGeo->Plane(plane).Cell(cell);
00130     double posit[3];
00131 
00132     fGeo->Plane(plane).Cell(cell).GetCenter(posit,0.0);
00133 
00134     //fGeo->Plane(plane).Cell(cell).LocalToWorld(posit,posit);
00135 
00136     if(i==0)
00137       { 
00138         p.fdt=fGeo->Plane(plane).Cell(cell).HalfD();
00139         p.fdz=fGeo->Plane(plane).Cell(cell).HalfW();
00140 
00141       }
00142     //  double posit[3];
00143     //  gcell.GetCenter(posit,0.0);
00144 
00145     //printf("   (%d,%d,%f,%f,%f,%f)",plane,cell,posit[0],posit[1],posit[2],mip);
00146 
00147 
00148     if(fGeo->Plane(plane).View()==geo::kY)
00149       tpos = posit[1];
00150     else
00151       tpos=posit[0];
00152 
00153     zpos = posit[2];
00154      
00155     //  tpos=zpos=1;
00156 
00157     p.ftpos +=tpos*mip;
00158     p.fzpos +=zpos*mip;
00159 
00160     if( tpos > tmax ) tmax = tpos;
00161     if( tpos < tmin ) tmin = tpos;
00162 
00163   }
00164   p.ftpos/=fQtot;
00165   p.fzpos/=fQtot;
00166   p.fdt = sqrt(pow(p.fdt,2.) + pow((tmax-tmin)/2.,2.));
00167 
00168   p.fW=fQtot;
00169 
00170 
00171   //printf("\n");
00172 
00173 
00174 }

Generated on Sun Feb 15 04:45:26 2009 for NOvA Offline by  doxygen 1.3.9.1