CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/DataFormats/FP420Cluster/src/ClusterFP420.cc

Go to the documentation of this file.
00001 
00002 // File: ClusterFP420.cc
00003 // Date: 12.2006
00004 // Description: ClusterFP420 for FP420
00005 // Modifications: 
00007 #include "DataFormats/FP420Cluster/interface/ClusterFP420.h"
00008 #include "DataFormats/FP420Digi/interface/HDigiFP420.h"
00009 #include <iostream>
00010 #include <cmath>
00011 using namespace std;
00012 
00013 //#define mydigidebug10
00014 //#define mydigidebug11
00015 
00016 //static float const_ps1s2[3] =  {0.050,.0139,0.0045};// pitch, sigma_1channelCluster, sigma_2channelsCluster - Narrow , mm
00017 //static float constW_ps1s2[3] = {0.400,.0920,0.0280};// pitch, sigma_1channelCluster, sigma_2channelsCluster - Wide , mm
00018 
00019 static float const_ps1s2[3] =  {0.050,.0135,0.0086};// pitch, sigma_1channelCluster, sigma_2channelsCluster - Narrow , mm
00020 static float constW_ps1s2[3] = {0.400,.1149,0.0648};// pitch, sigma_1channelCluster, sigma_2channelsCluster - Wide , mm
00021 
00022 // sense of xytype here is X or Y type planes. Now we are working with X only, i.e. xytype=2
00023 ClusterFP420::ClusterFP420( unsigned int detid, unsigned int xytype, const HDigiFP420Range& range, 
00024                             float & cog ,float & err ) :
00025   detId_(detid), firstStrip_(range.first->strip())
00026 //  detId_(detid), xytype_(xytype), firstStrip_(range.first->strip())
00027 {
00028   // For the range of strips in cluster assign adc(,its numbers i->strip()) calculate cog... 
00029   // strip   :    
00030 #ifdef mydigidebug11
00031    std::cout << "===================================== firstStrip = " << firstStrip_ << std::endl;
00032    std::cout << "==range.first->strip() = " << range.first->strip() << std::endl;
00033    std::cout << "==range.second->strip() = " << range.second->strip() << std::endl;
00034 #endif
00035 
00036   amplitudes_.reserve( range.second - range.first);
00037 
00038 
00039   int striprange = 0;
00040   float sumx = 0.;
00041   float sumxx = 0.;
00042   float sumy = 0.;
00043   float sumyy = 0.;
00044   int suma = 0;
00045 
00046 //  int lastStrip = -1;
00047   for (HDigiFP420Iter i=range.first; i!=range.second; i++) {
00048     striprange++;
00049 #ifdef mydigidebug11
00050    std::cout << " current striprange = " << striprange << std::endl;
00051 #endif
00052    /*
00054       if (i!=ibeg && (difNarr(xytype,i,i-1) > 1 || difWide(xytype,i,i-1) > 1)   ){
00055     if (lastStrip>0 && i->strip() != lastStrip + 1) {
00056                  for (int j=0; j < i->strip()-(lastStrip+1); j++) {
00057                    amplitudes_.push_back( 0);
00058                  }
00059     }
00060     lastStrip = i->strip();
00061 */
00062     short amp = i->adc();       // FIXME: gain correction here
00063 
00064 #ifdef mydigidebug11
00065    std::cout << " current strip = " << i->strip() << "  amp = " << amp << std::endl;
00066 #endif
00067 
00068     amplitudes_.push_back(amp);
00069     if(xytype == 1) {
00070       sumx += i->stripH()*amp;
00071       sumy += i->stripHW()*amp;
00072       suma += amp;
00073       sumxx += (i->stripH()) * (i->stripH()) * amp;
00074       sumyy += (i->stripHW()) * (i->stripHW()) * amp;
00075     }
00076     else if(xytype == 2) {
00077       sumx += i->stripV()*amp;
00078       sumy += i->stripVW()*amp;
00079       suma += amp;
00080       sumxx += (i->stripV()) * (i->stripV()) * amp;
00081       sumyy += (i->stripVW()) * (i->stripVW()) * amp;
00082     }
00083     else {
00084       std::cout << " ClusterFP420: wrong xytype = " << xytype << std::endl;
00085     }
00086 
00087 #ifdef mydigidebug11
00088    std::cout << " current sumx = " << sumx << std::endl;
00089    std::cout << " current sumy = " << sumy << std::endl;
00090    std::cout << " current suma = " << suma << std::endl;
00091    std::cout << " current barycenter = " << (sumx / static_cast<float>(suma) )  << std::endl;
00092    std::cout << " current barycenterW= " << (sumy / static_cast<float>(suma) )  << std::endl;
00093 #endif
00094   } //for i
00095 
00096 
00097   if(suma != 0) {
00098     barycenter_ = sumx / static_cast<float>(suma) ;
00099     barycerror_ = sumxx / static_cast<float>(suma) ;
00100     barycerror_ = fabs(barycerror_ - barycenter_*barycenter_) ;
00101 #ifdef mydigidebug11
00102     std::cout << "barycerror_ = " << barycerror_ << "barycenter_ = " << barycenter_ << std::endl;
00103 #endif
00104     barycenterW_ = sumy / static_cast<float>(suma) ;
00105     barycerrorW_ = sumyy / static_cast<float>(suma) ;
00106     barycerrorW_ = fabs(barycerrorW_ - barycenterW_*barycenterW_) ;
00107 #ifdef mydigidebug11
00108     std::cout << "barycerrorW_ = " << barycerrorW_ << "barycenterW_ = " << barycenterW_ << std::endl;
00109 #endif
00110   }
00111   else{
00112     barycenter_ = 1000000. ;
00113     barycerror_ = 1000000. ;
00114     barycenterW_ = 1000000. ;
00115     barycerrorW_ = 1000000. ;
00116   }
00117 
00121   cog = barycenter_;// cog for Narrow pixels only
00122 
00123 #ifdef mydigidebug11
00124    std::cout << "AT end: barycenter_ = " << barycenter_ << std::endl;
00125    std::cout << "AT end:  striprange = " << striprange << std::endl;
00126 #endif
00127 
00128 
00129 
00130 
00131 
00132    /*
00133 
00134   float sumx0 = 0.;
00135   float sumxx = 0.;
00136   lastStrip = -1;
00137   for (HDigiFP420Iter i=range.first; i!=range.second; i++) {
00138 #ifdef mydigidebug11
00139    std::cout << " current striprange = " << striprange << std::endl;
00140 #endif
00142     if (lastStrip>0 && i->strip() != lastStrip + 1) {
00143                  for (int j=0; j < i->strip()-(lastStrip+1); j++) {
00144                    amplitudes_.push_back( 0);
00145                  }
00146     }
00147     lastStrip = i->strip();
00148 
00149     short amp = i->adc();       // FIXME: gain correction here
00150 
00151 #ifdef mydigidebug11
00152    std::cout << " current strip = " << i->strip() << "  amp = " << amp << std::endl;
00153 #endif
00154 
00155     sumx0 += (i->strip()-cog)*amp;
00156     sumxx += (i->strip()-cog) * (i->strip()-cog) * amp;
00157 
00158 
00159 #ifdef mydigidebug11
00160    std::cout << " 2 current sumx0 = " << sumx0 << std::endl;
00161    std::cout << " 2 current sumxx = " << sumxx << std::endl;
00162 #endif
00163   } //for
00164 
00165 
00166   if(suma != 0) {
00167     sumx0 = sumx0 / static_cast<float>(suma) ;
00168     sumxx = sumxx / static_cast<float>(suma);
00169     
00170     //barycerror_ = fabs(sumxx - sumx0*sumx0) ;
00171 
00172     //barycerror_ = (sumxx - sumx0*sumx0) ;
00173     //barycerror_ *= barycerror_ ;
00174 
00175       barycerror_ = sumxx ;
00176 
00177   }
00178   else{
00179     barycerror_ = 1000000. ;
00180   }
00181 
00182 */
00183 
00184 #ifdef mydigidebug10
00185    std::cout << "pitchcommon = " << const_ps1s2[0] << " sigma1= " << const_ps1s2[1]  << " sigma2= " << const_ps1s2[2]  << std::endl;
00186 #endif
00187 
00188    //
00189   if(barycerror_ == 0.0) {
00190     barycerror_ = const_ps1s2[1]/const_ps1s2[0];// 
00191   }
00192   else{
00193     barycerror_ = const_ps1s2[2]/const_ps1s2[0];//  
00194   }
00195     barycerror_ *= barycerror_;
00196    //
00197   if(barycerrorW_ == 0.0) {
00198     barycerrorW_ = constW_ps1s2[1]/constW_ps1s2[0];// 
00199   }
00200   else{
00201     barycerrorW_ = constW_ps1s2[2]/constW_ps1s2[0];// 
00202   }
00203     barycerrorW_ *= barycerrorW_;
00204    //
00205 
00206 #ifdef mydigidebug11
00207    std::cout << "barycerror_ = " << barycerror_ << "barycerrorW_ = " << barycerrorW_ << std::endl;
00208 #endif
00209          
00210    // change by hands:
00211 
00212         // number of station
00213         int  mysn0 = 2;
00214         
00215         // number of planes 
00216         int  mypn0 = 5; // number of superplanes
00217 
00218         // number of station
00219         int  myrn0 = 6;//  6 possible sensors in superlayer
00220         
00221 
00222 
00223 
00224 
00225 
00226 
00227         // comment:              detID = theFP420NumberingScheme->FP420NumberingScheme::packMYIndex(rn0, pn0, sn0, det, zside, sector, zmodule);
00228   // unpack from detId_:
00229 
00230     int sScale = myrn0*mypn0, dScale = myrn0*mypn0*mysn0;
00231     
00232     int  det = (detId_-1)/dScale + 1;
00233     int  sector = (detId_-1- dScale*(det - 1))/sScale + 1;
00234 
00235 #ifdef mydigidebug11
00236    std::cout << "sector = " << sector << " det= " << det << std::endl;
00237 #endif
00238 
00239   // unpack from detId_ (OLD):
00240     //  int  sScale = 2*mypn0;
00241     //int  sector = (detId_-1)/sScale + 1 ;
00242 
00243 
00244 
00245         float a = 0.00001;
00246 
00247 
00249         if(mysn0 == 2) {
00250           if(sector==2) {
00251             a = 0.0026+((0.0075-0.0026)/7.)*(mypn0-2); // at 8 m in mm 
00252               }
00253         }
00255         else if(mysn0 == 3) {
00256           if(sector==2) {
00257             a = 0.0011+((0.0030-0.0011)/7.)*(mypn0-2); // at 4 m  in mm 
00258               }
00259           else if(sector==3) {
00260             a = 0.0022+((0.0068-0.0022)/7.)*(mypn0-2); // at 8 m  in mm 
00261               }
00262         }
00263         else if(mysn0 == 4) {
00264           if(sector==2) {
00265             a = 0.0009+((0.0024-0.0009)/7.)*(mypn0-2); // at 2.7 m  in mm 
00266               }
00267           else if(sector==3) {
00268             a = 0.0018+((0.0050-0.0018)/7.)*(mypn0-2); // at 5.4 m  in mm 
00269               }
00270           else if(sector==4) {
00271             a = 0.0026+((0.0075-0.0026)/7.)*(mypn0-2); // at 8.1 m  in mm 
00272               }
00273         }
00274 
00275         //      barycerror_+=a*a;
00276         //      barycerrorW_+=a*a;
00277         barycerror_+=a*a/const_ps1s2[0]/const_ps1s2[0];
00278         barycerrorW_+=a*a/constW_ps1s2[0]/constW_ps1s2[0];
00279 
00280     /*
00281 
00282   if(detId_ < 21) {
00283     float a = 0.0001*(int((detId_-1)/2.)+1)/pitchall;
00284     barycerror_+=a*a;
00285   }
00286   else if(detId_ < 41) {
00287     float a = 0.0001*(int((detId_-21)/2.)+1)/pitchall;
00288            a +=0.0036; // 2.5 m
00289     //          a +=0.0052; // 4 m
00290     //  a +=0.0131;// 8. m
00291     barycerror_+=a*a;
00292   }
00293   else if(detId_ < 61) {
00294     float a = 0.0001*(int((detId_-41)/2.)+1)/pitchall;
00295              a +=0.0069;// 5 m  0.0059
00296     //          a +=0.0101;// 8. m
00297     //  a +=0.0241;// 16. m
00298     barycerror_+=a*a;
00299   }
00300   else if(detId_ < 81) {
00301     float a = 0.0001*(int((detId_-61)/2.)+1)/pitchall;
00302           a +=0.0131;// 7.5 m   0.0111
00303     //       a +=0.0151;// 12. m
00304     //  a +=0.0301;// 24. m
00305     barycerror_+=a*a;
00306   }
00307 */
00308 #ifdef mydigidebug11
00309    std::cout << "AT end: barycerror_ = " << barycerror_ << std::endl;
00310 #endif
00311 
00312   barycerror_ = sqrt(  barycerror_ );
00313   err = barycerror_;
00314 
00315   barycerrorW_ = sqrt(  barycerrorW_ );
00316 
00317 
00318 #ifdef mydigidebug11
00319    std::cout << "AT end: err = " << err<< "   detId_= " << detId_ << std::endl;
00320 #endif
00321 
00322 }
00323