42 #define IfLogTrace(cond, cat) if(cond) LogTrace(cat) 44 #define IfLogTrace(cond, cat) LogTrace(cat) 56 using CandidateToDuplicate = std::vector<std::pair<int, int>>;
75 bool useForestFromDB_;
104 unsigned int overlapCheckMaxHits_;
106 unsigned int overlapCheckMaxMissingLayers_;
108 float overlapCheckMinCosT_;
148 desc.
add<
double>(
"minDeltaR3d",-4.0);
149 desc.
add<
double>(
"minBDTG",-0.1);
150 desc.
add<
double>(
"minpT",0.2);
151 desc.
add<
double>(
"minP",0.4);
152 desc.
add<
double>(
"maxDCA",30.0);
153 desc.
add<
double>(
"maxDPhi",0.30);
154 desc.
add<
double>(
"maxDLambda",0.30);
155 desc.
add<
double>(
"maxDdsz",10.0);
156 desc.
add<
double>(
"maxDdxy",10.0);
157 desc.
add<
double>(
"maxDQoP",0.25);
158 desc.
add<
unsigned>(
"overlapCheckMaxHits", 4);
159 desc.
add<
unsigned>(
"overlapCheckMaxMissingLayers", 1);
160 desc.
add<
double>(
"overlapCheckMinCosT", 0.99);
163 desc.
add<
bool>(
"useInnermostState",
true);
165 desc.
add<
std::string>(
"propagatorName",
"PropagatorWithMaterial");
166 desc.
add<
std::string>(
"chi2EstimatorName",
"DuplicateTrackMergerChi2Est");
167 descriptions.
add(
"DuplicateTrackMerger", desc);
171 DuplicateTrackMerger::DuplicateTrackMerger(
const edm::ParameterSet& iPara) : forest_(
nullptr), merger_(iPara)
175 minDeltaR3d2_ = iPara.
getParameter<
double>(
"minDeltaR3d"); minDeltaR3d2_*=
std::abs(minDeltaR3d2_);
177 minpT2_ = iPara.
getParameter<
double>(
"minpT"); minpT2_ *= minpT2_;
179 maxDCA2_ = iPara.
getParameter<
double>(
"maxDCA"); maxDCA2_*=maxDCA2_;
185 overlapCheckMaxHits_ = iPara.
getParameter<
unsigned>(
"overlapCheckMaxHits");
186 overlapCheckMaxMissingLayers_ = iPara.
getParameter<
unsigned>(
"overlapCheckMaxMissingLayers");
187 overlapCheckMinCosT_ = iPara.
getParameter<
double>(
"overlapCheckMinCosT");
189 produces<std::vector<TrackCandidate> >(
"candidates");
190 produces<CandidateToDuplicate>(
"candidateMap");
195 useForestFromDB_ = dbFileName_.empty();
217 DuplicateTrackMerger::~DuplicateTrackMerger()
220 if(!useForestFromDB_)
delete forest_;
227 Stat() : maxCos(1.1), nCand(0),nLoop0(0) {}
229 std::cout <<
"Stats " << nCand <<
' ' << nLoop0 <<
' ' << maxCos << std::endl;
231 std::atomic<float> maxCos;
232 std::atomic<int> nCand, nLoop0;
238 void update_maximum(std::atomic<T>& maximum_value,
T const&
value)
noexcept 240 T prev_value = maximum_value;
241 while(prev_value < value &&
242 !maximum_value.compare_exchange_weak(prev_value, value))
247 void update_minimum(std::atomic<T>& minimum_value,
T const& value)
noexcept 249 T prev_value = minimum_value;
250 while(prev_value > value &&
251 !minimum_value.compare_exchange_weak(prev_value, value))
259 merger_.init(iSetup);
262 if(useForestFromDB_){
265 forest_ = forestHandle.
product();
267 TFile gbrfile(dbFileName_.c_str());
268 forest_ =
dynamic_cast<const GBRForest*
>(gbrfile.Get(forestLabel_.c_str()));
279 magfield_ = hmagfield.
product();
291 propagator_ = hpropagator.
product();
295 chi2Estimator_ = hestimator.
product();
298 auto out_duplicateCandidates = std::make_unique<std::vector<TrackCandidate>>();
300 auto out_candidateMap = std::make_unique<CandidateToDuplicate>();
301 LogDebug(
"DuplicateTrackMerger") <<
"Number of tracks to be checked for merging: " <<
tracks.size();
307 const auto bOriAlgo =
b->originalAlgo();
309 const auto bSeed =
b->seedRef().key();
310 return ((
ev == 6903 && ((aOriAlgo == 23 && aSeed == 695 && bOriAlgo == 5 && bSeed == 652) ||
311 (aOriAlgo == 23 && aSeed == 400 && bOriAlgo == 7 && bSeed == 156) ||
312 (aOriAlgo == 4 && aSeed == 914 && bOriAlgo == 22 && bSeed == 503) ||
313 (aOriAlgo == 5 && aSeed == 809 && bOriAlgo == 4 && bSeed == 1030) ||
314 (aOriAlgo == 23 && aSeed == 749 && bOriAlgo == 5 && bSeed == 659) ||
315 (aOriAlgo == 4 && aSeed == 1053 && bOriAlgo == 23 && bSeed == 1035) ||
316 (aOriAlgo == 4 && aSeed == 810 && bOriAlgo == 5 && bSeed == 666) ||
317 (aOriAlgo == 4 && aSeed == 974 && bOriAlgo == 5 && bSeed == 778))) ||
318 (
ev == 6904 && ((aOriAlgo == 23 && aSeed == 526 && bOriAlgo == 5 && bSeed == 307) ||
319 (aOriAlgo == 4 && aSeed == 559 && bOriAlgo == 22 && bSeed == 472))) ||
320 (
ev == 6902 && ((aOriAlgo == 4 && aSeed == 750 && bOriAlgo == 22 && bSeed == 340) ||
321 (aOriAlgo == 4 && aSeed == 906 && bOriAlgo == 5 && bSeed == 609) ||
322 (aOriAlgo == 4 && aSeed == 724 && bOriAlgo == 5 && bSeed == 528) ||
323 (aOriAlgo == 4 && aSeed == 943 && bOriAlgo == 23 && bSeed == 739) ||
324 (aOriAlgo == 8 && aSeed == 2 && bOriAlgo == 9 && bSeed == 2282) ||
325 (aOriAlgo == 23 && aSeed == 827 && bOriAlgo == 5 && bSeed == 656) ||
326 (aOriAlgo == 22 && aSeed == 667 && bOriAlgo == 7 && bSeed == 516))));
340 if(
test(rt1, rt2) ||
test(rt2, rt1)) {
348 auto cosT = (*rt1).momentum().unit().Dot((*rt2).momentum().unit());
349 IfLogTrace(debug_,
"DuplicateTrackMerger") <<
" cosT " << cosT;
350 if (cosT<0.)
continue;
366 bool compatible =
false;
368 if(deltaR3d2 >= minDeltaR3d2_) {
369 compatible = checkForDisjointTracks(t1, t2, tscpBuilder);
373 compatible = checkForOverlappingTracks(t1, t2, cosT);
376 if(!compatible)
continue;
379 IfLogTrace(debug_,
"DuplicateTrackMerger") <<
" marking as duplicates";
380 out_duplicateCandidates->push_back(merger_.merge(*t1,*t2, duplType));
381 out_candidateMap->emplace_back(
i,
j);
386 if (cosT>0) update_minimum(stat.maxCos,
float(cosT));
392 iEvent.
put(
std::move(out_duplicateCandidates),
"candidates");
400 IfLogTrace(debug_,
"DuplicateTrackMerger") <<
" Checking for disjoint duplicates";
407 IfLogTrace(debug_,
"DuplicateTrackMerger") <<
" TSCP1.isValid " << TSCP1.
isValid() <<
" TSCP2.isValid " << TSCP2.
isValid();
408 if(!TSCP1.
isValid())
return false;
409 if(!TSCP2.
isValid())
return false;
419 float tmva_dqoverp_ = qoverp1-qoverp2;
420 IfLogTrace(debug_,
"DuplicateTrackMerger") <<
" dqoverp " << tmva_dqoverp_;
421 if (
std::abs(tmva_dqoverp_) > maxDQoP_ )
return false;
429 float tmva_dlambda_ = lambda1-lambda2;
430 IfLogTrace(debug_,
"DuplicateTrackMerger") <<
" dlambda " << tmva_dlambda_;
431 if (
std::abs(tmva_dlambda_) > maxDLambda_ )
return false;
435 float tmva_dphi_ = phi1-phi2;
437 IfLogTrace(debug_,
"DuplicateTrackMerger") <<
" dphi " << tmva_dphi_;
438 if (
std::abs(tmva_dphi_) > maxDPhi_ )
return false;
442 float tmva_ddxy_ = dxy1-dxy2;
443 IfLogTrace(debug_,
"DuplicateTrackMerger") <<
" ddxy " << tmva_ddxy_;
444 if (
std::abs(tmva_ddxy_) > maxDdxy_ )
return false;
450 float tmva_ddsz_ = dsz1-dsz2;
451 IfLogTrace(debug_,
"DuplicateTrackMerger") <<
" ddsz " << tmva_ddsz_;
452 if (
std::abs(tmva_ddsz_) > maxDdsz_ )
return false;
454 float tmva_d3dr_ = avgPoint.
perp();
455 float tmva_d3dz_ = avgPoint.
z();
460 gbrVals_[0] = tmva_ddsz_;
461 gbrVals_[1] = tmva_ddxy_;
462 gbrVals_[2] = tmva_dphi_;
463 gbrVals_[3] = tmva_dlambda_;
464 gbrVals_[4] = tmva_dqoverp_;
465 gbrVals_[5] = tmva_d3dr_;
466 gbrVals_[6] = tmva_d3dz_;
467 gbrVals_[7] = tmva_outer_nMissingInner_;
468 gbrVals_[8] = tmva_inner_nMissingOuter_;
470 auto mvaBDTG = forest_->GetClassifier(gbrVals_);
471 IfLogTrace(debug_,
"DuplicateTrackMerger") <<
" mvaBDTG " << mvaBDTG;
472 if(mvaBDTG < minBDTG_)
return false;
478 bool DuplicateTrackMerger::checkForOverlappingTracks(
const reco::Track *t1,
const reco::Track *t2,
float cosT)
const {
483 IfLogTrace(debug_,
"DuplicateTrackMerger") <<
" Checking for overlapping duplicates, cosT " << cosT <<
" t1 hits " << t1->
numberOfValidHits();
484 if(cosT < overlapCheckMinCosT_)
return false;
489 const auto hitDet = hit1->geographicalId().det();
490 const auto hitSubdet = hit1->geographicalId().subdetId();
491 const auto hitLayer = ttopo_->layer(hit1->geographicalId());
493 const auto& detId = hit2->geographicalId();
494 return (detId.det() == hitDet && detId.subdetId() == hitSubdet &&
495 ttopo_->layer(detId) == hitLayer);
500 if(!(*t1HitIter)->isValid()) {
501 IfLogTrace(debug_,
"DuplicateTrackMerger") <<
" first t1 hit invalid";
504 auto t2HitIter = findHitOnT2(*t1HitIter);
511 if(!(*t1HitIter)->isValid()) {
512 IfLogTrace(debug_,
"DuplicateTrackMerger") <<
" second t1 hit invalid";
515 t2HitIter = findHitOnT2(*t1HitIter);
516 if(t2HitIter == t2->
recHitsEnd())
return false;
521 auto prevSubdet = (*t1HitIter)->geographicalId().subdetId();
524 ++t1HitIter; ++t2HitIter;
525 unsigned int missedLayers = 0;
532 <<
" either is invalid, types t1 " << (*t1HitIter)->getType() <<
" t2 " << (*t2HitIter)->getType();
536 const auto& t1DetId = (*t1HitIter)->geographicalId();
537 const auto& t2DetId = (*t2HitIter)->geographicalId();
539 const auto t1Det = t1DetId.det();
540 const auto t2Det = t2DetId.det();
544 <<
" either not from Tracker, dets t1 " << t1Det <<
" t2 " << t2Det;
548 const auto t1Subdet = t1DetId.subdetId();
549 const auto t1Layer = ttopo_->layer(t1DetId);
552 if(t1DetId == t2DetId) {
556 <<
" same DetId (" << t1DetId.rawId() <<
") but do not share all input";
561 const auto t2Subdet = t2DetId.subdetId();
562 const auto t2Layer = ttopo_->layer(t2DetId);
565 if(t1Subdet != t2Subdet || t1Layer != t2Layer) {
566 bool recovered =
false;
568 if(t1Subdet == prevSubdet && t2Subdet != prevSubdet) {
573 else if(t1Subdet != prevSubdet && t2Subdet == prevSubdet) {
578 else if(t1Subdet == t2Subdet) {
579 prevSubdet = t1Subdet;
581 if(t2Layer > t1Layer) {
586 else if(t1Layer > t2Layer) {
594 if(missedLayers > overlapCheckMaxMissingLayers_) {
595 IfLogTrace(debug_,
"DuplicateTrackMerger") <<
" max number of missed layers exceeded";
603 <<
" are on different layers (subdet, layer) t1 " << t1Subdet <<
"," << t1Layer
604 <<
" t2 " << t2Subdet <<
"," << t2Layer;
611 <<
" are on same layer, but in non-pixel detector (det " << t1Det <<
" subdet " << t1Subdet <<
" layer " << t1Layer <<
")";
618 if(!tsosPropagated.
isValid()) {
621 <<
" TSOS not valid";
624 auto passChi2Pair = chi2Estimator_->estimate(tsosPropagated, **t1HitIter);
625 if(!passChi2Pair.first) {
628 <<
" hit chi2 compatibility failed with chi2 " << passChi2Pair.second;
632 prevSubdet = t1Subdet;
633 ++t1HitIter; ++t2HitIter;
636 IfLogTrace(debug_,
"DuplicateTrackMerger") <<
" hits on t2 ended before hits on t1";
640 IfLogTrace(debug_,
"DuplicateTrackMerger") <<
" all hits on t2 are on layers whre t1 has also a hit";
const edm::RefToBase< TrajectorySeed > & seedRef() const
T getParameter(std::string const &) const
EventNumber_t event() const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
const FreeTrajectoryState & theState() const
#define DEFINE_FWK_MODULE(type)
#define IfLogTrace(cond, cat)
Geom::Phi< T > phi() const
const math::XYZPoint & outerPosition() const
position of the outermost hit
Geom::Theta< T > theta() const
const math::XYZPoint & innerPosition() const
position of the innermost hit
const SurfaceType & surface() const
auto const T2 &decltype(t1.eta()) t2
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)
Abs< T >::type abs(const T &t)
unsigned short numberOfValidHits() const
number of valid hits found
trackingRecHit_iterator recHitsBegin() const
Iterator to first hit on the track.
ParameterDescriptionBase * add(U const &iLabel, T const &value)
GlobalVector momentum() const
GlobalPoint position() const
TrackAlgorithm originalAlgo() const
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
void add(std::string const &label, ParameterSetDescription const &psetDescription)
int numberOfLostHits(HitCategory category) const
const math::XYZVector & innerMomentum() const
momentum vector at the innermost hit position
bool isUndef(TrackingRecHit const &hit)
int charge() const
track electric charge
double signedInverseMomentum() const
T const * product() const
GlobalVector momentum() const
trackingRecHit_iterator recHitsEnd() const
Iterator to last hit on the track.