78 :
tag(tag_), tk(tk_), traj(traj_), tass(tass_), tsel(tsel_), tmva(tmva_) {}
82 consumes<reco::TrackCollection>(
tag),
83 consumes<std::vector<Trajectory>>(
tag),
84 consumes<TrajTrackAssociationCollection>(
tag),
90 consumes<reco::TrackCollection>(
tag),
91 consumes<std::vector<Trajectory>>(
tag),
92 consumes<TrajTrackAssociationCollection>(
tag),
145 #include <x86intrin.h> 150 inline volatile unsigned long long rdtsc() {
return __rdtsc(); }
155 unsigned long long st;
156 long long totBegin = 0;
157 long long totPre = 0;
158 long long totEnd = 0;
159 unsigned long long timeNo;
160 unsigned long long timeOv;
162 void start() { st = rdtsc(); }
163 void noOverlap() { timeNo += (rdtsc() - st); }
164 void overlap() { timeOv += (rdtsc() - st); }
165 void pre(
int tt) { totPre +=
tt; }
166 void end(
int tt) { totEnd +=
tt; }
177 std::cout <<
"TrackListMerger stat\nBegin/Pre/End/maxDPhi/maxDEta/Overlap/NoOverlap " << totBegin <<
'/' << totPre
178 <<
'/' << totEnd <<
'/' << maxDP <<
'/' << maxDE <<
'/' << timeOv / 1000 <<
'/' << timeNo / 1000
182 ~StatCount() {
print(); }
212 std::vector<edm::InputTag> trackProducerTags(conf.
getParameter<std::vector<edm::InputTag>>(
"TrackProducers"));
226 if (!qualityStr.empty()) {
244 std::vector<edm::InputTag>
selectors(conf.
getParameter<std::vector<edm::InputTag>>(
"selectedTrackQuals"));
245 std::vector<edm::InputTag> mvaStores;
246 if (conf.
exists(
"mvaValueTags")) {
247 mvaStores = conf.
getParameter<std::vector<edm::InputTag>>(
"mvaValueTags");
251 mvaStores.push_back(ntag);
254 unsigned int numTrkColl = trackProducerTags.size();
256 throw cms::Exception(
"Inconsistent size") <<
"need same number of track collections and selectors";
258 if (numTrkColl !=
hasSelector_.size() || numTrkColl != mvaStores.size()) {
259 throw cms::Exception(
"Inconsistent size") <<
"need same number of track collections and MVA stores";
269 for (
unsigned int i = 1;
i < numTrkColl;
i++) {
270 if (!(trackProducerTags[
i] == trackProducerTags[0]))
274 throw cms::Exception(
"Bad input") <<
"to use writeOnlyTrkQuals=True all input InputTags must be the same";
276 produces<edm::ValueMap<int>>();
277 produces<QualityMaskCollection>(
"QualityMasks");
282 produces<TrajectorySeedCollection>();
286 produces<reco::TrackExtraCollection>();
287 produces<TrackingRecHitCollection>();
293 produces<reco::TrackCollection>();
295 produces<std::vector<Trajectory>>();
296 produces<TrajTrackAssociationCollection>();
298 produces<edm::ValueMap<float>>(
"MVAVals");
299 produces<MVACollection>(
"MVAValues");
303 for (
unsigned int i = 0;
i < numTrkColl; ++
i) {
305 :
edTokens(trackProducerTags[
i], mvaStores[
i]);
328 std::vector<const reco::TrackCollection*> trackColls;
329 std::vector<edm::Handle<reco::TrackCollection>> trackHandles(
trackProducers_.size());
331 trackColls.push_back(
nullptr);
335 trackColls[
i] = trackHandles[
i].product();
338 trackColls[
i] = &s_empty;
342 if (trackColls.empty()) {
348 unsigned int collsSize = trackColls.size();
349 unsigned int rSize = 0;
350 unsigned int trackCollSizes[collsSize];
351 unsigned int trackCollFirsts[collsSize];
352 for (
unsigned int i = 0;
i != collsSize;
i++) {
353 trackCollSizes[
i] = trackColls[
i]->size();
354 trackCollFirsts[
i] = rSize;
355 rSize += trackCollSizes[
i];
364 statCount.begin(rSize);
373 bool trkUpdated[rSize];
374 int trackCollNum[rSize];
375 int trackQuals[rSize];
376 float trackMVAs[rSize];
378 std::vector<reco::TrackBase::AlgoMask> algoMask(rSize);
379 for (
unsigned int j = 0;
j < rSize;
j++) {
382 trkUpdated[
j] =
false;
385 trackMVAs[
j] = -998.0;
390 for (
unsigned int j = 0;
j != collsSize;
j++) {
403 for (reco::TrackCollection::const_iterator
track = tC1->begin();
track != tC1->end();
track++) {
406 trackQuals[
i] =
track->qualityMask();
407 oriAlgo[
i] =
track->originalAlgo();
408 algoMask[
i] =
track->algoMask();
412 if ((*trackMVAStore).contains(trkRef.
id()))
413 trackMVAs[
i] = (*trackMVAStore)[trkRef];
415 int qual = (*trackSelColl)[trkRef];
421 trackQuals[
i] = qual;
425 selected[
i] = trackQuals[
i] + 10;
426 if ((
short unsigned)
track->ndof() < 1) {
449 statCount.pre(ngood);
452 typedef std::pair<unsigned int, const TrackingRecHit*> IHit;
453 std::vector<std::vector<IHit>> rh1(ngood);
458 for (
unsigned int j = 0;
j < rSize;
j++) {
459 if (selected[
j] == 0)
463 unsigned int collNum = trackCollNum[
j];
464 unsigned int trackNum =
j - trackCollFirsts[collNum];
468 int validHits =
track->numberOfValidHits();
469 int validPixelHits =
track->hitPattern().numberOfValidPixelHits();
474 rh1[
i].reserve(validHits);
475 auto compById = [](IHit
const& h1, IHit
const& h2) {
return h1.first < h2.first; };
478 unsigned int id =
hit->rawId();
479 if (
hit->geographicalId().subdetId() > 2)
482 rh1[
i].emplace_back(
id,
hit);
483 std::push_heap(rh1[
i].begin(), rh1[
i].
end(), compById);
486 std::sort_heap(rh1[
i].begin(), rh1[
i].
end(), compById);
490 if LIKELY (ngood > 1 && collsSize > 1)
491 for (
unsigned int ltm = 0; ltm <
listsToMerge_.size(); ltm++) {
492 int saveSelected[rSize];
493 bool notActive[collsSize];
494 for (
unsigned int cn = 0; cn != collsSize; ++cn)
497 for (
unsigned int i = 0;
i < rSize;
i++)
498 saveSelected[
i] = selected[
i];
501 for (
unsigned int i = 0;
i < rSize - 1;
i++) {
502 if (selected[
i] == 0)
504 unsigned int collNum = trackCollNum[
i];
507 if (notActive[collNum])
511 unsigned int nh1 = rh1[k1].size();
512 int qualityMaskT1 = trackQuals[
i];
515 float score1 =
score[k1];
518 for (
unsigned int j =
i + 1;
j < rSize;
j++) {
519 if (selected[
j] == 0)
521 unsigned int collNum2 = trackCollNum[
j];
525 if (notActive[collNum2])
530 int newQualityMask = -9;
532 int maskT1 = saveSelected[
i] > 1 ? saveSelected[
i] - 10 : qualityMaskT1;
533 int maskT2 = saveSelected[
j] > 1 ? saveSelected[
j] - 10 : trackQuals[
j];
534 newQualityMask = (maskT1 | maskT2);
536 unsigned int nh2 = rh1[k2].size();
543 float delta =
std::abs(
it->localPosition().x() - jt->localPosition().x());
544 return (
it->geographicalId() == jt->geographicalId()) && (
delta <
eps);
551 int firstoverlap = 0;
563 while (ih != nh1 && jh != nh2) {
567 auto const id1 = rh1[k1][ih].first;
568 auto const id2 = rh1[k2][jh].first;
576 while ((++li) != nh1 &&
id1 == rh1[k1][li].
first) {
579 while ((++lj) != nh2 &&
id2 == rh1[k2][lj].
first) {
581 for (
auto ii = ih;
ii != li; ++
ii)
582 for (
auto jj = jh;
jj != lj; ++
jj) {
595 (collNum != collNum2)
599 auto seti = [&](
unsigned int ii,
unsigned int jj) {
601 selected[
ii] = 10 + newQualityMask;
602 trkUpdated[
ii] =
true;
604 oriAlgo[
ii] = oriAlgo[
jj];
605 algoMask[
ii] |= algoMask[
jj];
606 algoMask[
jj] = algoMask[
ii];
610 float score2 =
score[k2];
613 if (score1 - score2 > almostSame) {
615 }
else if (score2 - score1 > almostSame) {
647 statCount.noOverlap();
650 if (selected[
i] == 0)
656 auto vmMVA = std::make_unique<edm::ValueMap<float>>();
661 unsigned int tSize = trackColls[0]->size();
662 auto vm = std::make_unique<edm::ValueMap<int>>();
665 std::vector<int> finalQuals(tSize, -1);
666 for (
unsigned int i = 0;
i < rSize;
i++) {
667 unsigned int tNum =
i % tSize;
669 if (selected[
i] > 1) {
670 finalQuals[tNum] = selected[
i] - 10;
672 finalQuals[tNum] = (finalQuals[tNum] | (1 <<
qualityToSet_));
674 if (selected[
i] == 1)
675 finalQuals[tNum] = trackQuals[
i];
678 filler.insert(trackHandles[0], finalQuals.begin(), finalQuals.end());
682 for (
auto&
q : finalQuals)
684 auto quals = std::make_unique<QualityMaskCollection>(finalQuals.begin(), finalQuals.end());
687 std::vector<float> mvaVec(tSize, -99);
689 for (
unsigned int i = 0;
i < rSize;
i++) {
690 unsigned int tNum =
i % tSize;
691 mvaVec[tNum] = trackMVAs[tNum];
694 fillerMVA.insert(trackHandles[0], mvaVec.begin(), mvaVec.end());
698 auto mvas = std::make_unique<MVACollection>(mvaVec.begin(), mvaVec.end());
708 std::vector<reco::TrackRef> trackRefs(rSize);
709 std::vector<edm::RefToBase<TrajectorySeed>> seedsRefs(rSize);
711 unsigned int nToWrite = 0;
712 for (
unsigned int i = 0;
i < rSize;
i++)
713 if (selected[
i] != 0)
716 std::vector<float> mvaVec;
718 outputTrks = std::make_unique<reco::TrackCollection>();
726 outputTrkHits = std::make_unique<TrackingRecHitCollection>();
730 outputSeeds = std::make_unique<TrajectorySeedCollection>();
736 outputTrajs = std::make_unique<std::vector<Trajectory>>();
739 for (
unsigned int i = 0;
i < rSize;
i++) {
740 if (selected[
i] == 0) {
745 unsigned int collNum = trackCollNum[
i];
746 unsigned int trackNum =
i - trackCollFirsts[collNum];
749 mvaVec.push_back(trackMVAs[
i]);
750 if (selected[
i] > 1) {
751 outputTrks->back().setQualityMask(selected[
i] - 10);
756 if (selected[
i] == 1)
758 outputTrks->back().setOriginalAlgorithm(oriAlgo[
i]);
768 bool doRekeyOnThisSeed =
false;
772 if (origSeedRef->
nHits() != 0) {
781 doRekeyOnThisSeed =
e.getByLabel(clusterRemovalInfos, CRIh);
785 if (doRekeyOnThisSeed && !(clusterRemovalInfos ==
edm::InputTag(
""))) {
791 refSetter.
reKey(&newRecHitContainer.
back());
807 track->outerMomentum(),
809 track->innerPosition(),
810 track->innerMomentum(),
812 track->outerStateCovariance(),
814 track->innerStateCovariance(),
816 track->seedDirection(),
818 seedsRefs[
i] = origSeedRef;
824 unsigned nh1 =
track->recHitsSize();
828 for (
auto hh =
track->recHitsBegin(), eh =
track->recHitsEnd();
hh != eh; ++
hh) {
837 refTrajs =
e.getRefBeforePut<std::vector<Trajectory>>();
841 for (
unsigned int ti = 0; ti < trackColls.size(); ti++) {
850 for (
size_t i = 0,
n = hTraj1->size();
i <
n; ++
i) {
855 uint32_t oldKey = trackCollFirsts[ti] +
static_cast<uint32_t
>(trkRef.
key());
856 if (trackRefs[oldKey].isNonnull()) {
871 fillerMVA.insert(outHandle, mvaVec.begin(), mvaVec.end());
877 auto mvas = std::make_unique<MVACollection>(mvaVec.begin(), mvaVec.end());
894 auto vm = std::make_unique<edm::ValueMap<int>>();
896 auto quals = std::make_unique<QualityMaskCollection>();
899 auto outputTrks = std::make_unique<reco::TrackCollection>();
903 auto outputSeeds = std::make_unique<TrajectorySeedCollection>();
909 auto outputTrkHits = std::make_unique<TrackingRecHitCollection>();
914 auto outputTrajs = std::make_unique<std::vector<Trajectory>>();
915 outputTTAss = std::make_unique<TrajTrackAssociationCollection>();
919 auto vmMVA = std::make_unique<edm::ValueMap<float>>();
921 auto mvas = std::make_unique<MVACollection>();
TrackListMerger(const edm::ParameterSet &conf)
std::vector< unsigned char > QualityMaskCollection
T getParameter(std::string const &) const
std::vector< bool > promoteQuality_
std::unique_ptr< TrajTrackAssociationCollection > outputTTAss
ProductID id() const
Accessor for product ID.
const bool isValid(const Frame &aFrame, const FrameQuality &aQuality, const uint16_t aExpectedPos)
reco::TrackRefProd refTrks
RecHitRange recHits() const
void returnEmptyCollections(edm::Event &e)
TkEDGetTokenss edTokens(const edm::InputTag &tag, const edm::InputTag &mvatag)
TrackQuality
track quality
std::string const & productInstanceName() const
std::vector< ParameterSet > VParameterSet
bool exists(std::string const ¶meterName) const
checks if a parameter exists
reco::TrackBase::TrackQuality qualityToSet_
std::vector< Track > TrackCollection
collection of Tracks
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
std::vector< float > MVACollection
std::unique_ptr< std::vector< Trajectory > > outputTrajs
key_type key() const
Accessor for product key.
const_iterator find(const key_type &k) const
find element with specified reference key
TrackAlgorithm
track algorithm
TrackingRecHitRefProd refTrkHits
void produce(edm::Event &e, const edm::EventSetup &c) override
std::vector< double > indivShareFrac_
const_iterator end() const
last iterator over the map (read only)
T getUntrackedParameter(std::string const &, T const &) const
PropagationDirection direction() const
std::unique_ptr< TrackingRecHitCollection > outputTrkHits
edm::EDGetTokenT< edm::ValueMap< int > > tsel
std::vector< TrajectorySeed > TrajectorySeedCollection
std::string const & moduleLabel() const
unsigned int nHits() const
edm::RefProd< TrajectorySeedCollection > refTrajSeeds
edm::EDGetTokenT< reco::TrackCollection > tk
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Abs< T >::type abs(const T &t)
std::string const & processName() const
TkEDGetTokenss edTokens(const edm::InputTag &tag, const edm::InputTag &seltag, const edm::InputTag &mvatag)
#define DEFINE_FWK_MODULE(type)
edm::ESGetToken< TrackAlgoPriorityOrder, CkfComponentsRecord > priorityToken
edm::EDGetTokenT< TrajTrackAssociationCollection > tass
edm::RefProd< std::vector< Trajectory > > refTrajs
ALPAKA_FN_ACC ALPAKA_FN_INLINE void uint32_t const uint32_t CACellT< TrackerTraits > uint32_t CellNeighborsVector< TrackerTraits > CellTracksVector< TrackerTraits > HitsConstView< TrackerTraits > hh
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
PTrajectoryStateOnDet const & startingState() const
std::unique_ptr< reco::TrackExtraCollection > outputTrkExtras
std::vector< int > hasSelector_
ProductID id() const
Accessor for product ID.
std::vector< TrackExtra > TrackExtraCollection
collection of TrackExtra objects
double maxNormalizedChisq_
static TrackQuality qualityByName(const std::string &name)
std::unique_ptr< TrajectorySeedCollection > outputSeeds
edm::EDGetTokenT< edm::ValueMap< float > > tmva
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
constexpr std::array< unsigned int, reco::TrackBase::algoSize > trackAlgoPriorityOrder
void reKey(TrackingRecHit *hit) const
std::vector< TkEDGetTokenss > trackProducers_
TkEDGetTokenss(const edm::InputTag &tag_, edm::EDGetTokenT< reco::TrackCollection > &&tk_, edm::EDGetTokenT< std::vector< Trajectory >> &&traj_, edm::EDGetTokenT< TrajTrackAssociationCollection > &&tass_, edm::EDGetTokenT< edm::ValueMap< int >> &&tsel_, edm::EDGetTokenT< edm::ValueMap< float >> &&tmva_)
std::vector< std::vector< int > > listsToMerge_
std::unique_ptr< reco::TrackCollection > outputTrks
edm::EDGetTokenT< std::vector< Trajectory > > traj
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Log< level::Warning, false > LogWarning
std::string priorityName_
reco::TrackExtraRefProd refTrkExtras