CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalShapeBase.cc
Go to the documentation of this file.
3 
4 #include <cmath>
5 #include <iostream>
6 #include <fstream>
7 #include <algorithm>
8 
9 const double EcalShapeBase::qNSecPerBin = 1./(1.*kNBinsPerNSec) ;
10 
12 {
13  delete m_derivPtr ;
14 }
15 
16 EcalShapeBase::EcalShapeBase( bool aSaveDerivative ) :
17  m_firstIndexOverThreshold ( 0 ) ,
18  m_firstTimeOverThreshold ( 0.0 ) ,
19  m_indexOfMax ( 0 ) ,
20  m_timeOfMax ( 0.0 ) ,
21  m_shape ( DVec( kNBinsStored, 0.0 ) ) ,
22  m_derivPtr ( aSaveDerivative ? new DVec( kNBinsStored, 0.0 ) : 0 )
23 {
24 }
25 
26 double
28 {
30  }
31 
32 double
34 {
35  return m_timeOfMax ;
36 }
37 
38 double
40 {
41  return timeOfMax() - timeOfThr() ;
42 }
43 
44 
45 void
47 {
48  DVec shapeArray( k1NSecBinsTotal , 0.0 ) ;
49 
50  fillShape( shapeArray ) ;
51 
52  const double maxel ( *max_element( shapeArray.begin(), shapeArray.end() ) ) ;
53 
54  const double maxelt ( 1.e-5 < maxel ? maxel : 1 ) ;
55 
56  for( unsigned int i ( 0 ) ; i != shapeArray.size(); ++i )
57  {
58  shapeArray[i] = shapeArray[i]/maxelt ;
59  }
60 
61  const double thresh ( threshold()/maxelt ) ;
62 
63 /*
64  for( unsigned int i ( 0 ) ; i != k1NSecBinsTotal ; ++i )
65  {
66  LogDebug("EcalShapeBase") << " time (ns) = " << (double)i << " tabulated ECAL pulse shape = " << shapeArray[i];
67  }
68 */
69 
70  const double delta ( qNSecPerBin/2. ) ;
71 
72  for( unsigned int j ( 0 ) ; j != kNBinsStored ; ++j )
73  {
74  const double xb ( ( j + 0.5 )*qNSecPerBin ) ;
75 
76  const unsigned int ibin ( j/kNBinsPerNSec ) ;
77 
78  double value = 0.0 ;
79  double deriv = 0.0 ;
80 
81  if( 0 == ibin ||
82  shapeArray.size() == 1 + ibin ) // cannot do quadratic interpolation at ends
83  {
84  value = shapeArray[ibin];
85  deriv = 0.0 ;
86  }
87  else
88  {
89  const double x ( xb - ( ibin + 0.5 ) ) ;
90  const double f1 ( shapeArray[ ibin - 1 ] ) ;
91  const double f2 ( shapeArray[ ibin ] ) ;
92  const double f3 ( shapeArray[ ibin + 1 ] ) ;
93  const double a ( f2 ) ;
94  const double b ( ( f3 - f1 )/2. ) ;
95  const double c ( ( f1 + f3 )/2. - f2 ) ;
96  value = a + b*x + c*x*x;
97  deriv = ( b + 2*c*x )/delta ;
98  }
99 
100  m_shape[ j ] = value;
101  if( 0 != m_derivPtr ) (*m_derivPtr)[ j ] = deriv;
102 
103  if( 0 < j &&
104  thresh < value &&
106  {
109  }
110 
111  if( m_shape[ m_indexOfMax ] < value )
112  {
113  m_indexOfMax = j ;
114  }
115 
116 // LogDebug("EcalShapeBase") << " time (ns) = " << ( j + 1.0 )*qNSecPerBin - delta
117 // << " interpolated ECAL pulse shape = " << m_shape[ j ]
118 // << " derivative = " << ( 0 != m_derivPtr ? (*m_derivPtr)[ j ] : 0 ) ;
119  }
121 }
122 
123 unsigned int
124 EcalShapeBase::timeIndex( double aTime ) const
125 {
126  const int index ( m_firstIndexOverThreshold +
127  (unsigned int) ( aTime*kNBinsPerNSec + 0.5 ) ) ;
128 
129  const bool bad ( (int) m_firstIndexOverThreshold > index ||
130  (int) kNBinsStored <= index ) ;
131 
132  if( (int) kNBinsStored <= index )
133  {
134  LogDebug("EcalShapeBase") << " ECAL MGPA shape requested for out of range time " << aTime ;
135  }
136  return ( bad ? kNBinsStored : (unsigned int) index ) ;
137 }
138 
139 double
140 EcalShapeBase::operator() ( double aTime ) const
141 {
142  // return pulse amplitude for request time in ns
143 
144  const unsigned int index ( timeIndex( aTime ) ) ;
145  return ( kNBinsStored == index ? 0 : m_shape[ index ] ) ;
146 }
147 
148 double
149 EcalShapeBase::derivative( double aTime ) const
150 {
151  const unsigned int index ( timeIndex( aTime ) ) ;
152  return ( 0 == m_derivPtr ||
153  kNBinsStored == index ? 0 : (*m_derivPtr)[ index ] ) ;
154 }
#define LogDebug(id)
dbl * delta
Definition: mlp_gen.cc:36
DVec * m_derivPtr
Definition: EcalShapeBase.h:56
int i
Definition: DBlmapReader.cc:9
double operator()(double aTime) const
double derivative(double time) const
static const double qNSecPerBin
Definition: EcalShapeBase.h:39
EcalShapeBase(bool aSaveDerivative)
int bad(Items const &cont)
virtual double threshold() const =0
std::vector< double > DVec
Definition: EcalShapeBase.h:16
int j
Definition: DBlmapReader.cc:9
unsigned int timeIndex(double aTime) const
double m_firstTimeOverThreshold
Definition: EcalShapeBase.h:52
virtual void fillShape(DVec &aVec) const =0
double b
Definition: hdecay.h:120
unsigned int m_indexOfMax
Definition: EcalShapeBase.h:53
double timeOfThr() const
double m_timeOfMax
Definition: EcalShapeBase.h:54
double a
Definition: hdecay.h:121
unsigned int m_firstIndexOverThreshold
Definition: EcalShapeBase.h:51
Definition: DDAxes.h:10
virtual ~EcalShapeBase()
virtual double timeToRise() const
double timeOfMax() const