Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-12 04:16:21

0001 #ifndef DataFormats_L1Trigger_P2GTCandidate_h
0002 #define DataFormats_L1Trigger_P2GTCandidate_h
0003 
0004 #include <vector>
0005 #include <ap_int.h>
0006 #include <stdexcept>
0007 
0008 #include "DataFormats/Common/interface/Ref.h"
0009 #include "DataFormats/Common/interface/RefVector.h"
0010 #include "DataFormats/Candidate/interface/LeafCandidate.h"
0011 
0012 namespace l1t {
0013 
0014   class L1GTProducer;
0015 
0016   class P2GTCandidate;
0017   typedef std::vector<P2GTCandidate> P2GTCandidateCollection;
0018   typedef edm::Ref<P2GTCandidateCollection> P2GTCandidateRef;
0019   typedef edm::RefVector<P2GTCandidateCollection> P2GTCandidateRefVector;
0020   typedef std::vector<P2GTCandidateRef> P2GTCandidateVectorRef;
0021 
0022   class P2GTCandidate : public reco::LeafCandidate {
0023   public:
0024     using Base = reco::LeafCandidate;
0025 
0026     using Base::Base;
0027 
0028     friend class L1GTProducer;
0029 
0030     typedef ap_uint<16> hwPT_t;
0031     typedef ap_int<13> hwPhi_t;
0032     typedef ap_int<14> hwEta_t;
0033     typedef ap_int<18> hwZ0_t;
0034     typedef ap_uint<11> hwIsolationPT_t;
0035     typedef ap_uint<6> hwQualityFlags_t;
0036     typedef ap_uint<10> hwQualityScore_t;
0037     typedef ap_uint<1> hwCharge_t;
0038     typedef ap_int<12> hwD0_t;
0039     typedef ap_uint<4> hwBeta_t;
0040     typedef ap_uint<10> hwMass_t;
0041     typedef ap_uint<16> hwIndex_t;
0042     typedef ap_uint<10> hwSeed_pT_t;
0043     typedef ap_int<10> hwSeed_z0_t;
0044     typedef ap_uint<16> hwScalarSumPT_t;
0045     typedef ap_uint<5> hwNumber_of_tracks_t;
0046     typedef ap_uint<4> hwNumber_of_displaced_tracks_t;
0047     typedef ap_uint<12> hwSum_pT_pv_t;
0048     typedef ap_uint<2> hwType_t;
0049     typedef ap_uint<8> hwNumber_of_tracks_in_pv_t;
0050     typedef ap_uint<10> hwNumber_of_tracks_not_in_pv_t;
0051 
0052     // Similar to std::optional<T> but avoids inheritance for ROOT file embedding
0053     template <typename T>
0054     struct Optional {
0055       Optional() : value_(0), set_(false) {}
0056       Optional(T value) : value_(value), set_(true) {}
0057 
0058       operator T() const { return value_; }
0059       operator bool() const { return set_; }
0060 
0061       bool operator==(bool rhs) const { return set_ == rhs; }
0062       bool operator!=(bool rhs) const { return set_ != rhs; }
0063 
0064     private:
0065       T value_;
0066       bool set_;
0067     };
0068 
0069     enum ObjectType {
0070       Undefined,
0071       GCTNonIsoEg,
0072       GCTIsoEg,
0073       GCTJets,
0074       GCTTaus,
0075       GCTHtSum,
0076       GCTEtSum,
0077       GMTSaPromptMuons,
0078       GMTSaDisplacedMuons,
0079       GMTTkMuons,
0080       GMTTopo,
0081       GTTPromptJets,
0082       GTTDisplacedJets,
0083       GTTPhiCandidates,
0084       GTTRhoCandidates,
0085       GTTBsCandidates,
0086       GTTHadronicTaus,
0087       GTTPromptTracks,
0088       GTTDisplacedTracks,
0089       GTTPrimaryVert,
0090       GTTPromptHtSum,
0091       GTTDisplacedHtSum,
0092       GTTEtSum,
0093       CL2JetsSC4,
0094       CL2JetsSC8,
0095       CL2Taus,
0096       CL2Electrons,
0097       CL2Photons,
0098       CL2HtSum,
0099       CL2EtSum
0100     };
0101 
0102     void setHwPT(hwPT_t hwPT) { hwPT_ = hwPT.to_int(); }
0103     void setHwPhi(hwPhi_t hwPhi) { hwPhi_ = hwPhi.to_int(); }
0104     void setHwEta(hwEta_t hwEta) { hwEta_ = hwEta.to_int(); }
0105     void setHwZ0(hwZ0_t hwZ0) { hwZ0_ = hwZ0.to_int(); }
0106     void setHwIsolationPT(hwIsolationPT_t hwIso) { hwIsolationPT_ = hwIso.to_int(); }
0107     void setHwQualityFlags(hwQualityFlags_t hwQualityFlags) { hwQualityFlags_ = hwQualityFlags.to_int(); }
0108     void setHwQualityScore(hwQualityScore_t hwQualityScore) { hwQualityScore_ = hwQualityScore.to_int(); }
0109     void setHwCharge(hwCharge_t hwCharge) { hwCharge_ = hwCharge.to_int(); }
0110     void setHwD0(hwD0_t hwD0) { hwD0_ = hwD0.to_int(); }
0111     void setHwBeta(hwBeta_t hwBeta) { hwBeta_ = hwBeta.to_int(); }
0112     void setHwMass(hwMass_t hwMass) { hwMass_ = hwMass.to_int(); }
0113     void setHwIndex(hwIndex_t hwIndex) { hwIndex_ = hwIndex.to_int(); }
0114     void setHwSeed_pT(hwSeed_pT_t hwSeed_pT) { hwSeed_pT_ = hwSeed_pT.to_int(); }
0115     void setHwSeed_z0(hwSeed_z0_t hwSeed_z0) { hwSeed_z0_ = hwSeed_z0.to_int(); }
0116     void setHwScalarSumPT(hwScalarSumPT_t hwScalarSumPT) { hwScalarSumPT_ = hwScalarSumPT.to_int(); }
0117     void setHwNumber_of_tracks(hwNumber_of_tracks_t hwNumber_of_tracks) {
0118       hwNumber_of_tracks_ = hwNumber_of_tracks.to_int();
0119     }
0120 
0121     void setHwNumber_of_displaced_tracks(hwNumber_of_displaced_tracks_t hwNumber_of_displaced_tracks) {
0122       hwNumber_of_displaced_tracks_ = hwNumber_of_displaced_tracks.to_int();
0123     }
0124 
0125     void setHwSum_pT_pv(hwSum_pT_pv_t hwSum_pT_pv) { hwSum_pT_pv_ = hwSum_pT_pv.to_int(); }
0126     void setHwType(hwType_t hwType) { hwType_ = hwType.to_int(); }
0127     void setHwNumber_of_tracks_in_pv(hwNumber_of_tracks_in_pv_t hwNumber_of_tracks_in_pv) {
0128       hwNumber_of_tracks_in_pv_ = hwNumber_of_tracks_in_pv.to_int();
0129     }
0130     void setHwNumber_of_tracks_not_in_pv(hwNumber_of_tracks_not_in_pv_t hwNumber_of_tracks_not_in_pv) {
0131       hwNumber_of_tracks_not_in_pv_ = hwNumber_of_tracks_not_in_pv.to_int();
0132     }
0133 
0134     hwPT_t hwPT() const {
0135       if (!hwPT_) {
0136         throw std::invalid_argument("Object doesn't have pT");
0137       }
0138       return static_cast<int>(hwPT_);
0139     }
0140 
0141     hwPhi_t hwPhi() const {
0142       if (!hwPhi_) {
0143         throw std::invalid_argument("Object doesn't have phi");
0144       }
0145       return static_cast<int>(hwPhi_);
0146     }
0147 
0148     hwEta_t hwEta() const {
0149       if (!hwEta_) {
0150         throw std::invalid_argument("Object doesn't have eta");
0151       }
0152       return static_cast<int>(hwEta_);
0153     }
0154 
0155     hwZ0_t hwZ0() const {
0156       if (!hwZ0_) {
0157         throw std::invalid_argument("Object doesn't have z0");
0158       }
0159       return static_cast<int>(hwZ0_);
0160     }
0161 
0162     hwIsolationPT_t hwIsolationPT() const {
0163       if (!hwIsolationPT_) {
0164         throw std::invalid_argument("Object doesn't have isolationPT");
0165       }
0166       return static_cast<int>(hwIsolationPT_);
0167     }
0168 
0169     hwQualityFlags_t hwQualityFlags() const {
0170       if (!hwQualityFlags_) {
0171         throw std::invalid_argument("Object doesn't have qualityFlags");
0172       }
0173       return static_cast<int>(hwQualityFlags_);
0174     }
0175 
0176     hwQualityScore_t hwQualityScore() const {
0177       if (!hwQualityScore_) {
0178         throw std::invalid_argument("Object doesn't have qualityScore");
0179       }
0180       return static_cast<int>(hwQualityScore_);
0181     }
0182 
0183     hwCharge_t hwCharge() const {
0184       if (!hwCharge_) {
0185         throw std::invalid_argument("Object doesn't have charge");
0186       }
0187       return static_cast<int>(hwCharge_);
0188     }
0189 
0190     hwD0_t hwD0() const {
0191       if (!hwD0_) {
0192         throw std::invalid_argument("Object doesn't have d0");
0193       }
0194       return static_cast<int>(hwD0_);
0195     }
0196 
0197     hwBeta_t hwBeta() const {
0198       if (!hwBeta_) {
0199         throw std::invalid_argument("Object doesn't have beta");
0200       }
0201       return static_cast<int>(hwBeta_);
0202     }
0203 
0204     hwMass_t hwMass() const {
0205       if (!hwMass_) {
0206         throw std::invalid_argument("Object doesn't have mass");
0207       }
0208       return static_cast<int>(hwMass_);
0209     }
0210 
0211     hwIndex_t hwIndex() const {
0212       if (!hwIndex_) {
0213         throw std::invalid_argument("Object doesn't have index");
0214       }
0215       return static_cast<int>(hwIndex_);
0216     }
0217 
0218     hwSeed_pT_t hwSeed_pT() const {
0219       if (!hwSeed_pT_) {
0220         throw std::invalid_argument("Object doesn't have seed_pT");
0221       }
0222       return static_cast<int>(hwSeed_pT_);
0223     }
0224 
0225     hwSeed_z0_t hwSeed_z0() const {
0226       if (!hwSeed_z0_) {
0227         throw std::invalid_argument("Object doesn't have seed_z0");
0228       }
0229       return static_cast<int>(hwSeed_z0_);
0230     }
0231 
0232     hwScalarSumPT_t hwScalarSumPT() const {
0233       if (!hwScalarSumPT_) {
0234         throw std::invalid_argument("Object doesn't have scalarSumPT");
0235       }
0236       return static_cast<int>(hwScalarSumPT_);
0237     }
0238 
0239     hwNumber_of_tracks_t hwNumber_of_tracks() const {
0240       if (!hwNumber_of_tracks_) {
0241         throw std::invalid_argument("Object doesn't have number_of_tracks");
0242       }
0243       return static_cast<int>(hwNumber_of_tracks_);
0244     }
0245 
0246     hwNumber_of_displaced_tracks_t hwNumber_of_displaced_tracks() const {
0247       if (!hwNumber_of_displaced_tracks_) {
0248         throw std::invalid_argument("Object doesn't have hwNumber_of_displaced_tracks");
0249       }
0250       return static_cast<int>(hwNumber_of_displaced_tracks_);
0251     }
0252 
0253     hwSum_pT_pv_t hwSum_pT_pv() const {
0254       if (!hwSum_pT_pv_) {
0255         throw std::invalid_argument("Object doesn't have sum_pT_pv");
0256       }
0257       return static_cast<int>(hwSum_pT_pv_);
0258     }
0259 
0260     hwType_t hwType() const {
0261       if (!hwType_) {
0262         throw std::invalid_argument("Object doesn't have type");
0263       }
0264       return static_cast<int>(hwType_);
0265     }
0266 
0267     hwNumber_of_tracks_in_pv_t hwNumber_of_tracks_in_pv() const {
0268       if (!hwNumber_of_tracks_in_pv_) {
0269         throw std::invalid_argument("Object doesn't have number_of_tracks_in_pv");
0270       }
0271       return static_cast<int>(hwNumber_of_tracks_in_pv_);
0272     }
0273 
0274     hwNumber_of_tracks_not_in_pv_t hwNumber_of_tracks_not_in_pv() const {
0275       if (!hwNumber_of_tracks_not_in_pv_) {
0276         throw std::invalid_argument("Object doesn't have hwNumber_of_tracks_not_in_pv");
0277       }
0278       return static_cast<int>(hwNumber_of_tracks_not_in_pv_);
0279     }
0280 
0281     ObjectType objectType() const { return objectType_; }
0282 
0283     // Nano SimpleCandidateFlatTableProducer accessor functions
0284     int hwPT_toInt() const { return hwPT().to_int(); }
0285     int hwPhi_toInt() const { return hwPhi().to_int(); }
0286     int hwEta_toInt() const { return hwEta().to_int(); }
0287     int hwZ0_toInt() const { return hwZ0().to_int(); }
0288     int hwIsolationPT_toInt() const { return hwIsolationPT().to_int(); }
0289     int hwQualityFlags_toInt() const { return hwQualityFlags().to_int(); }
0290     int hwQualityScore_toInt() const { return hwQualityScore().to_int(); }
0291     int hwCharge_toInt() const { return hwCharge().to_int(); }
0292     int hwD0_toInt() const { return hwD0().to_int(); }
0293     int hwBeta_toInt() const { return hwBeta().to_int(); }
0294     int hwMass_toInt() const { return hwMass().to_int(); }
0295     int hwIndex_toInt() const { return hwIndex().to_int(); }
0296     int hwSeed_pT_toInt() const { return hwSeed_pT().to_int(); }
0297     int hwSeed_z0_toInt() const { return hwSeed_z0().to_int(); }
0298     int hwScalarSumPT_toInt() const { return hwScalarSumPT().to_int(); }
0299     int hwNumber_of_tracks_toInt() const { return hwNumber_of_tracks().to_int(); }
0300     int hwNumber_of_displaced_tracks_toInt() const { return hwNumber_of_displaced_tracks().to_int(); }
0301     int hwSum_pT_pv_toInt() const { return hwSum_pT_pv().to_int(); }
0302     int hwType_toInt() const { return hwType().to_int(); }
0303     int hwNumber_of_tracks_in_pv_toInt() const { return hwNumber_of_tracks_in_pv().to_int(); }
0304     int hwNumber_of_tracks_not_in_pv_toInt() const { return hwNumber_of_tracks_not_in_pv().to_int(); }
0305 
0306     bool operator==(const P2GTCandidate& rhs) const;
0307     bool operator!=(const P2GTCandidate& rhs) const;
0308 
0309     bool isElectron() const override { return objectType_ == CL2Electrons; };
0310 
0311     bool isMuon() const override {
0312       return objectType_ == GMTSaPromptMuons || objectType_ == GMTSaDisplacedMuons || objectType_ == GMTTkMuons;
0313     };
0314 
0315     bool isStandAloneMuon() const override {
0316       return objectType_ == GMTSaPromptMuons || objectType_ == GMTSaDisplacedMuons;
0317     };
0318 
0319     bool isTrackerMuon() const override { return objectType_ == GMTTkMuons; }
0320 
0321     bool isPhoton() const override { return objectType_ == CL2Photons; }
0322 
0323     bool isJet() const override {
0324       return objectType_ == GCTJets || objectType_ == GTTPromptJets || objectType_ == GTTDisplacedJets ||
0325              objectType_ == CL2JetsSC4 || objectType_ == CL2JetsSC8;
0326     }
0327 
0328   private:
0329     Optional<int> hwPT_;
0330     Optional<int> hwPhi_;
0331     Optional<int> hwEta_;
0332     Optional<int> hwZ0_;
0333     Optional<int> hwIsolationPT_;
0334     Optional<int> hwQualityFlags_;
0335     Optional<int> hwQualityScore_;
0336     Optional<int> hwCharge_;
0337     Optional<int> hwD0_;
0338     Optional<int> hwBeta_;
0339     Optional<int> hwMass_;
0340     Optional<int> hwIndex_;
0341     Optional<int> hwSeed_pT_;
0342     Optional<int> hwSeed_z0_;
0343     Optional<int> hwScalarSumPT_;
0344     Optional<int> hwNumber_of_tracks_;
0345     Optional<int> hwNumber_of_displaced_tracks_;
0346 
0347     // TODO ?
0348     Optional<int> hwSum_pT_pv_;
0349     Optional<int> hwType_;
0350     Optional<int> hwNumber_of_tracks_in_pv_;
0351     Optional<int> hwNumber_of_tracks_not_in_pv_;
0352 
0353     ObjectType objectType_ = Undefined;
0354   };
0355 
0356 };  // namespace l1t
0357 
0358 #endif  // DataFormats_L1Trigger_P2GTCandidate_h