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_;
33  const bool isTICLv5_;
34  // inputs
38  // For PFMuonAlgo
39  std::unique_ptr<PFMuonAlgo> pfmu_;
40 };
41 
43 
45  : useMTDTiming_(conf.getParameter<bool>("useMTDTiming")),
46  useTimingAverage_(conf.getParameter<bool>("useTimingAverage")),
47  timingQualityThreshold_(conf.getParameter<double>("timingQualityThreshold")),
48  energy_from_regression_(conf.getParameter<bool>("energyFromRegression")),
49  isTICLv5_(conf.getParameter<bool>("isTICLv5")),
50  ticl_candidates_(consumes<edm::View<TICLCandidate>>(conf.getParameter<edm::InputTag>("ticlCandidateSrc"))),
51  muons_(consumes<reco::MuonCollection>(conf.getParameter<edm::InputTag>("muonSrc"))),
52  pfmu_(std::make_unique<PFMuonAlgo>(conf.getParameterSet("pfMuonAlgoParameters"),
53  false)) { // postMuonCleaning = false
54  if (not isTICLv5_) {
55  srcTrackTime_ = consumes<edm::ValueMap<float>>(conf.getParameter<edm::InputTag>("trackTimeValueMap"));
56  srcTrackTimeError_ = consumes<edm::ValueMap<float>>(conf.getParameter<edm::InputTag>("trackTimeErrorMap"));
57  srcTrackTimeQuality_ = consumes<edm::ValueMap<float>>(conf.getParameter<edm::InputTag>("trackTimeQualityMap"));
58  }
59  produces<reco::PFCandidateCollection>();
60 }
61 
64  desc.add<edm::InputTag>("ticlCandidateSrc", edm::InputTag("ticlTrackstersMerge"));
65  desc.add<edm::InputTag>("trackTimeValueMap", edm::InputTag("tofPID:t0"));
66  desc.add<edm::InputTag>("trackTimeErrorMap", edm::InputTag("tofPID:sigmat0"));
67  desc.add<edm::InputTag>("trackTimeQualityMap", edm::InputTag("mtdTrackQualityMVA:mtdQualMVA"));
68  desc.add<bool>("energyFromRegression", true);
69  desc.add<double>("timingQualityThreshold", 0.5);
70  desc.add<bool>("useMTDTiming", true);
71  desc.add<bool>("isTICLv5", false);
72  desc.add<bool>("useTimingAverage", false);
73  // For PFMuonAlgo
74  desc.add<edm::InputTag>("muonSrc", edm::InputTag("muons1stStep"));
75  edm::ParameterSetDescription psd_PFMuonAlgo;
76  PFMuonAlgo::fillPSetDescription(psd_PFMuonAlgo);
77  desc.add<edm::ParameterSetDescription>("pfMuonAlgoParameters", psd_PFMuonAlgo);
78  //
79  descriptions.add("pfTICLProducer", desc);
80 }
81 
83  //get TICLCandidates
85  evt.getByToken(ticl_candidates_, ticl_cand_h);
86  const auto ticl_candidates = *ticl_cand_h;
87  edm::Handle<edm::ValueMap<float>> trackTimeH, trackTimeErrH, trackTimeQualH;
88  if (not isTICLv5_) {
89  evt.getByToken(srcTrackTime_, trackTimeH);
90  evt.getByToken(srcTrackTimeError_, trackTimeErrH);
91  evt.getByToken(srcTrackTimeQuality_, trackTimeQualH);
92  }
93  const auto muonH = evt.getHandle(muons_);
94  const auto& muons = *muonH;
95 
96  auto candidates = std::make_unique<reco::PFCandidateCollection>();
97 
98  for (const auto& ticl_cand : ticl_candidates) {
99  const auto abs_pdg_id = std::abs(ticl_cand.pdgId());
100  const auto charge = ticl_cand.charge();
101  const auto& four_mom = ticl_cand.p4();
102  float total_raw_energy = 0.f;
103  float total_em_raw_energy = 0.f;
104  for (const auto& t : ticl_cand.tracksters()) {
105  total_raw_energy += t->raw_energy();
106  total_em_raw_energy += t->raw_em_energy();
107  }
108  float ecal_energy_fraction = total_em_raw_energy / total_raw_energy;
109  float ecal_energy = energy_from_regression_ ? ticl_cand.p4().energy() * ecal_energy_fraction
110  : ticl_cand.rawEnergy() * ecal_energy_fraction;
111  float hcal_energy =
112  energy_from_regression_ ? ticl_cand.p4().energy() - ecal_energy : ticl_cand.rawEnergy() - ecal_energy;
113  // fix for floating point rounding could go slightly below 0
114  hcal_energy = std::max(0.f, hcal_energy);
116  switch (abs_pdg_id) {
117  case 11:
118  part_type = reco::PFCandidate::e;
119  break;
120  case 13:
121  part_type = reco::PFCandidate::mu;
122  break;
123  case 22:
124  part_type = reco::PFCandidate::gamma;
125  break;
126  case 130:
127  part_type = reco::PFCandidate::h0;
128  break;
129  case 211:
130  part_type = reco::PFCandidate::h;
131  break;
132  // default also handles neutral pions (111) for the time being (not yet foreseen in PFCandidate)
133  default:
134  part_type = reco::PFCandidate::X;
135  }
136 
137  candidates->emplace_back(charge, four_mom, part_type);
138 
139  auto& candidate = candidates->back();
140  candidate.setEcalEnergy(ecal_energy, ecal_energy);
141  candidate.setHcalEnergy(hcal_energy, hcal_energy);
142  if (candidate.charge()) { // otherwise PFCandidate throws
143  // Construct edm::Ref from edm::Ptr. As of now, assumes type to be reco::Track. To be extended (either via
144  // dynamic type checking or configuration) if additional track types are needed.
145  reco::TrackRef trackref(ticl_cand.trackPtr().id(), int(ticl_cand.trackPtr().key()), &evt.productGetter());
146  candidate.setTrackRef(trackref);
147  // Utilize PFMuonAlgo
148  const int muId = PFMuonAlgo::muAssocToTrack(trackref, muons);
149  if (isTICLv5_) {
150  if (muId != -1) {
151  const reco::MuonRef muonref = reco::MuonRef(muonH, muId);
152  if ((PFMuonAlgo::isMuon(muonref) and not(*muonH)[muId].isTrackerMuon()) or
153  (ticl_cand.tracksters().empty() and muonref.isNonnull() and muonref->isGlobalMuon())) {
154  const bool allowLoose = (part_type == reco::PFCandidate::mu);
155  // Redefine pfmuon candidate kinematics and add muonref
156  pfmu_->reconstructMuon(candidate, muonref, allowLoose);
157  }
158  }
159  } else {
160  if (muId != -1) {
161  const reco::MuonRef muonref = reco::MuonRef(muonH, muId);
162  const bool allowLoose = (part_type == reco::PFCandidate::mu);
163  // Redefine pfmuon candidate kinematics and add muonref
164  pfmu_->reconstructMuon(candidate, muonref, allowLoose);
165  }
166  }
167  }
168 
169  if (isTICLv5_) {
170  candidate.setTime(ticl_cand.time(), ticl_cand.timeError());
171  } else {
172  // HGCAL timing as default values
173  auto time = ticl_cand.time();
174  auto timeE = ticl_cand.timeError();
175 
176  if (useMTDTiming_ and candidate.charge()) {
177  // Ignore HGCAL timing until it will be TOF corrected
178  time = -99.;
179  timeE = -1.;
180  // Check MTD timing availability
181  const bool assocQuality = (*trackTimeQualH)[candidate.trackRef()] > timingQualityThreshold_;
182  if (assocQuality) {
183  const auto timeHGC = time;
184  const auto timeEHGC = timeE;
185  const auto timeMTD = (*trackTimeH)[candidate.trackRef()];
186  const auto timeEMTD = (*trackTimeErrH)[candidate.trackRef()];
187 
188  if (useTimingAverage_ && (timeEMTD > 0 && timeEHGC > 0)) {
189  // Compute weighted average between HGCAL and MTD timing
190  const auto invTimeESqHGC = pow(timeEHGC, -2);
191  const auto invTimeESqMTD = pow(timeEMTD, -2);
192  timeE = 1.f / (invTimeESqHGC + invTimeESqMTD);
193  time = (timeHGC * invTimeESqHGC + timeMTD * invTimeESqMTD) * timeE;
194  timeE = sqrt(timeE);
195  } else if (timeEMTD > 0) { // Ignore HGCal timing until it will be TOF corrected
196  time = timeMTD;
197  timeE = timeEMTD;
198  }
199  }
200  }
201  candidate.setTime(time, timeE);
202  }
203  }
204 
205  evt.put(std::move(candidates));
206 }
static int muAssocToTrack(const reco::TrackRef &trackref, const reco::MuonCollection &muons)
Definition: PFMuonAlgo.cc:479
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
const bool energy_from_regression_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
ParticleType
particle types
Definition: PFCandidate.h:44
edm::EDGetTokenT< edm::ValueMap< float > > srcTrackTimeError_
~PFTICLProducer() override
const bool useTimingAverage_
static bool isMuon(const reco::PFBlockElement &elt)
Definition: PFMuonAlgo.cc:48
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:526
PFTICLProducer(const edm::ParameterSet &)
muons
the two sets of parameters below are mutually exclusive, depending if RECO or ALCARECO is used the us...
Definition: DiMuonV_cfg.py:214
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
EDProductGetter const & productGetter() const
Definition: Event.cc:106
const bool isTICLv5_
edm::EDGetTokenT< edm::ValueMap< float > > srcTrackTimeQuality_
const edm::EDGetTokenT< edm::View< TICLCandidate > > ticl_candidates_
T sqrt(T t)
Definition: SSEVec.h:23
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
std::unique_ptr< PFMuonAlgo > pfmu_
const bool useMTDTiming_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
edm::Ref< MuonCollection > MuonRef
presistent reference to a Muon
Definition: MuonFwd.h:13
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< edm::ValueMap< float > > srcTrackTime_
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:550
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_