CMS 3D CMS Logo

EcalShapeBase.cc
Go to the documentation of this file.
3 
4 #include <cmath>
5 #include <algorithm>
6 
7 #include <iostream>
8 
10 
12  : m_useDBShape(useDBShape),
13  m_firstIndexOverThreshold(0),
14  m_firstTimeOverThreshold(0.0),
15  m_indexOfMax(0),
16  m_timeOfMax(0.0),
17  m_thresh(0.0) {}
18 
19 void EcalShapeBase::setEventSetup(const edm::EventSetup& evtSetup) { buildMe(&evtSetup); }
20 
22 
23 double EcalShapeBase::timeOfMax() const { return m_timeOfMax; }
24 
25 double EcalShapeBase::timeToRise() const { return timeOfMax() - timeOfThr(); }
26 
27 double EcalShapeBase::threshold() const { return m_thresh; }
28 
29 void EcalShapeBase::buildMe(const edm::EventSetup* evtSetup) {
30  DVec shapeArray;
31 
32  float time_interval = 0;
33  fillShape(time_interval,
34  m_thresh,
35  shapeArray,
36  evtSetup); // pure virtual function, implementation may vary for EB/EE/APD ...
37  m_arraySize = shapeArray.size(); // original data
38 
39  m_denseArraySize = 10 * m_arraySize; // dense array with interpolation between data
41  (unsigned int)(10 /
42  time_interval); // used to be an unsigned int = 10 in < CMSSW10X, should work for time intervals ~0.1, 0.2, 0.5, 1
43  m_qNSecPerBin = time_interval / 10.;
44 
45  m_deriv.resize(m_denseArraySize);
46  m_shape.resize(m_denseArraySize);
47 
48  const double maxel(*max_element(shapeArray.begin(), shapeArray.end()));
49 
50  const double maxelt(1.e-5 < maxel ? maxel : 1);
51 
52  for (unsigned int i(0); i != shapeArray.size(); ++i) {
53  shapeArray[i] = shapeArray[i] / maxelt;
54  }
55 
56  const double thresh(threshold() / maxelt);
57 
58  const double delta(m_qNSecPerBin / 2.);
59 
60  for (unsigned int denseIndex(0); denseIndex != m_denseArraySize; ++denseIndex) {
61  const double xb((denseIndex + 0.5) * m_qNSecPerBin);
62 
63  const unsigned int ibin(denseIndex / 10);
64 
65  double value = 0.0;
66  double deriv = 0.0;
67 
68  if (0 == ibin || shapeArray.size() == 1 + ibin) // cannot do quadratic interpolation at ends
69  {
70  value = shapeArray[ibin];
71  deriv = 0.0;
72  } else {
73  const double x(xb - (ibin + 0.5) * time_interval);
74  const double f1(shapeArray[ibin - 1]);
75  const double f2(shapeArray[ibin]);
76  const double f3(shapeArray[ibin + 1]);
77  const double a(f2);
78  const double b((f3 - f1) / (2. * time_interval));
79  const double c(((f1 + f3) / 2. - f2) / (time_interval * time_interval));
80  value = a + b * x + c * x * x;
81  deriv = (b + 2 * c * x) / delta;
82  }
83 
84  m_shape[denseIndex] = value;
85  m_deriv[denseIndex] = deriv;
86 
87  if (0 < denseIndex && thresh < value && 0 == m_firstIndexOverThreshold) {
88  m_firstIndexOverThreshold = denseIndex - 1;
90  }
91 
92  if (m_shape[m_indexOfMax] < value) {
93  m_indexOfMax = denseIndex;
94  }
95  }
97 }
98 
99 unsigned int EcalShapeBase::timeIndex(double aTime) const {
100  const int index(m_firstIndexOverThreshold + (unsigned int)(aTime * m_kNBinsPerNSec + 0.5));
101 
102  const bool bad((int)m_firstIndexOverThreshold > index || (int)m_denseArraySize <= index);
103 
104  if ((int)m_denseArraySize <= index) {
105  LogDebug("EcalShapeBase") << " ECAL MGPA shape requested for out of range time " << aTime;
106  }
107  return (bad ? m_denseArraySize : (unsigned int)index);
108 }
109 
110 double EcalShapeBase::operator()(double aTime) const {
111  // return pulse amplitude for request time in ns
112 
113  const unsigned int index(timeIndex(aTime));
114  return (m_denseArraySize == index ? 0 : m_shape[index]);
115 }
116 
117 double EcalShapeBase::derivative(double aTime) const {
118  const unsigned int index(timeIndex(aTime));
119  return (m_denseArraySize == index ? 0 : m_deriv[index]);
120 }
121 
123  std::ofstream fs;
124  fs.open(fileName);
125  for (auto i : m_shape)
126  fs << "vec.push_back(" << i << ");\n";
127  fs.close();
128 }
EcalShapeBase::m_firstIndexOverThreshold
unsigned int m_firstIndexOverThreshold
Definition: EcalShapeBase.h:57
EcalShapeBase::m_deriv
DVec m_deriv
Definition: EcalShapeBase.h:64
EcalShapeBase::setEventSetup
void setEventSetup(const edm::EventSetup &evtSetup)
Definition: EcalShapeBase.cc:19
EcalShapeBase::m_thresh
double m_thresh
Definition: EcalShapeBase.h:61
mps_fire.i
i
Definition: mps_fire.py:428
MessageLogger.h
EcalShapeBase::derivative
double derivative(double time) const
Definition: EcalShapeBase.cc:117
EcalShapeBase::DVec
std::vector< double > DVec
Definition: EcalShapeBase.h:26
EcalShapeBase::timeOfThr
double timeOfThr() const
Definition: EcalShapeBase.cc:21
EcalShapeBase::fillShape
virtual void fillShape(float &time_interval, double &m_thresh, EcalShapeBase::DVec &aVec, const edm::EventSetup *es) const =0
EcalShapeBase::timeOfMax
double timeOfMax() const
Definition: EcalShapeBase.cc:23
EcalShapeBase::operator()
double operator()(double aTime) const override
Definition: EcalShapeBase.cc:110
DDAxes::x
EcalShapeBase::m_arraySize
unsigned int m_arraySize
Definition: EcalShapeBase.h:66
MillePedeFileConverter_cfg.fileName
fileName
Definition: MillePedeFileConverter_cfg.py:32
EcalShapeBase::timeToRise
double timeToRise() const override
Definition: EcalShapeBase.cc:25
EcalShapeBase::m_shape
DVec m_shape
Definition: EcalShapeBase.h:63
EcalShapeBase::m_firstTimeOverThreshold
double m_firstTimeOverThreshold
Definition: EcalShapeBase.h:58
EcalShapeBase::threshold
double threshold() const
Definition: EcalShapeBase.cc:27
EcalShapeBase::m_denseArraySize
unsigned int m_denseArraySize
Definition: EcalShapeBase.h:67
EcalShapeBase::timeIndex
unsigned int timeIndex(double aTime) const
Definition: EcalShapeBase.cc:99
EcalShapeBase::m_indexOfMax
unsigned int m_indexOfMax
Definition: EcalShapeBase.h:59
b
double b
Definition: hdecay.h:118
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
a
double a
Definition: hdecay.h:119
EcalShapeBase::m_timeOfMax
double m_timeOfMax
Definition: EcalShapeBase.h:60
DeadROC_duringRun.f2
f2
Definition: DeadROC_duringRun.py:220
dumpMFGeometry_cfg.delta
delta
Definition: dumpMFGeometry_cfg.py:25
EcalShapeBase.h
createfilelist.int
int
Definition: createfilelist.py:10
value
Definition: value.py:1
edm::EventSetup
Definition: EventSetup.h:58
EcalShapeBase::m_qNSecPerBin
double m_qNSecPerBin
Definition: EcalShapeBase.h:68
EcalShapeBase::EcalShapeBase
EcalShapeBase(bool)
Definition: EcalShapeBase.cc:11
EcalShapeBase::~EcalShapeBase
~EcalShapeBase() override
Definition: EcalShapeBase.cc:9
GOODCOLL_filter_cfg.thresh
thresh
Definition: GOODCOLL_filter_cfg.py:74
EcalShapeBase::buildMe
void buildMe(const edm::EventSetup *=nullptr)
Definition: EcalShapeBase.cc:29
relativeConstraints.value
value
Definition: relativeConstraints.py:53
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:56
DeadROC_duringRun.f1
f1
Definition: DeadROC_duringRun.py:219
EcalShapeBase::m_shape_print
void m_shape_print(const char *fileName)
Definition: EcalShapeBase.cc:122
EcalShapeBase::m_kNBinsPerNSec
unsigned int m_kNBinsPerNSec
Definition: EcalShapeBase.h:62
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37