00001 #include "RecoTBCalo/EcalTBHodoscopeReconstructor/interface/EcalTBHodoscopeRecInfoAlgo.h"
00002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00003
00004 #include <list>
00005
00006 EcalTBHodoscopeRecInfoAlgo::EcalTBHodoscopeRecInfoAlgo(int fitMethod, const std::vector<double>& planeShift, const std::vector<double>& zPosition) : fitMethod_(fitMethod), planeShift_(planeShift), zPosition_(zPosition)
00007 {
00008 myGeometry_=new EcalTBHodoscopeGeometry();
00009 }
00010
00011 void EcalTBHodoscopeRecInfoAlgo::clusterPos(float &x, float &xQuality,const int& ipl, const int& xclus, const int& width) const
00012 {
00013 if ( width == 1 ) {
00014
00015 x = (myGeometry_->getFibreLp(ipl,xclus) + myGeometry_->getFibreRp(ipl,xclus))/2.0 -
00016 planeShift_[ipl];
00017 xQuality = (myGeometry_->getFibreRp(ipl,xclus) - myGeometry_->getFibreLp(ipl,xclus));
00018 } else if ( width == 2 ) {
00019
00020 x = (myGeometry_->getFibreLp(ipl,xclus+1) + myGeometry_->getFibreRp(ipl,xclus))/2.0 -
00021 planeShift_[ipl];
00022 xQuality =(myGeometry_->getFibreRp(ipl,xclus)-myGeometry_->getFibreLp(ipl,xclus+1));
00023 } else {
00024
00025 x = (myGeometry_->getFibreLp(ipl,xclus) +myGeometry_->getFibreRp(ipl,xclus+width-1))/2.0 -
00026 planeShift_[ipl];
00027 xQuality =(myGeometry_->getFibreRp(ipl,xclus+width-1) - myGeometry_->getFibreLp(ipl,xclus));
00028 }
00029 }
00030
00031 void EcalTBHodoscopeRecInfoAlgo::fitHodo(float &x, float &xQuality,
00032 const int& ipl, const int& nclus, const std::vector<int>& xclus, const std::vector<int>& wclus) const
00033 {
00034 if ( nclus == 1 ) {
00035
00036
00037
00038 clusterPos(x, xQuality, ipl, xclus[0], wclus[0]);
00039 } else {
00040 xQuality = -10 - nclus;
00041 }
00042 }
00043
00044 void EcalTBHodoscopeRecInfoAlgo::fitLine(float &x, float &xSlope, float &xQuality,
00045 const int& ipl1, const int& nclus1, const std::vector<int>& xclus1, const std::vector<int>& wclus1,
00046 const int& ipl2, const int& nclus2, const std::vector<int>& xclus2, const std::vector<int>& wclus2) const
00047 {
00048 if ( nclus1 == 0 ) {
00049 fitHodo(x, xQuality, ipl2,nclus2,xclus2,wclus2);
00050 xSlope = 0.0;
00051 return;
00052 }
00053 if ( nclus2 == 0 ) {
00054 fitHodo(x, xQuality, ipl1,nclus1,xclus1,wclus1);
00055 xSlope = 0.0;
00056 return;
00057 }
00058
00059
00060
00061 float x1,x2,xQ1,xQ2;
00062 float xs,x0,xq;
00063
00064 std::list<BeamTrack> tracks;
00065
00066 for(int i1=0;i1<nclus1;i1++) {
00067 for(int i2=0;i2<nclus2;i2++) {
00068 clusterPos(x1, xQ1, ipl1, xclus1[i1], wclus1[i1]);
00069 clusterPos(x2, xQ2, ipl2, xclus2[i2], wclus2[i2]);
00070
00071 xs = ( x2 - x1 ) /
00072 ( zPosition_[ipl2] - zPosition_[ipl1] );
00073 x0 = (( x2 + x1 ) - xs *
00074 ( zPosition_[ipl2] + zPosition_[ipl1] ))/2.0;
00075 xq = (xQ1 + xQ2)/2.0;
00076 tracks.push_back(BeamTrack(x0,xs,xq));
00077 }
00078 }
00079
00080
00081 tracks.sort();
00082
00083
00084 x = tracks.begin()->x;
00085 xSlope = tracks.begin()->xS;
00086 xQuality = tracks.begin()->xQ;
00087 }
00088
00089
00090
00091 EcalTBHodoscopeRecInfo EcalTBHodoscopeRecInfoAlgo::reconstruct(const EcalTBHodoscopeRawInfo& hodoscopeRawInfo) const {
00092
00093 float x,y= -100.0;
00094 float xSlope,ySlope = 0.0;
00095 float xQuality, yQuality = -100.0;
00096
00097 int nclus[4];
00098 std::vector<int> xclus[4];
00099 std::vector<int> wclus[4];
00100
00101 for(int ipl=0; ipl<myGeometry_->getNPlanes(); ipl++) {
00102
00103 int nhits = hodoscopeRawInfo[ipl].numberOfFiredHits();
00104
00105 nclus[ipl] = 0;
00106 if ( nhits > 0 )
00107 {
00108 int nh = nhits;
00109 int first = 0;
00110 int last = 0;
00111 while ( nh > 0 )
00112 {
00113 while ( hodoscopeRawInfo[ipl][first] == 0 ) first++;
00114 last = first+1; nh--;
00115 do
00116 {
00117 while ( last < myGeometry_->getNFibres() && hodoscopeRawInfo[ipl][last] ) { last++;nh--;}
00118 if ( last+1 < myGeometry_->getNFibres() && hodoscopeRawInfo[ipl][last+1] )
00119 {
00120 last+=2; nh--;
00121
00122 }
00123 else
00124 {
00125 break;
00126 }
00127 }
00128 while( nh>0 && last<myGeometry_->getNFibres() );
00129 wclus[ipl].push_back(last - first);
00130 xclus[ipl].push_back(first);
00131 nclus[ipl]++;
00132
00133 first = last + 1;
00134 }
00135 }
00136
00137 }
00138
00140
00141 if ( fitMethod_ == 0 )
00142 {
00143 fitLine(x, xSlope, xQuality,
00144 0,nclus[0],xclus[0],wclus[0],
00145 2,nclus[2],xclus[2],wclus[2]);
00146 fitLine(y, ySlope, yQuality,
00147 1,nclus[1],xclus[1],wclus[1],
00148 3,nclus[3],xclus[3],wclus[3]);
00149 }
00150 else if ( fitMethod_ == 1 )
00151 {
00153
00154 fitHodo(x, xQuality, 0,nclus[0],xclus[0],wclus[0]);
00155
00156
00157
00158
00159 fitHodo(y, yQuality, 1,nclus[1],xclus[1],wclus[1]);
00160
00161
00162
00163
00164 }
00165 else if ( fitMethod_ == 2 )
00166 {
00168
00169 fitHodo(x, xQuality, 2,nclus[2],xclus[2],wclus[2]);
00170
00171
00172
00173
00174 fitHodo(y, yQuality, 3,nclus[3],xclus[3],wclus[3]);
00175
00176
00177
00178
00179 }
00180
00181 return EcalTBHodoscopeRecInfo(x,y,xSlope,ySlope,xQuality,yQuality);
00182 }
00183