CalibTracker
SiStripAPVAnalysis
src
SimpleNoiseCalculator.cc
Go to the documentation of this file.
1
#include "
CalibTracker/SiStripAPVAnalysis/interface/SimpleNoiseCalculator.h
"
2
#include "
FWCore/MessageLogger/interface/MessageLogger.h
"
3
#include <cmath>
4
#include <numeric>
5
#include <algorithm>
6
using namespace
std
;
7
//
8
// Constructors
9
//
10
SimpleNoiseCalculator::SimpleNoiseCalculator
() : numberOfEvents(0), alreadyUsedEvent(
false
) {
11
if
(
false
)
12
cout
<<
"Constructing SimpleNoiseCalculator "
<< endl;
13
init
();
14
}
15
//
16
SimpleNoiseCalculator::SimpleNoiseCalculator
(
int
evnt_ini,
bool
use_DB) : numberOfEvents(0), alreadyUsedEvent(
false
) {
17
if
(
false
)
18
cout
<<
"Constructing SimpleNoiseCalculator "
<< endl;
19
useDB_
= use_DB;
20
eventsRequiredToCalibrate_
= evnt_ini;
21
// eventsRequiredToUpdate_ = evnt_iter;
22
// cutToAvoidSignal_ = sig_cut;
23
init
();
24
}
25
//
26
// Initialization.
27
//
28
void
SimpleNoiseCalculator::init
() {
29
theCMPSubtractedSignal
.clear();
30
theNoise
.clear();
31
theNoiseSum
.clear();
32
theNoiseSqSum
.clear();
33
theEventPerStrip
.clear();
34
// theStatus.setCalibrating();
35
}
36
//
37
// Destructor
38
//
39
SimpleNoiseCalculator::~SimpleNoiseCalculator
() {
40
if
(
false
)
41
cout
<<
"Destructing SimpleNoiseCalculator "
<< endl;
42
}
43
//
44
// Update the Status of Noise Calculation
45
//
46
void
SimpleNoiseCalculator::updateStatus
() {
47
if
((
theStatus
.
isCalibrating
() &&
numberOfEvents
>=
eventsRequiredToCalibrate_
) ||
48
(
useDB_
==
true
&&
numberOfEvents
== 1)) {
49
theStatus
.
setUpdating
();
50
}
51
}
52
//
53
// Calculate and update (when needed) Noise Values
54
//
55
void
SimpleNoiseCalculator::updateNoise
(
ApvAnalysis::PedestalType
&
in
) {
56
if
(
alreadyUsedEvent
==
false
) {
57
alreadyUsedEvent
=
true
;
58
numberOfEvents
++;
59
60
if
(
numberOfEvents
== 1 &&
theNoise
.size() !=
in
.size()) {
61
edm::LogError
(
"SimpleNoiseCalculator:updateNoise"
)
62
<<
" You did not initialize the Noise correctly prior to noise calibration."
;
63
}
64
65
// Initialize sums used for estimating noise.
66
if
(
numberOfEvents
== 1) {
67
theNoiseSum
.clear();
68
theNoiseSqSum
.clear();
69
theEventPerStrip
.clear();
70
71
theNoiseSum
.resize(
in
.size(), 0.0);
72
theNoiseSqSum
.resize(
in
.size(), 0.0);
73
theEventPerStrip
.resize(
in
.size(), 0);
74
}
75
76
unsigned
int
i
;
77
78
// At every event Update sums used for estimating noise.
79
for
(
i
= 0;
i
<
in
.size();
i
++) {
80
theNoiseSum
[
i
] +=
in
[
i
];
81
theNoiseSqSum
[
i
] +=
in
[
i
] *
in
[
i
];
82
theEventPerStrip
[
i
]++;
83
}
84
85
// Calculate noise.
86
if
((
theStatus
.
isCalibrating
() &&
numberOfEvents
==
eventsRequiredToCalibrate_
) ||
theStatus
.
isUpdating
()) {
87
theCMPSubtractedSignal
.clear();
88
theNoise
.clear();
89
90
for
(
i
= 0;
i
<
in
.size();
i
++) {
91
double
avVal = (
theEventPerStrip
[
i
]) ?
theNoiseSum
[
i
] / (
theEventPerStrip
[
i
]) : 0.0;
92
double
sqAvVal = (
theEventPerStrip
[
i
]) ?
theNoiseSqSum
[
i
] / (
theEventPerStrip
[
i
]) : 0.0;
93
double
corr_fac = (
theEventPerStrip
[
i
] > 1) ? (
theEventPerStrip
[
i
] / (
theEventPerStrip
[
i
] - 1)) : 1.0;
94
double
rmsVal = (sqAvVal - avVal * avVal > 0.0) ?
sqrt
(corr_fac * (sqAvVal - avVal * avVal)) : 0.0;
95
96
theCMPSubtractedSignal
.push_back(static_cast<float>(avVal));
97
98
theNoise
.push_back(static_cast<float>(rmsVal));
99
100
if
(
false
)
101
cout
<<
" SimpleNoiseCalculator::updateNoise "
<<
theNoiseSum
[
i
] <<
" "
<<
theNoiseSqSum
[
i
] <<
" "
102
<<
theEventPerStrip
[
i
] <<
" "
<< avVal <<
" "
<< sqAvVal <<
" "
<< (sqAvVal - avVal * avVal) <<
" "
103
<< rmsVal << endl;
104
}
105
}
106
updateStatus
();
107
}
108
}
109
//
110
// Define New Event
111
//
112
void
SimpleNoiseCalculator::newEvent
() {
alreadyUsedEvent
=
false
; }
SimpleNoiseCalculator::theEventPerStrip
std::vector< unsigned short > theEventPerStrip
Definition:
SimpleNoiseCalculator.h:39
mps_fire.i
i
Definition:
mps_fire.py:428
TkStateMachine::setUpdating
void setUpdating()
Definition:
TkStateMachine.h:20
MessageLogger.h
SimpleNoiseCalculator::~SimpleNoiseCalculator
~SimpleNoiseCalculator() override
Definition:
SimpleNoiseCalculator.cc:39
funct::false
false
Definition:
Factorize.h:29
SimpleNoiseCalculator::alreadyUsedEvent
bool alreadyUsedEvent
Definition:
SimpleNoiseCalculator.h:41
SimpleNoiseCalculator.h
gather_cfg.cout
cout
Definition:
gather_cfg.py:144
SimpleNoiseCalculator::updateNoise
void updateNoise(ApvAnalysis::PedestalType &in) override
Definition:
SimpleNoiseCalculator.cc:55
SimpleNoiseCalculator::theNoiseSqSum
std::vector< double > theNoiseSqSum
Definition:
SimpleNoiseCalculator.h:38
SimpleNoiseCalculator::useDB_
bool useDB_
Definition:
SimpleNoiseCalculator.h:42
SimpleNoiseCalculator::theCMPSubtractedSignal
ApvAnalysis::PedestalType theCMPSubtractedSignal
Definition:
SimpleNoiseCalculator.h:37
SimpleNoiseCalculator::theNoise
ApvAnalysis::PedestalType theNoise
Definition:
SimpleNoiseCalculator.h:36
mathSSE::sqrt
T sqrt(T t)
Definition:
SSEVec.h:19
SimpleNoiseCalculator::updateStatus
void updateStatus() override
Definition:
SimpleNoiseCalculator.cc:46
SimpleNoiseCalculator::init
void init()
Definition:
SimpleNoiseCalculator.cc:28
TkStateMachine::isCalibrating
bool isCalibrating() const
Definition:
TkStateMachine.h:29
TkNoiseCalculator::theStatus
TkStateMachine theStatus
Definition:
TkNoiseCalculator.h:34
SimpleNoiseCalculator::eventsRequiredToCalibrate_
int eventsRequiredToCalibrate_
Definition:
SimpleNoiseCalculator.h:44
recoMuon::in
Definition:
RecoMuonEnumerators.h:6
SimpleNoiseCalculator::theNoiseSum
std::vector< double > theNoiseSum
Definition:
SimpleNoiseCalculator.h:38
TkStateMachine::isUpdating
bool isUpdating() const
Definition:
TkStateMachine.h:28
edm::LogError
Log< level::Error, false > LogError
Definition:
MessageLogger.h:123
SimpleNoiseCalculator::newEvent
void newEvent() override
Definition:
SimpleNoiseCalculator.cc:112
std
Definition:
JetResolutionObject.h:76
SimpleNoiseCalculator::numberOfEvents
int numberOfEvents
Definition:
SimpleNoiseCalculator.h:40
ApvAnalysis::PedestalType
std::vector< float > PedestalType
Definition:
ApvAnalysis.h:44
SimpleNoiseCalculator::SimpleNoiseCalculator
SimpleNoiseCalculator()
Definition:
SimpleNoiseCalculator.cc:10
Generated for CMSSW Reference Manual by
1.8.16