File indexing completed on 2024-05-22 04:03:19
0001
0002
0003
0004
0005
0006
0007
0008 #include "Geometry/CommonDetUnit/interface/PixelGeomDetUnit.h"
0009 #include "RecoLocalTracker/SiPixelRecHits/interface/PixelCPEBase.h"
0010
0011 #define CORRECT_FOR_BIG_PIXELS
0012
0013
0014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0015
0016
0017 #include "MagneticField/Engine/interface/MagneticField.h"
0018
0019 #include <iostream>
0020
0021 using namespace std;
0022
0023
0024
0025
0026
0027 PixelCPEBase::PixelCPEBase(edm::ParameterSet const& conf,
0028 const MagneticField* mag,
0029 const TrackerGeometry& geom,
0030 const TrackerTopology& ttopo,
0031 const SiPixelLorentzAngle* lorentzAngle,
0032 const SiPixelGenErrorDBObject* genErrorDBObject,
0033 const SiPixelTemplateDBObject* templateDBobject,
0034 const SiPixelLorentzAngle* lorentzAngleWidth,
0035 int flag)
0036
0037 : useLAOffsetFromConfig_(false),
0038 useLAWidthFromConfig_(false),
0039 useLAWidthFromDB_(false),
0040 theFlag_(flag),
0041 magfield_(mag),
0042 geom_(geom),
0043 ttopo_(ttopo) {
0044 #ifdef EDM_ML_DEBUG
0045 nRecHitsTotal_ = 0;
0046 nRecHitsUsedEdge_ = 0,
0047 #endif
0048
0049
0050 lorentzAngle_ = lorentzAngle;
0051 lorentzAngleWidth_ = lorentzAngleWidth;
0052
0053
0054 genErrorDBObject_ = genErrorDBObject;
0055
0056
0057 if (theFlag_ != 0)
0058 templateDBobject_ = templateDBobject;
0059
0060
0061
0062
0063
0064 LoadTemplatesFromDB_ = conf.getParameter<bool>("LoadTemplatesFromDB");
0065
0066
0067 theVerboseLevel = conf.getUntrackedParameter<int>("VerboseLevel", 0);
0068
0069
0070 alpha2Order = conf.getParameter<bool>("Alpha2Order");
0071
0072
0073
0074
0075
0076
0077
0078 clusterProbComputationFlag_ = (unsigned int)conf.getParameter<int>("ClusterProbComputationFlag");
0079
0080
0081
0082
0083
0084
0085 useLAWidthFromDB_ = conf.getParameter<bool>("useLAWidthFromDB");
0086
0087
0088
0089
0090
0091
0092
0093 lAOffset_ = conf.getParameter<double>("lAOffset");
0094 lAWidthBPix_ = conf.getParameter<double>("lAWidthBPix");
0095 lAWidthFPix_ = conf.getParameter<double>("lAWidthFPix");
0096
0097
0098 if (lAOffset_ > 0.0)
0099 useLAOffsetFromConfig_ = true;
0100
0101 if (lAWidthBPix_ > 0.0 || lAWidthFPix_ > 0.0)
0102 useLAWidthFromConfig_ = true;
0103
0104
0105
0106 doLorentzFromAlignment_ = conf.getParameter<bool>("doLorentzFromAlignment");
0107 useLAFromDB_ = conf.getParameter<bool>("useLAFromDB");
0108
0109 LogDebug("PixelCPEBase") << " LA constants - " << lAOffset_ << " " << lAWidthBPix_ << " " << lAWidthFPix_
0110 << endl;
0111
0112 fillDetParams();
0113 }
0114
0115
0116
0117
0118 void PixelCPEBase::fillDetParams() {
0119
0120
0121
0122 auto const& dus = geom_.detUnits();
0123 unsigned m_detectors = dus.size();
0124 for (unsigned int i = 1; i < 7; ++i) {
0125 LogDebug("PixelCPEBase:: LookingForFirstStrip")
0126 << "Subdetector " << i << " GeomDetEnumerator " << GeomDetEnumerators::tkDetEnum[i] << " offset "
0127 << geom_.offsetDU(GeomDetEnumerators::tkDetEnum[i]) << " is it strip? "
0128 << (geom_.offsetDU(GeomDetEnumerators::tkDetEnum[i]) != dus.size()
0129 ? dus[geom_.offsetDU(GeomDetEnumerators::tkDetEnum[i])]->type().isOuterTracker()
0130 : false);
0131
0132 if (geom_.offsetDU(GeomDetEnumerators::tkDetEnum[i]) != dus.size() &&
0133 dus[geom_.offsetDU(GeomDetEnumerators::tkDetEnum[i])]->type().isOuterTracker()) {
0134 if (geom_.offsetDU(GeomDetEnumerators::tkDetEnum[i]) < m_detectors) {
0135 m_detectors = geom_.offsetDU(GeomDetEnumerators::tkDetEnum[i]);
0136 }
0137 }
0138 }
0139 LogDebug("LookingForFirstStrip") << " Chosen offset: " << m_detectors;
0140
0141 m_DetParams.resize(m_detectors);
0142 LogDebug("PixelCPEBase::fillDetParams():") << "caching " << m_detectors << " pixel detectors" << endl;
0143 for (unsigned i = 0; i != m_detectors; ++i) {
0144 auto& p = m_DetParams[i];
0145 p.theDet = dynamic_cast<const PixelGeomDetUnit*>(dus[i]);
0146 assert(p.theDet);
0147 assert(p.theDet->index() == int(i));
0148
0149 p.theOrigin = p.theDet->surface().toLocal(GlobalPoint(0, 0, 0));
0150
0151
0152 p.thePart = p.theDet->type().subDetector();
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163 p.theThickness = p.theDet->surface().bounds().thickness();
0164
0165
0166
0167 if (theFlag_ == 0) {
0168 if (LoadTemplatesFromDB_)
0169 p.detTemplateId = genErrorDBObject_->getGenErrorID(p.theDet->geographicalId().rawId());
0170 } else {
0171 p.detTemplateId = templateDBobject_->getTemplateID(p.theDet->geographicalId());
0172 }
0173
0174 auto topol = &(p.theDet->specificTopology());
0175 p.theTopol = topol;
0176
0177
0178 std::pair<float, float> pitchxy = p.theTopol->pitch();
0179 p.thePitchX = pitchxy.first;
0180 p.thePitchY = pitchxy.second;
0181
0182 LocalVector Bfield = p.theDet->surface().toLocal(magfield_->inTesla(p.theDet->surface().position()));
0183 p.bz = Bfield.z();
0184 p.bx = Bfield.x();
0185
0186
0187 if ((theFlag_ == 0) || useLAFromDB_ ||
0188 doLorentzFromAlignment_) {
0189 p.driftDirection = driftDirection(p, Bfield);
0190 computeLorentzShifts(p);
0191 }
0192
0193 LogDebug("PixelCPEBase::fillDetParams()") << "***** PIXEL LAYOUT *****"
0194 << " thePart = " << p.thePart << " theThickness = " << p.theThickness
0195 << " thePitchX = " << p.thePitchX << " thePitchY = " << p.thePitchY;
0196
0197 }
0198 }
0199
0200
0201
0202
0203 void PixelCPEBase::setTheClu(DetParam const& theDetParam, ClusterParam& theClusterParam) const {
0204
0205 int minInX, minInY, maxInX, maxInY = 0;
0206 minInX = theClusterParam.theCluster->minPixelRow();
0207 minInY = theClusterParam.theCluster->minPixelCol();
0208 maxInX = theClusterParam.theCluster->maxPixelRow();
0209 maxInY = theClusterParam.theCluster->maxPixelCol();
0210
0211 int min_row(0), min_col(0);
0212 int max_row = theDetParam.theTopol->nrows() - 1;
0213 int max_col = theDetParam.theTopol->ncolumns() - 1;
0214
0215 if (minInX == min_row)
0216 theClusterParam.edgeTypeX_ = 1;
0217 else if (maxInX == max_row)
0218 theClusterParam.edgeTypeX_ = 2;
0219 else
0220 theClusterParam.edgeTypeX_ = 0;
0221
0222 if (minInY == min_col)
0223 theClusterParam.edgeTypeY_ = 1;
0224 else if (maxInY == max_col)
0225 theClusterParam.edgeTypeY_ = 2;
0226 else
0227 theClusterParam.edgeTypeY_ = 0;
0228
0229 theClusterParam.isOnEdge_ = (theClusterParam.edgeTypeX_ || theClusterParam.edgeTypeY_);
0230
0231
0232
0233
0234
0235
0236
0237
0238 theClusterParam.spansTwoROCs_ = theDetParam.theTopol->containsBigPixelInX(minInX, maxInX) ||
0239 theDetParam.theTopol->containsBigPixelInY(minInY, maxInY);
0240 }
0241
0242
0243
0244
0245
0246 void PixelCPEBase::computeAnglesFromTrajectory(DetParam const& theDetParam,
0247 ClusterParam& theClusterParam,
0248 const LocalTrajectoryParameters& ltp) const {
0249 theClusterParam.cotalpha = ltp.dxdz();
0250 theClusterParam.cotbeta = ltp.dydz();
0251
0252 LocalPoint trk_lp = ltp.position();
0253 theClusterParam.trk_lp_x = trk_lp.x();
0254 theClusterParam.trk_lp_y = trk_lp.y();
0255
0256 theClusterParam.with_track_angle = true;
0257
0258
0259 theClusterParam.loc_trk_pred = Topology::LocalTrackPred(
0260 theClusterParam.trk_lp_x, theClusterParam.trk_lp_y, theClusterParam.cotalpha, theClusterParam.cotbeta);
0261 }
0262
0263
0264
0265
0266
0267
0268
0269
0270
0271
0272
0273
0274
0275
0276
0277
0278
0279
0280 void PixelCPEBase::computeAnglesFromDetPosition(DetParam const& theDetParam, ClusterParam& theClusterParam) const {
0281 LocalPoint lp = theDetParam.theTopol->localPosition(
0282 MeasurementPoint(theClusterParam.theCluster->x(), theClusterParam.theCluster->y()));
0283 auto gvx = lp.x() - theDetParam.theOrigin.x();
0284 auto gvy = lp.y() - theDetParam.theOrigin.y();
0285 auto gvz = -1.f / theDetParam.theOrigin.z();
0286
0287
0288
0289
0290
0291 theClusterParam.cotalpha = gvx * gvz;
0292 theClusterParam.cotbeta = gvy * gvz;
0293
0294 theClusterParam.with_track_angle = false;
0295
0296
0297
0298
0299
0300
0301
0302
0303
0304
0305
0306
0307
0308 }
0309
0310
0311 PixelCPEBase::DetParam const& PixelCPEBase::detParam(const GeomDetUnit& det) const {
0312 auto i = det.index();
0313
0314 assert(i < int(m_DetParams.size()));
0315
0316 const DetParam& p = m_DetParams[i];
0317 return p;
0318 }
0319
0320
0321
0322
0323
0324
0325
0326
0327 LocalVector PixelCPEBase::driftDirection(DetParam& theDetParam, GlobalVector bfield) const {
0328 Frame detFrame(theDetParam.theDet->surface().position(), theDetParam.theDet->surface().rotation());
0329 LocalVector Bfield = detFrame.toLocal(bfield);
0330 return driftDirection(theDetParam, Bfield);
0331 }
0332
0333 LocalVector PixelCPEBase::driftDirection(DetParam& theDetParam, LocalVector Bfield) const {
0334
0335 float langle = 0.;
0336 if (!useLAOffsetFromConfig_) {
0337 if (lorentzAngle_ != nullptr) {
0338 langle = lorentzAngle_->getLorentzAngle(theDetParam.theDet->geographicalId().rawId());
0339 LogDebug("PixelCPEBase::driftDirection()")
0340 << " la " << langle << " " << theDetParam.theDet->geographicalId().rawId() << endl;
0341 } else {
0342 langle = 0;
0343 LogDebug("PixelCPEBase::driftDirection()") << " LA object is NULL, assume LA = 0" << endl;
0344 }
0345 LogDebug("PixelCPEBase::driftDirection()") << " Will use LA Offset from DB " << langle << endl;
0346 } else {
0347 langle = lAOffset_;
0348 LogDebug("PixelCPEBase::driftDirection()") << " Will use LA Offset from config " << langle << endl;
0349 }
0350
0351
0352 theDetParam.widthLAFractionX = 1.;
0353 theDetParam.widthLAFractionY = 1.;
0354
0355
0356 if (theFlag_ == 0) {
0357 if (useLAWidthFromDB_ && (lorentzAngleWidth_ != nullptr)) {
0358
0359
0360 auto langleWidth = lorentzAngleWidth_->getLorentzAngle(theDetParam.theDet->geographicalId().rawId());
0361 if (langleWidth != 0.0)
0362 theDetParam.widthLAFractionX = std::abs(langleWidth / langle);
0363
0364
0365
0366 } else if (useLAWidthFromConfig_) {
0367
0368 double lAWidth = 0;
0369 if (GeomDetEnumerators::isTrackerPixel(theDetParam.thePart) && GeomDetEnumerators::isBarrel(theDetParam.thePart))
0370 lAWidth = lAWidthBPix_;
0371 else
0372 lAWidth = lAWidthFPix_;
0373
0374 if (langle != 0.0)
0375 theDetParam.widthLAFractionX = std::abs(lAWidth / langle);
0376
0377
0378
0379
0380 } else {
0381
0382
0383 }
0384
0385
0386
0387 }
0388
0389 float alpha2 = alpha2Order ? langle * langle : 0;
0390
0391
0392
0393
0394
0395
0396
0397
0398 float dir_x = -(langle * Bfield.y() + alpha2 * Bfield.z() * Bfield.x());
0399 float dir_y = (langle * Bfield.x() - alpha2 * Bfield.z() * Bfield.y());
0400 float dir_z = -(1.f + alpha2 * Bfield.z() * Bfield.z());
0401 auto scale = 1.f / std::abs(dir_z);
0402 LocalVector dd(dir_x * scale, dir_y * scale, -1.f);
0403
0404 LogDebug("PixelCPEBase") << " The drift direction in local coordinate is " << dd;
0405
0406 return dd;
0407 }
0408
0409
0410
0411
0412 void PixelCPEBase::computeLorentzShifts(DetParam& theDetParam) const {
0413
0414 theDetParam.lorentzShiftInCmX =
0415 theDetParam.driftDirection.x() / theDetParam.driftDirection.z() * theDetParam.theThickness;
0416 theDetParam.lorentzShiftInCmY =
0417 theDetParam.driftDirection.y() / theDetParam.driftDirection.z() * theDetParam.theThickness;
0418
0419 LogDebug("PixelCPEBase::computeLorentzShifts()")
0420 << " lorentzShiftsInCmX,Y = " << theDetParam.lorentzShiftInCmX << " " << theDetParam.lorentzShiftInCmY << " "
0421 << theDetParam.driftDirection;
0422 }
0423
0424
0425
0426
0427
0428
0429
0430 SiPixelRecHitQuality::QualWordType PixelCPEBase::rawQualityWord(ClusterParam& theClusterParam) const {
0431 SiPixelRecHitQuality::QualWordType qualWord(0);
0432 if (theClusterParam.hasFilledProb_) {
0433 float probabilityXY = 0;
0434 if (theClusterParam.filled_from_2d)
0435 probabilityXY = theClusterParam.probabilityX_;
0436 else if (theClusterParam.probabilityX_ != 0 && theClusterParam.probabilityY_ != 0)
0437 probabilityXY = theClusterParam.probabilityX_ * theClusterParam.probabilityY_ *
0438 (1.f - std::log(theClusterParam.probabilityX_ * theClusterParam.probabilityY_));
0439 SiPixelRecHitQuality::thePacking.setProbabilityXY(probabilityXY, qualWord);
0440
0441 SiPixelRecHitQuality::thePacking.setProbabilityQ(theClusterParam.probabilityQ_, qualWord);
0442 }
0443 SiPixelRecHitQuality::thePacking.setQBin(theClusterParam.qBin_, qualWord);
0444
0445 SiPixelRecHitQuality::thePacking.setIsOnEdge(theClusterParam.isOnEdge_, qualWord);
0446
0447 SiPixelRecHitQuality::thePacking.setHasBadPixels(theClusterParam.hasBadPixels_, qualWord);
0448
0449 SiPixelRecHitQuality::thePacking.setSpansTwoROCs(theClusterParam.spansTwoROCs_, qualWord);
0450
0451 SiPixelRecHitQuality::thePacking.setHasFilledProb(theClusterParam.hasFilledProb_, qualWord);
0452
0453 return qualWord;
0454 }
0455
0456 void PixelCPEBase::fillPSetDescription(edm::ParameterSetDescription& desc) {
0457 desc.add<bool>("LoadTemplatesFromDB", true);
0458 desc.add<bool>("Alpha2Order", true);
0459 desc.add<int>("ClusterProbComputationFlag", 0);
0460 desc.add<bool>("useLAWidthFromDB", true);
0461 desc.add<double>("lAOffset", 0.0);
0462 desc.add<double>("lAWidthBPix", 0.0);
0463 desc.add<double>("lAWidthFPix", 0.0);
0464 desc.add<bool>("doLorentzFromAlignment", false);
0465 desc.add<bool>("useLAFromDB", true);
0466 }