73 tag(tag_), tk(tk_), traj(traj_), tass(tass_), tsel(tsel_), tmva(tmva_) {}
77 consumes<std::vector<Trajectory> >(tag), consumes<TrajTrackAssociationCollection >(tag),
82 consumes<std::vector<Trajectory> >(tag), consumes<TrajTrackAssociationCollection >(tag),
137 #include <x86intrin.h>
142 inline volatile unsigned long long rdtsc() {
149 unsigned long long st;
150 long long totBegin=0;
153 unsigned long long timeNo;
154 unsigned long long timeOv;
158 void start() { st=rdtsc(); }
159 void noOverlap() { timeNo += (rdtsc()-st);}
160 void overlap() { timeOv += (rdtsc()-st);}
161 void pre(
int tt) { totPre+=
tt;}
162 void end(
int tt) { totEnd+=
tt;}
163 void de(
float d) {
if (d>maxDE) maxDE=
d;}
164 void dp(
float d) {
if (d>maxDP) maxDP=
d;}
168 std::cout <<
"TrackListMerger stat\nBegin/Pre/End/maxDPhi/maxDEta/Overlap/NoOverlap "
169 << totBegin <<
'/'<< totPre <<
'/'<< totEnd <<
'/'<< maxDP <<
'/'<< maxDE
170 <<
'/'<< timeOv/1000 <<
'/'<< timeNo/1000
174 ~StatCount() {
print();}
191 [[cms::thread_safe]] StatCount statCount;
209 std::vector<edm::InputTag> trackProducerTags(conf.
getParameter<std::vector<edm::InputTag> >(
"TrackProducers"));
222 if (qualityStr !=
"") {
233 for (
unsigned int i=0;
i<setsToMerge.size();
i++) {
234 listsToMerge_.push_back(setsToMerge[
i].getParameter<std::vector< int> >(
"tLists"));
240 std::vector<edm::InputTag> selectors(conf.
getParameter<std::vector<edm::InputTag> >(
"selectedTrackQuals"));
241 std::vector<edm::InputTag> mvaStores;
242 if(conf.
exists(
"mvaValueTags")){
243 mvaStores = conf.
getParameter<std::vector<edm::InputTag> >(
"mvaValueTags");
245 for (
int i = 0;
i < (int)selectors.size();
i++){
247 mvaStores.push_back(ntag);
250 unsigned int numTrkColl = trackProducerTags.size();
251 if (numTrkColl !=
hasSelector_.size() || numTrkColl != selectors.size()) {
252 throw cms::Exception(
"Inconsistent size") <<
"need same number of track collections and selectors";
254 if (numTrkColl !=
hasSelector_.size() || numTrkColl != mvaStores.size()) {
255 throw cms::Exception(
"Inconsistent size") <<
"need same number of track collections and MVA stores";
257 for (
unsigned int i = indivShareFrac_.size();
i < numTrkColl;
i++) {
259 indivShareFrac_.push_back(1.0);
265 for (
unsigned int i=1;
i<numTrkColl;
i++) {
266 if (!(trackProducerTags[
i]==trackProducerTags[0])) ok=
false;
269 throw cms::Exception(
"Bad input") <<
"to use writeOnlyTrkQuals=True all input InputTags must be the same";
271 produces<edm::ValueMap<int> >();
272 produces<QualityMaskCollection>(
"QualityMasks");
275 produces<reco::TrackCollection>();
278 if (makeReKeyedSeeds_){
280 produces<TrajectorySeedCollection>();
284 produces<reco::TrackExtraCollection>();
285 produces<TrackingRecHitCollection>();
287 produces< std::vector<Trajectory> >();
288 produces< TrajTrackAssociationCollection >();
290 produces<edm::ValueMap<float> >(
"MVAVals");
291 produces<MVACollection>(
"MVAValues");
295 for (
unsigned int i = 0;
i < numTrkColl; ++
i) {
321 std::vector<const reco::TrackCollection *> trackColls;
322 std::vector<edm::Handle<reco::TrackCollection> > trackHandles(
trackProducers_.size());
324 trackColls.push_back(0);
327 if (trackHandles[i].isValid()) {
328 trackColls[
i]= trackHandles[
i].product();
331 trackColls[
i]=&s_empty;
335 unsigned int collsSize =trackColls.size();
336 unsigned int rSize=0;
337 unsigned int trackCollSizes[collsSize];
338 unsigned int trackCollFirsts[collsSize];
339 for (
unsigned int i=0;
i!=collsSize;
i++) {
340 trackCollSizes[
i]=trackColls[
i]->size();
341 trackCollFirsts[
i]=rSize;
342 rSize+=trackCollSizes[
i];
345 statCount.begin(rSize);
354 bool trkUpdated[rSize];
355 int trackCollNum[rSize];
356 int trackQuals[rSize];
357 float trackMVAs[rSize];
359 std::vector<reco::TrackBase::AlgoMask> algoMask(rSize);
360 for (
unsigned int j=0;
j<rSize;
j++) {
365 for (
unsigned int j=0;
j!= collsSize;
j++) {
376 if ( 0<tC1->size() ){
378 for (reco::TrackCollection::const_iterator track=tC1->begin(); track!=tC1->end(); track++){
381 trackQuals[
i]=track->qualityMask();
382 oriAlgo[
i]=track->originalAlgo();
383 algoMask[
i]=track->algoMask();
387 if( (*trackMVAStore).contains(trkRef.
id()) ) trackMVAs[
i] = (*trackMVAStore)[trkRef];
389 int qual=(*trackSelColl)[trkRef];
399 selected[
i]=trackQuals[
i]+10;
400 if ((
short unsigned)track->ndof() < 1){
412 if (track->pt() <
minPT_){
424 statCount.pre(ngood);
427 typedef std::pair<unsigned int, const TrackingRecHit*> IHit;
428 std::vector<std::vector<IHit>> rh1(ngood);
434 for (
unsigned int j=0;
j<rSize;
j++) {
435 if (selected[
j]==0)
continue;
438 unsigned int collNum=trackCollNum[
j];
439 unsigned int trackNum=
j-trackCollFirsts[collNum];
440 const reco::Track *track=&((trackColls[collNum])->at(trackNum));
442 algo[
i]=track->
algo();
449 rh1[
i].reserve(validHits) ;
450 auto compById = [](IHit
const & h1, IHit
const & h2) {
return h1.first < h2.first;};
453 unsigned int id = hit->
rawId() ;
455 if likely(hit->
isValid()) { rh1[
i].emplace_back(
id,hit); std::push_heap(rh1[i].
begin(),rh1[i].
end(),compById); }
457 std::sort_heap(rh1[i].
begin(),rh1[i].
end(),compById);
461 if likely(ngood>1 && collsSize>1)
463 int saveSelected[rSize];
464 bool notActive[collsSize];
465 for (
unsigned int cn=0;cn!=collsSize;++cn)
468 for (
unsigned int i=0; i<rSize; i++) saveSelected[i]=selected[i];
471 for (
unsigned int i=0; i<rSize-1; i++) {
472 if (selected[i]==0)
continue;
473 unsigned int collNum=trackCollNum[
i];
476 if (notActive[collNum])
continue;
479 unsigned int nh1=rh1[k1].size();
480 int qualityMaskT1 = trackQuals[
i];
483 float score1 = score[k1];
486 for (
unsigned int j=i+1;
j<rSize;
j++) {
487 if (selected[
j]==0)
continue;
488 unsigned int collNum2=trackCollNum[
j];
489 if ( (collNum == collNum2) &&
indivShareFrac_[collNum] > 0.99)
continue;
491 if (notActive[collNum2])
continue;
495 int newQualityMask = -9;
497 int maskT1= saveSelected[
i]>1? saveSelected[
i]-10 : qualityMaskT1;
498 int maskT2= saveSelected[
j]>1? saveSelected[
j]-10 : trackQuals[
j];
499 newQualityMask =(maskT1 | maskT2);
501 unsigned int nh2=rh1[
k2].size();
521 if (share(it,jt,
epsilon_)) firstoverlap=1;
528 while (ih!=nh1 && jh!=nh2) {
532 auto const id1 = rh1[k1][ih].first;
533 auto const id2 = rh1[
k2][jh].first;
535 else if (id2<id1) ++jh;
538 auto li=ih;
while( (++li)!=nh1 && id1 == rh1[k1][li].first);
539 auto lj=jh;
while( (++lj)!=nh2 && id2 == rh1[k2][lj].first);
540 for (
auto ii=ih;
ii!=li; ++
ii)
541 for (
auto jj=jh;
jj!=lj; ++
jj) {
544 if (share(it,jt,
epsilon_)) noverlap++;
551 bool dupfound = (collNum != collNum2) ? (noverlap-firstoverlap) > (
std::min(nhit1,nhit2)-firstoverlap)*
shareFrac_ :
554 auto seti = [&](
unsigned int ii,
unsigned int jj) {
556 selected[
ii]=10+newQualityMask;
559 algoMask[
ii] |= algoMask[
jj];
560 algoMask[
jj] = algoMask[
ii];
564 float score2 = score[
k2];
566 if ( score1 - score2 > almostSame ) {
568 }
else if ( score2 - score1 > almostSame ) {
596 statCount.noOverlap();
599 if (selected[i]==0)
break;
606 std::auto_ptr<edm::ValueMap<float> > vmMVA = std::auto_ptr<edm::ValueMap<float> >(
new edm::ValueMap<float>);
613 unsigned int tSize=trackColls[0]->size();
614 std::auto_ptr<edm::ValueMap<int> > vm = std::auto_ptr<edm::ValueMap<int> >(
new edm::ValueMap<int>);
617 std::vector<int> finalQuals(tSize,-1);
618 for (
unsigned int i=0; i<rSize; i++) {
619 unsigned int tNum=i%tSize;
621 if (selected[i]>1 ) {
622 finalQuals[tNum]=selected[
i]-10;
626 if ( selected[i]==1 )
627 finalQuals[tNum]=trackQuals[
i];
630 filler.insert(trackHandles[0], finalQuals.begin(),finalQuals.end());
635 auto quals = std::make_unique<QualityMaskCollection>(finalQuals.begin(),finalQuals.end());
638 std::vector<float> mvaVec(tSize,-99);
640 for(
unsigned int i = 0; i < rSize; i++){
641 unsigned int tNum = i % tSize;
642 mvaVec[tNum] = trackMVAs[tNum];
645 fillerMVA.insert(trackHandles[0],mvaVec.begin(),mvaVec.end());
648 e.
put(vmMVA,
"MVAVals");
649 auto mvas = std::make_unique<MVACollection>(mvaVec.begin(),mvaVec.end());
660 std::vector<reco::TrackRef> trackRefs(rSize);
661 std::vector<edm::RefToBase<TrajectorySeed>> seedsRefs(rSize);
663 unsigned int nToWrite=0;
664 for (
unsigned int i=0; i<rSize; i++)
665 if (selected[i]!=0) nToWrite++;
667 std::vector<float> mvaVec;
678 outputTrkHits->reserve(nToWrite*25);
688 outputTrajs = std::auto_ptr< std::vector<Trajectory> >(
new std::vector<Trajectory>());
691 for (
unsigned int i=0; i<rSize; i++) {
692 if (selected[i]==0) {
697 unsigned int collNum=trackCollNum[
i];
698 unsigned int trackNum=i-trackCollFirsts[collNum];
699 const reco::Track *track=&((trackColls[collNum])->at(trackNum));
701 mvaVec.push_back(trackMVAs[i]);
702 if (selected[i]>1 ) {
703 outputTrks->back().setQualityMask(selected[i]-10);
708 if ( selected[i]==1 )
709 outputTrks->back().setQualityMask(trackQuals[i]);
710 outputTrks->back().setOriginalAlgorithm(oriAlgo[i]);
720 bool doRekeyOnThisSeed=
false;
724 if (origSeedRef->
nHits()!=0){
727 if (firstHit->isValid()){
736 doRekeyOnThisSeed=e.
getByLabel(clusterRemovalInfos,CRIh);
740 if (doRekeyOnThisSeed && !(clusterRemovalInfos==
edm::InputTag(
""))) {
746 for (;iH!=iH_end;++iH){
748 refSetter.
reKey(&newRecHitContainer.
back());
770 seedsRefs[
i]=origSeedRef;
792 for (
unsigned int ti=0; ti<trackColls.size(); ti++) {
800 for (
size_t i = 0,
n = hTraj1->size(); i <
n; ++
i) {
803 if (match != hTTAss1->end()) {
805 uint32_t oldKey = trackCollFirsts[ti]+
static_cast<uint32_t
>(trkRef.
key());
806 if (trackRefs[oldKey].isNonnull()) {
810 outputTrajs->back().setSeedRef( seedsRefs[oldKey] );
822 fillerMVA.insert(outHandle,mvaVec.begin(),mvaVec.end());
827 e.
put(vmMVA,
"MVAVals");
828 auto mvas = std::make_unique<MVACollection>(mvaVec.begin(),mvaVec.end());
PropagationDirection direction() const
std::auto_ptr< reco::TrackCollection > outputTrks
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
TrackListMerger(const edm::ParameterSet &conf)
std::vector< unsigned char > QualityMaskCollection
tuple start
Check for commandline option errors.
std::vector< bool > promoteQuality_
friend struct const_iterator
reco::TrackRefProd refTrks
bool getByToken(EDGetToken token, Handle< PROD > &result) const
edm::EDGetTokenT< TrajTrackAssociationCollection > tass
edm::RefProd< std::vector< Trajectory > > refTrajs
TkEDGetTokenss edTokens(const edm::InputTag &tag, const edm::InputTag &mvatag)
virtual void produce(Event &, EventSetup const &)=0
TrackQuality
track quality
#define DEFINE_FWK_MODULE(type)
size_t recHitsSize() const
Get number of RecHits. (Warning, this includes invalid hits, which are not physical hits)...
std::vector< ParameterSet > VParameterSet
std::string print(const Track &, edm::Verbosity=edm::Concise)
Track print utility.
void reKey(TrackingRecHit *hit) const
reco::TrackBase::TrackQuality qualityToSet_
std::vector< Track > TrackCollection
collection of Tracks
bool exists(std::string const ¶meterName) const
checks if a parameter exists
bool innerOk() const
return true if the innermost hit is valid
unsigned short numberOfLostHits() const
number of cases where track crossed a layer without getting a hit.
key_type key() const
Accessor for product key.
std::string const & processName() const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
const math::XYZPoint & outerPosition() const
position of the outermost hit
std::vector< float > MVACollection
edm::RefProd< TrajectorySeedCollection > refTrajSeeds
ProductID id() const
Accessor for product ID.
TrackAlgorithm
track algorithm
TrackingRecHitRefProd refTrkHits
virtual void produce(edm::Event &e, const edm::EventSetup &c) override
std::vector< double > indivShareFrac_
bool overlap(const reco::Muon &muon1, const reco::Muon &muon2, double pullX=1.0, double pullY=1.0, bool checkAdjacentChambers=false)
const math::XYZPoint & innerPosition() const
position of the innermost hit
TrackAlgorithm algo() const
std::auto_ptr< TrackingRecHitCollection > outputTrkHits
edm::EDGetTokenT< edm::ValueMap< int > > tsel
std::vector< TrajectorySeed > TrajectorySeedCollection
double chi2() const
chi-squared of the fit
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
recHitContainer::const_iterator const_iterator
CovarianceMatrix outerStateCovariance() const
outermost trajectory state curvilinear errors
edm::EDGetTokenT< reco::TrackCollection > tk
unsigned int outerDetId() const
DetId of the detector on which surface the outermost state is located.
Abs< T >::type abs(const T &t)
TkEDGetTokenss edTokens(const edm::InputTag &tag, const edm::InputTag &seltag, const edm::InputTag &mvatag)
unsigned short numberOfValidHits() const
number of valid hits found
std::auto_ptr< TrajTrackAssociationCollection > outputTTAss
trackingRecHit_iterator recHitsBegin() const
Iterator to first hit on the track.
virtual ~TrackListMerger()
edm::AssociationMap< edm::OneToOne< std::vector< Trajectory >, reco::TrackCollection, unsigned short > > TrajTrackAssociationCollection
int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
std::auto_ptr< std::vector< Trajectory > > outputTrajs
std::auto_ptr< TrajectorySeedCollection > outputSeeds
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
RefProd< PROD > getRefBeforePut()
std::vector< int > hasSelector_
std::vector< TrackExtra > TrackExtraCollection
collection of TrackExtra objects
double maxNormalizedChisq_
edm::OwnVector< TrackingRecHit > TrackingRecHitCollection
collection of TrackingRecHits
edm::RefToBase< TrajectorySeed > seedRef() const
PTrajectoryStateOnDet const & startingState() const
static TrackQuality qualityByName(const std::string &name)
const math::XYZVector & outerMomentum() const
momentum vector at the outermost hit position
bool outerOk() const
return true if the outermost hit is valid
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
edm::EDGetTokenT< edm::ValueMap< float > > tmva
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
CovarianceMatrix innerStateCovariance() const
innermost trajectory state curvilinear errors
std::string const & moduleLabel() const
std::auto_ptr< reco::TrackExtraCollection > outputTrkExtras
unsigned int nHits() const
std::vector< TkEDGetTokenss > trackProducers_
const math::XYZVector & innerMomentum() const
momentum vector at the innermost hit position
ProductID id() const
Accessor for product ID.
const TrackResiduals & residuals() const
int numberOfValidPixelHits() const
edm::EDGetTokenT< std::vector< Trajectory > > traj
PropagationDirection seedDirection() const
direction of how the hits were sorted in the original seed
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
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_)
DetId geographicalId() const
std::string const & productInstanceName() const
std::vector< std::vector< int > > listsToMerge_
Provenance getProvenance(BranchID const &theID) const
virtual LocalPoint localPosition() const =0
unsigned int innerDetId() const
DetId of the detector on which surface the innermost state is located.
reco::TrackExtraRefProd refTrkExtras
TrackingRecHitCollection::base::const_iterator trackingRecHit_iterator
iterator over a vector of reference to TrackingRecHit in the same collection
trackingRecHit_iterator recHitsEnd() const
Iterator to last hit on the track.