CMS 3D CMS Logo

CSCFindPeakTime.cc

Go to the documentation of this file.
00001 /* This is CSCFindPeakTime
00002  *
00003  * \author Dominique Fortin
00004  *
00005  * adapted from PulseTime.h originally written by S. Durkin
00006  */ 
00007 
00008 #include <RecoLocalMuon/CSCRecHitD/src/CSCFindPeakTime.h>
00009 
00010 #include <FWCore/MessageLogger/interface/MessageLogger.h>
00011 #include <FWCore/Utilities/interface/Exception.h>
00012 
00013 #include <cmath>
00014 #include <iostream>
00015 
00016 #include <vector>
00017 
00018 
00019 /* FindPeakTime
00020  *
00021  */
00022 bool CSCFindPeakTime::FindPeakTime( const int& tmax, const float* adc, float& t_zero, float& t_peak ) {
00023   
00024   // Initialize parameters in case fit fails
00025   float t0       = 0.;
00026   float N        = adc[1];
00027   t_peak         = 133.;
00028   float p0       = 4./t_peak;
00029 
00030   // If outside physical range, exit
00031   if ( tmax < 2 || tmax > 6 ) return false;
00032 
00033   float tb[4];
00034   for ( int time=0; time<4; ++time ){
00035     tb[time] = (tmax + time -1) * 50.;
00036   }
00037 
00038   int n_fit  = 4;
00039   if ( tmax == 6 ) n_fit = 3;
00040 
00041   float chi_min  = 1.e10;
00042   float chi_last = 1.e10;
00043   float tt0      = 0.;
00044   float chi2     = 0.;
00045   float del_t    = 100.;
00046 
00047   float x[4];
00048   float sx2 = 0.;
00049   float sxy = 0.;
00050   float NN = 0.;
00051 
00052   while ( del_t > 1. ) {
00053     sx2 = 0.;
00054     sxy = 0.;
00055         
00056     for ( int j=0; j < n_fit; ++j ) {
00057       x[j] = (tb[j] - tt0) * (tb[j] - tt0) * (tb[j] - tt0) * (tb[j] - tt0) * exp( -p0 * (tb[j] - tt0) );
00058       sx2  += x[j] * x[j];
00059       sxy  += x[j] * adc[j];
00060     }
00061     NN = sxy / sx2;
00062     
00063     // Compute chi^2
00064     chi2 = 0.0;
00065     for (int j=0; j < n_fit; ++j) chi2 += (adc[j] - NN * x[j]) * (adc[j] - NN * x[j]);
00066 
00067     // Test on chi^2 to decide what to do    
00068     if ( chi_last > chi2 ) {
00069       if (chi2 < chi_min ){
00070         t0      = tt0;
00071         N       = NN;
00072       }
00073       chi_last  = chi2;
00074       tt0       = tt0 + del_t;
00075     } else {
00076       tt0      = tt0 - 2. * del_t;
00077       del_t    = del_t / 2.;
00078       tt0      = tt0 + del_t;
00079       chi_last = 1.0e10;
00080     }
00081   }
00082 
00083   t_peak = t_peak;
00084   t_zero = tt0;
00085 
00086   return true;
00087 }
00088 
00089 
00090 /* FitCharge
00091  *
00092  */
00093 void CSCFindPeakTime::FitCharge( const int& tmax, const float* adc, const float& t_zero, const float& t_peak, std::vector<float>& adcsFit ) {
00094 
00095   float p0  = 4./t_peak;
00096   float tt0 = t_zero;
00097   int n_fit = 4;
00098   if ( tmax == 6 ) n_fit=3;
00099   
00100   float tb[4], y[4];
00101   for ( int t = 0; t < 4; ++t ){
00102     tb[t] = (tmax + t - 1) * 50.;
00103     y[t] = adc[t];
00104   }
00105 
00106   // Find the normalization factor for the function
00107   float x[4];    
00108   float sx2 = 0.;
00109   float sxy = 0.;
00110   for ( int j=0; j < n_fit; ++j ) {
00111     float t = tb[j];
00112     x[j] = (t-tt0)*(t-tt0)*(t-tt0)*(t-tt0) * exp( -p0 * (t-tt0) );
00113     sx2  = sx2 + x[j] * x[j];
00114     sxy  = sxy + x[j] * y[j];
00115   }
00116   float N = sxy / sx2;
00117     
00118 
00119   // Now compute charge for a given t  --> only need charges at: tpeak-50, tpeak and tpeak+50
00120   for ( int i = 0; i < 3; ++i ) {
00121     float t = t_peak + (i - 1) * 50.;
00122     float q_fitted = N * (t-tt0)*(t-tt0)*(t-tt0)*(t-tt0) * exp( -p0 * (t-tt0) );
00123     adcsFit.push_back(q_fitted);
00124   }
00125   return;
00126 }
00127 
00128 

Generated on Tue Jun 9 17:43:49 2009 for CMSSW by  doxygen 1.5.4