9 #include <Math/DistFunc.h>
19 return PowN<
N / 2>::op(
t) * PowN<(
N + 1) / 2>::op(
t);
48 return PowN<4>::op(
t);
50 return PowN<3>::op(
t);
52 return PowN<8>::op(
t);
54 return PowN<2>::op(
t);
56 return PowN<5>::op(
t);
58 return PowN<6>::op(
t);
60 return PowN<7>::op(
t);
62 return PowN<0>::op(
t);
64 return PowN<1>::op(
t);
75 useForestFromDB_ =
true;
80 mvavars_indices.clear();
81 for (
unsigned i = 0;
i < forestVars_.size();
i++) {
84 if (
v ==
"chi2perdofperlayer")
86 if (
v ==
"dxyperdxyerror")
88 if (
v ==
"dzperdzerror")
92 if (
v ==
"lostmidfrac")
100 if (
v ==
"chi2n_no1dmod")
104 if (
v ==
"nlayerslost")
106 if (
v ==
"nlayers3d")
117 <<
"Unknown forest variable " <<
v <<
". Please make sure it's in the list of supported variables\n";
119 mvavars_indices.push_back(ind);
127 useVertices_(
cfg.getParameter<
bool>(
"useVertices")),
128 useVtxError_(
cfg.getParameter<
bool>(
"useVtxError"))
135 if (
cfg.exists(
"applyPixelMergingCuts"))
146 if (
cfg.exists(
"useAnyMVA"))
149 if (
cfg.exists(
"mvaType"))
151 if (
cfg.exists(
"GBRForestLabel"))
153 if (
cfg.exists(
"GBRForestVars")) {
154 forestVars_ =
cfg.getParameter<std::vector<std::string>>(
"GBRForestVars");
157 if (
cfg.exists(
"GBRForestFileName")) {
163 std::vector<edm::ParameterSet> trkSelectors(
cfg.getParameter<std::vector<edm::ParameterSet>>(
"trackSelectors"));
167 res_par_.reserve(trkSelectors.size());
170 d0_par1_.reserve(trkSelectors.size());
171 dz_par1_.reserve(trkSelectors.size());
172 d0_par2_.reserve(trkSelectors.size());
173 dz_par2_.reserve(trkSelectors.size());
175 max_d0_.reserve(trkSelectors.size());
176 max_z0_.reserve(trkSelectors.size());
177 nSigmaZ_.reserve(trkSelectors.size());
192 min_eta_.reserve(trkSelectors.size());
193 max_eta_.reserve(trkSelectors.size());
194 useMVA_.reserve(trkSelectors.size());
196 min_MVA_.reserve(trkSelectors.size());
199 produces<edm::ValueMap<float>>(
"MVAVals");
201 for (
unsigned int i = 0;
i < trkSelectors.size();
i++) {
207 res_par_.push_back(trkSelectors[
i].getParameter<std::vector<double>>(
"res_par"));
208 chi2n_par_.push_back(trkSelectors[
i].getParameter<double>(
"chi2n_par"));
210 d0_par1_.push_back(trkSelectors[
i].getParameter<std::vector<double>>(
"d0_par1"));
211 dz_par1_.push_back(trkSelectors[
i].getParameter<std::vector<double>>(
"dz_par1"));
212 d0_par2_.push_back(trkSelectors[
i].getParameter<std::vector<double>>(
"d0_par2"));
213 dz_par2_.push_back(trkSelectors[
i].getParameter<std::vector<double>>(
"dz_par2"));
217 max_d0_.push_back(trkSelectors[
i].getParameter<double>(
"max_d0"));
218 max_z0_.push_back(trkSelectors[
i].getParameter<double>(
"max_z0"));
219 nSigmaZ_.push_back(trkSelectors[
i].getParameter<double>(
"nSigmaZ"));
221 min_layers_.push_back(trkSelectors[
i].getParameter<uint32_t>(
"minNumberLayers"));
222 min_3Dlayers_.push_back(trkSelectors[
i].getParameter<uint32_t>(
"minNumber3DLayers"));
223 max_lostLayers_.push_back(trkSelectors[
i].getParameter<uint32_t>(
"maxNumberLostLayers"));
224 min_hits_bypass_.push_back(trkSelectors[
i].getParameter<uint32_t>(
"minHitsToBypassChecks"));
227 keepAllTracks_.push_back(trkSelectors[
i].getParameter<bool>(
"keepAllTracks"));
228 max_relpterr_.push_back(trkSelectors[
i].getParameter<double>(
"max_relpterr"));
229 min_nhits_.push_back(trkSelectors[
i].getParameter<uint32_t>(
"min_nhits"));
231 ? trkSelectors[
i].getParameter<int32_t>(
"max_minMissHitOutOrIn")
234 ? trkSelectors[
i].getParameter<double>(
"max_lostHitFraction")
236 min_eta_.push_back(trkSelectors[
i].existsAs<double>(
"min_eta") ? trkSelectors[
i].getParameter<double>(
"min_eta")
238 max_eta_.push_back(trkSelectors[
i].existsAs<double>(
"max_eta") ? trkSelectors[
i].getParameter<double>(
"max_eta")
243 if (!qualityStr.empty()) {
245 qualityToSet_[
i] = TrackBase::qualityByName(trkSelectors[
i].getParameter<std::string>(
"qualityBit"));
250 <<
"You can't set the quality bit " << trkSelectors[
i].getParameter<
std::string>(
"qualityBit")
251 <<
" as it is 'undefQuality' or unknown.\n";
254 max_d0NoPV_.push_back(trkSelectors[
i].getParameter<double>(
"max_d0NoPV"));
255 max_z0NoPV_.push_back(trkSelectors[
i].getParameter<double>(
"max_z0NoPV"));
261 name_.push_back(trkSelectors[
i].getParameter<std::string>(
"name"));
266 if (!pfName.empty()) {
267 bool foundPF =
false;
268 for (
unsigned int j = 0;
j <
i;
j++)
274 throw cms::Exception(
"Configuration") <<
"Invalid prefilter name in HIMultiTrackSelector "
275 << trkSelectors[
i].getParameter<
std::string>(
"preFilterName");
279 pixel_pTMinCut_.push_back(trkSelectors[
i].getParameter<std::vector<double>>(
"pixel_pTMinCut"));
280 pixel_pTMaxCut_.push_back(trkSelectors[
i].getParameter<std::vector<double>>(
"pixel_pTMaxCut"));
284 produces<edm::ValueMap<int>>(
name_[
i]).setBranchAlias(
name_[
i] +
"TrackQuals");
286 bool thisMVA =
false;
287 if (trkSelectors[
i].exists(
"useMVA"))
288 thisMVA = trkSelectors[
i].getParameter<
bool>(
"useMVA");
292 if (trkSelectors[
i].exists(
"minMVA"))
293 minVal = trkSelectors[
i].getParameter<
double>(
"minMVA");
317 using namespace reco;
340 std::vector<int> selTracksSave(
qualityToSet_.size() * trkSize, 0);
342 std::vector<float> mvaVals_(
srcTracks.size(), -99.f);
346 std::vector<int> selTracks(trkSize, 0);
347 auto selTracksValueMap = std::make_unique<edm::ValueMap<int>>();
350 std::vector<Point>
points;
351 std::vector<float> vterr, vzerr;
357 for (TrackCollection::const_iterator it =
srcTracks.begin(), ed =
srcTracks.end(); it != ed; ++it, ++current) {
358 const Track &trk = *it;
361 LogTrace(
"TrackSelection") <<
"ready to check track with pt=" << trk.
pt();
367 selTracks[current] = -1;
373 mvaVal = mvaVals_[current];
374 ok =
select(
i, vertexBeamSpot, srcHits, trk,
points, vterr, vzerr, mvaVal);
376 LogTrace(
"TrackSelection") <<
"track with pt=" << trk.
pt() <<
" NOT selected";
378 selTracks[current] = -1;
382 LogTrace(
"TrackSelection") <<
"track with pt=" << trk.
pt() <<
" selected";
386 selTracks[current] = selTracksSave[
preFilter_[
i] * trkSize + current];
391 selTracks[current] = (selTracks[current] | (1 <<
qualityToSet_[
i]));
396 selTracks[current] = (selTracks[current] | (1 << TrackBase::tight));
401 selTracks[current] = (selTracks[current] | (1 << TrackBase::looseSetWithPV));
403 selTracks[current] = (selTracks[current] | (1 << TrackBase::looseSetWithPV));
404 selTracks[current] = (selTracks[current] | (1 << TrackBase::highPuritySetWithPV));
409 for (
unsigned int j = 0;
j < trkSize;
j++)
410 selTracksSave[
j +
i * trkSize] = selTracks[
j];
411 filler.insert(hSrcTrack, selTracks.begin(), selTracks.end());
423 const std::vector<Point> &
points,
424 std::vector<float> &vterr,
425 std::vector<float> &vzerr,
426 double mvaVal)
const {
438 if (tk.
ndof() < 1E-5)
459 LogDebug(
"TrackSelection") <<
"cuts on nlayers: " <<
nlayers <<
" " << nlayers3D <<
" " << nlayersLost <<
" vs "
467 LogTrace(
"TrackSelection") <<
"cuts on nlayers passed";
470 float chi2n_no1Dmod =
chi2n;
473 auto ith = tk.
extra()->firstRecHit();
475 for (; ith < edh; ++ith) {
477 if (
hit.dimension() == 1)
480 if (count1dhits > 0) {
506 int minLost =
std::min(lostIn, lostOut);
539 float nomdzE = nomd0E * (std::cosh(
eta));
547 bool primaryVertexZCompatibility(
false);
548 bool primaryVertexD0Compatibility(
false);
553 primaryVertexZCompatibility =
true;
556 primaryVertexD0Compatibility =
true;
561 LogTrace(
"TrackSelection") <<
"Test track w.r.t. vertex with z position " <<
point->z();
562 if (primaryVertexZCompatibility && primaryVertexD0Compatibility)
567 float dzErrPV =
std::sqrt(dzE * dzE + vzerr[
iv] * vzerr[
iv]);
568 float d0ErrPV =
std::sqrt(d0E * d0E + vterr[
iv] * vterr[
iv]);
572 primaryVertexZCompatibility =
true;
575 primaryVertexD0Compatibility =
true;
578 primaryVertexZCompatibility =
true;
580 primaryVertexD0Compatibility =
true;
582 LogTrace(
"TrackSelection") <<
"distances " << dzPV <<
" " << d0PV <<
" vs " <<
dzCut <<
" " <<
d0Cut;
591 if (
abs(
d0) >
max_d0_[tsNum] && !primaryVertexD0Compatibility)
593 LogTrace(
"TrackSelection") <<
"absolute cuts on d0 passed";
594 if (
abs(
dz) >
max_z0_[tsNum] && !primaryVertexZCompatibility)
596 LogTrace(
"TrackSelection") <<
"absolute cuts on dz passed";
600 <<
" d0 compatibility? " << primaryVertexD0Compatibility <<
" z compatibility? "
601 << primaryVertexZCompatibility;
604 return (primaryVertexD0Compatibility && primaryVertexZCompatibility);
612 std::vector<Point> &
points,
613 std::vector<float> &vterr,
614 std::vector<float> &vzerr)
const {
616 using namespace reco;
618 for (VertexCollection::const_iterator it = vtxs.begin(), ed = vtxs.end(); it != ed; ++it) {
619 LogDebug(
"SelectVertex") <<
" select vertex with z position " << it->z() <<
" " << it->chi2() <<
" " << it->ndof()
620 <<
" " << TMath::Prob(it->chi2(), static_cast<int32_t>(it->ndof()));
624 points.push_back(it->position());
625 vterr.push_back(
sqrt(it->yError() * it->xError()));
626 vzerr.push_back(it->zError());
627 LogTrace(
"SelectVertex") <<
" SELECTED vertex with z position " << it->z();
637 std::vector<float> &mvaVals_,
641 using namespace reco;
654 auto mvaValValueMap = std::make_unique<edm::ValueMap<float>>();
659 mvaFiller.insert(hSrcTrack, mvaVals_.begin(), mvaVals_.end());
670 for (TrackCollection::const_iterator it =
srcTracks.begin(), ed =
srcTracks.end(); it != ed; ++it, ++current) {
671 const Track &trk = *it;
684 auto ith = trk.
extra()->firstRecHit();
686 for (; ith < edh; ++ith) {
688 if (
hit.dimension() == 1)
691 if (count1dhits > 0) {
694 chi2n1d = (
chi2 + count1dhits) /
float(
ndof + count1dhits);
697 mvavalues[
chi2n] = chi2n1d;
699 mvavalues[
eta] = trk.
eta();
724 std::vector<float> gbrValues;
735 forest = forestHandle.
product();
739 mvaVals_[current] = gbrVal;
741 mvaFiller.insert(hSrcTrack, mvaVals_.begin(), mvaVals_.end());