44 using CandidateToDuplicate = std::vector<std::pair<int, int>>;
63 bool useForestFromDB_;
92 unsigned int overlapCheckMaxHits_;
94 unsigned int overlapCheckMaxMissingLayers_;
96 float overlapCheckMinCosT_;
136 desc.
add<
double>(
"minDeltaR3d",-4.0);
137 desc.add<
double>(
"minBDTG",-0.1);
138 desc.add<
double>(
"minpT",0.2);
139 desc.add<
double>(
"minP",0.4);
140 desc.add<
double>(
"maxDCA",30.0);
141 desc.add<
double>(
"maxDPhi",0.30);
142 desc.add<
double>(
"maxDLambda",0.30);
143 desc.add<
double>(
"maxDdsz",10.0);
144 desc.add<
double>(
"maxDdxy",10.0);
145 desc.add<
double>(
"maxDQoP",0.25);
146 desc.add<
unsigned>(
"overlapCheckMaxHits", 4);
147 desc.add<
unsigned>(
"overlapCheckMaxMissingLayers", 1);
148 desc.add<
double>(
"overlapCheckMinCosT", 0.99);
149 desc.add<
std::string>(
"forestLabel",
"MVADuplicate");
151 desc.add<
bool>(
"useInnermostState",
true);
152 desc.add<
std::string>(
"ttrhBuilderName",
"WithAngleAndTemplate");
153 desc.add<
std::string>(
"propagatorName",
"PropagatorWithMaterial");
154 desc.add<
std::string>(
"chi2EstimatorName",
"DuplicateTrackMergerChi2Est");
155 descriptions.add(
"DuplicateTrackMerger", desc);
163 minDeltaR3d2_ = iPara.getParameter<
double>(
"minDeltaR3d"); minDeltaR3d2_*=
std::abs(minDeltaR3d2_);
164 minBDTG_ = iPara.getParameter<
double>(
"minBDTG");
165 minpT2_ = iPara.getParameter<
double>(
"minpT"); minpT2_ *= minpT2_;
166 minP_ = iPara.getParameter<
double>(
"minP");
167 maxDCA2_ = iPara.getParameter<
double>(
"maxDCA"); maxDCA2_*=maxDCA2_;
168 maxDPhi_ = iPara.getParameter<
double>(
"maxDPhi");
169 maxDLambda_ = iPara.getParameter<
double>(
"maxDLambda");
170 maxDdsz_ = iPara.getParameter<
double>(
"maxDdsz");
171 maxDdxy_ = iPara.getParameter<
double>(
"maxDdxy");
172 maxDQoP_ = iPara.getParameter<
double>(
"maxDQoP");
173 overlapCheckMaxHits_ = iPara.getParameter<
unsigned>(
"overlapCheckMaxHits");
174 overlapCheckMaxMissingLayers_ = iPara.getParameter<
unsigned>(
"overlapCheckMaxMissingLayers");
175 overlapCheckMinCosT_ = iPara.getParameter<
double>(
"overlapCheckMinCosT");
177 produces<std::vector<TrackCandidate> >(
"candidates");
178 produces<CandidateToDuplicate>(
"candidateMap");
180 forestLabel_ = iPara.getParameter<
std::string>(
"forestLabel");
182 dbFileName_ = iPara.getParameter<
std::string>(
"GBRForestFileName");
183 useForestFromDB_ = dbFileName_.empty();
185 propagatorName_ = iPara.getParameter<
std::string>(
"propagatorName");
186 chi2EstimatorName_ = iPara.getParameter<
std::string>(
"chi2EstimatorName");
205 DuplicateTrackMerger::~DuplicateTrackMerger()
208 if(!useForestFromDB_)
delete forest_;
215 Stat() : maxCos(1.1), nCand(0),nLoop0(0) {}
217 std::cout <<
"Stats " << nCand <<
' ' << nLoop0 <<
' ' << maxCos << std::endl;
219 std::atomic<float> maxCos;
220 std::atomic<int> nCand, nLoop0;
226 void update_maximum(std::atomic<T>& maximum_value,
T const&
value)
noexcept 228 T prev_value = maximum_value;
229 while(prev_value <
value &&
230 !maximum_value.compare_exchange_weak(prev_value,
value))
235 void update_minimum(std::atomic<T>& minimum_value,
T const&
value)
noexcept 237 T prev_value = minimum_value;
238 while(prev_value >
value &&
239 !minimum_value.compare_exchange_weak(prev_value,
value))
247 merger_.init(iSetup);
250 if(useForestFromDB_){
253 forest_ = forestHandle.
product();
255 TFile gbrfile(dbFileName_.c_str());
256 forest_ =
dynamic_cast<const GBRForest*
>(gbrfile.Get(forestLabel_.c_str()));
267 magfield_ = hmagfield.
product();
279 propagator_ = hpropagator.
product();
283 chi2Estimator_ = hestimator.
product();
286 auto out_duplicateCandidates = std::make_unique<std::vector<TrackCandidate>>();
288 auto out_candidateMap = std::make_unique<CandidateToDuplicate>();
289 LogDebug(
"DuplicateTrackMerger") <<
"Number of tracks to be checked for merging: " <<
tracks.size();
295 const auto bOriAlgo =
b->originalAlgo();
297 const auto bSeed =
b->seedRef().key();
298 return ((
ev == 6903 && ((aOriAlgo == 23 && aSeed == 695 && bOriAlgo == 5 && bSeed == 652) ||
299 (aOriAlgo == 23 && aSeed == 400 && bOriAlgo == 7 && bSeed == 156) ||
300 (aOriAlgo == 4 && aSeed == 914 && bOriAlgo == 22 && bSeed == 503) ||
301 (aOriAlgo == 5 && aSeed == 809 && bOriAlgo == 4 && bSeed == 1030) ||
302 (aOriAlgo == 23 && aSeed == 749 && bOriAlgo == 5 && bSeed == 659) ||
303 (aOriAlgo == 4 && aSeed == 1053 && bOriAlgo == 23 && bSeed == 1035) ||
304 (aOriAlgo == 4 && aSeed == 810 && bOriAlgo == 5 && bSeed == 666) ||
305 (aOriAlgo == 4 && aSeed == 974 && bOriAlgo == 5 && bSeed == 778))) ||
306 (
ev == 6904 && ((aOriAlgo == 23 && aSeed == 526 && bOriAlgo == 5 && bSeed == 307) ||
307 (aOriAlgo == 4 && aSeed == 559 && bOriAlgo == 22 && bSeed == 472))) ||
308 (
ev == 6902 && ((aOriAlgo == 4 && aSeed == 750 && bOriAlgo == 22 && bSeed == 340) ||
309 (aOriAlgo == 4 && aSeed == 906 && bOriAlgo == 5 && bSeed == 609) ||
310 (aOriAlgo == 4 && aSeed == 724 && bOriAlgo == 5 && bSeed == 528) ||
311 (aOriAlgo == 4 && aSeed == 943 && bOriAlgo == 23 && bSeed == 739) ||
312 (aOriAlgo == 8 && aSeed == 2 && bOriAlgo == 9 && bSeed == 2282) ||
313 (aOriAlgo == 23 && aSeed == 827 && bOriAlgo == 5 && bSeed == 656) ||
314 (aOriAlgo == 22 && aSeed == 667 && bOriAlgo == 7 && bSeed == 516))));
328 if(
test(rt1, rt2) ||
test(rt2, rt1)) {
336 auto cosT = (*rt1).momentum().unit().Dot((*rt2).momentum().unit());
337 IfLogTrace(debug_,
"DuplicateTrackMerger") <<
" cosT " << cosT;
338 if (cosT<0.)
continue;
354 bool compatible =
false;
356 if(deltaR3d2 >= minDeltaR3d2_) {
357 compatible = checkForDisjointTracks(t1, t2, tscpBuilder);
361 compatible = checkForOverlappingTracks(t1, t2, cosT);
364 if(!compatible)
continue;
367 IfLogTrace(debug_,
"DuplicateTrackMerger") <<
" marking as duplicates";
368 out_duplicateCandidates->push_back(merger_.merge(*t1,*t2, duplType));
369 out_candidateMap->emplace_back(
i,j);
374 if (cosT>0) update_minimum(stat.maxCos,
float(cosT));
380 iEvent.
put(
std::move(out_duplicateCandidates),
"candidates");
388 IfLogTrace(debug_,
"DuplicateTrackMerger") <<
" Checking for disjoint duplicates";
395 IfLogTrace(debug_,
"DuplicateTrackMerger") <<
" TSCP1.isValid " << TSCP1.
isValid() <<
" TSCP2.isValid " << TSCP2.
isValid();
396 if(!TSCP1.
isValid())
return false;
397 if(!TSCP2.
isValid())
return false;
407 float tmva_dqoverp_ = qoverp1-qoverp2;
408 IfLogTrace(debug_,
"DuplicateTrackMerger") <<
" dqoverp " << tmva_dqoverp_;
409 if (
std::abs(tmva_dqoverp_) > maxDQoP_ )
return false;
417 float tmva_dlambda_ = lambda1-lambda2;
418 IfLogTrace(debug_,
"DuplicateTrackMerger") <<
" dlambda " << tmva_dlambda_;
419 if (
std::abs(tmva_dlambda_) > maxDLambda_ )
return false;
423 float tmva_dphi_ = phi1-phi2;
425 IfLogTrace(debug_,
"DuplicateTrackMerger") <<
" dphi " << tmva_dphi_;
426 if (
std::abs(tmva_dphi_) > maxDPhi_ )
return false;
430 float tmva_ddxy_ = dxy1-dxy2;
431 IfLogTrace(debug_,
"DuplicateTrackMerger") <<
" ddxy " << tmva_ddxy_;
432 if (
std::abs(tmva_ddxy_) > maxDdxy_ )
return false;
438 float tmva_ddsz_ = dsz1-dsz2;
439 IfLogTrace(debug_,
"DuplicateTrackMerger") <<
" ddsz " << tmva_ddsz_;
440 if (
std::abs(tmva_ddsz_) > maxDdsz_ )
return false;
442 float tmva_d3dr_ = avgPoint.perp();
443 float tmva_d3dz_ = avgPoint.z();
448 gbrVals_[0] = tmva_ddsz_;
449 gbrVals_[1] = tmva_ddxy_;
450 gbrVals_[2] = tmva_dphi_;
451 gbrVals_[3] = tmva_dlambda_;
452 gbrVals_[4] = tmva_dqoverp_;
453 gbrVals_[5] = tmva_d3dr_;
454 gbrVals_[6] = tmva_d3dz_;
455 gbrVals_[7] = tmva_outer_nMissingInner_;
456 gbrVals_[8] = tmva_inner_nMissingOuter_;
458 auto mvaBDTG = forest_->GetClassifier(gbrVals_);
459 IfLogTrace(debug_,
"DuplicateTrackMerger") <<
" mvaBDTG " << mvaBDTG;
460 if(mvaBDTG < minBDTG_)
return false;
466 bool DuplicateTrackMerger::checkForOverlappingTracks(
const reco::Track *t1,
const reco::Track *t2,
float cosT)
const {
471 IfLogTrace(debug_,
"DuplicateTrackMerger") <<
" Checking for overlapping duplicates, cosT " << cosT <<
" t1 hits " << t1->
numberOfValidHits();
472 if(cosT < overlapCheckMinCosT_)
return false;
477 const auto hitDet = hit1->geographicalId().det();
478 const auto hitSubdet = hit1->geographicalId().subdetId();
479 const auto hitLayer = ttopo_->layer(hit1->geographicalId());
481 const auto& detId = hit2->geographicalId();
482 return (detId.det() == hitDet && detId.subdetId() == hitSubdet &&
483 ttopo_->layer(detId) == hitLayer);
488 if(!(*t1HitIter)->isValid()) {
489 IfLogTrace(debug_,
"DuplicateTrackMerger") <<
" first t1 hit invalid";
492 auto t2HitIter = findHitOnT2(*t1HitIter);
499 if(!(*t1HitIter)->isValid()) {
500 IfLogTrace(debug_,
"DuplicateTrackMerger") <<
" second t1 hit invalid";
503 t2HitIter = findHitOnT2(*t1HitIter);
504 if(t2HitIter == t2->
recHitsEnd())
return false;
509 auto prevSubdet = (*t1HitIter)->geographicalId().subdetId();
512 ++t1HitIter; ++t2HitIter;
513 unsigned int missedLayers = 0;
520 <<
" either is invalid, types t1 " << (*t1HitIter)->getType() <<
" t2 " << (*t2HitIter)->getType();
524 const auto& t1DetId = (*t1HitIter)->geographicalId();
525 const auto& t2DetId = (*t2HitIter)->geographicalId();
527 const auto t1Det = t1DetId.det();
528 const auto t2Det = t2DetId.det();
532 <<
" either not from Tracker, dets t1 " << t1Det <<
" t2 " << t2Det;
536 const auto t1Subdet = t1DetId.subdetId();
537 const auto t1Layer = ttopo_->layer(t1DetId);
540 if(t1DetId == t2DetId) {
544 <<
" same DetId (" << t1DetId.rawId() <<
") but do not share all input";
549 const auto t2Subdet = t2DetId.subdetId();
550 const auto t2Layer = ttopo_->layer(t2DetId);
553 if(t1Subdet != t2Subdet || t1Layer != t2Layer) {
554 bool recovered =
false;
556 if(t1Subdet == prevSubdet && t2Subdet != prevSubdet) {
561 else if(t1Subdet != prevSubdet && t2Subdet == prevSubdet) {
566 else if(t1Subdet == t2Subdet) {
567 prevSubdet = t1Subdet;
569 if(t2Layer > t1Layer) {
574 else if(t1Layer > t2Layer) {
582 if(missedLayers > overlapCheckMaxMissingLayers_) {
583 IfLogTrace(debug_,
"DuplicateTrackMerger") <<
" max number of missed layers exceeded";
591 <<
" are on different layers (subdet, layer) t1 " << t1Subdet <<
"," << t1Layer
592 <<
" t2 " << t2Subdet <<
"," << t2Layer;
599 <<
" are on same layer, but in non-pixel detector (det " << t1Det <<
" subdet " << t1Subdet <<
" layer " << t1Layer <<
")";
606 if(!tsosPropagated.
isValid()) {
609 <<
" TSOS not valid";
612 auto passChi2Pair = chi2Estimator_->estimate(tsosPropagated, **t1HitIter);
613 if(!passChi2Pair.first) {
616 <<
" hit chi2 compatibility failed with chi2 " << passChi2Pair.second;
620 prevSubdet = t1Subdet;
621 ++t1HitIter; ++t2HitIter;
624 IfLogTrace(debug_,
"DuplicateTrackMerger") <<
" hits on t2 ended before hits on t1";
628 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)
Geom::Phi< T > phi() const
static void fillDescriptions(ConfigurationDescriptions &descriptions)
#define IfLogTrace(cond, cat)
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.
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.