TICLCandidate

Macros

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
#ifndef DataFormats_HGCalReco_TICLCandidate_h
#define DataFormats_HGCalReco_TICLCandidate_h

#include "DataFormats/Candidate/interface/LeafCandidate.h"
#include "DataFormats/Common/interface/Ref.h"
#include "DataFormats/HGCalReco/interface/Trackster.h"
#include "DataFormats/Math/interface/Point3D.h"
#include "DataFormats/TrackReco/interface/Track.h"
#include "DataFormats/TrackReco/interface/TrackFwd.h"
#include "Common.h"

#include "FWCore/MessageLogger/interface/MessageLogger.h"

// A TICLCandidate is a lightweight physics object made from one or multiple Tracksters.

class TICLCandidate : public reco::LeafCandidate {
public:
  typedef ticl::Trackster::ParticleType ParticleType;

  TICLCandidate(Charge q, const LorentzVector& p4)
      : LeafCandidate(q, p4), idProbabilities_{}, time_(0.f), timeError_(-1.f), rawEnergy_(0.f) {}

  TICLCandidate() : LeafCandidate(), idProbabilities_{}, time_(0.f), timeError_(-1.f), rawEnergy_(0.f) {}

  TICLCandidate(const edm::Ptr<ticl::Trackster>& trackster)
      : LeafCandidate(),
        tracksters_({trackster}),
        idProbabilities_{},
        time_(trackster->time()),
        timeError_(trackster->timeError()),
        MTDtime_{0.f},
        MTDtimeError_{-1.f},
        rawEnergy_(0.f) {}

  TICLCandidate(const edm::Ptr<reco::Track> trackPtr, const edm::Ptr<ticl::Trackster>& tracksterPtr)
      : LeafCandidate(), tracksters_{}, trackPtr_(trackPtr), time_(0.f), timeError_(-1.f) {
    if (trackPtr_.isNull() and tracksterPtr.isNull())
      throw cms::Exception("NullPointerError")
          << "TICLCandidate constructor: at least one between track and trackster must be valid";

    if (tracksterPtr.isNonnull()) {
      tracksters_.push_back(tracksterPtr);
      auto const& trackster = tracksters_[0].get();
      idProbabilities_ = trackster->id_probabilities();
      if (trackPtr_.isNonnull()) {
        auto pdgId = trackster->isHadronic() ? 211 : 11;
        auto const& tk = trackPtr_.get();
        setPdgId(pdgId * tk->charge());
        setCharge(tk->charge());
        rawEnergy_ = trackster->raw_energy();
        auto const& regrE = trackster->regressed_energy();
        math::XYZTLorentzVector p4(regrE * tk->momentum().unit().x(),
                                   regrE * tk->momentum().unit().y(),
                                   regrE * tk->momentum().unit().z(),
                                   regrE);
        setP4(p4);

      } else {
        auto pdgId = trackster->isHadronic() ? 130 : 22;
        setPdgId(pdgId);
        setCharge(0);
        rawEnergy_ = trackster->raw_energy();
        const float& regrE = trackster->regressed_energy();
        math::XYZTLorentzVector p4(regrE * trackster->barycenter().unit().x(),
                                   regrE * trackster->barycenter().unit().y(),
                                   regrE * trackster->barycenter().unit().z(),
                                   regrE);
        setP4(p4);
      }
    } else {
      //candidate from track only
      auto const& tk = trackPtr_.get();
      setPdgId(211 * tk->charge());
      setCharge(tk->charge());
      const float energy = std::sqrt(tk->p() * tk->p() + ticl::mpion2);
      setRawEnergy(energy);
      math::PtEtaPhiMLorentzVector p4Polar(tk->pt(), tk->eta(), tk->phi(), ticl::mpion);
      setP4(p4Polar);
    }
  }

  inline float time() const { return time_; }
  inline float timeError() const { return timeError_; }

  void setTime(float time, float timeError) {
    time_ = time;
    timeError_ = timeError;
  };

  inline float MTDtime() const { return MTDtime_; }
  inline float MTDtimeError() const { return MTDtimeError_; }

  void setMTDTime(float time, float timeError) {
    MTDtime_ = time;
    MTDtimeError_ = timeError;
  };

  inline const edm::Ptr<reco::Track> trackPtr() const { return trackPtr_; }
  void setTrackPtr(const edm::Ptr<reco::Track>& trackPtr) { trackPtr_ = trackPtr; }

  inline float rawEnergy() const { return rawEnergy_; }
  void setRawEnergy(float rawEnergy) { rawEnergy_ = rawEnergy; }

  inline const std::vector<edm::Ptr<ticl::Trackster> > tracksters() const { return tracksters_; };

  void setTracksters(const std::vector<edm::Ptr<ticl::Trackster> >& tracksters) { tracksters_ = tracksters; }
  void addTrackster(const edm::Ptr<ticl::Trackster>& trackster) {
    tracksters_.push_back(trackster);
    time_ = trackster->time();
    timeError_ = trackster->timeError();
  }
  // convenience method to return the ID probability for a certain particle type
  inline float id_probability(ParticleType type) const {
    // probabilities are stored in the same order as defined in the ParticleType enum
    return idProbabilities_[(int)type];
  }

  inline const std::array<float, 8>& idProbabilities() const { return idProbabilities_; }

  void zeroProbabilities() {
    for (auto& p : idProbabilities_) {
      p = 0.f;
    }
  }

  void setIdProbabilities(const std::array<float, 8>& idProbs) { idProbabilities_ = idProbs; }
  inline void setIdProbability(ParticleType type, float value) { idProbabilities_[int(type)] = value; }

private:
  // vector of Ptr so Tracksters can come from different collections
  // and there can be derived classes
  std::vector<edm::Ptr<ticl::Trackster> > tracksters_;
  edm::Ptr<reco::Track> trackPtr_;
  // Since it contains multiple tracksters, duplicate the probability interface
  std::array<float, 8> idProbabilities_;

  float time_;
  float timeError_;
  float MTDtime_;
  float MTDtimeError_;
  float rawEnergy_;
};
#endif