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 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 }
PDWG_BPHSkim_cff.muons
muons
Definition: PDWG_BPHSkim_cff.py:47
PFTICLProducer::srcTrackTime_
const edm::EDGetTokenT< edm::ValueMap< float > > srcTrackTime_
Definition: PFTICLProducer.cc:34
electrons_cff.bool
bool
Definition: electrons_cff.py:366
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
PFMuonAlgo.h
PFTICLProducer::useTimingAverage_
const bool useTimingAverage_
Definition: PFTICLProducer.cc:29
funct::false
false
Definition: Factorize.h:29
reco::PFCandidate::e
Definition: PFCandidate.h:47
sistrip::View
View
Definition: ConstantsForView.h:26
PFCandidate.h
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::Event::productGetter
EDProductGetter const & productGetter() const
Definition: Event.cc:106
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89285
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
PFTICLProducer::PFTICLProducer
PFTICLProducer(const edm::ParameterSet &)
Definition: PFTICLProducer.cc:42
reco::PFCandidate::h
Definition: PFCandidate.h:46
protons_cff.time
time
Definition: protons_cff.py:39
EDProducer.h
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
edm::Handle
Definition: AssociativeIterator.h:50
reco::PFCandidate::X
Definition: PFCandidate.h:45
edm::Ref< TrackCollection >
MakerMacros.h
PFTICLProducer::ticl_candidates_
const edm::EDGetTokenT< edm::View< TICLCandidate > > ticl_candidates_
Definition: PFTICLProducer.cc:33
PFTICLProducer::srcTrackTimeQuality_
const edm::EDGetTokenT< edm::ValueMap< float > > srcTrackTimeQuality_
Definition: PFTICLProducer.cc:34
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
reco::PFCandidate::mu
Definition: PFCandidate.h:48
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
reco::MuonCollection
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
reco::MuonRef
edm::Ref< MuonCollection > MuonRef
presistent reference to a Muon
Definition: MuonFwd.h:13
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:535
PFTICLProducer::srcTrackTimeError_
const edm::EDGetTokenT< edm::ValueMap< float > > srcTrackTimeError_
Definition: PFTICLProducer.cc:34
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
ALCARECOTkAlJpsiMuMu_cff.charge
charge
Definition: ALCARECOTkAlJpsiMuMu_cff.py:47
PFMuonAlgo
Definition: PFMuonAlgo.h:13
TICLCandidate.h
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
createfilelist.int
int
Definition: createfilelist.py:10
PFTICLProducer::pfmu_
std::unique_ptr< PFMuonAlgo > pfmu_
Definition: PFTICLProducer.cc:37
edm::Event::put
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
reco::PFCandidate::gamma
Definition: PFCandidate.h:49
edm::stream::EDProducer
Definition: EDProducer.h:38
PFTICLProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: PFTICLProducer.cc:72
edm::EventSetup
Definition: EventSetup.h:58
TICLCandidate
Definition: TICLCandidate.h:13
PFTICLProducer
Definition: PFTICLProducer.cc:18
PFTICLProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: PFTICLProducer.cc:55
edm::getParameterSet
ParameterSet const & getParameterSet(ParameterSetID const &id)
Definition: ParameterSet.cc:862
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
PFMuonAlgo::muAssocToTrack
static int muAssocToTrack(const reco::TrackRef &trackref, const reco::MuonCollection &muons)
Definition: PFMuonAlgo.cc:479
Frameworkfwd.h
HLT_FULL_cff.candidates
candidates
Definition: HLT_FULL_cff.py:54996
reco::PFCandidate::h0
Definition: PFCandidate.h:50
PFTICLProducer::timingQualityThreshold_
const float timingQualityThreshold_
Definition: PFTICLProducer.cc:30
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
View.h
PFTICLProducer::muons_
const edm::EDGetTokenT< reco::MuonCollection > muons_
Definition: PFTICLProducer.cc:35
reco::PFCandidate::ParticleType
ParticleType
particle types
Definition: PFCandidate.h:44
edm::Event
Definition: Event.h:73
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
PFMuonAlgo::fillPSetDescription
static void fillPSetDescription(edm::ParameterSetDescription &iDesc)
Definition: PFMuonAlgo.cc:1043
edm::Event::getHandle
Handle< PROD > getHandle(EDGetTokenT< PROD > token) const
Definition: Event.h:559
edm::InputTag
Definition: InputTag.h:15
PFTICLProducer::~PFTICLProducer
~PFTICLProducer() override
Definition: PFTICLProducer.cc:21
PFCandidateFwd.h