47 dbobject_den = &es.
getData(SiPixel2DTemp_den_token_);
48 dbobject_num = &es.
getData(SiPixel2DTemp_num_token_);
50 int numOfTemplates = dbobject_den->numOfTempl() + dbobject_num->numOfTempl();
51 templateStores_.reserve(numOfTemplates);
65 templ2D(templateStores_),
68 IDnum(conf.exists(
"TemplateIDnumerator") ? conf.getParameter<
int>(
"TemplateIDnumerator") : 0),
69 IDden(conf.exists(
"TemplateIDdenominator") ? conf.getParameter<
int>(
"TemplateIDdenominator") : 0),
72 applyLateReweighting_(conf.exists(
"applyLateReweighting") ? conf.getParameter<
bool>(
"applyLateReweighting")
80 edm::LogVerbatim(
"PixelDigitizer ") <<
"SiPixelChargeReweightingAlgorithm constructed" 87 LogDebug(
"PixelDigitizer") <<
"SiPixelChargeReweightingAlgorithm deleted";
93 std::map<
int,
float, std::less<int> >& hit_signal,
94 const size_t hitIndex,
95 const size_t hitIndex4CR,
96 const unsigned int tofBin,
100 unsigned short int processType,
101 const bool& boolmakeDigiSimLinks) {
102 int irow_min = topol->
nrows();
107 float chargeBefore = 0;
108 float chargeAfter = 0;
112 for (
std::map<
int,
float, std::less<int> >::const_iterator im = hit_signal.begin(); im != hit_signal.end(); ++im) {
113 int chan = (*im).first;
117 (*im).second, &
hit, hitIndex, hitIndex4CR, tofBin, (*im).second)
119 chargeBefore += (*im).second;
121 if (pixelWithCharge.first < irow_min)
122 irow_min = pixelWithCharge.first;
123 if (pixelWithCharge.first > irow_max)
124 irow_max = pixelWithCharge.first;
125 if (pixelWithCharge.second < icol_min)
126 icol_min = pixelWithCharge.second;
127 if (pixelWithCharge.second > icol_max)
128 icol_max = pixelWithCharge.second;
133 float trajectoryScaleToPosition =
std::abs(hitEntryPoint.
z() / direction.
z());
135 LocalPoint hitPosition = hitEntryPoint + trajectoryScaleToPosition * direction;
138 std::pair<int, int> hitPixel =
139 std::pair<int, int>(
int(floor(hitPositionPixel.
x())),
int(floor(hitPositionPixel.
y())));
146 std::pair<int, int> entryPixel =
147 std::pair<int, int>(
int(floor(hitEntryPointPixel.
x())),
int(floor(hitEntryPointPixel.
y())));
148 std::pair<int, int> exitPixel =
149 std::pair<int, int>(
int(floor(hitExitPointPixel.
x())),
int(floor(hitExitPointPixel.
y())));
151 int hitcol_min, hitcol_max, hitrow_min, hitrow_max;
152 if (entryPixel.first > exitPixel.first) {
153 hitrow_min = exitPixel.first;
154 hitrow_max = entryPixel.first;
156 hitrow_min = entryPixel.first;
157 hitrow_max = exitPixel.first;
160 if (entryPixel.second > exitPixel.second) {
161 hitcol_min = exitPixel.second;
162 hitcol_max = entryPixel.second;
164 hitcol_min = entryPixel.second;
165 hitcol_max = exitPixel.second;
172 <<
"Particle ID is: " <<
hit.particleType() <<
"\n" 173 <<
"Process type: " <<
hit.processType() <<
"\n" 176 <<
"Hit entry x/y/z: " <<
hit.entryPoint().
x() <<
" " <<
hit.entryPoint().
y() <<
" " 177 <<
hit.entryPoint().
z() <<
" " 178 <<
"Hit exit x/y/z: " <<
hit.exitPoint().
x() <<
" " <<
hit.exitPoint().
y() <<
" " 179 <<
hit.exitPoint().
z() <<
" " 181 <<
"Pixel Pos - X: " << hitPositionPixel.
x() <<
" Y: " << hitPositionPixel.
y() <<
"\n" 182 <<
"Cart.Cor. - X: " << CMSSWhitPosition.
x() <<
" Y: " << CMSSWhitPosition.
y() <<
"\n" 183 <<
"Z=0 Pos - X: " << hitPosition.x() <<
" Y: " << hitPosition.y() <<
"\n" 185 <<
"Origin of the template:" 187 <<
"Pixel Pos - X: " << originPixel.x() <<
" Y: " << originPixel.y() <<
"\n" 188 <<
"Cart.Cor. - X: " << origin.
x() <<
" Y: " << origin.
y() <<
"\n" 192 <<
"Entry - X: " <<
hit.entryPoint().
x() <<
" Y: " <<
hit.entryPoint().
y()
193 <<
" Z: " <<
hit.entryPoint().
z() <<
"\n" 194 <<
"Exit - X: " <<
hit.exitPoint().
x() <<
" Y: " <<
hit.exitPoint().
y()
195 <<
" Z: " <<
hit.exitPoint().
z() <<
"\n" 197 <<
"Entry - X Pixel: " << hitEntryPointPixel.
x() <<
" Y Pixel: " << hitEntryPointPixel.
y()
199 <<
"Exit - X Pixel: " << hitExitPointPixel.
x() <<
" Y Pixel: " << hitExitPointPixel.
y()
202 <<
"row min: " << irow_min <<
" col min: " << icol_min <<
"\n";
205 if (!(irow_min <= hitrow_max && irow_max >= hitrow_min && icol_min <= hitcol_max && icol_max >= hitcol_min)) {
213 track[3] = direction.x();
214 track[4] = direction.y();
215 track[5] = direction.z();
219 for (
int row = 0; row <
TXSIZE; ++row) {
221 pixrewgt[row][
col] = 0;
225 for (
int row = 0; row <
TXSIZE; ++row) {
240 for (
int row = rowmin; row < rowmax; ++row) {
241 for (
int col = colmin;
col < colmax; ++
col) {
249 LogDebug(
"PixelDigitizer ") <<
"Cluster before reweighting: ";
269 LogDebug(
"PixelDigitizer ") <<
"Cluster Charge Reweighting did not work properly.";
275 LogDebug(
"PixelDigitizer ") <<
"Cluster after reweighting: ";
279 for (
int row = rowmin; row < rowmax; ++row) {
280 for (
int col = colmin;
col < colmax; ++
col) {
285 (boolmakeDigiSimLinks
292 if (chargeBefore != 0. && chargeAfter == 0.) {
297 LogDebug(
"PixelDigitizer ") <<
"Charges (before->after): " << chargeBefore <<
" -> " << chargeAfter;
298 LogDebug(
"PixelDigitizer ") <<
"Charge loss: " << (1 - chargeAfter / chargeBefore) * 100 <<
" % \n";
315 int i,
j,
k,
l, kclose;
317 float xsize,
ysize, q50i, q100i, q50r, q10r, q100r, xhit2D, yhit2D, qclust, dist2, dmin2;
320 int goodWeightsUsed, nearbyWeightsUsed, noWeightsUsed;
321 float cotalpha, cotbeta;
339 LogDebug(
"Pixel Digitizer") <<
"Reweighting angle is not good! \n";
359 xy_rewgt[
j][
i] = 0.f;
370 LogDebug(
"Pixel Digitizer") <<
"No matching template found \n";
376 LogDebug(
"Pixel Digitizer") <<
"Template unirrad: \n";
386 if (cluster.num_dimensions() != 2) {
387 LogWarning(
"Pixel Digitizer") <<
"Cluster is not 2-dimensional. Return. \n";
390 nclusx = (
int)cluster.shape()[0];
391 nclusy = (
int)cluster.shape()[1];
393 LogWarning(
"Pixel Digitizer") <<
"Sizes in x do not match: nclusx=" << nclusx <<
" xdoubleSize=" <<
xdouble.size()
394 <<
" TXSIZE=" <<
TXSIZE <<
". Return. \n";
398 LogWarning(
"Pixel Digitizer") <<
"Sizes in y do not match. Return. \n";
407 xy_clust[
j][
i] = 0.f;
408 denx_clust[
j][
i] = 0;
409 deny_clust[
j][
i] = 0;
410 if (cluster[
j][
i] > q100i) {
411 qclust += cluster[
j][
i];
423 LogDebug(
"Pixel Digitizer") <<
"Template irrad: \n";
435 std::vector<int> ytclust;
436 std::vector<int> xtclust;
437 std::vector<int> ycclust;
438 std::vector<int> xcclust;
442 if (xy_in[
j + 1][
i + 1] > q100i) {
444 ytclust.push_back(
i);
445 xtclust.push_back(
j);
446 xy_clust[
j][
i] = xy_rewgt[
j + 1][
i + 1] / xy_in[
j + 1][
i + 1];
447 denx_clust[
j][
i] =
j;
448 deny_clust[
j][
i] =
i;
457 if (xy_rewgt[
j + 1][
i + 1] > q10r && xy_clust[
j][
i] == 0.
f && ntpix > 0) {
461 for (
k = 0;
k < ntpix; ++
k) {
462 dist2 = (
i - ytclust[
k]) * (
i - ytclust[
k]) + 0.44444f * (
j - xtclust[
k]) * (
j - xtclust[
k]);
468 xy_clust[
j][
i] = xy_rewgt[
j + 1][
i + 1] / xy_in[xtclust[kclose] + 1][ytclust[kclose] + 1];
469 denx_clust[
j][
i] = xtclust[kclose];
470 deny_clust[
j][
i] = ytclust[kclose];
476 LogDebug(
"Pixel Digitizer") <<
"Weights: \n";
482 nearbyWeightsUsed = 0;
487 if (xy_clust[
j][
i] > 0.
f) {
488 cluster[
j][
i] = xy_clust[
j][
i] * clust[denx_clust[
j][
i]][deny_clust[
j][
i]];
489 if (cluster[
j][
i] > q100r) {
490 qclust += cluster[
j][
i];
492 if (cluster[
j][
i] > 0) {
496 if (clust[
j][
i] > 0.
f) {
498 ycclust.push_back(
i);
499 xcclust.push_back(
j);
508 for (
l = 0;
l < ncpix; ++
l) {
513 for (
k = 0;
k < ntpix; ++
k) {
514 dist2 = (
i - ytclust[
k]) * (
i - ytclust[
k]) + 0.44444f * (
j - xtclust[
k]) * (
j - xtclust[
k]);
522 cluster[
j][
i] *= xy_clust[xtclust[kclose]][ytclust[kclose]];
523 if (cluster[
j][
i] > q100r) {
524 qclust += cluster[
j][
i];
538 for (
int row = 0; row <
TXSIZE; ++row) {
541 LogDebug(
"Pixel Digitizer") <<
"\n";
547 for (
int row = 0; row <
BXM2; ++row) {
550 LogDebug(
"Pixel Digitizer") <<
"\n";
556 for (
int row = 0; row <
TXSIZE; ++row) {
559 LogDebug(
"Pixel Digitizer") <<
"\n";
564 std::vector<PixelDigi>& digis,
568 CLHEP::HepRandomEngine* engine) {
573 LogError(
"Pixel Digitizer") <<
" ******************************** \n";
574 LogError(
"Pixel Digitizer") <<
" ******************************** \n";
575 LogError(
"Pixel Digitizer") <<
" ******************************** \n";
576 LogError(
"Pixel Digitizer") <<
" ***** INCONSISTENCY !!! ***** \n";
578 <<
" applyLateReweighting_ and UseReweighting can not be true at the same time for PU ! \n";
579 LogError(
"Pixel Digitizer") <<
" ---> DO NOT APPLY CHARGE REWEIGHTING TWICE !!! \n";
580 LogError(
"Pixel Digitizer") <<
" ******************************** \n";
581 LogError(
"Pixel Digitizer") <<
" ******************************** \n";
587 int irow_min = topol->
nrows();
592 float chargeBefore = 0;
593 float chargeAfter = 0;
596 std::vector<PixelDigi>::const_iterator loopDigi;
597 for (loopDigi = digis.begin(); loopDigi != digis.end(); ++loopDigi) {
598 unsigned int chan = loopDigi->channel();
600 float corresponding_charge = loopDigi->adc();
602 chargeBefore += corresponding_charge;
603 if (loopDigi->row() < irow_min)
604 irow_min = loopDigi->row();
605 if (loopDigi->row() > irow_max)
606 irow_max = loopDigi->row();
607 if (loopDigi->column() < icol_min)
608 icol_min = loopDigi->column();
609 if (loopDigi->column() > icol_max)
610 icol_max = loopDigi->column();
617 float trajectoryScaleToPosition =
std::abs(hitEntryPoint.
z() / direction.
z());
618 LocalPoint hitPosition = hitEntryPoint + trajectoryScaleToPosition * direction;
622 LocalPoint hitLocalPosition = hitEntryPoint + 0.5 * direction;
624 std::pair<int, int> hitPixel =
625 std::pair<int, int>(
int(floor(hitPositionPixel.
x())),
int(floor(hitPositionPixel.
y())));
632 std::pair<int, int> entryPixel =
633 std::pair<int, int>(
int(floor(hitEntryPointPixel.
x())),
int(floor(hitEntryPointPixel.
y())));
634 std::pair<int, int> exitPixel =
635 std::pair<int, int>(
int(floor(hitExitPointPixel.
x())),
int(floor(hitExitPointPixel.
y())));
637 int hitcol_min, hitcol_max, hitrow_min, hitrow_max;
638 if (entryPixel.first > exitPixel.first) {
639 hitrow_min = exitPixel.first;
640 hitrow_max = entryPixel.first;
642 hitrow_min = entryPixel.first;
643 hitrow_max = exitPixel.first;
646 if (entryPixel.second > exitPixel.second) {
647 hitcol_min = exitPixel.second;
648 hitcol_max = entryPixel.second;
650 hitcol_min = entryPixel.second;
651 hitcol_max = exitPixel.second;
654 if (!(irow_min <= hitrow_max && irow_max >= hitrow_min && icol_min <= hitcol_max && icol_max >= hitcol_min)) {
662 track[3] = direction.x();
663 track[4] = direction.y();
664 track[5] = direction.z();
676 for (
int row = 0; row <
TXSIZE; ++row) {
684 for (
int row = 0; row <
TXSIZE; ++row) {
693 LogDebug(
"Pixel Digitizer") <<
" Cluster before reweighting: ";
704 LogDebug(
"Pixel Digitizer") <<
" same template for num and den ";
710 LogDebug(
"PixelDigitizer ") <<
"Cluster Charge Reweighting did not work properly.";
715 LogDebug(
"Pixel Digitizer") <<
" Cluster after reweighting: ";
719 for (
int row = 0; row <
TXSIZE; ++row) {
723 if ((hitPixel.first + row -
THX) >= 0 && (hitPixel.first + row -
THX) < topol->
nrows() &&
732 if (chargeBefore != 0. && chargeAfter == 0.) {
737 LogDebug(
"Pixel Digitizer") <<
"Charges (before->after): " << chargeBefore <<
" -> " << chargeAfter;
738 LogDebug(
"Pixel Digitizer") <<
"Charge loss: " << (1 - chargeAfter / chargeBefore) * 100 <<
" %";
744 int chanDigi = (*i).first;
746 int row_digi = ip.first;
747 int col_digi = ip.second;
748 int i_transformed_row = row_digi - hitPixel.first +
THX;
749 int i_transformed_col = col_digi - hitPixel.second +
THY;
750 if (i_transformed_row < 0 || i_transformed_row >
TXSIZE || i_transformed_col < 0 || i_transformed_col >
TYSIZE) {
752 if (chanDigi >= 0 && (*i).second > 0) {
Log< level::Info, true > LogVerbatim
boost::multi_array< float, 2 > array_2d
const bool PrintTemplates
float xsize()
pixel x-size (microns)
bool xytemp(float xhit, float yhit, bool ydouble[21+2], bool xdouble[13+2], float template2d[13+2][21+2], bool dervatives, float dpdx2d[2][13+2][21+2], float &QTemplate)
static std::pair< int, int > channelToPixel(int ch)
virtual LocalPoint localPosition(const MeasurementPoint &) const =0
edm::ESGetToken< SiPixel2DTemplateDBObject, SiPixel2DTemplateDBObjectRcd > SiPixel2DTemp_num_token_
virtual int ncolumns() const =0
bool lateSignalReweight(const PixelGeomDetUnit *pixdet, std::vector< PixelDigi > &digis, PixelSimHitExtraInfo &loopTempSH, signal_map_type &theNewDigiSignal, const TrackerTopology *tTopo, CLHEP::HepRandomEngine *engine)
std::vector< bool > xdouble
virtual int nrows() const =0
std::map< int, SiPixelDigitizerAlgorithm::Amplitude, std::less< int > > signal_map_type
const bool UseReweighting
const SiPixel2DTemplateDBObject * dbobject_den
Log< level::Error, false > LogError
float s50()
1/2 of the pixel threshold signal in adc units
static int pixelToChannel(int row, int col)
bool applyLateReweighting_
Measurement2DPoint MeasurementPoint
Measurement points are two-dimensional by default.
SiPixelTemplate2D templ2D
virtual bool isItBigPixelInX(int ixbin) const =0
void init(const edm::EventSetup &es)
virtual bool isItBigPixelInY(int iybin) const =0
Abs< T >::type abs(const T &t)
virtual MeasurementPoint measurementPosition(const LocalPoint &) const =0
bool getData(T &iHolder) const
signal_map_type::const_iterator signal_map_const_iterator
DetId geographicalId() const
The label of this GeomDet.
const SiPixel2DTemplateDBObject * dbobject_num
void printCluster(array_2d &cluster)
int PixelTempRewgt2D(int id_gen, int id_rewgt, array_2d &cluster)
constexpr uint32_t rawId() const
get the raw id
SiPixelChargeReweightingAlgorithm(const edm::ParameterSet &conf, edm::ConsumesCollector iC)
~SiPixelChargeReweightingAlgorithm()
std::vector< bool > ydouble
chan
lumi = TPaveText(lowX+0.38, lowY+0.061, lowX+0.45, lowY+0.161, "NDC") lumi.SetBorderSize( 0 ) lumi...
float ysize()
pixel y-size (microns)
short getTemplateID(const uint32_t &detid) const
edm::ESGetToken< SiPixel2DTemplateDBObject, SiPixel2DTemplateDBObjectRcd > SiPixel2DTemp_den_token_
virtual const PixelTopology & specificTopology() const
Returns a reference to the pixel proxy topology.
bool hitSignalReweight(const PSimHit &hit, std::map< int, float, std::less< int > > &hit_signal, const size_t hitIndex, const size_t hitIndex4CR, const unsigned int tofBin, const PixelTopology *topol, uint32_t detID, signal_map_type &theSignal, unsigned short int processType, const bool &boolmakeDigiSimLinks)
std::vector< float > track
static bool pushfile(int filenum, std::vector< SiPixelTemplateStore2D > &pixelTemp, std::string dir="CalibTracker/SiPixelESProducers/data/")
Log< level::Warning, false > LogWarning
static constexpr float cmToMicrons