CMS 3D CMS Logo

HiBadParticleCleaner.cc
Go to the documentation of this file.
1 // system include files
2 #include <memory>
3 
4 // user include files
7 
10 
12 
22 //
23 // class declaration
24 //
25 
27 public:
28  explicit HiBadParticleCleaner(const edm::ParameterSet&);
29  ~HiBadParticleCleaner() override = default;
30 
31 private:
32  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
33  // ----------member data ---------------------------
34 
37 
38  const double minMuonPt_;
39  const double minChargedHadronPt_;
40  const double minMuonTrackRelPtErr_;
41  const double maxSigLoose_;
42  const double maxSigTight_;
43  const double minCaloCompatibility_;
44  const unsigned minTrackNHits_;
45  const unsigned minPixelNHits_;
48 };
49 
50 //
51 // constructors and destructor
52 //
54  : tokenPFCandidates_(consumes<edm::View<reco::PFCandidate> >(iConfig.getParameter<edm::InputTag>("PFCandidates"))),
55  tokenPV_(consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("offlinePV"))),
56  minMuonPt_(iConfig.getParameter<double>("minMuonPt")),
57  minChargedHadronPt_(iConfig.getParameter<double>("minChargedHadronPt")),
58  minMuonTrackRelPtErr_(iConfig.getParameter<double>("minMuonTrackRelPtErr")),
59  maxSigLoose_(iConfig.getParameter<double>("maxSigLoose")),
60  maxSigTight_(iConfig.getParameter<double>("maxSigTight")),
61  minCaloCompatibility_(iConfig.getParameter<double>("minCaloCompatibility")),
62  minTrackNHits_(iConfig.getParameter<uint>("minTrackNHits")),
63  minPixelNHits_(iConfig.getParameter<uint>("minPixelNHits")),
64  minTrackerLayersForMuonLoose_(iConfig.getParameter<int>("minTrackerLayersForMuonLoose")),
65  minTrackerLayersForMuonTight_(iConfig.getParameter<int>("minTrackerLayersForMuonTight")) {
66  produces<bool>();
67  produces<reco::PFCandidateCollection>();
68  produces<reco::PFCandidateCollection>("removed");
69 }
70 
71 //
72 // member functions
73 //
74 
75 // ------------ method called on each new Event ------------
77  using namespace std;
78  using namespace edm;
79 
83 
84  const reco::VertexCollection* recoVertices;
86  iEvent.getByToken(tokenPV_, vertexCollection);
87  recoVertices = vertexCollection.product();
88 
89  auto pOutputCandidateCollection = std::make_unique<reco::PFCandidateCollection>();
90  auto pBadCandidateCollection = std::make_unique<reco::PFCandidateCollection>();
91 
92  bool foundBadCandidate = false;
93 
94  for (const reco::PFCandidate& pfCandidate : *pfCandidates) {
95  if (pfCandidate.particleId() == reco::PFCandidate::ParticleType::mu) // muon cleaning
96  {
97  if (pfCandidate.pt() > minMuonPt_) {
98  if (!pfCandidate.muonRef()->isGlobalMuon() || !pfCandidate.muonRef()->isTrackerMuon() ||
99  !pfCandidate.trackRef().isNonnull()) {
100  foundBadCandidate = true;
101  continue;
102  }
103  reco::TrackRef track = pfCandidate.trackRef();
104 
105  if (track->ptError() / track->pt() > minMuonTrackRelPtErr_ || track->pt() < pfCandidate.pt() / 2.) {
106  foundBadCandidate = true;
107  continue;
108  }
109 
112  track->originalAlgo() == reco::TrackBase::muonSeededStepInOut ||
113  track->originalAlgo() == reco::TrackBase::muonSeededStepOutIn ||
114  track->hitPattern().trackerLayersWithMeasurement() < minTrackerLayersForMuonLoose_) {
115  const reco::Vertex& vtx = (*recoVertices)[0];
116  float bestVzError = vtx.zError();
117  const math::XYZPoint& bestVtx(vtx.position());
118  math::Error<3>::type vtx_cov = vtx.covariance();
119  float dz = std::abs(track->dz(bestVtx));
120  float dxy = std::abs(track->dxy(bestVtx));
121  float dzError2 = track->dzError() * track->dzError() + bestVzError * bestVzError;
122  float dxyError = track->dxyError(bestVtx, vtx_cov);
123 
124  float dzSig2 = dz * dz / dzError2;
125  float dxySig2 = dxy * dxy / dxyError / dxyError;
126 
127  float sig3d = sqrt(dzSig2 + dxySig2);
128 
129  if (sig3d > maxSigLoose_) {
130  pBadCandidateCollection->push_back(pfCandidate);
131  foundBadCandidate = true;
132  continue;
133  }
134 
135  if (track->pt() < pfCandidate.pt() / 1.5 || track->pt() > pfCandidate.pt() * 1.5) {
136  foundBadCandidate = true;
137  pBadCandidateCollection->push_back(pfCandidate);
138  continue;
139  }
140  if (track->originalAlgo() == reco::TrackBase::muonSeededStepOutIn &&
141  track->hitPattern().trackerLayersWithMeasurement() < minTrackerLayersForMuonTight_) {
142  foundBadCandidate = true;
143  pBadCandidateCollection->push_back(pfCandidate);
144  continue;
145  }
146  }
147  }
148  } else if (pfCandidate.particleId() == reco::PFCandidate::ParticleType::h) //charged hadron cleaning
149  {
150  if (pfCandidate.pt() > minChargedHadronPt_) {
151  reco::TrackRef track = pfCandidate.trackRef();
152 
153  unsigned nHits = track->numberOfValidHits();
154  unsigned nPixelHits = track->hitPattern().numberOfValidPixelHits();
155 
156  if ((nHits < minTrackNHits_ && nPixelHits < minPixelNHits_) || nHits == 3) {
157  foundBadCandidate = true;
158  pBadCandidateCollection->push_back(pfCandidate);
159  continue;
160  }
161 
162  const reco::Vertex& vtx = (*recoVertices)[0];
163  float bestVzError = vtx.zError();
164  const math::XYZPoint& bestVtx(vtx.position());
165  math::Error<3>::type vtx_cov = vtx.covariance();
166  float dz = std::abs(track->dz(bestVtx));
167  float dxy = std::abs(track->dxy(bestVtx));
168  float dzError2 = track->dzError() * track->dzError() + bestVzError * bestVzError;
169  float dxyError = track->dxyError(bestVtx, vtx_cov);
170 
171  float dzSig2 = dz * dz / dzError2;
172  float dxySig2 = dxy * dxy / dxyError / dxyError;
173 
174  float sig3d = sqrt(dzSig2 + dxySig2);
175 
176  if (sig3d > maxSigLoose_) {
177  foundBadCandidate = true;
178  pBadCandidateCollection->push_back(pfCandidate);
179  continue;
180  }
181 
182  if (sig3d > maxSigTight_ && nHits < minTrackNHits_) {
183  foundBadCandidate = true;
184  pBadCandidateCollection->push_back(pfCandidate);
185  continue;
186  }
187 
190  track->originalAlgo() == reco::TrackBase::muonSeededStepInOut ||
191  track->originalAlgo() == reco::TrackBase::muonSeededStepOutIn) {
192  if (sig3d > maxSigLoose_) {
193  foundBadCandidate = true;
194  pBadCandidateCollection->push_back(pfCandidate);
195  continue;
196  }
197 
198  if (nHits < minTrackNHits_) {
199  foundBadCandidate = true;
200  pBadCandidateCollection->push_back(pfCandidate);
201  continue;
202  }
203  }
204 
205  double caloEnergy = pfCandidate.ecalEnergy() + pfCandidate.hcalEnergy();
206 
207  if (caloEnergy < track->p() * minCaloCompatibility_) {
208  if (sig3d > maxSigTight_) {
209  foundBadCandidate = true;
210  pBadCandidateCollection->push_back(pfCandidate);
211  continue;
212  }
213 
214  if (nHits < minTrackNHits_) {
215  foundBadCandidate = true;
216  pBadCandidateCollection->push_back(pfCandidate);
217  continue;
218  }
219 
220  if (nPixelHits < minPixelNHits_) {
221  foundBadCandidate = true;
222  pBadCandidateCollection->push_back(pfCandidate);
223  continue;
224  }
225  }
226  }
227  }
228 
229  pOutputCandidateCollection->push_back(pfCandidate);
230 
231  } // end loop over pf candidates
232 
233  bool pass = !foundBadCandidate;
234 
235  iEvent.put(std::move(pOutputCandidateCollection));
236  iEvent.put(std::move(pBadCandidateCollection), "removed");
237 
238  iEvent.put(std::make_unique<bool>(pass));
239 }
240 
241 //define this as a plug-in
HiBadParticleCleaner::minMuonPt_
const double minMuonPt_
Definition: HiBadParticleCleaner.cc:38
edm::StreamID
Definition: StreamID.h:30
zmumugammaAnalyzer_cfi.pfCandidates
pfCandidates
Definition: zmumugammaAnalyzer_cfi.py:11
reco::CandidateView
edm::View< Candidate > CandidateView
view of a collection containing candidates
Definition: CandidateFwd.h:23
HLT_FULL_cff.track
track
Definition: HLT_FULL_cff.py:11713
Muon.h
sistrip::View
View
Definition: ConstantsForView.h:26
HiBadParticleCleaner::minTrackerLayersForMuonLoose_
const int minTrackerLayersForMuonLoose_
Definition: HiBadParticleCleaner.cc:46
PFCandidate.h
amptDefaultParameters_cff.mu
mu
Definition: amptDefaultParameters_cff.py:16
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
h
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
Definition: L1TUtmAlgorithmRcd.h:4
reco::VertexCollection
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89287
HiBadParticleCleaner::minChargedHadronPt_
const double minChargedHadronPt_
Definition: HiBadParticleCleaner.cc:39
HiBadParticleCleaner::minPixelNHits_
const unsigned minPixelNHits_
Definition: HiBadParticleCleaner.cc:45
HiBadParticleCleaner::minTrackerLayersForMuonTight_
const int minTrackerLayersForMuonTight_
Definition: HiBadParticleCleaner.cc:47
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
edm::Handle
Definition: AssociativeIterator.h:50
parallelization.uint
uint
Definition: parallelization.py:124
HiBadParticleCleaner::HiBadParticleCleaner
HiBadParticleCleaner(const edm::ParameterSet &)
Definition: HiBadParticleCleaner.cc:53
edm::Ref< TrackCollection >
HiBadParticleCleaner::produce
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
Definition: HiBadParticleCleaner.cc:76
HiBadParticleCleaner::maxSigTight_
const double maxSigTight_
Definition: HiBadParticleCleaner.cc:42
pfElectronTranslator_cfi.PFCandidate
PFCandidate
Definition: pfElectronTranslator_cfi.py:6
MakerMacros.h
reco::TrackBase::muonSeededStepOutIn
Definition: TrackBase.h:104
Track.h
TrackFwd.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
MuonSelectors.h
MuonFwd.h
HiBadParticleCleaner::minTrackNHits_
const unsigned minTrackNHits_
Definition: HiBadParticleCleaner.cc:44
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
HiBadParticleCleaner
Definition: HiBadParticleCleaner.cc:26
HiBadParticleCleaner::minMuonTrackRelPtErr_
const double minMuonTrackRelPtErr_
Definition: HiBadParticleCleaner.cc:40
edm::global::EDProducer
Definition: EDProducer.h:32
Vertex.h
edm::View< reco::PFCandidate >
edm::ParameterSet
Definition: ParameterSet.h:47
math::XYZPoint
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
Event.h
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::EventSetup
Definition: EventSetup.h:57
reco::TrackBase::muonSeededStepInOut
Definition: TrackBase.h:103
VertexFwd.h
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
HiBadParticleCleaner::tokenPV_
edm::EDGetTokenT< reco::VertexCollection > tokenPV_
Definition: HiBadParticleCleaner.cc:36
PVValHelper::dxy
Definition: PVValidationHelpers.h:47
extraflags_cff.vtx
vtx
Definition: extraflags_cff.py:18
PVValHelper::dz
Definition: PVValidationHelpers.h:50
Frameworkfwd.h
spclusmultinvestigator_cfi.vertexCollection
vertexCollection
Definition: spclusmultinvestigator_cfi.py:4
math::Error::type
ErrorD< N >::type type
Definition: Error.h:32
reco::PFCandidate
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:41
HiBadParticleCleaner::tokenPFCandidates_
edm::EDGetTokenT< edm::View< reco::PFCandidate > > tokenPFCandidates_
Definition: HiBadParticleCleaner.cc:35
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ParameterSet.h
EDProducer.h
edm::Event
Definition: Event.h:73
HiBadParticleCleaner::~HiBadParticleCleaner
~HiBadParticleCleaner() override=default
HiBadParticleCleaner::maxSigLoose_
const double maxSigLoose_
Definition: HiBadParticleCleaner.cc:41
HiBadParticleCleaner::minCaloCompatibility_
const double minCaloCompatibility_
Definition: HiBadParticleCleaner.cc:43
reco::Vertex
Definition: Vertex.h:35
PFCandidateFwd.h