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 public:
19  ~PFTICLProducer() override {}
20 
21  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
22 
23  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
24 
25 private:
26  // parameters
27  const bool useTimingAverage_;
29 
30  // inputs
33 };
34 
36 
38  : useTimingAverage_(conf.getParameter<bool>("useTimingAverage")),
39  timingQualityThreshold_(conf.getParameter<double>("timingQualityThreshold")),
40  ticl_candidates_(consumes<edm::View<TICLCandidate>>(conf.getParameter<edm::InputTag>("ticlCandidateSrc"))),
41  srcTrackTime_(consumes<edm::ValueMap<float>>(conf.getParameter<edm::InputTag>("trackTimeValueMap"))),
42  srcTrackTimeError_(consumes<edm::ValueMap<float>>(conf.getParameter<edm::InputTag>("trackTimeErrorMap"))),
43  srcTrackTimeQuality_(consumes<edm::ValueMap<float>>(conf.getParameter<edm::InputTag>("trackTimeQualityMap"))) {
44  produces<reco::PFCandidateCollection>();
45 }
46 
49  desc.add<edm::InputTag>("ticlCandidateSrc", edm::InputTag("ticlTrackstersMerge"));
50  desc.add<edm::InputTag>("trackTimeValueMap", edm::InputTag("tofPID:t0"));
51  desc.add<edm::InputTag>("trackTimeErrorMap", edm::InputTag("tofPID:sigmat0"));
52  desc.add<edm::InputTag>("trackTimeQualityMap", edm::InputTag("mtdTrackQualityMVA:mtdQualMVA"));
53  desc.add<double>("timingQualityThreshold", 0.5);
54  desc.add<bool>("useTimingAverage", false);
55  descriptions.add("pfTICLProducer", desc);
56 }
57 
59  //get TICLCandidates
61  evt.getByToken(ticl_candidates_, ticl_cand_h);
62  const auto ticl_candidates = *ticl_cand_h;
63  edm::Handle<edm::ValueMap<float>> trackTimeH, trackTimeErrH, trackTimeQualH;
64  evt.getByToken(srcTrackTime_, trackTimeH);
65  evt.getByToken(srcTrackTimeError_, trackTimeErrH);
66  evt.getByToken(srcTrackTimeQuality_, trackTimeQualH);
67 
68  auto candidates = std::make_unique<reco::PFCandidateCollection>();
69 
70  for (const auto& ticl_cand : ticl_candidates) {
71  const auto abs_pdg_id = std::abs(ticl_cand.pdgId());
72  const auto charge = ticl_cand.charge();
73  const auto& four_mom = ticl_cand.p4();
74  double ecal_energy = 0.;
75 
76  for (const auto& t : ticl_cand.tracksters()) {
77  double ecal_energy_fraction = t->raw_em_pt() / t->raw_pt();
78  ecal_energy += t->raw_energy() * ecal_energy_fraction;
79  }
80  double hcal_energy = ticl_cand.rawEnergy() - ecal_energy;
81  // fix for floating point rounding could go slightly below 0
82  hcal_energy = hcal_energy < 0 ? 0 : hcal_energy;
83 
85  switch (abs_pdg_id) {
86  case 11:
87  part_type = reco::PFCandidate::e;
88  break;
89  case 13:
90  part_type = reco::PFCandidate::mu;
91  break;
92  case 22:
93  part_type = reco::PFCandidate::gamma;
94  break;
95  case 130:
96  part_type = reco::PFCandidate::h0;
97  break;
98  case 211:
99  part_type = reco::PFCandidate::h;
100  break;
101  // default also handles neutral pions (111) for the time being (not yet foreseen in PFCandidate)
102  default:
103  part_type = reco::PFCandidate::X;
104  }
105 
106  candidates->emplace_back(charge, four_mom, part_type);
107 
108  auto& candidate = candidates->back();
109  candidate.setEcalEnergy(ecal_energy, ecal_energy);
110  candidate.setHcalEnergy(hcal_energy, hcal_energy);
111  if (candidate.charge()) { // otherwise PFCandidate throws
112  // Construct edm::Ref from edm::Ptr. As of now, assumes type to be reco::Track. To be extended (either via
113  // dynamic type checking or configuration) if additional track types are needed.
114  reco::TrackRef ref(ticl_cand.trackPtr().id(), int(ticl_cand.trackPtr().key()), &evt.productGetter());
115  candidate.setTrackRef(ref);
116  }
117 
118  // HGCAL timing as default values
119  auto time = ticl_cand.time();
120  auto timeE = ticl_cand.timeError();
121 
122  if (candidate.charge()) {
123  // Ignore HGCAL timing until it will be TOF corrected
124  time = -99.;
125  timeE = -1.;
126  // Check MTD timing availability
127  const bool assocQuality = (*trackTimeQualH)[candidate.trackRef()] > timingQualityThreshold_;
128  if (assocQuality) {
129  const auto timeHGC = time;
130  const auto timeEHGC = timeE;
131  const auto timeMTD = (*trackTimeH)[candidate.trackRef()];
132  const auto timeEMTD = (*trackTimeErrH)[candidate.trackRef()];
133 
134  if (useTimingAverage_ && (timeEMTD > 0 && timeEHGC > 0)) {
135  // Compute weighted average between HGCAL and MTD timing
136  const auto invTimeESqHGC = pow(timeEHGC, -2);
137  const auto invTimeESqMTD = pow(timeEMTD, -2);
138  timeE = (invTimeESqHGC * invTimeESqMTD) / (invTimeESqHGC + invTimeESqMTD);
139  time = (timeHGC * invTimeESqHGC + timeMTD * invTimeESqMTD) * timeE;
140  timeE = sqrt(timeE);
141  } else if (timeEMTD > 0) { // Ignore HGCal timing until it will be TOF corrected
142  time = timeMTD;
143  timeE = timeEMTD;
144  }
145  }
146  }
147  candidate.setTime(time, timeE);
148  }
149 
150  evt.put(std::move(candidates));
151 }
edm::StreamID
Definition: StreamID.h:30
PFTICLProducer::srcTrackTime_
const edm::EDGetTokenT< edm::ValueMap< float > > srcTrackTime_
Definition: PFTICLProducer.cc:32
electrons_cff.bool
bool
Definition: electrons_cff.py:393
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
PFTICLProducer::useTimingAverage_
const bool useTimingAverage_
Definition: PFTICLProducer.cc:27
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:105
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89287
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
PFTICLProducer::PFTICLProducer
PFTICLProducer(const edm::ParameterSet &)
Definition: PFTICLProducer.cc:37
reco::PFCandidate::h
Definition: PFCandidate.h:46
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:31
PFTICLProducer::srcTrackTimeQuality_
const edm::EDGetTokenT< edm::ValueMap< float > > srcTrackTimeQuality_
Definition: PFTICLProducer.cc:32
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
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:531
PFTICLProducer::srcTrackTimeError_
const edm::EDGetTokenT< edm::ValueMap< float > > srcTrackTimeError_
Definition: PFTICLProducer.cc:32
edm::global::EDProducer
Definition: EDProducer.h:32
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
ALCARECOTkAlJpsiMuMu_cff.charge
charge
Definition: ALCARECOTkAlJpsiMuMu_cff.py:47
TICLCandidate.h
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
createfilelist.int
int
Definition: createfilelist.py:10
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::EventSetup
Definition: EventSetup.h:57
TICLCandidate
Definition: TICLCandidate.h:13
PFTICLProducer::produce
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
Definition: PFTICLProducer.cc:58
PFTICLProducer
Definition: PFTICLProducer.cc:16
PFTICLProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: PFTICLProducer.cc:47
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
Frameworkfwd.h
HLT_FULL_cff.candidates
candidates
Definition: HLT_FULL_cff.py:54985
reco::PFCandidate::h0
Definition: PFCandidate.h:50
PFTICLProducer::timingQualityThreshold_
const float timingQualityThreshold_
Definition: PFTICLProducer.cc:28
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
EDProducer.h
reco::PFCandidate::ParticleType
ParticleType
particle types
Definition: PFCandidate.h:44
ntuplemaker.time
time
Definition: ntuplemaker.py:310
edm::Event
Definition: Event.h:73
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
edm::InputTag
Definition: InputTag.h:15
PFTICLProducer::~PFTICLProducer
~PFTICLProducer() override
Definition: PFTICLProducer.cc:19
PFCandidateFwd.h