40 #include <x86intrin.h>
45 inline volatile unsigned long long rdtsc() {
52 unsigned long long st;
56 unsigned long long timeNo;
57 unsigned long long timeOv;
61 void start() { st=rdtsc(); }
62 void noOverlap() { timeNo += (rdtsc()-st);}
63 void overlap() { timeOv += (rdtsc()-st);}
64 void pre(
int tt) { totPre+=
tt;}
66 void de(
float d) {
if (d>maxDE) maxDE=d;}
67 void dp(
float d) {
if (d>maxDP) maxDP=d;}
71 std::cout <<
"TrackListMerger stat\nBegin/Pre/End/maxDPhi/maxDEta/Overlap/NoOverlap "
72 << totBegin <<
'/'<< totPre <<
'/'<< totEnd <<
'/'<< maxDP <<
'/'<< maxDE
73 <<
'/'<< timeOv/1000 <<
'/'<< timeNo/1000
77 ~StatCount() {
print();}
94 [[cms::thread_safe]] StatCount statCount;
114 std::vector<edm::InputTag> trackProducerTags(conf.
getParameter<std::vector<edm::InputTag> >(
"TrackProducers"));
127 if (qualityStr !=
"") {
138 for (
unsigned int i=0;
i<setsToMerge.size();
i++) {
139 listsToMerge_.push_back(setsToMerge[
i].getParameter<std::vector< int> >(
"tLists"));
143 std::vector<edm::InputTag> selectors(conf.
getParameter<std::vector<edm::InputTag> >(
"selectedTrackQuals"));
144 std::vector<edm::InputTag> mvaStores;
145 if(conf.
exists(
"mvaValueTags")){
146 mvaStores = conf.
getParameter<std::vector<edm::InputTag> >(
"mvaValueTags");
148 for (
int i = 0;
i < (int)selectors.size();
i++){
150 mvaStores.push_back(ntag);
153 unsigned int numTrkColl = trackProducerTags.size();
154 if (numTrkColl !=
hasSelector_.size() || numTrkColl != selectors.size()) {
155 throw cms::Exception(
"Inconsistent size") <<
"need same number of track collections and selectors";
157 if (numTrkColl !=
hasSelector_.size() || numTrkColl != mvaStores.size()) {
158 throw cms::Exception(
"Inconsistent size") <<
"need same number of track collections and MVA stores";
160 for (
unsigned int i = indivShareFrac_.size();
i < numTrkColl;
i++) {
162 indivShareFrac_.push_back(1.0);
168 for (
unsigned int i=1;
i<numTrkColl;
i++) {
169 if (!(trackProducerTags[
i]==trackProducerTags[0])) ok=
false;
172 throw cms::Exception(
"Bad input") <<
"to use writeOnlyTrkQuals=True all input InputTags must be the same";
174 produces<edm::ValueMap<int> >();
177 produces<reco::TrackCollection>();
180 if (makeReKeyedSeeds_){
182 produces<TrajectorySeedCollection>();
186 produces<reco::TrackExtraCollection>();
187 produces<TrackingRecHitCollection>();
189 produces< std::vector<Trajectory> >();
190 produces< TrajTrackAssociationCollection >();
192 produces<edm::ValueMap<float> >(
"MVAVals");
196 for (
unsigned int i = 0;
i < numTrkColl; ++
i) {
222 std::vector<const reco::TrackCollection *> trackColls;
223 std::vector<edm::Handle<reco::TrackCollection> > trackHandles(
trackProducers_.size());
225 trackColls.push_back(0);
228 if (trackHandles[i].isValid()) {
229 trackColls[
i]= trackHandles[
i].product();
232 trackColls[
i]=&s_empty;
236 unsigned int collsSize =trackColls.size();
237 unsigned int rSize=0;
238 unsigned int trackCollSizes[collsSize];
239 unsigned int trackCollFirsts[collsSize];
240 for (
unsigned int i=0;
i!=collsSize;
i++) {
241 trackCollSizes[
i]=trackColls[
i]->size();
242 trackCollFirsts[
i]=rSize;
243 rSize+=trackCollSizes[
i];
246 statCount.begin(rSize);
255 bool trkUpdated[rSize];
256 int trackCollNum[rSize];
257 int trackQuals[rSize];
258 float trackMVAs[rSize];
259 for (
unsigned int j=0;
j<rSize;
j++) {
260 indexG[
j]=-1; selected[
j]=1; trkUpdated[
j]=
false; trackCollNum[
j]=0; trackQuals[
j]=0;trackMVAs[
j] = -99.0;
264 for (
unsigned int j=0;
j!= collsSize;
j++) {
274 if ( 0<tC1->size() ){
276 for (reco::TrackCollection::const_iterator track=tC1->begin(); track!=tC1->end(); track++){
279 trackQuals[
i]=track->qualityMask();
282 if((*trackMVAStore).contains(trkRef.
id()))trackMVAs[
i] = (*trackMVAStore)[trkRef];
284 int qual=(*trackSelColl)[trkRef];
294 selected[
i]=trackQuals[
i]+10;
295 if ((
short unsigned)track->ndof() < 1){
307 if (track->pt() <
minPT_){
319 statCount.pre(ngood);
322 typedef std::pair<unsigned int, const TrackingRecHit*> IHit;
323 std::vector<IHit> rh1[ngood];
329 for (
unsigned int j=0;
j<rSize;
j++) {
330 if (selected[
j]==0)
continue;
333 unsigned int collNum=trackCollNum[
j];
334 unsigned int trackNum=
j-trackCollFirsts[collNum];
335 const reco::Track *track=&((trackColls[collNum])->
at(trackNum));
337 algo[
i]=track->
algo();
343 rh1[
i].reserve(validHits) ;
344 auto compById = [](IHit
const & h1, IHit
const & h2) {
return h1.first < h2.first;};
348 unsigned int id = hit->
rawId() ;
350 if likely(hit->
isValid()) { rh1[
i].emplace_back(
id,hit); std::push_heap(rh1[i].
begin(),rh1[i].
end(),compById); }
352 std::sort_heap(rh1[i].
begin(),rh1[i].
end(),compById);
356 if likely(ngood>1 && collsSize>1)
358 int saveSelected[rSize];
359 bool notActive[collsSize];
360 for (
unsigned int cn=0;cn!=collsSize;++cn)
363 for (
unsigned int i=0; i<rSize; i++) saveSelected[i]=selected[i];
366 for (
unsigned int i=0; i<rSize-1; i++) {
367 if (selected[i]==0)
continue;
368 unsigned int collNum=trackCollNum[
i];
371 if (notActive[collNum])
continue;
374 unsigned int nh1=rh1[k1].size();
375 int qualityMaskT1 = trackQuals[
i];
378 float score1 = score[k1];
381 for (
unsigned int j=i+1;
j<rSize;
j++) {
382 if (selected[
j]==0)
continue;
383 unsigned int collNum2=trackCollNum[
j];
384 if ( (collNum == collNum2) &&
indivShareFrac_[collNum] > 0.99)
continue;
386 if (notActive[collNum2])
continue;
390 int newQualityMask = -9;
392 int maskT1= saveSelected[
i]>1? saveSelected[
i]-10 : qualityMaskT1;
393 int maskT2= saveSelected[
j]>1? saveSelected[
j]-10 : trackQuals[
j];
394 newQualityMask =(maskT1 | maskT2);
396 unsigned int nh2=rh1[k2].size();
416 if (share(it,jt,
epsilon_)) firstoverlap=1;
423 while (ih!=nh1 && jh!=nh2) {
427 auto const id1 = rh1[k1][ih].first;
428 auto const id2 = rh1[k2][jh].first;
430 else if (id2<id1) ++jh;
433 auto li=ih;
while( (++li)!=nh1 && id1 == rh1[k1][li].first);
434 auto lj=jh;
while( (++lj)!=nh2 && id2 == rh1[k2][lj].first);
435 for (
auto ii=ih;
ii!=li; ++
ii)
436 for (
auto jj=jh;
jj!=lj; ++
jj) {
439 if (share(it,jt,
epsilon_)) noverlap++;
446 bool dupfound = (collNum != collNum2) ? (noverlap-firstoverlap) > (
std::min(nhit1,nhit2)-firstoverlap)*
shareFrac_ :
450 float score2 = score[k2];
452 if ( score1 - score2 > almostSame ) {
454 selected[
i]=10+newQualityMask;
456 }
else if ( score2 - score1 > almostSame ) {
458 selected[
j]=10+newQualityMask;
465 if (algo[k1] <= algo[k2]) {
467 selected[
i]=10+newQualityMask;
471 selected[
j]=10+newQualityMask;
477 selected[
i]=10+newQualityMask;
481 selected[
j]=10+newQualityMask;
494 statCount.noOverlap();
497 if (selected[i]==0)
break;
504 std::auto_ptr<edm::ValueMap<float> > vmMVA = std::auto_ptr<edm::ValueMap<float> >(
new edm::ValueMap<float>);
511 unsigned int tSize=trackColls[0]->size();
512 std::auto_ptr<edm::ValueMap<int> > vm = std::auto_ptr<edm::ValueMap<int> >(
new edm::ValueMap<int>);
515 std::vector<int> finalQuals(tSize,-1);
516 for (
unsigned int i=0; i<rSize; i++) {
517 unsigned int tNum=i%tSize;
519 if (selected[i]>1 ) {
520 finalQuals[tNum]=selected[
i]-10;
524 if ( selected[i]==1 )
525 finalQuals[tNum]=trackQuals[
i];
528 filler.insert(trackHandles[0], finalQuals.begin(),finalQuals.end());
533 std::vector<float> mvaVec(tSize,-99);
535 for(
unsigned int i = 0; i < rSize; i++){
536 unsigned int tNum = i % tSize;
537 mvaVec[tNum] = trackMVAs[tNum];
540 fillerMVA.insert(trackHandles[0],mvaVec.begin(),mvaVec.end());
542 e.
put(vmMVA,
"MVAVals");
554 unsigned int nToWrite=0;
555 for (
unsigned int i=0; i<rSize; i++)
556 if (selected[i]!=0) nToWrite++;
558 std::vector<float> mvaVec;
569 outputTrkHits->reserve(nToWrite*25);
579 outputTrajs = std::auto_ptr< std::vector<Trajectory> >(
new std::vector<Trajectory>());
585 for (
unsigned int i=0; i<rSize; i++) {
586 if (selected[i]==0) {
591 unsigned int collNum=trackCollNum[
i];
592 unsigned int trackNum=i-trackCollFirsts[collNum];
593 const reco::Track *track=&((trackColls[collNum])->
at(trackNum));
595 mvaVec.push_back(trackMVAs[i]);
596 if (selected[i]>1 ) {
597 outputTrks->back().setQualityMask(selected[i]-10);
602 if ( selected[i]==1 )
603 outputTrks->back().setQualityMask(trackQuals[i]);
612 bool doRekeyOnThisSeed=
false;
616 if (origSeedRef->
nHits()!=0){
619 if (firstHit->isValid()){
628 doRekeyOnThisSeed=e.
getByLabel(clusterRemovalInfos,CRIh);
632 if (doRekeyOnThisSeed && !(clusterRemovalInfos==
edm::InputTag(
""))) {
638 for (;iH!=iH_end;++iH){
640 refSetter.
reKey(&newRecHitContainer.
back());
662 seedsRefs[
i]=origSeedRef;
669 for (
unsigned ih=0; ih<nh1; ++ih ) {
683 for (
unsigned int ti=0; ti<trackColls.size(); ti++) {
691 for (
size_t i = 0,
n = hTraj1->size(); i <
n; ++
i) {
694 if (match != hTTAss1->end()) {
696 short oldKey = trackCollFirsts[ti]+
static_cast<short>(trkRef.
key());
697 if (trackRefs[oldKey].isNonnull()) {
701 outputTrajs->back().setSeedRef( seedsRefs[oldKey] );
713 fillerMVA.insert(outHandle,mvaVec.begin(),mvaVec.end());
717 e.
put(vmMVA,
"MVAVals");
PropagationDirection direction() const
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
virtual void produce(edm::Event &e, const edm::EventSetup &c) override
virtual ~TrackListMerger()
tuple start
Check for commandline option errors.
std::auto_ptr< TrajectorySeedCollection > outputSeeds
std::auto_ptr< std::vector< Trajectory > > outputTrajs
friend struct const_iterator
bool getByToken(EDGetToken token, Handle< PROD > &result) const
size_t recHitsSize() const
Get number of RecHits. (Warning, this includes invalid hits, which are not physical hits)...
TkEDGetTokenss edTokens(const edm::InputTag &tag, const edm::InputTag &seltag, const edm::InputTag &mvatag)
std::vector< ParameterSet > VParameterSet
std::string print(const Track &, edm::Verbosity=edm::Concise)
Track print utility.
void reKey(TrackingRecHit *hit) const
std::auto_ptr< reco::TrackCollection > outputTrks
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.
std::vector< std::vector< int > > listsToMerge_
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
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
double maxNormalizedChisq_
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
edm::Ref< TrackingRecHitCollection > TrackingRecHitRef
persistent reference to a TrackingRecHit
TrackingRecHitRefProd refTrkHits
CovarianceMatrix outerStateCovariance() const
outermost trajectory state curvilinear errors
unsigned int outerDetId() const
DetId of the detector on which surface the outermost state is located.
Abs< T >::type abs(const T &t)
edm::RefProd< TrajectorySeedCollection > refTrajSeeds
edm::ProductID clusterProductB(const TrackingRecHit *hit)
reco::TrackRefProd refTrks
unsigned short numberOfValidHits() const
number of valid hits found
std::auto_ptr< reco::TrackExtraCollection > outputTrkExtras
trackingRecHit_iterator recHitsBegin() const
Iterator to first hit on the track.
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) ...
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
TrackListMerger(const edm::ParameterSet &conf)
RefProd< PROD > getRefBeforePut()
std::vector< double > indivShareFrac_
reco::TrackExtraRefProd refTrkExtras
std::vector< TrackExtra > TrackExtraCollection
collection of TrackExtra objects
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
std::vector< TkEDGetTokenss > trackProducers_
std::vector< bool > promoteQuality_
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
CovarianceMatrix innerStateCovariance() const
innermost trajectory state curvilinear errors
key_type key() const
Accessor for product key.
std::string const & moduleLabel() const
unsigned int nHits() const
const math::XYZVector & innerMomentum() const
momentum vector at the innermost hit position
TrackingRecHitRef recHit(size_t i) const
Get i-th hit on the track.
ProductID id() const
Accessor for product ID.
const TrackResiduals & residuals() const
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.
std::auto_ptr< TrackingRecHitCollection > outputTrkHits
ProductID id() const
Accessor for product ID.
DetId geographicalId() const
std::string const & productInstanceName() const
Provenance getProvenance(BranchID const &theID) const
reco::TrackBase::TrackQuality qualityToSet_
virtual LocalPoint localPosition() const =0
unsigned int innerDetId() const
DetId of the detector on which surface the innermost state is located.
edm::RefProd< std::vector< Trajectory > > refTrajs
std::vector< int > hasSelector_
trackingRecHit_iterator recHitsEnd() const
Iterator to last hit on the track.
std::auto_ptr< TrajTrackAssociationCollection > outputTTAss