21 #ifndef IDSCANZFINDER_IDSCANZFINDERINTERNAL_H
22 #define IDSCANZFINDER_IDSCANZFINDERINTERNAL_H
32 static const std::string mZFIVER(
"$Id: IDScanZFinderInternal.h 700483 2015-10-14 09:37:16Z sutt $");
64 void setLayers(
long maxLayers,
long lastBarrelLayer) {
74 std::vector<double>& phi, std::vector<double>&
rho, std::vector<double>& zed,
75 std::vector<long>& lyr, std::vector<long>& filledLayers);
79 const std::string&
getVersion()
const {
return mZFIVER; }
84 double computeZV(
double r1,
double z1,
double r2,
double z2)
const;
85 double computeZV(
double r1,
double p1,
double z1,
double r2,
double p2,
double z2)
const;
171 template<
class SpacePo
int>
173 const std::string&
name)
226 template<
class SpacePo
int>
229 m_halfTripletDK = 0.5*m_tripletDK;
231 m_IdScan_MaxNumLayers = maxLayers;
232 m_IdScan_LastBrlLayer = lastBarrel;
239 m_extraPhi = std::vector< std::vector<long> >( m_IdScan_MaxNumLayers, std::vector<long>(m_IdScan_MaxNumLayers) );
241 if ( m_fullScanMode ) m_usedROIphiWidth = 2*
M_PI;
242 else m_usedROIphiWidth = m_ROIphiWidth;
245 m_usedphiBinSize = m_phiBinSize;
247 if ( m_dphideta > 0 ) m_dphideta *= -m_dphideta;
249 m_invPhiSliceSize = 180./(
M_PI*m_usedphiBinSize);
253 for (
long l1=0;
l1<m_IdScan_MaxNumLayers-1; ++
l1) {
254 for (
long l2=
l1+1;
l2<m_IdScan_MaxNumLayers; ++
l2) {
255 m_extraPhi[
l1][
l2]=1;
261 long first_layer = 0;
262 long offset_layer = 1;
263 if ( m_IdScan_MaxNumLayers<20 ) {
269 for (
long l1=0;
l1<m_IdScan_LastBrlLayer; ++
l1) {
270 for (
long l2=
l1+1;
l2<=m_IdScan_LastBrlLayer; ++
l2) {
271 double dphi = ZF_dphiBrl[lyrcnt + 7*first_layer];
272 dphi *= m_neighborMultiplier;
273 m_extraPhi[
l1][
l2]=
static_cast<long>( ceil( sqrt(dphi*dphi+
ZF_phiRes*
ZF_phiRes*2) * m_invPhiSliceSize ) );
277 if (m_extraPhi[
l1][
l2]<1) m_extraPhi[
l1][
l2]=1;
290 for (
long lyrpair=12*first_layer ; lyrpair<117; ++lyrpair ) {
292 double dphi = ZF_dphiEC[lyrpair*4+2];
295 long l1 = (long)ZF_dphiEC[lyrpair*4] + offset_layer;
296 long l2 = (long)ZF_dphiEC[lyrpair*4+1] + offset_layer;
297 double eta = ZF_dphiEC[lyrpair*4+3];
301 dphi = dphi + m_dphideta * ( 0.9 - eta );
302 dphi *= m_neighborMultiplier;
305 if (m_extraPhi[
l1][
l2]<1) m_extraPhi[
l1][
l2]=1;
314 template<
class SpacePo
int>
316 return (z2*r1-z1*r2)/(r1-r2);
319 template<
class SpacePo
int>
321 double r2,
double p2,
double z2)
const {
333 double invslope = 1./slope;
334 double x0 = (slope*
x1-
y1)/(slope+invslope);
336 double d0sqr = x0*x0*(1+invslope*invslope);
338 double s1 = sqrt(r1*r1-d0sqr);
339 double s2 = sqrt(r2*r2-d0sqr);
343 double s1 = ( dotrr - r1*r1 ) * inv_dels;
344 double s2 = ( r2*r2 - dotrr ) * inv_dels;
347 return (z2*s1-z1*
s2)/(s1-
s2);
353 std::vector<double>& phi,
354 std::vector<double>&
rho,
355 std::vector<double>& zed,
356 std::vector<long>& lyr,
357 std::vector<long>& filledLayers)
359 std::vector<bool> lcount( m_IdScan_MaxNumLayers,
false );
362 typename std::vector<const SpacePoint *>::const_iterator SpItr( spVec.begin() );
364 long nSPs = spVec.size();
369 double roiPhiMin, roiPhiMax;
379 if ( m_trustSPprovider && m_usedROIphiWidth <
M_PI )
381 double roiPhiPosMin( 9.9), roiPhiPosMax(0);
382 double roiPhiNegMin(-9.9), roiPhiNegMax(0);
383 for(
long i=0;
i<nSPs; ++
i, ++SpItr)
385 double spphi = (*SpItr)->phi();
386 if ( spphi>0 && spphi>roiPhiPosMax ) roiPhiPosMax = spphi;
387 if ( spphi>0 && spphi<roiPhiPosMin ) roiPhiPosMin = spphi;
389 if ( spphi<0 && spphi<roiPhiNegMax ) roiPhiNegMax = spphi;
390 if ( spphi<0 && spphi>roiPhiNegMin ) roiPhiNegMin = spphi;
393 if ( roiPhiNegMax > roiPhiNegMin ) {
395 roiPhiMin = roiPhiPosMin;
396 roiPhiMax = roiPhiPosMax;
398 else if ( roiPhiPosMax < roiPhiPosMin ) {
400 roiPhiMin = roiPhiNegMax;
401 roiPhiMax = roiPhiNegMin;
403 else if ( roiPhiPosMin - roiPhiNegMin <
M_PI ) {
405 roiPhiMin = roiPhiNegMax;
406 roiPhiMax = roiPhiPosMax;
410 roiPhiMin = roiPhiPosMin;
411 roiPhiMax = roiPhiNegMin;
417 SpItr = spVec.begin();
423 roiPhiMin = roi.
phi()-0.5*m_usedROIphiWidth;
424 roiPhiMax = roi.
phi()+0.5*m_usedROIphiWidth;
425 if(roiPhiMin<-
M_PI) roiPhiMin+=2*
M_PI;
426 if(roiPhiMax>
M_PI) roiPhiMax-=2*
M_PI;
439 double dphi = roiPhiMax-roiPhiMin;
440 if ( dphi<0 ) dphi+=2*
M_PI;
442 m_usedROIphiWidth = dphi;
445 m_NumPhiSlices = long (ceil( m_usedROIphiWidth*m_invPhiSliceSize ));
448 bool piBound=(roiPhiMin>roiPhiMax);
455 for(
long i=0;
i<nSPs; ++
i, ++SpItr)
457 if (m_pixOnly && !(*SpItr)->isPixel())
continue;
458 double phi2 = (*SpItr)->phi() - roiPhiMin;
460 if ( phi2>=0 && phi2<dphi ) {
462 rho[
i] = (*SpItr)->r();
463 zed[
i] = (*SpItr)->z();
464 lyr[
i] = (*SpItr)->layer();
473 for(
long i=0;
i<nSPs; ++
i, ++SpItr)
475 if (m_pixOnly && !(*SpItr)->isPixel())
continue;
476 double phi2 = (*SpItr)->phi() - roiPhiMin;
477 if( phi2<0.0) phi2+=2*
M_PI;
479 if ( phi2>=0 && phi2<dphi ) {
481 rho[
i] = (*SpItr)->r();
482 zed[
i] = (*SpItr)->z();
483 lyr[
i] = (*SpItr)->layer();
509 for (
long i=0;
i<m_IdScan_MaxNumLayers; ++
i ) {
524 template<
class SpacePo
int>
528 std::vector<vertex>*
output =
new std::vector<vertex>();
530 long nsp = spVec.size();
531 if ( !nsp )
return output;
533 SetInternalStatus(0);
539 std::vector<double> phi(nsp),
rho(nsp), zed(nsp);
540 std::vector<long> lyr(nsp), filledLayers(m_IdScan_MaxNumLayers);
542 long filled = this->fillVectors( spVec, roi, phi,
rho, zed, lyr, filledLayers);
554 const double ZBinSize = m_minZBinSize + m_zBinSizeEtaCoeff*fabs(roi.
eta());
555 const double invZBinSize = 1./ZBinSize;
558 const long HalfZhistoBins = long ( ceil( 0.5*(zMax-zMin)*invZBinSize ) );
559 const long NumZhistoBins = 2*HalfZhistoBins;
562 const long extraPhiNeg =
static_cast<long> ( floor( (0.9 - fabs(roi.
eta()))*m_dphideta*m_invPhiSliceSize*m_neighborMultiplier ) );
571 long numZhistos = m_zHistoPerPhi ? m_NumPhiSlices : 1 ;
576 for (
int i=2 ;
i-- ; ) { m_nHisto[
i].clear(); m_nHisto[
i].resize(numZhistos); }
577 for (
int i=2 ;
i-- ; ) { m_zHisto[
i].clear(); m_zHisto[
i].resize(numZhistos); }
579 std::vector< std::vector<long> >*
nHisto = m_nHisto;
580 std::vector< std::vector<double> >* zHisto = m_zHisto;
588 std::vector< PhiSlice* > allSlices( m_NumPhiSlices );
589 for (
unsigned int sliceIndex = 0; sliceIndex < m_NumPhiSlices; sliceIndex++ )
591 allSlices[ sliceIndex ] =
new PhiSlice( sliceIndex, ZBinSize, m_invPhiSliceSize,
592 m_tripletDZ, m_halfTripletDK, m_tripletDP, zMin, zMax,
593 m_IdScan_MaxNumLayers, m_IdScan_LastBrlLayer );
596 int allSlicesSize = allSlices.size();
598 for (
long pointIndex = 0; pointIndex < nsp; pointIndex++ )
600 int phiIndex = floor( phi[ pointIndex ] * m_invPhiSliceSize );
604 allSlices[
phiIndex ]->AddPoint(
rho[ pointIndex ], zed[ pointIndex ], phi[ pointIndex ], lyr[ pointIndex ] );
608 std::vector< std::vector< double > > allLayerRhos, allLayerZs, allLayerPhis;
609 allLayerRhos.resize( m_IdScan_MaxNumLayers );
610 allLayerZs.resize( m_IdScan_MaxNumLayers );
611 allLayerPhis.resize( m_IdScan_MaxNumLayers );
612 std::vector< std::vector< int > > allSliceWidths( m_IdScan_MaxNumLayers, std::vector< int >( m_NumPhiSlices + 1, 0 ) );
613 for (
unsigned int sliceIndex = 0; sliceIndex < m_NumPhiSlices; sliceIndex++ )
615 allSlices[ sliceIndex ]->MakeWideLayers( &allLayerRhos, &allLayerZs, &allLayerPhis, &allSliceWidths,
filled, &filledLayers );
619 if ( m_zHistoPerPhi )
622 for (
unsigned int sliceIndex = 0; sliceIndex < m_NumPhiSlices; sliceIndex++ )
624 nHisto[0][sliceIndex].resize( NumZhistoBins + 1 );
625 zHisto[0][sliceIndex].resize( NumZhistoBins + 1 );
629 for (
unsigned int sliceIndex = 0; sliceIndex < m_NumPhiSlices; sliceIndex++ )
631 nHisto[1][sliceIndex].resize( NumZhistoBins + 1 );
632 zHisto[1][sliceIndex].resize( NumZhistoBins + 1 );
637 for (
unsigned int sliceIndex = 0; sliceIndex < m_NumPhiSlices; sliceIndex++ )
639 allSlices[ sliceIndex ]->GetHistogram( &(
nHisto[0][sliceIndex] ), &( zHisto[0][sliceIndex] ),
640 &(
nHisto[1][sliceIndex] ), &( zHisto[1][sliceIndex] ),
641 m_extraPhi, extraPhiNeg, m_nFirstLayers, m_tripletMode, m_chargeAware,
nHisto, zHisto );
645 delete allSlices[ sliceIndex ];
651 nHisto[0][0].resize( NumZhistoBins + 1 );
652 zHisto[0][0].resize( NumZhistoBins + 1 );
655 nHisto[1][0].resize( NumZhistoBins + 1 );
656 zHisto[1][0].resize( NumZhistoBins + 1 );
660 for (
unsigned int sliceIndex = 0; sliceIndex < m_NumPhiSlices; sliceIndex++ )
662 allSlices[ sliceIndex ]->GetHistogram( &(
nHisto[0][0] ), &( zHisto[0][0] ),
663 &(
nHisto[1][0] ), &( zHisto[1][0] ),
664 m_extraPhi, extraPhiNeg, m_nFirstLayers, m_tripletMode, m_chargeAware );
665 delete allSlices[ sliceIndex ];
683 if ( m_weightThreshold>0 ) {
687 for (
long zpm=0; zpm<1 || ( m_chargeAware && zpm<2 ) ; ++zpm ) {
691 if((*nfiter).empty())
continue;
692 if((*nfiter).size() <= 2 )
continue;
698 pedestal += *(niter) + *(niter-1) + *(niter-2);
714 std::vector<double> zoutput;
715 std::vector<double> woutput;
719 while((
int)zoutput.size() < m_numberOfPeaks) {
723 long bending=0, bestPhi=0;
726 for (
long zpm=0; zpm<1 || ( m_chargeAware && zpm<2 ) ; ++zpm ) {
730 if((*nfiter).empty())
continue;
731 if((*nfiter).size() <= 2 )
continue;
735 ztest = *(niter-2) + *(niter-1) + *(niter);
736 if ( ztest <= 0 || ztest < maxh )
continue;
739 if ( ztest >= maxh ) {
740 long bintest = niter-(*nfiter).begin()-1;
743 (m_preferCentralZ && std::abs( bintest - HalfZhistoBins ) < std::abs( binMax - HalfZhistoBins ) ) ) {
746 bestPhi = nfiter-
nHisto[zpm].begin();
756 if ( maxh==0 || ( m_tripletMode==0 && maxh<2 ) ) {
762 double weightedMax = ( zHisto[bending][bestPhi][binMax] +
763 zHisto[bending][bestPhi][binMax+1] +
764 zHisto[bending][bestPhi][binMax-1] ) /maxh;
767 if ( m_numberOfPeaks>1 ) {
768 nHisto[bending][bestPhi][binMax] = -1;
769 nHisto[bending][bestPhi][binMax-1] = -1;
770 nHisto[bending][bestPhi][binMax+1] = -1;
771 zHisto[bending][bestPhi][binMax] = 0;
772 zHisto[bending][bestPhi][binMax-1] = 0;
773 zHisto[bending][bestPhi][binMax+1] = 0;
777 float dist2closestVtx = 1000;
778 for (
size_t iv = 0; iv < zoutput.size(); ++iv )
779 if ( fabs(weightedMax-zoutput[iv]) < dist2closestVtx ) {
781 dist2closestVtx = fabs(weightedMax-zoutput[iv]);
784 if ( dist2closestVtx < m_nvrtxSeparation * ZBinSize ||
785 dist2closestVtx < fabs(weightedMax) * m_vrtxDistCut ) {
786 zoutput[closestVtx] = m_vrtxMixing * weightedMax + (1.0 - m_vrtxMixing) * zoutput[closestVtx] ;
787 woutput[closestVtx] = m_vrtxMixing * maxh + (1.0 - m_vrtxMixing) * woutput[closestVtx] ;
789 zoutput.push_back( weightedMax );
790 woutput.push_back( maxh );
814 if ( m_weightThreshold>0 ) {
824 for (
unsigned i=0 ;
i<zoutput.size() ;
i++ ) {
827 output->push_back( woutput[
i] - pedestal );
832 for (
unsigned i=0 ;
i<zoutput.size() ;
i++ )
output->push_back( zoutput[
i] );
841 if ( m_weightThreshold>0 ) {
842 for (
unsigned i=0 ;
i<zoutput.size() ;
i++ ) {
847 for (
unsigned i=0 ;
i<zoutput.size() ;
i++ ) {