TrackCaloMatching/src/TrackCaloIntersectionMVA_module.cc
double TrackCaloIntersectionMVA::scanIn(Calorimeter const& cal, TrkDifTraj const& traj, HelixTraj const& trkHel, int iSection, double rangeStart, double rangeEnd)
    {         

	 //check if we're inside the rdial envelope, if not, fast forward to it
	 double initRadius = radiusAtRange(traj,rangeStart);
	 


	 if (initRadius < cal.disk(iSection).geomInfo().innerEnvelopeR())  rangeStart += extendToRadius(trkHel, traj, rangeStart, cal.disk(iSection).geomInfo().innerEnvelopeR());	 
	 if (initRadius > cal.disk(iSection).geomInfo().outerEnvelopeR()) rangeStart += extendToRadius(trkHel, traj, rangeStart, cal.disk(iSection).geomInfo().outerEnvelopeR()); 

	 if (rangeStart > rangeEnd) return rangeEnd+1e-4;


	 //now find two starting points, one inside the boundary, the other outside
	 CLHEP::Hep3Vector trjVec;
	 updateTrjVec(cal,traj,rangeStart,trjVec);
	 
	 double rangeIn(rangeStart),rangeOut(rangeStart);
	 if ( cal.geomUtil().isInsideSection(iSection,trjVec))
	 {
	      while (cal.geomUtil().isInsideSection(iSection,trjVec))
	      {
		 rangeIn = rangeOut; 
		 rangeOut -= _pathStep;
		 updateTrjVec(cal,traj,rangeOut,trjVec);
		 if (_diagLevel>2) std::cout<<"TrackExtrpol position scan In down "<<trjVec<<"  for currentRange="<<rangeOut<<"   "<<"radius="<<radiusAtRange(traj,rangeOut)<<std::endl;
	      }	 

	 } else {
	 
	      while ( !cal.geomUtil().isInsideSection(iSection,trjVec) )
	      {
		 rangeOut = rangeIn; 
		 rangeIn += _pathStep;
        	 updateTrjVec(cal,traj,rangeIn,trjVec);
		 if (_diagLevel>2) std::cout<<"TrackExtrpol position scan In up "<<trjVec<<"  for currentRange="<<rangeIn<<"   "<<"radius="<<radiusAtRange(traj,rangeIn)<<std::endl;

		 if ( rangeIn > rangeEnd) return rangeIn;
	      }	    
	 }
	 
	 //finally, run the binary search for the intersection
	 return scanBinary(cal, traj, iSection, rangeIn, rangeOut);
    }
//-----------------------------------------------------------------------------
// find two starting points inside and outside of the calorimeter, either move out if we're in, or move in if we're out
// if we are outside the calorimeter envelope, fast forward to the envelope
find two starting points inside and outside of the calorimeter, either move out if we're in, or move in if we're out
if we are outside the calorimeter envelope, fast forward to the envelope
find two starting points inside and outside of the calorimeter either move out if we ' re in or move in if we ' re out if we are outside the calorimeter envelope fast forward to the envelope
double TrackCaloIntersectionMVA::scanIn(Calorimeter const& cal, TrkDifTraj const& traj, HelixTraj const& trkHel, int iSection, double rangeStart, double rangeEnd)
    {         
	 double initRadius = radiusAtRange(traj,rangeStart);
	 if (initRadius < cal.disk(iSection).geomInfo().innerEnvelopeR())  rangeStart += extendToRadius(trkHel, traj, rangeStart, cal.disk(iSection).geomInfo().innerEnvelopeR());	 
	 if (initRadius > cal.disk(iSection).geomInfo().outerEnvelopeR()) rangeStart += extendToRadius(trkHel, traj, rangeStart, cal.disk(iSection).geomInfo().outerEnvelopeR()); 
	 if (rangeStart > rangeEnd) return rangeEnd+1e-4;
	 CLHEP::Hep3Vector trjVec;
	 updateTrjVec(cal,traj,rangeStart,trjVec);
	 double rangeIn(rangeStart),rangeOut(rangeStart);
	 if ( cal.geomUtil().isInsideSection(iSection,trjVec))
	 {
	      while (cal.geomUtil().isInsideSection(iSection,trjVec))
	      {
		 rangeIn = rangeOut; 
		 rangeOut -= _pathStep;
		 updateTrjVec(cal,traj,rangeOut,trjVec);
		 if (_diagLevel>2) std::cout<<"TrackExtrpol position scan In down "<<trjVec<<"  for currentRange="<<rangeOut<<"   "<<"radius="<<radiusAtRange(traj,rangeOut)<<std::endl;
	      }	 
	 } else {
	      while ( !cal.geomUtil().isInsideSection(iSection,trjVec) )
	      {
		 rangeOut = rangeIn; 
		 rangeIn += _pathStep;
        	 updateTrjVec(cal,traj,rangeIn,trjVec);
		 if (_diagLevel>2) std::cout<<"TrackExtrpol position scan In up "<<trjVec<<"  for currentRange="<<rangeIn<<"   "<<"radius="<<radiusAtRange(traj,rangeIn)<<std::endl;
		 if ( rangeIn > rangeEnd) return rangeIn;
	      }	    
	 }
	 return scanBinary(cal, traj, iSection, rangeIn, rangeOut);
    }
double TrackCaloIntersectionMVA :: scanIn ( Calorimeter const & cal , TrkDifTraj const & traj , HelixTraj const & trkHel , int iSection , double rangeStart , double rangeEnd ) { double initRadius = radiusAtRange ( traj , rangeStart ) ; if ( initRadius < cal . disk ( iSection ) . geomInfo ( ) . innerEnvelopeR ( ) ) rangeStart += extendToRadius ( trkHel , traj , rangeStart , cal . disk ( iSection ) . geomInfo ( ) . innerEnvelopeR ( ) ) ; if ( initRadius > cal . disk ( iSection ) . geomInfo ( ) . outerEnvelopeR ( ) ) rangeStart += extendToRadius ( trkHel , traj , rangeStart , cal . disk ( iSection ) . geomInfo ( ) . outerEnvelopeR ( ) ) ; if ( rangeStart > rangeEnd ) return rangeEnd + 1e-4 ; CLHEP :: Hep3Vector trjVec ; updateTrjVec ( cal , traj , rangeStart , trjVec ) ; double rangeIn ( rangeStart ) , rangeOut ( rangeStart ) ; if ( cal . geomUtil ( ) . isInsideSection ( iSection , trjVec ) ) { while ( cal . geomUtil ( ) . isInsideSection ( iSection , trjVec ) ) { rangeIn = rangeOut ; rangeOut -= _pathStep ; updateTrjVec ( cal , traj , rangeOut , trjVec ) ; if ( _diagLevel > 2 ) std :: cout << " " << trjVec << " " << rangeOut << " " << " " << radiusAtRange ( traj , rangeOut ) << std :: endl ; } } else { while ( ! cal . geomUtil ( ) . isInsideSection ( iSection , trjVec ) ) { rangeOut = rangeIn ; rangeIn += _pathStep ; updateTrjVec ( cal , traj , rangeIn , trjVec ) ; if ( _diagLevel > 2 ) std :: cout << " " << trjVec << " " << rangeIn << " " << " " << radiusAtRange ( traj , rangeIn ) << std :: endl ; if ( rangeIn > rangeEnd ) return rangeIn ; } } return scanBinary ( cal , traj , iSection , rangeIn , rangeOut ) ; }
find two starting points inside and outside of the calorimeter, either move out if we're in, or move in if we're out
if we are outside the calorimeter envelope, fast forward to the envelope
find two starting points inside and outside of the calorimeter either move out if we ' re in or move in if we ' re out if we are outside the calorimeter envelope fast forward to the envelope
//check if we're inside the rdial envelope, if not, fast forward to it //now find two starting points, one inside the boundary, the other outside //finally, run the binary search for the intersection