Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-06-22 02:23:21

0001 #ifndef DataFormats_HGCalReco_TICLCandidate_h
0002 #define DataFormats_HGCalReco_TICLCandidate_h
0003 
0004 #include "DataFormats/Candidate/interface/LeafCandidate.h"
0005 #include "DataFormats/Common/interface/Ref.h"
0006 #include "DataFormats/HGCalReco/interface/Trackster.h"
0007 #include "DataFormats/Math/interface/Point3D.h"
0008 #include "DataFormats/TrackReco/interface/Track.h"
0009 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0010 #include "Common.h"
0011 
0012 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0013 
0014 // A TICLCandidate is a lightweight physics object made from one or multiple Tracksters.
0015 
0016 class TICLCandidate : public reco::LeafCandidate {
0017 public:
0018   typedef ticl::Trackster::ParticleType ParticleType;
0019 
0020   TICLCandidate(Charge q, const LorentzVector& p4)
0021       : LeafCandidate(q, p4), idProbabilities_{}, time_(0.f), timeError_(-1.f), rawEnergy_(0.f) {}
0022 
0023   TICLCandidate() : LeafCandidate(), idProbabilities_{}, time_(0.f), timeError_(-1.f), rawEnergy_(0.f) {}
0024 
0025   TICLCandidate(const edm::Ptr<ticl::Trackster>& trackster)
0026       : LeafCandidate(),
0027         tracksters_({trackster}),
0028         idProbabilities_{},
0029         time_(trackster->time()),
0030         timeError_(trackster->timeError()),
0031         MTDtime_{0.f},
0032         MTDtimeError_{-1.f},
0033         rawEnergy_(0.f) {}
0034 
0035   TICLCandidate(const edm::Ptr<reco::Track> trackPtr, const edm::Ptr<ticl::Trackster>& tracksterPtr)
0036       : LeafCandidate(), tracksters_{}, trackPtr_(trackPtr), time_(0.f), timeError_(-1.f) {
0037     if (trackPtr_.isNull() and tracksterPtr.isNull())
0038       throw cms::Exception("NullPointerError")
0039           << "TICLCandidate constructor: at least one between track and trackster must be valid";
0040 
0041     if (tracksterPtr.isNonnull()) {
0042       tracksters_.push_back(tracksterPtr);
0043       auto const& trackster = tracksters_[0].get();
0044       idProbabilities_ = trackster->id_probabilities();
0045       if (trackPtr_.isNonnull()) {
0046         auto pdgId = trackster->isHadronic() ? 211 : 11;
0047         auto const& tk = trackPtr_.get();
0048         setPdgId(pdgId * tk->charge());
0049         setCharge(tk->charge());
0050         rawEnergy_ = trackster->raw_energy();
0051         auto const& regrE = trackster->regressed_energy();
0052         math::XYZTLorentzVector p4(regrE * tk->momentum().unit().x(),
0053                                    regrE * tk->momentum().unit().y(),
0054                                    regrE * tk->momentum().unit().z(),
0055                                    regrE);
0056         setP4(p4);
0057 
0058       } else {
0059         auto pdgId = trackster->isHadronic() ? 130 : 22;
0060         setPdgId(pdgId);
0061         setCharge(0);
0062         rawEnergy_ = trackster->raw_energy();
0063         const float& regrE = trackster->regressed_energy();
0064         math::XYZTLorentzVector p4(regrE * trackster->barycenter().unit().x(),
0065                                    regrE * trackster->barycenter().unit().y(),
0066                                    regrE * trackster->barycenter().unit().z(),
0067                                    regrE);
0068         setP4(p4);
0069       }
0070     } else {
0071       //candidate from track only
0072       auto const& tk = trackPtr_.get();
0073       setPdgId(211 * tk->charge());
0074       setCharge(tk->charge());
0075       const float energy = std::sqrt(tk->p() * tk->p() + ticl::mpion2);
0076       setRawEnergy(energy);
0077       math::PtEtaPhiMLorentzVector p4Polar(tk->pt(), tk->eta(), tk->phi(), ticl::mpion);
0078       setP4(p4Polar);
0079     }
0080   }
0081 
0082   inline float time() const { return time_; }
0083   inline float timeError() const { return timeError_; }
0084 
0085   void setTime(float time, float timeError) {
0086     time_ = time;
0087     timeError_ = timeError;
0088   };
0089 
0090   inline float MTDtime() const { return MTDtime_; }
0091   inline float MTDtimeError() const { return MTDtimeError_; }
0092 
0093   void setMTDTime(float time, float timeError) {
0094     MTDtime_ = time;
0095     MTDtimeError_ = timeError;
0096   };
0097 
0098   inline const edm::Ptr<reco::Track> trackPtr() const { return trackPtr_; }
0099   void setTrackPtr(const edm::Ptr<reco::Track>& trackPtr) { trackPtr_ = trackPtr; }
0100 
0101   inline float rawEnergy() const { return rawEnergy_; }
0102   void setRawEnergy(float rawEnergy) { rawEnergy_ = rawEnergy; }
0103 
0104   inline const std::vector<edm::Ptr<ticl::Trackster> > tracksters() const { return tracksters_; };
0105 
0106   void setTracksters(const std::vector<edm::Ptr<ticl::Trackster> >& tracksters) { tracksters_ = tracksters; }
0107   void addTrackster(const edm::Ptr<ticl::Trackster>& trackster) {
0108     tracksters_.push_back(trackster);
0109     time_ = trackster->time();
0110     timeError_ = trackster->timeError();
0111   }
0112   // convenience method to return the ID probability for a certain particle type
0113   inline float id_probability(ParticleType type) const {
0114     // probabilities are stored in the same order as defined in the ParticleType enum
0115     return idProbabilities_[(int)type];
0116   }
0117 
0118   inline const std::array<float, 8>& idProbabilities() const { return idProbabilities_; }
0119 
0120   void zeroProbabilities() {
0121     for (auto& p : idProbabilities_) {
0122       p = 0.f;
0123     }
0124   }
0125 
0126   void setIdProbabilities(const std::array<float, 8>& idProbs) { idProbabilities_ = idProbs; }
0127   inline void setIdProbability(ParticleType type, float value) { idProbabilities_[int(type)] = value; }
0128 
0129 private:
0130   // vector of Ptr so Tracksters can come from different collections
0131   // and there can be derived classes
0132   std::vector<edm::Ptr<ticl::Trackster> > tracksters_;
0133   edm::Ptr<reco::Track> trackPtr_;
0134   // Since it contains multiple tracksters, duplicate the probability interface
0135   std::array<float, 8> idProbabilities_;
0136 
0137   float time_;
0138   float timeError_;
0139   float MTDtime_;
0140   float MTDtimeError_;
0141   float rawEnergy_;
0142 };
0143 #endif