SimG4CMS
Calo
src
CaloMeanResponse.cc
Go to the documentation of this file.
1
#include "
SimG4CMS/Calo/interface/CaloMeanResponse.h
"
2
#include "
FWCore/Utilities/interface/Exception.h
"
3
4
#include "CLHEP/Units/GlobalSystemOfUnits.h"
5
6
#include <iostream>
7
#include <fstream>
8
#include <iomanip>
9
10
//#define EDM_ML_DEBUG
11
12
CaloMeanResponse::CaloMeanResponse
(
edm::ParameterSet
const
&
p
) {
13
edm::ParameterSet
m_p =
p
.getParameter<
edm::ParameterSet
>(
"CaloResponse"
);
14
edm::FileInPath
fp
= m_p.
getParameter
<
edm::FileInPath
>(
"ResponseFile"
);
15
std::string
fName
=
fp
.fullPath();
16
useTable
= m_p.
getParameter
<
bool
>(
"UseResponseTable"
);
17
scale
= m_p.
getParameter
<
double
>(
"ResponseScale"
);
18
edm::LogVerbatim
(
"CaloSim"
) <<
"CaloMeanResponse initialized with scale "
<<
scale
<<
" and use Table "
<<
useTable
19
<<
" from file "
<<
fName
;
20
readResponse
(
fName
);
21
}
22
23
CaloMeanResponse::~CaloMeanResponse
() {}
24
25
double
CaloMeanResponse::getWeight
(
int
genPID,
double
genP) {
26
double
weight
= 1;
27
bool
found
=
false
;
28
for
(
unsigned
int
i
= 0;
i
<
pionTypes
.size();
i
++) {
29
if
(genPID ==
pionTypes
[
i
]) {
30
found
=
true
;
31
break
;
32
}
33
}
34
if
(
found
) {
35
weight
=
scale
;
36
if
(
useTable
) {
37
if
(
piLast
>= 0)
38
weight
*=
pionTable
[
piLast
];
39
for
(
unsigned
int
i
= 0;
i
<
pionTable
.size();
i
++) {
40
if
(genP <
pionMomentum
[
i
]) {
41
if
(
i
== 0)
42
weight
=
scale
*
pionTable
[
i
];
43
else
44
weight
=
45
scale
* ((
pionTable
[
i
- 1] * (
pionMomentum
[
i
] - genP) +
pionTable
[
i
] * (genP -
pionMomentum
[
i
- 1])) /
46
(
pionMomentum
[
i
] -
pionMomentum
[
i
- 1]));
47
break
;
48
}
49
}
50
}
51
#ifdef EDM_ML_DEBUG
52
edm::LogVerbatim
(
"CaloSim"
) <<
"CaloMeanResponse::getWeight PID "
<< genPID <<
" uses pion list and gets weight "
53
<<
weight
<<
" for momentum "
<< genP /
GeV
<<
" GeV/c"
;
54
#endif
55
}
else
{
56
for
(
unsigned
int
i
= 0;
i
<
protonTypes
.size();
i
++) {
57
if
(genPID ==
protonTypes
[
i
]) {
58
found
=
true
;
59
break
;
60
}
61
}
62
if
(
found
) {
63
weight
=
scale
;
64
if
(
useTable
) {
65
if
(
pLast
>= 0)
66
weight
*=
protonTable
[
pLast
];
67
for
(
unsigned
int
i
= 0;
i
<
protonTable
.size();
i
++) {
68
if
(genP <
protonMomentum
[
i
]) {
69
if
(
i
== 0)
70
weight
=
scale
*
protonTable
[
i
];
71
else
72
weight
=
73
scale
*
74
((
protonTable
[
i
- 1] * (
protonMomentum
[
i
] - genP) +
protonTable
[
i
] * (genP -
protonMomentum
[
i
- 1])) /
75
(
protonMomentum
[
i
] -
protonMomentum
[
i
- 1]));
76
break
;
77
}
78
}
79
}
80
#ifdef EDM_ML_DEBUG
81
edm::LogVerbatim
(
"CaloSim"
) <<
"CaloMeanResponse::getWeight PID "
<< genPID <<
" uses proton list and gets "
82
<<
"weight "
<<
weight
<<
" for momentum "
<< genP /
GeV
<<
" GeV/c"
;
83
#endif
84
}
else
{
85
#ifdef EDM_ML_DEBUG
86
edm::LogVerbatim
(
"CaloSim"
) <<
"CaloMeanResponse::getWeight PID "
<< genPID <<
" is not in either lists and "
87
<<
"weight "
<<
weight
;
88
#endif
89
}
90
}
91
return
weight
;
92
}
93
94
void
CaloMeanResponse::readResponse
(
std::string
fName
) {
95
std::ifstream
infile
;
96
infile
.open(
fName
.c_str(),
std::ios::in
);
97
98
if
(
infile
) {
99
int
nene,
npart
, pid;
100
double
ene, responseData, responseMC,
ratio
;
101
102
// First read the pion data
103
infile
>> nene >>
npart
;
104
for
(
int
i
= 0;
i
<
npart
;
i
++) {
105
infile
>> pid;
106
pionTypes
.push_back(pid);
107
}
108
for
(
int
i
= 0;
i
< nene;
i
++) {
109
infile
>> ene >> responseData >> responseMC;
110
if
(responseMC > 0)
111
ratio
= responseData / responseMC;
112
else
113
ratio
= 1;
114
pionMomentum
.push_back(ene *
GeV
);
115
pionTable
.push_back(
ratio
);
116
}
117
118
// Then read the proton data
119
infile
>> nene >>
npart
;
120
for
(
int
i
= 0;
i
<
npart
;
i
++) {
121
infile
>> pid;
122
protonTypes
.push_back(pid);
123
}
124
for
(
int
i
= 0;
i
< nene;
i
++) {
125
infile
>> ene >> responseData >> responseMC;
126
if
(responseMC > 0)
127
ratio
= responseData / responseMC;
128
else
129
ratio
= 1;
130
protonMomentum
.push_back(ene *
GeV
);
131
protonTable
.push_back(
ratio
);
132
}
133
infile
.close();
134
}
135
136
piLast
= (
int
)(
pionTable
.size()) - 1;
137
pLast
= (
int
)(
protonTable
.size()) - 1;
138
#ifdef EDM_ML_DEBUG
139
edm::LogVerbatim
(
"CaloSim"
) <<
"CaloMeanResponse::readResponse finds "
<<
pionTypes
.size()
140
<<
" particles to use pion "
141
<<
"response map with a table of "
<<
pionTable
.size() <<
" data points "
<<
piLast
;
142
for
(
unsigned
int
i
= 0;
i
<
pionTypes
.size();
i
++)
143
edm::LogVerbatim
(
"CaloSim"
) <<
"Particle ID["
<<
i
<<
"] = "
<<
pionTypes
[
i
];
144
for
(
unsigned
int
i
= 0;
i
<
pionTable
.size();
i
++)
145
edm::LogVerbatim
(
"CaloSim"
) <<
"Momentum["
<<
i
<<
"] ("
<<
pionMomentum
[
i
] /
GeV
<<
" GeV/c) --> "
<<
pionTable
[
i
];
146
edm::LogVerbatim
(
"CaloSim"
) <<
"CaloMeanResponse::readResponse finds "
<<
protonTypes
.size() <<
" particles to use "
147
<<
"proton response map with a table of "
<<
protonTable
.size() <<
" data points "
148
<<
pLast
;
149
for
(
unsigned
int
i
= 0;
i
<
protonTypes
.size();
i
++)
150
edm::LogVerbatim
(
"CaloSim"
) <<
"Particle ID["
<<
i
<<
"] = "
<<
protonTypes
[
i
];
151
for
(
unsigned
int
i
= 0;
i
<
protonTable
.size();
i
++)
152
edm::LogVerbatim
(
"CaloSim"
) <<
"Momentum["
<<
i
<<
"] ("
<<
protonMomentum
[
i
] /
GeV
<<
" GeV/c) --> "
153
<<
protonTable
[
i
];
154
#endif
155
}
mps_fire.i
i
Definition:
mps_fire.py:428
CaloMeanResponse::pionTable
std::vector< double > pionTable
Definition:
CaloMeanResponse.h:23
mps_merge.weight
weight
Definition:
mps_merge.py:88
AlCaHLTBitMon_ParallelJobs.p
p
Definition:
AlCaHLTBitMon_ParallelJobs.py:153
personalPlayback.fp
fp
Definition:
personalPlayback.py:523
CaloMeanResponse::CaloMeanResponse
CaloMeanResponse(edm::ParameterSet const &p)
Definition:
CaloMeanResponse.cc:12
CaloMeanResponse::protonTable
std::vector< double > protonTable
Definition:
CaloMeanResponse.h:24
newFWLiteAna.found
found
Definition:
newFWLiteAna.py:118
CaloMeanResponse::pionTypes
std::vector< int > pionTypes
Definition:
CaloMeanResponse.h:22
npart
double npart
Definition:
HydjetWrapper.h:46
MainPageGenerator.fName
fName
Definition:
MainPageGenerator.py:301
edm::FileInPath
Definition:
FileInPath.h:64
CaloMeanResponse::pionMomentum
std::vector< double > pionMomentum
Definition:
CaloMeanResponse.h:23
particleFlowDisplacedVertex_cfi.ratio
ratio
Definition:
particleFlowDisplacedVertex_cfi.py:93
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition:
AlCaHLTBitMon_QueryRunRegistry.py:256
CaloMeanResponse::piLast
int piLast
Definition:
CaloMeanResponse.h:21
CaloMeanResponse::useTable
bool useTable
Definition:
CaloMeanResponse.h:19
edm::ParameterSet
Definition:
ParameterSet.h:47
GeV
const double GeV
Definition:
MathUtil.h:16
recoMuon::in
Definition:
RecoMuonEnumerators.h:6
CaloMeanResponse::readResponse
void readResponse(std::string fName)
Definition:
CaloMeanResponse.cc:94
createfilelist.int
int
Definition:
createfilelist.py:10
CaloMeanResponse::pLast
int pLast
Definition:
CaloMeanResponse.h:21
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition:
MessageLogger.h:128
CaloMeanResponse::getWeight
double getWeight(int genPID, double genP)
Definition:
CaloMeanResponse.cc:25
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition:
ParameterSet.h:303
Exception.h
timingPdfMaker.infile
infile
Definition:
timingPdfMaker.py:350
CaloMeanResponse::protonTypes
std::vector< int > protonTypes
Definition:
CaloMeanResponse.h:22
CaloMeanResponse::~CaloMeanResponse
virtual ~CaloMeanResponse()
Definition:
CaloMeanResponse.cc:23
edm::Log
Definition:
MessageLogger.h:70
CaloMeanResponse::scale
double scale
Definition:
CaloMeanResponse.h:20
weight
Definition:
weight.py:1
CaloMeanResponse.h
CaloMeanResponse::protonMomentum
std::vector< double > protonMomentum
Definition:
CaloMeanResponse.h:24
Generated for CMSSW Reference Manual by
1.8.16