69 tag(tag_), tk(tk_), traj(traj_), tass(tass_), tsel(tsel_), tmva(tmva_) {}
73 consumes<std::vector<Trajectory> >(tag), consumes<TrajTrackAssociationCollection >(tag),
78 consumes<std::vector<Trajectory> >(tag), consumes<TrajTrackAssociationCollection >(tag),
133 #include <x86intrin.h>
138 inline volatile unsigned long long rdtsc() {
145 unsigned long long st;
146 long long totBegin=0;
149 unsigned long long timeNo;
150 unsigned long long timeOv;
154 void start() { st=rdtsc(); }
155 void noOverlap() { timeNo += (rdtsc()-st);}
156 void overlap() { timeOv += (rdtsc()-st);}
157 void pre(
int tt) { totPre+=
tt;}
158 void end(
int tt) { totEnd+=
tt;}
159 void de(
float d) {
if (d>maxDE) maxDE=
d;}
160 void dp(
float d) {
if (d>maxDP) maxDP=
d;}
164 std::cout <<
"TrackListMerger stat\nBegin/Pre/End/maxDPhi/maxDEta/Overlap/NoOverlap "
165 << totBegin <<
'/'<< totPre <<
'/'<< totEnd <<
'/'<< maxDP <<
'/'<< maxDE
166 <<
'/'<< timeOv/1000 <<
'/'<< timeNo/1000
170 ~StatCount() {
print();}
187 [[cms::thread_safe]] StatCount statCount;
205 std::vector<edm::InputTag> trackProducerTags(conf.
getParameter<std::vector<edm::InputTag> >(
"TrackProducers"));
218 if (qualityStr !=
"") {
229 for (
unsigned int i=0;
i<setsToMerge.size();
i++) {
230 listsToMerge_.push_back(setsToMerge[
i].getParameter<std::vector< int> >(
"tLists"));
236 std::vector<edm::InputTag> selectors(conf.
getParameter<std::vector<edm::InputTag> >(
"selectedTrackQuals"));
237 std::vector<edm::InputTag> mvaStores;
238 if(conf.
exists(
"mvaValueTags")){
239 mvaStores = conf.
getParameter<std::vector<edm::InputTag> >(
"mvaValueTags");
241 for (
int i = 0;
i < (int)selectors.size();
i++){
243 mvaStores.push_back(ntag);
246 unsigned int numTrkColl = trackProducerTags.size();
247 if (numTrkColl !=
hasSelector_.size() || numTrkColl != selectors.size()) {
248 throw cms::Exception(
"Inconsistent size") <<
"need same number of track collections and selectors";
250 if (numTrkColl !=
hasSelector_.size() || numTrkColl != mvaStores.size()) {
251 throw cms::Exception(
"Inconsistent size") <<
"need same number of track collections and MVA stores";
253 for (
unsigned int i = indivShareFrac_.size();
i < numTrkColl;
i++) {
255 indivShareFrac_.push_back(1.0);
261 for (
unsigned int i=1;
i<numTrkColl;
i++) {
262 if (!(trackProducerTags[
i]==trackProducerTags[0])) ok=
false;
265 throw cms::Exception(
"Bad input") <<
"to use writeOnlyTrkQuals=True all input InputTags must be the same";
267 produces<edm::ValueMap<int> >();
270 produces<reco::TrackCollection>();
273 if (makeReKeyedSeeds_){
275 produces<TrajectorySeedCollection>();
279 produces<reco::TrackExtraCollection>();
280 produces<TrackingRecHitCollection>();
282 produces< std::vector<Trajectory> >();
283 produces< TrajTrackAssociationCollection >();
285 produces<edm::ValueMap<float> >(
"MVAVals");
289 for (
unsigned int i = 0;
i < numTrkColl; ++
i) {
315 std::vector<const reco::TrackCollection *> trackColls;
316 std::vector<edm::Handle<reco::TrackCollection> > trackHandles(
trackProducers_.size());
318 trackColls.push_back(0);
321 if (trackHandles[i].isValid()) {
322 trackColls[
i]= trackHandles[
i].product();
325 trackColls[
i]=&s_empty;
329 unsigned int collsSize =trackColls.size();
330 unsigned int rSize=0;
331 unsigned int trackCollSizes[collsSize];
332 unsigned int trackCollFirsts[collsSize];
333 for (
unsigned int i=0;
i!=collsSize;
i++) {
334 trackCollSizes[
i]=trackColls[
i]->size();
335 trackCollFirsts[
i]=rSize;
336 rSize+=trackCollSizes[
i];
339 statCount.begin(rSize);
348 bool trkUpdated[rSize];
349 int trackCollNum[rSize];
350 int trackQuals[rSize];
351 float trackMVAs[rSize];
353 std::vector<reco::TrackBase::AlgoMask> algoMask(rSize);
354 for (
unsigned int j=0;
j<rSize;
j++) {
359 for (
unsigned int j=0;
j!= collsSize;
j++) {
370 if ( 0<tC1->size() ){
372 for (reco::TrackCollection::const_iterator track=tC1->begin(); track!=tC1->end(); track++){
375 trackQuals[
i]=track->qualityMask();
376 oriAlgo[
i]=track->originalAlgo();
377 algoMask[
i]=track->algoMask();
381 if( (*trackMVAStore).contains(trkRef.
id()) ) trackMVAs[
i] = (*trackMVAStore)[trkRef];
383 int qual=(*trackSelColl)[trkRef];
393 selected[
i]=trackQuals[
i]+10;
394 if ((
short unsigned)track->ndof() < 1){
406 if (track->pt() <
minPT_){
418 statCount.pre(ngood);
421 typedef std::pair<unsigned int, const TrackingRecHit*> IHit;
422 std::vector<std::vector<IHit>> rh1(ngood);
428 for (
unsigned int j=0;
j<rSize;
j++) {
429 if (selected[
j]==0)
continue;
432 unsigned int collNum=trackCollNum[
j];
433 unsigned int trackNum=
j-trackCollFirsts[collNum];
434 const reco::Track *track=&((trackColls[collNum])->
at(trackNum));
436 algo[
i]=track->
algo();
443 rh1[
i].reserve(validHits) ;
444 auto compById = [](IHit
const & h1, IHit
const & h2) {
return h1.first < h2.first;};
447 unsigned int id = hit->
rawId() ;
449 if likely(hit->
isValid()) { rh1[
i].emplace_back(
id,hit); std::push_heap(rh1[i].
begin(),rh1[i].
end(),compById); }
451 std::sort_heap(rh1[i].
begin(),rh1[i].
end(),compById);
455 if likely(ngood>1 && collsSize>1)
457 int saveSelected[rSize];
458 bool notActive[collsSize];
459 for (
unsigned int cn=0;cn!=collsSize;++cn)
462 for (
unsigned int i=0; i<rSize; i++) saveSelected[i]=selected[i];
465 for (
unsigned int i=0; i<rSize-1; i++) {
466 if (selected[i]==0)
continue;
467 unsigned int collNum=trackCollNum[
i];
470 if (notActive[collNum])
continue;
473 unsigned int nh1=rh1[k1].size();
474 int qualityMaskT1 = trackQuals[
i];
477 float score1 = score[k1];
480 for (
unsigned int j=i+1;
j<rSize;
j++) {
481 if (selected[
j]==0)
continue;
482 unsigned int collNum2=trackCollNum[
j];
483 if ( (collNum == collNum2) &&
indivShareFrac_[collNum] > 0.99)
continue;
485 if (notActive[collNum2])
continue;
489 int newQualityMask = -9;
491 int maskT1= saveSelected[
i]>1? saveSelected[
i]-10 : qualityMaskT1;
492 int maskT2= saveSelected[
j]>1? saveSelected[
j]-10 : trackQuals[
j];
493 newQualityMask =(maskT1 | maskT2);
495 unsigned int nh2=rh1[
k2].size();
515 if (share(it,jt,
epsilon_)) firstoverlap=1;
522 while (ih!=nh1 && jh!=nh2) {
526 auto const id1 = rh1[k1][ih].first;
527 auto const id2 = rh1[
k2][jh].first;
529 else if (id2<id1) ++jh;
532 auto li=ih;
while( (++li)!=nh1 && id1 == rh1[k1][li].first);
533 auto lj=jh;
while( (++lj)!=nh2 && id2 == rh1[k2][lj].first);
534 for (
auto ii=ih;
ii!=li; ++
ii)
535 for (
auto jj=jh;
jj!=lj; ++
jj) {
538 if (share(it,jt,
epsilon_)) noverlap++;
545 bool dupfound = (collNum != collNum2) ? (noverlap-firstoverlap) > (
std::min(nhit1,nhit2)-firstoverlap)*
shareFrac_ :
548 auto seti = [&](
unsigned int ii,
unsigned int jj) {
550 selected[
ii]=10+newQualityMask;
553 algoMask[
ii] |= algoMask[
jj];
554 algoMask[
jj] = algoMask[
ii];
558 float score2 = score[
k2];
560 if ( score1 - score2 > almostSame ) {
562 }
else if ( score2 - score1 > almostSame ) {
590 statCount.noOverlap();
593 if (selected[i]==0)
break;
600 std::auto_ptr<edm::ValueMap<float> > vmMVA = std::auto_ptr<edm::ValueMap<float> >(
new edm::ValueMap<float>);
607 unsigned int tSize=trackColls[0]->size();
608 std::auto_ptr<edm::ValueMap<int> > vm = std::auto_ptr<edm::ValueMap<int> >(
new edm::ValueMap<int>);
611 std::vector<int> finalQuals(tSize,-1);
612 for (
unsigned int i=0; i<rSize; i++) {
613 unsigned int tNum=i%tSize;
615 if (selected[i]>1 ) {
616 finalQuals[tNum]=selected[
i]-10;
620 if ( selected[i]==1 )
621 finalQuals[tNum]=trackQuals[
i];
624 filler.insert(trackHandles[0], finalQuals.begin(),finalQuals.end());
629 std::vector<float> mvaVec(tSize,-99);
631 for(
unsigned int i = 0; i < rSize; i++){
632 unsigned int tNum = i % tSize;
633 mvaVec[tNum] = trackMVAs[tNum];
636 fillerMVA.insert(trackHandles[0],mvaVec.begin(),mvaVec.end());
639 e.
put(vmMVA,
"MVAVals");
648 std::vector<reco::TrackRef> trackRefs(rSize);
649 std::vector<edm::RefToBase<TrajectorySeed>> seedsRefs(rSize);
651 unsigned int nToWrite=0;
652 for (
unsigned int i=0; i<rSize; i++)
653 if (selected[i]!=0) nToWrite++;
655 std::vector<float> mvaVec;
666 outputTrkHits->reserve(nToWrite*25);
676 outputTrajs = std::auto_ptr< std::vector<Trajectory> >(
new std::vector<Trajectory>());
679 for (
unsigned int i=0; i<rSize; i++) {
680 if (selected[i]==0) {
685 unsigned int collNum=trackCollNum[
i];
686 unsigned int trackNum=i-trackCollFirsts[collNum];
687 const reco::Track *track=&((trackColls[collNum])->
at(trackNum));
689 mvaVec.push_back(trackMVAs[i]);
690 if (selected[i]>1 ) {
691 outputTrks->back().setQualityMask(selected[i]-10);
696 if ( selected[i]==1 )
697 outputTrks->back().setQualityMask(trackQuals[i]);
698 outputTrks->back().setOriginalAlgorithm(oriAlgo[i]);
708 bool doRekeyOnThisSeed=
false;
712 if (origSeedRef->
nHits()!=0){
715 if (firstHit->isValid()){
724 doRekeyOnThisSeed=e.
getByLabel(clusterRemovalInfos,CRIh);
728 if (doRekeyOnThisSeed && !(clusterRemovalInfos==
edm::InputTag(
""))) {
734 for (;iH!=iH_end;++iH){
736 refSetter.
reKey(&newRecHitContainer.
back());
758 seedsRefs[
i]=origSeedRef;
780 for (
unsigned int ti=0; ti<trackColls.size(); ti++) {
788 for (
size_t i = 0,
n = hTraj1->size(); i <
n; ++
i) {
791 if (match != hTTAss1->end()) {
793 short oldKey = trackCollFirsts[ti]+
static_cast<short>(trkRef.
key());
794 if (trackRefs[oldKey].isNonnull()) {
798 outputTrajs->back().setSeedRef( seedsRefs[oldKey] );
810 fillerMVA.insert(outHandle,mvaVec.begin(),mvaVec.end());
815 e.
put(vmMVA,
"MVAVals");
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)
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
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.