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();}
113 std::vector<edm::InputTag> trackProducerTags(conf.
getParameter<std::vector<edm::InputTag> >(
"TrackProducers"));
126 if (qualityStr !=
"") {
137 for (
unsigned int i=0;
i<setsToMerge.size();
i++) {
138 listsToMerge_.push_back(setsToMerge[
i].getParameter<std::vector< int> >(
"tLists"));
142 std::vector<edm::InputTag> selectors(conf.
getParameter<std::vector<edm::InputTag> >(
"selectedTrackQuals"));
143 std::vector<edm::InputTag> mvaStores;
144 if(conf.
exists(
"mvaValueTags")){
145 mvaStores = conf.
getParameter<std::vector<edm::InputTag> >(
"mvaValueTags");
147 for (
int i = 0;
i < (int)selectors.size();
i++){
149 mvaStores.push_back(ntag);
152 unsigned int numTrkColl = trackProducerTags.size();
153 if (numTrkColl !=
hasSelector_.size() || numTrkColl != selectors.size()) {
154 throw cms::Exception(
"Inconsistent size") <<
"need same number of track collections and selectors";
156 if (numTrkColl !=
hasSelector_.size() || numTrkColl != mvaStores.size()) {
157 throw cms::Exception(
"Inconsistent size") <<
"need same number of track collections and MVA stores";
159 for (
unsigned int i = indivShareFrac_.size();
i < numTrkColl;
i++) {
161 indivShareFrac_.push_back(1.0);
167 for (
unsigned int i=1;
i<numTrkColl;
i++) {
168 if (!(trackProducerTags[
i]==trackProducerTags[0])) ok=
false;
171 throw cms::Exception(
"Bad input") <<
"to use writeOnlyTrkQuals=True all input InputTags must be the same";
173 produces<edm::ValueMap<int> >();
176 produces<reco::TrackCollection>();
179 if (makeReKeyedSeeds_){
181 produces<TrajectorySeedCollection>();
185 produces<reco::TrackExtraCollection>();
186 produces<TrackingRecHitCollection>();
188 produces< std::vector<Trajectory> >();
189 produces< TrajTrackAssociationCollection >();
191 produces<edm::ValueMap<float> >(
"MVAVals");
195 for (
unsigned int i = 0;
i < numTrkColl; ++
i) {
221 std::vector<const reco::TrackCollection *> trackColls;
222 std::vector<edm::Handle<reco::TrackCollection> > trackHandles(
trackProducers_.size());
224 trackColls.push_back(0);
227 if (trackHandles[i].isValid()) {
228 trackColls[
i]= trackHandles[
i].product();
231 trackColls[
i]=&s_empty;
235 unsigned int collsSize =trackColls.size();
236 unsigned int rSize=0;
237 unsigned int trackCollSizes[collsSize];
238 unsigned int trackCollFirsts[collsSize];
239 for (
unsigned int i=0;
i!=collsSize;
i++) {
240 trackCollSizes[
i]=trackColls[
i]->size();
241 trackCollFirsts[
i]=rSize;
242 rSize+=trackCollSizes[
i];
245 statCount.begin(rSize);
254 bool trkUpdated[rSize];
255 int trackCollNum[rSize];
256 int trackQuals[rSize];
257 float trackMVAs[rSize];
258 for (
unsigned int j=0;
j<rSize;
j++) {
259 indexG[
j]=-1; selected[
j]=1; trkUpdated[
j]=
false; trackCollNum[
j]=0; trackQuals[
j]=0;trackMVAs[
j] = -99.0;
263 for (
unsigned int j=0;
j!= collsSize;
j++) {
273 if ( 0<tC1->size() ){
275 for (reco::TrackCollection::const_iterator track=tC1->begin(); track!=tC1->end(); track++){
278 trackQuals[
i]=track->qualityMask();
281 if((*trackMVAStore).contains(trkRef.
id()))trackMVAs[
i] = (*trackMVAStore)[trkRef];
283 int qual=(*trackSelColl)[trkRef];
293 selected[
i]=trackQuals[
i]+10;
294 if ((
short unsigned)track->ndof() < 1){
306 if (track->pt() <
minPT_){
318 statCount.pre(ngood);
321 typedef std::pair<unsigned int, const TrackingRecHit*> IHit;
322 std::vector<IHit> rh1[ngood];
328 for (
unsigned int j=0;
j<rSize;
j++) {
329 if (selected[
j]==0)
continue;
332 unsigned int collNum=trackCollNum[
j];
333 unsigned int trackNum=
j-trackCollFirsts[collNum];
334 const reco::Track *track=&((trackColls[collNum])->
at(trackNum));
336 algo[
i]=track->
algo();
342 rh1[
i].reserve(validHits) ;
343 auto compById = [](IHit
const & h1, IHit
const & h2) {
return h1.first < h2.first;};
347 unsigned int id = hit->
rawId() ;
349 if likely(hit->
isValid()) { rh1[
i].emplace_back(
id,hit); std::push_heap(rh1[i].
begin(),rh1[i].
end(),compById); }
351 std::sort_heap(rh1[i].
begin(),rh1[i].
end(),compById);
355 if likely(ngood>1 && collsSize>1)
357 int saveSelected[rSize];
358 bool notActive[collsSize];
359 for (
unsigned int cn=0;cn!=collsSize;++cn)
362 for (
unsigned int i=0; i<rSize; i++) saveSelected[i]=selected[i];
365 for (
unsigned int i=0; i<rSize-1; i++) {
366 if (selected[i]==0)
continue;
367 unsigned int collNum=trackCollNum[
i];
370 if (notActive[collNum])
continue;
373 unsigned int nh1=rh1[k1].size();
374 int qualityMaskT1 = trackQuals[
i];
377 float score1 = score[k1];
380 for (
unsigned int j=i+1;
j<rSize;
j++) {
381 if (selected[
j]==0)
continue;
382 unsigned int collNum2=trackCollNum[
j];
383 if ( (collNum == collNum2) &&
indivShareFrac_[collNum] > 0.99)
continue;
385 if (notActive[collNum2])
continue;
389 int newQualityMask = -9;
391 int maskT1= saveSelected[
i]>1? saveSelected[
i]-10 : qualityMaskT1;
392 int maskT2= saveSelected[
j]>1? saveSelected[
j]-10 : trackQuals[
j];
393 newQualityMask =(maskT1 | maskT2);
395 unsigned int nh2=rh1[k2].size();
415 if (share(it,jt,
epsilon_)) firstoverlap=1;
422 while (ih!=nh1 && jh!=nh2) {
426 auto const id1 = rh1[k1][ih].first;
427 auto const id2 = rh1[k2][jh].first;
429 else if (id2<id1) ++jh;
432 auto li=ih;
while( (++li)!=nh1 && id1 == rh1[k1][li].first);
433 auto lj=jh;
while( (++lj)!=nh2 && id2 == rh1[k2][lj].first);
434 for (
auto ii=ih;
ii!=li; ++
ii)
435 for (
auto jj=jh;
jj!=lj; ++
jj) {
438 if (share(it,jt,
epsilon_)) noverlap++;
445 bool dupfound = (collNum != collNum2) ? (noverlap-firstoverlap) > (
std::min(nhit1,nhit2)-firstoverlap)*
shareFrac_ :
449 float score2 = score[k2];
451 if ( score1 - score2 > almostSame ) {
453 selected[
i]=10+newQualityMask;
455 }
else if ( score2 - score1 > almostSame ) {
457 selected[
j]=10+newQualityMask;
464 if (algo[k1] <= algo[k2]) {
466 selected[
i]=10+newQualityMask;
470 selected[
j]=10+newQualityMask;
476 selected[
i]=10+newQualityMask;
480 selected[
j]=10+newQualityMask;
493 statCount.noOverlap();
496 if (selected[i]==0)
break;
503 std::auto_ptr<edm::ValueMap<float> > vmMVA = std::auto_ptr<edm::ValueMap<float> >(
new edm::ValueMap<float>);
510 unsigned int tSize=trackColls[0]->size();
511 std::auto_ptr<edm::ValueMap<int> > vm = std::auto_ptr<edm::ValueMap<int> >(
new edm::ValueMap<int>);
514 std::vector<int> finalQuals(tSize,-1);
515 for (
unsigned int i=0; i<rSize; i++) {
516 unsigned int tNum=i%tSize;
518 if (selected[i]>1 ) {
519 finalQuals[tNum]=selected[
i]-10;
523 if ( selected[i]==1 )
524 finalQuals[tNum]=trackQuals[
i];
527 filler.insert(trackHandles[0], finalQuals.begin(),finalQuals.end());
532 std::vector<float> mvaVec(tSize,-99);
534 for(
unsigned int i = 0; i < rSize; i++){
535 unsigned int tNum = i % tSize;
536 mvaVec[tNum] = trackMVAs[tNum];
539 fillerMVA.insert(trackHandles[0],mvaVec.begin(),mvaVec.end());
541 e.
put(vmMVA,
"MVAVals");
553 unsigned int nToWrite=0;
554 for (
unsigned int i=0; i<rSize; i++)
555 if (selected[i]!=0) nToWrite++;
557 std::vector<float> mvaVec;
568 outputTrkHits->reserve(nToWrite*25);
578 outputTrajs = std::auto_ptr< std::vector<Trajectory> >(
new std::vector<Trajectory>());
584 for (
unsigned int i=0; i<rSize; i++) {
585 if (selected[i]==0) {
590 unsigned int collNum=trackCollNum[
i];
591 unsigned int trackNum=i-trackCollFirsts[collNum];
592 const reco::Track *track=&((trackColls[collNum])->
at(trackNum));
594 mvaVec.push_back(trackMVAs[i]);
595 if (selected[i]>1 ) {
596 outputTrks->back().setQualityMask(selected[i]-10);
601 if ( selected[i]==1 )
602 outputTrks->back().setQualityMask(trackQuals[i]);
611 bool doRekeyOnThisSeed=
false;
615 if (origSeedRef->
nHits()!=0){
618 if (firstHit->isValid()){
627 doRekeyOnThisSeed=e.
getByLabel(clusterRemovalInfos,CRIh);
631 if (doRekeyOnThisSeed && !(clusterRemovalInfos==
edm::InputTag(
""))) {
637 for (;iH!=iH_end;++iH){
639 refSetter.
reKey(&newRecHitContainer.
back());
661 seedsRefs[
i]=origSeedRef;
668 for (
unsigned ih=0; ih<nh1; ++ih ) {
682 for (
unsigned int ti=0; ti<trackColls.size(); ti++) {
690 for (
size_t i = 0,
n = hTraj1->size(); i <
n; ++
i) {
693 if (match != hTTAss1->end()) {
695 short oldKey = trackCollFirsts[ti]+
static_cast<short>(trkRef.
key());
696 if (trackRefs[oldKey].isNonnull()) {
700 outputTrajs->back().setSeedRef( seedsRefs[oldKey] );
712 fillerMVA.insert(outHandle,mvaVec.begin(),mvaVec.end());
716 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