calculate the vertex significance: First sort the n entries in each bin in to order, then calculate the mean bg excluding the largest (1-m_percentile), then the significance for each peak will be sig = (ypeak - bg)/sqrt(bg) and we can keep only those where sig > m_minVtxSignificance
if ( ztest >= maxh && ( ( m_applyWeightThreshold && ztest>m_weightThreshold ) || !m_applyWeightThreshold ) ) { apply threshold later - should we wish it
if we are in triplet mode, even a single pair means 3 consistent hits also bomb out if no maximum (above threshold) is found
at this point we have the histogram with the highest N vertices removed so we can find the "non vertex" pedestal from these, although it will be somewhat lower than perhaps it should be, in case some of the "vertices" we are removing are just random upwards fluctuations
NB: have moved pedestal calculation to before the extraction of the vertices if we calculate it after, then we have too low a pedestal if some vertices are really random fluctuations. If we calculate it before then we overestimate the pedestal, really we should try to decide how many real vertices we have, and then only exclude them, but that level of detail is probably not justified by the correlation with the offline track multiplicity on the vertex
copy vertices to output vector - this is so we can first impose cuts on the vertices we have found should we wish to
379 {
380
381 std::vector<vertex>*
output =
new std::vector<vertex>();
382
383 long nsp = spVec.size();
384 if ( !nsp )
return output;
385
386
387
388
389
390 std::vector<double>
phi(nsp),
rho(nsp), zed(nsp);
392
393 long numPhiSlices = 0;
394
396
398
399
400
401
404
405
406
407
408
410 const double invZBinSize = 1./ZBinSize;
411
412
413 const long HalfZhistoBins = long ( ceil( 0.5*(zMax-zMin)*invZBinSize ) );
414 const long NumZhistoBins = 2*HalfZhistoBins;
415
416
418
419
420
421
422
423
424
425
427
428
429
430
431 std::vector < std::vector<long> >
nHisto[2];
432 std::vector < std::vector<double> > zHisto[2];
433
434 for (
int i=2 ;
i-- ; ) {
nHisto[
i].clear();
nHisto[
i].resize(numZhistos); }
435 for (
int i=2 ;
i-- ; ) { zHisto[
i].clear(); zHisto[
i].resize(numZhistos); }
436
437
438
439
440
441
442
443 std::vector< PhiSlice* > allSlices( numPhiSlices );
444 for ( unsigned int sliceIndex = 0; sliceIndex < numPhiSlices; sliceIndex++ )
445 {
449 }
450
451 int allSlicesSize = allSlices.size();
452
453
454 for ( long pointIndex = 0; pointIndex < nsp; pointIndex++ )
455 {
457 if (phiIndex > allSlicesSize) {
458 continue;
459 }
460 allSlices[
phiIndex ]->AddPoint( rho[ pointIndex ], zed[ pointIndex ],
phi[ pointIndex ], lyr[ pointIndex ] );
461 }
462
463
464 std::vector< std::vector< double > > allLayerRhos, allLayerZs, allLayerPhis;
468
469 std::vector< std::vector< int > > allSliceWidths(
m_IdScan_MaxNumLayers, std::vector< int >( numPhiSlices + 1, 0 ) );
470 for ( unsigned int sliceIndex = 0; sliceIndex < numPhiSlices; sliceIndex++ )
471 {
472 allSlices[ sliceIndex ]->MakeWideLayers( &allLayerRhos, &allLayerZs, &allLayerPhis, &allSliceWidths, filled, &filledLayers );
473 }
474
475
477 {
478
479 for ( unsigned int sliceIndex = 0; sliceIndex < numPhiSlices; sliceIndex++ )
480 {
481 nHisto[0][sliceIndex].resize( NumZhistoBins + 1 );
482 zHisto[0][sliceIndex].resize( NumZhistoBins + 1 );
483 }
485 for ( unsigned int sliceIndex = 0; sliceIndex < numPhiSlices; sliceIndex++ ) {
486 nHisto[1][sliceIndex].resize( NumZhistoBins + 1 );
487 zHisto[1][sliceIndex].resize( NumZhistoBins + 1 );
488 }
489 }
490
491
492 for ( unsigned int sliceIndex = 0; sliceIndex < numPhiSlices; sliceIndex++ ) {
493 allSlices[ sliceIndex ]->GetHistogram( &( nHisto[0][sliceIndex] ), &( zHisto[0][sliceIndex] ),
494 &( nHisto[1][sliceIndex] ), &( zHisto[1][sliceIndex] ),
496
497
498
499
500 delete allSlices[ sliceIndex ];
501 }
502 }
503 else {
504
505 nHisto[0][0].resize( NumZhistoBins + 1 );
506 zHisto[0][0].resize( NumZhistoBins + 1 );
508 nHisto[1][0].resize( NumZhistoBins + 1 );
509 zHisto[1][0].resize( NumZhistoBins + 1 );
510 }
511
512
513 for ( unsigned int sliceIndex = 0; sliceIndex < numPhiSlices; sliceIndex++ ) {
514 allSlices[ sliceIndex ]->GetHistogram( &( nHisto[0][0] ), &( zHisto[0][0] ),
515 &( nHisto[1][0] ), &( zHisto[1][0] ),
517
518 delete allSlices[ sliceIndex ];
519 }
520 }
521
522
523
526
527 double pedestal = 0;
528
530
532
533 for (
long zpm=0; zpm<1 || (
m_chargeAware && zpm<2 ) ; ++zpm ) {
534
535 for(std::vector< std::vector<long> >::iterator nfiter = nHisto[zpm].
begin(); nfiter!=
nHisto[zpm].end(); ++nfiter) {
536
537 if((*nfiter).empty()) continue;
538 if((*nfiter).size() <= 2 ) continue;
539
540 for(std::vector<long>::iterator niter=nfiter->begin()+2; niter!=nfiter->end(); ++niter ) {
542 if ( *niter>=0 ) {
544 pedestal += *(niter) + *(niter-1) + *(niter-2);
545 }
546 }
547 }
548 }
549
551
552 }
553
554
561
563
565
567
568 std::vector<long>&
n =
nHisto[0][0];
569
570 std::vector<long> n3( nHisto[0][0].size()-2, 0);
571
572 for(
unsigned i=
n.size()-2 ; i-- ; ) n3[
i] = (
n[
i+2] +
n[
i+1] +
n[
i] );
574
576
577 for(
unsigned i=
nmax ;
i-- ; ) bg += n3[i];
578
580
581 }
582 }
583
584
585
586
587
588
589 std::vector<double> zoutput;
590 std::vector<double> woutput;
591
592
593
595
596 long maxh=0;
597 long binMax=0;
598 long bending=0, bestPhi=0;
599 long ztest;
600
601 for (
long zpm=0; zpm<1 || (
m_chargeAware && zpm<2 ) ; ++zpm ) {
602
603 std::vector< std::vector<long> >::iterator nfiter =
nHisto[zpm].begin();
604 for( ; nfiter!=
nHisto[zpm].end() ; ++nfiter) {
605
606 if((*nfiter).empty()) continue;
607 if((*nfiter).size() <= 2 ) continue;
608
609 for(std::vector<long>::iterator niter=(*nfiter).begin()+2; niter!=(*nfiter).end(); ++niter ) {
610
611 ztest = *(niter-2) + *(niter-1) + *(niter);
612 if ( ztest <= 0 || ztest < maxh ) continue;
615 if ( ztest >= maxh ) {
616 long bintest = niter-(*nfiter).begin()-1;
617 if ( ztest > maxh ||
618
619 (
m_preferCentralZ && std::abs( bintest - HalfZhistoBins ) < std::abs( binMax - HalfZhistoBins ) ) ) {
620 maxh = ztest;
621 binMax = bintest;
622 bestPhi = nfiter-
nHisto[zpm].begin();
623 bending = zpm;
624 }
625 }
626 }
627 }
628 }
629
630
634 break;
635 }
636
637
638
639 double weightedMax = ( zHisto[bending][bestPhi][binMax] +
640 zHisto[bending][bestPhi][binMax+1] +
641 zHisto[bending][bestPhi][binMax-1] ) /maxh;
642
645 nHisto[bending][bestPhi][binMax] = -1;
646 nHisto[bending][bestPhi][binMax-1] = -1;
647 nHisto[bending][bestPhi][binMax+1] = -1;
648 zHisto[bending][bestPhi][binMax] = 0;
649 zHisto[bending][bestPhi][binMax-1] = 0;
650 zHisto[bending][bestPhi][binMax+1] = 0;
651 }
652
653 int closestVtx = -1;
654 float dist2closestVtx = 1000;
655 for ( size_t iv = 0; iv < zoutput.size(); ++iv ) {
656 if ( fabs(weightedMax-zoutput[iv]) < dist2closestVtx ) {
657 closestVtx = iv;
658 dist2closestVtx = fabs(weightedMax-zoutput[iv]);
659 }
660 }
661
665 }
666 else {
667
670 bool addvtx = true;
671 double significance = 0;
672 if ( bg>0 ) {
673 significance = (maxh-
bg)/std::sqrt(bg);
675 }
676
677 if ( addvtx ) {
678 zoutput.push_back( weightedMax );
679 woutput.push_back( maxh );
680 }
681 }
682
683 }
684
685
690
698
701
702
707 for (
unsigned i=0 ;
i<zoutput.size() ;
i++ ) {
708 output->push_back(
vertex( woutput[i] - pedestal, zoutput[i] ) );
709 }
710 }
711 else {
712 for (
unsigned i=0 ;
i<zoutput.size() ;
i++ ) {
713 output->push_back(
vertex( zoutput[i], woutput[i] - pedestal ) );
714 }
715 }
716
717
718
719
721
722}
virtual double eta() const =0
virtual double zedPlus() const =0
the zed and eta values at the most forward and most rear ends of the RoI
virtual double zedMinus() const =0
long fillVectors(const std::vector< TrigSiSpacePointBase > &spVec, const IRoiDescriptor &roi, std::vector< double > &phi, std::vector< double > &rho, std::vector< double > &zed, std::vector< long > &lyr, std::vector< long > &filledLayers, long &numPhiSlices) const
long m_IdScan_LastBrlLayer
std::vector< std::vector< long > > m_extraPhi
int count(std::string s, const std::string ®x)
count how many occurances of a regx are in a string
unsigned int phiIndex(float phi, float binsize)
calculate phi index for a given phi
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.