67 tag(tag_), tk(tk_), traj(traj_), tass(tass_), tsel(tsel_), tmva(tmva_) {}
71 consumes<std::vector<Trajectory> >(tag), consumes<TrajTrackAssociationCollection >(tag),
76 consumes<std::vector<Trajectory> >(tag), consumes<TrajTrackAssociationCollection >(tag),
131 #include <x86intrin.h>
136 inline volatile unsigned long long rdtsc() {
143 unsigned long long st;
144 long long totBegin=0;
147 unsigned long long timeNo;
148 unsigned long long timeOv;
152 void start() { st=rdtsc(); }
153 void noOverlap() { timeNo += (rdtsc()-st);}
154 void overlap() { timeOv += (rdtsc()-st);}
155 void pre(
int tt) { totPre+=
tt;}
156 void end(
int tt) { totEnd+=
tt;}
157 void de(
float d) {
if (d>maxDE) maxDE=d;}
158 void dp(
float d) {
if (d>maxDP) maxDP=d;}
162 std::cout <<
"TrackListMerger stat\nBegin/Pre/End/maxDPhi/maxDEta/Overlap/NoOverlap "
163 << totBegin <<
'/'<< totPre <<
'/'<< totEnd <<
'/'<< maxDP <<
'/'<< maxDE
164 <<
'/'<< timeOv/1000 <<
'/'<< timeNo/1000
168 ~StatCount() {
print();}
185 [[cms::thread_safe]] StatCount statCount;
203 std::vector<edm::InputTag> trackProducerTags(conf.
getParameter<std::vector<edm::InputTag> >(
"TrackProducers"));
216 if (qualityStr !=
"") {
227 for (
unsigned int i=0;
i<setsToMerge.size();
i++) {
228 listsToMerge_.push_back(setsToMerge[
i].getParameter<std::vector< int> >(
"tLists"));
234 std::vector<edm::InputTag> selectors(conf.
getParameter<std::vector<edm::InputTag> >(
"selectedTrackQuals"));
235 std::vector<edm::InputTag> mvaStores;
236 if(conf.
exists(
"mvaValueTags")){
237 mvaStores = conf.
getParameter<std::vector<edm::InputTag> >(
"mvaValueTags");
239 for (
int i = 0;
i < (int)selectors.size();
i++){
241 mvaStores.push_back(ntag);
244 unsigned int numTrkColl = trackProducerTags.size();
245 if (numTrkColl !=
hasSelector_.size() || numTrkColl != selectors.size()) {
246 throw cms::Exception(
"Inconsistent size") <<
"need same number of track collections and selectors";
248 if (numTrkColl !=
hasSelector_.size() || numTrkColl != mvaStores.size()) {
249 throw cms::Exception(
"Inconsistent size") <<
"need same number of track collections and MVA stores";
251 for (
unsigned int i = indivShareFrac_.size();
i < numTrkColl;
i++) {
253 indivShareFrac_.push_back(1.0);
259 for (
unsigned int i=1;
i<numTrkColl;
i++) {
260 if (!(trackProducerTags[
i]==trackProducerTags[0])) ok=
false;
263 throw cms::Exception(
"Bad input") <<
"to use writeOnlyTrkQuals=True all input InputTags must be the same";
265 produces<edm::ValueMap<int> >();
268 produces<reco::TrackCollection>();
271 if (makeReKeyedSeeds_){
273 produces<TrajectorySeedCollection>();
277 produces<reco::TrackExtraCollection>();
278 produces<TrackingRecHitCollection>();
280 produces< std::vector<Trajectory> >();
281 produces< TrajTrackAssociationCollection >();
283 produces<edm::ValueMap<float> >(
"MVAVals");
287 for (
unsigned int i = 0;
i < numTrkColl; ++
i) {
313 std::vector<const reco::TrackCollection *> trackColls;
314 std::vector<edm::Handle<reco::TrackCollection> > trackHandles(
trackProducers_.size());
316 trackColls.push_back(0);
319 if (trackHandles[i].isValid()) {
320 trackColls[
i]= trackHandles[
i].product();
323 trackColls[
i]=&s_empty;
327 unsigned int collsSize =trackColls.size();
328 unsigned int rSize=0;
329 unsigned int trackCollSizes[collsSize];
330 unsigned int trackCollFirsts[collsSize];
331 for (
unsigned int i=0;
i!=collsSize;
i++) {
332 trackCollSizes[
i]=trackColls[
i]->size();
333 trackCollFirsts[
i]=rSize;
334 rSize+=trackCollSizes[
i];
337 statCount.begin(rSize);
346 bool trkUpdated[rSize];
347 int trackCollNum[rSize];
348 int trackQuals[rSize];
349 float trackMVAs[rSize];
350 for (
unsigned int j=0;
j<rSize;
j++) {
351 indexG[
j]=-1; selected[
j]=1; trkUpdated[
j]=
false; trackCollNum[
j]=0; trackQuals[
j]=0;trackMVAs[
j] = -99.0;
355 for (
unsigned int j=0;
j!= collsSize;
j++) {
366 if ( 0<tC1->size() ){
368 for (reco::TrackCollection::const_iterator track=tC1->begin(); track!=tC1->end(); track++){
371 trackQuals[
i]=track->qualityMask();
375 if( (*trackMVAStore).contains(trkRef.
id()) ) trackMVAs[
i] = (*trackMVAStore)[trkRef];
377 int qual=(*trackSelColl)[trkRef];
387 selected[
i]=trackQuals[
i]+10;
388 if ((
short unsigned)track->ndof() < 1){
400 if (track->pt() <
minPT_){
412 statCount.pre(ngood);
415 typedef std::pair<unsigned int, const TrackingRecHit*> IHit;
417 std::vector<std::vector<IHit>> rh1(ngood);
419 std::vector<IHit> rh1[ngood];
426 for (
unsigned int j=0;
j<rSize;
j++) {
427 if (selected[
j]==0)
continue;
430 unsigned int collNum=trackCollNum[
j];
431 unsigned int trackNum=
j-trackCollFirsts[collNum];
432 const reco::Track *track=&((trackColls[collNum])->
at(trackNum));
434 algo[
i]=track->
algo();
441 rh1[
i].reserve(validHits) ;
442 auto compById = [](IHit
const & h1, IHit
const & h2) {
return h1.first < h2.first;};
445 unsigned int id = hit->
rawId() ;
447 if likely(hit->
isValid()) { rh1[
i].emplace_back(
id,hit); std::push_heap(rh1[i].
begin(),rh1[i].
end(),compById); }
449 std::sort_heap(rh1[i].
begin(),rh1[i].
end(),compById);
453 if likely(ngood>1 && collsSize>1)
455 int saveSelected[rSize];
456 bool notActive[collsSize];
457 for (
unsigned int cn=0;cn!=collsSize;++cn)
460 for (
unsigned int i=0; i<rSize; i++) saveSelected[i]=selected[i];
463 for (
unsigned int i=0; i<rSize-1; i++) {
464 if (selected[i]==0)
continue;
465 unsigned int collNum=trackCollNum[
i];
468 if (notActive[collNum])
continue;
471 unsigned int nh1=rh1[k1].size();
472 int qualityMaskT1 = trackQuals[
i];
475 float score1 = score[k1];
478 for (
unsigned int j=i+1;
j<rSize;
j++) {
479 if (selected[
j]==0)
continue;
480 unsigned int collNum2=trackCollNum[
j];
481 if ( (collNum == collNum2) &&
indivShareFrac_[collNum] > 0.99)
continue;
483 if (notActive[collNum2])
continue;
487 int newQualityMask = -9;
489 int maskT1= saveSelected[
i]>1? saveSelected[
i]-10 : qualityMaskT1;
490 int maskT2= saveSelected[
j]>1? saveSelected[
j]-10 : trackQuals[
j];
491 newQualityMask =(maskT1 | maskT2);
493 unsigned int nh2=rh1[k2].size();
513 if (share(it,jt,
epsilon_)) firstoverlap=1;
520 while (ih!=nh1 && jh!=nh2) {
524 auto const id1 = rh1[k1][ih].first;
525 auto const id2 = rh1[k2][jh].first;
527 else if (id2<id1) ++jh;
530 auto li=ih;
while( (++li)!=nh1 && id1 == rh1[k1][li].first);
531 auto lj=jh;
while( (++lj)!=nh2 && id2 == rh1[k2][lj].first);
532 for (
auto ii=ih;
ii!=li; ++
ii)
533 for (
auto jj=jh;
jj!=lj; ++
jj) {
536 if (share(it,jt,
epsilon_)) noverlap++;
543 bool dupfound = (collNum != collNum2) ? (noverlap-firstoverlap) > (
std::min(nhit1,nhit2)-firstoverlap)*
shareFrac_ :
547 float score2 = score[k2];
549 if ( score1 - score2 > almostSame ) {
551 selected[
i]=10+newQualityMask;
553 }
else if ( score2 - score1 > almostSame ) {
555 selected[
j]=10+newQualityMask;
562 if (algo[k1] <= algo[k2]) {
564 selected[
i]=10+newQualityMask;
568 selected[
j]=10+newQualityMask;
574 selected[
i]=10+newQualityMask;
578 selected[
j]=10+newQualityMask;
591 statCount.noOverlap();
594 if (selected[i]==0)
break;
601 std::auto_ptr<edm::ValueMap<float> > vmMVA = std::auto_ptr<edm::ValueMap<float> >(
new edm::ValueMap<float>);
608 unsigned int tSize=trackColls[0]->size();
609 std::auto_ptr<edm::ValueMap<int> > vm = std::auto_ptr<edm::ValueMap<int> >(
new edm::ValueMap<int>);
612 std::vector<int> finalQuals(tSize,-1);
613 for (
unsigned int i=0; i<rSize; i++) {
614 unsigned int tNum=i%tSize;
616 if (selected[i]>1 ) {
617 finalQuals[tNum]=selected[
i]-10;
621 if ( selected[i]==1 )
622 finalQuals[tNum]=trackQuals[
i];
625 filler.insert(trackHandles[0], finalQuals.begin(),finalQuals.end());
630 std::vector<float> mvaVec(tSize,-99);
632 for(
unsigned int i = 0; i < rSize; i++){
633 unsigned int tNum = i % tSize;
634 mvaVec[tNum] = trackMVAs[tNum];
637 fillerMVA.insert(trackHandles[0],mvaVec.begin(),mvaVec.end());
640 e.
put(vmMVA,
"MVAVals");
650 std::vector<reco::TrackRef> trackRefs(rSize);
651 std::vector<edm::RefToBase<TrajectorySeed>> seedsRefs(rSize);
657 unsigned int nToWrite=0;
658 for (
unsigned int i=0; i<rSize; i++)
659 if (selected[i]!=0) nToWrite++;
661 std::vector<float> mvaVec;
672 outputTrkHits->reserve(nToWrite*25);
682 outputTrajs = std::auto_ptr< std::vector<Trajectory> >(
new std::vector<Trajectory>());
688 for (
unsigned int i=0; i<rSize; i++) {
689 if (selected[i]==0) {
694 unsigned int collNum=trackCollNum[
i];
695 unsigned int trackNum=i-trackCollFirsts[collNum];
696 const reco::Track *track=&((trackColls[collNum])->
at(trackNum));
698 mvaVec.push_back(trackMVAs[i]);
699 if (selected[i]>1 ) {
700 outputTrks->back().setQualityMask(selected[i]-10);
705 if ( selected[i]==1 )
706 outputTrks->back().setQualityMask(trackQuals[i]);
715 bool doRekeyOnThisSeed=
false;
719 if (origSeedRef->
nHits()!=0){
722 if (firstHit->isValid()){
731 doRekeyOnThisSeed=e.
getByLabel(clusterRemovalInfos,CRIh);
735 if (doRekeyOnThisSeed && !(clusterRemovalInfos==
edm::InputTag(
""))) {
741 for (;iH!=iH_end;++iH){
743 refSetter.
reKey(&newRecHitContainer.
back());
765 seedsRefs[
i]=origSeedRef;
785 for (
unsigned int ti=0; ti<trackColls.size(); ti++) {
793 for (
size_t i = 0,
n = hTraj1->size(); i <
n; ++
i) {
796 if (match != hTTAss1->end()) {
798 short oldKey = trackCollFirsts[ti]+
static_cast<short>(trkRef.
key());
799 if (trackRefs[oldKey].isNonnull()) {
803 outputTrajs->back().setSeedRef( seedsRefs[oldKey] );
815 fillerMVA.insert(outHandle,mvaVec.begin(),mvaVec.end());
820 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.
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.