Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:21:52

0001 #include "SimTracker/Common/interface/TrackingParticleSelector.h"
0002 #include "L1Trigger/TrackFindingTMTT/interface/TP.h"
0003 #include "L1Trigger/TrackFindingTMTT/interface/Stub.h"
0004 #include "L1Trigger/TrackFindingTMTT/interface/Settings.h"
0005 #include "L1Trigger/TrackFindingTMTT/interface/Utility.h"
0006 #include "DataFormats/Math/interface/deltaR.h"
0007 
0008 #include <array>
0009 
0010 using namespace std;
0011 
0012 namespace tmtt {
0013 
0014   //=== Store useful info about this tracking particle
0015 
0016   TP::TP(const TrackingParticlePtr& tpPtr, unsigned int index_in_vTPs, const Settings* settings)
0017       : trackingParticlePtr_(tpPtr),
0018         index_in_vTPs_(index_in_vTPs),
0019         settings_(settings),
0020         pdgId_(tpPtr->pdgId()),
0021         charge_(tpPtr->charge()),
0022         mass_(tpPtr->mass()),
0023         pt_(tpPtr->pt()),
0024         eta_(tpPtr->eta()),
0025         theta_(tpPtr->theta()),
0026         tanLambda_(1. / tan(theta_)),
0027         phi0_(tpPtr->phi()),
0028         vx_(tpPtr->vertex().x()),
0029         vy_(tpPtr->vertex().y()),
0030         vz_(tpPtr->vertex().z()),
0031         d0_(vx_ * sin(phi0_) - vy_ * cos(phi0_)),                      // Copied from CMSSW class TrackBase::d0().
0032         z0_(vz_ - (vx_ * cos(phi0_) + vy_ * sin(phi0_)) * tanLambda_)  // Copied from CMSSW class TrackBase::dz().
0033   {
0034     const vector<SimTrack>& vst = tpPtr->g4Tracks();
0035     EncodedEventId eid = vst.at(0).eventId();
0036     inTimeBx_ = (eid.bunchCrossing() == 0);  // TP from in-time or out-of-time Bx.
0037     physicsCollision_ = (eid.event() == 0);  // TP from physics collision or from pileup.
0038 
0039     this->fillUse();        // Fill use_ flag, indicating if TP is worth keeping.
0040     this->fillUseForEff();  // Fill useForEff_ flag, indicating if TP is good for tracking efficiency measurement.
0041   }
0042 
0043   //=== Fill truth info with association from tracking particle to stubs.
0044 
0045   void TP::fillTruth(const list<Stub>& vStubs) {
0046     for (const Stub& s : vStubs) {
0047       for (const TP* tp_i : s.assocTPs()) {
0048         if (tp_i->index() == this->index())
0049           assocStubs_.push_back(&s);
0050       }
0051     }
0052 
0053     this->fillUseForAlgEff();  // Fill useForAlgEff_ flag.
0054 
0055     this->calcNumLayers();  // Calculate number of tracker layers this TP has stubs in.
0056   }
0057 
0058   //=== Check if this tracking particle is worth keeping.
0059   //=== (i.e. If there is the slightest chance of reconstructing it, so as to measure fake rate).
0060 
0061   void TP::fillUse() {
0062     constexpr bool useOnlyInTimeParticles = false;
0063     constexpr bool useOnlyTPfromPhysicsCollisionFalse = false;
0064     // Use looser cuts here those those used for tracking efficiency measurement.
0065     // Keep only those TP that have a chance (allowing for finite track resolution) of being reconstructed as L1 tracks. L1 tracks not matching these TP will be defined as fake.
0066 
0067     // Include all possible particle types here, as if some are left out, L1 tracks matching one of missing types will be declared fake.
0068     constexpr std::array<int, 5> genPdgIdsAllUnsigned = {{11, 13, 211, 321, 2212}};
0069     vector<int> genPdgIdsAll;
0070     for (const int& iPdg : genPdgIdsAllUnsigned) {
0071       genPdgIdsAll.push_back(iPdg);
0072       genPdgIdsAll.push_back(-iPdg);
0073     }
0074 
0075     // Range big enough to include all TP needed to measure tracking efficiency
0076     // and big enough to include any TP that might be reconstructed for fake rate measurement.
0077     constexpr float ptMinScale = 0.7;
0078     const float ptMin = min(settings_->genMinPt(), ptMinScale * settings_->houghMinPt());
0079     constexpr double ptMax = 9.9e9;
0080     const float etaExtra = 0.2;
0081     const float etaMax = max(settings_->genMaxAbsEta(), etaExtra + std::abs(settings_->etaRegions()[0]));
0082     constexpr double fixedVertRcut = 10.;
0083     constexpr double fixedVertZcut = 35.;
0084 
0085     static const TrackingParticleSelector trackingParticleSelector(ptMin,
0086                                                                    ptMax,
0087                                                                    -etaMax,
0088                                                                    etaMax,
0089                                                                    max(fixedVertRcut, settings_->genMaxVertR()),
0090                                                                    max(fixedVertZcut, settings_->genMaxVertZ()),
0091                                                                    0,
0092                                                                    useOnlyTPfromPhysicsCollisionFalse,
0093                                                                    useOnlyInTimeParticles,
0094                                                                    true,
0095                                                                    false,
0096                                                                    genPdgIdsAll);
0097 
0098     use_ = trackingParticleSelector(*trackingParticlePtr_);
0099   }
0100 
0101   //=== Check if this tracking particle can be used to measure the L1 tracking efficiency.
0102 
0103   void TP::fillUseForEff() {
0104     useForEff_ = false;
0105     if (use_) {
0106       constexpr bool useOnlyInTimeParticles = true;
0107       constexpr bool useOnlyTPfromPhysicsCollision = true;
0108       constexpr double ptMax = 9.9e9;
0109       static const TrackingParticleSelector trackingParticleSelector(settings_->genMinPt(),
0110                                                                      ptMax,
0111                                                                      -settings_->genMaxAbsEta(),
0112                                                                      settings_->genMaxAbsEta(),
0113                                                                      settings_->genMaxVertR(),
0114                                                                      settings_->genMaxVertZ(),
0115                                                                      0,
0116                                                                      useOnlyTPfromPhysicsCollision,
0117                                                                      useOnlyInTimeParticles,
0118                                                                      true,
0119                                                                      false,
0120                                                                      settings_->genPdgIds());
0121 
0122       useForEff_ = trackingParticleSelector(*trackingParticlePtr_);
0123 
0124       // Add additional cut on particle transverse impact parameter.
0125       if (std::abs(d0_) > settings_->genMaxD0())
0126         useForEff_ = false;
0127       if (std::abs(z0_) > settings_->genMaxZ0())
0128         useForEff_ = false;
0129     }
0130   }
0131 
0132   //=== Check if this tracking particle can be used to measure the L1 tracking algorithmic efficiency (makes stubs in enough layers).
0133 
0134   void TP::fillUseForAlgEff() {
0135     useForAlgEff_ = false;
0136     if (useForEff_) {
0137       useForAlgEff_ = (Utility::countLayers(settings_, assocStubs_, true) >= settings_->genMinStubLayers());
0138     }
0139   }
0140 
0141   //== Estimated phi angle at which TP trajectory crosses the module containing the stub.
0142 
0143   float TP::trkPhiAtStub(const Stub* stub) const {
0144     float trkPhi = phi0_ - this->dphi(this->trkRAtStub(stub));
0145     return trkPhi;
0146   }
0147 
0148   //== Estimated r coord. at which TP trajectory crosses the module containing the given stub.
0149   //== Only works for modules orientated parallel or perpendicular to beam-axis,
0150   //== and makes the approximation that tracks are straight-lines in r-z plane.
0151 
0152   float TP::trkRAtStub(const Stub* stub) const {
0153     float rTrk = (stub->barrel()) ? stub->r() : (stub->z() - z0_) / tanLambda_;
0154     return rTrk;
0155   }
0156 
0157   //== Estimated z coord. at which TP trajectory crosses the module containing the given stub.
0158   //== Only works for modules orientated parallel or perpendicular to beam-axis,
0159   //== and makes the approximation that tracks are straight-lines in r-z plane.
0160 
0161   float TP::trkZAtStub(const Stub* stub) const {
0162     float zTrk = (stub->barrel()) ? z0_ + tanLambda_ * stub->r() : stub->z();
0163     return zTrk;
0164   }
0165 
0166   void TP::fillNearestJetInfo(const reco::GenJetCollection* genJets) {
0167     double minDR = 999.;
0168     double ptOfNearestJet = -1;
0169 
0170     reco::GenJetCollection::const_iterator iterGenJet;
0171     for (iterGenJet = genJets->begin(); iterGenJet != genJets->end(); ++iterGenJet) {
0172       reco::GenJet myJet = reco::GenJet(*iterGenJet);
0173 
0174       // Don't consider GenJets failing these cuts.
0175       constexpr float minPt = 30.0;
0176       constexpr float maxEta = 2.5;
0177 
0178       if (myJet.pt() > minPt && std::abs(myJet.eta()) > maxEta) {
0179         double deltaR = reco::deltaR(this->eta(), this->phi0(), myJet.eta(), myJet.phi());
0180 
0181         if (deltaR < minDR) {
0182           minDR = deltaR;
0183           ptOfNearestJet = myJet.pt();
0184         }
0185       }
0186     }
0187 
0188     // Only consider GenJets within this distance of TP.
0189     constexpr float cutDR = 0.4;
0190     tpInJet_ = (minDR < cutDR);
0191     nearestJetPt_ = tpInJet_ ? ptOfNearestJet : -1.;
0192   }
0193 
0194 }  // namespace tmtt