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;
161 void begin(
int tt) { totBegin +=
tt; }
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");
279 produces<reco::TrackCollection>();
284 produces<TrajectorySeedCollection>();
288 produces<reco::TrackExtraCollection>();
289 produces<TrackingRecHitCollection>();
291 produces<std::vector<Trajectory>>();
292 produces<TrajTrackAssociationCollection>();
294 produces<edm::ValueMap<float>>(
"MVAVals");
295 produces<MVACollection>(
"MVAValues");
299 for (
unsigned int i = 0;
i < numTrkColl; ++
i) {
301 :
edTokens(trackProducerTags[
i], mvaStores[
i]);
324 std::vector<const reco::TrackCollection*> trackColls;
325 std::vector<edm::Handle<reco::TrackCollection>> trackHandles(
trackProducers_.size());
327 trackColls.push_back(
nullptr);
331 trackColls[
i] = trackHandles[
i].product();
334 trackColls[
i] = &s_empty;
338 if (trackColls.empty()) {
344 unsigned int collsSize = trackColls.size();
345 unsigned int rSize = 0;
346 unsigned int trackCollSizes[collsSize];
347 unsigned int trackCollFirsts[collsSize];
348 for (
unsigned int i = 0;
i != collsSize;
i++) {
349 trackCollSizes[
i] = trackColls[
i]->size();
350 trackCollFirsts[
i] = rSize;
351 rSize += trackCollSizes[
i];
360 statCount.begin(rSize);
369 bool trkUpdated[rSize];
370 int trackCollNum[rSize];
371 int trackQuals[rSize];
372 float trackMVAs[rSize];
374 std::vector<reco::TrackBase::AlgoMask> algoMask(rSize);
375 for (
unsigned int j = 0;
j < rSize;
j++) {
378 trkUpdated[
j] =
false;
381 trackMVAs[
j] = -998.0;
386 for (
unsigned int j = 0;
j != collsSize;
j++) {
399 for (reco::TrackCollection::const_iterator
track = tC1->begin();
track != tC1->end();
track++) {
402 trackQuals[
i] =
track->qualityMask();
403 oriAlgo[
i] =
track->originalAlgo();
404 algoMask[
i] =
track->algoMask();
408 if ((*trackMVAStore).contains(trkRef.
id()))
409 trackMVAs[
i] = (*trackMVAStore)[trkRef];
411 int qual = (*trackSelColl)[trkRef];
417 trackQuals[
i] = qual;
421 selected[
i] = trackQuals[
i] + 10;
422 if ((
short unsigned)
track->ndof() < 1) {
445 statCount.pre(ngood);
448 typedef std::pair<unsigned int, const TrackingRecHit*> IHit;
449 std::vector<std::vector<IHit>> rh1(ngood);
454 for (
unsigned int j = 0;
j < rSize;
j++) {
455 if (selected[
j] == 0)
459 unsigned int collNum = trackCollNum[
j];
460 unsigned int trackNum =
j - trackCollFirsts[collNum];
464 int validHits =
track->numberOfValidHits();
465 int validPixelHits =
track->hitPattern().numberOfValidPixelHits();
470 rh1[
i].reserve(validHits);
471 auto compById = [](IHit
const& h1, IHit
const& h2) {
return h1.first < h2.first; };
474 unsigned int id =
hit->rawId();
475 if (
hit->geographicalId().subdetId() > 2)
478 rh1[
i].emplace_back(
id,
hit);
479 std::push_heap(rh1[
i].begin(), rh1[
i].
end(), compById);
482 std::sort_heap(rh1[
i].begin(), rh1[
i].
end(), compById);
486 if LIKELY (ngood > 1 && collsSize > 1)
487 for (
unsigned int ltm = 0; ltm <
listsToMerge_.size(); ltm++) {
488 int saveSelected[rSize];
489 bool notActive[collsSize];
490 for (
unsigned int cn = 0; cn != collsSize; ++cn)
493 for (
unsigned int i = 0;
i < rSize;
i++)
494 saveSelected[
i] = selected[
i];
497 for (
unsigned int i = 0;
i < rSize - 1;
i++) {
498 if (selected[
i] == 0)
500 unsigned int collNum = trackCollNum[
i];
503 if (notActive[collNum])
507 unsigned int nh1 = rh1[k1].size();
508 int qualityMaskT1 = trackQuals[
i];
511 float score1 =
score[k1];
514 for (
unsigned int j =
i + 1;
j < rSize;
j++) {
515 if (selected[
j] == 0)
517 unsigned int collNum2 = trackCollNum[
j];
521 if (notActive[collNum2])
526 int newQualityMask = -9;
528 int maskT1 = saveSelected[
i] > 1 ? saveSelected[
i] - 10 : qualityMaskT1;
529 int maskT2 = saveSelected[
j] > 1 ? saveSelected[
j] - 10 : trackQuals[
j];
530 newQualityMask = (maskT1 | maskT2);
532 unsigned int nh2 = rh1[k2].size();
547 int firstoverlap = 0;
559 while (ih != nh1 && jh != nh2) {
563 auto const id1 = rh1[k1][ih].first;
564 auto const id2 = rh1[k2][jh].first;
572 while ((++li) != nh1 &&
id1 == rh1[k1][li].
first) {
575 while ((++lj) != nh2 &&
id2 == rh1[k2][lj].
first) {
577 for (
auto ii = ih;
ii != li; ++
ii)
578 for (
auto jj = jh;
jj != lj; ++
jj) {
591 (collNum != collNum2)
595 auto seti = [&](
unsigned int ii,
unsigned int jj) {
597 selected[
ii] = 10 + newQualityMask;
598 trkUpdated[
ii] =
true;
600 oriAlgo[
ii] = oriAlgo[
jj];
601 algoMask[
ii] |= algoMask[
jj];
602 algoMask[
jj] = algoMask[
ii];
606 float score2 =
score[k2];
607 constexpr
float almostSame =
609 if (score1 - score2 > almostSame) {
611 }
else if (score2 - score1 > almostSame) {
643 statCount.noOverlap();
646 if (selected[
i] == 0)
652 auto vmMVA = std::make_unique<edm::ValueMap<float>>();
657 unsigned int tSize = trackColls[0]->size();
658 auto vm = std::make_unique<edm::ValueMap<int>>();
661 std::vector<int> finalQuals(tSize, -1);
662 for (
unsigned int i = 0;
i < rSize;
i++) {
663 unsigned int tNum =
i % tSize;
665 if (selected[
i] > 1) {
666 finalQuals[tNum] = selected[
i] - 10;
668 finalQuals[tNum] = (finalQuals[tNum] | (1 <<
qualityToSet_));
670 if (selected[
i] == 1)
671 finalQuals[tNum] = trackQuals[
i];
674 filler.insert(trackHandles[0], finalQuals.begin(), finalQuals.end());
678 for (
auto&
q : finalQuals)
680 auto quals = std::make_unique<QualityMaskCollection>(finalQuals.begin(), finalQuals.end());
683 std::vector<float> mvaVec(tSize, -99);
685 for (
unsigned int i = 0;
i < rSize;
i++) {
686 unsigned int tNum =
i % tSize;
687 mvaVec[tNum] = trackMVAs[tNum];
690 fillerMVA.insert(trackHandles[0], mvaVec.begin(), mvaVec.end());
694 auto mvas = std::make_unique<MVACollection>(mvaVec.begin(), mvaVec.end());
704 std::vector<reco::TrackRef> trackRefs(rSize);
705 std::vector<edm::RefToBase<TrajectorySeed>> seedsRefs(rSize);
707 unsigned int nToWrite = 0;
708 for (
unsigned int i = 0;
i < rSize;
i++)
709 if (selected[
i] != 0)
712 std::vector<float> mvaVec;
714 outputTrks = std::make_unique<reco::TrackCollection>();
722 outputTrkHits = std::make_unique<TrackingRecHitCollection>();
726 outputSeeds = std::make_unique<TrajectorySeedCollection>();
732 outputTrajs = std::make_unique<std::vector<Trajectory>>();
735 for (
unsigned int i = 0;
i < rSize;
i++) {
736 if (selected[
i] == 0) {
741 unsigned int collNum = trackCollNum[
i];
742 unsigned int trackNum =
i - trackCollFirsts[collNum];
745 mvaVec.push_back(trackMVAs[
i]);
746 if (selected[
i] > 1) {
747 outputTrks->back().setQualityMask(selected[
i] - 10);
752 if (selected[
i] == 1)
754 outputTrks->back().setOriginalAlgorithm(oriAlgo[
i]);
764 bool doRekeyOnThisSeed =
false;
768 if (origSeedRef->
nHits() != 0) {
777 doRekeyOnThisSeed =
e.getByLabel(clusterRemovalInfos, CRIh);
781 if (doRekeyOnThisSeed && !(clusterRemovalInfos ==
edm::InputTag(
""))) {
787 refSetter.
reKey(&newRecHitContainer.
back());
803 track->outerMomentum(),
805 track->innerPosition(),
806 track->innerMomentum(),
808 track->outerStateCovariance(),
810 track->innerStateCovariance(),
812 track->seedDirection(),
814 seedsRefs[
i] = origSeedRef;
820 unsigned nh1 =
track->recHitsSize();
824 for (
auto hh =
track->recHitsBegin(), eh =
track->recHitsEnd();
hh != eh; ++
hh) {
833 refTrajs =
e.getRefBeforePut<std::vector<Trajectory>>();
837 for (
unsigned int ti = 0; ti < trackColls.size(); ti++) {
846 for (
size_t i = 0,
n = hTraj1->size();
i <
n; ++
i) {
851 uint32_t oldKey = trackCollFirsts[ti] +
static_cast<uint32_t
>(trkRef.
key());
852 if (trackRefs[oldKey].isNonnull()) {
867 fillerMVA.insert(outHandle, mvaVec.begin(), mvaVec.end());
873 auto mvas = std::make_unique<MVACollection>(mvaVec.begin(), mvaVec.end());
890 auto vm = std::make_unique<edm::ValueMap<int>>();
892 auto quals = std::make_unique<QualityMaskCollection>();
895 auto outputTrks = std::make_unique<reco::TrackCollection>();
899 auto outputSeeds = std::make_unique<TrajectorySeedCollection>();
905 auto outputTrkHits = std::make_unique<TrackingRecHitCollection>();
910 auto outputTrajs = std::make_unique<std::vector<Trajectory>>();
911 outputTTAss = std::make_unique<TrajTrackAssociationCollection>();
915 auto vmMVA = std::make_unique<edm::ValueMap<float>>();
917 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)
friend struct const_iterator
reco::TrackRefProd refTrks
RecHitRange recHits() const
void returnEmptyCollections(edm::Event &e)
TkEDGetTokenss edTokens(const edm::InputTag &tag, const edm::InputTag &mvatag)
TrackQuality
track quality
#define DEFINE_FWK_MODULE(type)
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)
edm::ESGetToken< TrackAlgoPriorityOrder, CkfComponentsRecord > priorityToken
edm::EDGetTokenT< TrajTrackAssociationCollection > tass
edm::RefProd< std::vector< Trajectory > > refTrajs
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)
DetId geographicalId() const
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_
virtual LocalPoint localPosition() const =0
reco::TrackExtraRefProd refTrkExtras