17 #include <gsl/gsl_sf_erf.h>
19 #include "CLHEP/Random/RandGaussQ.h"
20 #include "CLHEP/Random/RandFlat.h"
21 #include "CLHEP/Random/RandGeneral.h"
83 dbobject_den = SiPixel2DTemp_den.
product();
87 dbobject_num = SiPixel2DTemp_num.
product();
89 int numOfTemplates = dbobject_den->
numOfTempl() + dbobject_num->numOfTempl();
90 templateStores_.reserve(numOfTemplates);
103 templ2D(templateStores_),
106 IDnum(conf.exists(
"TemplateIDnumerator") ? conf.getParameter<
int>(
"TemplateIDnumerator") : 0),
107 IDden(conf.exists(
"TemplateIDdenominator") ? conf.getParameter<
int>(
"TemplateIDdenominator") : 0),
112 edm::LogVerbatim(
"PixelDigitizer ") <<
"SiPixelChargeReweightingAlgorithm constructed"
118 LogDebug(
"PixelDigitizer") <<
"SiPixelChargeReweightingAlgorithm deleted";
124 std::map<
int,
float, std::less<int> >& hit_signal,
125 const size_t hitIndex,
126 const unsigned int tofBin,
130 unsigned short int processType,
131 const bool& boolmakeDigiSimLinks) {
132 int irow_min = topol->
nrows();
137 float chargeBefore = 0;
138 float chargeAfter = 0;
142 for (
std::map<
int,
float, std::less<int> >::const_iterator im = hit_signal.begin(); im != hit_signal.end(); ++im) {
143 int chan = (*im).first;
149 chargeBefore += (*im).second;
151 if (pixelWithCharge.first < irow_min)
152 irow_min = pixelWithCharge.first;
153 if (pixelWithCharge.first > irow_max)
154 irow_max = pixelWithCharge.first;
155 if (pixelWithCharge.second < icol_min)
156 icol_min = pixelWithCharge.second;
157 if (pixelWithCharge.second > icol_max)
158 icol_max = pixelWithCharge.second;
163 float trajectoryScaleToPosition = hitEntryPoint.
z() / direction.
z();
165 if ((hitEntryPoint.
z() > 0 && direction.
z() < 0) || (hitEntryPoint.
z() < 0 && direction.
z() > 0)) {
166 trajectoryScaleToPosition *= -1;
169 LocalPoint hitPosition = hitEntryPoint + trajectoryScaleToPosition * direction;
172 std::pair<int, int> hitPixel =
173 std::pair<int, int>(
int(floor(hitPositionPixel.
x())),
int(floor(hitPositionPixel.
y())));
180 std::pair<int, int> entryPixel =
181 std::pair<int, int>(
int(floor(hitEntryPointPixel.
x())),
int(floor(hitEntryPointPixel.
y())));
182 std::pair<int, int> exitPixel =
183 std::pair<int, int>(
int(floor(hitExitPointPixel.
x())),
int(floor(hitExitPointPixel.
y())));
185 int hitcol_min, hitcol_max, hitrow_min, hitrow_max;
186 if (entryPixel.first > exitPixel.first) {
187 hitrow_min = exitPixel.first;
188 hitrow_max = entryPixel.first;
190 hitrow_min = entryPixel.first;
191 hitrow_max = exitPixel.first;
194 if (entryPixel.second > exitPixel.second) {
195 hitcol_min = exitPixel.second;
196 hitcol_max = entryPixel.second;
198 hitcol_min = entryPixel.second;
199 hitcol_max = exitPixel.second;
206 <<
"Particle ID is: " <<
hit.particleType() <<
"\n"
207 <<
"Process type: " <<
hit.processType() <<
"\n"
210 <<
"Hit entry x/y/z: " <<
hit.entryPoint().
x() <<
" " <<
hit.entryPoint().
y() <<
" "
211 <<
hit.entryPoint().
z() <<
" "
212 <<
"Hit exit x/y/z: " <<
hit.exitPoint().
x() <<
" " <<
hit.exitPoint().
y() <<
" "
213 <<
hit.exitPoint().
z() <<
" "
215 <<
"Pixel Pos - X: " << hitPositionPixel.
x() <<
" Y: " << hitPositionPixel.
y() <<
"\n"
216 <<
"Cart.Cor. - X: " << CMSSWhitPosition.
x() <<
" Y: " << CMSSWhitPosition.
y() <<
"\n"
217 <<
"Z=0 Pos - X: " << hitPosition.
x() <<
" Y: " << hitPosition.
y() <<
"\n"
219 <<
"Origin of the template:"
221 <<
"Pixel Pos - X: " << originPixel.x() <<
" Y: " << originPixel.y() <<
"\n"
222 <<
"Cart.Cor. - X: " << origin.
x() <<
" Y: " << origin.
y() <<
"\n"
226 <<
"Entry - X: " <<
hit.entryPoint().
x() <<
" Y: " <<
hit.entryPoint().
y()
227 <<
" Z: " <<
hit.entryPoint().
z() <<
"\n"
228 <<
"Exit - X: " <<
hit.exitPoint().
x() <<
" Y: " <<
hit.exitPoint().
y()
229 <<
" Z: " <<
hit.exitPoint().
z() <<
"\n"
231 <<
"Entry - X Pixel: " << hitEntryPointPixel.
x() <<
" Y Pixel: " << hitEntryPointPixel.
y()
233 <<
"Exit - X Pixel: " << hitExitPointPixel.
x() <<
" Y Pixel: " << hitExitPointPixel.
y()
236 <<
"row min: " << irow_min <<
" col min: " << icol_min <<
"\n";
239 if (!(irow_min <= hitrow_max && irow_max >= hitrow_min && icol_min <= hitcol_max && icol_max >= hitcol_min)) {
244 float cmToMicrons = 10000.f;
246 track[0] = (hitPosition.
x() - origin.
x()) * cmToMicrons;
247 track[1] = (hitPosition.
y() - origin.
y()) * cmToMicrons;
249 track[3] = direction.x();
250 track[4] = direction.y();
251 track[5] = direction.z();
255 for (
int row = 0; row <
TXSIZE; ++row) {
257 pixrewgt[row][
col] = 0;
261 for (
int row = 0; row <
TXSIZE; ++row) {
269 for (
int row = 0; row <
TXSIZE; ++row) {
278 std::cout <<
"Cluster before reweighting: " << std::endl;
298 LogDebug(
"PixelDigitizer ") <<
"Cluster Charge Reweighting did not work properly.";
304 std::cout <<
"Cluster after reweighting: " << std::endl;
308 for (
int row = 0; row <
TXSIZE; ++row) {
312 if ((hitPixel.first + row -
THX) >= 0 && (hitPixel.first + row -
THX) < topol->
nrows() &&
322 if (chargeBefore != 0. && chargeAfter == 0.) {
328 std::cout <<
"Charges (before->after): " << chargeBefore <<
" -> " << chargeAfter << std::endl;
329 std::cout <<
"Charge loss: " << (1 - chargeAfter / chargeBefore) * 100 <<
" %" << std::endl << std::endl;
346 int i,
j,
k,
l, kclose;
348 float xsize,
ysize, q50i, q100i, q50r, q10r, q100r, xhit2D, yhit2D, qclust, dist2, dmin2;
351 int goodWeightsUsed, nearbyWeightsUsed, noWeightsUsed;
352 float cotalpha, cotbeta;
370 LogDebug(
"Pixel Digitizer") <<
"Reweighting angle is not good!" << std::endl;
390 xy_rewgt[
j][
i] = 0.f;
401 LogDebug(
"Pixel Digitizer") <<
"No matching template found" << std::endl;
407 std::cout <<
"Template unirrad: " << std::endl;
417 if (cluster.num_dimensions() != 2) {
418 LogWarning(
"Pixel Digitizer") <<
"Cluster is not 2-dimensional. Return." << std::endl;
421 nclusx = (
int)cluster.shape()[0];
422 nclusy = (
int)cluster.shape()[1];
424 LogWarning(
"Pixel Digitizer") <<
"Sizes in x do not match: nclusx=" << nclusx <<
" xdoubleSize=" <<
xdouble.size()
425 <<
" TXSIZE=" <<
TXSIZE <<
". Return." << std::endl;
429 LogWarning(
"Pixel Digitizer") <<
"Sizes in y do not match. Return." << std::endl;
438 xy_clust[
j][
i] = 0.f;
439 denx_clust[
j][
i] = 0;
440 deny_clust[
j][
i] = 0;
441 if (cluster[
j][
i] > q100i) {
442 qclust += cluster[
j][
i];
454 std::cout <<
"Template irrad: " << std::endl;
466 std::vector<int> ytclust;
467 std::vector<int> xtclust;
468 std::vector<int> ycclust;
469 std::vector<int> xcclust;
473 if (xy_in[
j + 1][
i + 1] > q100i) {
475 ytclust.push_back(
i);
476 xtclust.push_back(
j);
477 xy_clust[
j][
i] = xy_rewgt[
j + 1][
i + 1] / xy_in[
j + 1][
i + 1];
478 denx_clust[
j][
i] =
j;
479 deny_clust[
j][
i] =
i;
488 if (xy_rewgt[
j + 1][
i + 1] > q10r && xy_clust[
j][
i] == 0.
f && ntpix > 0) {
492 for (
k = 0;
k < ntpix; ++
k) {
493 dist2 = (
i - ytclust[
k]) * (
i - ytclust[
k]) + 0.44444f * (
j - xtclust[
k]) * (
j - xtclust[
k]);
499 xy_clust[
j][
i] = xy_rewgt[
j + 1][
i + 1] / xy_in[xtclust[kclose] + 1][ytclust[kclose] + 1];
500 denx_clust[
j][
i] = xtclust[kclose];
501 deny_clust[
j][
i] = ytclust[kclose];
513 nearbyWeightsUsed = 0;
518 if (xy_clust[
j][
i] > 0.
f) {
519 cluster[
j][
i] = xy_clust[
j][
i] * clust[denx_clust[
j][
i]][deny_clust[
j][
i]];
520 if (cluster[
j][
i] > q100r) {
521 qclust += cluster[
j][
i];
523 if (cluster[
j][
i] > 0) {
527 if (clust[
j][
i] > 0.
f) {
529 ycclust.push_back(
i);
530 xcclust.push_back(
j);
539 for (
l = 0;
l < ncpix; ++
l) {
544 for (
k = 0;
k < ntpix; ++
k) {
545 dist2 = (
i - ytclust[
k]) * (
i - ytclust[
k]) + 0.44444f * (
j - xtclust[
k]) * (
j - xtclust[
k]);
553 cluster[
j][
i] *= xy_clust[xtclust[kclose]][ytclust[kclose]];
554 if (cluster[
j][
i] > q100r) {
555 qclust += cluster[
j][
i];
569 for (
int row = 0; row <
TXSIZE; ++row) {
580 for (
int row = 0; row <
BXM2; ++row) {
591 for (
int row = 0; row <
TXSIZE; ++row) {