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