CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Attributes
CSCFindPeakTime Class Reference

#include <CSCFindPeakTime.h>

Public Member Functions

float averageTime (int tmax, const float *adc)
 Weighted average of time bins. More...
 
 CSCFindPeakTime (const edm::ParameterSet &ps)
 
void fivePoleFitCharge (int tmax, const float *adc, const float &t_zero, const float &t_peak, std::vector< float > &adcsFit)
 
float fivePoleFitTime (int tmax, const float *adc, float t_peak)
 
float parabolaFitTime (int tmax, const float *adc)
 Parabolic fit to three time bins centered on maximum. More...
 
float peakTime (int tmax, const float *adc, float t_peak)
 Basic result of this class. More...
 
 ~CSCFindPeakTime ()
 

Private Attributes

bool useAverageTime
 
bool useFivePoleFit
 
bool useParabolaFit
 

Detailed Description

This is CSCFindPeakTime

Used to provide improved estimate of SCA peak time.

Definition at line 13 of file CSCFindPeakTime.h.

Constructor & Destructor Documentation

CSCFindPeakTime::CSCFindPeakTime ( const edm::ParameterSet ps)
explicit

Definition at line 8 of file CSCFindPeakTime.cc.

References edm::ParameterSet::getParameter(), LogTrace, useAverageTime, useFivePoleFit, and useParabolaFit.

8  :
9  useAverageTime(false), useParabolaFit(false), useFivePoleFit(false) {
10 
11  useAverageTime = ps.getParameter<bool>("UseAverageTime");
12  useParabolaFit = ps.getParameter<bool>("UseParabolaFit");
13  useFivePoleFit = ps.getParameter<bool>("UseFivePoleFit");
14  LogTrace("CSCRecHit|CSCFindPeakTime") << "CSCFindPeakTime: useAverageTime=" << useAverageTime <<
15  ", useParabolaFit=" << useParabolaFit << ", useFivePoleFit=" << useFivePoleFit;
16 }
T getParameter(std::string const &) const
#define LogTrace(id)
CSCFindPeakTime::~CSCFindPeakTime ( )
inline

Definition at line 19 of file CSCFindPeakTime.h.

19 {};

Member Function Documentation

float CSCFindPeakTime::averageTime ( int  tmax,
const float *  adc 
)

Weighted average of time bins.

Definition at line 34 of file CSCFindPeakTime.cc.

References i.

Referenced by peakTime().

34  {
35  float sum = 0.;
36  float sumt = 0.;
37  for (size_t i=0; i<4; ++i){
38  sum += adc[i];
39  sumt += adc[i] * ( tmax - 1 + i );
40 
41  }
42  return sumt/sum * 50.; //@@ in ns. May be some bin width offset things to handle here?
43 }
int adc(sample_type sample)
get the ADC sample (12 bits)
int i
Definition: DBlmapReader.cc:9
static const double tmax[3]
void CSCFindPeakTime::fivePoleFitCharge ( int  tmax,
const float *  adc,
const float &  t_zero,
const float &  t_peak,
std::vector< float > &  adcsFit 
)

Integrated charge after fivePoleFitTime

Definition at line 151 of file CSCFindPeakTime.cc.

References create_public_lumi_plots::exp, i, j, N, lumiQTWidget::t, x, and detailsBasic3DVector::y.

151  {
152 
153  //@@ This code can certainly be replaced by fivePoleFitTime above, but I haven't time to do that now (Tim).
154 
155  float p0 = 4./t_peak;
156  float tt0 = t_zero;
157  int n_fit = 4;
158  if ( tmax == 6 ) n_fit=3;
159 
160  float tb[4], y[4];
161  for ( int t = 0; t < 4; ++t ){
162  tb[t] = (tmax + t - 1) * 50.;
163  y[t] = adc[t];
164  }
165 
166  // Find the normalization factor for the function
167  float x[4];
168  float sx2 = 0.;
169  float sxy = 0.;
170  for ( int j=0; j < n_fit; ++j ) {
171  float t = tb[j];
172  x[j] = (t-tt0)*(t-tt0)*(t-tt0)*(t-tt0) * exp( -p0 * (t-tt0) );
173  sx2 = sx2 + x[j] * x[j];
174  sxy = sxy + x[j] * y[j];
175  }
176  float N = sxy / sx2;
177 
178 
179  // Now compute charge for a given t --> only need charges at: t_peak-50, t_peak and t_peak+50
180  for ( int i = 0; i < 3; ++i ) {
181  float t = t_peak + (i - 1) * 50.;
182  float q_fitted = N * (t-tt0)*(t-tt0)*(t-tt0)*(t-tt0) * exp( -p0 * (t-tt0) );
183  adcsFit.push_back(q_fitted);
184  }
185  return;
186 }
int adc(sample_type sample)
get the ADC sample (12 bits)
int i
Definition: DBlmapReader.cc:9
int j
Definition: DBlmapReader.cc:9
static const double tmax[3]
#define N
Definition: blowfish.cc:9
Definition: DDAxes.h:10
float CSCFindPeakTime::fivePoleFitTime ( int  tmax,
const float *  adc,
float  t_peak 
)

Based on RecoLocalMuon/CSCStandAlone/interface/PulseTime.h by S. Durkin, and ported by D. Fortin. Comments updated by Tim Cox Apr 2009.

The SCA pulse shape should be representable by a function
N*(p0^2/256/exp(-4)) * (t-t0)^4 * exp( -p0*(t-t0) )

Rather than do a full fit with varying peak time too, assume the peak time is fixed to 133 nsec w.r.t. start time, t0, and fit for t0. The fit uses a binary search in t0, and at each step calculates the overall normalization factor between the function and the SCA pulse height as a least-squares fit over the 4 time bins tmax -1, tmax, tmax+1, tmax+2

Note: t0peak =4/p0 = 133 nsec, and adc[0] is arbitrarily defined a time of 0.0 nsec.

Definition at line 68 of file CSCFindPeakTime.cc.

References create_public_lumi_plots::exp, j, cond::rpcobgas::time, and x.

Referenced by peakTime().

68  {
69 
70  // Input is
71  // tmax = bin# 0-7 containing max SCA pulse height
72  // adc = 4-dim array containing SCA pulse heights in bins tmax-1 to tmax+2
73  // t_peak = input estimate for SCA peak time
74 
75  // Returned value is improved (we hope) estimate for SCA peak time
76 
77  // Algorithm is to fit five-pole Semi-Gaussian function for start time of SCA pulse, t0
78  // (The SCA peak is assumed to be 133 ns from t0.)
79  // Note that t^4 in time domain corresponds to 1/t^5 in frequency domain (that's the 5 poles).
80 
81  // Initialize parameters to sensible (?) values
82 
83  float t0 = 0.;
84  float t0peak = 133.; // this is offset of peak from start time t0
85  float p0 = 4./t0peak;
86 
87  // Require that tmax is in range 2-6 of bins the eight SCA time bins 0-7
88  // (Bins 0, 1 used for dynamic ped)
89 
90  if ( tmax < 2 || tmax > 6 ) return t_peak; //@@ Just return the input value
91 
92  // Set up time bins to match adc[4] input
93 
94  float tb[4];
95  for ( int time=0; time<4; ++time ){
96  tb[time] = (tmax + time -1) * 50.;
97  }
98 
99  // How many time bins are we fitting?
100 
101  int n_fit = 4;
102  if ( tmax == 6 ) n_fit = 3;
103 
104  float chi_min = 1.e10;
105  float chi_last = 1.e10;
106  float tt0 = 0.;
107  float chi2 = 0.;
108  float del_t = 100.;
109 
110  float x[4];
111  float sx2 = 0.;
112  float sxy = 0.;
113  float fN = 0.;
114 
115  while ( del_t > 1. ) {
116  sx2 = 0.;
117  sxy = 0.;
118 
119  for ( int j=0; j < n_fit; ++j ) {
120  float tdif = tb[j] - tt0;
121  x[j] = tdif * tdif * tdif * tdif * exp( -p0 * tdif );
122  sx2 += x[j] * x[j];
123  sxy += x[j] * adc[j];
124  }
125  fN = sxy / sx2; // least squares fit over time bins i to adc[i] = fN * fivePoleFunction[i]
126 
127  // Compute chi^2
128  chi2 = 0.0;
129  for (int j=0; j < n_fit; ++j) chi2 += (adc[j] - fN * x[j]) * (adc[j] - fN * x[j]);
130 
131  // Test on chi^2 to decide what to do
132  if ( chi_last > chi2 ) {
133  if (chi2 < chi_min ){
134  t0 = tt0;
135  }
136  chi_last = chi2;
137  tt0 = tt0 + del_t;
138  } else {
139  tt0 = tt0 - 2. * del_t;
140  del_t = del_t / 2.;
141  tt0 = tt0 + del_t;
142  chi_last = 1.0e10;
143  }
144  }
145 
146  return t0 + t0peak;
147 }
int adc(sample_type sample)
get the ADC sample (12 bits)
int j
Definition: DBlmapReader.cc:9
static const double tmax[3]
Definition: DDAxes.h:10
float CSCFindPeakTime::parabolaFitTime ( int  tmax,
const float *  adc 
)

Parabolic fit to three time bins centered on maximum.

Definition at line 45 of file CSCFindPeakTime.cc.

References LogTrace, and tmax.

Referenced by peakTime().

45  {
46  // 3-point parabolic fit, from Andy Kubik
47 
48  // We calculate offset to tmax by finding the peak of a parabola through three points
49  float tpeak = tmax;
50  float tcorr = 0;
51 
52  // By construction, input array adc is for bins tmax-1 to tmax+2
53  float y1 = adc[0];
54  float y2 = adc[1];
55  float y3 = adc[2];
56 
57  // Checked and simplified... Tim Cox 08-Apr-2009
58  // Denominator is not zero unless we fed in nonsense values with y2 not the peak!
59  if ( (y1+y3) < 2.*y2 ) tcorr = 0.5 * ( y1 - y3 ) / ( y1 - 2.*y2 + y3 );
60  tpeak += tcorr;
61 
62  LogTrace("CSCRecHit|CSCFindPeakTime") << "CSCFindPeakTime: tmax=" << tmax
63  << ", parabolic peak time is tmax+" << tcorr <<" bins, or " << tpeak*50. << " ns";
64 
65  return tpeak * 50.; // convert to ns.
66 }
int adc(sample_type sample)
get the ADC sample (12 bits)
#define LogTrace(id)
static const double tmax[3]
float CSCFindPeakTime::peakTime ( int  tmax,
const float *  adc,
float  t_peak 
)

Basic result of this class.

Definition at line 18 of file CSCFindPeakTime.cc.

References averageTime(), fivePoleFitTime(), parabolaFitTime(), useAverageTime, useFivePoleFit, and useParabolaFit.

18  {
19  if ( useAverageTime ) {
20  return averageTime( tmax, adc );
21  }
22  else if ( useParabolaFit ) {
23  return parabolaFitTime( tmax, adc );
24  }
25  else if ( useFivePoleFit ) {
26  return fivePoleFitTime( tmax, adc, t_peak);
27  }
28  else {
29  // return something, anyway.. may as well be average
30  return averageTime( tmax, adc );
31  }
32 }
int adc(sample_type sample)
get the ADC sample (12 bits)
float parabolaFitTime(int tmax, const float *adc)
Parabolic fit to three time bins centered on maximum.
float fivePoleFitTime(int tmax, const float *adc, float t_peak)
static const double tmax[3]
float averageTime(int tmax, const float *adc)
Weighted average of time bins.

Member Data Documentation

bool CSCFindPeakTime::useAverageTime
private

Definition at line 56 of file CSCFindPeakTime.h.

Referenced by CSCFindPeakTime(), and peakTime().

bool CSCFindPeakTime::useFivePoleFit
private

Definition at line 58 of file CSCFindPeakTime.h.

Referenced by CSCFindPeakTime(), and peakTime().

bool CSCFindPeakTime::useParabolaFit
private

Definition at line 57 of file CSCFindPeakTime.h.

Referenced by CSCFindPeakTime(), and peakTime().