52 #include <gsl/gsl_sf_erf.h>
54 #include "CLHEP/Random/RandGaussQ.h"
55 #include "CLHEP/Random/RandFlat.h"
103 using namespace sipixelobjects;
105 #define TP_DEBUG // protect all LogDebug with ifdef. Takes too much CPU
109 if(use_ineff_from_db_){
110 theSiPixelGainCalibrationService_->setESObjects( es );
112 if(use_deadmodule_DB_) {
115 if(use_LorentzAngle_DB_) {
129 makeDigiSimLinks_(conf.getUntrackedParameter<bool>(
"makeDigiSimLinks",
true)),
130 use_ineff_from_db_(conf.getParameter<bool>(
"useDB")),
131 use_module_killing_(conf.getParameter<bool>(
"killModules")),
132 use_deadmodule_DB_(conf.getParameter<bool>(
"DeadModules_DB")),
133 use_LorentzAngle_DB_(conf.getParameter<bool>(
"LorentzAngle_DB")),
139 GeVperElectron(3.61E-09),
142 alpha2Order(conf.getParameter<bool>(
"Alpha2Order")),
148 NumberOfBarrelLayers(conf.exists(
"NumPixelBarrel")?conf.getParameter<int>(
"NumPixelBarrel"):3),
149 NumberOfEndcapDisks(conf.exists(
"NumPixelEndcap")?conf.getParameter<int>(
"NumPixelEndcap"):2),
156 theElectronPerADC(conf.getParameter<double>(
"ElectronPerAdc")),
160 theAdcFullScale(conf.getParameter<int>(
"AdcFullScale")),
161 theAdcFullScaleStack(conf.exists(
"AdcFullScaleStack")?conf.getParameter<int>(
"AdcFullScaleStack"):255),
165 theNoiseInElectrons(conf.getParameter<double>(
"NoiseInElectrons")),
169 theReadoutNoise(conf.getParameter<double>(
"ReadoutNoiseInElec")),
174 theThresholdInE_FPix(conf.getParameter<double>(
"ThresholdInElectrons_FPix")),
175 theThresholdInE_BPix(conf.getParameter<double>(
"ThresholdInElectrons_BPix")),
176 theThresholdInE_BPix_L1(conf.exists(
"ThresholdInElectrons_BPix_L1")?conf.getParameter<double>(
"ThresholdInElectrons_BPix_L1"):theThresholdInE_BPix),
179 theThresholdSmearing_FPix(conf.getParameter<double>(
"ThresholdSmearing_FPix")),
180 theThresholdSmearing_BPix(conf.getParameter<double>(
"ThresholdSmearing_BPix")),
181 theThresholdSmearing_BPix_L1(conf.exists(
"ThresholdSmearing_BPix_L1")?conf.getParameter<double>(
"ThresholdSmearing_BPix_L1"):theThresholdSmearing_BPix),
184 electronsPerVCAL(conf.getParameter<double>(
"ElectronsPerVcal")),
185 electronsPerVCAL_Offset(conf.getParameter<double>(
"ElectronsPerVcal_Offset")),
189 theTofLowerCut(conf.getParameter<double>(
"TofLowerCut")),
190 theTofUpperCut(conf.getParameter<double>(
"TofUpperCut")),
193 tanLorentzAnglePerTesla_FPix(use_LorentzAngle_DB_ ? 0.0 : conf.getParameter<double>(
"TanLorentzAnglePerTesla_FPix")),
194 tanLorentzAnglePerTesla_BPix(use_LorentzAngle_DB_ ? 0.0 : conf.getParameter<double>(
"TanLorentzAnglePerTesla_BPix")),
197 FPix_p0(conf.getParameter<double>(
"FPix_SignalResponse_p0")),
198 FPix_p1(conf.getParameter<double>(
"FPix_SignalResponse_p1")),
199 FPix_p2(conf.getParameter<double>(
"FPix_SignalResponse_p2")),
200 FPix_p3(conf.getParameter<double>(
"FPix_SignalResponse_p3")),
202 BPix_p0(conf.getParameter<double>(
"BPix_SignalResponse_p0")),
203 BPix_p1(conf.getParameter<double>(
"BPix_SignalResponse_p1")),
204 BPix_p2(conf.getParameter<double>(
"BPix_SignalResponse_p2")),
205 BPix_p3(conf.getParameter<double>(
"BPix_SignalResponse_p3")),
208 addNoise(conf.getParameter<bool>(
"AddNoise")),
212 addChargeVCALSmearing(conf.getParameter<bool>(
"ChargeVCALSmearing")),
215 addNoisyPixels(conf.getParameter<bool>(
"AddNoisyPixels")),
218 fluctuateCharge(conf.getUntrackedParameter<bool>(
"FluctuateCharge",
true)),
221 AddPixelInefficiency(conf.getParameter<bool>(
"AddPixelInefficiency")),
224 addThresholdSmearing(conf.getParameter<bool>(
"AddThresholdSmearing")),
227 doMissCalibrate(conf.getParameter<bool>(
"MissCalibrate")),
228 theGainSmearing(conf.getParameter<double>(
"GainSmearing")),
229 theOffsetSmearing(conf.getParameter<double>(
"OffsetSmearing")),
232 AddPixelAging(conf.getParameter<bool>(
"DoPixelAging")),
237 tMax(conf.getParameter<double>(
"deltaProductionCut")),
241 calmap(doMissCalibrate ? initCal() : std::
map<int,
CalParameters,std::less<int> >()),
243 pixelEfficiencies_(conf, AddPixelInefficiency,NumberOfBarrelLayers,NumberOfEndcapDisks),
244 pixelAging_(conf,AddPixelAging,NumberOfBarrelLayers,NumberOfEndcapDisks)
246 LogInfo (
"PixelDigitizer ") <<
"SiPixelDigitizerAlgorithm constructed"
247 <<
"Configuration parameters:"
248 <<
"Threshold/Gain = "
249 <<
"threshold in electron FPix = "
251 <<
"threshold in electron BPix = "
253 <<
"threshold in electron BPix Layer1 = "
256 <<
" The delta cut-off is set to " <<
tMax
261 std::map<int, SiPixelDigitizerAlgorithm::CalParameters, std::less<int> >
268 std::map<int, SiPixelDigitizerAlgorithm::CalParameters, std::less<int> >
calmap;
271 <<
" miss-calibrate the pixel amplitude ";
273 const bool ReadCalParameters =
false;
274 if(ReadCalParameters) {
277 char filename[80] =
"phCalibrationFit_C0.dat";
281 cout <<
" File not found " << endl;
284 cout <<
" file opened : " << filename << endl;
287 for (
int i = 0;
i < 3;
i++) {
288 in_file.getline(line, 500,
'\n');
292 cout <<
" test map" << endl;
294 float par0,par1,par2,par3;
298 for(
int i=0;
i<(52*80);
i++) {
299 in_file >> par0 >> par1 >> par2 >> par3 >> name >> colid >> rowid;
301 cerr <<
"Cannot read data file" << endl;
304 if( in_file.eof() != 0 ) {
305 cerr << in_file.eof() <<
" " << in_file.gcount() <<
" "
306 << in_file.fail() <<
" " << in_file.good() <<
" end of file "
322 calmap.insert(std::pair<int,CalParameters>(chan,onePix));
326 if(rowid!=p.first)
cout<<
" wrong channel row "<<rowid<<
" "<<p.first<<endl;
327 if(colid!=p.second)
cout<<
" wrong channel col "<<colid<<
" "<<p.second<<endl;
331 cout <<
" map size " << calmap.size() <<
" max "<<calmap.max_size() <<
" "
332 <<calmap.empty()<< endl;
355 LogDebug (
"PixelDigitizer")<<
"SiPixelDigitizerAlgorithm deleted";
364 if (AddPixelInefficiency){
366 conf.
exists(
"thePixelColEfficiency_BPix1") && conf.
exists(
"thePixelColEfficiency_BPix2") && conf.
exists(
"thePixelColEfficiency_BPix3") &&
367 conf.
exists(
"thePixelColEfficiency_FPix1") && conf.
exists(
"thePixelColEfficiency_FPix2") &&
368 conf.
exists(
"thePixelEfficiency_BPix1") && conf.
exists(
"thePixelEfficiency_BPix2") && conf.
exists(
"thePixelEfficiency_BPix3") &&
369 conf.
exists(
"thePixelEfficiency_FPix1") && conf.
exists(
"thePixelEfficiency_FPix2") &&
370 conf.
exists(
"thePixelChipEfficiency_BPix1") && conf.
exists(
"thePixelChipEfficiency_BPix2") && conf.
exists(
"thePixelChipEfficiency_BPix3") &&
371 conf.
exists(
"thePixelChipEfficiency_FPix1") && conf.
exists(
"thePixelChipEfficiency_FPix2");
372 if (NumberOfBarrelLayers==3)
FromConfig =
FromConfig && conf.
exists(
"theLadderEfficiency_BPix1") && conf.
exists(
"theLadderEfficiency_BPix2") && conf.
exists(
"theLadderEfficiency_BPix3") &&
373 conf.
exists(
"theModuleEfficiency_BPix1") && conf.
exists(
"theModuleEfficiency_BPix2") && conf.
exists(
"theModuleEfficiency_BPix3") &&
374 conf.
exists(
"thePUEfficiency_BPix1") && conf.
exists(
"thePUEfficiency_BPix2") && conf.
exists(
"thePUEfficiency_BPix3") &&
375 conf.
exists(
"theInnerEfficiency_FPix1") && conf.
exists(
"theInnerEfficiency_FPix2") &&
376 conf.
exists(
"theOuterEfficiency_FPix1") && conf.
exists(
"theOuterEfficiency_FPix2") &&
377 conf.
exists(
"thePUEfficiency_FPix_Inner") && conf.
exists(
"thePUEfficiency_FPix_Outer") &&
378 conf.
exists(
"theInstLumiScaleFactor");
380 conf.
exists(
"thePixelEfficiency_BPix4") && conf.
exists(
"thePixelChipEfficiency_BPix4");
382 conf.
exists(
"thePixelEfficiency_FPix3") && conf.
exists(
"thePixelChipEfficiency_FPix3");
384 LogInfo (
"PixelDigitizer ") <<
"The PixelDigitizer inefficiency configuration is read from the config file.\n";
389 thePixelColEfficiency[i++] = conf.
getParameter<
double>(
"thePixelColEfficiency_BPix3");
390 if (NumberOfBarrelLayers>=4){thePixelColEfficiency[i++] = conf.
getParameter<
double>(
"thePixelColEfficiency_BPix4");}
395 thePixelEfficiency[i++] = conf.
getParameter<
double>(
"thePixelEfficiency_BPix3");
396 if (NumberOfBarrelLayers>=4){thePixelEfficiency[i++] = conf.
getParameter<
double>(
"thePixelEfficiency_BPix4");}
401 thePixelChipEfficiency[i++] = conf.
getParameter<
double>(
"thePixelChipEfficiency_BPix3");
402 if (NumberOfBarrelLayers>=4){thePixelChipEfficiency[i++] = conf.
getParameter<
double>(
"thePixelChipEfficiency_BPix4");}
404 if (NumberOfBarrelLayers==3){
408 theLadderEfficiency_BPix[i++] = conf.
getParameter<std::vector<double> >(
"theLadderEfficiency_BPix3");
409 if ( ((theLadderEfficiency_BPix[0].
size()!=20) || (theLadderEfficiency_BPix[1].
size()!=32) ||
410 (theLadderEfficiency_BPix[2].
size()!=44)) && (NumberOfBarrelLayers==3) )
411 throw cms::Exception(
"Configuration") <<
"Wrong ladder number in efficiency config!";
416 theModuleEfficiency_BPix[i++] = conf.
getParameter<std::vector<double> >(
"theModuleEfficiency_BPix3");
417 if ( ((theModuleEfficiency_BPix[0].
size()!=4) || (theModuleEfficiency_BPix[1].
size()!=4) ||
418 (theModuleEfficiency_BPix[2].
size()!=4)) && (NumberOfBarrelLayers==3) )
419 throw cms::Exception(
"Configuration") <<
"Wrong module number in efficiency config!";
426 throw cms::Exception(
"Configuration") <<
"At least one PU efficiency (BPix) number is needed in efficiency config!";
429 if (NumberOfBarrelLayers>=5){
430 if (NumberOfTotLayers>20){
throw cms::Exception(
"Configuration") <<
"SiPixelDigitizer was given more layers than it can handle";}
433 thePixelColEfficiency[
j-1]=0.999;
434 thePixelEfficiency[
j-1]=0.999;
435 thePixelChipEfficiency[
j-1]=0.999;
440 thePixelColEfficiency[i++] = conf.
getParameter<
double>(
"thePixelColEfficiency_FPix1");
441 thePixelColEfficiency[i++] = conf.
getParameter<
double>(
"thePixelColEfficiency_FPix2");
442 if (NumberOfEndcapDisks>=3){thePixelColEfficiency[i++] = conf.
getParameter<
double>(
"thePixelColEfficiency_FPix3");}
444 thePixelEfficiency[i++] = conf.
getParameter<
double>(
"thePixelEfficiency_FPix1");
445 thePixelEfficiency[i++] = conf.
getParameter<
double>(
"thePixelEfficiency_FPix2");
446 if (NumberOfEndcapDisks>=3){thePixelEfficiency[i++] = conf.
getParameter<
double>(
"thePixelEfficiency_FPix3");}
448 thePixelChipEfficiency[i++] = conf.
getParameter<
double>(
"thePixelChipEfficiency_FPix1");
449 thePixelChipEfficiency[i++] = conf.
getParameter<
double>(
"thePixelChipEfficiency_FPix2");
450 if (NumberOfEndcapDisks>=3){thePixelChipEfficiency[i++] = conf.
getParameter<
double>(
"thePixelChipEfficiency_FPix3");}
452 if (NumberOfEndcapDisks>=4){
453 if (NumberOfTotLayers>20){
throw cms::Exception(
"Configuration") <<
"SiPixelDigitizer was given more layers than it can handle";}
456 thePixelColEfficiency[
j-1]=0.999;
457 thePixelEfficiency[
j-1]=0.999;
458 thePixelChipEfficiency[
j-1]=0.999;
462 if (NumberOfBarrelLayers==3){
472 throw cms::Exception(
"Configuration") <<
"At least one (FPix) PU efficiency number is needed in efficiency config!";
476 else LogInfo (
"PixelDigitizer ") <<
"The PixelDigitizer inefficiency configuration is read from the database.\n";
493 theInstLumiScaleFactor = SiPixelDynamicInefficiency->gettheInstLumiScaleFactor();
494 std::map<uint32_t, double> PixelGeomFactorsDB = SiPixelDynamicInefficiency->getPixelGeomFactors();
495 std::map<uint32_t, double> ColGeomFactorsDB = SiPixelDynamicInefficiency->getColGeomFactors();
496 std::map<uint32_t, double> ChipGeomFactorsDB = SiPixelDynamicInefficiency->getChipGeomFactors();
497 std::map<uint32_t, std::vector<double> > PUFactors = SiPixelDynamicInefficiency->getPUFactors();
498 std::vector<uint32_t > DetIdmasks = SiPixelDynamicInefficiency->getDetIdmasks();
501 for(TrackerGeometry::DetUnitContainer::const_iterator it_module = geom->detUnits().begin(); it_module != geom->detUnits().end(); it_module++) {
502 if( dynamic_cast<PixelGeomDetUnit const*>((*it_module))==0)
continue;
503 const DetId detid = (*it_module)->geographicalId();
504 uint32_t rawid = detid.
rawId();
505 PixelGeomFactors[rawid] = 1;
506 ColGeomFactors[rawid] = 1;
507 ChipGeomFactors[rawid] = 1;
508 for (
auto db_factor : PixelGeomFactorsDB)
if (
matches(detid,
DetId(db_factor.first), DetIdmasks)) PixelGeomFactors[rawid] *= db_factor.second;
509 for (
auto db_factor : ColGeomFactorsDB)
if (
matches(detid,
DetId(db_factor.first), DetIdmasks)) ColGeomFactors[rawid] *= db_factor.second;
510 for (
auto db_factor : ChipGeomFactorsDB)
if (
matches(detid,
DetId(db_factor.first), DetIdmasks)) ChipGeomFactors[rawid] *= db_factor.second;
516 for (
auto factor : PUFactors) {
518 for(TrackerGeometry::DetUnitContainer::const_iterator it_module = geom->detUnits().begin(); it_module != geom->detUnits().end(); it_module++) {
519 if( dynamic_cast<PixelGeomDetUnit const*>((*it_module))==0)
continue;
520 const DetId detid = (*it_module)->geographicalId();
521 if (!
matches(detid, db_id, DetIdmasks))
continue;
522 if (iPU.count(detid.
rawId())) {
523 throw cms::Exception(
"Database")<<
"Multiple db_ids match to same module in SiPixelDynamicInefficiency DB Object";
528 thePUEfficiency.push_back(factor.second);
531 pu_scale.resize(thePUEfficiency.size());
536 for (
size_t i=0;
i<DetIdmasks.size(); ++
i) {
553 thePixelPseudoRadDamage[i++] = conf.
getParameter<
double>(
"thePixelPseudoRadDamage_BPix1");
554 thePixelPseudoRadDamage[i++] = conf.
getParameter<
double>(
"thePixelPseudoRadDamage_BPix2");
555 thePixelPseudoRadDamage[i++] = conf.
getParameter<
double>(
"thePixelPseudoRadDamage_BPix3");
556 thePixelPseudoRadDamage[i++] = conf.
getParameter<
double>(
"thePixelPseudoRadDamage_BPix4");
559 if (NumberOfBarrelLayers>=5){
560 if (NumberOfTotLayers>20){
throw cms::Exception(
"Configuration") <<
"SiPixelDigitizer was given more layers than it can handle";}
563 thePixelPseudoRadDamage[
j-1]=0.;
568 thePixelPseudoRadDamage[i++] = conf.
getParameter<
double>(
"thePixelPseudoRadDamage_FPix1");
569 thePixelPseudoRadDamage[i++] = conf.
getParameter<
double>(
"thePixelPseudoRadDamage_FPix2");
570 thePixelPseudoRadDamage[i++] = conf.
getParameter<
double>(
"thePixelPseudoRadDamage_FPix3");
573 if (NumberOfEndcapDisks>=4){
574 if (NumberOfTotLayers>20){
throw cms::Exception(
"Configuration") <<
"SiPixelDigitizer was given more layers than it can handle";}
577 thePixelPseudoRadDamage[
j-1]=0.;
587 std::vector<PSimHit>::const_iterator inputEnd,
588 const size_t inputBeginGlobalIndex,
589 const unsigned int tofBin,
593 CLHEP::HepRandomEngine* engine) {
598 size_t simHitGlobalIndex=inputBeginGlobalIndex;
599 for (std::vector<PSimHit>::const_iterator ssbegin = inputBegin; ssbegin != inputEnd; ++ssbegin, ++simHitGlobalIndex) {
601 if((*ssbegin).detUnitId() != detId) {
607 << (*ssbegin).particleType() <<
" " << (*ssbegin).pabs() <<
" "
608 << (*ssbegin).energyLoss() <<
" " << (*ssbegin).tof() <<
" "
609 << (*ssbegin).trackId() <<
" " << (*ssbegin).processType() <<
" "
610 << (*ssbegin).detUnitId()
611 << (*ssbegin).entryPoint() <<
" " << (*ssbegin).exitPoint() ;
615 std::vector<EnergyDepositUnit> ionization_points;
616 std::vector<SignalPoint> collection_points;
623 drift(*ssbegin, pixdet, bfield, tTopo, ionization_points, collection_points);
625 induce_signal(*ssbegin, simHitGlobalIndex, tofBin, pixdet, collection_points);
641 std::vector<int>::const_iterator pu;
642 std::vector<int>::const_iterator pu0 = bunchCrossing.end();
644 for (pu=bunchCrossing.begin(); pu!=bunchCrossing.end(); ++pu) {
651 if (pu0!=bunchCrossing.end()) {
654 double instlumi_pow=1.;
658 instlumi_pow*=instlumi;
672 std::vector<PixelDigi>& digis,
673 std::vector<PixelDigiSimLink>& simlinks,
675 CLHEP::HepRandomEngine* engine) {
686 int numRows = topol->
nrows();
693 float thePixelThresholdInE = 0.;
697 int lay = tTopo->
layer(detID);
718 else {
throw cms::Exception(
"NotAPixelGeomDetUnit") <<
"Not a pixel geomdet unit" << detID;}
726 <<
" PixelDigitizer "
727 << numColumns <<
" " << numRows <<
" " << moduleThickness;
748 make_digis(thePixelThresholdInE, detID, pixdet, digis, simlinks, tTopo);
751 LogDebug (
"PixelDigitizer") <<
"[SiPixelDigitizerAlgorithm] converted " << digis.size() <<
" PixelDigis in DetUnit" << detID;
762 const float SegmentLength = 0.0010;
769 float length = direction.
mag();
771 int NumberOfSegments = int ( length / SegmentLength);
772 if(NumberOfSegments < 1) NumberOfSegments = 1;
776 <<
" enter primary_ionzation " << NumberOfSegments
784 float* elossVector =
new float[NumberOfSegments];
791 float momentum = hit.
pabs();
794 elossVector, engine);
797 ionization_points.resize( NumberOfSegments);
800 for (
int i = 0;
i != NumberOfSegments;
i++) {
803 float((
i+0.5)/NumberOfSegments) * direction;
811 ionization_points[
i] = edu;
815 <<
i <<
" " << ionization_points[
i].x() <<
" "
816 << ionization_points[
i].y() <<
" "
817 << ionization_points[
i].z() <<
" "
818 << ionization_points[
i].energy();
823 delete[] elossVector;
831 float eloss,
float length,
832 int NumberOfSegs,
float elossVector[],
833 CLHEP::HepRandomEngine* engine)
const {
840 double particleMass = 139.6;
843 if(pid==11) particleMass = 0.511;
844 else if(pid==13) particleMass = 105.7;
845 else if(pid==321) particleMass = 493.7;
846 else if(pid==2212) particleMass = 938.3;
849 float segmentLength = length/NumberOfSegs;
854 double segmentEloss = (1000.*eloss)/NumberOfSegs;
855 for (
int i=0;
i<NumberOfSegs;
i++) {
861 double deltaCutoff =
tMax;
862 de =
fluctuate->SampleFluctuations(
double(particleMomentum*1000.),
863 particleMass, deltaCutoff,
864 double(segmentLength*10.),
865 segmentEloss, engine )/1000.;
872 float ratio = eloss/sum;
874 for (
int ii=0;
ii<NumberOfSegs;
ii++) elossVector[
ii]= ratio*elossVector[
ii];
876 float averageEloss = eloss/NumberOfSegs;
877 for (
int ii=0;
ii<NumberOfSegs;
ii++) elossVector[
ii]= averageEloss;
889 const std::vector<EnergyDepositUnit>& ionization_points,
890 std::vector<SignalPoint>& collection_points)
const {
893 LogDebug (
"Pixel Digitizer") <<
" enter drift " ;
896 collection_points.resize(ionization_points.size());
899 if(driftDir.
z() ==0.) {
900 LogWarning(
"Magnetic field") <<
" pxlx: drift in z is zero ";
908 float TanLorenzAngleX, TanLorenzAngleY,dir_z, CosLorenzAngleX,
911 TanLorenzAngleX = driftDir.
x();
912 TanLorenzAngleY = driftDir.
y();
913 dir_z = driftDir.
z();
914 CosLorenzAngleX = 1./
sqrt(1.+TanLorenzAngleX*TanLorenzAngleX);
915 CosLorenzAngleY = 1./
sqrt(1.+TanLorenzAngleY*TanLorenzAngleY);
918 TanLorenzAngleX = driftDir.
x();
919 TanLorenzAngleY = 0.;
920 dir_z = driftDir.
z();
921 CosLorenzAngleX = 1./
sqrt(1.+TanLorenzAngleX*TanLorenzAngleX);
922 CosLorenzAngleY = 1.;
928 <<
" Lorentz Tan " << TanLorenzAngleX <<
" " << TanLorenzAngleY <<
" "
929 << CosLorenzAngleX <<
" " << CosLorenzAngleY <<
" "
930 << moduleThickness*TanLorenzAngleX <<
" " << driftDir;
939 for (
unsigned int i = 0;
i != ionization_points.size();
i++) {
941 float SegX, SegY, SegZ;
942 SegX = ionization_points[
i].
x();
943 SegY = ionization_points[
i].y();
944 SegZ = ionization_points[
i].z();
949 DriftDistance = moduleThickness/2. - (dir_z * SegZ);
959 if( DriftDistance < 0.) {
961 }
else if( DriftDistance > moduleThickness )
962 DriftDistance = moduleThickness;
965 float XDriftDueToMagField = DriftDistance * TanLorenzAngleX;
966 float YDriftDueToMagField = DriftDistance * TanLorenzAngleY;
969 float CloudCenterX = SegX + XDriftDueToMagField;
970 float CloudCenterY = SegY + YDriftDueToMagField;
973 DriftLength =
sqrt( DriftDistance*DriftDistance +
974 XDriftDueToMagField*XDriftDueToMagField +
975 YDriftDueToMagField*YDriftDueToMagField );
981 Sigma_x = Sigma / CosLorenzAngleX ;
982 Sigma_y = Sigma / CosLorenzAngleY ;
985 float energyOnCollector = ionization_points[
i].energy();
990 energyOnCollector *=
exp( -1*kValue*DriftDistance/moduleThickness );
995 <<
" Dift DistanceZ= "<<DriftDistance<<
" module thickness= "<<moduleThickness
996 <<
" Start Energy= "<<ionization_points[
i].energy()<<
" Energy after loss= "<<energyOnCollector;
999 Sigma_x, Sigma_y, hit.
tof(), energyOnCollector );
1002 collection_points[
i] = (sp);
1011 const size_t hitIndex,
1012 const unsigned int tofBin,
1014 const std::vector<SignalPoint>& collection_points) {
1025 <<
" enter induce_signal, "
1026 << topol->
pitch().first <<
" " << topol->
pitch().second;
1030 typedef std::map< int, float, std::less<int> > hit_map_type;
1031 hit_map_type hit_signal;
1034 std::map<int, float, std::less<int> >
x,
y;
1039 for ( std::vector<SignalPoint>::const_iterator
i=collection_points.begin();
1040 i != collection_points.end(); ++
i) {
1042 float CloudCenterX =
i->position().x();
1043 float CloudCenterY =
i->position().y();
1044 float SigmaX =
i->sigma_x();
1045 float SigmaY =
i->sigma_y();
1046 float Charge =
i->amplitude();
1057 <<
" cloud " <<
i->position().x() <<
" " <<
i->position().y() <<
" "
1058 <<
i->sigma_x() <<
" " <<
i->sigma_y() <<
" " <<
i->amplitude();
1081 int IPixRightUpX = int( floor( mp.
x()));
1082 int IPixRightUpY = int( floor( mp.
y()));
1085 LogDebug (
"Pixel Digitizer") <<
" right-up " << PointRightUp <<
" "
1086 << mp.
x() <<
" " << mp.
y() <<
" "
1087 << IPixRightUpX <<
" " << IPixRightUpY ;
1092 int IPixLeftDownX = int( floor( mp.
x()));
1093 int IPixLeftDownY = int( floor( mp.
y()));
1096 LogDebug (
"Pixel Digitizer") <<
" left-down " << PointLeftDown <<
" "
1097 << mp.
x() <<
" " << mp.
y() <<
" "
1098 << IPixLeftDownX <<
" " << IPixLeftDownY ;
1102 int numColumns = topol->
ncolumns();
1103 int numRows = topol->
nrows();
1105 IPixRightUpX = numRows>IPixRightUpX ? IPixRightUpX : numRows-1 ;
1106 IPixRightUpY = numColumns>IPixRightUpY ? IPixRightUpY : numColumns-1 ;
1107 IPixLeftDownX = 0<IPixLeftDownX ? IPixLeftDownX : 0 ;
1108 IPixLeftDownY = 0<IPixLeftDownY ? IPixLeftDownY : 0 ;
1115 for (ix=IPixLeftDownX; ix<=IPixRightUpX; ix++) {
1116 float xUB, xLB, UpperBound, LowerBound;
1121 if(ix == 0 || SigmaX==0. )
1126 LowerBound = 1-
calcQ((xLB-CloudCenterX)/SigmaX);
1129 if(ix == numRows-1 || SigmaX==0. )
1134 UpperBound = 1. -
calcQ((xUB-CloudCenterX)/SigmaX);
1137 float TotalIntegrationRange = UpperBound - LowerBound;
1138 x[ix] = TotalIntegrationRange;
1146 for (iy=IPixLeftDownY; iy<=IPixRightUpY; iy++) {
1147 float yUB, yLB, UpperBound, LowerBound;
1149 if(iy == 0 || SigmaY==0.)
1154 LowerBound = 1. -
calcQ((yLB-CloudCenterY)/SigmaY);
1157 if(iy == numColumns-1 || SigmaY==0. )
1162 UpperBound = 1. -
calcQ((yUB-CloudCenterY)/SigmaY);
1165 float TotalIntegrationRange = UpperBound - LowerBound;
1166 y[iy] = TotalIntegrationRange;
1173 for (ix=IPixLeftDownX; ix<=IPixRightUpX; ix++) {
1174 for (iy=IPixLeftDownY; iy<=IPixRightUpY; iy++) {
1176 float ChargeFraction = Charge*x[ix]*y[iy];
1178 if( ChargeFraction > 0. ) {
1181 hit_signal[chan] += ChargeFraction;
1191 <<
" pixel " << ix <<
" " << iy <<
" - "<<
" "
1192 << chan <<
" " << ChargeFraction<<
" "
1193 << mp.
x() <<
" " << mp.
y() <<
" "
1194 << lp.
x() <<
" " << lp.
y() <<
" "
1224 for ( hit_map_type::const_iterator im = hit_signal.begin();
1225 im != hit_signal.end(); ++im) {
1226 int chan = (*im).first;
1227 theSignal[chan] += (
makeDigiSimLinks_ ?
Amplitude( (*im).second, &hit, hitIndex, tofBin, (*im).second) : Amplitude( (*im).second, (*im).second) ) ;
1232 <<
" pixel " << ip.first <<
" " << ip.second <<
" "
1245 std::vector<PixelDigi>& digis,
1246 std::vector<PixelDigiSimLink>& simlinks,
1250 LogDebug (
"Pixel Digitizer") <<
" make digis "<<
" "
1254 <<
" List pixels passing threshold ";
1259 signalMaps::const_iterator it =
_signal.find(detID);
1268 float signalInElectrons = (*i).second ;
1275 if( signalInElectrons >= thePixelThresholdInE) {
1277 int chan = (*i).first;
1284 int col = ip.second;
1285 adc = int(
missCalibrate(detID, pixdet, col, row, signalInElectrons));
1301 << (*i).first <<
" " << (*i).second <<
" " << signalInElectrons
1302 <<
" " << adc << ip.first <<
" " << ip.second ;
1306 digis.emplace_back(ip.first, ip.second, adc);
1310 if((*i).second.trackIds().size()>0){
1313 for( std::vector<unsigned int>::const_iterator itid = (*i).second.trackIds().begin();
1314 itid != (*i).second.trackIds().end(); ++itid) {
1315 simi[*itid].push_back((*i).second.individualampl()[il]);
1320 for( simlink_map::iterator simiiter=simi.begin();
1321 simiiter!=simi.end();
1324 float sum_samechannel=0;
1325 for (
unsigned int iii=0;iii<(*simiiter).second.size();iii++){
1326 sum_samechannel+=(*simiiter).second[iii];
1328 float fraction=sum_samechannel/(*i).second;
1329 if(fraction>1.) fraction=1.;
1330 simlinks.emplace_back((*i).first, (*simiiter).first, (*i).second.hitIndex(), (*i).second.tofBin(), (*i).second.eventId(),
fraction);
1342 float thePixelThreshold,
1343 CLHEP::HepRandomEngine* engine) {
1354 float theSmearedChargeRMS = 0.0;
1360 if((*i).second < 3000)
1362 theSmearedChargeRMS = 543.6 - (*i).second * 0.093;
1363 }
else if((*i).second < 6000){
1364 theSmearedChargeRMS = 307.6 - (*i).second * 0.01;
1366 theSmearedChargeRMS = -432.4 +(*i).second * 0.123;
1370 float noise_ChargeVCALSmearing = theSmearedChargeRMS * CLHEP::RandGaussQ::shoot(engine, 0., 1.);
1374 if(((*i).second +
Amplitude(noise+noise_ChargeVCALSmearing, -1.)) < 0. ) {
1375 (*i).second.set(0);}
1377 (*i).second +=
Amplitude(noise+noise_ChargeVCALSmearing, -1.);
1387 if(((*i).second +
Amplitude(noise, -1.)) < 0. ) {
1388 (*i).second.set(0);}
1400 int numColumns = topol->
ncolumns();
1401 int numRows = topol->
nrows();
1405 int numberOfPixels = (numRows * numColumns);
1406 std::map<int,float, std::less<int> > otherPixels;
1407 std::map<int,float, std::less<int> >::iterator mapI;
1417 <<
" Add noisy pixels " << numRows <<
" "
1420 << otherPixels.size() ;
1424 for (mapI = otherPixels.begin(); mapI!= otherPixels.end(); mapI++) {
1425 int iy = ((*mapI).first) / numRows;
1426 int ix = ((*mapI).first) - (iy*numRows);
1429 if( iy < 0 || iy > (numColumns-1) )
1430 LogWarning (
"Pixel Geometry") <<
" error in iy " << iy ;
1431 if( ix < 0 || ix > (numRows-1) )
1432 LogWarning (
"Pixel Geometry") <<
" error in ix " << ix ;
1438 <<
" Storing noise = " << (*mapI).first <<
" " << (*mapI).second
1439 <<
" " << ix <<
" " << iy <<
" " << chan ;
1442 if(theSignal[chan] == 0){
1444 int noise=int( (*mapI).second );
1445 theSignal[chan] =
Amplitude (noise, -1.);
1457 CLHEP::HepRandomEngine* engine) {
1462 int numColumns = topol->
ncolumns();
1463 int numRows = topol->
nrows();
1466 double pixelEfficiency = 1.0;
1467 double columnEfficiency = 1.0;
1468 double chipEfficiency = 1.0;
1474 int layerIndex=tTopo->
layer(detID);
1481 if(numColumns>416)
LogWarning (
"Pixel Geometry") <<
" wrong columns in barrel "<<numColumns;
1482 if(numRows>160)
LogWarning (
"Pixel Geometry") <<
" wrong rows in barrel "<<numRows;
1486 if (module<=4) module=5-
module;
1496 unsigned int panelIndex=tTopo->
pxfPanel(detID);
1497 unsigned int moduleIndex=tTopo->
pxfModule(detID);
1507 if(numColumns>260 || numRows>160) {
1508 if(numColumns>260)
LogWarning (
"Pixel Geometry") <<
" wrong columns in endcaps "<<numColumns;
1509 if(numRows>160)
LogWarning (
"Pixel Geometry") <<
" wrong rows in endcaps "<<numRows;
1512 if ((panelIndex==1 && (moduleIndex==1 || moduleIndex==2)) || (panelIndex==2 && moduleIndex==1)) {
1520 pixelEfficiency = 0.999;
1521 columnEfficiency = 0.999;
1522 chipEfficiency = 0.999;
1531 LogDebug (
"Pixel Digitizer") <<
" enter pixel_inefficiency " << pixelEfficiency <<
" "
1532 << columnEfficiency <<
" " << chipEfficiency;
1537 std::auto_ptr<PixelIndices> pIndexConverter(
new PixelIndices(numColumns,numRows));
1542 std::map<int, int, std::less<int> >chips, columns;
1543 std::map<int, int, std::less<int> >::iterator iter;
1549 int chan =
i->first;
1552 int col = ip.second;
1554 pIndexConverter->transformToROC(col,row,chipIndex,colROC,rowROC);
1555 int dColInChip = pIndexConverter->DColumn(colROC);
1557 int dColInDet = pIndexConverter->DColumnInModule(dColInChip,chipIndex);
1560 columns[dColInDet]++;
1564 for ( iter = chips.begin(); iter != chips.end() ; iter++ ) {
1566 float rand = CLHEP::RandFlat::shoot(engine);
1567 if( rand > chipEfficiency ) chips[iter->first]=0;
1571 for ( iter = columns.begin(); iter != columns.end() ; iter++ ) {
1573 float rand = CLHEP::RandFlat::shoot(engine);
1574 if( rand > columnEfficiency ) columns[iter->first]=0;
1584 int col = ip.second;
1586 pIndexConverter->transformToROC(col,row,chipIndex,colROC,rowROC);
1587 int dColInChip = pIndexConverter->DColumn(colROC);
1589 int dColInDet = pIndexConverter->DColumnInModule(dColInChip,chipIndex);
1592 float rand = CLHEP::RandFlat::shoot(engine);
1593 if( chips[chipIndex]==0 || columns[dColInDet]==0
1594 || rand>pixelEfficiency ) {
1614 float pseudoRadDamage = 0.0;
1619 int layerIndex=tTopo->
layer(detID);
1637 pseudoRadDamage = 0.;
1643 return pseudoRadDamage;
1645 LogDebug (
"Pixel Digitizer") <<
" enter pixel_aging " << pseudoRadDamage;
1660 const float signalInElectrons)
const {
1687 throw cms::Exception(
"NotAPixelGeomDetUnit") <<
"Not a pixel geomdet unit" << detID;
1698 newAmp = p3 + p2 * tanh(p0*signal - p1);
1743 const DetId& detId)
const {
1780 dir_z = -(1 + alpha2_BPix* Bfield.z()*Bfield.z() );
1785 dir_z = -(1 + alpha2_FPix* Bfield.z()*Bfield.z() );
1788 throw cms::Exception(
"NotAPixelGeomDetUnit") <<
"Not a pixel geomdet unit" << detID;
1795 alpha2 = lorentzAngle * lorentzAngle;
1797 dir_x = -( lorentzAngle * Bfield.y() + alpha2 * Bfield.z()* Bfield.x() );
1798 dir_y = +( lorentzAngle * Bfield.x() - alpha2 * Bfield.z()* Bfield.y() );
1799 dir_z = -(1 + alpha2 * Bfield.z()*Bfield.z() );
1806 LogDebug (
"Pixel Digitizer") <<
" The drift direction in local coordinate is "
1807 << theDriftDirection ;
1810 return theDriftDirection;
1825 int col = ip.second;
1842 Parameters::const_iterator itDeadModules=
DeadModules.begin();
1845 for(; itDeadModules !=
DeadModules.end(); ++itDeadModules){
1846 int Dead_detID = itDeadModules->getParameter<
int>(
"Dead_detID");
1847 if(detid == Dead_detID){
1860 if(Module==
"whole"){
1869 if(Module==
"tbmA" && ip.first>=80 && ip.first<=159){
1873 if( Module==
"tbmB" && ip.first<=79){
1884 std::vector<SiPixelQuality::disabledModuleType>disabledModules =
SiPixelBadModule_->getBadComponentList();
1888 for (
size_t id=0;
id<disabledModules.size();
id++)
1890 if(detID==disabledModules[
id].DetID){
1892 badmodule = disabledModules[id];
1912 std::vector<GlobalPixel> badrocpositions (0);
1913 for(
unsigned int j = 0;
j < 16;
j++){
1916 std::vector<CablingPathToDetUnit>
path =
map_.
product()->pathToDetUnit(detID);
1917 typedef std::vector<CablingPathToDetUnit>::const_iterator
IT;
1918 for (IT it = path.begin(); it != path.end(); ++it) {
1923 badrocpositions.push_back(global);
1934 for(std::vector<GlobalPixel>::const_iterator it = badrocpositions.begin(); it != badrocpositions.end(); ++it){
1935 if(it->row >= 80 && ip.first >= 80 ){
1936 if((fabs(ip.second - it->col) < 26) ) {
i->second.set(0.);}
1937 else if(it->row==120 && ip.second-it->col==26){
i->second.set(0.);}
1938 else if(it->row==119 && it->col-ip.second==26){
i->second.set(0.);}
1940 else if(it->row < 80 && ip.first < 80 ){
1941 if((fabs(ip.second - it->col) < 26) ){
i->second.set(0.);}
1942 else if(it->row==40 && ip.second-it->col==26){
i->second.set(0.);}
1943 else if(it->row==39 && it->col-ip.second==26){
i->second.set(0.);}
int adc(sample_type sample)
get the ADC sample (12 bits)
void init(const edm::EventSetup &es)
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
T getParameter(std::string const &) const
double theOuterEfficiency_FPix[20]
void pixel_inefficiency_db(uint32_t detID)
signal_map_type::const_iterator signal_map_const_iterator
Local3DVector LocalVector
float tof() const
deprecated name for timeOfFlight()
const bool use_deadmodule_DB_
edm::ESHandle< SiPixelFedCablingMap > map_
void init_DynIneffDB(const edm::EventSetup &, const unsigned int &)
const double theThresholdSmearing_FPix
std::map< int, CalParameters, std::less< int > > initCal() const
std::map< unsigned int, std::vector< float >, std::less< unsigned int > > simlink_map
const std::unique_ptr< SiPixelGainCalibrationOfflineSimService > theSiPixelGainCalibrationService_
virtual LocalPoint localPosition(const MeasurementPoint &) const =0
LocalVector DriftDirection(const PixelGeomDetUnit *pixdet, const GlobalVector &bfield, const DetId &detId) const
SiPixelDigitizerAlgorithm(const edm::ParameterSet &conf)
virtual int ncolumns() const =0
const std::vector< float > & getMix_TrueInteractions() const
const float tanLorentzAnglePerTesla_FPix
PixelEfficiencies pixelEfficiencies_
const std::unique_ptr< SiG4UniversalFluctuation > fluctuate
const int theAdcFullScale
PixelEfficiencies(const edm::ParameterSet &conf, bool AddPixelInefficiency, int NumberOfBarrelLayers, int NumberOfEndcapDisks)
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
const std::vector< int > & getMix_bunchCrossing() const
virtual const GeomDetType & type() const override
const double theThresholdSmearing_BPix_L1
unsigned int pxbLadder(const DetId &id) const
bool exists(std::string const ¶meterName) const
checks if a parameter exists
virtual int nrows() const =0
const float theThresholdInE_FPix
const double theThresholdSmearing_BPix
const Bounds & bounds() const
std::vector< std::vector< double > > thePUEfficiency
unsigned int pxbModule(const DetId &id) const
const bool addThresholdSmearing
void module_killing_conf(uint32_t detID)
const bool fluctuateCharge
float thePixelPseudoRadDamage[20]
edm::ESHandle< TrackerGeometry > geom_
~SiPixelDigitizerAlgorithm()
double calcQ(float x) const
const Plane & surface() const
The nominal surface of the GeomDet.
const float GeVperElectron
identify pixel inside single ROC
const bool use_ineff_from_db_
void make_digis(float thePixelThresholdInE, uint32_t detID, const PixelGeomDetUnit *pixdet, std::vector< PixelDigi > &digis, std::vector< PixelDigiSimLink > &simlinks, const TrackerTopology *tTopo) const
static int pixelToChannel(int row, int col)
global coordinates (row and column in DetUnit, as in PixelDigi)
uint32_t rawId() const
get the raw id
virtual float thickness() const =0
void induce_signal(const PSimHit &hit, const size_t hitIndex, const unsigned int tofBin, const PixelGeomDetUnit *pixdet, const std::vector< SignalPoint > &collection_points)
const bool use_LorentzAngle_DB_
Measurement2DPoint MeasurementPoint
Measurement points are two-dimensional by default.
Local3DPoint exitPoint() const
Exit point in the local Det frame.
tuple path
else: Piece not in the list, fine.
float missCalibrate(uint32_t detID, const PixelGeomDetUnit *pixdet, int col, int row, float amp) const
const std::map< int, CalParameters, std::less< int > > calmap
double theInstLumiScaleFactor
const Parameters DeadModules
float pixel_aging(const PixelAging &aging, const PixelGeomDetUnit *pixdet, const TrackerTopology *tTopo) const
double thePixelChipEfficiency[20]
const float theTofUpperCut
const bool use_module_killing_
std::vector< double > pu_scale
void module_killing_DB(uint32_t detID)
static int pixelToChannelROC(const int rowROC, const int colROC)
static std::pair< int, int > channelToPixelROC(const int chan)
unsigned int idInDetUnit() const
id of this ROC in DetUnit etermined by token path
void digitize(const PixelGeomDetUnit *pixdet, std::vector< PixelDigi > &digis, std::vector< PixelDigiSimLink > &simlinks, const TrackerTopology *tTopo, CLHEP::HepRandomEngine *)
Abs< T >::type abs(const T &t)
const float theThresholdInE_BPix
double theInnerEfficiency_FPix[20]
virtual int channel(const LocalPoint &p) const =0
DetId geographicalId() const
The label of this GeomDet.
const int NumberOfEndcapDisks
virtual MeasurementPoint measurementPosition(const LocalPoint &) const =0
std::vector< double > theModuleEfficiency_BPix[20]
std::vector< LinkConnSpec >::const_iterator IT
float pabs() const
fast and more accurate access to momentumAtEntry().mag()
bool isTrackerPixel() const
signal_map_type::iterator signal_map_iterator
int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
const float theThresholdInE_BPix_L1
edm::ESHandle< SiPixelLorentzAngle > SiPixelLorentzAngle_
unsigned int pxfModule(const DetId &id) const
virtual std::pair< float, float > pitch() const =0
void fluctuateEloss(int particleId, float momentum, float eloss, float length, int NumberOfSegments, float elossVector[], CLHEP::HepRandomEngine *) const
const bool doMissCalibrate
const bool AddPixelInefficiency
const bool addChargeVCALSmearing
const std::unique_ptr< GaussianTailNoiseGenerator > theNoiser
const float theNoiseInElectrons
std::map< int, Amplitude, std::less< int > > signal_map_type
const double electronsPerVCAL_Offset
edm::ESHandle< SiPixelQuality > SiPixelBadModule_
void primary_ionization(const PSimHit &hit, std::vector< EnergyDepositUnit > &ionization_points, CLHEP::HepRandomEngine *) const
void init_from_db(const edm::ESHandle< TrackerGeometry > &, const edm::ESHandle< SiPixelDynamicInefficiency > &)
double thePixelColEfficiency[20]
void calculateInstlumiFactor(PileupMixingContent *puInfo)
static std::pair< int, int > channelToPixel(int ch)
virtual const PixelTopology & specificTopology() const
Returns a reference to the pixel proxy topology.
T const * product() const
void accumulateSimHits(const std::vector< PSimHit >::const_iterator inputBegin, const std::vector< PSimHit >::const_iterator inputEnd, const size_t inputBeginGlobalIndex, const unsigned int tofBin, const PixelGeomDetUnit *pixdet, const GlobalVector &bfield, const TrackerTopology *tTopo, CLHEP::HepRandomEngine *)
const int theAdcFullScaleStack
row and collumn in ROC representation
const float tanLorentzAnglePerTesla_BPix
edm::ESHandle< SiPixelDynamicInefficiency > SiPixelDynamicInefficiency_
unsigned int layer(const DetId &id) const
bool matches(const DetId &, const DetId &, const std::vector< uint32_t > &)
std::vector< edm::ParameterSet > Parameters
std::vector< double > theLadderEfficiency_BPix[20]
float energyLoss() const
The energy deposit in the PSimHit, in ???.
const float theReadoutNoise
const double electronsPerVCAL
std::map< uint32_t, double > ColGeomFactors
const RotationType & rotation() const
double thePixelEfficiency[20]
PixelAging(const edm::ParameterSet &conf, bool AddPixelAging, int NumberOfBarrelLayers, int NumberOfEndcapDisks)
const float theTofLowerCut
void drift(const PSimHit &hit, const PixelGeomDetUnit *pixdet, const GlobalVector &bfield, const TrackerTopology *tTopo, const std::vector< EnergyDepositUnit > &ionization_points, std::vector< SignalPoint > &collection_points) const
std::map< uint32_t, double > PixelGeomFactors
std::map< uint32_t, double > ChipGeomFactors
Detector det() const
get the detector field from this detid
virtual SubDetector subDetector() const
Which subdetector.
const bool addNoisyPixels
const PixelAging pixelAging_
const PositionType & position() const
std::map< uint32_t, size_t > iPU
const float theElectronPerADC
Local3DPoint entryPoint() const
Entry point in the local Det frame.
tuple size
Write out results.
unsigned int pxfPanel(const DetId &id) const
const bool makeDigiSimLinks_
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
unsigned int detUnitId() const
const Plane & specificSurface() const
Same as surface(), kept for backward compatibility.
const int NumberOfBarrelLayers
GlobalPixel toGlobal(const LocalPixel &loc) const
void add_noise(const PixelGeomDetUnit *pixdet, float thePixelThreshold, CLHEP::HepRandomEngine *)
void pixel_inefficiency(const PixelEfficiencies &eff, const PixelGeomDetUnit *pixdet, const TrackerTopology *tTopo, CLHEP::HepRandomEngine *)