Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:30:42

0001 #ifndef L1Trigger_TrackFindingTMTT_Stub_h
0002 #define L1Trigger_TrackFindingTMTT_Stub_h
0003 
0004 #include "DataFormats/L1TrackTrigger/interface/TTTypes.h"
0005 #include "DataFormats/L1TrackTrigger/interface/TTStub.h"
0006 #include "DataFormats/Phase2TrackerDigi/interface/Phase2TrackerDigi.h"
0007 #include "SimTracker/TrackTriggerAssociation/interface/TTStubAssociationMap.h"
0008 #include "DataFormats/DetId/interface/DetId.h"
0009 #include "DataFormats/Common/interface/Ref.h"
0010 #include "DataFormats/Common/interface/DetSetVector.h"
0011 #include "FWCore/Framework/interface/Frameworkfwd.h"
0012 
0013 #include "L1Trigger/TrackFindingTMTT/interface/Settings.h"
0014 #include "L1Trigger/TrackFindingTMTT/interface/DigitalStub.h"
0015 #include "L1Trigger/TrackFindingTMTT/interface/DegradeBend.h"
0016 #include "L1Trigger/TrackFindingTMTT/interface/TrackerModule.h"
0017 
0018 #include <vector>
0019 #include <set>
0020 #include <array>
0021 #include <map>
0022 #include <memory>
0023 
0024 class TrackerGeometry;
0025 class TrackerTopology;
0026 
0027 namespace tmtt {
0028 
0029   class TP;
0030   class DegradeBend;
0031   class StubKiller;
0032 
0033   typedef edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_> > TTStubDetSetVec;
0034   typedef edmNew::DetSet<TTStub<Ref_Phase2TrackerDigi_> > TTStubDetSet;
0035   typedef edm::Ref<TTStubDetSetVec, TTStub<Ref_Phase2TrackerDigi_> > TTStubRef;
0036   typedef edm::Ref<edmNew::DetSetVector<TTCluster<Ref_Phase2TrackerDigi_> >, TTCluster<Ref_Phase2TrackerDigi_> >
0037       TTClusterRef;
0038   typedef TTStubAssociationMap<Ref_Phase2TrackerDigi_> TTStubAssMap;
0039   typedef TTClusterAssociationMap<Ref_Phase2TrackerDigi_> TTClusterAssMap;
0040 
0041   //=== Represents a Tracker stub (=pair of hits)
0042 
0043   class Stub {
0044   public:
0045     // Hybrid L1 tracking: stub constructor.
0046     Stub(const Settings* settings,
0047          unsigned int idStub,
0048          double phi,
0049          double r,
0050          double z,
0051          double bend,
0052          unsigned int iphi,
0053          double alpha,
0054          unsigned int layerId,
0055          unsigned int iPhiSec,
0056          bool psModule,
0057          bool barrel,
0058          bool tiltedBarrel,
0059          float stripPitch,
0060          float stripLength,
0061          unsigned int nStrips);
0062 
0063     // TMTT L1 tracking: stub constructor.
0064     Stub(const TTStubRef& ttStubRef,
0065          unsigned int index_in_vStubs,
0066          const Settings* settings,
0067          const TrackerTopology* trackerTopology,
0068          const TrackerModule* trackerModule,
0069          const DegradeBend* degradeBend,
0070          const StubKiller* stubKiller);
0071 
0072     bool operator==(const Stub& stubOther) { return (this->index() == stubOther.index()); }
0073 
0074     // Return reference to original TTStub.
0075     const TTStubRef& ttStubRef() const { return ttStubRef_; }
0076 
0077     // Info about tracker module containing stub.
0078     const TrackerModule* trackerModule() const { return trackerModule_; }
0079 
0080     // Fill truth info with association from stub to tracking particles.
0081     void fillTruth(const std::map<edm::Ptr<TrackingParticle>, const TP*>& translateTP,
0082                    const edm::Handle<TTStubAssMap>& mcTruthTTStubHandle,
0083                    const edm::Handle<TTClusterAssMap>& mcTruthTTClusterHandle);
0084 
0085     // Calculate HT m-bin range consistent with bend.
0086     void calcQoverPtrange();
0087 
0088     // Digitize stub for input to GP, HT, SF, TF
0089     enum class DigiStage { NONE, GP, HT, SF, TF };
0090     void digitize(unsigned int iPhiSec, DigiStage digiStep);
0091 
0092     // Control warning messages about accessing non-digitized quantities.
0093     void setDigitizeWarningsOn(bool newVal) { digitizeWarningsOn_ = newVal; }
0094 
0095     // Access to digitized version of stub coords.
0096     const DigitalStub* digitalStub() const { return digitalStub_.get(); }
0097 
0098     // === Functions for returning info about reconstructed stubs ===
0099 
0100     // Location in InputData::vStubs_
0101     unsigned int index() const { return index_in_vStubs_; }
0102 
0103     //--- Stub data and quantities derived from it ---
0104 
0105     // Stub coordinates (optionally after digitisation, if digitisation requested via cfg).
0106     // N.B. Digitisation is only run if Stub::digitize() is called.
0107     float phi() const { return phi_; }
0108     float r() const { return r_; }
0109     float z() const { return z_; }
0110     float theta() const { return atan2(r_, z_); }
0111     float eta() const { return asinh(z_ / r_); }
0112 
0113     // Location of stub in module in units of strip/pixel number in phi direction.
0114     // Range from 0 to (nStrips - 1) inclusive.
0115     unsigned int iphi() const { return iphi_; }
0116     // alpha correction for non-radial strips in endcap 2S modules.
0117     // (If true hit at larger r than stub r by deltaR, then stub phi needs correcting by +alpha*deltaR).
0118     // *** TO DO *** : Digitize this.
0119     float alpha() const { return alpha_; }
0120 
0121     // Get stub bend and its resolution, as available within the front end chip (i.e. prior to loss of bits
0122     // or digitisation).
0123     float bendInFrontend() const { return bendInFrontend_; }
0124     float bendCutInFrontend() const { return settings_->bendCut(); }
0125     // Get stub bend (i.e. displacement between two hits in stub in units of strip pitch).
0126     float bend() const { return bend_; }
0127     // Bend resolution.
0128     float bendCut() const { return (settings_->bendCut() + (numMergedBend_ - 1) * settings_->bendCutExtra()); }
0129     // No. of bend values merged into FE bend encoding of this stub.
0130     float numMergedBend() const { return numMergedBend_; }
0131     // Estimated track q/Pt based on stub bend info.
0132     float qOverPt() const { return (this->qOverPtOverBend() * this->bend()); }
0133     float qOverPtcut() const { return (this->qOverPtOverBend() * this->bendCut()); }
0134     // Range in q/Pt bins in HT array compatible with stub bend.
0135     unsigned int min_qOverPt_bin() const { return min_qOverPt_bin_; }
0136     unsigned int max_qOverPt_bin() const { return max_qOverPt_bin_; }
0137     // Difference in phi between stub and angle at which track crosses given radius, assuming track has given Pt.
0138     float phiDiff(float rad, float Pt) const { return std::abs(r_ - rad) * (settings_->invPtToDphi()) / Pt; }
0139     // Phi angle at which particle consistent with this stub & its bend cross specified radius.
0140     float trkPhiAtR(float rad) const { return phi_ + (bend_ * dphiOverBend_) * (1. - rad / r_); }
0141     // Its resolution
0142     float trkPhiAtRcut(float rad) const { return (bendCut() * dphiOverBend_) * std::abs(1. - rad / r_); }
0143 
0144     // -- conversion factors
0145     // Ratio of track crossing angle to bend.
0146     float dphiOverBend() const { return dphiOverBend_; }
0147     // Ratio of q/Pt to bend.
0148     float qOverPtOverBend() const { return dphiOverBend_ / (r_ * settings_->invPtToDphi()); }
0149 
0150     //--- Info about the two clusters that make up the stub.
0151 
0152     // Coordinates in frame of sensor, measured in units of strip pitch along two orthogonal axes running perpendicular and parallel to longer axis of pixels/strips (U & V).
0153     std::array<float, 2> localU_cluster() const { return localU_cluster_; }
0154     std::array<float, 2> localV_cluster() const { return localV_cluster_; }
0155 
0156     //--- Check if this stub will be output by FE. Stub failing this not used for L1 tracks.
0157     bool frontendPass() const { return frontendPass_; }
0158     // Indicates if stub would have passed DE cuts, were it not for window size encoded in DegradeBend.h
0159     bool stubFailedDegradeWindow() const { return stubFailedDegradeWindow_; }
0160 
0161     //--- Truth info
0162 
0163     // Association of stub to tracking particles
0164     const std::set<const TP*>& assocTPs() const {
0165       return assocTPs_;
0166     }  // Return TPs associated to this stub. (Whether only TPs contributing to both clusters are returned is determined by "StubMatchStrict" config param.)
0167     bool genuine() const { return (not assocTPs_.empty()); }  // Did stub match at least one TP?
0168     const TP* assocTP() const {
0169       return assocTP_;
0170     }  // If only one TP contributed to both clusters, this tells you which TP it is. Returns nullptr if none.
0171 
0172     // Association of both clusters making up stub to tracking particles
0173     std::array<bool, 2> genuineCluster() const {
0174       return std::array<bool, 2>{{(assocTPofCluster_[0] != nullptr), (assocTPofCluster_[1] != nullptr)}};
0175     }  // Was cluster produced by a single TP?
0176     std::array<const TP*, 2> assocTPofCluster() const {
0177       return assocTPofCluster_;
0178     }  // Which TP made each cluster. Warning: If cluster was not produced by a single TP, then returns nullptr! (P.S. If both clusters match same TP, then this will equal assocTP()).
0179 
0180     //--- Quantities common to all stubs in a given module ---
0181     // N.B. Not taken from trackerModule_ to cope with Hybrid tracking.
0182 
0183     // Angle between normal to module and beam-line along +ve z axis. (In range -PI/2 to +PI/2).
0184     float tiltAngle() const { return tiltAngle_; }
0185     // Uncertainty in stub (r,z)
0186     float sigmaR() const { return (barrel() ? 0. : sigmaPar()); }
0187     float sigmaZ() const { return (barrel() ? sigmaPar() : 0.); }
0188     // Hit resolution perpendicular to strip. Measures phi.
0189     float sigmaPerp() const { return invRoot12 * stripPitch_; }
0190     // Hit resolution parallel to strip. Measures r or z.
0191     float sigmaPar() const { return invRoot12 * stripLength_; }
0192 
0193     //--- These module variables could be taken directly from trackerModule_, were it not for need
0194     //--- to support Hybrid.
0195     // Module type: PS or 2S?
0196     bool psModule() const { return psModule_; }
0197     // Tracker layer ID number (1-6 = barrel layer; 11-15 = endcap A disk; 21-25 = endcap B disk)
0198     unsigned int layerId() const { return layerId_; }
0199     // Reduced layer ID (in range 1-7). This encodes the layer ID in only 3 bits (to simplify firmware) by merging some barrel layer and endcap disk layer IDs into a single ID.
0200     unsigned int layerIdReduced() const { return layerIdReduced_; }
0201     bool barrel() const { return barrel_; }
0202     // True if stub is in tilted barrel module.
0203     bool tiltedBarrel() const { return tiltedBarrel_; }
0204     // Strip pitch (or pixel pitch along shortest axis).
0205     float stripPitch() const { return stripPitch_; }
0206     // Strip length (or pixel pitch along longest axis).
0207     float stripLength() const { return stripLength_; }
0208     // No. of strips in sensor.
0209     unsigned int nStrips() const { return nStrips_; }
0210 
0211   private:
0212     // Degrade assumed stub bend resolution.
0213     // And return an integer indicating how many values of bend are merged into this single one.
0214     void degradeResolution(float bend, float& degradedBend, unsigned int& num) const;
0215 
0216     // Set the frontendPass_ flag, indicating if frontend readout electronics will output this stub.
0217     void setFrontend(const StubKiller* stubKiller);
0218 
0219     // Set info about the module that this stub is in.
0220     void setTrackerModule(const TrackerGeometry* trackerGeometry,
0221                           const TrackerTopology* trackerTopology,
0222                           const DetId& detId);
0223 
0224     // Function to calculate approximation for dphiOverBendCorrection aka B
0225     double approxB();
0226 
0227     // Calculate variables giving ratio of track intercept angle to stub bend.
0228     void calcDphiOverBend();
0229 
0230   private:
0231     TTStubRef ttStubRef_;  // Reference to original TTStub
0232 
0233     const Settings* settings_;  // configuration parameters.
0234 
0235     unsigned int index_in_vStubs_;  // location of this stub in InputData::vStubs
0236 
0237     //--- Parameters passed along optical links from PP to MP (or equivalent ones if easier for analysis software to use).
0238     // WARNING: If you add any variables in this section, take care to ensure that they are digitized correctly by Stub::digitize().
0239     float phi_;  // stub coords, optionally after digitisation.
0240     float r_;
0241     float z_;
0242     float bend_;                    // bend of stub.
0243     float dphiOverBend_;            // related to rho parameter.
0244     unsigned int min_qOverPt_bin_;  // Range in q/Pt bins in HT array compatible with stub bend.
0245     unsigned int max_qOverPt_bin_;
0246 
0247     //--- Info about the two clusters that make up the stub.
0248     std::array<float, 2> localU_cluster_;
0249     std::array<float, 2> localV_cluster_;
0250 
0251     unsigned int iphi_;
0252     float alpha_;
0253 
0254     // Would front-end electronics output this stub?
0255     bool frontendPass_;
0256     // Did stub fail window cuts assumed in DegradeBend.h?
0257     bool stubFailedDegradeWindow_;
0258     // Bend in front end chip (prior to degredation by loss of bits & digitization).
0259     float bendInFrontend_;
0260     // Used for stub bend resolution degrading.
0261     unsigned int numMergedBend_;
0262 
0263     //--- Truth info about stub.
0264     const TP* assocTP_;
0265     std::set<const TP*> assocTPs_;
0266     //--- Truth info about the two clusters that make up the stub
0267     std::array<const TP*, 2> assocTPofCluster_;
0268 
0269     std::unique_ptr<DigitalStub> digitalStub_;  // Class used to digitize stub if required.
0270     DigiStage lastDigiStep_;
0271     bool digitizeWarningsOn_;  // Enable warnings about accessing non-digitized quantities.
0272 
0273     // Info about tracker module containing stub.
0274     const TrackerModule* trackerModule_;
0275 
0276     // Used to degrade stub bend information.
0277     const DegradeBend* degradeBend_;
0278 
0279     // These module variables are needed only to support the Hybrid stub constructor.
0280     // (Otherwise, they could be taken from trackerModule_).
0281     unsigned int layerId_;
0282     unsigned int layerIdReduced_;
0283     float tiltAngle_;
0284     float stripPitch_;
0285     float stripLength_;
0286     unsigned int nStrips_;
0287     bool psModule_;
0288     bool barrel_;
0289     bool tiltedBarrel_;
0290 
0291     const float rejectedStubBend_ = 99999.;  // Bend set to this if stub rejected.
0292 
0293     const float invRoot12 = sqrt(1. / 12.);
0294   };
0295 
0296 }  // namespace tmtt
0297 #endif