CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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;
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 
110  if (track->algo() == reco::TrackBase::muonSeededStepInOut ||
111  track->algo() == reco::TrackBase::muonSeededStepOutIn ||
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 
188  if (track->algo() == reco::TrackBase::muonSeededStepInOut ||
189  track->algo() == reco::TrackBase::muonSeededStepOutIn ||
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
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
HiBadParticleCleaner(const edm::ParameterSet &)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
double zError() const
error on z
Definition: Vertex.h:141
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< reco::VertexCollection > tokenPV_
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
ErrorD< N >::type type
Definition: Error.h:32
double covariance(int i, int j) const
(i, j)-th element of error matrix, i, j = 0, ... 2
Definition: Vertex.h:148
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
std::vector< Vertex > VertexCollection
Definition: Vertex.h:12
const Point & position() const
position
Definition: Vertex.h:127
tuple vertexCollection
int iEvent
Definition: GenABIO.cc:224
T sqrt(T t)
Definition: SSEVec.h:19
const double minMuonTrackRelPtErr_
def move
Definition: eostools.py:511
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const int mu
Definition: Constants.h:22
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
caConstants::TupleMultiplicity const CAHitNtupletGeneratorKernelsGPU::HitToTuple const cms::cuda::AtomicPairCounter GPUCACell const *__restrict__ uint32_t const *__restrict__ gpuPixelDoublets::CellNeighborsVector const gpuPixelDoublets::CellTracksVector const GPUCACell::OuterHitOfCell const int32_t nHits
~HiBadParticleCleaner() override=default
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:41
const double minCaloCompatibility_
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
edm::EDGetTokenT< edm::View< reco::PFCandidate > > tokenPFCandidates_
edm::View< Candidate > CandidateView
view of a collection containing candidates
Definition: CandidateFwd.h:23