CMS 3D CMS Logo

PATMuonSlimmer.cc
Go to the documentation of this file.
1 
10 
14 
22 
23 namespace pat {
24 
26  public:
27  explicit PATMuonSlimmer(const edm::ParameterSet &iConfig);
28  ~PATMuonSlimmer() override {}
29 
30  void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override;
31  void beginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) final;
32 
33  private:
35  std::vector<edm::EDGetTokenT<reco::PFCandidateCollection>> pf_;
36  std::vector<edm::EDGetTokenT<edm::Association<pat::PackedCandidateCollection>>> pf2pc_;
37  const bool linkToPackedPF_;
41  std::unique_ptr<pat::ObjectModifier<pat::Muon>> muonModifier_;
42  };
43 
44 } // namespace pat
45 
47  : src_(consumes<pat::MuonCollection>(iConfig.getParameter<edm::InputTag>("src"))),
48  linkToPackedPF_(iConfig.getParameter<bool>("linkToPackedPFCandidates")),
49  saveTeVMuons_(iConfig.getParameter<std::string>("saveTeVMuons")),
50  dropDirectionalIso_(iConfig.getParameter<std::string>("dropDirectionalIso")),
51  dropPfP4_(iConfig.getParameter<std::string>("dropPfP4")),
52  slimCaloVars_(iConfig.getParameter<std::string>("slimCaloVars")),
53  slimKinkVars_(iConfig.getParameter<std::string>("slimKinkVars")),
54  slimCaloMETCorr_(iConfig.getParameter<std::string>("slimCaloMETCorr")),
55  slimMatches_(iConfig.getParameter<std::string>("slimMatches")),
56  segmentsMuonSelection_(iConfig.getParameter<std::string>("segmentsMuonSelection")),
57  saveSegments_(iConfig.getParameter<bool>("saveSegments")),
58  modifyMuon_(iConfig.getParameter<bool>("modifyMuons")) {
59  if (linkToPackedPF_) {
60  const std::vector<edm::InputTag> &pf = iConfig.getParameter<std::vector<edm::InputTag>>("pfCandidates");
61  const std::vector<edm::InputTag> &pf2pc = iConfig.getParameter<std::vector<edm::InputTag>>("packedPFCandidates");
62  if (pf.size() != pf2pc.size())
63  throw cms::Exception("Configuration") << "Mismatching pfCandidates and packedPFCandidates\n";
64  for (const edm::InputTag &tag : pf)
65  pf_.push_back(consumes<reco::PFCandidateCollection>(tag));
66  for (const edm::InputTag &tag : pf2pc)
68  }
69 
70  if (modifyMuon_) {
71  const edm::ParameterSet &mod_config = iConfig.getParameter<edm::ParameterSet>("modifierConfig");
72  muonModifier_ = std::make_unique<pat::ObjectModifier<pat::Muon>>(mod_config, consumesCollector());
73  }
74  produces<std::vector<pat::Muon>>();
75  if (saveSegments_) {
76  produces<DTRecSegment4DCollection>();
77  produces<CSCSegmentCollection>();
78  }
79 }
80 
82  if (modifyMuon_)
83  muonModifier_->setEventContent(iSetup);
84 }
85 
87  using namespace edm;
88  using namespace std;
89 
91  iEvent.getByToken(src_, src);
92 
93  auto out = std::make_unique<std::vector<pat::Muon>>();
94  out->reserve(src->size());
95 
96  auto outDTSegments = std::make_unique<DTRecSegment4DCollection>();
97  std::set<DTRecSegment4DRef> dtSegmentsRefs;
98  auto outCSCSegments = std::make_unique<CSCSegmentCollection>();
99  std::set<CSCSegmentRef> cscSegmentsRefs;
100 
101  if (modifyMuon_) {
102  muonModifier_->setEvent(iEvent);
103  }
104 
105  std::map<reco::CandidatePtr, pat::PackedCandidateRef> mu2pc;
106  if (linkToPackedPF_) {
109  for (unsigned int ipfh = 0, npfh = pf_.size(); ipfh < npfh; ++ipfh) {
110  iEvent.getByToken(pf_[ipfh], pf);
111  iEvent.getByToken(pf2pc_[ipfh], pf2pc);
112  const auto &pfcoll = (*pf);
113  const auto &pfmap = (*pf2pc);
114  for (unsigned int i = 0, n = pf->size(); i < n; ++i) {
115  const reco::PFCandidate &p = pfcoll[i];
116  if (p.muonRef().isNonnull())
117  mu2pc[refToPtr(p.muonRef())] = pfmap[reco::PFCandidateRef(pf, i)];
118  }
119  }
120  }
121 
122  for (vector<pat::Muon>::const_iterator it = src->begin(), ed = src->end(); it != ed; ++it) {
123  out->push_back(*it);
124  pat::Muon &mu = out->back();
125 
126  if (modifyMuon_) {
127  muonModifier_->modify(mu);
128  }
129 
130  if (saveTeVMuons_(mu)) {
131  mu.embedPickyMuon();
132  mu.embedTpfmsMuon();
133  mu.embedDytMuon();
134  }
135  if (linkToPackedPF_) {
136  mu.refToOrig_ = refToPtr(mu2pc[mu.refToOrig_]);
137  }
138  if (dropDirectionalIso_(mu)) {
140  mu.setPFIsolation("pfIsoMeanDRProfileR03", zero);
141  mu.setPFIsolation("pfIsoSumDRProfileR03", zero);
142  mu.setPFIsolation("pfIsoMeanDRProfileR04", zero);
143  mu.setPFIsolation("pfIsoSumDRProfileR04", zero);
144  }
145  if (mu.isPFMuon() && dropPfP4_(mu))
147  if (slimCaloVars_(mu) && mu.isEnergyValid()) {
148  reco::MuonEnergy ene = mu.calEnergy();
149  if (ene.tower)
150  ene.tower = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(ene.tower);
151  if (ene.towerS9)
152  ene.towerS9 = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(ene.towerS9);
153  if (ene.had)
154  ene.had = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(ene.had);
155  if (ene.hadS9)
156  ene.hadS9 = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(ene.hadS9);
157  if (ene.hadMax)
158  ene.hadMax = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(ene.hadMax);
159  if (ene.em)
160  ene.em = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(ene.em);
161  if (ene.emS25)
162  ene.emS25 = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(ene.emS25);
163  if (ene.emMax)
164  ene.emMax = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(ene.emMax);
165  if (ene.hcal_time)
166  ene.hcal_time = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(ene.hcal_time);
167  if (ene.hcal_timeError)
168  ene.hcal_timeError = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(ene.hcal_timeError);
169  if (ene.ecal_time)
170  ene.ecal_time = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(ene.ecal_time);
171  if (ene.ecal_timeError)
172  ene.ecal_timeError = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(ene.ecal_timeError);
173  ene.ecal_position = math::XYZPointF(MiniFloatConverter::reduceMantissaToNbitsRounding<14>(ene.ecal_position.X()),
174  MiniFloatConverter::reduceMantissaToNbitsRounding<14>(ene.ecal_position.Y()),
175  MiniFloatConverter::reduceMantissaToNbitsRounding<14>(ene.ecal_position.Z()));
176  ene.hcal_position = math::XYZPointF(MiniFloatConverter::reduceMantissaToNbitsRounding<12>(ene.hcal_position.X()),
177  MiniFloatConverter::reduceMantissaToNbitsRounding<12>(ene.hcal_position.Y()),
178  MiniFloatConverter::reduceMantissaToNbitsRounding<12>(ene.hcal_position.Z()));
179  mu.setCalEnergy(ene);
180  }
181  if (slimKinkVars_(mu) && mu.isQualityValid()) {
182  reco::MuonQuality qual = mu.combinedQuality();
183  qual.tkKink_position =
184  math::XYZPointF(MiniFloatConverter::reduceMantissaToNbitsRounding<12>(qual.tkKink_position.X()),
185  MiniFloatConverter::reduceMantissaToNbitsRounding<12>(qual.tkKink_position.Y()),
186  MiniFloatConverter::reduceMantissaToNbitsRounding<12>(qual.tkKink_position.Z()));
187  mu.setCombinedQuality(qual);
188  }
189  if (slimCaloMETCorr_(mu) && mu.caloMETMuonCorrs().type() != reco::MuonMETCorrectionData::NotUsed) {
190  reco::MuonMETCorrectionData corrs = mu.caloMETMuonCorrs();
191  corrs = reco::MuonMETCorrectionData(corrs.type(),
192  MiniFloatConverter::reduceMantissaToNbitsRounding<10>(corrs.corrX()),
193  MiniFloatConverter::reduceMantissaToNbitsRounding<10>(corrs.corrY()));
194  mu.embedCaloMETMuonCorrs(corrs);
195  }
196  if (slimMatches_(mu) && mu.isMatchesValid()) {
197  for (reco::MuonChamberMatch &cmatch : mu.matches()) {
198  cmatch.edgeX = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(cmatch.edgeX);
199  cmatch.edgeY = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(cmatch.edgeY);
200  cmatch.xErr = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(cmatch.xErr);
201  cmatch.yErr = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(cmatch.yErr);
202  cmatch.dXdZErr = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(cmatch.dXdZErr);
203  cmatch.dYdZErr = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(cmatch.dYdZErr);
204  for (reco::MuonSegmentMatch &smatch : cmatch.segmentMatches) {
205  smatch.xErr = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(smatch.xErr);
206  smatch.yErr = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(smatch.yErr);
207  smatch.dXdZErr = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(smatch.dXdZErr);
208  smatch.dYdZErr = MiniFloatConverter::reduceMantissaToNbitsRounding<12>(smatch.dYdZErr);
209  if (saveSegments_ && segmentsMuonSelection_(mu)) {
210  if (smatch.dtSegmentRef.isNonnull())
211  dtSegmentsRefs.insert(smatch.dtSegmentRef);
212  if (smatch.cscSegmentRef.isNonnull())
213  cscSegmentsRefs.insert(smatch.cscSegmentRef);
214  }
215  }
216  }
217  }
218  }
219 
220  if (saveSegments_) {
221  std::map<DTRecSegment4DRef, size_t> dtMap;
222  std::vector<DTRecSegment4D> outDTSegmentsTmp;
223  std::map<CSCSegmentRef, size_t> cscMap;
224  std::vector<CSCSegment> outCSCSegmentsTmp;
225  for (auto &seg : dtSegmentsRefs) {
226  dtMap[seg] = outDTSegments->size();
227  outDTSegmentsTmp.push_back(*seg);
228  }
229  for (auto &seg : cscSegmentsRefs) {
230  cscMap[seg] = outCSCSegments->size();
231  outCSCSegmentsTmp.push_back(*seg);
232  }
233  outDTSegments->put(DTChamberId(), outDTSegmentsTmp.begin(), outDTSegmentsTmp.end());
234  outCSCSegments->put(CSCDetId(), outCSCSegmentsTmp.begin(), outCSCSegmentsTmp.end());
235  auto dtHandle = iEvent.put(std::move(outDTSegments));
236  auto cscHandle = iEvent.put(std::move(outCSCSegments));
237  for (auto &mu : *out) {
238  if (mu.isMatchesValid()) {
239  for (reco::MuonChamberMatch &cmatch : mu.matches()) {
240  for (reco::MuonSegmentMatch &smatch : cmatch.segmentMatches) {
241  if (dtMap.find(smatch.dtSegmentRef) != dtMap.end())
242  smatch.dtSegmentRef = DTRecSegment4DRef(dtHandle, dtMap[smatch.dtSegmentRef]);
243  if (cscMap.find(smatch.cscSegmentRef) != cscMap.end())
244  smatch.cscSegmentRef = CSCSegmentRef(cscHandle, cscMap[smatch.cscSegmentRef]);
245  }
246  }
247  }
248  }
249  }
250  iEvent.put(std::move(out));
251 }
252 
254 using namespace pat;
pat::PATMuonSlimmer::slimMatches_
const StringCutObjectSelector< pat::Muon > slimMatches_
Definition: PATMuonSlimmer.cc:38
reco::MuonEnergy
Definition: MuonEnergy.h:17
reco::MuonEnergy::ecal_time
float ecal_time
Calorimeter timing.
Definition: MuonEnergy.h:47
ObjectModifier.h
electrons_cff.bool
bool
Definition: electrons_cff.py:372
mps_fire.i
i
Definition: mps_fire.py:355
pat::PATMuonSlimmer::saveSegments_
const bool saveSegments_
Definition: PATMuonSlimmer.cc:40
reco::MuonQuality
Definition: MuonQuality.h:6
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
StringCutObjectSelector.h
reco::MuonEnergy::hcal_position
math::XYZPointF hcal_position
Definition: MuonEnergy.h:54
reco::MuonMETCorrectionData::type
Type type()
Definition: MuonMETCorrectionData.h:25
PFCandidate.h
edm::LuminosityBlock
Definition: LuminosityBlock.h:50
amptDefaultParameters_cff.mu
mu
Definition: amptDefaultParameters_cff.py:16
edm::EDGetTokenT< pat::MuonCollection >
pat::PATMuonSlimmer::slimKinkVars_
const StringCutObjectSelector< pat::Muon > slimKinkVars_
Definition: PATMuonSlimmer.cc:38
edm
HLT enums.
Definition: AlignableModifier.h:19
Muon.h
pat::PATMuonSlimmer::pf_
std::vector< edm::EDGetTokenT< reco::PFCandidateCollection > > pf_
Definition: PATMuonSlimmer.cc:35
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
pat::PATMuonSlimmer::modifyMuon_
const bool modifyMuon_
Definition: PATMuonSlimmer.cc:40
pat::PATMuonSlimmer::~PATMuonSlimmer
~PATMuonSlimmer() override
Definition: PATMuonSlimmer.cc:28
EDProducer.h
reco::MuonEnergy::had
float had
Definition: MuonEnergy.h:36
reco::MuonEnergy::hcal_time
float hcal_time
Definition: MuonEnergy.h:49
pat::Muon
Analysis-level muon class.
Definition: Muon.h:51
reco::MuonEnergy::hadS9
float hadS9
energy deposited in 3x3 HCAL tower shape around central tower
Definition: MuonEnergy.h:38
Association.h
pat::PATMuonSlimmer::src_
const edm::EDGetTokenT< pat::MuonCollection > src_
Definition: PATMuonSlimmer.cc:34
reco::MuonSegmentMatch::dtSegmentRef
DTRecSegment4DRef dtSegmentRef
Definition: MuonSegmentMatch.h:50
edm::Handle
Definition: AssociativeIterator.h:50
reco::MuonSegmentMatch::xErr
float xErr
Definition: MuonSegmentMatch.h:36
reco::MuonEnergy::tower
float tower
Definition: MuonEnergy.h:20
reco::Particle::LorentzVector
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:21
edm::Ref< PFCandidateCollection >
reco::MuonSegmentMatch::cscSegmentRef
CSCSegmentRef cscSegmentRef
Definition: MuonSegmentMatch.h:51
edm::refToPtr
Ptr< typename C::value_type > refToPtr(Ref< C, typename C::value_type, refhelper::FindUsingAdvance< C, typename C::value_type > > const &ref)
Definition: RefToPtr.h:18
MakerMacros.h
reco::MuonSegmentMatch
Definition: MuonSegmentMatch.h:12
libminifloat.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
pat::PATMuonSlimmer::saveTeVMuons_
const StringCutObjectSelector< pat::Muon > saveTeVMuons_
Definition: PATMuonSlimmer.cc:38
GlobalPosition_Frontier_DevDB_cff.tag
tag
Definition: GlobalPosition_Frontier_DevDB_cff.py:11
pat::PATMuonSlimmer::slimCaloMETCorr_
const StringCutObjectSelector< pat::Muon > slimCaloMETCorr_
Definition: PATMuonSlimmer.cc:38
pat::PATMuonSlimmer::PATMuonSlimmer
PATMuonSlimmer(const edm::ParameterSet &iConfig)
Definition: PATMuonSlimmer.cc:46
pat::PATMuonSlimmer::linkToPackedPF_
const bool linkToPackedPF_
Definition: PATMuonSlimmer.cc:37
pat::MuonCollection
std::vector< Muon > MuonCollection
Definition: Muon.h:35
reco::MuonMETCorrectionData::NotUsed
Definition: MuonMETCorrectionData.h:10
pat::PATMuonSlimmer::beginLuminosityBlock
void beginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) final
Definition: PATMuonSlimmer.cc:81
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
reco::MuonEnergy::emS25
float emS25
energy deposited in 5x5 ECAL crystal shape around central crystal
Definition: MuonEnergy.h:30
pat::PATMuonSlimmer::dropPfP4_
const StringCutObjectSelector< pat::Muon > dropPfP4_
Definition: PATMuonSlimmer.cc:38
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::ParameterSet
Definition: ParameterSet.h:36
TrackRefitter_38T_cff.src
src
Definition: TrackRefitter_38T_cff.py:24
Event.h
reco::MuonEnergy::hcal_timeError
float hcal_timeError
Definition: MuonEnergy.h:50
pat::PATMuonSlimmer::dropDirectionalIso_
const StringCutObjectSelector< pat::Muon > dropDirectionalIso_
Definition: PATMuonSlimmer.cc:38
reco::MuonEnergy::hadMax
float hadMax
maximal energy of HCAL tower in the 3x3 shape
Definition: MuonEnergy.h:40
PackedCandidate.h
edm::Ref::isNonnull
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
CSCDetId
Definition: CSCDetId.h:26
iEvent
int iEvent
Definition: GenABIO.cc:224
reco::MuonEnergy::towerS9
float towerS9
total energy in 3x3 tower shape
Definition: MuonEnergy.h:22
RefToPtr.h
edm::stream::EDProducer
Definition: EDProducer.h:38
edm::Association
Definition: Association.h:18
edm::EventSetup
Definition: EventSetup.h:57
pat
Definition: HeavyIon.h:7
reco::MuonChamberMatch
Definition: MuonChamberMatch.h:10
reco::MuonQuality::tkKink_position
math::XYZPoint tkKink_position
Kink position for the tracker stub and global track.
Definition: MuonQuality.h:32
pat::PATMuonSlimmer::produce
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
Definition: PATMuonSlimmer.cc:86
reco::MuonEnergy::ecal_timeError
float ecal_timeError
Definition: MuonEnergy.h:48
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
reco::MuonPFIsolation
Definition: MuonPFIsolation.h:5
pat::PATMuonSlimmer::pf2pc_
std::vector< edm::EDGetTokenT< edm::Association< pat::PackedCandidateCollection > > > pf2pc_
Definition: PATMuonSlimmer.cc:36
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
pat::PATMuonSlimmer::slimCaloVars_
const StringCutObjectSelector< pat::Muon > slimCaloVars_
Definition: PATMuonSlimmer.cc:38
reco::MuonEnergy::emMax
float emMax
maximal energy of ECAL crystal in the 5x5 shape
Definition: MuonEnergy.h:32
Frameworkfwd.h
packedPFCandidateRefMixer_cfi.pf
pf
Definition: packedPFCandidateRefMixer_cfi.py:4
StringCutObjectSelector< pat::Muon >
reco::MuonMETCorrectionData::corrY
float corrY()
Definition: MuonMETCorrectionData.h:27
reco::MuonMETCorrectionData::corrX
float corrX()
Definition: MuonMETCorrectionData.h:26
pat::PATMuonSlimmer::segmentsMuonSelection_
const StringCutObjectSelector< pat::Muon > segmentsMuonSelection_
Definition: PATMuonSlimmer.cc:38
reco::MuonSegmentMatch::yErr
float yErr
Definition: MuonSegmentMatch.h:37
reco::MuonEnergy::ecal_position
math::XYZPointF ecal_position
Trajectory position at the calorimeter.
Definition: MuonEnergy.h:53
reco::PFCandidate
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:40
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
cms::Exception
Definition: Exception.h:70
pat::PATMuonSlimmer
Slimmer of PAT Muons.
Definition: PATMuonSlimmer.cc:25
DTChamberId
Definition: DTChamberId.h:14
View.h
ParameterSet.h
reco::MuonMETCorrectionData
Definition: MuonMETCorrectionData.h:7
reco::MuonSegmentMatch::dXdZErr
float dXdZErr
Definition: MuonSegmentMatch.h:40
math::XYZPointF
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< float > > XYZPointF
point in space with cartesian internal representation
Definition: Point3D.h:10
edm::Event
Definition: Event.h:73
reco::MuonEnergy::em
float em
Definition: MuonEnergy.h:26
edm::InputTag
Definition: InputTag.h:15
PFCandidateFwd.h
pat::PATMuonSlimmer::muonModifier_
std::unique_ptr< pat::ObjectModifier< pat::Muon > > muonModifier_
Definition: PATMuonSlimmer.cc:41
reco::MuonSegmentMatch::dYdZErr
float dYdZErr
Definition: MuonSegmentMatch.h:41