54 #include <gsl/gsl_sf_erf.h>
56 #include "CLHEP/Random/RandGaussQ.h"
57 #include "CLHEP/Random/RandFlat.h"
58 #include "CLHEP/Random/RandGeneral.h"
116 if (use_ineff_from_db_) {
117 theSiPixelGainCalibrationService_->setESObjects(es);
119 if (use_deadmodule_DB_) {
122 if (use_LorentzAngle_DB_) {
133 quality_map = PixelFEDChannelCollectionMapHandle.product();
136 std::vector<std::string> allScenarios;
140 std::back_inserter(allScenarios),
143 std::vector<std::string> allScenariosInProb;
145 for (
auto it = m_probabilities.begin(); it != m_probabilities.end(); ++it) {
147 for (
const auto&
entry : it->second) {
149 auto probability =
entry.second;
150 if (probability != 0) {
151 if (
std::find(allScenariosInProb.begin(), allScenariosInProb.end(),
scenario) == allScenariosInProb.end()) {
152 allScenariosInProb.push_back(
scenario);
159 std::copy_if(allScenariosInProb.begin(),
160 allScenariosInProb.end(),
163 return (
std::find(allScenarios.begin(), allScenarios.end(),
arg) == allScenarios.end());
169 <<
"The requested scenario: " <<
entry <<
" is not found in the map!!" << std::endl;
172 <<
" missing scenario(s) in SiPixelStatusScenariosRcd while "
173 "present in SiPixelStatusScenarioProbabilityRcd \n";
181 dbobject_den = SiPixel2DTemp_den.
product();
185 dbobject_num = SiPixel2DTemp_num.
product();
187 int numOfTemplates = dbobject_den->
numOfTempl() + dbobject_num->numOfTempl();
188 templateStores_.reserve(numOfTemplates);
202 conf.getParameter<
std::
string>(
"SiPixelQualityLabel")),
204 makeDigiSimLinks_(conf.getUntrackedParameter<
bool>(
"makeDigiSimLinks",
true)),
205 use_ineff_from_db_(conf.getParameter<
bool>(
"useDB")),
206 use_module_killing_(conf.getParameter<
bool>(
"killModules")),
207 use_deadmodule_DB_(conf.getParameter<
bool>(
"DeadModules_DB")),
208 use_LorentzAngle_DB_(conf.getParameter<
bool>(
"LorentzAngle_DB")),
211 : conf.getParameter<
Parameters>(
"DeadModules")),
213 templ2D(templateStores_),
216 IDnum(conf.exists(
"TemplateIDnumerator") ? conf.getParameter<
int>(
"TemplateIDnumerator") : 0),
217 IDden(conf.exists(
"TemplateIDdenominator") ? conf.getParameter<
int>(
"TemplateIDdenominator") : 0),
221 GeVperElectron(3.61E-09),
224 alpha2Order(conf.getParameter<
bool>(
"Alpha2Order")),
230 NumberOfBarrelLayers(conf.exists(
"NumPixelBarrel") ? conf.getParameter<
int>(
"NumPixelBarrel") : 3),
238 theElectronPerADC(conf.getParameter<double>(
"ElectronPerAdc")),
242 theAdcFullScale(conf.getParameter<
int>(
"AdcFullScale")),
246 theNoiseInElectrons(conf.getParameter<double>(
"NoiseInElectrons")),
250 theReadoutNoise(conf.getParameter<double>(
"ReadoutNoiseInElec")),
255 theThresholdInE_FPix(conf.getParameter<double>(
"ThresholdInElectrons_FPix")),
256 theThresholdInE_BPix(conf.getParameter<double>(
"ThresholdInElectrons_BPix")),
257 theThresholdInE_BPix_L1(conf.exists(
"ThresholdInElectrons_BPix_L1")
258 ? conf.getParameter<double>(
"ThresholdInElectrons_BPix_L1")
259 : theThresholdInE_BPix),
260 theThresholdInE_BPix_L2(conf.exists(
"ThresholdInElectrons_BPix_L2")
261 ? conf.getParameter<double>(
"ThresholdInElectrons_BPix_L2")
262 : theThresholdInE_BPix),
265 theThresholdSmearing_FPix(conf.getParameter<double>(
"ThresholdSmearing_FPix")),
266 theThresholdSmearing_BPix(conf.getParameter<double>(
"ThresholdSmearing_BPix")),
267 theThresholdSmearing_BPix_L1(conf.exists(
"ThresholdSmearing_BPix_L1")
268 ? conf.getParameter<double>(
"ThresholdSmearing_BPix_L1")
269 : theThresholdSmearing_BPix),
270 theThresholdSmearing_BPix_L2(conf.exists(
"ThresholdSmearing_BPix_L2")
271 ? conf.getParameter<double>(
"ThresholdSmearing_BPix_L2")
272 : theThresholdSmearing_BPix),
275 electronsPerVCAL(conf.getParameter<double>(
"ElectronsPerVcal")),
276 electronsPerVCAL_Offset(conf.getParameter<double>(
"ElectronsPerVcal_Offset")),
277 electronsPerVCAL_L1(conf.exists(
"ElectronsPerVcal_L1") ? conf.getParameter<double>(
"ElectronsPerVcal_L1")
279 electronsPerVCAL_L1_Offset(conf.exists(
"ElectronsPerVcal_L1_Offset")
280 ? conf.getParameter<double>(
"ElectronsPerVcal_L1_Offset")
281 : electronsPerVCAL_Offset),
285 theTofLowerCut(conf.getParameter<double>(
"TofLowerCut")),
286 theTofUpperCut(conf.getParameter<double>(
"TofUpperCut")),
289 tanLorentzAnglePerTesla_FPix(use_LorentzAngle_DB_ ? 0.0
290 : conf.getParameter<double>(
"TanLorentzAnglePerTesla_FPix")),
291 tanLorentzAnglePerTesla_BPix(use_LorentzAngle_DB_ ? 0.0
292 : conf.getParameter<double>(
"TanLorentzAnglePerTesla_BPix")),
295 FPix_p0(conf.getParameter<double>(
"FPix_SignalResponse_p0")),
296 FPix_p1(conf.getParameter<double>(
"FPix_SignalResponse_p1")),
297 FPix_p2(conf.getParameter<double>(
"FPix_SignalResponse_p2")),
298 FPix_p3(conf.getParameter<double>(
"FPix_SignalResponse_p3")),
300 BPix_p0(conf.getParameter<double>(
"BPix_SignalResponse_p0")),
301 BPix_p1(conf.getParameter<double>(
"BPix_SignalResponse_p1")),
302 BPix_p2(conf.getParameter<double>(
"BPix_SignalResponse_p2")),
303 BPix_p3(conf.getParameter<double>(
"BPix_SignalResponse_p3")),
306 addNoise(conf.getParameter<
bool>(
"AddNoise")),
310 addChargeVCALSmearing(conf.getParameter<
bool>(
"ChargeVCALSmearing")),
313 addNoisyPixels(conf.getParameter<
bool>(
"AddNoisyPixels")),
316 fluctuateCharge(conf.getUntrackedParameter<
bool>(
"FluctuateCharge",
true)),
323 addThresholdSmearing(conf.getParameter<
bool>(
"AddThresholdSmearing")),
326 doMissCalibrate(conf.getParameter<
bool>(
"MissCalibrate")),
327 theGainSmearing(conf.getParameter<double>(
"GainSmearing")),
328 theOffsetSmearing(conf.getParameter<double>(
"OffsetSmearing")),
331 AddPixelAging(conf.getParameter<
bool>(
"DoPixelAging")),
339 tMax(conf.getParameter<double>(
"deltaProductionCut")),
348 LogInfo(
"PixelDigitizer ") <<
"SiPixelDigitizerAlgorithm constructed"
349 <<
"Configuration parameters:"
350 <<
"Threshold/Gain = "
364 std::map<int, SiPixelDigitizerAlgorithm::CalParameters, std::less<int> >
calmap;
366 LogDebug(
"PixelDigitizer ") <<
" miss-calibrate the pixel amplitude ";
368 const bool ReadCalParameters =
false;
369 if (ReadCalParameters) {
371 std::ifstream in_file;
372 char filename[80] =
"phCalibrationFit_C0.dat";
376 cout <<
" File not found " << endl;
382 for (
int i = 0;
i < 3;
i++) {
383 in_file.getline(
line, 500,
'\n');
387 cout <<
" test map" << endl;
393 for (
int i = 0;
i < (52 * 80);
i++) {
396 cerr <<
"Cannot read data file" << endl;
399 if (in_file.eof() != 0) {
400 cerr << in_file.eof() <<
" " << in_file.gcount() <<
" " << in_file.fail() <<
" " << in_file.good()
401 <<
" end of file " << endl;
416 calmap.insert(std::pair<int, CalParameters>(
chan, onePix));
420 if (rowid !=
p.first)
421 cout <<
" wrong channel row " << rowid <<
" " <<
p.first << endl;
422 if (colid !=
p.second)
423 cout <<
" wrong channel col " << colid <<
" " <<
p.second << endl;
450 LogDebug(
"PixelDigitizer") <<
"SiPixelDigitizerAlgorithm deleted";
456 int NumberOfBarrelLayers,
464 conf.
exists(
"thePixelColEfficiency_BPix3") && conf.
exists(
"thePixelColEfficiency_FPix1") &&
465 conf.
exists(
"thePixelColEfficiency_FPix2") && conf.
exists(
"thePixelEfficiency_BPix1") &&
466 conf.
exists(
"thePixelEfficiency_BPix2") && conf.
exists(
"thePixelEfficiency_BPix3") &&
467 conf.
exists(
"thePixelEfficiency_FPix1") && conf.
exists(
"thePixelEfficiency_FPix2") &&
468 conf.
exists(
"thePixelChipEfficiency_BPix1") && conf.
exists(
"thePixelChipEfficiency_BPix2") &&
469 conf.
exists(
"thePixelChipEfficiency_BPix3") && conf.
exists(
"thePixelChipEfficiency_FPix1") &&
470 conf.
exists(
"thePixelChipEfficiency_FPix2");
473 conf.
exists(
"theLadderEfficiency_BPix3") && conf.
exists(
"theModuleEfficiency_BPix1") &&
474 conf.
exists(
"theModuleEfficiency_BPix2") && conf.
exists(
"theModuleEfficiency_BPix3") &&
475 conf.
exists(
"thePUEfficiency_BPix1") && conf.
exists(
"thePUEfficiency_BPix2") &&
476 conf.
exists(
"thePUEfficiency_BPix3") && conf.
exists(
"theInnerEfficiency_FPix1") &&
477 conf.
exists(
"theInnerEfficiency_FPix2") && conf.
exists(
"theOuterEfficiency_FPix1") &&
478 conf.
exists(
"theOuterEfficiency_FPix2") && conf.
exists(
"thePUEfficiency_FPix_Inner") &&
479 conf.
exists(
"thePUEfficiency_FPix_Outer") && conf.
exists(
"theInstLumiScaleFactor");
482 conf.
exists(
"thePixelEfficiency_BPix4") && conf.
exists(
"thePixelChipEfficiency_BPix4");
485 conf.
exists(
"thePixelEfficiency_FPix3") && conf.
exists(
"thePixelChipEfficiency_FPix3");
487 LogInfo(
"PixelDigitizer ") <<
"The PixelDigitizer inefficiency configuration is read from the config file.\n";
521 throw cms::Exception(
"Configuration") <<
"Wrong ladder number in efficiency config!";
530 throw cms::Exception(
"Configuration") <<
"Wrong module number in efficiency config!";
538 <<
"At least one PU efficiency (BPix) number is needed in efficiency config!";
542 if (NumberOfTotLayers > 20) {
543 throw cms::Exception(
"Configuration") <<
"SiPixelDigitizer was given more layers than it can handle";
573 if (NumberOfTotLayers > 20) {
574 throw cms::Exception(
"Configuration") <<
"SiPixelDigitizer was given more layers than it can handle";
595 <<
"At least one (FPix) PU efficiency number is needed in efficiency config!";
599 LogInfo(
"PixelDigitizer ") <<
"The PixelDigitizer inefficiency configuration is read from the database.\n";
627 for (
const auto& it_module :
geom->detUnits()) {
628 if (dynamic_cast<PixelGeomDetUnit const*>(it_module) ==
nullptr)
630 const DetId detid = it_module->geographicalId();
631 uint32_t rawid = detid.
rawId();
632 PixelGeomFactors[rawid] = 1;
633 ColGeomFactors[rawid] = 1;
634 ChipGeomFactors[rawid] = 1;
635 PixelGeomFactorsROCStdPixels[rawid] = std::vector<double>(16, 1);
636 PixelGeomFactorsROCBigPixels[rawid] = std::vector<double>(16, 1);
640 std::map<uint32_t, double> PixelGeomFactorsDB;
643 for (
auto db_factor : PixelGeomFactorsDBIn) {
646 unsigned int rocMask = rocIdMaskBits <<
shift;
647 unsigned int rocId = (((db_factor.first) & rocMask) >>
shift);
650 unsigned int rawid = db_factor.first & (~rocMask);
651 const PixelGeomDetUnit* theGeomDet = dynamic_cast<const PixelGeomDetUnit*>(
geom->idToDet(rawid));
654 const int nBigPixelsInROC = 2 *
topology->rowsperroc() +
topology->colsperroc() - 2;
655 double factor = db_factor.second;
656 double badFraction = 1 -
factor;
657 double bigPixelFraction = static_cast<double>(nBigPixelsInROC) / nPixelsInROC;
658 double stdPixelFraction = 1. - bigPixelFraction;
660 double badFractionBig =
std::min(bigPixelFraction, badFraction);
661 double badFractionStd =
std::max(0., badFraction - badFractionBig);
662 double badFractionBigReNormalized = badFractionBig / bigPixelFraction;
663 double badFractionStdReNormalized = badFractionStd / stdPixelFraction;
664 PixelGeomFactorsROCStdPixels[rawid][rocId] *= (1. - badFractionStdReNormalized);
665 PixelGeomFactorsROCBigPixels[rawid][rocId] *= (1. - badFractionBigReNormalized);
667 PixelGeomFactorsDB[db_factor.first] = db_factor.second;
672 PixelGeomFactorsDB = PixelGeomFactorsDBIn;
676 for (
const auto& it_module :
geom->detUnits()) {
677 if (dynamic_cast<PixelGeomDetUnit const*>(it_module) ==
nullptr)
679 const DetId detid = it_module->geographicalId();
680 uint32_t rawid = detid.
rawId();
681 for (
auto db_factor : PixelGeomFactorsDB)
683 PixelGeomFactors[rawid] *= db_factor.second;
684 for (
auto db_factor : ColGeomFactorsDB)
686 ColGeomFactors[rawid] *= db_factor.second;
687 for (
auto db_factor : ChipGeomFactorsDB)
689 ChipGeomFactors[rawid] *= db_factor.second;
695 for (
auto factor : PUFactors) {
697 for (
const auto& it_module :
geom->detUnits()) {
698 if (dynamic_cast<PixelGeomDetUnit const*>(it_module) ==
nullptr)
700 const DetId detid = it_module->geographicalId();
701 if (!
matches(detid, db_id, DetIdmasks))
703 if (iPU.count(detid.
rawId())) {
705 <<
"Multiple db_ids match to same module in SiPixelDynamicInefficiency DB Object";
710 thePUEfficiency.push_back(
factor.second);
713 pu_scale.resize(thePUEfficiency.size());
718 const std::vector<uint32_t>& DetIdmasks) {
721 for (
size_t i = 0;
i < DetIdmasks.size(); ++
i) {
743 thePixelPseudoRadDamage[
i++] = conf.
getParameter<
double>(
"thePixelPseudoRadDamage_BPix1");
744 thePixelPseudoRadDamage[
i++] = conf.
getParameter<
double>(
"thePixelPseudoRadDamage_BPix2");
745 thePixelPseudoRadDamage[
i++] = conf.
getParameter<
double>(
"thePixelPseudoRadDamage_BPix3");
746 thePixelPseudoRadDamage[
i++] = conf.
getParameter<
double>(
"thePixelPseudoRadDamage_BPix4");
750 if (NumberOfTotLayers > 20) {
751 throw cms::Exception(
"Configuration") <<
"SiPixelDigitizer was given more layers than it can handle";
755 thePixelPseudoRadDamage[
j - 1] = 0.;
760 thePixelPseudoRadDamage[
i++] = conf.
getParameter<
double>(
"thePixelPseudoRadDamage_FPix1");
761 thePixelPseudoRadDamage[
i++] = conf.
getParameter<
double>(
"thePixelPseudoRadDamage_FPix2");
762 thePixelPseudoRadDamage[
i++] = conf.
getParameter<
double>(
"thePixelPseudoRadDamage_FPix3");
766 if (NumberOfTotLayers > 20) {
767 throw cms::Exception(
"Configuration") <<
"SiPixelDigitizer was given more layers than it can handle";
771 thePixelPseudoRadDamage[
j - 1] = 0.;
781 std::vector<PSimHit>::const_iterator inputEnd,
782 const size_t inputBeginGlobalIndex,
783 const unsigned int tofBin,
787 CLHEP::HepRandomEngine* engine) {
792 size_t simHitGlobalIndex = inputBeginGlobalIndex;
793 for (std::vector<PSimHit>::const_iterator ssbegin = inputBegin; ssbegin != inputEnd; ++ssbegin, ++simHitGlobalIndex) {
795 if ((*ssbegin).detUnitId() != detId) {
800 LogDebug(
"Pixel Digitizer") << (*ssbegin).particleType() <<
" " << (*ssbegin).pabs() <<
" "
801 << (*ssbegin).energyLoss() <<
" " << (*ssbegin).tof() <<
" " << (*ssbegin).trackId()
802 <<
" " << (*ssbegin).processType() <<
" " << (*ssbegin).detUnitId()
803 << (*ssbegin).entryPoint() <<
" " << (*ssbegin).exitPoint();
806 std::vector<EnergyDepositUnit> ionization_points;
807 std::vector<SignalPoint> collection_points;
842 std::vector<int>::const_iterator
pu;
843 std::vector<int>::const_iterator pu0 = bunchCrossing.end();
845 for (
pu = bunchCrossing.begin();
pu != bunchCrossing.end(); ++
pu) {
852 if (pu0 != bunchCrossing.end()) {
855 double instlumi_pow = 1.;
859 instlumi_pow *= instlumi;
873 for (
unsigned int i = 0;
i < ps.size();
i++)
874 if (ps[
i].getBunchCrossing() == 0)
880 double instlumi_pow = 1.;
884 instlumi_pow *= instlumi;
899 const std::vector<PileupSummaryInfo>& ps, CLHEP::HepRandomEngine* engine) {
900 std::unique_ptr<PixelFEDChannelCollection> PixelFEDChannelCollection_ =
nullptr;
903 std::vector<int> bunchCrossing;
904 std::vector<float> TrueInteractionList;
906 for (
unsigned int i = 0;
i < ps.size();
i++) {
907 bunchCrossing.push_back(ps[
i].getBunchCrossing());
908 TrueInteractionList.push_back(ps[
i].getTrueNumInteractions());
912 std::vector<int>::const_iterator
pu;
913 std::vector<int>::const_iterator pu0 = bunchCrossing.end();
915 for (
pu = bunchCrossing.begin();
pu != bunchCrossing.end(); ++
pu) {
923 if (pu0 != bunchCrossing.end()) {
924 unsigned int PUBin = TrueInteractionList.at(
p);
926 std::vector<double> probabilities;
927 probabilities.reserve(theProbabilitiesPerScenario.size());
928 for (
auto it = theProbabilitiesPerScenario.begin(); it != theProbabilitiesPerScenario.end(); it++) {
929 probabilities.push_back(it->second);
932 CLHEP::RandGeneral randGeneral(*engine, &(probabilities.front()), probabilities.size());
933 double x = randGeneral.shoot();
934 unsigned int index =
x * probabilities.size() - 1;
937 PixelFEDChannelCollection_ = std::make_unique<PixelFEDChannelCollection>(
quality_map->at(
scenario));
942 return PixelFEDChannelCollection_;
946 CLHEP::HepRandomEngine* engine) {
949 std::unique_ptr<PixelFEDChannelCollection> PixelFEDChannelCollection_ =
nullptr;
956 std::vector<int>::const_iterator
pu;
957 std::vector<int>::const_iterator pu0 = bunchCrossing.end();
959 for (
pu = bunchCrossing.begin();
pu != bunchCrossing.end(); ++
pu) {
967 if (pu0 != bunchCrossing.end()) {
968 unsigned int PUBin = TrueInteractionList.at(
p);
970 std::vector<double> probabilities;
971 probabilities.reserve(theProbabilitiesPerScenario.size());
972 for (
auto it = theProbabilitiesPerScenario.begin(); it != theProbabilitiesPerScenario.end(); it++) {
973 probabilities.push_back(it->second);
976 CLHEP::RandGeneral randGeneral(*engine, &(probabilities.front()), probabilities.size());
977 double x = randGeneral.shoot();
978 unsigned int index =
x * probabilities.size() - 1;
981 PixelFEDChannelCollection_ = std::make_unique<PixelFEDChannelCollection>(
quality_map->at(
scenario));
986 return PixelFEDChannelCollection_;
991 for (
const auto& det : signalMap) {
992 auto& theSignal =
_signal[det.first];
993 for (
const auto&
chan : det.second) {
994 theSignal[
chan.first].set(
chan.second *
1002 std::vector<PixelDigi>& digis,
1003 std::vector<PixelDigiSimLink>& simlinks,
1005 CLHEP::HepRandomEngine* engine) {
1017 float thePixelThresholdInE = 0.;
1021 int lay = tTopo->
layer(detID);
1026 thePixelThresholdInE = CLHEP::RandGaussQ::shoot(
1028 }
else if (lay == 2) {
1029 thePixelThresholdInE = CLHEP::RandGaussQ::shoot(
1032 thePixelThresholdInE =
1041 }
else if (lay == 2) {
1050 thePixelThresholdInE =
1056 throw cms::Exception(
"NotAPixelGeomDetUnit") <<
"Not a pixel geomdet unit" << detID;
1062 int numColumns = topol->
ncolumns();
1063 int numRows = topol->
nrows();
1066 LogDebug(
"PixelDigitizer") <<
" PixelDigitizer " << numColumns <<
" " << numRows <<
" " << moduleThickness;
1088 make_digis(thePixelThresholdInE, detID, pixdet, digis, simlinks, tTopo);
1091 LogDebug(
"PixelDigitizer") <<
"[SiPixelDigitizerAlgorithm] converted " << digis.size() <<
" PixelDigis in DetUnit"
1100 std::vector<EnergyDepositUnit>& ionization_points,
1101 CLHEP::HepRandomEngine* engine)
const {
1104 const float SegmentLength = 0.0010;
1111 float length = direction.
mag();
1113 int NumberOfSegments =
int(length / SegmentLength);
1114 if (NumberOfSegments < 1)
1115 NumberOfSegments = 1;
1118 LogDebug(
"Pixel Digitizer") <<
" enter primary_ionzation " << NumberOfSegments
1119 <<
" shift = " << (
hit.exitPoint().
x() -
hit.entryPoint().
x()) <<
" "
1120 << (
hit.exitPoint().
y() -
hit.entryPoint().
y()) <<
" "
1121 << (
hit.exitPoint().
z() -
hit.entryPoint().
z()) <<
" " <<
hit.particleType() <<
" "
1125 float* elossVector =
new float[NumberOfSegments];
1129 int pid =
hit.particleType();
1132 float momentum =
hit.pabs();
1137 ionization_points.resize(NumberOfSegments);
1140 for (
int i = 0;
i != NumberOfSegments;
i++) {
1150 ionization_points[
i] = edu;
1153 LogDebug(
"Pixel Digitizer") <<
i <<
" " << ionization_points[
i].x() <<
" " << ionization_points[
i].y() <<
" "
1154 << ionization_points[
i].z() <<
" " << ionization_points[
i].energy();
1159 delete[] elossVector;
1166 float particleMomentum,
1170 float elossVector[],
1171 CLHEP::HepRandomEngine* engine)
const {
1177 double particleMass = 139.6;
1181 particleMass = 0.511;
1183 particleMass = 105.7;
1184 else if (pid == 321)
1185 particleMass = 493.7;
1186 else if (pid == 2212)
1187 particleMass = 938.3;
1190 float segmentLength = length / NumberOfSegs;
1195 double segmentEloss = (1000. * eloss) / NumberOfSegs;
1196 for (
int i = 0;
i < NumberOfSegs;
i++) {
1202 double deltaCutoff =
tMax;
1203 de =
fluctuate->SampleFluctuations(
double(particleMomentum * 1000.),
1206 double(segmentLength * 10.),
1210 elossVector[
i] = de;
1216 float ratio = eloss / sum;
1218 for (
int ii = 0;
ii < NumberOfSegs;
ii++)
1219 elossVector[
ii] =
ratio * elossVector[
ii];
1221 float averageEloss = eloss / NumberOfSegs;
1222 for (
int ii = 0;
ii < NumberOfSegs;
ii++)
1223 elossVector[
ii] = averageEloss;
1235 const std::vector<EnergyDepositUnit>& ionization_points,
1236 std::vector<SignalPoint>& collection_points)
const {
1238 LogDebug(
"Pixel Digitizer") <<
" enter drift ";
1241 collection_points.resize(ionization_points.size());
1244 if (driftDir.
z() == 0.) {
1245 LogWarning(
"Magnetic field") <<
" pxlx: drift in z is zero ";
1253 float TanLorenzAngleX, TanLorenzAngleY, dir_z, CosLorenzAngleX, CosLorenzAngleY;
1255 TanLorenzAngleX = driftDir.
x();
1256 TanLorenzAngleY = driftDir.
y();
1257 dir_z = driftDir.
z();
1258 CosLorenzAngleX = 1. /
sqrt(1. + TanLorenzAngleX * TanLorenzAngleX);
1259 CosLorenzAngleY = 1. /
sqrt(1. + TanLorenzAngleY * TanLorenzAngleY);
1262 TanLorenzAngleX = driftDir.
x();
1263 TanLorenzAngleY = 0.;
1264 dir_z = driftDir.
z();
1265 CosLorenzAngleX = 1. /
sqrt(1. + TanLorenzAngleX * TanLorenzAngleX);
1266 CosLorenzAngleY = 1.;
1271 LogDebug(
"Pixel Digitizer") <<
" Lorentz Tan " << TanLorenzAngleX <<
" " << TanLorenzAngleY <<
" " << CosLorenzAngleX
1272 <<
" " << CosLorenzAngleY <<
" " << moduleThickness * TanLorenzAngleX <<
" " << driftDir;
1277 float DriftDistance;
1281 for (
unsigned int i = 0;
i != ionization_points.size();
i++) {
1282 float SegX, SegY, SegZ;
1283 SegX = ionization_points[
i].
x();
1284 SegY = ionization_points[
i].y();
1285 SegZ = ionization_points[
i].z();
1290 DriftDistance = moduleThickness / 2. - (dir_z * SegZ);
1300 if (DriftDistance < 0.) {
1302 }
else if (DriftDistance > moduleThickness)
1303 DriftDistance = moduleThickness;
1306 float XDriftDueToMagField = DriftDistance * TanLorenzAngleX;
1307 float YDriftDueToMagField = DriftDistance * TanLorenzAngleY;
1310 float CloudCenterX = SegX + XDriftDueToMagField;
1311 float CloudCenterY = SegY + YDriftDueToMagField;
1314 DriftLength =
sqrt(DriftDistance * DriftDistance + XDriftDueToMagField * XDriftDueToMagField +
1315 YDriftDueToMagField * YDriftDueToMagField);
1321 Sigma_x = Sigma / CosLorenzAngleX;
1322 Sigma_y = Sigma / CosLorenzAngleY;
1325 float energyOnCollector = ionization_points[
i].energy();
1330 energyOnCollector *=
exp(-1 * kValue * DriftDistance / moduleThickness);
1334 LogDebug(
"Pixel Digitizer") <<
" Dift DistanceZ= " << DriftDistance <<
" module thickness= " << moduleThickness
1335 <<
" Start Energy= " << ionization_points[
i].energy()
1336 <<
" Energy after loss= " << energyOnCollector;
1338 SignalPoint sp(CloudCenterX, CloudCenterY, Sigma_x, Sigma_y,
hit.tof(), energyOnCollector);
1341 collection_points[
i] = (sp);
1350 std::vector<PSimHit>::const_iterator inputEnd,
1352 const size_t hitIndex,
1353 const unsigned int tofBin,
1355 const std::vector<SignalPoint>& collection_points) {
1364 LogDebug(
"Pixel Digitizer") <<
" enter induce_signal, " << topol->
pitch().first <<
" " << topol->
pitch().second;
1368 typedef std::map<int, float, std::less<int> > hit_map_type;
1369 hit_map_type hit_signal;
1372 std::map<int, float, std::less<int> >
x,
y;
1377 for (std::vector<SignalPoint>::const_iterator
i = collection_points.begin();
i != collection_points.end(); ++
i) {
1378 float CloudCenterX =
i->position().x();
1379 float CloudCenterY =
i->position().y();
1382 float Charge =
i->amplitude();
1391 LogDebug(
"Pixel Digitizer") <<
" cloud " <<
i->position().x() <<
" " <<
i->position().y() <<
" " <<
i->sigma_x()
1392 <<
" " <<
i->sigma_y() <<
" " <<
i->amplitude();
1415 int IPixRightUpX =
int(floor(mp.
x()));
1416 int IPixRightUpY =
int(floor(mp.
y()));
1419 LogDebug(
"Pixel Digitizer") <<
" right-up " << PointRightUp <<
" " << mp.
x() <<
" " << mp.
y() <<
" " << IPixRightUpX
1420 <<
" " << IPixRightUpY;
1425 int IPixLeftDownX =
int(floor(mp.
x()));
1426 int IPixLeftDownY =
int(floor(mp.
y()));
1429 LogDebug(
"Pixel Digitizer") <<
" left-down " << PointLeftDown <<
" " << mp.
x() <<
" " << mp.
y() <<
" "
1430 << IPixLeftDownX <<
" " << IPixLeftDownY;
1434 int numColumns = topol->
ncolumns();
1435 int numRows = topol->
nrows();
1437 IPixRightUpX = numRows > IPixRightUpX ? IPixRightUpX : numRows - 1;
1438 IPixRightUpY = numColumns > IPixRightUpY ? IPixRightUpY : numColumns - 1;
1439 IPixLeftDownX = 0 < IPixLeftDownX ? IPixLeftDownX : 0;
1440 IPixLeftDownY = 0 < IPixLeftDownY ? IPixLeftDownY : 0;
1447 for (ix = IPixLeftDownX; ix <= IPixRightUpX; ix++) {
1448 float xUB, xLB, UpperBound, LowerBound;
1453 if (ix == 0 ||
SigmaX == 0.)
1458 LowerBound = 1 -
calcQ((xLB - CloudCenterX) /
SigmaX);
1461 if (ix == numRows - 1 ||
SigmaX == 0.)
1466 UpperBound = 1. -
calcQ((xUB - CloudCenterX) /
SigmaX);
1469 float TotalIntegrationRange = UpperBound - LowerBound;
1470 x[ix] = TotalIntegrationRange;
1477 for (iy = IPixLeftDownY; iy <= IPixRightUpY; iy++) {
1478 float yUB, yLB, UpperBound, LowerBound;
1480 if (iy == 0 ||
SigmaY == 0.)
1485 LowerBound = 1. -
calcQ((yLB - CloudCenterY) /
SigmaY);
1488 if (iy == numColumns - 1 ||
SigmaY == 0.)
1493 UpperBound = 1. -
calcQ((yUB - CloudCenterY) /
SigmaY);
1496 float TotalIntegrationRange = UpperBound - LowerBound;
1497 y[iy] = TotalIntegrationRange;
1504 for (ix = IPixLeftDownX; ix <= IPixRightUpX; ix++) {
1505 for (iy = IPixLeftDownY; iy <= IPixRightUpY; iy++) {
1507 float ChargeFraction =
Charge *
x[ix] *
y[iy];
1509 if (ChargeFraction > 0.) {
1512 hit_signal[
chan] += ChargeFraction;
1519 LogDebug(
"Pixel Digitizer") <<
" pixel " << ix <<
" " << iy <<
" - "
1520 <<
" " <<
chan <<
" " << ChargeFraction <<
" " << mp.
x() <<
" " << mp.
y() <<
" "
1521 << lp.
x() <<
" " << lp.
y() <<
" "
1532 bool reweighted =
false;
1534 if (
hit.processType() == 0) {
1535 reweighted =
hitSignalReweight(
hit, hit_signal, hitIndex, tofBin, topol, detID, theSignal,
hit.processType());
1539 hitSignalReweight((*inputBegin), hit_signal, hitIndex, tofBin, topol, detID, theSignal,
hit.processType());
1543 for (hit_map_type::const_iterator im = hit_signal.begin(); im != hit_signal.end(); ++im) {
1544 int chan = (*im).first;
1546 :
Amplitude((*im).second, (*im).second));
1550 LogDebug(
"Pixel Digitizer") <<
" pixel " << ip.first <<
" " << ip.second <<
" " << theSignal[
chan];
1563 std::vector<PixelDigi>& digis,
1564 std::vector<PixelDigiSimLink>& simlinks,
1567 LogDebug(
"Pixel Digitizer") <<
" make digis "
1573 <<
" List pixels passing threshold ";
1578 signalMaps::const_iterator it =
_signal.find(detID);
1587 std::map<TrackEventId, float> simi;
1590 float signalInElectrons = (*i).second;
1597 if (signalInElectrons >= thePixelThresholdInE &&
1598 signalInElectrons > 0.) {
1600 int chan = (*i).first;
1607 int col = ip.second;
1614 LogDebug(
"Pixel Digitizer") << (*i).first <<
" " << (*i).second <<
" " << signalInElectrons <<
" " <<
adc
1615 << ip.first <<
" " << ip.second;
1619 digis.emplace_back(ip.first, ip.second,
adc);
1623 unsigned int il = 0;
1624 for (
const auto&
info : (*i).second.hitInfos()) {
1627 simi[std::make_pair(
info.trackId(),
info.eventId().rawId())] += (*i).second.individualampl()[il];
1632 for (
const auto&
info : (*i).second.hitInfos()) {
1634 auto found = simi.find(std::make_pair(
info.trackId(),
info.eventId().rawId()));
1635 if (
found == simi.end())
1638 float sum_samechannel =
found->second;
1639 float fraction = sum_samechannel / (*i).second;
1657 float thePixelThreshold,
1658 CLHEP::HepRandomEngine* engine) {
1667 float theSmearedChargeRMS = 0.0;
1671 if ((*i).second < 3000) {
1672 theSmearedChargeRMS = 543.6 - (*i).second * 0.093;
1673 }
else if ((*i).second < 6000) {
1674 theSmearedChargeRMS = 307.6 - (*i).second * 0.01;
1676 theSmearedChargeRMS = -432.4 + (*i).second * 0.123;
1680 float noise_ChargeVCALSmearing = theSmearedChargeRMS * CLHEP::RandGaussQ::shoot(engine, 0., 1.);
1684 if (((*i).second +
Amplitude(
noise + noise_ChargeVCALSmearing, -1.)) < 0.) {
1708 int numColumns = topol->
ncolumns();
1709 int numRows = topol->
nrows();
1713 int numberOfPixels = (numRows * numColumns);
1714 std::map<int, float, std::less<int> > otherPixels;
1715 std::map<int, float, std::less<int> >::iterator mapI;
1726 << otherPixels.size();
1730 for (mapI = otherPixels.begin(); mapI != otherPixels.end(); mapI++) {
1731 int iy = ((*mapI).first) / numRows;
1732 int ix = ((*mapI).first) - (iy * numRows);
1735 if (iy < 0 || iy > (numColumns - 1))
1736 LogWarning(
"Pixel Geometry") <<
" error in iy " << iy;
1737 if (ix < 0 || ix > (numRows - 1))
1738 LogWarning(
"Pixel Geometry") <<
" error in ix " << ix;
1743 LogDebug(
"Pixel Digitizer") <<
" Storing noise = " << (*mapI).first <<
" " << (*mapI).second <<
" " << ix <<
" "
1744 << iy <<
" " <<
chan;
1747 if (theSignal[
chan] == 0) {
1762 CLHEP::HepRandomEngine* engine) {
1766 int numColumns = topol->
ncolumns();
1767 int numRows = topol->
nrows();
1771 double pixelEfficiency = 1.0;
1772 double columnEfficiency = 1.0;
1773 double chipEfficiency = 1.0;
1774 std::vector<double> pixelEfficiencyROCStdPixels(16, 1);
1775 std::vector<double> pixelEfficiencyROCBigPixels(16, 1);
1777 auto pIndexConverter =
PixelIndices(numColumns, numRows);
1779 std::vector<int> badRocsFromFEDChannels(16, 0);
1785 for (
const auto& ch : *it) {
1786 for (
unsigned int i_roc = ch.roc_first; i_roc <= ch.roc_last; ++i_roc) {
1787 for (
const auto p :
path) {
1789 if (myroc->
idInDetUnit() == static_cast<unsigned int>(i_roc)) {
1792 int chipIndex(0), colROC(0), rowROC(0);
1793 pIndexConverter.transformToROC(global.
col, global.
row, chipIndex, colROC, rowROC);
1794 badRocsFromFEDChannels.at(chipIndex) = 1;
1806 int layerIndex = tTopo->
layer(detID);
1813 if (numColumns > 416)
1814 LogWarning(
"Pixel Geometry") <<
" wrong columns in barrel " << numColumns;
1816 LogWarning(
"Pixel Geometry") <<
" wrong rows in barrel " << numRows;
1832 unsigned int diskIndex =
1834 unsigned int panelIndex = tTopo->
pxfPanel(detID);
1835 unsigned int moduleIndex = tTopo->
pxfModule(detID);
1846 if (numColumns > 260 || numRows > 160) {
1847 if (numColumns > 260)
1848 LogWarning(
"Pixel Geometry") <<
" wrong columns in endcaps " << numColumns;
1850 LogWarning(
"Pixel Geometry") <<
" wrong rows in endcaps " << numRows;
1853 if ((panelIndex == 1 && (moduleIndex == 1 || moduleIndex == 2)) ||
1854 (panelIndex == 2 && moduleIndex == 1)) {
1863 pixelEfficiency = 0.999;
1864 columnEfficiency = 0.999;
1865 chipEfficiency = 0.999;
1880 LogDebug(
"Pixel Digitizer") <<
" enter pixel_inefficiency " << pixelEfficiency <<
" " << columnEfficiency <<
" "
1890 std::map<int, int, std::less<int> > chips,
columns, pixelStd, pixelBig;
1891 std::map<int, int, std::less<int> >::iterator iter;
1896 int chan =
i->first;
1899 int col = ip.second;
1901 pIndexConverter.transformToROC(
col, row, chipIndex, colROC, rowROC);
1902 int dColInChip = pIndexConverter.DColumn(colROC);
1904 int dColInDet = pIndexConverter.DColumnInModule(dColInChip, chipIndex);
1910 pixelBig[chipIndex]++;
1912 pixelStd[chipIndex]++;
1917 for (iter = chips.begin(); iter != chips.end(); iter++) {
1919 float rand = CLHEP::RandFlat::shoot(engine);
1920 if (
rand > chipEfficiency)
1921 chips[iter->first] = 0;
1927 float rand = CLHEP::RandFlat::shoot(engine);
1928 if (
rand > columnEfficiency)
1934 for (iter = pixelStd.begin(); iter != pixelStd.end(); iter++) {
1935 float rand = CLHEP::RandFlat::shoot(engine);
1936 if (
rand > pixelEfficiencyROCStdPixels[iter->first])
1937 pixelStd[iter->first] = 0;
1940 for (iter = pixelBig.begin(); iter != pixelBig.end(); iter++) {
1941 float rand = CLHEP::RandFlat::shoot(engine);
1942 if (
rand > pixelEfficiencyROCBigPixels[iter->first])
1943 pixelBig[iter->first] = 0;
1953 int col = ip.second;
1955 pIndexConverter.transformToROC(
col, row, chipIndex, colROC, rowROC);
1956 int dColInChip = pIndexConverter.DColumn(colROC);
1958 int dColInDet = pIndexConverter.DColumnInModule(dColInChip, chipIndex);
1961 float rand = CLHEP::RandFlat::shoot(engine);
1962 if (chips[chipIndex] == 0 ||
columns[dColInDet] == 0 ||
rand > pixelEfficiency ||
1963 (pixelStd.count(chipIndex) && pixelStd[chipIndex] == 0) ||
1964 (pixelBig.count(chipIndex) && pixelBig[chipIndex] == 0)) {
1969 if ((pixelStd.count(chipIndex) && pixelStd[chipIndex] == 0) ||
1970 (pixelBig.count(chipIndex) && pixelBig[chipIndex] == 0) || (badRocsFromFEDChannels.at(chipIndex) == 1)) {
1992 float pseudoRadDamage = 0.0f;
1997 int layerIndex = tTopo->
layer(detID);
1999 pseudoRadDamage =
aging.thePixelPseudoRadDamage[layerIndex - 1];
2007 unsigned int diskIndex =
2010 pseudoRadDamage =
aging.thePixelPseudoRadDamage[diskIndex - 1];
2017 pseudoRadDamage = 0.f;
2023 return pseudoRadDamage;
2025 LogDebug(
"Pixel Digitizer") <<
" enter pixel_aging " << pseudoRadDamage;
2043 const float signalInElectrons)
const {
2070 throw cms::Exception(
"NotAPixelGeomDetUnit") <<
"Not a pixel geomdet unit" << detID;
2086 newAmp =
p3 +
p2 * tanh(p0 * signal -
p1);
2130 const DetId& detId)
const {
2165 dir_z = -(1 + alpha2_BPix * Bfield.z() * Bfield.z());
2170 dir_z = -(1 + alpha2_FPix * Bfield.z() * Bfield.z());
2173 throw cms::Exception(
"NotAPixelGeomDetUnit") <<
"Not a pixel geomdet unit" << detID;
2180 alpha2 = lorentzAngle * lorentzAngle;
2182 dir_x = -(lorentzAngle * Bfield.y() + alpha2 * Bfield.z() * Bfield.x());
2183 dir_y = +(lorentzAngle * Bfield.x() - alpha2 * Bfield.z() * Bfield.y());
2184 dir_z = -(1 + alpha2 * Bfield.z() * Bfield.z());
2191 LogDebug(
"Pixel Digitizer") <<
" The drift direction in local coordinate is " << theDriftDirection;
2194 return theDriftDirection;
2207 int col = ip.second;
2222 Parameters::const_iterator itDeadModules =
DeadModules.begin();
2225 for (; itDeadModules !=
DeadModules.end(); ++itDeadModules) {
2226 int Dead_detID = itDeadModules->getParameter<
int>(
"Dead_detID");
2227 if (detid == Dead_detID) {
2249 if (
Module ==
"tbmA" && ip.first >= 80 && ip.first <= 159) {
2253 if (
Module ==
"tbmB" && ip.first <= 79) {
2268 for (
size_t id = 0;
id < disabledModules.size();
id++) {
2269 if (detID == disabledModules[
id].DetID) {
2271 badmodule = disabledModules[
id];
2290 std::vector<GlobalPixel> badrocpositions(0);
2291 for (
unsigned int j = 0;
j < 16;
j++) {
2294 typedef std::vector<CablingPathToDetUnit>::const_iterator
IT;
2295 for (
IT it =
path.begin(); it !=
path.end(); ++it) {
2300 badrocpositions.push_back(global);
2310 for (std::vector<GlobalPixel>::const_iterator it = badrocpositions.begin(); it != badrocpositions.end(); ++it) {
2311 if (it->row >= 80 && ip.first >= 80) {
2312 if ((
std::abs(ip.second - it->col) < 26)) {
2314 }
else if (it->row == 120 && ip.second - it->col == 26) {
2316 }
else if (it->row == 119 && it->col - ip.second == 26) {
2319 }
else if (it->row < 80 && ip.first < 80) {
2320 if ((
std::abs(ip.second - it->col) < 26)) {
2322 }
else if (it->row == 40 && ip.second - it->col == 26) {
2324 }
else if (it->row == 39 && it->col - ip.second == 26) {
2334 std::map<
int,
float, std::less<int> >& hit_signal,
2335 const size_t hitIndex,
2336 const unsigned int tofBin,
2340 unsigned short int processType) {
2341 int irow_min = topol->
nrows();
2346 float chargeBefore = 0;
2347 float chargeAfter = 0;
2351 for (
std::map<
int,
float, std::less<int> >::const_iterator im = hit_signal.begin(); im != hit_signal.end(); ++im) {
2352 int chan = (*im).first;
2357 :
Amplitude((*im).second, (*im).second));
2358 chargeBefore += (*im).second;
2360 if (pixelWithCharge.first < irow_min)
2361 irow_min = pixelWithCharge.first;
2362 if (pixelWithCharge.first > irow_max)
2363 irow_max = pixelWithCharge.first;
2364 if (pixelWithCharge.second < icol_min)
2365 icol_min = pixelWithCharge.second;
2366 if (pixelWithCharge.second > icol_max)
2367 icol_max = pixelWithCharge.second;
2372 float trajectoryScaleToPosition = hitEntryPoint.
z() / direction.
z();
2374 if ((hitEntryPoint.
z() > 0 && direction.
z() < 0) || (hitEntryPoint.
z() < 0 && direction.
z() > 0)) {
2375 trajectoryScaleToPosition *= -1;
2378 LocalPoint hitPosition = hitEntryPoint + trajectoryScaleToPosition * direction;
2381 std::pair<int, int> hitPixel =
2382 std::pair<int, int>(
int(floor(hitPositionPixel.
x())),
int(floor(hitPositionPixel.
y())));
2389 std::pair<int, int> entryPixel =
2390 std::pair<int, int>(
int(floor(hitEntryPointPixel.
x())),
int(floor(hitEntryPointPixel.
y())));
2391 std::pair<int, int> exitPixel =
2392 std::pair<int, int>(
int(floor(hitExitPointPixel.
x())),
int(floor(hitExitPointPixel.
y())));
2394 int hitcol_min, hitcol_max, hitrow_min, hitrow_max;
2395 if (entryPixel.first > exitPixel.first) {
2396 hitrow_min = exitPixel.first;
2397 hitrow_max = entryPixel.first;
2399 hitrow_min = entryPixel.first;
2400 hitrow_max = exitPixel.first;
2403 if (entryPixel.second > exitPixel.second) {
2404 hitcol_min = exitPixel.second;
2405 hitcol_max = entryPixel.second;
2407 hitcol_min = entryPixel.second;
2408 hitcol_max = exitPixel.second;
2414 LogDebug(
"Pixel Digitizer") <<
"\n"
2415 <<
"Particle ID is: " <<
hit.particleType() <<
"\n"
2416 <<
"Process type: " <<
hit.processType() <<
"\n"
2419 <<
"Hit entry x/y/z: " <<
hit.entryPoint().
x() <<
" " <<
hit.entryPoint().
y() <<
" "
2420 <<
hit.entryPoint().
z() <<
" "
2421 <<
"Hit exit x/y/z: " <<
hit.exitPoint().
x() <<
" " <<
hit.exitPoint().
y() <<
" "
2422 <<
hit.exitPoint().
z() <<
" "
2424 <<
"Pixel Pos - X: " << hitPositionPixel.
x() <<
" Y: " << hitPositionPixel.
y() <<
"\n"
2425 <<
"Cart.Cor. - X: " << CMSSWhitPosition.
x() <<
" Y: " << CMSSWhitPosition.
y() <<
"\n"
2426 <<
"Z=0 Pos - X: " << hitPosition.
x() <<
" Y: " << hitPosition.
y() <<
"\n"
2428 <<
"Origin of the template:"
2430 <<
"Pixel Pos - X: " << originPixel.x() <<
" Y: " << originPixel.y() <<
"\n"
2431 <<
"Cart.Cor. - X: " << origin.
x() <<
" Y: " << origin.
y() <<
"\n"
2435 <<
"Entry - X: " <<
hit.entryPoint().
x() <<
" Y: " <<
hit.entryPoint().
y()
2436 <<
" Z: " <<
hit.entryPoint().
z() <<
"\n"
2437 <<
"Exit - X: " <<
hit.exitPoint().
x() <<
" Y: " <<
hit.exitPoint().
y()
2438 <<
" Z: " <<
hit.exitPoint().
z() <<
"\n"
2440 <<
"Entry - X Pixel: " << hitEntryPointPixel.
x() <<
" Y Pixel: " << hitEntryPointPixel.
y()
2442 <<
"Exit - X Pixel: " << hitExitPointPixel.
x() <<
" Y Pixel: " << hitExitPointPixel.
y()
2445 <<
"row min: " << irow_min <<
" col min: " << icol_min <<
"\n";
2448 if (!(irow_min <= hitrow_max && irow_max >= hitrow_min && icol_min <= hitcol_max && icol_max >= hitcol_min)) {
2453 float cmToMicrons = 10000.f;
2455 track[0] = (hitPosition.
x() - origin.
x()) * cmToMicrons;
2456 track[1] = (hitPosition.
y() - origin.
y()) * cmToMicrons;
2458 track[3] = direction.x();
2459 track[4] = direction.y();
2460 track[5] = direction.z();
2464 for (
int row = 0; row <
TXSIZE; ++row) {
2466 pixrewgt[row][
col] = 0;
2470 for (
int row = 0; row <
TXSIZE; ++row) {
2478 for (
int row = 0; row <
TXSIZE; ++row) {
2481 pixrewgt[row][
col] =
2488 std::cout <<
"Cluster before reweighting: " << std::endl;
2508 LogDebug(
"PixelDigitizer ") <<
"Cluster Charge Reweighting did not work properly.";
2514 std::cout <<
"Cluster after reweighting: " << std::endl;
2518 for (
int row = 0; row <
TXSIZE; ++row) {
2522 if ((hitPixel.first + row -
THX) >= 0 && (hitPixel.first + row -
THX) < topol->
nrows() &&
2531 if (chargeBefore != 0. && chargeAfter == 0.) {
2537 std::cout <<
"Charges (before->after): " << chargeBefore <<
" -> " << chargeAfter << std::endl;
2538 std::cout <<
"Charge loss: " << (1 - chargeAfter / chargeBefore) * 100 <<
" %" << std::endl << std::endl;
2555 int i,
j,
k,
l, kclose;
2557 float xsize,
ysize, q50i, q100i, q50r, q10r, q100r, xhit2D, yhit2D, qclust, dist2, dmin2;
2560 int goodWeightsUsed, nearbyWeightsUsed, noWeightsUsed;
2561 float cotalpha, cotbeta;
2579 LogDebug(
"Pixel Digitizer") <<
"Reweighting angle is not good!" << std::endl;
2599 xy_rewgt[
j][
i] = 0.f;
2610 LogDebug(
"Pixel Digitizer") <<
"No matching template found" << std::endl;
2616 std::cout <<
"Template unirrad: " << std::endl;
2626 if (cluster.num_dimensions() != 2) {
2627 LogWarning(
"Pixel Digitizer") <<
"Cluster is not 2-dimensional. Return." << std::endl;
2630 nclusx = (
int)cluster.shape()[0];
2631 nclusy = (
int)cluster.shape()[1];
2633 LogWarning(
"Pixel Digitizer") <<
"Sizes in x do not match: nclusx=" << nclusx <<
" xdoubleSize=" <<
xdouble.size()
2634 <<
" TXSIZE=" <<
TXSIZE <<
". Return." << std::endl;
2638 LogWarning(
"Pixel Digitizer") <<
"Sizes in y do not match. Return." << std::endl;
2647 xy_clust[
j][
i] = 0.f;
2648 denx_clust[
j][
i] = 0;
2649 deny_clust[
j][
i] = 0;
2650 if (cluster[
j][
i] > q100i) {
2651 qclust += cluster[
j][
i];
2663 std::cout <<
"Template irrad: " << std::endl;
2675 std::vector<int> ytclust;
2676 std::vector<int> xtclust;
2677 std::vector<int> ycclust;
2678 std::vector<int> xcclust;
2682 if (xy_in[
j + 1][
i + 1] > q100i) {
2684 ytclust.push_back(
i);
2685 xtclust.push_back(
j);
2686 xy_clust[
j][
i] = xy_rewgt[
j + 1][
i + 1] / xy_in[
j + 1][
i + 1];
2687 denx_clust[
j][
i] =
j;
2688 deny_clust[
j][
i] =
i;
2697 if (xy_rewgt[
j + 1][
i + 1] > q10r && xy_clust[
j][
i] == 0.
f && ntpix > 0) {
2701 for (
k = 0;
k < ntpix; ++
k) {
2702 dist2 = (
i - ytclust[
k]) * (
i - ytclust[
k]) + 0.44444f * (
j - xtclust[
k]) * (
j - xtclust[
k]);
2703 if (dist2 < dmin2) {
2708 xy_clust[
j][
i] = xy_rewgt[
j + 1][
i + 1] / xy_in[xtclust[kclose] + 1][ytclust[kclose] + 1];
2709 denx_clust[
j][
i] = xtclust[kclose];
2710 deny_clust[
j][
i] = ytclust[kclose];
2721 goodWeightsUsed = 0;
2722 nearbyWeightsUsed = 0;
2727 if (xy_clust[
j][
i] > 0.
f) {
2728 cluster[
j][
i] = xy_clust[
j][
i] * clust[denx_clust[
j][
i]][deny_clust[
j][
i]];
2729 if (cluster[
j][
i] > q100r) {
2730 qclust += cluster[
j][
i];
2732 if (cluster[
j][
i] > 0) {
2736 if (clust[
j][
i] > 0.
f) {
2738 ycclust.push_back(
i);
2739 xcclust.push_back(
j);
2748 for (
l = 0;
l < ncpix; ++
l) {
2753 for (
k = 0;
k < ntpix; ++
k) {
2754 dist2 = (
i - ytclust[
k]) * (
i - ytclust[
k]) + 0.44444f * (
j - xtclust[
k]) * (
j - xtclust[
k]);
2755 if (dist2 < dmin2) {
2761 nearbyWeightsUsed++;
2762 cluster[
j][
i] *= xy_clust[xtclust[kclose]][ytclust[kclose]];
2763 if (cluster[
j][
i] > q100r) {
2764 qclust += cluster[
j][
i];
2768 cluster[
j][
i] = 0.f;
2778 for (
int row = 0; row <
TXSIZE; ++row) {
2789 for (
int row = 0; row <
BXM2; ++row) {
2800 for (
int row = 0; row <
TXSIZE; ++row) {