55 #include <gsl/gsl_sf_erf.h>
57 #include "CLHEP/Random/RandGaussQ.h"
58 #include "CLHEP/Random/RandFlat.h"
59 #include "CLHEP/Random/RandGeneral.h"
117 if (use_ineff_from_db_) {
118 theSiPixelGainCalibrationService_->setESObjects(es);
120 if (use_deadmodule_DB_) {
123 if (use_LorentzAngle_DB_) {
134 quality_map = PixelFEDChannelCollectionMapHandle.product();
137 std::vector<std::string> allScenarios;
141 std::back_inserter(allScenarios),
144 std::vector<std::string> allScenariosInProb;
146 for (
auto it = m_probabilities.begin(); it != m_probabilities.end(); ++it) {
148 for (
const auto&
entry : it->second) {
150 auto probability =
entry.second;
151 if (probability != 0) {
152 if (
std::find(allScenariosInProb.begin(), allScenariosInProb.end(),
scenario) == allScenariosInProb.end()) {
153 allScenariosInProb.push_back(
scenario);
160 std::copy_if(allScenariosInProb.begin(),
161 allScenariosInProb.end(),
164 return (
std::find(allScenarios.begin(), allScenarios.end(),
arg) == allScenarios.end());
170 <<
"The requested scenario: " <<
entry <<
" is not found in the map!!" << std::endl;
173 <<
" missing scenario(s) in SiPixelStatusScenariosRcd while "
174 "present in SiPixelStatusScenarioProbabilityRcd \n";
178 TheNewSiPixelChargeReweightingAlgorithmClass->init(es);
187 conf.getParameter<
std::
string>(
"SiPixelQualityLabel")),
189 makeDigiSimLinks_(conf.getUntrackedParameter<
bool>(
"makeDigiSimLinks",
true)),
190 use_ineff_from_db_(conf.getParameter<
bool>(
"useDB")),
191 use_module_killing_(conf.getParameter<
bool>(
"killModules")),
192 use_deadmodule_DB_(conf.getParameter<
bool>(
"DeadModules_DB")),
193 use_LorentzAngle_DB_(conf.getParameter<
bool>(
"LorentzAngle_DB")),
196 : conf.getParameter<
Parameters>(
"DeadModules")),
198 TheNewSiPixelChargeReweightingAlgorithmClass(),
202 GeVperElectron(3.61E-09),
205 alpha2Order(conf.getParameter<
bool>(
"Alpha2Order")),
211 NumberOfBarrelLayers(conf.exists(
"NumPixelBarrel") ? conf.getParameter<
int>(
"NumPixelBarrel") : 3),
219 theElectronPerADC(conf.getParameter<double>(
"ElectronPerAdc")),
223 theAdcFullScale(conf.getParameter<
int>(
"AdcFullScale")),
227 theNoiseInElectrons(conf.getParameter<double>(
"NoiseInElectrons")),
231 theReadoutNoise(conf.getParameter<double>(
"ReadoutNoiseInElec")),
236 theThresholdInE_FPix(conf.getParameter<double>(
"ThresholdInElectrons_FPix")),
237 theThresholdInE_BPix(conf.getParameter<double>(
"ThresholdInElectrons_BPix")),
238 theThresholdInE_BPix_L1(conf.exists(
"ThresholdInElectrons_BPix_L1")
239 ? conf.getParameter<double>(
"ThresholdInElectrons_BPix_L1")
240 : theThresholdInE_BPix),
241 theThresholdInE_BPix_L2(conf.exists(
"ThresholdInElectrons_BPix_L2")
242 ? conf.getParameter<double>(
"ThresholdInElectrons_BPix_L2")
243 : theThresholdInE_BPix),
246 theThresholdSmearing_FPix(conf.getParameter<double>(
"ThresholdSmearing_FPix")),
247 theThresholdSmearing_BPix(conf.getParameter<double>(
"ThresholdSmearing_BPix")),
248 theThresholdSmearing_BPix_L1(conf.exists(
"ThresholdSmearing_BPix_L1")
249 ? conf.getParameter<double>(
"ThresholdSmearing_BPix_L1")
250 : theThresholdSmearing_BPix),
251 theThresholdSmearing_BPix_L2(conf.exists(
"ThresholdSmearing_BPix_L2")
252 ? conf.getParameter<double>(
"ThresholdSmearing_BPix_L2")
253 : theThresholdSmearing_BPix),
256 electronsPerVCAL(conf.getParameter<double>(
"ElectronsPerVcal")),
257 electronsPerVCAL_Offset(conf.getParameter<double>(
"ElectronsPerVcal_Offset")),
258 electronsPerVCAL_L1(conf.exists(
"ElectronsPerVcal_L1") ? conf.getParameter<double>(
"ElectronsPerVcal_L1")
260 electronsPerVCAL_L1_Offset(conf.exists(
"ElectronsPerVcal_L1_Offset")
261 ? conf.getParameter<double>(
"ElectronsPerVcal_L1_Offset")
262 : electronsPerVCAL_Offset),
266 theTofLowerCut(conf.getParameter<double>(
"TofLowerCut")),
267 theTofUpperCut(conf.getParameter<double>(
"TofUpperCut")),
270 tanLorentzAnglePerTesla_FPix(use_LorentzAngle_DB_ ? 0.0
271 : conf.getParameter<double>(
"TanLorentzAnglePerTesla_FPix")),
272 tanLorentzAnglePerTesla_BPix(use_LorentzAngle_DB_ ? 0.0
273 : conf.getParameter<double>(
"TanLorentzAnglePerTesla_BPix")),
276 FPix_p0(conf.getParameter<double>(
"FPix_SignalResponse_p0")),
277 FPix_p1(conf.getParameter<double>(
"FPix_SignalResponse_p1")),
278 FPix_p2(conf.getParameter<double>(
"FPix_SignalResponse_p2")),
279 FPix_p3(conf.getParameter<double>(
"FPix_SignalResponse_p3")),
281 BPix_p0(conf.getParameter<double>(
"BPix_SignalResponse_p0")),
282 BPix_p1(conf.getParameter<double>(
"BPix_SignalResponse_p1")),
283 BPix_p2(conf.getParameter<double>(
"BPix_SignalResponse_p2")),
284 BPix_p3(conf.getParameter<double>(
"BPix_SignalResponse_p3")),
287 addNoise(conf.getParameter<
bool>(
"AddNoise")),
291 addChargeVCALSmearing(conf.getParameter<
bool>(
"ChargeVCALSmearing")),
294 addNoisyPixels(conf.getParameter<
bool>(
"AddNoisyPixels")),
297 fluctuateCharge(conf.getUntrackedParameter<
bool>(
"FluctuateCharge",
true)),
304 addThresholdSmearing(conf.getParameter<
bool>(
"AddThresholdSmearing")),
307 doMissCalibrate(conf.getParameter<
bool>(
"MissCalibrate")),
308 theGainSmearing(conf.getParameter<double>(
"GainSmearing")),
309 theOffsetSmearing(conf.getParameter<double>(
"OffsetSmearing")),
312 AddPixelAging(conf.getParameter<
bool>(
"DoPixelAging")),
318 tMax(conf.getParameter<double>(
"deltaProductionCut")),
327 LogInfo(
"PixelDigitizer ") <<
"SiPixelDigitizerAlgorithm constructed"
328 <<
"Configuration parameters:"
329 <<
"Threshold/Gain = "
345 std::map<int, SiPixelDigitizerAlgorithm::CalParameters, std::less<int> >
calmap;
347 LogDebug(
"PixelDigitizer ") <<
" miss-calibrate the pixel amplitude ";
349 const bool ReadCalParameters =
false;
350 if (ReadCalParameters) {
353 char filename[80] =
"phCalibrationFit_C0.dat";
357 cout <<
" File not found " << endl;
363 for (
int i = 0;
i < 3;
i++) {
368 cout <<
" test map" << endl;
374 for (
int i = 0;
i < (52 * 80);
i++) {
377 cerr <<
"Cannot read data file" << endl;
382 <<
" end of file " << endl;
397 calmap.insert(std::pair<int, CalParameters>(
chan, onePix));
401 if (rowid !=
p.first)
402 cout <<
" wrong channel row " << rowid <<
" " <<
p.first << endl;
403 if (colid !=
p.second)
404 cout <<
" wrong channel col " << colid <<
" " <<
p.second << endl;
431 LogDebug(
"PixelDigitizer") <<
"SiPixelDigitizerAlgorithm deleted";
437 int NumberOfBarrelLayers,
445 conf.
exists(
"thePixelColEfficiency_BPix3") && conf.
exists(
"thePixelColEfficiency_FPix1") &&
446 conf.
exists(
"thePixelColEfficiency_FPix2") && conf.
exists(
"thePixelEfficiency_BPix1") &&
447 conf.
exists(
"thePixelEfficiency_BPix2") && conf.
exists(
"thePixelEfficiency_BPix3") &&
448 conf.
exists(
"thePixelEfficiency_FPix1") && conf.
exists(
"thePixelEfficiency_FPix2") &&
449 conf.
exists(
"thePixelChipEfficiency_BPix1") && conf.
exists(
"thePixelChipEfficiency_BPix2") &&
450 conf.
exists(
"thePixelChipEfficiency_BPix3") && conf.
exists(
"thePixelChipEfficiency_FPix1") &&
451 conf.
exists(
"thePixelChipEfficiency_FPix2");
454 conf.
exists(
"theLadderEfficiency_BPix3") && conf.
exists(
"theModuleEfficiency_BPix1") &&
455 conf.
exists(
"theModuleEfficiency_BPix2") && conf.
exists(
"theModuleEfficiency_BPix3") &&
456 conf.
exists(
"thePUEfficiency_BPix1") && conf.
exists(
"thePUEfficiency_BPix2") &&
457 conf.
exists(
"thePUEfficiency_BPix3") && conf.
exists(
"theInnerEfficiency_FPix1") &&
458 conf.
exists(
"theInnerEfficiency_FPix2") && conf.
exists(
"theOuterEfficiency_FPix1") &&
459 conf.
exists(
"theOuterEfficiency_FPix2") && conf.
exists(
"thePUEfficiency_FPix_Inner") &&
460 conf.
exists(
"thePUEfficiency_FPix_Outer") && conf.
exists(
"theInstLumiScaleFactor");
463 conf.
exists(
"thePixelEfficiency_BPix4") && conf.
exists(
"thePixelChipEfficiency_BPix4");
466 conf.
exists(
"thePixelEfficiency_FPix3") && conf.
exists(
"thePixelChipEfficiency_FPix3");
468 LogInfo(
"PixelDigitizer ") <<
"The PixelDigitizer inefficiency configuration is read from the config file.\n";
502 throw cms::Exception(
"Configuration") <<
"Wrong ladder number in efficiency config!";
511 throw cms::Exception(
"Configuration") <<
"Wrong module number in efficiency config!";
519 <<
"At least one PU efficiency (BPix) number is needed in efficiency config!";
523 if (NumberOfTotLayers > 20) {
524 throw cms::Exception(
"Configuration") <<
"SiPixelDigitizer was given more layers than it can handle";
554 if (NumberOfTotLayers > 20) {
555 throw cms::Exception(
"Configuration") <<
"SiPixelDigitizer was given more layers than it can handle";
576 <<
"At least one (FPix) PU efficiency number is needed in efficiency config!";
580 LogInfo(
"PixelDigitizer ") <<
"The PixelDigitizer inefficiency configuration is read from the database.\n";
608 for (
const auto& it_module :
geom->detUnits()) {
609 if (dynamic_cast<PixelGeomDetUnit const*>(it_module) ==
nullptr)
611 const DetId detid = it_module->geographicalId();
612 uint32_t rawid = detid.
rawId();
613 PixelGeomFactors[rawid] = 1;
614 ColGeomFactors[rawid] = 1;
615 ChipGeomFactors[rawid] = 1;
616 PixelGeomFactorsROCStdPixels[rawid] = std::vector<double>(16, 1);
617 PixelGeomFactorsROCBigPixels[rawid] = std::vector<double>(16, 1);
621 std::map<uint32_t, double> PixelGeomFactorsDB;
624 for (
auto db_factor : PixelGeomFactorsDBIn) {
627 unsigned int rocMask = rocIdMaskBits <<
shift;
628 unsigned int rocId = (((db_factor.first) & rocMask) >>
shift);
631 unsigned int rawid = db_factor.first & (~rocMask);
632 const PixelGeomDetUnit* theGeomDet = dynamic_cast<const PixelGeomDetUnit*>(
geom->idToDet(rawid));
635 const int nBigPixelsInROC = 2 *
topology->rowsperroc() +
topology->colsperroc() - 2;
636 double factor = db_factor.second;
637 double badFraction = 1 -
factor;
638 double bigPixelFraction = static_cast<double>(nBigPixelsInROC) / nPixelsInROC;
639 double stdPixelFraction = 1. - bigPixelFraction;
641 double badFractionBig =
std::min(bigPixelFraction, badFraction);
642 double badFractionStd =
std::max(0., badFraction - badFractionBig);
643 double badFractionBigReNormalized = badFractionBig / bigPixelFraction;
644 double badFractionStdReNormalized = badFractionStd / stdPixelFraction;
645 PixelGeomFactorsROCStdPixels[rawid][rocId] *= (1. - badFractionStdReNormalized);
646 PixelGeomFactorsROCBigPixels[rawid][rocId] *= (1. - badFractionBigReNormalized);
648 PixelGeomFactorsDB[db_factor.first] = db_factor.second;
653 PixelGeomFactorsDB = PixelGeomFactorsDBIn;
657 for (
const auto& it_module :
geom->detUnits()) {
658 if (dynamic_cast<PixelGeomDetUnit const*>(it_module) ==
nullptr)
660 const DetId detid = it_module->geographicalId();
661 uint32_t rawid = detid.
rawId();
662 for (
auto db_factor : PixelGeomFactorsDB)
664 PixelGeomFactors[rawid] *= db_factor.second;
665 for (
auto db_factor : ColGeomFactorsDB)
667 ColGeomFactors[rawid] *= db_factor.second;
668 for (
auto db_factor : ChipGeomFactorsDB)
670 ChipGeomFactors[rawid] *= db_factor.second;
676 for (
const auto&
factor : PUFactors) {
678 for (
const auto& it_module :
geom->detUnits()) {
679 if (dynamic_cast<PixelGeomDetUnit const*>(it_module) ==
nullptr)
681 const DetId detid = it_module->geographicalId();
682 if (!
matches(detid, db_id, DetIdmasks))
684 if (iPU.count(detid.
rawId())) {
686 <<
"Multiple db_ids match to same module in SiPixelDynamicInefficiency DB Object";
691 thePUEfficiency.push_back(
factor.second);
694 pu_scale.resize(thePUEfficiency.size());
699 const std::vector<uint32_t>& DetIdmasks) {
702 for (
size_t i = 0;
i < DetIdmasks.size(); ++
i) {
724 thePixelPseudoRadDamage[
i++] = conf.
getParameter<
double>(
"thePixelPseudoRadDamage_BPix1");
725 thePixelPseudoRadDamage[
i++] = conf.
getParameter<
double>(
"thePixelPseudoRadDamage_BPix2");
726 thePixelPseudoRadDamage[
i++] = conf.
getParameter<
double>(
"thePixelPseudoRadDamage_BPix3");
727 thePixelPseudoRadDamage[
i++] = conf.
getParameter<
double>(
"thePixelPseudoRadDamage_BPix4");
731 if (NumberOfTotLayers > 20) {
732 throw cms::Exception(
"Configuration") <<
"SiPixelDigitizer was given more layers than it can handle";
736 thePixelPseudoRadDamage[
j - 1] = 0.;
741 thePixelPseudoRadDamage[
i++] = conf.
getParameter<
double>(
"thePixelPseudoRadDamage_FPix1");
742 thePixelPseudoRadDamage[
i++] = conf.
getParameter<
double>(
"thePixelPseudoRadDamage_FPix2");
743 thePixelPseudoRadDamage[
i++] = conf.
getParameter<
double>(
"thePixelPseudoRadDamage_FPix3");
747 if (NumberOfTotLayers > 20) {
748 throw cms::Exception(
"Configuration") <<
"SiPixelDigitizer was given more layers than it can handle";
752 thePixelPseudoRadDamage[
j - 1] = 0.;
762 std::vector<PSimHit>::const_iterator inputEnd,
763 const size_t inputBeginGlobalIndex,
764 const unsigned int tofBin,
768 CLHEP::HepRandomEngine* engine) {
773 size_t simHitGlobalIndex = inputBeginGlobalIndex;
774 for (std::vector<PSimHit>::const_iterator ssbegin = inputBegin; ssbegin != inputEnd; ++ssbegin, ++simHitGlobalIndex) {
776 if ((*ssbegin).detUnitId() != detId) {
781 LogDebug(
"Pixel Digitizer") << (*ssbegin).particleType() <<
" " << (*ssbegin).pabs() <<
" "
782 << (*ssbegin).energyLoss() <<
" " << (*ssbegin).tof() <<
" " << (*ssbegin).trackId()
783 <<
" " << (*ssbegin).processType() <<
" " << (*ssbegin).detUnitId()
784 << (*ssbegin).entryPoint() <<
" " << (*ssbegin).exitPoint();
787 std::vector<EnergyDepositUnit> ionization_points;
788 std::vector<SignalPoint> collection_points;
823 std::vector<int>::const_iterator
pu;
824 std::vector<int>::const_iterator pu0 = bunchCrossing.end();
826 for (
pu = bunchCrossing.begin();
pu != bunchCrossing.end(); ++
pu) {
833 if (pu0 != bunchCrossing.end()) {
836 double instlumi_pow = 1.;
840 instlumi_pow *= instlumi;
854 for (
unsigned int i = 0;
i < ps.size();
i++)
855 if (ps[
i].getBunchCrossing() == 0)
861 double instlumi_pow = 1.;
865 instlumi_pow *= instlumi;
880 const std::vector<PileupSummaryInfo>& ps, CLHEP::HepRandomEngine* engine) {
881 std::unique_ptr<PixelFEDChannelCollection> PixelFEDChannelCollection_ =
nullptr;
884 std::vector<int> bunchCrossing;
885 std::vector<float> TrueInteractionList;
887 for (
unsigned int i = 0;
i < ps.size();
i++) {
888 bunchCrossing.push_back(ps[
i].getBunchCrossing());
889 TrueInteractionList.push_back(ps[
i].getTrueNumInteractions());
893 std::vector<int>::const_iterator
pu;
894 std::vector<int>::const_iterator pu0 = bunchCrossing.end();
896 for (
pu = bunchCrossing.begin();
pu != bunchCrossing.end(); ++
pu) {
904 if (pu0 != bunchCrossing.end()) {
905 unsigned int PUBin = TrueInteractionList.at(
p);
907 std::vector<double> probabilities;
908 probabilities.reserve(theProbabilitiesPerScenario.size());
909 for (
auto it = theProbabilitiesPerScenario.begin(); it != theProbabilitiesPerScenario.end(); it++) {
910 probabilities.push_back(it->second);
913 CLHEP::RandGeneral randGeneral(*engine, &(probabilities.front()), probabilities.size());
914 double x = randGeneral.shoot();
915 unsigned int index =
x * probabilities.size() - 1;
918 PixelFEDChannelCollection_ = std::make_unique<PixelFEDChannelCollection>(
quality_map->at(
scenario));
923 return PixelFEDChannelCollection_;
927 CLHEP::HepRandomEngine* engine) {
930 std::unique_ptr<PixelFEDChannelCollection> PixelFEDChannelCollection_ =
nullptr;
937 std::vector<int>::const_iterator
pu;
938 std::vector<int>::const_iterator pu0 = bunchCrossing.end();
940 for (
pu = bunchCrossing.begin();
pu != bunchCrossing.end(); ++
pu) {
948 if (pu0 != bunchCrossing.end()) {
949 unsigned int PUBin = TrueInteractionList.at(
p);
951 std::vector<double> probabilities;
952 probabilities.reserve(theProbabilitiesPerScenario.size());
953 for (
auto it = theProbabilitiesPerScenario.begin(); it != theProbabilitiesPerScenario.end(); it++) {
954 probabilities.push_back(it->second);
957 CLHEP::RandGeneral randGeneral(*engine, &(probabilities.front()), probabilities.size());
958 double x = randGeneral.shoot();
959 unsigned int index =
x * probabilities.size() - 1;
962 PixelFEDChannelCollection_ = std::make_unique<PixelFEDChannelCollection>(
quality_map->at(
scenario));
967 return PixelFEDChannelCollection_;
972 for (
const auto& det : signalMap) {
973 auto& theSignal =
_signal[det.first];
974 for (
const auto&
chan : det.second) {
975 theSignal[
chan.first].set(
chan.second *
983 std::vector<PixelDigi>& digis,
984 std::vector<PixelDigiSimLink>& simlinks,
986 CLHEP::HepRandomEngine* engine) {
998 float thePixelThresholdInE = 0.;
1002 int lay = tTopo->
layer(detID);
1007 thePixelThresholdInE = CLHEP::RandGaussQ::shoot(
1009 }
else if (lay == 2) {
1010 thePixelThresholdInE = CLHEP::RandGaussQ::shoot(
1013 thePixelThresholdInE =
1022 }
else if (lay == 2) {
1031 thePixelThresholdInE =
1037 throw cms::Exception(
"NotAPixelGeomDetUnit") <<
"Not a pixel geomdet unit" << detID;
1043 int numColumns = topol->
ncolumns();
1044 int numRows = topol->
nrows();
1047 LogDebug(
"PixelDigitizer") <<
" PixelDigitizer " << numColumns <<
" " << numRows <<
" " << moduleThickness;
1069 make_digis(thePixelThresholdInE, detID, pixdet, digis, simlinks, tTopo);
1072 LogDebug(
"PixelDigitizer") <<
"[SiPixelDigitizerAlgorithm] converted " << digis.size() <<
" PixelDigis in DetUnit"
1081 std::vector<EnergyDepositUnit>& ionization_points,
1082 CLHEP::HepRandomEngine* engine)
const {
1085 const float SegmentLength = 0.0010;
1092 float length = direction.
mag();
1094 int NumberOfSegments =
int(length / SegmentLength);
1095 if (NumberOfSegments < 1)
1096 NumberOfSegments = 1;
1099 LogDebug(
"Pixel Digitizer") <<
" enter primary_ionzation " << NumberOfSegments
1100 <<
" shift = " << (
hit.exitPoint().
x() -
hit.entryPoint().
x()) <<
" "
1101 << (
hit.exitPoint().
y() -
hit.entryPoint().
y()) <<
" "
1102 << (
hit.exitPoint().
z() -
hit.entryPoint().
z()) <<
" " <<
hit.particleType() <<
" "
1106 float* elossVector =
new float[NumberOfSegments];
1110 int pid =
hit.particleType();
1113 float momentum =
hit.pabs();
1118 ionization_points.resize(NumberOfSegments);
1121 for (
int i = 0;
i != NumberOfSegments;
i++) {
1131 ionization_points[
i] = edu;
1134 LogDebug(
"Pixel Digitizer") <<
i <<
" " << ionization_points[
i].x() <<
" " << ionization_points[
i].y() <<
" "
1135 << ionization_points[
i].z() <<
" " << ionization_points[
i].energy();
1140 delete[] elossVector;
1147 float particleMomentum,
1151 float elossVector[],
1152 CLHEP::HepRandomEngine* engine)
const {
1158 double particleMass = 139.6;
1162 particleMass = 0.511;
1164 particleMass = 105.7;
1165 else if (pid == 321)
1166 particleMass = 493.7;
1167 else if (pid == 2212)
1168 particleMass = 938.3;
1171 float segmentLength = length / NumberOfSegs;
1176 double segmentEloss = (1000. * eloss) / NumberOfSegs;
1177 for (
int i = 0;
i < NumberOfSegs;
i++) {
1183 double deltaCutoff =
tMax;
1184 de =
fluctuate->SampleFluctuations(
double(particleMomentum * 1000.),
1187 double(segmentLength * 10.),
1191 elossVector[
i] = de;
1197 float ratio = eloss / sum;
1199 for (
int ii = 0;
ii < NumberOfSegs;
ii++)
1200 elossVector[
ii] =
ratio * elossVector[
ii];
1202 float averageEloss = eloss / NumberOfSegs;
1203 for (
int ii = 0;
ii < NumberOfSegs;
ii++)
1204 elossVector[
ii] = averageEloss;
1216 const std::vector<EnergyDepositUnit>& ionization_points,
1217 std::vector<SignalPoint>& collection_points)
const {
1219 LogDebug(
"Pixel Digitizer") <<
" enter drift ";
1222 collection_points.resize(ionization_points.size());
1225 if (driftDir.
z() == 0.) {
1226 LogWarning(
"Magnetic field") <<
" pxlx: drift in z is zero ";
1234 float TanLorenzAngleX, TanLorenzAngleY, dir_z, CosLorenzAngleX, CosLorenzAngleY;
1236 TanLorenzAngleX = driftDir.
x();
1237 TanLorenzAngleY = driftDir.
y();
1238 dir_z = driftDir.
z();
1239 CosLorenzAngleX = 1. /
sqrt(1. + TanLorenzAngleX * TanLorenzAngleX);
1240 CosLorenzAngleY = 1. /
sqrt(1. + TanLorenzAngleY * TanLorenzAngleY);
1243 TanLorenzAngleX = driftDir.
x();
1244 TanLorenzAngleY = 0.;
1245 dir_z = driftDir.
z();
1246 CosLorenzAngleX = 1. /
sqrt(1. + TanLorenzAngleX * TanLorenzAngleX);
1247 CosLorenzAngleY = 1.;
1252 LogDebug(
"Pixel Digitizer") <<
" Lorentz Tan " << TanLorenzAngleX <<
" " << TanLorenzAngleY <<
" " << CosLorenzAngleX
1253 <<
" " << CosLorenzAngleY <<
" " << moduleThickness * TanLorenzAngleX <<
" " << driftDir;
1258 float DriftDistance;
1262 for (
unsigned int i = 0;
i != ionization_points.size();
i++) {
1263 float SegX, SegY, SegZ;
1264 SegX = ionization_points[
i].
x();
1265 SegY = ionization_points[
i].y();
1266 SegZ = ionization_points[
i].z();
1271 DriftDistance = moduleThickness / 2. - (dir_z * SegZ);
1281 if (DriftDistance < 0.) {
1283 }
else if (DriftDistance > moduleThickness)
1284 DriftDistance = moduleThickness;
1287 float XDriftDueToMagField = DriftDistance * TanLorenzAngleX;
1288 float YDriftDueToMagField = DriftDistance * TanLorenzAngleY;
1291 float CloudCenterX = SegX + XDriftDueToMagField;
1292 float CloudCenterY = SegY + YDriftDueToMagField;
1295 DriftLength =
sqrt(DriftDistance * DriftDistance + XDriftDueToMagField * XDriftDueToMagField +
1296 YDriftDueToMagField * YDriftDueToMagField);
1302 Sigma_x = Sigma / CosLorenzAngleX;
1303 Sigma_y = Sigma / CosLorenzAngleY;
1306 float energyOnCollector = ionization_points[
i].energy();
1311 energyOnCollector *=
exp(-1 * kValue * DriftDistance / moduleThickness);
1315 LogDebug(
"Pixel Digitizer") <<
" Dift DistanceZ= " << DriftDistance <<
" module thickness= " << moduleThickness
1316 <<
" Start Energy= " << ionization_points[
i].energy()
1317 <<
" Energy after loss= " << energyOnCollector;
1319 SignalPoint sp(CloudCenterX, CloudCenterY, Sigma_x, Sigma_y,
hit.tof(), energyOnCollector);
1322 collection_points[
i] = (sp);
1331 std::vector<PSimHit>::const_iterator inputEnd,
1333 const size_t hitIndex,
1334 const unsigned int tofBin,
1336 const std::vector<SignalPoint>& collection_points) {
1345 LogDebug(
"Pixel Digitizer") <<
" enter induce_signal, " << topol->
pitch().first <<
" " << topol->
pitch().second;
1349 typedef std::map<int, float, std::less<int> > hit_map_type;
1350 hit_map_type hit_signal;
1353 std::map<int, float, std::less<int> >
x,
y;
1358 for (std::vector<SignalPoint>::const_iterator
i = collection_points.begin();
i != collection_points.end(); ++
i) {
1359 float CloudCenterX =
i->position().x();
1360 float CloudCenterY =
i->position().y();
1363 float Charge =
i->amplitude();
1372 LogDebug(
"Pixel Digitizer") <<
" cloud " <<
i->position().x() <<
" " <<
i->position().y() <<
" " <<
i->sigma_x()
1373 <<
" " <<
i->sigma_y() <<
" " <<
i->amplitude();
1396 int IPixRightUpX =
int(floor(mp.
x()));
1397 int IPixRightUpY =
int(floor(mp.
y()));
1400 LogDebug(
"Pixel Digitizer") <<
" right-up " << PointRightUp <<
" " << mp.
x() <<
" " << mp.
y() <<
" " << IPixRightUpX
1401 <<
" " << IPixRightUpY;
1406 int IPixLeftDownX =
int(floor(mp.
x()));
1407 int IPixLeftDownY =
int(floor(mp.
y()));
1410 LogDebug(
"Pixel Digitizer") <<
" left-down " << PointLeftDown <<
" " << mp.
x() <<
" " << mp.
y() <<
" "
1411 << IPixLeftDownX <<
" " << IPixLeftDownY;
1415 int numColumns = topol->
ncolumns();
1416 int numRows = topol->
nrows();
1418 IPixRightUpX = numRows > IPixRightUpX ? IPixRightUpX : numRows - 1;
1419 IPixRightUpY = numColumns > IPixRightUpY ? IPixRightUpY : numColumns - 1;
1420 IPixLeftDownX = 0 < IPixLeftDownX ? IPixLeftDownX : 0;
1421 IPixLeftDownY = 0 < IPixLeftDownY ? IPixLeftDownY : 0;
1428 for (ix = IPixLeftDownX; ix <= IPixRightUpX; ix++) {
1429 float xUB, xLB, UpperBound, LowerBound;
1434 if (ix == 0 ||
SigmaX == 0.)
1439 LowerBound = 1 -
calcQ((xLB - CloudCenterX) /
SigmaX);
1442 if (ix == numRows - 1 ||
SigmaX == 0.)
1447 UpperBound = 1. -
calcQ((xUB - CloudCenterX) /
SigmaX);
1450 float TotalIntegrationRange = UpperBound - LowerBound;
1451 x[ix] = TotalIntegrationRange;
1458 for (iy = IPixLeftDownY; iy <= IPixRightUpY; iy++) {
1459 float yUB, yLB, UpperBound, LowerBound;
1461 if (iy == 0 ||
SigmaY == 0.)
1466 LowerBound = 1. -
calcQ((yLB - CloudCenterY) /
SigmaY);
1469 if (iy == numColumns - 1 ||
SigmaY == 0.)
1474 UpperBound = 1. -
calcQ((yUB - CloudCenterY) /
SigmaY);
1477 float TotalIntegrationRange = UpperBound - LowerBound;
1478 y[iy] = TotalIntegrationRange;
1485 for (ix = IPixLeftDownX; ix <= IPixRightUpX; ix++) {
1486 for (iy = IPixLeftDownY; iy <= IPixRightUpY; iy++) {
1488 float ChargeFraction =
Charge *
x[ix] *
y[iy];
1490 if (ChargeFraction > 0.) {
1493 hit_signal[
chan] += ChargeFraction;
1500 LogDebug(
"Pixel Digitizer") <<
" pixel " << ix <<
" " << iy <<
" - "
1501 <<
" " <<
chan <<
" " << ChargeFraction <<
" " << mp.
x() <<
" " << mp.
y() <<
" "
1502 << lp.
x() <<
" " << lp.
y() <<
" "
1513 bool reweighted =
false;
1515 if (
hit.processType() == 0) {
1521 (*inputBegin), hit_signal, hitIndex, tofBin, topol, detID, theSignal,
hit.processType(),
makeDigiSimLinks_);
1525 for (hit_map_type::const_iterator im = hit_signal.begin(); im != hit_signal.end(); ++im) {
1526 int chan = (*im).first;
1528 :
Amplitude((*im).second, (*im).second));
1532 LogDebug(
"Pixel Digitizer") <<
" pixel " << ip.first <<
" " << ip.second <<
" " << theSignal[
chan];
1545 std::vector<PixelDigi>& digis,
1546 std::vector<PixelDigiSimLink>& simlinks,
1549 LogDebug(
"Pixel Digitizer") <<
" make digis "
1555 <<
" List pixels passing threshold ";
1560 signalMaps::const_iterator it =
_signal.find(detID);
1569 std::map<TrackEventId, float> simi;
1572 float signalInElectrons = (*i).second;
1579 if (signalInElectrons >= thePixelThresholdInE &&
1580 signalInElectrons > 0.) {
1582 int chan = (*i).first;
1589 int col = ip.second;
1596 LogDebug(
"Pixel Digitizer") << (*i).first <<
" " << (*i).second <<
" " << signalInElectrons <<
" " <<
adc
1597 << ip.first <<
" " << ip.second;
1601 digis.emplace_back(ip.first, ip.second,
adc);
1605 unsigned int il = 0;
1606 for (
const auto&
info : (*i).second.hitInfos()) {
1609 simi[std::make_pair(
info.trackId(),
info.eventId().rawId())] += (*i).second.individualampl()[il];
1614 for (
const auto&
info : (*i).second.hitInfos()) {
1616 auto found = simi.find(std::make_pair(
info.trackId(),
info.eventId().rawId()));
1617 if (
found == simi.end())
1620 float sum_samechannel =
found->second;
1621 float fraction = sum_samechannel / (*i).second;
1639 float thePixelThreshold,
1640 CLHEP::HepRandomEngine* engine) {
1649 float theSmearedChargeRMS = 0.0;
1653 if ((*i).second < 3000) {
1654 theSmearedChargeRMS = 543.6 - (*i).second * 0.093;
1655 }
else if ((*i).second < 6000) {
1656 theSmearedChargeRMS = 307.6 - (*i).second * 0.01;
1658 theSmearedChargeRMS = -432.4 + (*i).second * 0.123;
1662 float noise_ChargeVCALSmearing = theSmearedChargeRMS * CLHEP::RandGaussQ::shoot(engine, 0., 1.);
1666 if (((*i).second +
Amplitude(
noise + noise_ChargeVCALSmearing, -1.)) < 0.) {
1690 int numColumns = topol->
ncolumns();
1691 int numRows = topol->
nrows();
1695 int numberOfPixels = (numRows * numColumns);
1696 std::map<int, float, std::less<int> > otherPixels;
1697 std::map<int, float, std::less<int> >::iterator mapI;
1708 << otherPixels.size();
1712 for (mapI = otherPixels.begin(); mapI != otherPixels.end(); mapI++) {
1713 int iy = ((*mapI).first) / numRows;
1714 int ix = ((*mapI).first) - (iy * numRows);
1717 if (iy < 0 || iy > (numColumns - 1))
1718 LogWarning(
"Pixel Geometry") <<
" error in iy " << iy;
1719 if (ix < 0 || ix > (numRows - 1))
1720 LogWarning(
"Pixel Geometry") <<
" error in ix " << ix;
1725 LogDebug(
"Pixel Digitizer") <<
" Storing noise = " << (*mapI).first <<
" " << (*mapI).second <<
" " << ix <<
" "
1726 << iy <<
" " <<
chan;
1729 if (theSignal[
chan] == 0) {
1744 CLHEP::HepRandomEngine* engine) {
1748 int numColumns = topol->
ncolumns();
1749 int numRows = topol->
nrows();
1753 double pixelEfficiency = 1.0;
1754 double columnEfficiency = 1.0;
1755 double chipEfficiency = 1.0;
1756 std::vector<double> pixelEfficiencyROCStdPixels(16, 1);
1757 std::vector<double> pixelEfficiencyROCBigPixels(16, 1);
1759 auto pIndexConverter =
PixelIndices(numColumns, numRows);
1761 std::vector<int> badRocsFromFEDChannels(16, 0);
1767 for (
const auto& ch : *it) {
1768 for (
unsigned int i_roc = ch.roc_first; i_roc <= ch.roc_last; ++i_roc) {
1769 for (
const auto p :
path) {
1771 if (myroc->
idInDetUnit() == static_cast<unsigned int>(i_roc)) {
1774 int chipIndex(0), colROC(0), rowROC(0);
1775 pIndexConverter.transformToROC(global.
col, global.
row, chipIndex, colROC, rowROC);
1776 badRocsFromFEDChannels.at(chipIndex) = 1;
1788 int layerIndex = tTopo->
layer(detID);
1795 if (numColumns > 416)
1796 LogWarning(
"Pixel Geometry") <<
" wrong columns in barrel " << numColumns;
1798 LogWarning(
"Pixel Geometry") <<
" wrong rows in barrel " << numRows;
1803 module = 5 - module;
1814 unsigned int diskIndex =
1816 unsigned int panelIndex = tTopo->
pxfPanel(detID);
1817 unsigned int moduleIndex = tTopo->
pxfModule(detID);
1828 if (numColumns > 260 || numRows > 160) {
1829 if (numColumns > 260)
1830 LogWarning(
"Pixel Geometry") <<
" wrong columns in endcaps " << numColumns;
1832 LogWarning(
"Pixel Geometry") <<
" wrong rows in endcaps " << numRows;
1835 if ((panelIndex == 1 && (moduleIndex == 1 || moduleIndex == 2)) ||
1836 (panelIndex == 2 && moduleIndex == 1)) {
1845 pixelEfficiency = 0.999;
1846 columnEfficiency = 0.999;
1847 chipEfficiency = 0.999;
1862 LogDebug(
"Pixel Digitizer") <<
" enter pixel_inefficiency " << pixelEfficiency <<
" " << columnEfficiency <<
" "
1872 std::map<int, int, std::less<int> > chips,
columns, pixelStd, pixelBig;
1873 std::map<int, int, std::less<int> >::iterator iter;
1878 int chan =
i->first;
1881 int col = ip.second;
1883 pIndexConverter.transformToROC(
col, row, chipIndex, colROC, rowROC);
1884 int dColInChip = pIndexConverter.DColumn(colROC);
1886 int dColInDet = pIndexConverter.DColumnInModule(dColInChip, chipIndex);
1892 pixelBig[chipIndex]++;
1894 pixelStd[chipIndex]++;
1899 for (iter = chips.begin(); iter != chips.end(); iter++) {
1901 float rand = CLHEP::RandFlat::shoot(engine);
1902 if (rand > chipEfficiency)
1903 chips[iter->first] = 0;
1909 float rand = CLHEP::RandFlat::shoot(engine);
1910 if (rand > columnEfficiency)
1916 for (iter = pixelStd.begin(); iter != pixelStd.end(); iter++) {
1917 float rand = CLHEP::RandFlat::shoot(engine);
1918 if (rand > pixelEfficiencyROCStdPixels[iter->first])
1919 pixelStd[iter->first] = 0;
1922 for (iter = pixelBig.begin(); iter != pixelBig.end(); iter++) {
1923 float rand = CLHEP::RandFlat::shoot(engine);
1924 if (rand > pixelEfficiencyROCBigPixels[iter->first])
1925 pixelBig[iter->first] = 0;
1935 int col = ip.second;
1937 pIndexConverter.transformToROC(
col, row, chipIndex, colROC, rowROC);
1938 int dColInChip = pIndexConverter.DColumn(colROC);
1940 int dColInDet = pIndexConverter.DColumnInModule(dColInChip, chipIndex);
1943 float rand = CLHEP::RandFlat::shoot(engine);
1944 if (chips[chipIndex] == 0 ||
columns[dColInDet] == 0 || rand > pixelEfficiency ||
1945 (pixelStd.count(chipIndex) && pixelStd[chipIndex] == 0) ||
1946 (pixelBig.count(chipIndex) && pixelBig[chipIndex] == 0)) {
1951 if ((pixelStd.count(chipIndex) && pixelStd[chipIndex] == 0) ||
1952 (pixelBig.count(chipIndex) && pixelBig[chipIndex] == 0) || (badRocsFromFEDChannels.at(chipIndex) == 1)) {
1974 float pseudoRadDamage = 0.0f;
1979 int layerIndex = tTopo->
layer(detID);
1981 pseudoRadDamage =
aging.thePixelPseudoRadDamage[layerIndex - 1];
1989 unsigned int diskIndex =
1992 pseudoRadDamage =
aging.thePixelPseudoRadDamage[diskIndex - 1];
1999 pseudoRadDamage = 0.f;
2005 return pseudoRadDamage;
2007 LogDebug(
"Pixel Digitizer") <<
" enter pixel_aging " << pseudoRadDamage;
2025 const float signalInElectrons)
const {
2052 throw cms::Exception(
"NotAPixelGeomDetUnit") <<
"Not a pixel geomdet unit" << detID;
2068 newAmp =
p3 +
p2 * tanh(p0 * signal -
p1);
2112 const DetId& detId)
const {
2147 dir_z = -(1 + alpha2_BPix * Bfield.z() * Bfield.z());
2152 dir_z = -(1 + alpha2_FPix * Bfield.z() * Bfield.z());
2155 throw cms::Exception(
"NotAPixelGeomDetUnit") <<
"Not a pixel geomdet unit" << detID;
2162 alpha2 = lorentzAngle * lorentzAngle;
2164 dir_x = -(lorentzAngle * Bfield.y() + alpha2 * Bfield.z() * Bfield.x());
2165 dir_y = +(lorentzAngle * Bfield.x() - alpha2 * Bfield.z() * Bfield.y());
2166 dir_z = -(1 + alpha2 * Bfield.z() * Bfield.z());
2173 LogDebug(
"Pixel Digitizer") <<
" The drift direction in local coordinate is " << theDriftDirection;
2176 return theDriftDirection;
2189 int col = ip.second;
2204 Parameters::const_iterator itDeadModules =
DeadModules.begin();
2207 for (; itDeadModules !=
DeadModules.end(); ++itDeadModules) {
2208 int Dead_detID = itDeadModules->getParameter<
int>(
"Dead_detID");
2209 if (detid == Dead_detID) {
2222 if (Module ==
"whole") {
2231 if (Module ==
"tbmA" && ip.first >= 80 && ip.first <= 159) {
2235 if (Module ==
"tbmB" && ip.first <= 79) {
2250 for (
size_t id = 0;
id < disabledModules.size();
id++) {
2251 if (detID == disabledModules[
id].DetID) {
2253 badmodule = disabledModules[
id];
2272 std::vector<GlobalPixel> badrocpositions(0);
2273 for (
unsigned int j = 0;
j < 16;
j++) {
2276 typedef std::vector<CablingPathToDetUnit>::const_iterator
IT;
2277 for (
IT it =
path.begin(); it !=
path.end(); ++it) {
2282 badrocpositions.push_back(global);
2292 for (std::vector<GlobalPixel>::const_iterator it = badrocpositions.begin(); it != badrocpositions.end(); ++it) {
2293 if (it->row >= 80 && ip.first >= 80) {
2294 if ((
std::abs(ip.second - it->col) < 26)) {
2296 }
else if (it->row == 120 && ip.second - it->col == 26) {
2298 }
else if (it->row == 119 && it->col - ip.second == 26) {
2301 }
else if (it->row < 80 && ip.first < 80) {
2302 if ((
std::abs(ip.second - it->col) < 26)) {
2304 }
else if (it->row == 40 && ip.second - it->col == 26) {
2306 }
else if (it->row == 39 && it->col - ip.second == 26) {