CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_2_9_HLT1_bphpatch4/src/RecoTBCalo/EcalTBHodoscopeReconstructor/src/EcalTBHodoscopeRecInfoAlgo.cc

Go to the documentation of this file.
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     // Single fiber
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     // Two half overlapped fibers
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     // More then two fibers case
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     // Fill real x as mean position inside the cluster
00036     // Quality - width of cluster
00037     // To calculate sigma one can do sigma=sqrt(Quality**2/12.0)
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 ) {  // Fit with one plane 
00049     fitHodo(x, xQuality, ipl2,nclus2,xclus2,wclus2);
00050     xSlope = 0.0; //?? Should we put another number indicating that is not fitted
00051     return;
00052   }
00053   if ( nclus2 == 0 ) {  // Fit with one plane 
00054     fitHodo(x, xQuality, ipl1,nclus1,xclus1,wclus1);
00055     xSlope = 0.0; //?? Should we put another number indicating that is not fitted
00056     return;
00057   }
00058 
00059   // We have clusters in both planes
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] ); // slope
00073       x0 = (( x2 + x1 ) - xs *
00074             ( zPosition_[ipl2] + zPosition_[ipl1] ))/2.0;  // x0
00075       xq = (xQ1 + xQ2)/2.0; // Quality, how i can do better ?
00076       tracks.push_back(BeamTrack(x0,xs,xq));
00077     }
00078   }
00079 
00080   // find track with minimal slope
00081   tracks.sort();
00082 
00083   // Return results
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   // Reset Hodo data
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     // Finding clusters
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++; // start
00114             last = first+1; nh--;
00115             do 
00116               {
00117                 while ( last < myGeometry_->getNFibres() && hodoscopeRawInfo[ipl][last] ) { last++;nh--;} //end
00118                 if ( last+1 < myGeometry_->getNFibres() && hodoscopeRawInfo[ipl][last+1] ) 
00119                   { //Skip 1 fibre hole
00120                     last+=2; nh--;
00121                     //std::cout << "Skip fibre " << ipl << " " << first << " "<< last << std::endl;
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); // Left edge !!!
00131             nclus[ipl]++;
00132             
00133             first = last + 1;
00134           }
00135       } 
00136     //    printClusters(ipl);
00137   }
00138 
00140   // Straight line fit for one axis
00141   if ( fitMethod_ == 0 )
00142     {
00143       fitLine(x, xSlope, xQuality,
00144               0,nclus[0],xclus[0],wclus[0],   // X1
00145               2,nclus[2],xclus[2],wclus[2]);  // X2
00146       fitLine(y, ySlope, yQuality,
00147               1,nclus[1],xclus[1],wclus[1],  // Y1
00148               3,nclus[3],xclus[3],wclus[3]); // Y2
00149     }
00150   else if ( fitMethod_ == 1 )
00151     {
00153       // x1 and y2 hodoscope
00154       fitHodo(x, xQuality, 0,nclus[0],xclus[0],wclus[0]); // X1
00155       //   if ( xQuality[1] < 0.0 ) {
00156       //     printFibres(0);
00157       //     printClusters(0);
00158       //   }
00159       fitHodo(y, yQuality, 1,nclus[1],xclus[1],wclus[1]); // Y1
00160       //   if ( yQuality[1] < 0.0 ) {
00161       //     printFibres(1);
00162       //     printClusters(1);
00163       //   }
00164     }
00165   else if ( fitMethod_ == 2 )
00166     {
00168       //x2 and y2 hodoscope
00169       fitHodo(x, xQuality, 2,nclus[2],xclus[2],wclus[2]); // X2
00170       //   if ( xQuality[2] < 0.0 ) {
00171       //     printFibres(2);
00172       //     printClusters(2);
00173       //   }
00174       fitHodo(y, yQuality, 3,nclus[3],xclus[3],wclus[3]); // Y2
00175       //   if ( yQuality[2] < 0.0 ) {
00176       //     printFibres(3);
00177       //     printClusters(3);
00178       //   }
00179     }
00180 
00181   return EcalTBHodoscopeRecInfo(x,y,xSlope,ySlope,xQuality,yQuality); 
00182 }
00183