CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 useTimingAverage_;
31 
32  // inputs
36  // For PFMuonAlgo
37  std::unique_ptr<PFMuonAlgo> pfmu_;
38 };
39 
41 
43  : useTimingAverage_(conf.getParameter<bool>("useTimingAverage")),
44  timingQualityThreshold_(conf.getParameter<double>("timingQualityThreshold")),
45  ticl_candidates_(consumes<edm::View<TICLCandidate>>(conf.getParameter<edm::InputTag>("ticlCandidateSrc"))),
46  srcTrackTime_(consumes<edm::ValueMap<float>>(conf.getParameter<edm::InputTag>("trackTimeValueMap"))),
47  srcTrackTimeError_(consumes<edm::ValueMap<float>>(conf.getParameter<edm::InputTag>("trackTimeErrorMap"))),
48  srcTrackTimeQuality_(consumes<edm::ValueMap<float>>(conf.getParameter<edm::InputTag>("trackTimeQualityMap"))),
49  muons_(consumes<reco::MuonCollection>(conf.getParameter<edm::InputTag>("muonSrc"))),
50  pfmu_(std::make_unique<PFMuonAlgo>(conf.getParameterSet("pfMuonAlgoParameters"),
51  false)) { // postMuonCleaning = false
52  produces<reco::PFCandidateCollection>();
53 }
54 
57  desc.add<edm::InputTag>("ticlCandidateSrc", edm::InputTag("ticlTrackstersMerge"));
58  desc.add<edm::InputTag>("trackTimeValueMap", edm::InputTag("tofPID:t0"));
59  desc.add<edm::InputTag>("trackTimeErrorMap", edm::InputTag("tofPID:sigmat0"));
60  desc.add<edm::InputTag>("trackTimeQualityMap", edm::InputTag("mtdTrackQualityMVA:mtdQualMVA"));
61  desc.add<double>("timingQualityThreshold", 0.5);
62  desc.add<bool>("useTimingAverage", false);
63  // For PFMuonAlgo
64  desc.add<edm::InputTag>("muonSrc", edm::InputTag("muons1stStep"));
65  edm::ParameterSetDescription psd_PFMuonAlgo;
66  PFMuonAlgo::fillPSetDescription(psd_PFMuonAlgo);
67  desc.add<edm::ParameterSetDescription>("pfMuonAlgoParameters", psd_PFMuonAlgo);
68  //
69  descriptions.add("pfTICLProducer", desc);
70 }
71 
73  //get TICLCandidates
75  evt.getByToken(ticl_candidates_, ticl_cand_h);
76  const auto ticl_candidates = *ticl_cand_h;
77  edm::Handle<edm::ValueMap<float>> trackTimeH, trackTimeErrH, trackTimeQualH;
78  evt.getByToken(srcTrackTime_, trackTimeH);
79  evt.getByToken(srcTrackTimeError_, trackTimeErrH);
80  evt.getByToken(srcTrackTimeQuality_, trackTimeQualH);
81  const auto muonH = evt.getHandle(muons_);
82  const auto muons = *muonH;
83 
84  auto candidates = std::make_unique<reco::PFCandidateCollection>();
85 
86  for (const auto& ticl_cand : ticl_candidates) {
87  const auto abs_pdg_id = std::abs(ticl_cand.pdgId());
88  const auto charge = ticl_cand.charge();
89  const auto& four_mom = ticl_cand.p4();
90  double ecal_energy = 0.;
91 
92  for (const auto& t : ticl_cand.tracksters()) {
93  double ecal_energy_fraction = t->raw_em_pt() / t->raw_pt();
94  ecal_energy += t->raw_energy() * ecal_energy_fraction;
95  }
96  double hcal_energy = ticl_cand.rawEnergy() - ecal_energy;
97  // fix for floating point rounding could go slightly below 0
98  hcal_energy = hcal_energy < 0 ? 0 : hcal_energy;
99 
101  switch (abs_pdg_id) {
102  case 11:
103  part_type = reco::PFCandidate::e;
104  break;
105  case 13:
106  part_type = reco::PFCandidate::mu;
107  break;
108  case 22:
109  part_type = reco::PFCandidate::gamma;
110  break;
111  case 130:
112  part_type = reco::PFCandidate::h0;
113  break;
114  case 211:
115  part_type = reco::PFCandidate::h;
116  break;
117  // default also handles neutral pions (111) for the time being (not yet foreseen in PFCandidate)
118  default:
119  part_type = reco::PFCandidate::X;
120  }
121 
122  candidates->emplace_back(charge, four_mom, part_type);
123 
124  auto& candidate = candidates->back();
125  candidate.setEcalEnergy(ecal_energy, ecal_energy);
126  candidate.setHcalEnergy(hcal_energy, hcal_energy);
127  if (candidate.charge()) { // otherwise PFCandidate throws
128  // Construct edm::Ref from edm::Ptr. As of now, assumes type to be reco::Track. To be extended (either via
129  // dynamic type checking or configuration) if additional track types are needed.
130  reco::TrackRef trackref(ticl_cand.trackPtr().id(), int(ticl_cand.trackPtr().key()), &evt.productGetter());
131  candidate.setTrackRef(trackref);
132  // Utilize PFMuonAlgo
133  const int muId = PFMuonAlgo::muAssocToTrack(trackref, muons);
134  if (muId != -1) {
135  const reco::MuonRef muonref = reco::MuonRef(muonH, muId);
136  const bool allowLoose = (part_type == reco::PFCandidate::mu);
137  // Redefine pfmuon candidate kinematics and add muonref
138  pfmu_->reconstructMuon(candidate, muonref, allowLoose);
139  }
140  }
141 
142  // HGCAL timing as default values
143  auto time = ticl_cand.time();
144  auto timeE = ticl_cand.timeError();
145 
146  if (candidate.charge()) {
147  // Ignore HGCAL timing until it will be TOF corrected
148  time = -99.;
149  timeE = -1.;
150  // Check MTD timing availability
151  const bool assocQuality = (*trackTimeQualH)[candidate.trackRef()] > timingQualityThreshold_;
152  if (assocQuality) {
153  const auto timeHGC = time;
154  const auto timeEHGC = timeE;
155  const auto timeMTD = (*trackTimeH)[candidate.trackRef()];
156  const auto timeEMTD = (*trackTimeErrH)[candidate.trackRef()];
157 
158  if (useTimingAverage_ && (timeEMTD > 0 && timeEHGC > 0)) {
159  // Compute weighted average between HGCAL and MTD timing
160  const auto invTimeESqHGC = pow(timeEHGC, -2);
161  const auto invTimeESqMTD = pow(timeEMTD, -2);
162  timeE = (invTimeESqHGC * invTimeESqMTD) / (invTimeESqHGC + invTimeESqMTD);
163  time = (timeHGC * invTimeESqHGC + timeMTD * invTimeESqMTD) * timeE;
164  timeE = sqrt(timeE);
165  } else if (timeEMTD > 0) { // Ignore HGCal timing until it will be TOF corrected
166  time = timeMTD;
167  timeE = timeEMTD;
168  }
169  }
170  }
171  candidate.setTime(time, timeE);
172  }
173 
174  evt.put(std::move(candidates));
175 }
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_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
const edm::EDGetTokenT< edm::ValueMap< float > > srcTrackTime_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ParameterSet const & getParameterSet(ParameterSetID const &id)
EDProductGetter const & productGetter() const
Definition: Event.cc:106
PFTICLProducer(const edm::ParameterSet &)
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
const edm::EDGetTokenT< edm::ValueMap< float > > srcTrackTimeError_
const edm::EDGetTokenT< edm::ValueMap< float > > srcTrackTimeQuality_
Handle< PROD > getHandle(EDGetTokenT< PROD > token) const
Definition: Event.h:563
const edm::EDGetTokenT< edm::View< TICLCandidate > > ticl_candidates_
T sqrt(T t)
Definition: SSEVec.h:19
def move
Definition: eostools.py:511
std::unique_ptr< PFMuonAlgo > pfmu_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
edm::Ref< MuonCollection > MuonRef
presistent reference to a Muon
Definition: MuonFwd.h:13
ParameterDescriptionBase * add(U const &iLabel, T const &value)
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
tuple muons
Definition: patZpeak.py:39
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
const edm::EDGetTokenT< reco::MuonCollection > muons_