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
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 std::vector<const recobase::CellHit*> cellhit(0);
00061
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
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
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
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
00129
00130 double posit[3];
00131
00132 fGeo->Plane(plane).Cell(cell).GetCenter(posit,0.0);
00133
00134
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
00143
00144
00145
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
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
00172
00173
00174 }