CMS 3D CMS Logo

PFTICLProducer.cc
Go to the documentation of this file.
1 // This producer converts a list of TICLCandidates to a list of PFCandidates.
2 
5 
8 
10 
13 
15 
17 
19 public:
21  ~PFTICLProducer() override {}
22 
23  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
24 
25  void produce(edm::Event&, const edm::EventSetup&) override;
26 
27 private:
28  // parameters
29  const bool useMTDTiming_;
30  const bool useTimingAverage_;
32 
33  // inputs
37  // For PFMuonAlgo
38  std::unique_ptr<PFMuonAlgo> pfmu_;
39 };
40 
42 
44  : useMTDTiming_(conf.getParameter<bool>("useMTDTiming")),
45  useTimingAverage_(conf.getParameter<bool>("useTimingAverage")),
46  timingQualityThreshold_(conf.getParameter<double>("timingQualityThreshold")),
47  ticl_candidates_(consumes<edm::View<TICLCandidate>>(conf.getParameter<edm::InputTag>("ticlCandidateSrc"))),
48  srcTrackTime_(consumes<edm::ValueMap<float>>(conf.getParameter<edm::InputTag>("trackTimeValueMap"))),
49  srcTrackTimeError_(consumes<edm::ValueMap<float>>(conf.getParameter<edm::InputTag>("trackTimeErrorMap"))),
50  srcTrackTimeQuality_(consumes<edm::ValueMap<float>>(conf.getParameter<edm::InputTag>("trackTimeQualityMap"))),
51  muons_(consumes<reco::MuonCollection>(conf.getParameter<edm::InputTag>("muonSrc"))),
52  pfmu_(std::make_unique<PFMuonAlgo>(conf.getParameterSet("pfMuonAlgoParameters"),
53  false)) { // postMuonCleaning = false
54  produces<reco::PFCandidateCollection>();
55 }
56 
59  desc.add<edm::InputTag>("ticlCandidateSrc", edm::InputTag("ticlTrackstersMerge"));
60  desc.add<edm::InputTag>("trackTimeValueMap", edm::InputTag("tofPID:t0"));
61  desc.add<edm::InputTag>("trackTimeErrorMap", edm::InputTag("tofPID:sigmat0"));
62  desc.add<edm::InputTag>("trackTimeQualityMap", edm::InputTag("mtdTrackQualityMVA:mtdQualMVA"));
63  desc.add<double>("timingQualityThreshold", 0.5);
64  desc.add<bool>("useMTDTiming", true);
65  desc.add<bool>("useTimingAverage", false);
66  // For PFMuonAlgo
67  desc.add<edm::InputTag>("muonSrc", edm::InputTag("muons1stStep"));
68  edm::ParameterSetDescription psd_PFMuonAlgo;
69  PFMuonAlgo::fillPSetDescription(psd_PFMuonAlgo);
70  desc.add<edm::ParameterSetDescription>("pfMuonAlgoParameters", psd_PFMuonAlgo);
71  //
72  descriptions.add("pfTICLProducer", desc);
73 }
74 
76  //get TICLCandidates
78  evt.getByToken(ticl_candidates_, ticl_cand_h);
79  const auto ticl_candidates = *ticl_cand_h;
80  edm::Handle<edm::ValueMap<float>> trackTimeH, trackTimeErrH, trackTimeQualH;
81  evt.getByToken(srcTrackTime_, trackTimeH);
82  evt.getByToken(srcTrackTimeError_, trackTimeErrH);
83  evt.getByToken(srcTrackTimeQuality_, trackTimeQualH);
84  const auto muonH = evt.getHandle(muons_);
85  const auto muons = *muonH;
86 
87  auto candidates = std::make_unique<reco::PFCandidateCollection>();
88 
89  for (const auto& ticl_cand : ticl_candidates) {
90  const auto abs_pdg_id = std::abs(ticl_cand.pdgId());
91  const auto charge = ticl_cand.charge();
92  const auto& four_mom = ticl_cand.p4();
93  double ecal_energy = 0.;
94 
95  for (const auto& t : ticl_cand.tracksters()) {
96  double ecal_energy_fraction = t->raw_em_pt() / t->raw_pt();
97  ecal_energy += t->raw_energy() * ecal_energy_fraction;
98  }
99  double hcal_energy = ticl_cand.rawEnergy() - ecal_energy;
100  // fix for floating point rounding could go slightly below 0
101  hcal_energy = hcal_energy < 0 ? 0 : hcal_energy;
102 
104  switch (abs_pdg_id) {
105  case 11:
106  part_type = reco::PFCandidate::e;
107  break;
108  case 13:
109  part_type = reco::PFCandidate::mu;
110  break;
111  case 22:
112  part_type = reco::PFCandidate::gamma;
113  break;
114  case 130:
115  part_type = reco::PFCandidate::h0;
116  break;
117  case 211:
118  part_type = reco::PFCandidate::h;
119  break;
120  // default also handles neutral pions (111) for the time being (not yet foreseen in PFCandidate)
121  default:
122  part_type = reco::PFCandidate::X;
123  }
124 
125  candidates->emplace_back(charge, four_mom, part_type);
126 
127  auto& candidate = candidates->back();
128  candidate.setEcalEnergy(ecal_energy, ecal_energy);
129  candidate.setHcalEnergy(hcal_energy, hcal_energy);
130  if (candidate.charge()) { // otherwise PFCandidate throws
131  // Construct edm::Ref from edm::Ptr. As of now, assumes type to be reco::Track. To be extended (either via
132  // dynamic type checking or configuration) if additional track types are needed.
133  reco::TrackRef trackref(ticl_cand.trackPtr().id(), int(ticl_cand.trackPtr().key()), &evt.productGetter());
134  candidate.setTrackRef(trackref);
135  // Utilize PFMuonAlgo
136  const int muId = PFMuonAlgo::muAssocToTrack(trackref, muons);
137  if (muId != -1) {
138  const reco::MuonRef muonref = reco::MuonRef(muonH, muId);
139  const bool allowLoose = (part_type == reco::PFCandidate::mu);
140  // Redefine pfmuon candidate kinematics and add muonref
141  pfmu_->reconstructMuon(candidate, muonref, allowLoose);
142  }
143  }
144 
145  // HGCAL timing as default values
146  auto time = ticl_cand.time();
147  auto timeE = ticl_cand.timeError();
148 
149  if (useMTDTiming_ and candidate.charge()) {
150  // Ignore HGCAL timing until it will be TOF corrected
151  time = -99.;
152  timeE = -1.;
153  // Check MTD timing availability
154  const bool assocQuality = (*trackTimeQualH)[candidate.trackRef()] > timingQualityThreshold_;
155  if (assocQuality) {
156  const auto timeHGC = time;
157  const auto timeEHGC = timeE;
158  const auto timeMTD = (*trackTimeH)[candidate.trackRef()];
159  const auto timeEMTD = (*trackTimeErrH)[candidate.trackRef()];
160 
161  if (useTimingAverage_ && (timeEMTD > 0 && timeEHGC > 0)) {
162  // Compute weighted average between HGCAL and MTD timing
163  const auto invTimeESqHGC = pow(timeEHGC, -2);
164  const auto invTimeESqMTD = pow(timeEMTD, -2);
165  timeE = (invTimeESqHGC * invTimeESqMTD) / (invTimeESqHGC + invTimeESqMTD);
166  time = (timeHGC * invTimeESqHGC + timeMTD * invTimeESqMTD) * timeE;
167  timeE = sqrt(timeE);
168  } else if (timeEMTD > 0) { // Ignore HGCal timing until it will be TOF corrected
169  time = timeMTD;
170  timeE = timeEMTD;
171  }
172  }
173  }
174  candidate.setTime(time, timeE);
175  }
176 
177  evt.put(std::move(candidates));
178 }
static int muAssocToTrack(const reco::TrackRef &trackref, const reco::MuonCollection &muons)
Definition: PFMuonAlgo.cc:479
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
ParticleType
particle types
Definition: PFCandidate.h:44
~PFTICLProducer() override
const bool useTimingAverage_
const edm::EDGetTokenT< edm::ValueMap< float > > srcTrackTime_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
PFTICLProducer(const edm::ParameterSet &)
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
const edm::EDGetTokenT< edm::ValueMap< float > > srcTrackTimeError_
EDProductGetter const & productGetter() const
Definition: Event.cc:106
const edm::EDGetTokenT< edm::ValueMap< float > > srcTrackTimeQuality_
const edm::EDGetTokenT< edm::View< TICLCandidate > > ticl_candidates_
T sqrt(T t)
Definition: SSEVec.h:19
std::unique_ptr< PFMuonAlgo > pfmu_
const bool useMTDTiming_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
edm::Ref< MuonCollection > MuonRef
presistent reference to a Muon
Definition: MuonFwd.h:13
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const float timingQualityThreshold_
static void fillPSetDescription(edm::ParameterSetDescription &iDesc)
Definition: PFMuonAlgo.cc:1043
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void produce(edm::Event &, const edm::EventSetup &) override
ParameterSet const & getParameterSet(ParameterSetID const &id)
fixed size matrix
Handle< PROD > getHandle(EDGetTokenT< PROD > token) const
Definition: Event.h:563
HLT enums.
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
def move(src, dest)
Definition: eostools.py:511
const edm::EDGetTokenT< reco::MuonCollection > muons_