File indexing completed on 2024-04-06 12:21:52
0001 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0002 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0003 #include "Geometry/CommonTopologies/interface/PixelGeomDetUnit.h"
0004 #include "Geometry/CommonTopologies/interface/PixelTopology.h"
0005 #include "DataFormats/Math/interface/deltaPhi.h"
0006 #include "FWCore/Utilities/interface/Exception.h"
0007
0008 #include "L1Trigger/TrackFindingTMTT/interface/Stub.h"
0009 #include "L1Trigger/TrackFindingTMTT/interface/TP.h"
0010 #include "L1Trigger/TrackFindingTMTT/interface/StubKiller.h"
0011 #include "L1Trigger/TrackFindingTMTT/interface/PrintL1trk.h"
0012
0013 #include <iostream>
0014
0015 using namespace std;
0016
0017 namespace tmtt {
0018
0019
0020
0021 Stub::Stub(const Settings* settings,
0022 unsigned int idStub,
0023 double phi,
0024 double r,
0025 double z,
0026 double bend,
0027 unsigned int iphi,
0028 double alpha,
0029 unsigned int layerId,
0030 unsigned int iPhiSec,
0031 bool psModule,
0032 bool barrel,
0033 bool tiltedBarrel,
0034 float stripPitch,
0035 float stripLength,
0036 unsigned int nStrips)
0037 : index_in_vStubs_(idStub),
0038 phi_(phi),
0039 r_(r),
0040 z_(z),
0041 bend_(bend),
0042 iphi_(iphi),
0043 alpha_(alpha),
0044 digitalStub_(std::make_unique<DigitalStub>(settings, r, phi, z, iPhiSec)),
0045 layerId_(layerId),
0046 layerIdReduced_(TrackerModule::calcLayerIdReduced(layerId)),
0047 stripPitch_(stripPitch),
0048 stripLength_(stripLength),
0049 nStrips_(nStrips),
0050 psModule_(psModule),
0051 barrel_(barrel),
0052 tiltedBarrel_(tiltedBarrel) {}
0053
0054
0055
0056 Stub::Stub(const TTStubRef& ttStubRef,
0057 unsigned int index_in_vStubs,
0058 const Settings* settings,
0059 const TrackerTopology* trackerTopology,
0060 const TrackerModule* trackerModule,
0061 const DegradeBend* degradeBend,
0062 const StubKiller* stubKiller)
0063 : ttStubRef_(ttStubRef),
0064 settings_(settings),
0065 index_in_vStubs_(index_in_vStubs),
0066 assocTP_(nullptr),
0067 lastDigiStep_(Stub::DigiStage::NONE),
0068 digitizeWarningsOn_(true),
0069 trackerModule_(trackerModule),
0070 degradeBend_(degradeBend),
0071
0072 layerId_(trackerModule->layerId()),
0073 layerIdReduced_(trackerModule->layerIdReduced()),
0074 tiltAngle_(trackerModule->tiltAngle()),
0075 stripPitch_(trackerModule->stripPitch()),
0076 stripLength_(trackerModule->stripLength()),
0077 nStrips_(trackerModule->nStrips()),
0078 psModule_(trackerModule->psModule()),
0079 barrel_(trackerModule->barrel()),
0080 tiltedBarrel_(trackerModule->tiltedBarrel()) {
0081
0082 const TTStub<Ref_Phase2TrackerDigi_>* ttStubP = ttStubRef_.get();
0083
0084 const PixelGeomDetUnit* specDet = trackerModule_->specDet();
0085 const PixelTopology* specTopol = trackerModule_->specTopol();
0086 MeasurementPoint measurementPoint = ttStubRef_->clusterRef(0)->findAverageLocalCoordinatesCentered();
0087 LocalPoint clustlp = specTopol->localPosition(measurementPoint);
0088 GlobalPoint pos = specDet->surface().toGlobal(clustlp);
0089
0090 phi_ = pos.phi();
0091 r_ = pos.perp();
0092 z_ = pos.z();
0093
0094
0095
0096 for (unsigned int iClus = 0; iClus <= 1; iClus++) {
0097 localU_cluster_[iClus] = ttStubP->clusterRef(iClus)->findAverageLocalCoordinatesCentered().x();
0098 localV_cluster_[iClus] = ttStubP->clusterRef(iClus)->findAverageLocalCoordinatesCentered().y();
0099 }
0100
0101
0102
0103
0104 iphi_ = localU_cluster_[0];
0105
0106
0107
0108 alpha_ = 0.;
0109 if ((not barrel()) && (not psModule())) {
0110 float fracPosInModule = (float(iphi_) - 0.5 * float(nStrips())) / float(nStrips());
0111 float phiRelToModule = trackerModule_->sensorWidth() * fracPosInModule / r_;
0112 if (z_ < 0)
0113 phiRelToModule *= -1;
0114 if (trackerModule_->outerModuleAtSmallerR())
0115 phiRelToModule *= -1;
0116
0117 alpha_ = -phiRelToModule / r_;
0118 }
0119
0120
0121 this->calcDphiOverBend();
0122
0123
0124
0125 bendInFrontend_ = ttStubRef_->bendFE();
0126 if ((not barrel()) && pos.z() > 0)
0127 bendInFrontend_ *= -1;
0128 if (barrel())
0129 bendInFrontend_ *= -1;
0130
0131
0132
0133 numMergedBend_ = 1;
0134 if (settings->degradeBendRes() == 2) {
0135 float degradedBend;
0136
0137 this->degradeResolution(bendInFrontend_, degradedBend, numMergedBend_);
0138 bend_ = degradedBend;
0139 } else if (settings->degradeBendRes() == 1) {
0140 bend_ = ttStubRef_->bendBE();
0141 if ((not barrel()) && pos.z() > 0)
0142 bend_ *= -1;
0143 if (barrel())
0144 bend_ *= -1;
0145 } else {
0146 bend_ = bendInFrontend_;
0147 }
0148
0149
0150 this->setFrontend(stubKiller);
0151
0152
0153 this->calcQoverPtrange();
0154
0155
0156 for (unsigned int iClus = 0; iClus <= 1; iClus++) {
0157 assocTPofCluster_[iClus] = nullptr;
0158 }
0159 }
0160
0161
0162
0163 void Stub::calcQoverPtrange() {
0164
0165
0166 const int nbinsPt = (int)settings_->houghNbinsPt();
0167 const int min_array_bin = 0;
0168 const int max_array_bin = nbinsPt - 1;
0169
0170 float qOverPtMin = this->qOverPtOverBend() * (this->bend() - this->bendCut());
0171 float qOverPtMax = this->qOverPtOverBend() * (this->bend() + this->bendCut());
0172 int houghNbinsPt = settings_->houghNbinsPt();
0173 const float houghMaxInvPt = 1. / settings_->houghMinPt();
0174 float qOverPtBinSize = (2. * houghMaxInvPt) / houghNbinsPt;
0175 if (settings_->shape() == 2 || settings_->shape() == 1 || settings_->shape() == 3)
0176 qOverPtBinSize = 2. * houghMaxInvPt / (houghNbinsPt - 1);
0177
0178
0179
0180
0181
0182
0183 float tmp = (settings_->shape() == 2 || settings_->shape() == 1 || settings_->shape() == 3) ? 1. : 0.;
0184 int min_bin = std::floor(-tmp + (qOverPtMin + houghMaxInvPt) / qOverPtBinSize);
0185 int max_bin = std::floor(tmp + (qOverPtMax + houghMaxInvPt) / qOverPtBinSize);
0186
0187
0188 min_bin = max(min_bin, min_array_bin);
0189 max_bin = min(max_bin, max_array_bin);
0190
0191
0192 if (min_bin > max_bin) {
0193 min_bin = max_array_bin;
0194 max_bin = min_array_bin;
0195 }
0196 min_qOverPt_bin_ = (unsigned int)min_bin;
0197 max_qOverPt_bin_ = (unsigned int)max_bin;
0198 }
0199
0200
0201
0202
0203 void Stub::digitize(unsigned int iPhiSec, Stub::DigiStage digiStep) {
0204 if (settings_->enableDigitize()) {
0205 bool updated = true;
0206 if (not digitalStub_) {
0207
0208 digitalStub_ =
0209 std::make_unique<DigitalStub>(settings_, phi_, r_, z_, min_qOverPt_bin_, max_qOverPt_bin_, bend_, iPhiSec);
0210 } else {
0211
0212 updated = digitalStub_->changePhiSec(iPhiSec);
0213 }
0214
0215
0216 if (updated || digiStep != lastDigiStep_) {
0217 lastDigiStep_ = digiStep;
0218
0219
0220 if (digiStep == DigiStage::GP) {
0221 phi_ = digitalStub_->phi_GP();
0222 } else {
0223 phi_ = digitalStub_->phi_HT_TF();
0224 }
0225 if (digiStep == DigiStage::GP || digiStep == DigiStage::HT) {
0226 r_ = digitalStub_->r_GP_HT();
0227 } else {
0228 r_ = digitalStub_->r_SF_TF();
0229 }
0230 z_ = digitalStub_->z();
0231 bend_ = digitalStub_->bend();
0232
0233
0234
0235 digitizeWarningsOn_ = false;
0236 if (digiStep == DigiStage::GP)
0237 this->calcDphiOverBend();
0238 if (digiStep == DigiStage::HT)
0239 this->calcQoverPtrange();
0240 digitizeWarningsOn_ = true;
0241 }
0242 }
0243 }
0244
0245
0246
0247
0248 void Stub::degradeResolution(float bend, float& degradedBend, unsigned int& num) const {
0249
0250 float windowFE;
0251 if (settings_->killLowPtStubs()) {
0252
0253 float invPtMax = 1. / (settings_->houghMinPt());
0254 windowFE = invPtMax / std::abs(this->qOverPtOverBend());
0255
0256 windowFE += this->bendCutInFrontend();
0257 } else {
0258 windowFE = rejectedStubBend_;
0259 }
0260
0261 degradeBend_->degrade(bend, psModule(), trackerModule_->detId(), windowFE, degradedBend, num);
0262 }
0263
0264
0265
0266
0267 void Stub::setFrontend(const StubKiller* stubKiller) {
0268 frontendPass_ = true;
0269 stubFailedDegradeWindow_ = false;
0270
0271 if (std::abs(this->eta()) > settings_->maxStubEta())
0272 frontendPass_ = false;
0273
0274 const float qOverPtCut = 1. / settings_->houghMinPt();
0275 if (settings_->killLowPtStubs()) {
0276
0277 if (std::abs(this->bendInFrontend()) - this->bendCutInFrontend() > qOverPtCut / this->qOverPtOverBend())
0278 frontendPass_ = false;
0279 }
0280
0281 if (frontendPass_ && this->bend() == rejectedStubBend_) {
0282 throw cms::Exception(
0283 "BadConfig: FE stub bend window sizes provided in cfg ES source are tighter than those to make the stubs. "
0284 "Please fix them");
0285 }
0286
0287 if (settings_->killLowPtStubs()) {
0288
0289
0290 if (std::abs(this->bend()) - this->bendCut() > qOverPtCut / this->qOverPtOverBend())
0291 frontendPass_ = false;
0292 }
0293
0294
0295 StubKiller::KillOptions killScenario = static_cast<StubKiller::KillOptions>(settings_->killScenario());
0296 if (killScenario != StubKiller::KillOptions::none) {
0297 bool kill = stubKiller->killStub(ttStubRef_.get());
0298 if (kill)
0299 frontendPass_ = false;
0300 }
0301 }
0302
0303
0304 double Stub::approxB() {
0305 if (tiltedBarrel()) {
0306 return settings_->bApprox_gradient() * std::abs(z_) / r_ + settings_->bApprox_intercept();
0307 } else {
0308 return barrel() ? 1 : std::abs(z_) / r_;
0309 }
0310 }
0311
0312
0313
0314 void Stub::calcDphiOverBend() {
0315
0316 if (settings_->useApproxB()) {
0317 float dphiOverBendCorrection_approx_ = approxB();
0318 dphiOverBend_ = trackerModule_->pitchOverSep() * dphiOverBendCorrection_approx_;
0319 } else {
0320 float dphiOverBendCorrection_ = std::abs(cos(this->theta() - trackerModule_->tiltAngle()) / sin(this->theta()));
0321 dphiOverBend_ = trackerModule_->pitchOverSep() * dphiOverBendCorrection_;
0322 }
0323 }
0324
0325
0326
0327
0328 void Stub::fillTruth(const map<edm::Ptr<TrackingParticle>, const TP*>& translateTP,
0329 const edm::Handle<TTStubAssMap>& mcTruthTTStubHandle,
0330 const edm::Handle<TTClusterAssMap>& mcTruthTTClusterHandle) {
0331
0332
0333 bool genuine = mcTruthTTStubHandle->isGenuine(ttStubRef_);
0334 assocTP_ = nullptr;
0335
0336
0337 if (genuine) {
0338 edm::Ptr<TrackingParticle> tpPtr = mcTruthTTStubHandle->findTrackingParticlePtr(ttStubRef_);
0339 if (translateTP.find(tpPtr) != translateTP.end()) {
0340 assocTP_ = translateTP.at(tpPtr);
0341
0342 }
0343 }
0344
0345
0346
0347 if (settings_->stubMatchStrict()) {
0348
0349 if (assocTP_ != nullptr)
0350 assocTPs_.insert(assocTP_);
0351
0352 } else {
0353
0354
0355 for (unsigned int iClus = 0; iClus <= 1; iClus++) {
0356 const TTClusterRef& ttClusterRef = ttStubRef_->clusterRef(iClus);
0357
0358
0359 vector<edm::Ptr<TrackingParticle> > vecTpPtr = mcTruthTTClusterHandle->findTrackingParticlePtrs(ttClusterRef);
0360
0361 for (const edm::Ptr<TrackingParticle>& tpPtr : vecTpPtr) {
0362 if (translateTP.find(tpPtr) != translateTP.end()) {
0363 assocTPs_.insert(translateTP.at(tpPtr));
0364
0365 }
0366 }
0367 }
0368 }
0369
0370
0371
0372 for (unsigned int iClus = 0; iClus <= 1; iClus++) {
0373 const TTClusterRef& ttClusterRef = ttStubRef_->clusterRef(iClus);
0374
0375 bool genuineCluster = mcTruthTTClusterHandle->isGenuine(ttClusterRef);
0376 assocTPofCluster_[iClus] = nullptr;
0377
0378
0379 if (genuineCluster) {
0380 edm::Ptr<TrackingParticle> tpPtr = mcTruthTTClusterHandle->findTrackingParticlePtr(ttClusterRef);
0381
0382 if (translateTP.find(tpPtr) != translateTP.end()) {
0383 assocTPofCluster_[iClus] = translateTP.at(tpPtr);
0384
0385 }
0386 }
0387 }
0388 }
0389 }